List of usage examples for java.awt Graphics translate
public abstract void translate(int x, int y);
From source file:MessagePopup.java
public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(color);//from ww w. j av a2s.c o m g.translate(x, y); if (selected) { g.fillPolygon(poly); } else { g.drawPolygon(poly); } g.translate(-x, -y); }
From source file:components.ArrowIcon.java
public void paintIcon(Component c, Graphics g, int x, int y) { if (c.isEnabled()) { g.setColor(c.getForeground());// w ww . j a v a2 s . com } else { g.setColor(Color.gray); } g.translate(x, y); g.fillPolygon(xPoints, yPoints, xPoints.length); g.translate(-x, -y); //Restore graphics object }
From source file:CustomIconDemo.java
public void paintIcon(Component c, Graphics g, int x, int y) { if (c.isEnabled()) { g.setColor(c.getForeground());/*from w ww . j a v a 2 s . c om*/ } else { g.setColor(Color.gray); } g.translate(x, y); g.fillPolygon(xPoints, yPoints, xPoints.length); g.translate(-x, -y); // Restore graphics object }
From source file:Arrow.java
public void paintIcon(Component c, Graphics g, int x, int y) { Color color = c == null ? Color.GRAY : c.getBackground(); int dx = (int) (size / 2); int dy = descending ? dx : -dx; // Align icon (roughly) with font baseline. y = y + 5 * size / 6 + (descending ? -dy : 0); g.translate(x, y); g.setColor(Color.GRAY);/*from www .java 2 s .com*/ g.fillPolygon(new int[] { dx / 2, dx, 0 }, new int[] { dy, 0, 0 }, 3); g.translate(-x, -y); g.setColor(color); }
From source file:com.cburch.logisim.instance.InstanceFactory.java
@Override public final void paintIcon(ComponentDrawContext context, int x, int y, AttributeSet attrs) { InstancePainter painter = context.getInstancePainter(); painter.setFactory(this, attrs); Graphics g = painter.getGraphics(); g.translate(x, y); paintIcon(painter);// w w w.ja v a2 s .c o m g.translate(-x, -y); if (painter.getFactory() == null) { Icon i = icon; if (i == null) { String n = iconName; if (n != null) { i = Icons.getIcon(n); if (i == null) n = null; } } if (i != null) { i.paintIcon(context.getDestination(), g, x + 2, y + 2); } else { super.paintIcon(context, x, y, attrs); } } }
From source file:com.cburch.logisim.instance.InstanceFactory.java
@Override public final void drawGhost(ComponentDrawContext context, Color color, int x, int y, AttributeSet attrs) { InstancePainter painter = context.getInstancePainter(); Graphics g = painter.getGraphics(); g.setColor(color);/* w w w .jav a2 s . c o m*/ g.translate(x, y); painter.setFactory(this, attrs); paintGhost(painter); g.translate(-x, -y); if (painter.getFactory() == null) { super.drawGhost(context, color, x, y, attrs); } }
From source file:es.emergya.ui.base.plugins.PluggableJTabbedPane.java
@Override public void paint(Graphics g) { super.paint(g); for (JComponent bf : botones_flotantes) { try {// www .j ava 2s. c om g.translate(bf.getBounds().x, bf.getBounds().y); bf.paint(g); g.translate(-bf.getBounds().x, -bf.getBounds().y); } catch (Throwable t) { } } }
From source file:Main.java
private void paintArrow(Graphics g, int x, int y, Color highlight) { int mid, i, j; Color oldColor = g.getColor(); boolean isEnabled = isEnabled(); j = 0;//from w w w . j a v a2 s . c o m arrowSize = Math.max(arrowSize, 2); mid = (arrowSize / 2) - 1; g.translate(x, y); switch (direction) { case NORTH: for (i = 0; i < arrowSize; i++) { g.drawLine(mid - i, i, mid + i, i); } if (!isEnabled) { g.setColor(highlight); g.drawLine(mid - i + 2, i, mid + i, i); } break; case SOUTH: if (!isEnabled) { g.translate(1, 1); g.setColor(highlight); for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(mid - i, j, mid + i, j); j++; } g.translate(-1, -1); g.setColor(oldColor); } j = 0; for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(mid - i, j, mid + i, j); j++; } break; case WEST: for (i = 0; i < arrowSize; i++) { g.drawLine(i, mid - i, i, mid + i); } if (!isEnabled) { g.setColor(highlight); g.drawLine(i, mid - i + 2, i, mid + i); } break; case EAST: if (!isEnabled) { g.translate(1, 1); g.setColor(highlight); for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(j, mid - i, j, mid + i); j++; } g.translate(-1, -1); g.setColor(oldColor); } j = 0; for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(j, mid - i, j, mid + i); j++; } break; } g.translate(-x, -y); g.setColor(oldColor); }
From source file:JuliaSet2.java
public void print() { // Create some attributes objects. This is Java 1.3 stuff. // In Java 1.1, we'd use a java.util.Preferences object instead. JobAttributes jattrs = new JobAttributes(); PageAttributes pattrs = new PageAttributes(); // Set some example attributes: monochrome, landscape mode pattrs.setColor(PageAttributes.ColorType.MONOCHROME); pattrs.setOrientationRequested(PageAttributes.OrientationRequestedType.LANDSCAPE); // Print to file by default jattrs.setDestination(JobAttributes.DestinationType.FILE); jattrs.setFileName("juliaset.ps"); // Look up the Frame that holds this component Component frame = this; while (!(frame instanceof Frame)) frame = frame.getParent();//from w w w . ja v a 2 s .c o m // Get a PrintJob object to print the Julia set with. // The getPrintJob() method displays a print dialog and allows the user // to override and modify the default JobAttributes and PageAttributes Toolkit toolkit = this.getToolkit(); PrintJob job = toolkit.getPrintJob((Frame) frame, "JuliaSet1", jattrs, pattrs); // We get a null PrintJob if the user clicked cancel if (job == null) return; // Get a Graphics object from the PrintJob. // We print simply by drawing to this Graphics object. Graphics g = job.getGraphics(); // Center the image on the page Dimension pagesize = job.getPageDimension(); // how big is page? Dimension panesize = this.getSize(); // how big is image? g.translate((pagesize.width - panesize.width) / 2, // center it (pagesize.height - panesize.height) / 2); // Draw a box around the Julia Set and label it g.drawRect(-1, -1, panesize.width + 2, panesize.height + 2); g.drawString("Julia Set for c={" + cx + "," + cy + "}", 0, -15); // Set a clipping region g.setClip(0, 0, panesize.width, panesize.height); // Now print the component by calling its paint method this.paint(g); // Finally tell the printer we're done with the page. // No output will be generated if we don't call dispose() here. g.dispose(); }
From source file:RedGreenBorder.java
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Insets insets = getBorderInsets(c); Color horizontalColor;/*w ww. j a v a 2 s . co m*/ Color verticalColor; if (c.isEnabled()) { boolean pressed = false; if (c instanceof AbstractButton) { ButtonModel model = ((AbstractButton) c).getModel(); pressed = model.isPressed(); } if (pressed) { horizontalColor = Color.red; verticalColor = Color.green; } else { horizontalColor = Color.green; verticalColor = Color.red; } } else { horizontalColor = Color.lightGray; verticalColor = Color.lightGray; } g.setColor(horizontalColor); g.translate(x, y); // top g.fillRect(0, 0, width, insets.top); // bottom g.fillRect(0, height - insets.bottom, width, insets.bottom); g.setColor(verticalColor); // left g.fillRect(0, insets.top, insets.left, height - insets.top - insets.bottom); g.fillRect(width - insets.right, insets.top, insets.right, height - insets.top - insets.bottom); g.translate(-x, -y); }