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

The following are Jave code examples for showing how to use fillPolygon() 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: QN-ACTR-Release   File: PainterConvex2D.java   View Source Code Vote up 6 votes
/**
 * Draw a semi-trasparet area
 * @param g The graphic object
 * @param dragPoint The first point
 * @param beginPoint The second point
 * @param c The color of the area
 */
public void drawDragArea(Graphics2D g, Point dragPoint, Point beginPoint, Color c) {
	g.setColor(c);

	Polygon poly = new Polygon();

	poly.addPoint((int) beginPoint.getX(), (int) beginPoint.getY());
	poly.addPoint((int) beginPoint.getX(), (int) dragPoint.getY());
	poly.addPoint((int) dragPoint.getX(), (int) dragPoint.getY());
	poly.addPoint((int) dragPoint.getX(), (int) beginPoint.getY());

	//Set the widths of the shape's outline
	Stroke oldStro = g.getStroke();
	Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
	g.setStroke(stroke);
	g.drawPolygon(poly);
	g.setStroke(oldStro);

	//Set the trasparency of the iside of the rectangle
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
	g.setComposite(alphaComp);
	g.fillPolygon(poly);
	g.setComposite(oldComp);

}
 
Example 2
Project: DicomViewer   File: SelectorButton.java   View Source Code Vote up 6 votes
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int w = getWidth(), h = getHeight(), h2 = h / 2;
    x[0] = w - 6;
    x[1] = w - 9;
    x[2] = w - 12;
    y[0] = y[2] = h2 - 1;
    y[1] = h2 + 2;
    g2.setColor(Color.black);
    g2.fillPolygon(x, y, 3);

    g2.setColor(Color.gray);
    g2.drawLine(w - 18, 3, w - 18, h - 4);

    paintSelection(g2, w - 18, h);
}
 
Example 3
Project: brModelo   File: baseDrawerItem.java   View Source Code Vote up 5 votes
private boolean DrawComplexPath(Graphics2D g, int l, int t) {
        String[] dist = getPath().split(",");
        int dl = dist.length;
        if (dl < 3) {
            g.drawString("?", l, t);
            return false;
        }
        if (dl % 2 > 0) {
            String[] tmp = new String[dl + 1];
            tmp[dl] = "0";
            dist = tmp;
            dl = dist.length;
        }
        int tam = dl / 2;
        int xPoints[] = new int[tam];
        int yPoints[] = new int[tam];
        try {
            int y = 0;
            for (int i = 0; i < tam; i++) {
                xPoints[i] = Expr(dist[y++].trim());
                yPoints[i] = Expr(dist[y++].trim());
//                xPoints[i] = l + Integer.valueOf(dist[y++].trim());
//                yPoints[i] = t + Integer.valueOf(dist[y++].trim());
            }
        } catch (Exception x) {
            g.drawString("?", l, t);
            return false;
        }
        if (isFill()) {
            g.fillPolygon(xPoints, yPoints, tam);
        } else {
            g.drawPolygon(xPoints, yPoints, tam);
        }
        return true;
    }
 
Example 4
Project: COE1186   File: TrackRenderWindow.java   View Source Code Vote up 5 votes
public void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) {
    Graphics2D g = (Graphics2D) g1.create();

    double dx = x2 - x1, dy = y2 - y1;
    double angle = Math.atan2(dy, dx);
    int len = (int) Math.sqrt(dx*dx + dy*dy);
    AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
    at.concatenate(AffineTransform.getRotateInstance(angle));
    g.transform(at);

    g.drawLine(0, 0, len, 0);
    g.fillPolygon(new int[] {len+2, len-(ARR_SIZE*2+1), len-(ARR_SIZE*2+1), len+2},
                  new int[] {0, -(ARR_SIZE-1), ARR_SIZE-1, 0}, 4);
}
 
Example 5
Project: jmt   File: Convex2DGraph.java   View Source Code Vote up 5 votes
public void drawMaskedOffRectangle(Graphics2D g, Point2D point, Color color) {
	Polygon poly = new Polygon();

	poly.addPoint(plane.getTrueX(0), plane.getTrueY(0));
	poly.addPoint(plane.getTrueX(0), plane.getTrueY(point.getY()));
	poly.addPoint(plane.getTrueX(point.getX()),
			plane.getTrueY(point.getY()));
	poly.addPoint(plane.getTrueX(point.getX()), plane.getTrueY(0));

	g.setStroke(LINES);
	g.setColor(color);
	g.fillPolygon(poly);
}
 
