AMF3 Editor enhancements + help

This commit is contained in:
Jindra Petřík
2016-07-23 19:29:21 +02:00
parent e2882dd196
commit a882b92fff
4 changed files with 860 additions and 745 deletions

View File

@@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.gui.generictageditors.Amf3ValueEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.BinaryDataEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.BooleanEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.ColorEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.FullSized;
import com.jpexs.decompiler.flash.gui.generictageditors.GenericTagEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.NumberEditor;
import com.jpexs.decompiler.flash.gui.generictageditors.StringEditor;
@@ -49,6 +50,7 @@ import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
@@ -66,6 +68,7 @@ import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractCellEditor;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JMenu;
@@ -75,6 +78,7 @@ import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.event.TreeModelListener;
import javax.swing.plaf.basic.BasicLabelUI;
import javax.swing.plaf.basic.BasicTreeUI;
@@ -135,6 +139,12 @@ public class GenericTagTreePanel extends GenericTagPanel {
@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
Rectangle cellRect = tree.getPathBounds(tree.getPathForRow(row));
Rectangle treeVisibleRect = tree.getVisibleRect();
int scrollBarSize = ((Integer) UIManager.get("ScrollBar.width")).intValue();
Rectangle cellMaxVisibleRect = new Rectangle(cellRect.x, cellRect.y, treeVisibleRect.width - cellRect.x - tree.getInsets().left - tree.getInsets().right - scrollBarSize, cellRect.height);
if (value instanceof FieldNode) {
fnode = (FieldNode) value;
JPanel panSum = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
@@ -194,7 +204,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
}
};
pan.setBackground(Color.white);
pan.setOpaque(false);
nameLabel.setAlignmentY(TOP_ALIGNMENT);
pan.add(nameLabel);
@@ -203,6 +213,9 @@ public class GenericTagTreePanel extends GenericTagPanel {
nameLabel.setSize(nameLabel.getWidth(), editorComponent.getHeight());
editorComponent.setAlignmentY(TOP_ALIGNMENT);
pan.add(editorComponent);
if (editorComponent instanceof FullSized) {
editorComponent.setPreferredSize(new Dimension(cellMaxVisibleRect.width - (int) nameLabel.getPreferredSize().getWidth() - 5, editorComponent.getPreferredSize().height));
}
if (editorComponent instanceof GenericTagEditor) {
((GenericTagEditor) editorComponent).added();
}
@@ -212,6 +225,7 @@ public class GenericTagTreePanel extends GenericTagPanel {
}
panSum.add(pan);
}
panSum.setPreferredSize(new Dimension(cellMaxVisibleRect.width, panSum.getPreferredSize().height));
return panSum;
}
return null;

View File

