diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java index 442d482201c69b27f34b4ef184d9d925dac0cac1..507a0bfb2985b6404ed1ea2ae54718d413ec6b39 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java @@ -14,6 +14,7 @@ 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.MainPanelAction; +import de.hhu.ba.yoshikoWrapper.gui.SolutionsPanel; public class CyActivator extends AbstractCyActivator { @@ -42,12 +43,11 @@ public class CyActivator extends AbstractCyActivator { CySwingApplication cytoscapeDesktopService = getService(context,CySwingApplication.class); + //main panel and result panel MainPanel mainPanel = new MainPanel(); + SolutionsPanel solutionsPanel = new SolutionsPanel(); registerService(context,mainPanel,CytoPanelComponent.class, new Properties()); - - MainPanelAction controlPanelAction = new MainPanelAction(cytoscapeDesktopService,mainPanel); - registerService(context,controlPanelAction,CyAction.class, new Properties()); - + registerService(context,solutionsPanel,CytoPanelComponent.class, new Properties()); } } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/LocalizationManager.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/LocalizationManager.java new file mode 100644 index 0000000000000000000000000000000000000000..4a65d2efcb2c081fbf2ac9c5d681e3b363db7e1f --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/LocalizationManager.java @@ -0,0 +1,35 @@ +package de.hhu.ba.yoshikoWrapper.core; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Locale; +import java.util.ResourceBundle; + +public class LocalizationManager { + //Locales + static public final Locale usEnglish = new Locale("en","US"); + static public final Locale german = new Locale("de","DE"); + //List of Locales + static public final ArrayList<Locale> locales = new ArrayList<Locale>( + Arrays.asList( + usEnglish, + german + ) + ); + + static private ResourceBundle currentBundle; + + static public Locale currentLanguage = usEnglish; + + static public ResourceBundle yoshikoStrings() { + if (currentBundle == null) { + currentBundle = ResourceBundle.getBundle("YoshikoStrings",currentLanguage); + } + return currentBundle; + } + + static public void switchLanguage(Locale lcl) { + currentLanguage = lcl; + currentBundle = ResourceBundle.getBundle("YoshikoStrings",currentLanguage); + } +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/NetworkParser.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/NetworkParser.java index 3ee549796e15330ad808ce41da6f288ee838121b..8c3fd592ca156ce1b4f987815242bba4869829b0 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/NetworkParser.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/NetworkParser.java @@ -49,16 +49,13 @@ public class NetworkParser { if (weightColumn != null){ //Check if the column contains an entry for the respective edge //It is possible, that there are missing entries - if (edgeEntry.getAllValues().containsKey(weightColumn.getName())){ - //Find out if the weights are double or integer and cast accordingly - Class<?> weightType = weightColumn.getType(); - if (weightType == Integer.class) { - weight = (int)edgeEntry.get(weightColumn.getName(), weightType); + if (edgeEntry.get(weightColumn.getName(), weightColumn.getType()) != null){ + if (weightColumn.getType() == Integer.class) { + weight = edgeEntry.get(weightColumn.getName(), Integer.class); } - else if(weightType == Double.class) { - weight = (double)edgeEntry.get(weightColumn.getName(), weightType); + else if (weightColumn.getType() == Double.class) { + weight = edgeEntry.get(weightColumn.getName(), Double.class); } - } } @@ -67,17 +64,18 @@ public class NetworkParser { boolean permanent = false; if (permanentColumn != null) { //Additional check as it is not required to have a value in every row - if (edgeEntry.getAllValues().containsKey(permanentColumn.getName())) { + if (edgeEntry.get(permanentColumn.getName(), Boolean.class) != null) { permanent = (boolean)edgeEntry.get(permanentColumn.getName(), Boolean.class); } } if (forbiddenColumn != null) { //Additional check as it is not required to have a value in every row - if (edgeEntry.getAllValues().containsKey(forbiddenColumn.getName())) { + if (edgeEntry.get(forbiddenColumn.getName(), Boolean.class) != null) { forbidden = (boolean)edgeEntry.get(forbiddenColumn.getName(), Boolean.class); } } + System.out.println("Found Edge: "+edgeEntry.get("name", String.class)+ " with weight:"+weight); logger.debug("Found Edge: "+edgeEntry.get("name", String.class)+ " with weight:"+weight); diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ColumnMapper.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ColumnMapper.java index b17b17b20cae59a787ae1ec3a9e2e848091dc1a5..6744a35ae3980ffe826ed6161ad7ecda2961c028 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ColumnMapper.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ColumnMapper.java @@ -3,9 +3,6 @@ package de.hhu.ba.yoshikoWrapper.gui; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; - import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JCheckBox; diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/EditCostPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/EditCostPanel.java index c5b7c0e980f7888b3a7f63ba7ea6f0d3114abacd..83284aed7ba6ae5364ba266db37ca4b32cdb5c7d 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/EditCostPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/EditCostPanel.java @@ -3,7 +3,6 @@ package de.hhu.ba.yoshikoWrapper.gui; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JLabel; -import javax.swing.JPanel; import javax.swing.border.EtchedBorder; import org.cytoscape.model.CyColumn; 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 a403598585aba4b6504901daf6c6716b100a2fe5..48aed6c745a3b04c48091bd11e73d136aa085b09 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/FormatHelper.java @@ -13,7 +13,6 @@ public class FormatHelper { formatter.setValueClass(Integer.class); formatter.setMinimum(0); formatter.setMaximum(Integer.MAX_VALUE); - formatter.setAllowsInvalid(false); formatter.setCommitsOnValidEdit(true); return formatter; @@ -25,7 +24,6 @@ public class FormatHelper { formatter.setValueClass(Double.class); formatter.setMinimum(minValue); formatter.setMaximum(maxValue); - formatter.setAllowsInvalid(false); formatter.setCommitsOnValidEdit(true); return formatter; diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LanguageSwitcher.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LanguageSwitcher.java new file mode 100644 index 0000000000000000000000000000000000000000..638bdc08ff709841729b8885d5104fc8155d3f51 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LanguageSwitcher.java @@ -0,0 +1,30 @@ +package de.hhu.ba.yoshikoWrapper.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Locale; + +import javax.swing.JComboBox; + +import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; + +@SuppressWarnings( "serial") +public class LanguageSwitcher extends JComboBox<Locale>{ + + public LanguageSwitcher() { + for (Locale l: LocalizationManager.locales) { + this.addItem(l); + } + this.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + System.out.println("HI"); + LocalizationManager.switchLanguage(getItemAt(getSelectedIndex())); + } + + }); + } + + +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LibStatusPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LibStatusPanel.java index 82e0e9618c10b5e952d6157d23bfeb522a2fe478..0cc321a47527c0a12e74cf239a1233e368852eb3 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LibStatusPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LibStatusPanel.java @@ -1,5 +1,7 @@ package de.hhu.ba.yoshikoWrapper.gui; +import java.awt.Color; + import javax.swing.JLabel; public class LibStatusPanel extends JLabel { @@ -11,10 +13,12 @@ public class LibStatusPanel extends JLabel { public void setStyle(boolean libraryLoaded) { if(libraryLoaded) { - this.setText("YOSHIKO LOADED: TRUE"); + this.setText("YOSHIKO LIBRARY READY!"); + this.setForeground(Color.GREEN); } else { - this.setText("YOSHIKO LOADED: FALSE"); + this.setText("YOSHIKO LIBRARY NOT LOADED :("); + this.setForeground(Color.RED); } } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LibraryPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LibraryPanel.java new file mode 100644 index 0000000000000000000000000000000000000000..d2e666b761d9feab9da282045940e8931c80d895 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LibraryPanel.java @@ -0,0 +1,62 @@ +package de.hhu.ba.yoshikoWrapper.gui; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.border.EtchedBorder; + +import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; +import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; +import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; + +@SuppressWarnings("serial") +public class LibraryPanel extends ComfortPanel { + + //SYMBOLIC LINKS + private LibraryPanel self = this; + + private LibStatusPanel libStatusPanel; + private JButton searchLibButton; + private JLabel yoshikoVersionLabel; + + + public LibraryPanel() { + this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); + //SWING COMPONENT INITIALIZATION + libStatusPanel = new LibStatusPanel(); + searchLibButton = new JButton(LocalizationManager.yoshikoStrings().getString("resolveLibPath")); + yoshikoVersionLabel = new JLabel(LocalizationManager.yoshikoStrings().getString("yoshVersion")); + + libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded()); + + if (YoshikoLoader.isLibraryLoaded()) { + yoshikoVersionLabel.setText(LibraryInterface.getVersionString()); + searchLibButton.setEnabled(false); + } + + + searchLibButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + final YLibChooser c = new YLibChooser(); + int returnVal = c.showOpenDialog(self); + if (returnVal == JFileChooser.APPROVE_OPTION) { + YoshikoLoader.loadLibrary(c.getSelectedFile().getAbsolutePath()); + } + libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded()); + yoshikoVersionLabel.setText(LibraryInterface.getVersionString()); + searchLibButton.setEnabled(false); + } + }); + + this.addAll(libStatusPanel,yoshikoVersionLabel,searchLibButton); + + //Decoration/Visual + this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); + } +} 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 ff42424796102328cd159325577432127b49a4dc..ac0b3fbbaac9cac320d48cab213a95d4e02261ae 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java @@ -9,15 +9,12 @@ 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.JRadioButton; import org.cytoscape.application.swing.CytoPanelComponent; import org.cytoscape.application.swing.CytoPanelName; import de.hhu.ba.yoshikoWrapper.core.Core; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; -import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; /**This class describes the Swing Panel that the user interacts with in cytoscape * @author Philipp Spohr, Aug 6, 2017 @@ -26,26 +23,23 @@ import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; @SuppressWarnings("serial") public class MainPanel extends ComfortPanel implements CytoPanelComponent { - //SYMBOLIC LINKS - private MainPanel self = this; //for lambda function references - //SWING COMPONENTS - private LibStatusPanel libStatusPanel; - private JButton searchLibButton; - private JLabel yoshikoVersionLabel; + private final LanguageSwitcher langSwitcher; + + private final LibraryPanel libraryPanel; - private EditCostPanel ecPanel; + private final EditCostPanel ecPanel; - private ButtonGroup heuristicGroup; - private JRadioButton useHeuristic; - private JRadioButton useILP; + private final ButtonGroup heuristicGroup; + private final JRadioButton useHeuristic; + private final JRadioButton useILP; - private TimeLimitSetter timeLimitSetter; + private final TimeLimitSetter timeLimitSetter; - private ReductionRulesChooser reductionRulesChooser; + private final ReductionRulesChooser reductionRulesChooser; - private JCheckBox useTriangleCutsBox; - private JCheckBox usePartitionCutsBox; + private final JCheckBox useTriangleCutsBox; + private final JCheckBox usePartitionCutsBox; @@ -56,15 +50,9 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent { this.setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS)); - //SWING COMPONENT INITIALIZATION - libStatusPanel = new LibStatusPanel(); - libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded()); - - yoshikoVersionLabel = new JLabel("YOSHIKO VERSION"); - if (LibraryInterface.getVersionString() != null) { - yoshikoVersionLabel.setText(LibraryInterface.getVersionString()); - } - searchLibButton = new JButton("POINT TO LIB"); + //Initialize Swing components + langSwitcher = new LanguageSwitcher(); + libraryPanel = new LibraryPanel(); ecPanel = new EditCostPanel(); @@ -75,25 +63,11 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent { heuristicGroup.add(useILP); heuristicGroup.add(useHeuristic); - searchLibButton.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(ActionEvent e) { - final YLibChooser c = new YLibChooser(); - int returnVal = c.showOpenDialog(self); - if (returnVal == JFileChooser.APPROVE_OPTION) { - YoshikoLoader.loadLibrary(c.getSelectedFile().getAbsolutePath()); - } - libStatusPanel.setStyle(YoshikoLoader.isLibraryLoaded()); - yoshikoVersionLabel.setText(LibraryInterface.getVersionString()); - } - - }); JButton runButton = new JButton("RUN"); runButton.addActionListener(new ActionListener() { - + @Override public void actionPerformed(ActionEvent e) { if (YoshikoLoader.isLibraryLoaded()){ @@ -120,9 +94,8 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent { this.addAll( - libStatusPanel, - yoshikoVersionLabel, - searchLibButton, + langSwitcher, + libraryPanel, ecPanel, useILP, useHeuristic, @@ -155,7 +128,7 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent { public String getTitle() { //TODO: Be creative I guess - return "Yoshiko Wrapper Panel"; + return "Yoshiko"; } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionsPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionsPanel.java new file mode 100644 index 0000000000000000000000000000000000000000..588c66f411caf5b58b56f8ac28b1ede9b9ed2fd8 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionsPanel.java @@ -0,0 +1,36 @@ +package de.hhu.ba.yoshikoWrapper.gui; + +import java.awt.Component; + +import javax.swing.Icon; + +import org.cytoscape.application.swing.CytoPanelComponent; +import org.cytoscape.application.swing.CytoPanelName; + +import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; + +@SuppressWarnings("serial")//Will never be serialized +public class SolutionsPanel extends ComfortPanel implements CytoPanelComponent{ + + @Override + public Component getComponent() { + return this; + } + + @Override + public CytoPanelName getCytoPanelName() { + return CytoPanelName.EAST; + } + + @Override + public String getTitle() { + return LocalizationManager.yoshikoStrings().getString("resultsPanelTitle"); + } + + @Override + public Icon getIcon() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/main/resources/YoshikoStrings.properties b/src/main/resources/YoshikoStrings.properties new file mode 100644 index 0000000000000000000000000000000000000000..9d773a7796479c3d758c9bc4b19244b128f537b0 --- /dev/null +++ b/src/main/resources/YoshikoStrings.properties @@ -0,0 +1,3 @@ +resultsPanelTitle = Yoshiko Results +yoshVersion = Yoshiko Version +resolveLibPath = Resolve Yoshiko Library Path \ No newline at end of file diff --git a/src/main/resources/YoshikoStrings_de_DE.properties b/src/main/resources/YoshikoStrings_de_DE.properties new file mode 100644 index 0000000000000000000000000000000000000000..079652eeda680d61bb20b9da5fce6708dc989494 --- /dev/null +++ b/src/main/resources/YoshikoStrings_de_DE.properties @@ -0,0 +1,2 @@ +resultsPanelTitle = Yoshiko Ergebnisse +resolveLibPath = Yoshiko Library suchen \ No newline at end of file