Example usage for java.awt Graphics fillRect

List of usage examples for java.awt Graphics fillRect

Introduction

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

Prototype

public abstract void fillRect(int x, int y, int width, int height);

Source Link

Document

Fills the specified rectangle.

Usage

From source file:RedGreenBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Insets insets = getBorderInsets(c);
    Color horizontalColor;/*from   www.  j  av  a  2s.  co m*/
    Color verticalColor;
    if (c.isEnabled()) {
        boolean pressed = false;
        if (c instanceof AbstractButton) {
            ButtonModel model = ((AbstractButton) c).getModel();
            pressed = model.isPressed();
        }
        if (pressed) {
            horizontalColor = Color.red;
            verticalColor = Color.green;
        } else {
            horizontalColor = Color.green;
            verticalColor = Color.red;
        }
    } else {
        horizontalColor = Color.lightGray;
        verticalColor = Color.lightGray;
    }
    g.setColor(horizontalColor);

    g.translate(x, y);

    // top
    g.fillRect(0, 0, width, insets.top);
    // bottom
    g.fillRect(0, height - insets.bottom, width, insets.bottom);

    g.setColor(verticalColor);
    // left
    g.fillRect(0, insets.top, insets.left, height - insets.top - insets.bottom);
    g.fillRect(width - insets.right, insets.top, insets.right, height - insets.top - insets.bottom);
    g.translate(-x, -y);
}

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   www. j a  va  2 s.  c  om*/
    } 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:BeanContainer.java

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

        g.setColor(getBackground());/*from  ww w .j av a 2  s .  com*/
        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());
        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:ubic.basecode.graphics.MatrixDisplay.java

/**
 * Draws row names (horizontally)//from   w  w  w .  java2  s.c o  m
 * 
 * @param g Graphics
 * @param showScalebar
 */
protected void drawRowNames(Graphics g, boolean showScalebar) {

    if (colorMatrix == null)
        return;

    Color oldColor = g.getColor();

    g.setColor(Color.white);
    g.fillRect(colorMatrix.getColumnCount() * m_cellSize.width, 0,
            colorMatrix.getColumnCount() * m_cellSize.width, this.getHeight());

    int rowCount = colorMatrix.getRowCount();
    int xLabelStartPosition = colorMatrix.getColumnCount() * m_cellSize.width + m_labelGutter;
    g.setColor(Color.black);
    g.setFont(m_labelFont);

    for (int i = 0; i < rowCount; i++) {
        int y = i * m_cellSize.height + m_columnLabelHeight + m_labelGutter;
        int yLabelPosition = y + m_cellSize.height - m_fontGutter;
        if (showScalebar) {
            yLabelPosition += SCALE_BAR_ROOM;
        }

        Object rowName = colorMatrix.getRowName(i);
        if (null == rowName) {
            rowName = "Undefined";
        }

        g.drawString(rowName.toString(), xLabelStartPosition, yLabelPosition);

    } // end drawing row names
    g.setColor(oldColor);
}

From source file:MainClass.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Insets insets = getBorderInsets(c);
    Color horizontalColor;/*w w w  .ja v  a  2  s. c  om*/
    Color verticalColor;
    if (c.isEnabled()) {
        boolean pressed = false;
        if (c instanceof AbstractButton) {
            ButtonModel model = ((AbstractButton) c).getModel();
            pressed = model.isPressed();
        }
        if (pressed) {
            horizontalColor = Color.WHITE;
            verticalColor = Color.BLACK;
        } else {
            horizontalColor = Color.BLACK;
            verticalColor = Color.WHITE;
        }
    } else {
        horizontalColor = Color.LIGHT_GRAY;
        verticalColor = Color.LIGHT_GRAY;
    }
    g.setColor(horizontalColor);

    g.translate(x, y);

    // top
    g.fillRect(0, 0, width, insets.top);
    // bottom
    g.fillRect(0, height - insets.bottom, width, insets.bottom);

    g.setColor(verticalColor);
    // left
    g.fillRect(0, insets.top, insets.left, height - insets.top - insets.bottom);
    // right
    g.fillRect(width - insets.right, insets.top, insets.right, height - insets.top - insets.bottom);
    g.translate(-x, -y);
}

