Skip to content

Commit b6bb490

Browse files
committed
Moved static variables from the KEGGtranslator interface to the actual main class "Translator.java".
1 parent a954aa6 commit b6bb490

File tree

9 files changed

+67
-60
lines changed

9 files changed

+67
-60
lines changed

src/de/zbit/kegg/Translator.java

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,39 @@
5656
* @version $Rev$
5757
*/
5858
public class Translator {
59+
60+
/**
61+
* Filename of the KEGG cache file (implemented just
62+
* like the browser cache). Must be loaded upon start
63+
* and saved upon exit.
64+
*/
65+
public final static String cacheFileName = "keggdb.dat";
66+
67+
/**
68+
* Filename of the KEGG function cache file (implemented just
69+
* like the browser cache). Must be loaded upon start
70+
* and saved upon exit.
71+
*/
72+
public final static String cacheFunctionFileName = "keggfc.dat";
73+
74+
/**
75+
* The name of the application.
76+
* Removed the final attribute, such that referencing applications can still change this.
77+
*/
78+
public static String APPLICATION_NAME = "KEGGtranslator";
79+
80+
/**
81+
* Version number of this translator
82+
*/
83+
public static final String VERSION_NUMBER = "1.2.0";
84+
85+
5986
/**
6087
* The cache to be used by all KEGG interacting classes.
6188
* Access via {@link #getManager()}.
6289
*/
6390
private static KeggInfoManagement manager=null;
91+
6492
/**
6593
* The cache to be used by all KEGG-Functions interacting classes.
6694
* Access via {@link #getFunctionManager()}.
@@ -201,14 +229,14 @@ public static boolean translate(Format format, String input, String output)
201229
public synchronized static KeggInfoManagement getManager() {
202230

203231
// Try to load from cache file
204-
if (manager==null && new File(KEGGtranslator.cacheFileName).exists() && new File(KEGGtranslator.cacheFileName).length() > 0) {
232+
if (manager==null && new File(Translator.cacheFileName).exists() && new File(Translator.cacheFileName).length() > 0) {
205233
try {
206-
manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(KEGGtranslator.cacheFileName);
234+
manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(Translator.cacheFileName);
207235
} catch (Throwable e) { // IOException or class cast, if class is moved.
208236
e.printStackTrace();
209237
// Delete invalid cache file
210238
try {
211-
File f = new File(KEGGtranslator.cacheFileName);
239+
File f = new File(Translator.cacheFileName);
212240
if (f.exists() && f.canRead()) {
213241
System.out.println("Deleting invalid cache file " + f.getName());
214242
f.delete();
@@ -229,15 +257,15 @@ public synchronized static KeggInfoManagement getManager() {
229257
public synchronized static KeggFunctionManagement getFunctionManager() {
230258

231259
// Try to load from cache file
232-
if (managerFunction==null && new File(KEGGtranslator.cacheFunctionFileName).exists() && new File(KEGGtranslator.cacheFunctionFileName).length() > 0) {
260+
if (managerFunction==null && new File(Translator.cacheFunctionFileName).exists() && new File(Translator.cacheFunctionFileName).length() > 0) {
233261
try {
234-
managerFunction = (KeggFunctionManagement) KeggFunctionManagement.loadFromFilesystem(KEGGtranslator.cacheFunctionFileName);
262+
managerFunction = (KeggFunctionManagement) KeggFunctionManagement.loadFromFilesystem(Translator.cacheFunctionFileName);
235263
} catch (Throwable e) { // IOException or class cast, if class is moved.
236264
e.printStackTrace();
237265

238266
// Delete invalid cache file
239267
try {
240-
File f = new File(KEGGtranslator.cacheFunctionFileName);
268+
File f = new File(Translator.cacheFunctionFileName);
241269
if (f.exists() && f.canRead()) {
242270
System.out.println("Deleting invalid cache file " + f.getName());
243271
f.delete();
@@ -259,10 +287,10 @@ public synchronized static KeggFunctionManagement getFunctionManager() {
259287
*/
260288
public synchronized static void saveCache() {
261289
if (manager!=null && manager.hasChanged()) {
262-
KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, manager);
290+
KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, manager);
263291
}
264292
if (managerFunction!=null && managerFunction.isCacheChangedSinceLastLoading()) {
265-
KeggFunctionManagement.saveToFilesystem(KEGGtranslator.cacheFunctionFileName, managerFunction);
293+
KeggFunctionManagement.saveToFilesystem(Translator.cacheFunctionFileName, managerFunction);
266294
}
267295
}
268296

