Example usage for java.awt Graphics2D drawRect

List of usage examples for java.awt Graphics2D drawRect

Introduction

In this page you can find the example usage for java.awt Graphics2D drawRect.

Prototype

public void drawRect(int x, int y, int width, int height) 

Source Link

Document

Draws the outline of the specified rectangle.

Usage

From source file:net.rptools.maptool.client.ui.ChatTypingNotification.java

/**
 * This component is only made visible when there are notifications to be displayed. That means the first couple of
 * IF statements in this method are redundant since paintComponent() will not be called unless the component is
 * visible, and it will only be visible when there are notifications...
 *///  w  w  w.j  a  va2 s.  co  m
@Override
protected void paintComponent(Graphics g) {
    //      System.out.println("Chat panel is painting itself...");
    if (AppPreferences.getTypingNotificationDuration() == 0) {
        return;
    }
    LinkedMap chatTypers = MapTool.getFrame().getChatNotificationTimers().getChatTypers();
    if (chatTypers == null || chatTypers.isEmpty()) {
        return;
    }
    Boolean showBackground = AppPreferences.getChatNotificationShowBackground();

    Graphics2D statsG = (Graphics2D) g.create();

    Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD);
    Font font = AppStyle.labelFont;
    FontMetrics valueFM = g.getFontMetrics(font);
    FontMetrics keyFM = g.getFontMetrics(boldFont);

    int PADDING7 = 7;
    int PADDING3 = 3;
    int PADDING2 = 2;

    BufferedImage img = AppStyle.panelTexture;
    int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight());

    setBorder(null);
    int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin();
    int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin()
            + AppStyle.miniMapBorder.getBottomMargin();

    statsG.setFont(font);
    SwingUtil.useAntiAliasing(statsG);
    Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(),
            height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width,
            getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin()
                    + PADDING2);

    int y = bounds.y + rowHeight;
    rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight());

    setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight)) + AppStyle.miniMapBorder.getTopMargin()
            + AppStyle.miniMapBorder.getBottomMargin()));

    if (showBackground) {
        g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this);
        AppStyle.miniMapBorder.paintAround(statsG, bounds);
    }
    Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7,
            AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(),
            AppStyle.chatImage.getHeight());

    Set<?> keySet = chatTypers.keySet();
    @SuppressWarnings("unchecked")
    Set<String> playerTimers = (Set<String>) keySet;
    for (String playerNamer : playerTimers) {
        if (showBackground) {
            statsG.setColor(new Color(249, 241, 230, 140));
            statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                    (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
            statsG.setColor(new Color(175, 163, 149));
            statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                    (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
        }
        g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(),
                (int) rightRow.getHeight(), this);

        // Values
        statsG.setColor(MapTool.getFrame().getChatTypingLabelColor());
        statsG.setFont(boldFont);
        statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer),
                bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5);

        y += PADDING2 + rowHeight;
    }
    if (showBackground) {
        AppStyle.shadowBorder.paintWithin(statsG, bounds);
    } else {
        setOpaque(false);
    }
}

From source file:krasa.cpu.CpuUsagePanel.java

