Corrected and removed redundant error messages on resources not found.

This commit is contained in:
Marcel Kronfeld 2010-05-12 08:48:32 +00:00
parent ebe02870df
commit f29dae18c6
18 changed files with 180 additions and 297 deletions

View File

@ -96,17 +96,31 @@ public class EvAInfo {
try { try {
EVA_PROPERTIES = BasicResourceLoader.readProperties(EvAInfo.propertyFile); EVA_PROPERTIES = BasicResourceLoader.readProperties(EvAInfo.propertyFile);
} catch (Exception ex) { } catch (Exception ex) {
System.err.println("ERROR! Could not read the configuration file "+ EvAInfo.propertyFile); System.err.println(resourceNotFoundErrorMessage(EvAInfo.propertyFile));
System.err.println(ex.getMessage()); System.err.println(ex.getMessage());
System.exit(1); System.exit(1);
} }
File f=new File(EvAInfo.iconLocation); File f=new File(EvAInfo.iconLocation);
if (!f.exists()) { if (!f.exists()) {
System.err.println("Error: Could not find EvA2 resources. Did you copy the resources folder to working directory? (EvAInfo.static)"); throw new RuntimeException(resourceNotFoundErrorMessage(EvAInfo.iconLocation) + " (EvAInfo.static)");
// System.exit(2); // dont be as harsh right here - there will be plenty of exceptions later in the bad case... // System.exit(2); // dont be as harsh right here - there will be plenty of exceptions later in the bad case...
} }
} }
/**
* An eloquent error message in case a resource was not found - which was
* expected in the EvA2 resource directory.
* @param resourceName
* @return
*/
public static String resourceNotFoundErrorMessage(String resourceName) {
String cp = System.getProperty("java.class.path");
return "Could not find " + resourceName +
"\nPlease make resources folder available on the class path! " +
"Current class path is: " + cp +
"\nYou may copy it there or add the parent folder of resources/ to the class path.";
}
public static String getProperty(String key) { public static String getProperty(String key) {
String myVal = EVA_PROPERTIES.getProperty(key); String myVal = EVA_PROPERTIES.getProperty(key);
return myVal; return myVal;

View File

@ -282,12 +282,8 @@ public class EvAClient implements RemoteStateListener, Serializable {
if (withGUI ) { if (withGUI ) {
m_Frame = new JEFrame(EvAInfo.productName + " workbench"); m_Frame = new JEFrame(EvAInfo.productName + " workbench");
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
try {
m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
} catch (java.lang.NullPointerException e) {
System.err.println("Could not find EvA2 icon, please move resources folder to working directory!");
}
// m_Frame.setTitle(EvAInfo.productName + " workbench"); // m_Frame.setTitle(EvAInfo.productName + " workbench");
try { try {
@ -986,8 +982,7 @@ class SplashScreen extends Frame {
public void splash(){ public void splash(){
JWindow splashWindow = new JWindow(this); JWindow splashWindow = new JWindow(this);
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(imgLocation); byte[] bytes = loader.getBytesFromResourceLocation(imgLocation, true);
try {
ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)); ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes));
JLabel splashLabel = new JLabel(ii); JLabel splashLabel = new JLabel(ii);
splashWindow.add(splashLabel); splashWindow.add(splashLabel);
@ -995,9 +990,6 @@ class SplashScreen extends Frame {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
splashWindow.setLocation(screenSize.width / 2 - splashWindow.getSize().width / 2, screenSize.height / 2 - splashWindow.getSize().height / 2); splashWindow.setLocation(screenSize.width / 2 - splashWindow.getSize().width / 2, screenSize.height / 2 - splashWindow.getSize().height / 2);
splashWindow.setVisible(true); splashWindow.setVisible(true);
} catch (java.lang.NullPointerException e) {
System.err.println("Could not find EvA2 splash screen, please move resources folder to working directory!");
}
} }
} }

View File

@ -174,13 +174,8 @@ public class GenericOptimizationObjectivesEditor extends JPanel implements Prope
gbc.fill = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.REMAINDER;
gbc.gridx = 1; gbc.gridx = 1;
gbc.weightx = 1; gbc.weightx = 1;
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif"); bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true);
try {
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find Sub24 icon, please move resources folder to working directory!");
this.m_Delete[i] = new JButton("Sub");
}
this.m_Delete[i].addActionListener(deleteTarget); this.m_Delete[i].addActionListener(deleteTarget);
this.m_TargetList.add(this.m_Delete[i], gbc); this.m_TargetList.add(this.m_Delete[i], gbc);
} }

View File

@ -198,13 +198,8 @@ public class GenericOptimizationObjectivesWithParamEditor extends JPanel impleme
gbc.fill = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.REMAINDER;
gbc.gridx = 2; gbc.gridx = 2;
gbc.weightx = 1; gbc.weightx = 1;
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif"); bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true);
try {
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find Sub24 icon, please move resources folder to working directory!");
this.m_Delete[i] = new JButton("Sub");
}
this.m_Delete[i].addActionListener(deleteTarget); this.m_Delete[i].addActionListener(deleteTarget);
this.m_TargetList.add(this.m_Delete[i], gbc); this.m_TargetList.add(this.m_Delete[i], gbc);
} }