Example 6
Project: JAddOn   File: JExpandableTextArea.java   View Source Code Vote up 5 votes
/**
 * paint the text area
 * @param arg0 iwas
 */
@Override
protected void paintComponent(Graphics arg0) {
    super.paintComponent(arg0);
    Graphics2D graphics = (Graphics2D) arg0;
    if(inTheTriangleZone) {
        graphics.setColor(new Color(0.5f, 0.5f, 0.5f, 0.75f));
    } else {
        graphics.setColor(new Color(0.5f, 0.5f, 0.5f, 0.2f));
    }
    graphics.fillPolygon(getTriangle());
}
 
Example 7
Project: jaer   File: CollapsablePanel.java   View Source Code Vote up 5 votes
protected void paintComponent(Graphics g) {  
            super.paintComponent(g);  
            Graphics2D g2 = (Graphics2D) g;  
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,  
                    RenderingHints.VALUE_ANTIALIAS_ON);  
            int h = getHeight();  
            int width = getWidth();
        	Polygon arrow = new Polygon();
//        	Polygon leftArrow = new Polygon();

//                g2.drawImage(closed, PAD, 0, h, h, this); 
            g2.setFont(font);  
            FontRenderContext frc = g2.getFontRenderContext();  
            LineMetrics lm = font.getLineMetrics(title, frc);  
            float height = lm.getAscent() + lm.getDescent();  
            float x = OFFSET;  
            float y = (h + height) / 2 - lm.getDescent();  
            g2.drawString(title, x, y);
            int th = ((int)height)-2;
            if (selected) {
            	arrow.addPoint(width - 3*th/2 + 1, h/2 - th/4);
            	arrow.addPoint(width - th/2 - 1, h/2 - th/4);
            	arrow.addPoint(width - th, h/2 + th/4 );
            	g2.fillPolygon(arrow);
            }
//                g2.drawImage(open, PAD, 0, h, h, this); 
            else { 
            	arrow.addPoint(width - 3*th/4, h/2 - (th-2)/2);
            	arrow.addPoint(width - 3*th/4, h/2 + (th-2)/2);
            	arrow.addPoint(width - 5*th/4, h /2);
            	g2.fillPolygon(arrow);
            }
        }
 
Example 8
Project: openjdk-jdk10   File: Test8004821.java   View Source Code Vote up 5 votes
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 9
Project: MaxSim   File: EdgeSwitchWidget.java   View Source Code Vote up 5 votes
@Override
public void paintWidget() {   
    ObjectState os = this.getState();       
    if(!os.isHovered() && !os.isSelected()) return; //all previewEdges visible and not hovering, 
                                                    //no need to paint the switch         
    float hw = width/2;    
    Polygon pol = new Polygon();
    pol.addPoint(0,(int) -height/2); 
    pol.addPoint((int)hw,(int) height/2);
    pol.addPoint((int)-hw,(int) height/2);  
    Graphics2D gr = getGraphics();
    gr.setColor(this.getForeground());
    BasicStroke bs = new BasicStroke(2.0f, BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
    gr.setStroke(bs);
    AffineTransform previousTransform;
    previousTransform = gr.getTransform ();
    if(output) {
        if(os.isSelected() ){//hidden
             gr.scale(1.0, -1.0);
        }
    } else { //input switch
        if(os.isHovered() && !os.isSelected()){
             gr.scale(1.0, -1.0);
        }     
    }            
    gr.fillPolygon(pol);
    gr.setTransform(previousTransform);
    
}
 
Example 10
Project: jdk8u-jdk   File: Test8004821.java   View Source Code Vote up 5 votes
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
Example 11
Project: openjdk-jdk10   File: MultiGradientTest.java   View Source Code Vote up 4 votes
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g.create();

    int w = getWidth();
    int h = getHeight();
    g2d.setColor(Color.black);
    g2d.fillRect(0, 0, w, h);

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         antialiasHint);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                         renderHint);

    g2d.transform(transform);
    g2d.setPaint(paint);

    switch (shapeType) {
    default:
    case RECT:
        g2d.fillRect(0, 0, w, h);
        break;

    case ELLIPSE:
        g2d.fillOval(0, 0, w, h);
        break;

    case MULTIPLE:
        g2d.fillRect(0, 0, w/2, h/2);
        g2d.fillOval(w/2, 0, w/2, h/2);
        g2d.drawOval(0, h/2, w/2, h/2);
        g2d.drawLine(0, h/2, w/2, h);
        g2d.drawLine(0, h, w/2, h/2);
        Polygon p = new Polygon();
        p.addPoint(w/2, h);
        p.addPoint(w, h);
        p.addPoint(3*w/4, h/2);
        g2d.fillPolygon(p);
        break;
    }

    switch (paintType) {
    default:
    case BASIC:
    case LINEAR:
        g2d.setColor(Color.white);
        g2d.fillRect(startX-1, startY-1, 2, 2);
        g2d.drawString("1", startX, startY + 12);
        g2d.fillRect(endX-1, endY-1, 2, 2);
        g2d.drawString("2", endX, endY + 12);
        break;

    case RADIAL:
        g2d.setColor(Color.white);
        g2d.fillRect(ctrX-1, ctrY-1, 2, 2);
        g2d.drawString("C", ctrX, ctrY + 12);
        g2d.fillRect(focusX-1, focusY-1, 2, 2);
        g2d.drawString("F", focusX, focusY + 12);
        break;
    }

    g2d.dispose();
}
 
