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

The following are Jave code examples for showing how to use setStroke() 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: jmt   File: StatiDrawer.java   View Source Code Vote up 6 votes
public void drawStatus(int status, double probability, Graphics2D g2d, Color sc, Color pc, Color borderC, boolean bold) {
	double x = 2.0 * (2.0 * STATUS_RAD + ELEMS_GAP) * status + START_GAP;
	double y = panelH / 2.0 - STATUS_RAD;
	double pie = probability * 360;
	Color ctmp = g2d.getColor();
	if (bold) {
		g2d.setStroke(strokeB);
	}
	statusE[status] = new Ellipse2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0);
	statusP[status] = new Arc2D.Double(x, y, STATUS_RAD * 2.0, STATUS_RAD * 2.0, 0.0, pie, Arc2D.PIE);
	g2d.setPaint(sc);
	g2d.fill(statusE[status]);
	g2d.setPaint(pc);
	g2d.fill(statusP[status]);
	g2d.setPaint(borderC);
	g2d.draw(statusE[status]);
	drawCenteredText(probabilityToString(probability, 3), Color.BLACK, x + STATUS_RAD, y - STATUS_RAD, g2d, false);
	drawCenteredText("" + status, borderC, x + STATUS_RAD, panelH / 2.0, g2d, false);
	g2d.setColor(ctmp);
	g2d.setStroke(stroke);
}
 
Example 2
Project: rapidminer   File: GenericArrowButton.java   View Source Code Vote up 6 votes
private void paintEastArrow(Graphics2D g2, int w, int h, boolean isPressed, boolean isRollover) {
	g2.setColor(Colors.SCROLLBAR_ARROW_BORDER);
	g2.drawLine(0, 0, w - 1, 0);

	if (isPressed) {
		g2.setColor(Colors.SCROLLBAR_ARROW_PRESSED);
	} else if (isRollover) {
		g2.setColor(Colors.SCROLLBAR_ARROW_ROLLOVER);
	} else {
		g2.setColor(Colors.SCROLLBAR_ARROW);
	}

	g2.setStroke(ARROW_STROKE);
	g2.drawLine(6, OFFSET, w - 6, h / 2);
	g2.drawLine(w - 6, h / 2, 6, h - OFFSET);
}
 
Example 3
Project: oscm   File: ImageProducer.java   View Source Code Vote up 6 votes
/**
 * @param g2d
 */
private void createPattern(final Graphics2D g2d) {
    g2d.setColor(Color.WHITE);
    g2d.setStroke(new BasicStroke(1));
    int variant = 5;
    // horizontal line
    for (int ii = 0; ii < END_Y; ii++) {
        g2d.drawLine(0, ii, END_X, ii);
        ii += variant;
    }
    // vertical line
    for (int ii = 0; ii < END_X; ii++) {
        g2d.drawLine(ii, 0, ii, END_Y);
        ii += variant;
    }
}
 
Example 4
Project: COE1186   File: TrackRenderWindow.java   View Source Code Vote up 6 votes
public void drawCrossing(Graphics2D g2d){

        g2d.setColor(new Color(0, 100, 100)); // teal
        g2d.setStroke(new BasicStroke(6));
        
        for (int i = 0; i < blocks.size(); i++){
            if (blocks.get(i).getCrossing() != null){

                double[] x_coords = blocks.get(i).getXCoordinates();
                double[] y_coords = blocks.get(i).getYCoordinates();

                for (int j = 3; j < x_coords.length-2; j+=3){

                    int x0 = (int)x_coords[j-3];
                    int y0 = (int)y_coords[j-3];
                    int x1 = (int)x_coords[j];
                    int y1 = (int)y_coords[j];

                    g2d.drawLine(x0, y0, x1, y1);
                }
            }
        }
    }
 
Example 5
Project: spacesettlers   File: BeaconGraphics.java   View Source Code Vote up 6 votes
public void draw(Graphics2D g) {
      float radius = Beacon.BEACON_RADIUS;
      float diameter = Beacon.BEACON_RADIUS * 2;
      
      Ellipse2D.Double shape = new Ellipse2D.Double(drawLocation.getX() - radius,
      		drawLocation.getY() - radius, diameter, diameter);

      g.setColor(BEACON_COLOR);
      g.fill(shape);

      g.setStroke(JSpaceSettlersComponent.THICK_STROKE);
      g.setColor(BEACON_LINE_COLOR);
      g.draw(shape);

      // add an E to make it clear it is an energy beacon
g.setPaint(Color.BLACK);
g.drawString("E", (int) drawLocation.getX()-3, (int) drawLocation.getY() + 4);

  }
 
