001 /** 002 * Created by IntelliJ IDEA. 003 * User: Wei Wang 004 * Date: Nov 27, 2002 005 * Time: 9:11:28 PM 006 */ 007 008 package EVolve.visualization.XYViz.ValRefViz.HotSpotViz; 009 010 import java.awt.FlowLayout; 011 import java.awt.GridLayout; 012 013 import javax.swing.JComboBox; 014 import javax.swing.JLabel; 015 import javax.swing.JPanel; 016 017 import EVolve.data.Element; 018 import EVolve.data.ValueComparator; 019 import EVolve.util.painters.PredictionPainter; 020 import EVolve.util.painters.Painter; 021 import EVolve.util.xmlutils.datastructures.SerializedVisualization; 022 import EVolve.visualization.Dimension; 023 import EVolve.visualization.Predictor; 024 import EVolve.visualization.PredictorFactory; 025 import EVolve.visualization.ReferenceDimension; 026 import EVolve.visualization.ValueDimension; 027 028 public class PredictionViz extends HotSpotVisualization{ 029 private PredictorFactory[] factory; // predictor factories 030 private PredictorFactory selectedFactory; // predictor factory in use 031 private Predictor[] predictor; // predictors 032 private JComboBox comboPredictor; // combobox for selecting predictor factory 033 034 public PredictionViz(PredictorFactory[] factory) { 035 super(); 036 this.factory = factory; 037 painters = new Painter[1]; 038 painters[0] = new PredictionPainter(); 039 //painters[0] = new PredictionPainter(); 040 //painters[1] = painters[0]; 041 } 042 043 public Dimension[] createDimension() { 044 Dimension [] returnDimension = new Dimension[3]; 045 046 xAxis = new ValueDimension(); 047 yAxis = new ReferenceDimension(true); 048 zAxis = new ReferenceDimension(true); 049 returnDimension[0] = xAxis; 050 returnDimension[1] = yAxis; 051 returnDimension[2] = zAxis; 052 yAxis.addSortSchemes("Miss"); 053 054 return returnDimension; 055 } 056 057 protected JPanel createConfigurationPanel() { 058 configurationPanel = new JPanel(new GridLayout(2, 1, 5, 5)); 059 060 selectedFactory = factory[0]; 061 062 JPanel panelTop = new JPanel(new FlowLayout()); 063 configurationPanel.add(panelTop); 064 065 panelTop.add(new JLabel("Predictor: ")); 066 067 comboPredictor = new JComboBox(); 068 for (int i = 0; i < factory.length; i++) { 069 comboPredictor.addItem(factory[i].getName()); 070 } 071 panelTop.add(comboPredictor); 072 073 JPanel returnValue = super.createConfigurationPanel(); 074 075 return returnValue; 076 } 077 078 public void restoreConfiguration(SerializedVisualization config) { 079 080 for (int i=0; i<factory.length; i++) { 081 if (factory[i].getName().equals(config.PredictorName)) { 082 comboPredictor.setSelectedIndex(i); 083 selectedFactory = factory[i]; 084 break; 085 } 086 } 087 088 super.restoreConfiguration(config); 089 } 090 091 public SerializedVisualization getCurrentConfiguration() { 092 SerializedVisualization data = super.getCurrentConfiguration(); 093 data.PredictorName = selectedFactory.getName(); 094 095 return data; 096 } 097 098 public void preVisualize() { 099 predictor = new Predictor[yAxis.getMaxEntityNumber()]; 100 for (int i = 0; i < predictor.length; i++) { 101 predictor[i] = selectedFactory.createPredictor(); 102 } 103 super.preVisualize(); 104 } 105 106 public void receiveElement(Element element) { 107 if (element.isOptional()) return; 108 109 long x = xAxis.getField(element); 110 long y = yAxis.getField(element); 111 long z = zAxis.getField(element); 112 113 paint(x,y,zAxis.getEntityFromInt((int)z).getId()); 114 } 115 116 public void visualize() { 117 yAxis.addComparator(new ValueComparator("Miss", false, ((PredictionPainter)painter).getMiss(),yAxis.getEntityName2IntMap())); 118 super.visualize(); 119 } 120 121 protected void installPainter() { 122 ((PredictionPainter)painters[0]).setPredictor(predictor,zAxis.getDataFilter().getTargetType()); 123 super.installPainter(); 124 } 125 126 public Object clone() { 127 PredictionViz o = (PredictionViz) super.clone(); 128 o.factory = new PredictorFactory[factory.length]; 129 for (int i=0; i<factory.length; i++) { 130 o.factory[i] = (PredictorFactory)factory[i].clone(); 131 } 132 o.selectedFactory = (PredictorFactory)selectedFactory.clone(); 133 if (predictor != null) { 134 o.predictor = new Predictor[predictor.length]; 135 for (int i=0; i<predictor.length; i++) 136 o.predictor[i] = (Predictor)predictor[i].clone(); 137 } 138 return o; 139 } 140 }