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:de.tor.tribes.ui.views.DSWorkbenchConquersFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    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 w w  .jav  a2  s.  c o  m*/
        g.dispose();
        TexturePaint paint = new TexturePaint(back,
                new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));
        jxFilterPane.setBackgroundPainter(new MattePainter(paint));
        DefaultListModel model = new DefaultListModel();

        for (int i = 0; i < jConquersTable.getColumnCount(); i++) {
            TableColumnExt col = jConquersTable.getColumnExt(i);
            if (col.isVisible() && !col.getTitle().equals("Entfernung")
                    && !col.getTitle().equals("Dorfpunkte")) {
                model.addElement(col.getTitle());
            }
        }
        jXColumnList.setModel(model);
        jXColumnList.setSelectedIndex(0);
        jxFilterPane.setVisible(true);
    }
}

From source file:edu.ku.brc.specify.plugins.imgproc.ImageProcessorPanel.java

@Override
public void paint(Graphics g) {
    ((Graphics2D) g).addRenderingHints(hints);

    super.paint(g);

    if (font == null) {
        font = (new JLabel()).getFont();
        font = font.deriveFont(18.0f);//ww w . ja  v  a 2  s .  c  om
        font = font.deriveFont(Font.BOLD);
    }
    String title = "Specify Image Processor";
    g.setColor(new Color(32, 131, 155));
    g.setFont(font);
    int w = g.getFontMetrics().stringWidth(title);
    int y = g.getFontMetrics().getHeight() - 5;
    int x = (getSize().width - w) / 2;

    g.drawString(title, x, y);
}

From source file:TreeLinkTest.java

void paintLines(Graphics g, Color dk, Color br) {
    if (comp.isVisible()) {
        Rectangle b = comp.getBounds();
        int x1off = b.x + b.width / 2;
        int x2off = b.x + b.width;
        int y1off = b.y;
        for (Enumeration e = children.elements(); e.hasMoreElements();) {
            TreeNode tn = (TreeNode) (e.nextElement());
            if (tn.comp.isVisible()) {
                Rectangle bn = tn.comp.getBounds();
                int y2off = bn.y + bn.height / 2;
                g.setColor(dk);
                g.drawLine(x1off, y1off, x1off, y2off);
                g.drawLine(x1off, y2off - 1, x2off, y2off - 1);
                g.setColor(br);/*from   ww  w . j a  v  a2s .c  om*/
                g.drawLine(x1off + 1, y1off, x1off + 1, y2off);
                g.drawLine(x1off, y2off, x2off, y2off);
                tn.paintLines(g, dk, br);
            }
        }
    }
}

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

@Override
public void actionPerformed(ActionEvent e) {
    TroopTableTab activeTab = getActiveTab();
    if (e.getActionCommand().equals("Delete")) {
        if (activeTab != null) {
            activeTab.deleteSelection();
        }//from w w w .  j a  v  a 2 s .  com
    } else if (e.getActionCommand().equals("BBCopy")) {
        if (activeTab != null) {
            activeTab.transferSelection(TroopTableTab.TRANSFER_TYPE.CLIPBOARD_BB);
        }
    } 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);
        g.dispose();
        TexturePaint paint = new TexturePaint(back,
                new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));
        jxSearchPane.setBackgroundPainter(new MattePainter(paint));
        updateTagList();
        jxSearchPane.setVisible(true);
    } else if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("SelectionDone")) {
            activeTab.updateSelectionInfo();
        }
    }
}

From source file:edu.clemson.cs.nestbed.client.gui.MoteManagementPanel.java

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

    if (moteDepConfig == null) {
        paintDisabledPattern(g);//w ww  .ja va 2 s  .c om
    } else if (drawBorder) {
        Color oldColor = g.getColor();
        Color newColor = (installedSuccessfully || (installAnimationThread != null)) ? Color.green : Color.red;
        int arcSize = 4;

        g.setColor(newColor);
        g.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arcSize, arcSize);
        g.setColor(oldColor);
    }
}

From source file:BeanContainer.java

public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Color colorRetainer = g.getColor();

        g.setColor(getBackground());
        g.fillRect(0, 0, getWidth(), getHeight());
        getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight());

        m_calendar.setTime(new Date()); // get current time
        int hrs = m_calendar.get(Calendar.HOUR_OF_DAY);
        int min = m_calendar.get(Calendar.MINUTE);

        g.setColor(getForeground());/* ww  w .j a v a 2 s .  c  om*/
        if (m_digital) {
            String time = "" + hrs + ":" + min;
            g.setFont(getFont());
            FontMetrics fm = g.getFontMetrics();
            int y = (getHeight() + fm.getAscent()) / 2;
            int x = (getWidth() - fm.stringWidth(time)) / 2;
            g.drawString(time, x, y);
        } else {
            int x = getWidth() / 2;
            int y = getHeight() / 2;
            int rh = getHeight() / 4;
            int rm = getHeight() / 3;

            double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI;
            double am = min / 30.0 * Math.PI;

            g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah)));
            g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am)));
        }

        g.setColor(colorRetainer);
    }

From source file:ImageLabel.java