Example 6
Project: geomapapp   File: ShoreLine.java   View Source Code Vote up 5 votes
public void draw( Graphics2D g ) {
	if( !visible || path==null ) return;
	g.setColor( color );
	g.setStroke( new BasicStroke(
			lineWidth/(float)map.getZoom(),
			BasicStroke.CAP_ROUND,
			BasicStroke.JOIN_ROUND) );
	g.draw( path );
}
 
Example 7
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 8
Project: litiengine   File: ListField.java   View Source Code Vote up 5 votes
@Override
public void render(final Graphics2D g) {
  super.render(g);
  if (this.selectedComponent != null) {
    final Stroke oldStroke = g.getStroke();
    g.setStroke(new BasicStroke(2));
    final Rectangle2D border = new Rectangle2D.Double(this.selectedComponent.getX() - 1, this.selectedComponent.getY() - 1, this.selectedComponent.getWidth() + 2, this.selectedComponent.getHeight() + 2);
    g.setColor(Color.WHITE);
    g.draw(border);
    g.setStroke(oldStroke);
  }
}
 
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: rapidminer   File: CardButton.java   View Source Code Vote up 5 votes
protected void paintBorder(Graphics graphics) {
    Graphics2D g = (Graphics2D)graphics.create();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setColor(this.colorBorder);
    g.setStroke(new BasicStroke(2.0F));
    g.drawRoundRect(0, 0, this.getWidth() - 1, this.getHeight() - 1, 10, 10);
}
 
Example 11
Project: spacesettlers   File: LineGraphics.java   View Source Code Vote up 5 votes
/**
 * This handles the toroidal space wrapping internally.  It probably shouldn't.
 * 
 * TODO: Fix it so it does the wrapping externally like the other graphics (but it is harder here)
 */
public void draw(Graphics2D graphics) {
	graphics.setColor(lineColor);
	graphics.setStroke(new BasicStroke(strokeWidth));
	
	graphics.drawLine((int)startPoint.getX(), (int)startPoint.getY(), 
			(int)endPoint.getX(), (int)endPoint.getY());
}
 
Example 12
Project: Cognizant-Intelligent-Test-Scripter   File: SelectionManager.java   View Source Code Vote up 5 votes
private void drawSelection(Graphics2D g2d) {
    selection.setFrameFromDiagonal(start, end);
    Rectangle select = this.selection.getBounds();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_OFF);

    g2d.setStroke(new BasicStroke(1.8f));
    g2d.setColor(Color.RED);
    g2d.drawRect(select.x, select.y, select.width, select.height);
}
 
Example 13
Project: jmt   File: PainterConvex2D.java   View Source Code Vote up 4 votes
/**
 * Draw the selected line of the convex hull 
 * and the information about it
 * @param g Graphic object
 * @param p1 The first point of the line
 * @param p2 The second point of the line
 * @param s3d Information aboute the classes
 * @param classNames The name of the classes
 */
