diff --git a/src/eva2/EvAInfo.java b/src/eva2/EvAInfo.java index 401ce56a..f5b9c3a0 100644 --- a/src/eva2/EvAInfo.java +++ b/src/eva2/EvAInfo.java @@ -96,17 +96,31 @@ public class EvAInfo { try { EVA_PROPERTIES = BasicResourceLoader.readProperties(EvAInfo.propertyFile); } 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.exit(1); } File f=new File(EvAInfo.iconLocation); 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... } } + /** + * 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) { String myVal = EVA_PROPERTIES.getProperty(key); return myVal; diff --git a/src/eva2/client/EvAClient.java b/src/eva2/client/EvAClient.java index 8d86b002..129476da 100644 --- a/src/eva2/client/EvAClient.java +++ b/src/eva2/client/EvAClient.java @@ -282,12 +282,8 @@ public class EvAClient implements RemoteStateListener, Serializable { if (withGUI ) { m_Frame = new JEFrame(EvAInfo.productName + " workbench"); BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); - 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!"); - } + byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); + m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); // m_Frame.setTitle(EvAInfo.productName + " workbench"); try { @@ -986,18 +982,14 @@ class SplashScreen extends Frame { public void splash(){ JWindow splashWindow = new JWindow(this); BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader.getBytesFromResourceLocation(imgLocation); - try { - ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)); - JLabel splashLabel = new JLabel(ii); - splashWindow.add(splashLabel); - splashWindow.pack(); - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - splashWindow.setLocation(screenSize.width / 2 - splashWindow.getSize().width / 2, screenSize.height / 2 - splashWindow.getSize().height / 2); - splashWindow.setVisible(true); - } catch (java.lang.NullPointerException e) { - System.err.println("Could not find EvA2 splash screen, please move resources folder to working directory!"); - } + byte[] bytes = loader.getBytesFromResourceLocation(imgLocation, true); + ImageIcon ii = new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes)); + JLabel splashLabel = new JLabel(ii); + splashWindow.add(splashLabel); + splashWindow.pack(); + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + splashWindow.setLocation(screenSize.width / 2 - splashWindow.getSize().width / 2, screenSize.height / 2 - splashWindow.getSize().height / 2); + splashWindow.setVisible(true); } } \ No newline at end of file diff --git a/src/eva2/gui/GenericOptimizationObjectivesEditor.java b/src/eva2/gui/GenericOptimizationObjectivesEditor.java index 621ec0f3..60d0c670 100644 --- a/src/eva2/gui/GenericOptimizationObjectivesEditor.java +++ b/src/eva2/gui/GenericOptimizationObjectivesEditor.java @@ -174,13 +174,8 @@ public class GenericOptimizationObjectivesEditor extends JPanel implements Prope gbc.fill = GridBagConstraints.REMAINDER; gbc.gridx = 1; gbc.weightx = 1; - bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif"); - try { - 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"); - } + bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true); + this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.m_Delete[i].addActionListener(deleteTarget); this.m_TargetList.add(this.m_Delete[i], gbc); } diff --git a/src/eva2/gui/GenericOptimizationObjectivesWithParamEditor.java b/src/eva2/gui/GenericOptimizationObjectivesWithParamEditor.java index ce419639..67987547 100644 --- a/src/eva2/gui/GenericOptimizationObjectivesWithParamEditor.java +++ b/src/eva2/gui/GenericOptimizationObjectivesWithParamEditor.java @@ -198,13 +198,8 @@ public class GenericOptimizationObjectivesWithParamEditor extends JPanel impleme gbc.fill = GridBagConstraints.REMAINDER; gbc.gridx = 2; gbc.weightx = 1; - bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif"); - try { - 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"); - } + bytes = loader.getBytesFromResourceLocation("resources/images/Sub24.gif", true); + this.m_Delete[i] = new JButton("", new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); this.m_Delete[i].addActionListener(deleteTarget); this.m_TargetList.add(this.m_Delete[i], gbc); } diff --git a/src/eva2/gui/GenericRemoteServersEditor.java b/src/eva2/gui/GenericRemoteServersEditor.java index 3ed3bfd3..1fc2e87b 100644 --- a/src/eva2/gui/GenericRemoteServersEditor.java +++ b/src/eva2/gui/GenericRemoteServersEditor.java @@ -111,13 +111,9 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor private JButton makeButtonWith(String iconSrc, String title) { JButton tmpB; byte[] bytes; - bytes = BasicResourceLoader.instance().getBytesFromResourceLocation(iconSrc); - try { - tmpB = new JButton(title, new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - } catch (java.lang.NullPointerException e) { - System.err.println("Could not find icon " + iconSrc + ", please move resources folder to working directory!"); - tmpB = new JButton(title); - } + bytes = BasicResourceLoader.instance().getBytesFromResourceLocation(iconSrc, false); + if (bytes!=null) tmpB = new JButton(title, new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); + else tmpB = new JButton(title); return tmpB; } @@ -172,7 +168,7 @@ public class GenericRemoteServersEditor extends JPanel implements PropertyEditor this.m_ServerList.add(this.m_CPUs[i], gbc); // The delete button 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].addActionListener(deleteServer); this.m_ServerList.add(this.m_Delete[i], gbc); diff --git a/src/eva2/gui/HtmlDemo.java b/src/eva2/gui/HtmlDemo.java index 8dcd996d..4a3e9ad0 100644 --- a/src/eva2/gui/HtmlDemo.java +++ b/src/eva2/gui/HtmlDemo.java @@ -94,12 +94,8 @@ public class HtmlDemo { } JFrame frame = new JFrame (m_name); BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); - try { - 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!"); - } + byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); + frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); JScrollPane scroller = new JScrollPane(); JViewport vp = scroller.getViewport(); vp.add(m_html); diff --git a/src/eva2/gui/JTextoutputFrame.java b/src/eva2/gui/JTextoutputFrame.java index dab47b3b..22838635 100644 --- a/src/eva2/gui/JTextoutputFrame.java +++ b/src/eva2/gui/JTextoutputFrame.java @@ -107,12 +107,9 @@ Serializable { m_TextArea.setCaretPosition(0); BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); - try { - 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!"); - } + byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); + frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); + frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.dispose(); diff --git a/src/eva2/gui/LogPanel.java b/src/eva2/gui/LogPanel.java index b5880b79..88bd8116 100644 --- a/src/eva2/gui/LogPanel.java +++ b/src/eva2/gui/LogPanel.java @@ -105,12 +105,8 @@ public class LogPanel extends JPanel { final JFrame frame = new JFrame("Log_Panel_Test"); frame.getContentPane().setLayout(new BorderLayout()); BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); - try { - 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!"); - } + byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); + frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); LogPanel panel = new LogPanel(); frame.getContentPane().add(panel, BorderLayout.CENTER); frame.addWindowListener(new WindowAdapter() { diff --git a/src/eva2/gui/Plot.java b/src/eva2/gui/Plot.java index 378ca2af..0a3a6a4c 100644 --- a/src/eva2/gui/Plot.java +++ b/src/eva2/gui/Plot.java @@ -221,16 +221,8 @@ public class Plot implements PlotInterface, Serializable { public void init() { m_Frame = new JEFrame("Plot: " + m_PlotName); BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader - .getBytesFromResourceLocation(EvAInfo.iconLocation); - 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!"); - } + byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); + m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); m_ButtonPanel = new JPanel(); m_PlotArea = new FunctionArea(m_xname, m_yname); diff --git a/src/eva2/gui/PropertyDialog.java b/src/eva2/gui/PropertyDialog.java index 1ac4088c..9695c230 100644 --- a/src/eva2/gui/PropertyDialog.java +++ b/src/eva2/gui/PropertyDialog.java @@ -35,12 +35,9 @@ public class PropertyDialog extends JEFrame { public PropertyDialog (PropertyEditor editor,String Title, int x, int y) { super(getFrameNameFromEditor(editor)); // that was the long class name !! BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); - try { - 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!"); - } + byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); + setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); + //System.out.println("PropertyDialog.Constructor of "+ Title); setDefaultCloseOperation(DISPOSE_ON_CLOSE); getContentPane().setLayout(new BorderLayout()); diff --git a/src/eva2/gui/TagEditor.java b/src/eva2/gui/TagEditor.java index bb5dd1cd..77f70261 100644 --- a/src/eva2/gui/TagEditor.java +++ b/src/eva2/gui/TagEditor.java @@ -126,12 +126,8 @@ public class TagEditor extends PropertyEditorSupport { PropertyValueSelector ps = new PropertyValueSelector(ce); JFrame f = new JFrame(); BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation); - try { - 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!"); - } + byte[] bytes = loader.getBytesFromResourceLocation(EvAInfo.iconLocation, true); + f.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes)); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); diff --git a/src/eva2/server/go/mocco/MOCCOChooseMOStrategy.java b/src/eva2/server/go/mocco/MOCCOChooseMOStrategy.java index 2c6fe668..d3e7b8a4 100644 --- a/src/eva2/server/go/mocco/MOCCOChooseMOStrategy.java +++ b/src/eva2/server/go/mocco/MOCCOChooseMOStrategy.java @@ -34,136 +34,111 @@ public class MOCCOChooseMOStrategy extends MOCCOPhase implements InterfaceProces /** This method will call the init method and will go to stall */ public void initProcessElementParametrization() { - this.m_Mocco.m_JPanelControl.removeAll(); - this.m_Mocco.m_JPanelParameters.removeAll(); - this.m_Mocco.m_JPanelParameters.setLayout(new BorderLayout()); + this.m_Mocco.m_JPanelControl.removeAll(); + this.m_Mocco.m_JPanelParameters.removeAll(); + this.m_Mocco.m_JPanelParameters.setLayout(new BorderLayout()); - // The button panel + // The button panel - // the parameter panel - this.m_Mocco.m_JPanelParameters.add(this.makeHelpText("Please choose a multi-objective" + - " optimization strategy for the next optimization iteration. The different optimization approaches" + - " not only differ in the number of soltuion alternatives generated (more soltuions typicall require" + - " higher computational effort), but also in the amount of input required by the decision maker (DM)."), BorderLayout.NORTH); - JPanel tmpP = new JPanel(); - tmpP.setLayout(new GridBagLayout()); - JButton tmpB; - BasicResourceLoader loader = BasicResourceLoader.instance(); - byte[] bytes; - GridBagConstraints gbc = new GridBagConstraints(); - gbc.anchor = GridBagConstraints.WEST; - gbc.fill = GridBagConstraints.BOTH; - gbc.weightx = 100; - tmpB = new JButton(); - try { - bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_MOEA.gif"); - tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - 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.gridx = 0; - tmpP.add(tmpB, gbc); - tmpB.setEnabled(true); - tmpB.addActionListener(choosenMOEA); - gbc.gridy = 0; - gbc.gridx = 1; - tmpP.add(this.makeInformationText("Multi-Objective Evolutionary Algorithm", "The MOEA is the" + - " only optimization strategy, which returns an approximated Pareto set in a single run." + - " Please note that with increasing number of objectives the selection pressure for" + - " the evolutionary algorithm decreases significantly in case of multi-objective" + - " optimization. Therefore the MOEA should only be applied in case of less than ten" + - " objectives."), gbc); + // the parameter panel + this.m_Mocco.m_JPanelParameters.add(this.makeHelpText("Please choose a multi-objective" + + " optimization strategy for the next optimization iteration. The different optimization approaches" + + " not only differ in the number of soltuion alternatives generated (more soltuions typicall require" + + " higher computational effort), but also in the amount of input required by the decision maker (DM)."), BorderLayout.NORTH); + JPanel tmpP = new JPanel(); + tmpP.setLayout(new GridBagLayout()); + JButton tmpB; + BasicResourceLoader loader = BasicResourceLoader.instance(); + byte[] bytes; + GridBagConstraints gbc = new GridBagConstraints(); + gbc.anchor = GridBagConstraints.WEST; + gbc.fill = GridBagConstraints.BOTH; + gbc.weightx = 100; + tmpB = new JButton(); + bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_MOEA.gif", true); + tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); + tmpB.setBackground(Color.WHITE); + gbc.gridy = 0; + gbc.gridx = 0; + tmpP.add(tmpB, gbc); + tmpB.setEnabled(true); + tmpB.addActionListener(choosenMOEA); + gbc.gridy = 0; + gbc.gridx = 1; + tmpP.add(this.makeInformationText("Multi-Objective Evolutionary Algorithm", "The MOEA is the" + + " only optimization strategy, which returns an approximated Pareto set in a single run." + + " Please note that with increasing number of objectives the selection pressure for" + + " the evolutionary algorithm decreases significantly in case of multi-objective" + + " optimization. Therefore the MOEA should only be applied in case of less than ten" + + " objectives."), gbc); - tmpB = new JButton(); - try { - bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_GDF.gif"); - tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - 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.gridx = 0; - tmpP.add(tmpB, gbc); - tmpB.setEnabled(true); - tmpB.addActionListener(choosenGDF); - gbc.gridy = 1; - gbc.gridx = 1; - tmpP.add(this.makeInformationText("Geoffrion-Dyer-Feinberg Method", "Here the DM needs to select a reference solution" + - " from the currently known solution. For this solution the DM has to specify trade-off values for each" + - " objective. This method assumes a linear utility function by results in a simple weighted aggregation."), gbc); - this.m_Mocco.m_JPanelParameters.add(tmpP, BorderLayout.CENTER); + tmpB = new JButton(); + bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_GDF.gif", true); + tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); + tmpB.setBackground(Color.WHITE); + gbc.gridy = 1; + gbc.gridx = 0; + tmpP.add(tmpB, gbc); + tmpB.setEnabled(true); + tmpB.addActionListener(choosenGDF); + gbc.gridy = 1; + gbc.gridx = 1; + tmpP.add(this.makeInformationText("Geoffrion-Dyer-Feinberg Method", "Here the DM needs to select a reference solution" + + " from the currently known solution. For this solution the DM has to specify trade-off values for each" + + " objective. This method assumes a linear utility function by results in a simple weighted aggregation."), gbc); + this.m_Mocco.m_JPanelParameters.add(tmpP, BorderLayout.CENTER); - tmpB = new JButton(); - try { - bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_STEP.gif"); - tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - 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.gridx = 0; - tmpP.add(tmpB, gbc); - tmpB.setEnabled(true); - tmpB.addActionListener(choosenSTEP); - gbc.gridy = 2; - gbc.gridx = 1; - tmpP.add(this.makeInformationText("STEP Method", "The STEP method requires the DM to select a" + - " reference solution from the current solution set. For this solution the obtained objective values are to" + - " be classified by the DM into satisfactory and unsatisfactory ones. The satifactory ones" + - " are treaded as constraints, while the unsatisfactory objectives are weight aggregated" + - " into a single objectives. The individual weights are also to be given by the DM."), gbc); + tmpB = new JButton(); + bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_STEP.gif", true); + tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); + tmpB.setBackground(Color.WHITE); + gbc.gridy = 2; + gbc.gridx = 0; + tmpP.add(tmpB, gbc); + tmpB.setEnabled(true); + tmpB.addActionListener(choosenSTEP); + gbc.gridy = 2; + gbc.gridx = 1; + tmpP.add(this.makeInformationText("STEP Method", "The STEP method requires the DM to select a" + + " reference solution from the current solution set. For this solution the obtained objective values are to" + + " be classified by the DM into satisfactory and unsatisfactory ones. The satifactory ones" + + " are treaded as constraints, while the unsatisfactory objectives are weight aggregated" + + " into a single objectives. The individual weights are also to be given by the DM."), gbc); - tmpB = new JButton(); - try { - bytes = loader.getBytesFromResourceLocation("resources/MOCCO/MOCCO_REFP.gif"); - tmpB.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(bytes))); - 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.gridx = 0; - tmpP.add(tmpB, gbc); - tmpB.setEnabled(true); - tmpB.addActionListener(choosenREFP); - gbc.gridy = 3; - gbc.gridx = 1; - tmpP.add(this.makeInformationText("Reference Point Method", "Here the DM chooses a reference point of" + - " aspiration levels (unattainable values are allowed). The optimizier tries to minimze the L-metric ( readLines(String resourceFile, String[] ignorePrefix, int lOffset, int lCnt) @@ -135,7 +137,7 @@ public class BasicResourceLoader implements ResourceLoader byte[] bytes = BasicResourceLoader.instance() .getBytesFromResourceLocation( - resourceFile); + resourceFile, false); if (bytes == null) { @@ -382,21 +384,34 @@ public class BasicResourceLoader implements ResourceLoader // } // return getStreamFromFile(found.get(0)); // } - /** * Gets the byte data from a file at the given resource location. * * @param rawResrcLoc Description of the Parameter * @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); - - if (in == null) { - return null; + byte[] arr = null; + if (in != 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(); BasicResourceLoader loader = BasicResourceLoader.instance(); - byte bytes[] = loader.getBytesFromResourceLocation(resourceName); + byte bytes[] = loader.getBytesFromResourceLocation(resourceName, false); if (bytes != null) { ByteArrayInputStream bais = new ByteArrayInputStream(bytes); prop.load(bais); diff --git a/src/eva2/tools/EVAHELP.java b/src/eva2/tools/EVAHELP.java index f5fe519c..369e354f 100644 --- a/src/eva2/tools/EVAHELP.java +++ b/src/eva2/tools/EVAHELP.java @@ -12,12 +12,9 @@ package eva2.tools; /*==========================================================================* * IMPORTS *==========================================================================*/ -import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.BufferedWriter; -import java.io.ByteArrayInputStream; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; @@ -25,8 +22,6 @@ import java.net.InetAddress; import java.util.Enumeration; 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; - } /** *