@Override
public void paintComponent(final Graphics g) {
    final boolean pressed = getModel().isPressed();
    final boolean stateChanged = myWasPressed != pressed;
    myWasPressed = pressed;/*from ww w .jav a  2  s.c o  m*/
    Image bufferedImage = myBufferedImage;

    if (bufferedImage == null || stateChanged) {
        final Dimension size = getSize();
        final Insets insets = getInsets();

        bufferedImage = UIUtil.createImage(g, size.width, size.height, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g2 = (Graphics2D) bufferedImage.getGraphics().create();

        final int max = 100;
        int system = CpuUsageManager.system;
        int process = CpuUsageManager.process;
        final int otherProcesses = system - process;

        final int totalBarLength = size.width - insets.left - insets.right - 3;
        final int processUsageBarLength = totalBarLength * process / max;
        final int otherProcessesUsageBarLength = totalBarLength * otherProcesses / max;
        final int barHeight = Math.max(size.height, getFont().getSize() + 2);
        final int yOffset = (size.height - barHeight) / 2;
        final int xOffset = insets.left;

        // background
        g2.setColor(UIUtil.getPanelBackground());
        g2.fillRect(0, 0, size.width, size.height);

        // gauge (ide)
        g2.setColor(ideColor);
        g2.fillRect(xOffset + 1, yOffset, processUsageBarLength + 1, barHeight);

        // gauge (system)
        g2.setColor(systemColor);
        g2.fillRect(xOffset + processUsageBarLength + 1, yOffset, otherProcessesUsageBarLength + 1, barHeight);

        // label
        g2.setFont(getFont());
        // final String info = CpuUsageBundle.message("cpu.usage.panel.message.text", CpuUsageManager.process,
        // CpuUsageManager.system);
        final String info = fixedLengthString(String.valueOf(process), 3) + "% / "
                + fixedLengthString(String.valueOf(system), 3) + "%";

        final FontMetrics fontMetrics = g.getFontMetrics();
        final int infoWidth = fontMetrics.charsWidth(info.toCharArray(), 0, info.length());
        final int infoHeight = fontMetrics.getAscent();
        UISettings.setupAntialiasing(g2);

        final Color fg = pressed ? UIUtil.getLabelDisabledForeground() : JBColor.foreground();
        g2.setColor(fg);
        g2.drawString(info, xOffset + (totalBarLength - infoWidth) / 2,
                yOffset + infoHeight + (barHeight - infoHeight) / 2 - 1);

        // border
        g2.setStroke(new BasicStroke(1));
        g2.setColor(JBColor.GRAY);
        g2.drawRect(0, 0, size.width - 2, size.height - 1);

        g2.dispose();
        myBufferedImage = bufferedImage;
    }

    draw(g, bufferedImage);
}

From source file:uk.co.modularaudio.service.gui.impl.racktable.back.AbstractLinkImage.java

private void drawLinkWireIntoImage(final Point sourcePoint, final Point sinkPoint) {
    //      log.debug("Drawing link from " + sourcePoint + " to " + sinkPoint);

    final int fromX = sourcePoint.x;
    final int fromY = sourcePoint.y;
    final int toX = sinkPoint.x;
    final int toY = sinkPoint.y;

    float f1, f2, f3, f4, f5, f6, f7, f8 = 0.0f;
    f1 = fromX;/*w w  w .j a v a  2 s.  co  m*/
    f2 = fromY;
    f3 = fromX;
    f4 = fromY + WIRE_DIP_PIXELS;
    f5 = toX;
    f6 = toY + WIRE_DIP_PIXELS;
    f7 = toX;
    f8 = toY;
    final CubicCurve2D cubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8);
    final Rectangle cubicCurveBounds = cubicCurve.getBounds();

    final int imageWidthToUse = cubicCurveBounds.width + LINK_IMAGE_PADDING_FOR_WIRE_RADIUS;
    //      int imageHeightToUse = cubicCurveBounds.height + WIRE_DIP_PIXELS;
    int imageHeightToUse = cubicCurveBounds.height;
    // If the wire is close to vertical (little Y difference) we make the image a little bigger to account for the wire "dip"
    if (Math.abs(sinkPoint.y - sourcePoint.y) <= WIRE_DIP_PIXELS) {
        imageHeightToUse += (WIRE_DIP_PIXELS / 2);
    }

    //      bufferedImage = new BufferedImage( imageWidthToUse, imageHeightToUse, BufferedImage.TYPE_INT_ARGB );
    try {
        tiledBufferedImage = bufferImageAllocationService.allocateBufferedImage(allocationSource,
                allocationMatchToUse, AllocationLifetime.SHORT, AllocationBufferType.TYPE_INT_ARGB,
                imageWidthToUse, imageHeightToUse);

        bufferedImage = tiledBufferedImage.getUnderlyingBufferedImage();
        final Graphics2D g2d = bufferedImage.createGraphics();

        g2d.setComposite(AlphaComposite.Clear);
        g2d.fillRect(0, 0, imageWidthToUse, imageHeightToUse);

        g2d.setComposite(AlphaComposite.SrcOver);

        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        f1 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f2 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;
        f3 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f4 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;
        f5 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f6 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;
        f7 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.x;
        f8 += LINK_IMAGE_DIST_TO_CENTER - cubicCurveBounds.y;

        final CubicCurve2D offSetCubicCurve = new CubicCurve2D.Float(f1, f2, f3, f4, f5, f6, f7, f8);

        // Draw the highlight and shadow
        if (DRAW_HIGHTLIGHT_AND_SHADOW) {
            final Graphics2D sG2d = (Graphics2D) g2d.create();
            sG2d.translate(WIRE_SHADOW_X_OFFSET, WIRE_SHADOW_Y_OFFSET);
            sG2d.setColor(Color.BLUE.darker());
            sG2d.setStroke(new BasicStroke(WIRE_SHADOW_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            sG2d.draw(offSetCubicCurve);

            final Graphics2D hG2d = (Graphics2D) g2d.create();
            hG2d.translate(WIRE_HIGHLIGHT_X_OFFSET, WIRE_HIGHLIGHT_Y_OFFSET);
            hG2d.setColor(Color.WHITE);
            hG2d.setStroke(
                    new BasicStroke(WIRE_HIGHLIGHT_WIDTH, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
            hG2d.draw(offSetCubicCurve);
        }

        g2d.setColor(Color.BLACK);
        g2d.setStroke(wireStroke);
        g2d.draw(offSetCubicCurve);

        g2d.setColor(Color.BLUE);
        g2d.setStroke(wireBodyStroke);
        g2d.draw(offSetCubicCurve);

        // For debugging, draw a green line around the outside of this image.
        if (DRAW_WIRE_BOUNDING_BOX) {
            g2d.setStroke(basicStrokeOfOne);
            g2d.setColor(Color.GREEN);
            g2d.drawRect(0, 0, imageWidthToUse - 1, imageHeightToUse - 1);
        }

        rectangle.x = cubicCurveBounds.x - LINK_IMAGE_DIST_TO_CENTER;
        rectangle.y = cubicCurveBounds.y - LINK_IMAGE_DIST_TO_CENTER;
        rectangle.width = imageWidthToUse;
        rectangle.height = imageHeightToUse;
    } catch (final Exception e) {
        final String msg = "Exception caught allocating buffered image: " + e.toString();
        log.error(msg, e);
    }
}

From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java

@Override
public void renderCellLD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY,
        int cellWidth, int cellHeight) {
    if (v == null || v.isNaN()) {
        //System.out.println(v);
        _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight);
    } else {/*from   w  ww  .ja va  2  s. c o  m*/
        try {
            g2D.setColor(UI.colorBlack2);
            g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight);
            g2D.setColor(barColorNormal);
            g2D.setStroke(UI.stroke1_5);

            //This is the 
            //int height = (int)Math.round(cellHeight * (v - _minValue)/(_maxValue - _minValue));
            //g2D.fillRect(Math.round(anchorX), Math.round(anchorY + cellHeight - height), Math.round(cellWidth), Math.round(cellHeight));
            if (rowNode.isSingleNode() && columnNode.isSingleNode()) {

                double value = (v - _minValue) / (_maxValue - _minValue);

                if (v >= disectBound) {
                    g2D.setColor(barColorNormal);
                } else {
                    g2D.setColor(barColorBelow);
                }

                g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * value),
                        (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * value));
            } else {

                //                    double min = percentile.evaluate(valueArray, 0);
                //                    double max = percentile.evaluate(valueArray, 100)
                double fiveVal[] = boxPlotValues(getCoolMapObject(), rowNode, columnNode);
                if (fiveVal == null) {
                    g2D.setColor(UI.colorBlack1);
                    g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth),
                            Math.round(cellHeight));
                }

                double range = _maxValue - _minValue;
                double minP = (fiveVal[0] - _minValue) / range;
                double maxP = (fiveVal[4] - _minValue) / range;
                double medianP = (fiveVal[2] - _minValue) / range;
                double q1P = (fiveVal[1] - _minValue) / range;
                double q3P = (fiveVal[3] - _minValue) / range;

                try {
                    //                        if (cellWidth >= 2 && cellHeight >= 2) {
                    g2D.drawLine((int) (anchorX + cellWidth / 2),
                            (int) (anchorY + cellHeight - cellHeight * maxP), (int) (anchorX + cellWidth / 2),
                            (int) (anchorY + cellHeight - cellHeight * minP));

                    if (fiveVal[2] >= disectBound) {
                        g2D.setColor(UI.colorLightGreen4);
                    } else {
                        g2D.setColor(UI.colorOrange2);
                    }

                    g2D.fillRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P),
                            (int) (cellWidth), (int) (cellHeight * (q3P - q1P)));

                    if (fiveVal[2] >= disectBound) {
                        g2D.setColor(barColorNormal);
                    } else {
                        g2D.setColor(barColorBelow);
                    }

                    //                        g2D.setColor(barColorNormal);
                    //g2D.drawRect((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth), (int) (cellHeight * (q3P - q1P)));
                    g2D.drawLine((int) (anchorX), (int) (anchorY + cellHeight - cellHeight * medianP),
                            (int) (anchorX + cellWidth), (int) (anchorY + cellHeight - cellHeight * medianP));
                    //                        } else {
                    //
                    //                            if (fiveVal[2] >= medianP) {
                    //                                g2D.setColor(barColorNormal);
                    //                            } else {
                    //                                g2D.setColor(barColorBelow);
                    //                            }
                    //
                    ////                            System.out.println("painted rect");
                    ////                            System.out.println((int) cellWidth + " " + ((int) cellHeight));
                    //                            g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight);
                    //                        }

                } catch (Exception e) {
                    System.err.println("Boxplot render exception");
                }
            }

            //                if(cellWidth>=4 && cellHeight >=){
            //                    g2D.setColor(UI.colorBlack1);
            //                    g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth), Math.round(cellHeight));
            //                }
        } catch (Exception e) {
        }
    }
}