public void drawSelectLine(Graphics2D g, DPoint p1, DPoint p2, Vector<Object> s3d, String[] classNames) {
	if ((p1 != null) && (p2 != null)) {
		//Draw the selected line
		Stroke oldStro = g.getStroke();
		Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
		g.setStroke(stroke);
		g.setColor(Color.BLACK);
		g.drawLine((int) (p1.getX() * scale) + tran_x, tran_y - (int) (p1.getY() * scale), (int) (p2.getX() * scale) + tran_x, tran_y
				- (int) (p2.getY() * scale));
		g.setStroke(oldStro);

		//Set the middle point
		int x = (int) p2.getX() + (int) ((p1.getX() - p2.getX()) / 2);
		int y = (int) p2.getY() + (int) ((p1.getY() - p2.getY()) / 2);
		x = (int) (x * scale) + tran_x + (pointSize + 3);
		y = tran_y - (int) (y * scale) - (pointSize + 1);

		Font label = new Font("Arial", Font.PLAIN, 7 + pointSize);
		g.setFont(label);

		//Draw the label
		for (int i = 0; i < s3d.size(); i++) {
			// Current sector
			FinalSect2D sect = (FinalSect2D) s3d.get(i);
			String pb11 = format2Dec.format(sect.getBeta11() * 100);
			String pb12 = format2Dec.format(sect.getBeta1() * 100);
			String pb21 = format2Dec.format(sect.getBeta22() * 100);
			String pb22 = format2Dec.format(sect.getBeta2() * 100);

			if (sect.countStation() < 2) {
				continue;
			}

			Station2D d1 = (sect.getstation()).get(0);
			Station2D d2 = (sect.getstation()).get(1);
			int d1x = (int) (d1.getVert()).getX();
			int d1y = (int) (d1.getVert()).getY();
			int d2x = (int) (d2.getVert()).getX();
			int d2y = (int) (d2.getVert()).getY();
			int p1x = (int) (p1.getX() * 100);
			int p1y = (int) (p1.getY() * 100);
			int p2x = (int) (p2.getX() * 100);
			int p2y = (int) (p2.getY() * 100);
			double t1 = ((p1.getY() - p2.getY()) / ((p2.getX() * p1.getY()) - (p1.getX() * p2.getY())));
			double t2 = ((p2.getX() - p1.getX()) / ((p2.getX() * p1.getY()) - (p1.getX() * p2.getY())));

			if (((d1x == p1x) && (d1y == p1y) && (d2x == p2x) && (d2y == p2y)) || ((d1x == p2x) && (d1y == p2y) && (d2x == p1x) && (d2y == p1y))) {
				g.drawString(classNames[0] + "=" + format4Dec.format(t1) + " job/sec", x, y - (8 + pointSize));
				g.drawString(classNames[1] + "=" + format4Dec.format(t2) + " job/sec", x, y);

				g.drawString(classNames[1] + "% [" + pb22 + "," + pb12 + "]", x, y - 2 * (8 + pointSize));
				g.drawString(classNames[0] + "% [" + pb21 + "," + pb11 + "]", x, y - 3 * (8 + pointSize));
				break;
			}
		}
	}
}
 
Example 14
Project: geomapapp   File: MGG.java   View Source Code Vote up 4 votes
public void draw(Graphics2D g) {
		if( !loaded ) return;
		if(display.data != null)display.data.currentPoint = null;
		Stroke stroke = g.getStroke();
		if( types==0 ) {
			g.setStroke( new BasicStroke( 1f/(float)map.getZoom() ));
			if(enabled && display.data != null) display.data.draw(g);
			g.setStroke(stroke);
			return;
		}
		g.setStroke( new BasicStroke( 1f/(float)map.getZoom() ));
		Rectangle2D rect = map.getClipRect2D();

		int temp = selectedIndex;

		model.clearTracks();
		selectedIndex = temp;

		if(enabled) {
			g.setColor(Color.black);
		} else {
			g.setColor(Color.darkGray);
		}
		for( int i=0 ; i<size ; i++) {

//			if( (types & tracks[i].getTypes()) ==0)continue;
			if( (types & tracks[i].getTypes()) ==0)continue;
			if( !tracks[i].intersects(rect) && !tracks[i].getName().equals(IMPORT_TRACK_LINE.getName())) continue;
			if( i==dataIndex && display.data != null) display.data.draw(g);
			else tracks[i].draw(g);
			model.addTrack(tracks[i], i);
		}
		if(enabled && display.data != null) display.data.draw(g);
		if((selectedIndex>=0) && (selectedIndex<size)) {
			if(enabled) {
				g.setColor(Color.white);
			} else {
				g.setColor(Color.lightGray);
			}
			if( selectedIndex==dataIndex && display.data != null) display.data.draw(g);
			else tracks[selectedIndex].draw(g);
		}
		model.updateList();

		selectedIndex = temp;

		g.setStroke(stroke);
		if( enabled && selectedIndex!=-1 ) {
			int index = model.indexOf(tracks[selectedIndex]);
			synchronized( map.getTreeLock() ) {
				list.setSelectedIndex(index);
				list.ensureIndexIsVisible(index);
			}
		//	list.setSelectedValue( tracks[selectedIndex], true );
		}
	}
 
