Skip to content
Snippets Groups Projects
Commit fd30aebb authored by Philipp Spohr's avatar Philipp Spohr
Browse files

A bit of comfort:

Implemented basic configuration system
Saves previously stored yoshiko library location
parent 6c0793c9
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,9 @@ import org.cytoscape.application.swing.CytoPanelComponent; ...@@ -9,7 +9,9 @@ import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.service.util.AbstractCyActivator; import org.cytoscape.service.util.AbstractCyActivator;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import de.hhu.ba.yoshikoWrapper.core.ConfigurationManager;
import de.hhu.ba.yoshikoWrapper.core.Core; import de.hhu.ba.yoshikoWrapper.core.Core;
import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader;
import de.hhu.ba.yoshikoWrapper.gui.MainPanel; import de.hhu.ba.yoshikoWrapper.gui.MainPanel;
import de.hhu.ba.yoshikoWrapper.gui.MainPanelAction; import de.hhu.ba.yoshikoWrapper.gui.MainPanelAction;
...@@ -22,7 +24,19 @@ public class CyActivator extends AbstractCyActivator { ...@@ -22,7 +24,19 @@ public class CyActivator extends AbstractCyActivator {
@Override @Override
public void start(BundleContext context) throws Exception { public void start(BundleContext context) throws Exception {
//TODO: Load shared library if installed on startup //Initialize cytoscape configuration system
ConfigurationManager cm = new ConfigurationManager("yoshikoWrapper", "yoshiko.props");
Properties propsReaderServiceProps = new Properties();
propsReaderServiceProps.setProperty("cyPropertyName", "yoshiko.props");
registerAllServices(context,cm,propsReaderServiceProps);
//Attempt to find the yoshiko lib in r a previously stored location
YoshikoLoader.provideConfiguration(cm);
if (!YoshikoLoader.isLibraryLoaded()){
YoshikoLoader.loadLibrary(cm.getProperties().getProperty("pathToYoshiko"));
}
CyApplicationManager cyApplicationManager = getService(context, CyApplicationManager.class); CyApplicationManager cyApplicationManager = getService(context, CyApplicationManager.class);
Core.registerApplicationManager(cyApplicationManager); Core.registerApplicationManager(cyApplicationManager);
......
package de.hhu.ba.yoshikoWrapper.core;
import org.cytoscape.property.AbstractConfigDirPropsReader;
import org.cytoscape.property.CyProperty;
public class ConfigurationManager extends AbstractConfigDirPropsReader{
public ConfigurationManager(String appName, String fileName){
super(appName, fileName, CyProperty.SavePolicy.CONFIG_DIR);
this.getProperties().list(System.out);
}
}
package de.hhu.ba.yoshikoWrapper.core; package de.hhu.ba.yoshikoWrapper.core;
import java.util.HashMap;
import java.util.List; import java.util.List;
import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyEdge; import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyRow; import org.cytoscape.model.CyRow;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
......
package de.hhu.ba.yoshikoWrapper.core; package de.hhu.ba.yoshikoWrapper.core;
public class YoshikoLoader { import java.io.File;
//SINGLETON TEMPLATE public class YoshikoLoader {
private static YoshikoLoader instance;
private static boolean libraryLoaded; private static boolean libraryLoaded;
private static ConfigurationManager cm;
public static YoshikoLoader getInstance() { public static void loadLibrary(String libPath) {
if (instance == null){
instance = new YoshikoLoader();
}
return instance;
}
private YoshikoLoader() {
libraryLoaded = false;
}
public void loadLibrary() {
if (libraryLoaded) { if (libraryLoaded) {
return; return;
} }
try {
System.loadLibrary("libyoshikoLibrary");
}
catch (Exception e) {
e.printStackTrace();
}
}
public void loadLibrary(String libPath) { File f = new File (libPath);
if (libraryLoaded) { if (!f.exists()) {
System.out.println("Could not find a previously saved yoshiko library path, needs to be set manually!");
return; return;
} }
try { try {
System.out.println("Attempting to load library @: "+libPath);
System.load(libPath); System.load(libPath);
//update cfg
cm.getProperties().setProperty("pathToYoshiko", libPath);
libraryLoaded = true; libraryLoaded = true;
} }
catch(UnsatisfiedLinkError e) { catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
libraryLoaded = false;
} }
finally {
}
} }
//SETTER / GETTER //SETTER / GETTER
public boolean isLibraryLoaded() { public static boolean isLibraryLoaded() {
return libraryLoaded; return libraryLoaded;
} }
public static void provideConfiguration(ConfigurationManager _cm) {
cm = _cm;
}
} }
...@@ -14,7 +14,6 @@ import org.cytoscape.application.swing.CytoPanelComponent; ...@@ -14,7 +14,6 @@ import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.application.swing.CytoPanelName; import org.cytoscape.application.swing.CytoPanelName;
import de.hhu.ba.yoshikoWrapper.core.Core; import de.hhu.ba.yoshikoWrapper.core.Core;
import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader;
import de.hhu.ba.yoshikoWrapper.gui.*;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
/**This class describes the Swing Panel that the user interacts with in cytoscape /**This class describes the Swing Panel that the user interacts with in cytoscape
...@@ -29,7 +28,6 @@ public class MainPanel extends JPanel implements CytoPanelComponent { ...@@ -29,7 +28,6 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
private static final long serialVersionUID = 6214827920591046457L; private static final long serialVersionUID = 6214827920591046457L;
//SYMBOLIC LINKS //SYMBOLIC LINKS
private YoshikoLoader yoshikoLoader = YoshikoLoader.getInstance();
private MainPanel self = this; //for lambda function references private MainPanel self = this; //for lambda function references
//SWING COMPONENTS //SWING COMPONENTS
...@@ -48,7 +46,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent { ...@@ -48,7 +46,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
//SWING COMPONENT INITIALIZATION //SWING COMPONENT INITIALIZATION
libStatusPanel = new LibStatusPanel(); libStatusPanel = new LibStatusPanel();
libStatusPanel.setStyle(yoshikoLoader.isLibraryLoaded()); libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded());
this.add(libStatusPanel); this.add(libStatusPanel);
searchLibButton = new JButton("SHOW YOSHIKO LIB"); searchLibButton = new JButton("SHOW YOSHIKO LIB");
...@@ -59,35 +57,31 @@ public class MainPanel extends JPanel implements CytoPanelComponent { ...@@ -59,35 +57,31 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
final YLibChooser c = new YLibChooser(); final YLibChooser c = new YLibChooser();
int returnVal = c.showOpenDialog(self); int returnVal = c.showOpenDialog(self);
if (returnVal == JFileChooser.APPROVE_OPTION) { if (returnVal == JFileChooser.APPROVE_OPTION) {
yoshikoLoader.loadLibrary(c.getSelectedFile().getAbsolutePath()); YoshikoLoader.loadLibrary(c.getSelectedFile().getAbsolutePath());
} }
libStatusPanel.setStyle(yoshikoLoader.isLibraryLoaded()); libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded());
yoshikoVersionLabel.setText(LibraryInterface.getVersionString()); yoshikoVersionLabel.setText(LibraryInterface.getVersionString());
} }
}); });
this.add(searchLibButton); this.add(searchLibButton);
// JButton runButton = new JButton("RUN");
// runButton.addActionListener(new ActionListener() {
//TODO: REMOVE IN FINAL RELEASE
JButton debugGraphActionButton = new JButton("DO MYSTERIOUS DEBUG STUFF");
debugGraphActionButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (yoshikoLoader.isLibraryLoaded()){ if (YoshikoLoader.isLibraryLoaded()){
Core.performYoshiko(timeLimitSetter.getTimeLimit()); Core.performYoshiko(timeLimitSetter.getTimeLimit());
} }
} }
}); });
this.add(debugGraphActionButton); this.add(runButton);
//
//
//
timeLimitSetter = new TimeLimitSetter(); timeLimitSetter = new TimeLimitSetter();
this.add(timeLimitSetter); this.add(timeLimitSetter);
......
package de.hhu.ba.yoshikoWrapper.gui; package de.hhu.ba.yoshikoWrapper.gui;
import java.text.NumberFormat;
import javax.swing.JFormattedTextField; import javax.swing.JFormattedTextField;
import javax.swing.text.NumberFormatter;
/** /**
* Provides a more strict input field that only accepts integers * Provides a more strict input field that only accepts integers
......
package de.hhu.ba.yoshikoWrapper.gui; package de.hhu.ba.yoshikoWrapper.gui;
import java.awt.Dimension;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
......
yoshiko.pathToYoshiko = "NO PATH SET"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment