Ejemplo n.º 1
0
 private void setLandscapeCommon(final List<Pair<String, Float>> landscape) {
   this.landscape = landscape;
   if (!stkLineChartZoom.empty()) {
     pnlLineChart.setViewport(stkLineChartZoom.get(0));
     stkLineChartZoom.clear();
   }
   if (landscape == null) {
     landscapeMin = landscapeMax = null;
   } else {
     float min = Float.POSITIVE_INFINITY;
     float max = Float.NEGATIVE_INFINITY;
     for (final Pair<String, Float> p : landscape) {
       final float fitness = p.getSecond();
       if (Float.isInfinite(fitness)) {
         continue;
       }
       if (fitness < min) {
         min = fitness;
       }
       if (fitness > max) {
         max = fitness;
       }
     }
     landscapeMin = new Float(min - max * 0.05);
     landscapeMax = new Float(max * 1.05);
   }
   if (!stkHistogramZoom.empty()) {
     pnlHistogram.setViewport(stkHistogramZoom.get(0));
     stkHistogramZoom.clear();
   }
   if (useMinMax && (landscapeMin != null) && (landscapeMax != null)) {
     pnlHistogram.setBins(
         binLandscape(((Number) spnBins.getValue()).intValue()),
         landscapeMin.floatValue(),
         landscapeMax.floatValue());
   } else {
     pnlHistogram.setBins(binLandscape(((Number) spnBins.getValue()).intValue()));
   }
   // cboDisplayType.setSelectedIndex(0);
   if (landscape == null) {
     txaRaw.setText("");
   } else {
     final StringBuffer b = new StringBuffer();
     if (rawTextComparator != null) {
       Collections.sort(landscape, rawTextComparator);
     }
     b.append(getXAxisLabel());
     b.append('\t');
     b.append(getYAxisLabel());
     b.append('\n');
     for (final Pair<String, Float> p : landscape) {
       b.append(p.getFirst());
       b.append('\t');
       b.append(Float.toString(p.getSecond()));
       b.append('\n');
     }
     txaRaw.setText(b.toString());
     txaRaw.select(0, 0);
   }
 }
Ejemplo n.º 2
0
 private long[] binLandscape(final int nBins) {
   if (landscape == null) {
     return null;
   }
   final long[] bins = new long[nBins];
   for (final Pair<String, Float> p : landscape) {
     float fitness = p.getSecond();
     if (Float.isInfinite(fitness)) {
       continue;
     }
     if (useMinMax && (landscapeMin != null) && (landscapeMax != null)) {
       fitness = (fitness - landscapeMin) / (landscapeMax - landscapeMin);
     }
     if (fitness >= 1.0) {
       bins[bins.length - 1]++;
     } else {
       bins[(int) (fitness * nBins)]++;
     }
   }
   return bins;
 }
Ejemplo n.º 3
0
 @SuppressWarnings("unchecked")
 private void checkEnabled(final boolean enabled) {
   cboDisplayType.setEnabled(enabled);
   cmdSave.setEnabled(enabled);
   lblBins.setEnabled(enabled);
   spnBins.setEnabled(enabled);
   pnlLineChart.setSelectionEnabled(enabled);
   pnlHistogram.setSelectionEnabled(enabled);
   final Pair<String, Component> p = (Pair<String, Component>) cboDisplayType.getSelectedItem();
   if (enabled) {
     boolean zoomed = false;
     if (p.getSecond() == scpLineChart) {
       zoomed = !stkLineChartZoom.empty();
     } else if (p.getSecond() == scpHistogram) {
       zoomed = !stkHistogramZoom.empty();
     }
     cmdUnzoom.setEnabled(zoomed);
     cmdResetView.setEnabled(zoomed);
   } else {
     cmdUnzoom.setEnabled(false);
     cmdResetView.setEnabled(false);
   }
 }
Ejemplo n.º 4
0
 @SuppressWarnings("unchecked")
 public void itemStateChanged(final ItemEvent e) {
   final Pair<String, Component> p = (Pair<String, Component>) e.getItem();
   crdDisplay.show(pnlDisplay, p.toString());
   crdDisplayControls.show(pnlDisplayControls, p.toString());
   if (p.getSecond() == scpLineChart) {
     crdZoomControls.show(pnlZoomControls, "Zoomable");
   } else if (p.getSecond() == scpHistogram) {
     crdZoomControls.show(pnlZoomControls, "Zoomable");
   } else if (p.getSecond() == scpRaw) {
     crdZoomControls.show(pnlZoomControls, "Unzoomable");
   }
   checkEnabled(isEnabled());
 }
Ejemplo n.º 5
0
 public void actionPerformed(final ActionEvent e) {
   @SuppressWarnings("unchecked")
   final Pair<String, Component> p = (Pair<String, Component>) cboDisplayType.getSelectedItem();
   AbstractChart chart = null;
   Dimension chartSize = null;
   Stack<Rectangle2D> stack = null;
   String saveTitle = null;
   List<? extends FileFilter> filters = null;
   if (p.getSecond() == scpLineChart) {
     stack = stkLineChartZoom;
     chart = pnlLineChart;
     chartSize = new Dimension(1200, 400);
     saveTitle = "Save Landscape Line Chart";
     filters = FileSaver.fltGraphics;
   } else if (p.getSecond() == scpHistogram) {
     stack = stkHistogramZoom;
     chart = pnlHistogram;
     chartSize = new Dimension(1000, 1000);
     saveTitle = "Save Landscape Histogram";
     filters = FileSaver.fltGraphics;
   } else {
     saveTitle = "Save Landscape Raw Text";
     filters = FileSaver.fltText;
   }
   if ((e.getSource() == cmdUnzoom) && (stack != null) && (chart != null)) {
     final Rectangle2D viewport = stack.pop();
     chart.setViewport(viewport);
     checkEnabled(isEnabled());
   } else if ((e.getSource() == cmdResetView) && (stack != null) && (chart != null)) {
     chart.setViewport(stack.firstElement());
     stack.clear();
     checkEnabled(isEnabled());
   } else if (e.getSource() == cmdSave) {
     try {
       final Pair<File, FileFilter> ff =
           FileSaver.getSaveFile(getTopLevelAncestor(), saveTitle, filters);
       if (ff == null) {
         return;
       }
       if ((chart == null) || (chartSize == null)) {
         FileSaver.saveText(txaRaw.getText(), ff.getFirst());
       } else if (ff.getSecond() == FileSaver.epsFilter) {
         final Writer w = new FileWriter(ff.getFirst());
         w.write(chart.getEpsText(chartSize.width, chartSize.height));
         w.flush();
         w.close();
       } else if (ff.getSecond() == FileSaver.pngFilter) {
         ImageIO.write(chart.getImage(chartSize.width, chartSize.height), "png", ff.getFirst());
       } else if (ff.getSecond() == FileSaver.jpgFilter) {
         ImageIO.write(chart.getImage(chartSize.width, chartSize.height), "jpeg", ff.getFirst());
       }
     } catch (final IOException ex) {
       Utility.logException(ex);
       JOptionPane.showMessageDialog(
           getTopLevelAncestor(), ex.getMessage(), "I/O Error", JOptionPane.ERROR_MESSAGE);
     }
   } else {
     throw new IllegalArgumentException(e.getActionCommand());
   }
 }