From source file:coolmap.canvas.datarenderer.renderer.impl.NumberToBoxPlot.java

@Override
public void renderCellSD(Double v, VNode rowNode, VNode columnNode, Graphics2D g2D, int anchorX, int anchorY,
        int cellWidth, int cellHeight) {
    if (v == null || v.isNaN()) {
        //System.out.println(v);
        _markNull(v, rowNode, columnNode, g2D, anchorX, anchorY, cellWidth, cellHeight);
    } else {/*  w  w w.java  2 s  .  c  om*/
        try {
            g2D.setColor(UI.colorBlack2);
            g2D.fillRect((int) anchorX, (int) anchorY, (int) cellWidth, (int) cellHeight);
            g2D.setColor(barColorNormal);

            //                g2D.setStroke(null);
            g2D.setStroke(UI.stroke1_5);

            //This is the 
            //int height = (int)Math.round(cellHeight * (v - _minValue)/(_maxValue - _minValue));
            //g2D.fillRect(Math.round(anchorX), Math.round(anchorY + cellHeight - height), Math.round(cellWidth), Math.round(cellHeight));
            if (rowNode.isSingleNode() && columnNode.isSingleNode()) {

                double medianP = (v - _minValue) / (_maxValue - _minValue);
                if (v >= disectBound) {
                    g2D.setColor(barColorNormal);
                } else {
                    g2D.setColor(barColorBelow);

                }

                g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * medianP),
                        (int) (anchorX + cellWidth - 1), (int) (anchorY + cellHeight - cellHeight * medianP));
            } else {

                //                    double min = percentile.evaluate(valueArray, 0);
                //                    double max = percentile.evaluate(valueArray, 100)
                double fiveVal[] = boxPlotValues(getCoolMapObject(), rowNode, columnNode);
                if (fiveVal == null) {
                    g2D.setColor(UI.colorBlack1);
                    g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth),
                            Math.round(cellHeight));
                }

                double range = _maxValue - _minValue;
                double minP = (fiveVal[0] - _minValue) / range;
                double maxP = (fiveVal[4] - _minValue) / range;
                double medianP = (fiveVal[2] - _minValue) / range;
                double q1P = (fiveVal[1] - _minValue) / range;
                double q3P = (fiveVal[3] - _minValue) / range;

                try {
                    g2D.drawLine((int) (anchorX + cellWidth / 2),
                            (int) (anchorY + cellHeight - cellHeight * maxP), (int) (anchorX + cellWidth / 2),
                            (int) (anchorY + cellHeight - cellHeight * minP));

                    if (fiveVal[2] >= disectBound) {
                        g2D.setColor(UI.colorLightGreen4);
                    } else {
                        g2D.setColor(UI.colorOrange2);
                    }

                    g2D.fillRect((int) (anchorX + cellWidth / 4),
                            (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth / 2),
                            (int) (cellHeight * (q3P - q1P)));

                    if (fiveVal[2] >= disectBound) {
                        g2D.setColor(barColorNormal);
                    } else {
                        g2D.setColor(barColorBelow);
                    }

                    //                        g2D.setColor(barColorNormal);
                    g2D.drawRect((int) (anchorX + cellWidth / 4),
                            (int) (anchorY + cellHeight - cellHeight * q3P), (int) (cellWidth / 2),
                            (int) (cellHeight * (q3P - q1P)));

                    g2D.drawLine((int) (anchorX + 1), (int) (anchorY + cellHeight - cellHeight * medianP),
                            (int) (anchorX + cellWidth - 1),
                            (int) (anchorY + cellHeight - cellHeight * medianP));
                } catch (Exception e) {
                    System.err.println("Boxplot render exception");
                }
            }

            g2D.setColor(UI.colorBlack1);
            g2D.drawRect(Math.round(anchorX), Math.round(anchorY), Math.round(cellWidth),
                    Math.round(cellHeight));
        } catch (Exception e) {
        }
    }
}

From source file:com.t3.client.ui.ChatTypingNotification.java

/**
 * This component is only made visible when there are notifications to be displayed. That means the first couple of
 * IF statements in this method are redundant since paintComponent() will not be called unless the component is
 * visible, and it will only be visible when there are notifications...
 *//*from  ww  w  . ja  v a  2 s. c  o  m*/
@Override
protected void paintComponent(Graphics g) {
    //      System.out.println("Chat panel is painting itself...");
    if (AppPreferences.getTypingNotificationDuration() != 0) {
        LinkedMap<String, Long> chatTypers = TabletopTool.getFrame().getChatNotificationTimers()
                .getChatTypers();
        if (chatTypers == null || chatTypers.isEmpty()) {
            return;
        }
        Boolean showBackground = AppPreferences.getChatNotificationShowBackground();

        Graphics2D statsG = (Graphics2D) g.create();

        Font boldFont = AppStyle.labelFont.deriveFont(Font.BOLD);
        Font font = AppStyle.labelFont;
        FontMetrics valueFM = g.getFontMetrics(font);
        FontMetrics keyFM = g.getFontMetrics(boldFont);

        int PADDING7 = 7;
        int PADDING3 = 3;
        int PADDING2 = 2;

        BufferedImage img = AppStyle.panelTexture;
        int rowHeight = Math.max(valueFM.getHeight(), keyFM.getHeight());

        setBorder(null);
        int width = AppStyle.miniMapBorder.getRightMargin() + AppStyle.miniMapBorder.getLeftMargin();
        int height = getHeight() - PADDING2 + AppStyle.miniMapBorder.getTopMargin()
                + AppStyle.miniMapBorder.getBottomMargin();

        statsG.setFont(font);
        SwingUtil.useAntiAliasing(statsG);
        Rectangle bounds = new Rectangle(AppStyle.miniMapBorder.getLeftMargin(),
                height - getHeight() - AppStyle.miniMapBorder.getTopMargin(), getWidth() - width,
                getHeight() - AppStyle.miniMapBorder.getBottomMargin() - AppStyle.miniMapBorder.getTopMargin()
                        + PADDING2);

        int y = bounds.y + rowHeight;
        rowHeight = Math.max(rowHeight, AppStyle.chatImage.getHeight());

        setSize(getWidth(), ((chatTypers.size() * (PADDING3 + rowHeight))
                + AppStyle.miniMapBorder.getTopMargin() + AppStyle.miniMapBorder.getBottomMargin()));

        if (showBackground) {
            g.drawImage(img, 0, 0, getWidth(), getHeight() + PADDING7, this);
            AppStyle.miniMapBorder.paintAround(statsG, bounds);
        }
        Rectangle rightRow = new Rectangle(AppStyle.miniMapBorder.getLeftMargin() + PADDING7,
                AppStyle.miniMapBorder.getTopMargin() + PADDING7, AppStyle.chatImage.getWidth(),
                AppStyle.chatImage.getHeight());

        Set<?> keySet = chatTypers.keySet();
        @SuppressWarnings("unchecked")
        Set<String> playerTimers = (Set<String>) keySet;
        Color c1 = new Color(249, 241, 230, 140);
        Color c2 = new Color(175, 163, 149);
        for (String playerNamer : playerTimers) {
            if (showBackground) {
                statsG.setColor(c1);
                statsG.fillRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                        (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
                statsG.setColor(c2);
                statsG.drawRect(bounds.x + PADDING3, y - keyFM.getAscent(),
                        (bounds.width - PADDING7 / 2) - PADDING3, rowHeight);
            }
            g.drawImage(AppStyle.chatImage, bounds.x + 5, y - keyFM.getAscent(), (int) rightRow.getWidth(),
                    (int) rightRow.getHeight(), this);

            // Values
            statsG.setColor(TabletopTool.getFrame().getChatTypingLabelColor());
            statsG.setFont(boldFont);
            statsG.drawString(I18N.getText("msg.commandPanel.liveTyping", playerNamer),
                    bounds.x + AppStyle.chatImage.getWidth() + PADDING7 * 2, y + 5);

            y += PADDING2 + rowHeight;
        }
        if (showBackground) {
            AppStyle.shadowBorder.paintWithin(statsG, bounds);
        } else {
            setOpaque(false);
        }
    }
}

From source file:org.tsho.dmc2.core.chart.TrajectoryRenderer.java

public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) {
    ValueAxis domainAxis = plot.getDomainAxis();
    ValueAxis rangeAxis = plot.getRangeAxis();

    Stroke stroke = new BasicStroke(7f);
    Stroke origStroke = g2.getStroke();
    Color color = Color.BLACK;

    /* transients */
    if (!continua) {
        stepper.initialize();/* www  .  j  a  v  a  2s .  c  o  m*/

        state = STATE_TRANSIENTS;

        try {
            for (index = 0; index < transients; index++) {
                stepper.step();
                if (stopped) {
                    state = STATE_STOPPED;
                    return;
                }
            }
        } catch (RuntimeException re) {
            throw new RuntimeException(re);
        }

        index = 0;
        prevX = 0;
        prevY = 0;
    }

    state = STATE_POINTS;

    Stepper.Point2D point;
    double[] fullPoint = new double[dataset.getNcol()];
    dataset.clearRows();
    int x, y;
    int start = index;
    int end = 0;
    if (index == 0) {
        end = start + iterations + 1;
    } else {
        end = start + iterations;
    }

    for (; index < end; index++) {
        point = stepper.getCurrentPoint2D();
        stepper.getCurrentValue(fullPoint);
        try {
            dataset.addRow((double[]) fullPoint.clone());
        } catch (DatasetException e) {
            System.err.println(e);
        }

        if (!timePlot) {
            x = (int) domainAxis.valueToJava2D(point.getX(), dataArea, RectangleEdge.BOTTOM);
        } else {
            x = (int) domainAxis.valueToJava2D(index + transients, dataArea, RectangleEdge.BOTTOM);
        }

        y = (int) rangeAxis.valueToJava2D(point.getY(), dataArea, RectangleEdge.LEFT);

        if (Double.isNaN(point.getX()) || Double.isNaN(point.getY())) {
            System.err.println("NaN values at iteration " + index);
            //FIXME
            //Don't simply throw exception: that would mess up the state machine!
            //throw new RuntimeException("NaN values at iteration " + index);
        }

        if (delay > 0) {
            boolean flag = false;

            try {
                Thread.sleep(delay * 5);

                drawItem(g2, index, x, y);

                g2.setXORMode(color);
                g2.setStroke(stroke);
                g2.drawRect(x - 1, y - 1, 3, 3);

                flag = true;

                Thread.sleep(delay * 5);
            } catch (final InterruptedException e) {
            }

            if (flag) {
                g2.drawRect(x - 1, y - 1, 3, 3);
                g2.setPaintMode();
                g2.setStroke(origStroke);
            } else {
                drawItem(g2, index, x, y);
            }
        } else {
            drawItem(g2, index, x, y);
        }

        try {
            stepper.step();
        } catch (RuntimeException re) {
            throw new RuntimeException(re);
        }

        if (stopped) {
            state = STATE_STOPPED;
            return;
        }
    }

    state = STATE_FINISHED;
}

