Java Code Examples for java.awt.Graphics2D.draw()

The following are Jave code examples for showing how to use draw() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: geomapapp   File: BRGTable.java   View Source Code Vote up 6 votes
public void plotXY( Graphics2D g, 
			Rectangle2D bounds,
			double xScale, double yScale,
			int k) {
	GeneralPath path = new GeneralPath();
	boolean start = true;
	for( int i=0 ; i<rows.size() ; i++) {
		if( !plot[k][i] )continue;
		double[] row = (double[])rows.get(i);
		float x = (float)((row[k+1]-bounds.getX())*xScale);
		float y = (float)((row[0]-bounds.getY())*yScale);
		if( start ) {
			path.moveTo(x,y);
			start = false;
		} else path.lineTo(x,y);
	}
	g.setColor( Color.white );
	g.setStroke( new BasicStroke(3f) );
	g.draw(path);
	g.setColor( Color.black );
	g.setStroke( new BasicStroke(1f) );
	g.draw(path);
}
 
Example 2
Project: parabuild-ci   File: SimpleDialFrame.java   View Source Code Vote up 6 votes
/**
 * Draws the frame.  This method is called by the {@link DialPlot} class,
 * you shouldn't need to call it directly.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param frame  the frame (<code>null</code> not permitted).
 * @param view  the view (<code>null</code> not permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {
    
    Shape window = getWindow(frame);
    
    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, 
            this.radius + 0.02);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), 
            f.getHeight());
    
    Area area = new Area(e);
    Area area2 = new Area(window);
    area.subtract(area2);
    g2.setPaint(this.backgroundPaint);
    g2.fill(area);
    
    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(e);
}
 
Example 3
Project: parabuild-ci   File: MeterPlot.java   View Source Code Vote up 6 votes
/**
 * Draws an arc.
 *
 * @param g2  the graphics device.
 * @param area  the plot area.
 * @param minValue  the minimum value.
 * @param maxValue  the maximum value.
 * @param paint  the paint.
 * @param stroke  the stroke.
 */
protected void drawArc(Graphics2D g2, Rectangle2D area, double minValue, 
                       double maxValue, Paint paint, Stroke stroke) {

    double startAngle = valueToAngle(maxValue);
    double endAngle = valueToAngle(minValue);
    double extent = endAngle - startAngle;

    double x = area.getX();
    double y = area.getY();
    double w = area.getWidth();
    double h = area.getHeight();
    g2.setPaint(paint);
    g2.setStroke(stroke);

    if (paint != null && stroke != null) {
        Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, 
                extent, Arc2D.OPEN);
        g2.setPaint(paint); 
        g2.setStroke(stroke);
        g2.draw(arc);
    }

}
 
Example 4
Project: rapidminer   File: RoundTitledBorder.java   View Source Code Vote up 5 votes
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
	Graphics2D g2d = (Graphics2D) g.create();
	g2d.setRenderingHints(ProcessDrawer.HI_QUALITY_HINTS);
	g2d.setStroke(new BasicStroke(2f));

	// clear edges, otherwise they will be in the color of the component background
	if (drawRoundFrame && !c.getBackground().equals(c.getParent().getBackground())) {
		Shape frame = new Rectangle2D.Float(x + 2, y + 2, width - 4, height - 4);
		g2d.setPaint(c.getParent().getBackground());
		g2d.draw(frame);
	}

	g2d.setPaint(paint);
	g2d.setFont(new Font("Dialog", Font.BOLD, 21));

	if (drawRoundFrame) {
		Shape roundFrame = new RoundRectangle2D.Float(x + 2, y + 2, width - 4, height - 4, 10, 10);
		g2d.draw(roundFrame);
	}

	if (number > 0) {
		Shape circle = new Ellipse2D.Float(20, 20, 34, 34);
		g2d.fill(circle);
		g2d.setPaint(Color.WHITE);
		g2d.drawString(String.valueOf(number), 29, 44);
	}

	if (key != null) {
		g2d.setPaint(paint);
		g2d.drawString(key, 60, 44);
	}

	g2d.dispose();
}
 
