Java Code Examples for java.awt.Graphics

The following are top voted examples for showing how to use java.awt.Graphics. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: oscm   File: ImageProducer.java   Source Code and License 7 votes vote down vote up
protected BufferedImage createImage(Color bgColor) {
    BufferedImage bufferedImage = new BufferedImage(END_X, END_Y,
            BufferedImage.TYPE_INT_RGB);
    // create graphics and graphics2d
    final Graphics graphics = bufferedImage.getGraphics();
    final Graphics2D g2d = (Graphics2D) graphics;

    // set the background color
    g2d.setBackground(bgColor == null ? Color.gray : bgColor);
    g2d.clearRect(START_X, START_Y, END_X, END_Y);
    // create a pattern for the background
    createPattern(g2d);
    // set the fonts and font rendering hints
    Font font = new Font("Helvetica", Font.ITALIC, 30);
    g2d.setFont(font);
    FontRenderContext frc = g2d.getFontRenderContext();
    g2d.translate(10, 24);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setStroke(new BasicStroke(3));

    // sets the foreground color
    g2d.setPaint(Color.DARK_GRAY);
    GlyphVector gv = font.createGlyphVector(frc, message);
    int numGlyphs = gv.getNumGlyphs();
    for (int ii = 0; ii < numGlyphs; ii++) {
        AffineTransform at;
        Point2D p = gv.getGlyphPosition(ii);
        at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate(Math.PI / 8);
        Shape shape = gv.getGlyphOutline(ii);
        Shape sss = at.createTransformedShape(shape);
        g2d.fill(sss);
    }
    return blurImage(bufferedImage);
}
 
Example 2
Project: incubator-netbeans   File: TreeView.java   Source Code and License 6 votes vote down vote up
private void guardedPaint(Graphics g) {
    if (firstPaint) {
        firstPaint = false;
        calcRowHeight(g);

        //This will generate a repaint, so don't bother continuing with super.paint()
        //but do paint the background color so it doesn't paint gray the first time
        g.setColor(getBackground());
        g.fillRect(0, 0, getWidth(), getHeight());

        return;
    }

    try {
        ExplorerTree.super.paint(g);
    } catch (NullPointerException ex) {
        // #139696: Making this issue more acceptable by not showing a dialog
        // still it deserves more investigation later
       LOG.log(Level.INFO, "Problems while painting", ex);  // NOI18N
    }
}
 
Example 3
Project: incubator-netbeans   File: HeaderButton.java   Source Code and License 6 votes vote down vote up
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect,
                          Rectangle textRect, Rectangle iconRect) {
    Graphics2D g2 = (Graphics2D)g;
    g2.setStroke(FOCUS_STROKE);
    g2.setColor(FOCUS_COLOR);
    g2.drawRect(2, 2, b.getWidth() - 5, b.getHeight() - 5);
}
 
Example 4
Project: jdk8u-jdk   File: MotifBorders.java   Source Code and License 6 votes vote down vote up
/** Draws the InternalFrameBorder's right border.
  */
protected boolean drawRightBorder(Component c, Graphics g, int x, int y,
                              int width, int height) {
    if (super.drawRightBorder(c, g, x, y, width, height) &&
        frame.isResizable()) {
        int startX = width - getBorderInsets(c).right;
        g.setColor(getFrameHighlight());
        int topY = y + CORNER_SIZE;
        g.drawLine(startX, topY, width - 2, topY);
        int bottomY = height - CORNER_SIZE;
        g.drawLine(startX + 1, bottomY, startX + 3, bottomY);
        g.setColor(getFrameShadow());
        g.drawLine(startX + 1, topY - 1, width - 2, topY - 1);
        g.drawLine(startX + 1, bottomY - 1, startX + 3, bottomY - 1);
        return true;
    }
    return false;
}
 
Example 5
Project: openjdk-jdk10   File: ParsedSynthStyle.java   Source Code and License 6 votes vote down vote up
public void paintComboBoxBackground(SynthContext context, Graphics g,
                                    int x, int y,
                                    int w, int h) {
    for (SynthPainter painter: painters) {
        painter.paintComboBoxBackground(context, g, x, y, w, h);
    }
}
 
Example 6
Project: rapidminer   File: DropDownButton.java   Source Code and License 6 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
	super.paintComponent(g);

	GeneralPath arrow = new GeneralPath();
	int w, h;
	h = (int) (2 * sizeFactor);
	w = (int) (4 * sizeFactor);
	arrow.moveTo(getWidth() / 2 - w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2 + w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2, getHeight() / 2 + 2 * h);
	arrow.closePath();
	if (isEnabled()) {
		g.setColor(Color.BLACK);
	} else {
		g.setColor(Color.GRAY);
	}
	((Graphics2D) g).fill(arrow);
}
 
Example 7
Project: openjdk-jdk10   File: BufferStrategyExceptionTest.java   Source Code and License 6 votes vote down vote up
public void render() {
    ImageCapabilities imgBackBufCap = new ImageCapabilities(true);
    ImageCapabilities imgFrontBufCap = new ImageCapabilities(true);
    BufferCapabilities bufCap =
        new BufferCapabilities(imgFrontBufCap,
            imgBackBufCap, BufferCapabilities.FlipContents.COPIED);
    try {

        createBufferStrategy(2, bufCap);
    } catch (AWTException ex) {
        createBufferStrategy(2);
    }

    BufferStrategy bs = getBufferStrategy();
    do {
        Graphics g =  bs.getDrawGraphics();
        g.setColor(Color.green);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(Color.red);
        g.drawString("Rendering test", 20, 20);

        g.drawImage(bi, 50, 50, null);

        g.dispose();
        bs.show();
    } while (bs.contentsLost()||bs.contentsRestored());
}
 
Example 8
Project: Logisim   File: PainterShaped.java   Source Code and License 6 votes vote down vote up
static void paintOr(InstancePainter painter, int width, int height) {
	Graphics g = painter.getGraphics();
	GraphicsUtil.switchToWidth(g, 2);
	/*
	 * The following, used previous to version 2.5.1, didn't use GeneralPath
	 * g.setColor(Color.LIGHT_GRAY); if (width < 40) {
	 * GraphicsUtil.drawCenteredArc(g, -30, -21, 36, -90, 53);
	 * GraphicsUtil.drawCenteredArc(g, -30, 21, 36, 90, -53); } else if (width < 60)
	 * { GraphicsUtil.drawCenteredArc(g, -50, -37, 62, -90, 53);
	 * GraphicsUtil.drawCenteredArc(g, -50, 37, 62, 90, -53); } else {
	 * GraphicsUtil.drawCenteredArc(g, -70, -50, 85, -90, 53);
	 * GraphicsUtil.drawCenteredArc(g, -70, 50, 85, 90, -53); } paintShield(g,
	 * -width, 0, width, height);
	 */

	GeneralPath path;
	if (width < 40) {
		path = PATH_NARROW;
	} else if (width < 60) {
		path = PATH_MEDIUM;
	} else {
		path = PATH_WIDE;
	}
	((Graphics2D) g).draw(path);
	if (height > width) {
		paintShield(g, 0, width, height);
	}
}
 
Example 9
Project: openjdk-jdk10   File: Slot.java   Source Code and License 6 votes vote down vote up
public int getWidth() {
    if (shortName == null || shortName.length() <= 1) {
        return Figure.SLOT_WIDTH;
    } else {
        BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setFont(figure.getDiagram().getSlotFont().deriveFont(Font.BOLD));
        FontMetrics metrics = g.getFontMetrics();
        return Math.max(Figure.SLOT_WIDTH, metrics.stringWidth(shortName) + 6);
    }
}
 
Example 10
Project: QN-ACTR-Release   File: DefaultIcons.java   Source Code and License 6 votes vote down vote up
public static Image getStationIcon(String type, Rectangle bounds) {
	BufferedImage bi = new BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_4BYTE_ABGR);
	Graphics g = bi.getGraphics();
	int qLength = bounds.width * 3 / 5, height = bounds.height, width = bounds.width;
	for (int i = 0, monoChannel = 0; i < 5; i++, monoChannel = (int) ((1 - Math.exp(-i)) * 50)) {
		g.setColor(new Color(230 - monoChannel, 230 - monoChannel, 230 - monoChannel, 255));
		g.drawPolyline(new int[] { i, i, qLength - i }, new int[] { height - i, i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 45, 180);
		g.setColor(new Color(130 + monoChannel, 130 + monoChannel, 130 + monoChannel, 255));
		g.drawPolyline(new int[] { i, qLength - i, qLength - i }, new int[] { height - i, height - i, i }, 3);
		g.fillArc(width - height + i, i, height - 2 * i, height - 2 * i, 225, 180);
	}
	g.fillRect(5, 5, qLength - 9, height - 9);
	g.fillOval(width - height + 5, 5, height - 10, height - 10);
	return bi;
}
 
Example 11
Project: Equella   File: FlatterTabbedPaneUI.java   Source Code and License 6 votes vote down vote up
@Override
protected void paintText(Graphics g, int tabPlacement, Font font, FontMetrics metrics, int tabIndex, String title,
	Rectangle textRect, boolean isSelected)
{
	g.setFont(font);

	View v = getTextViewForTab(tabIndex);
	if( v != null )
	{
		// html
		v.paint(g, textRect);
	}
	else
	{
		// plain text
		int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);

		if( tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex) )
		{
			g.setColor(isSelected ? Color.white : Color.black);
			BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
				textRect.y + metrics.getAscent());
		}
		else
		{ // tab disabled
			g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
			BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
				textRect.y + metrics.getAscent());
			g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
			BasicGraphicsUtils.drawStringUnderlineCharAt(g, title, mnemIndex, textRect.x,
				textRect.y + metrics.getAscent());
		}
	}
}
 
Example 12
Project: geomapapp   File: WWMap.java   Source Code and License 6 votes vote down vote up
public int print(Graphics g, PageFormat fmt, int pageNo) {
	if( pageNo>0 ) return NO_SUCH_PAGE;
	Graphics2D g2 = (Graphics2D)g;
	Dimension dim = wwd.getPreferredSize();
	Rectangle r = wwd.getBounds();

	if(r.width>dim.width) r.width = dim.width;
	if(r.height>dim.height) r.height = dim.height;

	org.geomapapp.util.DateFmt df = new org.geomapapp.util.DateFmt();
	int secs = (int)(System.currentTimeMillis()/1000L);
	String date = df.format(secs);
	Font font = new Font("SansSerif", Font.PLAIN, 8);
	g.setFont( font );
	Rectangle2D r2d = font.getStringBounds(date, g2.getFontRenderContext());
//	g2.translate( r.getWidth()-20.-r2d.getWidth(), r.getHeight()+18. );
	g2.setColor( Color.black);

//	g.setClip( new Rectangle( 0, 0, r.width, r.height) );
	double w = fmt.getImageableWidth();
	double h = fmt.getImageableHeight();
	double x = fmt.getImageableX();
	double y = fmt.getImageableY();
	g2.translate(x, y);
	double scale = Math.min( w / r.getWidth(), h / r.getHeight());
	int xd = (int)(scale*r.getWidth()-10.-r2d.getWidth());
	int yd = (int)(scale*r.getHeight()+18.);
	g2.drawString( date, xd, yd);
	g2.translate( -r.getX()*scale, -r.getY()*scale );
	g2.scale( scale, scale);

	wwd.getContext().makeCurrent();
	BufferedImage image = Screenshot.readToBufferedImage(r.width, r.height);
	g2.drawImage(image, 0, 0, this);
	return PAGE_EXISTS;
}
 
