List of usage examples for java.awt Graphics drawRect
public void drawRect(int x, int y, int width, int height)
From source file:DesktopManagerDemo.java
public void paintEventSquare(Graphics g, int value, int currwidth, int currheight, int cellwidth, int cellheight, Color color) { if (value != 0) { g.setColor(color);/*from w w w .j a v a 2 s.c o m*/ g.fillRect(currwidth, currheight, cellwidth, cellheight); g.setColor(Color.green); g.drawString("" + value, currwidth + 5, currheight + 14); } g.setColor(Color.black); g.drawRect(currwidth, currheight, cellwidth, cellheight); }
From source file:uk.co.modularaudio.mads.base.soundfile_player.ui.SoundfilePlayerWaveOverviewUiJComponent.java
@Override public void paintComponent(final Graphics g) { // log.trace("WaveOverview paint() called"); final int xWaveOffset = WAVE_OVERVIEW_BORDER_PIXELS + WAVE_OVERVIEW_INTRO_PIXELS; g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_BACKGROUND_COLOR); g.fillRect(1, 1, lastWidth - 1, lastHeight - 1); g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_BORDER_COLOR); g.drawRect(0, 0, lastWidth, lastHeight); if (staticThumbnail != null) { g.drawImage(staticThumbnail, xWaveOffset, WAVE_OVERVIEW_BORDER_PIXELS, null); } else {// w w w. j av a 2 s . com g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_WAVE_BG_COLOR); g.fillRect(xWaveOffset, WAVE_OVERVIEW_BORDER_PIXELS, lastOverviewWidth, lastOverviewHeight); if (internalPercentComplete >= 0) { g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_WAVE_FG_COLOR); final int yOffset = WAVE_OVERVIEW_BORDER_PIXELS + (lastOverviewHeight / 2); final int widthOfLine = (lastOverviewWidth * internalPercentComplete) / 100; g.drawLine(xWaveOffset, yOffset, xWaveOffset + widthOfLine, yOffset); } } g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_CURRENT_POSITION_COLOUR); final int actualPos = xWaveOffset + desiredNormalisedPositionPixel; g.drawLine(actualPos, WAVE_OVERVIEW_BORDER_PIXELS, actualPos, lastOverviewHeight); displayedNormalisedPositionPixel = desiredNormalisedPositionPixel; }
From source file:util.ui.PictureAreaIcon.java
public void paintIcon(final Component c, Graphics g, int x, int y) { if (mScaledIcon == null) { return;/*from ww w . jav a 2 s . c o m*/ } y += 2; Color color = g.getColor(); if (!colorsInEqualRange(c.getBackground(), c.getForeground()) && !mProgram.isExpired()) { g.setColor(c.getBackground()); g.fillRect(x, y, getIconWidth(), getIconHeight() - 2); } g.setColor(color); g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 3); y += 3; x += 3; if (mIsGrayFilter && !mIsExpired && mProgram.isExpired()) { ImageFilter filter = new GrayFilter(true, 60); mScaledIcon .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter))); mIsExpired = true; } if (c.getForeground().getAlpha() != 255) { ImageFilter filter = new RGBImageFilter() { public int filterRGB(int x, int y, int rgb) { if ((rgb & 0xff000000) != 0) { return (rgb & 0xffffff) | (c.getForeground().getAlpha() << 24); } return rgb; } }; mScaledIcon .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter))); } mScaledIcon.paintIcon(c, g, x, y); /* if(!mProgram.isExpired()) { g.setColor(color); } else { g.setColor(color); } */ mCopyrightText.paintIcon(null, g, x, y + mScaledIcon.getIconHeight()); if (mDescriptionLines > 0 && mDescriptionText != null) { mDescriptionText.paintIcon(null, g, x, y + mScaledIcon.getIconHeight() + mCopyrightText.getIconHeight() + 1); } g.setColor(color); }
From source file:ColorVariousObjects.java
public void paint(Graphics g) { Color c1 = new Color(255, 100, 100); Color c2 = new Color(100, 255, 100); Color c3 = new Color(100, 100, 255); g.setColor(c1);/*from w w w. j a va 2s . com*/ g.drawLine(0, 0, 100, 100); g.drawLine(0, 100, 100, 0); g.setColor(c2); g.drawLine(40, 25, 250, 180); g.drawLine(75, 90, 400, 400); g.setColor(c3); g.drawLine(20, 150, 400, 40); g.drawLine(5, 290, 80, 19); g.setColor(Color.red); g.drawOval(10, 10, 50, 50); g.fillOval(70, 90, 140, 100); g.setColor(Color.blue); g.drawOval(190, 10, 90, 30); g.drawRect(10, 10, 60, 50); g.setColor(Color.cyan); g.fillRect(100, 10, 60, 50); g.drawRoundRect(190, 10, 60, 50, 15, 15); }
From source file:org.esa.s1tbx.ocean.toolviews.polarview.polarplot.PolarCanvas.java
private void drawColorBar(Graphics g, Axis cAxis) { final Dimension cbSize = new Dimension((int) (graphSize.width * 0.03), (int) (Math.min(200, graphSize.height * 0.6))); final Point at = new Point(20, -30); g.translate(at.x, at.y);//www. ja va 2 s .c om g.drawImage(colorBar, 0, 0, cbSize.width, cbSize.height, this); g.drawRect(0, 0, cbSize.width, cbSize.height); g.translate(cbSize.width, cbSize.height); cAxis.draw(g, cbSize); g.drawString(cAxis.getUnit(), 50, 5); g.translate(-cbSize.width - at.x, -cbSize.height - at.y); }
From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java
private void drawColorBar(Graphics g, Axis cAxis) { final Dimension cbSize = new Dimension((int) (graphSize.width * 0.03), (int) (Math.min(200, graphSize.height * 0.6))); final Point at = new Point(20, -100); g.translate(at.x, at.y);/*from www . j ava 2 s . co m*/ g.drawImage(colorBar, 0, 0, cbSize.width, cbSize.height, this); g.drawRect(0, 0, cbSize.width, cbSize.height); g.translate(cbSize.width, cbSize.height); cAxis.draw(g, cbSize); g.drawString(cAxis.getUnit(), 50, 5); g.translate(-cbSize.width - at.x, -cbSize.height - at.y); }
From source file:AncestorTree.java
public void paint(Graphics g) { Color bColor = getBackground(); Icon icon = getIcon();/* w w w .ja va 2 s.c o m*/ g.setColor(bColor); int offset = 0; if (icon != null && getText() != null) offset = (icon.getIconWidth() + getIconTextGap()); g.fillRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); if (m_selected) { g.setColor(m_borderSelectionColor); g.drawRect(offset, 0, getWidth() - 1 - offset, getHeight() - 1); } super.paint(g); }
From source file:view.ImagePanel.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (bi != null) { try {/*from w w w.j a va 2 s. co m*/ Point p = getImageLocation(); g.drawImage(bi, p.x, p.y, this); g.setColor(Color.LIGHT_GRAY); g.drawRect(p.x, p.y, bi.getWidth(), bi.getHeight()); } catch (Exception e) { } } }
From source file:VASSAL.counters.Labeler.java
public static void drawLabel(Graphics g, String text, int x, int y, Font f, int hAlign, int vAlign, Color fgColor, Color bgColor, Color borderColor) { g.setFont(f);/* ww w . j av a 2 s . c o m*/ final int width = g.getFontMetrics().stringWidth(text + " "); final int height = g.getFontMetrics().getHeight(); int x0 = x; int y0 = y; switch (hAlign) { case CENTER: x0 = x - width / 2; break; case LEFT: x0 = x - width; break; } switch (vAlign) { case CENTER: y0 = y - height / 2; break; case BOTTOM: y0 = y - height; break; } if (bgColor != null) { g.setColor(bgColor); g.fillRect(x0, y0, width, height); } if (borderColor != null) { g.setColor(borderColor); g.drawRect(x0, y0, width, height); } g.setColor(fgColor); ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawString(" " + text + " ", x0, y0 + g.getFontMetrics().getHeight() - g.getFontMetrics().getDescent()); }
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 www . j ava 2s . c om // 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(); }