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:Main.java

@Override
public void paintDeterminate(Graphics g, JComponent c) {
    if (!(g instanceof Graphics2D)) {
        return;/*  w w w.jav  a2  s . c o  m*/
    }
    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:se.llbit.chunky.world.Layer.java

/**
 * Render block highlight//ww w  .jav a  2 s .  co  m
 * @param rbuff
 * @param cx
 * @param cz
 * @param hlBlock
 * @param highlight
 */
public synchronized void renderHighlight(RenderBuffer rbuff, int cx, int cz, Block hlBlock,
        java.awt.Color highlight) {

    ChunkView view = rbuff.getView();
    int x0 = view.chunkScale * (cx - view.ix0);
    int z0 = view.chunkScale * (cz - view.iz0);

    if (blocks == null)
        return;

    Graphics g = rbuff.getGraphics();
    g.setColor(new java.awt.Color(1, 1, 1, 0.35f));
    g.fillRect(x0, z0, view.chunkScale, view.chunkScale);
    g.setColor(highlight);

    if (view.chunkScale == 16) {

        for (int x = 0; x < 16; ++x) {
            int xp = x0 + x;

            for (int z = 0; z < 16; ++z) {
                int yp = z0 + z;

                if (hlBlock.id == (0xFF & blocks[x * 16 + z])) {
                    rbuff.setRGB(xp, yp, highlight.getRGB());
                }
            }
        }
    } else {
        int blockScale = view.chunkScale / 16;

        for (int x = 0; x < 16; ++x) {
            int xp0 = x0 + x * blockScale;
            int xp1 = xp0 + blockScale;

            for (int z = 0; z < 16; ++z) {
                int yp0 = z0 + z * blockScale;
                int yp1 = yp0 + blockScale;

                if (hlBlock.id == (0xFF & blocks[x * 16 + z])) {
                    g.fillRect(xp0, yp0, xp1 - xp0, yp1 - yp0);
                }
            }
        }
    }
}

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

private void addGlassPane() {
    glassPane = new JPanel() {
        @Override//  w ww.java2 s .  c  o 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:uk.co.modularaudio.mads.base.soundfile_player.ui.SoundfilePlayerWaveDisplayUiJComponent.java

@Override
public void paint(final Graphics g) {
    //      log.trace("WaveDisplay paint() called");
    if (rollPainter != null) {
        if (rollPainter.buffer0Visible()) {
            g.drawImage(rollPainter.buffer0.bi, rollPainter.buffer0XOffset, 0, null);
        }// w  w  w  .java 2s  . c o  m
        if (rollPainter.buffer1Visible()) {
            g.drawImage(rollPainter.buffer1.bi, rollPainter.buffer1XOffset, 0, null);
        }
    } else {
        g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_BACKGROUND_COLOR);
        g.fillRect(0, 0, displayWidth, displayHeight);
    }
    g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_CURRENT_POSITION_COLOUR);
    g.drawLine(displayWidthMinusOneOverTwo, 0, displayWidthMinusOneOverTwo, displayHeight);
}

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);/*from  w w  w  .  ja v a  2 s.  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:uk.co.modularaudio.util.audio.gui.patternsequencer.PatternSequenceNoteGrid.java

private void paintCells(final Graphics g, final int startCol, final int endCol, final int startRow,
        final int endRow) {
    g.setColor(blockColour);//from  w w  w . j a v  a  2 s  .c om
    // Now fill in any spots that have something currently set
    for (int i = startCol; i < endCol; i++) {
        final PatternSequenceStep psn = dataModel.getNoteAtStep(i);
        final MidiNote mn = psn.note;
        if (mn != null) {
            final int row = (numMidiNotes - 1) - mn.getMidiNumber();
            final int startx = (i * cellDimensions.width) + 2;
            final int starty = (row * cellDimensions.height) + 2;
            g.fillRect(startx, starty, cellDimensions.width - 3, cellDimensions.height - 3);
        }
    }
}

From source file:br.fapesp.myutils.MyUtils.java

/**
 * Plot a matrix consisting of 0's and 1's.
 * /*from w  ww .  ja va 2s .co  m*/
 * @param map
 */
public static void plotBinaryMatrix(final int[][] map, int width, int height) {
    JFrame frame = new JFrame("Binary matrix plot");

    frame.add(new JComponent() {
        private static final long serialVersionUID = 1L;

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

            int w = getWidth() / map.length;
            int h = getHeight() / map[0].length;

            for (int i = 0; i < map.length; i++) {
                for (int j = 0; j < map[0].length; j++) {
                    if (map[i][j] != 0) {
                        g.setColor(new Color(map[i][j]));
                        g.fillRect(i * w, j * h, w, h);
                    }
                }
            }
        }
    });

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(width, height);
    frame.setVisible(true);
}

From source file:org.deegree.portal.standard.wms.control.DynLegendListener.java

/**
 * Draws the given symbol to the given image
 * // w w w. j a  va  2s.c o  m
 * @param map
 *            Hashmap holding the properties of the legend
 * @param bi
 *            image of the legend
 * @param color
 *            color to fill the graphic
 * @return The drawn BufferedImage
 */
private BufferedImage drawSymbolsToBI(HashMap<String, Object> map, BufferedImage bi, Color color) {

    Graphics g = bi.getGraphics();
    g.setColor(color);
    g.fillRect(0, 0, bi.getWidth(), bi.getHeight());

    String[] layers = (String[]) map.get("NAMES");
    String[] titles = (String[]) map.get("TITLES");
    BufferedImage[] legs = (BufferedImage[]) map.get("IMAGES");
    int h = topMargin;
    for (int i = layers.length - 1; i >= 0; i--) {
        g.drawImage(legs[i], leftMargin, h, null);
        g.setColor(Color.BLACK);
        // just draw title if the flag has been set in listener configuration,
        // the legend image is less than a defined value and a legend image
        // (not missing) has been accessed
        if (useLayerTitle && legs[i].getHeight() < maxNNLegendSize && !missing.contains(layers[i])) {
            g.drawString(titles[i], leftMargin + legs[i].getWidth() + 10,
                    h + (int) (legs[i].getHeight() / 1.2));
        }
        h += legs[i].getHeight() + 5;
        if (separator != null && i > 0) {
            g.drawImage(separator, leftMargin, h, null);
            h += separator.getHeight() + 5;
        }
    }
    g.dispose();
    return bi;
}

From source file:org.kchine.r.server.impl.RGraphicsPanelRemote.java

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

    Dimension d = getSize();/*from w w  w . ja v  a2 s .  com*/

    if (!d.equals(_lastSize)) {
        _lastResizeTime = System.currentTimeMillis();
        _lastSize = d;
        return;
    } else {

    }

    if (forceAntiAliasing) {
        Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }

    int i = 0, j = _l.size();
    g.setFont(_gs.f);
    g.setClip(0, 0, d.width, d.height); // reset clipping rect
    g.setColor(Color.white);
    g.fillRect(0, 0, d.width, d.height);
    while (i < j) {
        GDObject o = (GDObject) _l.elementAt(i++);
        o.paint(this, _gs, g);
    }
}

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 . j  a  v  a  2  s  . c om
        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);
    }
}