Example 13
Project: kettle_support_kettle8.0   File: Captcha.java   Source Code and License 6 votes vote down vote up
/**
 * 绘制干扰线
 */
private void drowLine(Graphics g) {
	int x = random.nextInt(width);
	int y = random.nextInt(height);
	int x0 = random.nextInt(16);
	int y0 = random.nextInt(16);
	g.drawLine(x, y, x + x0, y + y0);
}
 
Example 14
Project: incubator-netbeans   File: ComponentDocument.java   Source Code and License 6 votes vote down vote up
@Override
protected void paintComponent(Graphics graphics) {
    Graphics2D g = Config.getDefault().getGraphics(graphics);

    g.setColor(myBackgroundColor);
    g.fillRect(0, 0, myWidth, myHeight);

    int y = 0;

    for (int i = 0; i < myLines.size(); i++) {
        ComponentLine line = myLines.get(i);
        y += myCorrection[i] + myAscent[i];
        line.draw(g, myMinOffset, y);

        y += myDescent[i] + myLeading[i];
    }
}
 
Example 15
Project: gitplex-mit   File: AvatarGenerator.java   Source Code and License 6 votes vote down vote up
public static BufferedImage generate(int width, int height, String message,
		String fontFamily, Color background, Color foreground) {
	BufferedImage bi = new BufferedImage(width, height,
			BufferedImage.TYPE_INT_ARGB);

	Graphics ig2 = null;

	try {
		ig2 = bi.getGraphics();

		ig2.setColor(background);
		ig2.fillRect(0, 0, width, height);

		int fontSize = new Double(height * 0.5d).intValue();
		Font font = new Font(fontFamily, Font.PLAIN, fontSize);
		Map<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
		map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
		font = font.deriveFont(map);
		ig2.setFont(font);
		ig2.setColor(foreground);
		drawCenteredString(message.toUpperCase(), width, height, ig2);
	} finally {
		if (ig2 != null)
			ig2.dispose();
	}

	return bi;
}
 
Example 16
Project: PhySIX   File: Display.java   Source Code and License 6 votes vote down vote up
/**
 * creates a JFrame and a background Thread managing the rendering and the Frame itself.
 */
public static void create(){
if(!running){
	running = true;
	GFrame = new JFrame();
	GFrame.setVisible(true);
	RefreshWindow();
	RegisterInputDevices();
	BStrategy = GFrame.getBufferStrategy();
	setCurrentscreen(new EmptyScreen());
	PhySIX = new Thread(new Runnable(){
		@Override
		public void run() {
			try {
				while(GFrame.isVisible()){
					Graphics g = BStrategy.getDrawGraphics();
					clearScreen(g);
					updateDHs(g);
					renderDHs(g);
					drawDHs(g);
					drawmodels(g);
					UpdateStrat(g);
					Sync();
				}
			} catch (LessThanZeroException e) {
				e.printStackTrace();
			}
		}
	}, "Display-Loop-Thread.");
	PhySIX.start();
}
}
 
Example 17
Project: rapidminer   File: TransparentGlassPanePanel.java   Source Code and License 6 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
	// necessary for glass panes to see a transparent background
	// first paint the background
	setOpaque(true);
	super.paintComponent(g);
	// then show the transparency
	setOpaque(false);
}
 
Example 18
Project: incubator-netbeans   File: SimpleSeparator.java   Source Code and License 6 votes vote down vote up
public void paint(Graphics g) {
    g.setColor(new Color(192, 192, 192));
    Insets insets = getInsets();
    if (orientation == HORIZONTAL)
        g.drawLine(insets.left, insets.top, getWidth() - insets.right, insets.top);
    else
        g.drawLine(insets.left, insets.top, insets.left, getHeight() - insets.bottom);
}
 
Example 19
Project: jdk8u-jdk   File: ParsedSynthStyle.java   Source Code and License 6 votes vote down vote up
public void paintSliderTrackBackground(SynthContext context, Graphics g,
                                       int x, int y, int w, int h,
                                       int orientation) {
    for (SynthPainter painter: painters) {
        painter.paintSliderTrackBackground(context, g, x, y, w, h,
                                           orientation);
    }
}
 
Example 20
Project: Logisim   File: TableTab.java   Source Code and License 6 votes vote down vote up
private void computePreferredSize() {
	int inputs = table.getInputColumnCount();
	int outputs = table.getOutputColumnCount();
	if (inputs == 0 && outputs == 0) {
		setPreferredSize(new Dimension(0, 0));
		return;
	}

	Graphics g = getGraphics();
	if (g == null) {
		cellHeight = 16;
		cellWidth = 24;
	} else {
		FontMetrics fm = g.getFontMetrics(HEAD_FONT);
		cellHeight = fm.getHeight();
		cellWidth = 24;
		if (inputs == 0 || outputs == 0) {
			cellWidth = Math.max(cellWidth, fm.stringWidth(Strings.get("tableNullHeader")));
		}
		for (int i = 0; i < inputs + outputs; i++) {
			String header = i < inputs ? table.getInputHeader(i) : table.getOutputHeader(i - inputs);
			cellWidth = Math.max(cellWidth, fm.stringWidth(header));
		}
	}

	if (inputs == 0)
		inputs = 1;
	if (outputs == 0)
		outputs = 1;
	tableWidth = (cellWidth + COLUMN_SEP) * (inputs + outputs) - COLUMN_SEP;
	tableHeight = cellHeight * (1 + table.getRowCount()) + HEADER_SEP;
	setPreferredSize(new Dimension(tableWidth, tableHeight));
	revalidate();
	repaint();
}
 
