use of java.awt.GradientPaint in project openblocks by mikaelhg.
the class LowerRightCorner method paint.
/**
* paints scrollbar
*/
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.addRenderingHints(renderingHints);
g2.setColor(Color.gray);
g2.drawRoundRect(0, 0, this.getWidth() - 1, this.getHeight() - 1, this.getHeight(), this.getHeight());
double viewValue = modelToView(modelrange.getValue());
double viewExtent = modelToView(modelrange.getExtent());
if (viewValue < this.getWidth() - 0.5f * this.getHeight()) {
g2.translate(viewValue, 0);
} else {
g2.translate(this.getWidth() - 0.5f * this.getHeight(), 0);
}
g2.setColor(Color.lightGray);
g2.setPaint(new GradientPaint(0, 0, thumbColor, 0, this.getHeight() + 10, Color.black, true));
g2.fill(reformThumbShape(this.getWidth(), this.getHeight(), (int) viewExtent));
}
use of java.awt.GradientPaint in project EnrichmentMapApp by BaderLab.
the class ColorGradientWidget method renderGradient.
private void renderGradient(Graphics2D g2d) {
// create the gradient from min to center
final GradientPaint gradientLow = new GradientPaint((float) minimumConditionGradientRectangle.getX(), (float) minimumConditionGradientRectangle.getY(), colorGradientTheme.getMinColor(), (float) maximumConditionGradientRectangle.getX(), (float) minimumConditionGradientRectangle.getY(), colorGradientTheme.getCenterColor());
g2d.setPaint(gradientLow);
g2d.fillRect((int) minimumConditionGradientRectangle.getX(), (int) minimumConditionGradientRectangle.getY(), (int) minimumConditionGradientRectangle.getWidth(), (int) minimumConditionGradientRectangle.getHeight());
// create the gradient from center to max
final GradientPaint gradientHigh = new GradientPaint((float) maximumConditionGradientRectangle.getX(), (float) maximumConditionGradientRectangle.getY(), colorGradientTheme.getCenterColor(), (float) (maximumConditionGradientRectangle.getX() + maximumConditionGradientRectangle.getWidth()), (float) maximumConditionGradientRectangle.getY(), colorGradientTheme.getMaxColor());
g2d.setPaint(gradientHigh);
g2d.fillRect((int) maximumConditionGradientRectangle.getX(), (int) maximumConditionGradientRectangle.getY(), (int) maximumConditionGradientRectangle.getWidth(), (int) maximumConditionGradientRectangle.getHeight());
// draw outline around gradient
final Rectangle rect = new Rectangle(0, 0, gradientWidth - 1, gradientHeight - 1);
g2d.setPaint(borderColor);
g2d.draw(rect);
}
use of java.awt.GradientPaint in project EnrichmentMapApp by BaderLab.
the class ColorGradientWidget method renderLegendGradient.
private void renderLegendGradient(Graphics2D g2d) {
// minimum gradient
final GradientPaint gradientLow = new GradientPaint((float) minimumConditionGradientRectangle.getX(), (float) minimumConditionGradientRectangle.getY(), colorGradientTheme.getMinColor(), (float) centerConditionGradientRectangle.getX(), (float) centerConditionGradientRectangle.getY(), colorGradientTheme.getCenterColor());
g2d.setPaint(gradientLow);
g2d.fillRect((int) minimumConditionGradientRectangle.getX(), (int) minimumConditionGradientRectangle.getY(), (int) minimumConditionGradientRectangle.getWidth(), (int) minimumConditionGradientRectangle.getHeight());
// center gradient
g2d.setPaint(colorGradientTheme.getCenterColor());
g2d.fillRect((int) centerConditionGradientRectangle.getX(), (int) centerConditionGradientRectangle.getY(), (int) centerConditionGradientRectangle.getWidth(), (int) centerConditionGradientRectangle.getHeight());
// max gradient
final GradientPaint gradientHigh = new GradientPaint((float) centerConditionGradientRectangle.getX(), (float) centerConditionGradientRectangle.getY(), colorGradientTheme.getCenterColor(), (float) (maximumConditionGradientRectangle.getX() + maximumConditionGradientRectangle.getWidth()), (float) maximumConditionGradientRectangle.getY(), colorGradientTheme.getMaxColor());
g2d.setPaint(gradientHigh);
g2d.fillRect((int) maximumConditionGradientRectangle.getX(), (int) maximumConditionGradientRectangle.getY(), (int) maximumConditionGradientRectangle.getWidth(), (int) maximumConditionGradientRectangle.getHeight());
// draw outline around gradient - use any rectangle for starting y
final Rectangle rect = new Rectangle(positionLegendWidth, (int) minimumConditionGradientRectangle.getY(), gradientWidth - 1, gradientHeight - 1);
g2d.setPaint(borderColor);
g2d.draw(rect);
}
use of java.awt.GradientPaint in project adempiere by adempiere.
the class CompiereTabbedPaneUI method paintTabBackground.
// paint
/**************************************************************************
* Paint the actual Tab Background.
* Called from Basic.PaintTab (<- Basic.paintTabArea <- Basic.paint)
* <p>
* Based on MetalTabbedPaneUI.paintTabBackground:
* Differences:
* - Color based on primary Background of Tab
* - Selected Tab is painted
* <pre>
* selected not sel
* top ////////// ////////// (lighter)
* ++++++++++ (flat/darker)
*
* bottom ////////// (flat/lighter)
* ++++++++++ ++++++++++ (darker)
*
* sides ////////// (flat/ligher)
* ++++++++++ (flat/darker)
* </pre>
* @param g graphics
* @param tabPlacement tab placement
* @param tabIndex tab index
* @param x x
* @param y y
* @param w width
* @param h height
* @param isSelected selected
*/
protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
Graphics2D g2D = (Graphics2D) g;
// Get Background color of Tab
Component comp = tabPane.getComponentAt(tabIndex);
// System.out.println("Tab " + tabIndex + " Comp=" + comp.getName() + " " + comp.getClass().getName() + " x=" + x + ", y=" + y + ", w=" +w + ", h=" + h);
g2D.setPaint(comp.getBackground());
CompiereColor bg = CompiereColor.getDefaultBackground();
if (comp instanceof JPanel) {
JPanel jp = (JPanel) comp;
try {
bg = (CompiereColor) jp.getClientProperty(CompiereLookAndFeel.BACKGROUND);
} catch (Exception e) {
System.err.println("AdempiereTabbedPaneUI - ClientProperty: " + e.getMessage());
}
}
if (// No Background
bg == null) {
if (CompiereUtils.isLeftToRight(tabPane)) {
switch(tabPlacement) {
case LEFT:
g2D.fillRect(x + 5, y + 1, w - 5, h - 1);
g2D.fillRect(x + 2, y + 4, 3, h - 4);
break;
case BOTTOM:
g2D.fillRect(x + 2, y, w - 2, h - 4);
g2D.fillRect(x + 5, y + (h - 1) - 3, w - 5, 3);
break;
case RIGHT:
g2D.fillRect(x + 1, y + 1, w - 5, h - 1);
g2D.fillRect(x + (w - 1) - 3, y + 5, 3, h - 5);
break;
case TOP:
default:
g2D.fillRect(x + 4, y + 2, (w - 1) - 3, (h - 1) - 1);
g2D.fillRect(x + 2, y + 5, 2, h - 5);
}
} else {
switch(tabPlacement) {
case LEFT:
g2D.fillRect(x + 5, y + 1, w - 5, h - 1);
g2D.fillRect(x + 2, y + 4, 3, h - 4);
break;
case BOTTOM:
g2D.fillRect(x, y, w - 5, h - 1);
g2D.fillRect(x + (w - 1) - 4, y, 4, h - 5);
g2D.fillRect(x + (w - 1) - 4, y + (h - 1) - 4, 2, 2);
break;
case RIGHT:
g2D.fillRect(x + 1, y + 1, w - 5, h - 1);
g2D.fillRect(x + (w - 1) - 3, y + 5, 3, h - 5);
break;
case TOP:
default:
g2D.fillRect(x, y + 2, (w - 1) - 3, (h - 1) - 1);
g2D.fillRect(x + (w - 1) - 3, y + 4, 3, h - 4);
}
}
} else // we have a background
{
if (CompiereUtils.isLeftToRight(tabPane)) {
switch(tabPlacement) {
case LEFT:
bg.paintRect(g2D, tabPane, x + 5, y + 1, w - 5, h - 1);
bg.paintRect(g2D, tabPane, x + 2, y + 4, 3, h - 4);
break;
case BOTTOM:
bg.paintRect(g2D, tabPane, x + 2, y, w - 2, h - 4);
bg.paintRect(g2D, tabPane, x + 5, y + (h - 1) - 3, w - 5, 3);
break;
case RIGHT:
// bg.paintRect (g2D, tabPane, x + 1, y + 1, w - 5, h - 1);
// changed
bg.paintRect(g2D, tabPane, x, y + 2, w - 4, h - 2);
bg.paintRect(g2D, tabPane, x + (w - 1) - 3, y + 5, 3, h - 5);
break;
case TOP:
default:
bg.paintRect(g2D, tabPane, x + 4, y + 2, (w - 1) - 3, (h - 1) - 1);
bg.paintRect(g2D, tabPane, x + 2, y + 5, 2, h - 5);
}
} else {
switch(tabPlacement) {
case LEFT:
bg.paintRect(g2D, tabPane, x + 5, y + 1, w - 5, h - 1);
bg.paintRect(g2D, tabPane, x + 2, y + 4, 3, h - 4);
break;
case BOTTOM:
bg.paintRect(g2D, tabPane, x, y, w - 5, h - 1);
bg.paintRect(g2D, tabPane, x + (w - 1) - 4, y, 4, h - 5);
bg.paintRect(g2D, tabPane, x + (w - 1) - 4, y + (h - 1) - 4, 2, 2);
break;
case RIGHT:
bg.paintRect(g2D, tabPane, x + 1, y + 1, w - 5, h - 1);
bg.paintRect(g2D, tabPane, x + (w - 1) - 3, y + 5, 3, h - 5);
break;
case TOP:
default:
bg.paintRect(g2D, tabPane, x, y + 2, (w - 1) - 3, (h - 1) - 1);
bg.paintRect(g2D, tabPane, x + (w - 1) - 3, y + 4, 3, h - 4);
}
}
}
// Upper Part - not when selected and R/L/B
if (!(isSelected && (tabPlacement == RIGHT || tabPlacement == LEFT || tabPlacement == BOTTOM))) {
// upper half
Shape top = new Rectangle(x, y, w, h / 2);
if (tabPlacement == TOP || tabPlacement == LEFT)
top = new // top left triangle
Polygon(new int[] { x + 6, x + w, x + w, x, x }, new int[] { y, y, y + (h / 2), y + (h / 2), y + 6 }, 5);
else if (tabPlacement == RIGHT)
top = new // top right triangle
Polygon(new int[] { x, x + w - 6, x + w, x + w, x }, new int[] { y, y, y + 6, y + (h / 2), y + (h / 2) }, 5);
// lighter
GradientPaint paint = new GradientPaint(x, y, CompiereUtils.COL_1TOP, x, y + (h / 2), CompiereUtils.COL_1END);
g2D.setPaint(paint);
g2D.fill(top);
}
// Lower part - not when selected and T/R/L
if (!(isSelected && (tabPlacement == TOP || tabPlacement == RIGHT || tabPlacement == LEFT))) {
// lower half
Shape end = new Rectangle(x, y + (h / 2), w, h / 2);
if (tabPlacement == BOTTOM)
end = new // bottom left triangle
Polygon(new int[] { x, x + w, x + w, x + 6, x }, new int[] { y + (h / 2), y + (h / 2), y + h, y + h, y + h - 6 }, 5);
// darker
GradientPaint paint = new GradientPaint(x, y + (h / 2), CompiereUtils.COL_2TOP, x, y + h, CompiereUtils.COL_2END);
g2D.setPaint(paint);
g2D.fill(end);
}
}
use of java.awt.GradientPaint in project jdk8u_jdk by JetBrains.
the class RenderTests method initContext.
public void initContext(TestEnvironment env, GraphicsTests.Context ctx) {
super.initContext(env, ctx);
RenderTests.Context rctx = (RenderTests.Context) ctx;
boolean alphacolor;
if (hasGraphics2D) {
Graphics2D g2d = (Graphics2D) rctx.graphics;
if (env.isEnabled(doAntialias)) {
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
alphacolor = env.isEnabled(doAlphaColors);
g2d.setStroke((Stroke) env.getModifier(strokeList));
} else {
alphacolor = false;
}
String paint = (String) env.getModifier(paintList);
if (paint.equals("single")) {
Color c = Color.darkGray;
if (alphacolor) {
c = makeAlphaColor(c, 32);
}
rctx.graphics.setColor(c);
} else if (paint.equals("random")) {
rctx.colorlist = alphacolor ? randAlphaColors : randOpaqueColors;
} else if (paint.equals("gradient2")) {
Color[] colors = makeGradientColors(2, alphacolor);
Graphics2D g2d = (Graphics2D) rctx.graphics;
g2d.setPaint(new GradientPaint(0.0f, 0.0f, colors[0], 10.0f, 10.0f, colors[1], true));
} else if (paint.equals("linear2")) {
Graphics2D g2d = (Graphics2D) rctx.graphics;
g2d.setPaint(makeLinear(2, alphacolor));
} else if (paint.equals("linear3")) {
Graphics2D g2d = (Graphics2D) rctx.graphics;
g2d.setPaint(makeLinear(3, alphacolor));
} else if (paint.equals("radial2")) {
Graphics2D g2d = (Graphics2D) rctx.graphics;
g2d.setPaint(makeRadial(2, alphacolor));
} else if (paint.equals("radial3")) {
Graphics2D g2d = (Graphics2D) rctx.graphics;
g2d.setPaint(makeRadial(3, alphacolor));
} else if (paint.equals("texture20")) {
Graphics2D g2d = (Graphics2D) rctx.graphics;
g2d.setPaint(makeTexturePaint(20, alphacolor));
} else if (paint.equals("texture32")) {
Graphics2D g2d = (Graphics2D) rctx.graphics;
g2d.setPaint(makeTexturePaint(32, alphacolor));
} else {
throw new InternalError("Invalid paint mode");
}
}
Aggregations