Java Code Examples for java.awt.Graphics#drawLine()
The following examples show how to use
java.awt.Graphics#drawLine() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThinBevelBorder.java From visualvm with GNU General Public License v2.0 | 6 votes |
protected void paintRaisedBevel(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(getHighlightOuterColor(c)); g.drawLine(0, 0, 0, h - 2); g.drawLine(1, 0, w - 2, 0); g.setColor(getShadowOuterColor(c)); g.drawLine(0, h - 1, w - 1, h - 1); g.drawLine(w - 1, 0, w - 1, h - 2); g.translate(-x, -y); g.setColor(oldColor); }
Example 2
Source File: BasicBorders.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { if (!(c instanceof BasicSplitPaneDivider)) { return; } Component child; Rectangle cBounds; JSplitPane splitPane = ((BasicSplitPaneDivider)c). getBasicSplitPaneUI().getSplitPane(); Dimension size = c.getSize(); child = splitPane.getLeftComponent(); // This is needed for the space between the divider and end of // splitpane. g.setColor(c.getBackground()); g.drawRect(x, y, width - 1, height - 1); if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) { if(child != null) { g.setColor(highlight); g.drawLine(0, 0, 0, size.height); } child = splitPane.getRightComponent(); if(child != null) { g.setColor(shadow); g.drawLine(size.width - 1, 0, size.width - 1, size.height); } } else { if(child != null) { g.setColor(highlight); g.drawLine(0, 0, size.width, 0); } child = splitPane.getRightComponent(); if(child != null) { g.setColor(shadow); g.drawLine(0, size.height - 1, size.width, size.height - 1); } } }
Example 3
Source File: MyCursor.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Override public void paint(Graphics gr) { gr.setColor(Color.GREEN); ((Graphics2D)gr).setStroke(new BasicStroke(3)); gr.drawLine(0, 0, width, height); gr.drawLine(0, 0, width/2, 0); gr.drawLine(0, 0, 0, height/2); }
Example 4
Source File: UIRes.java From RipplePower with Apache License 2.0 | 5 votes |
public void paintIcon(Component c, Graphics g, int x, int y) { Color backgroundColor = c.getBackground(); g.setColor(backgroundColor != null ? backgroundColor : Color.white); g.fillRect(x, y, SIZE - 1, SIZE - 1); g.setColor(Color.gray); g.drawRect(x, y, SIZE - 1, SIZE - 1); g.setColor(Color.black); g.drawLine(x + 2, y + HALF_SIZE, x + (SIZE - 3), y + HALF_SIZE); }
Example 5
Source File: MyCursor.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Override public void paint(Graphics gr) { gr.setColor(Color.GREEN); ((Graphics2D)gr).setStroke(new BasicStroke(3)); gr.drawLine(0, 0, width, height); gr.drawLine(0, 0, width/2, 0); gr.drawLine(0, 0, 0, height/2); }
Example 6
Source File: MyCursor.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public void paint(Graphics gr) { gr.setColor(Color.GREEN); ((Graphics2D)gr).setStroke(new BasicStroke(3)); //arrow gr.drawLine(0, 0, width/2, height/2); gr.drawLine(0, 0, width/2, 0); gr.drawLine(0, 0, 0, height/2); //plus gr.drawRect(width/2 - 1, height/2 -1, width/2 - 1, height/2 - 1); gr.drawLine(width*3/4 - 1, height/2 - 1, width*3/4 - 1, height); gr.drawLine(width/2 - 1, height*3/4 - 1, width, height*3/4 - 1); }
Example 7
Source File: BevelArrowIcon.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Draws the arrow pointing up. * * @param g the graphics device. * @param xo ?? * @param yo ?? */ private void drawUpArrow(final Graphics g, final int xo, final int yo) { g.setColor(this.edge1); int x = xo + (this.size / 2); g.drawLine(x, yo, x, yo); x--; int y = yo + 1; int dx = 0; while (y + 3 < yo + this.size) { g.setColor(this.edge1); g.drawLine(x, y, x + 1, y); g.drawLine(x, y + 1, x + 1, y + 1); if (0 < dx) { g.setColor(this.fill); g.drawLine(x + 2, y, x + 1 + dx, y); g.drawLine(x + 2, y + 1, x + 1 + dx, y + 1); } g.setColor(this.edge2); g.drawLine(x + dx + 2, y, x + dx + 3, y); g.drawLine(x + dx + 2, y + 1, x + dx + 3, y + 1); x -= 1; y += 2; dx += 2; } g.setColor(this.edge1); g.drawLine(xo, yo + this.size - 3, xo + 1, yo + this.size - 3); g.setColor(this.edge2); g.drawLine(xo + 2, yo + this.size - 2, xo + this.size - 1, yo + this.size - 2); g.drawLine(xo, yo + this.size - 1, xo + this.size, yo + this.size - 1); }
Example 8
Source File: BevelBorder.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
protected void paintRaisedBevel(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(getHighlightOuterColor(c)); g.drawLine(0, 0, 0, h-2); g.drawLine(1, 0, w-2, 0); g.setColor(getHighlightInnerColor(c)); g.drawLine(1, 1, 1, h-3); g.drawLine(2, 1, w-3, 1); g.setColor(getShadowOuterColor(c)); g.drawLine(0, h-1, w-1, h-1); g.drawLine(w-1, 0, w-1, h-2); g.setColor(getShadowInnerColor(c)); g.drawLine(1, h-2, w-2, h-2); g.drawLine(w-2, 1, w-2, h-3); g.translate(-x, -y); g.setColor(oldColor); }
Example 9
Source File: RenderTests.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void runTest(Object ctx, int numReps) { RenderTests.Context rctx = (RenderTests.Context) ctx; int size = rctx.size - 1; int x = rctx.initX; int y = rctx.initY; Graphics g = rctx.graphics; g.translate(rctx.orgX, rctx.orgY); Color rCArray[] = rctx.colorlist; int ci = rctx.colorindex; if (rctx.animate) { do { if (rCArray != null) { g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]); } g.drawLine(x, y, x, y + size); if ((x -= 3) < 0) x += rctx.maxX; if ((y -= 1) < 0) y += rctx.maxY; } while (--numReps > 0); } else { do { if (rCArray != null) { g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]); } g.drawLine(x, y, x, y + size); } while (--numReps > 0); } rctx.colorindex = ci; g.translate(-rctx.orgX, -rctx.orgY); }
Example 10
Source File: VerificationCodeTool.java From OASystem with MIT License | 5 votes |
/** *Draw line interference *@param g Graphics * */ public void drawDisturbLine2(Graphics g){ int x1 = random.nextInt(IMG_WIDTH); int y1 = random.nextInt(IMG_HEIGHT); int x2 = random.nextInt(13); int y2 = random.nextInt(15); //x1 - The first point of the x coordinate. //y1 - The first point of the y coordinate //x2 - The second point of the x coordinate. //y2 - The second point of the y coordinate. //X1 and x2 is the starting point coordinates, x2 and y2 is end coordinates. g.drawLine(x1, y1, x1 - x2, y1 - y2); }
Example 11
Source File: ComplexDataset.java From osp with GNU General Public License v3.0 | 5 votes |
public void draw(DrawingPanel panel, Graphics g) { int w = panel.getWidth()-5+1; int h = panel.getHeight()-25; for(int i = 5; i<w; i++) { double theta = Math.PI*(-1+2*((float) i)/w); Color c = DisplayColors.phaseToColor(theta); g.setColor(c); g.drawLine(i, 5, i, h); } }
Example 12
Source File: MetalBorders.java From TencentKona-8 with GNU General Public License v2.0 | 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 13
Source File: LuckPopupMenuSeparatorUI.java From littleluck with Apache License 2.0 | 5 votes |
@Override public void paint(Graphics g, JComponent c) { Dimension s = c.getSize(); g.setColor(UIManager.getColor(LuckPopupMenuUIBundle.SEPEREATOR_COLOR)); g.drawLine(0, 0, s.width, 0); }
Example 14
Source File: XComponentPeer.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void draw3DRect(Graphics g, Color colors[], int x, int y, int width, int height, boolean raised) { Color c = g.getColor(); g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]); g.drawLine(x, y, x, y + height); g.drawLine(x + 1, y, x + width - 1, y); g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]); g.drawLine(x + 1, y + height, x + width, y + height); g.drawLine(x + width, y, x + width, y + height - 1); g.setColor(c); }
Example 15
Source File: MetalBorders.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { Color background; Color highlight; Color shadow; Window window = SwingUtilities.getWindowAncestor(c); if (window != null && window.isActive()) { background = MetalLookAndFeel.getPrimaryControlDarkShadow(); highlight = MetalLookAndFeel.getPrimaryControlShadow(); shadow = MetalLookAndFeel.getPrimaryControlInfo(); } else { background = MetalLookAndFeel.getControlDarkShadow(); highlight = MetalLookAndFeel.getControlShadow(); shadow = MetalLookAndFeel.getControlInfo(); } g.setColor(background); // Draw outermost lines g.drawLine( x+1, y+0, x+w-2, y+0); g.drawLine( x+0, y+1, x+0, y +h-2); g.drawLine( x+w-1, y+1, x+w-1, y+h-2); g.drawLine( x+1, y+h-1, x+w-2, y+h-1); // Draw the bulk of the border for (int i = 1; i < 5; i++) { g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1); } if ((window instanceof Frame) && ((Frame) window).isResizable()) { g.setColor(highlight); // Draw the Long highlight lines g.drawLine( corner+1, 3, w-corner, 3); g.drawLine( 3, corner+1, 3, h-corner); g.drawLine( w-2, corner+1, w-2, h-corner); g.drawLine( corner+1, h-2, w-corner, h-2); g.setColor(shadow); // Draw the Long shadow lines g.drawLine( corner, 2, w-corner-1, 2); g.drawLine( 2, corner, 2, h-corner-1); g.drawLine( w-3, corner, w-3, h-corner-1); g.drawLine( corner, h-3, w-corner-1, h-3); } }
Example 16
Source File: BEUtils.java From beautyeye with Apache License 2.0 | 4 votes |
/** * <pre> * <b>给一个距形区域绘制4个角效果,形状和坐标如下:</b> * A(x,y)----B(x+β) C(x+(w-β),y)---D(x+w,y) * | | * | | * | | * E(x,y+β) L(x+w,y+β) * * * F(x,y+(h-β)) K(x+w,y+(h-β)) * | | * | | * | | * G(x,y+h)----H(x+β,y+h) I(x+(w-β),y+h)----J(x+w,y+h) * </pre> * @param g * @param x 距形区的X坐标 * @param y 距形区的Y坐标 * @param w 距形区的宽 * @param h 距形区的高 * @param β 每个角的角长 * @author Jack Jiang, 2013-04-05 * @since 3.5 */ public static void draw4RecCorner(Graphics g,int x,int y,int w,int h,int β,Color c) { Color oldColor = g.getColor(); g.setColor(c); //top(A~B,C~D) g.drawLine(x, y, x+β, y); g.drawLine(x+(w-β), y, x+w, y); //left(A~E,F~G) g.drawLine(x,y, x, y+β); g.drawLine(x,y+(h-β), x,y+h ); //bottom(G~H,I~J) g.drawLine(x,y+h, x+β,y+h ); g.drawLine(x+(w-β),y+h, x+w,y+h ); //right(J~K,L~D) g.drawLine(x+w,y+h, x+w,y+(h-β) ); g.drawLine(x+w,y+β, x+w, y); g.setColor(oldColor); }
Example 17
Source File: MenuBarBorder.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
@Override public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.setColor(Colors.MENUBAR_BORDER); g.drawLine(0, h - 1, w, h - 1); }
Example 18
Source File: SyntaxView.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
@Override protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, int p1) { setRenderingHits((Graphics2D) graphics); Font saveFont = graphics.getFont(); Color saveColor = graphics.getColor(); SyntaxDocument doc = (SyntaxDocument) getDocument(); Segment segment = getLineBuffer(); // Draw the right margin first, if needed. This way the text overalys // the margin if (rightMarginColumn > 0) { int m_x = rightMarginColumn * graphics.getFontMetrics().charWidth('m'); int h = graphics.getFontMetrics().getHeight(); graphics.setColor(rightMarginColor); graphics.drawLine(m_x, y, m_x, y - h); } try { // Colour the parts Iterator<Token> i = doc.getTokens(p0, p1); int start = p0; while (i.hasNext()) { Token t = i.next(); // if there is a gap between the next token start and where we // should be starting (spaces not returned in tokens), then draw // it in the default type if (start < t.start) { doc.getText(start, t.start - start, segment); x = DEFAULT_STYLE.drawText(segment, x, y, graphics, this, start); } // t and s are the actual start and length of what we should // put on the screen. assume these are the whole token.... int l = t.length; int s = t.start; // ... unless the token starts before p0: if (s < p0) { // token is before what is requested. adgust the length and s l -= (p0 - s); s = p0; } // if token end (s + l is still the token end pos) is greater // than p1, then just put up to p1 if (s + l > p1) { l = p1 - s; } doc.getText(s, l, segment); x = styles.drawText(segment, x, y, graphics, this, t); start = t.end(); } // now for any remaining text not tokenized: if (start < p1) { doc.getText(start, p1 - start, segment); x = DEFAULT_STYLE.drawText(segment, x, y, graphics, this, start); } } catch (BadLocationException ex) { log.log(Level.SEVERE, "Requested: " + ex.offsetRequested(), ex); } finally { graphics.setFont(saveFont); graphics.setColor(saveColor); } return x; }
Example 19
Source File: CloseableTabbedPane.java From SikuliX1 with MIT License | 4 votes |
/** * Draw the icon at the specified location. Icon implementations may use the Component argument * to get properties useful for painting, e.g. the foreground or background color. * * @param c the component which the icon belongs to * @param g the graphic object to draw on * @param x the upper left point of the icon in the x direction * @param y the upper left point of the icon in the y direction */ public void paintIcon(Component c, Graphics g, int x, int y) { boolean doPaintCloseIcon = true; try { // JComponent.putClientProperty("isClosable", new Boolean(false)); JTabbedPane tabbedpane = (JTabbedPane) c; int tabNumber = tabbedpane.getUI().tabForCoordinate(tabbedpane, x, y); JComponent curPanel = (JComponent) tabbedpane.getComponentAt(tabNumber); Object prop = null; if ((prop = curPanel.getClientProperty("isClosable")) != null) { doPaintCloseIcon = (Boolean) prop; } } catch (Exception ignored) {/*Could probably be a ClassCastException*/ } if (doPaintCloseIcon) { x_pos = x; y_pos = y; int y_p = y + 1; if (normalCloseIcon != null && !mouseover) { normalCloseIcon.paintIcon(c, g, x, y_p); } else if (hooverCloseIcon != null && mouseover && !mousepressed) { hooverCloseIcon.paintIcon(c, g, x, y_p); } else if (pressedCloseIcon != null && mousepressed) { pressedCloseIcon.paintIcon(c, g, x, y_p); } else { y_p++; Color col = g.getColor(); if (mousepressed && mouseover) { g.setColor(Color.WHITE); g.fillRect(x + 1, y_p, 12, 13); } g.setColor(Color.GRAY); /* g.drawLine(x+1, y_p, x+12, y_p); g.drawLine(x+1, y_p+13, x+12, y_p+13); g.drawLine(x, y_p+1, x, y_p+12); g.drawLine(x+13, y_p+1, x+13, y_p+12); g.drawLine(x+3, y_p+3, x+10, y_p+10); */ if (mouseover) { g.setColor(Color.RED); } g.drawLine(x + 3, y_p + 4, x + 9, y_p + 10); g.drawLine(x + 4, y_p + 3, x + 10, y_p + 9); g.drawLine(x + 10, y_p + 3, x + 3, y_p + 10); g.drawLine(x + 10, y_p + 4, x + 4, y_p + 10); g.drawLine(x + 9, y_p + 3, x + 3, y_p + 9); g.setColor(col); if (fileIcon != null) { fileIcon.paintIcon(c, g, x + width, y_p); } } } }
Example 20
Source File: SoftBevelBorder.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Paints the border for the specified component with the specified * position and size. * @param c the component for which this border is being painted * @param g the paint graphics * @param x the x position of the painted border * @param y the y position of the painted border * @param width the width of the painted border * @param height the height of the painted border */ public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Color oldColor = g.getColor(); g.translate(x, y); if (bevelType == RAISED) { g.setColor(getHighlightOuterColor(c)); g.drawLine(0, 0, width-2, 0); g.drawLine(0, 0, 0, height-2); g.drawLine(1, 1, 1, 1); g.setColor(getHighlightInnerColor(c)); g.drawLine(2, 1, width-2, 1); g.drawLine(1, 2, 1, height-2); g.drawLine(2, 2, 2, 2); g.drawLine(0, height-1, 0, height-2); g.drawLine(width-1, 0, width-1, 0); g.setColor(getShadowOuterColor(c)); g.drawLine(2, height-1, width-1, height-1); g.drawLine(width-1, 2, width-1, height-1); g.setColor(getShadowInnerColor(c)); g.drawLine(width-2, height-2, width-2, height-2); } else if (bevelType == LOWERED) { g.setColor(getShadowOuterColor(c)); g.drawLine(0, 0, width-2, 0); g.drawLine(0, 0, 0, height-2); g.drawLine(1, 1, 1, 1); g.setColor(getShadowInnerColor(c)); g.drawLine(2, 1, width-2, 1); g.drawLine(1, 2, 1, height-2); g.drawLine(2, 2, 2, 2); g.drawLine(0, height-1, 0, height-2); g.drawLine(width-1, 0, width-1, 0); g.setColor(getHighlightOuterColor(c)); g.drawLine(2, height-1, width-1, height-1); g.drawLine(width-1, 2, width-1, height-1); g.setColor(getHighlightInnerColor(c)); g.drawLine(width-2, height-2, width-2, height-2); } g.translate(-x, -y); g.setColor(oldColor); }