From source file:org.cruk.mga.CreateReport.java

/**
 * Draws the x-axis for the number of sequences and the legend.
 *
 * @param g2/*  ww  w.j  av a 2 s .co m*/
 * @param x0
 * @param y
 * @param tickIntervals
 * @param maxSequenceCount
 * @return
 */
private int drawAxisAndLegend(Graphics2D g2, int x0, int y, int tickIntervals, long maxSequenceCount) {
    g2.setColor(Color.BLACK);
    g2.setFont(axisFont);

    boolean millions = maxSequenceCount / tickIntervals >= 1000000;
    long largestTickValue = maxSequenceCount;
    if (millions)
        largestTickValue /= 1000000;
    int w = g2.getFontMetrics().stringWidth(Long.toString(largestTickValue));
    int x1 = plotWidth - (w / 2) - gapSize;
    g2.drawLine(x0, y, x1, y);

    int tickFontHeight = g2.getFontMetrics().getAscent();
    int tickHeight = tickFontHeight / 2;
    for (int i = 0; i <= tickIntervals; i++) {
        int x = x0 + i * (x1 - x0) / tickIntervals;
        g2.drawLine(x, y, x, y + tickHeight);
        long tickValue = i * maxSequenceCount / tickIntervals;
        if (millions)
            tickValue /= 1000000;
        String s = Long.toString(tickValue);
        int xs = x - g2.getFontMetrics().stringWidth(s) / 2 + 1;
        int ys = y + tickHeight + tickFontHeight + 1;
        g2.drawString(s, xs, ys);
    }

    g2.setFont(font);
    int fontHeight = g2.getFontMetrics().getAscent();
    String s = "Number of sequences";
    if (millions)
        s += " (millions)";
    int xs = x0 + (x1 - x0 - g2.getFontMetrics().stringWidth(s)) / 2;
    int ys = y + tickHeight + tickFontHeight + fontHeight + fontHeight / 3;
    g2.drawString(s, xs, ys);

    int yl = ys + fontHeight * 2;
    int xl = x0;

    int barHeight = (int) (fontHeight * 0.7f);
    int barWidth = 3 * barHeight;
    int yb = yl + (int) (fontHeight * 0.3f);
    int gap = (int) (fontHeight * 0.4f);

    g2.setColor(Color.GREEN);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    g2.setFont(axisFont);
    String label = "Sequenced species/genome";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(Color.ORANGE);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Control";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(Color.RED);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Contaminant";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(ADAPTER_COLOR);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Adapter";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Unmapped";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);
    xl += g2.getFontMetrics().stringWidth(label) + gap * 3;

    g2.setColor(Color.GRAY);
    g2.fillRect(xl, yb, barWidth, barHeight);
    g2.setColor(Color.BLACK);
    g2.drawRect(xl, yb, barWidth, barHeight);
    label = "Unknown";
    xl += barWidth + gap;
    g2.drawString(label, xl, yl + fontHeight);

    return x1;
}