public void paint(Graphics g) {

    /*/*from w  ww.ja v a2s  . co m*/
     * Draw the image stretched to exactly cover the size of the drawing area.
     */
    Dimension size = getSize();
    g.drawImage(img, 0, 0, size.width, size.height, 0, 0, img.getWidth(null), img.getHeight(null), null);

    /*
     * Fill a rounded rectangle centered in the drawing area. Calculate the size
     * of the rectangle from the size of the text
     */
    g.setFont(font);
    FontRenderContext frc = ((Graphics2D) g).getFontRenderContext();
    Rectangle2D bounds = font.getStringBounds(text, frc);

    int wText = (int) bounds.getWidth();
    int hText = (int) bounds.getHeight();

    int rX = (size.width - wText) / 2;
    int rY = (size.height - hText) / 2;
    g.setColor(Color.yellow);
    g.fillRoundRect(rX, rY, wText, hText, hText / 2, hText / 2);

    /*
     * Draw text positioned in the rectangle. Since the rectangle is sized based
     * on the bounds of the String we can position it using those bounds.
     */
    int xText = rX - (int) bounds.getX();
    int yText = rY - (int) bounds.getY();
    g.setColor(Color.black);
    g.setFont(font);
    g.drawString(text, xText, yText);
}

From source file:org.openconcerto.task.TodoListPanel.java

private void initTable(int mode) {
    this.t.setBlockRepaint(true);

    this.t.setBlockEventOnColumn(true);
    this.model.setMode(mode);

    this.t.getColumnModel().getColumn(0).setCellRenderer(this.a);
    this.t.getColumnModel().getColumn(0).setCellEditor(this.a);
    this.t.setBlockEventOnColumn(true);
    setIconForColumn(0, this.iconTache);
    setIconForColumn(1, this.iconPriorite);
    this.t.setBlockEventOnColumn(true);

    this.t.getColumnModel().getColumn(1).setCellEditor(this.iconEditor);
    final JTextField textField = new JTextField() {
        @Override/*from w  ww. j  a  va  2 s .c o  m*/
        public void paint(Graphics g) {
            super.paint(g);
            g.setColor(TodoListPanel.this.t.getGridColor());
            g.fillRect(getWidth() - 19, 0, 1, getHeight());
            g.setColor(new Color(250, 250, 250));
            g.fillRect(getWidth() - 18, 0, 18, getHeight());
            g.setColor(Color.BLACK);
            for (int i = 0; i < 3; i++) {
                int x = getWidth() - 14 + i * 4;
                int y = getHeight() - 5;
                g.fillRect(x, y, 1, 2);
            }
        }
    };
    textField.setBorder(BorderFactory.createEmptyBorder());
    final DefaultCellEditor defaultCellEditor = new DefaultCellEditor(textField);
    textField.addMouseListener(new MouseListener() {

        public void mouseClicked(MouseEvent e) {

        }

        public void mouseEntered(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mouseExited(MouseEvent e) {
            // TODO Auto-generated method stub

        }

        public void mousePressed(MouseEvent e) {

        }

        public void mouseReleased(MouseEvent e) {
            if (e.getX() > textField.getWidth() - 19) {
                TodoListElement l = getTaskAt(
                        SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), TodoListPanel.this.t));
                TodoListPanel.this.t.editingCanceled(new ChangeEvent(this));
                JFrame f = new JFrame(TM.tr("details"));
                f.setContentPane(new TodoListElementEditorPanel(l));
                f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                f.setSize(500, 200);
                f.setLocation(50, e.getYOnScreen() + TodoListPanel.this.t.getRowHeight());
                f.setVisible(true);
            }

        }
    });
    this.t.getColumnModel().getColumn(2).setCellEditor(defaultCellEditor);
    this.t.getColumnModel().getColumn(3).setMaxWidth(300);
    this.t.getColumnModel().getColumn(3).setMinWidth(100);

    this.timestampTableCellEditorCreated.stopCellEditing();
    this.timestampTableCellEditorDone.stopCellEditing();
    this.timestampTableCellEditorDeadLine.stopCellEditing();

    if (this.model.getMode() == TodoListModel.EXTENDED_MODE) {
        this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererCreated);
        this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorCreated);

        this.t.getColumnModel().getColumn(4).setCellRenderer(this.timestampTableCellRendererDone);
        this.t.getColumnModel().getColumn(4).setCellEditor(this.timestampTableCellEditorDone);

        this.t.getColumnModel().getColumn(5).setCellRenderer(this.timestampTableCellRendererDeadLine);
        this.t.getColumnModel().getColumn(5).setCellEditor(this.timestampTableCellEditorDeadLine);
    } else {
        this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererDeadLine);
        this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorDeadLine);
    }

    final TableColumn userColumn = this.t.getColumnModel()
            .getColumn(this.t.getColumnModel().getColumnCount() - 1);
    userColumn.setCellRenderer(this.userTableCellRenderer);
    userColumn.setMaxWidth(150);
    userColumn.setMinWidth(100);
    t.setEnabled(false);
    initUserCellEditor(userColumn);

    this.t.setBlockEventOnColumn(false);
    this.t.setBlockRepaint(false);
    this.t.getColumnModel().getColumn(1).setCellRenderer(this.iconRenderer);
    // Better look
    this.t.setShowHorizontalLines(false);
    this.t.setGridColor(new Color(230, 230, 230));
    this.t.setRowHeight(new JTextField(" ").getPreferredSize().height + 4);
    AlternateTableCellRenderer.UTILS.setAllColumns(this.t);
    this.t.repaint();

}

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

private void drawVolumeMeterBar(Graphics pGraphics, int pX, int pY, int pWidth, int pHeight) {
    float c = 0;/*from ww  w  . j a  va2s  .  co  m*/
    for (int a = pX; a <= pX + pWidth; a += 2) {
        c += vuColorScale;
        if (c < 256.0f) {
            pGraphics.setColor(spectrumAnalyserColors[(int) c]);
        }
        pGraphics.fillRect(a, pY, 1, pHeight);
    }
}

From source file:rod_design_compute.ShowPanel.java

private void drawChoosePoint(Point point, Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(2f));

    int x = toScreenX(point.X);
    int y = toScreenY(point.Y);

    g.setColor(Color.blue);
    g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
}