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: openjdk-jdk10   File: TestUnsupportedResolution.java   View source code 7 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 2
Project: incubator-netbeans   File: TreeView.java   View source code 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: jdk8u-jdk   File: MotifBorders.java   View source code 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 4
Project: OpenJSharp   File: CompositionArea.java   View source code 6 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 5
Project: rapidminer   File: DropDownButton.java   View source code 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 6
Project: QN-ACTR-Release   File: DefaultIcons.java   View source code 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 7
Project: OpenJSharp   File: SynthToolBarUI.java   View source code 6 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 8
Project: incubator-netbeans   File: ComponentDocument.java   View source code 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 9
Project: lemon-framework   File: VerifyCodeUtils.java   View source code 6 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 10
Project: New-Kepard   File: JWindow.java   View source code 6 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 11
Project: org.alloytools.alloy   File: OurAntiAlias.java   View source code 6 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 12
Project: brModelo   File: QuadroDeEdicao.java   View source code 6 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 13
Project: OpenJSharp   File: FontPanel.java   View source code 6 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 14
Project: OpenJSharp   File: WindowsBorders.java   View source code 6 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 15
Project: openjdk-jdk10   File: SourceClippingBlitTest.java   View source code 6 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 16
Project: sumo   File: ImageConverter.java   View source code 6 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 17
Project: incubator-netbeans   File: HideableBarRenderer.java   View source code 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 18
Project: JuggleMasterPro   File: PreferenceStringLocalColorJButton.java   View source code 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 19
Project: incubator-netbeans   File: HeaderButton.java   View source code 5 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 20
Project: openjdk-jdk10   File: ParsedSynthStyle.java   View source code 5 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 21
Project: openjdk-jdk10   File: BufferStrategyExceptionTest.java   View source code 5 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 22
Project: Logisim   File: PainterShaped.java   View source code 5 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 23
Project: openjdk-jdk10   File: Slot.java   View source code 5 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 24
Project: Equella   File: FlatterTabbedPaneUI.java   View source code 5 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 25
Project: geomapapp   File: WWMap.java   View source code 5 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 26
Project: kettle_support_kettle8.0   File: Captcha.java   View source code 5 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 27
Project: gitplex-mit   File: AvatarGenerator.java   View source code 5 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 28
Project: PhySIX   File: Display.java   View source code 5 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 29
Project: oscm   File: ImageProducer.java   View source code 5 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 30
Project: PengueeBot   File: GrabPanel.java   View source code 5 votes vote down vote up
private BufferedImage copyImage(BufferedImage source) {
	BufferedImage b = new BufferedImage(source.getWidth(),
			source.getHeight(), source.getType());
	Graphics g = b.getGraphics();
	g.drawImage(source, 0, 0, null);
	g.dispose();
	return b;
}
 
Example 31
Project: rapidminer   File: TransparentGlassPanePanel.java   View source code 5 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 32
Project: incubator-netbeans   File: SimpleSeparator.java   View source code 5 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 33
Project: jdk8u-jdk   File: ParsedSynthStyle.java   View source code 5 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 34
Project: Logisim   File: TableTab.java   View source code 5 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 35
Project: VASSAL-src   File: Embellishment.java   View source code 5 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 36
Project: OpenJSharp   File: RenderTests.java   View source code 5 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 37
Project: incubator-netbeans   File: AxisComponent.java   View source code 5 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 38
Project: powertext   File: RSyntaxTextAreaHighlighter.java   View source code 5 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 39
Project: openjdk-jdk10   File: CaretFloatingPointAPITest.java   View source code 5 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 40
Project: defense-solutions-proofs-of-concept   File: EquipmentListJPanel.java   View source code 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);
    }
}