diff --git a/config/gui_default.cfg b/config/gui_default.cfg index c4f5f3ca..6e84ce9c 100644 --- a/config/gui_default.cfg +++ b/config/gui_default.cfg @@ -19,7 +19,7 @@ "VisualizerPanel": { "Width": 1500, "Height": 800, - "InnerWidth": 1600, + "InnerWidth": 2000, "InnerHeight": 1000 }, "Buttons": { @@ -146,12 +146,12 @@ "LinesPointSize": 5, "PaintFill": false, "VerticalBarSize": 5, - "xAxisTitle": "Timestamp", + "xAxisTitle": "", "xAxisType": "date", "xAxisFormat": "hh:mm:ss:SS", "xAxisOffset": 0.2, - "y1AxisTitle": "y1", - "y2AxisTitle": "y2" + "y1AxisTitle": "", + "y2AxisTitle": "" }, "Legend": { "Width": 190, @@ -179,7 +179,9 @@ "MenuBar": { "Width": 635, "Height": 50, + "visible": true, "showIntervalPanel": true, + "connected": true, "showXOptionsPanel": true, "showYOptionsPanel": true, "showCoordsPanel": true, @@ -221,10 +223,10 @@ "PaintFill": false, "VerticalBarSize": 5, "xAxisOffset": 0.2, - "x1AxisTitle": "x1", - "x2AxisTitle": "x2", - "y1AxisTitle": "y1", - "y2AxisTitle": "y2" + "x1AxisTitle": "", + "x2AxisTitle": "", + "y1AxisTitle": "", + "y2AxisTitle": "" }, "Legend": { "Width": 190, @@ -252,6 +254,7 @@ "MenuBar": { "Width": 635, "Height": 50, + "visible": true, "showIntervalPanel": true, "showXOptionsPanel": true, "showYOptionsPanel": true, @@ -286,6 +289,71 @@ } } } - } + }, + "LabelVisualizerConfigs": { + "LabelVisualizer1": { + "Name": "Label Visualizer 1", + "TraceLength": 1000, + "TraceModeLtd": true, + + "AdditionPolicy": "all", + "AdditionList": ["labeler0.type0", "labeler0.type1"], + + "position": { + "x": 2, + "y": 0, + "rowspan": 1, + "colspan": 1 + }, + "Chart": { + "Width": 450, + "Height": 140, + "BarThickness": 0.7, + "xAxisTitle": "Timestamp", + "xAxisType": "date", + "xAxisFormat": "hh:mm:ss:SS", + "y1AxisTitle": "Labels", + }, + "Legend": { + "Width": 190, + "Height": 150, + + "LegendItem": { + "Width": 165, + "Height": 40, + "Button_Width": 20, + "Button_Height": 20, + "ButtonPanel_Width": 100, + "ButtonPanel_Height": 20, + "NameLabel_Width": 160, + "NameLabel_Height": 16, + "ValueLabel_Width": 60, + "ValueLabel_Height": 20, + "ValueFont": { + "Name": "Dialog", + "Style": "PLAIN", + "Size": 9, + "Color": "BLACK" + } + } + }, + "MenuBar": { + "Width": 635, + "Height": 50, + "visible": false, + "showIntervalPanel": true, + "connected": true, + "showXOptionsPanel": true, + "showYOptionsPanel": false, + "showCoordsPanel": true, + "CoordsFont": { + "Name": "Dialog", + "Style": "PLAIN", + "Size": 11, + "Color": "BLACK" + } + }, + } + }, } } \ No newline at end of file diff --git a/config/gui_min_lab.cfg b/config/gui_min_lab.cfg new file mode 100644 index 00000000..4aa38df4 --- /dev/null +++ b/config/gui_min_lab.cfg @@ -0,0 +1,49 @@ +{ + "MainDisplayConfig": { + "Name": "DNA - Dynamic Network Analyzer", + "LiveDisplayMode": false, + "DefaultDir": "data/test123/run.0/", + + "Width": 1680, + "Height": 800, + + "VisualizerPanel": { + "Width": 1000, + "Height": 800, + "InnerWidth": 900, + "InnerHeight": 1600 + }, + + + "StatsDisplayConfig": { + }, + + "MetricVisualizerConfigs": { + "MetricVisualizer1": { + "Name": "Metric Visualizer 1", + "position": { + "x": 0, + "y": 0, + } + } + }, + "MultiScalarVisualizerConfigs": { + "MultiScalarVisualizer1": { + "Name": "MultiScalar Visualizer 1", + "position": { + "x": 0, + "y": 2, + } + } + }, + "LabelVisualizerConfigs": { + "LabelVisualizer1": { + "Name": "Label Visualizer 2", + "position": { + "x": 0, + "y": 1, + } + } + } + } +} diff --git a/src/dna/visualization/MainDisplay.java b/src/dna/visualization/MainDisplay.java index 042b803b..9594e842 100644 --- a/src/dna/visualization/MainDisplay.java +++ b/src/dna/visualization/MainDisplay.java @@ -38,9 +38,11 @@ import dna.visualization.BatchHandler.ZipMode; import dna.visualization.components.LogDisplay; import dna.visualization.components.statsdisplay.StatsDisplay; +import dna.visualization.components.visualizer.LabelVisualizer; import dna.visualization.components.visualizer.MetricVisualizer; import dna.visualization.components.visualizer.MultiScalarVisualizer; import dna.visualization.components.visualizer.Visualizer; +import dna.visualization.config.components.LabelVisualizerConfig; import dna.visualization.config.components.LogDisplayConfig; import dna.visualization.config.components.MainDisplayConfig; import dna.visualization.config.components.MetricVisualizerConfig; @@ -50,8 +52,7 @@ public class MainDisplay extends JFrame { /** MAIN **/ - public static void main(String[] args) throws URISyntaxException, - IOException { + public static void main(String[] args) throws URISyntaxException, IOException { Log.infoSep(); // check cmd line parameters @@ -116,42 +117,27 @@ public static void main(String[] args) throws URISyntaxException, if (helpFlag) { System.out.println("DNA - Dynamic Network Analyzer"); - System.out - .println("Run the program with the following command line parameters to change the GUI's behaviour:"); + System.out.println( + "Run the program with the following command line parameters to change the GUI's behaviour:"); System.out.println("Parameter" + "\t\t" + "Function"); - System.out.println("-c " + "\t" - + "Uses the specified file as main display configuration"); - System.out.println("-c " + "\t" - + "Uses the specified file as main display configuration"); - System.out - .println("\t\t\t" - + "Note: It will first check the path on the actual filesystem"); - System.out - .println("\t\t\t" - + "then inside the jar. If it is not present, it will use the default-cfg,"); - System.out - .println("\t\t\t" - + "again first the one from the filesystem, then from the jar."); - System.out.println("-d " + "\t\t" - + "Specifies the data-dir as default dir"); + System.out.println("-c " + "\t" + "Uses the specified file as main display configuration"); + System.out.println("-c " + "\t" + "Uses the specified file as main display configuration"); + System.out.println("\t\t\t" + "Note: It will first check the path on the actual filesystem"); + System.out.println("\t\t\t" + "then inside the jar. If it is not present, it will use the default-cfg,"); + System.out.println("\t\t\t" + "again first the one from the filesystem, then from the jar."); + System.out.println("-d " + "\t\t" + "Specifies the data-dir as default dir"); System.out.println("-h" + "\t\t\t" + "Displays this help message"); - System.out.println("-l" + "\t\t\t" - + "Runs the GUI in live display mode"); - System.out.println("-p" + "\t\t\t" - + "Runs the GUI in playback mode"); - System.out.println("-z" + "\t\t\t" - + "Enables zipped batches support"); - System.out - .println("-zr" + "\t\t\t" + "Enables zipped runs support"); - - System.out.println("Example: run vis.jar -c " + '"' - + "config/my_guy.cfg" + '"' + " -d " + '"' + System.out.println("-l" + "\t\t\t" + "Runs the GUI in live display mode"); + System.out.println("-p" + "\t\t\t" + "Runs the GUI in playback mode"); + System.out.println("-z" + "\t\t\t" + "Enables zipped batches support"); + System.out.println("-zr" + "\t\t\t" + "Enables zipped runs support"); + + System.out.println("Example: run vis.jar -c " + '"' + "config/my_guy.cfg" + '"' + " -d " + '"' + "data/scenario1337/run.42/" + '"' + " -l -z"); } else { MainDisplayConfig customConfig = MainDisplay.DefaultConfig; if (configFlag) { - MainDisplayConfig tempConfig = MainDisplayConfig - .readConfig(configPath); + MainDisplayConfig tempConfig = MainDisplayConfig.readConfig(configPath); if (tempConfig != null) customConfig = tempConfig; } @@ -190,8 +176,7 @@ else if (zipRunFlag) MainDisplay display = new MainDisplay(liveFlag, zipMode, config); if (config.isFullscreen()) { - display.setExtendedState(display.getExtendedState() - | JFrame.MAXIMIZED_BOTH); + display.setExtendedState(display.getExtendedState() | JFrame.MAXIMIZED_BOTH); } display.setVisible(true); @@ -231,8 +216,7 @@ else if (zipRunFlag) // config public static boolean runFromJar = IOUtils.isRunFromJar(); public static MainDisplayConfig config; - public static MainDisplayConfig DefaultConfig = MainDisplayConfig - .getDefaultConfig(); + public static MainDisplayConfig DefaultConfig = MainDisplayConfig.getDefaultConfig(); // static paths public static final String defaultConfigPath = "config/gui_default.cfg"; @@ -265,8 +249,9 @@ public MainDisplay(boolean liveDisplay, ZipMode zipMode, String configPath) { this(liveDisplay, zipMode, MainDisplayConfig.readConfig(configPath)); } - public MainDisplay(boolean liveDisplay, ZipMode zipMode, - MainDisplayConfig config) { + public MainDisplay(boolean liveDisplay, ZipMode zipMode, MainDisplayConfig config) { + MainDisplay.config = config; + // init setTitle(config.getName()); setSize(config.getSize()); @@ -368,9 +353,7 @@ public void actionPerformed(ActionEvent event) { batchHandler.start(); startLogDisplays(); } else { - Log.info("Dir '" - + f.getPath() - + "' not present, try again with existing directory."); + Log.info("Dir '" + f.getPath() + "' not present, try again with existing directory."); } } } @@ -401,10 +384,9 @@ public void actionPerformed(ActionEvent event) { // create lock checkbox and add to buttons panel this.mainLock = new JCheckBox("Lock"); - this.mainLock - .setToolTipText("Locks all visualizers, which means their legends wont be altered during reset / directory change."); - this.mainLock.setFont(new Font(this.getDefaultFont().getName(), - Font.BOLD, this.getDefaultFont().getSize())); + this.mainLock.setToolTipText( + "Locks all visualizers, which means their legends wont be altered during reset / directory change."); + this.mainLock.setFont(new Font(this.getDefaultFont().getName(), Font.BOLD, this.getDefaultFont().getSize())); this.mainLock.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { @@ -423,8 +405,7 @@ public void actionPerformed(ActionEvent arg0) { /* * Create StatsDisplay */ - this.statsDisplay = new StatsDisplay(this, - config.getStatsDisplayConfig(), liveDisplay); + this.statsDisplay = new StatsDisplay(this, config.getStatsDisplayConfig(), liveDisplay); this.statsDisplay.setLocation(0, 0); this.statsDisplay.setDirectory(config.getDefaultDir()); @@ -439,16 +420,14 @@ public void actionPerformed(ActionEvent arg0) { * Init LogoPanel, set position and add to leftSidePanel */ this.logoPanel = new JPanel(); - this.logoPanel - .setLayout(new BoxLayout(this.logoPanel, BoxLayout.X_AXIS)); + this.logoPanel.setLayout(new BoxLayout(this.logoPanel, BoxLayout.X_AXIS)); BufferedImage image = null; JarFile x = null; InputStream is = null; try { if (runFromJar) { - Path pPath = Paths.get(Config.class.getProtectionDomain() - .getCodeSource().getLocation().toURI()); + Path pPath = Paths.get(Config.class.getProtectionDomain().getCodeSource().getLocation().toURI()); String[] splits = config.getLogoDir().split("/"); x = new JarFile(pPath.toFile(), false); is = x.getInputStream(x.getEntry(splits[splits.length - 1])); @@ -461,17 +440,14 @@ public void actionPerformed(ActionEvent arg0) { } // rescale image - Image newimg = image.getScaledInstance( - (int) Math.floor(config.getLogoSize().getWidth()), - (int) Math.floor(config.getLogoSize().getHeight()), - java.awt.Image.SCALE_SMOOTH); + Image newimg = image.getScaledInstance((int) Math.floor(config.getLogoSize().getWidth()), + (int) Math.floor(config.getLogoSize().getHeight()), java.awt.Image.SCALE_SMOOTH); JLabel logoLabel = new JLabel(new ImageIcon(newimg)); this.logoPanel.setLayout(new GridBagLayout()); // this.logoPanel.setPreferredSize(config.getLogoSize()); this.logoPanel.add(logoLabel); - this.logoPanel.setBorder(BorderFactory - .createEtchedBorder((EtchedBorder.LOWERED))); + this.logoPanel.setBorder(BorderFactory.createEtchedBorder((EtchedBorder.LOWERED))); // free resources try { @@ -503,13 +479,10 @@ public void actionPerformed(ActionEvent arg0) { int maxYPosition = 0; // FILL PANEL // add metric visualizer - for (MetricVisualizerConfig metVisConfig : config - .getMetricVisualizerConfigs()) { - MetricVisualizer metricVisualizerTemp = new MetricVisualizer(this, - metVisConfig); + for (MetricVisualizerConfig metVisConfig : config.getMetricVisualizerConfigs()) { + MetricVisualizer metricVisualizerTemp = new MetricVisualizer(this, metVisConfig); - if (metVisConfig.getPositionX() >= 0 - && metVisConfig.getPositionY() >= 0) { + if (metVisConfig.getPositionX() >= 0 && metVisConfig.getPositionY() >= 0) { visualizerPanelConstraints.gridx = metVisConfig.getPositionX(); visualizerPanelConstraints.gridy = metVisConfig.getPositionY(); if (visualizerPanelConstraints.gridy > maxYPosition) @@ -517,58 +490,67 @@ public void actionPerformed(ActionEvent arg0) { } else { visualizerPanelConstraints.gridy = maxYPosition++; } - if (metVisConfig.getColSpan() >= 1 - && metVisConfig.getRowSpan() >= 1) { - visualizerPanelConstraints.gridwidth = metVisConfig - .getColSpan(); - visualizerPanelConstraints.gridheight = metVisConfig - .getRowSpan(); + if (metVisConfig.getColSpan() >= 1 && metVisConfig.getRowSpan() >= 1) { + visualizerPanelConstraints.gridwidth = metVisConfig.getColSpan(); + visualizerPanelConstraints.gridheight = metVisConfig.getRowSpan(); } else { visualizerPanelConstraints.gridwidth = 1; visualizerPanelConstraints.gridheight = 1; } - this.visualizerPanel.add(metricVisualizerTemp, - visualizerPanelConstraints); + this.visualizerPanel.add(metricVisualizerTemp, visualizerPanelConstraints); this.registerDataComponent(metricVisualizerTemp); } // add multi scalar visualizer - for (MultiScalarVisualizerConfig multiVisConfig : config - .getMultiScalarVisualizerConfigs()) { - MultiScalarVisualizer metricVisualizerTemp = new MultiScalarVisualizer( - this, multiVisConfig); - - if (multiVisConfig.getPositionX() >= 0 - && multiVisConfig.getPositionY() >= 0) { - visualizerPanelConstraints.gridx = multiVisConfig - .getPositionX(); - visualizerPanelConstraints.gridy = multiVisConfig - .getPositionY(); + for (MultiScalarVisualizerConfig multiVisConfig : config.getMultiScalarVisualizerConfigs()) { + MultiScalarVisualizer metricVisualizerTemp = new MultiScalarVisualizer(this, multiVisConfig); + + if (multiVisConfig.getPositionX() >= 0 && multiVisConfig.getPositionY() >= 0) { + visualizerPanelConstraints.gridx = multiVisConfig.getPositionX(); + visualizerPanelConstraints.gridy = multiVisConfig.getPositionY(); if (visualizerPanelConstraints.gridy > maxYPosition) maxYPosition = visualizerPanelConstraints.gridy; } else { visualizerPanelConstraints.gridy = maxYPosition++; } - if (multiVisConfig.getColSpan() >= 1 - && multiVisConfig.getRowSpan() >= 1) { - visualizerPanelConstraints.gridwidth = multiVisConfig - .getColSpan(); - visualizerPanelConstraints.gridheight = multiVisConfig - .getRowSpan(); + if (multiVisConfig.getColSpan() >= 1 && multiVisConfig.getRowSpan() >= 1) { + visualizerPanelConstraints.gridwidth = multiVisConfig.getColSpan(); + visualizerPanelConstraints.gridheight = multiVisConfig.getRowSpan(); } else { visualizerPanelConstraints.gridwidth = 1; visualizerPanelConstraints.gridheight = 1; } - this.visualizerPanel.add(metricVisualizerTemp, - visualizerPanelConstraints); + this.visualizerPanel.add(metricVisualizerTemp, visualizerPanelConstraints); this.registerDataComponent(metricVisualizerTemp); } + // add label visualizers + for (LabelVisualizerConfig labelVisConfig : config.getLabelVisualizerConfigs()) { + LabelVisualizer labelVisualizerTemp = new LabelVisualizer(this, labelVisConfig); + + if (labelVisConfig.getPositionX() >= 0 && labelVisConfig.getPositionY() >= 0) { + visualizerPanelConstraints.gridx = labelVisConfig.getPositionX(); + visualizerPanelConstraints.gridy = labelVisConfig.getPositionY(); + if (visualizerPanelConstraints.gridy > maxYPosition) + maxYPosition = visualizerPanelConstraints.gridy; + } else { + visualizerPanelConstraints.gridy = maxYPosition++; + } + if (labelVisConfig.getColSpan() >= 1 && labelVisConfig.getRowSpan() >= 1) { + visualizerPanelConstraints.gridwidth = labelVisConfig.getColSpan(); + visualizerPanelConstraints.gridheight = labelVisConfig.getRowSpan(); + } else { + visualizerPanelConstraints.gridwidth = 1; + visualizerPanelConstraints.gridheight = 1; + } + + this.visualizerPanel.add(labelVisualizerTemp, visualizerPanelConstraints); + this.registerDataComponent(labelVisualizerTemp); + } // add log display for (LogDisplayConfig logDisConfig : config.getLogDisplayConfigs()) { LogDisplay logDisplayTemp = new LogDisplay(this, logDisConfig); - if (logDisConfig.getPositionX() >= 0 - && logDisConfig.getPositionY() >= 0) { + if (logDisConfig.getPositionX() >= 0 && logDisConfig.getPositionY() >= 0) { visualizerPanelConstraints.gridx = logDisConfig.getPositionX(); visualizerPanelConstraints.gridy = logDisConfig.getPositionY(); if (visualizerPanelConstraints.gridy > maxYPosition) @@ -576,26 +558,21 @@ public void actionPerformed(ActionEvent arg0) { } else { visualizerPanelConstraints.gridy = maxYPosition++; } - if (logDisConfig.getColSpan() >= 1 - && logDisConfig.getRowSpan() >= 1) { - visualizerPanelConstraints.gridwidth = logDisConfig - .getColSpan(); - visualizerPanelConstraints.gridheight = logDisConfig - .getRowSpan(); + if (logDisConfig.getColSpan() >= 1 && logDisConfig.getRowSpan() >= 1) { + visualizerPanelConstraints.gridwidth = logDisConfig.getColSpan(); + visualizerPanelConstraints.gridheight = logDisConfig.getRowSpan(); } else { visualizerPanelConstraints.gridwidth = 1; visualizerPanelConstraints.gridheight = 1; } - this.visualizerPanel - .add(logDisplayTemp, visualizerPanelConstraints); + this.visualizerPanel.add(logDisplayTemp, visualizerPanelConstraints); this.dataComponents.add(logDisplayTemp); logDisplayTemp.start(); } JScrollPane dataScrollPanel = new JScrollPane(this.visualizerPanel); dataScrollPanel.setPreferredSize(config.getVisualizerPanelSize()); - this.visualizerPanel.setPreferredSize(config - .getInnerVisualizerPanelSize()); + this.visualizerPanel.setPreferredSize(config.getInnerVisualizerPanelSize()); this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.X_AXIS)); this.getContentPane().add(this.leftSidePanel); @@ -624,10 +601,8 @@ public void updateData(BatchData b) { BatchData tempBatch = b; // scaling - if (this.config.getScalingExpression() != null - && !this.config.getScalingExpression().equals("none")) { - tempBatch = BatchHandler.scaleTimestamp(b, - this.config.getScalingExpression()); + if (this.config.getScalingExpression() != null && !this.config.getScalingExpression().equals("none")) { + tempBatch = BatchHandler.scaleTimestamp(b, this.config.getScalingExpression()); } for (Component c : this.dataComponents) { @@ -640,6 +615,9 @@ public void updateData(BatchData b) { if (c instanceof MultiScalarVisualizer) { ((MultiScalarVisualizer) c).updateData(tempBatch); } + if (c instanceof LabelVisualizer) { + ((LabelVisualizer) c).updateData(tempBatch); + } } } @@ -656,19 +634,15 @@ public void initData(BatchData b) { // scaling if (MainDisplay.config.getScalingExpression() != null && !MainDisplay.config.getScalingExpression().equals("none")) { - tempBatch = BatchHandler.scaleTimestamp(b, - MainDisplay.config.getScalingExpression()); + tempBatch = BatchHandler.scaleTimestamp(b, MainDisplay.config.getScalingExpression()); } for (Component c : this.dataComponents) { if (c instanceof StatsDisplay) { if (this.liveDisplay) - ((StatsDisplay) c).initData(tempBatch, - batchHandler.getDir()); + ((StatsDisplay) c).initData(tempBatch, batchHandler.getDir()); else - ((StatsDisplay) c).initData(tempBatch, - batchHandler.getDir(), - batchHandler.getMinTimestamp(), + ((StatsDisplay) c).initData(tempBatch, batchHandler.getDir(), batchHandler.getMinTimestamp(), batchHandler.getMaxTimestamp()); } if (c instanceof MetricVisualizer) { @@ -677,7 +651,13 @@ public void initData(BatchData b) { if (c instanceof MultiScalarVisualizer) { ((MultiScalarVisualizer) c).initData(tempBatch); } + if (c instanceof LabelVisualizer) { + ((LabelVisualizer) c).initData(tempBatch); + } } + + // sync x-axises of metric and label visualizers + setSync(); } /** register components to recieve the batchdata objects **/ @@ -697,6 +677,9 @@ public void reset() { if (c instanceof MultiScalarVisualizer) { ((MultiScalarVisualizer) c).reset(); } + if (c instanceof LabelVisualizer) { + ((LabelVisualizer) c).reset(); + } } } @@ -738,16 +721,13 @@ public void initBatchHandler() throws IOException { if (!this.liveDisplay) { File f; if (this.zipMode.equals(ZipMode.runs)) { - f = new File(this.batchHandler.getDir() + "run." - + this.batchHandler.getRunId() + f = new File(this.batchHandler.getDir() + "run." + this.batchHandler.getRunId() + Config.get("SUFFIX_ZIP_FILE")); if (f.exists() && !f.isDirectory()) { this.batchHandler.updateBatches(); this.batchHandler.init(); } else { - Log.info("Zip '" - + f.getPath() - + "' not existing, BatchHandler could not be initialized."); + Log.info("Zip '" + f.getPath() + "' not existing, BatchHandler could not be initialized."); } } else { f = new File(this.batchHandler.getDir()); @@ -755,25 +735,20 @@ public void initBatchHandler() throws IOException { this.batchHandler.updateBatches(); this.batchHandler.init(); } else { - Log.info("Dir '" - + f.getPath() - + "' not existing, BatchHandler could not be initialized."); + Log.info("Dir '" + f.getPath() + "' not existing, BatchHandler could not be initialized."); } } } } /** Creates and inits a new BatchHandler. **/ - protected void createBatchHandler(MainDisplayConfig config) - throws IOException { - createBatchHandler(config.getDefaultDir(), this, liveDisplay, - this.zipMode); + protected void createBatchHandler(MainDisplayConfig config) throws IOException { + createBatchHandler(config.getDefaultDir(), this, liveDisplay, this.zipMode); } - protected void createBatchHandler(String dataDir, MainDisplay display, - boolean liveFlag, ZipMode zipMode) throws IOException { - display.setBatchHandler(new BatchHandler(dataDir, display, liveFlag, - zipMode)); + protected void createBatchHandler(String dataDir, MainDisplay display, boolean liveFlag, ZipMode zipMode) + throws IOException { + display.setBatchHandler(new BatchHandler(dataDir, display, liveFlag, zipMode)); display.initBatchHandler(); } @@ -782,15 +757,14 @@ public void setBatchHandlerDir(String dir) { if (this.zipMode.equals(ZipMode.runs)) { try { String[] splits = dir.split(Dir.delimiter); - this.batchHandler.setRunId(Dir.getRun(splits[splits.length - 1] - .replace(Config.get("SUFFIX_ZIP_FILE"), ""))); + this.batchHandler + .setRunId(Dir.getRun(splits[splits.length - 1].replace(Config.get("SUFFIX_ZIP_FILE"), ""))); String tempDir = ""; for (int i = 0; i < splits.length - 1; i++) tempDir += splits[i] + Dir.delimiter; this.batchHandler.setDir(tempDir); } catch (NumberFormatException e) { - Log.warn("NumberFormatException on dir '" + dir - + "', no run-zip."); + Log.warn("NumberFormatException on dir '" + dir + "', no run-zip."); } } else { this.batchHandler.setDir(dir); @@ -863,7 +837,9 @@ public long getPreviousTimestamp(long timestamp) { return this.batchHandler.getPreviousTimestamp(timestamp); } - /** called from the statsdisplay to get the amount of previous timestamps **/ + /** + * called from the statsdisplay to get the amount of previous timestamps + **/ public int getAmountOfPreviousTimestamps(long timestamp) { return this.batchHandler.getAmountOfPreviousTimestamps(timestamp); } @@ -917,4 +893,67 @@ public void setLocked(boolean locked) { } } } + + /** + * Broadcasts a x1 size slider change to all registered data components. + **/ + public void broadcastX1SizeSliderChange(Component source, int value) { + for (Component c : this.dataComponents) { + // dont broadcast to source + if (!c.equals(source)) { + if (c instanceof MetricVisualizer) { + ((MetricVisualizer) c).setX1IntervalSizeSlider(value); + } + if (c instanceof LabelVisualizer) { + ((LabelVisualizer) c).setX1IntervalSizeSlider(value); + } + } + } + } + + /** + * Broadcasts a x1 interval scroll bar change to all registered data + * components. + **/ + public void broadcastX1IntervalScrollBarChange(Component source, int value) { + for (Component c : this.dataComponents) { + // dont broadcast to source + if (!c.equals(source)) { + if (c instanceof MetricVisualizer) { + ((MetricVisualizer) c).setX1IntervalScrollBar(value); + } + if (c instanceof LabelVisualizer) { + ((LabelVisualizer) c).setX1IntervalScrollBar(value); + } + } + } + } + + public void broadcastX1IntervalEnabled(Component source, boolean enabled) { + for (Component c : this.dataComponents) { + // dont broadcast to source + if (!c.equals(source)) { + if (c instanceof MetricVisualizer) { + ((MetricVisualizer) c).setX1IntervalEnabled(enabled); + } + if (c instanceof LabelVisualizer) { + ((LabelVisualizer) c).setX1IntervalEnabled(enabled); + } + } + } + } + + public void setSync() { + Visualizer source = null; + for (Component c : this.dataComponents) { + if (c instanceof MetricVisualizer || c instanceof LabelVisualizer) { + if (source == null) { + source = (Visualizer) c; + } else { + ((Visualizer) c).getChart().setSynchronizedXStartChart(source.getChart()); + } + } + } + } + } diff --git a/src/dna/visualization/components/visualizer/CircularArrayList.java b/src/dna/visualization/components/visualizer/CircularArrayList.java new file mode 100644 index 00000000..f1187afe --- /dev/null +++ b/src/dna/visualization/components/visualizer/CircularArrayList.java @@ -0,0 +1,136 @@ +package dna.visualization.components.visualizer; + +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.RandomAccess; + +/** + * Original Source: + * http://www.museful.net/2012/software-development/circulararraylist-for-java + * + * If you use this code, please consider notifying isak at du-preez dot com with + * a brief description of your application. + * + * This is free and unencumbered software released into the public domain. + * Anyone is free to copy, modify, publish, use, compile, sell, or distribute + * this software, either in source code form or as a compiled binary, for any + * purpose, commercial or non-commercial, and by any means. + */ + +public class CircularArrayList extends AbstractList implements RandomAccess { + + private final int n; // buffer length + private final List buf; // a List implementing RandomAccess + private int head = 0; + private int tail = 0; + + public CircularArrayList(int capacity) { + n = capacity + 1; + buf = new ArrayList(Collections.nCopies(n, (E) null)); + } + + public int capacity() { + return n - 1; + } + + private int wrapIndex(int i) { + int m = i % n; + if (m < 0) { // java modulus can be negative + m += n; + } + return m; + } + + // This method is O(n) but will never be called if the + // CircularArrayList is used in its typical/intended role. + private void shiftBlock(int startIndex, int endIndex) { + assert (endIndex > startIndex); + for (int i = endIndex - 1; i >= startIndex; i--) { + set(i + 1, get(i)); + } + } + + @Override + public int size() { + return tail - head + (tail < head ? n : 0); + } + + @Override + public E get(int i) { + if (i < 0 || i >= size()) { + throw new IndexOutOfBoundsException(); + } + return buf.get(wrapIndex(head + i)); + } + + @Override + public E set(int i, E e) { + if (i < 0 || i >= size()) { + throw new IndexOutOfBoundsException(); + } + return buf.set(wrapIndex(head + i), e); + } + + @Override + public void add(int i, E e) { + int s = size(); + if (s == n - 1) { + throw new IllegalStateException("Cannot add element." + " CircularArrayList is filled to capacity."); + } + if (i < 0 || i > s) { + throw new IndexOutOfBoundsException(); + } + tail = wrapIndex(tail + 1); + if (i < s) { + shiftBlock(i, s); + } + set(i, e); + } + + @Override + public E remove(int i) { + int s = size(); + if (i < 0 || i >= s) { + throw new IndexOutOfBoundsException(); + } + E e = get(i); + if (i > 0) { + shiftBlock(0, i); + } + head = wrapIndex(head + 1); + return e; + } + + /** + * Added for convenience. + * + * @author Rwilmes + */ + public E getHead() { + return this.get(0); + } + + /** + * Added for convenience. + * + * @author Rwilmes + */ + public E getTail() { + return this.get(size() - 1); + } + + /** + * Added for convenience. + * + * @author Rwilmes + */ + public void addSilent(E element) { + if (size() == capacity()) { + remove(0); + } + add(element); + } + +} \ No newline at end of file diff --git a/src/dna/visualization/components/visualizer/LabelVisualizer.java b/src/dna/visualization/components/visualizer/LabelVisualizer.java new file mode 100644 index 00000000..665b38a0 --- /dev/null +++ b/src/dna/visualization/components/visualizer/LabelVisualizer.java @@ -0,0 +1,621 @@ +package dna.visualization.components.visualizer; + +import java.awt.Color; +import java.awt.Font; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; + +import javax.swing.BorderFactory; +import javax.swing.border.EtchedBorder; +import javax.swing.border.TitledBorder; + +import dna.labels.Label; +import dna.labels.LabelList; +import dna.series.data.BatchData; +import dna.visualization.MainDisplay; +import dna.visualization.components.visualizer.traces.LabelTrace; +import dna.visualization.config.components.LabelVisualizerConfig; +import dna.visualization.config.components.LabelVisualizerConfig.LabelAdditionPolicy; +import info.monitorenter.gui.chart.IAxis.AxisTitle; +import info.monitorenter.gui.chart.ITrace2D; +import info.monitorenter.gui.chart.ITracePoint2D; +import info.monitorenter.gui.chart.axis.scalepolicy.AxisScalePolicyAutomaticBestFit; +import info.monitorenter.gui.chart.axis.scalepolicy.AxisScalePolicyManualTicks; +import info.monitorenter.gui.chart.labelformatters.LabelFormatterDate; +import info.monitorenter.gui.chart.rangepolicies.RangePolicyFixedViewport; +import info.monitorenter.gui.chart.rangepolicies.RangePolicyUnbounded; +import info.monitorenter.util.Range; + +public class LabelVisualizer extends Visualizer { + + /** + * + */ + private static final long serialVersionUID = 1L; + + protected HashMap labelTraces; + + protected HashMap mapping; + protected HashMap colorMap; + protected int mappingCounter; + + protected ArrayList availableValues; + private LinkedList batchBuffer; + private BatchData initBatch; + private int bufferSize; + private boolean reload; + + private boolean xAxisTypeTimestamp; + private long currentTimestamp; + + // config + protected MainDisplay mainDisplay; + protected LabelVisualizerConfig config; + + protected boolean automaticAddition; + + protected LabelAdditionPolicy labelAdditionPolicy; + protected String[] labelAdditionList; + + public LabelVisualizer(MainDisplay mainDisplay, LabelVisualizerConfig config) { + super(config.getChartSize(), config.getLegendSize()); + + this.x1Connected = config.getMenuBarConfig().isX1AxisConnected(); + this.mainDisplay = mainDisplay; + this.labelTraces = new HashMap(); + this.mapping = new HashMap(); + this.colorMap = new HashMap(); + this.mappingCounter = 0; + this.availableValues = new ArrayList(); + + this.bufferSize = config.getTraceLength(); + this.TRACE_LENGTH = config.getTraceLength(); + + this.labelAdditionPolicy = config.getAdditionPolicy(); + this.labelAdditionList = config.getAdditionList(); + + this.config = config; + this.automaticAddition = true; + + // batch buffer + this.batchBuffer = new LinkedList(); + this.reload = false; + + // set title and border of the metric visualizer + TitledBorder title = BorderFactory.createTitledBorder(config.getName()); + title.setBorder(BorderFactory.createEtchedBorder((EtchedBorder.LOWERED))); + title.setTitleFont(new Font(this.mainDisplay.getDefaultFont().getName(), Font.BOLD, + this.mainDisplay.getDefaultFont().getSize())); + title.setTitleColor(this.mainDisplay.getDefaultFontColor()); + this.setBorder(title); + + // if x axis type is date + this.xAxisTypeTimestamp = true; + if (config.getxAxisType().equals("date")) { + this.xAxisTypeTimestamp = false; + this.xAxis1.setFormatter(new LabelFormatterDate(new SimpleDateFormat(config.getxAxisFormat()))); + this.xAxis1.setMajorTickSpacing(5); + this.xAxis1.setMinorTickSpacing(1); + this.xAxis1.setAxisScalePolicy(new AxisScalePolicyAutomaticBestFit()); + } + + this.yAxis1.setAxisScalePolicy(new AxisScalePolicyManualTicks()); + this.yAxis1.setRangePolicy(new RangePolicyFixedViewport(new Range(0, 1))); + this.yAxis1.setPaintScale(false); + + // add menu bar + super.addMenuBar(config.getMenuBarConfig()); + this.menuBar.setYCoordsLabelText("v:"); + this.menuBar.setVisible(config.getMenuBarConfig().isVisible()); + + // add coordinate parsing to mouseover on chart + this.chart.addMouseMotionListener(new MouseMotionListener() { + @Override + public void mouseMoved(MouseEvent e) { + if (chart.getPointFinder().getNearestPoint(e, chart) != null) { + ITracePoint2D tempPointFinder = chart.getPointFinder().getNearestPoint(e, chart); + if (tempPointFinder != null) + menuBar.updateCoordsPanel(tempPointFinder.getX(), tempPointFinder.getY()); + } + } + + public void mouseDragged(MouseEvent e) { + } + }); + + // apply config + this.chart.setPreferredSize(config.getChartSize()); + this.legend.setLegendSize(config.getLegendSize()); + + this.xAxis1.setAxisTitle(new AxisTitle(config.getX1AxisTitle())); + this.yAxis1.setAxisTitle(new AxisTitle(config.getY1AxisTitle())); + + } + + /** initializes the data with the first batch **/ + public void initData(BatchData b) { + this.initBatch = b; + this.minTimestamp = b.getTimestamp(); + this.maxTimestamp = b.getTimestamp(); + this.minShownTimestamp = b.getTimestamp(); + this.maxShownTimestamp = this.minShownTimestamp; + + this.currentTimestamp = b.getTimestamp(); + + // clear chart + for (ITrace2D t : this.chart.getTraces()) { + t.removeAllPoints(); + } + + for (String name : this.labelTraces.keySet()) { + this.labelTraces.get(name).setLastTimestamp(b.getTimestamp() - 1); + } + + // gather all available values + for (Label label : b.getLabels().getList()) { + String key = getLabelKey(label.getName(), label.getType()); + this.availableValues.add(key); + + this.handleAutomaticAdditions(key); + // if (this.automaticAddition) + // this.legend.addLabelItemToList(key); + } + + // init addbox + String[] tempValues = this.gatherValues(b); + this.legend.updateAddBox(tempValues); + + // toggle visibility and validate + this.toggleYAxisVisibility(); + this.validate(); + } + + /** gathers all plottable values from the batch **/ + public String[] gatherValues(BatchData b) { + ArrayList tempList = new ArrayList(); + tempList.add("labels"); + + ArrayList labelers = new ArrayList(); + ArrayList> types = new ArrayList>(); + + for (Label l : b.getLabels().getList()) { + String name = l.getName(); + String type = l.getType(); + + if (!labelers.contains(name)) { + labelers.add(name); + types.add(new ArrayList()); + } + + int index = labelers.indexOf(name); + ArrayList typesList = types.get(index); + + if (!typesList.contains(type)) + typesList.add(type); + } + + // store original indices before sorting + HashMap indexMap = new HashMap(); + for (int i = 0; i < labelers.size(); i++) + indexMap.put(labelers.get(i), i); + + // sort labelers alphabetically + Collections.sort(labelers); + + // fill templist + for (int i = 0; i < labelers.size(); i++) { + String name = labelers.get(i); + tempList.add("--- " + name); + + ArrayList ts = types.get(indexMap.get(name)); + Collections.sort(ts); + + for (String type : ts) + tempList.add("----- " + name + "." + type); + } + + String[] tempValues = tempList.toArray(new String[tempList.size()]); + return tempValues; + } + + /** adds trace to the visualizer with default trace length **/ + public void addTrace(String name, Color color) { + if (!this.labelTraces.containsKey(name)) { + int yMapping = this.getLabelerTypeKeyMapping(name); + this.colorMap.put(name, color); + LabelTrace labelTrace = new LabelTrace(this, this.chart, name, yMapping, 10, color, this.currentTimestamp); + this.labelTraces.put(name, labelTrace); + } + + this.updateTraceSizes(); + this.updateYAxisRange(); + } + + /** + * If the name is already being mapped it returns the mapping. Else a new + * one is created and returned. + **/ + protected int getLabelerTypeKeyMapping(String labelerTypeKey) { + if (this.mapping.containsKey(labelerTypeKey)) + return this.mapping.get(labelerTypeKey); + + int newMapping = this.mappingCounter; + this.mapping.put(labelerTypeKey, newMapping); + this.mappingCounter--; + + return newMapping; + } + + /** + * removes a trace from the chart and the traces-list and the current traces + **/ + public void removeTrace(String name) { + if (this.labelTraces.containsKey(name)) { + LabelTrace trace = this.labelTraces.get(name); + trace.clear(); + this.labelTraces.remove(name); + } + + this.toggleXAxisVisibility(); + this.toggleYAxisVisibility(); + + this.updateTraceSizes(); + this.updateYAxisRange(); + } + + /** Updates the trace sizes. **/ + protected void updateTraceSizes() { + int traces = this.labelTraces.size(); + for (String name : this.labelTraces.keySet()) { + LabelTrace trace = this.labelTraces.get(name); + trace.setSize(this.getTraceSize(traces)); + } + } + + /** Returns the trace size of a trace based on the number of traces. **/ + protected int getTraceSize(int traces) { + int paddings = 50; // this will be substracted from the absolute height + int chartHeight = (int) Math.floor(this.config.getChartSize().getHeight()) - paddings; + int individualHeight = (int) Math.floor((this.config.getBarThickness() * chartHeight) / traces); + + return individualHeight; + } + + /** Updates the YAxisRange. **/ + protected void updateYAxisRange() { + this.yAxis1.setRangePolicy(new RangePolicyFixedViewport(getYAxisRange())); + } + + /** Returns the y-axis range based on the number of traces. **/ + protected Range getYAxisRange() { + int max = 0; + int min = 0; + boolean first = true; + for (String name : this.labelTraces.keySet()) { + int y = this.labelTraces.get(name).getYMapping(); + if (first) { + max = y; + min = y; + first = false; + } else { + max = Math.max(max, y); + min = Math.min(min, y); + } + } + return new Range(min - 1, max + 1); + } + + /** + * Updates the chart and the legend with a new batch. + * + * @param b + * New batch + */ + public void updateData(BatchData b) { + long timestamp = b.getTimestamp(); + double timestampDouble = timestamp; + + // check if new batch is before last one which means time slided + // backwards + if (timestamp < this.currentTimestamp) { + while (this.batchBuffer.size() > 0) { + if (this.batchBuffer.getLast().getTimestamp() <= b.getTimestamp()) { + break; + } else { + this.batchBuffer.removeLast(); + } + } + + // reload data + this.reloadData(); + // this.updateData(b); + } else { + // if reload flag is set, dont add batch to buffer + if (!this.reload) { + // if buffer sizer is reached, remove batches until its + if (this.batchBuffer.size() >= this.bufferSize) + while (!(this.batchBuffer.size() < this.bufferSize)) + this.batchBuffer.removeFirst(); + // add new batch as last batch to list + this.batchBuffer.addLast(b); + } + + this.currentTimestamp = timestamp; + + if (timestamp < this.minTimestamp) + this.minTimestamp = timestamp; + if (timestamp > this.maxTimestamp) + this.maxTimestamp = timestamp; + + // iterate over all added traces + LabelList labels = b.getLabels(); + + for (String name : this.labelTraces.keySet()) { + LabelTrace labelTrace = this.labelTraces.get(name); + boolean updated = false; + for (Label l : labels.getList()) { + String key = getLabelKey(l.getName(), l.getType()); + if (key.equals(name)) { + labelTrace.update(timestampDouble, l); + updated = true; + break; + } + } + + if (!updated) + labelTrace.update(timestampDouble, null); + } + + // timestamp adjustmens for x-axis tick calculation + if (config.isTraceModeLtd() && !this.FIXED_VIEWPORT) { + this.maxShownTimestamp = this.maxTimestamp; + if (this.maxShownTimestamp - this.TRACE_LENGTH > 0) + this.minShownTimestamp = this.maxShownTimestamp - this.TRACE_LENGTH; + else + this.minShownTimestamp = 0; + this.xAxis1.setRange(new Range(this.minShownTimestamp, this.maxShownTimestamp)); + } else { + if (this.FIXED_VIEWPORT) { + double lowP = 1.0 * this.menuBar.getIntervalSlider().getValue() / 100; + double highP = 1.0 * (this.menuBar.getIntervalSlider().getValue() + + this.menuBar.getIntervalSlider().getModel().getExtent()) / 100; + double minD = 0; + double maxD = 0; + + for (String s : this.labelTraces.keySet()) { + minD = this.labelTraces.get(s).getMinX(); + maxD = this.labelTraces.get(s).getMaxX(); + if (this.labelTraces.get(s).getMinX() < this.minTimestamp) + minD = this.labelTraces.get(s).getMinX(); + if (this.labelTraces.get(s).getMaxX() > this.maxTimestamp) + maxD = this.labelTraces.get(s).getMaxX(); + } + double tMinNew = minD + (lowP * (maxD - minD)); + double tMaxNew = minD + (highP * (maxD - minD)); + + this.xAxis1.setRange(new Range(tMinNew, tMaxNew)); + this.setMinShownTimestamp((long) tMinNew); + this.setMaxShownTimestamp((long) tMaxNew); + } + } + // update chart axis ticks + this.updateTicks(); + + // check if new label contained in the batch + boolean newLabelFound = false; + + for (Label l : labels.getList()) { + String name = l.getName(); + String type = l.getType(); + + String key = getLabelKey(name, type); + + if (!this.availableValues.contains(key)) { + newLabelFound = true; + this.availableValues.add(key); + + this.handleAutomaticAdditions(key); + // if (this.automaticAddition) + // this.legend.addLabelItemToList(key); + } + } + + if (newLabelFound) + this.legend.updateAddBox(this.gatherAddBoxChoicesFromAvailableValues()); + } + + this.validate(); + } + + /** Handles the automatic additions given the policy. **/ + protected void handleAutomaticAdditions(String key) { + switch (this.labelAdditionPolicy) { + case AUTOMATIC_ADDITION_ALL: + this.addLabelItemToList(key); + break; + case AUTOMATIC_ADDITION_LIST: + for (String s : this.labelAdditionList) { + if (s.equals(key)) { + this.addLabelItemToList(key); + break; + } + } + break; + case MANUAL: + // do nothing + break; + } + } + + /** + * Adds a label item to the legend list (same as when selected from addbox. + **/ + protected void addLabelItemToList(String key) { + this.legend.addLabelItemToList(key); + } + + /** Gathers all currently available addbox-choices. **/ + protected String[] gatherAddBoxChoicesFromAvailableValues() { + ArrayList addBoxList = new ArrayList(); + addBoxList.add("labels"); + + HashMap> labelers = new HashMap>(); + + // split available value-keys by . + for (String keys : this.availableValues) { + String[] splits = keys.split("\\."); + String name = splits[0]; + String type = splits[1]; + + for (int i = 2; i < splits.length; i++) + type += "." + splits[i]; + + ArrayList tempList; + if (labelers.containsKey(name)) { + tempList = labelers.get(name); + } else { + tempList = new ArrayList(); + labelers.put(name, tempList); + } + + tempList.add(type); + } + + for (String l : labelers.keySet()) { + addBoxList.add("--- " + l); + for (String t : labelers.get(l)) + addBoxList.add("----- " + getLabelKey(l, t)); + } + + String[] tempValues = addBoxList.toArray(new String[addBoxList.size()]); + return tempValues; + } + + /** Returns the key of a label based on its name and type. **/ + protected String getLabelKey(String name, String type) { + return name + "." + type; + } + + /** reloads all data included in the batchBuffer **/ + private void reloadData() { + // set reload flag + this.reload = true; + + // reset current timestamp + this.currentTimestamp = 0; + + // clear chart + for (String name : this.labelTraces.keySet()) { + LabelTrace trace = this.labelTraces.get(name); + trace.clear(); + } + + // update with old batches + Iterator iterator = this.batchBuffer.iterator(); + while (iterator.hasNext()) { + this.updateData(iterator.next()); + } + + // unset reload flag + this.reload = false; + } + + /** resets the metric visualizer **/ + public void reset() { + this.minShownTimestamp = 0; + this.maxShownTimestamp = 10; + + // clear labels + for (String name : this.labelTraces.keySet()) { + LabelTrace trace = this.labelTraces.get(name); + trace.clear(); + } + this.batchBuffer.clear(); + this.availableValues.clear(); + this.chart.updateUI(); + } + + /** handles the ticks that are shown on the x axis **/ + @Override + protected void updateX1Ticks() { + if (this.xAxisTypeTimestamp) { + double minTemp = 0; + double maxTemp = 10; + if (this.xAxis1.getRangePolicy() instanceof RangePolicyUnbounded) { + minTemp = this.minTimestamp * 1.0; + maxTemp = this.maxTimestamp * 1.0; + } else { + if (this.xAxis1.getRangePolicy() instanceof RangePolicyFixedViewport) { + minTemp = this.minShownTimestamp; + maxTemp = this.maxShownTimestamp; + } + } + if (maxTemp > minTemp) { + double range = maxTemp - minTemp; + if (range > 0) { + double tickSpacingNew = Math.floor(range / 10); + if (tickSpacingNew < 1) + tickSpacingNew = 1.0; + this.xAxis1.setMajorTickSpacing(tickSpacingNew); + this.xAxis1.setMinorTickSpacing(tickSpacingNew); + } + } + } + } + + /** shows/hides a trace from the chart without deleting it **/ + public void toggleTraceVisibility(String name) { + if (this.labelTraces.containsKey(name)) { + LabelTrace trace = this.labelTraces.get(name); + if (trace.isVisible()) + trace.setVisible(false); + else + trace.setVisible(true); + } + this.chart.setRequestedRepaint(true); + } + + /** Returns the value at the given y-location. **/ + public String getValue(double x, double y) { + String value = "unknown"; + int yFloored = (int) Math.floor(y); + for (String key : this.labelTraces.keySet()) { + LabelTrace label = this.labelTraces.get(key); + if (yFloored == label.getYMapping()) { + value = label.getValue(x); + break; + } + } + return value; + } + + /** Updates the according legend item. **/ + public void updateItem(String name, String value) { + this.legend.updateItem(name, value); + } + + @Override + public void broadcastX1IntervalSizeSliderChange(int value) { + if (this.isX1Connected()) + this.mainDisplay.broadcastX1SizeSliderChange(this, value); + } + + @Override + public void broadcastX1IntervalScrollBarChange(int value) { + if (this.isX1Connected()) + this.mainDisplay.broadcastX1IntervalScrollBarChange(this, value); + } + + @Override + public void broadcastX1IntervalEnabled(boolean enabled) { + if (this.isX1Connected()) + this.mainDisplay.broadcastX1IntervalEnabled(this, enabled); + } + +} diff --git a/src/dna/visualization/components/visualizer/Legend.java b/src/dna/visualization/components/visualizer/Legend.java index 3321a081..12cd34f6 100644 --- a/src/dna/visualization/components/visualizer/Legend.java +++ b/src/dna/visualization/components/visualizer/Legend.java @@ -74,19 +74,15 @@ public Legend(Visualizer parent, Dimension size) { c.gridy = 0; this.add(list, c); this.scrollPane = new JScrollPane(this.list); - this.scrollPane.setPreferredSize(new Dimension(size.width - 3, - size.height - 25)); - this.scrollPane - .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + this.scrollPane.setPreferredSize(new Dimension(size.width - 3, size.height - 25)); + this.scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); this.add(scrollPane); // init addbutton panel and add it this.addButtonPanel = new JPanel(); this.addButtonPanel.setPreferredSize(new Dimension(size.width - 3, 20)); - this.addButtonPanel.setBorder(BorderFactory - .createEtchedBorder((EtchedBorder.LOWERED))); - this.addButtonPanel.setLayout(new BoxLayout(this.addButtonPanel, - BoxLayout.X_AXIS)); + this.addButtonPanel.setBorder(BorderFactory.createEtchedBorder((EtchedBorder.LOWERED))); + this.addButtonPanel.setLayout(new BoxLayout(this.addButtonPanel, BoxLayout.X_AXIS)); c.gridx = 0; c.gridy = 1; @@ -96,13 +92,43 @@ public Legend(Visualizer parent, Dimension size) { } public void setLegendSize(Dimension size) { - this.scrollPane.setPreferredSize(new Dimension(size.width - 3, - size.height - 25)); + this.scrollPane.setPreferredSize(new Dimension(size.width - 3, size.height - 25)); this.addButtonPanel.setPreferredSize(new Dimension(size.width - 3, 20)); this.validate(); } - /** adds a value item to the list, if its already added nothing will happen **/ + /** + * adds a label item to the list, if its already added nothing will happen + **/ + public void addLabelItemToList(String name) { + boolean alreadyAdded = false; + for (Component c : this.list.getComponents()) { + if (c instanceof LegendItem) { + if (c.getName().equals(name)) { + alreadyAdded = true; + } + } + } + + if (!alreadyAdded) { + Color color = this.colorHandler.getNextColor(); + + LegendItem i = new LegendItemLabel(this.list, name, color); + i.setToolTipText(Legend.getToolTipText(name)); + this.list.add(i); + if (this.parent instanceof LabelVisualizer) + ((LabelVisualizer) this.parent).addTrace(name, color); + + this.parent.updateTicks(); + } + this.parent.toggleXAxisVisibility(); + this.parent.toggleYAxisVisibility(); + this.validate(); + } + + /** + * adds a value item to the list, if its already added nothing will happen + **/ public void addValueItemToList(String name) { boolean alreadyAdded = false; for (Component c : this.list.getComponents()) { @@ -147,8 +173,7 @@ public void addValueItemToList(MetricVisualizerItem item) { String name = item.getName(); Color color; - if ((item.getColor() != null) - && this.colorHandler.containsColor(item.getColor())) { + if ((item.getColor() != null) && this.colorHandler.containsColor(item.getColor())) { color = item.getColor(); this.colorHandler.addColor(color); } else { @@ -216,16 +241,13 @@ public void addDistributionItemToList(String name) { if (this.parent instanceof MultiScalarVisualizer) { MultiScalarVisualizerConfig config = ((MultiScalarVisualizer) this.parent).config; if (config.getListConfig() != null) { - xAxis = config.getListConfig().getAllDistributionsConfig() - .getXAxis(); - yAxis = config.getListConfig().getAllDistributionsConfig() - .getYAxis(); + xAxis = config.getListConfig().getAllDistributionsConfig().getXAxis(); + yAxis = config.getListConfig().getAllDistributionsConfig().getYAxis(); } } if (this.parent instanceof MultiScalarVisualizer) - ((MultiScalarVisualizer) this.parent).addDistributionTrace( - name, color, xAxis, yAxis); + ((MultiScalarVisualizer) this.parent).addDistributionTrace(name, color, xAxis, yAxis); this.parent.updateTicks(); } this.parent.toggleXAxisVisibility(); @@ -251,8 +273,7 @@ public void addDistributionItemToList(MultiScalarDistributionItem item) { String name = item.getName(); Color color; - if ((item.getColor() != null) - && this.colorHandler.containsColor(item.getColor())) { + if ((item.getColor() != null) && this.colorHandler.containsColor(item.getColor())) { color = item.getColor(); this.colorHandler.addColor(color); } else { @@ -264,8 +285,8 @@ public void addDistributionItemToList(MultiScalarDistributionItem item) { this.list.add(i); if (this.parent instanceof MultiScalarVisualizer) - ((MultiScalarVisualizer) this.parent).addDistributionTrace( - name, color, item.getXAxis(), item.getYAxis()); + ((MultiScalarVisualizer) this.parent).addDistributionTrace(name, color, item.getXAxis(), + item.getYAxis()); // usually added to x1/y1, check if config says otherways and toggle // buttons accordingly @@ -321,16 +342,13 @@ public void addNodeValueListItemToList(String name) { if (this.parent instanceof MultiScalarVisualizer) { MultiScalarVisualizerConfig config = ((MultiScalarVisualizer) this.parent).config; if (config.getListConfig() != null) { - xAxis = config.getListConfig().getAllNodeValueListsConfig() - .getXAxis(); - yAxis = config.getListConfig().getAllNodeValueListsConfig() - .getYAxis(); + xAxis = config.getListConfig().getAllNodeValueListsConfig().getXAxis(); + yAxis = config.getListConfig().getAllNodeValueListsConfig().getYAxis(); } } if (this.parent instanceof MultiScalarVisualizer) - ((MultiScalarVisualizer) this.parent).addNodeValueListTrace( - name, color, xAxis, yAxis); + ((MultiScalarVisualizer) this.parent).addNodeValueListTrace(name, color, xAxis, yAxis); this.parent.updateTicks(); } @@ -357,8 +375,7 @@ public void addNodeValueListItemToList(MultiScalarNodeValueListItem item) { String name = item.getName(); Color color; - if ((item.getColor() != null) - && this.colorHandler.containsColor(item.getColor())) { + if ((item.getColor() != null) && this.colorHandler.containsColor(item.getColor())) { color = item.getColor(); this.colorHandler.addColor(color); } else { @@ -369,8 +386,8 @@ public void addNodeValueListItemToList(MultiScalarNodeValueListItem item) { i.setToolTipText(Legend.getToolTipText(name)); this.list.add(i); if (this.parent instanceof MultiScalarVisualizer) - ((MultiScalarVisualizer) this.parent).addNodeValueListTrace( - name, color, item.getXAxis(), item.getYAxis()); + ((MultiScalarVisualizer) this.parent).addNodeValueListTrace(name, color, item.getXAxis(), + item.getYAxis()); // usually added to x1/y1, check if config says otherways and toggle // buttons accordingly @@ -410,6 +427,8 @@ public void removeItem(String name, Color color) { ((MetricVisualizer) this.parent).removeTrace(name); if (this.parent instanceof MultiScalarVisualizer) ((MultiScalarVisualizer) this.parent).removeTrace(name); + if (this.parent instanceof LabelVisualizer) + ((LabelVisualizer) this.parent).removeTrace(name); this.colorHandler.removeColor(color); } @@ -422,15 +441,13 @@ public void updateAddBox(String[] addBoxChoices) { @Override public void actionPerformed(ActionEvent event) { if (thisLegend.addBox.getSelectedItem() instanceof String) { - thisLegend.addSelection(thisLegend.addBox - .getSelectedIndex()); + thisLegend.addSelection(thisLegend.addBox.getSelectedIndex()); } } }); this.addBox.setToolTipText("Add selected value to the list"); this.addBox.setFont(MainDisplay.config.getDefaultFont()); - BoundsPopupMenuListener listener = new BoundsPopupMenuListener(true, - false); + BoundsPopupMenuListener listener = new BoundsPopupMenuListener(true, false); this.addBox.addPopupMenuListener(listener); this.addBox.setPrototypeDisplayValue("Test"); this.addButtonPanel.add(addBox); @@ -448,21 +465,18 @@ private void initAddBox(String[] addBoxChoices) { @Override public void actionPerformed(ActionEvent event) { if (thisLegend.addBox.getSelectedItem() instanceof String) - thisLegend.addSelection(thisLegend.addBox - .getSelectedIndex()); + thisLegend.addSelection(thisLegend.addBox.getSelectedIndex()); } }); this.addBox.setToolTipText("Add selected value to the list"); this.addBox.setFont(MainDisplay.config.getDefaultFont()); - BoundsPopupMenuListener listener = new BoundsPopupMenuListener(true, - false); + BoundsPopupMenuListener listener = new BoundsPopupMenuListener(true, false); this.addBox.addPopupMenuListener(listener); this.addBox.setPrototypeDisplayValue("Test"); // create lock checkbox this.lock = new JCheckBox("Lock"); - this.lock - .setToolTipText("Locks the visualizer. Prevents any legend alteration on reset / directory change."); + this.lock.setToolTipText("Locks the visualizer. Prevents any legend alteration on reset / directory change."); this.lock.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { @@ -498,21 +512,18 @@ public void addSelection(int selectionIndex) { // each if (this.addBoxMenu[selectionIndex].equals("metrics")) { int x = selectionIndex + 1; - while (x != this.addBoxMenu.length - && this.addBoxMenu[x].charAt(0) == '-') { + while (x != this.addBoxMenu.length && this.addBoxMenu[x].charAt(0) == '-') { if (this.addBoxMenu[x].substring(0, 6).equals("----- ")) { - this.addValueItemToList(this.addBoxMenu[x] - .substring(6)); + this.addValueItemToList(this.addBoxMenu[x].substring(6)); } x++; } } else { // if selected element is a category other than "metrics" int x = selectionIndex + 1; - while (x != this.addBoxMenu.length - && this.addBoxMenu[x].charAt(0) == '-') { - this.addValueItemToList(this.addBoxMenu[selectionIndex] - + "." + this.addBoxMenu[x].substring(3)); + while (x != this.addBoxMenu.length && this.addBoxMenu[x].charAt(0) == '-') { + this.addValueItemToList( + this.addBoxMenu[selectionIndex] + "." + this.addBoxMenu[x].substring(3)); x++; } } @@ -521,12 +532,9 @@ public void addSelection(int selectionIndex) { if (this.addBoxMenu[selectionIndex].substring(0, 3).equals("---")) { // if selected element starts with "--- " // means element is metric with different values - if (this.addBoxMenu[selectionIndex].substring(0, 4).equals( - "--- ")) { + if (this.addBoxMenu[selectionIndex].substring(0, 4).equals("--- ")) { int x = selectionIndex + 1; - while (x != this.addBoxMenu.length - && this.addBoxMenu[x].substring(0, 6).equals( - "----- ")) { + while (x != this.addBoxMenu.length && this.addBoxMenu[x].substring(0, 6).equals("----- ")) { this.addValueItemToList(this.addBoxMenu[x].substring(6)); x++; } @@ -534,21 +542,17 @@ public void addSelection(int selectionIndex) { // if selected element is single element starting with // "----- " // means it is a metric value without sub-elements - if (this.addBoxMenu[selectionIndex].substring(0, 6).equals( - "----- ")) { - this.addValueItemToList(this.addBoxMenu[selectionIndex] - .substring(6)); + if (this.addBoxMenu[selectionIndex].substring(0, 6).equals("----- ")) { + this.addValueItemToList(this.addBoxMenu[selectionIndex].substring(6)); } else { // if selected element starts with "---" // means it is a value of runtimes or batch statistics int x = selectionIndex - 1; - while (x > 0 - && (this.addBoxMenu[x].substring(0, 3) - .equals("---"))) { + while (x > 0 && (this.addBoxMenu[x].substring(0, 3).equals("---"))) { x--; } - this.addValueItemToList(this.addBoxMenu[x] + "." - + this.addBoxMenu[selectionIndex].substring(3)); + this.addValueItemToList( + this.addBoxMenu[x] + "." + this.addBoxMenu[selectionIndex].substring(3)); } } } @@ -560,58 +564,101 @@ public void addSelection(int selectionIndex) { if (this.addBoxMenu[selectionIndex].substring(0, 3).equals("---")) { // if selected element starts with "--- " // means element is metric with different values - if (this.addBoxMenu[selectionIndex].substring(0, 4).equals( - "--- ")) { + if (this.addBoxMenu[selectionIndex].substring(0, 4).equals("--- ")) { // check if distributions or nodevaluelists should be added boolean addDistribution; - if (this.addBoxMenu[selectionIndex].substring(0, 5).equals( - "--- D")) + if (this.addBoxMenu[selectionIndex].substring(0, 5).equals("--- D")) addDistribution = true; else addDistribution = false; int x = selectionIndex + 1; - while (x != this.addBoxMenu.length - && this.addBoxMenu[x].substring(0, 6).equals( - "----- ")) { + while (x != this.addBoxMenu.length && this.addBoxMenu[x].substring(0, 6).equals("----- ")) { if (addDistribution) - this.addDistributionItemToList(this.addBoxMenu[x] - .substring(6)); + this.addDistributionItemToList(this.addBoxMenu[x].substring(6)); else - this.addNodeValueListItemToList(this.addBoxMenu[x] - .substring(6)); + this.addNodeValueListItemToList(this.addBoxMenu[x].substring(6)); x++; } } else { // if selected element is single element starting with // "----- " // means it is a single value without sub-elements - if (this.addBoxMenu[selectionIndex].substring(0, 6).equals( - "----- ")) { + if (this.addBoxMenu[selectionIndex].substring(0, 6).equals("----- ")) { // check if a distribution or a nodevaluelist should be // added boolean addDistribution = true; for (int i = 1; selectionIndex - i >= 0; i++) { - if (this.addBoxMenu[selectionIndex - i].substring( - 0, 5).equals("--- N")) { + if (this.addBoxMenu[selectionIndex - i].substring(0, 5).equals("--- N")) { addDistribution = false; break; } - if (this.addBoxMenu[selectionIndex - i].substring( - 0, 5).equals("--- D")) { + if (this.addBoxMenu[selectionIndex - i].substring(0, 5).equals("--- D")) { addDistribution = true; break; } } if (addDistribution) - this.addDistributionItemToList(this.addBoxMenu[selectionIndex] - .substring(6)); + this.addDistributionItemToList(this.addBoxMenu[selectionIndex].substring(6)); else - this.addNodeValueListItemToList(this.addBoxMenu[selectionIndex] - .substring(6)); + this.addNodeValueListItemToList(this.addBoxMenu[selectionIndex].substring(6)); + } + } + } + } + // if its a label visualizer -> add label-legenditems + if (this.parent instanceof LabelVisualizer) { + // if selected element is a category + if (this.addBoxMenu[selectionIndex].charAt(0) != '-') { + // if selected element is "labels" category + // means it probably has different metrics with different values + // each + if (this.addBoxMenu[selectionIndex].equals("labels")) { + int x = selectionIndex + 1; + while (x != this.addBoxMenu.length && this.addBoxMenu[x].charAt(0) == '-') { + if (this.addBoxMenu[x].substring(0, 6).equals("----- ")) { + this.addLabelItemToList(this.addBoxMenu[x].substring(6)); + } + x++; + } + } else { + // if selected element is a category other than "labels" + int x = selectionIndex + 1; + while (x != this.addBoxMenu.length && this.addBoxMenu[x].charAt(0) == '-') { + this.addLabelItemToList( + this.addBoxMenu[selectionIndex] + "." + this.addBoxMenu[x].substring(3)); + x++; + } + } + } + // if selected element starts with "---" + if (this.addBoxMenu[selectionIndex].substring(0, 3).equals("---")) { + // if selected element starts with "--- " + // means element is labeler with different types + if (this.addBoxMenu[selectionIndex].substring(0, 4).equals("--- ")) { + int x = selectionIndex + 1; + while (x != this.addBoxMenu.length && this.addBoxMenu[x].substring(0, 6).equals("----- ")) { + this.addLabelItemToList(this.addBoxMenu[x].substring(6)); + x++; + } + } else { + // if selected element is single element starting with + // "----- " + // means it is a labeler type pair without sub-elements + if (this.addBoxMenu[selectionIndex].substring(0, 6).equals("----- ")) { + this.addLabelItemToList(this.addBoxMenu[selectionIndex].substring(6)); + } else { + // if selected element starts with "---" + // means it is a value of runtimes or batch statistics + int x = selectionIndex - 1; + while (x > 0 && (this.addBoxMenu[x].substring(0, 3).equals("---"))) { + x--; + } + this.addLabelItemToList( + this.addBoxMenu[x] + "." + this.addBoxMenu[selectionIndex].substring(3)); } } } @@ -621,6 +668,11 @@ public void addSelection(int selectionIndex) { /** updates the value of an item **/ public void updateItem(String name, double value) { + this.list.updateItem(name, "" + value); + } + + /** updates the value of an item **/ + public void updateItem(String name, String value) { this.list.updateItem(name, value); } @@ -652,11 +704,12 @@ public void toggleXAxis(LegendItem item) { /** toggles visiblity of a trace **/ public void toggleVisiblity(LegendItem item) { if (this.parent instanceof MetricVisualizer) - ((MetricVisualizer) this.parent).toggleTraceVisiblity(item - .getName()); + ((MetricVisualizer) this.parent).toggleTraceVisiblity(item.getName()); if (this.parent instanceof MultiScalarVisualizer) - ((MultiScalarVisualizer) this.parent).toggleTraceVisiblity(item - .getName()); + ((MultiScalarVisualizer) this.parent).toggleTraceVisiblity(item.getName()); + if (this.parent instanceof LabelVisualizer) { + ((LabelVisualizer) this.parent).toggleTraceVisibility(item.getName()); + } } /** toggles the display mode of a trace **/ @@ -664,8 +717,7 @@ public void toggleDisplayMode(LegendItem item) { if (this.parent instanceof MetricVisualizer) ((MetricVisualizer) this.parent).toggleDisplayMode(item.getName()); if (this.parent instanceof MultiScalarVisualizer) - ((MultiScalarVisualizer) this.parent).toggleDisplayMode(item - .getName()); + ((MultiScalarVisualizer) this.parent).toggleDisplayMode(item.getName()); } /** called from an item to get resorted while paused **/ @@ -697,8 +749,7 @@ public static String getToolTipText(String name) { String descr = Config.getPropertyDescription(splits[0], splits[1]); if (descr != null) { - tooltip = Legend.HTML_Begin + descr + Legend.HTML_NewLine - + Legend.HTML_NewLine + tooltip + Legend.HTML_End; + tooltip = Legend.HTML_Begin + descr + Legend.HTML_NewLine + Legend.HTML_NewLine + tooltip + Legend.HTML_End; } // return diff --git a/src/dna/visualization/components/visualizer/LegendItem.java b/src/dna/visualization/components/visualizer/LegendItem.java index 815869b4..3bf6fb10 100644 --- a/src/dna/visualization/components/visualizer/LegendItem.java +++ b/src/dna/visualization/components/visualizer/LegendItem.java @@ -19,6 +19,7 @@ import dna.visualization.MainDisplay; import dna.visualization.config.VisualizerListConfig.yAxisSelection; +import dna.visualization.config.components.LabelVisualizerConfig; import dna.visualization.config.components.MetricVisualizerConfig; import dna.visualization.config.components.MultiScalarVisualizerConfig; @@ -76,7 +77,7 @@ public LegendItem(LegendList parent, String name, Color color) { this.valueLabelSize = config.getLegendItemValueLabelSize(); this.valueFont = config.getLegendItemValueFont(); this.valueFontColor = config.getLegendItemValueFontColor(); - } else { + } else if (parent.parent.parent instanceof MultiScalarVisualizer) { MultiScalarVisualizerConfig config = ((MultiScalarVisualizer) parent.parent.parent).config; this.buttonPanelSize = config.getLegendItemButtonPanelSize(); this.buttonSize = config.getLegendItemButtonSize(); @@ -85,6 +86,15 @@ public LegendItem(LegendList parent, String name, Color color) { this.valueLabelSize = config.getLegendItemValueLabelSize(); this.valueFont = config.getLegendItemValueFont(); this.valueFontColor = config.getLegendItemValueFontColor(); + } else if (parent.parent.parent instanceof LabelVisualizer) { + LabelVisualizerConfig config = ((LabelVisualizer) parent.parent.parent).config; + this.buttonPanelSize = config.getLegendItemButtonPanelSize(); + this.buttonSize = config.getLegendItemButtonSize(); + this.size = config.getLegendItemSize(); + this.nameLabelSize = config.getLegendItemNameLabelSize(); + this.valueLabelSize = config.getLegendItemValueLabelSize(); + this.valueFont = config.getLegendItemValueFont(); + this.valueFontColor = config.getLegendItemValueFontColor(); } this.setPreferredSize(this.size); this.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); @@ -115,11 +125,9 @@ public LegendItem(LegendList parent, String name, Color color) { // remove button this.removeButton = new JButton("-"); this.removeButton.setFont(MainDisplay.config.getDefaultFont()); - this.removeButton.setForeground(MainDisplay.config - .getDefaultFontColor()); + this.removeButton.setForeground(MainDisplay.config.getDefaultFontColor()); this.removeButton.setPreferredSize(this.buttonSize); - this.removeButton - .setToolTipText("Removes this value from list and plot."); + this.removeButton.setToolTipText("Removes this value from list and plot."); this.removeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @@ -127,18 +135,16 @@ public void actionPerformed(ActionEvent event) { } }); this.removeButton.setMargin(new Insets(0, 0, 0, 0)); - this.removeButton.setFont(new Font(this.removeButton.getFont() - .getName(), this.removeButton.getFont().getStyle(), 17)); + this.removeButton + .setFont(new Font(this.removeButton.getFont().getName(), this.removeButton.getFont().getStyle(), 17)); // toggle y axis button this.toggleYAxisButton = new JButton("y1"); this.toggleYAxisButton.setFont(MainDisplay.config.getDefaultFont()); - this.toggleYAxisButton.setForeground(MainDisplay.config - .getDefaultFontColor()); + this.toggleYAxisButton.setForeground(MainDisplay.config.getDefaultFontColor()); this.toggleYAxisButton.setPreferredSize(this.buttonSize); this.toggleYAxisButton.setMargin(new Insets(0, 0, 0, 0)); - this.toggleYAxisButton - .setToolTipText("Currently plotted on left y-axis (y1). Click to change to right y-axis"); + this.toggleYAxisButton.setToolTipText("Currently plotted on left y-axis (y1). Click to change to right y-axis"); this.toggleYAxisButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @@ -158,8 +164,7 @@ public void actionPerformed(ActionEvent event) { // show/hide button this.showHideButton = new JButton("S"); this.showHideButton.setFont(MainDisplay.config.getDefaultFont()); - this.showHideButton.setForeground(MainDisplay.config - .getDefaultFontColor()); + this.showHideButton.setForeground(MainDisplay.config.getDefaultFontColor()); this.showHideButton.setPreferredSize(this.buttonSize); this.showHideButton.setMargin(new Insets(0, 0, 0, 0)); this.showHideButton.setToolTipText("Hides this value in the chart"); @@ -168,15 +173,12 @@ public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) { if (thisItem.showHideButton.getText().equals("H")) { thisItem.showHideButton.setText("S"); - thisItem.showHideButton.setForeground(MainDisplay.config - .getDefaultFontColor()); - thisItem.showHideButton - .setToolTipText("Hides this value in the chart"); + thisItem.showHideButton.setForeground(MainDisplay.config.getDefaultFontColor()); + thisItem.showHideButton.setToolTipText("Hides this value in the chart"); } else { thisItem.showHideButton.setText("H"); thisItem.showHideButton.setForeground(Color.RED); - thisItem.showHideButton - .setToolTipText("Shows this value in the chart"); + thisItem.showHideButton.setToolTipText("Shows this value in the chart"); } thisItem.parent.toggleVisiblity(thisItem); } @@ -185,12 +187,10 @@ public void actionPerformed(ActionEvent event) { // bar/linespoint button this.displayModeButton = new JButton("L"); this.displayModeButton.setFont(MainDisplay.config.getDefaultFont()); - this.displayModeButton.setForeground(MainDisplay.config - .getDefaultFontColor()); + this.displayModeButton.setForeground(MainDisplay.config.getDefaultFontColor()); this.displayModeButton.setPreferredSize(this.buttonSize); this.displayModeButton.setMargin(new Insets(0, 0, 0, 0)); - this.displayModeButton - .setToolTipText("Currently shown as linespoint. Click to change to bars."); + this.displayModeButton.setToolTipText("Currently shown as linespoint. Click to change to bars."); this.displayModeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { @@ -210,8 +210,7 @@ public void actionPerformed(ActionEvent event) { // button panel this.buttonPanel = new JPanel(); this.buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0)); - this.buttonPanel - .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); + this.buttonPanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); this.buttonPanel.setPreferredSize(this.buttonPanelSize); this.buttonPanel.add(this.removeButton); this.buttonPanel.add(this.showHideButton); @@ -259,8 +258,7 @@ public Color getColor() { public void setShowHideButton(boolean visible) { if (visible) { this.showHideButton.setText("S"); - this.showHideButton.setForeground(MainDisplay.config - .getDefaultFontColor()); + this.showHideButton.setForeground(MainDisplay.config.getDefaultFontColor()); this.showHideButton.setToolTipText("Hides this value in the chart"); } else { this.showHideButton.setText("H"); @@ -273,12 +271,10 @@ public void setShowHideButton(boolean visible) { public void setDisplayModeButton(boolean displayAsLinespoint) { if (displayAsLinespoint) { this.displayModeButton.setText("L"); - this.displayModeButton - .setToolTipText("Currently shown as linespoint. Click to change to bars."); + this.displayModeButton.setToolTipText("Currently shown as linespoint. Click to change to bars."); } else { this.displayModeButton.setText("B"); - this.displayModeButton - .setToolTipText("Currently shown as bars. Click to change to linespoint."); + this.displayModeButton.setToolTipText("Currently shown as bars. Click to change to linespoint."); } } diff --git a/src/dna/visualization/components/visualizer/LegendItemLabel.java b/src/dna/visualization/components/visualizer/LegendItemLabel.java new file mode 100644 index 00000000..0d7c7281 --- /dev/null +++ b/src/dna/visualization/components/visualizer/LegendItemLabel.java @@ -0,0 +1,31 @@ +package dna.visualization.components.visualizer; + +import java.awt.Color; + +/** + * A legenditem in the legendlist representing a labeler and type pair. + * + * @author Rwilmes + * + */ +@SuppressWarnings("serial") +public class LegendItemLabel extends LegendItem { + + // constructor + public LegendItemLabel(LegendList parent, String name, Color color) { + super(parent, name, color); + + this.nameLabel.setText(name); + this.valueLabel.setText("V=0.0"); + + // remove displaymode and y-axis toggle button + this.buttonPanel.remove(this.displayModeButton); + this.buttonPanel.remove(this.toggleYAxisButton); + } + + /** sets the value of an item **/ + public void setValue(String value) { + this.valueLabel.setText("V=" + value); + this.valueLabel.setToolTipText("V=" + value); + } +} diff --git a/src/dna/visualization/components/visualizer/LegendItemValue.java b/src/dna/visualization/components/visualizer/LegendItemValue.java index 34bf577f..51d51fac 100644 --- a/src/dna/visualization/components/visualizer/LegendItemValue.java +++ b/src/dna/visualization/components/visualizer/LegendItemValue.java @@ -19,7 +19,7 @@ public LegendItemValue(LegendList parent, String name, Color color) { } /** sets the value of an item **/ - public void setValue(double value) { + public void setValue(String value) { this.valueLabel.setText("V=" + value); this.valueLabel.setToolTipText("V=" + value); } diff --git a/src/dna/visualization/components/visualizer/LegendList.java b/src/dna/visualization/components/visualizer/LegendList.java index 2a2620d2..4b7e3f4b 100644 --- a/src/dna/visualization/components/visualizer/LegendList.java +++ b/src/dna/visualization/components/visualizer/LegendList.java @@ -70,13 +70,27 @@ public void removeItem(Component c) { } /** updates the value of an legend item contained in the list **/ - public void updateItem(String name, double value) { + public void updateItem(String name, String value) { for (Component c : this.getComponents()) { - if (c instanceof LegendItemValue) { - if (c.getName().equals(name)) { + if (c.getName().equals(name)) { + if (c instanceof LegendItemValue) { ((LegendItemValue) c).setValue(value); } + if (c instanceof LegendItemLabel) { + ((LegendItemLabel) c).setValue(value); + } + } + // if (c instanceof LegendItemValue) { + // if (c.getName().equals(name)) { + // ((LegendItemValue) c).setValue(value); + // } + // } + // if (c instanceof LegendItemLabel) { + // if (c.getName().equals(name)) { + // ((Legend)) + // } + // } } this.validate(); } diff --git a/src/dna/visualization/components/visualizer/MenuBar.java b/src/dna/visualization/components/visualizer/MenuBar.java index d4124afe..21148cc8 100644 --- a/src/dna/visualization/components/visualizer/MenuBar.java +++ b/src/dna/visualization/components/visualizer/MenuBar.java @@ -1,11 +1,5 @@ package dna.visualization.components.visualizer; -import info.monitorenter.gui.chart.rangepolicies.RangePolicyFixedViewport; -import info.monitorenter.gui.chart.rangepolicies.RangePolicyUnbounded; -import info.monitorenter.gui.chart.traces.Trace2DLtd; -import info.monitorenter.gui.chart.traces.Trace2DSimple; -import info.monitorenter.util.Range; - import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; @@ -34,6 +28,11 @@ import dna.visualization.MainDisplay; import dna.visualization.config.components.MenuBarConfig; +import info.monitorenter.gui.chart.rangepolicies.RangePolicyFixedViewport; +import info.monitorenter.gui.chart.rangepolicies.RangePolicyUnbounded; +import info.monitorenter.gui.chart.traces.Trace2DLtd; +import info.monitorenter.gui.chart.traces.Trace2DSimple; +import info.monitorenter.util.Range; /** * The menubar is a bar containing several options for a visualizer, for example @@ -52,16 +51,12 @@ public class MenuBar extends JPanel implements ChangeListener { private Color coordsFontColor = Color.BLACK; // sizes - public static final Dimension menuBarCoordsPanelSize = new Dimension(145, - 45); - public static final Dimension menuBarXOptionsPanelSize = new Dimension(65, - 45); - public static final Dimension menuBarYOptionsPanelSize = new Dimension(65, - 45); - public static final Dimension menuBarYRightOptionsPanelSize = new Dimension( - 65, 45); - public static final Dimension menuBarIntervalPanelSize = new Dimension(210, - 45); + public static final Dimension menuBarCoordsPanelSize = new Dimension(145, 45); + public static final Dimension menuBarXOptionsPanelSize = new Dimension(65, 45); + public static final Dimension menuBarYOptionsPanelSize = new Dimension(65, 45); + public static final Dimension menuBarYRightOptionsPanelSize = new Dimension(65, 45); + public static final Dimension menuBarIntervalPanelSize = new Dimension(225, 45); + public static final Dimension menuBarMultiScalarIntervalPanelSize = new Dimension(210, 45); // creates the default menu with all panels public MenuBar(Visualizer parent, Dimension d) { @@ -70,17 +65,16 @@ public MenuBar(Visualizer parent, Dimension d) { // creates the menu with a given config public MenuBar(Visualizer parent, MenuBarConfig config) { - this(parent, config.getSize(), config.isAddCoordsPanel(), config - .isAddIntervalPanel(), config.isAddXOptionsPanel(), config - .isAddYOptionsPanel()); + this(parent, config.getSize(), config.isAddCoordsPanel(), config.isAddIntervalPanel(), + config.isAddXOptionsPanel(), config.isAddYOptionsPanel()); } // constructor - public MenuBar(Visualizer parent, Dimension size, boolean addCoordsPanel, - boolean addIntervalPanel, boolean addXOptionsPanel, - boolean addYOptionsPanel) { + public MenuBar(Visualizer parent, Dimension size, boolean addCoordsPanel, boolean addIntervalPanel, + boolean addXOptionsPanel, boolean addYOptionsPanel) { this.parent = parent; this.thisMenuBar = this; + this.setLayout(new GridBagLayout()); this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); @@ -94,7 +88,10 @@ public MenuBar(Visualizer parent, Dimension size, boolean addCoordsPanel, // add interval panel if (addIntervalPanel) { - this.addIntervalPanel(menuBarIntervalPanelSize); + Dimension tempSize = menuBarIntervalPanelSize; + if (parent instanceof MultiScalarVisualizer) + tempSize = menuBarMultiScalarIntervalPanelSize; + this.addIntervalPanel(tempSize); } // add x axis options panel @@ -110,7 +107,9 @@ public MenuBar(Visualizer parent, Dimension size, boolean addCoordsPanel, // menu bar elements private JPanel coordsPanel; + private JLabel xCoordsLabel; private JLabel xCoordsValue; + private JLabel yCoordsLabel; private JLabel yCoordsValue; private JPanel xOptionsPanel; private JPanel yLeftOptionsPanel; @@ -122,6 +121,8 @@ public MenuBar(Visualizer parent, Dimension size, boolean addCoordsPanel, private JScrollBar x1IntervalScrollBar; private JCheckBox x1ShowAllCheckBox; private JSlider x1SizeSlider; + private JCheckBox x1ConnectedCheckBox; + // for x2 private JScrollBar x2IntervalScrollBar; private JCheckBox x2ShowAllCheckBox; @@ -142,8 +143,8 @@ private void addIntervalPanel(Dimension size) { /** upper panel **/ final JPanel upperPanel = new JPanel(); - upperPanel.setPreferredSize(new Dimension((int) (size.getWidth() - 5), - (int) Math.floor((size.getHeight() - 5) / 2))); + upperPanel.setPreferredSize( + new Dimension((int) (size.getWidth() - 5), (int) Math.floor((size.getHeight() - 5) / 2))); upperPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); // x1 label @@ -172,8 +173,7 @@ public void actionPerformed(ActionEvent event) { double minTemp = 0; double maxTemp = 1; parent.setFixedViewport(true); - parent.xAxis1 - .setRangePolicy(new RangePolicyFixedViewport()); + parent.xAxis1.setRangePolicy(new RangePolicyFixedViewport()); if (parent instanceof MultiScalarVisualizer) { for (Object t : parent.xAxis1.getTraces()) { if (t instanceof Trace2DSimple) { @@ -198,18 +198,17 @@ public void actionPerformed(ActionEvent event) { } } double lowP = 1.0 * x1IntervalScrollBar.getValue() / 100; - double highP = 1.0 * (x1IntervalScrollBar.getValue() + x1IntervalScrollBar - .getModel().getExtent()) / 100; - - int minTimestampNew = (int) Math.floor(minTemp) - + (int) Math.floor(lowP * (maxTemp - minTemp)); - int maxTimestampNew = (int) Math.floor(minTemp) - + (int) Math.floor(highP * (maxTemp - minTemp)); - parent.xAxis1.setRange(new Range(minTimestampNew, - maxTimestampNew)); + double highP = 1.0 * (x1IntervalScrollBar.getValue() + x1IntervalScrollBar.getModel().getExtent()) + / 100; + + int minTimestampNew = (int) Math.floor(minTemp) + (int) Math.floor(lowP * (maxTemp - minTemp)); + int maxTimestampNew = (int) Math.floor(minTemp) + (int) Math.floor(highP * (maxTemp - minTemp)); + parent.xAxis1.setRange(new Range(minTimestampNew, maxTimestampNew)); x1IntervalScrollBar.setEnabled(true); x1SizeSlider.setEnabled(true); } + + parent.broadcastX1IntervalEnabled(x1ShowAllCheckBox.isSelected()); } }); @@ -223,59 +222,78 @@ public void actionPerformed(ActionEvent event) { this.x1SizeSlider.setToolTipText("Set size of shown interval"); // interval scroll bar - this.x1IntervalScrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 50, - 0, 100); + this.x1IntervalScrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 50, 0, 100); this.x1IntervalScrollBar.setPreferredSize(new Dimension(100, 20)); this.x1IntervalScrollBar.setEnabled(false); - this.x1IntervalScrollBar - .addAdjustmentListener(new AdjustmentListener() { - @Override - public void adjustmentValueChanged(AdjustmentEvent e) { - if (parent.chart.getAxisX().getRangePolicy() instanceof RangePolicyFixedViewport) { - double lowP = 1.0 * x1IntervalScrollBar.getValue() / 100; - double highP = 1.0 * (x1IntervalScrollBar - .getValue() + x1IntervalScrollBar - .getModel().getExtent()) / 100; + this.x1IntervalScrollBar.addAdjustmentListener(new AdjustmentListener() { + @Override + public void adjustmentValueChanged(AdjustmentEvent e) { + if (parent.chart.getAxisX().getRangePolicy() instanceof RangePolicyFixedViewport) { + double lowP = 1.0 * x1IntervalScrollBar.getValue() / 100; + double highP = 1.0 * (x1IntervalScrollBar.getValue() + x1IntervalScrollBar.getModel().getExtent()) + / 100; - double minTemp = 0; - double maxTemp = 1; + double minTemp = 0; + double maxTemp = 1; - // get range of plotted data - for (Object t : parent.xAxis1.getTraces()) { - if (t instanceof Trace2DSimple) { - double minX = ((Trace2DSimple) t).getMinX(); - double maxX = ((Trace2DSimple) t).getMaxX(); - if (minTemp > minX) - minTemp = minX; - if (maxTemp < maxX) - maxTemp = maxX; - } else if (t instanceof Trace2DLtd) { - minTemp = ((Trace2DLtd) t).getMinX(); - maxTemp = ((Trace2DLtd) t).getMaxX(); - } - } - int minTimestampNew = (int) Math.floor(minTemp) - + (int) Math.floor(lowP - * (maxTemp - minTemp)); - int maxTimestampNew = (int) Math.floor(minTemp) - + (int) Math.floor(highP - * (maxTemp - minTemp)); - parent.setMinShownTimestamp((long) minTimestampNew); - parent.setMaxShownTimestamp((long) maxTimestampNew); - parent.xAxis1.setRange(new Range(minTimestampNew, - maxTimestampNew)); - // update x ticks - parent.updateX1Ticks(); + // get range of plotted data + for (Object t : parent.xAxis1.getTraces()) { + if (t instanceof Trace2DSimple) { + double minX = ((Trace2DSimple) t).getMinX(); + double maxX = ((Trace2DSimple) t).getMaxX(); + if (minTemp > minX) + minTemp = minX; + if (maxTemp < maxX) + maxTemp = maxX; + } else if (t instanceof Trace2DLtd) { + minTemp = ((Trace2DLtd) t).getMinX(); + maxTemp = ((Trace2DLtd) t).getMaxX(); } } - }); + if (parent instanceof LabelVisualizer) { + minTemp = ((LabelVisualizer) parent).getMinTimestamp(); + maxTemp = ((LabelVisualizer) parent).getMaxTimestamp(); + } + + int minTimestampNew = (int) Math.floor(minTemp) + (int) Math.floor(lowP * (maxTemp - minTemp)); + int maxTimestampNew = (int) Math.floor(minTemp) + (int) Math.floor(highP * (maxTemp - minTemp)); + parent.setMinShownTimestamp((long) minTimestampNew); + parent.setMaxShownTimestamp((long) maxTimestampNew); + parent.xAxis1.setRange(new Range(minTimestampNew, maxTimestampNew)); + // update x ticks + parent.updateX1Ticks(); + + parent.broadcastX1IntervalSizeSliderChange(x1SizeSlider.getValue()); + parent.broadcastX1IntervalScrollBarChange(x1IntervalScrollBar.getValue()); + } + } + + }); + + // x1 connected checkbox + this.x1ConnectedCheckBox = new JCheckBox("", this.parent.isX1Connected()); + this.x1ConnectedCheckBox.setToolTipText("Check to connect x1 axis with other components"); + this.x1ConnectedCheckBox.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent event) { + // check if checkbox is selected + if (x1ConnectedCheckBox.isSelected()) { + parent.setX1Connected(true); + + } else { + parent.setX1Connected(false); + } + } + }); // add components upperPanel.add(x1Label); upperPanel.add(this.x1ShowAllCheckBox); upperPanel.add(this.x1SizeSlider); upperPanel.add(this.x1IntervalScrollBar); + if (!(parent instanceof MultiScalarVisualizer)) + upperPanel.add(this.x1ConnectedCheckBox); /** add uppper panel **/ c.gridx = 0; @@ -287,9 +305,8 @@ public void adjustmentValueChanged(AdjustmentEvent e) { if (parent instanceof MultiScalarVisualizer) { // lower panel final JPanel lowerPanel = new JPanel(); - lowerPanel.setPreferredSize(new Dimension( - (int) (size.getWidth() - 5), (int) Math.floor((size - .getHeight() - 5) / 2))); + lowerPanel.setPreferredSize( + new Dimension((int) (size.getWidth() - 5), (int) Math.floor((size.getHeight() - 5) / 2))); lowerPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); // x1 label @@ -309,27 +326,24 @@ public void actionPerformed(ActionEvent event) { // if selected: disable bar and slider and set x2 to // unbounded policy if (parent instanceof MultiScalarVisualizer) - ((MultiScalarVisualizer) parent).xAxis2 - .setRangePolicy(new RangePolicyUnbounded()); + ((MultiScalarVisualizer) parent).xAxis2.setRangePolicy(new RangePolicyUnbounded()); x2IntervalScrollBar.setEnabled(false); x2SizeSlider.setEnabled(false); } else { // if not selected: enable bar and slider and set x2 to // fixedviewport policy if (parent instanceof MultiScalarVisualizer) { - ((MultiScalarVisualizer) parent).xAxis2 - .setRangePolicy(new RangePolicyFixedViewport()); + ((MultiScalarVisualizer) parent).xAxis2.setRangePolicy(new RangePolicyFixedViewport()); double lowP = 1.0 * x2IntervalScrollBar.getValue() / 100; - double highP = 1.0 * (x2IntervalScrollBar - .getValue() + x2IntervalScrollBar - .getModel().getExtent()) / 100; + double highP = 1.0 + * (x2IntervalScrollBar.getValue() + x2IntervalScrollBar.getModel().getExtent()) + / 100; double minTemp = 0; double maxTemp = 10; // get range of plotted data - for (Object t : ((MultiScalarVisualizer) parent).xAxis2 - .getTraces()) { + for (Object t : ((MultiScalarVisualizer) parent).xAxis2.getTraces()) { if (t instanceof Trace2DSimple) { double minX = ((Trace2DSimple) t).getMinX(); double maxX = ((Trace2DSimple) t).getMaxX(); @@ -341,15 +355,12 @@ public void actionPerformed(ActionEvent event) { } int minTimestampNew = (int) Math.floor(minTemp) - + (int) Math.floor(lowP - * (maxTemp - minTemp)); + + (int) Math.floor(lowP * (maxTemp - minTemp)); int maxTimestampNew = (int) Math.floor(minTemp) - + (int) Math.floor(highP - * (maxTemp - minTemp)); + + (int) Math.floor(highP * (maxTemp - minTemp)); ((MultiScalarVisualizer) parent).xAxis2 - .setRange(new Range(minTimestampNew, - maxTimestampNew)); + .setRange(new Range(minTimestampNew, maxTimestampNew)); // update x2 ticks ((MultiScalarVisualizer) parent).updateX2Ticks(); } @@ -369,57 +380,46 @@ public void actionPerformed(ActionEvent event) { this.x2SizeSlider.setToolTipText("Set size of shown interval"); // interval scroll bar - this.x2IntervalScrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, - 50, 0, 100); + this.x2IntervalScrollBar = new JScrollBar(JScrollBar.HORIZONTAL, 0, 50, 0, 100); this.x2IntervalScrollBar.setPreferredSize(new Dimension(100, 20)); this.x2IntervalScrollBar.setEnabled(false); - this.x2IntervalScrollBar - .addAdjustmentListener(new AdjustmentListener() { - @Override - public void adjustmentValueChanged(AdjustmentEvent e) { - if (parent instanceof MultiScalarVisualizer) { - if (((MultiScalarVisualizer) parent).xAxis2 - .getRangePolicy() instanceof RangePolicyFixedViewport) { - double lowP = 1.0 * x2IntervalScrollBar - .getValue() / 100; - double highP = 1.0 * (x2IntervalScrollBar - .getValue() + x2IntervalScrollBar - .getModel().getExtent()) / 100; - - double minTemp = 0; - double maxTemp = 10; - - // get range of plotted data - for (Object t : ((MultiScalarVisualizer) parent).xAxis2 - .getTraces()) { - if (t instanceof Trace2DSimple) { - double minX = ((Trace2DSimple) t) - .getMinX(); - double maxX = ((Trace2DSimple) t) - .getMaxX(); - if (minTemp > minX) - minTemp = minX; - if (maxTemp < maxX) - maxTemp = maxX; - } - } - - int minTimestampNew = (int) Math.floor(lowP - * (maxTemp - minTemp)); - int maxTimestampNew = (int) Math - .floor(highP * (maxTemp - minTemp)); - - ((MultiScalarVisualizer) parent).xAxis2 - .setRange(new Range( - minTimestampNew, - maxTimestampNew)); - // update x2 ticks - ((MultiScalarVisualizer) parent) - .updateX2Ticks(); + this.x2IntervalScrollBar.addAdjustmentListener(new AdjustmentListener() { + @Override + public void adjustmentValueChanged(AdjustmentEvent e) { + if (parent instanceof MultiScalarVisualizer) { + if (((MultiScalarVisualizer) parent).xAxis2 + .getRangePolicy() instanceof RangePolicyFixedViewport) { + double lowP = 1.0 * x2IntervalScrollBar.getValue() / 100; + double highP = 1.0 + * (x2IntervalScrollBar.getValue() + x2IntervalScrollBar.getModel().getExtent()) + / 100; + + double minTemp = 0; + double maxTemp = 10; + + // get range of plotted data + for (Object t : ((MultiScalarVisualizer) parent).xAxis2.getTraces()) { + if (t instanceof Trace2DSimple) { + double minX = ((Trace2DSimple) t).getMinX(); + double maxX = ((Trace2DSimple) t).getMaxX(); + if (minTemp > minX) + minTemp = minX; + if (maxTemp < maxX) + maxTemp = maxX; } } + + int minTimestampNew = (int) Math.floor(lowP * (maxTemp - minTemp)); + int maxTimestampNew = (int) Math.floor(highP * (maxTemp - minTemp)); + + ((MultiScalarVisualizer) parent).xAxis2 + .setRange(new Range(minTimestampNew, maxTimestampNew)); + // update x2 ticks + ((MultiScalarVisualizer) parent).updateX2Ticks(); } - }); + } + } + }); // add components lowerPanel.add(x2Label); @@ -433,8 +433,7 @@ public void adjustmentValueChanged(AdjustmentEvent e) { } else { // if parent not multiscalarvisualizer -> add dummy panel JPanel dummyPanel = new JPanel(); - dummyPanel.setPreferredSize(new Dimension(size.width - 5, - (int) Math.floor((size.height - 5) / 2))); + dummyPanel.setPreferredSize(new Dimension(size.width - 5, (int) Math.floor((size.height - 5) / 2))); /** add dummy panel **/ c.gridy = 1; @@ -462,59 +461,61 @@ private void addYOptionsPanel(Dimension size) { final JButton toggleGridYLeftButton = new JButton("y1"); toggleGridYLeftButton.setFont(MainDisplay.config.getDefaultFont()); toggleGridYLeftButton.setForeground(Color.GRAY); - toggleGridYLeftButton.setPreferredSize(new Dimension(size.width - 5, - (int) Math.floor((size.getHeight() - 5) / 2))); + toggleGridYLeftButton + .setPreferredSize(new Dimension(size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2))); toggleGridYLeftButton.setMargin(new Insets(0, 0, 0, 0)); toggleGridYLeftButton.setToolTipText("Show grid of left y-axis (y1)."); toggleGridYLeftButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (toggleGridYLeftButton.getForeground().equals(Color.GRAY)) { - toggleGridYLeftButton.setForeground(MainDisplay.config - .getDefaultFontColor()); - toggleGridYLeftButton - .setToolTipText("Hide grid of left y-axis (y1)."); + toggleGridYLeftButton.setForeground(MainDisplay.config.getDefaultFontColor()); + toggleGridYLeftButton.setToolTipText("Hide grid of left y-axis (y1)."); } else { toggleGridYLeftButton.setForeground(Color.GRAY); - toggleGridYLeftButton - .setToolTipText("Show grid of left y-axis (y1)."); + toggleGridYLeftButton.setToolTipText("Show grid of left y-axis (y1)."); } parent.toggleY1Grid(); } }); yLeftOptionsPanelConstraints.gridx = 0; yLeftOptionsPanelConstraints.gridy = 0; - this.yLeftOptionsPanel.add(toggleGridYLeftButton, - yLeftOptionsPanelConstraints); + this.yLeftOptionsPanel.add(toggleGridYLeftButton, yLeftOptionsPanelConstraints); - // toggle right y axis grid button - final JButton toggleGridYRightButton = new JButton("y2"); - toggleGridYRightButton.setFont(MainDisplay.config.getDefaultFont()); - toggleGridYRightButton.setForeground(Color.GRAY); - toggleGridYRightButton.setPreferredSize(new Dimension(new Dimension( - size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); - toggleGridYRightButton.setMargin(new Insets(0, 0, 0, 0)); - toggleGridYRightButton - .setToolTipText("Show grid of right y-axis (y2)."); - toggleGridYRightButton.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent event) { - if (toggleGridYRightButton.getForeground().equals(Color.GRAY)) { - toggleGridYRightButton.setForeground(MainDisplay.config - .getDefaultFontColor()); - toggleGridYRightButton - .setToolTipText("Hide grid of right y-axis (y2)."); - } else { - toggleGridYRightButton.setForeground(Color.GRAY); - toggleGridYRightButton - .setToolTipText("Show grid of right y-axis (y2)."); + if (this.parent instanceof LabelVisualizer) { + // add dummy panel + JPanel dummyP = new JPanel(); + dummyP.setPreferredSize( + new Dimension(new Dimension(size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); + yLeftOptionsPanelConstraints.gridx = 0; + yLeftOptionsPanelConstraints.gridy = 1; + this.yLeftOptionsPanel.add(dummyP, yLeftOptionsPanelConstraints); + } else { + // toggle right y axis grid button + final JButton toggleGridYRightButton = new JButton("y2"); + toggleGridYRightButton.setFont(MainDisplay.config.getDefaultFont()); + toggleGridYRightButton.setForeground(Color.GRAY); + toggleGridYRightButton.setPreferredSize( + new Dimension(new Dimension(size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); + toggleGridYRightButton.setMargin(new Insets(0, 0, 0, 0)); + toggleGridYRightButton.setToolTipText("Show grid of right y-axis (y2)."); + toggleGridYRightButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent event) { + if (toggleGridYRightButton.getForeground().equals(Color.GRAY)) { + toggleGridYRightButton.setForeground(MainDisplay.config.getDefaultFontColor()); + toggleGridYRightButton.setToolTipText("Hide grid of right y-axis (y2)."); + } else { + toggleGridYRightButton.setForeground(Color.GRAY); + toggleGridYRightButton.setToolTipText("Show grid of right y-axis (y2)."); + } + parent.toggleY2Grid(); } - parent.toggleY2Grid(); - } - }); - yLeftOptionsPanelConstraints.gridy = 1; - this.yLeftOptionsPanel.add(toggleGridYRightButton, - yLeftOptionsPanelConstraints); + }); + yLeftOptionsPanelConstraints.gridy = 1; + + this.yLeftOptionsPanel.add(toggleGridYRightButton, yLeftOptionsPanelConstraints); + } // add to menu bar this.add(this.yLeftOptionsPanel); @@ -537,43 +538,37 @@ private void addYRightOptionsPanel(Dimension size) { final JButton toggleGridYRightButton = new JButton("y2"); toggleGridYRightButton.setFont(MainDisplay.config.getDefaultFont()); toggleGridYRightButton.setForeground(Color.GRAY); - toggleGridYRightButton.setPreferredSize(new Dimension(new Dimension( - size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); + toggleGridYRightButton.setPreferredSize( + new Dimension(new Dimension(size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); toggleGridYRightButton.setMargin(new Insets(0, 0, 0, 0)); - toggleGridYRightButton - .setToolTipText("Show grid of right y-axis (y2)."); + toggleGridYRightButton.setToolTipText("Show grid of right y-axis (y2)."); toggleGridYRightButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (toggleGridYRightButton.getForeground().equals(Color.GRAY)) { - toggleGridYRightButton.setForeground(MainDisplay.config - .getDefaultFontColor()); - toggleGridYRightButton - .setToolTipText("Hide grid of right y-axis (y2)."); + toggleGridYRightButton.setForeground(MainDisplay.config.getDefaultFontColor()); + toggleGridYRightButton.setToolTipText("Hide grid of right y-axis (y2)."); } else { toggleGridYRightButton.setForeground(Color.GRAY); - toggleGridYRightButton - .setToolTipText("Show grid of right y-axis (y2)."); + toggleGridYRightButton.setToolTipText("Show grid of right y-axis (y2)."); } parent.toggleY2Grid(); } }); yRightOptionsPanelConstraints.gridx = 0; yRightOptionsPanelConstraints.gridy = 0; - this.yRightOptionsPanel.add(toggleGridYRightButton, - yRightOptionsPanelConstraints); + this.yRightOptionsPanel.add(toggleGridYRightButton, yRightOptionsPanelConstraints); // toggle right y axis log button final JButton toggleLogYRightButton = new JButton("+log y1"); toggleLogYRightButton.setFont(MainDisplay.config.getDefaultFont()); toggleLogYRightButton.setForeground(Color.GRAY); - toggleLogYRightButton.setPreferredSize(new Dimension(new Dimension( - size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); + toggleLogYRightButton.setPreferredSize( + new Dimension(new Dimension(size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); toggleLogYRightButton.setMargin(new Insets(0, 0, 0, 0)); yRightOptionsPanelConstraints.gridx = 0; yRightOptionsPanelConstraints.gridy = 1; - this.yRightOptionsPanel.add(toggleLogYRightButton, - yRightOptionsPanelConstraints); + this.yRightOptionsPanel.add(toggleLogYRightButton, yRightOptionsPanelConstraints); // add to menu bar this.add(this.yRightOptionsPanel); @@ -596,16 +591,15 @@ private void addXOptionsPanel(Dimension size) { final JButton toggleGridX1Button = new JButton("x1"); toggleGridX1Button.setFont(MainDisplay.config.getDefaultFont()); toggleGridX1Button.setForeground(Color.GRAY); - toggleGridX1Button.setPreferredSize(new Dimension(new Dimension( - size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); + toggleGridX1Button.setPreferredSize( + new Dimension(new Dimension(size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); toggleGridX1Button.setMargin(new Insets(0, 0, 0, 0)); toggleGridX1Button.setToolTipText("Show grid of x1."); toggleGridX1Button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (toggleGridX1Button.getForeground().equals(Color.GRAY)) { - toggleGridX1Button.setForeground(MainDisplay.config - .getDefaultFontColor()); + toggleGridX1Button.setForeground(MainDisplay.config.getDefaultFontColor()); toggleGridX1Button.setToolTipText("Hide grid of x1."); } else { toggleGridX1Button.setForeground(Color.GRAY); @@ -616,25 +610,22 @@ public void actionPerformed(ActionEvent event) { }); xAxisOptionsPanelConstraints.gridx = 0; xAxisOptionsPanelConstraints.gridy = 0; - this.xOptionsPanel - .add(toggleGridX1Button, xAxisOptionsPanelConstraints); + this.xOptionsPanel.add(toggleGridX1Button, xAxisOptionsPanelConstraints); // if parent is multiscalarvisualizer -> add grid button for x2 if (parent instanceof MultiScalarVisualizer) { final JButton toggleGridX2Button = new JButton("x2"); toggleGridX2Button.setFont(MainDisplay.config.getDefaultFont()); toggleGridX2Button.setForeground(Color.GRAY); - toggleGridX2Button.setPreferredSize(new Dimension(new Dimension( - size.width - 5, - (int) Math.floor((size.getHeight() - 5) / 2)))); + toggleGridX2Button.setPreferredSize( + new Dimension(new Dimension(size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); toggleGridX2Button.setMargin(new Insets(0, 0, 0, 0)); toggleGridX2Button.setToolTipText("Show grid of x2."); toggleGridX2Button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (toggleGridX2Button.getForeground().equals(Color.GRAY)) { - toggleGridX2Button.setForeground(MainDisplay.config - .getDefaultFontColor()); + toggleGridX2Button.setForeground(MainDisplay.config.getDefaultFontColor()); toggleGridX2Button.setToolTipText("Hide grid of x2."); } else { toggleGridX2Button.setForeground(Color.GRAY); @@ -645,13 +636,12 @@ public void actionPerformed(ActionEvent event) { }); xAxisOptionsPanelConstraints.gridx = 0; xAxisOptionsPanelConstraints.gridy = 1; - this.xOptionsPanel.add(toggleGridX2Button, - xAxisOptionsPanelConstraints); + this.xOptionsPanel.add(toggleGridX2Button, xAxisOptionsPanelConstraints); } else { // else add dummy panel JPanel dummyP = new JPanel(); - dummyP.setPreferredSize(new Dimension(new Dimension(size.width - 5, - (int) Math.floor((size.getHeight() - 5) / 2)))); + dummyP.setPreferredSize( + new Dimension(new Dimension(size.width - 5, (int) Math.floor((size.getHeight() - 5) / 2)))); xAxisOptionsPanelConstraints.gridx = 0; xAxisOptionsPanelConstraints.gridy = 1; this.xOptionsPanel.add(dummyP, xAxisOptionsPanelConstraints); @@ -678,18 +668,17 @@ private void addCoordsPanel(Dimension size) { coordsPanelConstraints.gridy = 0; // x coords label - JLabel xCoordsLabel = new JLabel("x:"); + xCoordsLabel = new JLabel("x:"); xCoordsLabel.setFont(this.coordsFont); xCoordsLabel.setForeground(this.coordsFontColor); xCoordsLabel.setPreferredSize(new Dimension(10, 20)); this.coordsPanel.add(xCoordsLabel, coordsPanelConstraints); // x coords value this.xCoordsValue = new JLabel(); - if (MainDisplay.config.getMetricVisualizerConfigs()[0].getxAxisType() - .equals("date") && (this.parent instanceof MetricVisualizer)) { + if ((this.parent instanceof MetricVisualizer) + && MainDisplay.config.getMetricVisualizerConfigs()[0].getxAxisType().equals("date")) { SimpleDateFormat tempDateFormat = new SimpleDateFormat( - MainDisplay.config.getMetricVisualizerConfigs()[0] - .getxAxisFormat()); + MainDisplay.config.getMetricVisualizerConfigs()[0].getxAxisFormat()); this.xCoordsValue.setText(tempDateFormat.format(new Date(0))); } else { this.xCoordsValue.setText("0"); @@ -702,7 +691,7 @@ private void addCoordsPanel(Dimension size) { this.coordsPanel.add(this.xCoordsValue, coordsPanelConstraints); // y coords label - JLabel yCoordsLabel = new JLabel("y:"); + yCoordsLabel = new JLabel("y:"); yCoordsLabel.setFont(this.coordsFont); yCoordsLabel.setForeground(this.coordsFontColor); yCoordsLabel.setPreferredSize(new Dimension(10, 20)); @@ -742,19 +731,31 @@ private void addDummyPanel(Dimension size) { * @param y * y-value */ - public void updateCoordsPanel(int x, double y) { + public void updateCoordsPanel(double x, double y) { if (this.coordsPanel != null) { - if (MainDisplay.config.getMetricVisualizerConfigs()[0] - .getxAxisType().equals("date") - && (this.parent instanceof MetricVisualizer)) { - SimpleDateFormat tempDateFormat = new SimpleDateFormat( - MainDisplay.config.getMetricVisualizerConfigs()[0] - .getxAxisFormat()); - this.xCoordsValue.setText(tempDateFormat.format(new Date(x))); + if (this.parent instanceof LabelVisualizer) { + if (MainDisplay.config.getLabelVisualizerConfigs()[0].getxAxisType().equals("date")) { + SimpleDateFormat tempDateFormat = new SimpleDateFormat( + MainDisplay.config.getLabelVisualizerConfigs()[0].getxAxisFormat()); + this.xCoordsValue.setText(tempDateFormat.format(new Date((long) Math.floor(x)))); + } else { + this.xCoordsValue.setText("" + x); + } + + LabelVisualizer labelVisualizer = (LabelVisualizer) this.parent; + String yValueString = labelVisualizer.getValue(x, y); + this.yCoordsValue.setText("" + yValueString); } else { - this.xCoordsValue.setText("" + x); + if ((this.parent instanceof MetricVisualizer) + && MainDisplay.config.getMetricVisualizerConfigs()[0].getxAxisType().equals("date")) { + SimpleDateFormat tempDateFormat = new SimpleDateFormat( + MainDisplay.config.getMetricVisualizerConfigs()[0].getxAxisFormat()); + this.xCoordsValue.setText(tempDateFormat.format(new Date((long) Math.floor(x)))); + } else { + this.xCoordsValue.setText("" + x); + } + this.yCoordsValue.setText("" + y); } - this.yCoordsValue.setText("" + y); } } @@ -778,13 +779,18 @@ public void stateChanged(ChangeEvent e) { source = (JSlider) e.getSource(); intervalScrollBar = this.x1IntervalScrollBar; // check if event is coming from x2SizeSlider - if (e.getSource().equals(this.x2SizeSlider)) + if (e.getSource().equals(this.x2SizeSlider)) { intervalScrollBar = this.x2IntervalScrollBar; + } else { + // if its x1 and parent is not multiscalar vis --> broadcast new + // value + if (!(this.parent instanceof MultiScalarVisualizer)) + this.parent.broadcastX1IntervalSizeSliderChange(source.getValue()); + } // check if slider is set on the right end - if (intervalScrollBar.getValue() - + intervalScrollBar.getModel().getExtent() == intervalScrollBar - .getMaximum()) { + if (intervalScrollBar.getValue() + intervalScrollBar.getModel().getExtent() == intervalScrollBar + .getMaximum()) { int oldValue = intervalScrollBar.getValue(); int oldExtent = intervalScrollBar.getModel().getExtent(); @@ -794,11 +800,10 @@ public void stateChanged(ChangeEvent e) { intervalScrollBar.getModel().setExtent(source.getValue()); // if slider is not set on right end anymore, adjust value - if (intervalScrollBar.getValue() - + intervalScrollBar.getModel().getExtent() != intervalScrollBar - .getMaximum()) { - intervalScrollBar.setValue(intervalScrollBar.getMaximum() - - intervalScrollBar.getModel().getExtent()); + if (intervalScrollBar.getValue() + intervalScrollBar.getModel().getExtent() != intervalScrollBar + .getMaximum()) { + intervalScrollBar + .setValue(intervalScrollBar.getMaximum() - intervalScrollBar.getModel().getExtent()); } // if slider is in between, just resize it } else { @@ -815,4 +820,39 @@ public JScrollBar getIntervalSlider() { return this.x1IntervalScrollBar; } + /** Sets the x-coords label text. **/ + public void setXCoordsLabelText(String text) { + this.xCoordsLabel.setText(text); + } + + /** Sets the y-coords label text. **/ + public void setYCoordsLabelText(String text) { + this.yCoordsLabel.setText(text); + } + + /** Sets the x1 interval size slider to a value. **/ + public void setX1IntervalSizeSlider(int value) { + if (this.x1SizeSlider != null && this.x1SizeSlider.isEnabled()) + this.x1SizeSlider.setValue(value); + } + + /** Set x1 interval scroll bar. **/ + public void setX1IntervalScrollBar(int value) { + if (this.x1IntervalScrollBar != null & this.x1IntervalScrollBar.isEnabled()) + this.x1IntervalScrollBar.setValue(value); + } + + /** Set x1 interval enabled. **/ + public void setX1IntervalEnabled(boolean enabled) { + if (this.x1ShowAllCheckBox != null) { + if (this.x1ShowAllCheckBox.isSelected()) { + if (!enabled) + this.x1ShowAllCheckBox.doClick(); + } else { + if (enabled) + this.x1ShowAllCheckBox.doClick(); + } + } + } + } diff --git a/src/dna/visualization/components/visualizer/MetricVisualizer.java b/src/dna/visualization/components/visualizer/MetricVisualizer.java index ef22dd4e..8ab8cc2a 100644 --- a/src/dna/visualization/components/visualizer/MetricVisualizer.java +++ b/src/dna/visualization/components/visualizer/MetricVisualizer.java @@ -1,23 +1,5 @@ package dna.visualization.components.visualizer; -import info.monitorenter.gui.chart.IAxis; -import info.monitorenter.gui.chart.IAxis.AxisTitle; -import info.monitorenter.gui.chart.ITrace2D; -import info.monitorenter.gui.chart.ITracePainter; -import info.monitorenter.gui.chart.ITracePoint2D; -import info.monitorenter.gui.chart.axis.scalepolicy.AxisScalePolicyAutomaticBestFit; -import info.monitorenter.gui.chart.labelformatters.LabelFormatterDate; -import info.monitorenter.gui.chart.rangepolicies.RangePolicyFixedViewport; -import info.monitorenter.gui.chart.rangepolicies.RangePolicyUnbounded; -import info.monitorenter.gui.chart.traces.Trace2DLtd; -import info.monitorenter.gui.chart.traces.Trace2DSimple; -import info.monitorenter.gui.chart.traces.painters.TracePainterDisc; -import info.monitorenter.gui.chart.traces.painters.TracePainterFill; -import info.monitorenter.gui.chart.traces.painters.TracePainterLine; -import info.monitorenter.gui.chart.traces.painters.TracePainterPolyline; -import info.monitorenter.gui.chart.traces.painters.TracePainterVerticalBar; -import info.monitorenter.util.Range; - import java.awt.Color; import java.awt.Font; import java.awt.event.MouseEvent; @@ -41,6 +23,23 @@ import dna.visualization.config.MetricVisualizerItem; import dna.visualization.config.VisualizerListConfig; import dna.visualization.config.components.MetricVisualizerConfig; +import info.monitorenter.gui.chart.IAxis; +import info.monitorenter.gui.chart.IAxis.AxisTitle; +import info.monitorenter.gui.chart.ITrace2D; +import info.monitorenter.gui.chart.ITracePainter; +import info.monitorenter.gui.chart.ITracePoint2D; +import info.monitorenter.gui.chart.axis.scalepolicy.AxisScalePolicyAutomaticBestFit; +import info.monitorenter.gui.chart.labelformatters.LabelFormatterDate; +import info.monitorenter.gui.chart.rangepolicies.RangePolicyFixedViewport; +import info.monitorenter.gui.chart.rangepolicies.RangePolicyUnbounded; +import info.monitorenter.gui.chart.traces.Trace2DLtd; +import info.monitorenter.gui.chart.traces.Trace2DSimple; +import info.monitorenter.gui.chart.traces.painters.TracePainterDisc; +import info.monitorenter.gui.chart.traces.painters.TracePainterFill; +import info.monitorenter.gui.chart.traces.painters.TracePainterLine; +import info.monitorenter.gui.chart.traces.painters.TracePainterPolyline; +import info.monitorenter.gui.chart.traces.painters.TracePainterVerticalBar; +import info.monitorenter.util.Range; @SuppressWarnings("serial") public class MetricVisualizer extends Visualizer { @@ -68,10 +67,11 @@ public class MetricVisualizer extends Visualizer { private static String statisticsPrefix = "statistics."; // constructor - public MetricVisualizer(MainDisplay mainDisplay, - MetricVisualizerConfig config) { + public MetricVisualizer(MainDisplay mainDisplay, MetricVisualizerConfig config) { // initialization super(config.getChartSize(), config.getLegendSize()); + + this.x1Connected = config.getMenuBarConfig().isX1AxisConnected(); this.mainDisplay = mainDisplay; this.traces = new HashMap(); this.availableValues = new ArrayList(); @@ -86,10 +86,8 @@ public MetricVisualizer(MainDisplay mainDisplay, // set title and border of the metric visualizer TitledBorder title = BorderFactory.createTitledBorder(config.getName()); - title.setBorder(BorderFactory - .createEtchedBorder((EtchedBorder.LOWERED))); - title.setTitleFont(new Font( - this.mainDisplay.getDefaultFont().getName(), Font.BOLD, + title.setBorder(BorderFactory.createEtchedBorder((EtchedBorder.LOWERED))); + title.setTitleFont(new Font(this.mainDisplay.getDefaultFont().getName(), Font.BOLD, this.mainDisplay.getDefaultFont().getSize())); title.setTitleColor(this.mainDisplay.getDefaultFontColor()); this.setBorder(title); @@ -98,12 +96,10 @@ public MetricVisualizer(MainDisplay mainDisplay, this.xAxisTypeTimestamp = true; if (config.getxAxisType().equals("date")) { this.xAxisTypeTimestamp = false; - this.xAxis1.setFormatter(new LabelFormatterDate( - new SimpleDateFormat(config.getxAxisFormat()))); + this.xAxis1.setFormatter(new LabelFormatterDate(new SimpleDateFormat(config.getxAxisFormat()))); this.xAxis1.setMajorTickSpacing(5); this.xAxis1.setMinorTickSpacing(1); - this.xAxis1 - .setAxisScalePolicy(new AxisScalePolicyAutomaticBestFit()); + this.xAxis1.setAxisScalePolicy(new AxisScalePolicyAutomaticBestFit()); } // add menu bar @@ -114,11 +110,8 @@ public MetricVisualizer(MainDisplay mainDisplay, @Override public void mouseMoved(MouseEvent e) { if (chart.getPointFinder().getNearestPoint(e, chart) != null) { - ITracePoint2D tempPointFinder = chart.getPointFinder() - .getNearestPoint(e, chart); - menuBar.updateCoordsPanel( - (int) Math.floor(tempPointFinder.getX()), - tempPointFinder.getY()); + ITracePoint2D tempPointFinder = chart.getPointFinder().getNearestPoint(e, chart); + menuBar.updateCoordsPanel((int) Math.floor(tempPointFinder.getX()), tempPointFinder.getY()); } } @@ -130,9 +123,11 @@ public void mouseDragged(MouseEvent e) { this.chart.setPreferredSize(config.getChartSize()); this.legend.setLegendSize(config.getLegendSize()); this.xAxisOffset = config.getxAxisOffset(); - + this.xAxis1.setAxisTitle(new AxisTitle(config.getx1AxisTitle())); this.yAxis1.setAxisTitle(new AxisTitle(config.getY1AxisTitle())); this.yAxis2.setAxisTitle(new AxisTitle(config.getY2AxisTitle())); + + this.menuBar.setVisible(config.getMenuBarConfig().isVisible()); } /** handles the ticks that are shown on the x axis **/ @@ -177,8 +172,7 @@ public void updateData(BatchData b) { // backwards if (timestamp < this.currentTimestamp) { while (this.batchBuffer.size() > 0) { - if (this.batchBuffer.getLast().getTimestamp() <= b - .getTimestamp()) { + if (this.batchBuffer.getLast().getTimestamp() <= b.getTimestamp()) { break; } else { this.batchBuffer.removeLast(); @@ -209,14 +203,11 @@ public void updateData(BatchData b) { // update values for (String metric : b.getMetrics().getNames()) { - for (String value : b.getMetrics().get(metric).getValues() - .getNames()) { + for (String value : b.getMetrics().get(metric).getValues().getNames()) { if (this.traces.containsKey(metric + "." + value)) { String tempName = metric + "." + value; - double tempValue = b.getMetrics().get(metric) - .getValues().get(value).getValue(); - this.traces.get(tempName).addPoint( - timestampDouble + offsetX, tempValue); + double tempValue = b.getMetrics().get(metric).getValues().get(value).getValue(); + this.traces.get(tempName).addPoint(timestampDouble + offsetX, tempValue); offsetX += this.xAxisOffset; this.legend.updateItem(tempName, tempValue); } @@ -224,44 +215,32 @@ public void updateData(BatchData b) { } // update general runtimes for (String runtime : b.getGeneralRuntimes().getNames()) { - if (this.traces - .containsKey(MetricVisualizer.generalRuntimesPrefix - + runtime)) { - String tempName = MetricVisualizer.generalRuntimesPrefix - + runtime; - double tempValue = b.getGeneralRuntimes().get(runtime) - .getRuntime(); - this.traces.get(tempName).addPoint( - timestampDouble + offsetX, tempValue); + if (this.traces.containsKey(MetricVisualizer.generalRuntimesPrefix + runtime)) { + String tempName = MetricVisualizer.generalRuntimesPrefix + runtime; + double tempValue = b.getGeneralRuntimes().get(runtime).getRuntime(); + this.traces.get(tempName).addPoint(timestampDouble + offsetX, tempValue); offsetX += this.xAxisOffset; this.legend.updateItem(tempName, tempValue); } } // update metric runtimes for (String runtime : b.getMetricRuntimes().getNames()) { - if (this.traces - .containsKey(MetricVisualizer.metricRuntimesPrefix - + runtime)) { - String tempName = MetricVisualizer.metricRuntimesPrefix - + runtime; - double tempValue = b.getMetricRuntimes().get(runtime) - .getRuntime(); - - this.traces.get(tempName).addPoint( - timestampDouble + offsetX, tempValue); + if (this.traces.containsKey(MetricVisualizer.metricRuntimesPrefix + runtime)) { + String tempName = MetricVisualizer.metricRuntimesPrefix + runtime; + double tempValue = b.getMetricRuntimes().get(runtime).getRuntime(); + + this.traces.get(tempName).addPoint(timestampDouble + offsetX, tempValue); offsetX += this.xAxisOffset; this.legend.updateItem(tempName, tempValue); } } // update statistics for (String value : b.getValues().getNames()) { - if (this.traces.containsKey(MetricVisualizer.statisticsPrefix - + value)) { + if (this.traces.containsKey(MetricVisualizer.statisticsPrefix + value)) { String tempName = MetricVisualizer.statisticsPrefix + value; double tempValue = b.getValues().get(value).getValue(); - this.traces.get(tempName).addPoint( - timestampDouble + offsetX, tempValue); + this.traces.get(tempName).addPoint(timestampDouble + offsetX, tempValue); offsetX += this.xAxisOffset; this.legend.updateItem(tempName, tempValue); } @@ -270,19 +249,15 @@ public void updateData(BatchData b) { if (config.isTraceModeLtd() && !this.FIXED_VIEWPORT) { this.maxShownTimestamp = this.maxTimestamp; if (this.maxShownTimestamp - this.TRACE_LENGTH > 0) - this.minShownTimestamp = this.maxShownTimestamp - - this.TRACE_LENGTH; + this.minShownTimestamp = this.maxShownTimestamp - this.TRACE_LENGTH; else this.minShownTimestamp = 0; - this.xAxis1.setRange(new Range(this.minShownTimestamp, - this.maxShownTimestamp)); + this.xAxis1.setRange(new Range(this.minShownTimestamp, this.maxShownTimestamp)); } else { if (this.FIXED_VIEWPORT) { - double lowP = 1.0 * this.menuBar.getIntervalSlider() - .getValue() / 100; - double highP = 1.0 * (this.menuBar.getIntervalSlider() - .getValue() + this.menuBar.getIntervalSlider() - .getModel().getExtent()) / 100; + double lowP = 1.0 * this.menuBar.getIntervalSlider().getValue() / 100; + double highP = 1.0 * (this.menuBar.getIntervalSlider().getValue() + + this.menuBar.getIntervalSlider().getModel().getExtent()) / 100; double minD = 0; double maxD = 0; @@ -352,15 +327,12 @@ private void updateTrace(BatchData b, String name) { double timestampDouble = timestamp; // update values for (String metric : b.getMetrics().getNames()) { - for (String value : b.getMetrics().get(metric).getValues() - .getNames()) { + for (String value : b.getMetrics().get(metric).getValues().getNames()) { if (this.traces.containsKey(metric + "." + value)) { String tempName = metric + "." + value; if (tempName.equals(name)) { - double tempValue = b.getMetrics().get(metric) - .getValues().get(value).getValue(); - this.traces.get(tempName).addPoint(timestampDouble, - tempValue); + double tempValue = b.getMetrics().get(metric).getValues().get(value).getValue(); + this.traces.get(tempName).addPoint(timestampDouble, tempValue); this.legend.updateItem(tempName, tempValue); } } @@ -368,43 +340,33 @@ private void updateTrace(BatchData b, String name) { } // update general runtimes for (String runtime : b.getGeneralRuntimes().getNames()) { - if (this.traces.containsKey(MetricVisualizer.generalRuntimesPrefix - + runtime)) { - String tempName = MetricVisualizer.generalRuntimesPrefix - + runtime; + if (this.traces.containsKey(MetricVisualizer.generalRuntimesPrefix + runtime)) { + String tempName = MetricVisualizer.generalRuntimesPrefix + runtime; if (tempName.equals(name)) { - double tempValue = b.getGeneralRuntimes().get(runtime) - .getRuntime(); - this.traces.get(tempName).addPoint(timestampDouble, - tempValue); + double tempValue = b.getGeneralRuntimes().get(runtime).getRuntime(); + this.traces.get(tempName).addPoint(timestampDouble, tempValue); this.legend.updateItem(tempName, tempValue); } } } // update metric runtimes for (String runtime : b.getMetricRuntimes().getNames()) { - if (this.traces.containsKey(MetricVisualizer.metricRuntimesPrefix - + runtime)) { - String tempName = MetricVisualizer.metricRuntimesPrefix - + runtime; - double tempValue = b.getMetricRuntimes().get(runtime) - .getRuntime(); + if (this.traces.containsKey(MetricVisualizer.metricRuntimesPrefix + runtime)) { + String tempName = MetricVisualizer.metricRuntimesPrefix + runtime; + double tempValue = b.getMetricRuntimes().get(runtime).getRuntime(); if (tempName.equals(name)) { - this.traces.get(tempName).addPoint(timestampDouble, - tempValue); + this.traces.get(tempName).addPoint(timestampDouble, tempValue); this.legend.updateItem(tempName, tempValue); } } } // update statistics for (String value : b.getValues().getNames()) { - if (this.traces.containsKey(MetricVisualizer.statisticsPrefix - + value)) { + if (this.traces.containsKey(MetricVisualizer.statisticsPrefix + value)) { String tempName = MetricVisualizer.statisticsPrefix + value; if (tempName.equals(name)) { double tempValue = b.getValues().get(value).getValue(); - this.traces.get(tempName).addPoint(timestampDouble, - tempValue); + this.traces.get(tempName).addPoint(timestampDouble, tempValue); this.legend.updateItem(tempName, tempValue); } } @@ -420,8 +382,7 @@ public void addTrace(String name, Color color) { this.traces.put(name, newTrace); this.chart.addTrace(newTrace); if (config.isPaintLinesPoint()) - newTrace.addTracePainter(new TracePainterDisc(config - .getLinesPointSize())); + newTrace.addTracePainter(new TracePainterDisc(config.getLinesPointSize())); if (config.isPaintFill()) newTrace.addTracePainter(new TracePainterFill(this.chart)); } else { @@ -431,8 +392,7 @@ public void addTrace(String name, Color color) { this.chart.addTrace(newTrace); if (config.isPaintLinesPoint()) - newTrace.addTracePainter(new TracePainterDisc(config - .getLinesPointSize())); + newTrace.addTracePainter(new TracePainterDisc(config.getLinesPointSize())); if (config.isPaintFill()) newTrace.addTracePainter(new TracePainterFill(this.chart)); } @@ -453,16 +413,13 @@ public void addTrace(String name, Color color, boolean verticalBar) { if (painter instanceof TracePainterPolyline) newTrace.removeTracePainter(painter); } - newTrace.addTracePainter(new TracePainterVerticalBar(config - .getVerticalBarSize(), this.chart)); + newTrace.addTracePainter(new TracePainterVerticalBar(config.getVerticalBarSize(), this.chart)); } else { if (config.isPaintLinesPoint()) - newTrace.addTracePainter(new TracePainterDisc(config - .getLinesPointSize())); + newTrace.addTracePainter(new TracePainterDisc(config.getLinesPointSize())); if (config.isPaintFill()) - newTrace.addTracePainter(new TracePainterFill( - this.chart)); + newTrace.addTracePainter(new TracePainterFill(this.chart)); } } else { Trace2DSimple newTrace = new Trace2DSimple(); @@ -471,8 +428,7 @@ public void addTrace(String name, Color color, boolean verticalBar) { this.chart.addTrace(newTrace); if (config.isPaintLinesPoint()) - newTrace.addTracePainter(new TracePainterDisc(config - .getLinesPointSize())); + newTrace.addTracePainter(new TracePainterDisc(config.getLinesPointSize())); if (config.isPaintFill()) newTrace.addTracePainter(new TracePainterFill(this.chart)); } @@ -496,8 +452,7 @@ public void initData(BatchData b) { // gather all available values for (String metric : b.getMetrics().getNames()) { - for (String value : b.getMetrics().get(metric).getValues() - .getNames()) { + for (String value : b.getMetrics().get(metric).getValues().getNames()) { this.availableValues.add(metric + "." + value); } } @@ -505,13 +460,11 @@ public void initData(BatchData b) { // graphGeneration runtime will be ignored cause it is only present // in the initial batch if (!runtime.equals("graphGeneration")) { - this.availableValues.add(MetricVisualizer.generalRuntimesPrefix - + runtime); + this.availableValues.add(MetricVisualizer.generalRuntimesPrefix + runtime); } } for (String runtime : b.getMetricRuntimes().getNames()) { - this.availableValues.add(MetricVisualizer.metricRuntimesPrefix - + runtime); + this.availableValues.add(MetricVisualizer.metricRuntimesPrefix + runtime); } for (String value : b.getValues().getNames()) { this.availableValues.add(MetricVisualizer.statisticsPrefix + value); @@ -563,12 +516,10 @@ public void toggleDisplayMode(String name) { verticalBar = true; } if (verticalBar) { - trace.setTracePainter(new TracePainterDisc(config - .getLinesPointSize())); + trace.setTracePainter(new TracePainterDisc(config.getLinesPointSize())); trace.addTracePainter(new TracePainterLine()); } else { - trace.setTracePainter(new TracePainterVerticalBar(config - .getVerticalBarSize(), this.chart)); + trace.setTracePainter(new TracePainterVerticalBar(config.getVerticalBarSize(), this.chart)); } } } @@ -678,8 +629,7 @@ public void loadConfig(VisualizerListConfig config) { // add single configs to lists for (ConfigItem c : config.getEntries()) { if (c instanceof MetricVisualizerItem) { - if (this.availableValues.contains(c.getName()) - && c.getOrderId() >= -1) { + if (this.availableValues.contains(c.getName()) && c.getOrderId() >= -1) { configsList.add((MetricVisualizerItem) c); } } @@ -689,21 +639,18 @@ public void loadConfig(VisualizerListConfig config) { MetricVisualizer.addGeneralConfigs(configsList, config); // craft names list to use as a blacklist for general configs later - ArrayList configsNamesList = new ArrayList( - configsList.size()); + ArrayList configsNamesList = new ArrayList(configsList.size()); for (MetricVisualizerItem c : configsList) configsNamesList.add(c.getName()); // convert list to array - MetricVisualizerItem[] configsArray = configsList - .toArray(new MetricVisualizerItem[configsList.size()]); + MetricVisualizerItem[] configsArray = configsList.toArray(new MetricVisualizerItem[configsList.size()]); // sort array with insertion sort for (int i = 1; i < configsArray.length; i++) { MetricVisualizerItem single = configsArray[i]; int j = i; - while (j > 0 - && configsArray[j - 1].getOrderId() > single.getOrderId()) { + while (j > 0 && configsArray[j - 1].getOrderId() > single.getOrderId()) { configsArray[j] = configsArray[j - 1]; j--; } @@ -715,20 +662,16 @@ public void loadConfig(VisualizerListConfig config) { // calculate "breakpoint" in sorted list: where does -1 end? int breakpoint = 0; - for (int i = 0; i < configsArray.length - && configsArray[i].getOrderId() < 0; i++) + for (int i = 0; i < configsArray.length && configsArray[i].getOrderId() < 0; i++) breakpoint = i + 1; // first insert items with id > -1, then those with -1 - this.insertForId(breakpoint, configsArray.length, b, configsNamesList, - configsArray, config); - this.insertForId(0, breakpoint, b, configsNamesList, configsArray, - config); + this.insertForId(breakpoint, configsArray.length, b, configsNamesList, configsArray, config); + this.insertForId(0, breakpoint, b, configsNamesList, configsArray, config); } /** Inserts items from the configs array to the legend. **/ - private void insertForId(int from, int to, BatchData b, - ArrayList configsNamesList, + private void insertForId(int from, int to, BatchData b, ArrayList configsNamesList, MetricVisualizerItem[] configsArray, VisualizerListConfig config) { for (int i = from; i < to; i++) { MetricVisualizerItem item = configsArray[i]; @@ -760,90 +703,89 @@ private void insertForId(int from, int to, BatchData b, } /** Adds all set general configs to the list. **/ - private static void addGeneralConfigs( - ArrayList configs, VisualizerListConfig config) { + private static void addGeneralConfigs(ArrayList configs, VisualizerListConfig config) { if (config.isAnyGeneralConfigSet()) { - if (config.getAllGeneralRuntimesConfig() != null - && config.getAllGeneralRuntimesConfig().getOrderId() >= -1) + if (config.getAllGeneralRuntimesConfig() != null && config.getAllGeneralRuntimesConfig().getOrderId() >= -1) configs.add(config.getAllGeneralRuntimesConfig()); - if (config.getAllMetricRuntimesConfig() != null - && config.getAllMetricRuntimesConfig().getOrderId() >= -1) + if (config.getAllMetricRuntimesConfig() != null && config.getAllMetricRuntimesConfig().getOrderId() >= -1) configs.add(config.getAllMetricRuntimesConfig()); - if (config.getAllStatisticsConfig() != null - && config.getAllStatisticsConfig().getOrderId() >= -1) + if (config.getAllStatisticsConfig() != null && config.getAllStatisticsConfig().getOrderId() >= -1) configs.add(config.getAllStatisticsConfig()); - if (config.getAllMetricsConfig() != null - && config.getAllMetricsConfig().getOrderId() >= -1) + if (config.getAllMetricsConfig() != null && config.getAllMetricsConfig().getOrderId() >= -1) configs.add(config.getAllMetricsConfig()); } } /** Insert all available metric runtimes. **/ - private void insertMetricRuntimes(BatchData b, VisualizerListConfig config, - ArrayList blackList) { + private void insertMetricRuntimes(BatchData b, VisualizerListConfig config, ArrayList blackList) { // insert all available metric runtimes for (String runtime : b.getMetricRuntimes().getNames()) { - if (!blackList.contains(MetricVisualizer.metricRuntimesPrefix - + runtime)) { + if (!blackList.contains(MetricVisualizer.metricRuntimesPrefix + runtime)) { MetricVisualizerItem c = config.getAllMetricRuntimesConfig(); - this.legend.addValueItemToList(new MetricVisualizerItem( - MetricVisualizer.metricRuntimesPrefix + runtime, c - .getDisplayMode(), c.getYAxis(), c - .getVisibility())); + this.legend.addValueItemToList(new MetricVisualizerItem(MetricVisualizer.metricRuntimesPrefix + runtime, + c.getDisplayMode(), c.getYAxis(), c.getVisibility())); } } } /** Insert all available general runtimes. **/ - private void insertGeneralRuntimes(BatchData b, - VisualizerListConfig config, ArrayList blackList) { + private void insertGeneralRuntimes(BatchData b, VisualizerListConfig config, ArrayList blackList) { for (String runtime : b.getGeneralRuntimes().getNames()) { // graphGeneration runtime will be ignored cause it is only present // in the initial batch if (!runtime.equals("graphGeneration") - && !blackList - .contains(MetricVisualizer.generalRuntimesPrefix - + runtime)) { + && !blackList.contains(MetricVisualizer.generalRuntimesPrefix + runtime)) { MetricVisualizerItem c = config.getAllGeneralRuntimesConfig(); - this.legend.addValueItemToList(new MetricVisualizerItem( - MetricVisualizer.generalRuntimesPrefix + runtime, c - .getDisplayMode(), c.getYAxis(), c - .getVisibility())); + this.legend + .addValueItemToList(new MetricVisualizerItem(MetricVisualizer.generalRuntimesPrefix + runtime, + c.getDisplayMode(), c.getYAxis(), c.getVisibility())); } } } /** Insert all available statistics. **/ - private void insertStatistics(BatchData b, VisualizerListConfig config, - ArrayList blackList) { + private void insertStatistics(BatchData b, VisualizerListConfig config, ArrayList blackList) { for (String value : b.getValues().getNames()) { if (!blackList.contains(MetricVisualizer.statisticsPrefix + value)) { MetricVisualizerItem c = config.getAllStatisticsConfig(); - this.legend.addValueItemToList(new MetricVisualizerItem( - MetricVisualizer.statisticsPrefix + value, c - .getDisplayMode(), c.getYAxis(), c - .getVisibility())); + this.legend.addValueItemToList(new MetricVisualizerItem(MetricVisualizer.statisticsPrefix + value, + c.getDisplayMode(), c.getYAxis(), c.getVisibility())); } } } /** Insert all available metrics. **/ - private void insertMetrics(BatchData b, VisualizerListConfig config, - ArrayList blackList) { + private void insertMetrics(BatchData b, VisualizerListConfig config, ArrayList blackList) { for (String metric : b.getMetrics().getNames()) { - for (String value : b.getMetrics().get(metric).getValues() - .getNames()) { + for (String value : b.getMetrics().get(metric).getValues().getNames()) { if (!blackList.contains(metric + "." + value)) { MetricVisualizerItem c = config.getAllMetricsConfig(); - this.legend.addValueItemToList(new MetricVisualizerItem( - metric + "." + value, c.getDisplayMode(), c - .getYAxis(), c.getVisibility())); + this.legend.addValueItemToList(new MetricVisualizerItem(metric + "." + value, c.getDisplayMode(), + c.getYAxis(), c.getVisibility())); } } } } + @Override + public void broadcastX1IntervalSizeSliderChange(int value) { + if (this.isX1Connected()) + this.mainDisplay.broadcastX1SizeSliderChange(this, value); + } + + @Override + public void broadcastX1IntervalScrollBarChange(int value) { + if (this.isX1Connected()) + this.mainDisplay.broadcastX1IntervalScrollBarChange(this, value); + } + + @Override + public void broadcastX1IntervalEnabled(boolean enabled) { + if (this.isX1Connected()) + this.mainDisplay.broadcastX1IntervalEnabled(this, enabled); + } + } diff --git a/src/dna/visualization/components/visualizer/MultiScalarVisualizer.java b/src/dna/visualization/components/visualizer/MultiScalarVisualizer.java index e32bb24e..4ea0f4c3 100644 --- a/src/dna/visualization/components/visualizer/MultiScalarVisualizer.java +++ b/src/dna/visualization/components/visualizer/MultiScalarVisualizer.java @@ -1,16 +1,5 @@ package dna.visualization.components.visualizer; -import info.monitorenter.gui.chart.IAxis; -import info.monitorenter.gui.chart.IAxis.AxisTitle; -import info.monitorenter.gui.chart.ITrace2D; -import info.monitorenter.gui.chart.ITracePainter; -import info.monitorenter.gui.chart.ITracePoint2D; -import info.monitorenter.gui.chart.traces.Trace2DSimple; -import info.monitorenter.gui.chart.traces.painters.TracePainterDisc; -import info.monitorenter.gui.chart.traces.painters.TracePainterFill; -import info.monitorenter.gui.chart.traces.painters.TracePainterLine; -import info.monitorenter.gui.chart.traces.painters.TracePainterVerticalBar; - import java.awt.Color; import java.awt.Font; import java.awt.event.MouseEvent; @@ -47,6 +36,16 @@ import dna.visualization.config.VisualizerListConfig.xAxisSelection; import dna.visualization.config.VisualizerListConfig.yAxisSelection; import dna.visualization.config.components.MultiScalarVisualizerConfig; +import info.monitorenter.gui.chart.IAxis; +import info.monitorenter.gui.chart.IAxis.AxisTitle; +import info.monitorenter.gui.chart.ITrace2D; +import info.monitorenter.gui.chart.ITracePainter; +import info.monitorenter.gui.chart.ITracePoint2D; +import info.monitorenter.gui.chart.traces.Trace2DSimple; +import info.monitorenter.gui.chart.traces.painters.TracePainterDisc; +import info.monitorenter.gui.chart.traces.painters.TracePainterFill; +import info.monitorenter.gui.chart.traces.painters.TracePainterLine; +import info.monitorenter.gui.chart.traces.painters.TracePainterVerticalBar; @SuppressWarnings("serial") public class MultiScalarVisualizer extends Visualizer { @@ -73,8 +72,7 @@ public class MultiScalarVisualizer extends Visualizer { private BatchData currentBatch; // constructor - public MultiScalarVisualizer(MainDisplay mainDisplay, - MultiScalarVisualizerConfig config) { + public MultiScalarVisualizer(MainDisplay mainDisplay, MultiScalarVisualizerConfig config) { // initialization super(config.getChartSize(), config.getLegendSize()); this.config = config; @@ -99,10 +97,8 @@ public MultiScalarVisualizer(MainDisplay mainDisplay, // set title and border of the visualizer TitledBorder title = BorderFactory.createTitledBorder(config.getName()); - title.setBorder(BorderFactory - .createEtchedBorder((EtchedBorder.LOWERED))); - title.setTitleFont(new Font( - this.mainDisplay.getDefaultFont().getName(), Font.BOLD, + title.setBorder(BorderFactory.createEtchedBorder((EtchedBorder.LOWERED))); + title.setTitleFont(new Font(this.mainDisplay.getDefaultFont().getName(), Font.BOLD, this.mainDisplay.getDefaultFont().getSize())); title.setTitleColor(this.mainDisplay.getDefaultFontColor()); this.setBorder(title); @@ -115,11 +111,8 @@ public MultiScalarVisualizer(MainDisplay mainDisplay, @Override public void mouseMoved(MouseEvent e) { if (chart.getPointFinder().getNearestPoint(e, chart) != null) { - ITracePoint2D tempPointFinder = chart.getPointFinder() - .getNearestPoint(e, chart); - menuBar.updateCoordsPanel( - (int) Math.floor(tempPointFinder.getX()), - tempPointFinder.getY()); + ITracePoint2D tempPointFinder = chart.getPointFinder().getNearestPoint(e, chart); + menuBar.updateCoordsPanel((int) Math.floor(tempPointFinder.getX()), tempPointFinder.getY()); } } @@ -131,6 +124,7 @@ public void mouseDragged(MouseEvent e) { // apply config this.chart.setPreferredSize(config.getChartSize()); this.legend.setLegendSize(config.getLegendSize()); + this.menuBar.setVisible(config.getMenuBarConfig().isVisible()); this.xAxisOffset = config.getxAxisOffset(); this.xAxis1.setAxisTitle(new AxisTitle(config.getx1AxisTitle())); @@ -158,12 +152,10 @@ public void initData(BatchData b) { // gather all available values for (String metric : b.getMetrics().getNames()) { - for (String dist : b.getMetrics().get(metric).getDistributions() - .getNames()) { + for (String dist : b.getMetrics().get(metric).getDistributions().getNames()) { this.availableDistributions.add(metric + "." + dist); } - for (String nvl : b.getMetrics().get(metric).getNodeValues() - .getNames()) { + for (String nvl : b.getMetrics().get(metric).getNodeValues().getNames()) { this.availableNodeValueLists.add(metric + "." + nvl); } } @@ -199,74 +191,58 @@ public void updateData(BatchData b) { // add points for (String metric : b.getMetrics().getNames()) { - for (String dist : b.getMetrics().get(metric).getDistributions() - .getNames()) { + for (String dist : b.getMetrics().get(metric).getDistributions().getNames()) { if (this.traces.containsKey(metric + "." + dist)) { - Distr tempDist = b.getMetrics().get(metric) - .getDistributions().get(dist); + Distr tempDist = b.getMetrics().get(metric).getDistributions().get(dist); String tempName = metric + "." + dist; DistrType tempType = tempDist.getDistrType(); - SortModeDist tempSortMode = ((LegendItemDistribution) this.legend - .getLegendList().getLegendItem(tempName)) - .getSortMode(); + SortModeDist tempSortMode = ((LegendItemDistribution) this.legend.getLegendList() + .getLegendItem(tempName)).getSortMode(); switch (tempType) { case BINNED_DOUBLE: BinnedDoubleDistr bdd = (BinnedDoubleDistr) tempDist; - this.addLongDistributionTrace(tempName, - bdd.getValues(), bdd.getDenominator(), - bdd.getBinSize(), tempSortMode, - this.getTraceOffsetX(tempName)); + this.addLongDistributionTrace(tempName, bdd.getValues(), bdd.getDenominator(), bdd.getBinSize(), + tempSortMode, this.getTraceOffsetX(tempName)); break; case BINNED_INT: BinnedIntDistr bid = (BinnedIntDistr) tempDist; - this.addLongDistributionTrace(tempName, - bid.getValues(), bid.getDenominator(), - bid.getBinSize(), tempSortMode, - this.getTraceOffsetX(tempName)); + this.addLongDistributionTrace(tempName, bid.getValues(), bid.getDenominator(), bid.getBinSize(), + tempSortMode, this.getTraceOffsetX(tempName)); break; case BINNED_LONG: BinnedLongDistr bld = (BinnedLongDistr) tempDist; - this.addLongDistributionTrace(tempName, - bld.getValues(), bld.getDenominator(), - bld.getBinSize(), tempSortMode, - this.getTraceOffsetX(tempName)); + this.addLongDistributionTrace(tempName, bld.getValues(), bld.getDenominator(), bld.getBinSize(), + tempSortMode, this.getTraceOffsetX(tempName)); break; case QUALITY_DOUBLE: QualityDoubleDistr qdd = (QualityDoubleDistr) tempDist; - this.addDoubleDistributionTrace(tempName, - qdd.getValues(), qdd.getBinSize(), - tempSortMode, this.getTraceOffsetX(tempName)); + this.addDoubleDistributionTrace(tempName, qdd.getValues(), qdd.getBinSize(), tempSortMode, + this.getTraceOffsetX(tempName)); break; case QUALITY_INT: QualityIntDistr qid = (QualityIntDistr) tempDist; - this.addDoubleDistributionTrace(tempName, - qid.getValues(), qid.getBinSize(), - tempSortMode, this.getTraceOffsetX(tempName)); + this.addDoubleDistributionTrace(tempName, qid.getValues(), qid.getBinSize(), tempSortMode, + this.getTraceOffsetX(tempName)); break; case QUALITY_LONG: QualityLongDistr qld = (QualityLongDistr) tempDist; - this.addDoubleDistributionTrace(tempName, - qld.getValues(), qld.getBinSize(), - tempSortMode, this.getTraceOffsetX(tempName)); + this.addDoubleDistributionTrace(tempName, qld.getValues(), qld.getBinSize(), tempSortMode, + this.getTraceOffsetX(tempName)); break; } } } - for (String nvl : b.getMetrics().get(metric).getNodeValues() - .getNames()) { + for (String nvl : b.getMetrics().get(metric).getNodeValues().getNames()) { String tempName = metric + "." + nvl; if (this.traces.containsKey(tempName)) { - SortModeNVL tempSortMode = ((LegendItemNodeValueList) this.legend - .getLegendList().getLegendItem(tempName)) - .getSortMode(); - double[] tempValues = b.getMetrics().get(metric) - .getNodeValues().get(nvl).getValues(); + SortModeNVL tempSortMode = ((LegendItemNodeValueList) this.legend.getLegendList() + .getLegendItem(tempName)).getSortMode(); + double[] tempValues = b.getMetrics().get(metric).getNodeValues().get(nvl).getValues(); this.doubleValues.put(tempName, tempValues); - this.addPoints(metric + "." + nvl, tempValues, - tempSortMode, this.getTraceOffsetX(tempName)); + this.addPoints(metric + "." + nvl, tempValues, tempSortMode, this.getTraceOffsetX(tempName)); } } } @@ -275,8 +251,8 @@ public void updateData(BatchData b) { } /** adds points sorted and normalized by dividing through denominator **/ - private void addDistributionPoints(String name, long[] values, - long denominator, double binsize, SortModeDist sort, double offsetX) { + private void addDistributionPoints(String name, long[] values, long denominator, double binsize, SortModeDist sort, + double offsetX) { ITrace2D tempTrace = this.traces.get(name); long[] tempValues = new long[values.length]; @@ -291,8 +267,7 @@ private void addDistributionPoints(String name, long[] values, break; case distribution: for (int i = 0; i < values.length; i++) { - tempTrace.addPoint(i * binsize + offsetX, (1.0 * values[i]) - / denominator); + tempTrace.addPoint(i * binsize + offsetX, (1.0 * values[i]) / denominator); } break; } @@ -304,8 +279,8 @@ private void addDistributionPoints(String name, long[] values, } /** adds points sorted and normalized by dividing through denominator **/ - private void addDistributionPoints(String name, double[] values, - double binsize, SortModeDist sort, double offsetX) { + private void addDistributionPoints(String name, double[] values, double binsize, SortModeDist sort, + double offsetX) { ITrace2D tempTrace = this.traces.get(name); double[] tempValues = new double[values.length]; @@ -332,8 +307,7 @@ private void addDistributionPoints(String name, double[] values, } /** adds points sorted **/ - private void addPoints(String name, double[] values, SortModeNVL sort, - double offsetX) { + private void addPoints(String name, double[] values, SortModeNVL sort, double offsetX) { ITrace2D tempTrace = this.traces.get(name); double[] tempValues = new double[values.length]; int tempIndex = 0; @@ -365,8 +339,7 @@ private void addPoints(String name, double[] values, SortModeNVL sort, else break; } - for (int i = 0, j = tempValues.length - 1; i < tempValues.length - - tempIndex; i++) { + for (int i = 0, j = tempValues.length - 1; i < tempValues.length - tempIndex; i++) { tempTrace.addPoint(j - (i + tempIndex), tempValues[i]); } break; @@ -394,8 +367,7 @@ public void clearPoints() { } /** adds trace to the visualizer **/ - public void addTrace(String name, Color color, xAxisSelection xAxis, - yAxisSelection yAxis) { + public void addTrace(String name, Color color, xAxisSelection xAxis, yAxisSelection yAxis) { Trace2DSimple newTrace = new Trace2DSimple(); newTrace.setColor(color); this.traces.put(name, newTrace); @@ -410,15 +382,13 @@ public void addTrace(String name, Color color, xAxisSelection xAxis, this.yAxis2.addTrace(newTrace); if (config.isPaintLinesPoint()) - newTrace.addTracePainter(new TracePainterDisc(config - .getLinesPointSize())); + newTrace.addTracePainter(new TracePainterDisc(config.getLinesPointSize())); if (config.isPaintFill()) newTrace.addTracePainter(new TracePainterFill(this.chart)); } /** adds trace of a distribution and its points to the visualizer **/ - public void addDistributionTrace(String name, Color color, - xAxisSelection xAxis, yAxisSelection yAxis) { + public void addDistributionTrace(String name, Color color, xAxisSelection xAxis, yAxisSelection yAxis) { // calculate offset double offsetX = this.calculateOffsetX(name, xAxis); @@ -431,55 +401,46 @@ public void addDistributionTrace(String name, Color color, // get sort mode SortModeDist tempSortMode = SortModeDist.distribution; if (config.getListConfig() != null) { - tempSortMode = config.getListConfig().getAllDistributionsConfig() - .getSortMode(); + tempSortMode = config.getListConfig().getAllDistributionsConfig().getSortMode(); } // add points to chart for (String metric : this.currentBatch.getMetrics().getNames()) { - for (String dist : this.currentBatch.getMetrics().get(metric) - .getDistributions().getNames()) { + for (String dist : this.currentBatch.getMetrics().get(metric).getDistributions().getNames()) { if ((metric + "." + dist).equals(name)) { - Distr tempDist = this.currentBatch.getMetrics() - .get(metric).getDistributions().get(dist); + Distr tempDist = this.currentBatch.getMetrics().get(metric).getDistributions().get(dist); String tempName = metric + "." + dist; switch (tempDist.getDistrType()) { case BINNED_DOUBLE: BinnedDoubleDistr bdd = (BinnedDoubleDistr) tempDist; - this.addLongDistributionTrace(tempName, - bdd.getValues(), bdd.getDenominator(), - bdd.getBinSize(), tempSortMode, offsetX); + this.addLongDistributionTrace(tempName, bdd.getValues(), bdd.getDenominator(), bdd.getBinSize(), + tempSortMode, offsetX); break; case BINNED_INT: BinnedIntDistr bid = (BinnedIntDistr) tempDist; - this.addLongDistributionTrace(tempName, - bid.getValues(), bid.getDenominator(), - bid.getBinSize(), tempSortMode, offsetX); + this.addLongDistributionTrace(tempName, bid.getValues(), bid.getDenominator(), bid.getBinSize(), + tempSortMode, offsetX); break; case BINNED_LONG: BinnedLongDistr bld = (BinnedLongDistr) tempDist; - this.addLongDistributionTrace(tempName, - bld.getValues(), bld.getDenominator(), - bld.getBinSize(), tempSortMode, offsetX); + this.addLongDistributionTrace(tempName, bld.getValues(), bld.getDenominator(), bld.getBinSize(), + tempSortMode, offsetX); break; case QUALITY_DOUBLE: QualityDoubleDistr qdd = (QualityDoubleDistr) tempDist; - this.addDoubleDistributionTrace(tempName, - qdd.getValues(), qdd.getBinSize(), - tempSortMode, offsetX); + this.addDoubleDistributionTrace(tempName, qdd.getValues(), qdd.getBinSize(), tempSortMode, + offsetX); break; case QUALITY_INT: QualityIntDistr qid = (QualityIntDistr) tempDist; - this.addDoubleDistributionTrace(tempName, - qid.getValues(), qid.getBinSize(), - tempSortMode, offsetX); + this.addDoubleDistributionTrace(tempName, qid.getValues(), qid.getBinSize(), tempSortMode, + offsetX); break; case QUALITY_LONG: QualityLongDistr qld = (QualityLongDistr) tempDist; - this.addDoubleDistributionTrace(tempName, - qld.getValues(), qld.getBinSize(), - tempSortMode, offsetX); + this.addDoubleDistributionTrace(tempName, qld.getValues(), qld.getBinSize(), tempSortMode, + offsetX); break; } } @@ -490,28 +451,25 @@ public void addDistributionTrace(String name, Color color, } /** adds trace of a double distribution and its points to the visualizer **/ - private void addDoubleDistributionTrace(String name, double[] values, - double binsize, SortModeDist tempSortMode, double offsetX) { + private void addDoubleDistributionTrace(String name, double[] values, double binsize, SortModeDist tempSortMode, + double offsetX) { this.doubleValues.put(name, values); this.binSizes.put(name, binsize); this.addDistributionPoints(name, values, binsize, tempSortMode, offsetX); } /** adds trace of a long distribution and its points to the visualizer **/ - private void addLongDistributionTrace(String name, long[] values, - long denominator, double binsize, SortModeDist tempSortMode, - double offsetX) { + private void addLongDistributionTrace(String name, long[] values, long denominator, double binsize, + SortModeDist tempSortMode, double offsetX) { this.longValues.put(name, values); this.longDenominators.put(name, denominator); this.binSizes.put(name, binsize); - this.addDistributionPoints(name, values, denominator, binsize, - tempSortMode, offsetX); + this.addDistributionPoints(name, values, denominator, binsize, tempSortMode, offsetX); this.legend.updateItem(name, denominator); } /** adds trace of a nodevaluelist and its points to the visualizer **/ - public void addNodeValueListTrace(String name, Color color, - xAxisSelection xAxis, yAxisSelection yAxis) { + public void addNodeValueListTrace(String name, Color color, xAxisSelection xAxis, yAxisSelection yAxis) { // calculate offset double offsetX = this.calculateOffsetX(name, xAxis); @@ -523,19 +481,16 @@ public void addNodeValueListTrace(String name, Color color, // add points to chart for (String metric : this.currentBatch.getMetrics().getNames()) { - for (String nvl : this.currentBatch.getMetrics().get(metric) - .getNodeValues().getNames()) { + for (String nvl : this.currentBatch.getMetrics().get(metric).getNodeValues().getNames()) { String tempName = metric + "." + nvl; if (this.traces.containsKey(tempName)) { - SortModeNVL tempSortMode = ((LegendItemNodeValueList) this.legend - .getLegendList().getLegendItem(tempName)) - .getSortMode(); - double[] tempValues = this.currentBatch.getMetrics() - .get(metric).getNodeValues().get(nvl).getValues(); + SortModeNVL tempSortMode = ((LegendItemNodeValueList) this.legend.getLegendList() + .getLegendItem(tempName)).getSortMode(); + double[] tempValues = this.currentBatch.getMetrics().get(metric).getNodeValues().get(nvl) + .getValues(); this.doubleValues.put(tempName, tempValues); - this.addPoints(metric + "." + nvl, tempValues, - tempSortMode, offsetX); + this.addPoints(metric + "." + nvl, tempValues, tempSortMode, offsetX); } } } @@ -723,17 +678,12 @@ public void toggleYAxis(String name) { /** toggles the x axis for a trace identified by its name **/ public void toggleXAxis(String name) { if (this.traces.containsKey(name)) { - if (this.chart.getAxesXBottom().get(0).getTraces() - .contains(this.traces.get(name))) { - this.chart.getAxesXBottom().get(0) - .removeTrace(this.traces.get(name)); - this.chart.getAxesXBottom().get(1) - .addTrace(this.traces.get(name)); + if (this.chart.getAxesXBottom().get(0).getTraces().contains(this.traces.get(name))) { + this.chart.getAxesXBottom().get(0).removeTrace(this.traces.get(name)); + this.chart.getAxesXBottom().get(1).addTrace(this.traces.get(name)); } else { - this.chart.getAxesXBottom().get(1) - .removeTrace(this.traces.get(name)); - this.chart.getAxesXBottom().get(0) - .addTrace(this.traces.get(name)); + this.chart.getAxesXBottom().get(1).removeTrace(this.traces.get(name)); + this.chart.getAxesXBottom().get(0).addTrace(this.traces.get(name)); } this.toggleXAxisVisibility(); this.updateTicks(); @@ -761,13 +711,11 @@ public void toggleDisplayMode(String name) { verticalBar = true; } if (verticalBar) { - trace.setTracePainter(new TracePainterDisc(config - .getLinesPointSize())); + trace.setTracePainter(new TracePainterDisc(config.getLinesPointSize())); trace.addTracePainter(new TracePainterLine()); } else { - trace.setTracePainter(new TracePainterVerticalBar(config - .getVerticalBarSize(), this.chart)); + trace.setTracePainter(new TracePainterVerticalBar(config.getVerticalBarSize(), this.chart)); } } } @@ -810,11 +758,9 @@ public void sortItem(String name, SortModeDist s) { double offsetX = 0; if (this.doubleValues.containsKey(name)) { - this.addDistributionPoints(name, this.doubleValues.get(name), - this.binSizes.get(name), s, offsetX); + this.addDistributionPoints(name, this.doubleValues.get(name), this.binSizes.get(name), s, offsetX); } else if (this.longValues.containsKey(name)) { - this.addDistributionPoints(name, this.longValues.get(name), - this.longDenominators.get(name), + this.addDistributionPoints(name, this.longValues.get(name), this.longDenominators.get(name), this.binSizes.get(name), s, offsetX); } } @@ -828,14 +774,12 @@ public void loadConfig(VisualizerListConfig config) { // add single configs to lists for (ConfigItem c : config.getEntries()) { if (c instanceof MultiScalarDistributionItem) { - if (this.availableDistributions.contains(c.getName()) - && c.getOrderId() >= -1) { + if (this.availableDistributions.contains(c.getName()) && c.getOrderId() >= -1) { configsList.add(c); } } if (c instanceof MultiScalarNodeValueListItem) { - if (this.availableNodeValueLists.contains(c.getName()) - && c.getOrderId() >= -1) { + if (this.availableNodeValueLists.contains(c.getName()) && c.getOrderId() >= -1) { configsList.add(c); } } @@ -845,21 +789,18 @@ public void loadConfig(VisualizerListConfig config) { MultiScalarVisualizer.addGeneralConfigs(configsList, config); // craft names list to use as a blacklist for general configs later - ArrayList configsNamesList = new ArrayList( - configsList.size()); + ArrayList configsNamesList = new ArrayList(configsList.size()); for (ConfigItem c : configsList) configsNamesList.add(c.getName()); // convert list to array - ConfigItem[] configsArray = configsList - .toArray(new ConfigItem[configsList.size()]); + ConfigItem[] configsArray = configsList.toArray(new ConfigItem[configsList.size()]); // sort array with insertion sort for (int i = 1; i < configsArray.length; i++) { ConfigItem single = configsArray[i]; int j = i; - while (j > 0 - && configsArray[j - 1].getOrderId() > single.getOrderId()) { + while (j > 0 && configsArray[j - 1].getOrderId() > single.getOrderId()) { configsArray[j] = configsArray[j - 1]; j--; } @@ -869,19 +810,16 @@ public void loadConfig(VisualizerListConfig config) { // calculate "breakpoint" in sorted list: where does -1 end? int breakpoint = 0; - for (int i = 0; i < configsArray.length - && configsArray[i].getOrderId() < 0; i++) + for (int i = 0; i < configsArray.length && configsArray[i].getOrderId() < 0; i++) breakpoint = i + 1; // first insert items with id > -1, then those with -1 - this.insertForId(breakpoint, configsArray.length, configsNamesList, - configsArray, config); + this.insertForId(breakpoint, configsArray.length, configsNamesList, configsArray, config); this.insertForId(0, breakpoint, configsNamesList, configsArray, config); } /** Inserts items from the configs array to the legend. **/ - private void insertForId(int from, int to, - ArrayList configsNamesList, ConfigItem[] configsArray, + private void insertForId(int from, int to, ArrayList configsNamesList, ConfigItem[] configsArray, VisualizerListConfig config) { for (int i = from; i < to; i++) { ConfigItem item = configsArray[i]; @@ -901,13 +839,11 @@ private void insertForId(int from, int to, default: if (item instanceof MultiScalarDistributionItem) { if (this.availableDistributions.contains(item.getName())) - this.legend - .addDistributionItemToList((MultiScalarDistributionItem) item); + this.legend.addDistributionItemToList((MultiScalarDistributionItem) item); } if (item instanceof MultiScalarNodeValueListItem) { if (this.availableNodeValueLists.contains(item.getName())) - this.legend - .addNodeValueListItemToList((MultiScalarNodeValueListItem) item); + this.legend.addNodeValueListItemToList((MultiScalarNodeValueListItem) item); } break; } @@ -915,45 +851,34 @@ private void insertForId(int from, int to, } /** Adds all set general configs to the list. **/ - private static void addGeneralConfigs(ArrayList configs, - VisualizerListConfig config) { + private static void addGeneralConfigs(ArrayList configs, VisualizerListConfig config) { if (config.isAnyGeneralConfigSet()) { - if (config.getAllDistributionsConfig() != null - && config.getAllDistributionsConfig().getOrderId() >= -1) + if (config.getAllDistributionsConfig() != null && config.getAllDistributionsConfig().getOrderId() >= -1) configs.add(config.getAllDistributionsConfig()); - if (config.getAllNodeValueListsConfig() != null - && config.getAllNodeValueListsConfig().getOrderId() >= -1) + if (config.getAllNodeValueListsConfig() != null && config.getAllNodeValueListsConfig().getOrderId() >= -1) configs.add(config.getAllNodeValueListsConfig()); } } /** Insert all available distributions. **/ - private void insertDistributions(VisualizerListConfig config, - ArrayList blackList) { + private void insertDistributions(VisualizerListConfig config, ArrayList blackList) { MultiScalarDistributionItem c = config.getAllDistributionsConfig(); for (String dist : this.availableDistributions) { if (!blackList.contains(dist)) { - this.legend - .addDistributionItemToList(new MultiScalarDistributionItem( - dist, c.getSortMode(), c.getXAxis(), c - .getYAxis(), c.getDisplayMode(), c - .getVisibility())); + this.legend.addDistributionItemToList(new MultiScalarDistributionItem(dist, c.getSortMode(), + c.getXAxis(), c.getYAxis(), c.getDisplayMode(), c.getVisibility())); } } } /** Insert all available nodevaluelists. **/ - private void insertNodeValueLists(VisualizerListConfig config, - ArrayList blackList) { + private void insertNodeValueLists(VisualizerListConfig config, ArrayList blackList) { MultiScalarNodeValueListItem c = config.getAllNodeValueListsConfig(); for (String nvl : this.availableNodeValueLists) { if (!blackList.contains(nvl)) { - this.legend - .addNodeValueListItemToList(new MultiScalarNodeValueListItem( - nvl, c.getSortMode(), c.getXAxis(), c - .getYAxis(), c.getDisplayMode(), c - .getVisibility())); + this.legend.addNodeValueListItemToList(new MultiScalarNodeValueListItem(nvl, c.getSortMode(), + c.getXAxis(), c.getYAxis(), c.getDisplayMode(), c.getVisibility())); } } } @@ -977,12 +902,10 @@ public double calculateOffsetX(String name, xAxisSelection axis) { // gather used offsets List usedOffsets = new ArrayList(); for (ITrace2D trace : this.offsets.keySet()) { - if (this.xAxis1.containsTrace(trace) - && axis.equals(xAxisSelection.x1)) { + if (this.xAxis1.containsTrace(trace) && axis.equals(xAxisSelection.x1)) { usedOffsets.add(this.offsets.get(trace)); } - if (this.xAxis2.containsTrace(trace) - && axis.equals(xAxisSelection.x2)) { + if (this.xAxis2.containsTrace(trace) && axis.equals(xAxisSelection.x2)) { usedOffsets.add(this.offsets.get(trace)); } } @@ -1009,8 +932,7 @@ public void decrementOffsetsX1() { for (ITrace2D trace : this.offsets.keySet()) { if (this.xAxis1.containsTrace(trace)) if (this.offsets.get(trace) != 0) - this.offsets.put(trace, this.offsets.get(trace) - - this.xAxisOffset); + this.offsets.put(trace, this.offsets.get(trace) - this.xAxisOffset); } } @@ -1019,8 +941,7 @@ public void decrementOffsetsX2() { for (ITrace2D trace : this.offsets.keySet()) { if (this.xAxis2.containsTrace(trace)) if (this.offsets.get(trace) != 0) - this.offsets.put(trace, this.offsets.get(trace) - - this.xAxisOffset); + this.offsets.put(trace, this.offsets.get(trace) - this.xAxisOffset); } } } diff --git a/src/dna/visualization/components/visualizer/Visualizer.java b/src/dna/visualization/components/visualizer/Visualizer.java index 78e9237c..39bdda53 100644 --- a/src/dna/visualization/components/visualizer/Visualizer.java +++ b/src/dna/visualization/components/visualizer/Visualizer.java @@ -1,5 +1,15 @@ package dna.visualization.components.visualizer; +import java.awt.Dimension; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.text.DecimalFormat; +import java.text.NumberFormat; + +import javax.swing.JPanel; + +import dna.visualization.MainDisplay; +import dna.visualization.config.components.MenuBarConfig; import info.monitorenter.gui.chart.Chart2D; import info.monitorenter.gui.chart.IAxis; import info.monitorenter.gui.chart.IAxis.AxisTitle; @@ -12,17 +22,6 @@ import info.monitorenter.gui.chart.traces.Trace2DLtd; import info.monitorenter.gui.chart.traces.Trace2DSimple; -import java.awt.Dimension; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.text.DecimalFormat; -import java.text.NumberFormat; - -import javax.swing.JPanel; - -import dna.visualization.MainDisplay; -import dna.visualization.config.components.MenuBarConfig; - @SuppressWarnings("serial") public class Visualizer extends JPanel { // components @@ -58,6 +57,9 @@ public class Visualizer extends JPanel { // shows if the visualizer is locked or not protected boolean locked; + // if true the x1 axis interval selections are shared with other components + protected boolean x1Connected; + // constructor @SuppressWarnings("rawtypes") public Visualizer(Dimension chartSize, Dimension legendSize) { @@ -65,8 +67,7 @@ public Visualizer(Dimension chartSize, Dimension legendSize) { // this.setPreferredSize(GuiOptions.visualizerDefaultSize); this.paused = true; - this.TRACE_LENGTH = MainDisplay.DefaultConfig - .getMetricVisualizerConfigs()[0].getTraceLength(); + this.TRACE_LENGTH = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getTraceLength(); this.FIXED_VIEWPORT = false; this.minTimestamp = 0; this.maxTimestamp = 0; @@ -82,6 +83,8 @@ public Visualizer(Dimension chartSize, Dimension legendSize) { // init chart this.chart = new Chart2D(); this.chart.setPreferredSize(chartSize); + // TODO: add anti alias to config + // this.chart.setUseAntialiasing(true); /* * axis configuration @@ -93,8 +96,7 @@ public Visualizer(Dimension chartSize, Dimension legendSize) { // y1 this.yAxis1 = this.chart.getAxisY(); this.yAxis1.setAxisTitle(new AxisTitle("y1")); - this.yAxis1.setFormatter(new LabelFormatterNumber(new DecimalFormat( - "0.0"))); + this.yAxis1.setFormatter(new LabelFormatterNumber(new DecimalFormat("0.0"))); // x2 this.xAxis2 = new AxisLinear(); @@ -102,8 +104,7 @@ public Visualizer(Dimension chartSize, Dimension legendSize) { this.chart.addAxisXBottom((AAxis) this.xAxis2); // y2 - this.yAxis2 = new AxisLinear(new LabelFormatterNumber( - new DecimalFormat("0.0"))); + this.yAxis2 = new AxisLinear(new LabelFormatterNumber(new DecimalFormat("0.0"))); this.yAxis2 = new AxisLinear(); this.yAxis2.setVisible(false); this.yAxis2.setAxisTitle(new AxisTitle("y2")); @@ -133,14 +134,13 @@ public Visualizer(Dimension chartSize, Dimension legendSize) { this.xAxis2.setAxisScalePolicy(manualTickScalePolicy); } - protected void addMenuBar(Dimension size, boolean addCoordsPanel, - boolean addIntervalPanel, boolean addXOptionsPanel, - boolean addYLeftOptionsPanel) { + protected void addMenuBar(Dimension size, boolean addCoordsPanel, boolean addIntervalPanel, + boolean addXOptionsPanel, boolean addYLeftOptionsPanel) { this.mainConstraints.gridx = 0; this.mainConstraints.gridy = 1; this.mainConstraints.gridwidth = 2; - this.menuBar = new MenuBar(this, size, addCoordsPanel, - addIntervalPanel, addXOptionsPanel, addYLeftOptionsPanel); + this.menuBar = new MenuBar(this, size, addCoordsPanel, addIntervalPanel, addXOptionsPanel, + addYLeftOptionsPanel); this.add(this.menuBar, this.mainConstraints); } @@ -463,7 +463,9 @@ protected void setLocked(boolean locked) { this.locked = locked; } - /** Called when the visualizer gets locked by the main lock in maindisplay. **/ + /** + * Called when the visualizer gets locked by the main lock in maindisplay. + **/ public void setLockedByMainDisplay(boolean locked) { this.legend.setLocked(locked); this.locked = locked; @@ -474,4 +476,67 @@ public boolean isLocked() { return this.locked; } + /** + * Broadcasts the x1 interval size slider changes. The visualizer method + * does nothing as the visualizer does not know the main display and cant + * forward the broadcast. Shall be overridden by visualizer implementations. + **/ + public void broadcastX1IntervalSizeSliderChange(int value) { + // do nothing here + } + + /** + * Broadcasts the x1 interval scroll bar changes. The visualizer method does + * nothing as the visualizer does not know the main display and cant forward + * the broadcast. Shall be overridden by visualizer implementations. + **/ + public void broadcastX1IntervalScrollBarChange(int value) { + // do nothing here + } + + /** + * Broadcasts the x1 interval checkbox changes. The visualizer method does + * nothing as the visualizer does not know the main display and cant forward + * the broadcast. Shall be overridden by visualizer implementations. + **/ + public void broadcastX1IntervalEnabled(boolean enabled) { + // do nothing here + } + + /** Sets the x1 interval size slider. **/ + public void setX1IntervalSizeSlider(int value) { + if (this.isX1Connected()) + this.menuBar.setX1IntervalSizeSlider(value); + } + + /** Sets the x1 interval scrollbar. **/ + public void setX1IntervalScrollBar(int value) { + if (this.isX1Connected()) + this.menuBar.setX1IntervalScrollBar(value); + } + + /** Sets if the interval checkbox is set and if alterations are enabled. **/ + public void setX1IntervalEnabled(boolean enabled) { + if (this.isX1Connected()) + this.menuBar.setX1IntervalEnabled(enabled); + } + + /** Returns if this component is currently connected to shared x1 axis. **/ + public boolean isX1Connected() { + return this.x1Connected; + } + + /** + * Sets if the component is connected or not. Called by menu-bar, dont call + * manually! Changes will not be reflected by the menu-bar checkbox. + **/ + public void setX1Connected(boolean connected) { + this.x1Connected = connected; + } + + /** Returns the chart. **/ + public Chart2D getChart() { + return this.chart; + } + } diff --git a/src/dna/visualization/components/visualizer/traces/LabelTrace.java b/src/dna/visualization/components/visualizer/traces/LabelTrace.java new file mode 100644 index 00000000..17a89c86 --- /dev/null +++ b/src/dna/visualization/components/visualizer/traces/LabelTrace.java @@ -0,0 +1,254 @@ +package dna.visualization.components.visualizer.traces; + +import java.awt.BasicStroke; +import java.awt.Color; +import java.util.ArrayList; +import java.util.HashMap; + +import dna.labels.Label; +import dna.visualization.components.visualizer.CircularArrayList; +import dna.visualization.components.visualizer.LabelVisualizer; +import info.monitorenter.gui.chart.Chart2D; +import info.monitorenter.gui.chart.ITrace2D; +import info.monitorenter.gui.chart.traces.Trace2DLtd; +import info.monitorenter.gui.chart.traces.painters.TracePainterLine; + +/** + * The LabelTrace represents one entire trace of a single labeler-type pair in a + * label-visualizer. It encapsulates and handles all logical traces that are + * actually being used. + * + * @author Rwilmes + * + */ +public class LabelTrace { + + protected LabelVisualizer parent; + protected Chart2D chart; + protected String key; + + protected int y; + + protected double minX; + protected double maxX; + + protected boolean visible; + protected int size; + protected Color color; + + protected double initTimestamp; + protected double lastTimestamp; + + protected boolean active; + protected HashMap currentTraces; + protected ArrayList removedTraces; + protected HashMap values; + + protected CircularArrayList timestampBuffer; + + public LabelTrace(LabelVisualizer parent, Chart2D chart, String key, int y, int size, Color color, + double initTimestamp) { + this.parent = parent; + this.chart = chart; + this.key = key; + this.y = y; + this.size = size; + this.color = color; + this.visible = true; + + this.initTimestamp = initTimestamp; + this.lastTimestamp = initTimestamp; + + this.minX = initTimestamp; + this.maxX = initTimestamp; + + this.active = false; + this.currentTraces = new HashMap(); + this.removedTraces = new ArrayList(); + this.values = new HashMap(); + this.timestampBuffer = new CircularArrayList(this.parent.getTraceLength()); + } + + /** + * Called for each batch to update the trace. If label was not present in + * the batch the handed over Label-object should be null. + **/ + public void update(double timestamp, Label label) { + this.timestampBuffer.addSilent(timestamp); + + // maybe remove old traces + handleRemovedTraces(); + + if (label != null) { + String value = label.getValue(); + if (active) { + // add points to all traces + for (double y : this.currentTraces.keySet()) { + this.currentTraces.get(y).addPoint(timestamp, y); + this.addValue(timestamp, value); + } + } else { + double y = this.y; + + Trace2DLtd newTrace = new Trace2DLtd(this.parent.getTraceLength()); + newTrace.setColor(this.color); + newTrace.setStroke(new BasicStroke(this.size, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + this.chart.addTrace(newTrace); + newTrace.addTracePainter(new TracePainterLine()); + + // add point t-1 + if (this.lastTimestamp == timestamp) { + newTrace.addPoint(timestamp - 1, y); + this.addValue(timestamp - 1, value); + } else { + newTrace.addPoint(lastTimestamp, y); + this.addValue(lastTimestamp, value); + } + + // add point t + newTrace.addPoint(timestamp, y); + this.addValue(timestamp, value); + + // add trace to current traces + this.currentTraces.put(y, newTrace); + + // mark as active + this.active = true; + } + } else { + + // label is null + if (active) { + // move all current traces to removed traces + this.removeCurrentTraces(); + + // mark as inactive + this.active = false; + } + + this.parent.updateItem(this.key, " -"); + } + + // update last timestamp to this one + this.lastTimestamp = timestamp; + } + + /** Handles removed traces. **/ + protected void handleRemovedTraces() { + double minX = this.getMinX(); + + ArrayList toBeTrashed = new ArrayList(); + + for (ITrace2D trace : this.removedTraces) { + if (trace.getMaxX() >= minX) + break; + else + toBeTrashed.add(trace); + } + + for (ITrace2D trace : toBeTrashed) { + this.removedTraces.remove(trace); + this.chart.removeTrace(trace); + trace.removeAllPoints(); + } + } + + /** Adds a label-value to the internal hashmap. **/ + protected void addValue(double y, String value) { + this.values.put(y, value); + this.parent.updateItem(this.key, value); + } + + /** Clears all traces associated with this object. **/ + public void clear() { + this.removeCurrentTraces(); + for (ITrace2D trace : this.removedTraces) { + trace.removeAllPoints(); + trace.removeAllPointHighlighters(); + this.chart.removeTrace(trace); + } + this.removedTraces.clear(); + this.values.clear(); + this.minX = this.initTimestamp; + this.maxX = this.initTimestamp; + this.lastTimestamp = this.initTimestamp; + this.active = false; + } + + /** Moves all current traces to the removed traces. **/ + protected void removeCurrentTraces() { + for (Double y : this.currentTraces.keySet()) + this.removedTraces.add(this.currentTraces.get(y)); + + this.currentTraces.clear(); + } + + /** Sets the last-timestamp. **/ + public void setLastTimestamp(double timestamp) { + this.lastTimestamp = timestamp; + } + + /** Returns the traces y-mapping. **/ + public int getYMapping() { + return this.y; + } + + /** Sets a new size and updates all traces. **/ + public void setSize(int size) { + this.size = size; + updateTraceSizes(); + } + + /** Updates the size of all traces. **/ + protected void updateTraceSizes() { + for (Double y : this.currentTraces.keySet()) { + ITrace2D trace = this.currentTraces.get(y); + trace.setStroke(new BasicStroke(this.size, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + } + for (ITrace2D trace : this.removedTraces) { + trace.setStroke(new BasicStroke(this.size, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL)); + } + } + + /** Returns whether the traces are currently shown or not **/ + public boolean isVisible() { + return this.visible; + } + + /** Sets the visibility of the traces. **/ + public void setVisible(boolean visible) { + for (Double y : this.currentTraces.keySet()) { + this.currentTraces.get(y).setVisible(visible); + } + for (ITrace2D trace : this.removedTraces) { + trace.setVisible(visible); + } + this.visible = visible; + } + + /** Returns the value for the given timestamp (x-coordinate). **/ + public String getValue(double timestamp) { + String value = this.values.get(timestamp); + if (value == null) + return "null"; + else + return value; + } + + // public double getMinX() { + // return this.minX; + // } + // + // public double getMaxX() { + // return this.maxX; + // } + + public double getMinX() { + return this.timestampBuffer.getHead(); + } + + public double getMaxX() { + return this.timestampBuffer.getTail(); + } + +} diff --git a/src/dna/visualization/config/components/LabelVisualizerConfig.java b/src/dna/visualization/config/components/LabelVisualizerConfig.java new file mode 100644 index 00000000..1abc6b29 --- /dev/null +++ b/src/dna/visualization/config/components/LabelVisualizerConfig.java @@ -0,0 +1,481 @@ +package dna.visualization.config.components; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Font; +import java.lang.reflect.Field; + +import dna.visualization.MainDisplay; +import dna.visualization.config.JSON.JSONArray; +import dna.visualization.config.JSON.JSONObject; + +/** + * A config object for label visualizers. + * + * @author Rwilmes + * + */ +public class LabelVisualizerConfig { + + /** Enumeration for addition policies. **/ + public enum LabelAdditionPolicy { + AUTOMATIC_ADDITION_ALL, AUTOMATIC_ADDITION_LIST, MANUAL + } + + public LabelVisualizerConfig(String name, int traceLength, boolean traceModeLtd, double barThickness, + LabelAdditionPolicy additionPolicy, String[] additionList, int positionX, int positionY, int rowSpan, + int colSpan, Dimension chartSize, String x1AxisTitle, String xAxisType, String xAxisFormat, + String y1AxisTitle, Dimension legendSize, Dimension legendItemSize, Dimension legendItemButtonSize, + Dimension legendItemButtonPanelSize, Dimension legendItemNameLabelSize, Dimension legendItemValueLabelSize, + Font legendItemValueFont, Color legendItemValueFontColor, MenuBarConfig menuBarConfig) { + this.name = name; + this.traceLength = traceLength; + this.traceModeLtd = traceModeLtd; + this.barThickness = barThickness; + this.additionPolicy = additionPolicy; + this.additionList = additionList; + this.positionX = positionX; + this.positionY = positionY; + this.rowSpan = rowSpan; + this.colSpan = colSpan; + this.chartSize = chartSize; + this.x1AxisTitle = x1AxisTitle; + this.xAxisType = xAxisType; + this.xAxisFormat = xAxisFormat; + this.y1AxisTitle = y1AxisTitle; + this.legendSize = legendSize; + this.legendItemSize = legendItemSize; + this.legendItemButtonSize = legendItemButtonSize; + this.legendItemButtonPanelSize = legendItemButtonPanelSize; + this.legendItemNameLabelSize = legendItemNameLabelSize; + this.legendItemValueLabelSize = legendItemValueLabelSize; + this.legendItemValueFont = legendItemValueFont; + this.legendItemValueFontColor = legendItemValueFontColor; + this.menuBarConfig = menuBarConfig; + } + + // general options + private String name; + private int traceLength; + private boolean traceModeLtd; + private double barThickness; + + private LabelAdditionPolicy additionPolicy; + private String[] additionList; + + // position + private int positionX; + private int positionY; + private int rowSpan; + private int colSpan; + + // chart options + private Dimension chartSize; + + // x axis + private String x1AxisTitle; + private String xAxisType; + private String xAxisFormat; + + // y axis + private String y1AxisTitle; + + // legend options + private Dimension legendSize; + private Dimension legendItemSize; + private Dimension legendItemButtonSize; + private Dimension legendItemButtonPanelSize; + private Dimension legendItemNameLabelSize; + private Dimension legendItemValueLabelSize; + private Font legendItemValueFont; + private Color legendItemValueFontColor; + + // menu bar options + private MenuBarConfig menuBarConfig; + + // get methods + public String getName() { + return this.name; + } + + public int getTraceLength() { + return this.traceLength; + } + + public boolean isTraceModeLtd() { + return this.traceModeLtd; + } + + public double getBarThickness() { + return this.barThickness; + } + + public int getPositionX() { + return this.positionX; + } + + public int getPositionY() { + return this.positionY; + } + + public int getRowSpan() { + return this.rowSpan; + } + + public int getColSpan() { + return this.colSpan; + } + + public Dimension getChartSize() { + return this.chartSize; + } + + public String getX1AxisTitle() { + return this.x1AxisTitle; + } + + public String getxAxisType() { + return this.xAxisType; + } + + public String getxAxisFormat() { + return this.xAxisFormat; + } + + public String getY1AxisTitle() { + return this.y1AxisTitle; + } + + public Dimension getLegendSize() { + return this.legendSize; + } + + public Dimension getLegendItemSize() { + return this.legendItemSize; + } + + public Dimension getLegendItemButtonSize() { + return this.legendItemButtonSize; + } + + public Dimension getLegendItemButtonPanelSize() { + return this.legendItemButtonPanelSize; + } + + public Dimension getLegendItemNameLabelSize() { + return this.legendItemNameLabelSize; + } + + public Dimension getLegendItemValueLabelSize() { + return this.legendItemValueLabelSize; + } + + public Font getLegendItemValueFont() { + return this.legendItemValueFont; + } + + public Color getLegendItemValueFontColor() { + return this.legendItemValueFontColor; + } + + public MenuBarConfig getMenuBarConfig() { + return this.menuBarConfig; + } + + public LabelAdditionPolicy getAdditionPolicy() { + return additionPolicy; + } + + public String[] getAdditionList() { + return additionList; + } + + /** Creates a Label visualizer config object from a given json object. **/ + public static LabelVisualizerConfig createLabelVisualizerConfigFromJSONObject(JSONObject o) { + // init + String name; + int traceLength; + boolean traceModeLtd; + double barThickness = 0.5; + LabelAdditionPolicy additionPolicy; + String[] additionList; + + int positionX = -1; + int positionY = -1; + int rowSpan = 1; + int colSpan = 1; + Dimension chartSize; + String x1AxisTitle; + String xAxisType; + String xAxisFormat; + String y1AxisTitle; + Dimension legendSize; + Dimension legendItemSize; + Dimension legendItemButtonSize; + Dimension legendItemButtonPanelSize; + Dimension legendItemNameLabelSize; + Dimension legendItemValueLabelSize; + Font legendItemValueFont; + Color legendItemValueFontColor; + MenuBarConfig menuBarConfig; + + // set default values + if (MainDisplay.DefaultConfig == null) { + // if the defaultconfig is not set, use this default values + name = o.getString("Name"); + traceLength = o.getInt("TraceLength"); + traceModeLtd = o.getBoolean("TraceModeLtd"); + JSONObject chart = o.getJSONObject("Chart"); + chartSize = new Dimension(chart.getInt("Width"), chart.getInt("Height")); + x1AxisTitle = chart.getString("xAxisTitle"); + xAxisType = chart.getString("xAxisType"); + xAxisFormat = chart.getString("xAxisFormat"); + y1AxisTitle = chart.getString("y1AxisTitle"); + barThickness = chart.getDouble("BarThickness"); + + String policyString = o.getString("AdditionPolicy"); + switch (policyString) { + case "all": + additionPolicy = LabelAdditionPolicy.AUTOMATIC_ADDITION_ALL; + break; + case "list": + additionPolicy = LabelAdditionPolicy.AUTOMATIC_ADDITION_LIST; + break; + default: + additionPolicy = LabelAdditionPolicy.MANUAL; + break; + } + + JSONArray additionListArray = o.getJSONArray("AdditionList"); + additionList = new String[additionListArray.length()]; + for (int i = 0; i < additionListArray.length(); i++) { + additionList[i] = additionListArray.getString(i); + } + + JSONObject legend = o.getJSONObject("Legend"); + legendSize = new Dimension(legend.getInt("Width"), legend.getInt("Height")); + JSONObject legendItem = legend.getJSONObject("LegendItem"); + legendItemSize = new Dimension(legendItem.getInt("Width"), legendItem.getInt("Height")); + legendItemButtonSize = new Dimension(legendItem.getInt("Button_Width"), legendItem.getInt("Button_Height")); + legendItemButtonPanelSize = new Dimension(legendItem.getInt("ButtonPanel_Width"), + legendItem.getInt("ButtonPanel_Height")); + legendItemNameLabelSize = new Dimension(legendItem.getInt("NameLabel_Width"), + legendItem.getInt("NameLabel_Height")); + legendItemValueLabelSize = new Dimension(legendItem.getInt("ValueLabel_Width"), + legendItem.getInt("ValueLabel_Height")); + JSONObject fontObject = legendItem.getJSONObject("ValueFont"); + String tempName = fontObject.getString("Name"); + String tempStyle = fontObject.getString("Style"); + int tempSize = fontObject.getInt("Size"); + int style; + switch (tempStyle) { + case "PLAIN": + style = Font.PLAIN; + break; + case "BOLD": + style = Font.BOLD; + break; + case "ITALIC": + style = Font.ITALIC; + break; + default: + style = Font.PLAIN; + break; + } + legendItemValueFont = new Font(tempName, style, tempSize); + legendItemValueFontColor = Color.BLACK; + try { + Field field = Color.class.getField(fontObject.getString("Color")); + legendItemValueFontColor = (Color) field.get(null); + } catch (Exception e) { + } + menuBarConfig = MenuBarConfig.createMenuBarConfigFromJSONObject(o.getJSONObject("MenuBar")); + } else { + // use default config values as defaults + LabelVisualizerConfig defaultConfig = MainDisplay.DefaultConfig.getLabelVisualizerConfigs()[0]; + name = defaultConfig.getName(); + traceLength = defaultConfig.getTraceLength(); + traceModeLtd = defaultConfig.isTraceModeLtd(); + barThickness = defaultConfig.getBarThickness(); + additionPolicy = defaultConfig.getAdditionPolicy(); + additionList = defaultConfig.getAdditionList(); + chartSize = defaultConfig.getChartSize(); + x1AxisTitle = defaultConfig.getX1AxisTitle(); + xAxisType = defaultConfig.getxAxisType(); + xAxisFormat = defaultConfig.getxAxisFormat(); + y1AxisTitle = defaultConfig.getY1AxisTitle(); + legendSize = defaultConfig.getLegendSize(); + legendItemSize = defaultConfig.getLegendItemSize(); + legendItemButtonSize = defaultConfig.getLegendItemButtonSize(); + legendItemButtonPanelSize = defaultConfig.getLegendItemButtonPanelSize(); + legendItemNameLabelSize = defaultConfig.getLegendItemNameLabelSize(); + legendItemValueLabelSize = defaultConfig.getLegendItemValueLabelSize(); + legendItemValueFont = defaultConfig.getLegendItemValueFont(); + legendItemValueFontColor = defaultConfig.getLegendItemValueFontColor(); + menuBarConfig = defaultConfig.getMenuBarConfig(); + } + + // overwrite default values with parsed values + try { + name = o.getString("Name"); + } catch (Exception e) { + } + + try { + traceLength = o.getInt("TraceLength"); + } catch (Exception e) { + } + + try { + traceModeLtd = o.getBoolean("TraceModeLtd"); + } catch (Exception e) { + } + + try { + String policyString = o.getString("AdditionPolicy"); + + switch (policyString) { + case "all": + additionPolicy = LabelAdditionPolicy.AUTOMATIC_ADDITION_ALL; + break; + case "list": + additionPolicy = LabelAdditionPolicy.AUTOMATIC_ADDITION_LIST; + break; + default: + additionPolicy = LabelAdditionPolicy.MANUAL; + break; + } + } catch (Exception e) { + } + + try { + JSONArray additionListArray = o.getJSONArray("AdditionList"); + additionList = new String[additionListArray.length()]; + for (int i = 0; i < additionListArray.length(); i++) { + additionList[i] = additionListArray.getString(i); + } + } catch (Exception e) { + } + + try { + JSONObject positionObject = o.getJSONObject("position"); + try { + positionX = positionObject.getInt("x"); + positionY = positionObject.getInt("y"); + } catch (Exception e) { + } + try { + rowSpan = positionObject.getInt("rowspan"); + colSpan = positionObject.getInt("colspan"); + } catch (Exception e) { + } + } catch (Exception e) { + } + + try { + JSONObject chart = o.getJSONObject("Chart"); + try { + chartSize = new Dimension(chart.getInt("Width"), chart.getInt("Height")); + } catch (Exception e) { + } + + for (String s : JSONObject.getNames(chart)) { + switch (s) { + case "BarThickness": + barThickness = chart.getDouble(s); + break; + case "xAxisTitle": + x1AxisTitle = chart.getString(s); + break; + case "xAxisType": + xAxisType = chart.getString(s); + break; + case "xAxisFormat": + xAxisFormat = chart.getString(s); + break; + case "y1AxisTitle": + y1AxisTitle = chart.getString(s); + break; + } + } + } catch (Exception e) { + } + + // legend + try { + JSONObject legend = o.getJSONObject("Legend"); + legendSize = new Dimension(legend.getInt("Width"), legend.getInt("Height")); + try { + JSONObject legendItem = legend.getJSONObject("LegendItem"); + try { + legendItemSize = new Dimension(legendItem.getInt("Width"), legendItem.getInt("Height")); + } catch (Exception e) { + } + try { + legendItemButtonSize = new Dimension(legendItem.getInt("Button_Width"), + legendItem.getInt("Button_Height")); + } catch (Exception e) { + } + try { + legendItemButtonPanelSize = new Dimension(legendItem.getInt("ButtonPanel_Width"), + legendItem.getInt("ButtonPanel_Height")); + } catch (Exception e) { + } + try { + legendItemNameLabelSize = new Dimension(legendItem.getInt("NameLabel_Width"), + legendItem.getInt("NameLabel_Height")); + } catch (Exception e) { + } + try { + legendItemValueLabelSize = new Dimension(legendItem.getInt("ValueLabel_Width"), + legendItem.getInt("ValueLabel_Height")); + } catch (Exception e) { + } + try { + JSONObject fontObject = legendItem.getJSONObject("ValueFont"); + + String tempName = fontObject.getString("Name"); + String tempStyle = fontObject.getString("Style"); + int tempSize = fontObject.getInt("Size"); + int style; + switch (tempStyle) { + case "PLAIN": + style = Font.PLAIN; + break; + case "BOLD": + style = Font.BOLD; + break; + case "ITALIC": + style = Font.ITALIC; + break; + default: + style = Font.PLAIN; + break; + } + legendItemValueFont = new Font(tempName, style, tempSize); + legendItemValueFontColor = Color.BLACK; + try { + Field field = Color.class.getField(fontObject.getString("Color")); + legendItemValueFontColor = (Color) field.get(null); + } catch (Exception e) { + } + } catch (Exception e) { + } + } catch (Exception e) { + } + } catch (Exception e) { + } + + // parse menu bar config + try { + menuBarConfig = MenuBarConfig.createMenuBarConfigFromJSONObject(o.getJSONObject("MenuBar")); + } catch (Exception e) { + } + + // craft metric visualizer config + return new LabelVisualizerConfig(name, traceLength, traceModeLtd, barThickness, additionPolicy, additionList, + positionX, positionY, rowSpan, colSpan, chartSize, x1AxisTitle, xAxisType, xAxisFormat, y1AxisTitle, + legendSize, legendItemSize, legendItemButtonSize, legendItemButtonPanelSize, legendItemNameLabelSize, + legendItemValueLabelSize, legendItemValueFont, legendItemValueFontColor, menuBarConfig); + } +} diff --git a/src/dna/visualization/config/components/MainDisplayConfig.java b/src/dna/visualization/config/components/MainDisplayConfig.java index d112f76c..1b48e04f 100644 --- a/src/dna/visualization/config/components/MainDisplayConfig.java +++ b/src/dna/visualization/config/components/MainDisplayConfig.java @@ -23,16 +23,13 @@ public class MainDisplayConfig { // constructor - public MainDisplayConfig(String name, Dimension size, - boolean liveDisplayMode, boolean fullscreen, ZipMode zipMode, - String defaultDir, Font defaultFont, Color defaultFontColor, - Dimension buttonSize, String logoDir, Dimension logoSize, - String scalingExpression, Dimension visualizerPanelSize, - Dimension innerVisualizerPanelSize, - StatsDisplayConfig statsDisplayConfig, - LogDisplayConfig[] logDisplayConfigs, - MetricVisualizerConfig[] metricVisualizerConfigs, - MultiScalarVisualizerConfig[] multiScalarVisualizerConfigs) { + public MainDisplayConfig(String name, Dimension size, boolean liveDisplayMode, boolean fullscreen, ZipMode zipMode, + String defaultDir, Font defaultFont, Color defaultFontColor, Dimension buttonSize, String logoDir, + Dimension logoSize, String scalingExpression, Dimension visualizerPanelSize, + Dimension innerVisualizerPanelSize, StatsDisplayConfig statsDisplayConfig, + LogDisplayConfig[] logDisplayConfigs, MetricVisualizerConfig[] metricVisualizerConfigs, + MultiScalarVisualizerConfig[] multiScalarVisualizerConfigs, + LabelVisualizerConfig[] labelVisualizerConfigs) { this.name = name; this.size = size; this.liveDisplayMode = liveDisplayMode; @@ -51,6 +48,7 @@ public MainDisplayConfig(String name, Dimension size, this.logDisplayConfigs = logDisplayConfigs; this.metricVisualizerConfigs = metricVisualizerConfigs; this.multiScalarVisualizerConfigs = multiScalarVisualizerConfigs; + this.labelVisualizerConfigs = labelVisualizerConfigs; } private String name; @@ -73,6 +71,7 @@ public MainDisplayConfig(String name, Dimension size, private LogDisplayConfig[] logDisplayConfigs; private MetricVisualizerConfig[] metricVisualizerConfigs; private MultiScalarVisualizerConfig[] multiScalarVisualizerConfigs; + private LabelVisualizerConfig[] labelVisualizerConfigs; // get methods public String getName() { @@ -169,6 +168,10 @@ public MultiScalarVisualizerConfig[] getMultiScalarVisualizerConfigs() { return this.multiScalarVisualizerConfigs; } + public LabelVisualizerConfig[] getLabelVisualizerConfigs() { + return this.labelVisualizerConfigs; + } + /* * STATIC METHODS */ @@ -189,8 +192,7 @@ public static MainDisplayConfig getDisplayConfig() { } /** Creates a main display config object from a given json object. **/ - public static MainDisplayConfig createMainDisplayConfigFromJSONObject( - JSONObject o) { + public static MainDisplayConfig createMainDisplayConfigFromJSONObject(JSONObject o) { // init String name; Dimension size; @@ -212,6 +214,7 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( LogDisplayConfig[] logDisplayConfigs = new LogDisplayConfig[0]; MetricVisualizerConfig[] metricVisualizerConfigs = new MetricVisualizerConfig[0]; MultiScalarVisualizerConfig[] multiScalarVisualizerConfigs = new MultiScalarVisualizerConfig[0]; + LabelVisualizerConfig[] labelVisualizerConfigs = new LabelVisualizerConfig[0]; // set default values if (MainDisplay.DefaultConfig == null) { @@ -257,24 +260,19 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( defaultFont = new Font(tempName, style, tempSize); defaultFontColor = Color.BLACK; try { - Field field = Color.class.getField(fontObject - .getString("Color")); + Field field = Color.class.getField(fontObject.getString("Color")); defaultFontColor = (Color) field.get(null); } catch (Exception e) { } JSONObject buttonObject = o.getJSONObject("Buttons"); - buttonSize = new Dimension(buttonObject.getInt("Width"), - buttonObject.getInt("Height")); + buttonSize = new Dimension(buttonObject.getInt("Width"), buttonObject.getInt("Height")); JSONObject logoObject = o.getJSONObject("Logo"); logoDir = logoObject.getString("Dir"); - logoSize = new Dimension(logoObject.getInt("Width"), - logoObject.getInt("Height")); + logoSize = new Dimension(logoObject.getInt("Width"), logoObject.getInt("Height")); scalingExpression = o.getString("Scaling"); JSONObject visPanelObject = o.getJSONObject("VisualizerPanel"); - visualizerPanelSize = new Dimension(visPanelObject.getInt("Width"), - visPanelObject.getInt("Height")); - innerVisualizerPanelSize = new Dimension( - visPanelObject.getInt("InnerWidth"), + visualizerPanelSize = new Dimension(visPanelObject.getInt("Width"), visPanelObject.getInt("Height")); + innerVisualizerPanelSize = new Dimension(visPanelObject.getInt("InnerWidth"), visPanelObject.getInt("InnerHeight")); } else { // use default config values as defaults @@ -289,12 +287,9 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( buttonSize = MainDisplay.DefaultConfig.getButtonSize(); logoDir = MainDisplay.DefaultConfig.getLogoDir(); logoSize = MainDisplay.DefaultConfig.getLogoSize(); - scalingExpression = MainDisplay.DefaultConfig - .getScalingExpression(); - visualizerPanelSize = MainDisplay.DefaultConfig - .getVisualizerPanelSize(); - innerVisualizerPanelSize = MainDisplay.DefaultConfig - .getInnerVisualizerPanelSize(); + scalingExpression = MainDisplay.DefaultConfig.getScalingExpression(); + visualizerPanelSize = MainDisplay.DefaultConfig.getVisualizerPanelSize(); + innerVisualizerPanelSize = MainDisplay.DefaultConfig.getInnerVisualizerPanelSize(); } // overwrite default values with parsed values @@ -374,8 +369,7 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( } catch (Exception e) { } try { - Field field = Color.class.getField(fontObject - .getString("Color")); + Field field = Color.class.getField(fontObject.getString("Color")); defaultFontColor = (Color) field.get(null); } catch (Exception e) { } @@ -389,8 +383,7 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( try { JSONObject buttonObject = o.getJSONObject("Buttons"); - buttonSize = new Dimension(buttonObject.getInt("Width"), - buttonObject.getInt("Height")); + buttonSize = new Dimension(buttonObject.getInt("Width"), buttonObject.getInt("Height")); } catch (Exception e) { } @@ -401,8 +394,7 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( } catch (Exception e) { } try { - logoSize = new Dimension(logoObject.getInt("Width"), - logoObject.getInt("Height")); + logoSize = new Dimension(logoObject.getInt("Width"), logoObject.getInt("Height")); } catch (Exception e) { } } catch (Exception e) { @@ -411,14 +403,11 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( try { JSONObject visPanelObject = o.getJSONObject("VisualizerPanel"); try { - visualizerPanelSize = new Dimension( - visPanelObject.getInt("Width"), - visPanelObject.getInt("Height")); + visualizerPanelSize = new Dimension(visPanelObject.getInt("Width"), visPanelObject.getInt("Height")); } catch (Exception e) { } try { - innerVisualizerPanelSize = new Dimension( - visPanelObject.getInt("InnerWidth"), + innerVisualizerPanelSize = new Dimension(visPanelObject.getInt("InnerWidth"), visPanelObject.getInt("InnerHeight")); } catch (Exception e) { } @@ -427,8 +416,7 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( try { statsDisplayConfig = StatsDisplayConfig - .creatStatsDisplayConfigFromJSONObject(o - .getJSONObject("StatsDisplayConfig")); + .creatStatsDisplayConfigFromJSONObject(o.getJSONObject("StatsDisplayConfig")); } catch (Exception e) { } @@ -439,9 +427,8 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( for (String logDis : JSONObject.getNames(mvo)) { try { - logDisplayConfigsArray.add(LogDisplayConfig - .createLogDisplayConfigFromJSONObject(mvo - .getJSONObject(logDis))); + logDisplayConfigsArray + .add(LogDisplayConfig.createLogDisplayConfigFromJSONObject(mvo.getJSONObject(logDis))); } catch (Exception e) { } } @@ -459,15 +446,14 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( for (String metricVis : JSONObject.getNames(mvo)) { try { metricVisualizerConfigsArray.add(MetricVisualizerConfig - .createMetricVisualizerConfigFromJSONObject(mvo - .getJSONObject(metricVis))); + .createMetricVisualizerConfigFromJSONObject(mvo.getJSONObject(metricVis))); } catch (Exception e) { + e.printStackTrace(); } } } catch (Exception e) { } - metricVisualizerConfigs = new MetricVisualizerConfig[metricVisualizerConfigsArray - .size()]; + metricVisualizerConfigs = new MetricVisualizerConfig[metricVisualizerConfigsArray.size()]; for (int i = 0; i < metricVisualizerConfigsArray.size(); i++) { metricVisualizerConfigs[i] = metricVisualizerConfigsArray.get(i); } @@ -478,28 +464,42 @@ public static MainDisplayConfig createMainDisplayConfigFromJSONObject( JSONObject mvo = o.getJSONObject("MultiScalarVisualizerConfigs"); for (String multiScalarVis : JSONObject.getNames(mvo)) { try { - multiScalarVisualizerConfigsArray - .add(MultiScalarVisualizerConfig - .createMultiScalarVisualizerConfigFromJSONObject(mvo - .getJSONObject(multiScalarVis))); + multiScalarVisualizerConfigsArray.add(MultiScalarVisualizerConfig + .createMultiScalarVisualizerConfigFromJSONObject(mvo.getJSONObject(multiScalarVis))); } catch (Exception e) { + e.printStackTrace(); } } } catch (Exception e) { } - multiScalarVisualizerConfigs = new MultiScalarVisualizerConfig[multiScalarVisualizerConfigsArray - .size()]; + multiScalarVisualizerConfigs = new MultiScalarVisualizerConfig[multiScalarVisualizerConfigsArray.size()]; for (int i = 0; i < multiScalarVisualizerConfigsArray.size(); i++) { - multiScalarVisualizerConfigs[i] = multiScalarVisualizerConfigsArray - .get(i); + multiScalarVisualizerConfigs[i] = multiScalarVisualizerConfigsArray.get(i); + } + + // gather label visualizer configs + ArrayList labelVisualizerConfigsArray = new ArrayList(); + try { + JSONObject mvo = o.getJSONObject("LabelVisualizerConfigs"); + for (String labelVis : JSONObject.getNames(mvo)) { + try { + labelVisualizerConfigsArray.add(LabelVisualizerConfig + .createLabelVisualizerConfigFromJSONObject(mvo.getJSONObject(labelVis))); + } catch (Exception e) { + e.printStackTrace(); + } + } + } catch (Exception e) { + } + labelVisualizerConfigs = new LabelVisualizerConfig[labelVisualizerConfigsArray.size()]; + for (int i = 0; i < labelVisualizerConfigsArray.size(); i++) { + labelVisualizerConfigs[i] = labelVisualizerConfigsArray.get(i); } - return new MainDisplayConfig(name, size, liveDisplayMode, fullscreen, - zipMode, defaultDir, defaultFont, defaultFontColor, buttonSize, - logoDir, logoSize, scalingExpression, visualizerPanelSize, - innerVisualizerPanelSize, statsDisplayConfig, - logDisplayConfigs, metricVisualizerConfigs, - multiScalarVisualizerConfigs); + return new MainDisplayConfig(name, size, liveDisplayMode, fullscreen, zipMode, defaultDir, defaultFont, + defaultFontColor, buttonSize, logoDir, logoSize, scalingExpression, visualizerPanelSize, + innerVisualizerPanelSize, statsDisplayConfig, logDisplayConfigs, metricVisualizerConfigs, + multiScalarVisualizerConfigs, labelVisualizerConfigs); } /** @@ -524,8 +524,7 @@ public static MainDisplayConfig readConfig(String path) { } } else { if (IOUtils.isRunFromJar()) { - Log.info("'" + path - + "-> ' not found. Attempting to read from .jar"); + Log.info("'" + path + "-> ' not found. Attempting to read from .jar"); try { jar = IOUtils.getExecutionJarFile(); is = IOUtils.getInputStreamFromJar(jar, path, true); @@ -541,8 +540,7 @@ public static MainDisplayConfig readConfig(String path) { JSONTokener tk = new JSONTokener(is); JSONObject jsonConfig = new JSONObject(tk); config = MainDisplayConfig - .createMainDisplayConfigFromJSONObject(jsonConfig - .getJSONObject("MainDisplayConfig")); + .createMainDisplayConfigFromJSONObject(jsonConfig.getJSONObject("MainDisplayConfig")); try { is.close(); diff --git a/src/dna/visualization/config/components/MenuBarConfig.java b/src/dna/visualization/config/components/MenuBarConfig.java index d12b7dda..a34b7118 100644 --- a/src/dna/visualization/config/components/MenuBarConfig.java +++ b/src/dna/visualization/config/components/MenuBarConfig.java @@ -11,29 +11,36 @@ public class MenuBarConfig { // constructor - public MenuBarConfig(Dimension size, Font coordsFont, - Color coordsFontColor, boolean addCoordsPanel, - boolean addIntervalPanel, boolean addXOptionsPanel, + public MenuBarConfig(boolean visible, Dimension size, Font coordsFont, Color coordsFontColor, + boolean addCoordsPanel, boolean addIntervalPanel, boolean x1AxisConnected, boolean addXOptionsPanel, boolean addYOptionsPanel) { + this.visible = visible; this.size = size; this.coordsFont = coordsFont; this.coordsFontColor = coordsFontColor; this.addCoordsPanel = addCoordsPanel; this.addIntervalPanel = addIntervalPanel; + this.x1AxisConnected = x1AxisConnected; this.addXOptionsPanel = addXOptionsPanel; this.addYOptionsPanel = addYOptionsPanel; } // variables + private boolean visible; private Dimension size; private Font coordsFont; private Color coordsFontColor; private boolean addCoordsPanel; private boolean addIntervalPanel; + private boolean x1AxisConnected; private boolean addXOptionsPanel; private boolean addYOptionsPanel; // get methods + public boolean isVisible() { + return this.visible; + } + public Dimension getSize() { return this.size; } @@ -54,6 +61,10 @@ public boolean isAddIntervalPanel() { return this.addIntervalPanel; } + public boolean isX1AxisConnected() { + return this.x1AxisConnected; + } + public boolean isAddXOptionsPanel() { return this.addXOptionsPanel; } @@ -69,20 +80,24 @@ public void setSize(Dimension size) { /** creates a menubar config object from a given json object **/ public static MenuBarConfig createMenuBarConfigFromJSONObject(JSONObject o) { // init + boolean visible; Dimension size; Font coordsFont; Color coordsFontColor; boolean addCoordsPanel; boolean addIntervalPanel; + boolean x1AxisConnected; boolean addXOptionsPanel; boolean addYOptionsPanel; // set default values if (MainDisplay.DefaultConfig == null) { // if the defaultconfig is not set, read default values + visible = o.getBoolean("visible"); size = new Dimension(o.getInt("Width"), o.getInt("Height")); addCoordsPanel = o.getBoolean("showCoordsPanel"); addIntervalPanel = o.getBoolean("showIntervalPanel"); + x1AxisConnected = true; addXOptionsPanel = o.getBoolean("showXOptionsPanel"); addYOptionsPanel = o.getBoolean("showYOptionsPanel"); JSONObject fontObject = o.getJSONObject("CoordsFont"); @@ -107,38 +122,37 @@ public static MenuBarConfig createMenuBarConfigFromJSONObject(JSONObject o) { coordsFont = new Font(tempName, style, tempSize); coordsFontColor = Color.BLACK; try { - Field field = Color.class.getField(fontObject - .getString("Color")); + Field field = Color.class.getField(fontObject.getString("Color")); coordsFontColor = (Color) field.get(null); } catch (Exception e) { } - return new MenuBarConfig(size, coordsFont, coordsFontColor, - addCoordsPanel, addIntervalPanel, addXOptionsPanel, - addYOptionsPanel); + return new MenuBarConfig(visible, size, coordsFont, coordsFontColor, addCoordsPanel, addIntervalPanel, + x1AxisConnected, addXOptionsPanel, addYOptionsPanel); } else { // use default config values as defaults - size = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0] - .getMenuBarConfig().getSize(); - addCoordsPanel = MainDisplay.DefaultConfig - .getMetricVisualizerConfigs()[0].getMenuBarConfig() + size = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getMenuBarConfig().getSize(); + visible = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getMenuBarConfig().isVisible(); + addCoordsPanel = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getMenuBarConfig() .isAddCoordsPanel(); - addIntervalPanel = MainDisplay.DefaultConfig - .getMetricVisualizerConfigs()[0].getMenuBarConfig() + addIntervalPanel = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getMenuBarConfig() .isAddIntervalPanel(); - addXOptionsPanel = MainDisplay.DefaultConfig - .getMetricVisualizerConfigs()[0].getMenuBarConfig() + x1AxisConnected = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getMenuBarConfig() + .isX1AxisConnected(); + addXOptionsPanel = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getMenuBarConfig() .isAddXOptionsPanel(); - addYOptionsPanel = MainDisplay.DefaultConfig - .getMetricVisualizerConfigs()[0].getMenuBarConfig() + addYOptionsPanel = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getMenuBarConfig() .isAddYOptionsPanel(); - coordsFont = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0] - .getMenuBarConfig().getCoordsFont(); - coordsFontColor = MainDisplay.DefaultConfig - .getMetricVisualizerConfigs()[0].getMenuBarConfig() + coordsFont = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getMenuBarConfig().getCoordsFont(); + coordsFontColor = MainDisplay.DefaultConfig.getMetricVisualizerConfigs()[0].getMenuBarConfig() .getCoordsFontColor(); } // overwrite default values with parsed values + try { + visible = o.getBoolean("visible"); + } catch (Exception e) { + } + try { size = new Dimension(o.getInt("Width"), o.getInt("Height")); } catch (Exception e) { @@ -187,16 +201,14 @@ public static MenuBarConfig createMenuBarConfigFromJSONObject(JSONObject o) { coordsFont = new Font(tempName, style, tempSize); coordsFontColor = Color.BLACK; try { - Field field = Color.class.getField(fontObject - .getString("Color")); + Field field = Color.class.getField(fontObject.getString("Color")); coordsFontColor = (Color) field.get(null); } catch (Exception e) { } } catch (Exception e) { } - return new MenuBarConfig(size, coordsFont, coordsFontColor, - addCoordsPanel, addIntervalPanel, addXOptionsPanel, - addYOptionsPanel); + return new MenuBarConfig(visible, size, coordsFont, coordsFontColor, addCoordsPanel, addIntervalPanel, + x1AxisConnected, addXOptionsPanel, addYOptionsPanel); } }