Example 12
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 4 votes
public static void drawCond(
		Graphics2D g2d,
		int circleCondX, int circleCondY,
		int triangleCondX, int triangleCondY,
		int lineCondStartX, int lineCondEndX,
		char trianglePos, int addToLineX, int addToLineY) {
		
	g2d.setColor(Constants.CONDITION_RELATION_COLOR);
	
	// circle
	g2d.fillOval(circleCondX - Constants.DOT_SIZE / 2, circleCondY - Constants.DOT_SIZE /2, Constants.DOT_SIZE, Constants.DOT_SIZE);
	
	// triangle
	Point pCond1 = new Point(triangleCondX, triangleCondY);
	int pResp2X = 0;
	int pResp3X = 0;
	int pResp2Y = 0;
	int pResp3Y = 0;
	
	switch(trianglePos) {
	  	case 'U':
			pResp2X = pCond1.x - Constants.TRIANGLE_HEIGHT / 2;
			pResp3X = pCond1.x + Constants.TRIANGLE_HEIGHT / 2;
			pResp2Y = pCond1.y + Constants.TRIANGLE_HEIGHT;
			pResp3Y = pCond1.y + Constants.TRIANGLE_HEIGHT;
			break;
	  	case 'D':
			pResp2X = pCond1.x - Constants.TRIANGLE_HEIGHT / 2;
			pResp3X = pCond1.x + Constants.TRIANGLE_HEIGHT / 2;
			pResp2Y = pCond1.y - Constants.TRIANGLE_HEIGHT;
			pResp3Y = pCond1.y - Constants.TRIANGLE_HEIGHT;
			break;
		case 'L':
			pResp2X = pCond1.x + Constants.TRIANGLE_HEIGHT;
			pResp3X = pCond1.x + Constants.TRIANGLE_HEIGHT;
			pResp2Y = pCond1.y - Constants.TRIANGLE_HEIGHT / 2;
			pResp3Y = pCond1.y + Constants.TRIANGLE_HEIGHT / 2;
			break;
		case 'R':
	  		pResp2X = pCond1.x - Constants.TRIANGLE_HEIGHT;
	  		pResp3X = pCond1.x - Constants.TRIANGLE_HEIGHT;
	  		pResp2Y = pCond1.y - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3Y = pCond1.y + Constants.TRIANGLE_HEIGHT / 2;
	  		break;
	}
	  
	Point pCond2 = new Point(pResp2X, pResp2Y);
	Point pCond3 = new Point(pResp3X, pResp3Y);
	int[] xsCond = {pCond1.x, pCond2.x, pCond3.x};
	int[] ysCond = {pCond1.y, pCond2.y, pCond3.y};
	g2d.fillPolygon(xsCond, ysCond, 3);
	
	// line
    g2d.drawLine(circleCondX + addToLineX, circleCondY + addToLineY, lineCondStartX, lineCondEndX);
}
 
