meterplot.java
来自「这是一个segy数据显示程序」· Java 代码 · 共 1,369 行 · 第 1/3 页
JAVA
1,369 行
this.valuePaint = paint == null ? DEFAULT_VALUE_PAINT : paint; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the paint for the 'normal' level. * * @return The paint. */ public Paint getNormalPaint() { return this.normalPaint; } /** * Sets the paint used to display the 'normal' range. * <P> * If you set this to null, it will revert to the default color. * * @param paint The paint. */ public void setNormalPaint(Paint paint) { this.normalPaint = (paint == null) ? DEFAULT_NORMAL_PAINT : paint; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the paint used to display the 'warning' range. * * @return The paint. */ public Paint getWarningPaint() { return this.warningPaint; } /** * Sets the paint used to display the 'warning' range. * <P> * If you set this to null, it will revert to the default color. * * @param paint The paint. */ public void setWarningPaint(Paint paint) { this.warningPaint = (paint == null) ? DEFAULT_WARNING_PAINT : paint; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the paint used to display the 'critical' range. * * @return The paint. */ public Paint getCriticalPaint() { return this.criticalPaint; } /** * Sets the paint used to display the 'critical' range. * <P> * If you set this to null, it will revert to the default color. * * @param paint The paint. */ public void setCriticalPaint(Paint paint) { this.criticalPaint = (paint == null) ? DEFAULT_CRITICAL_PAINT : paint; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the tick label type. Defined by the constants: NO_LABELS, * VALUE_LABELS. * * @return The tick label type. */ public int getTickLabelType() { return this.tickLabelType; } /** * Sets the tick label type. * * @param type the type of tick labels - either <code>NO_LABELS</code> or * <code>VALUE_LABELS</code> */ public void setTickLabelType(int type) { // check the argument... if ((type != NO_LABELS) && (type != VALUE_LABELS)) { throw new IllegalArgumentException( "MeterPlot.setLabelType(int): unrecognised type."); } // make the change... if (this.tickLabelType != type) { this.tickLabelType = type; notifyListeners(new PlotChangeEvent(this)); } } /** * Returns the tick label font. * * @return The font (never <code>null</code>). */ public Font getTickLabelFont() { return this.tickLabelFont; } /** * Sets the tick label font and sends a {@link PlotChangeEvent} to all registered listeners. * * @param font the font (<code>null</code> not permitted). */ public void setTickLabelFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } if (!this.tickLabelFont.equals(font)) { this.tickLabelFont = font; notifyListeners(new PlotChangeEvent(this)); } } /** * Returns the tick label format. * * @return The tick label format (never <code>null</code>). */ public NumberFormat getTickLabelFormat() { return this.tickLabelFormat; } /** * Sets the format for the tick labels and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param format the format (<code>null</code> not permitted). */ public void setTickLabelFormat(NumberFormat format) { if (format == null) { throw new IllegalArgumentException("Null 'format' argument."); } this.tickLabelFormat = format; notifyListeners(new PlotChangeEvent(this)); } /** * Returns a flag that controls whether or not a rectangular border is drawn around the plot * area. * * @return A flag. */ public boolean getDrawBorder() { return this.drawBorder; } /** * Sets the flag that controls whether or not a rectangular border is drawn around the plot * area. * <P> * Note: it looks like the true setting needs some work to provide some insets. * * @param draw the flag. */ public void setDrawBorder(boolean draw) { this.drawBorder = draw; } /** * Returns the meter angle. * * @return the meter angle. */ public int getMeterAngle() { return this.meterAngle; } /** * Sets the range through which the dial's needle is free to rotate. * * @param angle the angle. */ public void setMeterAngle(int angle) { this.meterAngle = angle; notifyListeners(new PlotChangeEvent(this)); } /** * Returns the dial outline paint. * * @return The paint. */ public Paint getDialOutlinePaint() { return this.dialOutlinePaint; } /** * Sets the dial outline paint. * * @param paint the paint. */ public void setDialOutlinePaint(Paint paint) { this.dialOutlinePaint = paint; } /** * Returns the primary dataset for the plot. * * @return The primary dataset (possibly <code>null</code>). */ public ValueDataset getDataset() { return this.dataset; } /** * Sets the dataset for the plot, replacing the existing dataset if there is one. * * @param dataset the dataset (<code>null</code> permitted). */ public void setDataset(ValueDataset dataset) { // if there is an existing dataset, remove the plot from the list of change listeners... ValueDataset existing = this.dataset; if (existing != null) { existing.removeChangeListener(this); } // set the new dataset, and register the chart as a change listener... this.dataset = dataset; if (dataset != null) { setDatasetGroup(dataset.getGroup()); dataset.addChangeListener(this); } // send a dataset change event to self... DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); datasetChanged(event); } /** * Returns a list of legend item labels. * * @return the legend item labels. * * @deprecated use getLegendItems(). */ public List getLegendItemLabels() { return null; } /** * Returns null. * * @return null. */ public LegendItemCollection getLegendItems() { return null; } /** * Draws the plot on a Java 2D graphics device (such as the screen or a printer). * * @param g2 the graphics device. * @param plotArea the area within which the plot should be drawn. * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ public void draw(Graphics2D g2, Rectangle2D plotArea, PlotState parentState, PlotRenderingInfo info) { if (info != null) { info.setPlotArea(plotArea); } // adjust for insets... Insets insets = getInsets(); if (insets != null) { plotArea.setRect( plotArea.getX() + insets.left, plotArea.getY() + insets.top, plotArea.getWidth() - insets.left - insets.right, plotArea.getHeight() - insets.top - insets.bottom ); } plotArea.setRect( plotArea.getX() + 4, plotArea.getY() + 4, plotArea.getWidth() - 8, plotArea.getHeight() - 8 ); // draw the background if (this.drawBorder) { drawBackground(g2, plotArea); } // adjust the plot area by the interior spacing value double gapHorizontal = (2 * DEFAULT_BORDER_SIZE); double gapVertical = (2 * DEFAULT_BORDER_SIZE); double meterX = plotArea.getX() + gapHorizontal / 2; double meterY = plotArea.getY() + gapVertical / 2; double meterW = plotArea.getWidth() - gapHorizontal; double meterH = plotArea.getHeight() - gapVertical + ((this.meterAngle <= 180) && (this.shape != DialShape.CIRCLE) ? plotArea.getHeight() / 1.25 : 0); double min = Math.min(meterW, meterH) / 2; meterX = (meterX + meterX + meterW) / 2 - min; meterY = (meterY + meterY + meterH) / 2 - min; meterW = 2 * min; meterH = 2 * min; Rectangle2D meterArea = new Rectangle2D.Double(meterX, meterY, meterW, meterH); Rectangle2D.Double originalArea = new Rectangle2D.Double(meterArea.getX() - 4, meterArea.getY() - 4, meterArea.getWidth() + 8, meterArea.getHeight() + 8); double meterMiddleX = meterArea.getCenterX(); double meterMiddleY = meterArea.getCenterY(); // plot the data (unless the dataset is null)... ValueDataset data = getDataset(); if (data != null) { //double dataMin = data.getMinimumValue().doubleValue(); //double dataMax = data.getMaximumValue().doubleValue(); double dataMin = this.range.getLowerBound(); double dataMax = this.range.getUpperBound(); this.minMeterValue = dataMin; this.meterCalcAngle = 180 + ((this.meterAngle - 180) / 2); this.meterRange = dataMax - dataMin; Shape savedClip = g2.getClip(); g2.clip(originalArea); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, getForegroundAlpha()) ); if (this.dialBackgroundPaint != null) { drawArc(g2, originalArea, dataMin, dataMax, this.dialBackgroundPaint, 1); } drawTicks(g2, meterArea, dataMin, dataMax); drawArcFor(g2, meterArea, data, FULL_DATA_RANGE); if (this.normalRange != null) { drawArcFor(g2, meterArea, data, NORMAL_DATA_RANGE); } if (this.warningRange != null) { drawArcFor(g2, meterArea, data, WARNING_DATA_RANGE); } if (this.criticalRange != null) { drawArcFor(g2, meterArea, data, CRITICAL_DATA_RANGE); } if (data.getValue() != null) { double dataVal = data.getValue().doubleValue(); drawTick(g2, meterArea, dataVal, true, this.valuePaint, true, getUnits()); g2.setPaint(this.needlePaint); g2.setStroke(new BasicStroke(2.0f)); double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE + 15; double valueAngle = calculateAngle(dataVal); double valueP1 = meterMiddleX + (radius * Math.cos(Math.PI * (valueAngle / 180))); double valueP2 = meterMiddleY - (radius * Math.sin(Math.PI * (valueAngle / 180))); Polygon arrow = new Polygon(); if ((valueAngle > 135 && valueAngle < 225) || (valueAngle < 45 && valueAngle > -45)) { double valueP3 = (meterMiddleY - DEFAULT_CIRCLE_SIZE / 4); double valueP4 = (meterMiddleY + DEFAULT_CIRCLE_SIZE / 4); arrow.addPoint((int) meterMiddleX, (int) valueP3); arrow.addPoint((int) meterMiddleX, (int) valueP4); } else { arrow.addPoint((int) (meterMiddleX - DEFAULT_CIRCLE_SIZE / 4), (int) meterMiddleY); arrow.addPoint((int) (meterMiddleX + DEFAULT_CIRCLE_SIZE / 4), (int) meterMiddleY); } arrow.addPoint((int) valueP1, (int) valueP2); Ellipse2D circle = new Ellipse2D.Double(meterMiddleX - DEFAULT_CIRCLE_SIZE / 2, meterMiddleY - DEFAULT_CIRCLE_SIZE / 2, DEFAULT_CIRCLE_SIZE, DEFAULT_CIRCLE_SIZE); g2.fill(arrow); g2.fill(circle); } g2.clip(savedClip); g2.setComposite(originalComposite); } if (this.drawBorder) { drawOutline(g2, plotArea); } } /** * Draws a colored range (arc) for one level. * * @param g2 The graphics device. * @param meterArea The drawing area. * @param data The dataset. * @param type The level. */ protected void drawArcFor(Graphics2D g2, Rectangle2D meterArea, ValueDataset data, int type) { double minValue = 0.0; double maxValue = 0.0; Paint paint = null; switch (type) { case NORMAL_DATA_RANGE: minValue = this.normalRange.getLowerBound(); maxValue = this.normalRange.getUpperBound(); paint = getNormalPaint(); break; case WARNING_DATA_RANGE: minValue = this.warningRange.getLowerBound(); maxValue = this.warningRange.getUpperBound(); paint = getWarningPaint(); break; case CRITICAL_DATA_RANGE: minValue = this.criticalRange.getLowerBound(); maxValue = this.criticalRange.getUpperBound(); paint = getCriticalPaint(); break; case FULL_DATA_RANGE: minValue = this.range.getLowerBound(); maxValue = this.range.getUpperBound(); paint = DEFAULT_BACKGROUND_PAINT; break; default: return; }// if (data.getBorderType() == type) {// drawArc(g2, meterArea,// minValue.doubleValue(),// data.getMinimumValue().doubleValue(),// paint);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?