Example usage for java.awt Graphics setColor

List of usage examples for java.awt Graphics setColor

Introduction

In this page you can find the example usage for java.awt Graphics setColor.

Prototype

public abstract void setColor(Color c);

Source Link

Document

Sets this graphics context's current color to the specified color.

Usage

From source file:org.eurocarbdb.application.glycoworkbench.plugin.AnnotationReportApplet.java

public void paint(Graphics g) {

    super.paint(g);

    // Draw a 2-pixel border
    g.setColor(Color.black);

    int width = getSize().width; // Width of the applet.
    int height = getSize().height; // Height of the applet.
    g.drawRect(0, 0, width - 1, height - 1);
    g.drawRect(1, 1, width - 3, height - 3);
}

From source file:net.technicpack.launcher.ui.InstallerFrame.java

private void addGlassPane() {
    glassPane = new JPanel() {
        @Override// w  w w.ja v  a2 s .co  m
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.setColor(LauncherFrame.COLOR_CENTRAL_BACK);
            g.fillRect(0, 0, getWidth(), getHeight());
        }
    };
    glassPane.addMouseListener(new MouseListener() {
        @Override
        public void mouseClicked(MouseEvent e) {
            e.consume();
        }

        @Override
        public void mousePressed(MouseEvent e) {
            e.consume();
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            e.consume();
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            e.consume();
        }

        @Override
        public void mouseExited(MouseEvent e) {
            e.consume();
        }
    });
    glassPane.setOpaque(false);
    glassPane.setLayout(new GridBagLayout());

    JLabel spinner = new JLabel(resources.getIcon("loader.gif"));
    glassPane.add(spinner);
    setGlassPane(glassPane);
}

From source file:HiResCoordTest.java

private Shape3D createLabel(String szText, float x, float y, float z) {
    BufferedImage bufferedImage = new BufferedImage(50, 20, BufferedImage.TYPE_INT_RGB);
    Graphics g = bufferedImage.getGraphics();
    g.setColor(Color.white);
    g.drawString(szText, 10, 10);//from  www . j  ava  2  s. c o  m

    ImageComponent2D imageComponent2D = new ImageComponent2D(ImageComponent2D.FORMAT_RGB, bufferedImage);
    imageComponent2D.setCapability(ImageComponent.ALLOW_IMAGE_READ);
    imageComponent2D.setCapability(ImageComponent.ALLOW_SIZE_READ);

    // create the Raster for the image
    javax.media.j3d.Raster renderRaster = new javax.media.j3d.Raster(new Point3f(x, y, z),
            javax.media.j3d.Raster.RASTER_COLOR, 0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(),
            imageComponent2D, null);

    return new Shape3D(renderRaster);
}

From source file:Main.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    g.drawLine(10, 100, 380, 100);// w ww .  j a va  2 s.c  om
    g.drawLine(200, 30, 200, 190);

    g.drawLine(380, 100, 370, 90);
    g.drawLine(380, 100, 370, 110);
    g.drawLine(200, 30, 190, 40);
    g.drawLine(200, 30, 210, 40);

    g.drawString("X", 360, 80);
    g.drawString("Y", 220, 40);

    Polygon p = new Polygon();
    Polygon p2 = new Polygon();

    for (int x = -170; x <= 170; x++) {
        p.addPoint(x + 200, 100 - (int) (50 * f((x / 100.0) * 2 * Math.PI)));

    }

    for (int x = -170; x <= 170; x++) {
        p2.addPoint(x + 200, 100 - (int) (50 * gCos((x / 100.0) * 2 * Math.PI)));

    }

    g.setColor(Color.red);
    g.drawPolyline(p.xpoints, p.ypoints, p.npoints);
    g.drawString("-2\u03c0", 95, 115);
    g.drawString("-\u03c0", 147, 115);
    g.drawString("\u03c0", 253, 115);
    g.drawString("2\u03c0", 305, 115);
    g.drawString("0", 200, 115);

    g.setColor(Color.blue);
    g.drawPolyline(p2.xpoints, p2.ypoints, p2.npoints);

}

