From 742d58b3bae64f86da332a2f1edc8876712f5a3b Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Tue, 18 Nov 2014 00:11:43 +0100 Subject: [PATCH] caching images and other smallfixes --- .../decompiler/flash/gui/ImagePanel.java | 10 +- .../flash/gui/LoadFromMemoryFrame.java | 1 - .../jpexs/decompiler/flash/gui/MainPanel.java | 41 +-- .../decompiler/flash/gui/PreviewPanel.java | 137 +++++----- .../decompiler/flash/gui/abc/ABCPanel.java | 8 - .../flash/gui/player/PlayerControls.java | 63 +++-- .../flash/gui/proxy/ProxyFrame.java | 233 ++++++++---------- 7 files changed, 210 insertions(+), 283 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 66d6f083b..a64464a45 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -214,7 +214,8 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis if (e == null) { return; } - synchronized (iconPanel) { + boolean draw2 = false; + synchronized (ImagePanel.class) { lastMouseEvent = e; boolean handCursor = false; DepthState newStateUnderCursor = null; @@ -272,12 +273,13 @@ public final class ImagePanel extends JPanel implements ActionListener, MediaDis } if (newStateUnderCursor != stateUnderCursor) { stateUnderCursor = newStateUnderCursor; - if (draw) { - drawFrame(); - } + draw2 = true; } } } + if (draw2) { + drawFrame(); + } } private void showSelectedName() { diff --git a/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java b/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java index 584916067..6ced7c58f 100644 --- a/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java +++ b/src/com/jpexs/decompiler/flash/gui/LoadFromMemoryFrame.java @@ -46,7 +46,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index eb6466e71..b96cf1e9d 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -73,37 +73,14 @@ import com.jpexs.decompiler.flash.importers.ImageImporter; import com.jpexs.decompiler.flash.importers.ShapeImporter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; -import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag; -import com.jpexs.decompiler.flash.tags.DefineBitsJPEG3Tag; -import com.jpexs.decompiler.flash.tags.DefineBitsJPEG4Tag; -import com.jpexs.decompiler.flash.tags.DefineBitsLossless2Tag; -import com.jpexs.decompiler.flash.tags.DefineBitsLosslessTag; -import com.jpexs.decompiler.flash.tags.DefineBitsTag; -import com.jpexs.decompiler.flash.tags.DefineButton2Tag; -import com.jpexs.decompiler.flash.tags.DefineButtonTag; -import com.jpexs.decompiler.flash.tags.DefineEditTextTag; -import com.jpexs.decompiler.flash.tags.DefineFont2Tag; -import com.jpexs.decompiler.flash.tags.DefineFont3Tag; -import com.jpexs.decompiler.flash.tags.DefineFont4Tag; -import com.jpexs.decompiler.flash.tags.DefineFontTag; -import com.jpexs.decompiler.flash.tags.DefineMorphShape2Tag; -import com.jpexs.decompiler.flash.tags.DefineMorphShapeTag; -import com.jpexs.decompiler.flash.tags.DefineShape2Tag; -import com.jpexs.decompiler.flash.tags.DefineShape3Tag; -import com.jpexs.decompiler.flash.tags.DefineShape4Tag; -import com.jpexs.decompiler.flash.tags.DefineShapeTag; import com.jpexs.decompiler.flash.tags.DefineSoundTag; import com.jpexs.decompiler.flash.tags.DefineSpriteTag; -import com.jpexs.decompiler.flash.tags.DefineText2Tag; -import com.jpexs.decompiler.flash.tags.DefineTextTag; -import com.jpexs.decompiler.flash.tags.JPEGTablesTag; import com.jpexs.decompiler.flash.tags.SymbolClassTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.tags.base.BoundedTag; import com.jpexs.decompiler.flash.tags.base.ButtonTag; import com.jpexs.decompiler.flash.tags.base.CharacterTag; -import com.jpexs.decompiler.flash.tags.base.Container; import com.jpexs.decompiler.flash.tags.base.ContainerItem; import com.jpexs.decompiler.flash.tags.base.DrawableTag; import com.jpexs.decompiler.flash.tags.base.FontTag; @@ -594,12 +571,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec for (SWF swf : newSwfs) { - for (Tag t : swf.tags) { - if (t instanceof JPEGTablesTag) { - swf.jtt = (JPEGTablesTag) t; - } - } - if (Configuration.autoRenameIdentifiers.get()) { try { swf.deobfuscateIdentifiers(RenameType.TYPENUMBER); @@ -1075,21 +1046,21 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } } - public void gotoFrame(int frame){ + public void gotoFrame(int frame) { TreeItem treeItem = (TreeItem) tagTree.getLastSelectedPathComponent(); if (treeItem == null) { return; } - if(treeItem instanceof Timelined){ - Timelined t = (Timelined)treeItem; + if (treeItem instanceof Timelined) { + Timelined t = (Timelined) treeItem; Timeline tim = t.getTimeline(); - Frame f = ((TagTreeModel)tagTree.getModel()).getFrame(treeItem.getSwf(), t, frame); - if(f!=null){ + Frame f = ((TagTreeModel) tagTree.getModel()).getFrame(treeItem.getSwf(), t, frame); + if (f != null) { setTagTreeSelectedNode(f); } } } - + public void gotoDocumentClass(SWF swf) { if (swf == null) { return; diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index 6f3232e83..364bab7de 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -283,7 +283,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener { flashPlayPanel.add(bottomPanel, BorderLayout.SOUTH);*/ JPanel flashPlayPanel2 = new JPanel(new BorderLayout()); flashPlayPanel2.add(flashPlayPanel, BorderLayout.CENTER); - flashPlayPanel2.add(new PlayerControls(mainPanel,flashPanel), BorderLayout.SOUTH); + flashPlayPanel2.add(new PlayerControls(mainPanel, flashPanel), BorderLayout.SOUTH); leftComponent = flashPlayPanel2; } else { JPanel swtPanel = new JPanel(new BorderLayout()); @@ -303,7 +303,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener { JPanel previewCnt = new JPanel(new BorderLayout()); imagePanel = new ImagePanel(); previewCnt.add(imagePanel, BorderLayout.CENTER); - previewCnt.add(imagePlayControls = new PlayerControls(mainPanel,imagePanel), BorderLayout.SOUTH); + previewCnt.add(imagePlayControls = new PlayerControls(mainPanel, imagePanel), BorderLayout.SOUTH); imagePlayControls.setMedia(imagePanel); previewPanel.add(previewCnt, BorderLayout.CENTER); JLabel prevIntLabel = new HeaderLabel(mainPanel.translate("swfpreview.internal")); @@ -512,26 +512,25 @@ public class PreviewPanel extends JSplitPane implements ActionListener { if (tagObj instanceof DefineSoundTag) { frameCount = 1; } - - if(tagObj instanceof DefineSpriteTag){ - frameCount = ((DefineSpriteTag)tagObj).frameCount; + + if (tagObj instanceof DefineSpriteTag) { + frameCount = ((DefineSpriteTag) tagObj).frameCount; } byte[] data; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { SWFOutputStream sos2 = new SWFOutputStream(baos, SWF.DEFAULT_VERSION); RECT outrect = new RECT(swf.displayRect); - + if (tagObj instanceof FontTag) { - outrect.Xmin=0; - outrect.Ymin=0; - outrect.Xmax = FontTag.PREVIEWSIZE*20; - outrect.Ymax = FontTag.PREVIEWSIZE*20; + outrect.Xmin = 0; + outrect.Ymin = 0; + outrect.Xmax = FontTag.PREVIEWSIZE * 20; + outrect.Ymax = FontTag.PREVIEWSIZE * 20; } int width = outrect.getWidth(); int height = outrect.getHeight(); - - + sos2.writeRECT(outrect); sos2.writeUI8(0); sos2.writeUI8(frameRate); @@ -605,18 +604,17 @@ public class PreviewPanel extends JSplitPane implements ActionListener { new ShowFrameTag(swf).writeTag(sos2); } else { - boolean isSprite=false; - if(tagObj instanceof DefineSpriteTag){ + boolean isSprite = false; + if (tagObj instanceof DefineSpriteTag) { isSprite = true; } int chtId = 0; if (tagObj instanceof CharacterTag) { chtId = ((CharacterTag) tagObj).getCharacterId(); } - - + if (tagObj instanceof DefineBitsTag) { - JPEGTablesTag jtt = swf.jtt; + JPEGTablesTag jtt = swf.getJtt(); if (jtt != null) { jtt.writeTag(sos2); } @@ -625,7 +623,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener { Set needed = new HashSet<>(); ((Tag) tagObj).getNeededCharactersDeep(needed); for (int n : needed) { - if(isSprite && chtId == n){ + if (isSprite && chtId == n) { continue; } classicTag(swf.characters.get(n)).writeTag(sos2); @@ -634,8 +632,6 @@ public class PreviewPanel extends JSplitPane implements ActionListener { classicTag((Tag) tagObj).writeTag(sos2); - - MATRIX mat = new MATRIX(); mat.hasRotate = false; mat.hasScale = false; @@ -653,8 +649,8 @@ public class PreviewPanel extends JSplitPane implements ActionListener { } if (tagObj instanceof FontTag) { - FontTag ft=(FontTag)classicTag((Tag)tagObj); - + FontTag ft = (FontTag) classicTag((Tag) tagObj); + int countGlyphsTotal = ft.getGlyphShapeTable().size(); int countGlyphs = Math.min(SHAPERECORD.MAX_CHARACTERS_IN_FONT_PREVIEW, countGlyphsTotal); int fontId = ft.getFontId(); @@ -664,34 +660,34 @@ public class PreviewPanel extends JSplitPane implements ActionListener { int y = 0; int firstGlyphIndex = fontPageNum * SHAPERECORD.MAX_CHARACTERS_IN_FONT_PREVIEW; countGlyphs = Math.min(SHAPERECORD.MAX_CHARACTERS_IN_FONT_PREVIEW, countGlyphsTotal - firstGlyphIndex); - List shapes=ft.getGlyphShapeTable(); + List shapes = ft.getGlyphShapeTable(); int maxw = 0; - for (int f = firstGlyphIndex; f < firstGlyphIndex + countGlyphs; f++) { + for (int f = firstGlyphIndex; f < firstGlyphIndex + countGlyphs; f++) { RECT b = shapes.get(f).getBounds(); - if(b.Xmin == Integer.MAX_VALUE){ + if (b.Xmin == Integer.MAX_VALUE) { continue; } - if(b.Ymin == Integer.MAX_VALUE){ + if (b.Ymin == Integer.MAX_VALUE) { continue; } - int w=(int)(b.getWidth()/ft.getDivider()); - if(w>maxw){ + int w = (int) (b.getWidth() / ft.getDivider()); + if (w > maxw) { maxw = w; - } + } x++; } - + x = 0; - - int BORDER = 3*20; - - int textHeight = height / rows; - - while(maxw*textHeight/1024.0 > width/cols-2*BORDER){ + + int BORDER = 3 * 20; + + int textHeight = height / rows; + + while (maxw * textHeight / 1024.0 > width / cols - 2 * BORDER) { textHeight--; } - - MATRIX tmat=new MATRIX(); + + MATRIX tmat = new MATRIX(); for (int f = firstGlyphIndex; f < firstGlyphIndex + countGlyphs; f++) { if (x >= cols) { x = 0; @@ -699,41 +695,39 @@ public class PreviewPanel extends JSplitPane implements ActionListener { } List rec = new ArrayList<>(); TEXTRECORD tr = new TEXTRECORD(); - + RECT b = shapes.get(f).getBounds(); - int xmin = b.Xmin == Integer.MAX_VALUE?0:(int)(b.Xmin/ft.getDivider()); - xmin *= textHeight/1024.0; - int ymin = b.Ymin == Integer.MAX_VALUE?0:(int)(b.Ymin/ft.getDivider()); - ymin *= textHeight/1024.0; - int w=(int)(b.getWidth()/ft.getDivider()); - w *= textHeight/1024.0; - int h=(int)(b.getHeight()/ft.getDivider()); - h *= textHeight/1024.0; - + int xmin = b.Xmin == Integer.MAX_VALUE ? 0 : (int) (b.Xmin / ft.getDivider()); + xmin *= textHeight / 1024.0; + int ymin = b.Ymin == Integer.MAX_VALUE ? 0 : (int) (b.Ymin / ft.getDivider()); + ymin *= textHeight / 1024.0; + int w = (int) (b.getWidth() / ft.getDivider()); + w *= textHeight / 1024.0; + int h = (int) (b.getHeight() / ft.getDivider()); + h *= textHeight / 1024.0; + tr.fontId = fontId; tr.styleFlagsHasFont = true; tr.textHeight = textHeight; - tr.xOffset=-xmin; - tr.yOffset=0; - tr.styleFlagsHasXOffset=true; - tr.styleFlagsHasYOffset=true; + tr.xOffset = -xmin; + tr.yOffset = 0; + tr.styleFlagsHasXOffset = true; + tr.styleFlagsHasYOffset = true; tr.glyphEntries = new GLYPHENTRY[1]; tr.styleFlagsHasColor = true; tr.textColor = new RGB(0, 0, 0); tr.glyphEntries[0] = new GLYPHENTRY(); - - - - double ga=ft.getGlyphAdvance(f); - int cw=ga==-1?w:(int)(ga/ft.getDivider()*textHeight/1024.0); - + + double ga = ft.getGlyphAdvance(f); + int cw = ga == -1 ? w : (int) (ga / ft.getDivider() * textHeight / 1024.0); + tr.glyphEntries[0].glyphAdvance = 0; tr.glyphEntries[0].glyphIndex = f; - rec.add(tr); - - tmat.translateX = x * width/ cols + width/ cols/2-w/2; + rec.add(tr); + + tmat.translateX = x * width / cols + width / cols / 2 - w / 2; tmat.translateY = y * height / rows + height / rows / 2; - new DefineTextTag(swf, 999 + f, new RECT(0, cw, ymin, ymin+h), new MATRIX(), rec).writeTag(sos2); + new DefineTextTag(swf, 999 + f, new RECT(0, cw, ymin, ymin + h), new MATRIX(), rec).writeTag(sos2); new PlaceObject2Tag(swf, false, false, false, true, false, true, true, false, 1 + f, 999 + f, tmat, null, 0, null, 0, null).writeTag(sos2); x++; } @@ -882,25 +876,24 @@ public class PreviewPanel extends JSplitPane implements ActionListener { new ShowFrameTag(swf).writeTag(sos2); first = false; } - } else if(tagObj instanceof DefineSpriteTag){ - DefineSpriteTag s=(DefineSpriteTag)tagObj; + } else if (tagObj instanceof DefineSpriteTag) { + DefineSpriteTag s = (DefineSpriteTag) tagObj; Tag lastTag = null; - for(Tag t:s.subTags){ - if(t instanceof EndTag){ + for (Tag t : s.subTags) { + if (t instanceof EndTag) { break; - } else if(t instanceof PlaceObjectTypeTag){ - PlaceObjectTypeTag pt=(PlaceObjectTypeTag)t; + } else if (t instanceof PlaceObjectTypeTag) { + PlaceObjectTypeTag pt = (PlaceObjectTypeTag) t; MATRIX m = pt.getMatrix(); MATRIX m2 = new Matrix(m).preConcatenate(new Matrix(mat)).toMATRIX(); pt.writeTagWithMatrix(sos2, m2); lastTag = t; - } - else{ + } else { t.writeTag(sos2); lastTag = t; } } - if(!s.subTags.isEmpty() && (lastTag!=null)&&(!(lastTag instanceof ShowFrameTag))){ + if (!s.subTags.isEmpty() && (lastTag != null) && (!(lastTag instanceof ShowFrameTag))) { new ShowFrameTag(swf).writeTag(sos2); } } else { @@ -923,7 +916,7 @@ public class PreviewPanel extends JSplitPane implements ActionListener { fos.flush(); } if (flashPanel != null) { - flashPanel.displaySWF(tempFile.getAbsolutePath(), backgroundColor, frameRate); + flashPanel.displaySWF(tempFile.getAbsolutePath(), backgroundColor, frameRate); } showFlashViewerPanel(); } catch (IOException | ActionParseException ex) { diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index f6ddac4a0..675af4320 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -65,7 +65,6 @@ import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import java.awt.BorderLayout; -import java.awt.Component; import java.awt.Cursor; import java.awt.FlowLayout; import java.awt.Font; @@ -105,12 +104,7 @@ import javax.swing.JToggleButton; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.border.BevelBorder; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableModel; import javax.swing.text.Highlighter; import javax.swing.tree.TreePath; import jsyntaxpane.DefaultSyntaxKit; @@ -224,8 +218,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se return false; } - - public void setAbc(ABC abc) { this.abc = abc; updateConstList(); diff --git a/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java b/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java index 12c541e0e..db2cd8d67 100644 --- a/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java +++ b/src/com/jpexs/decompiler/flash/gui/player/PlayerControls.java @@ -93,20 +93,21 @@ public class PlayerControls extends JPanel implements ActionListener { public static final int ZOOM_DECADE_STEPS = 10; public static final double ZOOM_MULTIPLIER = Math.pow(10, 1.0 / ZOOM_DECADE_STEPS); - private static String underline(String s){ - return ""+s+""; + private static String underline(String s) { + return "" + s + ""; } - private static Font underlinedFont=null; - private static Font notUnderlinedFont=null; - static{ + private static Font underlinedFont = null; + private static Font notUnderlinedFont = null; + + static { notUnderlinedFont = new JLabel().getFont(); - Map fontAttributes = new HashMap(); + Map fontAttributes = new HashMap<>(); fontAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); - underlinedFont= notUnderlinedFont.deriveFont(fontAttributes); + underlinedFont = notUnderlinedFont.deriveFont(fontAttributes); } - - public PlayerControls(final MainPanel mainPanel,MediaDisplay display) { + + public PlayerControls(final MainPanel mainPanel, MediaDisplay display) { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); @@ -160,22 +161,22 @@ public class PlayerControls extends JPanel implements ActionListener { playbackControls = new JPanel(); this.display = display; JPanel controlPanel = new JPanel(new BorderLayout()); - frameLabel = new JLabel("0",SwingConstants.RIGHT); + frameLabel = new JLabel("0", SwingConstants.RIGHT); frameLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); frameLabel.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { - + } - + }); - - Dimension min=new Dimension(frameLabel.getFontMetrics(notUnderlinedFont).stringWidth("000"),frameLabel.getPreferredSize().height); + + Dimension min = new Dimension(frameLabel.getFontMetrics(notUnderlinedFont).stringWidth("000"), frameLabel.getPreferredSize().height); frameLabel.setMinimumSize(min); frameLabel.setPreferredSize(min); - - frameLabel.addMouseListener(new MouseAdapter() { + + frameLabel.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { @@ -186,31 +187,27 @@ public class PlayerControls extends JPanel implements ActionListener { public void mouseExited(MouseEvent e) { frameLabel.setFont(notUnderlinedFont); } - - - - - + @Override public void mouseClicked(MouseEvent e) { int gotoFrame = PlayerControls.this.display.getCurrentFrame(); - if(gotoFrame>0){ + if (gotoFrame > 0) { mainPanel.gotoFrame(gotoFrame); } } - + }); - timeLabel = new JLabel("(00:00.00)"); + timeLabel = new JLabel("(00:00.00)"); totalTimeLabel = new JLabel("(00:00.00)"); totalFrameLabel = new JLabel("0"); - - JPanel currentPanel=new JPanel(new FlowLayout()); + + JPanel currentPanel = new JPanel(new FlowLayout()); currentPanel.add(frameLabel); currentPanel.add(timeLabel); - JPanel totalPanel=new JPanel(new FlowLayout()); + JPanel totalPanel = new JPanel(new FlowLayout()); totalPanel.add(totalFrameLabel); totalPanel.add(totalTimeLabel); - + controlPanel.add(currentPanel, BorderLayout.WEST); controlPanel.add(totalPanel, BorderLayout.EAST); playbackControls.setLayout(new BoxLayout(playbackControls, BoxLayout.Y_AXIS)); @@ -302,11 +299,11 @@ public class PlayerControls extends JPanel implements ActionListener { progress.setValue(currentFrame); progress.setIndeterminate(false); } - frameLabel.setText((""+(currentFrame+1))); - totalFrameLabel.setText(""+totalFrames); - if (frameRate != 0) { - timeLabel.setText("("+formatMs((currentFrame * 1000) / frameRate)+")"); - totalTimeLabel.setText("("+formatMs(((totalFrames - 1) * 1000) / frameRate)+")"); + frameLabel.setText(("" + (currentFrame + 1))); + totalFrameLabel.setText("" + totalFrames); + if (frameRate != 0) { + timeLabel.setText("(" + formatMs((currentFrame * 1000) / frameRate) + ")"); + totalTimeLabel.setText("(" + formatMs(((totalFrames - 1) * 1000) / frameRate) + ")"); } if (totalFrames <= 1 && playbackControls.isVisible()) { playbackControls.setVisible(false); diff --git a/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java b/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java index 77a23a416..451388b75 100644 --- a/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java +++ b/src/com/jpexs/decompiler/flash/gui/proxy/ProxyFrame.java @@ -24,11 +24,9 @@ import com.jpexs.decompiler.flash.gui.AppStrings; import com.jpexs.decompiler.flash.gui.GuiAbortRetryIgnoreHandler; import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.MainFrame; -import com.jpexs.decompiler.flash.gui.SaveFileMode; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin; import com.jpexs.helpers.Helper; -import com.jpexs.helpers.Path; import com.jpexs.proxy.CatchedListener; import com.jpexs.proxy.ReplacedListener; import com.jpexs.proxy.Replacement; @@ -48,48 +46,35 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.io.OutputStream; import java.nio.file.Files; import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; -import java.util.Comparator; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.BoxLayout; -import javax.swing.DefaultRowSorter; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; -import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.JTextField; -import javax.swing.ListModel; -import javax.swing.RowSorter; import javax.swing.SwingConstants; -import javax.swing.event.TableModelListener; import javax.swing.filechooser.FileFilter; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableColumnModel; import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import javax.swing.table.TableModel; -import javax.swing.table.TableRowSorter; -import org.pushingpixels.substance.api.renderers.SubstanceDefaultTableCellRenderer; /** * Frame with Proxy @@ -107,8 +92,7 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe static final String ACTION_SAVEAS = "SAVEAS"; static final String ACTION_REPLACE = "REPLACE"; - - private JTable replacementsTable; + private JTable replacementsTable; private JButton switchButton = new JButton(translate("proxy.start")); private boolean started = false; private JTextField portField = new JTextField("55555"); @@ -134,60 +118,60 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe public void setPort(int port) { portField.setText(Integer.toString(port)); } - - - - private static class SizeItem implements Comparable{ + + private static class SizeItem implements Comparable { + String file; - public SizeItem(String file){ + + public SizeItem(String file) { this.file = file; } @Override public String toString() { return Helper.byteCountStr(new File(file).length(), false); - } + } @Override - public int compareTo(SizeItem o) { - return (int)(new File(file).length() - new File(o.file).length()); + public int compareTo(SizeItem o) { + return (int) (new File(file).length() - new File(o.file).length()); } - + } - + DefaultTableModel tableModel; - private SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); + private SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); List reps; + /** * Constructor * * @param mainFrame */ public ProxyFrame(final MainFrame mainFrame) { - - - final String[] columnNames=new String[]{ + + final String[] columnNames = new String[]{ translate("column.accessed"), translate("column.size"), - translate("column.url")}; - + translate("column.url")}; + reps = Configuration.getReplacements(); - + Object data[][] = new Object[reps.size()][3]; - - for(int i=0;i getColumnClass(int columnIndex) { - Class classes[] = new Class[]{String.class,SizeItem.class,String.class}; + Class classes[] = new Class[]{String.class, SizeItem.class, String.class}; return classes[columnIndex]; } @@ -195,38 +179,29 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe public boolean isCellEditable(int row, int column) { return false; } - - - - }; + + }; replacementsTable = new JTable(tableModel); - - DefaultTableCellRenderer tcr=new DefaultTableCellRenderer(); + + DefaultTableCellRenderer tcr = new DefaultTableCellRenderer(); tcr.setHorizontalAlignment(SwingConstants.RIGHT); - - + replacementsTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer()); - replacementsTable.setDefaultRenderer(SizeItem.class, tcr); - - - replacementsTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); - + replacementsTable.setDefaultRenderer(SizeItem.class, tcr); + + replacementsTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + replacementsTable.setRowSelectionAllowed(true); - - + DefaultTableColumnModel colModel = (DefaultTableColumnModel) replacementsTable.getColumnModel(); colModel.getColumn(0).setMaxWidth(100); - + colModel.getColumn(1).setMaxWidth(200); - - - + replacementsTable.setAutoCreateRowSorter(true); - - + replacementsTable.setAutoCreateRowSorter(false); - - + replacementsTable.addMouseListener(this); replacementsTable.setFont(new Font("Monospaced", Font.PLAIN, 12)); switchButton.addActionListener(this); @@ -265,7 +240,6 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe buttonsPanel21.add(removeButton); //JPanel buttonsPanel22 = new JPanel(new FlowLayout()); - JButton copyUrlButton = new JButton(translate("copy.url")); copyUrlButton.setActionCommand(ACTION_COPYURL); copyUrlButton.addActionListener(this); @@ -326,13 +300,12 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe } private void open() { - if (replacementsTable.getSelectedRow()>-1){ + if (replacementsTable.getSelectedRow() > -1) { Replacement r = reps.get(replacementsTable.getRowSorter().convertRowIndexToModel(replacementsTable.getSelectedRow())); Main.openFile(r.targetFile, r.urlPattern); } } - private String selectExportDir() { JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new File(Configuration.lastExportDir.get())); @@ -346,7 +319,7 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe } return null; } - + /** * Method handling actions from buttons * @@ -354,28 +327,28 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe */ @Override public void actionPerformed(ActionEvent e) { - int sel[] = replacementsTable.getSelectedRows(); - for(int i=0;i0) { + case ACTION_REPLACE: + if (sel.length > 0) { Replacement r = reps.get(sel[0]); JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File(Configuration.lastOpenDir.get())); - String n=r.urlPattern; - if(n.contains("?")){ - n = n.substring(0,n.indexOf("?")); + String n = r.urlPattern; + if (n.contains("?")) { + n = n.substring(0, n.indexOf('?')); + } + if (n.contains("/")) { + n = n.substring(n.lastIndexOf('/')); } - if(n.contains("/")){ - n=n.substring(n.lastIndexOf("/")); - } String ext = ".swf"; final String extension = ext; FileFilter swfFilter = new FileFilter() { @@ -466,48 +439,48 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe } }; fc.setFileFilter(swfFilter); - fc.setAcceptAllFileFilterUsed(true); + fc.setAcceptAllFileFilterUsed(true); JFrame f = new JFrame(); View.setWindowIcon(f); if (fc.showOpenDialog(f) == JFileChooser.APPROVE_OPTION) { File file = Helper.fixDialogFile(fc.getSelectedFile()); try { - Files.copy(file.toPath(),new File(r.targetFile).toPath(), REPLACE_EXISTING); + Files.copy(file.toPath(), new File(r.targetFile).toPath(), REPLACE_EXISTING); tableModel.fireTableCellUpdated(sel[0], 1/*size*/); } catch (IOException ex) { - View.showMessageDialog(f, translate("error.replace")+"\r\n"+ex.getLocalizedMessage(), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); + View.showMessageDialog(f, translate("error.replace") + "\r\n" + ex.getLocalizedMessage(), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); } } } break; - case ACTION_COPYURL: - String copyText=""; - for (int sc:sel) { + case ACTION_COPYURL: + String copyText = ""; + for (int sc : sel) { Replacement r = reps.get(sc); - if(!copyText.isEmpty()){ - copyText += System.lineSeparator(); - } + if (!copyText.isEmpty()) { + copyText += System.lineSeparator(); + } copyText += r.urlPattern; } - - if(!copyText.isEmpty()){ + + if (!copyText.isEmpty()) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection stringSelection = new StringSelection(copyText); clipboard.setContents(stringSelection, null); } break; case ACTION_RENAME: - if (sel.length>0) { + if (sel.length > 0) { Replacement r = reps.get(sel[0]); String s = View.showInputDialog("URL", r.urlPattern); if (s != null) { r.urlPattern = s; - tableModel.setValueAt(s, sel[0], 2/*url*/); + tableModel.setValueAt(s, sel[0], 2/*url*/); } } break; case ACTION_CLEAR: - for (Replacement r:reps) { + for (Replacement r : reps) { File f; try { f = (new File(Main.tempFile(r.targetFile))); @@ -518,21 +491,21 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe Logger.getLogger(ProxyFrame.class.getName()).log(Level.SEVERE, null, ex); } } - tableModel = new DefaultTableModel(0,3); + tableModel = new DefaultTableModel(0, 3); replacementsTable.setModel(tableModel); reps.clear(); break; case ACTION_REMOVE: - + Arrays.sort(sel); - for(int i=sel.length-1;i>=0;i--){ + for (int i = sel.length - 1; i >= 0; i--) { tableModel.removeRow(sel[i]); Replacement r = reps.remove(sel[i]); File f = (new File(r.targetFile)); if (f.exists()) { f.delete(); - } - } + } + } break; case ACTION_SWITCH_STATE: Main.switchProxy(); @@ -565,8 +538,8 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe catchedContentTypes.add("text/xml"); catchedContentTypes.add("application/xml"); catchedContentTypes.add("application/octet-stream"); - if(!Server.startServer(port, Configuration.getReplacements(), catchedContentTypes, this, this)){ - JOptionPane.showMessageDialog(this, translate("error.start.server"),AppStrings.translate("error"),JOptionPane.ERROR_MESSAGE); + if (!Server.startServer(port, Configuration.getReplacements(), catchedContentTypes, this, this)) { + JOptionPane.showMessageDialog(this, translate("error.start.server"), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); started = false; return; } @@ -659,8 +632,8 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe byte[] result = null; boolean cont = false; - for(Replacement r:reps){ - if(r.matches(url)){ + for (Replacement r : reps) { + if (r.matches(url)) { cont = true; break; } @@ -687,7 +660,7 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe r.lastAccess = Calendar.getInstance(); reps.add(r); tableModel.addRow(new Object[]{ - r.lastAccess == null?"":format.format(r.lastAccess.getTime()), + r.lastAccess == null ? "" : format.format(r.lastAccess.getTime()), new SizeItem(r.targetFile), r.urlPattern }); @@ -726,7 +699,7 @@ public class ProxyFrame extends AppFrame implements ActionListener, CatchedListe @Override public void replaced(Replacement replacement, String url, String contentType) { int index = reps.indexOf(replacement); - tableModel.setValueAt(replacement.lastAccess == null?"":format.format(replacement.lastAccess.getTime()), index, 0); + tableModel.setValueAt(replacement.lastAccess == null ? "" : format.format(replacement.lastAccess.getTime()), index, 0); tableModel.setValueAt(new SizeItem(replacement.targetFile), index, 1); tableModel.setValueAt(replacement.urlPattern, index, 2); }