Example 21
Project: VASSAL-src   File: Embellishment.java   Source Code and License 6 votes vote down vote up
public void draw(Graphics g, int x, int y, Component obs, double zoom) {
  final boolean drawUnder = drawUnderneathWhenSelected && Boolean.TRUE.equals(getProperty(Properties.SELECTED));

  if (!drawUnder) {
    piece.draw(g, x, y, obs, zoom);
  }

  checkPropertyLevel();

  if (!isActive()) {
    if (drawUnder) {
      piece.draw(g, x, y, obs, zoom);
    }
    return;
  }

  final int i = value - 1;

  if (i < imagePainter.length && imagePainter[i] != null) {
    final Rectangle r = getCurrentImageBounds();
    imagePainter[i].draw(g, x + (int)(zoom*r.x), y + (int)(zoom*r.y), zoom, obs);
  }

  if (drawUnder) {
    piece.draw(g, x, y, obs, zoom);
  }
}
 
Example 22
Project: OpenJSharp   File: RenderTests.java   Source Code and License 6 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    int size = rctx.size;
    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.fillOval(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.fillOval(x, y, size, size);
        } while (--numReps > 0);
    }
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
Example 23
Project: incubator-netbeans   File: AxisComponent.java   Source Code and License 6 votes vote down vote up
protected void paintVerticalTick(Graphics g, AxisMark mark, int y,
                                   Rectangle clip, Rectangle chartMask) {
    g.setColor(getForeground());
    if (location == SwingConstants.WEST) {
        g.drawLine(getWidth() - 2 - getAxisBasisExtent(), y, getWidth() - 2, y);
    } else {
        g.drawLine(1, y, 1 + getAxisBasisExtent(), y);
    }
}
 
Example 24
Project: powertext   File: RSyntaxTextAreaHighlighter.java   Source Code and License 6 votes vote down vote up
@Override
public void paintLayeredHighlights(Graphics g, int lineStart, int lineEnd,
					Shape viewBounds, JTextComponent editor, View view) {
	paintListLayered(g, lineStart,lineEnd, viewBounds, editor, view, markedOccurrences);
	super.paintLayeredHighlights(g, lineStart, lineEnd, viewBounds, editor, view);
	paintListLayered(g, lineStart,lineEnd, viewBounds, editor, view, parserHighlights);
}
 
Example 25
Project: openjdk-jdk10   File: CaretFloatingPointAPITest.java   Source Code and License 6 votes vote down vote up
@Override
public void paint(Graphics g) {

    if (component == null) {
        return;
    }

    int dot = getDot();
    Rectangle2D r = null;
    try {
        r = component.modelToView2D(dot);
    } catch (BadLocationException e) {
        return;
    }

    if (r == null) {
        return;
    }

    Rectangle2D cr = getCaretRectangle(r);
    repaint(cr.getBounds());

    g.setColor(component.getCaretColor());
    float cx = (float) cr.getX();
    float cy = (float) cr.getY();
    float cw = (float) cr.getWidth();
    float ch = (float) cr.getHeight();
    float c = cx + cw / 2;

    Graphics2D g2d = (Graphics2D) g;
    g2d.draw(new Line2D.Float(c, cy, c, cy + ch));
    g2d.draw(new Line2D.Float(cx, cy, cx + cw, cy));
    g2d.draw(new Line2D.Float(cx, cy + ch, cx + cw, cy + ch));
}
 
Example 26
Project: incubator-netbeans   File: HideableBarRenderer.java   Source Code and License 6 votes vote down vote up
public void paint(Graphics g) {
    g.setColor(getBackground());
    g.fillRect(location.x, location.y, size.width, size.height);
    
    JComponent component = mainRenderer.getComponent();
    int componentWidth = component.getPreferredSize().width;
    int componentX = size.width - componentWidth;
    
    mainRenderer.move(location.x + componentX, location.y);
    component.setSize(componentWidth, size.height);
    component.paint(g);
    
    int freeWidth = size.width - maxRendererWidth - renderersGap();
    if (freeWidth >= MIN_BAR_WIDTH) {
        barRenderer.setSize(Math.min(freeWidth, MAX_BAR_WIDTH), size.height);
        barRenderer.move(location.x, location.y);
        barRenderer.paint(g);
    }
}
 
Example 27
Project: jdk8u-jdk   File: LineBorder.java   Source Code and License 6 votes vote down vote up
/**
 * 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) {
    if ((this.thickness > 0) && (g instanceof Graphics2D)) {
        Graphics2D g2d = (Graphics2D) g;

        Color oldColor = g2d.getColor();
        g2d.setColor(this.lineColor);

        Shape outer;
        Shape inner;

        int offs = this.thickness;
        int size = offs + offs;
        if (this.roundedCorners) {
            float arc = .2f * offs;
            outer = new RoundRectangle2D.Float(x, y, width, height, offs, offs);
            inner = new RoundRectangle2D.Float(x + offs, y + offs, width - size, height - size, arc, arc);
        }
        else {
            outer = new Rectangle2D.Float(x, y, width, height);
            inner = new Rectangle2D.Float(x + offs, y + offs, width - size, height - size);
        }
        Path2D path = new Path2D.Float(Path2D.WIND_EVEN_ODD);
        path.append(outer, false);
        path.append(inner, false);
        g2d.fill(path);
        g2d.setColor(oldColor);
    }
}
 
Example 28
Project: JuggleMasterPro   File: PreferenceStringLocalColorJButton.java   Source Code and License 6 votes vote down vote up
/**
 * Method description
 * 
 * @see
 * @param objPgraphics
 */