View File

@ -111,13 +111,9 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor
private JButton makeButtonWith(String iconSrc, String title) { private JButton makeButtonWith(String iconSrc, String title) {
JButton tmpB; JButton tmpB;
byte[] bytes; byte[] bytes;
bytes = BasicResourceLoader.instance().getBytesFromResourceLocation(iconSrc); bytes = BasicResourceLoader.instance().getBytesFromResourceLocation(iconSrc, false);
try { if (bytes!=null) tmpB = new JButton(title, new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
tmpB = new JButton(title, new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); else tmpB = new JButton(title);
} catch (java.lang.NullPointerException e) {
System.err.println("Could not find icon " + iconSrc + ", please move resources folder to working directory!");
tmpB = new JButton(title);
}
return tmpB; return tmpB;
} }
@ -172,7 +168,7 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor
this.m_ServerList.add(this.m_CPUs[i], gbc); this.m_ServerList.add(this.m_CPUs[i], gbc);
// The delete button // The delete button
setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.REMAINDER, 3, 10); setGBC(gbc, GridBagConstraints.WEST, GridBagConstraints.REMAINDER, 3, 10);
bytes = BasicResourceLoader.instance().getBytesFromResourceLocation("resources/images/Sub24.gif"); bytes = BasicResourceLoader.instance().getBytesFromResourceLocation("resources/images/Sub24.gif", true);
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
this.m_Delete[i].addActionListener(deleteServer); this.m_Delete[i].addActionListener(deleteServer);
this.m_ServerList.add(this.m_Delete[i], gbc); this.m_ServerList.add(this.m_Delete[i], gbc);

View File

@ -94,12 +94,8 @@ public class HtmlDemo {
} }
JFrame frame = new JFrame (m_name); JFrame frame = new JFrame (m_name);
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
try {
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
} catch (java.lang.NullPointerException e) {
System.err.println("Could not find EvA2 icon, please move resources folder to working directory!");
}
JScrollPane scroller = new JScrollPane(); JScrollPane scroller = new JScrollPane();
JViewport vp = scroller.getViewport(); JViewport vp = scroller.getViewport();
vp.add(m_html); vp.add(m_html);

View File

