Java Code Examples for java.awt.Graphics#drawRect()

The following examples show how to use java.awt.Graphics#drawRect() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: megamek   File: MechMapSet.java    License: GNU General Public License v2.0 6 votes vote down vote up
private void drawHeatControl(int t, boolean mtHeat) {
    int y = 0;
    int maxHeat, steps;
    if (mtHeat) {
        maxHeat = 50;
        steps = 2;
    } else {
        maxHeat = 30;
        steps = 4;
    }
    Graphics g = heatImage.getGraphics();
    for (int i = 0; i < maxHeat; i++) {
        y = 120 - (i + 1) * steps;
        if (i < t) {
            g.setColor(Color.red);
        } else {
            g.setColor(Color.lightGray);
        }
        g.fillRect(0, y, 10, steps);
        g.setColor(Color.black);
        g.drawRect(0, y, 10, steps);
    }
}
 
Example 2
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example 3
Source Project: netbeans   File: SplashUISupport.java    License: Apache License 2.0 6 votes vote down vote up
public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D)g;
    if (!isEnabled()) {
        g2d.setComposite(AlphaComposite.getInstance(
                AlphaComposite.SRC_OVER, 0.3f));
    }                
    Color oldColor = g.getColor();
    Dimension size = getSize();
    g.setColor(getBackground());
    g.fillRect(0, 0, size.width, size.height);
    int i = (size.height - SIZE) / 2;
    if (value.color != null) {
        g.setColor(Color.black);
        g.drawRect(i, i, SIZE, SIZE);
        g.setColor(value.color);
        g.fillRect(i + 1, i + 1, SIZE - 1, SIZE - 1);
    }
    if (value.text != null) {
        g.setColor(Color.black);
        if (value.color != null)
            g.drawString(value.text, i + SIZE + 5, i + SIZE);
        else
            g.drawString(value.text, 5, i + SIZE);
    }
    g.setColor(oldColor);
}
 
Example 4
Source Project: opt4j   File: ZoomRectangle.java    License: MIT License 6 votes vote down vote up
/**
 * Draws the zoom out rectangle.
 * 
 * @param component
 *            the component to be used as the observer if this icon has no
 *            image observer
 * @param graphics
 *            the graphics context
 */
protected void paintZoomingOutRectangle(Component component, Graphics graphics) {
	// draw box
	graphics.drawRect(getX2(), getY2(), getX1() - getX2(), getY1() - getY2());
	int innerBoxWidth = 5;
	graphics.drawRect(getX2() + (getX1() - getX2()) / 2 - innerBoxWidth, getY2() + (getY1() - getY2()) / 2
			- innerBoxWidth, 2 * innerBoxWidth, 2 * innerBoxWidth);

	if (isShowingFancyIcons()) {
		drawZoomOutIcon(component, graphics);
	} else {
		// draw simple minus sign
		graphics.drawLine(getX1() - signLength - signBorder, getY2() + signBorder + signMiddle, getX1()
				- signBorder, getY2() + signBorder + signMiddle);
	}
}
 
Example 5
Source Project: osp   File: CustomAxes.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the axes in a drawing panel.
 * @param panel
 * @param g
 */
public void draw(DrawingPanel panel, Graphics g) {
  if(!visible) {
    return;
  }
  if(interiorColor!=panel.getBackground()) {
    g.setColor(interiorColor);
    int gw = panel.getLeftGutter()+panel.getRightGutter();
    int gh = panel.getTopGutter()+panel.getLeftGutter();
    g.fillRect(panel.getLeftGutter(), panel.getTopGutter(), panel.getWidth()-gw, panel.getHeight()-gh);
    g.setColor(gridColor);
    g.drawRect(panel.getLeftGutter(), panel.getTopGutter(), panel.getWidth()-gw, panel.getHeight()-gh);
  }
  Iterator<Drawable> it = drawableList.iterator();
  while(it.hasNext()) {
    Drawable drawable = it.next();
    drawable.draw(panel, g);
  }
  titleLine.setX((panel.getXMax()+panel.getXMin())/2);
  if(panel.getTopGutter()>20) {
    titleLine.setY(panel.getYMax()+5/panel.getYPixPerUnit());
  } else {
    titleLine.setY(panel.getYMax()-25/panel.getYPixPerUnit());
  }
  titleLine.draw(panel, g);
}
 
Example 6
public void paintIcon(Component c, Graphics g, int x, int y) {
  Graphics2D g2d = (Graphics2D)g;
  Paint oldPaint = g2d.getPaint();

  if (color != null) {
    g2d.setPaint(color);
    g.fillRect(x, y, getIconWidth(), getIconHeight());
  }

  g.setColor(UIManager.getColor("controlDkShadow"));
  g.drawRect(x, y, getIconWidth(), getIconHeight());

  g2d.setPaint(oldPaint);
}
 
