java.awt.Color Java Examples

The following examples show how to use java.awt.Color. 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
Source File: MultiFrequencyDistributionHistogram.java    From systemsgenetics with GNU General Public License v3.0 8 votes vote down vote up
private void determineColor(int i) {
    Color[] colors = {
        new Color(0, 0, 0, 128),
        new Color(128, 128, 128, 128),
        new Color(192, 192, 192, 64),
        new Color(0, 0, 255, 128),
        new Color(255, 255, 0, 128),
        new Color(0, 255, 255, 128),
        new Color(255, 0, 255, 128),};

    while (i > colors.length - 1) {
        i -= colors.length - 1;
    }

    setColor(colors[i]);

}
 
Example #2
Source File: VTDualListingHighlightProvider.java    From ghidra with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a darker shade of the color passed-in, based on the given amount.
 * 
 * algorithm: 1) grab individual rgb elements
 *            2) multiply each by a factor.
 *            
 *            ie: int newRed = (int)(oldRed * 0.85);
 * 
 * @param color the color to shade
 * @param amount number between 0..1 (the smaller the number, the darker the shade)
 * @return
 */
private static Color shade(Color color, double amount) {
	if (color != null) {
	
		int r = color.getRed();
		int g = color.getGreen();
		int b = color.getBlue();
		
		double newR = (r * amount);
		double newG = (g * amount);
		double newB = (b * amount);
		
		return new Color((int)newR, (int)newG, (int)newB);
	}
	
	return null;
}
 
Example #3
Source File: GeometryDrawer.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * The inherited drawing method. Applies the rotation, translation and scaling declared in the draw statement,
 * computes a number of properties attached to the geometry object, and calls the main drawing method
 */
@Override
protected final void _draw(final GeometryObject object) {
	gl.pushMatrix();
	try {

		applyRotation(object);
		applyTranslation(object);
		applyScaling(object);
		final boolean solid = object.isFilled() || gl.isTextured();
		final Color border = !solid && object.getAttributes().getBorder() == null
				? object.getAttributes().getColor() : object.getAttributes().getBorder();
		final Geometry geometry = object.getObject();
		final double height = object.getAttributes().getHeight() == null ? 0d : object.getAttributes().getHeight();
		final IShape.Type type = object.getAttributes().getType();
		drawGeometry(geometry, solid, border, height, type);
	} finally {
		gl.popMatrix();
	}
}
 
Example #4
Source File: ColorPane.java    From patchwork-patcher with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void append(Color color, String string) {
	if (color != null) {
		StyleConstants.setForeground(oneStyleToRuleThemAll, color);
	}

	try {
		this.getDocument().insertString(this.getDocument().getLength(), string, oneStyleToRuleThemAll);
	} catch (BadLocationException e) {
		PatchworkUI.LOGGER.throwing(Level.ERROR, e);
	}
}
 
Example #5
Source File: Test6849805.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    Minimbus laf = new Minimbus();
    laf.test(Color.WHITE, Color.BLACK, 0f);
    laf.test(Color.WHITE, Color.BLACK, 1f);
    laf.test(Color.BLACK, Color.WHITE, 0f);
    laf.test(Color.BLACK, Color.WHITE, 1f);
    laf.test(Color.RED, Color.GREEN, 0f);
    laf.test(Color.RED, Color.GREEN, 1f);
    laf.test(new Color(127, 127, 127), new Color(51, 151, 212), 0f);
    laf.test(new Color(127, 127, 127), new Color(51, 151, 212), 1f);
    laf.test(new Color(221, 63, 189), new Color(112, 200, 89), 0f);
    laf.test(new Color(221, 63, 189), new Color(112, 200, 89), 1f);

    if (! pass) {
        throw new RuntimeException("Some testcases failed, see above");
    }
}
 
Example #6
Source File: DisplayChangeVITest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
void render(Graphics g) {
    do {
        // volatile images validated here
        initBackbuffer();

        g.setColor(Color.black);
        g.fillRect(0, 0, getWidth(), getHeight());

        Graphics gg = bb.getGraphics();
        gg.setColor(new Color(rnd.nextInt(0x00ffffff)));
        gg.fillRect(0, 0, bb.getWidth(), bb.getHeight());
        for (int x = 0; x < 10; x++) {
            gg.drawImage(sprite, x*200, 0, null);
            gg.drawImage(volSprite, x*200, 500, null);
        }

        g.drawImage(bb, 0, 0, null);
    } while (bb.contentsLost());
}
 
