public Component getTableCellRendererComponent(
     JTable aTable,
     Object aNumberValue,
     boolean aIsSelected,
     boolean aHasFocus,
     int aRow,
     int aColumn) {
   /*
    * Implementation Note :
    * It is important that no "new" be present in this
    * implementation (excluding exceptions):
    * if the table is large, then a large number of objects would be
    * created during rendering.
    */
   if (aNumberValue == null) return this;
   Component renderer =
       super.getTableCellRendererComponent(
           aTable, aNumberValue, aIsSelected, aHasFocus, aRow, aColumn);
   Number value = (Number) aNumberValue;
   if (value.doubleValue() < 0) {
     renderer.setForeground(Color.red);
   } else {
     renderer.setForeground(fDarkGreen);
   }
   return this;
 }
 public void saveDisplayObjectType() {
   DOTPoint newDOTPoint =
       (DOTPoint) _dotDefinitionDialogFrame.getScratchDisplayObjectType().getCopy(null);
   final String name = _dotDefinitionDialogFrame.getNameText();
   if ((name == null) || (name.length() == 0)) {
     JOptionPane.showMessageDialog(
         new JFrame(), "Bitte geben Sie einen Namen an!", "Fehler", JOptionPane.ERROR_MESSAGE);
     return;
   }
   if (!_dotDefinitionDialogFrame.isReviseOnly()) {
     if (_dotDefinitionDialogFrame.getDotManager().containsDisplayObjectType(name)) {
       JOptionPane.showMessageDialog(
           new JFrame(),
           "Ein Darstellungstyp mit diesem Namen existiert bereits!",
           "Fehler",
           JOptionPane.ERROR_MESSAGE);
       return;
     }
   }
   newDOTPoint.setName(name);
   newDOTPoint.setInfo(_dotDefinitionDialogFrame.getInfoText());
   final Object value = _translationFactorSpinner.getValue();
   if (value instanceof Number) {
     final Number number = (Number) value;
     newDOTPoint.setTranslationFactor(number.doubleValue());
   }
   newDOTPoint.setJoinByLine(_joinByLineCheckBox.isSelected());
   _dotDefinitionDialogFrame.getDotManager().saveDisplayObjectType(newDOTPoint);
   _dotDefinitionDialogFrame.setDisplayObjectType(newDOTPoint, true);
 }
Beispiel #3
0
    /**
     * Creates a {@link RenderedImage} representing the results of an imaging operation for a given
     * {@link ParameterBlock} and {@link RenderingHints}.
     */
    @Override
    public RenderedImage create(final ParameterBlock param, final RenderingHints hints) {
      final RenderedImage image = (RenderedImage) param.getSource(0);
      final Number srcVal = (Number) param.getObjectParameter(0);
      final Number destVal = (Number) param.getObjectParameter(1);

      return new RecodeRaster(image, srcVal.doubleValue(), destVal.doubleValue(), hints);
    }
Beispiel #4
0
  private static float calculateMax(Number[] yValues) {
    float max = yValues[0].floatValue();
    for (Number d : yValues) {
      max = Math.max(max, d.floatValue());
    }

    return max;
  }
Beispiel #5
0
  private static float calculateMin(Number[] yValues) {
    float min = yValues[0].floatValue();
    for (Number d : yValues) {
      min = Math.min(min, d.floatValue());
    }

    return min;
  }
Beispiel #6
0
 /** Return a double parsed from the given string, possibly formatted with a "%" sign */
 public static double parseDouble(String val) throws NumberFormatException, ParseException {
   NumberFormat formatPercent = NumberFormat.getPercentInstance(Locale.US); // for zoom factor
   if (val.indexOf("%") == -1) { // not in percent format !
     return Double.parseDouble(val);
   }
   // else it's a percent format -> parse it
   Number n = formatPercent.parse(val);
   return n.doubleValue();
 }
 public int compare(Number o1, Number o2) {
   final double d1 = o1.doubleValue();
   final double d2 = o2.doubleValue();
   if (d1 < d2) {
     return -1;
   }
   if (d1 == d2) {
     return 0;
   }
   return 1;
 }
Beispiel #8
0
  /**
   * Called to create a map the parent of each bookmark.
   *
   * @param parent top level bookmark.
   * @param parentMap map to add children to.
   * @param pagenoVector vector of page numbers.
   * @param depth object indicating bookmark depth.
   */
  protected void mapChildren(
      final Bookmark parent,
      final Hashtable parentMap,
      final Vector pagenoVector,
      final Number depth) {
    getDepthMap().put(parent, depth);

    final int pageno = parent.getPageno();

    if (pageno >= 0) {
      while (pageno >= pagenoVector.size()) {
        pagenoVector.addElement(null);
      }

      pagenoVector.setElementAt(parent, pageno);
    }

    final Enumeration e = parent.elements();

    if (e.hasMoreElements()) {
      final Number childDepth = new Integer(depth.intValue() + 1);

      do {
        final Bookmark child = (Bookmark) e.nextElement();
        parentMap.put(child, parent);
        mapChildren(child, parentMap, pagenoVector, childDepth);
      } while (e.hasMoreElements());
    }
  }
  private static boolean isLengthDefined(final StyleKey key, final StyleSheet styleSheet) {
    if (key.isInheritable()) {
      if (styleSheet.isLocalKey(key) == false) {
        return false;
      }
    }

    final Object o = styleSheet.getStyleProperty(key, null);
    if (o == null) {
      return false;
    }
    if (o instanceof Number == false) {
      return false;
    }
    final Number n = (Number) o;
    return n.doubleValue() != 0;
  }
Beispiel #10
0
 /**
  * Set the value of this object as a Number.
  *
  * @return True if the value was set.
  */
 public boolean setCurrentAccessibleValue(Number n) {
   // TIGER - 4422535
   if (n == null) {
     return false;
   }
   setValue(n.intValue());
   return true;
 }
Beispiel #11
0
 /**
  * @return a double parsed from the value associated with the given key in the given Properties.
  *     returns "def" in key wasn't found, or if a parsing error occured. If "value" contains a "%"
  *     sign, we use a <code>NumberFormat.getPercentInstance</code> to convert it to a double.
  */
 public static double parseProperty(Properties preferences, String key, double def) {
   NumberFormat formatPercent = NumberFormat.getPercentInstance(Locale.US); // for zoom factor
   String val = preferences.getProperty(key);
   if (val == null) return def;
   if (val.indexOf("%") == -1) { // not in percent format !
     try {
       return Double.parseDouble(val);
     } catch (NumberFormatException nfe) {
       nfe.printStackTrace();
       return def;
     }
   }
   // else it's a percent format -> parse it
   try {
     Number n = formatPercent.parse(val);
     return n.doubleValue();
   } catch (ParseException ex) {
     ex.printStackTrace();
     return def;
   }
 }
  @Override
  public void paintStateValue(Graphics2D g2, State s, double value, float cWidth, float cHeight) {

    Number x = (Number) s.get(xKey);
    Number y = (Number) s.get(yKey);

    float xval;
    float yval;
    float width;
    float height;

    width = cWidth / (float) (xRange.span() / xWidth);
    height = cHeight / (float) (yRange.span() / yWidth);

    float normX = (float) xRange.norm(x.doubleValue());
    xval = normX * cWidth;

    float normY = (float) yRange.norm(y.doubleValue());
    yval = cHeight - height - normY * cHeight;

    Color col = this.colorBlend.color(value);
    g2.setColor(col);

    g2.fill(new Rectangle2D.Float(xval, yval, width, height));

    if (this.renderValueString) {

      g2.setColor(this.vsFontColor);
      g2.setFont(new Font("sansserif", Font.BOLD, this.vsFontSize));
      String fstring = String.format("%." + this.vsPrecision + "f", value);

      float sxval = xval + this.vsOffsetFromLeft * width;
      float syval = yval + this.vsOffsetFromTop * height;

      g2.drawString(fstring, sxval, syval);
    }
  }