From source file:JavaXWin.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    m_height = getHeight();/*from   www. java  2 s .  c om*/
    m_width = getWidth();
    g.setColor(C_BACKGROUND);
    g.fillRect(0, 0, m_width, m_height);
    Component[] components = m_desktop.getComponents();
    m_widthratio = ((float) m_desktop.getWidth()) / ((float) m_width);
    m_heightratio = ((float) m_desktop.getHeight()) / ((float) m_height);
    for (int i = components.length - 1; i > -1; i--) {
        if (components[i].isVisible()) {
            g.setColor(C_UNSELECTED);
            if (components[i] instanceof JInternalFrame) {
                if (((JInternalFrame) components[i]).isSelected())
                    g.setColor(C_SELECTED);
            } else if (components[i] instanceof WindowWatcher)
                g.setColor(C_WWATCHER);
            g.fillRect((int) (((float) components[i].getX()) / m_widthratio),
                    (int) (((float) components[i].getY()) / m_heightratio),
                    (int) (((float) components[i].getWidth()) / m_widthratio),
                    (int) (((float) components[i].getHeight()) / m_heightratio));
            g.setColor(Color.black);
            g.drawRect((int) (((float) components[i].getX()) / m_widthratio),
                    (int) (((float) components[i].getY()) / m_heightratio),
                    (int) (((float) components[i].getWidth()) / m_widthratio),
                    (int) (((float) components[i].getHeight()) / m_heightratio));
        }
    }
    g.drawLine(m_width / 2, 0, m_width / 2, m_height);
    g.drawLine(0, m_height / 2, m_width, m_height / 2);
}

From source file:de.tor.tribes.ui.views.DSWorkbenchNotepad.java

@Override
public void actionPerformed(ActionEvent e) {

    NoteTableTab activeTab = getActiveTab();
    if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("Copy")) {
            activeTab.transferSelection(NoteTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("BBCopy")) {
            activeTab.transferSelection(NoteTableTab.TRANSFER_TYPE.CLIPBOARD_BB);
        } else if (e.getActionCommand().equals("BBCopy_Village")) {
            activeTab.copyVillagesAsBBCodes();
        } else if (e.getActionCommand().equals("Cut")) {
            activeTab.transferSelection(NoteTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("Paste")) {
            activeTab.transferSelection(NoteTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("Delete")) {
            activeTab.deleteSelection(true);
        } else if (e.getActionCommand().equals("Delete_Village")) {
            activeTab.deleteVillagesFromNotes();
        } else if (e.getActionCommand().equals("Find")) {
            BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT);
            Graphics g = back.getGraphics();
            g.setColor(new Color(120, 120, 120, 120));
            g.fillRect(0, 0, back.getWidth(), back.getHeight());
            g.setColor(new Color(120, 120, 120));
            g.drawLine(0, 0, 3, 3);//w ww .j  a v  a 2s  .c  om
            g.dispose();
            TexturePaint paint = new TexturePaint(back,
                    new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));
            jxSearchPane.setBackgroundPainter(new MattePainter(paint));
            jxSearchPane.setVisible(true);
        }
    }
}

From source file:javazoom.jlgui.player.amp.visual.ui.SpectrumTimeAnalyzer.java

public synchronized void process(float[] pLeft, float[] pRight, float pFrameRateRatioHint) {
    if (displayMode == DISPLAY_MODE_OFF)
        return;//from w  ww  .  j  a v a2  s  . c o  m
    Graphics wGrp = getDoubleBuffer().getGraphics();
    wGrp.setColor(getBackground());
    wGrp.fillRect(0, 0, getSize().width, getSize().height);
    switch (displayMode) {
    case DISPLAY_MODE_SCOPE:
        drawScope(wGrp, stereoMerge(pLeft, pRight));
        break;
    case DISPLAY_MODE_SPECTRUM_ANALYSER:
        drawSpectrumAnalyser(wGrp, stereoMerge(pLeft, pRight), pFrameRateRatioHint);
        break;
    case DISPLAY_MODE_OFF:
        drawVUMeter(wGrp, pLeft, pRight, pFrameRateRatioHint);
        break;
    }
    // -- Show FPS if necessary.
    if (showFPS) {
        // -- Calculate FPS.
        if (System.currentTimeMillis() >= lfu + 1000) {
            lfu = System.currentTimeMillis();
            fps = fc;
            fc = 0;
        }
        fc++;
        wGrp.setColor(Color.yellow);
        wGrp.drawString("FPS: " + fps + " (FRRH: " + pFrameRateRatioHint + ")", 0, height - 1);
    }
    if (getGraphics() != null)
        getGraphics().drawImage(getDoubleBuffer(), 0, 0, null);
    //      repaint();
    //      try {
    //          EventQueue.invokeLater( new AWTPaintSynchronizer() );
    //      } catch ( Exception pEx ) {
    //          // -- Ignore exception.
    //          pEx.printStackTrace();
    //      }
}

From source file:Main.java