Example #7
Source File: MotifIconFactory.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public void drawCheckBezelOut(Graphics g, int x, int y, int csize){
    Color controlShadow = UIManager.getColor("controlShadow");

    int w = csize;
    int h = csize;
    Color oldColor = g.getColor();

    g.translate(x,y);
    g.setColor(highlight);    // inner 3D border
    g.drawLine(0, 0, 0, h-1);
    g.drawLine(1, 0, w-1, 0);

    g.setColor(shadow);         // black drop shadow  __|
    g.drawLine(1, h-1, w-1, h-1);
    g.drawLine(w-1, h-1, w-1, 1);
    g.translate(-x,-y);
    g.setColor(oldColor);
}
 
Example #8
Source File: ThemePackagePresets.java    From JCommunique with MIT License 6 votes vote down vote up
public static ThemePackage cleanDark() {
	ThemePackage pack = new ThemePackage();

	WindowTheme window = new WindowTheme();
	window.background = new Color(0, 0, 0);
	window.foreground = new Color(16, 124, 162);
	window.opacity = 0.8f;
	window.width = 300;
	window.height = 100;

	TextTheme text = new TextTheme();
	text.title = new Font("Arial", Font.BOLD, 22);
	text.subtitle = new Font("Arial", Font.PLAIN, 16);
	text.titleColor = new Color(200, 200, 200);
	text.subtitleColor = new Color(200, 200, 200);

	pack.setTheme(WindowTheme.class, window);
	pack.setTheme(TextTheme.class, text);

	return pack;
}
 
Example #9
Source File: NimbusStyle.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Overridden to cause this style to populate itself with data from
 * UIDefaults, if necessary.</p>
 *
 * <p>In addition, NimbusStyle handles ColorTypes slightly differently from
 * Synth.</p>
 * <ul>
 *  <li>ColorType.BACKGROUND will equate to the color stored in UIDefaults
 *      named "background".</li>
 *  <li>ColorType.TEXT_BACKGROUND will equate to the color stored in
 *      UIDefaults named "textBackground".</li>
 *  <li>ColorType.FOREGROUND will equate to the color stored in UIDefaults
 *      named "textForeground".</li>
 *  <li>ColorType.TEXT_FOREGROUND will equate to the color stored in
 *      UIDefaults named "textForeground".</li>
 * </ul>
 */
@Override protected Color getColorForState(SynthContext ctx, ColorType type) {
    String key = null;
    if (type == ColorType.BACKGROUND) {
        key = "background";
    } else if (type == ColorType.FOREGROUND) {
        //map FOREGROUND as TEXT_FOREGROUND
        key = "textForeground";
    } else if (type == ColorType.TEXT_BACKGROUND) {
        key = "textBackground";
    } else if (type == ColorType.TEXT_FOREGROUND) {
        key = "textForeground";
    } else if (type == ColorType.FOCUS) {
        key = "focus";
    } else if (type != null) {
        key = type.toString();
    } else {
        return DEFAULT_COLOR;
    }
    Color c = (Color) get(ctx, key);
    //if all else fails, return a default color (which is a ColorUIResource)
    if (c == null) c = DEFAULT_COLOR;
    return c;
}
 
Example #10
Source File: Shop.java    From JAVA-MVC-Swing-Monopoly with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * ������ʾ��ϸ����UI
 * 
 */
private void drawDetailUI(Graphics g) {
	g.drawImage(detialBg, position.x + atWhere.x, position.y + atWhere.y,
			position.x + atWhere.x + detialBg.getWidth(null), position.y
					+ atWhere.y + detialBg.getHeight(null), 0, 0,
			detialBg.getWidth(null), detialBg.getHeight(null), null);
	// ��ǰ��Ƭ
	Card tempCard = this.shop.getCards().get(chooseCard);
	Image tempIMG = this.createCardImg(tempCard.getName())[4];
	g.drawImage(tempIMG, position.x + atWhere.x, position.y + atWhere.y
			- 30, position.x + atWhere.x + (int) (tempIMG.getWidth(null)),
			position.y + atWhere.y - 30 + (int) (tempIMG.getHeight(null)),
			0, 0, tempIMG.getWidth(null), tempIMG.getHeight(null), null);
	// ��Ƭ����
	Image tempIMG2 = this.createCardImg(tempCard.getName())[5];
	g.drawImage(tempIMG2, position.x + atWhere.x + 115, position.y
			+ atWhere.y,
			position.x + atWhere.x + (int) (tempIMG2.getWidth(null)) + 115,
			position.y + atWhere.y + (int) (tempIMG2.getHeight(null)), 0,
			0, tempIMG2.getWidth(null), tempIMG2.getHeight(null), null);
	// ��ǰ��Ƭ�۸�
	g.setColor(Color.WHITE);
	g.setFont(new Font(null, 0, 14));
	String str = tempCard.getPrice() + "���";
	FontMetrics fm = g.getFontMetrics();
	g.drawString(str, position.x + atWhere.x + 80 - fm.stringWidth(str),
			position.y + atWhere.y + 110);

}
 
Example #11
Source File: MinMaxCategoryRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Provides serialization support.
 *
 * @param stream  the input stream.
 *
 * @throws IOException  if there is an I/O error.
 * @throws ClassNotFoundException  if there is a classpath problem.
 */
private void readObject(ObjectInputStream stream)
    throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    this.groupStroke = SerialUtilities.readStroke(stream);
    this.groupPaint = SerialUtilities.readPaint(stream);

    this.minIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0, 360,
            Arc2D.OPEN), null, Color.black);
    this.maxIcon = getIcon(new Arc2D.Double(-4, -4, 8, 8, 0, 360,
            Arc2D.OPEN), null, Color.black);
    this.objectIcon = getIcon(new Line2D.Double(-4, 0, 4, 0), false, true);
}
 
Example #12
Source File: OldGoldenSpiral.java    From IngressAnimations with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void draw(Graphics gr, ScaleAnimation scale, double t) {
	gr.setColor(Color.white);
	gr.fillRect(0, 0, scale.getWidth(), scale.getHeight());
	int maxFullSquare = (int) Math.floor(t);
	drawSquare(gr, (maxFullSquare+1), scale.getScale(t), t - Math.floor(t)); 
	for (int square=maxFullSquare; square >= startSquare; square--) {
		drawSquare(gr, square, scale.getScale(t), 1); 
	}
}
 
Example #13
Source File: OpCompatibleImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private BufferedImage createTestImage(int type) {
    BufferedImage img = new BufferedImage(100, 100, type);
    Graphics g = img.createGraphics();
    g.setColor(Color.red);
    g.fillRect(0, 0, 100, 100);
    g.dispose();

    return img;
}
 
Example #14
Source File: ImageRepresentation.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public boolean drawToBufImage(Graphics g, ToolkitImage img,
                              int x, int y, int w, int h,
                              Color bg, ImageObserver iw) {

    if (src != null) {
        src.checkSecurity(null, false);
    }
    if ((availinfo & ImageObserver.ERROR) != 0) {
        if (iw != null) {
            iw.imageUpdate(image, ImageObserver.ERROR|ImageObserver.ABORT,
                           -1, -1, -1, -1);
        }
        return false;
    }

    boolean done  = ((availinfo & ImageObserver.ALLBITS) != 0);
    boolean abort = ((availinfo & ImageObserver.ABORT) != 0);

    if (!done && !abort) {
        addWatcher(iw);
        startProduction();
        // Some producers deliver image data synchronously
        done = ((availinfo & ImageObserver.ALLBITS) != 0);
    }

    if (done || (0 != (availinfo & ImageObserver.FRAMEBITS))) {
        g.drawImage (bimage, x, y, w, h, bg, null);
    }

    return done;
}
 
Example #15
Source File: PaletteBuilder.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected int getBranchIndex(Color aColor, int aLevel) {
    if (aLevel > MAXLEVEL || aLevel < 0) {
        throw new IllegalArgumentException("Invalid octree node depth: " +
                                           aLevel);
    }

    int shift = MAXLEVEL - aLevel;
    int red_index = 0x1 & ((0xff & aColor.getRed()) >> shift);
    int green_index = 0x1 & ((0xff & aColor.getGreen()) >> shift);
    int blue_index = 0x1 & ((0xff & aColor.getBlue()) >> shift);
    int index = (red_index << 2) | (green_index << 1) | blue_index;
    return index;
}
 
Example #16
Source File: PetriNetControllerTest.java    From PIPE with MIT License 5 votes vote down vote up
@Test
public void doesNotUpdateNameIfNotChanged() throws PetriNetComponentNotFoundException {
    Token token = mock(Token.class);
    String id = "id";
    when(token.getId()).thenReturn(id);

    boolean enabled = true;

    Color color = new Color(255, 0, 0);
    when(token.getColor()).thenReturn(color);
    net.addToken(token);

    controller.updateToken(id, id, color);
    verify(token, never()).setId(anyString());
}
 
Example #17
Source File: PageCleaner.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Process glyph-based inter.
 * Strategy is to paint the glyph (its runTable actually) in white.
 *
 * @param glyph the inter underlying glyph
 */
protected void processGlyph (Glyph glyph)
{
    // Use pixels of underlying glyph
    Color oldColor = g.getColor();
    g.setColor(Color.WHITE);
    glyph.getRunTable().render(g, glyph.getTopLeft());
    g.setColor(oldColor);
}
 
Example #18
Source File: GlowPathEffect.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance of GlowPathEffect
 */
public GlowPathEffect(float opacity) {
    super();
    setBrushColor(Color.WHITE);
    setBrushSteps(10);
    setEffectWidth(10);
    setShouldFillShape(false);
    setOffset(new Point(0, 0));

    setOpacity(opacity); // opacity support added by lbalazscs
}
 
Example #19
Source File: BlockBorderTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    BlockBorder b1 = new BlockBorder(new RectangleInsets(1.0, 2.0, 3.0,
            4.0), new GradientPaint(1.0f, 2.0f, Color.red, 3.0f, 4.0f,
            Color.yellow));
    BlockBorder b2 = (BlockBorder) TestUtilities.serialised(b1);
    assertEquals(b1, b2);
}
 
Example #20
Source File: SheetCell.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void paint(Graphics g) {
    //do this for self-painting editors in Options window - because
    //we've turned off most property changes, the background won't be
    //painted correctly otherwise
    Color c = getBackground();
    Color old = g.getColor();
    g.setColor(c);
    g.fillRect(0,0,getWidth(),getHeight());
    g.setColor(old);
    
    super.paint(g);

    if (focused) {
        Color bdr = UIManager.getColor("Tree.selectionBorderColor"); //NOI18N
        if (bdr == null) {
            //Button focus color doesn't work on win classic - better to
            //get the color from a value we know will work - Tim
            if (getForeground().equals(Color.BLACK)) { //typical
                bdr = getBackground().darker();
            } else {
                bdr = getForeground().darker();
            }
        }
        g.setColor(bdr);
        g.drawRect(1, 1, getWidth() - 3, getHeight() - 3);
    }
    g.setColor(old);
}
 
Example #21
Source File: PostScriptRendererTest.java    From OkapiBarcode with Apache License 2.0 5 votes vote down vote up
@Test
public void testCode93Margin() throws IOException {
    Code93 code93 = new Code93();
    code93.setQuietZoneHorizontal(20);
    code93.setQuietZoneVertical(20);
    code93.setContent("123456789");
    test(code93, 1, Color.WHITE, Color.BLACK, "code93-margin-size-20.eps");
}
 
Example #22
Source File: HerbiboarConfig.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@ConfigItem(
	position = 0,
	keyName = "colorStart",
	name = "Start Color",
	description = "Color for rocks that start the trails",
	titleSection = "colorsTitle"
)
default Color getStartColor()
{
	return Color.CYAN;
}
 
Example #23
Source File: BarRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests each setter method to ensure that it sends an event notification.
 */
@Test
public void testEventNotification() {

    RendererChangeDetector detector = new RendererChangeDetector();
    BarRenderer r1 = new BarRenderer();
    r1.addChangeListener(detector);

    detector.setNotified(false);
    r1.setBasePaint(Color.red);
    assertTrue(detector.getNotified());

}
 
Example #24
Source File: Test4193384.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    test(new Color[] {
            new Color(11, 12, 13),
            new Color(204, 0, 204),
            new Color(0, 51, 51)
    });
}
 
Example #25
Source File: ColorMapper.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Converts a double to a color.
 * @param value
 * @return the color
 */
public Color doubleToColor(double value) { // Changed by Paco to use doubleToIndex
  int index = doubleToIndex(value);
  if(index<0) return floorColor;
  if(index>=colors.length) return ceilColor;
  return colors[index];
}
 
Example #26
Source File: ColorPalette.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
     * Returns Color by mapping a given value to a common log palette.
     *
     * @param value  the value.
     *
     * @return The color.
     */
    public Color getColorLog(double value) {
        int izV;
        double minZtmp = this.minZ;
        double maxZtmp = this.maxZ;
        if (this.minZ <= 0.0) {
//          negatives = true;
            this.maxZ = maxZtmp - minZtmp + 1;
            this.minZ = 1;
            value = value - minZtmp + 1;
        }
        double minZlog = Math.log(this.minZ) / log10;
        double maxZlog = Math.log(this.maxZ) / log10;
        value = Math.log(value) / log10;
        //  value = Math.pow(10,value);
        if (this.stepped) {
            int numSteps = this.tickValues.length;
            int steps = 256 / (numSteps - 1);
            izV = steps * (int) (numSteps * (value - minZlog)
                    / (maxZlog - minZlog)) + 2;
            //  izV = steps*numSteps*(int)((value/minZ)/(maxZlog-minZlog)) + 2;
        }
        else {
            izV = (int) (253 * (value - minZlog) / (maxZlog - minZlog)) + 2;
        }
        izV = Math.min(izV, 255);
        izV = Math.max(izV, 2);

        this.minZ = minZtmp;
        this.maxZ = maxZtmp;

        return getColor(izV);
    }
 
Example #27
Source File: MyCursor.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override public void paint(Graphics gr) {
    gr.setColor(Color.GREEN);
    ((Graphics2D)gr).setStroke(new BasicStroke(3));

    gr.drawLine(0, 0, width, height);
    gr.drawLine(0, 0, width/2, 0);
    gr.drawLine(0, 0, 0, height/2);
}
 
Example #28
Source File: ColorChooserPanel.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void updateChooser() {
    Color color = getColorFromModel();
    if (color != null) {
        this.panel.setColor(color);
        this.text.setValue(Integer.valueOf(color.getRGB()));
        this.slider.repaint();
        this.diagram.repaint();
    }
}
 
Example #29
Source File: HexMap.java    From Rails with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void paintImage(Graphics2D g) {
    try {
        // Abort if called too early.
        Rectangle rectClip = g.getClipBounds();
        if (rectClip == null) {
            return;
        }

        // paint train paths
        if (hexMap.getTrainPaths() != null) {
            Stroke oldStroke = g.getStroke();
            Color oldColor = g.getColor();
            Stroke trainStroke =
                    new BasicStroke((int) (STROKE_WIDTH * hexMap.getZoomFactor()),
                            STROKE_CAP, STROKE_JOIN);
            g.setStroke(trainStroke);

            Color[] trainColors =
                    new Color[] { colour1, colour2, colour3, colour4 };
            int color = 0;
            for (GeneralPath path:hexMap.getTrainPaths()) {
                g.setColor(trainColors[color++ % trainColors.length]);
                g.draw(path);
            }
            g.setStroke(oldStroke);
            g.setColor(oldColor);
        }
    } catch (NullPointerException ex) {
        // If we try to paint before something is loaded, just retry
        // later.
        log.debug("Premature call to RoutesLayer.paintImage(Graphics g)");
    }
}
 
Example #30
Source File: SurfaceDataProxy.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean isSupportedOperation(SurfaceData srcData,
                                    int txtype,
                                    CompositeType comp,
                                    Color bgColor)
{
    return false;
}