Beispiel #13
0
  private void updateDataSet() {
    if (!isInitialized) {
      return;
    }

    dataset.removeAllSeries();

    double dx = 0.5 * dataSourceConfig.boxSize;

    if (profileData != null) {
      final float[] sampleValues = profileData.getSampleValues();
      final float[] sampleSigmas = profileData.getSampleSigmas();
      XYIntervalSeries series =
          new XYIntervalSeries(
              getRaster() != null ? getRaster().getName() : DEFAULT_SAMPLE_DATASET_NAME);
      for (int x = 0; x < sampleValues.length; x++) {
        final float y = sampleValues[x];
        final float dy = sampleSigmas[x];
        series.add(x, x - dx, x + dx, y, y - dy, y + dy);
      }
      dataset.addSeries(series);

      if (dataSourceConfig.useCorrelativeData
          && dataSourceConfig.pointDataSource != null
          && dataSourceConfig.dataField != null) {

        XYIntervalSeries corrSeries =
            new XYIntervalSeries(
                getCorrelativeDataLabel(
                    dataSourceConfig.pointDataSource, dataSourceConfig.dataField));
        int[] shapeVertexIndexes = profileData.getShapeVertexIndexes();
        SimpleFeature[] simpleFeatures =
            dataSourceConfig.pointDataSource.getFeatureCollection().toArray(new SimpleFeature[0]);

        if (shapeVertexIndexes.length == simpleFeatures.length) {
          int fieldIndex =
              getAttributeIndex(dataSourceConfig.pointDataSource, dataSourceConfig.dataField);
          if (fieldIndex != -1) {
            for (int i = 0; i < simpleFeatures.length; i++) {
              Number attribute = (Number) simpleFeatures[i].getAttribute(fieldIndex);
              if (attribute != null) {
                final double x = shapeVertexIndexes[i];
                final double y = attribute.doubleValue();
                corrSeries.add(x, x, x, y, y, y);
              }
            }
            dataset.addSeries(corrSeries);
          }
        } else {
          System.out.println("Weird things happened:");
          System.out.println("  shapeVertexIndexes.length = " + shapeVertexIndexes.length);
          System.out.println("  simpleFeatures.length     = " + simpleFeatures.length);
        }
      }

      profilePlotDisplay.restoreAutoBounds();
      xAxisRangeControl
          .getBindingContext()
          .setComponentsEnabled(
              PROPERTY_NAME_MARK_SEGMENTS, profileData.getShapeVertices().length > 2);
    }
  }
 public double getStrokeMiterLimitFactor() {
   Number value = (Number) getAttribute(AttributeKeys.STROKE_MITER_LIMIT);
   return (value != null) ? value.doubleValue() : 10f;
 }