Example 15
Project: parabuild-ci   File: MeterPlot.java   View Source Code Vote up 4 votes
/**
 * Draws a tick on the dial.
 *
 * @param g2  the graphics device.
 * @param meterArea  the meter area.
 * @param value  the tick value.
 * @param label  a flag that controls whether or not a value label is drawn.
 */
protected void drawTick(Graphics2D g2, Rectangle2D meterArea,
                        double value, boolean label) {

    double valueAngle = valueToAngle(value);

    double meterMiddleX = meterArea.getCenterX();
    double meterMiddleY = meterArea.getCenterY();

    g2.setPaint(this.tickPaint);
    g2.setStroke(new BasicStroke(2.0f));

    double valueP2X = 0;
    double valueP2Y = 0;

    double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE;
    double radius1 = radius - 15;

    double valueP1X = meterMiddleX 
            + (radius * Math.cos(Math.PI * (valueAngle / 180)));
    double valueP1Y = meterMiddleY 
            - (radius * Math.sin(Math.PI * (valueAngle / 180)));

    valueP2X = meterMiddleX 
            + (radius1 * Math.cos(Math.PI * (valueAngle / 180)));
    valueP2Y = meterMiddleY 
            - (radius1 * Math.sin(Math.PI * (valueAngle / 180)));

    Line2D.Double line = new Line2D.Double(valueP1X, valueP1Y, valueP2X, 
            valueP2Y);
    g2.draw(line);

    if (this.tickLabelsVisible && label) {

        String tickLabel =  this.tickLabelFormat.format(value);
        g2.setFont(this.tickLabelFont);
        g2.setPaint(this.tickLabelPaint);

        FontMetrics fm = g2.getFontMetrics();
        Rectangle2D tickLabelBounds 
            = TextUtilities.getTextBounds(tickLabel, g2, fm);

        double x = valueP2X;
        double y = valueP2Y;
        if (valueAngle == 90 || valueAngle == 270) {
            x = x - tickLabelBounds.getWidth() / 2;
        }
        else if (valueAngle < 90 || valueAngle > 270) {
            x = x - tickLabelBounds.getWidth();
        }
        if ((valueAngle > 135 && valueAngle < 225) 
                || valueAngle > 315 || valueAngle < 45) {
            y = y - tickLabelBounds.getHeight() / 2;
        }
        else {
            y = y + tickLabelBounds.getHeight() / 2;
        }
        g2.drawString(tickLabel, (float) x, (float) y);
    }
}
 
Example 16
Project: AutonomousCar   File: IImageBoxDrawer.java   View Source Code Vote up 4 votes
public void drawRisk(IImage image, List<MovingBlob> iBlobs)
{
    Rectangle[] rectangles = findRectangles(image, iBlobs);
    BufferedImage b = new BufferedImage(image.getImage()[0].length, image.getImage().length,
            BufferedImage.TYPE_INT_ARGB);
    setPixels(b, image.getImage());

    Graphics2D g = (Graphics2D) b.getGraphics();
    BasicStroke bs = new BasicStroke(DEFAULT_LINE_THICKNESS);
    
    Point center = new Point((image.getImage()[0].length / 2f), (image.getImage().length / 2f));

    for (Rectangle rect : rectangles)
    {
        for (int i = 0; i < 4; i++)
        {
            int indexOfNextPoint;
            if (i == 3)
            {
                indexOfNextPoint = 0;
            }
            else
            {
                indexOfNextPoint = i + 1;
            }
            Point start = rect.getPoints()[i];
            Point end = rect.getPoints()[indexOfNextPoint];

            g.setStroke(bs);

            double risk = getRisk(rect.getBlob(), 10, center);
            
            final int maxGreen = 180;
            
            Color lineColor = findColor(Color.RED, new Color(255 - maxGreen, maxGreen, 0), risk);

            g.setColor(lineColor);
            g.drawLine((int) start.getX(), (int) start.getY(), (int) end.getX(), (int) end.getY());
        }
    }
    currentImage = b;
    

}
 