Example 13
Project: rapidminer   File: ComboBoxUI.java   View Source Code Vote up 4 votes
/**
 * Draws the combobox itself.
 */
private void paintBox(Graphics g, JComponent c) {
	int w = c.getWidth();
	int h = c.getHeight() - 1;
	if (w <= 0 || h <= 0) {
		return;
	}

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

	if (c.isEnabled()) {
		if (Boolean.parseBoolean(String.valueOf(c.getClientProperty(RapidLookTools.PROPERTY_INPUT_BACKGROUND_DARK)))) {
			g2.setColor(Colors.COMBOBOX_BACKGROUND_DARK);
		} else {
			g2.setColor(Colors.COMBOBOX_BACKGROUND);
		}
	} else {
		g2.setColor(Colors.COMBOBOX_BACKGROUND_DISABLED);
	}

	g2.fillRoundRect(0, 0, w - 1, h, RapidLookAndFeel.CORNER_DEFAULT_RADIUS, RapidLookAndFeel.CORNER_DEFAULT_RADIUS);

	// arrow
	int ny = c.getSize().height / 2 - 3;
	int nx = c.getWidth() - 15;

	if (isDown && c.isEnabled()) {
		nx++;
		ny++;
	}
	g2.translate(nx, ny);

	if (c.isEnabled()) {
		g2.setColor(Colors.COMBOBOX_ARROW);
	} else {
		g2.setColor(Colors.COMBOBOX_ARROW_DISABLED);
	}

	w = 14;
	Polygon arrow = new Polygon(new int[] { 0, 4, 8 }, new int[] { 0, 6, 0 }, 3);
	g2.fillPolygon(arrow);

	g2.translate(-nx, -ny);
}
 
Example 14
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 4 votes
public static void drawResp(
		Graphics2D g2d,
		int circleRespX, int circleRespY,
		int triangleRespX, int triangleRespY,
		char trianglePos, int addToLineX, int addToLineY) {
		  
	g2d.setColor(Constants.RESPONSE_RELATION_COLOR);
		  
	// circle
	g2d.fillOval(circleRespX - Constants.DOT_SIZE / 2, circleRespY - Constants.DOT_SIZE /2, Constants.DOT_SIZE, Constants.DOT_SIZE);
	
	// triangle
	Point pResp1 = new Point(triangleRespX, triangleRespY);
	int pResp2X = 0;
	int pResp3X = 0;
	int pResp2Y = 0;
	int pResp3Y = 0;
	  
	switch(trianglePos) {
	  	case 'U':
	  		pResp2X = pResp1.x - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3X = pResp1.x + Constants.TRIANGLE_HEIGHT / 2;
	  		pResp2Y = pResp1.y + Constants.TRIANGLE_HEIGHT;
	  		pResp3Y = pResp1.y + Constants.TRIANGLE_HEIGHT;
	  		break;
	  	case 'D':
	  		pResp2X = pResp1.x - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3X = pResp1.x + Constants.TRIANGLE_HEIGHT / 2;
	  		pResp2Y = pResp1.y - Constants.TRIANGLE_HEIGHT;
	  		pResp3Y = pResp1.y - Constants.TRIANGLE_HEIGHT;
	  		break;
	  	case 'L':
	  		pResp2X = pResp1.x + Constants.TRIANGLE_HEIGHT;
	  		pResp3X = pResp1.x + Constants.TRIANGLE_HEIGHT;
	  		pResp2Y = pResp1.y - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3Y = pResp1.y + Constants.TRIANGLE_HEIGHT / 2;
	  		break;
	  	case 'R':
	  		pResp2X = pResp1.x - Constants.TRIANGLE_HEIGHT;
	  		pResp3X = pResp1.x - Constants.TRIANGLE_HEIGHT;
	  		pResp2Y = pResp1.y - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3Y = pResp1.y + Constants.TRIANGLE_HEIGHT / 2;
	  		break;
	}
	
	Point pResp2 = new Point(pResp2X, pResp2Y);
	Point pResp3 = new Point(pResp3X, pResp3Y);
	int[] xsResp = {pResp1.x, pResp2.x, pResp3.x};
	int[] ysResp = {pResp1.y, pResp2.y, pResp3.y};
	g2d.fillPolygon(xsResp, ysResp, 3);
	  
	// line
	g2d.drawLine(circleRespX + addToLineX, circleRespY + addToLineY, triangleRespX, triangleRespY);
}
 