@Override final public void paintComponent(Graphics objPgraphics) {

	// Draw a colored rectangle in place of the button :
	final int intLjButtonWidth = this.getWidth();
	final int intLjButtonHeight = this.getHeight();
	final BufferedImage imgLbuffer =
											Constants.objS_GRAPHICS_CONFIGURATION.createCompatibleImage(intLjButtonWidth,
																										intLjButtonHeight,
																										Transparency.OPAQUE);
	final Graphics2D objLgraphics2D = (Graphics2D) imgLbuffer.getGraphics();
	objLgraphics2D.setColor(Tools.getPenGammaColor(	this.objGpreferencesJDialog.strGstringLocalAA[this.bytGcolorPreferenceType][Constants.bytS_UNCLASS_TEMPORARY_CURRENT],
													Preferences.getGlobalBytePreference(Constants.bytS_BYTE_GLOBAL_GAMMA_CORRECTION)));
	objLgraphics2D.fillRect(1, 1, intLjButtonWidth - 2, intLjButtonHeight - 2);
	objLgraphics2D.setColor(Color.BLACK);
	objLgraphics2D.drawRect(0, 0, intLjButtonWidth, intLjButtonHeight);
	objLgraphics2D.dispose();
	objPgraphics.drawImage(imgLbuffer, 0, 0, null);
}
 
Example 29
Project: OpenJSharp   File: CompositionArea.java   Source Code and License 5 votes vote down vote up
private Rectangle getCaretRectangle(TextHitInfo caret) {
    int caretLocation = 0;
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        caretLocation = Math.round(layout.getCaretInfo(caret)[0]);
    }
    Graphics g = getGraphics();
    FontMetrics metrics = null;
    try {
        metrics = g.getFontMetrics();
    } finally {
        g.dispose();
    }
    return new Rectangle(TEXT_ORIGIN_X + caretLocation,
                         TEXT_ORIGIN_Y - metrics.getAscent(),
                         0, metrics.getAscent() + metrics.getDescent());
}
 
Example 30
Project: openjdk-jdk10   File: TestUnsupportedResolution.java   Source Code and License 5 votes vote down vote up
public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException
{
    if (pageIndex>0)
    {
        return NO_SUCH_PAGE;
    }

    StringBuffer s=new StringBuffer();
    for (int i=0;i<10;i++)
    {
        s.append("1234567890ABCDEFGHIJ");
    }

    int x=(int) pageFormat.getImageableX();
    int y=(int) (pageFormat.getImageableY()+50);
    graphics.drawString(s.toString(), x, y);

    return PAGE_EXISTS;
}
 
Example 31
Project: OpenJSharp   File: SynthToolBarUI.java   Source Code and License 5 votes vote down vote up
/**
 * Paints the toolbar.
 *
 * @param context context for the component being painted
 * @param g the {@code Graphics} object used for painting
 * @see #update(Graphics,JComponent)
 */
protected void paint(SynthContext context, Graphics g) {
    if (handleIcon != null && toolBar.isFloatable()) {
        int startX = toolBar.getComponentOrientation().isLeftToRight() ?
            0 : toolBar.getWidth() -
                SynthIcon.getIconWidth(handleIcon, context);
        SynthIcon.paintIcon(handleIcon, context, g, startX, 0,
                SynthIcon.getIconWidth(handleIcon, context),
                SynthIcon.getIconHeight(handleIcon, context));
    }

    SynthContext subcontext = getContext(
            toolBar, Region.TOOL_BAR_CONTENT, contentStyle);
    paintContent(subcontext, g, contentRect);
    subcontext.dispose();
}
 
Example 32
Project: FaceAnnotationTool   File: TestFrame.java   Source Code and License 5 votes vote down vote up
/**
	 * Create the frame.
	 */
	public TestFrame() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		contentPane.add(new JComponent() {
            public void paintComponent(Graphics g) {
            	Graphics2D g2d = (Graphics2D) g;
            	for(int i=0;i<200;i++){
            		g2d.fill(UniversalTool.getPointOval(0, 10*i, 5));
            		g2d.fill(UniversalTool.getPointOval(10*i, 0, 5));
            	}
            	
            	Ellipse e = UniversalTool.getTestEllipse(10);
            	Ellipse2D.Double ed = e.getErectedEllipse2D();
            		
        			//save old transform
        			AffineTransform old = g2d.getTransform();
        			for (Point_ p : e.getKeyPoints()){
        				g2d.fill(UniversalTool.getPointOval(p, 5));
        			}
//        			for(int i=0;i<12;i++){
//        				g2d.setTransform(old);
//        				trf.rotate(Math.toRadians(30*i),e.x,e.y);
//        				g2d.setTransform(trf);
//        				g2d.draw(ed);
//        			}
        			g2d.rotate(e.angle,e.x,e.y);
        			//draw elps
        			g2d.setColor(Color.GREEN);
        			
        			g2d.draw(ed);
        			//draw pts
        			g2d.setColor(Color.RED);
        			
        			//revert transform
        			g2d.setTransform(old);
//                g2d.setStroke(new BasicStroke(10));
//                g2d.draw(new Line2D.Float(30, 20, 80, 90));
            }
        });
		contentPane.repaint();
	}
 