Example 17
Project: parabuild-ci   File: CyclicNumberAxis.java   View Source Code Vote up 4 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 18
Project: geomapapp   File: SurveyLine.java   View Source Code Vote up 4 votes
@Override
public void draw(Graphics2D g) {
	float wrap = (float)map.getWrap();
	
	//get the limits of the displayed map
	Rectangle2D rect = map.getClipRect2D();
	double xmin = rect.getMinX();
	double xmax = rect.getMaxX();
	
	Projection proj = map.getProjection();
	Point2D.Double pt = new Point2D.Double();
	pt.x = getStartLon();
	pt.y = getStartLat();
	Point2D.Double p_start = (Point2D.Double) proj.getMapXY(pt);

	if( wrap>0f ) {
		while( p_start.x <= xmin ){p_start.x+=wrap;}
		while( p_start.x >= xmax ){p_start.x-=wrap;}
	}
	
	pt.x = getEndLon();
	pt.y = getEndLat();
	Point2D.Double p_end = (Point2D.Double) proj.getMapXY(pt);

	if( wrap>0f ) {
		while( p_end.x <= xmin ){p_end.x+=wrap;}
		while( p_end.x > wrap + xmin ){p_end.x-=wrap;}
	}
	
	//draw the shortest line - either p_start.x to p_end.x or the x+wrap values. 
	if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) > 
		((p_start.x - (p_end.x + wrap)) * (p_start.x - (p_end.x + wrap))) )  {p_end.x += wrap;}
	if ( ((p_start.x - p_end.x) * (p_start.x - p_end.x)) > 
	(((p_start.x + wrap) - p_end.x) * ((p_start.x + wrap) - p_end.x)) )  {p_start.x += wrap;}
	
	if (lineNum == 1) g.setColor( Color.RED ); 
	else g.setColor( Color.black );
	
	double zoom = map.getZoom();
	g.setStroke( new BasicStroke( 2f/(float)zoom ));

   	double arr_size = 6./zoom;
   	double sq_size = 6./zoom;
       double dx = p_end.x - p_start.x, dy = p_end.y - p_start.y;
       double angle = Math.atan2(dy, dx);
       double len = Math.sqrt(dx*dx + dy*dy);

       AffineTransform at = g.getTransform(); 
       g.translate(p_start.x, p_start.y);
       g.rotate(angle);

       //draw the line
       g.draw(new Line2D.Double(0, 0, len, 0));
       //draw the arrow
       Path2D arrow = new Path2D.Double();
       double xpts[] = {len/3d, len/3d-arr_size, len/3d-arr_size, len/3d};
       double ypts[] = {0, -arr_size, arr_size, 0};
       arrow.moveTo(xpts[0], ypts[0]);
       arrow.lineTo(xpts[1], ypts[1]);
       arrow.lineTo(xpts[2], ypts[2]);
       arrow.closePath();
	if (lineNum == 1) g.setColor( Color.ORANGE ); 
	else g.setColor( Color.ORANGE );
       g.fill(arrow);
	if (lineNum == 1) g.setColor( Color.RED ); 
	else g.setColor( Color.black );
       //draw squares at the end points
       Rectangle2D startSq = new Rectangle2D.Double(0d-sq_size/2d, 0d-sq_size/2d, sq_size, sq_size);
       Rectangle2D endSq = new Rectangle2D.Double(len-sq_size/2d, 0d-sq_size/2d,  sq_size, sq_size);
       g.fill(startSq);
       g.fill(endSq);

       g.setTransform(at);
       
}
 
Example 19
Project: saveOrganizer   File: CalendarFrame.java   View Source Code Vote up 4 votes
@Override
public void paintComponent(Graphics g)
{
	Day now = Day.now();

	// Initialisieren
	super.paintComponent(g);

	Graphics2D g2 = (Graphics2D) g;

	int dayWidth = getWidth() / days;
	int hourheight = getHeight() / (hoursPerDay + 1);
	Font defaultFont = g2.getFont();
	Font domFont = new Font(Font.SANS_SERIF, Font.BOLD, 15);
	// Rahmenzeichnen
	g2.setColor(Color.BLACK);
	g2.setStroke(new BasicStroke(3));
	g2.drawLine(0, hourheight, getWidth(), hourheight);

	g2.setColor(TODAY_BACKGROUND_COLOR);
	g2.fillRect(0, hourheight, dayWidth, getHeight());
	g2.setColor(Color.BLACK);

	// X-Achse
	Day tmpDate = null;
	for (int i = 0; i < days; ++i)
	{

		if (0 == i)
			tmpDate = now;
		else
		{
			tmpDate = now.getDateInDays(i);
			g2.drawLine((dayWidth * i), 0, (dayWidth * i), getHeight()); // Tagestrennstriche
		}

		// Day of month
		g2.setFont(domFont);
		int stringWidth = SwingUtilities.computeStringWidth(g2.getFontMetrics(),
				" " + tmpDate.getDate().getDayOfMonth());
		int numberX = (dayWidth * (i + 1)) - stringWidth;
		g2.drawString(tmpDate.getDate().getDayOfMonth() + " ", numberX, (hourheight / 2));

		// Dayname
		g2.setFont(defaultFont);
		g2.drawString(" " + tmpDate.getDayName(), (dayWidth * i), (hourheight / 2));
	}

	g2.setStroke(new BasicStroke(1));

	// Y-Achse
	for (int i = 2; i < (hoursPerDay + 1); ++i)
	{
		g2.drawLine(0, (hourheight * i), getWidth(), (hourheight * i));
	}

}
 