Example 15
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 4 votes
public static void drawResp(
		Graphics2D g2d,
		int circleRespX, int circleRespY,
		int triangleRespX, int triangleRespY,
		char trianglePos, int addToLineX, int addToLineY) {
		  
	g2d.setColor(Constants.RESPONSE_RELATION_COLOR);
		  
	// circle
	g2d.fillOval(circleRespX - Constants.DOT_SIZE / 2, circleRespY - Constants.DOT_SIZE /2, Constants.DOT_SIZE, Constants.DOT_SIZE);
	
	// triangle
	Point pResp1 = new Point(triangleRespX, triangleRespY);
	int pResp2X = 0;
	int pResp3X = 0;
	int pResp2Y = 0;
	int pResp3Y = 0;
	  
	switch(trianglePos) {
	  	case 'U':
	  		pResp2X = pResp1.x - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3X = pResp1.x + Constants.TRIANGLE_HEIGHT / 2;
	  		pResp2Y = pResp1.y + Constants.TRIANGLE_HEIGHT;
	  		pResp3Y = pResp1.y + Constants.TRIANGLE_HEIGHT;
	  		break;
	  	case 'D':
	  		pResp2X = pResp1.x - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3X = pResp1.x + Constants.TRIANGLE_HEIGHT / 2;
	  		pResp2Y = pResp1.y - Constants.TRIANGLE_HEIGHT;
	  		pResp3Y = pResp1.y - Constants.TRIANGLE_HEIGHT;
	  		break;
	  	case 'L':
	  		pResp2X = pResp1.x + Constants.TRIANGLE_HEIGHT;
	  		pResp3X = pResp1.x + Constants.TRIANGLE_HEIGHT;
	  		pResp2Y = pResp1.y - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3Y = pResp1.y + Constants.TRIANGLE_HEIGHT / 2;
	  		break;
	  	case 'R':
	  		pResp2X = pResp1.x - Constants.TRIANGLE_HEIGHT;
	  		pResp3X = pResp1.x - Constants.TRIANGLE_HEIGHT;
	  		pResp2Y = pResp1.y - Constants.TRIANGLE_HEIGHT / 2;
	  		pResp3Y = pResp1.y + Constants.TRIANGLE_HEIGHT / 2;
	  		break;
	}
	
	Point pResp2 = new Point(pResp2X, pResp2Y);
	Point pResp3 = new Point(pResp3X, pResp3Y);
	int[] xsResp = {pResp1.x, pResp2.x, pResp3.x};
	int[] ysResp = {pResp1.y, pResp2.y, pResp3.y};
	g2d.fillPolygon(xsResp, ysResp, 3);
	  
	// line
	g2d.drawLine(circleRespX + addToLineX, circleRespY + addToLineY, triangleRespX, triangleRespY);
}
 