src/de/zbit/kegg/ext/RestrictedEditMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@
7070
import y.view.Overview;
7171
import de.zbit.gui.GUITools;
7272
import de.zbit.gui.SystemBrowser;
73+
import de.zbit.kegg.Translator;
7374
import de.zbit.kegg.TranslatorTools;
7475
import de.zbit.kegg.io.KEGG2jSBML;
7576
import de.zbit.kegg.io.KEGG2yGraph;
76-
import de.zbit.kegg.io.KEGGtranslator;
7777
import de.zbit.util.EscapeChars;
7878
import de.zbit.util.StringUtil;
7979

@@ -231,7 +231,7 @@ public void mouseClicked(double x, double y) {
231231
String kgId = TranslatorTools.getKeggIDs(n);
232232
if (kgId.toLowerCase().startsWith("path:")) {
233233
int ret = GUITools.showQuestionMessage(null, "Do you want to download and open the referenced pathway in a new tab?",
234-
KEGGtranslator.APPLICATION_NAME, new String[]{"Yes", "No"});
234+
Translator.APPLICATION_NAME, new String[]{"Yes", "No"});
235235
if (ret==0) {
236236
ActionEvent e = new ActionEvent(kgId.trim().substring(5).toLowerCase(), JOptionPane.OK_OPTION, OPEN_PATHWAY);
237237
aListener.actionPerformed(e);

src/de/zbit/kegg/ext/TranslatorPanelOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
package de.zbit.kegg.ext;
2222

23+
import de.zbit.kegg.Translator;
2324
import de.zbit.kegg.gui.TranslatorPanel;
24-
import de.zbit.kegg.io.KEGGtranslator;
2525
import de.zbit.util.prefs.KeyProvider;
2626
import de.zbit.util.prefs.Option;
2727
import de.zbit.util.prefs.OptionGroup;
@@ -39,7 +39,7 @@ public abstract interface TranslatorPanelOptions extends KeyProvider{
3939
* as background image.
4040
*/
4141
public static final Option<Boolean> SHOW_LOGO_IN_GRAPH_BACKGROUND = new Option<Boolean>("SHOW_LOGO_IN_GRAPH_BACKGROUND",Boolean.class,
42-
"If true, shows the " + KEGGtranslator.APPLICATION_NAME + " logo in the background of each graph.", false);
42+
"If true, shows the " + Translator.APPLICATION_NAME + " logo in the background of each graph.", false);
4343

4444
/**
4545
* Shows an overview and navigation panel in every graph frame.

src/de/zbit/kegg/gui/TranslatorPanel.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import de.zbit.kegg.io.BatchKEGGtranslator;
7373
import de.zbit.kegg.io.KEGG2jSBML;
7474
import de.zbit.kegg.io.KEGG2yGraph;
75-
import de.zbit.kegg.io.KEGGtranslator;
7675
import de.zbit.kegg.io.KEGGtranslatorIOOptions;
7776
import de.zbit.kegg.io.KEGGtranslatorIOOptions.Format;
7877
import de.zbit.util.AbstractProgressBar;
@@ -431,7 +430,7 @@ private static AbstractProgressBar generateLoadingPanel(Container parent, String
431430
} else {
432431
// Display the panel in an jFrame
433432
JDialog f = new JDialog();
434-
f.setTitle(KEGGtranslator.APPLICATION_NAME);
433+
f.setTitle(Translator.APPLICATION_NAME);
435434
f.setSize(panel.getPreferredSize());
436435
f.setContentPane(panel);
437436
f.setPreferredSize(panel.getPreferredSize());
@@ -604,7 +603,7 @@ public void updateButtons(JMenuBar menuBar) {
604603
public void writeLaTeXReport(File targetFile) {
605604
if (document==null) return;
606605
if (!isSBML()) {
607-
GUITools.showMessage("This option is only available for SBML documents.", KEGGtranslator.APPLICATION_NAME);
606+
GUITools.showMessage("This option is only available for SBML documents.", Translator.APPLICATION_NAME);
608607
return;
609608
}
610609

src/de/zbit/kegg/gui/TranslatorUI.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import de.zbit.gui.prefs.PreferencesPanel;
6363
import de.zbit.kegg.Translator;
6464
import de.zbit.kegg.ext.RestrictedEditMode;
65-
import de.zbit.kegg.io.KEGGtranslator;
6665
import de.zbit.kegg.io.KEGGtranslatorIOOptions;
6766
import de.zbit.kegg.io.KEGGtranslatorIOOptions.Format;
6867
import de.zbit.util.AbstractProgressBar;
@@ -105,7 +104,7 @@ public static enum Action implements ActionCommand {
105104
/**
106105
* This is coming from {@link RestrictedEditMode#OPEN_PATHWAY} and must be
107106
* renamed accordingly. The source is a kegg pathway id that should be opened
108-
* as new tab, when this action is fired.
107+
* as new tab, when this action is fired. This is an invisible action.
109108
*/
110109
OPEN_PATHWAY,
111110
/**
@@ -325,15 +324,15 @@ private void createNewTab(File inFile, String format) {
325324
if (inFile!=null) {
326325
message = '\'' + inFile.getName() + "' is no valid input file.";
327326
}
328-
JOptionPane.showMessageDialog(this, message, KEGGtranslator.APPLICATION_NAME, JOptionPane.WARNING_MESSAGE);
327+
JOptionPane.showMessageDialog(this, message, Translator.APPLICATION_NAME, JOptionPane.WARNING_MESSAGE);
329328
} else {
330329
Format f = null;
331330
try {
332331
f = Format.valueOf(format);
333332
} catch (Throwable exc) {
334333
exc.printStackTrace();
335334
JOptionPane.showMessageDialog(this, '\'' + format + "' is no valid output format.",
336-
KEGGtranslator.APPLICATION_NAME, JOptionPane.WARNING_MESSAGE);
335+
Translator.APPLICATION_NAME, JOptionPane.WARNING_MESSAGE);
337336
}
338337
if (f != null) {
339338
// Tanslate and add tab.
@@ -476,7 +475,7 @@ public File[] openFile(File... files) {
476475
if ( askOutputFormat || (format == null) || (format.length() < 1)) {
477476
JLabeledComponent outputFormat = (JLabeledComponent) PreferencesPanel.getJComponentForOption(KEGGtranslatorIOOptions.FORMAT, prefsIO, null);
478477
outputFormat.setTitle("Please select the output format");
479-
JOptionPane.showMessageDialog(this, outputFormat, KEGGtranslator.APPLICATION_NAME, JOptionPane.QUESTION_MESSAGE);
478+
JOptionPane.showMessageDialog(this, outputFormat, Translator.APPLICATION_NAME, JOptionPane.QUESTION_MESSAGE);
480479
format = outputFormat.getSelectedItem().toString();
481480
}
482481

@@ -718,7 +717,7 @@ public URL getURLOnlineHelp() {
718717
* @see de.zbit.gui.BaseFrame#getApplicationName()
719718
*/
720719
public String getApplicationName() {
721-
return KEGGtranslator.APPLICATION_NAME;
720+
return Translator.APPLICATION_NAME;
722721
}
723722

724723
/*
@@ -727,7 +726,7 @@ public String getApplicationName() {
727726
* @see de.zbit.gui.BaseFrame#getDottedVersionNumber()
728727
*/
729728
public String getDottedVersionNumber() {
730-
return KEGGtranslator.VERSION_NUMBER;
729+
return Translator.VERSION_NUMBER;
731730
}
732731

733732
/*

src/de/zbit/kegg/io/KEGG2jSBML.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import de.zbit.kegg.KEGGtranslatorOptions;
4949
import de.zbit.kegg.KeggInfoManagement;
5050
import de.zbit.kegg.KeggInfos;
51+
import de.zbit.kegg.Translator;
5152
import de.zbit.kegg.io.KEGGtranslatorIOOptions.Format;
5253
import de.zbit.kegg.parser.KeggParser;
5354
import de.zbit.kegg.parser.pathway.Entry;
@@ -315,7 +316,7 @@ public boolean writeToFile(SBMLDocument doc, String outFile) {
315316
if (new File(outFile).exists()) lastFileWasOverwritten=true;
316317
try {
317318
SBMLWriter writer = new SBMLWriter();
318-
writer.write(doc, outFile, KEGGtranslator.APPLICATION_NAME, KEGGtranslator.VERSION_NUMBER);
319+
writer.write(doc, outFile, Translator.APPLICATION_NAME, Translator.VERSION_NUMBER);
319320
} catch (Exception e) {
320321
e.printStackTrace();
321322
return false;
@@ -434,7 +435,7 @@ protected SBMLDocument translateWithoutPreprocessing(Pathway p) {
434435
notes.append("</p>");
435436
}
436437
notes.append(String.format("<div align=\"right\"><i><small>This file has been generated by %s version %s</small></i></div><br/>\n",
437-
KEGGtranslator.APPLICATION_NAME, VERSION_NUMBER));
438+
Translator.APPLICATION_NAME, Translator.VERSION_NUMBER));
438439

439440
// Save all reaction modifiers in a list. String = reaction id.
440441
SortedArrayList<Info<String, ModifierSpeciesReference>> reactionModifiers = new SortedArrayList<Info<String, ModifierSpeciesReference>>();
@@ -1177,9 +1178,9 @@ public static void main(String[] args) throws IOException {
11771178
// Speedup Kegg2SBML by loading alredy queried objects. Reduces network
11781179
// load and heavily reduces computation time.
11791180
AbstractKEGGtranslator<SBMLDocument> k2s;
1180-
if (new File(KEGGtranslator.cacheFileName).exists()
1181-
&& new File(KEGGtranslator.cacheFileName).length() > 0) {
1182-
KeggInfoManagement manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(KEGGtranslator.cacheFileName);
1181+
if (new File(Translator.cacheFileName).exists()
1182+
&& new File(Translator.cacheFileName).length() > 0) {
1183+
KeggInfoManagement manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(Translator.cacheFileName);
11831184
k2s = new KEGG2jSBML(manager);
11841185
} else {
11851186
k2s = new KEGG2jSBML();
@@ -1211,7 +1212,7 @@ && new File(KEGGtranslator.cacheFileName).length() > 0) {
12111212

12121213
// Remember already queried objects (save cache)
12131214
if (k2s.getKeggInfoManager().hasChanged()) {
1214-
KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, k2s.getKeggInfoManager());
1215+
KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, k2s.getKeggInfoManager());
12151216
}
12161217

12171218
return;
@@ -1228,7 +1229,7 @@ && new File(KEGGtranslator.cacheFileName).length() > 0) {
12281229

12291230
// Remember already queried objects
12301231
if (k2s.getKeggInfoManager().hasChanged()) {
1231-
KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, k2s.getKeggInfoManager());
1232+
KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, k2s.getKeggInfoManager());
12321233
}
12331234

12341235
} catch (Exception e) {

src/de/zbit/kegg/io/KEGG2yGraph.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@
6969
import y.view.ShapeNodeRealizer;
7070
import y.view.hierarchy.GroupNodeRealizer;
7171
import y.view.hierarchy.HierarchyManager;
72+
import de.zbit.kegg.KEGGtranslatorOptions;
7273
import de.zbit.kegg.KeggInfoManagement;
7374
import de.zbit.kegg.KeggInfos;
74-
import de.zbit.kegg.KEGGtranslatorOptions;
75+
import de.zbit.kegg.Translator;
7576
import de.zbit.kegg.ext.GenericDataMap;
7677
import de.zbit.kegg.io.KEGGtranslatorIOOptions.Format;
7778
import de.zbit.kegg.parser.KeggParser;
@@ -1202,9 +1203,9 @@ public static KEGG2yGraph createKEGG2YGF(KeggInfoManagement manager) {
12021203
*/
12031204
public static void main(String[] args) throws IOException {
12041205
KeggInfoManagement manager;
1205-
if (new File(KEGGtranslator.cacheFileName).exists()
1206-
&& new File(KEGGtranslator.cacheFileName).length() > 0) {
1207-
manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(KEGGtranslator.cacheFileName);
1206+
if (new File(Translator.cacheFileName).exists()
1207+
&& new File(Translator.cacheFileName).length() > 0) {
1208+
manager = (KeggInfoManagement) KeggInfoManagement.loadFromFilesystem(Translator.cacheFileName);
12081209
} else {
12091210
manager = new KeggInfoManagement();
12101211
}
@@ -1236,7 +1237,7 @@ && new File(KEGGtranslator.cacheFileName).length() > 0) {
12361237

12371238
// Remember already queried objects (save cache)
12381239
if (k2g.getKeggInfoManager().hasChanged()) {
1239-
KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, k2g.getKeggInfoManager());
1240+
KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, k2g.getKeggInfoManager());
12401241
}
12411242

12421243
return;
@@ -1253,7 +1254,7 @@ && new File(KEGGtranslator.cacheFileName).length() > 0) {
12531254

12541255
// Remember already queried objects
12551256
if (k2g.getKeggInfoManager().hasChanged()) {
1256-
KeggInfoManagement.saveToFilesystem(KEGGtranslator.cacheFileName, k2g.getKeggInfoManager());
1257+
KeggInfoManagement.saveToFilesystem(Translator.cacheFileName, k2g.getKeggInfoManager());
12571258
}
12581259

12591260
} catch (Exception e) {

src/de/zbit/kegg/io/KEGGtranslator.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,6 @@
3131
*/
3232
public interface KEGGtranslator {
3333

34-
/**
35-
* The name of the application.
36-
* Removed the final attribute, such that referencing applications can still change this.
37-
*/
38-
public static String APPLICATION_NAME = "KEGGtranslator";
39-
40-
/**
41-
* Version number of this translator
42-
*/
43-
public static final String VERSION_NUMBER = "1.2.0";
44-
45-
/**
46-
* Filename of the KEGG cache file (implemented just
47-
* like the browser cache). Must be loaded upon start
48-
* and saved upon exit.
49-
*/
50-
public static String cacheFileName = "keggdb.dat";
51-
/**
52-
* Filename of the KEGG function cache file (implemented just
53-
* like the browser cache). Must be loaded upon start
54-
* and saved upon exit.
55-
*/
56-
public static String cacheFunctionFileName = "keggfc.dat";
5734

5835
/**
5936
* Translate a given KEGG Pathway and write it in the new format to outfile.

src/de/zbit/kegg/io/YFilesWriter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import java.util.HashMap;
3232
import java.util.Map;
3333

34+
import de.zbit.kegg.Translator;
35+
3436
/**
3537
* This class creates an {@link OutputStream} that can be used with
3638
* the yFiles Java library. It ensures that KEGGtranslator name
@@ -72,8 +74,8 @@ public YFilesWriter(OutputStream out) {
7274
* </ul>
7375
* such that no notes of yFiles are being written to the file.
7476
*/
75-
toReplace.put("yFiles", KEGGtranslator.APPLICATION_NAME);
76-
toReplace.put(y.util.YVersion.currentVersionString(), KEGGtranslator.VERSION_NUMBER);
77+
toReplace.put("yFiles", Translator.APPLICATION_NAME);
78+
toReplace.put(y.util.YVersion.currentVersionString(), Translator.VERSION_NUMBER);
7779

7880
realOut = out;
7981

0 commit comments

Comments
 (0)