From 01f7d0fa727a68586ebd486e2ec29835cb8674fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Tue, 7 Sep 2010 21:54:32 +0200 Subject: [PATCH] AS2:Added statusbar to GUI --- trunk/src/com/jpexs/asdec/Main.java | 8 ++- .../com/jpexs/asdec/abc/gui/MainFrame.java | 20 +++--- trunk/src/com/jpexs/asdec/action/Action.java | 2 +- .../com/jpexs/asdec/action/gui/MainFrame.java | 67 +++++++++++++++---- 4 files changed, 70 insertions(+), 27 deletions(-) diff --git a/trunk/src/com/jpexs/asdec/Main.java b/trunk/src/com/jpexs/asdec/Main.java index 598d78302..707f52ae7 100644 --- a/trunk/src/com/jpexs/asdec/Main.java +++ b/trunk/src/com/jpexs/asdec/Main.java @@ -115,12 +115,18 @@ public class Main { public static void startWork(String name) { working = true; + if(abcMainFrame!=null) abcMainFrame.setStatus(name); + if(actionMainFrame!=null) + actionMainFrame.setStatus(name); } public static void stopWork() { working = false; - abcMainFrame.setStatus(""); + if(abcMainFrame!=null) + abcMainFrame.setStatus(""); + if(actionMainFrame!=null) + actionMainFrame.setStatus(""); } public static SWF parseSWF(String file) throws Exception { diff --git a/trunk/src/com/jpexs/asdec/abc/gui/MainFrame.java b/trunk/src/com/jpexs/asdec/abc/gui/MainFrame.java index 271a57710..469f80626 100644 --- a/trunk/src/com/jpexs/asdec/abc/gui/MainFrame.java +++ b/trunk/src/com/jpexs/asdec/abc/gui/MainFrame.java @@ -47,13 +47,9 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener { public void setStatus(String s) { if (s.equals("")) { - //statusLabel.setOpaque(false); loadingPanel.setVisible(false); } else { loadingPanel.setVisible(true); - //statusLabel.setForeground(Color.white); - //statusLabel.setBackground(Color.red); - //statusLabel.setOpaque(true); } statusLabel.setText(s); } @@ -296,6 +292,13 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener { } public void actionPerformed(ActionEvent e) { + if (e.getActionCommand().equals("EXIT")) { + setVisible(false); + if (Main.proxyFrame != null) { + if (Main.proxyFrame.isVisible()) return; + } + Main.exit(); + } if (Main.isWorking()) return; if (e.getActionCommand().equals("SHOWPROXY")) { Main.showProxy(); @@ -349,14 +352,7 @@ public class MainFrame extends JFrame implements ActionListener, ItemListener { } - } - if (e.getActionCommand().equals("EXIT")) { - setVisible(false); - if (Main.proxyFrame != null) { - if (Main.proxyFrame.isVisible()) return; - } - Main.exit(); - } + } } public void itemStateChanged(ItemEvent e) { diff --git a/trunk/src/com/jpexs/asdec/action/Action.java b/trunk/src/com/jpexs/asdec/action/Action.java index dc131cc68..9d13d8613 100644 --- a/trunk/src/com/jpexs/asdec/action/Action.java +++ b/trunk/src/com/jpexs/asdec/action/Action.java @@ -786,7 +786,7 @@ public class Action { isFor = false; isForIn = false; continue; - } else if(action instanceof ActionEnumerate2){ + } else if((action instanceof ActionEnumerate2)||(action instanceof ActionEnumerate)){ loopStart=ip+1; isForIn=true; inItem=stack.pop(); diff --git a/trunk/src/com/jpexs/asdec/action/gui/MainFrame.java b/trunk/src/com/jpexs/asdec/action/gui/MainFrame.java index df1854347..1ff93817a 100644 --- a/trunk/src/com/jpexs/asdec/action/gui/MainFrame.java +++ b/trunk/src/com/jpexs/asdec/action/gui/MainFrame.java @@ -3,6 +3,7 @@ package com.jpexs.asdec.action.gui; import com.jpexs.asdec.Main; import com.jpexs.asdec.action.parser.ASMParser; import com.jpexs.asdec.action.parser.ParseException; +import com.jpexs.asdec.gui.LoadingPanel; import com.jpexs.asdec.gui.View; import com.jpexs.asdec.helpers.Highlighting; import com.jpexs.asdec.tags.ASMSource; @@ -24,6 +25,7 @@ import java.io.IOException; import java.util.List; public class MainFrame extends JFrame implements TreeSelectionListener, ActionListener { + public JTree tagTree; public JEditorPane editor; public JEditorPane decompiledEditor; @@ -33,6 +35,9 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi public JButton saveButton = new JButton("Save"); public JLabel asmLabel = new JLabel("P-code source (editable)"); public JLabel decLabel = new JLabel("ActionScript source"); + public JPanel statusPanel = new JPanel(); + public LoadingPanel loadingPanel = new LoadingPanel(20, 20); + public JLabel statusLabel = new JLabel(""); public MainFrame(List list) { this.list = list; @@ -52,7 +57,7 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi panB.setLayout(new BorderLayout()); asmLabel.setHorizontalAlignment(SwingConstants.CENTER); asmLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); - panB.add(asmLabel,BorderLayout.NORTH); + panB.add(asmLabel, BorderLayout.NORTH); panB.add(new JScrollPane(editor), BorderLayout.CENTER); JPanel buttonsPan = new JPanel(); @@ -63,24 +68,42 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi saveButton.addActionListener(this); saveButton.setActionCommand("SAVEACTION"); - JPanel panA=new JPanel(); + JPanel panA = new JPanel(); panA.setLayout(new BorderLayout()); - panA.add(new JScrollPane(decompiledEditor),BorderLayout.CENTER); + panA.add(new JScrollPane(decompiledEditor), BorderLayout.CENTER); panA.add(decLabel, BorderLayout.NORTH); decLabel.setHorizontalAlignment(SwingConstants.CENTER); decLabel.setBorder(new BevelBorder(BevelBorder.RAISED)); - - setLayout(new BorderLayout()); - add(splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tagTree), splitPane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panA, panB)), BorderLayout.CENTER); + + + + loadingPanel.setPreferredSize(new Dimension(30, 30)); + statusPanel = new JPanel(); + statusPanel.setPreferredSize(new Dimension(1, 30)); + statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED)); + statusPanel.setLayout(new BorderLayout()); + statusPanel.add(loadingPanel, BorderLayout.WEST); + statusPanel.add(statusLabel, BorderLayout.CENTER); + loadingPanel.setVisible(false); + + + Container cont = getContentPane(); + cont.setLayout(new BorderLayout()); + cont.add(splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(tagTree), splitPane2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panA, panB)), BorderLayout.CENTER); + cont.add(statusPanel, BorderLayout.SOUTH); + editor.setContentType("text/flasm"); decompiledEditor.setContentType("text/actionscript"); setSize(640, 480); tagTree.addTreeSelectionListener(this); addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent e) { if (Main.proxyFrame != null) { - if (Main.proxyFrame.isVisible()) return; + if (Main.proxyFrame.isVisible()) { + return; + } } Main.exit(); } @@ -103,11 +126,11 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi miSaveAs.addActionListener(this); JMenuItem miExport = new JMenuItem("Export..."); miExport.setActionCommand("EXPORT"); - //miExport.addActionListener(this); + miExport.addActionListener(this); menuFile.add(miOpen); menuFile.add(miSave); menuFile.add(miSaveAs); - menuFile.add(miExport); + //menuFile.add(miExport); menuFile.addSeparator(); JMenuItem miClose = new JMenuItem("Exit"); miClose.setActionCommand("EXIT"); @@ -129,12 +152,22 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi } public void valueChanged(TreeSelectionEvent e) { + if (Main.isWorking()) return; Object obj = ((JTree) e.getSource()).getLastSelectedPathComponent(); if (obj instanceof TagTreeItem) { obj = ((TagTreeItem) obj).tag; if (obj instanceof ASMSource) { - editor.setText(((ASMSource) obj).getASMSource(10)); //TODO: Ensure correct version here - decompiledEditor.setText(Highlighting.stripHilights(com.jpexs.asdec.action.Action.actionsToSource(((ASMSource) obj).getActions(), 10))); //TODO:Ensure correct version here + Main.startWork("Decompiling..."); + final ASMSource asm = (ASMSource) obj; + (new Thread() { + + @Override + public void run() { + editor.setText(asm.getASMSource(10)); //TODO: Ensure correct version here + decompiledEditor.setText(Highlighting.stripHilights(com.jpexs.asdec.action.Action.actionsToSource(asm.getActions(), 10))); //TODO:Ensure correct version here + Main.stopWork(); + } + }).start(); } } } @@ -152,6 +185,7 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi if (e.getActionCommand().equals("SHOWPROXY")) { Main.showProxy(); } + if (Main.isWorking()) return; if (e.getActionCommand().equals("SAVEACTION")) { TagTreeItem ti = (TagTreeItem) tagTree.getLastSelectedPathComponent(); if (ti.tag instanceof ASMSource) { @@ -159,7 +193,6 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi try { dat.setActions(ASMParser.parse(new ByteArrayInputStream(editor.getText().getBytes()), 10)); //TODO:Ensure correct version here } catch (IOException ex) { - } catch (ParseException ex) { JOptionPane.showMessageDialog(this, "" + ex.text + " on line " + ex.line, "Error", JOptionPane.ERROR_MESSAGE); } @@ -169,7 +202,6 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi try { Main.saveFile(Main.file); } catch (IOException ex) { - } } if (e.getActionCommand().equals("SAVEAS")) { @@ -181,4 +213,13 @@ public class MainFrame extends JFrame implements TreeSelectionListener, ActionLi Main.openFileDialog(); } } + + public void setStatus(String s) { + if (s.equals("")) { + loadingPanel.setVisible(false); + } else { + loadingPanel.setVisible(true); + } + statusLabel.setText(s); + } }