From source file:it.unibo.alchemist.boundary.gui.effects.DrawShape.java

@SuppressFBWarnings("ES_COMPARING_STRINGS_WITH_EQ")
@Override//from www .j  a v a 2  s .c om
public void apply(final Graphics2D g, final Node<?> n, final int x, final int y) {
    if (molString != molStringCached // NOPMD: pointer comparison is wanted here
            || incarnation == null || curIncarnation != prevIncarnation) { // NOPMD: pointer comparison is wanted here
        molStringCached = molString;
        prevIncarnation = curIncarnation;
        incarnation = SupportedIncarnations.get(curIncarnation.getCurrent()).get();
        /*
         * Process in a separate thread: if it fails, does not kill EDT.
         */
        final Thread th = new Thread(() -> molecule = incarnation.createMolecule(molString));
        th.start();
        try {
            th.join();
        } catch (final InterruptedException e) {
            L.error("Bug.", e);
        }
    }
    if (!molFilter || (molecule != null && n.contains(molecule))) {
        final double ks = (scaleFactor.getVal() - MIN_SCALE) * 2 / (double) (SCALE_DIFF);
        final int sizex = size.getVal();
        final int startx = x - sizex / 2;
        final int sizey = (int) Math.ceil(sizex * ks);
        final int starty = y - sizey / 2;
        final Color toRestore = g.getColor();
        colorCache = new Color(red.getVal(), green.getVal(), blue.getVal(), alpha.getVal());
        Color newcolor = colorCache;
        if (molPropertyFilter && molecule != null) {
            final int minV = (int) (minprop.getVal() * FastMath.pow(PROPERTY_SCALE, propoom.getVal()));
            final int maxV = (int) (maxprop.getVal() * FastMath.pow(PROPERTY_SCALE, propoom.getVal()));
            if (minV < maxV) {
                @SuppressWarnings({ "rawtypes", "unchecked" })
                double propval = incarnation.getProperty((Node) n, molecule, property);
                if (isWritingPropertyValue()) {
                    g.setColor(colorCache);
                    g.drawString(Double.toString(propval), startx + sizex, starty + sizey);
                }
                propval = Math.min(Math.max(propval, minV), maxV);
                propval = (propval - minV) / (maxV - minV);
                if (reverse) {
                    propval = 1f - propval;
                }
                newcolor = c.alter(newcolor, (float) propval);
            }
        }
        g.setColor(newcolor);
        switch (mode) {
        case FillEllipse:
            g.fillOval(startx, starty, sizex, sizey);
            break;
        case DrawEllipse:
            g.drawOval(startx, starty, sizex, sizey);
            break;
        case DrawRectangle:
            g.drawRect(startx, starty, sizex, sizey);
            break;
        case FillRectangle:
            g.fillRect(startx, starty, sizex, sizey);
            break;
        default:
            g.fillOval(startx, starty, sizex, sizey);
        }
        g.setColor(toRestore);
    }
}

