Commit 4fe665ec authored by Philipp Spohr's avatar Philipp Spohr
Browse files

Basic sanity checks for lib loading

parent 502e0e3d
/*******************************************************************************
* 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() {
......
/*******************************************************************************
* 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;
}
}
......@@ -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);
}
}
......
/*******************************************************************************
* 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";
}
});
}
}
......@@ -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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment