From 3ec510b009f57386ac7a47493b530171ac0d167f Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Wed, 6 May 2015 20:11:02 +0200 Subject: [PATCH] #470: glitch fixed --- .../flash/configuration/Configuration.java | 24 +++---- .../decompiler/flash/gui/ImagePanel.java | 72 +++++++++---------- .../gui/controls/JPersistentSplitPane.java | 59 ++++++++++----- 3 files changed, 86 insertions(+), 69 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 236788a9d..340a2a790 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -251,29 +251,29 @@ public class Configuration { @ConfigurationName("gui.window.maximized.vertical") public static final ConfigurationItem guiWindowMaximizedVertical = null; - @ConfigurationDefaultInt(50) + @ConfigurationDefaultDouble(0.5) @ConfigurationName("gui.avm2.splitPane.dividerLocationPercent") - public static final ConfigurationItem guiAvm2SplitPaneDividerLocationPercent = null; + public static final ConfigurationItem guiAvm2SplitPaneDividerLocationPercent = null; - @ConfigurationDefaultInt(50) + @ConfigurationDefaultDouble(0.5) @ConfigurationName("gui.actionSplitPane.dividerLocationPercent") - public static final ConfigurationItem guiActionSplitPaneDividerLocationPercent = null; + public static final ConfigurationItem guiActionSplitPaneDividerLocationPercent = null; - @ConfigurationDefaultInt(50) + @ConfigurationDefaultDouble(0.5) @ConfigurationName("gui.previewSplitPane.dividerLocationPercent") - public static final ConfigurationItem guiPreviewSplitPaneDividerLocationPercent = null; + public static final ConfigurationItem guiPreviewSplitPaneDividerLocationPercent = null; - @ConfigurationDefaultInt(33) + @ConfigurationDefaultDouble(0.3333333333) @ConfigurationName("gui.splitPane1.dividerLocationPercent") - public static final ConfigurationItem guiSplitPane1DividerLocationPercent = null; + public static final ConfigurationItem guiSplitPane1DividerLocationPercent = null; - @ConfigurationDefaultInt(60) + @ConfigurationDefaultDouble(0.6) @ConfigurationName("gui.splitPane2.dividerLocationPercent") - public static final ConfigurationItem guiSplitPane2DividerLocationPercent = null; + public static final ConfigurationItem guiSplitPane2DividerLocationPercent = null; - @ConfigurationDefaultInt(50) + @ConfigurationDefaultDouble(0.5) @ConfigurationName("gui.timeLineSplitPane.dividerLocationPercent") - public static final ConfigurationItem guiTimeLineSplitPaneDividerLocationPercent = null; + public static final ConfigurationItem guiTimeLineSplitPaneDividerLocationPercent = null; @ConfigurationDefaultString("com.jpexs.decompiler.flash.gui.OceanicSkin") @ConfigurationName("gui.skin") diff --git a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java index 14ecce9ca..5e8b40a0f 100644 --- a/src/com/jpexs/decompiler/flash/gui/ImagePanel.java +++ b/src/com/jpexs/decompiler/flash/gui/ImagePanel.java @@ -84,8 +84,6 @@ public final class ImagePanel extends JPanel implements MediaDisplay { private boolean zoomAvailable = false; - private int counter = 0; - private SWF swf; private boolean loaded; @@ -122,6 +120,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { if (depth != selectedDepth) { this.selectedDepth = depth; } + hideMouseSelection(); } @@ -262,7 +261,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { iconPanel.removeMouseMotionListener(l); } - private void updatePos(Timelined timelined, MouseEvent lastMouseEvent, int counter) { + private void updatePos(Timelined timelined, MouseEvent lastMouseEvent, Timer thisTimer) { boolean handCursor = false; DepthState newStateUnderCursor = null; if (timelined != null) { @@ -284,7 +283,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { String ret = ""; synchronized (ImagePanel.class) { - if (counter == this.counter) { + if (timer == thisTimer) { p = p == null ? null : iconPanel.toImagePoint(p); if (p != null) { int x = p.x; @@ -318,7 +317,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } synchronized (ImagePanel.class) { - if (counter == this.counter) { + if (timer == thisTimer) { debugLabel.setText(ret); if (handCursor) { @@ -395,7 +394,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { ButtonTag b = (ButtonTag) swf.getCharacter(stateUnderCursor.characterId); DefineButtonSoundTag sounds = b.getSounds(); if (sounds != null && sounds.buttonSoundChar2 != 0) { //OverUpToOverDown - playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar2), counter); + playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar2), timer); } } } @@ -411,7 +410,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { ButtonTag b = (ButtonTag) swf.getCharacter(stateUnderCursor.characterId); DefineButtonSoundTag sounds = b.getSounds(); if (sounds != null && sounds.buttonSoundChar3 != 0) { //OverDownToOverUp - playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar3), counter); + playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar3), timer); } } } @@ -431,7 +430,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { ButtonTag b = (ButtonTag) swf.getCharacter(stateUnderCursor.characterId); DefineButtonSoundTag sounds = b.getSounds(); if (sounds != null && sounds.buttonSoundChar1 != 0) { //IddleToOverUp - playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar1), counter); + playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar1), timer); } } } @@ -441,7 +440,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { ButtonTag b = (ButtonTag) swf.getCharacter(lastUnderCur.characterId); DefineButtonSoundTag sounds = b.getSounds(); if (sounds != null && sounds.buttonSoundChar0 != 0) { //OverUpToIddle - playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar0), counter); + playSound((SoundTag) swf.getCharacter(sounds.buttonSoundChar0), timer); } } } @@ -460,12 +459,8 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } private synchronized void redraw() { - if (!isPlaying()) { - counter++; - } - if (timer == null && timelined != null) { - startTimer(counter, timelined.getTimeline(), false); + startTimer(timelined.getTimeline(), false); } } @@ -540,7 +535,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { this.timelined = drawable; this.swf = swf; zoomAvailable = true; - counter++; + timer = null; if (frame > -1) { this.frame = frame; this.stillFrame = true; @@ -683,10 +678,10 @@ public final class ImagePanel extends JPanel implements MediaDisplay { newTextTag = null; } - private void nextFrame(int counter) { - drawFrame(counter); + private void nextFrame(Timer thisTimer) { + drawFrame(thisTimer); synchronized (ImagePanel.class) { - if (timelined != null && counter == this.counter) { + if (timelined != null && timer == thisTimer) { int frameCount = timelined.getTimeline().getFrameCount(); if (!stillFrame && frame == frameCount - 1 && !loop) { @@ -792,7 +787,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { return img; } - private void drawFrame(int counter) { + private void drawFrame(Timer thisTimer) { Timelined timelined; MouseEvent lastMouseEvent; int frame; @@ -830,8 +825,8 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } double zoomDouble = zoom.fit ? getZoomToFit() : zoom.value; - getOutlines(timelined, frame, time, zoomDouble, stateUnderCursor, mouseButton, counter); - updatePos(timelined, lastMouseEvent, counter); + getOutlines(timelined, frame, time, zoomDouble, stateUnderCursor, mouseButton, thisTimer); + updatePos(timelined, lastMouseEvent, thisTimer); Matrix mat = new Matrix(); mat.translateX = swf.displayRect.Xmin; @@ -855,7 +850,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { CharacterTag c = swf.getCharacter(sndId); if (c instanceof SoundTag) { SoundTag st = (SoundTag) c; - playSound(st, counter); + playSound(st, thisTimer); } } } catch (Throwable ex) { @@ -864,7 +859,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } synchronized (ImagePanel.class) { - if (counter == this.counter) { + if (timer == thisTimer) { iconPanel.setImg(img); drawReady = true; synchronized (delayObject) { @@ -874,7 +869,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } } - private void playSound(SoundTag st, int counter) { + private void playSound(SoundTag st, Timer thisTimer) { final SoundTagPlayer sp; try { sp = new SoundTagPlayer(st, 1, false); @@ -893,7 +888,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { }); synchronized (ImagePanel.class) { - if (timer != null && counter == this.counter) { + if (timer != null && timer == thisTimer) { soundPlayers.add(sp); sp.play(); } @@ -903,7 +898,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } } - private List getOutlines(Timelined timelined, int frame, int time, double zoom, DepthState stateUnderCursor, int mouseButton, int counter) { + private List getOutlines(Timelined timelined, int frame, int time, double zoom, DepthState stateUnderCursor, int mouseButton, Timer thisTimer) { List objs = new ArrayList<>(); List outlines = new ArrayList<>(); Matrix m = new Matrix(); @@ -918,7 +913,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } synchronized (ImagePanel.class) { - if (counter == this.counter) { + if (timer == thisTimer) { iconPanel.setOutlines(objs, outlines); } } @@ -949,18 +944,19 @@ public final class ImagePanel extends JPanel implements MediaDisplay { frame = 0; } - startTimer(counter, timeline, true); + startTimer(timeline, true); } } - private void startTimer(int cnt, Timeline timeline, boolean playing) { + private void startTimer(Timeline timeline, boolean playing) { int frameRate = timeline.frameRate; int msPerFrame = frameRate == 0 ? 1000 : 1000 / frameRate; final boolean singleFrame = !playing || (timeline.getRealFrameCount() <= 1 && timeline.isSingleFrame()); + timer = new Timer(); TimerTask task = new TimerTask() { - public final int taskCounter = cnt; + public final Timer thisTimer = timer; public final boolean isSingleFrame = singleFrame; @@ -968,22 +964,23 @@ public final class ImagePanel extends JPanel implements MediaDisplay { public void run() { try { synchronized (ImagePanel.class) { - if (timer == null || taskCounter != counter) { + if (timer != thisTimer) { return; } } if (isSingleFrame) { - drawFrame(taskCounter); + drawFrame(thisTimer); synchronized (ImagePanel.class) { - if (taskCounter == counter) { + thisTimer.cancel(); + if (timer == thisTimer) { timer = null; } } fireMediaDisplayStateChanged(); } else { - nextFrame(taskCounter); + nextFrame(thisTimer); } } catch (Exception ex) { Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex); @@ -991,7 +988,6 @@ public final class ImagePanel extends JPanel implements MediaDisplay { } }; - timer = new Timer(); if (singleFrame) { timer.schedule(task, 0); } else { @@ -1007,11 +1003,7 @@ public final class ImagePanel extends JPanel implements MediaDisplay { @Override public synchronized boolean isPlaying() { - if (timelined == null) { - return false; - } - - if (stillFrame) { + if (timelined == null || stillFrame) { return false; } diff --git a/src/com/jpexs/decompiler/flash/gui/controls/JPersistentSplitPane.java b/src/com/jpexs/decompiler/flash/gui/controls/JPersistentSplitPane.java index a7bc0d0e5..67e4b1b4e 100644 --- a/src/com/jpexs/decompiler/flash/gui/controls/JPersistentSplitPane.java +++ b/src/com/jpexs/decompiler/flash/gui/controls/JPersistentSplitPane.java @@ -18,12 +18,14 @@ package com.jpexs.decompiler.flash.gui.controls; import com.jpexs.decompiler.flash.configuration.ConfigurationItem; import java.awt.Component; +import java.awt.Graphics; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; import java.beans.PropertyChangeEvent; +import java.util.Date; import javax.swing.JSplitPane; /** @@ -32,13 +34,15 @@ import javax.swing.JSplitPane; */ public class JPersistentSplitPane extends JSplitPane { - private ConfigurationItem config; + private ConfigurationItem config; - private boolean resize = false; + private boolean painted = false; + + private Date resize = new Date(); private ComponentListener childComponentListener; - public JPersistentSplitPane(int newOrientation, ConfigurationItem config) { + public JPersistentSplitPane(int newOrientation, ConfigurationItem config) { super(newOrientation); initialize(config); } @@ -46,27 +50,28 @@ public class JPersistentSplitPane extends JSplitPane { public JPersistentSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent, - ConfigurationItem config) { + ConfigurationItem config) { super(newOrientation, newLeftComponent, newRightComponent); initialize(config); newLeftComponent.addComponentListener(childComponentListener); newRightComponent.addComponentListener(childComponentListener); } - private double getConfigValue(ConfigurationItem config) { - int pos = config.get(); + private double getConfigValue(ConfigurationItem config) { + double pos = config.get(); if (pos < 0) { pos = 0; - } else if (pos > 100) { - pos = 100; + } else if (pos > 1) { + pos = 1; } - return pos / 100.0; + return pos; } - private void initialize(ConfigurationItem config) { + private void initialize(ConfigurationItem config) { this.config = config; double pos = getConfigValue(config); + //System.out.println("init " + config.getName() + ": " + pos); setDividerLocation(pos); setResizeWeight(pos); @@ -74,15 +79,19 @@ public class JPersistentSplitPane extends JSplitPane { @Override public void componentResized(ComponentEvent e) { - resize = true; + resize = new Date(); double pos = getConfigValue(config); + //System.out.println("resized " + config.getName() + ": " + pos); setDividerLocation(pos); + setResizeWeight(pos); } @Override public void componentShown(ComponentEvent e) { double pos = getConfigValue(config); + //System.out.println("shown " + config.getName() + ": " + pos); setDividerLocation(pos); + setResizeWeight(pos); } }); @@ -91,7 +100,9 @@ public class JPersistentSplitPane extends JSplitPane { @Override public void componentShown(ComponentEvent e) { double pos = getConfigValue(config); + //System.out.println("childShown " + config.getName() + ": " + pos); setDividerLocation(pos); + setResizeWeight(pos); } }; @@ -99,30 +110,44 @@ public class JPersistentSplitPane extends JSplitPane { @Override public void componentAdded(ContainerEvent e) { - e.getComponent().addComponentListener(childComponentListener); + e.getChild().addComponentListener(childComponentListener); } @Override public void componentRemoved(ContainerEvent e) { - e.getComponent().removeComponentListener(childComponentListener); + e.getChild().removeComponentListener(childComponentListener); } }); addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, (PropertyChangeEvent pce) -> { - if (resize) { - resize = false; + if (!painted) { + return; + } + + // hack + long diff = new Date().getTime() - resize.getTime(); + if (diff >= 0 && diff < 100) { + resize = new Date(0); return; } if (getLeftComponent().isVisible() && getRightComponent().isVisible()) { JPersistentSplitPane pane = (JPersistentSplitPane) pce.getSource(); - int size = (getOrientation() == JSplitPane.HORIZONTAL_SPLIT + double size = (getOrientation() == JSplitPane.HORIZONTAL_SPLIT ? pane.getWidth() : pane.getHeight()) - pane.getDividerSize(); if (size != 0) { - int p = Math.round(100.0f * (Integer) pce.getNewValue() / size); + double p = (Integer) pce.getNewValue() / size; + setResizeWeight(p); + //System.out.println("set " + config.getName() + ": " + p); config.set(p); } } }); } + + @Override + public void paint(Graphics g) { + super.paint(g); + painted = true; + } }