@ -107,12 +107,9 @@ Serializable {
m_TextArea.setCaretPosition(0); m_TextArea.setCaretPosition(0);
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
try {
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find EvA2 icon, please move resources folder to working directory!");
}
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
frame.dispose(); frame.dispose();

View File

@ -105,12 +105,8 @@ public class LogPanel extends JPanel {
final JFrame frame = new JFrame("Log_Panel_Test"); final JFrame frame = new JFrame("Log_Panel_Test");
frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().setLayout(new BorderLayout());
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
try {
frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find EvA2 icon, please move resources folder to working directory!");
}
LogPanel panel = new LogPanel(); LogPanel panel = new LogPanel();
frame.getContentPane().add(panel, BorderLayout.CENTER); frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.addWindowListener(new WindowAdapter() { frame.addWindowListener(new WindowAdapter() {

View File

@ -221,16 +221,8 @@ public class Plot implements PlotInterface, Serializable {
public void init() { public void init() {
m_Frame = new JEFrame("Plot: " + m_PlotName); m_Frame = new JEFrame("Plot: " + m_PlotName);
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
.getBytesFromResourceLocation(EvAInfo.iconLocation); m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
try {
m_Frame
.setIconImage(Toolkit.getDefaultToolkit()
.createImage(bytes));
} catch (java.lang.NullPointerException e) {
System.err
.println("Could not find EvA2 icon, please move resources folder to working directory!");
}
m_ButtonPanel = new JPanel(); m_ButtonPanel = new JPanel();
m_PlotArea = new FunctionArea(m_xname, m_yname); m_PlotArea = new FunctionArea(m_xname, m_yname);

View File

@ -35,12 +35,9 @@ public class PropertyDialog extends JEFrame {
public PropertyDialog (PropertyEditor editor,String Title, int x, int y) { public PropertyDialog (PropertyEditor editor,String Title, int x, int y) {
super(getFrameNameFromEditor(editor)); // that was the long class name !! super(getFrameNameFromEditor(editor)); // that was the long class name !!
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
try {
setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
} catch (java.lang.NullPointerException e) {
System.err.println("Could not find EvA2 icon, please move resources folder to working directory!");
}
//System.out.println("PropertyDialog.Constructor of "+ Title); //System.out.println("PropertyDialog.Constructor of "+ Title);
setDefaultCloseOperation(DISPOSE_ON_CLOSE); setDefaultCloseOperation(DISPOSE_ON_CLOSE);
getContentPane().setLayout(new BorderLayout()); getContentPane().setLayout(new BorderLayout());

View File

@ -126,12 +126,8 @@ public class TagEditor extends PropertyEditorSupport {
PropertyValueSelector ps = new PropertyValueSelector(ce); PropertyValueSelector ps = new PropertyValueSelector(ce);
JFrame f = new JFrame(); JFrame f = new JFrame();
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true);
try {
f.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); f.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find EvA2 icon, please move resources folder to working directory!");
}
f.addWindowListener(new WindowAdapter() { f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) { public void windowClosing(WindowEvent e) {
System.exit(0); System.exit(0);

View File

@ -55,14 +55,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
gbc.fill = GridBagConstraints.BOTH; gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = 100; gbc.weightx = 100;
tmpB = new JButton(); tmpB = new JButton();
try { bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_MOEA.gif", true);
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_MOEA.gif");
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
tmpB.setBackground(Color.WHITE); tmpB.setBackground(Color.WHITE);
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find MOCCO_MOEA icon, please move resources folder to working directory!");
tmpB.setText("Multi-Objective EA");
}
gbc.gridy = 0; gbc.gridy = 0;
gbc.gridx = 0; gbc.gridx = 0;
tmpP.add(tmpB, gbc); tmpP.add(tmpB, gbc);
@ -78,14 +73,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
" objectives."), gbc); " objectives."), gbc);
tmpB = new JButton(); tmpB = new JButton();
try { bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_GDF.gif", true);
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_GDF.gif");
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
tmpB.setBackground(Color.WHITE); tmpB.setBackground(Color.WHITE);
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find MOCCO_GDF icon, please move resources folder to working directory!");
tmpB.setText("Geoffrion-Dyer-Feinberg Meth.");
}
gbc.gridy = 1; gbc.gridy = 1;
gbc.gridx = 0; gbc.gridx = 0;
tmpP.add(tmpB, gbc); tmpP.add(tmpB, gbc);
@ -99,14 +89,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
this.m_Mocco.m_JPanelParameters.add(tmpP, BorderLayout.CENTER); this.m_Mocco.m_JPanelParameters.add(tmpP, BorderLayout.CENTER);
tmpB = new JButton(); tmpB = new JButton();
try { bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_STEP.gif", true);
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_STEP.gif");
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
tmpB.setBackground(Color.WHITE); tmpB.setBackground(Color.WHITE);
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find MOCCO_STEP icon, please move resources folder to working directory!");
tmpB.setText("STEP Method");
}
gbc.gridy = 2; gbc.gridy = 2;
gbc.gridx = 0; gbc.gridx = 0;
tmpP.add(tmpB, gbc); tmpP.add(tmpB, gbc);
@ -121,14 +106,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
" into a single objectives. The individual weights are also to be given by the DM."), gbc); " into a single objectives. The individual weights are also to be given by the DM."), gbc);
tmpB = new JButton(); tmpB = new JButton();
try { bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_REFP.gif", true);
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_REFP.gif");
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
tmpB.setBackground(Color.WHITE); tmpB.setBackground(Color.WHITE);
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find MOCCO_REFP icon, please move resources folder to working directory!");
tmpB.setText("Reference Point Method");
}
gbc.gridy = 3; gbc.gridy = 3;
gbc.gridx = 0; gbc.gridx = 0;
tmpP.add(tmpB, gbc); tmpP.add(tmpB, gbc);
@ -143,14 +123,9 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces
" same time."), gbc); " same time."), gbc);
tmpB = new JButton(); tmpB = new JButton();
try { bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_TBCH.gif", true);
bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_TBCH.gif");
tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
tmpB.setBackground(Color.WHITE); tmpB.setBackground(Color.WHITE);
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find MOCCO_TBCH icon, please move resources folder to working directory!");
tmpB.setText("Tchebycheff Method");
}
gbc.gridy = 4; gbc.gridy = 4;
gbc.gridx = 0; gbc.gridx = 0;
tmpB.addActionListener(choosenTBCH); tmpB.addActionListener(choosenTBCH);

View File

@ -50,32 +50,6 @@ public abstract class MOCCOPhase implements InterfaceProcessElement {
} }
}; };
// /** Fetch the alternatives for a given class
// * @param type The class to test
// * @return The class alternatives
// */
// public Vector getClassAlternatives4(String type) {
// String typeOptions = EvAClient.getProperty(type);
// Vector classes = new Vector();
// StringTokenizer st = new StringTokenizer(typeOptions, ", ");
// while (st.hasMoreTokens()) {
// String current = st.nextToken().trim();
// try {
// try {
// Class c = Class.forName(current);
// classes.addElement(current);
// } catch (java.lang.ClassNotFoundException et) {
// System.out.println("Could not find class for value " + current + " for type " + type);
// }
// } catch (Exception ex) {
// System.out.println("Couldn't load class with name: " + current + " for type " + type);
// System.out.println("ex:"+ex.getMessage());
// ex.printStackTrace();
// }
// }
// return classes;
// }
/** This method makes a helptext element similar to that used in EvA /** This method makes a helptext element similar to that used in EvA
* @param help The text to display * @param help The text to display
* @return the helptext component * @return the helptext component

View File

@ -201,13 +201,8 @@ public class PropertyCrossoverMixerEditor extends JPanel implements PropertyEdit
gbc.fill = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.REMAINDER;
gbc.gridx = 2; gbc.gridx = 2;
gbc.weightx = 1; gbc.weightx = 1;
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif"); bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true);
try {
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find sub24 icon, please move resources folder to working directory!");
this.m_Delete[i] = new JButton("Sub");
}
this.m_Delete[i].addActionListener(deleteTarget); this.m_Delete[i].addActionListener(deleteTarget);
this.m_TargetList.add(this.m_Delete[i], gbc); this.m_TargetList.add(this.m_Delete[i], gbc);
} }

View File

@ -176,13 +176,8 @@ public class PropertyMutationMixerEditor extends JPanel implements PropertyEdito
gbc.fill = GridBagConstraints.REMAINDER; gbc.fill = GridBagConstraints.REMAINDER;
gbc.gridx = 2; gbc.gridx = 2;
gbc.weightx = 1; gbc.weightx = 1;
bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif"); bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true);
try {
this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)));
} catch (java.lang.NullPointerException e) {
System.out.println("Could not find sub24 icon, please move resources folder to working directory!");
this.m_Delete[i] = new JButton("Sub");
}
this.m_Delete[i].addActionListener(deleteTarget); this.m_Delete[i].addActionListener(deleteTarget);
this.m_TargetList.add(this.m_Delete[i], gbc); this.m_TargetList.add(this.m_Delete[i], gbc);
} }

View File

@ -37,17 +37,17 @@ public class FileTools {
static public String[] loadStringsFromFile(String file) { static public String[] loadStringsFromFile(String file) {
String[] result = null; String[] result = null;
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte bytes[] = loader.getBytesFromResourceLocation(file); byte bytes[] = loader.getBytesFromResourceLocation(file, false);
if (bytes != null) { if (bytes != null) {
String data = new String(bytes); String data = new String(bytes);
result = data.split("\n"); result = data.split("\n");
} else { } else {
System.out.println("BasicResourceLoader failed to read "+file); System.err.println("BasicResourceLoader failed to read "+file);
BufferedReader reader= null; BufferedReader reader= null;
try { try {
reader = new BufferedReader(new FileReader(file)); reader = new BufferedReader(new FileReader(file));
} catch (java.io.FileNotFoundException e) { } catch (java.io.FileNotFoundException e) {
System.out.println("Could not find " + file); System.err.println("Could not find " + file);
return result; return result;
} }
String currentLine; String currentLine;
@ -63,7 +63,7 @@ public class FileTools {
} }
reader.close(); reader.close();
} catch (java.io.IOException e) { } catch (java.io.IOException e) {
System.out.println("Java.io.IOExeption: " + e.getMessage()); System.err.println("Java.io.IOExeption: " + e.getMessage());
} }
} }
return result; return result;

View File

@ -43,6 +43,8 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import eva2.EvAInfo;
/** /**
* Loads resource file from directory OR jar file. Now it is easier possible to * Loads resource file from directory OR jar file. Now it is easier possible to
@ -117,13 +119,13 @@ public class BasicResourceLoader implements ResourceLoader
} }
/** /**
* Description of the Method * Read String lines from a file into a list.
* *
* @param resourceFile Description of the Parameter * @param resourceFile File to read
* @param ignorePrefix array of prefixes which mark a line to be ignored * @param ignorePrefix array of prefixes which mark a line to be ignored
* @param lOffset offset of the first line to read * @param lOffset offset of the first line to read
* @param lCnt number of lines to read, if <= 0, all lines are read * @param lCnt number of lines to read, if <= 0, all lines are read
* @return Description of the Return Value * @return List of lines which were read or null on an error
*/ */
public static List<String> readLines(String resourceFile, public static List<String> readLines(String resourceFile,
String[] ignorePrefix, int lOffset, int lCnt) String[] ignorePrefix, int lOffset, int lCnt)
@ -135,7 +137,7 @@ public class BasicResourceLoader implements ResourceLoader
byte[] bytes = BasicResourceLoader.instance() byte[] bytes = BasicResourceLoader.instance()
.getBytesFromResourceLocation( .getBytesFromResourceLocation(
resourceFile); resourceFile, false);
if (bytes == null) if (bytes == null)
{ {
@ -382,21 +384,34 @@ public class BasicResourceLoader implements ResourceLoader
// } // }
// return getStreamFromFile(found.get(0)); // return getStreamFromFile(found.get(0));
// } // }
/** /**
* Gets the byte data from a file at the given resource location. * Gets the byte data from a file at the given resource location.
* *
* @param rawResrcLoc Description of the Parameter * @param rawResrcLoc Description of the Parameter
* @return the byte array of file. * @return the byte array of file.
*/ */
public byte[] getBytesFromResourceLocation(String rawResrcLoc) public byte[] getBytesFromResourceLocation(String rawResrcLoc) {
return getBytesFromResourceLocation(rawResrcLoc, false);
}
/**
* Gets the byte data from a file at the given resource location.
*
* @param rawResrcLoc Location of the resource
* @param exceptionOnNotFound if true, a RuntimeException is thrown if the resource was not found.
* @return the byte array of file.
*/
public byte[] getBytesFromResourceLocation(String rawResrcLoc, boolean exceptionOnNotFound)
{ {
InputStream in = getStreamFromResourceLocation(rawResrcLoc); InputStream in = getStreamFromResourceLocation(rawResrcLoc);
byte[] arr = null;
if (in == null) { if (in != null) {
return null; arr = getBytesFromStream(in);
} }
return getBytesFromStream(in); if (exceptionOnNotFound && (arr==null)) {
throw new RuntimeException(EvAInfo.resourceNotFoundErrorMessage(rawResrcLoc));
}
return arr;
} }
/** /**
@ -621,7 +636,7 @@ public class BasicResourceLoader implements ResourceLoader
Properties prop = new Properties(); Properties prop = new Properties();
BasicResourceLoader loader = BasicResourceLoader.instance(); BasicResourceLoader loader = BasicResourceLoader.instance();
byte bytes[] = loader.getBytesFromResourceLocation(resourceName); byte bytes[] = loader.getBytesFromResourceLocation(resourceName, false);
if (bytes != null) { if (bytes != null) {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes); ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
prop.load(bais); prop.load(bais);

View File

@ -12,12 +12,9 @@ package eva2.tools;
/*==========================================================================* /*==========================================================================*
* IMPORTS * IMPORTS
*==========================================================================*/ *==========================================================================*/
import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;
@ -25,8 +22,6 @@ import java.net.InetAddress;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import eva2.client.EvAClient;
/** /**
* *
@ -36,38 +31,6 @@ public class EVAHELP {
/** /**
* *
*/ */
/**
*
*/
static public Properties readProperties(String resourceName) throws Exception {
if (EvAClient.TRACE) System.out.println("readProperties of file: " + resourceName);
Properties prop = new Properties();
BasicResourceLoader loader = BasicResourceLoader.instance();
byte bytes[] = loader.getBytesFromResourceLocation(resourceName);
if (bytes != null) {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
prop.load(bais);
}
if (prop != null)
return prop;
/////////////
int slInd = resourceName.lastIndexOf('/');
if (slInd != -1)
resourceName = resourceName.substring(slInd + 1);
Properties userProps = new Properties();
File propFile = new File(File.separatorChar + "resources" +
File.separatorChar + resourceName);
if (propFile.exists()) {
try {
userProps.load(new FileInputStream(propFile));
}
catch (Exception ex) {
System.out.println("Problem reading user properties: " + propFile);
}
}
return userProps;
}
/** /**
* *