Example 33
Project: lemon-framework   File: VerifyCodeUtils.java   Source Code and License 5 votes vote down vote up
private static void shearY(Graphics g, int w1, int h1, Color color) {  

      int period = random.nextInt(40) + 10; // 50;  

      boolean borderGap = true;  
      int frames = 20;  
      int phase = 7;  
      for (int i = 0; i < w1; i++) {  
          double d = (double) (period >> 1)  
                  * Math.sin((double) i / (double) period  
                          + (6.2831853071795862D * (double) phase)  
                          / (double) frames);  
          g.copyArea(i, 0, 1, h1, 0, (int) d);  
          if (borderGap) {  
              g.setColor(color);  
              g.drawLine(i, (int) d, i, 0);  
              g.drawLine(i, (int) d + h1, i, h1);  
          }  

      }  

  }
 
Example 34
Project: New-Kepard   File: JWindow.java   Source Code and License 5 votes vote down vote up
private void drawRocketWithBrakes(Graphics g, int startX,int startY, int rW, int rH, int bDist, int bW, int bH)
{
	g.drawOval(startX - rW, startY - rH, 2*rW, 2*rH);
	
	if(window.telemetry_booster_brakes[1])	//left
		g.fillRect(startX - rW - bDist - 2*bH, startY - bW, 2*bH, 2*bW);
	else g.drawRect(startX - rW - bDist - 2*bH, startY - bW, 2*bH, 2*bW);
	
	if(window.telemetry_booster_brakes[0])	//top
		g.fillRect(startX - bW, startY - rH - bDist - 2*bH, 2*bW, 2*bH);
	else g.drawRect(startX - bW, startY - rH - bDist - 2*bH, 2*bW, 2*bH);
	
	if(window.telemetry_booster_brakes[3])	//right
		g.fillRect(startX + rW + bDist, startY - bW, 2*bH, 2*bW);
	else g.drawRect(startX + rW + bDist, startY - bW, 2*bH, 2*bW);
	
	if(window.telemetry_booster_brakes[2])	//bottom
		g.fillRect(startX - bW, startY + rH + bDist, 2*bW, 2*bH);
	else g.drawRect(startX - bW, startY + rH + bDist, 2*bW, 2*bH);	
}
 
Example 35
Project: org.alloytools.alloy   File: OurAntiAlias.java   Source Code and License 5 votes vote down vote up
/**
 * Constructs an antialias-capable JTextPane with a DefaultHighlighter
 * associated with it.
 * 
 * @param attributes - see {@link edu.mit.csail.sdg.alloy4.OurUtil#make
 *            OurUtil.make(component, attributes...)}
 */
public static JTextPane pane(Object... attributes) {
	JTextPane ans = new JTextPane() {
		static final long serialVersionUID = 0;

		@Override
		public void paint(Graphics gr) {
			if (antiAlias && gr instanceof Graphics2D) {
				((Graphics2D) gr).setRenderingHint(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
			}
			super.paint(gr);
		}
	};
	OurUtil.make(ans, attributes);
	ans.setHighlighter(new DefaultHighlighter());
	map.put(ans, Boolean.TRUE);
	return ans;
}
 
Example 36
Project: brModelo   File: QuadroDeEdicao.java   Source Code and License 5 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background
    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    //renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    Graphics2D Canvas = (Graphics2D) g;

    Canvas.addRenderingHints(renderHints);

    Canvas.setStroke(new BasicStroke(
            1f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND));

    Canvas.setPaint(Color.BLACK);
    ProcessPaint(Canvas);
}
 
Example 37
Project: OpenJSharp   File: FontPanel.java   Source Code and License 5 votes vote down vote up
public void paintComponent( Graphics g ) {
    if ( updateBackBuffer ) {
        Dimension d = this.getSize();
        isPrinting = false;
        try {
            drawText( g, d.width, d.height );
        }
        catch ( CannotDrawException e ) {
            f2dt.fireChangeStatus( ERRORS[ e.id ], true );
            super.paintComponent(g);
            return;
        }
    }
    else {
      /// Screen refresh
      g.drawImage( backBuffer, 0, 0, this );
    }

    showingError = false;
    updateBackBuffer = false;
}
 
Example 38
Project: OpenJSharp   File: WindowsBorders.java   Source Code and License 5 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y,
        int width, int height) {

    JInternalFrame jif = null;
    if (c instanceof JInternalFrame) {
        jif = (JInternalFrame)c;
    } else if (c instanceof JInternalFrame.JDesktopIcon) {
        jif = ((JInternalFrame.JDesktopIcon)c).getInternalFrame();
    } else {
        return;
    }

    if (jif.isSelected()) {
        // Set the line color so the line border gets the correct
        // color.
        lineColor = activeColor;
        super.paintBorder(c, g, x, y, width, height);
    } else {
        lineColor = inactiveColor;
        super.paintBorder(c, g, x, y, width, height);
    }
}
 
Example 39
Project: openjdk-jdk10   File: SourceClippingBlitTest.java   Source Code and License 5 votes vote down vote up
static void initImage(GraphicsConfiguration gc, Image image) {
    Graphics g = image.getGraphics();
    g.setColor(Color.RED);
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    g.fillRect(0, 0, w, h);
    g.dispose();

    // need to 'accelerate' the image
    if (dstImage == null) {
        dstImage =
            gc.createCompatibleVolatileImage(TESTW, TESTH,
                                             Transparency.OPAQUE);
    }
    dstImage.validate(gc);
    g = dstImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.drawImage(image, 0, 0, null);
    g.drawImage(image, 0, 0, null);
}
 
Example 40
Project: sumo   File: ImageConverter.java   Source Code and License 5 votes vote down vote up
/**
 * Converts the given image to a gl compatible format if necessary and returns the data in the format GL_RGBA as GL_UNSIGNED_BYTE.
 * @param awtImage the image to be converted to an byte buffer
 * @return nio buffer
 */