Example 5
Project: rapidminer   File: PlotterAdapter.java   View Source Code Vote up 5 votes
/** This method can be used to draw a legend on the given graphics context. */
public void drawNumericalLegend(Graphics graphics, int width, String minColorString, String maxColorString,
		String legendColumnName, int alpha) {
	Graphics2D g = (Graphics2D) graphics.create();

	// painting label name
	g.drawString(legendColumnName, MARGIN, 15);
	Rectangle2D legendNameBounds = LABEL_FONT.getStringBounds(legendColumnName, g.getFontRenderContext());
	g.translate(legendNameBounds.getWidth(), 0);

	// painting legend

	Rectangle2D minStringBounds = LABEL_FONT.getStringBounds(minColorString, g.getFontRenderContext());
	Rectangle2D maxStringBounds = LABEL_FONT.getStringBounds(maxColorString, g.getFontRenderContext());
	int legendWidth = (int) (minStringBounds.getWidth() + 114 + maxStringBounds.getWidth());
	int keyX = MARGIN + width / 2 - legendWidth / 2;
	int keyY = (int) (MARGIN + 2 - minStringBounds.getHeight() / 2);
	g.setColor(Color.black);
	g.drawString(minColorString, keyX, keyY);
	keyX += minStringBounds.getWidth() + 10;
	for (int i = 0; i < 100; i++) {
		double scaledColor = i / 100.0d;
		Color lineColor = getColorProvider().getPointColor(scaledColor, alpha);
		g.setColor(lineColor);
		g.drawLine(keyX, keyY, keyX, keyY - 10);
		keyX++;
	}
	g.setColor(Color.black);
	Rectangle2D frame = new Rectangle2D.Double(keyX - 101, keyY - 11, 101, 11);
	g.draw(frame);
	keyX += 4;
	g.drawString(maxColorString, keyX, keyY);
}
 
Example 6
Project: awe-awesomesky   File: CodeUtil.java   View Source Code Vote up 5 votes
private static void insertImage(BufferedImage source, String imgPath,
        boolean needCompress) throws Exception {
    File file = new File(imgPath);
    if (!file.exists()) {
        System.err.println(""+imgPath+"   该文件不存在!");
        return;
    }
    Image src = ImageIO.read(new File(imgPath));
    int width = src.getWidth(null);
    int height = src.getHeight(null);
    if (needCompress) {// 压缩LOGO
        if (width > WIDTH) {
            width = WIDTH;
        }
        if (height > HEIGHT) {
            height = HEIGHT;
        }
        Image image = src.getScaledInstance(width, height,
                Image.SCALE_SMOOTH);
        BufferedImage tag = new BufferedImage(width, height,
                BufferedImage.TYPE_INT_RGB);
        Graphics g = tag.getGraphics();
        g.drawImage(image, 0, 0, null); // 绘制缩小后的图
        g.dispose();
        src = image;
    }
 // 插入LOGO
    Graphics2D graph = source.createGraphics();
    int x = (QRCODE_SIZE - width) / 2;
    int y = (QRCODE_SIZE - height) / 2;
    graph.drawImage(src, x, y, width, height, null);
    Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
    graph.setStroke(new BasicStroke(3f));
    graph.draw(shape);
    graph.dispose();
}
 
Example 7
Project: parabuild-ci   File: CyclicNumberAxis.java   View Source Code Vote up 5 votes
/**
 * Draws the axis.
 * 
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param cursor  the cursor position.
 * @param plotArea  the plot area (<code>null</code> not permitted).
 * @param dataArea  the data area (<code>null</code> not permitted).
 * @param edge  the edge (<code>null</code> not permitted).
 * @param plotState  collects information about the plot (<code>null</code> permitted).
 * 
 * @return the axis state (never <code>null</code>).
 */
public AxisState draw(Graphics2D g2, 
                      double cursor,
                      Rectangle2D plotArea, 
                      Rectangle2D dataArea, 
                      RectangleEdge edge,
                      PlotRenderingInfo plotState) {
    
    AxisState ret = super.draw(g2, cursor, plotArea, dataArea, edge, plotState);
    if (isAdvanceLineVisible()) {
        double xx = valueToJava2D(getRange().getUpperBound(), dataArea, edge);
        Line2D mark = null;
        g2.setStroke(getAdvanceLineStroke());
        g2.setPaint(getAdvanceLinePaint());
        if (edge == RectangleEdge.LEFT) {
            mark = new Line2D.Double(cursor, xx, cursor + dataArea.getWidth(), xx);
        }
        else if (edge == RectangleEdge.RIGHT) {
            mark = new Line2D.Double(cursor - dataArea.getWidth(), xx, cursor, xx);
        }
        else if (edge == RectangleEdge.TOP) {
            mark = new Line2D.Double(xx, cursor + dataArea.getHeight(), xx, cursor);
        }
        else if (edge == RectangleEdge.BOTTOM) {
            mark = new Line2D.Double(xx, cursor, xx, cursor - dataArea.getHeight());
        }
        g2.draw(mark);
    }
    return ret;
}
 