From source file:ubic.basecode.graphics.MatrixDisplay.java

/**
 * Gets called from #paintComponent and #saveImage. Does not draw the labels.
 * //  w w w  .  j a va  2  s  .c  om
 * @param g Graphics
 * @param leaveRoomForLabels boolean
 */
protected void drawMatrix(ColorMatrix<R, C> matrix, Graphics g, boolean leaveRoomForLabels,
        boolean leaveRoomForScalebar) {

    // fill in background with white.
    Color oldColor = g.getColor();
    g.setColor(Color.white);
    g.fillRect(0, 0, this.getWidth(), this.getHeight());

    int rowCount = matrix.getRowCount();
    int columnCount = matrix.getColumnCount();

    // loop through the matrix, one row at a time
    for (int i = 0; i < rowCount; i++) {
        int y = i * m_cellSize.height;
        if (leaveRoomForLabels) {
            y += m_columnLabelHeight + m_labelGutter;
        }
        if (leaveRoomForScalebar) {
            y += SCALE_BAR_ROOM;
        }

        // draw an entire row, one cell at a time
        for (int j = 0; j < columnCount; j++) {
            int x = j * m_cellSize.width;
            int width = (j + 1) * m_cellSize.width - x;

            Color color = matrix.getColor(i, j);
            g.setColor(color);
            g.fillRect(x, y, width, m_cellSize.height);
        }

    }
    g.setColor(oldColor);
}

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/*ww w  .j  av a  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  www .  j av  a 2s  . c  om*/
    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:JXTransformer.java

public void paint(Graphics g) {
    //repaint the whole transformer in case the view component was repainted
    Rectangle clipBounds = g.getClipBounds();        
    if (clipBounds != null && !clipBounds.equals(visibleRect)) {
        repaint();/*from   ww w .ja  v  a 2s . com*/
    }
    //clear the background
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());

    if (view != null && at.getDeterminant() != 0) {
        Graphics2D g2 = (Graphics2D) g.create();
        Insets insets = getInsets();
        Rectangle bounds = getBounds();
            
        //don't forget about insets
        bounds.x += insets.left;
        bounds.y += insets.top;
        bounds.width -= insets.left + insets.right;
        bounds.height -= insets.top + insets.bottom;
        double centerX1 = bounds.getCenterX();
        double centerY1 = bounds.getCenterY();

        Rectangle tb = getTransformedSize();
        double centerX2 = tb.getCenterX();
        double centerY2 = tb.getCenterY();

        //set antialiasing by default
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        if (renderingHints != null) {
            g2.addRenderingHints(renderingHints);
        }
        //translate it to the center of the view component again
        double tx = centerX1 - centerX2 - getX();
        double ty = centerY1 - centerY2 - getY();
        g2.translate((int) tx, (int) ty);
        g2.transform(at);
        view.paint(g2);
        g2.dispose();
    }
    //paint the border
    paintBorder(g);
}

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

private void drawSpectrumAnalyserBar(Graphics pGraphics, int pX, int pY, int pWidth, int pHeight, int band) {
    float c = 0;// ww w . j  a  va 2  s  . c  o m
    for (int a = pY; a >= pY - pHeight; a -= barOffset) {
        c += saColorScale;
        if (c < spectrumAnalyserColors.length) {
            pGraphics.setColor(spectrumAnalyserColors[(int) c]);
        }
        pGraphics.fillRect(pX, a, pWidth, 1);
    }
    if ((peakColor != null) && (peaksEnabled == true)) {
        pGraphics.setColor(peakColor);
        if (pHeight > peaks[band]) {
            peaks[band] = pHeight;
            peaksDelay[band] = peakDelay;
        } else {
            peaksDelay[band]--;
            if (peaksDelay[band] < 0)
                peaks[band]--;
            if (peaks[band] < 0)
                peaks[band] = 0;
        }
        pGraphics.fillRect(pX, pY - peaks[band], pWidth, 1);
    }
}