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

Some work on wrapping parameters

parent fd30aebb
Branches
Tags
No related merge requests found
Showing
with 264 additions and 50 deletions
...@@ -38,7 +38,7 @@ public class CyActivator extends AbstractCyActivator { ...@@ -38,7 +38,7 @@ public class CyActivator extends AbstractCyActivator {
} }
CyApplicationManager cyApplicationManager = getService(context, CyApplicationManager.class); CyApplicationManager cyApplicationManager = getService(context, CyApplicationManager.class);
Core.registerApplicationManager(cyApplicationManager); Core.setApplicationManager(cyApplicationManager);
CySwingApplication cytoscapeDesktopService = getService(context,CySwingApplication.class); CySwingApplication cytoscapeDesktopService = getService(context,CySwingApplication.class);
......
...@@ -14,9 +14,6 @@ public class Core { ...@@ -14,9 +14,6 @@ public class Core {
private static CyApplicationManager cy; private static CyApplicationManager cy;
public static void registerApplicationManager(CyApplicationManager cyApplicationManager) {
cy = cyApplicationManager;
}
public static void performYoshiko(int timeLimit) { public static void performYoshiko(int timeLimit) {
CyNetwork currentNetwork = cy.getCurrentNetwork(); CyNetwork currentNetwork = cy.getCurrentNetwork();
...@@ -60,4 +57,15 @@ public class Core { ...@@ -60,4 +57,15 @@ public class Core {
LibraryInterface.delete_LibraryInput(input); LibraryInterface.delete_LibraryInput(input);
} }
//SETTER / GETTER METHODS
public static void setApplicationManager(CyApplicationManager cyApplicationManager) {
cy = cyApplicationManager;
}
public static CyNetwork getCurrentNetwork() {
return cy.getCurrentNetwork();
}
} }
...@@ -2,17 +2,23 @@ package de.hhu.ba.yoshikoWrapper.core; ...@@ -2,17 +2,23 @@ package de.hhu.ba.yoshikoWrapper.core;
import java.io.File; import java.io.File;
import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
public class YoshikoLoader { public class YoshikoLoader {
private static boolean libraryLoaded;
private static ConfigurationManager cm; private static ConfigurationManager cm;
public static void loadLibrary(String libPath) { public static void loadLibrary(String libPath) {
//TODO: Java has no method to unload a native library :( This means, that reloading the library file on the fly is not possible
//Check 1: Library is already loaded
if (libraryLoaded) { if (isLibraryLoaded()) {
System.out.println("Library is already loaded!");
return; return;
} }
//Attempt to load from a previously stored path
File f = new File (libPath); File f = new File (libPath);
if (!f.exists()) { if (!f.exists()) {
System.out.println("Could not find a previously saved yoshiko library path, needs to be set manually!"); System.out.println("Could not find a previously saved yoshiko library path, needs to be set manually!");
...@@ -24,7 +30,6 @@ public class YoshikoLoader { ...@@ -24,7 +30,6 @@ public class YoshikoLoader {
System.load(libPath); System.load(libPath);
//update cfg //update cfg
cm.getProperties().setProperty("pathToYoshiko", libPath); cm.getProperties().setProperty("pathToYoshiko", libPath);
libraryLoaded = true;
} }
catch(Exception e) { catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -34,7 +39,9 @@ public class YoshikoLoader { ...@@ -34,7 +39,9 @@ public class YoshikoLoader {
//SETTER / GETTER //SETTER / GETTER
public static boolean isLibraryLoaded() { public static boolean isLibraryLoaded() {
return libraryLoaded;
if (LibraryInterface.getVersionString() != null) return true;
return false;
} }
......
package de.hhu.ba.yoshikoWrapper.gui;
import javax.swing.JComponent;
import javax.swing.JPanel;
@SuppressWarnings("serial")
public class ComfortPanel extends JPanel {
/**
* Comfort Function
* @param components The components that are to be added to this panel
*/
protected void addAll(JComponent... components) {
for (JComponent c : components){
this.add(c);
}
}
}
package de.hhu.ba.yoshikoWrapper.gui;
import javax.swing.JFormattedTextField;
/**
* Provides a more strict input field that only accepts double
*/
@SuppressWarnings("serial")
public class DoubleInputField extends JFormattedTextField{
public DoubleInputField() {
super(FormatHelper.getDoubleFormatter());
this.setColumns(8);
}
public int getTimeLimit() {
return Integer.parseInt(getText());
}
}
...@@ -18,4 +18,16 @@ public class FormatHelper { ...@@ -18,4 +18,16 @@ public class FormatHelper {
return formatter; return formatter;
} }
public static NumberFormatter getDoubleFormatter() {
NumberFormat format = NumberFormat.getInstance();
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(Integer.MAX_VALUE);
formatter.setAllowsInvalid(false);
formatter.setCommitsOnValidEdit(true);
return formatter;
}
} }
...@@ -5,16 +5,12 @@ import javax.swing.JFormattedTextField; ...@@ -5,16 +5,12 @@ import javax.swing.JFormattedTextField;
/** /**
* Provides a more strict input field that only accepts integers * Provides a more strict input field that only accepts integers
*/ */
public class NumberInputField extends JFormattedTextField{ @SuppressWarnings("serial")
public class IntegerInputField extends JFormattedTextField{
/** public IntegerInputField() {
* SerialVersionUID
*/
private static final long serialVersionUID = -1144461027491991050L;
public NumberInputField() {
super(FormatHelper.getIntegerFormatter()); super(FormatHelper.getIntegerFormatter());
this.setColumns(8);
} }
public int getTimeLimit() { public int getTimeLimit() {
......
...@@ -5,11 +5,14 @@ import java.awt.event.ActionEvent; ...@@ -5,11 +5,14 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JRadioButton;
import org.cytoscape.application.swing.CytoPanelComponent; 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;
...@@ -20,36 +23,58 @@ import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; ...@@ -20,36 +23,58 @@ import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
* @author Philipp Spohr, Aug 6, 2017 * @author Philipp Spohr, Aug 6, 2017
* *
*/ */
public class MainPanel extends JPanel implements CytoPanelComponent { @SuppressWarnings("serial")
public class MainPanel extends ComfortPanel implements CytoPanelComponent {
/**
* Unique identifier for serialization
*/
private static final long serialVersionUID = 6214827920591046457L;
//SYMBOLIC LINKS //SYMBOLIC LINKS
private MainPanel self = this; //for lambda function references private MainPanel self = this; //for lambda function references
//SWING COMPONENTS
//SWING COMPONENTS
private LibStatusPanel libStatusPanel; private LibStatusPanel libStatusPanel;
private JButton searchLibButton; private JButton searchLibButton;
private JLabel yoshikoVersionLabel; private JLabel yoshikoVersionLabel;
private ModificationCostMapper modCostMapper;
private ButtonGroup heuristicGroup;
private JRadioButton useHeuristic;
private JRadioButton useILP;
private TimeLimitSetter timeLimitSetter; private TimeLimitSetter timeLimitSetter;
private ReductionRulesChooser reductionRulesChooser;
private JCheckBox useTriangleCutsBox;
private JCheckBox usePartitionCutsBox;
/** /**
* Main constructor, creates a new Panel and initializes subcomponents * Main constructor, creates a new Panel and initializes subcomponents
*/ */
public MainPanel() { public MainPanel() {
this.setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS)); this.setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
//SWING COMPONENT INITIALIZATION
//SWING COMPONENT INITIALIZATION
libStatusPanel = new LibStatusPanel(); libStatusPanel = new LibStatusPanel();
libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded()); libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded());
this.add(libStatusPanel);
searchLibButton = new JButton("SHOW YOSHIKO LIB"); yoshikoVersionLabel = new JLabel("YOSHIKO VERSION");
if (LibraryInterface.getVersionString() != null) {
yoshikoVersionLabel.setText(LibraryInterface.getVersionString());
}
searchLibButton = new JButton("POINT TO LIB");
modCostMapper = new ModificationCostMapper();
heuristicGroup = new ButtonGroup();
useILP = new JRadioButton("Use Integer Linear Programming");
useILP.setSelected(true);
useHeuristic = new JRadioButton("Use Heuristic");
heuristicGroup.add(useILP);
heuristicGroup.add(useHeuristic);
searchLibButton.addActionListener(new ActionListener() { searchLibButton.addActionListener(new ActionListener() {
@Override @Override
...@@ -64,7 +89,6 @@ public class MainPanel extends JPanel implements CytoPanelComponent { ...@@ -64,7 +89,6 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
} }
}); });
this.add(searchLibButton);
JButton runButton = new JButton("RUN"); JButton runButton = new JButton("RUN");
runButton.addActionListener(new ActionListener() { runButton.addActionListener(new ActionListener() {
...@@ -79,20 +103,36 @@ public class MainPanel extends JPanel implements CytoPanelComponent { ...@@ -79,20 +103,36 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
} }
}); });
this.add(runButton);
reductionRulesChooser = new ReductionRulesChooser();
timeLimitSetter = new TimeLimitSetter(); timeLimitSetter = new TimeLimitSetter();
this.add(timeLimitSetter);
useTriangleCutsBox = new JCheckBox("Use Triangle Cuts");
usePartitionCutsBox = new JCheckBox("Use Partition Cuts");
yoshikoVersionLabel = new JLabel("YOSHIKO VERSION");
this.add(yoshikoVersionLabel); this.addAll(
libStatusPanel,
yoshikoVersionLabel,
searchLibButton,
modCostMapper,
useILP,
useHeuristic,
timeLimitSetter,
reductionRulesChooser,
useTriangleCutsBox,
usePartitionCutsBox,
runButton
);
this.setVisible(true); this.setVisible(true);
} }
//GETTER / SETTER
public Component getComponent() { public Component getComponent() {
return this; return this;
} }
......
package de.hhu.ba.yoshikoWrapper.gui;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNetwork;
import de.hhu.ba.yoshikoWrapper.core.Core;
@SuppressWarnings("serial") //will never be serialized
public class ModificationCostMapper extends JPanel {
//Symbolic links
private CyNetwork net;
//Swing components
private JComboBox<CyColumn> tableFields;
private JCheckBox useMapping;
public ModificationCostMapper() {
tableFields = new JComboBox<CyColumn>();
useMapping = new JCheckBox("Map modification costs");
useMapping.setToolTipText(
"When you use this value you can assign a column in the edge table to represent the modification costs that are to be paid for deleting an edge."
+"You can also assign negative values if you have a complete graph to represent insertion costs."
+"Note: Any missing values are assumed to be the default values"
);
net = Core.getCurrentNetwork();
//Initial call to get table values
updateValues();
//Add a focus listener to update values
//TODO: This might be a bit inelegant but there is no way to get a callback from CS when a table changes values
this.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
updateValues();
}
@Override
public void focusLost(FocusEvent e) {}
});
}
public void updateValues() {
//Clear entries
tableFields.removeAllItems();
for (CyColumn c : net.getDefaultEdgeTable().getColumns()){
tableFields.addItem(c);
}
}
public CyColumn getValue() {
if (useMapping.isSelected()) {
return tableFields.getItemAt(tableFields.getSelectedIndex());
}
return null;
}
}
package de.hhu.ba.yoshikoWrapper.gui;
import java.awt.Component;
import javax.swing.JCheckBox;
@SuppressWarnings("serial")
public class ReductionRulesChooser extends ComfortPanel{
private JCheckBox useCRule;
private JCheckBox useCCRule;
private JCheckBox useACRule;
private JCheckBox useHERule;
private JCheckBox usePDRRule;
private JCheckBox useSNRule;
public ReductionRulesChooser() {
//Initialize subcomponents
useCRule = new JCheckBox("Use Clique Rule");
useCCRule = new JCheckBox("Use Critical-Clique Rule");
useACRule = new JCheckBox("Use Almost-Clique Rule");
useHERule = new JCheckBox("Use Heavy-Edge 3 in 1 Rule");
usePDRRule = new JCheckBox("Use Parameter Dependent Reduction Rule");
useSNRule = new JCheckBox("Use Similar Neighborhood Rule");
this.addAll(
useCRule,
useCCRule,
useACRule,
useHERule,
usePDRRule,
useSNRule
);
//By default all reduction rules should be applied
for (Component c :this.getComponents()) {
((JCheckBox)c).setSelected(true);
}
}
/** Creates a 6 Bit bitmask representing the currently selected choice of reduction rules.
* @return
*/
public String getBitMask() {
String ret = "";
ret += (useCRule.isSelected() ? "1" : "0");
ret += (useCCRule.isSelected() ? "1" : "0");
ret += (useACRule.isSelected() ? "1" : "0");
ret += (useHERule.isSelected() ? "1" : "0");
ret += (usePDRRule.isSelected() ? "1" : "0");
ret += (useSNRule.isSelected() ? "1" : "0");
return ret;
}
}
...@@ -4,21 +4,16 @@ import java.awt.event.ActionEvent; ...@@ -4,21 +4,16 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JPanel;
public class TimeLimitSetter extends JPanel{ @SuppressWarnings("serial")
public class TimeLimitSetter extends ComfortPanel{
/**
* Unique UID for serialization
*/
private static final long serialVersionUID = 6617497954814566334L;
private JCheckBox checkBox; private JCheckBox checkBox;
private NumberInputField numberField; private IntegerInputField numberField;
public TimeLimitSetter() { public TimeLimitSetter() {
checkBox = new JCheckBox("Use time limit (s):"); checkBox = new JCheckBox("Use time limit (s):");
numberField = new NumberInputField(); numberField = new IntegerInputField();
numberField.setEnabled(false); //By default time limit is turned off numberField.setEnabled(false); //By default time limit is turned off
checkBox.addActionListener( checkBox.addActionListener(
new ActionListener() { new ActionListener() {
...@@ -31,8 +26,7 @@ public class TimeLimitSetter extends JPanel{ ...@@ -31,8 +26,7 @@ public class TimeLimitSetter extends JPanel{
} }
); );
//REGISTER COMPONENTS //REGISTER COMPONENTS
this.add(checkBox); this.addAll(checkBox,numberField);
this.add(numberField);
} }
public int getTimeLimit() { public int getTimeLimit() {
......
/** /**This package contains all Swing extensions and components (frontend)
*
*/
/**
* @author Philipp Spohr, Aug 6, 2017
* *
*/ */
package de.hhu.ba.yoshikoWrapper.gui; package de.hhu.ba.yoshikoWrapper.gui;
\ 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