Permalink
Browse files

first implementation of the node manager

git-svn-id: https://svn.sosy-lab.org/software/ccvisu/trunk@1040 fc36ee94-785d-4715-976b-05dfc5071072
  • Loading branch information...
1 parent a593f42 commit 85890c7b1c08e0a13fa2a1badf3682d09bbd3d26 kaeufl committed Dec 14, 2011
@@ -0,0 +1,258 @@
+/*
+ * CCVisu is a tool for visual graph clustering
+ * and general force-directed graph layout.
+ * This file is part of CCVisu.
+ *
+ * Copyright (C) 2005-2011 Dirk Beyer
+ *
+ * CCVisu is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * CCVisu 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with CCVisu; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Please find the GNU Lesser General Public License in file
+ * license_lgpl.txt or http://www.gnu.org/licenses/lgpl.txt
+ *
+ * Dirk Beyer (firstname.lastname@uni-passau.de)
+ * University of Passau, Bavaria, Germany
+ */
+package org.sosy_lab.ccvisu.ui;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.util.EventObject;
+import java.util.List;
+
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.ScrollPaneConstants;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableCellRenderer;
+import javax.swing.table.TableColumn;
+
+import org.sosy_lab.ccvisu.Options;
+import org.sosy_lab.ccvisu.graph.GraphVertex;
+import org.sosy_lab.ccvisu.graph.Group;
+import org.sosy_lab.ccvisu.graph.interfaces.GraphEventListener;
+
+@SuppressWarnings("serial")
+public class ControlPanelNodeManager extends ControlPanel implements GraphEventListener {
+
+ private static String[] COLUMNS = { "", "Group", "Label", "InDegree", "OutDegree" };
+
+ private static Integer[] COLUMNS_WIDTH = { 1, 50, 300, 25, 25 };
+
+ private final Options ccvisuOptions;
+
+ private final JTable table;
+
+ private GraphVertexTableModel tableModel;
+
+ public ControlPanelNodeManager(Options ccvisuOptions) {
+ assert (ccvisuOptions.graph != null);
+
+ this.ccvisuOptions = ccvisuOptions;
+ table = new JTable();
+
+ ccvisuOptions.graph.addOnGraphChangeListener(this);
+ ccvisuOptions.graph.addOnGroupChangeListener(this);
+
+ JScrollPane tablePane = createTablePanel();
+ add(tablePane, BorderLayout.CENTER);
+ }
+
+ @Override
+ public void onGraphChangedEvent(EventObject event) {
+ List<GraphVertex>vertices = ccvisuOptions.graph.getVertices();
+ synchronized (vertices) {
+ // format data for table
+ Object[][] tableData = formatTableData(vertices);
+
+ // update table model
+ tableModel.setData(tableData);
+ }
+ }
+
+ private JScrollPane createTablePanel() {
+ // set the tables properties
+ table.setDefaultRenderer(Color.class, new ColorTableCellRenderer());
+
+ // create table data using the graph's vertices
+ List<GraphVertex> vertices = ccvisuOptions.graph.getVertices();
+ Object[][] tableData = formatTableData(vertices);
+
+ // fill the table
+ tableModel = new GraphVertexTableModel(tableData);
+ table.setModel(tableModel);
+
+ // set the initial column sizes
+ initColumnSizes(table);
+
+ // activate row sorting
+ table.setAutoCreateRowSorter(true);
+
+ // create table pane
+ JScrollPane tablePane = new JScrollPane(table);
+ int asNeeded = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
+ tablePane.setHorizontalScrollBarPolicy(asNeeded);
+ asNeeded = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
+ tablePane.setVerticalScrollBarPolicy(asNeeded);
+
+ return tablePane;
+ }
+
+ private void initColumnSizes(JTable table) {
+ for (int i = 0; i < COLUMNS.length; i++) {
+ TableColumn column = table.getColumnModel().getColumn(i);
+ column.setPreferredWidth(COLUMNS_WIDTH[i]);
+ }
+ }
+
+ private Object[][] formatTableData(List<GraphVertex> vertices) {
+
+ if (vertices == null) {
+ throw new IllegalArgumentException("the vertices list may not be null");
+ }
+
+ Object[][] tableData;
+
+ synchronized (vertices) {
+
+ int i = 0;
+ tableData = new Object[vertices.size()][COLUMNS.length];
+
+ for (GraphVertex vertex : vertices) {
+ String groupName = null;
+ for (Group group : ccvisuOptions.graph.getGroups()) {
+ if (group.getNodes().contains(vertex)) {
+ groupName = group.getName();
+ }
+ }
+
+ tableData[i][0] = vertex.getColor();
+
+ if (groupName != null) {
+ tableData[i][1] = groupName;
+ } else {
+ tableData[i][1] = "unknown";
+ }
+
+ tableData[i][2] = vertex.getLabel();
+ tableData[i][3] = vertex.getDegree();
+ tableData[i][4] = vertex.getDegreeOut();
+ i++;
+ }
+ }
+
+ return tableData;
+ }
+
+ private class GraphVertexTableModel extends AbstractTableModel {
+
+ private Object[][] data;
+
+ public GraphVertexTableModel(Object[][] data) {
+ this.data = data;
+ }
+
+ @Override
+ public int getRowCount() {
+ return data.length;
+ }
+
+ @Override
+ public int getColumnCount() {
+ return COLUMNS.length;
+ }
+
+ @Override
+ public String getColumnName(int column) {
+ if (column < 0 || column >= getColumnCount()) {
+ throw new IllegalArgumentException("column is out of bounds");
+ }
+
+ return COLUMNS[column];
+ }
+
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ if (rowIndex < 0 || rowIndex >= getRowCount()) {
+ throw new IllegalArgumentException("rowIndex is out of bounds");
+ }
+
+ if (columnIndex < 0 || columnIndex >= getColumnCount()) {
+ throw new IllegalArgumentException("columnIndex is out of bounds");
+ }
+
+ return data[rowIndex][columnIndex];
+ }
+
+ public void setData(Object[][] data) {
+
+ if (data == null) {
+ throw new IllegalArgumentException("data may not be null");
+ }
+
+ for (Object[] row : data) {
+ if (row == null) {
+ throw new IllegalArgumentException("data may not contain null rows");
+ }
+ for (Object cell : row) {
+ if (cell == null) {
+ throw new IllegalArgumentException("data may not contain null columns");
+ }
+ }
+ }
+
+ // prepare update
+ int oldRowCount = this.data.length;
+ int newRowCount = data.length;
+
+ // update
+ this.data = data;
+
+ // inform about update
+ if (newRowCount > oldRowCount) {
+ fireTableRowsInserted(oldRowCount, newRowCount - 1);
+ } else if (newRowCount < oldRowCount) {
+ fireTableRowsDeleted(newRowCount, oldRowCount);
+ } else {
+ fireTableRowsUpdated(0, newRowCount - 1);
+ }
+ }
+
+ @Override
+ public Class<?> getColumnClass(int column) {
+ return getValueAt(0, column).getClass();
+ }
+ }
+
+ private class ColorTableCellRenderer extends JLabel implements TableCellRenderer {
+
+ public ColorTableCellRenderer() {
+ setOpaque(true);
+ }
+
+ @Override
+ public Component getTableCellRendererComponent(JTable table, Object value,
+ boolean isSelected, boolean hasFocus, int row, int column) {
+
+ Color color = (Color) value;
+ setBackground(color);
+ setText("");
+
+ return this;
+ }
+ }
+}
@@ -48,13 +48,15 @@
private ControlPanelDependencies dependencyPanel;
private ControlPanelVisualization visualizationPanel;
private ControlPanelGroups groupsPanel;
+ private ControlPanelNodeManager nodeManagerPanel;
public FrameProperties(Options pOptions, WriterDataLayoutDISP writer, WorkerManager workerManager) {
this.minimizerPanel = new ControlPanelMinimizer(pOptions, workerManager);
this.clusteringPanel = new ControlPanelClustering(pOptions, workerManager);
this.visualizationPanel = new ControlPanelVisualization(pOptions, writer);
this.groupsPanel = new ControlPanelGroups(writer, pOptions.graph);
this.dependencyPanel = new ControlPanelDependencies(pOptions, workerManager);
+ nodeManagerPanel = new ControlPanelNodeManager(pOptions);
initComponents();
loadOptions();
@@ -80,11 +82,16 @@ private void initComponents() {
dependencyTab.setLayout(new FlowLayout());
dependencyTab.add(dependencyPanel);
+ JPanel nodeManagerTab = new JPanel();
+ nodeManagerTab.setLayout(new FlowLayout());
+ nodeManagerTab.add(nodeManagerPanel);
+
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("Layout", minimizerTab);
tabbedPane.addTab("Visualization", visualizationTab);
tabbedPane.addTab("Grouping", clusteringTab);
tabbedPane.addTab("Measures", dependencyTab);
+ tabbedPane.addTab("Node Manager", nodeManagerTab);
this.add(tabbedPane, BorderLayout.CENTER);
//this.pack();

0 comments on commit 85890c7

Please sign in to comment.