[Pixelle-commit] SF.net SVN: pixelle:[283] trunk/pixelle/src/com/mebigfatguy/pixelle/ AlgorithmArch
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-07-18 19:55:19
|
Revision: 283
http://pixelle.svn.sourceforge.net/pixelle/?rev=283&view=rev
Author: dbrosius
Date: 2009-07-18 19:55:14 +0000 (Sat, 18 Jul 2009)
Log Message:
-----------
move settings to .mebigfatguy/pixelle
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java 2009-07-18 19:40:12 UTC (rev 282)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java 2009-07-18 19:55:14 UTC (rev 283)
@@ -60,12 +60,12 @@
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 = ".mebigfatguy/pixelle";
public static final String ALGORITHMS_FILE = "algorithms.xml";
-
-
+
+
private static AlgorithmArchiver archiver = new AlgorithmArchiver();
-
+
private final Map<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>> systemAlgorithms;
private final Map<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>> userAlgorithms;
@@ -75,19 +75,19 @@
loadSystemAlgorithms();
loadUserAlgorithms();
}
-
+
public static AlgorithmArchiver getArchiver() {
return archiver;
}
-
+
public JPopupMenu getAlgorithmDisplayPopup(ImageType imageType, ActionListener l) {
JPopupMenu m = new JPopupMenu(PixelleBundle.getString(PixelleBundle.PIXEL_ALGORITHM));
populateMenuAlgorithms(m, systemAlgorithms.get(imageType), l);
populateMenuAlgorithms(m, userAlgorithms.get(imageType), l);
-
+
return m;
}
-
+
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()) {
@@ -105,68 +105,69 @@
}
}
}
-
+
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)
+ if (algo != null) {
return algo;
+ }
}
}
-
+
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<PixelleComponent, String> algo = group.get(algorithmName);
if (algo == null) {
throw new IllegalArgumentException("Unknown algorithm name " + algorithmName);
}
-
+
return algo;
-
+
}
-
+
public String[] getUserGroups(ImageType imageType) {
Set<String> groups = new TreeSet<String>(userAlgorithms.get(imageType).keySet());
groups.remove(CURRENT);
return groups.toArray(new String[groups.size()]);
}
-
+
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<PixelleComponent, String>>();
type.put(groupName, group);
}
-
+
group.put(algorithmName, new EnumMap<PixelleComponent, String>(algorithm));
}
-
+
public void setCurrent(ImageType imageType, Map<PixelleComponent, String> algorithm) {
addAlgorithm(imageType, AlgorithmArchiver.CURRENT, AlgorithmArchiver.CURRENT, algorithm);
}
-
+
public Map<PixelleComponent, String> getCurrent(ImageType imageType) {
return getAlgorithm(imageType, AlgorithmArchiver.CURRENT, AlgorithmArchiver.CURRENT);
}
-
+
public void removeAlgorithm(ImageType imageType, String group, String name) {
Map<String, Map<String, Map<PixelleComponent, String>>> type = userAlgorithms.get(imageType);
if (type != null) {
@@ -176,7 +177,7 @@
}
}
}
-
+
public void save() {
OutputStream xmlOut = null;
try {
@@ -190,9 +191,9 @@
} finally {
Closer.close(xmlOut);
}
-
+
}
-
+
private void loadSystemAlgorithms() {
InputStream xmlIs = null;
try {
@@ -204,7 +205,7 @@
Closer.close(xmlIs);
}
}
-
+
private void loadUserAlgorithms() {
InputStream is = null;
try {
@@ -220,9 +221,9 @@
} finally {
Closer.close(is);
}
-
+
}
-
+
private void writeAlgorithms(OutputStream is, Map<ImageType, Map<String, Map<String, Map<PixelleComponent, String>>>> algorithms) throws IOException {
PrintWriter pw = null;
try {
@@ -230,15 +231,15 @@
pw.println("<algorithms xmlns='http://pixelle.mebigfatguy.com/" + Version.getVersion() + "'");
pw.println(" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'");
pw.println(" xsi:schemaLocation='/com/mebigfatguy/pixelle/resources/algorithms.xsd'>");
-
+
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<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(" " + XMLEncoder.xmlEncode(component.getValue()));
@@ -257,7 +258,7 @@
pw.close();
}
}
-
+
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() {
@@ -266,7 +267,7 @@
Map<PixelleComponent, String> currentAlgorithm = null;
String currentComponentName = null;
StringBuilder algorithmText = null;
-
+
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) {
if (TYPE.equals(localName)) {
@@ -283,14 +284,14 @@
algorithmText = new StringBuilder();
}
}
-
+
@Override
public void characters(char[] c, int start, int offset) {
if (currentComponentName != null) {
algorithmText.append(c, start, offset);
}
}
-
+
@Override
public void endElement(String uri, String localName, String qName) {
if (COMPONENT.equals(localName)) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|