@Override
public void paintDeterminate(Graphics g, JComponent c) {
    if (!(g instanceof Graphics2D)) {
        return;/*w  w  w. j  a va2 s  .  c om*/
    }
    Insets b = progressBar.getInsets(); // area for border
    int barRectWidth = progressBar.getWidth() - (b.right + b.left);
    int barRectHeight = progressBar.getHeight() - (b.top + b.bottom);
    if (barRectWidth <= 0 || barRectHeight <= 0) {
        return;
    }
    int cellLength = getCellLength();
    int cellSpacing = getCellSpacing();

    int amountFull = getAmountFull(b, barRectWidth, barRectHeight);

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {

        float x = amountFull / (float) barRectWidth;
        g.setColor(Color.BLUE);
        g.fillRect(b.left, b.top, amountFull, barRectHeight);

    } else { // VERTICAL

    }
    if (progressBar.isStringPainted()) {
        paintString(g, b.left, b.top, barRectWidth, barRectHeight, amountFull, b);
    }
}

From source file:edu.umn.cs.spatialHadoop.osm.OSMEdge.java

@Override
public void draw(Graphics g, double xscale, double yscale) {
    int x1 = (int) Math.round(this.lon1 * xscale);
    int y1 = (int) Math.round(this.lat1 * yscale);
    int x2 = (int) Math.round(this.lon2 * xscale);
    int y2 = (int) Math.round(this.lat2 * yscale);
    Color shape_color = g.getColor();
    // Compute alpha to use based on edge length and image scale
    double geom_alpha = this.getLength() * (xscale + yscale) / 2.0;
    int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255);
    if (color_alpha == 0)
        return;/*from  ww w.  j  ava  2  s  .  c o  m*/

    g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true));
    g.drawLine(x1, y1, x2, y2);
}

From source file:fr.avianey.androidsvgdrawable.SvgDrawablePlugin.java

/**
 * Draw the stretch and content area defined by the {@link NinePatch} around the given image
 * @param is//  ww w  . jav a  2  s .  c  om
 * @param finalName
 * @param ninePatch
 * @param ratio
 * @throws IOException
 */
private void toNinePatch(final InputStream is, final String finalName, final NinePatch ninePatch,
        final double ratio) throws IOException {
    BufferedImage image = ImageIO.read(is);
    final int w = image.getWidth();
    final int h = image.getHeight();
    BufferedImage ninePatchImage = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB);
    Graphics g = ninePatchImage.getGraphics();
    g.drawImage(image, 1, 1, null);

    // draw patch
    g.setColor(Color.BLACK);

    Zone stretch = ninePatch.getStretch();
    Zone content = ninePatch.getContent();

    if (stretch.getX() == null) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("+ ninepatch stretch(x) [start=0 - size=" + w + "]");
        }
        g.fillRect(1, 0, w, 1);
    } else {
        for (int[] seg : stretch.getX()) {
            final int start = NinePatch.start(seg[0], seg[1], w, ratio);
            final int size = NinePatch.size(seg[0], seg[1], w, ratio);
            if (getLog().isDebugEnabled()) {
                getLog().debug("+ ninepatch stretch(x) [start=" + start + " - size=" + size + "]");
            }
            g.fillRect(start + 1, 0, size, 1);
        }
    }

    if (stretch.getY() == null) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("+ ninepatch stretch(y) [start=0 - size=" + h + "]");
        }
        g.fillRect(0, 1, 1, h);
    } else {
        for (int[] seg : stretch.getY()) {
            final int start = NinePatch.start(seg[0], seg[1], h, ratio);
            final int size = NinePatch.size(seg[0], seg[1], h, ratio);
            if (getLog().isDebugEnabled()) {
                getLog().debug("+ ninepatch stretch(y) [start=" + start + " - size=" + size + "]");
            }
            g.fillRect(0, start + 1, 1, size);
        }
    }

    if (content.getX() == null) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("+ ninepatch content(x) [start=0 - size=" + w + "]");
        }
        g.fillRect(1, h + 1, w, 1);
    } else {
        for (int[] seg : content.getX()) {
            final int start = NinePatch.start(seg[0], seg[1], w, ratio);
            final int size = NinePatch.size(seg[0], seg[1], w, ratio);
            if (getLog().isDebugEnabled()) {
                getLog().debug("+ ninepatch content(x) [start=" + start + " - size=" + size + "]");
            }
            g.fillRect(start + 1, h + 1, size, 1);
        }
    }

    if (content.getY() == null) {
        if (getLog().isDebugEnabled()) {
            getLog().debug("+ ninepatch content(y) [start=0 - size=" + h + "]");
        }
        g.fillRect(w + 1, 1, 1, h);
    } else {
        for (int[] seg : content.getY()) {
            final int start = NinePatch.start(seg[0], seg[1], h, ratio);
            final int size = NinePatch.size(seg[0], seg[1], h, ratio);
            if (getLog().isDebugEnabled()) {
                getLog().debug("+ ninepatch content(y) [start=" + start + " - size=" + size + "]");
            }
            g.fillRect(w + 1, start + 1, 1, size);
        }
    }

    ImageIO.write(ninePatchImage, "png", new File(finalName));
}