Example 8
Project: rapidminer   File: SimilarityKDistanceVisualization.java   View Source Code Vote up 5 votes
private void drawVerticalTic(Graphics2D g, int ticNumber, DecimalFormat format, double dx, double dy, double sx,
		double sy) {
	double x = ticNumber * xTicSize + minX;
	g.setColor(GRID_COLOR);
	g.draw(new Line2D.Double((x + dx) * sx, (minY + dy) * sy, (x + dx) * sx, (maxY + dy) * sy));
	g.setColor(Color.black);
}
 
Example 9
Project: VASSAL-src   File: ColoredBorder.java   View Source Code Vote up 5 votes
public void draw(GamePiece p, Graphics g, int x, int y,
                 Component obs, double zoom) {
  if (thickness > 0) {
    if (c != null) {
      // Find the border by outsetting the bounding box, and then scaling
      // the shape to fill the outset.
      final Shape s = p.getShape();
      final Rectangle br = s.getBounds();

      // Don't bother if the shape is empty.
      if (!br.isEmpty()) {
        final double xzoom = (br.getWidth()+1) / br.getWidth();
        final double yzoom = (br.getHeight()+1) / br.getHeight();
        final AffineTransform t = AffineTransform.getTranslateInstance(x,y);
        t.scale(xzoom*zoom, yzoom*zoom);

        final Graphics2D g2d = (Graphics2D) g;
        final Stroke str = g2d.getStroke();
        g2d.setStroke(
          new BasicStroke(Math.max(1, Math.round(zoom*thickness))));
        g2d.setColor(c);
        g2d.draw(t.createTransformedShape(s));
        g2d.setStroke(str);
      }
    }
    else {
      highlightSelectionBounds(p, g, x, y, obs, zoom);
    }
  }

  // Draw any additional highlighters
  for (Highlighter h : highlighters) {
    h.draw(p, g, x, y, obs, zoom);
  }
}
 
Example 10
Project: geomapapp   File: SurveyPlannerSelector.java   View Source Code Vote up 5 votes
void finish(MouseEvent e) {
	double wrap = map.getWrap();
	if (p0==null) {
		return;
	}
	drawLine();
	Graphics2D g = map.getGraphics2D();
	g.setStroke( new BasicStroke(4f/(float)map.getZoom()) );
	g.setColor( Color.white );
	//g.setXORMode(Color.white);
	g.draw( currentPath );
	if( wrap>0.) {
		g.translate(wrap,0.);
		g.draw( currentPath );
	}
	Point p1 = e.getPoint();
	if( p0.x==p1.x && p0.y==p1.y ) {
		if( line!=null ) {
			line=null;
			if(dialog!=null)dialog.setVisible(false);
			map.repaint();
		}
		p0=null;
		return;
	}

	Point2D pA = map.getScaledPoint( p0 );
	Point2D pB = map.getScaledPoint( e.getPoint());
	Point2D latLonA = map.getProjection().getRefXY(pA);
	Point2D latLonB = map.getProjection().getRefXY(pB);
	
	startLonTF.setText(df.format(latLonA.getX()));
	startLatTF.setText(df.format(latLonA.getY()));
	endLonTF.setText(df.format(latLonB.getX()));
	endLatTF.setText(df.format(latLonB.getY()));

	currentLine = null;
	currentPath = null;
	p0=null;
}
 
