From fb0b11f99df919f81db5920a3e07d42f52c7e65a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sat, 10 Aug 2013 21:52:08 +0200 Subject: [PATCH] Issue #298 Fixed progressbar UI --- .../decompiler/flash/gui/MyProgressBarUI.java | 115 ++++++++++++++++++ .../com/jpexs/decompiler/flash/gui/View.java | 2 + 2 files changed, 117 insertions(+) create mode 100644 trunk/src/com/jpexs/decompiler/flash/gui/MyProgressBarUI.java diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MyProgressBarUI.java b/trunk/src/com/jpexs/decompiler/flash/gui/MyProgressBarUI.java new file mode 100644 index 000000000..8ab937d87 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MyProgressBarUI.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2013 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 java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import javax.swing.CellRendererPane; +import javax.swing.JComponent; +import javax.swing.JProgressBar; +import javax.swing.SwingUtilities; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import javax.swing.plaf.ComponentUI; +import org.pushingpixels.lafwidget.animation.AnimationConfigurationManager; +import org.pushingpixels.substance.internal.ui.SubstanceProgressBarUI; +import org.pushingpixels.substance.internal.utils.SubstanceCoreUtilities; +import org.pushingpixels.trident.Timeline; +import org.pushingpixels.trident.TimelinePropertyBuilder; +import org.pushingpixels.trident.ease.Spline; + +/** + * + * @author JPEXS + */ +public class MyProgressBarUI extends SubstanceProgressBarUI { + + private final class SubstanceChangeListener implements ChangeListener { + + @Override + public void stateChanged(ChangeEvent e) { + SubstanceCoreUtilities.testComponentStateChangeThreadingViolation(progressBar); + + if (displayTimeline != null) { //Main Change - this should be first + displayTimeline.abort(); + } + int currValue = progressBar.getValue(); + int span = progressBar.getMaximum() - progressBar.getMinimum(); + + int barRectWidth = progressBar.getWidth() - 2 * margin; + int barRectHeight = progressBar.getHeight() - 2 * margin; + int totalPixels = (progressBar.getOrientation() == JProgressBar.HORIZONTAL) ? barRectWidth + : barRectHeight; + + int pixelDelta = (span <= 0) ? 0 : (currValue - displayedValue) + * totalPixels / span; + + + displayTimeline = new Timeline(progressBar); + displayTimeline.addPropertyToInterpolate(Timeline + .property("displayedValue").from(displayedValue) + .to(currValue).setWith(new TimelinePropertyBuilder.PropertySetter() { + @Override + public void set(Object obj, String fieldName, + Integer value) { + displayedValue = value; + progressBar.repaint(); + } + })); + displayTimeline.setEase(new Spline(0.4f)); + AnimationConfigurationManager.getInstance().configureTimeline( + displayTimeline); + + boolean isInCellRenderer = (SwingUtilities.getAncestorOfClass( + CellRendererPane.class, progressBar) != null); + if (currValue > 0 && !isInCellRenderer && Math.abs(pixelDelta) > 5) { + displayTimeline.play(); + } else { + displayedValue = currValue; + progressBar.repaint(); + } + } + } + + public static ComponentUI createUI(JComponent comp) { + SubstanceCoreUtilities.testComponentCreationThreadingViolation(comp); + return new MyProgressBarUI(); + } + + @Override + protected void installListeners() { + substanceValueChangeListener = new MyProgressBarUI.SubstanceChangeListener(); + this.progressBar.addChangeListener(this.substanceValueChangeListener); + + this.substancePropertyChangeListener = new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + if ("font".equals(evt.getPropertyName())) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + if (progressBar != null) { + progressBar.updateUI(); + } + } + }); + } + } + }; + this.progressBar.addPropertyChangeListener(this.substancePropertyChangeListener); + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/View.java b/trunk/src/com/jpexs/decompiler/flash/gui/View.java index 0400b56d6..39b2deeaf 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/View.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/View.java @@ -37,6 +37,7 @@ import javax.swing.KeyStroke; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; +import javax.swing.plaf.basic.BasicProgressBarUI; import org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon; import org.pushingpixels.substance.api.SubstanceConstants; import org.pushingpixels.substance.api.SubstanceLookAndFeel; @@ -72,6 +73,7 @@ public class View { UIManager.put("RibbonApplicationMenuPopupPanelUI", MyRibbonApplicationMenuPopupPanelUI.class.getName()); UIManager.put("RibbonApplicationMenuButtonUI", MyRibbonApplicationMenuButtonUI.class.getName()); + UIManager.put("ProgressBarUI", MyProgressBarUI.class.getName()); //UIManager.put(SubstanceLookAndFeel.USE_THEMED_DEFAULT_ICONS,Boolean.TRUE); //UIManager.put("InternalFrame.icon",View.getIcon("icon16")); //UIManager.getDefaults().put("TreeUI", BasicTreeUI.class.getName() );