Beispiel #15
0
  /**
   * Draw a sparkline with x axis and y axis values, and pre-calculated min and max of the y axis
   * values. Use this when you already have min/max values calculated and want to avoid extra
   * calculations by <code>SparklineGraph</code> X values <b>must</b> be ordered and not repeated.
   *
   * @param xValues X axis values
   * @param yValues Y axis values
   * @param yMinValue Minimum value of the Y axis, should be correct
   * @param yMaxValue Maximum value of the Y axis, should be correct
   * @param parameters Rendering parameters
   * @return Image of the sparkline
   */
  public static BufferedImage draw(
      Number[] xValues,
      Number[] yValues,
      Number yMinValue,
      Number yMaxValue,
      SparklineParameters parameters) {
    if (parameters == null) {
      throw new IllegalArgumentException("parameters can't be null");
    }

    if (yValues == null || yValues.length < 2) {
      throw new IllegalArgumentException("Y values can't be null and have a length of at least 2");
    }

    if (xValues != null && xValues.length != yValues.length) {
      throw new IllegalArgumentException("X values should have the same length as Y values");
    }

    final BufferedImage image =
        new BufferedImage(
            parameters.getWidth(), parameters.getHeight(), BufferedImage.TYPE_INT_ARGB);
    final Color backgroundColor =
        parameters.getBackgroundColor() != null
            ? parameters.getBackgroundColor()
            : SparklineParameters.DEFAULT_BACKGROUND_COLOR;
    final Color lineColor =
        parameters.getLineColor() != null
            ? parameters.getLineColor()
            : SparklineParameters.DEFAULT_LINE_COLOR;
    final Color areaColor =
        parameters.getAreaColor() != null
            ? parameters.getAreaColor()
            : SparklineParameters.DEFAULT_AREA_COLOR;
    Color highlightMinColor = parameters.getHighlightMinColor();
    Color highlightMaxColor = parameters.getHighlightMaxColor();
    int width = parameters.getWidth();
    int height = parameters.getHeight();
    ArrayList<HighlightParameters> highlightsList = new ArrayList<>();
    Color highlightValueColor =
        parameters.getHighligtValueColor() != null
            ? parameters.getHighligtValueColor()
            : SparklineParameters.DEFAULT_HIGHLIGHT_VALUE_COLOR;
    Integer highlightedValueXPosition = parameters.getHighlightedValueXPosition();
    String highlightedValueText = null;

    // Calculate y min if not provided:
    float yMin;
    if (yMinValue != null) {
      yMin = yMinValue.floatValue();
    } else {
      yMin = calculateMin(yValues);
    }

    // Calculate y max if not provided:
    float yMax;
    if (yMaxValue != null) {
      yMax = yMaxValue.floatValue();
    } else {
      yMax = calculateMax(yValues);
    }

    // Begin drawing:
    final Graphics2D g = image.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Background:
    if (backgroundColor != null && !parameters.isTransparentBackground()) {
      g.setBackground(backgroundColor);
      g.clearRect(0, 0, width, height);
    }

    // Sparklines:
    g.setPaint(lineColor);
    // For special case, all the Y values are equal:
    if (yMin == yMax) {
      // Disable min/max highlight since all Y values are equal
      highlightMaxColor = null;
      highlightMinColor = null;
    }

    if (highlightMaxColor != null || highlightMinColor != null || highlightValueColor != null) {
      height -=
          HIGHLIGHT_RADIUS; // Highlight circle radius pixels less in order not to draw outside
      // bounds
      width -= HIGHLIGHT_RADIUS; // Highlight circle radius pixels less in order not to draw outside
      // bounds
      g.translate(HIGHLIGHT_RADIUS / 2, HIGHLIGHT_RADIUS / 2);
    }

    // Poly for area:
    Path2D.Float path = new Path2D.Float();
    path.moveTo(0, height);

    // Calculate x tick width and x min value:
    float xMin;
    float xTickWidth;
    if (xValues == null) {
      xMin = 0;
      xTickWidth = (float) width / (yValues.length - 1);
    } else {
      xMin = xValues[0].floatValue(); // X values have to be ordered
      xTickWidth = (float) width / (xValues[xValues.length - 1].floatValue() - xMin);
    }
    // Calculate yTickWidth:
    float yTickWidth = height / (yMax - yMin);

    float bottom = height;

    float x0, y0, x1, y1;
    for (int i = 0; i < yValues.length - 1; i++) {
      if (xValues == null) {
        x0 = i * xTickWidth;
        x1 = (i + 1) * xTickWidth;
      } else {
        x0 = (xValues[i].floatValue() - xMin) * xTickWidth;
        x1 = (xValues[i + 1].floatValue() - xMin) * xTickWidth;
      }

      if (yMin == yMax) {
        // For special case, all the Y values are equal:
        y0 = y1 = bottom - height / 2.0f;
      } else {
        y0 = bottom - (yValues[i].floatValue() - yMin) * yTickWidth;
        y1 = bottom - (yValues[i + 1].floatValue() - yMin) * yTickWidth;
      }

      // Draw line:
      g.draw(new Line2D.Double(x0, y0, x1, y1));

      // Add to path for area:
      if (parameters.isDrawArea()) {
        if (i == 0) {
          path.lineTo(x0, y0);
        }
        path.lineTo(x1, y1);
      }

      // Save min/max values highlihgting if enabled:
      if (yValues[i + 1].floatValue() == yMin && highlightMinColor != null) {
        highlightsList.add(new HighlightParameters(x1, y1, highlightMinColor));
        highlightMinColor = null; // Only highlight first min
      }
      if (yValues[i + 1].floatValue() == yMax && highlightMaxColor != null) {
        highlightsList.add(new HighlightParameters(x1, y1, highlightMaxColor));
        highlightMaxColor = null; // Only highlight first max
      }
      // Save first point special case min/max values highlihgting if enabled:
      if (i == 0) {
        if (yValues[0].floatValue() == yMin && highlightMinColor != null) {
          highlightsList.add(new HighlightParameters(x0, y0, highlightMinColor));
          highlightMinColor = null; // Only highlight first min
        }
        if (yValues[0].floatValue() == yMax && highlightMaxColor != null) {
          highlightsList.add(new HighlightParameters(x0, y0, highlightMaxColor));
          highlightMaxColor = null; // Only highlight first max
        }
      }

      // Save x position value highlighting if enabled:
      if (highlightedValueXPosition != null && x1 >= highlightedValueXPosition) {
        // Highlight closest point:
        if ((highlightedValueXPosition - x0) < (x1 - x0) / 2f) { // Highlight left point
          highlightsList.add(new HighlightParameters(x0, y0, highlightValueColor));
          if (parameters.getHighlightTextColor() != null) {
            highlightedValueText =
                buildHighlightText(
                    parameters.getHighlightTextMode(),
                    xValues != null ? xValues[i] : i,
                    yValues[i]);
          }
        } else { // Highlight right point
          highlightsList.add(new HighlightParameters(x1, y1, highlightValueColor));
          if (parameters.getHighlightTextColor() != null) {
            highlightedValueText =
                buildHighlightText(
                    parameters.getHighlightTextMode(),
                    xValues != null ? xValues[i + 1] : i + 1,
                    yValues[i + 1]);
          }
        }
        highlightedValueXPosition = null;
      }
    }

    // Draw area
    if (parameters.isDrawArea()) {
      // End Path
      path.lineTo(width, height);
      path.lineTo(0, height);

      g.setColor(areaColor);
      g.fill(path);
    }

    // Draw list of highlights at the end in order to always draw them on top of lines:
    for (HighlightParameters p : highlightsList) {
      drawHighlight(g, p.x, p.y, p.color);
    }

    // Finally draw value text (x,y) if enabled:
    if (highlightedValueText != null) {
      g.setFont(g.getFont().deriveFont(Font.BOLD));
      int textWidth = g.getFontMetrics().stringWidth(highlightedValueText);
      int textHeight = g.getFontMetrics().getHeight();
      g.translate((width - textWidth) / 2f, (height + textHeight / 2f) / 2f);
      // Draw bounding box if enabled:
      if (parameters.getHighlightTextBoxColor() != null) {
        g.setPaint(parameters.getHighlightTextBoxColor());
        g.fill(g.getFontMetrics().getStringBounds(highlightedValueText, g));
      }
      g.setPaint(parameters.getHighlightTextColor());
      g.drawString(highlightedValueText, 0, 0);
    }

    return image;
  }
 /**
  * Set number value of the input field
  *
  * @param value the <code>Number</code> to set the input field
  */
 public void setTo(Number value) {
   inputfield.setText(value.toString());
 }