Example 20
Project: incubator-netbeans   File: ParagraphView.java   View Source Code Vote up 4 votes
@Override
public void paint(Graphics2D g, Shape alloc, Rectangle clipBounds) {
    // The background is already cleared by BasicTextUI.paintBackground() which uses component.getBackground()
    checkChildrenNotNull();
    children.paint(this, g, alloc, clipBounds);
    
    if (getDocumentView().op.isGuideLinesEnable()) {
        DocumentView docView = getDocumentView();
        CharSequence docText = DocumentUtilities.getText(docView.getDocument());
        int textlength = getEndOffset() - getStartOffset();
        int firstNonWhite = 0;
        int prefixlength = 0;
        for (; firstNonWhite < textlength; firstNonWhite++) {
            if (!Character.isWhitespace(docText.charAt(firstNonWhite + getStartOffset()))) {
                break;
            }
            if ('\t' == docText.charAt(firstNonWhite + getStartOffset())) {
                prefixlength += docView.op.getTabSize();
            } else {
                prefixlength++;
            }     
        }
        if (firstNonWhite >= textlength) {
            int[] guideLinesCache = docView.op.getGuideLinesCache();
            if (guideLinesCache[0] != -1 && guideLinesCache[0] <= getStartOffset() && guideLinesCache[1] >= getEndOffset()) {
                prefixlength = guideLinesCache[2];
                firstNonWhite = 0;
                textlength = prefixlength != -1 ? 1 : -1;
            } else {
                firstNonWhite = 0;
                prefixlength = 0;
                int secondNonWhite = getEndOffset();
                for (; secondNonWhite < docText.length(); secondNonWhite++) {
                    char currentChar = docText.charAt(secondNonWhite);
                    firstNonWhite++;
                    if (!Character.isWhitespace(currentChar)) {
                        break;
                    }
                    if ('\t' == currentChar) {
                        prefixlength += docView.op.getTabSize();
                    } else {
                        prefixlength++;
                    }
                    if ((currentChar == '\n') || (currentChar == '\r')) {
                        firstNonWhite = 0;
                        prefixlength = 0;
                    }
                }
                if (secondNonWhite >= docText.length()) {
                    docView.op.setGuideLinesCache(getStartOffset(), secondNonWhite - firstNonWhite+1, -1);
                    textlength = -1;
                } else {
                    textlength = firstNonWhite + 1;
                    docView.op.setGuideLinesCache(getStartOffset(), secondNonWhite - firstNonWhite+1, prefixlength);
                }
            }
        } else {
            docView.op.setGuideLinesCache(-1, -1, -1);
        }
        if (firstNonWhite < textlength) {
            Color oldColor = g.getColor();
            Stroke oldStroke = g.getStroke();
            
            g.setColor(docView.op.getGuideLinesColor());
            g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{1}, 0));
            
            float textsize = docView.op.getDefaultCharWidth() * prefixlength;
            float tabwidth = docView.op.getDefaultCharWidth() * docView.op.getIndentLevelSize();
            int rowHeight = (int) docView.op.getDefaultRowHeight();
            if (tabwidth > 0) {
                int x = alloc.getBounds().x;
                while (x < alloc.getBounds().x + alloc.getBounds().width && x < textsize) {
                    g.drawLine(x, alloc.getBounds().y, x, alloc.getBounds().y + rowHeight);
                    x += tabwidth;
                } 
            }
            g.setColor(oldColor);
            g.setStroke(oldStroke);
        }
    }
}