Java Code Examples for java.awt.Graphics.drawLine()

The following are Jave code examples for showing how to use drawLine() of the java.awt.Graphics 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: OpenJSharp   File: MotifGraphicsUtils.java   View Source Code Vote up 6 votes
private static void drawMenuBezel(Graphics g, Color background,
                                int x, int y,
                                int width, int height)
{
  // shadowed button region
  g.setColor(background);
  g.fillRect(x,y,width,height);

  g.setColor(background.brighter().brighter());
  g.drawLine(x+1,       y+height-1,  x+width-1, y+height-1);
  g.drawLine(x+width-1, y+height-2,  x+width-1, y+1);

  g.setColor(background.darker().darker());
  g.drawLine(x,   y,   x+width-2, y);
  g.drawLine(x,   y+1, x,         y+height-2);

}
 
Example 2
Project: openjdk-jdk10   File: MotifGraphicsUtils.java   View Source Code Vote up 6 votes
private static void drawMenuBezel(Graphics g, Color background,
                                int x, int y,
                                int width, int height)
{
  // shadowed button region
  g.setColor(background);
  g.fillRect(x,y,width,height);

  g.setColor(background.brighter().brighter());
  g.drawLine(x+1,       y+height-1,  x+width-1, y+height-1);
  g.drawLine(x+width-1, y+height-2,  x+width-1, y+1);

  g.setColor(background.darker().darker());
  g.drawLine(x,   y,   x+width-2, y);
  g.drawLine(x,   y+1, x,         y+height-2);

}
 