Example 11
Project: ramus   File: DFDFunctionEllipse.java   View Source Code Vote up 5 votes
@Override
public void paint(Graphics2D g) {
    g.setColor(function.getBackground());
    final Rectangle2D rect = movingArea.getBounds(getBounds());
    Ellipse2D ellipse = new Ellipse2D.Double(rect.getX(), rect.getY(),
            rect.getWidth(), rect.getHeight());
    g.fill(ellipse);
    g.setFont(function.getFont());
    paintText(g);
    paintBorder(g);

    final Stroke tmp = g.getStroke();
    g.draw(ellipse);
    if (!function.isHaveChilds()) {
        FRectangle fr = new FRectangle(rect);
        double y1 = rect.getY() + rect.getHeight() / 2.5;
        double x1 = getX(rect.getY() + rect.getHeight() / 2.5, true, fr);

        double x2 = rect.getX() + rect.getWidth() / 2.5;
        double y2 = getY(x2, true, fr);

        g.draw(new Line2D.Double(x1, y1, x2, y2));
    }
    g.setStroke(new BasicStroke(2));

    final String string = Integer.toString(function.getId());
    g.setFont(function.getFont());
    double h = MovingArea.getWidth(0)
            + MovingArea.getWidth((int) function.getFont()
            .getStringBounds(string, g.getFontRenderContext())
            .getHeight());
    h = h * 0.7;

    paintTringle(g);
    g.setStroke(tmp);

    movingArea.paintText(g, string, new FRectangle(getBounds().getX(),
                    getBounds().getBottom() - h, getBounds().getWidth(), h),
            com.ramussoft.pb.print.old.Line.RIGHT_ALIGN, 1, true);
}
 
Example 12
Project: openjdk-jdk10   File: TextClipErrorTest.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    Locale.setDefault(Locale.US);

    // initialize j.u.l Looger:
    final Logger log = Logger.getLogger("sun.java2d.marlin");
    log.addHandler(new Handler() {
        @Override
        public void publish(LogRecord record) {
            Throwable th = record.getThrown();
            // detect any Throwable:
            if (th != null) {
                System.out.println("Test failed:\n" + record.getMessage());
                th.printStackTrace(System.out);

                throw new RuntimeException("Test failed: ", th);
            }
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() throws SecurityException {
        }
    });

    log.info("TextClipErrorTest: start");

    // enable Marlin logging & internal checks:
    System.setProperty("sun.java2d.renderer.log", "true");
    System.setProperty("sun.java2d.renderer.useLogger", "true");
    System.setProperty("sun.java2d.renderer.doChecks", "true");

    BufferedImage image = new BufferedImage(256, 256,
                                            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2d = image.createGraphics();
    g2d.setColor(Color.red);
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);

        Font font = g2d.getFont();
        FontRenderContext frc = new FontRenderContext(
            new AffineTransform(), true, true);

        g2d.setStroke(new BasicStroke(4.0f,
                                      BasicStroke.CAP_ROUND,
                                      BasicStroke.JOIN_ROUND));

        final Shape badShape;
        if (SERIALIZE) {
            final GlyphVector gv1 = font.createGlyphVector(frc, "\u00d6");
            final Shape textShape = gv1.getOutline();

            final AffineTransform at1 = AffineTransform.getTranslateInstance(
                -2091202.554154681, 5548.601436981691);
            badShape = at1.createTransformedShape(textShape);
            serializeShape(badShape);
        } else {
            badShape = deserializeShape();
        }

        g2d.draw(badShape);

        // Draw anything within bounds and it fails:
        g2d.draw(new Line2D.Double(10, 20, 30, 40));

        if (SAVE_IMAGE) {
            final File file = new File("TextClipErrorTest.png");
            System.out.println("Writing file: " + file.getAbsolutePath());
            ImageIO.write(image, "PNG", file);
        }
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        g2d.dispose();
        log.info("TextClipErrorTest: end");
    }
}
 
