From 0a313f10fa501b42f88654c311adcd22a70bd1af Mon Sep 17 00:00:00 2001 From: Philipp Spohr <spohr.philipp@web.de> Date: Sun, 13 Aug 2017 17:58:39 +0200 Subject: [PATCH] some basic work on implementing time limit --- .../ba/yoshikoWrapper/gui/FormatHelper.java | 21 +++++++++ .../hhu/ba/yoshikoWrapper/gui/MainPanel.java | 5 +++ .../yoshikoWrapper/gui/NumberInputField.java | 23 ++++++++++ .../yoshikoWrapper/gui/TimeLimitSetter.java | 45 +++++++++++++++++++ .../yoshikoWrapper/swig/LibraryInterface.java | 4 ++ .../swig/LibraryInterfaceJNI.java | 1 + 6 files changed, 99 insertions(+) create mode 100644 src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java create mode 100644 src/main/java/de/hhu/ba/yoshikoWrapper/gui/NumberInputField.java create mode 100644 src/main/java/de/hhu/ba/yoshikoWrapper/gui/TimeLimitSetter.java diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java new file mode 100644 index 0000000..9de27ea --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java @@ -0,0 +1,21 @@ +package de.hhu.ba.yoshikoWrapper.gui; + +import java.text.NumberFormat; + +import javax.swing.text.NumberFormatter; + +public class FormatHelper { + + public static NumberFormatter getIntegerFormatter() { + 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/MainPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java index 5aa2e73..9a817bd 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java @@ -19,6 +19,7 @@ import de.hhu.ba.yoshikoWrapper.core.Core; import de.hhu.ba.yoshikoWrapper.core.NetworkParser; import de.hhu.ba.yoshikoWrapper.core.NodeMap; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; +import de.hhu.ba.yoshikoWrapper.gui.TimeLimitSetter; import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput; import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_ysk__ClusterEditingSolutions; @@ -42,6 +43,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent { private LibStatusPanel libStatusPanel; private JButton searchLibButton; private JLabel yoshikoVersionLabel; + private TimeLimitSetter timeLimitSetter; /** * Main constructor, creates a new Panel and initializes subcomponents @@ -91,6 +93,9 @@ public class MainPanel extends JPanel implements CytoPanelComponent { // // // + timeLimitSetter = new TimeLimitSetter(); + this.add(timeLimitSetter); + yoshikoVersionLabel = new JLabel("YOSHIKO VERSION"); this.add(yoshikoVersionLabel); diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/NumberInputField.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/NumberInputField.java new file mode 100644 index 0000000..c876695 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/NumberInputField.java @@ -0,0 +1,23 @@ +package de.hhu.ba.yoshikoWrapper.gui; + +import java.text.NumberFormat; + +import javax.swing.JFormattedTextField; +import javax.swing.text.NumberFormatter; + +/** + * Provides a more strict input field that only accepts integers + */ +public class NumberInputField extends JFormattedTextField{ + + /** + * SerialVersionUID + */ + private static final long serialVersionUID = -1144461027491991050L; + + + public NumberInputField() { + super(FormatHelper.getIntegerFormatter()); + } + +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/TimeLimitSetter.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/TimeLimitSetter.java new file mode 100644 index 0000000..7bb6cb5 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/TimeLimitSetter.java @@ -0,0 +1,45 @@ +package de.hhu.ba.yoshikoWrapper.gui; + +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; + + private JCheckBox checkBox; + private NumberInputField numberField; + + public TimeLimitSetter() { + checkBox = new JCheckBox(); + numberField = new NumberInputField(); + numberField.setEnabled(false); //By default time limit is turned off + checkBox.addActionListener( + new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + numberField.setEnabled(checkBox.isSelected()); + } + + } + ); + //REGISTER COMPONENTS + this.add(checkBox); + this.add(numberField); + } + + public int getTimeLimit() { + if (checkBox.isSelected()) { + return -1; + } + return (int)numberField.getValue(); + } + +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swig/LibraryInterface.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swig/LibraryInterface.java index d06fa11..e87817e 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swig/LibraryInterface.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swig/LibraryInterface.java @@ -114,4 +114,8 @@ public class LibraryInterface { return (cPtr == 0) ? null : new SWIGTYPE_p_ysk__ClusterEditingSolutions(cPtr, false); } + public static void setTimeLimit(int limit) { + LibraryInterfaceJNI.setTimeLimit(limit); + } + } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swig/LibraryInterfaceJNI.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swig/LibraryInterfaceJNI.java index aa49472..2ed4244 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swig/LibraryInterfaceJNI.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swig/LibraryInterfaceJNI.java @@ -34,4 +34,5 @@ public class LibraryInterfaceJNI { public final static native void LibraryInput_addEdge__SWIG_1(long jarg1, long jarg2, long jarg3, double jarg4, boolean jarg5, boolean jarg6); public final static native String getVersionString(); public final static native long processLibraryInput(long jarg1); + public final static native void setTimeLimit(int jarg1); } -- GitLab