Example 3
Project: incubator-netbeans   File: ThinBevelBorder.java   View Source Code Vote up 6 votes
protected void paintLoweredBevel(Component c, Graphics g, int x, int y, int width, int height) {
    Color oldColor = g.getColor();
    int h = height;
    int w = width;

    g.translate(x, y);

    g.setColor(getShadowInnerColor(c));
    g.drawLine(0, 0, 0, h - 1);
    g.drawLine(1, 0, w - 1, 0);

    g.setColor(getHighlightOuterColor(c));
    g.drawLine(1, h - 1, w - 1, h - 1);
    g.drawLine(w - 1, 1, w - 1, h - 2);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 4
Project: jdk8u-jdk   File: BasicGraphicsUtils.java   View Source Code Vote up 6 votes
public static void drawGroove(Graphics g, int x, int y, int w, int h,
                              Color shadow, Color highlight)
{
    Color oldColor = g.getColor();  // Make no net change to g
    g.translate(x, y);

    g.setColor(shadow);
    g.drawRect(0, 0, w-2, h-2);

    g.setColor(highlight);
    g.drawLine(1, h-3, 1, 1);
    g.drawLine(1, 1, w-3, 1);

    g.drawLine(0, h-1, w-1, h-1);
    g.drawLine(w-1, h-1, w-1, 0);

    g.translate(-x, -y);
    g.setColor(oldColor);
}
 
Example 5
Project: org.alloytools.alloy   File: OurBorder.java   View Source Code Vote up 6 votes
/** This method is called by Swing to actually draw the borders. */
public void paintBorder(Component component, Graphics graphics, int x, int y, int width, int height) {
	if (width < 1 || height < 1)
		return;
	Color old = graphics.getColor();
	if (top != null) {
		graphics.setColor(top);
		graphics.drawLine(x, y, x + width - 1, y);
	}
	if (bottom != null) {
		graphics.setColor(bottom);
		graphics.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
	}
	if (left != null) {
		graphics.setColor(left);
		graphics.drawLine(x, y, x, y + height - 1);
	}
	if (right != null) {
		graphics.setColor(right);
		graphics.drawLine(x + width - 1, y, x + width - 1, y + height - 1);
	}
	graphics.setColor(old);
}
 
Example 6
Project: rapidminer   File: TreeUI.java   View Source Code Vote up 6 votes
protected void paintHorizontalSeparators(Graphics g, JComponent c) {
	Rectangle clipBounds = g.getClipBounds();

	int beginRow = getRowForPath(this.tree, getClosestPathForLocation(this.tree, 0, clipBounds.y));
	int endRow = getRowForPath(this.tree, getClosestPathForLocation(this.tree, 0, clipBounds.y + clipBounds.height - 1));

	if ((beginRow <= -1) || (endRow <= -1)) {
		return;
	}

	for (int i = beginRow; i <= endRow; ++i) {
		TreePath path = getPathForRow(this.tree, i);

		if ((path != null) && (path.getPathCount() == 2)) {
			Rectangle rowBounds = getPathBounds(this.tree, getPathForRow(this.tree, i));

			// Draw a line at the top
			if (rowBounds != null) {
				g.drawLine(clipBounds.x, rowBounds.y, clipBounds.x + clipBounds.width, rowBounds.y);
			}
		}
	}

}
 
Example 7
Project: OpenJSharp   File: MotifBorders.java   View Source Code Vote up 6 votes
/** Draws the FrameBorder's left border.
  */
protected boolean drawLeftBorder(Component c, Graphics g, int x, int y,
                       int width, int height) {
    Rectangle borderRect =
        new Rectangle(0, 0, getBorderInsets(c).left, height);
    if (!g.getClipBounds().intersects(borderRect)) {
        return false;
    }

    int startY = BORDER_SIZE;

    g.setColor(frameHighlight);
    g.drawLine(x, startY, x, height - 1);
    g.drawLine(x + 1, startY, x + 1, height - 2);

    g.setColor(frameColor);
    g.fillRect(x + 2, startY, x + 2, height - 3);

    g.setColor(frameShadow);
    g.drawLine(x + 4, startY, x + 4, height - 5);

    return true;
}
 
Example 8
Project: jdk8u-jdk   File: MotifGraphicsUtils.java   View Source Code Vote up 6 votes
private static void drawMenuBezel(Graphics g, Color background,
                                int x, int y,
                                int width, int height)
{
  // shadowed button region
  g.setColor(background);
  g.fillRect(x,y,width,height);

  g.setColor(background.brighter().brighter());
  g.drawLine(x+1,       y+height-1,  x+width-1, y+height-1);
  g.drawLine(x+width-1, y+height-2,  x+width-1, y+1);

  g.setColor(background.darker().darker());
  g.drawLine(x,   y,   x+width-2, y);
  g.drawLine(x,   y+1, x,         y+height-2);

}
 
Example 9
Project: jdk8u-jdk   File: BasicSeparatorUI.java   View Source Code Vote up 6 votes
public void paint( Graphics g, JComponent c )
{
    Dimension s = c.getSize();

    if ( ((JSeparator)c).getOrientation() == JSeparator.VERTICAL )
    {
      g.setColor( c.getForeground() );
      g.drawLine( 0, 0, 0, s.height );

      g.setColor( c.getBackground() );
      g.drawLine( 1, 0, 1, s.height );
    }
    else  // HORIZONTAL
    {
      g.setColor( c.getForeground() );
      g.drawLine( 0, 0, s.width, 0 );

      g.setColor( c.getBackground() );
      g.drawLine( 0, 1, s.width, 1 );
    }
}
 
Example 10
Project: DigitRecognizer   File: DigitManipulator.java   View Source Code Vote up 5 votes
private static BufferedImage markCenterOfMassAndBounds(BufferedImage im, Point centerOfPixels, Rectangle bounds)
{
    Graphics g1 = im.createGraphics();
    g1.setColor(Color.RED);
    g1.drawOval(centerOfPixels.x, centerOfPixels.y, 5, 5);
    g1.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
    g1.setColor(Color.BLUE);
    g1.drawLine(centerOfPixels.x, centerOfPixels.y, im.getWidth() / 2, im.getHeight() / 2);
    return im;
}
 
Example 11
Project: JDigitalSimulator   File: BinaryDisplay.java   View Source Code Vote up 5 votes
@Override public void paint(Graphics graphics) {
	if(input.isCharged()) {
		graphics.setColor(Color.RED);
		graphics.fillOval(5, 0, size.height, size.height);
	}
	graphics.setColor(Color.BLACK);
	graphics.drawOval(5, 0, size.height, size.height);
	int corner = (int)(Math.cos(Math.PI/4)*(size.height/2))-size.height/4+1;
	graphics.drawLine(5+corner, corner, 5+size.height-corner, size.height-corner);
	graphics.drawLine(5+corner, size.height-corner, 5+size.height-corner, corner);
	ContactUtilities.paintSolderingJoints(graphics, contacts);
}
 
Example 12
Project: incubator-netbeans   File: InsetBorder.java   View Source Code Vote up 5 votes
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    int h = c.getHeight();
    Color col = g.getColor();
    g.setColor (UIManager.getColor("controlShadow")); //NOI18N
    if (left) {
        g.drawLine (x + 3, y, x + 3, y + h - 1);
    }
    if (right) {
        g.drawLine (x + width - 3, y, x + width - 3, y + h - 1);
    }
    g.drawLine (x, y, x + width - 1, y);
}
 
Example 13
Project: OpenJSharp   File: MetalBorders.java   View Source Code Vote up 5 votes
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    g.translate( x, y );

    g.setColor( MetalLookAndFeel.getControlDarkShadow() );
    g.drawLine( w-1, 0, w-1, h-1 );
    g.drawLine( 1, h-1, w-1, h-1 );
    g.setColor( MetalLookAndFeel.getControlHighlight() );
    g.drawLine( 0, 0, w-2, 0 );
    g.drawLine( 0, 0, 0, h-2 );

    g.translate( -x, -y );
}
 
