diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java index 7dc34f7fe13d5f00a552065ac61931a906880ba8..442d482201c69b27f34b4ef184d9d925dac0cac1 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java @@ -38,7 +38,7 @@ public class CyActivator extends AbstractCyActivator { } CyApplicationManager cyApplicationManager = getService(context, CyApplicationManager.class); - Core.registerApplicationManager(cyApplicationManager); + Core.setApplicationManager(cyApplicationManager); CySwingApplication cytoscapeDesktopService = getService(context,CySwingApplication.class); diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/Core.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/Core.java index 8d15d888412ed64bcfdf701f17d39db95b0e1391..9dd443be77506e2c718bcf4675a091ae5a7a79cf 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/Core.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/Core.java @@ -14,9 +14,6 @@ public class Core { private static CyApplicationManager cy; - public static void registerApplicationManager(CyApplicationManager cyApplicationManager) { - cy = cyApplicationManager; - } public static void performYoshiko(int timeLimit) { CyNetwork currentNetwork = cy.getCurrentNetwork(); @@ -59,5 +56,16 @@ public class Core { LibraryInterface.delete_LibraryInput(input); } + + + //SETTER / GETTER METHODS + + public static void setApplicationManager(CyApplicationManager cyApplicationManager) { + cy = cyApplicationManager; + } + + public static CyNetwork getCurrentNetwork() { + return cy.getCurrentNetwork(); + } } 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 b9a430f28def8440dc9a9bae6e8ec9d1dd46ad31..e8fc5a9aeb123dea93490b868546e631578cb9f9 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java @@ -2,17 +2,23 @@ package de.hhu.ba.yoshikoWrapper.core; import java.io.File; +import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; + public class YoshikoLoader { - private static boolean libraryLoaded; private static ConfigurationManager cm; 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; } + //Attempt to load from a previously stored path File f = new File (libPath); if (!f.exists()) { System.out.println("Could not find a previously saved yoshiko library path, needs to be set manually!"); @@ -24,7 +30,6 @@ public class YoshikoLoader { System.load(libPath); //update cfg cm.getProperties().setProperty("pathToYoshiko", libPath); - libraryLoaded = true; } catch(Exception e) { e.printStackTrace(); @@ -34,7 +39,9 @@ public class YoshikoLoader { //SETTER / GETTER public static boolean isLibraryLoaded() { - return libraryLoaded; + + if (LibraryInterface.getVersionString() != null) return true; + return false; } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ComfortPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ComfortPanel.java new file mode 100644 index 0000000000000000000000000000000000000000..e2e320dbcfe5e42ec35c4e9e2e6cb7c3c86c8443 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ComfortPanel.java @@ -0,0 +1,20 @@ +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); + } + + } + +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/DoubleInputField.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/DoubleInputField.java new file mode 100644 index 0000000000000000000000000000000000000000..ba893825fcd140fcc01427755e2eb85c0264c16e --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/DoubleInputField.java @@ -0,0 +1,19 @@ +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()); + } +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java index 9de27eae347737a6e1557162006e1188ccf86cef..dd448186bb2396aafb773173aeb941b8f1731a32 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java @@ -18,4 +18,16 @@ public class FormatHelper { 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; + } + } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/NumberInputField.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/IntegerInputField.java similarity index 58% rename from src/main/java/de/hhu/ba/yoshikoWrapper/gui/NumberInputField.java rename to src/main/java/de/hhu/ba/yoshikoWrapper/gui/IntegerInputField.java index 51cd3f4a014bb1f64772e697e636508e5307cdcd..fe400a19e488d7041dd581029ee72453551e431a 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/NumberInputField.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/IntegerInputField.java @@ -5,16 +5,12 @@ import javax.swing.JFormattedTextField; /** * Provides a more strict input field that only accepts integers */ -public class NumberInputField extends JFormattedTextField{ +@SuppressWarnings("serial") +public class IntegerInputField extends JFormattedTextField{ - /** - * SerialVersionUID - */ - private static final long serialVersionUID = -1144461027491991050L; - - - public NumberInputField() { + public IntegerInputField() { super(FormatHelper.getIntegerFormatter()); + this.setColumns(8); } public int getTimeLimit() { diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java index 05a4de5ae137f03d88fc110fe3bc57fcd4620b48..a50e9be6eeb50fd133b3ec531b4510c726451259 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java @@ -5,11 +5,14 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; import javax.swing.Icon; import javax.swing.JButton; +import javax.swing.JCheckBox; import javax.swing.JFileChooser; import javax.swing.JLabel; -import javax.swing.JPanel; +import javax.swing.JRadioButton; + import org.cytoscape.application.swing.CytoPanelComponent; import org.cytoscape.application.swing.CytoPanelName; import de.hhu.ba.yoshikoWrapper.core.Core; @@ -20,36 +23,58 @@ import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; * @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 private MainPanel self = this; //for lambda function references - //SWING COMPONENTS + //SWING COMPONENTS private LibStatusPanel libStatusPanel; private JButton searchLibButton; private JLabel yoshikoVersionLabel; + + private ModificationCostMapper modCostMapper; + + private ButtonGroup heuristicGroup; + private JRadioButton useHeuristic; + private JRadioButton useILP; + private TimeLimitSetter timeLimitSetter; + + private ReductionRulesChooser reductionRulesChooser; + + private JCheckBox useTriangleCutsBox; + private JCheckBox usePartitionCutsBox; + + /** * Main constructor, creates a new Panel and initializes subcomponents */ public MainPanel() { - this.setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS)); - //SWING COMPONENT INITIALIZATION + //SWING COMPONENT INITIALIZATION libStatusPanel = new LibStatusPanel(); 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() { @Override @@ -64,7 +89,6 @@ public class MainPanel extends JPanel implements CytoPanelComponent { } }); - this.add(searchLibButton); JButton runButton = new JButton("RUN"); runButton.addActionListener(new ActionListener() { @@ -79,19 +103,35 @@ public class MainPanel extends JPanel implements CytoPanelComponent { } }); - this.add(runButton); + reductionRulesChooser = new ReductionRulesChooser(); 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); } + + + //GETTER / SETTER public Component getComponent() { return this; diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ModificationCostMapper.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ModificationCostMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..f5f145c2cf17d38b49505a0e10a0206b78c66c23 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ModificationCostMapper.java @@ -0,0 +1,68 @@ +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; + } + +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ReductionRulesChooser.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ReductionRulesChooser.java new file mode 100644 index 0000000000000000000000000000000000000000..12273280c21033b3c82980575e73b1befab49d08 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ReductionRulesChooser.java @@ -0,0 +1,54 @@ +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; + } +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/TimeLimitSetter.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/TimeLimitSetter.java index 536f9a1d2e4fc6b6c8e5bb73220ce9dd72572d3e..c5445d6509f906abf71b60fb3c29cbee661afebc 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/TimeLimitSetter.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/TimeLimitSetter.java @@ -4,21 +4,16 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JCheckBox; -import javax.swing.JPanel; -public class TimeLimitSetter extends JPanel{ - - /** - * Unique UID for serialization - */ - private static final long serialVersionUID = 6617497954814566334L; - +@SuppressWarnings("serial") +public class TimeLimitSetter extends ComfortPanel{ + private JCheckBox checkBox; - private NumberInputField numberField; + private IntegerInputField numberField; public TimeLimitSetter() { checkBox = new JCheckBox("Use time limit (s):"); - numberField = new NumberInputField(); + numberField = new IntegerInputField(); numberField.setEnabled(false); //By default time limit is turned off checkBox.addActionListener( new ActionListener() { @@ -31,8 +26,7 @@ public class TimeLimitSetter extends JPanel{ } ); //REGISTER COMPONENTS - this.add(checkBox); - this.add(numberField); + this.addAll(checkBox,numberField); } public int getTimeLimit() { diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/package-info.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/package-info.java index 312d9193351f22fd2d291114f1927339abba7452..af1b4ba45c3d45e8e18a4dea897dfc1baf319f6f 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/package-info.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/package-info.java @@ -1,8 +1,4 @@ -/** - * - */ -/** - * @author Philipp Spohr, Aug 6, 2017 +/**This package contains all Swing extensions and components (frontend) * */ package de.hhu.ba.yoshikoWrapper.gui; \ No newline at end of file