@@ -19,6 +19,8 @@ package com.jpexs.decompiler.flash.gui.generictageditors;
import com.jpexs.decompiler.flash.amf.amf3.Amf3Value;
import com.jpexs.decompiler.flash.exporters.amf.amf3.Amf3Exporter;
import com.jpexs.decompiler.flash.gui.AppStrings;
import com.jpexs.decompiler.flash.gui.View;
import com.jpexs.decompiler.flash.gui.editor.LineMarkedEditorPane;
import com.jpexs.decompiler.flash.importers.amf.amf3.Amf3Importer;
import com.jpexs.decompiler.flash.importers.amf.amf3.Amf3ParseException;
import com.jpexs.helpers.Helper;
@@ -27,6 +29,11 @@ import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusAdapter;
@@ -37,11 +44,13 @@ import java.awt.event.MouseListener;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Timer;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
@@ -49,24 +58,9 @@ import javax.swing.event.CaretListener;
*
* @author JPEXS
*/
public class Amf3ValueEditor extends JPanel implements GenericTagEditor {
public class Amf3ValueEditor extends JPanel implements GenericTagEditor, FullSized {
private JEditorPane editor = new JEditorPane() {
@Override
public boolean getScrollableTracksViewportWidth() {
return true;
}
@Override
public Component.BaselineResizeBehavior getBaselineResizeBehavior() {
return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
}
@Override
public int getBaseline(int width, int height) {
return 0;
}
};
private LineMarkedEditorPane editor = new LineMarkedEditorPane();
private final Object obj;
@@ -88,6 +82,23 @@ public class Amf3ValueEditor extends JPanel implements GenericTagEditor {
String s = editor.getText();
editor.setContentType("text/javascript");
editor.setText(s);
editor.setCaretPosition(0);
//Dimension csize = getPreferredSize();
//System.out.println("max=" + getMaximumSize());
//csize.height = 300;
//Dimension editorSize = editor.getPreferredSize();
//setPreferredSize(csize);
}
@Override
public BaselineResizeBehavior getBaselineResizeBehavior() {
return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
}
@Override
public int getBaseline(int width, int height) {
return 0;
}
public Amf3ValueEditor(String fieldName, Object obj, Field field, int index, Class<?> type) {
@@ -96,12 +107,56 @@ public class Amf3ValueEditor extends JPanel implements GenericTagEditor {
this.index = index;
this.type = type;
this.fieldName = fieldName;
setPreferredSize(new Dimension(800, 200));
setLayout(new BorderLayout());
Dimension d = new Dimension(500, 330);
setSize(d);
setPreferredSize(d);
JPanel titlePanel = new JPanel(new BorderLayout()) {
@Override
public Insets getInsets() {
Insets is = super.getInsets();
is.left = 5;
return is;
}
};
JLabel titleLabel = new JLabel(AppStrings.translate("generic.editor.amf3.title"));
titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD));
titlePanel.add(titleLabel, BorderLayout.CENTER);
JButton helpButton = new JButton(View.getIcon("about16"));
helpButton.setFocusable(false);
JTextArea txthelp = new JTextArea();
txthelp.setFont(new Font("monospaced", Font.PLAIN, 12));
final String SCALAR_SAMPLES = " * undefined, null, false, true\n"
+ " * integer : -5, 5, 29\n"
+ " * double: 5.5, 1.27, -187.568\n"
+ " * String: \"hello\", \"escape new\\nline\"\n";
final String NONSCALAR_SAMPLES = " * XMLDocument: {\"type\":\"XMLDocument\", value: \"<foo></foo>\"}\n"
+ " * Date: {\"type\":\"Date\", \"value\": \"2016-07-17 14:51:42.584\"}\n"
+ " * Array: {\"type\":\"Array\", \"denseValues\": [27,58,99], \"associativeValues\": {\"key1\":5, \"key2\": -4.6 }}\n"
+ " * Object: {\"type\":\"Object\",\"className\":\"\",\"dynamic\":true,\n"
+ " \"sealedMembers\": {\"smemberA\": \"abc\", \"smemberB\":987.5},\n"
+ " \"dynamicMembers\": {\"member1\": 5, \"member2\": \"aaa\"}\n"
+ " }\n"
+ " * XML: {\"type\":\"XML\", value: \"<foo></foo>\"}\n"
+ " * ByteArray: {\"type\":\"ByteArray\", \"value\":\"B0312F\"}\n"
+ " * Vector: {\"type\": \"Vector\", \"fixed\":false, \"subtype\":\"int\", \"values\": [8, 4, 6]}\n"
+ " * Dictionary: {\"type\": \"Dictionary\", \"weakKeys\":false, \"entries\": { \"dkey1\" : \"val1\", \"dkey2\": 56 }}\n";
final String REFERENCE_SAMPLE = " {\"type\": \"Vector\", \"fixed\":false, \"subtype\":\"\",\n"
+ " \"values\": [\n"
+ " {\"type\":\"Date\", id=\"mydate\",\"value\": \"2016-07-17 14:51:42.584\"}\n"
+ " #mydate,\n"
+ " #mydate,\n"
+ " {\"type\":\"Date\", \"value\": \"2016-07-26 18:12:22.188\"}\n"
+ " ]}";
txthelp.setText(AppStrings.translate("generic.editor.amf3.help").replace("%scalar_samples%", SCALAR_SAMPLES).replace("%nonscalar_samples%", NONSCALAR_SAMPLES).replace("%reference_sample%", REFERENCE_SAMPLE));
txthelp.setEditable(false);
helpButton.addActionListener((ActionEvent e) -> {
View.showMessageDialog(null, txthelp);
});
titlePanel.add(helpButton, BorderLayout.EAST);
add(titlePanel, BorderLayout.NORTH);
add(new JScrollPane(editor), BorderLayout.CENTER);
add(errorLabel, BorderLayout.SOUTH);
@@ -161,6 +216,13 @@ public class Amf3ValueEditor extends JPanel implements GenericTagEditor {
importer.stringToAmf(textVal);
}
} catch (IOException | Amf3ParseException ex) {
if (ex instanceof Amf3ParseException) {
Amf3ParseException ape = (Amf3ParseException) ex;
if (ape.line > 0) {
editor.gotoLine((int) ape.line);
}
}
final CaretListener cl = new CaretListener() {
@Override
public void caretUpdate(CaretEvent e) {

View File

@@ -0,0 +1,25 @@
/*
* Copyright (C) 2016 Jindra
*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.jpexs.decompiler.flash.gui.generictageditors;
/**
*
* @author JPEXS
*/
public interface FullSized {
}

File diff suppressed because it is too large Load Diff