From b642a99dceda5744a4cf678d22adf324ac80e119 Mon Sep 17 00:00:00 2001 From: Honfika Date: Sun, 2 Feb 2014 10:30:35 +0100 Subject: [PATCH] generic tag panel refactored --- .../decompiler/flash/gui/BinaryPanel.java | 12 +- .../decompiler/flash/gui/GenericTagPanel.java | 104 ++++++++++++++++++ .../jpexs/decompiler/flash/gui/MainPanel.java | 74 +++++++++---- 3 files changed, 162 insertions(+), 28 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/BinaryPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/BinaryPanel.java index f6b668fb8..2d9c5364b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/BinaryPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/BinaryPanel.java @@ -21,14 +21,16 @@ import com.jpexs.helpers.Helper; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import javax.swing.JPanel; import javax.swing.JScrollPane; -public final class BinaryPanel extends JPanel implements ActionListener, ComponentListener { +/** + * + * @author JPEXS + */ +public final class BinaryPanel extends JPanel implements ComponentListener { public LineMarkedEditorPane hexEditor = new LineMarkedEditorPane(); private byte[] data; @@ -45,10 +47,6 @@ public final class BinaryPanel extends JPanel implements ActionListener, Compone addComponentListener(this); } - @Override - public void actionPerformed(ActionEvent e) { - } - public void setBinaryData(byte[] data) { this.data = data; hexEditor.setEditable(false); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java new file mode 100644 index 000000000..643b65800 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/gui/GenericTagPanel.java @@ -0,0 +1,104 @@ +/* + * 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; + +import com.jpexs.decompiler.flash.helpers.GraphTextWriter; +import com.jpexs.decompiler.flash.tags.Tag; +import java.awt.BorderLayout; +import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; +import java.lang.reflect.Field; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.JEditorPane; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; + +/** + * + * @author JPEXS + */ +public class GenericTagPanel extends JPanel implements ComponentListener { + + private final JEditorPane genericTagPropertiesEditorPane; + private final JPanel genericTagPropertiesEditPanel; + private final JScrollPane genericTagPropertiesEditorPaneScrollPanel; + private final JScrollPane genericTagPropertiesEditPanelScrollPanel; + + public GenericTagPanel() { + super(new BorderLayout()); + + genericTagPropertiesEditorPane = new JEditorPane(); + genericTagPropertiesEditorPane.setEditable(false); + genericTagPropertiesEditorPaneScrollPanel = new JScrollPane(genericTagPropertiesEditorPane); + add(genericTagPropertiesEditorPaneScrollPanel); + + genericTagPropertiesEditPanel = new JPanel(); + genericTagPropertiesEditPanelScrollPanel = new JScrollPane(genericTagPropertiesEditPanel); + } + + public void setEditMode(boolean edit) { + if (edit) { + remove(genericTagPropertiesEditorPaneScrollPanel); + add(genericTagPropertiesEditPanelScrollPanel); + } else { + remove(genericTagPropertiesEditPanelScrollPanel); + add(genericTagPropertiesEditorPaneScrollPanel); + } + } + + public void setTagText(Tag tag) { + StringBuilder sb = new StringBuilder(); + Field[] fields = tag.getClass().getDeclaredFields(); + for (Field field : fields) { + try { + field.setAccessible(true); + sb.append(field.getName()).append(": ").append(field.get(tag)); + sb.append(GraphTextWriter.NEW_LINE); + } catch (IllegalArgumentException | IllegalAccessException ex) { + Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex); + } + } + genericTagPropertiesEditorPane.setText(sb.toString()); + genericTagPropertiesEditorPane.setSize(0, 0); + } + + public void generateEditControls() { + genericTagPropertiesEditPanel.removeAll(); + genericTagPropertiesEditPanel.add(new JLabel("aa")); + } + + @Override + public void componentResized(ComponentEvent e) { + genericTagPropertiesEditorPane.setSize(0, 0); + } + + @Override + public void componentMoved(ComponentEvent ce) { + } + + @Override + public void componentShown(ComponentEvent ce) { + } + + @Override + public void componentHidden(ComponentEvent ce) { + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 3cf51a104..4daa1d673 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -212,7 +212,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private final JPanel displayPanel; private ImagePanel imagePanel; private BinaryPanel binaryPanel; - private JEditorPane genericTagPropertiesEditorPane; + private GenericTagPanel genericTagPanel; private final ImagePanel previewImagePanel; private final SWFPreviwPanel swfPreviewPanel; private boolean isWelcomeScreen = true; @@ -251,6 +251,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private JPanel imageButtonsPanel; private JButton binaryReplaceButton; private JPanel binaryButtonsPanel; + private JButton genericEditButton; + private JButton genericSaveButton; + private JButton genericCancelButton; + private JPanel genericButtonsPanel; private PlayerControls flashControls; private final ImagePanel internelViewerPanel; private final JPanel viewerCards; @@ -263,6 +267,9 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private static final String ACTION_SELECT_COLOR = "SELECTCOLOR"; private static final String ACTION_REPLACE_IMAGE = "REPLACEIMAGE"; private static final String ACTION_REPLACE_BINARY = "REPLACEBINARY"; + private static final String ACTION_EDIT_GENERIC_TAG = "EDITGENERICTAG"; + private static final String ACTION_SAVE_GENERIC_TAG = "SAVEGENERICTAG"; + private static final String ACTION_CANCEL_GENERIC_TAG = "CANCELGENERICTAG"; private static final String ACTION_REMOVE_ITEM = "REMOVEITEM"; private static final String ACTION_EDIT_TEXT = "EDITTEXT"; private static final String ACTION_CANCEL_TEXT = "CANCELTEXT"; @@ -497,12 +504,30 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private JPanel createGenericTagCard() { JPanel genericTagCard = new JPanel(new BorderLayout()); - JPanel genericTagPanel = new JPanel(new BorderLayout()); - genericTagPropertiesEditorPane = new JEditorPane(); - genericTagPropertiesEditorPane.setEditable(false); - genericTagPanel.add(new JScrollPane(genericTagPropertiesEditorPane)); + genericTagPanel = new GenericTagPanel(); genericTagCard.add(genericTagPanel, BorderLayout.CENTER); + genericEditButton = new JButton(translate("button.edit"), View.getIcon("edit16")); + genericEditButton.setMargin(new Insets(3, 3, 3, 10)); + genericEditButton.setActionCommand(ACTION_EDIT_GENERIC_TAG); + genericEditButton.addActionListener(this); + genericSaveButton = new JButton(translate("button.save"), View.getIcon("save16")); + genericSaveButton.setMargin(new Insets(3, 3, 3, 10)); + genericSaveButton.setActionCommand(ACTION_SAVE_GENERIC_TAG); + genericSaveButton.addActionListener(this); + genericSaveButton.setVisible(false); + genericCancelButton = new JButton(translate("button.cancel"), View.getIcon("cancel16")); + genericCancelButton.setMargin(new Insets(3, 3, 3, 10)); + genericCancelButton.setActionCommand(ACTION_CANCEL_GENERIC_TAG); + genericCancelButton.addActionListener(this); + genericCancelButton.setVisible(false); + genericButtonsPanel = new JPanel(new FlowLayout()); + genericButtonsPanel.add(genericEditButton); + genericButtonsPanel.add(genericSaveButton); + genericButtonsPanel.add(genericCancelButton); + // todo: honfika: temporary hide edit button + genericTagCard.add(genericButtonsPanel, BorderLayout.SOUTH); + return genericTagCard; } @@ -2095,6 +2120,28 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } break; + case ACTION_EDIT_GENERIC_TAG: { + genericEditButton.setVisible(false); + genericSaveButton.setVisible(true); + genericCancelButton.setVisible(true); + genericTagPanel.setEditMode(true); + genericTagPanel.generateEditControls(); + } + break; + case ACTION_SAVE_GENERIC_TAG: { + genericEditButton.setVisible(true); + genericSaveButton.setVisible(false); + genericCancelButton.setVisible(false); + genericTagPanel.setEditMode(false); + } + break; + case ACTION_CANCEL_GENERIC_TAG: { + genericEditButton.setVisible(true); + genericSaveButton.setVisible(false); + genericCancelButton.setVisible(false); + genericTagPanel.setEditMode(false); + } + break; case ACTION_REMOVE_ITEM: List sel = getSelected(tagTree); @@ -2390,27 +2437,12 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } else if (tagObj instanceof Tag) { showCard(CARDGENEICTAGPANEL); - showGenericTag((Tag) tagObj); + genericTagPanel.setTagText((Tag) tagObj); } else { showCard(CARDEMPTYPANEL); } } - private void showGenericTag(Tag tag) { - StringBuilder sb = new StringBuilder(); - Field[] fields = tag.getClass().getDeclaredFields(); - for (Field field : fields) { - try { - field.setAccessible(true); - sb.append(field.getName()).append(": ").append(field.get(tag)); - sb.append(GraphTextWriter.NEW_LINE); - } catch (IllegalArgumentException | IllegalAccessException ex) { - Logger.getLogger(MainPanel.class.getName()).log(Level.SEVERE, null, ex); - } - } - genericTagPropertiesEditorPane.setText(sb.toString()); - } - private void createAndShowTempSwf(Object tagObj) { SWF swf; try {