public static ByteBuffer convert(BufferedImage awtImage)
{
	if(!isGlCompatibleAwtImage(awtImage))
	{
		BufferedImage convertImage = createGlCompatibleAwtImage(awtImage.getWidth(), awtImage.getHeight());
        // copy the source image into the produced image
        Graphics g = convertImage.getGraphics();
        g.setColor(new Color(0f, 0f, 0f, 0f));
        g.fillRect(0, 0, awtImage.getWidth(), awtImage.getHeight());
        g.drawImage(awtImage, 0, 0, null);
        awtImage = convertImage;
	}
	
       // build a byte buffer from the temporary image 
       // that be used by OpenGL to produce a texture.
       byte[] data = ((DataBufferByte) awtImage.getRaster().getDataBuffer()).getData(); 
       ByteBuffer imageBuffer = ByteBuffer.allocateDirect(data.length); 
       imageBuffer.order(ByteOrder.nativeOrder()); 
       imageBuffer.put(data, 0, data.length); 
       imageBuffer.flip();
       
       return imageBuffer; 
}
 
Example 41
Project: defense-solutions-proofs-of-concept   File: EquipmentListJPanel.java   Source Code and License 5 votes vote down vote up
/**
 * Sets the names of the equipment for which buttons should display.
 * @param equipmentNames the names of the equipment for which buttons should display.
 */
public void setEquipmentNames(List<String> equipmentNames) {
    removeAll();

    for (final String name : equipmentNames) {
        JButton button = new JButton(name) {
            @Override
            public void paint(Graphics g) {
                if (null == getIcon()) {
                    //Doing this here because it's expensive, so only
                    //do it when we actually need it.
                    setIcon(new ImageIcon(mil2525CSymbolController.getSymbolImage(name)));
                }
                super.paint(g);
            }
        };
        button.setFont(BUTTON_FONT);
        button.setHorizontalAlignment(SwingConstants.LEFT);
        button.setFocusable(false);
        button.setMaximumSize(new Dimension(Integer.MAX_VALUE, 60));
        button.setMinimumSize(new Dimension(0, 60));
        button.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                for (ActionListener listener : listeners) {
                    listener.actionPerformed(e);
                }
            }
        });
        add(button);
    }
}
 
Example 42
Project: OpenJSharp   File: Utilities.java   Source Code and License 5 votes vote down vote up
/**
 * Draws the given composed text passed from an input method.
 *
 * @param view View hosting text
 * @param attr the attributes containing the composed text
 * @param g  the graphics context
 * @param x  the X origin
 * @param y  the Y origin
 * @param p0 starting offset in the composed text to be rendered
 * @param p1 ending offset in the composed text to be rendered
 * @return  the new insertion position
 */
static int drawComposedText(View view, AttributeSet attr, Graphics g,
                            int x, int y, int p0, int p1)
                                 throws BadLocationException {
    Graphics2D g2d = (Graphics2D)g;
    AttributedString as = (AttributedString)attr.getAttribute(
        StyleConstants.ComposedTextAttribute);
    as.addAttribute(TextAttribute.FONT, g.getFont());

    if (p0 >= p1)
        return x;

    AttributedCharacterIterator aci = as.getIterator(null, p0, p1);
    return x + (int)SwingUtilities2.drawString(
                         getJComponent(view), g2d,aci,x,y);
}
 
Example 43
Project: Mujeed-Arabic-Prolog   File: PPTTabbedPaneUI.java   Source Code and License 5 votes vote down vote up
protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected)
{
	Polygon shape = new Polygon();

	shape.addPoint(x - (h / 4), y + h);
	shape.addPoint(x + (h / 4), y);
	shape.addPoint(x + w - (h / 4), y);

	if (isSelected || (tabIndex == (rects.length - 1)))
	{
		if (isSelected)
		{
			g.setColor(selectedColor);
		}
		else
		{
			g.setColor(unselectedColor);
		}
		shape.addPoint(x + w + (h / 4), y + h);
	}
	else
	{
		g.setColor(unselectedColor);
		shape.addPoint(x + w, y + (h / 2));
		shape.addPoint(x + w - (h / 4), y + h);
	}

	g.fillPolygon(shape);
}
 
Example 44
Project: ramus   File: TemplateSample.java   Source Code and License 5 votes vote down vote up
@Override
public void paint(Graphics g) {
    super.paint(g);
    if (active != null) {
        if (active.getDecompositionType() != diagramType) {
            active.setDecompositionType(diagramType);
            active.refresh();
            repaint();
        }
        active.paint((Graphics2D) g, getVisibleRect());
    }
}
 
Example 45
Project: jdk8u-jdk   File: GifTransparencyTest.java   Source Code and License 5 votes vote down vote up
protected BufferedImage createTestImage() {
    BufferedImage img = new BufferedImage(200, 200,
                                          BufferedImage.TYPE_INT_ARGB);
    Graphics g = img.createGraphics();

    g.setColor(Color.red);
    g.fillRect(50, 50, 100, 100);
    g.dispose();

    return img;
}
 
Example 46
Project: Logisim   File: Drawgates.java   Source Code and License 5 votes vote down vote up
static void paintSingleInputgate(Graphics g, int xpin, int y, int xinput, int youtput, boolean up) {
	int[] yPoints, xPoints;
	xPoints = new int[] { xpin, xpin, xinput };
	if (!up)
		yPoints = new int[] { y + AbstractTtlGate.height - AbstractTtlGate.pinheight, youtput, youtput };
	else
		yPoints = new int[] { y + AbstractTtlGate.pinheight, youtput, youtput };
	g.drawPolyline(xPoints, yPoints, 3);
}
 
Example 47
Project: openjdk-jdk10   File: SynthSliderUI.java   Source Code and License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void paintBorder(SynthContext context, Graphics g, int x,
                        int y, int w, int h) {
    context.getPainter().paintSliderBorder(context, g, x, y, w, h,
                                           slider.getOrientation());
}
 
