From: Niki Roo Date: Sun, 19 Feb 2017 00:38:51 +0000 (+0100) Subject: 1.1.1: add UI component for Progress X-Git-Tag: nikiroo-utils-1.2.3~3 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=b3aad1f93ce78c9806361ca1659defcf99b45bdc;p=nikiroo-utils.git 1.1.1: add UI component for Progress --- diff --git a/VERSION b/VERSION index 9084fa2..524cb55 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.0 +1.1.1 diff --git a/changelog b/changelog index 5bc5c48..02a6944 100644 --- 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 ------------- diff --git a/configure.sh b/configure.sh index 7d8a70d..0ac4e2e 100755 --- a/configure.sh +++ b/configure.sh @@ -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 diff --git a/src/be/nikiroo/utils/ui/Progress.java b/src/be/nikiroo/utils/Progress.java similarity index 99% rename from src/be/nikiroo/utils/ui/Progress.java rename to src/be/nikiroo/utils/Progress.java index 2785180..8b6e10e 100644 --- a/src/be/nikiroo/utils/ui/Progress.java +++ b/src/be/nikiroo/utils/Progress.java @@ -1,4 +1,4 @@ -package be.nikiroo.utils.ui; +package be.nikiroo.utils; import java.util.ArrayList; import java.util.EventListener; diff --git a/src/be/nikiroo/utils/resources/Bundle.java b/src/be/nikiroo/utils/resources/Bundle.java index 2039d57..cfdc9e0 100644 --- a/src/be/nikiroo/utils/resources/Bundle.java +++ b/src/be/nikiroo/utils/resources/Bundle.java @@ -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> { 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. *

diff --git a/src/be/nikiroo/utils/test/ProgressTest.java b/src/be/nikiroo/utils/test/ProgressTest.java index 2509735..2194c23 100644 --- a/src/be/nikiroo/utils/test/ProgressTest.java +++ b/src/be/nikiroo/utils/test/ProgressTest.java @@ -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 index 0000000..2abd2b7 --- /dev/null +++ b/src/be/nikiroo/utils/ui/ProgressBar.java @@ -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 listeners; + + public ProgressBar() { + bar = new JProgressBar(); + label = new JLabel(); + listeners = new ArrayList(); + + 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(); + } +}