From 632275396b72ecbb7bd98108b037f3052f0ac65d Mon Sep 17 00:00:00 2001 From: "T. van der Zwan" Date: Sun, 17 Nov 2013 20:56:47 +0100 Subject: [PATCH] Add hiding of progressbar when finished creating image Former-commit-id: b5732d9ac6fbcead8d4127e2b18c446fd7f0e0a6 --- .../hypercon/gui/LedSimulationComponent.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/LedSimulationComponent.java b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/LedSimulationComponent.java index b2be209a..18ac8274 100644 --- a/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/LedSimulationComponent.java +++ b/src/config-tool/ConfigTool/src/org/hyperion/hypercon/gui/LedSimulationComponent.java @@ -24,6 +24,7 @@ import javax.swing.JMenu; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JProgressBar; +import javax.swing.SwingWorker; import org.hyperion.hypercon.LedFrameFactory; import org.hyperion.hypercon.spec.ImageProcessConfig; @@ -145,22 +146,24 @@ public class LedSimulationComponent extends JPanel { mWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { + if (evt.getPropertyName() == "state") { + if (evt.getNewValue() == SwingWorker.StateValue.STARTED) { + mProgressBar.setVisible(true); + } else if (evt.getNewValue() == SwingWorker.StateValue.DONE) { + handleWorkerDone(); + mProgressBar.setVisible(false); + } + } else if (evt.getPropertyName() == "progress") { + mProgressBar.setValue(mWorker.getProgress()); + } + } + + private void handleWorkerDone() { BufferedImage backgroundImage = null; - synchronized(LedSimulationComponent.this) { if (mWorker == null) { return; } - - if (evt.getPropertyName() == "progress") { - mProgressBar.setValue(mWorker.getProgress()); - return; - } - - if (!mWorker.isDone()) { - return; - } - try { backgroundImage = mWorker.get(); mWorker = null; @@ -169,6 +172,7 @@ public class LedSimulationComponent extends JPanel { if (backgroundImage == null) { return; } + int width = backgroundImage.getWidth(); int height = backgroundImage.getHeight(); int borderWidth = (int) (backgroundImage.getWidth() * 0.1); @@ -186,6 +190,7 @@ public class LedSimulationComponent extends JPanel { mBottomRightImage.setImage(backgroundImage.getSubimage(width-borderWidth, height-borderHeight, borderWidth, borderHeight)); mProgressBar.setValue(100); + mProgressBar.setVisible(false); mWorker = null; LedSimulationComponent.this.repaint();