[Pixelle-commit] SF.net SVN: pixelle:[184] trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs /Pixe
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-11-14 17:17:20
|
Revision: 184
http://pixelle.svn.sourceforge.net/pixelle/?rev=184&view=rev
Author: dbrosius
Date: 2008-11-14 17:17:15 +0000 (Fri, 14 Nov 2008)
Log Message:
-----------
simplify controls by relying on PixelleComponent, as opposed to some hazy implicit array to component association
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java 2008-11-14 16:45:44 UTC (rev 183)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java 2008-11-14 17:17:15 UTC (rev 184)
@@ -48,37 +48,29 @@
import com.mebigfatguy.pixelle.utils.GuiUtils;
public class PixelleExpressionDialog extends JDialog {
-
- private static final long serialVersionUID = -420573137466431577L;
-
- private static final int NUM_LABELS = 5;
- private final JLabel lhs[] =
- {
- new JLabel(PixelleBundle.getString(PixelleBundle.RED_FORMULA) + " = "),
- new JLabel(PixelleBundle.getString(PixelleBundle.GREEN_FORMULA) + " = "),
- new JLabel(PixelleBundle.getString(PixelleBundle.BLUE_FORMULA) + " = "),
- new JLabel(PixelleBundle.getString(PixelleBundle.TRANSPARENCY_FORMULA) + " = "),
- new JLabel(PixelleBundle.getString(PixelleBundle.SELECTION_FORMULA) + " = ")
- };
+ private static final long serialVersionUID = -4273352119079307059L;
- private final JTextField editor[] =
- {
- new JTextField(PixelleBundle.getString(PixelleBundle.RED_FORMULA), 50),
- new JTextField(PixelleBundle.getString(PixelleBundle.GREEN_FORMULA), 50),
- new JTextField(PixelleBundle.getString(PixelleBundle.BLUE_FORMULA), 50),
- new JTextField(PixelleBundle.getString(PixelleBundle.TRANSPARENCY_FORMULA), 50),
- new JTextField(PixelleBundle.getString(PixelleBundle.SELECTION_FORMULA), 50),
- };
+ private final Map<PixelleComponent, JLabel> lhs = new EnumMap<PixelleComponent, JLabel>(PixelleComponent.class);
+ {
+ for (PixelleComponent comp : PixelleComponent.values()) {
+ lhs.put(comp, new JLabel(PixelleBundle.getString("formula." + comp.name().toLowerCase()) + " = "));
+ }
+ };
+
+ private final Map<PixelleComponent, JTextField> editor = new EnumMap<PixelleComponent, JTextField>(PixelleComponent.class);
+ {
+ for (PixelleComponent comp : PixelleComponent.values()) {
+ editor.put(comp, new JTextField(PixelleBundle.getString("formula." + comp.name().toLowerCase()), 50));
+ }
+ };
- private final JLabel labels[] =
- {
- new JLabel(PixelleBundle.getString(PixelleBundle.RED_LABEL)),
- new JLabel(PixelleBundle.getString(PixelleBundle.GREEN_LABEL)),
- new JLabel(PixelleBundle.getString(PixelleBundle.BLUE_LABEL)),
- new JLabel(PixelleBundle.getString(PixelleBundle.TRANSPARENCY_LABEL)),
- new JLabel(PixelleBundle.getString(PixelleBundle.SELECTION_LABEL))
- };
+ private final Map<PixelleComponent, JLabel> labels = new EnumMap<PixelleComponent, JLabel>(PixelleComponent.class);
+ {
+ for (PixelleComponent comp : PixelleComponent.values()) {
+ labels.put(comp, new JLabel(PixelleBundle.getString("label." + comp.name().toLowerCase())));
+ }
+ };
PixelleFrame frame;
JButton ok;
@@ -104,11 +96,9 @@
public Map<PixelleComponent, String> getAlgorithms() {
Map<PixelleComponent, String> algorithms = new EnumMap<PixelleComponent, String>(PixelleComponent.class);
- algorithms.put(PixelleComponent.RED, editor[0].getText());
- algorithms.put(PixelleComponent.GREEN, editor[1].getText());
- algorithms.put(PixelleComponent.BLUE, editor[2].getText());
- algorithms.put(PixelleComponent.TRANSPARENCY, editor[3].getText());
- algorithms.put(PixelleComponent.SELECTION, editor[4].getText());
+ for (PixelleComponent comp : PixelleComponent.values()) {
+ algorithms.put(comp, editor.get(comp).getText());
+ }
return algorithms;
}
@@ -142,21 +132,17 @@
String groupName = (String)item.getClientProperty(AlgorithmArchiver.NAME);
selectedAlgorithm.setText(algorithmName);
Map<PixelleComponent, String> algorithms = AlgorithmArchiver.getArchiver().getAlgorithm(groupName, algorithmName);
- editor[0].setText(algorithms.get(PixelleComponent.RED));
- editor[1].setText(algorithms.get(PixelleComponent.GREEN));
- editor[2].setText(algorithms.get(PixelleComponent.BLUE));
- editor[3].setText(algorithms.get(PixelleComponent.TRANSPARENCY));
- editor[4].setText(algorithms.get(PixelleComponent.SELECTION));
+ for (PixelleComponent comp : PixelleComponent.values()) {
+ editor.get(comp).setText(algorithms.get(comp));
+ }
}
});
try {
Map<PixelleComponent, String> algorithms = AlgorithmArchiver.getArchiver().getCurrent();
if (algorithms != null) {
- editor[0].setText(algorithms.get(PixelleComponent.RED));
- editor[1].setText(algorithms.get(PixelleComponent.GREEN));
- editor[2].setText(algorithms.get(PixelleComponent.BLUE));
- editor[3].setText(algorithms.get(PixelleComponent.TRANSPARENCY));
- editor[4].setText(algorithms.get(PixelleComponent.SELECTION));
+ for (PixelleComponent comp : PixelleComponent.values()) {
+ editor.get(comp).setText(algorithms.get(comp));
+ }
}
} catch (IllegalArgumentException iae) {
}
@@ -172,17 +158,17 @@
JPanel algoPanel = new JPanel();
algoPanel.setLayout(new GridLayout(5, 1));
- GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, lhs);
- GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, editor);
- GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, labels);
+ GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, lhs.values().toArray(new JComponent[lhs.size()]));
+ GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, editor.values().toArray(new JComponent[lhs.size()]));
+ GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, labels.values().toArray(new JComponent[lhs.size()]));
- for (int i = 0; i < NUM_LABELS; i++) {
+ for (PixelleComponent comp : PixelleComponent.values()) {
JPanel p = new JPanel();
p.setLayout(new BorderLayout(10, 10));
- p.add(lhs[i], BorderLayout.WEST);
- p.add(editor[i], BorderLayout.CENTER);
- p.add(labels[i], BorderLayout.EAST);
- labels[i].setLabelFor(editor[i]);
+ p.add(lhs.get(comp), BorderLayout.WEST);
+ p.add(editor.get(comp), BorderLayout.CENTER);
+ p.add(labels.get(comp), BorderLayout.EAST);
+ labels.get(comp).setLabelFor(editor.get(comp));
p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
algoPanel.add(p);
}
@@ -260,11 +246,9 @@
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
- editor[0].setText(PixelleBundle.getString(PixelleBundle.RED_FORMULA));
- editor[1].setText(PixelleBundle.getString(PixelleBundle.GREEN_FORMULA));
- editor[2].setText(PixelleBundle.getString(PixelleBundle.BLUE_FORMULA));
- editor[3].setText(PixelleBundle.getString(PixelleBundle.TRANSPARENCY_FORMULA));
- editor[4].setText(PixelleBundle.getString(PixelleBundle.SELECTION_FORMULA));
+ for (PixelleComponent comp : PixelleComponent.values()) {
+ editor.get(comp).setText(PixelleBundle.getString("formula." + comp.name().toLowerCase()));
+ }
}
});
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|