Example 16
Project: KeysPerSecond   File: GraphPanel.java   View Source Code Vote up 4 votes
@Override
public void paintComponent(Graphics g1){
	if(Main.config.showGraph){
		try{
			Graphics2D g = (Graphics2D)g1;
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
			if(ColorManager.transparency){
				g.setColor(ColorManager.transparent);
				g.fillRect(0, 0, this.getWidth(), this.getHeight());
				g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getBackgroundOpacity()));
				g.setColor(Main.config.getBackgroundColor());
				g.fillRect(0, 0, this.getWidth(), this.getHeight());
				g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getBackgroundOpacity()));
			}else{
				g.setColor(Main.config.getBackgroundColor());
				g.fillRect(0, 0, this.getWidth(), this.getHeight());
				g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0F));
			}
			Polygon poly = new Polygon();
			poly.addPoint(this.getWidth() - SizeManager.graphOffset - 2, this.getHeight() - SizeManager.graphOffset);
			for(int i = 1; i <= values.size(); i++){
				int px = (int) (SizeManager.graphOffset + 2 + ((double)(this.getWidth() - SizeManager.graphOffset * 2 - 4) / (double)(Main.config.backlog - 1)) * (Main.config.backlog - i));
				int py = (int) (this.getHeight() - SizeManager.graphOffset - ((float)(this.getHeight() - SizeManager.graphOffset * 2) * ((float)values.get(i - 1) / (float)maxval)));
				poly.addPoint(px, py);
				if(i == values.size()){
					poly.addPoint(px, this.getHeight() - SizeManager.graphOffset);
				}
			}
			g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getForegroundOpacity()));
			if(Main.config.graphAvg){
				int y = (int) (this.getHeight() - SizeManager.graphOffset - ((float)(this.getHeight() - SizeManager.graphOffset * 2) * (Main.avg / (float)maxval)));
				g.setColor(Main.config.getForegroundColor().darker());
				g.setStroke(avgstroke);
				g.drawLine(SizeManager.graphOffset + 2, y, this.getWidth() - SizeManager.graphOffset - 2, y);
			}
			g.setStroke(line);
			g.setColor(ColorManager.alphaAqua);
			g.fillPolygon(poly);
			g.setColor(Main.config.getForegroundColor());
			g.drawPolygon(poly);
			g.drawImage(ColorManager.graph_upper_left,   2, 2, 2 + SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, 0, 0, 4, 4, this);
			g.drawImage(ColorManager.graph_lower_left,   2, this.getHeight() - 3 - SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, this.getHeight() - 3, 0, 0, 4, 4, this);
			g.drawImage(ColorManager.graph_upper_right,  this.getWidth() - 3 - SizeManager.graphImageSize, 2, this.getWidth() - 3, 2 + SizeManager.graphImageSize, 0, 0, 4, 4, this);
			g.drawImage(ColorManager.graph_lower_right,  this.getWidth() - 3 - SizeManager.graphImageSize, this.getHeight() - 3 - SizeManager.graphImageSize, this.getWidth() - 3, this.getHeight() - 3, 0, 0, 4, 4, this);
			g.drawImage(ColorManager.graph_side_left,    2, 2 + SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, this.getHeight() - 3 - SizeManager.graphImageSize, 0, 0, 4, 56, this);
			g.drawImage(ColorManager.graph_upper_middle, 2 + SizeManager.graphImageSize, 2, this.getWidth() - 3 - SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, 0, 0, 46, 4, this);
			g.drawImage(ColorManager.graph_lower_middle, 2 + SizeManager.graphImageSize, this.getHeight() - 3 - SizeManager.graphImageSize, this.getWidth() - 3 - SizeManager.graphImageSize, this.getHeight() - 3, 0, 0, 46, 4, this);
			g.drawImage(ColorManager.graph_side_right,   this.getWidth() - 3 - SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, this.getWidth() - 3, this.getHeight() - 3 - SizeManager.graphImageSize, 0, 0, 4, 56, this);
		}catch(NullPointerException e){
			//catch but do not solve, this is caused by the race
			//condition. However adding synchronisation would impact
			//performance more then it is worth
		}
	}
}
 