Example 7
public void paintBorder(Component c, Graphics g, int x, int y, int w,
                        int h) {
    g.translate(x, y);

    g.setColor(UIManager.getColor("controlShadow")); //NOI18N
    g.drawRect(0, 0, w - 2, h - 2);
    g.setColor(UIManager.getColor("controlHighlight")); //NOI18N
    g.drawLine(w - 1, 1, w - 1, h - 1);
    g.drawLine(1, h - 1, w - 1, h - 1);

    g.translate(-x, -y);
}
 
Example 8
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 9
Source Project: Bytecoder   File: BasicBorders.java    License: Apache License 2.0 5 votes vote down vote up
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();

    Color shade = shadow;
    Component p = b.getParent();
    if (p != null && p.getBackground().equals(shadow)) {
        shade = darkShadow;
    }

    if ((model.isRollover() && !(model.isPressed() && !model.isArmed())) ||
        model.isSelected()) {

        Color oldColor = g.getColor();
        g.translate(x, y);

        if (model.isPressed() && model.isArmed() || model.isSelected()) {
            // Draw the pressd button
            g.setColor(shade);
            g.drawRect(0, 0, w-1, h-1);
            g.setColor(lightHighlight);
            g.drawLine(w-1, 0, w-1, h-1);
            g.drawLine(0, h-1, w-1, h-1);
        } else {
            // Draw a rollover button
            g.setColor(lightHighlight);
            g.drawRect(0, 0, w-1, h-1);
            g.setColor(shade);
            g.drawLine(w-1, 0, w-1, h-1);
            g.drawLine(0, h-1, w-1, h-1);
        }
        g.translate(-x, -y);
        g.setColor(oldColor);
    }
}
 
Example 10
Source Project: SNT   File: Path.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void fillRect(final Graphics g, final Color gColor, final int x, final int y, int dim,
		final boolean highContrast) {
	if (highContrast) {
		if (dim < 4)
			dim = 4;
		g.fillRect(x, y, dim, dim);
		g.setColor(Color.BLACK);
		g.drawRect(x + 1, y + 1, dim - 4, dim - 4);
		g.setColor(Color.WHITE);
		g.drawRect(x + 2, y + 2, dim - 4, dim - 4);
		g.setColor(gColor);
	} else {
		g.fillRect(x, y, dim, dim);
	}
}
 
Example 11
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {

            g.translate(x,y);
            g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
            g.drawLine(0, 1, 0, h-2);
            g.drawLine(1, h-1, w-2, h-1);
            g.drawLine(w-1,  1, w-1, h-2);
            g.drawLine( 1, 0, w-2, 0);
            g.drawRect(1,1, w-3, h-3);
            g.translate(-x,-y);

        }
 
Example 12
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.drawRect(x, y, size, 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.drawRect(x, y, size, size);
        } while (--numReps > 0);
    }
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 13
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
    g.translate( x, y );

    g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
    g.drawRect( 0, 0, w - 1, h - 1 );

    g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
    g.drawLine( 1, 1, w - 2, 1 );
    g.drawLine( 1, 2, 1, 2 );
    g.drawLine( 1, h - 2, 1, h - 2 );

    g.translate( -x, -y );

}
 
Example 14
Source Project: hottub   File: MyCursor.java    License: GNU General Public License v2.0 5 votes vote down vote up
@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 15
@Override
public void paint(Graphics g) {
	if (map == null)
		return;
	int h = getSize().height - 10;
	int w = getSize().width - 10;
	int M = map.length;
	int N = map[0].length;
	int cell_h = h / M;
	int cell_w = w / N;
	int y0 = (getSize().height - M * cell_h) / 2;
	int x0 = (getSize().width - N * cell_w) / 2;
	int x, y, c;
	if (color != null) {
		for (int i = 0; i < M; ++i) {
			for (int j = 0; j < N; ++j) {
				x = x0 + j * cell_w;
				y = y0 + i * cell_h;
				c = color[map[i][j]];
				g.setColor(ct[c]);
				g.fillRect(x, y, cell_w, cell_h);
			}
		}
	}
	g.setColor(Color.black);
	g.drawRect(x0, y0, N * cell_w, M * cell_h);
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			x = x0 + j * cell_w;
			y = y0 + i * cell_h;
			if (i < M - 1 && map[i][j] != map[i + 1][j]) {
				g.drawLine(x, y + cell_h, x + cell_w, y + cell_h);
			}
			if (j < N - 1 && map[i][j] != map[i][j + 1]) {
				g.drawLine(x + cell_w, y, x + cell_w, y + cell_h);
			}
		}
	}
}
 
