[Pixelle-commit] SF.net SVN: pixelle:[205] trunk/pixelle/src/com/mebigfatguy/pixelle
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-11-20 07:18:47
|
Revision: 205
http://pixelle.svn.sourceforge.net/pixelle/?rev=205&view=rev
Author: dbrosius
Date: 2008-11-20 07:18:44 +0000 (Thu, 20 Nov 2008)
Log Message:
-----------
Get the tabbed panes marginally working with a single PixelleComponent
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleComponent.java
trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.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/algorithms.xml
trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xsd
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java 2008-11-20 06:39:17 UTC (rev 204)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java 2008-11-20 07:18:44 UTC (rev 205)
@@ -51,23 +51,24 @@
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";
+ public static final String TYPE = "type";
public static final String GROUP = "group";
public static final String CURRENT = "current_";
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 PIXELLE = ".pixelle";
public static final String ALGORITHMS_FILE = "algorithms.xml";
private static AlgorithmArchiver archiver = new AlgorithmArchiver();
- private final Map<String, Map<String, Map<RGBPixelleComponent, String>>> systemAlgorithms;
- private final Map<String, Map<String, Map<RGBPixelleComponent, String>>> userAlgorithms;
+ private final Map<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>> systemAlgorithms;
+ private final Map<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>> userAlgorithms;
private AlgorithmArchiver() {
- systemAlgorithms = new HashMap<String, Map<String, Map<RGBPixelleComponent, String>>>();
- userAlgorithms = new HashMap<String, Map<String, Map<RGBPixelleComponent, String>>>();
+ systemAlgorithms = new HashMap<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>>();
+ userAlgorithms = new HashMap<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>>();
loadSystemAlgorithms();
loadUserAlgorithms();
}
@@ -76,44 +77,54 @@
return archiver;
}
- public JPopupMenu getAlgorithmDisplayPopup(ImageType type, ActionListener l) {
+ public JPopupMenu getAlgorithmDisplayPopup(ImageType imageType, ActionListener l) {
JPopupMenu m = new JPopupMenu(PixelleBundle.getString(PixelleBundle.PIXEL_ALGORITHM));
- populateMenuAlgorithms(m, systemAlgorithms, l);
- populateMenuAlgorithms(m, userAlgorithms, l);
+ populateMenuAlgorithms(m, systemAlgorithms.get(imageType), l);
+ populateMenuAlgorithms(m, userAlgorithms.get(imageType), l);
return m;
}
- private void populateMenuAlgorithms(JPopupMenu menu, Map<String, Map<String, Map<RGBPixelleComponent, String>>> algorithms, ActionListener l) {
- for (final Map.Entry<String, Map<String, Map<RGBPixelleComponent, String>>> entry : algorithms.entrySet()) {
- String groupName = entry.getKey();
- if (!CURRENT.equals(groupName)) {
- 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);
+ private void populateMenuAlgorithms(JPopupMenu menu, Map<String, Map<String, Map<PixelleComponent, String>>> algorithms, ActionListener l) {
+ if (algorithms != null) {
+ for (final Map.Entry<String, Map<String, Map<PixelleComponent, String>>> entry : algorithms.entrySet()) {
+ String groupName = entry.getKey();
+ if (!CURRENT.equals(groupName)) {
+ 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<? extends Enum, String> getAlgorithm(ImageType type, String groupName, String algorithmName) {
- Map<String, Map<RGBPixelleComponent, String>> group = systemAlgorithms.get(groupName);
- if (group != null) {
- Map<RGBPixelleComponent, String> algo = group.get(algorithmName);
- if (algo != null)
- return algo;
+ public Map<PixelleComponent, String> getAlgorithm(ImageType imageType, String groupName, String algorithmName) {
+ Map<String, Map<String, Map<PixelleComponent, String>>> type = systemAlgorithms.get(imageType);
+ if (type != null) {
+ Map<String, Map<PixelleComponent, String>> group = type.get(groupName);
+ if (group != null) {
+ Map<PixelleComponent, String> algo = group.get(algorithmName);
+ if (algo != null)
+ return algo;
+ }
}
- group = userAlgorithms.get(groupName);
+ type = userAlgorithms.get(imageType);
+ if (type == null) {
+ throw new IllegalArgumentException("Unknown type name " + imageType.name());
+ }
+
+ Map<String, Map<PixelleComponent, String>> group = type.get(groupName);
if (group == null) {
throw new IllegalArgumentException("Unknown group name " + groupName);
}
- Map<RGBPixelleComponent, String> algo = group.get(algorithmName);
+ Map<PixelleComponent, String> algo = group.get(algorithmName);
if (algo == null) {
throw new IllegalArgumentException("Unknown algorithm name " + algorithmName);
}
@@ -126,28 +137,38 @@
return userAlgorithms.keySet().toArray(new String[userAlgorithms.size()]);
}
- public void addAlgorithm(String groupName, String algorithmName, Map<RGBPixelleComponent, String> algorithm) {
- Map<String, Map<RGBPixelleComponent, String>> group = userAlgorithms.get(groupName);
+ public void addAlgorithm(ImageType imageType, String groupName, String algorithmName, Map<PixelleComponent, String> algorithm) {
+ Map<String, Map<String, Map<PixelleComponent, String>>> type = userAlgorithms.get(imageType);
+ if (type == null) {
+ type = new HashMap<String, Map<String, Map<PixelleComponent, String>>>();
+ userAlgorithms.put(imageType, type);
+ }
+
+
+ Map<String, Map<PixelleComponent, String>> group = type.get(groupName);
if (group == null) {
- group = new HashMap<String, Map<RGBPixelleComponent, String>>();
- userAlgorithms.put(groupName, group);
+ group = new HashMap<String, Map<PixelleComponent, String>>();
+ type.put(groupName, group);
}
- group.put(algorithmName, new HashMap<RGBPixelleComponent, String>(algorithm));
+ group.put(algorithmName, new HashMap<PixelleComponent, String>(algorithm));
}
- public void setCurrent(Map<RGBPixelleComponent, String> algorithm) {
- addAlgorithm(AlgorithmArchiver.CURRENT, AlgorithmArchiver.CURRENT, algorithm);
+ public void setCurrent(ImageType imageType, Map<PixelleComponent, String> algorithm) {
+ addAlgorithm(imageType, AlgorithmArchiver.CURRENT, AlgorithmArchiver.CURRENT, algorithm);
}
- public Map<? extends Enum, String> getCurrent(ImageType type) {
- return getAlgorithm(type, AlgorithmArchiver.CURRENT, AlgorithmArchiver.CURRENT);
+ public Map<PixelleComponent, String> getCurrent(ImageType imageType) {
+ return getAlgorithm(imageType, AlgorithmArchiver.CURRENT, AlgorithmArchiver.CURRENT);
}
- public void removeAlgorithm(String group, String name) {
- Map<String, Map<RGBPixelleComponent, String>> algoGroup = userAlgorithms.get(group);
- if (algoGroup != null) {
- algoGroup.remove(name);
+ public void removeAlgorithm(ImageType imageType, String group, String name) {
+ Map<String, Map<String, Map<PixelleComponent, String>>> type = userAlgorithms.get(imageType);
+ if (type != null) {
+ Map<String, Map<PixelleComponent, String>> algoGroup = type.get(group);
+ if (algoGroup != null) {
+ algoGroup.remove(name);
+ }
}
}
@@ -197,7 +218,7 @@
}
- private void writeAlgorithms(OutputStream is, Map<String, Map<String, Map<RGBPixelleComponent, String>>> algorithms) throws IOException {
+ private void writeAlgorithms(OutputStream is, Map<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>> algorithms) throws IOException {
PrintWriter pw = null;
try {
pw = new PrintWriter(new OutputStreamWriter(is));
@@ -205,20 +226,24 @@
pw.println(" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'");
pw.println(" xsi:schemaLocation='/com/mebigfatguy/pixelle/resources/algorithms.xsd'>");
- for (Map.Entry<String, Map<String, Map<RGBPixelleComponent, String>>> group : algorithms.entrySet()) {
- pw.println(" <group name='" + group.getKey() + "'>");
-
- for (Map.Entry<String, Map<RGBPixelleComponent, String>> algorithm : group.getValue().entrySet()) {
- pw.println(" <algorithm name='" + algorithm.getKey() + "'>");
+ for (Map.Entry<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>> type : algorithms.entrySet()) {
+ pw.println(" <type name'" + type.getKey() + "'>");
+ for (Map.Entry<String, Map<String, Map<PixelleComponent, String>>> group : type.getValue().entrySet()) {
+ pw.println(" <group name='" + group.getKey() + "'>");
- for (Map.Entry<RGBPixelleComponent, String> component : algorithm.getValue().entrySet()) {
- pw.println(" <component name='" + component.getKey().name().toLowerCase() + "'>");
- pw.println(" " + component.getValue());
- pw.println(" </component>");
+ for (Map.Entry<String, Map<PixelleComponent, String>> algorithm : group.getValue().entrySet()) {
+ pw.println(" <algorithm name='" + algorithm.getKey() + "'>");
+
+ for (Map.Entry<PixelleComponent, String> component : algorithm.getValue().entrySet()) {
+ pw.println(" <component name='" + component.getKey().name().toLowerCase() + "'>");
+ pw.println(" " + component.getValue());
+ pw.println(" </component>");
+ }
+ pw.println(" </algorithm>");
}
- pw.println(" </algorithm>");
+ pw.println(" </group>");
}
- pw.println(" </group>");
+ pw.println(" </type>");
}
pw.println("</algorithms>");
pw.flush();
@@ -228,21 +253,25 @@
}
}
- private void parseAlgorithms(InputStream is, final Map<String, Map<String, Map<RGBPixelleComponent, String>>> algorithms) throws IOException, SAXException {
+ private void parseAlgorithms(InputStream is, final Map<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>> algorithms) throws IOException, SAXException {
XMLReader r = XMLReaderFactory.createXMLReader();
r.setContentHandler(new DefaultHandler() {
- Map<String, Map<RGBPixelleComponent, String>> currentGroup = null;
- Map<RGBPixelleComponent, String> currentAlgorithm = null;
+ Map<String, Map<String, Map<PixelleComponent, String>>> currentType = null;
+ 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) {
- if (GROUP.equals(localName)) {
- currentGroup = new HashMap<String, Map<RGBPixelleComponent, String>>();
- algorithms.put(atts.getValue(NAME), currentGroup);
+ if (TYPE.equals(localName)) {
+ currentType = new HashMap<String, Map<String, Map<PixelleComponent, String>>>();
+ algorithms.put(ImageType.valueOf(atts.getValue(NAME)), currentType);
+ } else if (GROUP.equals(localName)) {
+ currentGroup = new HashMap<String, Map<PixelleComponent, String>>();
+ currentType.put(atts.getValue(NAME), currentGroup);
} else if (ALGORITHM.equals(localName)) {
- currentAlgorithm = new EnumMap<RGBPixelleComponent, String>(RGBPixelleComponent.class);
+ currentAlgorithm = new EnumMap<PixelleComponent, String>(PixelleComponent.class);
currentGroup.put(atts.getValue(NAME), currentAlgorithm);
} else if (COMPONENT.equals(localName)) {
currentComponentName = atts.getValue(NAME);
@@ -260,7 +289,7 @@
@Override
public void endElement(String uri, String localName, String qName) {
if (COMPONENT.equals(localName)) {
- RGBPixelleComponent pc = RGBPixelleComponent.valueOf(currentComponentName.toUpperCase());
+ PixelleComponent pc = PixelleComponent.valueOf(currentComponentName.toUpperCase());
currentAlgorithm.put(pc, algorithmText.toString().trim());
algorithmText = null;
currentComponentName = null;
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleComponent.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleComponent.java 2008-11-20 06:39:17 UTC (rev 204)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleComponent.java 2008-11-20 07:18:44 UTC (rev 205)
@@ -18,6 +18,9 @@
*/
package com.mebigfatguy.pixelle;
+import java.util.EnumSet;
+import java.util.Set;
+
/**
* an enum that represents a part of an rgb bitmap
*/
@@ -44,4 +47,18 @@
public char getPixelSpec() {
return pixelSpec;
}
+
+ public static Set<PixelleComponent> rgbValues() {
+ Set<PixelleComponent> components = EnumSet.<PixelleComponent>allOf(PixelleComponent.class);
+ components.remove(PixelleComponent.BLACK);
+ return components;
+ }
+
+ public static Set<PixelleComponent> gsValues() {
+ Set<PixelleComponent> components = EnumSet.<PixelleComponent>allOf(PixelleComponent.class);
+ components.remove(PixelleComponent.RED);
+ components.remove(PixelleComponent.GREEN);
+ components.remove(PixelleComponent.BLUE);
+ return components;
+ }
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2008-11-20 06:39:17 UTC (rev 204)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/PixelleTransformer.java 2008-11-20 07:18:44 UTC (rev 205)
@@ -41,14 +41,14 @@
public class PixelleTransformer {
private final PixelleImage srcImage;
- private Map<RGBPixelleComponent, String> algorithms = null;
+ private Map<PixelleComponent, String> algorithms = null;
/**
* constructions a transformer given a source bitmap and algorithms
* @param image the source image
* @param algos the algorithms for the color components
*/
- public PixelleTransformer(PixelleImage image, Map<RGBPixelleComponent, String> algos) {
+ public PixelleTransformer(PixelleImage image, Map<PixelleComponent, String> algos) {
srcImage = image;
algorithms = algos;
}
@@ -58,13 +58,13 @@
*
* @return a set of transformation algorithms
*/
- public static Map<RGBPixelleComponent, String> getSampleTransform() {
- Map<RGBPixelleComponent, String> algorithms = new EnumMap<RGBPixelleComponent, String>(RGBPixelleComponent.class);
- algorithms.put(RGBPixelleComponent.RED, "x");
- algorithms.put(RGBPixelleComponent.GREEN, "y");
- algorithms.put(RGBPixelleComponent.BLUE, "abs((width/2) - x)");
- algorithms.put(RGBPixelleComponent.TRANSPARENCY, "((x < 10) || (x >= (width - 10)) || (y < 10) || (y >= (height - 10))) ? 180 : 255");
- algorithms.put(RGBPixelleComponent.SELECTION, "0");
+ public static Map<PixelleComponent, String> getSampleTransform() {
+ Map<PixelleComponent, String> algorithms = new EnumMap<PixelleComponent, String>(PixelleComponent.class);
+ algorithms.put(PixelleComponent.RED, "x");
+ algorithms.put(PixelleComponent.GREEN, "y");
+ algorithms.put(PixelleComponent.BLUE, "abs((width/2) - x)");
+ algorithms.put(PixelleComponent.TRANSPARENCY, "((x < 10) || (x >= (width - 10)) || (y < 10) || (y >= (height - 10))) ? 180 : 255");
+ algorithms.put(PixelleComponent.SELECTION, "0");
return algorithms;
}
/**
@@ -94,7 +94,7 @@
}
});
- for (Map.Entry<RGBPixelleComponent, String> entry : algorithms.entrySet()) {
+ for (Map.Entry<PixelleComponent, String> entry : algorithms.entrySet()) {
currentComponent = entry.getKey().name();
currentAlgorithm = entry.getValue();
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/actions/TransformAction.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/actions/TransformAction.java 2008-11-20 06:39:17 UTC (rev 204)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/actions/TransformAction.java 2008-11-20 07:18:44 UTC (rev 205)
@@ -50,7 +50,7 @@
d.setModal(true);
d.setVisible(true);
if (d.isOK()) {
- PixelleTransformer transformer = new PixelleTransformer(frame.getImage(), d.getAlgorithms());
+ PixelleTransformer transformer = new PixelleTransformer(frame.getImage(), d.getAlgorithms(d.getImageType()));
PixelleImage dstImage = transformer.transform();
if (dstImage != null) {
if (frame.createNewWindow()) {
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java 2008-11-20 06:39:17 UTC (rev 204)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/dialogs/PixelleExpressionDialog.java 2008-11-20 07:18:44 UTC (rev 205)
@@ -43,55 +43,54 @@
import javax.swing.JTextField;
import com.mebigfatguy.pixelle.AlgorithmArchiver;
-import com.mebigfatguy.pixelle.GrayscalePixelleComponent;
import com.mebigfatguy.pixelle.ImageType;
import com.mebigfatguy.pixelle.PixelleBundle;
+import com.mebigfatguy.pixelle.PixelleComponent;
import com.mebigfatguy.pixelle.PixelleFrame;
-import com.mebigfatguy.pixelle.RGBPixelleComponent;
import com.mebigfatguy.pixelle.utils.GuiUtils;
public class PixelleExpressionDialog extends JDialog {
private static final long serialVersionUID = -4273352119079307059L;
- private final Map<RGBPixelleComponent, JLabel> rgbLHS = new EnumMap<RGBPixelleComponent, JLabel>(RGBPixelleComponent.class);
+ private final Map<PixelleComponent, JLabel> rgbLHS = new EnumMap<PixelleComponent, JLabel>(PixelleComponent.class);
{
- for (RGBPixelleComponent comp : RGBPixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.rgbValues()) {
rgbLHS.put(comp, new JLabel(PixelleBundle.getString("formula." + comp.name().toLowerCase()) + " = "));
}
};
- private final Map<RGBPixelleComponent, JTextField> rgbEditor = new EnumMap<RGBPixelleComponent, JTextField>(RGBPixelleComponent.class);
+ private final Map<PixelleComponent, JTextField> rgbEditor = new EnumMap<PixelleComponent, JTextField>(PixelleComponent.class);
{
- for (RGBPixelleComponent comp : RGBPixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.rgbValues()) {
rgbEditor.put(comp, new JTextField(PixelleBundle.getString("formula." + comp.name().toLowerCase()), 50));
}
};
- private final Map<RGBPixelleComponent, JLabel> rgbLabels = new EnumMap<RGBPixelleComponent, JLabel>(RGBPixelleComponent.class);
+ private final Map<PixelleComponent, JLabel> rgbLabels = new EnumMap<PixelleComponent, JLabel>(PixelleComponent.class);
{
- for (RGBPixelleComponent comp : RGBPixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.rgbValues()) {
rgbLabels.put(comp, new JLabel(PixelleBundle.getString("label." + comp.name().toLowerCase())));
}
};
- private final Map<GrayscalePixelleComponent, JLabel> gsLHS = new EnumMap<GrayscalePixelleComponent, JLabel>(GrayscalePixelleComponent.class);
+ private final Map<PixelleComponent, JLabel> gsLHS = new EnumMap<PixelleComponent, JLabel>(PixelleComponent.class);
{
- for (GrayscalePixelleComponent comp : GrayscalePixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.gsValues()) {
gsLHS.put(comp, new JLabel(PixelleBundle.getString("formula." + comp.name().toLowerCase()) + " = "));
}
};
- private final Map<GrayscalePixelleComponent, JTextField> gsEditor = new EnumMap<GrayscalePixelleComponent, JTextField>(GrayscalePixelleComponent.class);
+ private final Map<PixelleComponent, JTextField> gsEditor = new EnumMap<PixelleComponent, JTextField>(PixelleComponent.class);
{
- for (GrayscalePixelleComponent comp : GrayscalePixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.gsValues()) {
gsEditor.put(comp, new JTextField(PixelleBundle.getString("formula." + comp.name().toLowerCase()), 50));
}
};
- private final Map<GrayscalePixelleComponent, JLabel> gsLabels = new EnumMap<GrayscalePixelleComponent, JLabel>(GrayscalePixelleComponent.class);
+ private final Map<PixelleComponent, JLabel> gsLabels = new EnumMap<PixelleComponent, JLabel>(PixelleComponent.class);
{
- for (GrayscalePixelleComponent comp : GrayscalePixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.gsValues()) {
gsLabels.put(comp, new JLabel(PixelleBundle.getString("label." + comp.name().toLowerCase())));
}
};
@@ -105,6 +104,7 @@
JPopupMenu savedRGBAlgorithms;
JTextField selectedGSAlgorithm;
JPopupMenu savedGSAlgorithms;
+ JTabbedPane tabbedPane;
JButton save;
JButton delete;
@@ -121,9 +121,13 @@
return clickedOK;
}
- public Map<RGBPixelleComponent, String> getAlgorithms() {
- Map<RGBPixelleComponent, String> algorithms = new EnumMap<RGBPixelleComponent, String>(RGBPixelleComponent.class);
- for (RGBPixelleComponent comp : RGBPixelleComponent.values()) {
+ public ImageType getImageType() {
+ return (tabbedPane.getSelectedIndex() == 0) ? ImageType.RGB : ImageType.Grayscale;
+ }
+
+ public Map<PixelleComponent, String> getAlgorithms(ImageType imageType) {
+ Map<PixelleComponent, String> algorithms = new EnumMap<PixelleComponent, String>(PixelleComponent.class);
+ for (PixelleComponent comp : (imageType == ImageType.RGB) ? PixelleComponent.rgbValues() : PixelleComponent.gsValues()) {
algorithms.put(comp, rgbEditor.get(comp).getText());
}
return algorithms;
@@ -141,7 +145,7 @@
cp.setLayout(new BorderLayout(4, 4));
- JTabbedPane tabbedPane = new JTabbedPane();
+ tabbedPane = new JTabbedPane();
cp.add(tabbedPane, BorderLayout.CENTER);
tabbedPane.add(PixelleBundle.getString(PixelleBundle.RGB), buildRGBPane());
@@ -190,16 +194,16 @@
String algorithmName = item.getText();
String groupName = (String)item.getClientProperty(AlgorithmArchiver.NAME);
selectedRGBAlgorithm.setText(algorithmName);
- Map<RGBPixelleComponent, String> algorithms = (Map<RGBPixelleComponent, String>)AlgorithmArchiver.getArchiver().getAlgorithm(ImageType.RGB, groupName, algorithmName);
- for (RGBPixelleComponent comp : RGBPixelleComponent.values()) {
+ Map<PixelleComponent, String> algorithms = AlgorithmArchiver.getArchiver().getAlgorithm(ImageType.RGB, groupName, algorithmName);
+ for (PixelleComponent comp : PixelleComponent.rgbValues()) {
rgbEditor.get(comp).setText(algorithms.get(comp));
}
}
});
try {
- Map<RGBPixelleComponent, String> algorithms = (Map<RGBPixelleComponent, String>)AlgorithmArchiver.getArchiver().getCurrent(ImageType.RGB);
+ Map<PixelleComponent, String> algorithms = AlgorithmArchiver.getArchiver().getCurrent(ImageType.RGB);
if (algorithms != null) {
- for (RGBPixelleComponent comp : RGBPixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.rgbValues()) {
rgbEditor.get(comp).setText(algorithms.get(comp));
}
}
@@ -221,7 +225,7 @@
GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, rgbEditor.values().toArray(new JComponent[rgbLHS.size()]));
GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, rgbLabels.values().toArray(new JComponent[rgbLHS.size()]));
- for (RGBPixelleComponent comp : RGBPixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.rgbValues()) {
JPanel p = new JPanel();
p.setLayout(new BorderLayout(10, 10));
p.add(rgbLHS.get(comp), BorderLayout.WEST);
@@ -259,16 +263,16 @@
String algorithmName = item.getText();
String groupName = (String)item.getClientProperty(AlgorithmArchiver.NAME);
selectedGSAlgorithm.setText(algorithmName);
- Map<GrayscalePixelleComponent, String> algorithms = (Map<GrayscalePixelleComponent, String>)AlgorithmArchiver.getArchiver().getAlgorithm(ImageType.Grayscale, groupName, algorithmName);
- for (GrayscalePixelleComponent comp : GrayscalePixelleComponent.values()) {
+ Map<PixelleComponent, String> algorithms = AlgorithmArchiver.getArchiver().getAlgorithm(ImageType.Grayscale, groupName, algorithmName);
+ for (PixelleComponent comp : PixelleComponent.gsValues()) {
gsEditor.get(comp).setText(algorithms.get(comp));
}
}
});
try {
- Map<GrayscalePixelleComponent, String> algorithms = (Map<GrayscalePixelleComponent, String>)AlgorithmArchiver.getArchiver().getCurrent(ImageType.Grayscale);
+ Map<PixelleComponent, String> algorithms = AlgorithmArchiver.getArchiver().getCurrent(ImageType.Grayscale);
if (algorithms != null) {
- for (GrayscalePixelleComponent comp : GrayscalePixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.gsValues()) {
gsEditor.get(comp).setText(algorithms.get(comp));
}
}
@@ -290,7 +294,7 @@
GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, gsEditor.values().toArray(new JComponent[gsLHS.size()]));
GuiUtils.sizeUniformly(GuiUtils.Sizing.Both, gsLabels.values().toArray(new JComponent[gsLHS.size()]));
- for (GrayscalePixelleComponent comp : GrayscalePixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.gsValues()) {
JPanel p = new JPanel();
p.setLayout(new BorderLayout(10, 10));
p.add(gsLHS.get(comp), BorderLayout.WEST);
@@ -326,11 +330,12 @@
dialog.setModal(true);
dialog.setVisible(true);
if (dialog.isOK()) {
+ ImageType imageType = getImageType();
String group = dialog.getGroup();
String name = dialog.getName();
- Map<RGBPixelleComponent, String> algorithm = getAlgorithms();
+ Map<PixelleComponent, String> algorithm = getAlgorithms(imageType);
AlgorithmArchiver archiver = AlgorithmArchiver.getArchiver();
- archiver.addAlgorithm(group, name, algorithm);
+ archiver.addAlgorithm(imageType, group, name, algorithm);
archiver.save();
}
}
@@ -338,9 +343,10 @@
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
- Map<RGBPixelleComponent, String> algorithm = getAlgorithms();
+ ImageType imageType = getImageType();
+ Map<PixelleComponent, String> algorithm = getAlgorithms(imageType);
AlgorithmArchiver archiver = AlgorithmArchiver.getArchiver();
- archiver.setCurrent(algorithm);
+ archiver.setCurrent(imageType, algorithm);
archiver.save();
clickedOK = true;
@@ -356,7 +362,7 @@
reset.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
- for (RGBPixelleComponent comp : RGBPixelleComponent.values()) {
+ for (PixelleComponent comp : PixelleComponent.gsValues()) {
rgbEditor.get(comp).setText(PixelleBundle.getString("formula." + comp.name().toLowerCase()));
}
}
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xml
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xml 2008-11-20 06:39:17 UTC (rev 204)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xml 2008-11-20 07:18:44 UTC (rev 205)
@@ -21,74 +21,73 @@
<algorithms xmlns="http://pixelle.mebigfatguy.com/0.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="/com/mebigfatguy/pixelle/resources/algorithms.xsd">
- <group name="Separations">
- <algorithm name="cyan">
- <component name="red">
- (255 - p[x,y].r) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="green">
- (255 - p[x,y].r) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="blue">
- (255 - p[x,y].r) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="transparency">
- 255
- </component>
- <component name="selection">
- 0
- </component>
- </algorithm>
- <algorithm name="magenta">
- <component name="red">
- (255 - p[x,y].g) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="green">
- (255 - p[x,y].g) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="blue">
- (255 - p[x,y].g) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="transparency">
- 255
- </component>
- <component name="selection">
- 0
- </component>
- </algorithm>
- <algorithm name="yellow">
- <component name="red">
- (255 - p[x,y].b) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="green">
- (255 - p[x,y].b) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="blue">
- (255 - p[x,y].b) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="transparency">
- 255
- </component>
- <component name="selection">
- 0
- </component>
- </algorithm>
- <algorithm name="black">
- <component name="red">
- min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="green">
- min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="blue">
- min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
- </component>
- <component name="transparency">
- 255
- </component>
- <component name="selection">
- 0
- </component>
- </algorithm>
- </group>
+ <type name="RGB">
+ <group name="Blends">
+ <algorithm name="linear">
+ <component name="red">
+ (x * 255) / width
+ </component>
+ <component name="green">
+ (y * 255) / height
+ </component>
+ <component name="blue">
+ ((width - x) * 255) / width
+ </component>
+ <component name="transparency">
+ 255
+ </component>
+ <component name="selection">
+ 0
+ </component>
+ </algorithm>
+ </group>
+ </type>
+ <type name="Grayscale">
+ <group name="Separations">
+ <algorithm name="cyan">
+ <component name="black">
+ (255 - p[x,y].r) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
+ </component>
+ <component name="transparency">
+ 255
+ </component>
+ <component name="selection">
+ 0
+ </component>
+ </algorithm>
+ <algorithm name="magenta">
+ <component name="black">
+ (255 - p[x,y].g) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
+ </component>
+ <component name="transparency">
+ 255
+ </component>
+ <component name="selection">
+ 0
+ </component>
+ </algorithm>
+ <algorithm name="yellow">
+ <component name="black">
+ (255 - p[x,y].b) - min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
+ </component>
+ <component name="transparency">
+ 255
+ </component>
+ <component name="selection">
+ 0
+ </component>
+ </algorithm>
+ <algorithm name="black">
+ <component name="black">
+ min(min(255 - p[x,y].r, 255 - p[x,y].g), 255 - p[x,y].b)
+ </component>
+ <component name="transparency">
+ 255
+ </component>
+ <component name="selection">
+ 0
+ </component>
+ </algorithm>
+ </group>
+ </type>
</algorithms>
\ No newline at end of file
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xsd
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xsd 2008-11-20 06:39:17 UTC (rev 204)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/resources/algorithms.xsd 2008-11-20 07:18:44 UTC (rev 205)
@@ -4,10 +4,22 @@
xmlns="http://pixelle.mebigfatguy.com/0.1.0"
elementFormDefault="qualified">
<xsd:complexType name="AlgorithmsClass">
+ <xsd:sequence>
+ <xsd:element maxOccurs="2" minOccurs="2" name="type" type="TypeClass"/>
+ </xsd:sequence>
+ </xsd:complexType>
+ <xsd:complexType name="TypeClass">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="1" name="group" type="GroupClass"/>
</xsd:sequence>
+ <xsd:attribute name="name" type="TypeNameClass" use="required"/>
</xsd:complexType>
+ <xsd:simpleType name="TypeNameClass">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="RGB"/>
+ <xsd:enumeration value="Grayscale"/>
+ </xsd:restriction>
+ </xsd:simpleType>
<xsd:complexType name="GroupClass">
<xsd:sequence>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="algorithm" type="AlgorithmClass"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|