Example 13
Project: spacesettlers   File: BaseGraphics.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics2D graphics) {
	float radius = Base.BASE_RADIUS;
	float diameter = Base.BASE_RADIUS * 2;

	// change the base's transparency based upon the energy level
	int alpha =  (int) (((float) base.getEnergy() / base.getMaxEnergy()) * 255.0);
	Color energyColor = new Color(teamColor.getRed(), teamColor.getGreen(), teamColor.getBlue(), alpha);
	graphics.setColor(energyColor);
	
	graphics.fillOval((int)(drawLocation.getX() - radius), (int)(drawLocation.getY() - radius), 
				(int)diameter, (int)diameter);
	
	// draw an outline around the base (in case its healing energy goes to 0)
       final Ellipse2D.Double shape = new Ellipse2D.Double(drawLocation.getX() - radius,
       		drawLocation.getY() - radius, diameter, diameter);
       graphics.setStroke(JSpaceSettlersComponent.STROKE);
	Color outlineColor = new Color(teamColor.getRed(), teamColor.getGreen(), teamColor.getBlue());
   	graphics.setColor(outlineColor);
       graphics.draw(shape);

	// if the base is shielded, put a white circle around the outside
       if (base.isShielded()) {
        double shieldRadius = radius + 8;
        final Ellipse2D.Double shieldShape = new Ellipse2D.Double(drawLocation.getX() - shieldRadius,
        		drawLocation.getY() - shieldRadius, 2 * shieldRadius, 2 * shieldRadius);
        graphics.setStroke(JSpaceSettlersComponent.THIN_STROKE);
    	graphics.setColor(BASE_SHIELD_COLOR);
        graphics.draw(shieldShape);
       }
       
	// show the healing energy level of the base
	final Font font = new Font("Arial", Font.BOLD, 12);
	graphics.setFont(font);

	String number = Integer.toString(base.getHealingEnergy());
	graphics.setPaint(JSpaceSettlersComponent.TEXT_COLOR);
	graphics.drawString(number, (int) drawLocation.getX() + 12, (int) drawLocation.getY() + 12);
	
	// show the resourcesAvailable collected by the team at this base
	//number = Integer.toString(base.getMoney());
	//graphics.setPaint(JSpaceSettlersComponent.TEXT_COLOR);
	//graphics.drawString(number, (int) drawLocation.getX() + 12, (int) drawLocation.getY() - 12);
	
	// if it is a home base, put a H inside it
	if (base.isHomeBase()) {
		graphics.setPaint(Color.BLACK);
		graphics.drawString("H", (int) drawLocation.getX()-4, (int) drawLocation.getY() + 4);
	}
	
	
}
 
Example 14
Project: parabuild-ci   File: XYPolygonAnnotation.java   View Source Code Vote up 4 votes
/**
 * Draws the annotation.  This method is usually called by the 
 * {@link XYPlot} class, you shouldn't need to call it directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  the plot rendering info.
 */
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea,
                 ValueAxis domainAxis, ValueAxis rangeAxis, 
                 int rendererIndex, PlotRenderingInfo info) {

    // if we don't have at least 2 (x, y) coordinates, just return
    if (this.polygon.length < 4) {
        return;
    }
    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(
            plot.getDomainAxisLocation(), orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(
            plot.getRangeAxisLocation(), orientation);

    GeneralPath area = new GeneralPath();
    double x = domainAxis.valueToJava2D(this.polygon[0], dataArea, 
            domainEdge);
    double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea, 
            rangeEdge);
    if (orientation == PlotOrientation.HORIZONTAL) {
        area.moveTo((float) y, (float) x);
        for (int i = 2; i < this.polygon.length; i += 2) {
            x = domainAxis.valueToJava2D(this.polygon[i], dataArea, 
                    domainEdge);
            y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, 
                    rangeEdge);
            area.lineTo((float) y, (float) x);
        }
        area.closePath();
    }
    else if (orientation == PlotOrientation.VERTICAL) {
        area.moveTo((float) x, (float) y);            
        for (int i = 2; i < this.polygon.length; i += 2) {
            x = domainAxis.valueToJava2D(this.polygon[i], dataArea, 
                    domainEdge);
            y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, 
                    rangeEdge);
            area.lineTo((float) x, (float) y);
        }
        area.closePath();
   }
    

    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(area);
    }
    
    if (this.stroke != null && this.outlinePaint != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.stroke);
        g2.draw(area);
    }
    addEntity(info, area, rendererIndex, getToolTipText(), getURL());
    
}
 
Example 15
Project: rapidminer   File: RadioButtonMenuItemIcon.java   View Source Code Vote up 4 votes
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
	JMenuItem b = (JMenuItem) c;
	ButtonModel bm = b.getModel();

	g.translate(x, y);

	boolean isSelected = bm.isSelected();
	boolean isEnabled = bm.isEnabled();
	boolean isPressed = bm.isPressed();

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

	// drawing background section
	if (!isEnabled) {
		g2.setColor(Colors.RADIOBUTTON_BORDER_DISABLED);
	} else {
		if (isPressed) {
			g2.setColor(Colors.RADIOBUTTON_BORDER_FOCUS);
		} else {
			g2.setColor(Colors.RADIOBUTTON_BORDER);
		}
	}
	g2.setStroke(RADIO_STROKE);
	Shape circle = new Ellipse2D.Double(0, 0, 9, 9);
	g2.draw(circle);

	// drawing sphere
	if (isSelected) {
		if (isEnabled) {
			g2.setColor(Colors.RADIOBUTTON_CHECKED);
		} else {
			g2.setColor(Colors.RADIOBUTTON_CHECKED_DISABLED);
		}
		circle = new Ellipse2D.Double(3, 3, 4, 4);
		g2.fill(circle);
	}

	g.translate(-x, -y);
}
 
