Made configuration of node info table persistent

This commit is contained in:
nifi 2010-09-26 21:48:21 +00:00
parent 93b953f815
commit bf91d4906b
3 changed files with 96 additions and 7 deletions

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: CollectServer.java,v 1.19 2010/09/21 20:24:18 nifi Exp $
* $Id: CollectServer.java,v 1.20 2010/09/26 21:48:21 nifi Exp $
*
* -----------------------------------------------------------------
*
@ -34,8 +34,8 @@
*
* Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008
* Updated : $Date: 2010/09/21 20:24:18 $
* $Revision: 1.19 $
* Updated : $Date: 2010/09/26 21:48:21 $
* $Revision: 1.20 $
*/
package se.sics.contiki.collect;
@ -777,6 +777,13 @@ public class CollectServer {
/* TODO Clean up resources */
if (configFile != null) {
configTable.setProperty("collect.bounds", "" + window.getX() + ',' + window.getY() + ',' + window.getWidth() + ',' + window.getHeight());
if (visualizers != null) {
for(Visualizer v : visualizers) {
if (v instanceof Configurable) {
((Configurable)v).updateConfig(configTable);
}
}
}
saveConfig(configTable, configFile);
}
if (serialConnection != null) {

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2010, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: Configurable.java,v 1.1 2010/09/26 21:48:21 nifi Exp $
*
* -----------------------------------------------------------------
*
* Configurable
*
* Authors : Joakim Eriksson, Niclas Finne
* Created : 24 sep 2010
* Updated : $Date: 2010/09/26 21:48:21 $
* $Revision: 1.1 $
*/
package se.sics.contiki.collect;
import java.util.Properties;
/**
*
*/
public interface Configurable {
public void updateConfig(Properties config);
}

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: NodeInfoPanel.java,v 1.6 2010/09/24 06:00:16 nifi Exp $
* $Id: NodeInfoPanel.java,v 1.7 2010/09/26 21:48:21 nifi Exp $
*
* -----------------------------------------------------------------
*
@ -34,8 +34,8 @@
*
* Authors : Joakim Eriksson, Niclas Finne
* Created : 6 sep 2010
* Updated : $Date: 2010/09/24 06:00:16 $
* $Revision: 1.6 $
* Updated : $Date: 2010/09/26 21:48:21 $
* $Revision: 1.7 $
*/
package se.sics.contiki.collect.gui;
@ -45,6 +45,7 @@ import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Properties;
import javax.swing.AbstractAction;
import javax.swing.JCheckBoxMenuItem;
@ -62,6 +63,7 @@ import javax.swing.table.TableColumn;
import javax.swing.table.TableRowSorter;
import se.sics.contiki.collect.CollectServer;
import se.sics.contiki.collect.Configurable;
import se.sics.contiki.collect.Node;
import se.sics.contiki.collect.SensorData;
import se.sics.contiki.collect.SensorInfo;
@ -70,7 +72,7 @@ import se.sics.contiki.collect.Visualizer;
/**
*
*/
public class NodeInfoPanel extends JPanel implements Visualizer {
public class NodeInfoPanel extends JPanel implements Visualizer, Configurable {
private static final long serialVersionUID = -1060893468047793431L;
@ -259,6 +261,21 @@ public class NodeInfoPanel extends JPanel implements Visualizer {
packColumn(table, i);
}
String savedColumnData = server.getConfig("collect.nodeinfo.table");
if (savedColumnData != null) {
String[] columnList = savedColumnData.split("[ ,]");
for(int i = 1; i < columns.length; i++) {
columns[i].setVisible(false);
}
for(int i = 0; i < columnList.length; i++) {
int c = Integer.parseInt(columnList[i]);
int index = table.convertColumnIndexToView(c);
if (index >= 0) {
table.getColumnModel().moveColumn(index, i);
}
columns[c].setVisible(true);
}
}
JPopupMenu popupMenu = new JPopupMenu();
// The first column (the node name) should always be visible.
for(int i = 1; i < columns.length; i++) {
@ -268,6 +285,20 @@ public class NodeInfoPanel extends JPanel implements Visualizer {
add(new JScrollPane(table), BorderLayout.CENTER);
}
public void updateConfig(Properties config) {
StringBuilder sb = new StringBuilder();
for(int i = 0, n = table.getColumnCount(); i < n; i++) {
int index = table.convertColumnIndexToModel(i);
if (index >= 0) {
if (sb.length() > 0) {
sb.append(',');
}
sb.append(index);
}
}
config.setProperty("collect.nodeinfo.table", sb.toString());
}
@Override
public Component getPanel() {
return this;