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

Some refactoring // cleanup

parent 0c43e678
No related branches found
No related tags found
No related merge requests found
Showing
with 343 additions and 100 deletions
......@@ -3,6 +3,7 @@ package de.hhu.ba.yoshikoWrapper;
import java.util.Properties;
import org.cytoscape.application.CyApplicationManager;
import org.cytoscape.application.events.SetCurrentNetworkListener;
import org.cytoscape.application.swing.CySwingApplication;
import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.model.CyNetworkFactory;
......@@ -88,6 +89,7 @@ public class CyActivator extends AbstractCyActivator {
registerService(context,netChangeListener, ColumnCreatedListener.class, new Properties());
registerService(context,netChangeListener, ColumnDeletedListener.class, new Properties());
registerService(context,netChangeListener, SessionLoadedListener.class, new Properties());
registerService(context,netChangeListener, SetCurrentNetworkListener.class, new Properties());
}
......
package de.hhu.ba.yoshikoWrapper.core;
import javax.swing.ImageIcon;
public class GraphicsLoader {
private static ImageIcon yoshikoLogo;
private static ImageIcon yoshikoText;
public static ImageIcon getLogo() {
if (yoshikoLogo == null) {
yoshikoLogo = new ImageIcon("/resources/graphics/YoshikoAlphaLogo.png");
}
return yoshikoLogo;
}
public static ImageIcon getText() {
if (yoshikoLogo == null) {
yoshikoLogo = new ImageIcon("/graphics/YoshikoAlphaText.png");
}
return yoshikoText;
}
}
package de.hhu.ba.yoshikoWrapper.core;
import org.cytoscape.application.events.SetCurrentNetworkEvent;
import org.cytoscape.application.events.SetCurrentNetworkListener;
import org.cytoscape.model.events.AddedEdgesEvent;
import org.cytoscape.model.events.AddedEdgesListener;
import org.cytoscape.model.events.ColumnCreatedEvent;
......@@ -22,7 +24,8 @@ AddedEdgesListener,
RemovedEdgesListener,
ColumnCreatedListener,
ColumnDeletedListener,
SessionLoadedListener
SessionLoadedListener,
SetCurrentNetworkListener
{
private ColumnMapper columnMapper;
......@@ -60,4 +63,9 @@ SessionLoadedListener
columnMapper.updateValues();
}
@Override
public void handleEvent(SetCurrentNetworkEvent e) {
columnMapper.updateValues();
}
}
package de.hhu.ba.yoshikoWrapper.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
......@@ -18,43 +17,64 @@ public class ColumnMapper extends ComfortPanel{
//Swing components
private JComboBox<CyColumn> editingCostMapper;
private JComboBox<CyColumn> permanentMapper;
private JComboBox<CyColumn> forbiddenMapper;
private final JComboBox<CyColumn> editingCostMapper;
private final JComboBox<CyColumn> permanentMapper;
private final JComboBox<CyColumn> forbiddenMapper;
private JCheckBox useMappingCost;
private JCheckBox useMappingPerm;
private JCheckBox useMappingForb;
private final JCheckBox useMappingCost;
private final JCheckBox useMappingPerm;
private final JCheckBox useMappingForb;
private JButton updateColumns;
private final ComfortPanel costGroup;
private final ComfortPanel permGroup;
private final ComfortPanel forbGroup;
public ColumnMapper() {
this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
//SWING COMPONENTS
//Combo-Boxes that map to the CyColumns
editingCostMapper = new JComboBox<CyColumn>();
permanentMapper = new JComboBox<CyColumn>();
forbiddenMapper = new JComboBox<CyColumn>();
//Should only be enabled if the option is checked
editingCostMapper.setEnabled(false);
permanentMapper.setEnabled(false);
forbiddenMapper.setEnabled(false);
useMappingCost = new JCheckBox("Map modification costs");
useMappingPerm = new JCheckBox("Map edges as permanent");
useMappingForb = new JCheckBox("Map edges as forbidden");
updateColumns = new JButton("Update Columns!");
useMappingCost.addActionListener(
new EnableWhenSelectedListener(useMappingCost, editingCostMapper)
);
useMappingPerm.addActionListener(
new EnableWhenSelectedListener(useMappingPerm, permanentMapper)
);
useMappingForb.addActionListener(
new EnableWhenSelectedListener(useMappingForb, forbiddenMapper)
);
this.addAll(useMappingCost,editingCostMapper,useMappingPerm,permanentMapper,useMappingForb,forbiddenMapper,updateColumns);
//Initial call to get table values
updateValues();
//Add a focus listener to update values
updateColumns.addActionListener(new ActionListener() {
costGroup = new ComfortPanel();
permGroup = new ComfortPanel();
forbGroup = new ComfortPanel();
costGroup.setLayout(new FlowLayout());
permGroup.setLayout(new FlowLayout());
forbGroup.setLayout(new FlowLayout());
costGroup.addAll(useMappingCost,editingCostMapper);
permGroup.addAll(useMappingPerm,permanentMapper);
forbGroup.addAll(useMappingForb,forbiddenMapper);
@Override
public void actionPerformed(ActionEvent e) {
updateValues(); //shitty temporary solution
}
});
this.addAll(costGroup,permGroup,forbGroup);
//Initial call to get table values
updateValues();
}
......
package de.hhu.ba.yoshikoWrapper.gui;
import java.awt.FlowLayout;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import org.cytoscape.model.CyColumn;
import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
@SuppressWarnings("serial") //Will never be serialized
public class EditCostPanel extends ComfortPanel {
//SWING COMPONENTS
private ColumnMapper columnMapper;
private DoubleInputField icField;
private DoubleInputField dcField;
private JLabel icLabel;
private JLabel dcLabel;
......@@ -25,23 +32,33 @@ public class EditCostPanel extends ComfortPanel {
this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
//Initialize components
columnMapper = new ColumnMapper();
icField = new DoubleInputField(Double.NEGATIVE_INFINITY,0);
dcField = new DoubleInputField(0,Double.POSITIVE_INFINITY);
icField.setText("-1.0");
icField.setToolTipText(LocalizationManager.get("icTooltip"));
dcField.setText("1.0");
icLabel = new JLabel("Insertion Cost:");
dcLabel = new JLabel("Deletion Cost:");
icLabel = new JLabel(LocalizationManager.get("defaultInsertion"));
dcLabel = new JLabel(LocalizationManager.get("defaultDeletion"));
//Group the labels with their text fields
groupIC = new ComfortPanel();
groupDC = new ComfortPanel();
groupIC.setLayout(new FlowLayout());
groupDC.setLayout(new FlowLayout());
groupIC.addAll(icLabel,icField);
groupDC.addAll(dcLabel,dcField);
this.addAll(columnMapper,groupIC,groupDC);
//Decoration/Visual
this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
Border border = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
border = BorderFactory.createTitledBorder(border,LocalizationManager.get("editingCostPanel"));
this.setBorder(border);
}
//SETTER / GETTER
......
package de.hhu.ba.yoshikoWrapper.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
public class EnableWhenSelectedListener implements ActionListener {
private final JComponent component;
private final JCheckBox checkBox;
public EnableWhenSelectedListener(JCheckBox cb, JComponent c) {
this.component = c;
this.checkBox = cb;
}
@Override
public void actionPerformed(ActionEvent e) {
if (checkBox.isSelected()) {
component.setEnabled(true);
}
else {
component.setEnabled(false);
}
}
}
package de.hhu.ba.yoshikoWrapper.gui;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;
import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.application.swing.CytoPanelName;
......@@ -19,6 +21,7 @@ import org.cytoscape.work.TaskIterator;
import de.hhu.ba.yoshikoWrapper.core.AlgorithmTask;
import de.hhu.ba.yoshikoWrapper.core.CyCore;
import de.hhu.ba.yoshikoWrapper.core.GraphicsLoader;
import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader;
......@@ -30,81 +33,101 @@ import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader;
public class MainPanel extends ComfortPanel implements CytoPanelComponent {
//SWING COMPONENTS
private final YoshikoHeader header;
/**
* Swing is a bit special sometimes, so a panel is used to wrap the lang-switcher.
* This prevents stretching of the component
*/
private final ComfortPanel langSwitcherWrapper;
private final LanguageSwitcher langSwitcher;
private final LibraryPanel libraryPanel;
private final EditCostPanel ecPanel;
private final ButtonGroup heuristicGroup;
private final JRadioButton useHeuristic;
private final JRadioButton useILP;
private final TimeLimitSetter timeLimitSetter;
private final ReductionRulesChooser reductionRulesChooser;
private final JCheckBox useTriangleCutsBox;
private final JCheckBox usePartitionCutsBox;
private final OperationModePanel opModePanel;
private final JCheckBox showAdvancedOptions;
private final SolutionNumberChooser solutionNumberChooser;
private final ArrayList<JComponent> advancedOptions;
/**
* Main constructor, creates a new Panel and initializes subcomponents
* @param solPanel
*/
public MainPanel() {
//SWING INIT
this.setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
this.setLayout(new FlowLayout());
//Initialize Swing components
header = new YoshikoHeader();
langSwitcherWrapper = new ComfortPanel();
langSwitcher = new LanguageSwitcher();
langSwitcherWrapper.addAll(new JLabel(LocalizationManager.get("switchLanguage")),langSwitcher);
langSwitcherWrapper.setLayout(new FlowLayout());
libraryPanel = new LibraryPanel();
ecPanel = new EditCostPanel();
heuristicGroup = new ButtonGroup();
useILP = new JRadioButton("Use Integer Linear Programming");
useILP.setSelected(true);
useHeuristic = new JRadioButton("Use Heuristic");
heuristicGroup.add(useILP);
heuristicGroup.add(useHeuristic);
solutionNumberChooser = new SolutionNumberChooser();
opModePanel = new OperationModePanel();
reductionRulesChooser = new ReductionRulesChooser();
timeLimitSetter = new TimeLimitSetter();
useTriangleCutsBox = new JCheckBox("Use Triangle Cuts");
usePartitionCutsBox = new JCheckBox("Use Partition Cuts");
JButton runButton = new JButton("RUN");
runButton.addActionListener(buttonListener);
//Link time limit option to ILP
useILP.addActionListener(ilpHeuristicSwitch);
useHeuristic.addActionListener(ilpHeuristicSwitch);
showAdvancedOptions = new JCheckBox(LocalizationManager.get("showAdvanced"));
showAdvancedOptions.addActionListener(toggleAdvancedOptionsListener);
this.addAll(
langSwitcher,
header,
langSwitcherWrapper,
showAdvancedOptions,
libraryPanel,
ecPanel,
useILP,
useHeuristic,
timeLimitSetter,
reductionRulesChooser,
useTriangleCutsBox,
usePartitionCutsBox,
solutionNumberChooser,
opModePanel,
runButton
);
advancedOptions = new ArrayList<JComponent>();
//Manage all advanced components separately to enable toggling
advancedOptions.addAll(
Arrays.asList(
opModePanel,
reductionRulesChooser
)
);
showAdvancedOptions(false);
this.setVisible(true);
}
private ActionListener toggleAdvancedOptionsListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showAdvancedOptions(showAdvancedOptions.isSelected());
}
};
private void showAdvancedOptions(boolean show) {
for (JComponent j : advancedOptions) {
j.setVisible(show);
}
}
/**
* ButtonListener for the "Run" Button
* Handles calling the algorithm and fetching/passing the arguments from swing components
......@@ -116,7 +139,7 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent {
if (YoshikoLoader.isLibraryLoaded()){
AbstractTask yoshiko = new AlgorithmTask(
CyCore.cy.getCurrentNetwork(),
timeLimitSetter.getTimeLimit(),
opModePanel.getTimeLimit(),
ecPanel.getWeightColumn(),
ecPanel.getPermanentColumn(),
ecPanel.getForbiddenColumn(),
......@@ -124,16 +147,15 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent {
ecPanel.getDefaultDeletionCost(),
reductionRulesChooser.getBitMask(),
reductionRulesChooser.getMultFactor(),
useTriangleCutsBox.isSelected(),
usePartitionCutsBox.isSelected(),
useHeuristic.isSelected(),
solutionNumberChooser.getSolCount()
opModePanel.useTriangleCuts(),
opModePanel.usePartitionCuts(),
opModePanel.useHeuristic(),
opModePanel.getSolCount()
);
CyCore.dialogTaskManager.execute(new TaskIterator(1,yoshiko));
}
else {
JOptionPane.showMessageDialog(
null,
LocalizationManager.get("noLibTitle"),
LocalizationManager.get("noLibMessage"),
......@@ -143,21 +165,6 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent {
}
};
ActionListener ilpHeuristicSwitch = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (useILP.isSelected()) {
timeLimitSetter.setEnabled(true);
}
else {
timeLimitSetter.setEnabled(false);
}
}
};
public ColumnMapper getColumnMapper() {
return ecPanel.getColumnMapper();
}
//GETTER / SETTER
......@@ -179,10 +186,12 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent {
return "Yoshiko";
}
public ColumnMapper getColumnMapper() {
return ecPanel.getColumnMapper();
}
public Icon getIcon() {
//TODO:
return null;
return GraphicsLoader.getLogo();
}
......
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.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
@SuppressWarnings("serial")
public class OperationModePanel extends ComfortPanel{
private final JRadioButton useHeuristic;
private final JRadioButton useILP;
private final TimeLimitSetter timeLimitSetter;
private final SolutionNumberChooser solutionNumberChooser;
private final JCheckBox useTriangleCutsBox;
private final JCheckBox usePartitionCutsBox;
private final ButtonGroup heuristicGroup;
public OperationModePanel() {
this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
heuristicGroup = new ButtonGroup();
useILP = new JRadioButton("Use Integer Linear Programming");
useILP.setSelected(true);
useHeuristic = new JRadioButton("Use Heuristic");
heuristicGroup.add(useILP);
heuristicGroup.add(useHeuristic);
solutionNumberChooser = new SolutionNumberChooser();
timeLimitSetter = new TimeLimitSetter();
useTriangleCutsBox = new JCheckBox("Use Triangle Cuts");
usePartitionCutsBox = new JCheckBox("Use Partition Cuts");
//Link time limit option to ILP
useILP.addActionListener(ilpHeuristicSwitch);
useHeuristic.addActionListener(ilpHeuristicSwitch);
this.addAll(useILP,useHeuristic,solutionNumberChooser,timeLimitSetter,useTriangleCutsBox,usePartitionCutsBox);
Border border = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
border = BorderFactory.createTitledBorder(border,LocalizationManager.get("operationMode"));
this.setBorder(border);
}
ActionListener ilpHeuristicSwitch = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (useILP.isSelected()) {
timeLimitSetter.setEnabled(true);
useTriangleCutsBox.setEnabled(true);
usePartitionCutsBox.setEnabled(true);
solutionNumberChooser.setEnabled(true);
}
else {
timeLimitSetter.setEnabled(false);
useTriangleCutsBox.setEnabled(false);
usePartitionCutsBox.setEnabled(false);
solutionNumberChooser.setEnabled(false);
}
}
};
//SETTER GETTER
public int getTimeLimit() {
return timeLimitSetter.getTimeLimit();
}
public boolean useTriangleCuts() {
return useTriangleCutsBox.isSelected();
}
public boolean usePartitionCuts() {
return usePartitionCutsBox.isSelected();
}
public boolean useHeuristic() {
return useHeuristic.isSelected();
}
public int getSolCount() {
return solutionNumberChooser.getSolCount();
}
}
......@@ -17,7 +17,11 @@ public class SolutionNumberChooser extends ComfortPanel {
numSolutionsSetter.setModel(new SpinnerNumberModel(1,1,Integer.MAX_VALUE,1));
label = new JLabel(LocalizationManager.get("nrSolutions"));
this.addAll(label, numSolutionsSetter);
}
@Override
public void setEnabled(boolean enabled) {
numSolutionsSetter.setEnabled(enabled);
}
public int getSolCount() {
......
......@@ -32,6 +32,7 @@ public class TimeLimitSetter extends ComfortPanel{
this.addAll(checkBox,numberField);
}
@Override
public void setEnabled(boolean enabled) {
if (enabled) {
this.checkBox.setEnabled(enabled);
......
package de.hhu.ba.yoshikoWrapper.gui;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import de.hhu.ba.yoshikoWrapper.core.GraphicsLoader;
@SuppressWarnings("serial")
public class YoshikoHeader extends ComfortPanel {
private JLabel logo;
private JLabel text;
public YoshikoHeader() {
this.setLayout(new BoxLayout(this,BoxLayout.X_AXIS));
logo = new JLabel(GraphicsLoader.getLogo());
text = new JLabel(GraphicsLoader.getText());
this.addAll(logo,text);
}
}
......@@ -22,3 +22,10 @@ redRuleChooserTitle = Reduction Rules
discardSolution = Discard
createMetaGraph = Create Meta-Graph
metaGraph = Meta Graph
showAdvanced = Show advanced options
editingCostPanel = Editing Costs
defaultInsertion = Default insertion cost:
defaultDeletion = Default deletion cost:
switchLanguage = Plugin language:
icTooltip = This value is used to determine what the algorithm pays when inserting an edge. Existing mappings overwrite this value. A higher value means that the algorithm is less likely to insert edges in order to generate a cluster.
operationMode = Operation Mode
\ No newline at end of file
src/main/resources/graphics/YoshikoAlphaLogo.png

6.7 KiB

src/main/resources/graphics/YoshikoAlphaText.png

6.96 KiB

package graphics;
\ 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