diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java index 34607e95f245a064effcd872f6f23a2d2a62516e..d8ebf32dd583b7e7264487b6cf74104d14f73c55 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java @@ -50,12 +50,10 @@ import org.osgi.framework.BundleContext; import de.hhu.ba.yoshikoWrapper.core.ConfigurationManager; import de.hhu.ba.yoshikoWrapper.core.CyCore; -import de.hhu.ba.yoshikoWrapper.core.Hint; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.core.YoshUtil; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; import de.hhu.ba.yoshikoWrapper.cytoUtil.NetChangeListener; -import de.hhu.ba.yoshikoWrapper.swing.HintManager; import de.hhu.ba.yoshikoWrapper.swing.components.MainPanel; /** @@ -124,8 +122,6 @@ public class CyActivator extends AbstractCyActivator { registerService(context,netChangeListener, SessionLoadedListener.class, new Properties()); registerService(context,netChangeListener, SetCurrentNetworkListener.class, new Properties()); - //Show Startup-Hint - HintManager.showMappingHint(Hint.FIRST_START); } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/Hint.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/Hint.java deleted file mode 100644 index c916fe6d8b68edee465b7f7fac61758fbdcd134f..0000000000000000000000000000000000000000 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/Hint.java +++ /dev/null @@ -1,6 +0,0 @@ -package de.hhu.ba.yoshikoWrapper.core; - -public enum Hint { - USE_MAPPING, - FIRST_START -} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/HintManager.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/HintManager.java deleted file mode 100644 index 3c0d640f80ade521832ab1e0e87c7d03c72366d6..0000000000000000000000000000000000000000 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/HintManager.java +++ /dev/null @@ -1,75 +0,0 @@ -package de.hhu.ba.yoshikoWrapper.swing; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import javax.swing.JOptionPane; - -import org.slf4j.Logger; - -import de.hhu.ba.yoshikoWrapper.core.CyCore; -import de.hhu.ba.yoshikoWrapper.core.Hint; -import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; -import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger; - -/** - * Bothers the user with useful hints - * - */ -public class HintManager { - - //TODO: Implement as HashMap - - private static Logger logger = YoshikoLogger.getInstance().getLogger(); - - private static final Runnable useMappingHint = new Runnable() { - - @Override - public void run() { - JOptionPane.showMessageDialog(null, LocalizationManager.get("noMappingHint"), LocalizationManager.get("yoshikoHint"),JOptionPane.INFORMATION_MESSAGE); - } - - }; - - private static final Runnable firstStart = new Runnable() { - - @Override - public void run() { - JOptionPane.showMessageDialog(null, LocalizationManager.get("firstStart"), "Yoshiko Welcome", JOptionPane.INFORMATION_MESSAGE, GraphicsLoader.getLogo(40)); - } - - }; - - private final static Map<Hint,Runnable> hints; - - static { - Map<Hint, Runnable> map = new HashMap<Hint,Runnable>(); - map.put(Hint.USE_MAPPING, useMappingHint); - map.put(Hint.FIRST_START, firstStart); - hints = Collections.unmodifiableMap(map); - } - - public static void showMappingHint(Hint hint) { - if ( - CyCore.getConfig( - hint.toString()+"shown" - ) == null - ) - { - - //Save property so we dont show this again - CyCore.cm.getProperties().setProperty(hint.toString()+ "shown", "1"); - if (hints.get(hint) != null) { - hints.get(hint).run(); - } - else { - logger.warn("Asked for a hint that doesnt exist with hint name: "+hint.toString()); - } - - } - } - - - -} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java index d61f7593430a2f4124e381174a462493d80450dc..965ae4635cbec4b7d382ea9788e919efccdb24b0 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java @@ -1,16 +1,16 @@ /******************************************************************************* * Copyright (C) 2017 Philipp Spohr - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -52,13 +52,11 @@ 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.Hint; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.core.ParameterSet; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; import de.hhu.ba.yoshikoWrapper.swing.AboutDialogFactory; import de.hhu.ba.yoshikoWrapper.swing.GraphicsLoader; -import de.hhu.ba.yoshikoWrapper.swing.HintManager; import de.hhu.ba.yoshikoWrapper.swing.LanguageSwitcherPanelFactory; import de.hhu.ba.yoshikoWrapper.swing.LibraryPanelFactory; import de.hhu.ba.yoshikoWrapper.swing.SwingUtil; @@ -68,39 +66,39 @@ import de.hhu.ba.yoshikoWrapper.swing.SwingUtil; */ @SuppressWarnings("serial") public class MainPanel extends JPanel implements CytoPanelComponent { - + //SWING COMPONENTS - + private final YoshikoHeader header; - + private final JButton about; - + private final JCheckBox showAdvancedOptions; private final ArrayList<JComponent> advancedOptions; //Those two work with factories whysoever private final BasicCollapsiblePanel langPanel; private final BasicCollapsiblePanel libraryPanel; - + //Those don't work really as collapsible panels and cause glitches which forces the workaround of wrapping them //Probably someone used getClass() == instead of instanceof so extending BasicCollapsiblePanel is sadly not possible private final BasicCollapsiblePanel ecPanelWrapper; private final EditCostPanel ecPanel; - + private final BasicCollapsiblePanel reductionWrapper; private final ReductionRulesChooser reductionRulesChooser; - + private final BasicCollapsiblePanel opWrapper; - private final OperationModePanel opModePanel; - + private final OperationModePanel opModePanel; + /** * Main constructor, creates a new Panel and initializes subcomponents */ public MainPanel() { - //Initialize Swing components + //Initialize Swing components header = new YoshikoHeader(); - + about = new JButton(LocalizationManager.get("aboutButton"),GraphicsLoader.getInfoIcon(16)); about.addActionListener(new ActionListener() { @@ -108,33 +106,33 @@ public class MainPanel extends JPanel implements CytoPanelComponent { public void actionPerformed(ActionEvent e) { AboutDialogFactory.showDialog(); } - + }); - + showAdvancedOptions = new JCheckBox(LocalizationManager.get("showAdvanced")); showAdvancedOptions.addActionListener(toggleAdvancedOptionsListener); - + langPanel = LanguageSwitcherPanelFactory.createLanguageSwitcherPanel(); - + libraryPanel = LibraryPanelFactory.createLibraryPanel(); //If no library is loaded yet the obvious panel should be showing up if (!YoshikoLoader.isLibraryLoaded()) { libraryPanel.setCollapsed(false); } - + ecPanel = new EditCostPanel(); ecPanelWrapper = new BasicCollapsiblePanel(LocalizationManager.get("editingCostPanel")); ecPanelWrapper.add(ecPanel); ecPanelWrapper.setCollapsed(false); - + opModePanel = new OperationModePanel(); opWrapper = new BasicCollapsiblePanel(LocalizationManager.get("operationMode")); opWrapper.add(opModePanel); - + reductionWrapper = new BasicCollapsiblePanel(LocalizationManager.get("redRuleChooserTitle")); reductionRulesChooser = new ReductionRulesChooser(); reductionWrapper.add(reductionRulesChooser); - + JButton runButton = new JButton(LocalizationManager.get("run")); runButton.addActionListener(buttonListener); @@ -150,7 +148,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent { opWrapper, runButton ); - + //Manage all advanced components separately to enable toggling advancedOptions = new ArrayList<JComponent>(); advancedOptions.addAll( @@ -159,15 +157,15 @@ public class MainPanel extends JPanel implements CytoPanelComponent { reductionWrapper ) ); - + showAdvancedOptions(false); - + //Layout GroupLayout layout = new GroupLayout(this); - + layout.setAutoCreateGaps(true); layout.setAutoCreateContainerGaps(true); - + layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING,true) .addGroup(layout.createSequentialGroup() .addComponent(header,DEFAULT_SIZE, DEFAULT_SIZE,DEFAULT_SIZE) @@ -184,7 +182,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent { .addComponent(opWrapper,DEFAULT_SIZE, DEFAULT_SIZE,DEFAULT_SIZE) .addComponent(runButton,DEFAULT_SIZE, DEFAULT_SIZE,DEFAULT_SIZE) ); - + layout.setVerticalGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup() .addComponent(header,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE) @@ -197,22 +195,22 @@ public class MainPanel extends JPanel implements CytoPanelComponent { .addComponent(ecPanelWrapper,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE) .addComponent(reductionWrapper,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE) .addComponent(opWrapper,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE) - .addComponent(runButton,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE) + .addComponent(runButton,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE) ); - + this.setLayout(layout); - + } - + 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); @@ -230,7 +228,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent { private final TaskIterator iterator = new TaskIterator(); @Override public void actionPerformed(ActionEvent e) { - + //SWING BLACK MAGIC Window noWindow = null; JDialog statusWindow = new JDialog(noWindow); @@ -241,14 +239,8 @@ public class MainPanel extends JPanel implements CytoPanelComponent { statusWindow.setModalityType(ModalityType.MODELESS); statusWindow.setAlwaysOnTop(false); //SWING BLACK MAGIC - + if (YoshikoLoader.isLibraryLoaded()){ - - //User has mapped no values -> Annoy him - if (ecPanel.getWeightColumn() == null) { - HintManager.showMappingHint(Hint.USE_MAPPING); - } - AbstractTask yoshiko = new AlgorithmTask( popupLevel, CyCore.cy.getCurrentNetwork(), @@ -259,14 +251,14 @@ public class MainPanel extends JPanel implements CytoPanelComponent { */ if (!iterator.hasNext()) { iterator.append(yoshiko); - + CyCore.dialogTaskManager.setExecutionContext(statusWindow); CyCore.dialogTaskManager.execute(iterator); - + } } else { - JOptionPane.showMessageDialog( + JOptionPane.showMessageDialog( null, LocalizationManager.get("noLibTitle"), LocalizationManager.get("noLibMessage"), @@ -275,7 +267,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent { } } }; - + /** * Fetches all the parameters from the various swing components and packs them into a neat abstract wrapper class * @return The currently selected parameter wrapped in a ParameterSet @@ -291,16 +283,16 @@ public class MainPanel extends JPanel implements CytoPanelComponent { ret.reductionRulesBitMask = reductionRulesChooser.getBitMask(); ret.snrMultFactor = reductionRulesChooser.getMultFactor(); ret.useTriangleCuts = opModePanel.useTriangleCuts(); - ret.usePartitionCuts = opModePanel.usePartitionCuts(); + ret.usePartitionCuts = opModePanel.usePartitionCuts(); ret.useHeuristic = opModePanel.useHeuristic(); ret.solCount = opModePanel.getSolCount(); ret.disableMultiThreading = opModePanel.isMultiThreadingDisabled(); return ret; } - + //GETTER / SETTER - + public ColumnMapper getColumnMapper() { return ecPanel.getColumnMapper(); } @@ -320,7 +312,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent { public String getTitle() { return "Yoshiko"; } - + public Icon getIcon() { return GraphicsLoader.getLogo(16); } diff --git a/src/test/java/de/hhu/ba/yoshikoWrapper/logging/YoshikoLogger_test.java b/src/test/java/de/hhu/ba/yoshikoWrapper/logging/YoshikoLogger_test.java new file mode 100644 index 0000000000000000000000000000000000000000..da737f43b1b8cda8f18283fe6e55edb0be2b4961 --- /dev/null +++ b/src/test/java/de/hhu/ba/yoshikoWrapper/logging/YoshikoLogger_test.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (C) 2017 Philipp Spohr + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + ******************************************************************************/ +package de.hhu.ba.yoshikoWrapper.logging; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.slf4j.Logger; + +public class YoshikoLogger_test { + + @Test + public void loggerTest1(){ + Logger logger = YoshikoLogger.getInstance().getLogger(); + assertEquals(logger.getClass(),org.slf4j.Logger.class); + } + +}