List of usage examples for java.awt Graphics drawLine
public abstract void drawLine(int x1, int y1, int x2, int y2);
(x1, y1)
and (x2, y2)
in this graphics context's coordinate system. From source file:edu.umn.cs.spatialHadoop.osm.OSMEdge.java
@Override public void draw(Graphics g, Rectangle fileMBR, int imageWidth, int imageHeight, double scale) { int x1 = (int) ((this.lon1 - fileMBR.x1) * imageWidth / fileMBR.getWidth()); int y1 = (int) ((this.lat1 - fileMBR.y1) * imageHeight / fileMBR.getHeight()); int x2 = (int) ((this.lon2 - fileMBR.x1) * imageWidth / fileMBR.getWidth()); int y2 = (int) ((this.lat2 - fileMBR.y1) * imageHeight / fileMBR.getHeight()); Color shape_color = g.getColor(); // Compute alpha to use based on edge length and image scale double geom_alpha = this.getLength() * scale; int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255); if (color_alpha == 0) return;/* w ww . ja v a 2s .c om*/ g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true)); g.drawLine(x1, y1, x2, y2); }
From source file:CornerCaret.java
public void paint(Graphics g) { JTextComponent comp = getComponent(); if (comp == null) return;/* w w w .jav a 2 s. c o m*/ int dot = getDot(); Rectangle r = null; try { r = comp.modelToView(dot); } catch (BadLocationException e) { return; } if (r == null) return; int dist = r.height * 4 / 5 - 3; // will be distance from r.y to top if ((x != r.x) || (y != r.y + dist)) { // paint() has been called directly, without a previous call to // damage(), so do some cleanup. (This happens, for example, when // the // text component is resized.) repaint(); // erase previous location of caret x = r.x; // set new values for x,y,width,height y = r.y + dist; width = 5; height = 5; } if (isVisible()) { g.setColor(comp.getCaretColor()); g.drawLine(r.x, r.y + dist, r.x, r.y + dist + 4); // 5 vertical // pixels g.drawLine(r.x, r.y + dist + 4, r.x + 4, r.y + dist + 4); // 5 horiz // px } }
From source file:oct.analysis.application.OCTSelection.java
public void drawSelection(Graphics g, int imageOffsetX, int imageOffsetY) { if (highlighted) { g.setColor(Color.pink);//from w w w .j a v a 2s . co m } else { g.setColor(Color.green); } //draw lines arround the area that is the selection int leftEdge = getSelectionLeftEdgeCoordinate(); int rightEdge = getSelectionRightEdgeCoordinate(); // g.drawRect(imageOffsetX + leftEdge - 1, imageOffsetY + yPositionOnOct - 1, width + 2, height + 2); //draw left line g.drawLine(imageOffsetX + leftEdge - 1, imageOffsetY + yPositionOnOct, imageOffsetX + leftEdge - 1, imageOffsetY + yPositionOnOct + height - 1); //draw right line g.drawLine(imageOffsetX + rightEdge + 1, imageOffsetY + yPositionOnOct, imageOffsetX + rightEdge + 1, imageOffsetY + yPositionOnOct + height - 1); //draw top line g.drawLine(imageOffsetX + leftEdge, imageOffsetY + yPositionOnOct, imageOffsetX + rightEdge, imageOffsetY + yPositionOnOct); //draw bottom line g.drawLine(imageOffsetX + leftEdge, imageOffsetY + yPositionOnOct + height, imageOffsetX + rightEdge, imageOffsetY + yPositionOnOct + height); //draw button for interacting with the selection drawSelectButton(g, imageOffsetX, imageOffsetY); drawn = true; }
From source file:SortableTable.java
/** * Draws the arrow pointing down./*w w w. j a v a 2s . c o m*/ * * @param g the graphics device. * @param xo ?? * @param yo ?? */ private void drawDownArrow(final Graphics g, final int xo, final int yo) { g.setColor(this.edge1); g.drawLine(xo, yo, xo + this.size - 1, yo); g.drawLine(xo, yo + 1, xo + this.size - 3, yo + 1); g.setColor(this.edge2); g.drawLine(xo + this.size - 2, yo + 1, xo + this.size - 1, yo + 1); int x = xo + 1; int y = yo + 2; int dx = this.size - 6; while (y + 1 < 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 + (this.size / 2), yo + this.size - 1, xo + (this.size / 2), yo + this.size - 1); }
From source file:Main.java
@Override public Shape paintLayer(Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view) { g.setColor(color == null ? c.getSelectionColor() : color); Rectangle rect = null;//from w ww .j av a 2 s . c o m if (offs0 == view.getStartOffset() && offs1 == view.getEndOffset()) { if (bounds instanceof Rectangle) { rect = (Rectangle) bounds; } else { rect = bounds.getBounds(); } } else { try { Shape shape = view.modelToView(offs0, Position.Bias.Forward, offs1, Position.Bias.Backward, bounds); rect = (shape instanceof Rectangle) ? (Rectangle) shape : shape.getBounds(); } catch (BadLocationException e) { return null; } } FontMetrics fm = c.getFontMetrics(c.getFont()); int baseline = rect.y + rect.height - fm.getDescent() + 1; g.drawLine(rect.x, baseline, rect.x + rect.width, baseline); g.drawLine(rect.x, baseline + 1, rect.x + rect.width, baseline + 1); return rect; }
From source file:ColorGradient.java
/** * Draw a color gradient from the top of the specified component to the * bottom. Start with the start color and change smoothly to the end *//*from w ww. ja v a2 s . co m*/ public void fillGradient(Component c, Graphics g, Color start, Color end) { Rectangle bounds = this.getBounds(); // How big is the component? // Get the red, green, and blue components of the start and end // colors as floats between 0.0 and 1.0. Note that the Color class // also works with int values between 0 and 255 float r1 = start.getRed() / 255.0f; float g1 = start.getGreen() / 255.0f; float b1 = start.getBlue() / 255.0f; float r2 = end.getRed() / 255.0f; float g2 = end.getGreen() / 255.0f; float b2 = end.getBlue() / 255.0f; // Figure out how much each component should change at each y value float dr = (r2 - r1) / bounds.height; float dg = (g2 - g1) / bounds.height; float db = (b2 - b1) / bounds.height; // Now loop once for each row of pixels in the component for (int y = 0; y < bounds.height; y++) { g.setColor(new Color(r1, g1, b1)); // Set the color of the row g.drawLine(0, y, bounds.width - 1, y); // Draw the row r1 += dr; g1 += dg; b1 += db; // Increment color components } }
From source file:SortableTable.java
/** * Draws the arrow pointing up.//from w w w . ja v a 2s . c om * * @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); }
From source file:com.jcraft.weirdx.Draw.java
static void reqPolyPoint(Client c, XDrawable d, GC gc) throws IOException { // int foo;/*from www . j a v a 2 s. co m*/ int n = c.length; InputOutput io = c.client; Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode); if (graphics == null) { io.readPad(n * 4); return; } boolean coor = false; if (c.data != 0) coor = true; if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { io.readPad(4 * n); return; } } int x, y; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; if (coor) { x = (short) io.readShort(); y = (short) io.readShort(); n--; graphics.drawLine(x, y, x, y); if (x <= sx) sx = x; if (x >= lx) lx = x; if (y <= sy) sy = y; if (y >= ly) ly = y; while (n != 0) { x += (short) io.readShort(); y += (short) io.readShort(); n--; graphics.drawLine(x, y, x, y); if (x <= sx) sx = x; if (x >= lx) lx = x; if (y <= sy) sy = y; if (y >= ly) ly = y; } } else { while (n != 0) { x = (short) io.readShort(); y = (short) io.readShort(); n--; graphics.drawLine(x, y, x, y); if (x <= sx) sx = x; if (x >= lx) lx = x; if (y <= sy) sy = y; if (y >= ly) ly = y; } } if (sx < 0) sx = 0; if (sy < 0) sy = 0; if (d instanceof XWindow) { ((XWindow) d).draw(sx, sy, lx - sx + 1, ly - sy + 1); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:edu.ku.brc.af.core.NavBox.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); Dimension dim = getSize();/*from w ww. jav a2 s . c o m*/ FontMetrics fm = g.getFontMetrics(); int strW = fm.stringWidth(name); int x = (dim.width - strW) / 2; Insets ins = getBorder().getBorderInsets(this); int y = 2 + fm.getAscent(); int lineW = dim.width - ins.left - ins.right; x = ins.left; int txtY = y; y += 3; g.setColor(Color.LIGHT_GRAY); g.drawLine(x, y, x + lineW, y); y++; minHeight = y; x++; g.setColor(Color.LIGHT_GRAY.darker()); g.drawLine(x, y, x + lineW, y); ((Graphics2D) g).setRenderingHints(UIHelper.createTextRenderingHints()); g.setColor(Color.BLUE.darker()); g.drawString(name, x, txtY); if (collapsableIconOpen != null) { if (iconRect == null) { iconRect = getBounds(); iconRect.x = iconRect.width - collapsableIconOpen.getIconWidth(); iconRect.y = 0; } g.drawImage(icon.getImage(), iconRect.x, iconRect.y, null); } }
From source file:VASSAL.build.module.map.LOS_Thread.java
public void draw(java.awt.Graphics g, Map m) { if (initializing || !visible) { return;/* www. j a va 2s .c o m*/ } g.setColor(threadColor); Point mapAnchor = map.componentCoordinates(anchor); Point mapArrow = map.componentCoordinates(arrow); g.drawLine(mapAnchor.x, mapAnchor.y, mapArrow.x, mapArrow.y); Board b; if (drawRange) { if (rangeScale > 0) { int dist = (int) (rangeRounding + anchor.getLocation().distance(arrow.getLocation()) / rangeScale); drawRange(g, dist); } else { b = map.findBoard(anchor); MapGrid grid = null; if (b != null) { grid = b.getGrid(); } if (grid != null && grid instanceof ZonedGrid) { Point bp = new Point(anchor); bp.translate(-b.bounds().x, -b.bounds().y); Zone z = ((ZonedGrid) b.getGrid()).findZone(bp); if (z != null) { grid = z.getGrid(); } } if (grid != null) { drawRange(g, grid.range(anchor, arrow)); } } } lastAnchor = mapAnchor; lastArrow = mapArrow; }