Java Code Examples for java.awt.Graphics2D#fillRoundRect()

The following examples show how to use java.awt.Graphics2D#fillRoundRect() . 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 check out the related API usage on the sidebar.
Example 1
private void drawButtonInfo(Graphics2D g, String s, Symbol button) {
	g.setFont(sensorReadingFont);
	int stringWidth = g.getFontMetrics().stringWidth(s);
	g.setStroke(thinStroke);
	g.setColor(Color.black);
	switch (controlPanelPosition) {
	case 0:
		g.fillRoundRect(button.xSymbol + (button.wSymbol - stringWidth) / 2 - 5, button.ySymbol - 24, stringWidth + 10, 20, 8, 8);
		g.setColor(Color.white);
		g.drawString(s, button.xSymbol + (button.wSymbol - stringWidth) / 2, button.ySymbol - 12);
		break;
	case 1:
		g.fillRoundRect(button.xSymbol + (button.wSymbol - stringWidth) / 2 - 5, button.ySymbol + button.getSymbolHeight() + 8, stringWidth + 10, 20, 8, 8);
		g.setColor(Color.white);
		g.drawString(s, button.xSymbol + (button.wSymbol - stringWidth) / 2, button.ySymbol + button.getSymbolHeight() + 20);
		break;
	}
}
 
Example 2
public void paintIcon(Component c, Graphics g, int x, int y) {
	super.paintIcon(c, g, xSymbol, ySymbol);
	Graphics2D g2 = (Graphics2D) g;
	String s = "Energy2D";
	g2.setFont(font);
	FontMetrics fm = g.getFontMetrics();
	wSymbol = fm.stringWidth(s) + 10;
	hSymbol = fm.getHeight() + fm.getDescent() + 3;
	xSymbol = x - 6;
	ySymbol = y - fm.getAscent() - 3;
	g2.setColor(Color.gray);
	g2.fillRoundRect(xSymbol, ySymbol, wSymbol, hSymbol, cornerDiameter, cornerDiameter);
	g2.setStroke(stroke);
	g2.setColor(color);
	g2.drawRoundRect(xSymbol, ySymbol, wSymbol, hSymbol, cornerDiameter, cornerDiameter);
	g2.setColor(Color.black);
	g2.drawString(s, x + 1, y - 1);
	g2.drawString(s, x + 1, y + 1);
	g2.drawString(s, x - 1, y - 1);
	g2.drawString(s, x - 1, y + 1);
	g2.setColor(Color.lightGray);
	g2.drawString(s, x, y);
}
 
Example 3
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
    int alpha = isThumbRollover() ? SCROLL_BAR_ALPHA_ROLLOVER : SCROLL_BAR_ALPHA;
    int orientation = scrollbar.getOrientation();
    int arc = THUMB_SIZE;
    int x = thumbBounds.x + THUMB_BORDER_SIZE;
    int y = thumbBounds.y + THUMB_BORDER_SIZE;

    int width = orientation == JScrollBar.VERTICAL ?
            THUMB_SIZE : thumbBounds.width - (THUMB_BORDER_SIZE * 2);
    width = Math.max(width, THUMB_SIZE);

    int height = orientation == JScrollBar.VERTICAL ?
            thumbBounds.height - (THUMB_BORDER_SIZE * 2) : THUMB_SIZE;
    height = Math.max(height, THUMB_SIZE);

    Graphics2D graphics2D = (Graphics2D) g.create();
    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.setColor(new Color(THUMB_COLOR.getRed(),
            THUMB_COLOR.getGreen(), THUMB_COLOR.getBlue(), alpha));
    graphics2D.fillRoundRect(x, y, width, height, arc, arc);
    graphics2D.dispose();
}
 
