From b6bb49055782c29c9d6e8927f345d23f05fb26e9 Mon Sep 17 00:00:00 2001
From: Clemens Wrzodek
Date: Mon, 4 Jul 2011 15:24:51 +0000
Subject: [PATCH] Moved static variables from the KEGGtranslator interface to
the actual main class "Translator.java".
---
src/de/zbit/kegg/Translator.java | 44 +++++++++++++++----
src/de/zbit/kegg/ext/RestrictedEditMode.java | 4 +-
.../zbit/kegg/ext/TranslatorPanelOptions.java | 4 +-
src/de/zbit/kegg/gui/TranslatorPanel.java | 5 +--
src/de/zbit/kegg/gui/TranslatorUI.java | 13 +++---
src/de/zbit/kegg/io/KEGG2jSBML.java | 15 ++++---
src/de/zbit/kegg/io/KEGG2yGraph.java | 13 +++---
src/de/zbit/kegg/io/KEGGtranslator.java | 23 ----------
src/de/zbit/kegg/io/YFilesWriter.java | 6 ++-
9 files changed, 67 insertions(+), 60 deletions(-)
diff --git a/src/de/zbit/kegg/Translator.java b/src/de/zbit/kegg/Translator.java
index 69aa087..089d562 100644
--- a/src/de/zbit/kegg/Translator.java
+++ b/src/de/zbit/kegg/Translator.java
@@ -56,11 +56,39 @@
* @version $Rev$
*/
public class Translator {
+
+ /**
+ * Filename of the KEGG cache file (implemented just
+ * like the browser cache). Must be loaded upon start
+ * and saved upon exit.
+ */
+ public final static String cacheFileName = "keggdb.dat";
+
+ /**
+ * Filename of the KEGG function cache file (implemented just
+ * like the browser cache). Must be loaded upon start
+ * and saved upon exit.
+ */
+ public final static String cacheFunctionFileName = "keggfc.dat";
+
+ /**
+ * The name of the application.
+ * Removed the final attribute, such that referencing applications can still change this.
+ */
+ public static String APPLICATION_NAME = "KEGGtranslator";
+
+ /**
+ * Version number of this translator
+ */
+ public static final String VERSION_NUMBER = "1.2.0";
+
+
/**
* The cache to be used by all KEGG interacting classes.
* Access via {@link #getManager()}.
*/
private static KeggInfoManagement manager=null;
+
/**
* The cache to be used by all KEGG-Functions interacting classes.
* Access via {@link #getFunctionManager()}.
@@ -201,14 +229,14 @@ public static boolean translate(Format format, String input, String output)
public synchronized static KeggInfoManagement getManager() {
// Try to load from cache file
- if (manager==null && new File(KEGGtranslator.cacheFileName).exists() && new File(KEGGtranslator.cacheFileName).length() > 0) {
+ if (manager==null && new File(Translator.cacheFileName).exists() && new File(Translator.cacheFileName).length() > 0) {
try {
- manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(KEGGtranslator.cacheFileName);
+ manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(Translator.cacheFileName);
} catch (Throwable e) { // IOException or class cast, if class is moved.
e.printStackTrace();
// Delete invalid cache file
try {
- File f = new File(KEGGtranslator.cacheFileName);
+ File f = new File(Translator.cacheFileName);
if (f.exists() && f.canRead()) {
System.out.println("Deleting invalid cache file " + f.getName());
f.delete();
@@ -229,15 +257,15 @@ public synchronized static KeggInfoManagement getManager() {
public synchronized static KeggFunctionManagement getFunctionManager() {
// Try to load from cache file
- if (managerFunction==null && new File(KEGGtranslator.cacheFunctionFileName).exists() && new File(KEGGtranslator.cacheFunctionFileName).length() > 0) {
+ if (managerFunction==null && new File(Translator.cacheFunctionFileName).exists() && new File(Translator.cacheFunctionFileName).length() > 0) {
try {
- managerFunction = (KeggFunctionManagement) KeggFunctionManagement.loadFromFilesystem(KEGGtranslator.cacheFunctionFileName);
+ managerFunction = (KeggFunctionManagement) KeggFunctionManagement.loadFromFilesystem(Translator.cacheFunctionFileName);
} catch (Throwable e) { // IOException or class cast, if class is moved.
e.printStackTrace();
// Delete invalid cache file
try {
- File f = new File(KEGGtranslator.cacheFunctionFileName);
+ File f = new File(Translator.cacheFunctionFileName);
if (f.exists() && f.canRead()) {
System.out.println("Deleting invalid cache file " + f.getName());
f.delete();
@@ -259,10 +287,10 @@ public synchronized static KeggFunctionManagement getFunctionManager() {
*/
public synchronized static void saveCache() {
if (manager!=null && manager.hasChanged()) {
- KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, manager);
+ KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, manager);
}
if (managerFunction!=null && managerFunction.isCacheChangedSinceLastLoading()) {
- KeggFunctionManagement.saveToFilesystem(KEGGtranslator.cacheFunctionFileName, managerFunction);
+ KeggFunctionManagement.saveToFilesystem(Translator.cacheFunctionFileName, managerFunction);
}
}
diff --git a/src/de/zbit/kegg/ext/RestrictedEditMode.java b/src/de/zbit/kegg/ext/RestrictedEditMode.java
index 33f49c9..6d099fd 100644
--- a/src/de/zbit/kegg/ext/RestrictedEditMode.java
+++ b/src/de/zbit/kegg/ext/RestrictedEditMode.java
@@ -70,10 +70,10 @@
import y.view.Overview;
import de.zbit.gui.GUITools;
import de.zbit.gui.SystemBrowser;
+import de.zbit.kegg.Translator;
import de.zbit.kegg.TranslatorTools;
import de.zbit.kegg.io.KEGG2jSBML;
import de.zbit.kegg.io.KEGG2yGraph;
-import de.zbit.kegg.io.KEGGtranslator;
import de.zbit.util.EscapeChars;
import de.zbit.util.StringUtil;
@@ -231,7 +231,7 @@ public void mouseClicked(double x, double y) {
String kgId = TranslatorTools.getKeggIDs(n);
if (kgId.toLowerCase().startsWith("path:")) {
int ret = GUITools.showQuestionMessage(null, "Do you want to download and open the referenced pathway in a new tab?",
- KEGGtranslator.APPLICATION_NAME, new String[]{"Yes", "No"});
+ Translator.APPLICATION_NAME, new String[]{"Yes", "No"});
if (ret==0) {
ActionEvent e = new ActionEvent(kgId.trim().substring(5).toLowerCase(), JOptionPane.OK_OPTION, OPEN_PATHWAY);
aListener.actionPerformed(e);
diff --git a/src/de/zbit/kegg/ext/TranslatorPanelOptions.java b/src/de/zbit/kegg/ext/TranslatorPanelOptions.java
index e02c62d..ffe1159 100644
--- a/src/de/zbit/kegg/ext/TranslatorPanelOptions.java
+++ b/src/de/zbit/kegg/ext/TranslatorPanelOptions.java
@@ -20,8 +20,8 @@
*/
package de.zbit.kegg.ext;
+import de.zbit.kegg.Translator;
import de.zbit.kegg.gui.TranslatorPanel;
-import de.zbit.kegg.io.KEGGtranslator;
import de.zbit.util.prefs.KeyProvider;
import de.zbit.util.prefs.Option;
import de.zbit.util.prefs.OptionGroup;
@@ -39,7 +39,7 @@ public abstract interface TranslatorPanelOptions extends KeyProvider{
* as background image.
*/
public static final Option SHOW_LOGO_IN_GRAPH_BACKGROUND = new Option("SHOW_LOGO_IN_GRAPH_BACKGROUND",Boolean.class,
- "If true, shows the " + KEGGtranslator.APPLICATION_NAME + " logo in the background of each graph.", false);
+ "If true, shows the " + Translator.APPLICATION_NAME + " logo in the background of each graph.", false);
/**
* Shows an overview and navigation panel in every graph frame.
diff --git a/src/de/zbit/kegg/gui/TranslatorPanel.java b/src/de/zbit/kegg/gui/TranslatorPanel.java
index 814885d..e90a784 100644
--- a/src/de/zbit/kegg/gui/TranslatorPanel.java
+++ b/src/de/zbit/kegg/gui/TranslatorPanel.java
@@ -72,7 +72,6 @@
import de.zbit.kegg.io.BatchKEGGtranslator;
import de.zbit.kegg.io.KEGG2jSBML;
import de.zbit.kegg.io.KEGG2yGraph;
-import de.zbit.kegg.io.KEGGtranslator;
import de.zbit.kegg.io.KEGGtranslatorIOOptions;
import de.zbit.kegg.io.KEGGtranslatorIOOptions.Format;
import de.zbit.util.AbstractProgressBar;
@@ -431,7 +430,7 @@ private static AbstractProgressBar generateLoadingPanel(Container parent, String
} else {
// Display the panel in an jFrame
JDialog f = new JDialog();
- f.setTitle(KEGGtranslator.APPLICATION_NAME);
+ f.setTitle(Translator.APPLICATION_NAME);
f.setSize(panel.getPreferredSize());
f.setContentPane(panel);
f.setPreferredSize(panel.getPreferredSize());
@@ -604,7 +603,7 @@ public void updateButtons(JMenuBar menuBar) {
public void writeLaTeXReport(File targetFile) {
if (document==null) return;
if (!isSBML()) {
- GUITools.showMessage("This option is only available for SBML documents.", KEGGtranslator.APPLICATION_NAME);
+ GUITools.showMessage("This option is only available for SBML documents.", Translator.APPLICATION_NAME);
return;
}
diff --git a/src/de/zbit/kegg/gui/TranslatorUI.java b/src/de/zbit/kegg/gui/TranslatorUI.java
index 73ab7a5..7b25090 100644
--- a/src/de/zbit/kegg/gui/TranslatorUI.java
+++ b/src/de/zbit/kegg/gui/TranslatorUI.java
@@ -62,7 +62,6 @@
import de.zbit.gui.prefs.PreferencesPanel;
import de.zbit.kegg.Translator;
import de.zbit.kegg.ext.RestrictedEditMode;
-import de.zbit.kegg.io.KEGGtranslator;
import de.zbit.kegg.io.KEGGtranslatorIOOptions;
import de.zbit.kegg.io.KEGGtranslatorIOOptions.Format;
import de.zbit.util.AbstractProgressBar;
@@ -105,7 +104,7 @@ public static enum Action implements ActionCommand {
/**
* This is coming from {@link RestrictedEditMode#OPEN_PATHWAY} and must be
* renamed accordingly. The source is a kegg pathway id that should be opened
- * as new tab, when this action is fired.
+ * as new tab, when this action is fired. This is an invisible action.
*/
OPEN_PATHWAY,
/**
@@ -325,7 +324,7 @@ private void createNewTab(File inFile, String format) {
if (inFile!=null) {
message = '\'' + inFile.getName() + "' is no valid input file.";
}
- JOptionPane.showMessageDialog(this, message, KEGGtranslator.APPLICATION_NAME, JOptionPane.WARNING_MESSAGE);
+ JOptionPane.showMessageDialog(this, message, Translator.APPLICATION_NAME, JOptionPane.WARNING_MESSAGE);
} else {
Format f = null;
try {
@@ -333,7 +332,7 @@ private void createNewTab(File inFile, String format) {
} catch (Throwable exc) {
exc.printStackTrace();
JOptionPane.showMessageDialog(this, '\'' + format + "' is no valid output format.",
- KEGGtranslator.APPLICATION_NAME, JOptionPane.WARNING_MESSAGE);
+ Translator.APPLICATION_NAME, JOptionPane.WARNING_MESSAGE);
}
if (f != null) {
// Tanslate and add tab.
@@ -476,7 +475,7 @@ public File[] openFile(File... files) {
if ( askOutputFormat || (format == null) || (format.length() < 1)) {
JLabeledComponent outputFormat = (JLabeledComponent) PreferencesPanel.getJComponentForOption(KEGGtranslatorIOOptions.FORMAT, prefsIO, null);
outputFormat.setTitle("Please select the output format");
- JOptionPane.showMessageDialog(this, outputFormat, KEGGtranslator.APPLICATION_NAME, JOptionPane.QUESTION_MESSAGE);
+ JOptionPane.showMessageDialog(this, outputFormat, Translator.APPLICATION_NAME, JOptionPane.QUESTION_MESSAGE);
format = outputFormat.getSelectedItem().toString();
}
@@ -718,7 +717,7 @@ public URL getURLOnlineHelp() {
* @see de.zbit.gui.BaseFrame#getApplicationName()
*/
public String getApplicationName() {
- return KEGGtranslator.APPLICATION_NAME;
+ return Translator.APPLICATION_NAME;
}
/*
@@ -727,7 +726,7 @@ public String getApplicationName() {
* @see de.zbit.gui.BaseFrame#getDottedVersionNumber()
*/
public String getDottedVersionNumber() {
- return KEGGtranslator.VERSION_NUMBER;
+ return Translator.VERSION_NUMBER;
}
/*
diff --git a/src/de/zbit/kegg/io/KEGG2jSBML.java b/src/de/zbit/kegg/io/KEGG2jSBML.java
index ae3a825..4e1d473 100644
--- a/src/de/zbit/kegg/io/KEGG2jSBML.java
+++ b/src/de/zbit/kegg/io/KEGG2jSBML.java
@@ -48,6 +48,7 @@
import de.zbit.kegg.KEGGtranslatorOptions;
import de.zbit.kegg.KeggInfoManagement;
import de.zbit.kegg.KeggInfos;
+import de.zbit.kegg.Translator;
import de.zbit.kegg.io.KEGGtranslatorIOOptions.Format;
import de.zbit.kegg.parser.KeggParser;
import de.zbit.kegg.parser.pathway.Entry;
@@ -315,7 +316,7 @@ public boolean writeToFile(SBMLDocument doc, String outFile) {
if (new File(outFile).exists()) lastFileWasOverwritten=true;
try {
SBMLWriter writer = new SBMLWriter();
- writer.write(doc, outFile, KEGGtranslator.APPLICATION_NAME, KEGGtranslator.VERSION_NUMBER);
+ writer.write(doc, outFile, Translator.APPLICATION_NAME, Translator.VERSION_NUMBER);
} catch (Exception e) {
e.printStackTrace();
return false;
@@ -434,7 +435,7 @@ protected SBMLDocument translateWithoutPreprocessing(Pathway p) {
notes.append("
");
}
notes.append(String.format("This file has been generated by %s version %s
\n",
- KEGGtranslator.APPLICATION_NAME, VERSION_NUMBER));
+ Translator.APPLICATION_NAME, Translator.VERSION_NUMBER));
// Save all reaction modifiers in a list. String = reaction id.
SortedArrayList> reactionModifiers = new SortedArrayList>();
@@ -1177,9 +1178,9 @@ public static void main(String[] args) throws IOException {
// Speedup Kegg2SBML by loading alredy queried objects. Reduces network
// load and heavily reduces computation time.
AbstractKEGGtranslator k2s;
- if (new File(KEGGtranslator.cacheFileName).exists()
- && new File(KEGGtranslator.cacheFileName).length() > 0) {
- KeggInfoManagement manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(KEGGtranslator.cacheFileName);
+ if (new File(Translator.cacheFileName).exists()
+ && new File(Translator.cacheFileName).length() > 0) {
+ KeggInfoManagement manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(Translator.cacheFileName);
k2s = new KEGG2jSBML(manager);
} else {
k2s = new KEGG2jSBML();
@@ -1211,7 +1212,7 @@ && new File(KEGGtranslator.cacheFileName).length() > 0) {
// Remember already queried objects (save cache)
if (k2s.getKeggInfoManager().hasChanged()) {
- KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, k2s.getKeggInfoManager());
+ KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, k2s.getKeggInfoManager());
}
return;
@@ -1228,7 +1229,7 @@ && new File(KEGGtranslator.cacheFileName).length() > 0) {
// Remember already queried objects
if (k2s.getKeggInfoManager().hasChanged()) {
- KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, k2s.getKeggInfoManager());
+ KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, k2s.getKeggInfoManager());
}
} catch (Exception e) {
diff --git a/src/de/zbit/kegg/io/KEGG2yGraph.java b/src/de/zbit/kegg/io/KEGG2yGraph.java
index 4423046..de1dd85 100644
--- a/src/de/zbit/kegg/io/KEGG2yGraph.java
+++ b/src/de/zbit/kegg/io/KEGG2yGraph.java
@@ -69,9 +69,10 @@
import y.view.ShapeNodeRealizer;
import y.view.hierarchy.GroupNodeRealizer;
import y.view.hierarchy.HierarchyManager;
+import de.zbit.kegg.KEGGtranslatorOptions;
import de.zbit.kegg.KeggInfoManagement;
import de.zbit.kegg.KeggInfos;
-import de.zbit.kegg.KEGGtranslatorOptions;
+import de.zbit.kegg.Translator;
import de.zbit.kegg.ext.GenericDataMap;
import de.zbit.kegg.io.KEGGtranslatorIOOptions.Format;
import de.zbit.kegg.parser.KeggParser;
@@ -1202,9 +1203,9 @@ public static KEGG2yGraph createKEGG2YGF(KeggInfoManagement manager) {
*/
public static void main(String[] args) throws IOException {
KeggInfoManagement manager;
- if (new File(KEGGtranslator.cacheFileName).exists()
- && new File(KEGGtranslator.cacheFileName).length() > 0) {
- manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(KEGGtranslator.cacheFileName);
+ if (new File(Translator.cacheFileName).exists()
+ && new File(Translator.cacheFileName).length() > 0) {
+ manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(Translator.cacheFileName);
} else {
manager = new KeggInfoManagement();
}
@@ -1236,7 +1237,7 @@ && new File(KEGGtranslator.cacheFileName).length() > 0) {
// Remember already queried objects (save cache)
if (k2g.getKeggInfoManager().hasChanged()) {
- KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, k2g.getKeggInfoManager());
+ KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, k2g.getKeggInfoManager());
}
return;
@@ -1253,7 +1254,7 @@ && new File(KEGGtranslator.cacheFileName).length() > 0) {
// Remember already queried objects
if (k2g.getKeggInfoManager().hasChanged()) {
- KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, k2g.getKeggInfoManager());
+ KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, k2g.getKeggInfoManager());
}
} catch (Exception e) {
diff --git a/src/de/zbit/kegg/io/KEGGtranslator.java b/src/de/zbit/kegg/io/KEGGtranslator.java
index 6cec1d0..65bf4f4 100644
--- a/src/de/zbit/kegg/io/KEGGtranslator.java
+++ b/src/de/zbit/kegg/io/KEGGtranslator.java
@@ -31,29 +31,6 @@
*/
public interface KEGGtranslator {
- /**
- * The name of the application.
- * Removed the final attribute, such that referencing applications can still change this.
- */
- public static String APPLICATION_NAME = "KEGGtranslator";
-
- /**
- * Version number of this translator
- */
- public static final String VERSION_NUMBER = "1.2.0";
-
- /**
- * Filename of the KEGG cache file (implemented just
- * like the browser cache). Must be loaded upon start
- * and saved upon exit.
- */
- public static String cacheFileName = "keggdb.dat";
- /**
- * Filename of the KEGG function cache file (implemented just
- * like the browser cache). Must be loaded upon start
- * and saved upon exit.
- */
- public static String cacheFunctionFileName = "keggfc.dat";
/**
* Translate a given KEGG Pathway and write it in the new format to outfile.
diff --git a/src/de/zbit/kegg/io/YFilesWriter.java b/src/de/zbit/kegg/io/YFilesWriter.java
index e3a1e13..d88dfe2 100644
--- a/src/de/zbit/kegg/io/YFilesWriter.java
+++ b/src/de/zbit/kegg/io/YFilesWriter.java
@@ -31,6 +31,8 @@
import java.util.HashMap;
import java.util.Map;
+import de.zbit.kegg.Translator;
+
/**
* This class creates an {@link OutputStream} that can be used with
* the yFiles Java library. It ensures that KEGGtranslator name
@@ -72,8 +74,8 @@ public YFilesWriter(OutputStream out) {
*
* such that no notes of yFiles are being written to the file.
*/
- toReplace.put("yFiles", KEGGtranslator.APPLICATION_NAME);
- toReplace.put(y.util.YVersion.currentVersionString(), KEGGtranslator.VERSION_NUMBER);
+ toReplace.put("yFiles", Translator.APPLICATION_NAME);
+ toReplace.put(y.util.YVersion.currentVersionString(), Translator.VERSION_NUMBER);
realOut = out;