Example 14
Project: OpenJSharp   File: MetalBorders.java   View Source Code Vote up 5 votes
public void paintBorder(Component c, Graphics g, int x, int y,
                  int w, int h) {

    if (!(c instanceof JScrollPane)) {
        return;
    }
    JScrollPane scroll = (JScrollPane)c;
    JComponent colHeader = scroll.getColumnHeader();
    int colHeaderHeight = 0;
    if (colHeader != null)
       colHeaderHeight = colHeader.getHeight();

    JComponent rowHeader = scroll.getRowHeader();
    int rowHeaderWidth = 0;
    if (rowHeader != null)
       rowHeaderWidth = rowHeader.getWidth();


    g.translate( x, y);

    g.setColor( MetalLookAndFeel.getControlDarkShadow() );
    g.drawRect( 0, 0, w-2, h-2 );
    g.setColor( MetalLookAndFeel.getControlHighlight() );

    g.drawLine( w-1, 1, w-1, h-1);
    g.drawLine( 1, h-1, w-1, h-1);

    g.setColor( MetalLookAndFeel.getControl() );
    g.drawLine( w-2, 2+colHeaderHeight, w-2, 2+colHeaderHeight );
    g.drawLine( 1+rowHeaderWidth, h-2, 1+rowHeaderWidth, h-2 );

    g.translate( -x, -y);

}
 
Example 15
Project: Logisim   File: BitAdder.java   View Source Code Vote up 5 votes
@Override
public void paintInstance(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	painter.drawRoundBounds(Color.WHITE);
	painter.drawPorts();

	GraphicsUtil.switchToWidth(g, 2);
	Location loc = painter.getLocation();
	int x = loc.getX() - 10;
	int y = loc.getY();
	g.drawLine(x - 2, y - 5, x - 2, y + 5);
	g.drawLine(x + 2, y - 5, x + 2, y + 5);
	g.drawLine(x - 5, y - 2, x + 5, y - 2);
	g.drawLine(x - 5, y + 2, x + 5, y + 2);
}
 
Example 16
Project: incubator-netbeans   File: ColorIcon.java   View Source Code Vote up 5 votes
@Override
public void paintIcon( Component c, Graphics g, int x, int y ) {
    g.setColor( Color.black );
    g.drawRect( x, y, size-1, size-1 );
    if( null == color ) {
        g.drawLine( x, y+size-1, x+size-1, y );
    } else {
        g.setColor( color );
        g.fillRect( x+1, y+1, size-2, size-2 );
    }
}
 
Example 17
Project: jdk8u-jdk   File: WindowsBorders.java   View Source Code Vote up 5 votes
public void paintBorder(Component c, Graphics g, int x, int y,
                        int width, int height) {
    g.setColor(shadow);
    g.drawLine(x,y, width-1,y); // draw top
    g.drawLine(x,y, x,height-1); // draw left
    g.setColor(highlight);
    g.drawLine(x,height-1, width-1,height-1); // draw bottom
    g.drawLine(width-1,y, width-1,height-1); // draw right
}
 
Example 18
Project: The-Kraken-Pathfinding   File: NavmeshEdge.java   View Source Code Vote up 5 votes
@Override
public void print(Graphics g, GraphicPanel f)
{
	if(highlight)
		g.setColor(ColorKraken.RED.color);
	else if(isBlocked())
		g.setColor(ColorKraken.NAVMESH_BLOCKED.color);
	g.drawLine(f.XtoWindow(points[0].position.getX()), f.YtoWindow(points[0].position.getY()), f.XtoWindow(points[1].position.getX()), f.YtoWindow(points[1].position.getY()));
}
 
