1.1.1: add UI component for Progress
authorNiki Roo <niki@nikiroo.be>
Sun, 19 Feb 2017 00:38:51 +0000 (01:38 +0100)
committerNiki Roo <niki@nikiroo.be>
Sun, 19 Feb 2017 00:38:51 +0000 (01:38 +0100)
VERSION
changelog
configure.sh
src/be/nikiroo/utils/Progress.java [moved from src/be/nikiroo/utils/ui/Progress.java with 99% similarity]
src/be/nikiroo/utils/resources/Bundle.java
src/be/nikiroo/utils/test/ProgressTest.java
src/be/nikiroo/utils/ui/ProgressBar.java [new file with mode: 0644]

diff --git a/VERSION b/VERSION
index 9084fa2f716a7117829f3f32a5f4cef400e02903..524cb55242b53f6a64cc646ea05db6acc7696d2d 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.1.0
+1.1.1
index 5bc5c4810643f952f233fdd00f8849e97cd6a6e6..02a6944ae6a2654c5eb795891beacbd623e90b17 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,10 @@
+Version 1.1.1
+-------------
+
+Add UI component for Progress
+       Still a WIP, it only show the current progress bar, still not the
+       children bars (it's planned)
+
 Version 1.1.0
 -------------
 
index 7d8a70d8ee2b7d010106fb41a54499bd9c1d0549..0ac4e2e423e10bceb187396910a9d4701c531bc7 100755 (executable)
@@ -45,7 +45,7 @@ fi;
 
 
 echo "MAIN = be/nikiroo/utils/resources/TransBundle" > Makefile
-echo "MORE = be/nikiroo/utils/StringUtils be/nikiroo/utils/IOUtils be/nikiroo/utils/MarkableFileInputStream be/nikiroo/utils/ui/UIUtils be/nikiroo/utils/ui/WrapLayout be/nikiroo/utils/ui/Progress be/nikiroo/utils/test/TestLauncher" >> Makefile
+echo "MORE = be/nikiroo/utils/StringUtils be/nikiroo/utils/IOUtils be/nikiroo/utils/MarkableFileInputStream be/nikiroo/utils/ui/UIUtils be/nikiroo/utils/ui/WrapLayout be/nikiroo/utils/ui/ProgressBar be/nikiroo/utils/test/TestLauncher" >> Makefile
 echo "TEST = be/nikiroo/utils/test/Test" >> Makefile
 echo "TEST_PARAMS = $cols $ok $ko" >> Makefile
 echo "NAME = nikiroo-utils" >> Makefile
similarity index 99%
rename from src/be/nikiroo/utils/ui/Progress.java
rename to src/be/nikiroo/utils/Progress.java
index 278518028f6ca842cd47df084c4bfc35f9ffdf64..8b6e10e5fc97ca6e5b2748aeb58c4829d80a3287 100644 (file)
@@ -1,4 +1,4 @@
-package be.nikiroo.utils.ui;
+package be.nikiroo.utils;
 
 import java.util.ArrayList;
 import java.util.EventListener;
index 2039d578e3c581a98efabad7369dbd0c879ed626..cfdc9e0836871347ec76f6c9f11c84acee4ed90d 100644 (file)
@@ -1,5 +1,6 @@
 package be.nikiroo.utils.resources;
 
+import java.awt.Color;
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileInputStream;
@@ -178,6 +179,31 @@ public class Bundle<E extends Enum<E>> {
                return ' ';
        }
 
+       /**
+        * Return the value associated to the given id as a {@link Color}.
+        * 
+        * @param the
+        *            id of the value to get
+        * 
+        * @return the associated value
+        */
+       public Color getColor(E id) {
+               Color color = null;
+
+               String bg = getString(id).trim();
+               if (bg.startsWith("#") && bg.length() == 7) {
+                       try {
+                               color = new Color(Integer.parseInt(bg.substring(1, 3), 16),
+                                               Integer.parseInt(bg.substring(3, 5), 16),
+                                               Integer.parseInt(bg.substring(5, 7), 16));
+                       } catch (NumberFormatException e) {
+                               color = null; // no changes
+                       }
+               }
+
+               return color;
+       }
+
        /**
         * Create/update the .properties file.
         * <p>
index 2509735fbbac45f2ecad20594b1f7abd2bfb4302..2194c237b625434422dc342654cf93ef5ac2e175 100644 (file)
@@ -1,6 +1,6 @@
 package be.nikiroo.utils.test;
 
-import be.nikiroo.utils.ui.Progress;
+import be.nikiroo.utils.Progress;
 
 public class ProgressTest extends TestLauncher {
        public ProgressTest(String[] args) {
diff --git a/src/be/nikiroo/utils/ui/ProgressBar.java b/src/be/nikiroo/utils/ui/ProgressBar.java
new file mode 100644 (file)
index 0000000..2abd2b7
--- /dev/null
@@ -0,0 +1,81 @@
+package be.nikiroo.utils.ui;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.SwingUtilities;
+
+import be.nikiroo.utils.Progress;
+
+public class ProgressBar extends JPanel {
+       private static final long serialVersionUID = 1L;
+
+       private JProgressBar bar;
+       private JLabel label;
+       private List<ActionListener> listeners;
+
+       public ProgressBar() {
+               bar = new JProgressBar();
+               label = new JLabel();
+               listeners = new ArrayList<ActionListener>();
+
+               setLayout(new BorderLayout());
+       }
+
+       public void setProgress(Progress pg) {
+               if (pg == null) {
+                       setPresent(false);
+               } else {
+                       label.setText(pg.getName());
+                       bar.setMinimum(pg.getMin());
+                       bar.setMaximum(pg.getMax());
+                       bar.setValue(pg.getProgress());
+
+                       pg.addProgressListener(new Progress.ProgressListener() {
+                               public void progress(final Progress progress, final String name) {
+                                       SwingUtilities.invokeLater(new Runnable() {
+                                               public void run() {
+                                                       label.setText(name);
+                                                       bar.setValue(progress.getProgress());
+
+                                                       if (progress.isDone()) {
+                                                               for (ActionListener listener : listeners) {
+                                                                       listener.actionPerformed(new ActionEvent(
+                                                                                       ProgressBar.this, 0, "done"));
+                                                               }
+                                                       }
+                                               }
+                                       });
+                               }
+                       });
+
+                       setPresent(true);
+               }
+       }
+
+       public void addActioListener(ActionListener l) {
+               listeners.add(l);
+       }
+
+       public void clearActionListeners() {
+               listeners.clear();
+       }
+
+       private void setPresent(boolean present) {
+               removeAll();
+
+               if (present) {
+                       add(label, BorderLayout.NORTH);
+                       add(bar, BorderLayout.CENTER);
+               }
+
+               validate();
+               repaint();
+       }
+}