[Pixelle-commit] SF.net SVN: pixelle: [150] trunk/pixelle/src/com/mebigfatguy/pixelle
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-07-07 04:53:12
|
Revision: 150
http://pixelle.svn.sourceforge.net/pixelle/?rev=150&view=rev
Author: dbrosius
Date: 2008-07-06 21:53:13 -0700 (Sun, 06 Jul 2008)
Log Message:
-----------
start adding in saved algorithms
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java
trunk/pixelle/src/com/mebigfatguy/pixelle/Pixelle.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleBundle.java
trunk/pixelle/src/com/mebigfatguy/pixelle/actions/TransformAction.java
trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java
trunk/pixelle/src/com/mebigfatguy/pixelle/resources/pixelle.properties
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java 2008-07-06 22:09:40 UTC (rev 149)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java 2008-07-07 04:53:13 UTC (rev 150)
@@ -18,6 +18,7 @@
*/
package com.mebigfatguy.pixelle;
+import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -26,6 +27,8 @@
import java.util.HashMap;
import java.util.Map;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
@@ -42,12 +45,12 @@
private static final String SYSTEM_ALGO_XML_PATH = "/com/mebigfatguy/pixelle/resources/algorithms.xml";
private static final String SYSTEM_ALGO_XSD_PATH = "/com/mebigfatguy/pixelle/resources/algorithms.xsd";
- private static final String GROUP = "group";
- private static final String ALGORITHM = "algorithm";
- private static final String COMPONENT = "component";
- private static final String NAME = "name";
- private static final String PIXELLE = "pixelle";
- private static final String ALGORITHMS_FILE = "algorithms.xml";
+ public static final String GROUP = "group";
+ public static final String ALGORITHM = "algorithm";
+ public static final String COMPONENT = "component";
+ public static final String NAME = "name";
+ public static final String PIXELLE = "pixelle";
+ public static final String ALGORITHMS_FILE = "algorithms.xml";
private static AlgorithmArchiver archiver = new AlgorithmArchiver();
@@ -66,10 +69,50 @@
return archiver;
}
- public JPopupMenu getAlgorithmDisplayPopup() {
- return new JPopupMenu(PixelleBundle.getString(PixelleBundle.PIXEL_ALGORITHM));
+ public JPopupMenu getAlgorithmDisplayPopup(ActionListener l) {
+ JPopupMenu m = new JPopupMenu(PixelleBundle.getString(PixelleBundle.PIXEL_ALGORITHM));
+ populateMenuAlgorithms(m, systemAlgorithms, l);
+ populateMenuAlgorithms(m, userAlgorithms, l);
+
+ return m;
}
+ private void populateMenuAlgorithms(JPopupMenu menu, Map<String, Map<String, Map<PixelleComponent, String>>> algorithms, ActionListener l) {
+ for (final Map.Entry<String, Map<String, Map<PixelleComponent, String>>> entry : algorithms.entrySet()) {
+ String groupName = entry.getKey();
+ JMenu group = new JMenu(groupName);
+ menu.add(group);
+ for (final String algos : entry.getValue().keySet()) {
+ JMenuItem algoItem = new JMenuItem(algos);
+ algoItem.putClientProperty(NAME, groupName);
+ algoItem.addActionListener(l);
+ group.add(algoItem);
+ }
+ }
+ }
+
+ public Map<PixelleComponent, String> getAlgorithm(String groupName, String algorithmName) {
+ Map<String, Map<PixelleComponent, String>> group = systemAlgorithms.get(groupName);
+ if (group != null) {
+ Map<PixelleComponent, String> algo = group.get(algorithmName);
+ if (algo != null)
+ return algo;
+ }
+
+ group = userAlgorithms.get(groupName);
+ if (group == null) {
+ throw new IllegalArgumentException("Unknown group name " + groupName);
+ }
+
+ Map<PixelleComponent, String> algo = group.get(algorithmName);
+ if (algo == null) {
+ throw new IllegalArgumentException("Unknown algorithm name " + algorithmName);
+ }
+
+ return algo;
+
+ }
+
public void addAlgorithm(String group, String name, Map<PixelleComponent, String> algorithm) {
}
@@ -114,6 +157,7 @@
Map<String, Map<PixelleComponent, String>> currentGroup = null;
Map<PixelleComponent, String> currentAlgorithm = null;
String currentComponentName = null;
+ StringBuilder algorithmText = null;
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) {
@@ -125,20 +169,23 @@
currentGroup.put(atts.getValue(NAME), currentAlgorithm);
} else if (COMPONENT.equals(localName)) {
currentComponentName = atts.getValue(NAME);
+ algorithmText = new StringBuilder();
}
}
@Override
public void characters(char[] c, int start, int offset) {
if (currentComponentName != null) {
- PixelleComponent pc = PixelleComponent.valueOf(currentComponentName.toUpperCase());
- currentAlgorithm.put(pc, new String(c, start, offset).trim());
+ algorithmText.append(c, start, offset);
}
}
@Override
public void endElement(String uri, String localName, String qName) {
if (COMPONENT.equals(localName)) {
+ PixelleComponent pc = PixelleComponent.valueOf(currentComponentName.toUpperCase());
+ currentAlgorithm.put(pc, algorithmText.toString().trim());
+ algorithmText = null;
currentComponentName = null;
} else if (ALGORITHM.equals(localName)) {
currentAlgorithm = null;
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/Pixelle.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/Pixelle.java 2008-07-06 22:09:40 UTC (rev 149)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/Pixelle.java 2008-07-07 04:53:13 UTC (rev 150)
@@ -39,7 +39,7 @@
public static void main(String[] args) {
try {
PixelleFrame pf = new PixelleFrame();
- String title = MessageFormat.format(PixelleBundle.getString(PixelleBundle.TITLE), PixelleBundle.getString(PixelleBundle.UNKNOWN));
+ String title = MessageFormat.format(PixelleBundle.getString(PixelleBundle.TITLE), PixelleBundle.getString(PixelleBundle.UNTITLED));
pf.setTitle(title);
Rectangle bounds = GuiUtils.getScreenBounds();
pf.setBounds(bounds);
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleBundle.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleBundle.java 2008-07-06 22:09:40 UTC (rev 149)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleBundle.java 2008-07-07 04:53:13 UTC (rev 150)
@@ -29,7 +29,7 @@
public static final String CANCEL = "cancel";
public static final String RESET = "reset";
public static final String TITLE = "pixelle.title";
- public static final String UNKNOWN = "pixelle.unknown";
+ public static final String UNTITLED = "pixelle.untitled";
public static final String FILE_MENU = "menu.file.title";
public static final String NEW_ITEM = "menu.file.new";
public static final String OPEN_ITEM = "menu.file.open";
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/actions/TransformAction.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/actions/TransformAction.java 2008-07-06 22:09:40 UTC (rev 149)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/actions/TransformAction.java 2008-07-07 04:53:13 UTC (rev 150)
@@ -55,7 +55,7 @@
if (dstImage != null) {
if (frame.createNewWindow()) {
PixelleFrame f = new PixelleFrame(dstImage);
- String title = MessageFormat.format(PixelleBundle.getString(PixelleBundle.TITLE), PixelleBundle.getString(PixelleBundle.UNKNOWN));
+ String title = MessageFormat.format(PixelleBundle.getString(PixelleBundle.TITLE), PixelleBundle.getString(PixelleBundle.UNTITLED));
f.setTitle(title);
f.setVisible(true);
} else
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java 2008-07-06 22:09:40 UTC (rev 149)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java 2008-07-07 04:53:13 UTC (rev 150)
@@ -23,6 +23,8 @@
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.util.EnumMap;
import java.util.Map;
@@ -34,9 +36,13 @@
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
import javax.swing.JTextField;
+import com.mebigfatguy.pixelle.AlgorithmArchiver;
import com.mebigfatguy.pixelle.PixelleBundle;
import com.mebigfatguy.pixelle.PixelleComponent;
import com.mebigfatguy.pixelle.PixelleFrame;
@@ -63,7 +69,7 @@
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)
+ new JTextField(PixelleBundle.getString(PixelleBundle.SELECTION_FORMULA), 50),
};
private final JLabel labels[] =
@@ -78,6 +84,10 @@
JButton ok;
JButton cancel;
JButton reset;
+ JTextField selectedAlgorithm;
+ JPopupMenu savedAlgorithms;
+
+ JButton save;
boolean clickedOK = false;
public PixelleExpressionDialog(PixelleFrame owner) {
@@ -102,45 +112,100 @@
private void initComponents() {
Container cp = getContentPane();
- cp.setLayout(new GridLayout(6, 1));
- GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, lhs);
- GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, editor);
- GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, labels);
-
- for (int i = 0; i < NUM_LABELS; i++) {
- 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.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
- cp.add(p);
- }
-
ok = new JButton(PixelleBundle.getString(PixelleBundle.OK));
cancel = new JButton(PixelleBundle.getString(PixelleBundle.CANCEL));
reset = new JButton(PixelleBundle.getString(PixelleBundle.RESET));
- GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, new JComponent[] {ok, cancel, reset});
+ save = new JButton(PixelleBundle.getString(PixelleBundle.SAVE_ALGORITHM));
+ GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, new JComponent[] {ok, cancel, reset, save});
+
+ cp.setLayout(new BorderLayout(4, 4));
- JPanel p = new JPanel();
- p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
- p.add(Box.createHorizontalStrut(10));
- p.add(reset);
- p.add(Box.createHorizontalGlue());
- p.add(ok);
- p.add(Box.createHorizontalStrut(10));
- p.add(cancel);
- p.add(Box.createHorizontalStrut(10));
- p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
- cp.add(p);
+ {
+ JPanel optionsPanel = new JPanel();
+ optionsPanel.setLayout(new BoxLayout(optionsPanel, BoxLayout.X_AXIS));
+ optionsPanel.add(Box.createHorizontalGlue());
+ JLabel l = new JLabel(PixelleBundle.getString(PixelleBundle.PIXEL_ALGORITHM));
+ optionsPanel.add(l);
+ optionsPanel.add(Box.createHorizontalStrut(10));
+ selectedAlgorithm = new JTextField(PixelleBundle.getString(PixelleBundle.UNTITLED));
+ selectedAlgorithm.setEditable(false);
+ optionsPanel.add(selectedAlgorithm);
+ optionsPanel.add(Box.createHorizontalStrut(10));
+ savedAlgorithms = AlgorithmArchiver.getArchiver().getAlgorithmDisplayPopup(new ActionListener() {
+ public void actionPerformed(ActionEvent ae) {
+ JMenuItem item = (JMenuItem)ae.getSource();
+ String algorithmName = item.getText();
+ 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));
+ }
+ });
+ savedAlgorithms.setInvoker(selectedAlgorithm);
+ optionsPanel.add(savedAlgorithms);
+ optionsPanel.add(Box.createHorizontalGlue());
+ optionsPanel.setBorder(BorderFactory.createEmptyBorder(10, 4, 5, 4));
+ cp.add(optionsPanel, BorderLayout.NORTH);
+ }
+
+ {
+ 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);
+
+ for (int i = 0; i < NUM_LABELS; i++) {
+ 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.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
+ algoPanel.add(p);
+ }
+
+ cp.add(algoPanel, BorderLayout.CENTER);
+ }
+
+ {
+ JPanel ctlPanel = new JPanel();
+ ctlPanel.setLayout(new BoxLayout(ctlPanel, BoxLayout.X_AXIS));
+ ctlPanel.add(Box.createHorizontalStrut(10));
+ ctlPanel.add(reset);
+ ctlPanel.add(Box.createHorizontalStrut(10));
+ ctlPanel.add(save);
+ ctlPanel.add(Box.createHorizontalGlue());
+ ctlPanel.add(ok);
+ ctlPanel.add(Box.createHorizontalStrut(10));
+ ctlPanel.add(cancel);
+ ctlPanel.add(Box.createHorizontalStrut(10));
+ ctlPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
+ cp.add(ctlPanel, BorderLayout.SOUTH);
+ }
+
pack();
}
private void initListeners() {
getRootPane().setDefaultButton(ok);
+
+ selectedAlgorithm.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent me) {
+ savedAlgorithms.setSize(selectedAlgorithm.getSize());
+ savedAlgorithms.show(selectedAlgorithm, 0, 0);
+ }
+ });
+
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
clickedOK = true;
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/resources/pixelle.properties
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/resources/pixelle.properties 2008-07-06 22:09:40 UTC (rev 149)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/resources/pixelle.properties 2008-07-07 04:53:13 UTC (rev 150)
@@ -20,7 +20,7 @@
reset = RESET
pixelle.title = Pixelle - {0}
-pixelle.unknown = Unknown
+pixelle.untitled = Untitled
menu.file.title = File
menu.file.new = New
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|