Example 17
Project: ramus   File: External.java   View Source Code Vote up 4 votes
@Override
public void paint(Graphics2D g) {
    DataPlugin dp = ((NFunction) function).getDataPlugin();

    Row row = dp.findRowByGlobalId(function.getLink());
    final class PolygonD extends Polygon {
        /**
         *
         */
        private static final long serialVersionUID = 113232131232134523L;

        public void addPoint(final double x, final double y) {
            super.addPoint((int) x, (int) y);
        }
    }

    g.setColor(function.getBackground());
    final Rectangle2D rect = movingArea.getBounds(getBounds());
    g.fill(rect);
    g.setFont(function.getFont());
    paintText(g);

    if (row != null) {
        String string = row.getKod();

        movingArea.paintText(g, string,
                new FRectangle(myBounds.getX() + 3, myBounds.getY() + 3,
                        myBounds.getWidth() - 3, myBounds.getHeight() - 3),
                Line.LEFT_ALIGN, 0, true);
    }

    paintBorder(g);

    final Stroke tmp = g.getStroke();
    g.draw(rect);

    double zm = movingArea.getIDoubleOrdinate(2);

    g.draw(new Line2D.Double(rect.getX() + zm, rect.getY() + zm, rect
            .getX() + zm, rect.getY() + rect.getHeight()));
    g.draw(new Line2D.Double(rect.getX() + zm, rect.getY() + zm, rect
            .getX() + rect.getWidth(), rect.getY() + zm));

    if (paintTriangle >= 0) {
        final PolygonD p = new PolygonD();
        p.addPoint(rect.getX() + rect.getWidth() / 2,
                rect.getY() + rect.getHeight() / 2);
        int standoff2 = -1;
        switch (paintTriangle) {
            case Point.TOP: {
                p.addPoint(rect.getX() + standoff2, rect.getY() + standoff2);
                p.addPoint(rect.getX() + rect.getWidth() - standoff2,
                        rect.getY() + standoff2);
            }
            break;
            case Point.LEFT: {
                p.addPoint(rect.getX() + standoff2, rect.getY() + standoff2);
                p.addPoint(rect.getX() + standoff2,
                        rect.getY() + rect.getHeight() - standoff2);
            }
            break;
            case Point.RIGHT: {
                p.addPoint(rect.getX() + rect.getWidth() - standoff2,
                        rect.getY() + standoff2);
                p.addPoint(rect.getX() + rect.getWidth() - standoff2,
                        rect.getY() + rect.getHeight() - standoff2);
            }
            break;
            case Point.BOTTOM: {
                p.addPoint(rect.getX() + standoff2,
                        rect.getY() + rect.getHeight() - standoff2);
                p.addPoint(rect.getX() + rect.getWidth() - standoff2,
                        rect.getY() + rect.getHeight() - standoff2);
            }
            break;
        }
        if (p.npoints > 1)
            g.fillPolygon(p);
    }
    g.setStroke(tmp);
}
 
Example 18
Project: SE2017-Team2   File: CrDrawing.java   View Source Code Vote up 4 votes
/**
 * Draws an arrow representing a relation
 * @param g
 * @param e1
 * @param e2
 * @param c
 * @param id
 * @param isConditional
 */
private void drawArrow(Graphics2D g, Event e1, Event e2, Color c, String id, boolean isConditional) {
	Tuple<Position, Position> tuple = shortest(e1, e2);
	Position p1 = tuple.f;
	Position p2 = tuple.s;
	relationPos.add(p1); 
	relationPos.add(p2); 
	AffineTransform oldXForm = g.getTransform();
	g.setColor(c);
	int ARR_SIZE = 8;
	Stroke oldS = g.getStroke();
	int strokeSize = ARR_SIZE/4;
	Stroke newS = new BasicStroke(strokeSize);
	g.setStroke(newS);
		
	double dx = p2.x() - p1.x(), dy = p2.y() - p1.y();
	double angle = Math.atan2(dy, dx);
	
	int len = (int) Math.sqrt(dx*dx + dy*dy);
	AffineTransform at = AffineTransform.getTranslateInstance(p1.x(), p1.y());
	at.concatenate(AffineTransform.getRotateInstance(angle));
	g.transform(at);
	Font fontUp = new Font("Times New Roman", Font.BOLD, 18);
	Font fontDw = new Font("Times New Roman", Font.BOLD, -18);
	FontMetrics mUp = g.getFontMetrics(fontUp);
	if (isConditional) {
		if (p1.x() > p2.x()) {
			g.setFont(fontDw);
			g.drawString(id, (len/2), -strokeSize+MARGIN);
		}
		else {
			g.setFont(fontUp);
			g.drawString(id, (len/2)-mUp.stringWidth(id), -strokeSize);
		}
		len -= CIRCLE_RADIUS;
		g.drawLine(0, 0, len-ARR_SIZE, 0);
		g.fillRoundRect(len, -(CIRCLE_RADIUS/2), CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS);
	}
	else {
		if (p1.x() > p2.x()) {
			g.setFont(fontDw);
			g.drawString(id, CIRCLE_RADIUS+(len/2), -strokeSize+MARGIN);
		}
		else {
			g.setFont(fontUp);
			g.drawString(id, CIRCLE_RADIUS+(len/2)-mUp.stringWidth(id), -strokeSize);
		}
		g.drawLine(CIRCLE_RADIUS, 0, len-ARR_SIZE, 0);
		g.fillRoundRect(0, -(CIRCLE_RADIUS/2), CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS, CIRCLE_RADIUS);
	}
	g.fillPolygon(new int[] {len, len-ARR_SIZE, len-ARR_SIZE, len},
                    new int[] {0, -ARR_SIZE, ARR_SIZE, 0}, 4);
	//reset
	g.setStroke(oldS);
	g.setTransform(oldXForm);
}
 
