/** * 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); }
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; }
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); }
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; }
/** 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(); }
@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); } }
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; }
/** * @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; } }
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; }