From source file:org.clipsmonitor.core.MonitorGenMap.java

/**
 * Metodo per il disegno della scena utilizzando i valori in stringhe della
 * mappa.le mappe sono di due tipologie per cui devono essere riempite in
 * maniera distinta. Per prima cosa viene eseguito il controllo su quale
 * matrice bisogna costruire.//from   www .ja v  a 2  s  .  c  om
 *
 * @param g : per effettuare il draw del pannello
 * @param MapWidth : larghezza in pixel del pannello della mappa
 * @param MapHeight : altezza in pixel del pannello della mappa
 */
public void drawScene(Graphics2D g, float MapWidth, float MapHeight) {

    BufferedImage[][] icons = makeIconMatrix();

    //aggiorno le dimensioni della finestra
    MapWidth = MapWidth;
    MapHeight = MapHeight;

    //calcolo la larghezza delle celle
    CellWidth = (MapWidth - 20) / NumCellX;
    CellHeight = (MapHeight - 20) / NumCellY;

    //verifico chi delle due dimensioni  minore e setto quella maggiore uguale a quella minore
    // per rendere le celle quadrate
    if (CellWidth > CellHeight) {
        CellWidth = CellHeight;
    } else {
        CellHeight = CellWidth;
    }

    //calcolo le coordinate di inizio della scena partendo a disegnare
    //dall'angolo in alto a sinistra della nostra scena
    float x0 = (MapWidth - CellWidth * NumCellX) / 2;
    float y0 = (MapHeight - CellHeight * NumCellY) / 2;

    //setto colore delle scritte
    g.setColor(Color.BLACK);

    //doppio ciclo sulla matrice
    for (int i = 0; i < NumCellX; i++) {
        for (int j = 0; j < NumCellY; j++) {
            //calcolo la posizione x,y dell'angolo in alto a sinistra della
            //cella corrente
            int x = (int) (x0 + i * CellWidth);
            int y = (int) (y0 + j * CellHeight);
            //se la cella non  vuota, allora disegno l'immagine corrispondente
            if (!scene[i][j].equals("")) {
                //disegno l'immagine corretta usando la stringa che definisce la chiave per l'hashmap
                g.drawImage(icons[i][j], x, y, (int) (CellWidth - 1), (int) (CellHeight - 1), null);
            }

            //traccio il rettangolo della cella
            g.drawRect(x, y, (int) (CellWidth - 1), (int) (CellHeight - 1));
        }
    }
}