Example 16
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {

            g.translate(x,y);
            g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
            g.drawLine(0, 1, 0, h-2);
            g.drawLine(1, h-1, w-2, h-1);
            g.drawLine(w-1,  1, w-1, h-2);
            g.drawLine( 1, 0, w-2, 0);
            g.drawRect(1,1, w-3, h-3);
            g.translate(-x,-y);

        }
 
Example 17
@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 18
public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
    g.translate( x, y );

    g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
    g.drawRect( 0, 0, w - 1, h - 1 );

    g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
    g.drawLine( 1, 1, w - 2, 1 );
    g.drawLine( 1, 2, 1, 2 );
    g.drawLine( 1, h - 2, 1, h - 2 );

    g.translate( -x, -y );

}
 
Example 19
public void paintIcon(Component c, Graphics g, int x, int y) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();

    boolean flat = false;

    if(b instanceof JCheckBox) {
        flat = ((JCheckBox)b).isBorderPaintedFlat();
    }

    boolean isPressed = model.isPressed();
    boolean isArmed = model.isArmed();
    boolean isEnabled = model.isEnabled();
    boolean isSelected = model.isSelected();

    // There are 4 "looks" to the Motif CheckBox:
    //  drawCheckBezelOut  -  default unchecked state
    //  drawBezel          -  when we uncheck in toggled state
    //  drawCheckBezel     -  when we check in toggle state
    //  drawCheckBezelIn   -  selected, mouseReleased
    boolean checkToggleIn = ((isPressed &&
                              !isArmed   &&
                              isSelected) ||
                             (isPressed &&
                              isArmed   &&
                              !isSelected));
    boolean uncheckToggleOut = ((isPressed &&
                                 !isArmed &&
                                 !isSelected) ||
                                (isPressed &&
                                 isArmed &&
                                 isSelected));

    boolean checkIn = (!isPressed  &&
                       isArmed    &&
                       isSelected  ||
                       (!isPressed &&
                        !isArmed  &&
                        isSelected));


    if(flat) {
        g.setColor(shadow);
        g.drawRect(x+2,y,csize-1,csize-1);
        if(uncheckToggleOut || checkToggleIn) {
            g.setColor(control);
            g.fillRect(x+3,y+1,csize-2,csize-2);
        }
    }

    if (checkToggleIn) {
        // toggled from unchecked to checked
        drawCheckBezel(g,x,y,csize,true,false,false,flat);
    } else if (uncheckToggleOut) {
        // MotifBorderFactory.drawBezel(g,x,y,csize,csize,false,false);
        drawCheckBezel(g,x,y,csize,true,true,false,flat);
    } else if (checkIn) {
        // show checked, unpressed state
        drawCheckBezel(g,x,y,csize,false,false,true,flat);
    } else if(!flat) {
        //  show unchecked state
        drawCheckBezelOut(g,x,y,csize);
    }
}
 
Example 20
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
    boolean isPressed = false;
    boolean hasFocus = false;
    boolean canBeDefault = false;
    boolean isDefault = false;

    if (c instanceof AbstractButton) {
        AbstractButton b = (AbstractButton)c;
        ButtonModel model = b.getModel();

        isPressed = (model.isArmed() && model.isPressed());
        hasFocus = (model.isArmed() && isPressed) ||
                   (b.isFocusPainted() && b.hasFocus());
        if (b instanceof JButton) {
            canBeDefault = ((JButton)b).isDefaultCapable();
            isDefault = ((JButton)b).isDefaultButton();
        }
    }
    int bx1 = x+1;
    int by1 = y+1;
    int bx2 = x+w-2;
    int by2 = y+h-2;

    if (canBeDefault) {
        if (isDefault) {
            g.setColor(shadow);
            g.drawLine(x+3, y+3, x+3, y+h-4);
            g.drawLine(x+3, y+3, x+w-4, y+3);

            g.setColor(highlight);
            g.drawLine(x+4, y+h-4, x+w-4, y+h-4);
            g.drawLine(x+w-4, y+3, x+w-4, y+h-4);
        }
        bx1 +=6;
        by1 += 6;
        bx2 -= 6;
        by2 -= 6;
    }

    if (hasFocus) {
        g.setColor(focus);
        if (isDefault) {
            g.drawRect(x, y, w-1, h-1);
        } else {
            g.drawRect(bx1-1, by1-1, bx2-bx1+2, by2-by1+2);
        }
    }

    g.setColor(isPressed? shadow : highlight);
    g.drawLine(bx1, by1, bx2, by1);
    g.drawLine(bx1, by1, bx1, by2);

    g.setColor(isPressed? highlight : shadow);
    g.drawLine(bx2, by1+1, bx2, by2);
    g.drawLine(bx1+1, by2, bx2, by2);
}