Example 48
Project: Logisim   File: Clock.java   Source Code and License 5 votes vote down vote up
@Override
public void paintInstance(InstancePainter painter) {
	Graphics g = painter.getGraphics();
	Bounds bds = painter.getInstance().getBounds();
	int x = bds.getX();
	int y = bds.getY();
	painter.drawRoundBounds(Color.WHITE);
	GraphicsUtil.switchToWidth(g, 2);
	g.setColor(painter.getAttributeValue(StdAttr.ATTR_LABEL_COLOR));
	painter.drawLabel();

	boolean drawUp;
	if (painter.getShowState()) {
		ClockState state = getState(painter);
		g.setColor(state.sending.getColor());
		drawUp = state.sending == Value.TRUE;
	} else {
		g.setColor(Color.BLACK);
		drawUp = true;
	}
	x += 10;
	y += 10;
	int[] xs = { x - 6, x - 6, x, x, x + 6, x + 6 };
	int[] ys;
	if (drawUp) {
		ys = new int[] { y, y - 4, y - 4, y + 4, y + 4, y };
	} else {
		ys = new int[] { y, y + 4, y + 4, y - 4, y - 4, y };
	}
	g.drawPolyline(xs, ys, xs.length);

	painter.drawPorts();
}
 
Example 49
Project: JDigitalSimulator   File: Guitilities.java   Source Code and License 5 votes vote down vote up
public static int centerText(Direction direction, Graphics graphics, java.awt.Rectangle bounds, String text) {
	FontMetrics metrics = graphics.getFontMetrics();
	switch(direction) {
	case HORRIZONTAL: return bounds.x+bounds.width/2-metrics.stringWidth(text)/2;
	case VERTICAL: return bounds.y+(int)((bounds.height-metrics.getStringBounds(text, graphics).getHeight())/2+metrics.getAscent());
	default: return 0; }
}
 
Example 50
Project: Tarski   File: OurTree.java   Source Code and License 5 votes vote down vote up
/** We override the paint() method to avoid drawing the box around the "extra space" (if height is double height) */
@Override public void paint(Graphics g) {
   int w=getWidth(), h=getHeight(), y=h-height;
   Color background = isSelected ? UIManager.getColor("Tree.selectionBackground") : Color.WHITE;
   Color border = isFocused ? UIManager.getColor("Tree.selectionBorderColor") : null;
   if (background!=null) { g.setColor(background); g.fillRect(0, y, w, h-y); }
   if (border!=null && isSelected) { g.setColor(border); g.drawRect(0, y, w-1, h-1-y); }
   super.paint(g);
}
 
Example 51
Project: ramus   File: LineStyleAttributePlugin.java   Source Code and License 5 votes vote down vote up
public void paint(Graphics gr) {
    super.paint(gr);
    if (stroke == null)
        return;
    final Graphics2D g = (Graphics2D) gr;

    g.setColor(getForeground());
    g.setStroke(stroke);
    g.draw(new Line2D.Double(0, (double) getHeight() / 2, getWidth(),
            (double) getHeight() / 2));
}
 
Example 52
Project: openjdk-jdk10   File: ParsedSynthStyle.java   Source Code and License 4 votes vote down vote up
public void paintTextPaneBackground(SynthContext context,
             Graphics g, int x, int y, int w, int h) {
    getPainter(context, "textpanebackground", -1).
        paintTextPaneBackground(context, g, x, y, w, h);
}
 
Example 53
Project: openjdk-jdk10   File: RepaintArea.java   Source Code and License 4 votes vote down vote up
/**
 * Calls {@code Component.update(Graphics)} with given Graphics.
 */
protected void updateComponent(Component comp, Graphics g) {
    if (comp != null) {
        comp.update(g);
    }
}
 
Example 54
Project: jdk8u-jdk   File: ParsedSynthStyle.java   Source Code and License 4 votes vote down vote up
public void paintSplitPaneDragDivider(SynthContext context,
             Graphics g, int x, int y, int w, int h, int direction) {
    getPainter(context, "splitpanedragdivider", direction).
        paintSplitPaneDragDivider(context, g, x, y, w, h, direction);
}
 
Example 55
Project: OpenJSharp   File: CSSBorder.java   Source Code and License 4 votes vote down vote up
public void paint(Polygon shape, Graphics g, Color color, int side) {
    g.setColor(color);
    g.fillPolygon(shape);
}
 
Example 56
Project: jdk8u-jdk   File: Test6888156.java   Source Code and License 4 votes vote down vote up
@Override public void paintIcon(Component c, Graphics g, int w, int h) {
}
 
Example 57
Project: incubator-netbeans   File: NimbusEditorTabCellRenderer.java   Source Code and License 4 votes vote down vote up
public void paintBorder(Component c, Graphics g, int x, int y,
                        int width, int height) {
    return;
}
 
Example 58
Project: JDigitalSimulator   File: XorGate.java   Source Code and License 4 votes vote down vote up
@Override public void paint(Graphics graphics) {
	super.paint(graphics);
	paintLabel(graphics, "=1");
}
 
Example 59
Project: hearthstone   File: EscudoDivino.java   Source Code and License 4 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    g.setColor(new Color(255, 201, 14, 100));
    g.fillOval(8, 2, 128, 163);
}
 
Example 60
Project: QN-ACTR-Release   File: SampleQNAnimation.java   Source Code and License 4 votes vote down vote up
@Override
public void paint(Graphics g, ImageObserver io) {
	createQueue(g);
	createCPU(g);
	g.drawImage(this.overlayedShading, getBounds().x, getBounds().y, io);
}