Example 4
@Override
protected void paintComponent(Graphics g) {
       super.paintComponent(g);

       if(isOpaque()) {
          return;
       }
	if(bgGradient1 == null || bgGradient2 == null) {
		return;
	}

	Graphics2D g2 = (Graphics2D) g;
       g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
       int w = getWidth();
       int h = getHeight();

       GradientPaint gradient = new GradientPaint(0, 0, bgGradient1, 0, h, bgGradient2, false);
       g2.setPaint(gradient);

       g2.fillRoundRect(0, 0, w, h, border.getCornerRadius(), border.getCornerRadius());

       if(additionalPaint != null) {
           additionalPaint.additionalPaint(g2, w, h);
       }
}
 
Example 5
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(getBackground());
    g2d.fillRoundRect(0, 0, getWidth(), getHeight(), cornerRadius, cornerRadius);
}
 
Example 6
Source Project: oim-fx   File: ImageUtil.java    License: MIT License 5 votes vote down vote up
public static BufferedImage getRoundedCornerBufferedImage(String imagePath, int width, int height, int cornersWidth, int cornerHeight) {
    try {
        File imageFile = new File(imagePath);
        if (imageFile.exists()) {
            BufferedImage image = ImageIO.read(imageFile); // BufferedImage)
            // Toolkit.getDefaultToolkit().getImage(imagePath);

            int w = image.getWidth();
            int h = image.getHeight();
            if (0 != width && 0 < width) {
                w = width;
            }
            if (0 != height && 0 < height) {
                h = height;
            }
            BufferedImage output = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = output.createGraphics();
            g2.setComposite(AlphaComposite.Src);
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            // g2.setColor(new Color(0,0,0));
            // g2.setBackground(Color);
            g2.setStroke(new BasicStroke(1));
            g2.fillRoundRect(0, 0, w, h, cornersWidth, cornerHeight);
            // g2.setComposite(AlphaComposite.Src);
            // g2.fill(new RoundRectangle2D.Float(0, 0, w, h, cornersWidth,
            // cornerHeight));
            g2.setComposite(AlphaComposite.SrcAtop);
            // g2.setColor(Color.white);//这里设置背景颜色
            // g2.fillRect(0, 0, w, h);//这里填充背景颜色
            g2.drawImage(image, 0, 0, w, h, null);
            g2.dispose();
            return output;
        }
    } catch (IOException ex) {
        Logger.getLogger(ImageUtil.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
 
Example 7
private void drawSelectedFill(Graphics g) {
    final Graphics2D g2d = (Graphics2D) g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(HIGHLIGHT_COLOR);
    g2d.fillRoundRect(0, 0, getWidth(), getHeight()-1, 16, 16);
    drawSelectedRoundBorder(g, MagicStyle.getRolloverColor());
}
 
Example 8
@Override
public void draw(Graphics2D g2) {
	int color = 0xFFFFCC00;
	if (!enabled) {
		color = 0xFFC0C0C0;
	} else
	if (pressed) {
		color = 0xFFFF0000;
	} else
	if (selected) {
		color = 0xFFFFFFFF;
	}
	Composite save0 = g2.getComposite();
	g2.setComposite(AlphaComposite.SrcOver.derive(0.5f));
	if (selected) {
		g2.setColor(new Color(224, 0, 0));
		g2.fillRoundRect(0, 0, width, height, 10, 10);
	} else {
		g2.setColor(Color.BLACK);
		g2.fillRoundRect(0, 0, width, height, 10, 10);
	}
	g2.setComposite(save0);

	String s = get(label);
	
	int dx = (width - commons.text().getTextWidth(size, s)) / 2;
	
	commons.text().paintTo(g2, dx + 2, 7, size, 0xFF000000, s);
	commons.text().paintTo(g2, dx + 1, 6, size, 0xFF000000, s);
	commons.text().paintTo(g2, dx + 0, 5, size, color, s);
}
 
Example 9
public static Image[] getColorIcons(Model model){
	Stroke outlineStroke = new BasicStroke(2.0f);
	Stroke holeStroke = new BasicStroke(2.0f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_ROUND,19.0f,new float[]{3.0f,1.0f},0.0f);
	Color holeColor = new Color(213, 246, 255);
	Color holeStrokeColor = new Color(0,102,128);
	
	Image[] icons = new Image[16];
	for(int i = 0; i < 16; i++){
		BufferedImage icon = new BufferedImage(32,32,BufferedImage.TYPE_INT_ARGB);
		icons[i] = icon;
		Graphics2D g2d = (Graphics2D)icon.getGraphics();
		g2d.setFont(Resources.SMALL_FONT);
		g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		if(i == 0){
			g2d.setStroke(holeStroke);
			g2d.setColor(holeColor);
			g2d.fillRoundRect(4, 4, 24, 24, 8, 8);
			g2d.setColor(holeStrokeColor);
			g2d.drawRoundRect(4, 4, 24, 24, 8, 8);
			Rectangle2D bounds = g2d.getFontMetrics().getStringBounds("Hole", g2d);
			g2d.drawString("Hole",16-(int)bounds.getCenterX(),16-(int)bounds.getCenterY());
		} else {
			g2d.setStroke(outlineStroke);
			Color c = new Color(model.getColor(i));
			g2d.setColor(c);
			g2d.fillRoundRect(4, 4, 24, 24, 8, 8);
			g2d.setPaint(new GradientPaint(new Point(0,4),c.brighter(),new Point(0,32+4), c.darker()));
			g2d.drawRoundRect(4, 4, 24, 24, 8, 8);
		}
	}
	return icons;
}
 
Example 10
private static void centerString(String s, Graphics2D g, int x, int y, boolean box) {
	FontMetrics fm = g.getFontMetrics();
	int stringWidth = fm.stringWidth(s);
	int x2 = x - stringWidth / 2;
	if (box) {
		g.setColor(Color.gray);
		g.fillRoundRect(x2 - 5, y - fm.getAscent(), stringWidth + 10, fm.getHeight(), 8, 8);
	}
	g.setColor(Color.white);
	g.drawString(s, x2, y);
}
 
Example 11
Source Project: brModelo   File: PreTexto.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected void PaintGradiente(Graphics2D g, boolean round) {
    int dist = 0;
    int w = getWidth() - dist;
    int h = getHeight() - dist;
    int L = getLeft();
    int T = getTop();
    boolean dv = getGDirecao() == VERTICAL;

    //Composite originalComposite = g.getComposite();
    //g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER, alfa));
    GradientPaint GP = new GradientPaint(L, T, getGradienteStartColor(), dv ? L : L + w, dv ? T + h : T, getGradienteEndColor(), true);
    //g.setPaint(GP);

    g.setPaint(getForeColor());
    if (round) {
        g.drawRoundRect(L, T, w - 1, h - 1, roundRectSize, roundRectSize);
        g.setPaint(GP);
        g.fillRoundRect(L + 1, T + 1, w - 2, h - 2, roundRectSize, roundRectSize);
        g.setPaint(isDisablePainted()? disabledColor : Color.WHITE);
        g.drawRoundRect(L + 1, T + 1, w - 3, h - 3, roundRectSize, roundRectSize);
    } else {
        g.drawRect(L, T, w - 1, h - 1);
        g.setPaint(GP);
        g.fillRect(L + 1, T + 1, w - 2, h - 2);
        g.setPaint(isDisablePainted()? disabledColor : Color.WHITE);
        g.drawRect(L + 1, T + 1, w - 3, h - 3);
    }
    if (isGradientePinteDetalhe()) {
        g.setPaint(getGradienteCorDetalhe());
        GeneralPath path = new GeneralPath();
        path.moveTo(L + 2, T + 2);
        path.quadTo(L + w / 2 + 1, T + h / 2 + 1, L + w - 1, T + 2);
        path.closePath();
        g.fill(path);
    }
    //g.setComposite(originalComposite);

}
 
Example 12
private void drawButtonInfo(Graphics2D g) {
	String s = null;
	Rectangle r = null;
	if (closeButton.contains(mouseMovedPoint)) {
		s = "Close graph";
		r = closeButton;
	} else if (dataButton.contains(mouseMovedPoint)) {
		s = "View data";
		r = dataButton;
	} else if (xExpandButton.contains(mouseMovedPoint)) {
		s = "Expand x axis";
		r = xExpandButton;
	} else if (xShrinkButton.contains(mouseMovedPoint)) {
		s = "Shrink x axis";
		r = xShrinkButton;
	} else if (yExpandButton.contains(mouseMovedPoint)) {
		s = "Expand y axis";
		r = yExpandButton;
	} else if (yShrinkButton.contains(mouseMovedPoint)) {
		s = "Shrink y axis";
		r = yShrinkButton;
	} else if (yFitButton.contains(mouseMovedPoint)) {
		s = "Fit y axis to data";
		r = yFitButton;
	} else if (ySelectButton.contains(mouseMovedPoint)) {
		s = "Select data type";
		r = ySelectButton;
	}
	if (s == null)
		return;
	g.setFont(smallFont);
	int stringWidth = g.getFontMetrics().stringWidth(s);
	g.setStroke(thinStroke);
	g.setColor(Color.black);
	g.fillRoundRect(r.x + (r.width - stringWidth) / 2 - 5, r.y - 24, stringWidth + 10, 20, 8, 8);
	g.setColor(Color.white);
	g.drawString(s, r.x + (r.width - stringWidth) / 2, r.y - 12);
}
 
Example 13
@Override
public void paintComponent(Graphics g) {
	calculateWidth();

	int x = getWidth();
	int y = getHeight();

	Graphics2D g2d = (Graphics2D) g;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2d.setColor(OSVColors.GREY_2);
	int offX = x / 10;
	int offY = y / 10;
	int width = x * 8 / 10;
	int height = y * 8 / 10;
	g2d.fillRect(offX, offY, width, height);

	g2d.setColor(OSVColors.GREY_3);
	float yF = width / 6;
	g2d.setFont(font.deriveFont(yF));

	FontMetrics fm = getFontMetrics(g2d.getFont());
	int xF = fm.stringWidth(temperatureL.getText());
	int xFPos = offX + width / 3 - xF / 2;
	int yFPos = (int) (offY + height / 2 + yF / 2) - 2;
	g2d.drawString(temperatureL.getText(), xFPos, yFPos);

	// Draw temperature gauge
	float gWidth = width / 6f;
	float gHeight = height * 0.9f;
	float xC = xF + xFPos + offX;
	float yC = (height - gHeight) / 2f + offY;

	if (temperature > 40 && temperature < 60) {
		g2d.setColor(OSVColors.ORANGE);
	} else if (temperature >= 60) {
		g2d.setColor(OSVColors.RED_1);
	} else {
		g2d.setColor(OSVColors.BLUE_1);
	}

	if (temperature > 0) {
		float glHeight;
		if (temperature >= 60) {
			glHeight = gHeight;
		} else {
			glHeight = gHeight * temperature / 60f;
		}
		float ylC = yC + gHeight - glHeight;
		g2d.fillRoundRect((int) xC, (int) ylC, (int) gWidth, (int) glHeight, 15, 15);
	}

	g2d.setColor(OSVColors.WHITE);
	g2d.setStroke(new BasicStroke(3));
	g2d.drawRoundRect((int) xC, (int) yC, (int) gWidth, (int) gHeight, 15, 15);
	//

}
 
Example 14
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException{
	cfImageData im	= getImage( _session, argStruct );
	
	int x	= getNamedIntParam(argStruct, "x", -1 );
	int y	= getNamedIntParam(argStruct, "y", -1 );
	int w	= getNamedIntParam(argStruct, "width", -1 );
	int h	= getNamedIntParam(argStruct, "height", -1 );

	int aw	= getNamedIntParam(argStruct, "arcwidth", -1 );
	int ah	= getNamedIntParam(argStruct, "archeight", -1 );
	
	boolean bFilled	= getNamedBooleanParam(argStruct, "filled", false );
	
	//Check boundaries
	BufferedImage	bim	= im.getImage();
	
	if ( x < 0 || x > bim.getWidth() )
		throwException(_session, "x (" + x + ") is outside the image" );
	
	if ( y < 0 || y > bim.getHeight() )
		throwException(_session, "y (" + y + ") is outside the image" );

	if ( (x+w) < 0 || (x+w) > bim.getWidth() )
		throwException(_session, "w (" + w + ") is outside the image" );

	if ( (y+w) < 0 || (y+w) > bim.getHeight() )
		throwException(_session, "w (" + w + ") is outside the image" );

	if ( aw < 0 )
		throwException(_session, "arcwidth (" + aw + ") is non-zero" );
	
	if ( ah < 0 )
		throwException(_session, "archeight (" + ah + ") is non-zero" );


	// Perform the operation
	Graphics2D g2 = im.createGraphics();
	
	if ( bFilled ){
		g2.fillRoundRect( x, y, w, h, aw, ah );	
	}else{
		g2.drawRoundRect(x, y, w, h, aw, ah );	
	}
	
	im.dispose(g2);
	return cfBooleanData.TRUE;
}
 
Example 15
Source Project: oim-fx   File: JIMHistoryTextPane.java    License: MIT License 4 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
	Graphics2D g2D = (Graphics2D) g;
	g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // 反锯齿平滑绘制

	// 通过对并发消息链表遍历绘制全部消息气泡、消息发出者头像
	if (messageConcurrentLinkedQueue != null) {
		Iterator<Message> iterator = messageConcurrentLinkedQueue.iterator();
		while (iterator.hasNext()) {
			Message message = iterator.next();

			Point point = message.getMessagePaintLeftTop();

			if (point != null) {
				// 绘制消息发出者头像
				if (senderHeadImageConcurrentHashMap != null) {
					Image image = senderHeadImageConcurrentHashMap.get(message.getSenderHeadImageID());
					if (image != null) {
						if (message.isSelfSender()) {
							g2D.drawImage(image, this.getWidth() - image.getWidth(null) - 9, point.y - 25, null);
						} else {
							// 消息发出者是别人,则头像靠左显示
							g2D.drawImage(image, 9, point.y - 25, null);
						}
					}
				}

				// 绘制额消息气泡左边小箭头
				int xPoints[] = new int[3];
				int yPoints[] = new int[3];

				if (message.isSelfSender()) {
					// 绘制自己消息圆角消息气泡矩形
					g2D.setColor(selfMessageColor);
					g2D.fillRoundRect(point.x - 7, point.y - 7, message.getMessagePaintWidth() + 14, message.getMessagePaintHeight() + 14, 10, 10);
					// 绘制圆角消息气泡边框
					g2D.setColor(selfMessageBorderColor);
					g2D.drawRoundRect(point.x - 7, point.y - 7, message.getMessagePaintWidth() + 14, message.getMessagePaintHeight() + 14, 10, 10);

					// 消息发出者是自己,则头像靠右显示
					xPoints[0] = (point.x - 7) + (message.getMessagePaintWidth() + 14);
					yPoints[0] = point.y;
					xPoints[1] = xPoints[0] + 7;
					yPoints[1] = point.y;
					xPoints[2] = xPoints[0];
					yPoints[2] = point.y + 7;

					g2D.setColor(selfMessageColor);
					g2D.fillPolygon(xPoints, yPoints, 3);
					g2D.setColor(selfMessageBorderColor);
					g2D.drawPolyline(xPoints, yPoints, 3);
					g2D.setColor(selfMessageColor);
					g2D.drawLine(xPoints[0], yPoints[0] + 1, xPoints[2], yPoints[2] - 1);
				} else {
					// 绘制别人消息圆角消息气泡矩形
					// 绘制圆角消息气泡矩形
					g2D.setColor(otherMessageColor);
					g2D.fillRoundRect(point.x - 7, point.y - 7, message.getMessagePaintWidth() + 14, message.getMessagePaintHeight() + 14, 10, 10);
					// 绘制圆角消息气泡边框
					g2D.setColor(otherMessageBorderColor);
					g2D.drawRoundRect(point.x - 7, point.y - 7, message.getMessagePaintWidth() + 14, message.getMessagePaintHeight() + 14, 10, 10);

					// 消息发出者是别人,则头像靠左显示
					xPoints[0] = point.x - 7;
					yPoints[0] = point.y;
					xPoints[1] = xPoints[0] - 7;
					yPoints[1] = point.y;
					xPoints[2] = xPoints[0];
					yPoints[2] = point.y + 7;

					g2D.setColor(otherMessageColor);
					g2D.fillPolygon(xPoints, yPoints, 3);
					g2D.setColor(otherMessageBorderColor);
					g2D.drawPolyline(xPoints, yPoints, 3);
					g2D.setColor(otherMessageColor);
					g2D.drawLine(xPoints[0], yPoints[0] + 1, xPoints[2], yPoints[2] - 1);
				}
			}
		} // while
	}

	super.paintComponent(g); // 执行默认组件绘制(消息文本、图片以及段落显示等内容)
}
 
Example 16
Source Project: RipplePower   File: RoundedPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected void paintComponent(Graphics g) {

	super.paintComponent(g);

	int width = getWidth();
	int height = getHeight();

	Graphics2D g2 = (Graphics2D) g;

	GraphicsUtils.setExcellentRenderingHints(g2);

	g2.setColor(Color.black);
	g2.fillRoundRect(0, 0, width, height, cornerRadius, cornerRadius);

	Stroke original = g2.getStroke();
	g2.setColor(Color.black);
	g2.setStroke(new BasicStroke(0));
	g2.drawRoundRect(0, 0, width, height, cornerRadius, cornerRadius);
	g2.setStroke(original);

}
 
Example 17
@Override
public void paintTrack(Graphics g) {
	Graphics2D g2 = (Graphics2D) g;

	// make sure slider has same background as container
	if (slider.getParent() != null) {
		g2.setColor(slider.getParent().getBackground());
		g2.fillRect(0, 0, slider.getWidth(), slider.getHeight());
	}

	if (this.slider.getOrientation() == SwingConstants.HORIZONTAL) {
		int trackTop = (int) this.trackRect.getY() + 2;
		int w = this.slider.getWidth();
		int length = w - 6;

		// draw background bar
		if (this.slider.isEnabled()) {
			g2.setColor(Colors.SLIDER_TRACK_BACKGROUND);
		} else {
			g2.setColor(Colors.SLIDER_TRACK_BACKGROUND_DISABLED);
		}
		g2.fillRoundRect(3, trackTop + 1, length, 5, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
				RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);

		// draw fill bar
		g2.setColor(Colors.SLIDER_TRACK_FOREGROUND);
		g2.fill(new Rectangle2D.Double(4, trackTop + 2, this.thumbRect.x + 2, 3));

		// draw border
		g2.setColor(Colors.SLIDER_TRACK_BORDER);
		g2.drawRoundRect(2, trackTop, length, 6, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
				RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
	} else {
		int trackLeft = (int) this.trackRect.getX() + 2;
		int h = this.slider.getHeight();
		int height = h - 6;

		// draw background bar
		if (this.slider.isEnabled()) {
			g2.setColor(Colors.SLIDER_TRACK_BACKGROUND);
		} else {
			g2.setColor(Colors.SLIDER_TRACK_BACKGROUND_DISABLED);
		}
		g2.fillRoundRect(trackLeft + 1, 3, 5, height, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
				RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);

		// draw fill bar
		g2.setColor(Colors.SLIDER_TRACK_FOREGROUND);
		g2.fill(new Rectangle2D.Double(trackLeft + 2, this.thumbRect.y - 2, 3, h - this.thumbRect.y - 4));

		// draw border
		g2.setColor(Colors.SLIDER_TRACK_BORDER);
		g2.drawRoundRect(trackLeft, 2, 6, height, RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2,
				RapidLookAndFeel.CORNER_DEFAULT_RADIUS / 2);
	}
}
 
Example 18
Source Project: MyBox   File: ImageManufacture.java    License: Apache License 2.0 4 votes vote down vote up
public static BufferedImage drawHTML(BufferedImage backImage,
        BufferedImage html,
        DoubleRectangle bkRect, Color bkColor, float bkOpacity, int bkarc,
        int rotate, int margin) {
    try {
        if (html == null || backImage == null || bkRect == null) {
            return backImage;
        }
        int width = backImage.getWidth();
        int height = backImage.getHeight();
        int imageType = BufferedImage.TYPE_INT_ARGB;
        BufferedImage target = new BufferedImage(width, height, imageType);
        Graphics2D g = target.createGraphics();
        g.setBackground(CommonFxValues.TRANSPARENT);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

        g.drawImage(backImage, 0, 0, null);

        g.rotate(Math.toRadians(rotate),
                bkRect.getSmallX() + bkRect.getWidth() / 2,
                bkRect.getSmallY() + bkRect.getHeight() / 2);
        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, bkOpacity));
        g.setColor(bkColor);
        g.fillRoundRect((int) bkRect.getSmallX(), (int) bkRect.getSmallY(),
                (int) bkRect.getWidth(), (int) bkRect.getHeight(), bkarc, bkarc);

        g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f));
        g.setColor(CommonFxValues.TRANSPARENT);
        g.drawImage(html, (int) bkRect.getSmallX() + margin, (int) bkRect.getSmallY() + margin,
                (int) bkRect.getWidth() - 2 * margin, (int) bkRect.getHeight() - 2 * margin,
                null);

        g.dispose();

        return target;
    } catch (Exception e) {
        logger.error(e.toString());
        return backImage;
    }
}
 
Example 19
Source Project: PolyGlot   File: PComboBox.java    License: MIT License 4 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    final int buttonWidth = 20;
    boolean enabled = this.isEnabled();
    
    // turn on anti-alias mode
    Graphics2D antiAlias = (Graphics2D) g;
    antiAlias.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            
    if (enabled) {
        antiAlias.setColor(Color.white);
    } else {
        antiAlias.setColor(Color.decode("#e0e0e4"));
    }
    antiAlias.fillRoundRect(1, 1, getWidth(), getHeight() - 2, 5, 5);
    
    // draw text
    if (enabled) {
        antiAlias.setColor(Color.black);
    } else {
        antiAlias.setColor(Color.decode("#909090"));
    } 
    Object selectedItem = getSelectedItem();
    String text = selectedItem == null ? "" : selectedItem.toString();
    
    // display default text if appropriate
    if (text.isBlank() && this.getSelectedIndex() == 0) {
        text = defaultText;
        antiAlias.setColor(Color.decode("#909090"));
    }
    
    if (!text.isEmpty()) { // 0 length text makes bounding box explode
        FontMetrics fm = antiAlias.getFontMetrics(getFont());
        Rectangle2D rec = fm.getStringBounds(text, antiAlias);
        int stringW = (int) Math.round(rec.getWidth());
        int stringH = (int) Math.round(rec.getHeight());
        antiAlias.drawChars(text.toCharArray(), 0, text.length(), ((getWidth() - buttonWidth)/2) 
                - (stringW/2), (getHeight() - 9)/2 + stringH/2);
    }
    
    if (enabled) {
        antiAlias.setColor(PGTUtil.COLOR_ENABLED_BG);
    } else {
        antiAlias.setColor(Color.decode("#d0d0d0"));
    }
    antiAlias.fillRect(getWidth() - buttonWidth, 1, buttonWidth, getHeight() - 1);
    
    // draw outline
    if ((mouseOver || this.hasFocus()) && enabled) {
        antiAlias.setColor(Color.black);
    } else 
    {
        antiAlias.setColor(Color.lightGray);
    }
    antiAlias.drawRoundRect(1, 1, getWidth() - 2, getHeight() - 2, 5, 5);
}
 
Example 20
Source Project: whyline   File: FillRoundRectEvent.java    License: MIT License 2 votes vote down vote up
public void paint(Graphics2D g) {

	g.fillRoundRect(getX(), getY(), getWidth(), getHeight(), getCornerX(), getCornerY());

}