Example 19
Project: jdk8u-jdk   File: MultiGradientTest.java   View Source Code Vote up 4 votes
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g.create();

    int w = getWidth();
    int h = getHeight();
    g2d.setColor(Color.black);
    g2d.fillRect(0, 0, w, h);

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         antialiasHint);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                         renderHint);

    g2d.transform(transform);
    g2d.setPaint(paint);

    switch (shapeType) {
    default:
    case RECT:
        g2d.fillRect(0, 0, w, h);
        break;

    case ELLIPSE:
        g2d.fillOval(0, 0, w, h);
        break;

    case MULTIPLE:
        g2d.fillRect(0, 0, w/2, h/2);
        g2d.fillOval(w/2, 0, w/2, h/2);
        g2d.drawOval(0, h/2, w/2, h/2);
        g2d.drawLine(0, h/2, w/2, h);
        g2d.drawLine(0, h, w/2, h/2);
        Polygon p = new Polygon();
        p.addPoint(w/2, h);
        p.addPoint(w, h);
        p.addPoint(3*w/4, h/2);
        g2d.fillPolygon(p);
        break;
    }

    switch (paintType) {
    default:
    case BASIC:
    case LINEAR:
        g2d.setColor(Color.white);
        g2d.fillRect(startX-1, startY-1, 2, 2);
        g2d.drawString("1", startX, startY + 12);
        g2d.fillRect(endX-1, endY-1, 2, 2);
        g2d.drawString("2", endX, endY + 12);
        break;

    case RADIAL:
        g2d.setColor(Color.white);
        g2d.fillRect(ctrX-1, ctrY-1, 2, 2);
        g2d.drawString("C", ctrX, ctrY + 12);
        g2d.fillRect(focusX-1, focusY-1, 2, 2);
        g2d.drawString("F", focusX, focusY + 12);
        break;
    }

    g2d.dispose();
}
 
Example 20
Project: QN-ACTR-Release   File: PanelConvex2D.java   View Source Code Vote up 2 votes
/**
 * This function in used every time that the window have to be repiainted
 */
@Override
protected void paintComponent(Graphics g) {
	super.paintComponent(g);

	Graphics2D g3 = (Graphics2D) g;

	g3.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	//The graph is paint in a Image objet, in this way if it has to
	//be rapaint and the graph is no change it's repaint only the image
	if (painter.update(getHeight(), getWidth()) || editFigura) {

		figura = createImage(getWidth(), getHeight());
		Graphics2D g2 = (Graphics2D) figura.getGraphics();

		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

		g2.setColor(Color.white);
		g2.fillPolygon(painter.twoPointRectangle(0, 0, getWidth(), getHeight()));

		painter.drawArea(g2, engine.getAllConvex(), engine.getAllDominants(), new Color(255, 250, 120), Color.orange);

		painter.drawSelectLine(g2, lineP1, lineP2, s3d, data.getClassNames());

		painter.drawPoint(g2, engine.getDominants(), Color.blue, painter.getPointSize() + 1);

		painter.drawPoint(g2, engine.getDominates(), new Color(15, 185, 100), painter.getPointSize() + 1);

		painter.drawPoint(g2, engine.getConvex(), Color.red, painter.getPointSize() + 3);

		painter.drawPoint(g2, engine.getFiltDominants(), Color.black, painter.getPointSize() + 1);

		painter.drawPoint(g2, engine.getFiltConvex(), Color.black, painter.getPointSize() + 3);

		painter.drawPoint(g2, engine.getFiltDominates(), Color.gray, painter.getPointSize() + 1);

		painter.drawDominantArrow(g2, engine.getDominants(), engine.getDominates());

		painter.pointLabel(g2, engine.getPoints());

		painter.axis(g2, data.getClassNames());

		painter.drawFiltArea(g2, engine.getFilteredArea());

		painter.summary(g2);

		editFigura = false;
	}

	g3.drawImage(figura, 0, 0, this);

	drawDrag(g3);

	//painter.drawMousePosition(g3,dragPoint); 
}