Example 19
Project: OpenJSharp   File: MotifIconFactory.java   View Source Code Vote up 4 votes
public void paintIcon(Component c, Graphics g, int x, int y) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();

    // These variables are kind of pointless as the following code
    // assumes the icon will be 10 x 10 regardless of their value.
    int w = getIconWidth();
    int h = getIconHeight();

    Color oldColor = g.getColor();

    if (model.isSelected()){
        if( MotifGraphicsUtils.isLeftToRight(c) ){
            g.setColor(shadow);
            g.fillRect(x+1,y+1,2,h);
            g.drawLine(x+4,y+2,x+4,y+2);
            g.drawLine(x+6,y+3,x+6,y+3);
            g.drawLine(x+8,y+4,x+8,y+5);
            g.setColor(focus);
            g.fillRect(x+2,y+2,2,h-2);
            g.fillRect(x+4,y+3,2,h-4);
            g.fillRect(x+6,y+4,2,h-6);
            g.setColor(highlight);
            g.drawLine(x+2,y+h,x+2,y+h);
            g.drawLine(x+4,y+h-1,x+4,y+h-1);
            g.drawLine(x+6,y+h-2,x+6,y+h-2);
            g.drawLine(x+8,y+h-4,x+8,y+h-3);
        } else {
            g.setColor(highlight);
            g.fillRect(x+7,y+1,2,10);
            g.drawLine(x+5,y+9,x+5,y+9);
            g.drawLine(x+3,y+8,x+3,y+8);
            g.drawLine(x+1,y+6,x+1,y+7);
            g.setColor(focus);
            g.fillRect(x+6,y+2,2,8);
            g.fillRect(x+4,y+3,2,6);
            g.fillRect(x+2,y+4,2,4);
            g.setColor(shadow);
            g.drawLine(x+1,y+4,x+1,y+5);
            g.drawLine(x+3,y+3,x+3,y+3);
            g.drawLine(x+5,y+2,x+5,y+2);
            g.drawLine(x+7,y+1,x+7,y+1);
        }
    } else {
        if( MotifGraphicsUtils.isLeftToRight(c) ){
            g.setColor(highlight);
            g.drawLine(x+1,y+1,x+1,y+h);
            g.drawLine(x+2,y+1,x+2,y+h-2);
            g.fillRect(x+3,y+2,2,2);
            g.fillRect(x+5,y+3,2,2);
            g.fillRect(x+7,y+4,2,2);
            g.setColor(shadow);
            g.drawLine(x+2,y+h-1,x+2,y+h);
            g.fillRect(x+3,y+h-2,2,2);
            g.fillRect(x+5,y+h-3,2,2);
            g.fillRect(x+7,y+h-4,2,2);
            g.setColor(oldColor);
        } else {
            g.setColor(highlight);
            g.fillRect(x+1,y+4,2,2);
            g.fillRect(x+3,y+3,2,2);
            g.fillRect(x+5,y+2,2,2);
            g.drawLine(x+7,y+1,x+7,y+2);
            g.setColor(shadow);
            g.fillRect(x+1,y+h-4,2,2);
            g.fillRect(x+3,y+h-3,2,2);
            g.fillRect(x+5,y+h-2,2,2);
            g.drawLine(x+7,y+3,x+7,y+h);
            g.drawLine(x+8,y+1,x+8,y+h);
            g.setColor(oldColor);
        }
    }

}
 
Example 20
Project: Logisim   File: PainterDin.java   View Source Code Vote up 4 votes
private static void paint(InstancePainter painter, int width, int height, boolean drawBubble, int dinType) {
	Graphics g = painter.getGraphics();
	int xMid = -width;
	int y0 = -height / 2;
	if (drawBubble) {
		width -= 8;
	}
	int diam = Math.min(height, 2 * width);
	if (dinType == AND) {
		; // nothing to do
	} else if (dinType == OR) {
		paintOrLines(painter, width, height, drawBubble);
	} else if (dinType == XOR || dinType == XNOR) {
		int elen = Math.min(diam / 2 - 10, 20);
		int ex0 = xMid + (diam / 2 - elen) / 2;
		int ex1 = ex0 + elen;
		g.drawLine(ex0, -5, ex1, -5);
		g.drawLine(ex0, 0, ex1, 0);
		g.drawLine(ex0, 5, ex1, 5);
		if (dinType == XOR) {
			int exMid = ex0 + elen / 2;
			g.drawLine(exMid, -8, exMid, 8);
		}
	} else {
		throw new IllegalArgumentException("unrecognized shape");
	}

	GraphicsUtil.switchToWidth(g, 2);
	int x0 = xMid - diam / 2;
	Color oldColor = g.getColor();
	if (painter.getShowState()) {
		Value val = painter.getPort(0);
		g.setColor(val.getColor());
	}
	g.drawLine(x0 + diam, 0, 0, 0);
	g.setColor(oldColor);
	if (height <= diam) {
		g.drawArc(x0, y0, diam, diam, -90, 180);
	} else {
		int x1 = x0 + diam;
		int yy0 = -(height - diam) / 2;
		int yy1 = (height - diam) / 2;
		g.drawArc(x0, y0, diam, diam, 0, 90);
		g.drawLine(x1, yy0, x1, yy1);
		g.drawArc(x0, y0 + height - diam, diam, diam, -90, 90);
	}
	g.drawLine(xMid, y0, xMid, y0 + height);
	if (drawBubble) {
		g.fillOval(x0 + diam - 4, -4, 8, 8);
		xMid += 4;
	}
}