diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java index c8a8708a98c9a300cb4eb4a17b925badb15f97b8..9b66bdb5912175cd99fe5c4fc5b9d215de3eb962 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java @@ -1,16 +1,16 @@ /******************************************************************************* * Copyright (C) 2017 Philipp Spohr - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,41 +23,48 @@ package de.hhu.ba.yoshikoWrapper.core; import java.io.File; +import javax.swing.JOptionPane; + import org.slf4j.Logger; import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger; import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; public class YoshikoLoader { - + + public static final String REQUIRED_VERSION = "2.1"; + private static boolean isLoaded; - + //Symbolic Links private static Logger logger = YoshikoLogger.getInstance().getLogger(); - + public static void loadLibrary(String libPath) { - + //Attempt to load from a previously stored path File f = new File (libPath); if (!f.exists()) { logger.info("Could not load the Yoshiko-library from a previously saved path! You might need to set the path manually."); return; } - + try { System.out.println("Attempting to load library @: "+libPath); + if (!libPath.substring(0,libPath.lastIndexOf(".")).endsWith(REQUIRED_VERSION)) { + throw new Exception(LocalizationManager.get("libFail")+" "+REQUIRED_VERSION); + } System.load(libPath); //update cfg CyCore.cm.getProperties().setProperty("pathToYoshiko", libPath); } catch(Exception e) { - //e.printStackTrace(); + JOptionPane.showMessageDialog(null, LocalizationManager.get("libFail")+" "+REQUIRED_VERSION); return; } LibraryInterface.setVerbosity(3); isLoaded = true; } - + //SETTER / GETTER public static boolean isLibraryLoaded() { diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LibraryPanelFactory.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LibraryPanelFactory.java index 6c7714c533db78a0a0f624c04d8ca7af2e934b64..72ab8aa22857806d19527a5db76de5192f774d85 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LibraryPanelFactory.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LibraryPanelFactory.java @@ -1,16 +1,16 @@ /******************************************************************************* * Copyright (C) 2017 Philipp Spohr - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -29,7 +29,6 @@ import java.net.URI; import javax.swing.GroupLayout; import javax.swing.JButton; import javax.swing.JFileChooser; -import javax.swing.JLabel; import javax.swing.GroupLayout.Alignment; @@ -38,47 +37,39 @@ import org.cytoscape.util.swing.BasicCollapsiblePanel; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger; -import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swing.components.LibStatusPanel; -import de.hhu.ba.yoshikoWrapper.swing.components.YLibChooser; public class LibraryPanelFactory{ - + public static BasicCollapsiblePanel createLibraryPanel() { final BasicCollapsiblePanel ret = new BasicCollapsiblePanel(LocalizationManager.get("libraryPanel")); - + final LibStatusPanel libStatusPanel; final JButton searchLibButton; - final JLabel yoshikoVersionLabel; final JButton getYoshiko; - + //SWING COMPONENT INITIALIZATION libStatusPanel = new LibStatusPanel(); searchLibButton = new JButton(LocalizationManager.get("resolveLibPath")); - yoshikoVersionLabel = new JLabel(); libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded()); - - if (YoshikoLoader.isLibraryLoaded()) { - yoshikoVersionLabel.setText(LibraryInterface.getVersionString()); - searchLibButton.setEnabled(false); - } - + + searchLibButton.setEnabled(!YoshikoLoader.isLibraryLoaded()); + searchLibButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - final YLibChooser c = new YLibChooser(); + final JFileChooser c = new JFileChooser(); int returnVal = c.showOpenDialog(ret); if (returnVal == JFileChooser.APPROVE_OPTION) { YoshikoLoader.loadLibrary(c.getSelectedFile().getAbsolutePath()); } libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded()); - yoshikoVersionLabel.setText(LocalizationManager.get("yoshVersion")+" "+LibraryInterface.getVersionString()); - searchLibButton.setEnabled(false); + searchLibButton.setEnabled(!YoshikoLoader.isLibraryLoaded()); } }); - + getYoshiko = new JButton(LocalizationManager.get("getYoshiko")); getYoshiko.addActionListener(new ActionListener() { @@ -93,40 +84,37 @@ public class LibraryPanelFactory{ } catch (Exception ex) { YoshikoLogger.getInstance().getLogger().info("Can't access desktop browser!"); ex.printStackTrace(); - } + } } } } }); - + SwingUtil.addAll(ret, libStatusPanel, - yoshikoVersionLabel, searchLibButton, getYoshiko ); - + //Layout GroupLayout layout = new GroupLayout(ret.getContentPane()); - + layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING,true) .addComponent(libStatusPanel) - .addComponent(yoshikoVersionLabel) .addComponent(searchLibButton) .addComponent(getYoshiko) ); - + layout.setVerticalGroup(layout.createSequentialGroup() .addComponent(libStatusPanel) - .addComponent(yoshikoVersionLabel) .addComponent(searchLibButton) .addComponent(getYoshiko) ); - - + + ret.getContentPane().setLayout(layout); - + return ret; } } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/LibStatusPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/LibStatusPanel.java index dadb3aea90e35d60991fd87199ff4f31964f974f..719915e834f5047260cf69cc982fb8b84f7a8775 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/LibStatusPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/LibStatusPanel.java @@ -24,25 +24,37 @@ package de.hhu.ba.yoshikoWrapper.swing.components; import java.awt.Color; import javax.swing.JLabel; +import javax.swing.JPanel; +import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; +import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; +import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swing.GraphicsLoader; /** - * Simple JLabel visually representing whether or not the Yoshiko Lib is loaded + * Simple JPanel visually representing whether or not the Yoshiko Lib is loaded and showing some basic info * */ @SuppressWarnings("serial") -public class LibStatusPanel extends JLabel { +public class LibStatusPanel extends JPanel { + + final JLabel yoshikoVersionLabel; + + public LibStatusPanel() { + yoshikoVersionLabel = new JLabel(); + this.add(yoshikoVersionLabel); + } + /** * Adjusts the style accordingly by changing its color and updating its text */ public void setStyle(boolean libraryLoaded) { if(libraryLoaded) { - this.setText("YOSHIKO LIBRARY READY!"); - this.setForeground(GraphicsLoader.yoshikoGreen); + yoshikoVersionLabel.setText(LocalizationManager.get("yoshVersion")+" "+YoshikoLoader.REQUIRED_VERSION+"("+LibraryInterface.getVersionString()+")"); + yoshikoVersionLabel.setForeground(GraphicsLoader.yoshikoGreen); } else { - this.setText("YOSHIKO LIBRARY NOT LOADED :("); - this.setForeground(Color.RED); + yoshikoVersionLabel.setText(LocalizationManager.get("noLibTitle")); + yoshikoVersionLabel.setForeground(Color.RED); } } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/YLibChooser.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/YLibChooser.java deleted file mode 100644 index c5e8ae72a8a8e960d7482e215ce84434f7b3c717..0000000000000000000000000000000000000000 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/YLibChooser.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2017 Philipp Spohr - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - ******************************************************************************/ -package de.hhu.ba.yoshikoWrapper.swing.components; - -import java.io.File; - -import javax.swing.JFileChooser; -import javax.swing.filechooser.FileFilter; - -/**Implementation of the JFileChooser that limits choices to shared library - * TODO: Perform basic sanity checks on the selected file (Checksum?) - * @author Philipp Spohr, Aug 6, 2017 - * - */ -@SuppressWarnings("serial") -public class YLibChooser extends JFileChooser { - - /** - * Default constructor - */ - public YLibChooser() { - super(); - this.setFileFilter(new FileFilter() { - - @Override - public boolean accept(File f) { - //TODO - return true; - } - - @Override - public String getDescription() { - return "Compiled Yoshiko-Libraries"; - } - - }); - } -} diff --git a/src/main/resources/YoshikoStrings.properties b/src/main/resources/YoshikoStrings.properties index 7b0e8d0ab54ad89462fe096728bfba742ff973f9..13324bf87ad96c512c927168ced2abe7ad11642d 100644 --- a/src/main/resources/YoshikoStrings.properties +++ b/src/main/resources/YoshikoStrings.properties @@ -42,6 +42,7 @@ icTooltip = This value is used to determine what the algorithm pays when inserti ilpMarker = ILP Properties incompleteResult = This run yielded no usable result! instance = Instance +libFail = Failed to load library! Make sure you got the right file. The required version for this version of the wrapper is: libraryPanel = Library metaGraph = Meta Graph multFactor = Multiplicative Factor for SNR: