java.awt.Color源码实例Demo

类java.awt.Color源码实例Demo

下面列出了java.awt.Color 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: ghidra   文件: VTDualListingHighlightProvider.java
/**
 * 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;
}
 
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]);

}
 
源代码3 项目: gama   文件: GeometryDrawer.java
/**
 * 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();
	}
}
 
源代码4 项目: jdk8u-jdk   文件: Test6849805.java
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");
    }
}
 
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());
}
 
源代码6 项目: JDKSourceCode1.8   文件: MotifIconFactory.java
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);
}
 
源代码7 项目: JCommunique   文件: ThemePackagePresets.java
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;
}
 
源代码8 项目: Bytecoder   文件: NimbusStyle.java
/**
 * {@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;
}
 
源代码9 项目: JAVA-MVC-Swing-Monopoly   文件: Shop.java
/**
 * 
 * ������ʾ��ϸ����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);

}
 
源代码10 项目: astor   文件: MinMaxCategoryRenderer.java
/**
 * 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);
}
 
源代码11 项目: IngressAnimations   文件: OldGoldenSpiral.java
@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); 
	}
}
 
源代码12 项目: jdk8u_jdk   文件: OpCompatibleImageTest.java
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;
}
 
源代码13 项目: openjdk-jdk8u   文件: ImageRepresentation.java
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;
}
 
源代码14 项目: jdk8u-dev-jdk   文件: PaletteBuilder.java
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;
}
 
源代码15 项目: PIPE   文件: PetriNetControllerTest.java
@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());
}
 
源代码16 项目: audiveris   文件: PageCleaner.java
/**
 * 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);
}
 
源代码17 项目: Pixelitor   文件: GlowPathEffect.java
/**
 * 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
}
 
源代码18 项目: patchwork-patcher   文件: ColorPane.java
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);
	}
}
 
源代码19 项目: ECG-Viewer   文件: BlockBorderTest.java
/**
 * 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);
}
 
源代码20 项目: netbeans   文件: SheetCell.java
@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);
}
 
源代码21 项目: OkapiBarcode   文件: PostScriptRendererTest.java
@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");
}
 
源代码22 项目: plugins   文件: HerbiboarConfig.java
@ConfigItem(
	position = 0,
	keyName = "colorStart",
	name = "Start Color",
	description = "Color for rocks that start the trails",
	titleSection = "colorsTitle"
)
default Color getStartColor()
{
	return Color.CYAN;
}
 
源代码23 项目: ECG-Viewer   文件: BarRendererTest.java
/**
 * 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());

}
 
源代码24 项目: openjdk-jdk8u   文件: Test4193384.java
public static void main(String[] args) {
    test(new Color[] {
            new Color(11, 12, 13),
            new Color(204, 0, 204),
            new Color(0, 51, 51)
    });
}
 
源代码25 项目: osp   文件: ColorMapper.java
/**
 * 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];
}
 
源代码26 项目: ECG-Viewer   文件: ColorPalette.java
/**
     * 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);
    }
 
源代码27 项目: openjdk-8-source   文件: MyCursor.java
@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);
}
 
源代码28 项目: hottub   文件: ColorChooserPanel.java
@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();
    }
}
 
源代码29 项目: Rails   文件: HexMap.java
@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)");
    }
}
 
源代码30 项目: dragonwell8_jdk   文件: SurfaceDataProxy.java
@Override
public boolean isSupportedOperation(SurfaceData srcData,
                                    int txtype,
                                    CompositeType comp,
                                    Color bgColor)
{
    return false;
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法