Example 16
Project: lemon   File: CustomProcessDiagramGenerator.java   View Source Code Vote up 4 votes
/**
 * 绘制任务
 */
protected static void drawEvent(int x, int y, int width, int height,
        Graphics2D graphics) {
    Double circle = new Ellipse2D.Double(x, y, width, height);
    graphics.draw(circle);
}
 
Example 17
Project: MapAnalyst   File: OpenStreetMap.java   View Source Code Vote up 4 votes
private void drawMinorParallel(Graphics2D g2d, double latDeg, double xLeft, double xRight) {
    double parallelY = yMercator(latDeg);
    Line2D parallel = new Line2D.Double(xLeft, parallelY, xRight, parallelY);
    minorLineStyle(g2d);
    g2d.draw(parallel);
}
 
Example 18
Project: QN-ACTR-Release   File: QueueDrawer.java   View Source Code Vote up 4 votes
/**
 * drawing the legend
 * 
 * @param ca
 *            color of the legend
 * @param sa
 *            Comments
 * @param f
 *            font
 * @param x
 *            initial abscissa
 * @param y
 *            initial ordinate
 * @param g2d
 * @return panel lenght 
 */
private double drawLegend(Color[] ca, String[] sa, Font f, double x, double y, Graphics2D g2d, boolean draw) {
	Rectangle2D[] ra = new Rectangle2D[ca.length];
	Rectangle2D[] tba = new Rectangle2D[ca.length];
	double maxw = 0.0, gap = 5.0;
	String ts = "Legenda";
	// backup
	Color ctmp = g2d.getColor();
	Font ftmp = g2d.getFont();

	g2d.setFont(f);
	Rectangle2D tr = f.getStringBounds(ts, g2d.getFontRenderContext());
	maxw = tr.getWidth();
	for (int i = 0; i < ca.length; i++) {
		tba[i] = f.getStringBounds(sa[i], g2d.getFontRenderContext());
		ra[i] = new Rectangle2D.Double(x + gap, y + gap + (tr.getHeight() + gap) * (i + 1), tr.getHeight(), tr.getHeight());
		if (draw) {
			g2d.setColor(ca[i]);
			g2d.fill(ra[i]);
			g2d.setColor(Color.BLACK);
			g2d.draw(ra[i]);
			g2d.drawString(sa[i], (float) (x + gap * 2 + tr.getHeight()), (float) (y + gap + (tr.getHeight() + gap) * (i + 1) + tr.getHeight()
					/ 2.0 - tr.getY() / 2.0));
		}
		if (maxw < tba[i].getWidth()) {
			maxw = tba[i].getWidth();
		}
	}
	if (draw) {
		g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (y + (tr.getHeight() + gap) * (ca.length + 1) + gap));
		g2d.drawRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
		g2d.fillRect((int) x, (int) y, (int) (maxw + 3.0 * gap + tr.getHeight()), (int) (tr.getHeight() + gap));
		g2d.setColor(Color.WHITE);
		g2d.drawString(ts, (float) (x + gap + (maxw - tr.getWidth() + tr.getHeight()) / 2.0), (float) (y + tr.getY() / 2.0 + tr.getHeight()));
	}

	// restore
	g2d.setFont(ftmp);
	g2d.setColor(ctmp);
	return (maxw + 3.0 * gap + tr.getHeight());

}
 
Example 19
Project: parabuild-ci   File: LongNeedle.java   View Source Code Vote up 4 votes
/**
 * Draws the needle.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area.
 * @param rotate  the rotation point.
 * @param angle  the angle.
 */
protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {

    GeneralPath shape1 = new GeneralPath();
    GeneralPath shape2 = new GeneralPath();
    GeneralPath shape3 = new GeneralPath();

    float minX = (float) plotArea.getMinX();
    float minY = (float) plotArea.getMinY();
    float maxX = (float) plotArea.getMaxX();
    float maxY = (float) plotArea.getMaxY();
    //float midX = (float) (minX + (plotArea.getWidth() * getRotateX()));
    //float midY = (float) (minY + (plotArea.getHeight() * getRotateY()));
    float midX = (float) (minX + (plotArea.getWidth() * 0.5));
    float midY = (float) (minY + (plotArea.getHeight() * 0.8));
    float y = maxY - (2 * (maxY - midY));
    if (y < minY) {
        y = minY;
    }
    shape1.moveTo(minX, midY);
    shape1.lineTo(midX, minY);
    shape1.lineTo(midX, y);
    shape1.closePath();

    shape2.moveTo(maxX, midY);
    shape2.lineTo(midX, minY);
    shape2.lineTo(midX, y);
    shape2.closePath();

    shape3.moveTo(minX, midY);
    shape3.lineTo(midX, maxY);
    shape3.lineTo(maxX, midY);
    shape3.lineTo(midX, y);
    shape3.closePath();

    Shape s1 = shape1;
    Shape s2 = shape2;
    Shape s3 = shape3;

    if ((rotate != null) && (angle != 0)) {
        /// we have rotation huston, please spin me
        getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
        s1 = shape1.createTransformedShape(transform);
        s2 = shape2.createTransformedShape(transform);
        s3 = shape3.createTransformedShape(transform);
    }


    if (getHighlightPaint() != null) {
        g2.setPaint(getHighlightPaint());
        g2.fill(s3);
    }

    if (getFillPaint() != null) {
        g2.setPaint(getFillPaint());
        g2.fill(s1);
        g2.fill(s2);
    }


    if (getOutlinePaint() != null) {
        g2.setStroke(getOutlineStroke());
        g2.setPaint(getOutlinePaint());
        g2.draw(s1);
        g2.draw(s2);
        g2.draw(s3);
    }
}
 
Example 20
Project: parabuild-ci   File: StandardDialScale.java   View Source Code Vote up 4 votes
/**
 * Draws the scale on the dial plot.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the dial plot (<code>null</code> not permitted).
 * @param frame  the reference frame that is used to construct the
 *     geometry of the plot (<code>null</code> not permitted).
 * @param view  the visible part of the plot (<code>null</code> not 
 *     permitted).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, 
        Rectangle2D view) {
    
    Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, 
            this.tickRadius, this.tickRadius);
    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, 
            this.tickRadius - this.minorTickLength, 
            this.tickRadius - this.minorTickLength);
    Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame, 
            this.tickRadius - this.tickLabelOffset, 
            this.tickRadius - this.tickLabelOffset);
    
    boolean firstLabel = true;
    
    Arc2D arc = new Arc2D.Double();
    for (double v = this.lowerBound; v <= this.upperBound; 
            v += this.majorTickIncrement) {
        arc.setArc(arcRect, this.startAngle, valueToAngle(v) 
                - this.startAngle, Arc2D.OPEN);
        Point2D pt0 = arc.getEndPoint();
        arc.setArc(arcRectInner, this.startAngle, valueToAngle(v) 
                - this.startAngle, Arc2D.OPEN);
        Point2D pt1 = arc.getEndPoint();
        g2.setPaint(this.majorTickPaint);
        g2.setStroke(this.majorTickStroke);
        g2.draw(new Line2D.Double(pt0, pt1));
        arc.setArc(arcRectForLabels, this.startAngle, valueToAngle(v) 
                - this.startAngle, Arc2D.OPEN);
        Point2D pt2 = arc.getEndPoint();
        
        if (tickLabelsVisible) {
            if (!firstLabel || this.firstTickLabelVisible) {
                g2.setFont(this.tickLabelFont);
                TextUtilities.drawAlignedString(String.valueOf(v), g2, 
                        (float) pt2.getX(), (float) pt2.getY(), 
                        TextAnchor.CENTER);
            }
        }
        firstLabel = false;
        
        // now do the minor tick marks
        if (this.minorTickCount > 0) {
            double minorTickIncrement = this.majorTickIncrement 
                    / (this.minorTickCount + 1);
            for (int i = 0; i < this.minorTickCount; i++) {
                double vv = v + ((i + 1) * minorTickIncrement);
                if (vv >= this.upperBound) {
                    break;
                }
                double angle = valueToAngle(vv);
               
                arc.setArc(arcRect, this.startAngle, angle 
                        - this.startAngle, Arc2D.OPEN);
                pt0 = arc.getEndPoint();
                arc.setArc(arcRectInner, this.startAngle, angle 
                        - this.startAngle, Arc2D.OPEN);
                Point2D pt3 = arc.getEndPoint();
                g2.setStroke(new BasicStroke(1.0f));
                g2.draw(new Line2D.Double(pt0, pt3));
            }
        }
        
    }
}