Commit fb41a529 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Made selection of active layers persisent

parent f7c16e22
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
* *
* This file is part of PeerfactSim.KOM. * This file is part of PeerfactSim.KOM.
* *
* PeerfactSim.KOM is free software: you can redistribute it and/or modify * PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* any later version. * any later version.
* *
* PeerfactSim.KOM is distributed in the hope that it will be useful, * PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>. * along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
* *
...@@ -26,20 +26,21 @@ import java.util.List; ...@@ -26,20 +26,21 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JMenu;
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.SimControlPanel;
import de.tud.kom.p2psim.impl.topology.views.visualization.ui.VisualizationComponent; import de.tud.kom.p2psim.impl.topology.views.visualization.ui.VisualizationComponent;
import de.tud.kom.p2psim.impl.util.guirunner.Config;
/** /**
* This manager keeps track of all components that are added to the UI. It can * This manager keeps track of all components that are added to the UI. It can
* be used to add/remove named component to/from the UI and allows to change the * be used to add/remove named component to/from the UI and allows to change the
* components visibility based on their name or component reference. * components visibility based on their name or component reference.
* *
* @author Fabio Zöllner * @author Fabio Zöllner
* @version 1.0, 12.07.2012 * @version 1.0, 12.07.2012
*/ */
...@@ -63,7 +64,7 @@ public class ComponentVisManager { ...@@ -63,7 +64,7 @@ public class ComponentVisManager {
/** /**
* Adds the given component to the visualization * Adds the given component to the visualization
* *
* @param name * @param name
* @param priority * @param priority
* @param component * @param component
...@@ -74,7 +75,7 @@ public class ComponentVisManager { ...@@ -74,7 +75,7 @@ public class ComponentVisManager {
/** /**
* Adds the given component to the visualization * Adds the given component to the visualization
* *
* @param name * @param name
* @param priority * @param priority
* @param component * @param component
...@@ -85,7 +86,7 @@ public class ComponentVisManager { ...@@ -85,7 +86,7 @@ public class ComponentVisManager {
/** /**
* Adds the component of the given VisInfo to the visualization * Adds the component of the given VisInfo to the visualization
* *
* @param visInfo * @param visInfo
*/ */
public void addComponent(VisInfo visInfo) { public void addComponent(VisInfo visInfo) {
...@@ -108,7 +109,7 @@ public class ComponentVisManager { ...@@ -108,7 +109,7 @@ public class ComponentVisManager {
/** /**
* Removes the given component from the visualization * Removes the given component from the visualization
* *
* @param name * @param name
*/ */
public void removeComponent(String name) { public void removeComponent(String name) {
...@@ -124,7 +125,7 @@ public class ComponentVisManager { ...@@ -124,7 +125,7 @@ public class ComponentVisManager {
/** /**
* Removes the given component from the visualization * Removes the given component from the visualization
* *
* @param component * @param component
*/ */
public void removeComponent(JComponent component) { public void removeComponent(JComponent component) {
...@@ -144,20 +145,26 @@ public class ComponentVisManager { ...@@ -144,20 +145,26 @@ public class ComponentVisManager {
/** /**
* Toggles the visibility of a component. * Toggles the visibility of a component.
* *
* @param component * @param component
*/ */
public void toggleComponent(String name) { public void toggleComponent(String name) {
boolean first = true;
for (JComponent component : nameToComponentMap.get(name)) { for (JComponent component : nameToComponentMap.get(name)) {
toggleComponent(component); toggleComponent(component);
if (first) {
Config.setValue(SimControlPanel.getConfMainPath(name), component.isVisible());
first = false;
}
} }
} }
/** /**
* Toggles the visibility of a component. * Toggles the visibility of a component.
* *
* It's the same as component.setVisible(!component.isVisible()); * It's the same as component.setVisible(!component.isVisible());
* *
* @param component * @param component
*/ */
public void toggleComponent(JComponent component) { public void toggleComponent(JComponent component) {
...@@ -178,7 +185,7 @@ public class ComponentVisManager { ...@@ -178,7 +185,7 @@ public class ComponentVisManager {
/** /**
* Sets the given component invisible. * Sets the given component invisible.
* *
* @param component * @param component
*/ */
public void deactivateComponent(String name) { public void deactivateComponent(String name) {
...@@ -189,9 +196,9 @@ public class ComponentVisManager { ...@@ -189,9 +196,9 @@ public class ComponentVisManager {
/** /**
* Sets the given component invisible. * Sets the given component invisible.
* *
* It's the same as component.setVisible(false); * It's the same as component.setVisible(false);
* *
* @param component * @param component
*/ */
public void deactivateComponent(JComponent component) { public void deactivateComponent(JComponent component) {
...@@ -204,7 +211,7 @@ public class ComponentVisManager { ...@@ -204,7 +211,7 @@ public class ComponentVisManager {
/** /**
* Sets the given component visible. * Sets the given component visible.
* *
* @param component * @param component
*/ */
public void activateComponent(String name) { public void activateComponent(String name) {
...@@ -215,9 +222,9 @@ public class ComponentVisManager { ...@@ -215,9 +222,9 @@ public class ComponentVisManager {
/** /**
* Sets the given component visible. * Sets the given component visible.
* *
* It's the same as component.setVisible(true); * It's the same as component.setVisible(true);
* *
* @param component * @param component
*/ */
public void activateComponent(JComponent component) { public void activateComponent(JComponent component) {
...@@ -229,7 +236,7 @@ public class ComponentVisManager { ...@@ -229,7 +236,7 @@ public class ComponentVisManager {
/** /**
* Adds a visualization listener to the manager * Adds a visualization listener to the manager
* *
* @param listener * @param listener
*/ */
public void addVisualizationListener(VisualizationListener listener) { public void addVisualizationListener(VisualizationListener listener) {
...@@ -238,7 +245,7 @@ public class ComponentVisManager { ...@@ -238,7 +245,7 @@ public class ComponentVisManager {
/** /**
* Removes a visualization listener from the manager * Removes a visualization listener from the manager
* *
* @param listener * @param listener
*/ */
public void removeVisualizationListener(VisualizationListener listener) { public void removeVisualizationListener(VisualizationListener listener) {
...@@ -259,9 +266,9 @@ public class ComponentVisManager { ...@@ -259,9 +266,9 @@ public class ComponentVisManager {
/** /**
* Bean that holds the name, priority and reference to the component. * Bean that holds the name, priority and reference to the component.
* *
* Note: The equals and hashCode methods omit the priority. * Note: The equals and hashCode methods omit the priority.
* *
* @author Fabio Zöllner * @author Fabio Zöllner
* @version 1.0, 12.07.2012 * @version 1.0, 12.07.2012
*/ */
...@@ -290,7 +297,7 @@ public class ComponentVisManager { ...@@ -290,7 +297,7 @@ public class ComponentVisManager {
/** /**
* Recommended way: use the {@link VisualizationComponent} * Recommended way: use the {@link VisualizationComponent}
* *
* @param comp * @param comp
*/ */
public VisInfo(VisualizationComponent comp) { public VisInfo(VisualizationComponent comp) {
...@@ -308,7 +315,7 @@ public class ComponentVisManager { ...@@ -308,7 +315,7 @@ public class ComponentVisManager {
/** /**
* Recommended container for custom visualizations. * Recommended container for custom visualizations.
* *
* @return may be null (legacy visualizations) * @return may be null (legacy visualizations)
*/ */
public VisualizationComponent getVisualizationComponent() { public VisualizationComponent getVisualizationComponent() {
...@@ -363,7 +370,7 @@ public class ComponentVisManager { ...@@ -363,7 +370,7 @@ public class ComponentVisManager {
/** /**
* A listener interface that is used by the ComponentVisManager to notify * A listener interface that is used by the ComponentVisManager to notify
* interested parties about added or removed visualization components. * interested parties about added or removed visualization components.
* *
* @author Fabio Zöllner * @author Fabio Zöllner
* @version 1.0, 12.07.2012 * @version 1.0, 12.07.2012
*/ */
...@@ -375,7 +382,7 @@ public class ComponentVisManager { ...@@ -375,7 +382,7 @@ public class ComponentVisManager {
/** /**
* Returns a list of currently visible and invisible components. * Returns a list of currently visible and invisible components.
* *
* @return * @return
*/ */
public Collection<VisInfo> getVisualizations() { public Collection<VisInfo> getVisualizations() {
......
...@@ -2,17 +2,17 @@ ...@@ -2,17 +2,17 @@
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab * Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
* *
* This file is part of PeerfactSim.KOM. * This file is part of PeerfactSim.KOM.
* *
* PeerfactSim.KOM is free software: you can redistribute it and/or modify * PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* any later version. * any later version.
* *
* PeerfactSim.KOM is distributed in the hope that it will be useful, * PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>. * along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
* *
...@@ -43,16 +43,18 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza ...@@ -43,16 +43,18 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager; import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager;
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisInfo; import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisInfo;
import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisualizationListener; import de.tud.kom.p2psim.impl.topology.views.visualization.ComponentVisManager.VisualizationListener;
import de.tud.kom.p2psim.impl.util.guirunner.Config;
/** /**
* Menu-Bar containing means to alter the simulation speed, pause and un-pause * Menu-Bar containing means to alter the simulation speed, pause and un-pause
* simulations and (new) configuration of plots and visualization layers. * simulations and (new) configuration of plots and visualization layers.
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 27.08.2012 * @version 1.0, 27.08.2012
*/ */
public class SimControlPanel extends JMenuBar public class SimControlPanel extends JMenuBar implements ActionListener, ChangeListener, VisualizationListener {
implements ActionListener, ChangeListener, VisualizationListener {
private static final String CONF_PATH = "GUIRunner/Menu/Layels/";
private static final long serialVersionUID = -914578954798611308L; private static final long serialVersionUID = -914578954798611308L;
...@@ -111,7 +113,7 @@ public class SimControlPanel extends JMenuBar ...@@ -111,7 +113,7 @@ public class SimControlPanel extends JMenuBar
} }
return layerMenu; return layerMenu;
} }
public ComponentVisManager getVisManager() { public ComponentVisManager getVisManager() {
return visManager; return visManager;
} }
...@@ -119,7 +121,14 @@ public class SimControlPanel extends JMenuBar ...@@ -119,7 +121,14 @@ public class SimControlPanel extends JMenuBar
@Override @Override
public void visualizationAdded(VisInfo visInfo) { public void visualizationAdded(VisInfo visInfo) {
JCheckBoxMenuItem checkBox = new JCheckBoxMenuItem(visInfo.getName()); JCheckBoxMenuItem checkBox = new JCheckBoxMenuItem(visInfo.getName());
checkBox.setSelected(visInfo.isActiveByDefault()); boolean isActive = visInfo.isActiveByDefault();
isActive = Config.getValue(getConfMainPath(visInfo.getName()), isActive);
checkBox.setSelected(isActive);
if (!isActive) {
getVisManager().deactivateComponent(visInfo.getName());
}
checkBox.addActionListener(new ActionListener() { checkBox.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
...@@ -221,4 +230,22 @@ public class SimControlPanel extends JMenuBar ...@@ -221,4 +230,22 @@ public class SimControlPanel extends JMenuBar
} }
} }
/**
* @return the confPath
*/
public static String getConfPath(String pName) {
return CONF_PATH + pName.replace(":", "").replaceAll(" ", "");
}
/**
* @return the confPath
*/
public static String getConfMainPath(String pName) {
String newName = "Layer_" + pName.replace(":", "").replaceAll(" ", "").replace("/", "_");
if (newName.length() > 1) {
return CONF_PATH + newName + "/Main";
}
return null;
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment