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
package be.nikiroo.utils.resources;
+import java.awt.Color;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
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>
--- /dev/null
+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();
+ }
+}