Commit b9c1a47d authored by Tobias Meuser's avatar Tobias Meuser Committed by Jose Ignacio Monreal Bailey
Browse files

Made selection of active layers persisent

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