001 /* EVolve - an Extensible Software Visualization Framework 002 * Copyright (C) 2001-2002 Qin Wang 003 * 004 * This library is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU Library General Public 006 * License as published by the Free Software Foundation; either 007 * version 2 of the License, or (at your option) any later version. 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Library General Public License for more details. 013 * 014 * You should have received a copy of the GNU Library General Public 015 * License along with this library; if not, write to the 016 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 017 * Boston, MA 02111-1307, USA. 018 */ 019 020 /* 021 * EVolve is distributed at http://www.sable.mcgill.ca/EVolve/ 022 */ 023 024 package EVolve.visualization; 025 026 import EVolve.util.VizInfo; 027 import EVolve.data.*; 028 import java.awt.*; 029 import java.util.HashMap; 030 import java.util.ArrayList; 031 import javax.swing.*; 032 033 /** 034 * Two-column table. 035 */ 036 public class TableViz extends Visualization { 037 private ReferenceDimension leftColumn; // dimension, left column 038 private ValueDimension rightColumn; // dimension, right column 039 040 private JTable table; // the table 041 private TableVizModel model; // table model 042 043 private int[] value; // value of the right column 044 045 /** 046 * Creates a table. 047 */ 048 public TableViz() { 049 model = new TableVizModel(); 050 table = new JTable(model); 051 052 JScrollPane scrollPane = new JScrollPane(table); 053 scrollPane.setBackground(Color.white); 054 scrollPane.getViewport().setBackground(Color.white); 055 panel.add(scrollPane, BorderLayout.CENTER); 056 057 addPopupTrigger(table); 058 addPopupTrigger(scrollPane.getViewport()); 059 } 060 061 public Dimension[] createDimension() { 062 leftColumn = new ReferenceDimension(); 063 rightColumn = new ValueDimension(); 064 065 Dimension[] returnVal = new Dimension[2]; 066 returnVal[0] = leftColumn; 067 returnVal[1] = rightColumn; 068 069 return returnVal; 070 } 071 072 protected JPanel createPanel() { 073 JPanel returnVal = new JPanel(new BorderLayout()); 074 returnVal.setBackground(Color.white); 075 return returnVal; 076 } 077 078 protected JPanel createConfigurationPanel() { 079 return null; 080 } 081 082 protected void updateConfiguration() { 083 model = new TableVizModel(); 084 model.setName(leftColumn.getName(), rightColumn.getName()); 085 table.setModel(model); 086 } 087 088 public void preVisualize() { 089 value = new int[leftColumn.getMaxEntityNumber()]; 090 for (int i = 0; i < value.length; i++) { 091 value[i] = 0; 092 } 093 } 094 095 public void receiveElement(Element element) { 096 if (element.getField()[element.getField().length-1] == Integer.MAX_VALUE) 097 return; 098 value[leftColumn.getField(element)] += rightColumn.getField(element); 099 } 100 101 public void visualize() { 102 leftColumn.addComparator(new ValueComparator("Value", false, value)); 103 sort(); 104 } 105 106 public void sort() { 107 String[] sortedName = new String[leftColumn.getEntityNumber()]; 108 int[] sortedValue = new int[leftColumn.getEntityNumber()]; 109 110 for (int i = 0; i < leftColumn.getMaxEntityNumber(); i++) { 111 int sortedIndex = leftColumn.getSortedIndex(i); 112 if (sortedIndex != -1) { 113 sortedName[sortedIndex] = leftColumn.getEntity(sortedIndex).getName(); 114 sortedValue[sortedIndex] = value[i]; 115 } 116 } 117 118 model = new TableVizModel(); 119 model.setName(leftColumn.getName(), rightColumn.getName()); 120 model.setValue(sortedName, sortedValue); 121 table.setModel(model); 122 } 123 124 public void makeSelection() { 125 leftColumn.makeSelection(table.getSelectedRows()); 126 } 127 128 public HashMap getCurrentConfigure() { 129 HashMap configure = super.getCurrentConfigure(); 130 131 VizInfo vizInfo = new VizInfo(); 132 133 vizInfo.setFactory((VisualizationFactory)configure.get("Factory")); 134 vizInfo.setSubject((ElementDefinition)configure.get("Subject")); 135 String[] dimensionDefs = new String[2]; 136 dimensionDefs[0] = leftColumn.getName() ; 137 dimensionDefs[1] = rightColumn.getName() ; 138 configure.put("Dimension",vizInfo.createDimension(dimensionDefs)); 139 140 141 return configure; 142 } 143 144 public ReferenceDimension getLinkableDimension(int dim) { 145 return null; 146 } 147 148 public AutoImage getImage() { 149 return null; 150 } 151 152 public int getxMax() { 153 return -1; 154 } 155 156 public void generateMetricsViz(String metricsName) { 157 } 158 159 public ArrayList getNotApplicableMetrics() { 160 ArrayList returnVal = new ArrayList(); 161 162 returnVal.add("Miss Prediction"); 163 return returnVal; 164 } 165 166 public void clearMagnifier() { 167 return; 168 } 169 170 public void setImage(AutoImage newImage) { 171 return; 172 } 173 174 public JMenuItem[] createSelectionMenuItem() { 175 return null; 176 } 177 }