From c620164c0a761dafeb38d7410b825274ca941ad7 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Tue, 30 Sep 2014 23:27:32 +0200 Subject: [PATCH] Show warning message when text is truncated in the editor (in debug mode) --- .../flash/gui/abc/LineMarkedEditorPane.java | 184 +++++++++--------- .../flash/gui/locales/MainFrame.properties | 4 +- 2 files changed, 96 insertions(+), 92 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/abc/LineMarkedEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/LineMarkedEditorPane.java index 1ef9741ab..29ad9b26b 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/LineMarkedEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/LineMarkedEditorPane.java @@ -1,91 +1,93 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash.gui.abc; - -import com.jpexs.decompiler.flash.configuration.Configuration; -import java.awt.Color; -import java.awt.FontMetrics; -import java.awt.Graphics; -import javax.swing.event.CaretEvent; -import javax.swing.event.CaretListener; -import javax.swing.text.Element; -import jsyntaxpane.actions.ActionUtils; - -/** - * - * @author JPEXS - */ -public class LineMarkedEditorPane extends UndoFixedEditorPane { - - int lastLine = -1; - - public int getLine() { - return lastLine; - } - - public void gotoLine(int line) { - setCaretPosition(ActionUtils.getDocumentPosition(this, line, 0)); - } - - public LineMarkedEditorPane() { - setOpaque(false); - addCaretListener(new CaretListener() { - @Override - public void caretUpdate(CaretEvent e) { - int caretPosition = getCaretPosition(); - Element root = getDocument().getDefaultRootElement(); - int currentLine = root.getElementIndex(caretPosition); - if (currentLine != lastLine) { - lastLine = currentLine; - repaint(); - } - } - }); - } - - @Override - public void setText(String t) { - lastLine = -1; - if (Configuration.debugMode.get() && t.length() > 4192) { - t = t.substring(0, 4192); - } - super.setText(t); - setCaretPosition(0); //scroll to top - } - - @Override - public void setText(String t, String contentType) { - lastLine = -1; - super.setText(t, contentType); - setCaretPosition(0); //scroll to top - } - - @Override - public void paint(Graphics g) { - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); - FontMetrics fontMetrics = g.getFontMetrics(); - int lh = fontMetrics.getHeight(); - int a = fontMetrics.getAscent(); - int d = fontMetrics.getDescent(); - int h = a + d; - int rH = h; - g.setColor(new Color(0xee, 0xee, 0xee)); - g.fillRect(0, d + lh * lastLine - 1, getWidth(), lh); - super.paint(g); - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.gui.abc; + +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.gui.AppStrings; +import java.awt.Color; +import java.awt.FontMetrics; +import java.awt.Graphics; +import javax.swing.event.CaretEvent; +import javax.swing.event.CaretListener; +import javax.swing.text.Element; +import jsyntaxpane.actions.ActionUtils; + +/** + * + * @author JPEXS + */ +public class LineMarkedEditorPane extends UndoFixedEditorPane { + + private static final int truncateLimit = 8192; + private int lastLine = -1; + + public int getLine() { + return lastLine; + } + + public void gotoLine(int line) { + setCaretPosition(ActionUtils.getDocumentPosition(this, line, 0)); + } + + public LineMarkedEditorPane() { + setOpaque(false); + addCaretListener(new CaretListener() { + @Override + public void caretUpdate(CaretEvent e) { + int caretPosition = getCaretPosition(); + Element root = getDocument().getDefaultRootElement(); + int currentLine = root.getElementIndex(caretPosition); + if (currentLine != lastLine) { + lastLine = currentLine; + repaint(); + } + } + }); + } + + @Override + public void setText(String t) { + lastLine = -1; + if (Configuration.debugMode.get() && t.length() > truncateLimit) { + t = t.substring(0, truncateLimit) + "\r\n" + AppStrings.translate("editorTruncateWarning").replace("%chars%", Integer.toString(truncateLimit)); + } + super.setText(t); + setCaretPosition(0); //scroll to top + } + + @Override + public void setText(String t, String contentType) { + lastLine = -1; + super.setText(t, contentType); + setCaretPosition(0); //scroll to top + } + + @Override + public void paint(Graphics g) { + g.setColor(Color.white); + g.fillRect(0, 0, getWidth(), getHeight()); + FontMetrics fontMetrics = g.getFontMetrics(); + int lh = fontMetrics.getHeight(); + int a = fontMetrics.getAscent(); + int d = fontMetrics.getDescent(); + int h = a + d; + int rH = h; + g.setColor(new Color(0xee, 0xee, 0xee)); + g.fillRect(0, d + lh * lastLine - 1, getWidth(), lh); + super.paint(g); + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index 392635c4f..d7f8e1595 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -510,4 +510,6 @@ button.zoomin.hint = Zoom in button.zoomout.hint = Zoom out button.zoomfit.hint = Zoom to fit button.zoomnone.hint = Zoom to 1:1 -button.snapshot.hint = Take snapshot into clipboard \ No newline at end of file +button.snapshot.hint = Take snapshot into clipboard + +editorTruncateWarning = Text truncated at position %chars% in debug mode. \ No newline at end of file