Example usage for java.awt Graphics2D fillRoundRect

List of usage examples for java.awt Graphics2D fillRoundRect

Introduction

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

Prototype

public abstract void fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight);

Source Link

Document

Fills the specified rounded corner rectangle with the current color.

Usage

From source file:org.squidy.designer.components.versioning.Versioning.java

@Override
protected void paintShape(PPaintContext paintContext) {
    super.paintShape(paintContext);

    Graphics2D g = paintContext.getGraphics();

    PBounds bounds = getBoundsReference();
    double x = bounds.getX();
    double y = bounds.getY();
    double width = bounds.getWidth();
    double height = bounds.getHeight();

    //      g.setColor(Color.RED);
    //      g.draw(bounds);

    g.setClip(bounds);/*from  w ww  .  j av  a  2 s. co  m*/

    for (int i = 0; i < 7; i++) {
        PAffineTransform transform = new PAffineTransform();
        transform.scale(0.12, 0.12);
        transform.translate(i * 122, 0);

        paintContext.pushTransform(transform);

        if (!isRenderPrimitive()) {
            versionNode.fullPaint(paintContext);
        }

        if (i == 6) {
            g.setStroke(StrokeUtils.getBasicStroke(5f));
            g.setColor(Color.GRAY);
            if (isRenderPrimitiveRect())
                g.drawRect((int) x, (int) y, 100, (int) (height / 0.12));
            else
                g.drawRoundRect((int) x, (int) y, 100, (int) (height / 0.12), 15, 15);

            g.setColor(COLOR_FILL);
            if (isRenderPrimitiveRect())
                g.fillRect((int) x, (int) y, 100, (int) (height / 0.12));
            else
                g.fillRoundRect((int) x, (int) y, 100, (int) (height / 0.12), 15, 15);
        }

        paintContext.popTransform(transform);
    }

    g.setClip(null);
}

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

private void updateGradient() {
    //        System.out.println("Gradient updated..");
    _gradient.reset();/*from w w  w  .j  a  v  a 2s.  c o  m*/
    for (int i = 0; i < editor.getNumPoints(); i++) {
        Color c = editor.getColorAt(i);
        float p = editor.getColorPositionAt(i);

        if (c == null || p < 0 || p > 1) {
            continue;
        }

        _gradient.addColor(c, p);
    }

    _gradientColors = _gradient.generateGradient(CImageGradient.InterType.Linear);

    int width = DEFAULT_LEGEND_WIDTH;
    int height = DEFAULT_LEGENT_HEIGHT;
    legend = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getDefaultConfiguration().createCompatibleImage(width, height, Transparency.TRANSLUCENT);
    Graphics2D g = (Graphics2D) legend.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    LinearGradientPaint paint = editor.getLinearGradientPaint(0, 0, width, 0);

    g.setPaint(paint);
    g.fillRoundRect(0, 0, width, height - 12, 5, 5);

    g.setColor(UI.colorBlack2);
    g.setFont(UI.fontMono.deriveFont(10f));
    DecimalFormat format = new DecimalFormat("#.##");
    g.drawString(format.format(_minValue), 2, 23);

    String maxString = format.format(_maxValue);
    int swidth = g.getFontMetrics().stringWidth(maxString);
    g.drawString(maxString, width - 2 - swidth, 23);
    g.dispose();

    //        System.out.println("===Gradient updated===" + _gradientColors + " " + this);
}

From source file:com.quinsoft.zeidon.objectbrowser.EntitySquare.java

@Override
public void paint(Graphics g) {
    Graphics2D graphics2 = (Graphics2D) g;
    EntityDef entityDef = getEntityDef();
    EntityCursor cursor = getView().cursor(entityDef);

    Color borderColor = Color.black;
    BasicStroke stroke = new BasicStroke(1);
    EntitySquare selectedSquare = oiDisplay.getSelectedEntity();
    if (selectedSquare != null) {
        EntityDef selectedEntityDef = selectedSquare.getEntityDef();
        if (selectedEntityDef.getRecursiveChild() == entityDef
                || selectedEntityDef.getRecursiveParent() == entityDef) {
            borderColor = Color.yellow;
            stroke = new BasicStroke(5);
            oiDisplay.setForRepaint(this);
        }//from   w  w  w.j  a  va2 s  .  c o  m
    }

    if (selectedSquare == this)
        g.setColor(SELECTED_COLOR);
    else {
        switch (cursor.getStatus()) {
        case NULL:
            g.setColor(NULL_ENTITY);
            break;

        case OUT_OF_SCOPE:
            g.setColor(OUT_OF_SCOPE);
            break;

        case NOT_LOADED:
            g.setColor(NOT_LOADED);
            break;

        default:
            g.setColor(ENTITY_EXISTS);
        }
    }

    // Fill in the shape.
    graphics2.fillRoundRect(0, 0, size.width - 1, size.height - 1, 20, 20);

    // Draw the black outline.
    g.setColor(borderColor);
    RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, size.width - 1, size.height - 1, 20,
            20);
    graphics2.setStroke(stroke);
    graphics2.draw(roundedRectangle);

    // Write the entity name
    g.setColor(Color.black);
    graphics2.setFont(font);
    paintCenteredText(graphics2, env.getPainterScaleFactor(), entityDef.getName(), null);

    switch (cursor.getStatus()) {
    case NULL:
        paintCenteredText(graphics2, size.height / 2, "null", Color.WHITE);
        setToolTipText(cursor);
        break;

    case NOT_LOADED:
        paintCenteredText(graphics2, size.height / 2, "(Not yet loaded)", Color.WHITE);
        setToolTipText(entityDef.getName());
        break;

    case OUT_OF_SCOPE:
        paintCenteredText(graphics2, size.height / 2, "(Out of Scope)", Color.WHITE);
        setToolTipText(entityDef.getName());
        break;

    default:
        String s = getKeyString(cursor, entityDef, env);
        paintCenteredText(graphics2, size.height / 2, s, null);

        s = getSiblingCount(cursor);
        paintCenteredText(graphics2, size.height - env.getPainterScaleFactor(), s, null);
        setToolTipText(cursor);
    }

}

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

@Override
public void renderCellHD(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 .j a v  a 2 s . c om*/
        try {
            int index = (int) ((v - _minValue) / (_maxValue - _minValue) * _gradientColors.length);
            if (index >= _gradientColors.length) {
                index = _gradientColors.length - 1;
            }
            if (index < 0) {
                index = 0;
            }
            Color c = _gradientColors[index];
            //System.out.println(c);
            g2D.setColor(c);
            //                System.out.println((int) cellWidth + " " + ((int) cellHeight)) ;
            g2D.fillRoundRect((int) anchorX + 1, (int) anchorY + 1, (int) cellWidth - 2, (int) cellHeight - 2,
                    4, 4);

            if (drawSubMap.isSelected()) {
                //paint the sub heatmap block

                //                    System.out.println("draw submap");
                if (rowNode == null || columnNode == null
                        || rowNode.isSingleNode() && columnNode.isSingleNode()) {
                    return;
                } else {

                    g2D.setStroke(UI.strokeDash1_5);
                    //need to determine the number of cMatrices
                    CoolMapObject object = getCoolMapObject();
                    List<CMatrix> matrices = object.getBaseCMatrices();
                    Double value;

                    //row and column indices
                    Integer[] rowIndices;
                    Integer[] colIndices;

                    //whether they are group node or node
                    if (rowNode.isGroupNode()) {
                        rowIndices = rowNode.getBaseIndicesFromCOntology(
                                (CMatrix) object.getBaseCMatrices().get(0), COntology.ROW);
                    } else {
                        rowIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0))
                                .getIndexOfRowName(rowNode.getName()) };
                    }
                    if (columnNode.isGroupNode()) {
                        colIndices = columnNode.getBaseIndicesFromCOntology(
                                (CMatrix) object.getBaseCMatrices().get(0), COntology.COLUMN);
                    } else {
                        colIndices = new Integer[] { ((CMatrix) object.getBaseCMatrices().get(0))
                                .getIndexOfColName(columnNode.getName()) };
                    }

                    //then determine the width
                    int subMatrixWidth = Math.round(cellWidth * 1.0f / matrices.size());

                    int subAnchorX = anchorX;

                    int subCellHeight = Math.round(cellHeight * 1.0f / rowIndices.length);
                    int subCellWidth = Math.round(subMatrixWidth * 1.0f / colIndices.length);

                    //                        System.out.println("CW:" + cellWidth + " " + colIndices.length + " " + subCellWidth);
                    //                        System.out.println("CH:" + cellHeight + " " + rowIndices.length + " " + subCellHeight);
                    if (subCellHeight < 1) {
                        subCellHeight = 1;
                    }
                    if (subCellWidth < 1) {
                        subCellWidth = 1;
                    }

                    int matrixIndex = 0;
                    for (CMatrix matrix : matrices) {

                        int rowIndex = 0;
                        for (Integer i : rowIndices) {
                            if (i == null || i < 0) {
                                continue;
                            }
                            int columnIndex = 0;
                            for (Integer j : colIndices) {
                                if (j == null || j < 0) {
                                    continue;
                                }
                                try {

                                    value = (Double) matrix.getValue(i, j);
                                    index = (int) ((value - _minValue) / (_maxValue - _minValue)
                                            * _gradientColors.length);
                                    if (index >= _gradientColors.length) {
                                        index = _gradientColors.length - 1;
                                    }
                                    if (index < 0) {
                                        index = 0;
                                    }
                                    c = _gradientColors[index];

                                    g2D.setColor(c);

                                    int subCellX = Math
                                            .round(subMatrixWidth * 1.0f * columnIndex / colIndices.length)
                                            + subAnchorX;
                                    int subCellY = Math.round(cellHeight * 1.0f * rowIndex / rowIndices.length)
                                            + anchorY;

                                    //                                        System.out.println("WTF:" + columnIndex + " " + rowIndex + "----" + subCellX + " " + subCellY + " " + subCellWidth + " " + subCellHeight);
                                    g2D.fillRect(subCellX, subCellY, subCellWidth, subCellHeight);

                                } catch (Exception e) {
                                    //draw it here
                                    e.printStackTrace();
                                }

                                columnIndex++;
                            } //end of column loop

                            rowIndex++;
                        } //end of row loop

                        g2D.setColor(UI.colorBlack1);
                        g2D.drawRect(subAnchorX, anchorY, subMatrixWidth, cellHeight);

                        //
                        //                            subAnchorX += subMatrixWidth;
                        matrixIndex++;
                        subAnchorX = anchorX + Math.round(cellWidth * 1.0f * matrixIndex / matrices.size());
                    } //end of matrix loop

                    g2D.setStroke(UI.stroke2);
                    g2D.setColor(Color.BLACK);
                    g2D.drawRect(anchorX, anchorY, cellWidth, cellHeight);
                }
            }

        } catch (Exception e) {
            //                System.out.println("Null pointer exception:" + v + "," + _minValue + "," + _maxValue + "," + _gradientColors + " " + getName() + "" + this);
            //e.printStackTrace();

        }
    }
}

From source file:edu.ku.brc.ui.UIRegistry.java

/**
 * Writes a string message into the BufferedImage on GlassPane and sets the main component's visibility to false and
 * shows the GlassPane.//from   w  w  w  .  j  a  va  2  s .  co  m
 * @param msg the message
 * @param pointSize the Font point size for the message to be writen in
 */
public static GhostGlassPane writeGlassPaneMsg(final String msg, final int pointSize) {
    GhostGlassPane glassPane = getGlassPane();
    if (glassPane != null) {
        glassPane.finishDnD();
    }

    glassPane.setMaskingEvents(true);

    Component mainComp = get(MAINPANE);
    if (mainComp != null && glassPane != null) {
        JFrame frame = (JFrame) get(FRAME);
        frameRect = frame.getBounds();

        int y = 0;
        JMenuBar menuBar = null;
        Dimension size = mainComp.getSize();
        if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
            menuBar = frame.getJMenuBar();
            size.height += menuBar.getSize().height;
            y += menuBar.getSize().height;
        }
        BufferedImage buffer = getGlassPaneBufferedImage(size.width, size.height);
        Graphics2D g2 = buffer.createGraphics();
        if (menuBar != null) {
            menuBar.paint(g2);
        }
        g2.translate(0, y);
        mainComp.paint(g2);
        g2.translate(0, -y);

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(new Color(255, 255, 255, 128));
        g2.fillRect(0, 0, size.width, size.height);

        g2.setFont(new Font((new JLabel()).getFont().getName(), Font.BOLD, pointSize));
        FontMetrics fm = g2.getFontMetrics();

        int tw = fm.stringWidth(msg);
        int th = fm.getHeight();
        int tx = (size.width - tw) / 2;
        int ty = (size.height - th) / 2;

        int expand = 20;
        int arc = expand * 2;
        g2.setColor(Color.WHITE);
        g2.fillRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc,
                arc);

        g2.setColor(Color.DARK_GRAY);
        g2.drawRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc,
                arc);

        g2.setColor(Color.BLACK);
        g2.drawString(msg, tx, ty);
        g2.dispose();

        glassPane.setImage(buffer);
        glassPane.setPoint(new Point(0, 0), GhostGlassPane.ImagePaintMode.ABSOLUTE);
        glassPane.setOffset(new Point(0, 0));

        glassPane.setVisible(true);
        mainComp.setVisible(false);

        //Using paintImmediately fixes problems with glass pane not showing, such as for workbench saves initialed
        //during workbench or app shutdown. Don't know if there is a better way to fix it.
        //glassPane.repaint();
        glassPane.paintImmediately(glassPane.getBounds());
        showingGlassPane = true;
    }

    return glassPane;
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void drawInformationBox(Graphics2D g2, Activities activities, Rectangle2D rect, List<String> params,
        List<String> values, String totalParam, double totalValue, Color background_color, Color border_color) {
    final Font oldFont = g2.getFont();
    final Font paramFont = oldFont;
    final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont);
    final Font valueFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() + 1);
    final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont);
    final Font dateFont = oldFont.deriveFont((float) oldFont.getSize() - 1);
    final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont);

    final int x = (int) rect.getX();
    final int y = (int) rect.getY();
    final int width = (int) rect.getWidth();
    final int height = (int) rect.getHeight();

    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Composite oldComposite = g2.getComposite();
    final Color oldColor = g2.getColor();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(border_color);// w w  w. j  a v a2s .co m
    g2.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 15, 15);
    g2.setColor(background_color);
    g2.setComposite(Utils.makeComposite(0.75f));
    g2.fillRoundRect(x, y, width, height, 15, 15);
    g2.setComposite(oldComposite);
    g2.setColor(oldColor);

    final Date date = activities.getDate().getTime();
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy");
    final String dateString = simpleDateFormat.format(date);

    final int padding = 5;

    int yy = y + padding + dateFontMetrics.getAscent();
    g2.setFont(dateFont);
    g2.setColor(COLOR_BLUE);
    g2.drawString(dateString, ((width - dateFontMetrics.stringWidth(dateString)) >> 1) + x, yy);

    int index = 0;
    final int dateInfoHeightMargin = 5;
    final int infoTotalHeightMargin = 5;
    final int paramValueHeightMargin = 0;

    yy += dateFontMetrics.getDescent() + dateInfoHeightMargin
            + Math.max(paramFontMetrics.getAscent(), valueFontMetrics.getAscent());
    for (String param : params) {
        final String value = values.get(index++);
        g2.setColor(Color.BLACK);
        g2.setFont(paramFont);
        g2.drawString(param + ":", padding + x, yy);
        g2.setFont(valueFont);
        g2.drawString(value, width - padding - valueFontMetrics.stringWidth(value) + x, yy);
        // Same as yy += valueFontMetrics.getDescent() + paramValueHeightMargin + valueFontMetrics.getAscent()
        yy += paramValueHeightMargin + Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight());
    }

    if (values.size() > 1) {
        yy -= paramValueHeightMargin;
        yy += infoTotalHeightMargin;
        if (totalValue > 0.0) {
            g2.setColor(JStockOptions.DEFAULT_HIGHER_NUMERICAL_VALUE_FOREGROUND_COLOR);
        } else if (totalValue < 0.0) {
            g2.setColor(JStockOptions.DEFAULT_LOWER_NUMERICAL_VALUE_FOREGROUND_COLOR);
        }

        g2.setFont(paramFont);
        g2.drawString(totalParam + ":", padding + x, yy);
        g2.setFont(valueFont);
        final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace();
        final String totalValueStr = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace,
                totalValue);
        g2.drawString(totalValueStr, width - padding - valueFontMetrics.stringWidth(totalValueStr) + x, yy);
    }

    g2.setColor(oldColor);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    g2.setFont(oldFont);
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private void drawBusyBox(Graphics2D g2, JXLayer<? extends V> layer) {
    final Font oldFont = g2.getFont();
    final Font font = oldFont;
    final FontMetrics fontMetrics = g2.getFontMetrics(font);

    // Not sure why. Draw GIF image on JXLayer, will cause endless setDirty
    // being triggered by system.
    //final Image image = ((ImageIcon)Icons.BUSY).getImage();
    //final int imgWidth = Icons.BUSY.getIconWidth();
    //final int imgHeight = Icons.BUSY.getIconHeight();
    //final int imgMessageWidthMargin = 5;
    final int imgWidth = 0;
    final int imgHeight = 0;
    final int imgMessageWidthMargin = 0;

    final String message = MessagesBundle.getString("info_message_retrieving_latest_stock_price");
    final int maxWidth = imgWidth + imgMessageWidthMargin + fontMetrics.stringWidth(message);
    final int maxHeight = Math.max(imgHeight, fontMetrics.getHeight());

    final int padding = 5;
    final int width = maxWidth + (padding << 1);
    final int height = maxHeight + (padding << 1);
    final int x = (int) this.drawArea.getX() + (((int) this.drawArea.getWidth() - width) >> 1);
    final int y = (int) this.drawArea.getY() + (((int) this.drawArea.getHeight() - height) >> 1);

    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Composite oldComposite = g2.getComposite();
    final Color oldColor = g2.getColor();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(COLOR_BORDER);//  w ww  . j av a2  s.  c o  m
    g2.drawRoundRect(x - 1, y - 1, width + 1, height + 1, 15, 15);
    g2.setColor(COLOR_BACKGROUND);
    g2.setComposite(Utils.makeComposite(0.75f));
    g2.fillRoundRect(x, y, width, height, 15, 15);
    g2.setComposite(oldComposite);
    g2.setColor(oldColor);

    //g2.drawImage(image, x + padding, y + ((height - imgHeight) >> 1), layer.getView());

    g2.setFont(font);
    g2.setColor(COLOR_BLUE);

    int yy = y + ((height - fontMetrics.getHeight()) >> 1) + fontMetrics.getAscent();
    g2.setFont(font);
    g2.setColor(COLOR_BLUE);
    g2.drawString(message, x + padding + imgWidth + imgMessageWidthMargin, yy);
    g2.setColor(oldColor);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    g2.setFont(oldFont);
}

From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java

@Override
public void paintComponent(final Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int x = 0;/*from  ww  w  .ja va  2  s .c  o  m*/
    int y = 0;
    int width = (int) getSize().getWidth();
    int height = (int) getSize().getHeight();

    // draw background depending special roles and hovering
    if (getModel() != null && getModel().isSpecialAtt()) {
        if (Attributes.LABEL_NAME.equals(getModel().getSpecialAttName())) {
            // label special attributes have a distinct color
            g2.setPaint(
                    new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.LABEL_NAME, true, hovered),
                            x, height, getColorForSpecialAttribute(Attributes.LABEL_NAME, false, hovered)));
        } else if (Attributes.WEIGHT_NAME.equals(getModel().getSpecialAttName())) {
            // weight special attributes have another distinct color
            g2.setPaint(
                    new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.WEIGHT_NAME, true, hovered),
                            x, height, getColorForSpecialAttribute(Attributes.WEIGHT_NAME, false, hovered)));
        } else if (Attributes.PREDICTION_NAME.equals(getModel().getSpecialAttName())) {
            // prediction special attributes have another distinct color
            g2.setPaint(new GradientPaint(x, y,
                    getColorForSpecialAttribute(Attributes.PREDICTION_NAME, true, hovered), x, height,
                    getColorForSpecialAttribute(Attributes.PREDICTION_NAME, false, hovered)));
        } else if (getModel().getSpecialAttName().startsWith(Attributes.CONFIDENCE_NAME + "_")) {
            // confidence special attributes have another distinct color
            g2.setPaint(new GradientPaint(x, y,
                    getColorForSpecialAttribute(Attributes.CONFIDENCE_NAME, true, hovered), x, height,
                    getColorForSpecialAttribute(Attributes.CONFIDENCE_NAME, false, hovered)));
        } else if (Attributes.ID_NAME.equals(getModel().getSpecialAttName())) {
            // id special attributes have another distinct color
            g2.setPaint(new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.ID_NAME, true, hovered),
                    x, height, getColorForSpecialAttribute(Attributes.ID_NAME, false, hovered)));
        } else {
            // other special attributes have another color
            g2.setPaint(
                    new GradientPaint(x, y, getColorForSpecialAttribute(GENERIC_SPECIAL_NAME, true, hovered), x,
                            height, getColorForSpecialAttribute(GENERIC_SPECIAL_NAME, false, hovered)));
        }
    } else {
        // regular attributes
        g2.setPaint(
                new GradientPaint(x, y, getColorForSpecialAttribute(Attributes.ATTRIBUTE_NAME, true, hovered),
                        x, height, getColorForSpecialAttribute(Attributes.ATTRIBUTE_NAME, false, hovered)));
    }
    g2.fillRoundRect(x, y, width, height, CORNER_ARC_WIDTH, CORNER_ARC_WIDTH);

    // draw border
    g2.setPaint(new GradientPaint(x, y, COLOR_BORDER_GRADIENT_FIRST, x, height, COLOR_BORDER_GRADIENT_SECOND));
    if (hovered) {
        g2.setStroke(new BasicStroke(1.0f));
    } else {
        g2.setStroke(new BasicStroke(0.5f));
    }
    g2.drawRoundRect(x, y, width - 1, height - 1, CORNER_ARC_WIDTH, CORNER_ARC_WIDTH);

    // let Swing draw its components
    super.paintComponent(g2);
}

From source file:org.yccheok.jstock.gui.charting.ChartLayerUI.java

private void drawInformationBox(Graphics2D g2, JXLayer<? extends V> layer) {
    if (JStock.instance().getJStockOptions()
            .getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Hide) {
        return;//from w  w w  .j a v  a 2 s  .c o  m
    }

    final Font oldFont = g2.getFont();
    final Font paramFont = oldFont;
    final FontMetrics paramFontMetrics = g2.getFontMetrics(paramFont);
    final Font valueFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() + 1);
    final FontMetrics valueFontMetrics = g2.getFontMetrics(valueFont);
    final Font dateFont = oldFont.deriveFont((float) oldFont.getSize() - 1);
    final FontMetrics dateFontMetrics = g2.getFontMetrics(dateFont);

    final List<ChartData> chartDatas = this.chartJDialog.getChartDatas();
    List<String> values = new ArrayList<String>();
    final ChartData chartData = chartDatas.get(this.mainTraceInfo.getDataIndex());

    // Number formats are generally not synchronized. It is recommended to create separate format instances for each thread. 
    // If multiple threads access a format concurrently, it must be synchronized externally.
    // http://stackoverflow.com/questions/2213410/usage-of-decimalformat-for-the-following-case
    final DecimalFormat integerFormat = new DecimalFormat("###,###");

    // It is common to use OHLC for chat, instead of using PrevPrice.        
    values.add(org.yccheok.jstock.gui.Utils.stockPriceDecimalFormat(chartData.openPrice));
    values.add(org.yccheok.jstock.gui.Utils.stockPriceDecimalFormat(chartData.highPrice));
    values.add(org.yccheok.jstock.gui.Utils.stockPriceDecimalFormat(chartData.lowPrice));
    values.add(org.yccheok.jstock.gui.Utils.stockPriceDecimalFormat(chartData.lastPrice));
    values.add(integerFormat.format(chartData.volume));

    final List<String> indicatorParams = new ArrayList<String>();
    final List<String> indicatorValues = new ArrayList<String>();
    final DecimalFormat decimalFormat = new DecimalFormat("0.00");
    for (TraceInfo indicatorTraceInfo : this.indicatorTraceInfos) {
        final int plotIndex = indicatorTraceInfo.getPlotIndex();
        final int seriesIndex = indicatorTraceInfo.getSeriesIndex();
        final int dataIndex = indicatorTraceInfo.getDataIndex();
        final String name = this.getLegendName(plotIndex, seriesIndex);
        final Number value = this.getValue(plotIndex, seriesIndex, dataIndex);
        if (name == null || value == null) {
            continue;
        }
        indicatorParams.add(name);
        indicatorValues.add(decimalFormat.format(value));
    }

    assert (values.size() == params.size());
    int index = 0;
    final int paramValueWidthMargin = 10;
    final int paramValueHeightMargin = 0;
    // Slightly larger than dateInfoHeightMargin, as font for indicator is
    // larger than date's.
    final int infoIndicatorHeightMargin = 8;
    int maxInfoWidth = -1;
    // paramFontMetrics will always "smaller" than valueFontMetrics.
    int totalInfoHeight = Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight()) * values.size()
            + paramValueHeightMargin * (values.size() - 1);
    for (String param : params) {
        final String value = values.get(index++);
        final int paramStringWidth = paramFontMetrics.stringWidth(param + ":") + paramValueWidthMargin
                + valueFontMetrics.stringWidth(value);
        if (maxInfoWidth < paramStringWidth) {
            maxInfoWidth = paramStringWidth;
        }
    }

    if (indicatorValues.size() > 0) {
        totalInfoHeight += infoIndicatorHeightMargin;
        totalInfoHeight += Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight())
                * indicatorValues.size() + paramValueHeightMargin * (indicatorValues.size() - 1);
        index = 0;
        for (String indicatorParam : indicatorParams) {
            final String indicatorValue = indicatorValues.get(index++);
            final int paramStringWidth = paramFontMetrics.stringWidth(indicatorParam + ":")
                    + paramValueWidthMargin + valueFontMetrics.stringWidth(indicatorValue);
            if (maxInfoWidth < paramStringWidth) {
                maxInfoWidth = paramStringWidth;
            }
        }
    }

    final Date date = new Date(chartData.timestamp);

    // Date formats are not synchronized. It is recommended to create separate format instances for each thread.
    // If multiple threads access a format concurrently, it must be synchronized externally.
    final SimpleDateFormat simpleDateFormat = this.simpleDataFormatThreadLocal.get();
    final String dateString = simpleDateFormat.format(date);
    final int dateStringWidth = dateFontMetrics.stringWidth(dateString);
    final int dateStringHeight = dateFontMetrics.getHeight();
    // We want to avoid information box from keep changing its width while
    // user moves along the mouse. This will prevent user from feeling,
    // information box is flickering, which is uncomfortable to user's eye.
    final int maxStringWidth = Math.max(dateFontMetrics.stringWidth(longDateString),
            Math.max(this.maxWidth, Math.max(dateStringWidth, maxInfoWidth)));
    if (maxStringWidth > this.maxWidth) {
        this.maxWidth = maxStringWidth;
    }
    final int dateInfoHeightMargin = 5;
    final int maxStringHeight = dateStringHeight + dateInfoHeightMargin + totalInfoHeight;

    final int padding = 5;
    final int boxPointMargin = 8;
    final int width = maxStringWidth + (padding << 1);
    final int height = maxStringHeight + (padding << 1);

    /* Get Border Rect Information. */
    /*
    fillRect(1, 1, 1, 1);   // O is rect pixel
            
    xxx
    xOx
    xxx
            
    drawRect(0, 0, 2, 2);   // O is rect pixel
            
    OOO
    OxO
    OOO
     */
    final int borderWidth = width + 2;
    final int borderHeight = height + 2;
    // On left side of the ball.
    final double suggestedBorderX = this.mainTraceInfo.getPoint().getX() - borderWidth - boxPointMargin;
    final double suggestedBorderY = this.mainTraceInfo.getPoint().getY() - (borderHeight >> 1);
    double bestBorderX = 0;
    double bestBorderY = 0;
    if (JStock.instance().getJStockOptions()
            .getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Stay) {
        if (this.mainTraceInfo.getPoint()
                .getX() > ((int) (this.mainDrawArea.getX() + this.mainDrawArea.getWidth() + 0.5) >> 1)) {
            bestBorderX = this.mainDrawArea.getX();
            bestBorderY = this.mainDrawArea.getY();
        } else {
            bestBorderX = this.mainDrawArea.getX() + this.mainDrawArea.getWidth() - borderWidth;
            bestBorderY = this.mainDrawArea.getY();
        }
    } else {
        assert (JStock.instance().getJStockOptions()
                .getYellowInformationBoxOption() == JStockOptions.YellowInformationBoxOption.Follow);
        bestBorderX = suggestedBorderX > this.mainDrawArea.getX()
                ? (suggestedBorderX + borderWidth) < (this.mainDrawArea.getX() + this.mainDrawArea.getWidth())
                        ? suggestedBorderX
                        : this.mainDrawArea.getX() + this.mainDrawArea.getWidth() - borderWidth - boxPointMargin
                : this.mainTraceInfo.getPoint().getX() + boxPointMargin;
        bestBorderY = suggestedBorderY > this.mainDrawArea.getY()
                ? (suggestedBorderY + borderHeight) < (this.mainDrawArea.getY() + this.mainDrawArea.getHeight())
                        ? suggestedBorderY
                        : this.mainDrawArea.getY() + this.mainDrawArea.getHeight() - borderHeight
                                - boxPointMargin
                : this.mainDrawArea.getY() + boxPointMargin;
    }

    final double x = bestBorderX + 1;
    final double y = bestBorderY + 1;

    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Composite oldComposite = g2.getComposite();
    final Color oldColor = g2.getColor();

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(COLOR_BORDER);
    g2.drawRoundRect((int) (bestBorderX + 0.5), (int) (bestBorderY + 0.5), borderWidth - 1, borderHeight - 1,
            15, 15);
    g2.setColor(COLOR_BACKGROUND);
    g2.setComposite(Utils.makeComposite(0.75f));
    g2.fillRoundRect((int) (x + 0.5), (int) (y + 0.5), width, height, 15, 15);
    g2.setComposite(oldComposite);
    g2.setColor(oldColor);

    int yy = (int) (y + padding + dateFontMetrics.getAscent() + 0.5);
    g2.setFont(dateFont);
    g2.setColor(COLOR_BLUE);
    g2.drawString(dateString, (int) (((width - dateFontMetrics.stringWidth(dateString)) >> 1) + x + 0.5), yy);

    index = 0;
    yy += dateFontMetrics.getDescent() + dateInfoHeightMargin + valueFontMetrics.getAscent();
    final String CLOSE_STR = GUIBundle.getString("StockHistory_Close");
    for (String param : params) {
        final String value = values.get(index++);
        g2.setColor(Color.BLACK);
        if (param.equals(CLOSE_STR)) {
            // It is common to use OHLC for chat, instead of using PrevPrice.
            final double changePrice = chartData.lastPrice - chartData.openPrice;
            if (changePrice > 0.0) {
                g2.setColor(JStockOptions.DEFAULT_HIGHER_NUMERICAL_VALUE_FOREGROUND_COLOR);
            } else if (changePrice < 0.0) {
                g2.setColor(JStockOptions.DEFAULT_LOWER_NUMERICAL_VALUE_FOREGROUND_COLOR);
            }
        }
        g2.setFont(paramFont);
        g2.drawString(param + ":", (int) (padding + x + 0.5), yy);
        g2.setFont(valueFont);
        g2.drawString(value, (int) (width - padding - valueFontMetrics.stringWidth(value) + x + 0.5), yy);
        // Same as yy += valueFontMetrics.getDescent() + paramValueHeightMargin + valueFontMetrics.getAscent()
        yy += paramValueHeightMargin + valueFontMetrics.getHeight();
    }

    g2.setColor(Color.BLACK);
    yy -= paramValueHeightMargin;
    yy += infoIndicatorHeightMargin;

    index = 0;
    for (String indicatorParam : indicatorParams) {
        final String indicatorValue = indicatorValues.get(index++);
        g2.setFont(paramFont);
        g2.drawString(indicatorParam + ":", (int) (padding + x + 0.5), yy);
        g2.setFont(valueFont);
        g2.drawString(indicatorValue,
                (int) (width - padding - valueFontMetrics.stringWidth(indicatorValue) + x + 0.5), yy);
        // Same as yy += valueFontMetrics.getDescent() + paramValueHeightMargin + valueFontMetrics.getAscent()
        yy += paramValueHeightMargin + valueFontMetrics.getHeight();
    }

    g2.setColor(oldColor);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldValueAntiAlias);
    g2.setFont(oldFont);
}

From source file:lu.fisch.unimozer.Diagram.java

@Override
public void paint(Graphics graphics) {
    super.paint(graphics);
    Graphics2D g = (Graphics2D) graphics;
    // set anti-aliasing rendering
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.setFont(new Font(g.getFont().getFontName(), Font.PLAIN, Unimozer.DRAW_FONT_SIZE));

    // clear background
    g.setColor(Color.WHITE);/*  w  ww  .j a  v a 2 s  .co m*/
    g.fillRect(0, 0, getWidth() + 1, getHeight() + 1);
    g.setColor(Color.BLACK);

    /*Set<String> set;
    Iterator<String> itr;
    // draw classes a first time
    for(MyClass clas : classes.values())
    {
      clas.setEnabled(this.isEnabled());
      clas.draw(graphics,showFields,showMethods);
    }*/

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        MyClass clas = entry.getValue();
        clas.setEnabled(this.isEnabled());
        clas.draw(graphics, showFields, showMethods);
    }

    // draw packages
    packages.clear();
    for (MyClass myClass : classes.values()) {
        if (myClass.isDisplayUML()) {
            Package myPackage = null;
            if (!packages.containsKey(myClass.getPackagename())) {
                myPackage = new Package(myClass.getPackagename(), myClass.getPosition().y,
                        myClass.getPosition().x, myClass.getWidth(), myClass.getHeight());
                packages.put(myPackage.getName(), myPackage);
            } else
                myPackage = packages.get(myClass.getPackagename());

            if (myClass.getPosition().x + myClass.getWidth() > myPackage.getRight())
                myPackage.setRight(myClass.getPosition().x + myClass.getWidth());
            if (myClass.getPosition().y + myClass.getHeight() > myPackage.getBottom())
                myPackage.setBottom(myClass.getPosition().y + myClass.getHeight());

            if (myClass.getPosition().x < myPackage.getLeft())
                myPackage.setLeft(myClass.getPosition().x);
            if (myClass.getPosition().y < myPackage.getTop())
                myPackage.setTop(myClass.getPosition().y);
        }
    }

    // draw classes
    /*
    set = classes.keySet();
    itr = set.iterator();
    while (itr.hasNext())
    {
      String str = itr.next();
      classes.get(str).draw(graphics);
    }/**/

    mostRight = 0;
    mostBottom = 0;

    // ??
    /*
    set = classes.keySet();
    itr = set.iterator();
    while (itr.hasNext())
    {
      String str = itr.next();
      MyClass thisClass = classes.get(str);
    }
    */

    // init topLeft & bottomRight
    topLeft = new Point(this.getWidth(), this.getHeight());
    bottomRight = new Point(0, 0);

    // draw packages
    if (packages.size() > 0)
        if ((packages.size() == 1 && packages.get(Package.DEFAULT) == null) || packages.size() > 1)
            for (Package pack : packages.values()) {
                pack.draw(graphics);
                // push outer box
                if (pack.getTopAbs() < topLeft.y)
                    topLeft.y = pack.getTopAbs();
                if (pack.getLeftAbs() < topLeft.x)
                    topLeft.x = pack.getLeftAbs();
                if (pack.getBottomAbs() > bottomRight.y)
                    bottomRight.y = pack.getBottomAbs();
                if (pack.getRightAbs() > bottomRight.x)
                    bottomRight.x = pack.getRightAbs();
            }

    // draw implmementations
    if (isShowHeritage()) {
        Stroke oldStroke = g.getStroke();
        g.setStroke(dashed);

        /*itr = set.iterator();
        while (itr.hasNext())
        {
          String str = itr.next();
        */

        /* let's try this one ... */
        for (Entry<String, MyClass> entry : classes.entrySet()) {
            // get the actual class ...
            String str = entry.getKey();

            MyClass thisClass = classes.get(str);

            if (thisClass.getPosition().x + thisClass.getWidth() > mostRight)
                mostRight = thisClass.getPosition().x + thisClass.getWidth();
            if (thisClass.getPosition().y + thisClass.getHeight() > mostBottom)
                mostBottom = thisClass.getPosition().y + thisClass.getHeight();

            if (thisClass.getImplements().size() > 0)
                for (String extendsClass : thisClass.getImplements()) {
                    MyClass otherClass = classes.get(extendsClass);
                    if (otherClass == null)
                        otherClass = findByShortName(extendsClass);
                    //if(otherClass==null) System.err.println(extendsClass+" not found (1)");
                    //if (otherClass==null) otherClass=findByShortName(extendsClass);
                    //if(otherClass==null) System.err.println(extendsClass+" not found (2)");
                    if (otherClass != null && thisClass.isDisplayUML() && otherClass.isDisplayUML()) {
                        thisClass.setExtendsMyClass(otherClass);
                        // draw arrow from thisClass to otherClass

                        // get the center point of each class
                        Point fromP = new Point(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y + thisClass.getHeight() / 2);
                        Point toP = new Point(otherClass.getPosition().x + otherClass.getWidth() / 2,
                                otherClass.getPosition().y + otherClass.getHeight() / 2);

                        // get the corner 4 points of the desstination class
                        // (outer margin = 4)
                        Point toP1 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y - 4);
                        Point toP2 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4,
                                otherClass.getPosition().y - 4);
                        Point toP3 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4,
                                otherClass.getPosition().y + otherClass.getHeight() + 4);
                        Point toP4 = new Point(otherClass.getPosition().x - 4,
                                otherClass.getPosition().y + otherClass.getHeight() + 4);

                        // get the intersection with the center line an one of the
                        // sedis of the destination class
                        Point2D toDraw = getIntersection(fromP, toP, toP1, toP2);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP2, toP3);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP3, toP4);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP4, toP1);

                        // draw the arrowed line
                        if (toDraw != null)
                            drawExtends(g, fromP, new Point((int) toDraw.getX(), (int) toDraw.getY()));

                    }
                }

        }
        g.setStroke(oldStroke);
    }

    // draw inheritance
    if (isShowHeritage()) {
        /*itr = set.iterator();
        while (itr.hasNext())
        {
          String str = itr.next();
        */

        /* let's try this one ... */
        for (Entry<String, MyClass> entry : classes.entrySet()) {
            // get the actual class ...
            String str = entry.getKey();

            MyClass thisClass = classes.get(str);

            if (thisClass.getPosition().x + thisClass.getWidth() > mostRight)
                mostRight = thisClass.getPosition().x + thisClass.getWidth();
            if (thisClass.getPosition().y + thisClass.getHeight() > mostBottom)
                mostBottom = thisClass.getPosition().y + thisClass.getHeight();

            String extendsClass = thisClass.getExtendsClass();
            //System.out.println(thisClass.getFullName()+" extends "+extendsClass);
            if (!extendsClass.equals("") && thisClass.isDisplayUML()) {
                MyClass otherClass = classes.get(extendsClass);
                if (otherClass == null)
                    otherClass = findByShortName(extendsClass);
                //if(otherClass==null) System.err.println(extendsClass+" not found (1)");
                //if (otherClass==null) otherClass=findByShortName(extendsClass);
                //if(otherClass==null) System.err.println(extendsClass+" not found (2)");
                if (otherClass != null) {
                    if (otherClass != thisClass) {
                        thisClass.setExtendsMyClass(otherClass);
                        // draw arrow from thisClass to otherClass

                        // get the center point of each class
                        Point fromP = new Point(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y + thisClass.getHeight() / 2);
                        Point toP = new Point(otherClass.getPosition().x + otherClass.getWidth() / 2,
                                otherClass.getPosition().y + otherClass.getHeight() / 2);

                        // get the corner 4 points of the desstination class
                        // (outer margin = 4)
                        Point toP1 = new Point(otherClass.getPosition().x - 4, otherClass.getPosition().y - 4);
                        Point toP2 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4,
                                otherClass.getPosition().y - 4);
                        Point toP3 = new Point(otherClass.getPosition().x + otherClass.getWidth() + 4,
                                otherClass.getPosition().y + otherClass.getHeight() + 4);
                        Point toP4 = new Point(otherClass.getPosition().x - 4,
                                otherClass.getPosition().y + otherClass.getHeight() + 4);

                        // get the intersection with the center line an one of the
                        // sedis of the destination class
                        Point2D toDraw = getIntersection(fromP, toP, toP1, toP2);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP2, toP3);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP3, toP4);
                        if (toDraw == null)
                            toDraw = getIntersection(fromP, toP, toP4, toP1);

                        // draw in red if there is a cclic inheritance problem
                        if (thisClass.hasCyclicInheritance()) {
                            ((Graphics2D) graphics).setStroke(new BasicStroke(2));
                            graphics.setColor(Color.RED);
                        }

                        // draw the arrowed line
                        if (toDraw != null)
                            drawExtends((Graphics2D) graphics, fromP,
                                    new Point((int) toDraw.getX(), (int) toDraw.getY()));

                    } else {
                        ((Graphics2D) graphics).setStroke(new BasicStroke(2));
                        graphics.setColor(Color.RED);

                        // line
                        graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y, thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y - 32);
                        graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y - 32,
                                thisClass.getPosition().x + thisClass.getWidth() + 32,
                                thisClass.getPosition().y - 32);
                        graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() + 32,
                                thisClass.getPosition().y - 32,
                                thisClass.getPosition().x + thisClass.getWidth() + 32,
                                thisClass.getPosition().y + thisClass.getHeight() + 32);
                        graphics.drawLine(thisClass.getPosition().x + thisClass.getWidth() + 32,
                                thisClass.getPosition().y + thisClass.getHeight() + 32,
                                thisClass.getPosition().x + thisClass.getWidth() / 2,
                                thisClass.getPosition().y + thisClass.getHeight() + 32);
                        drawExtends((Graphics2D) graphics,
                                new Point(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                        thisClass.getPosition().y + thisClass.getHeight() + 32),
                                new Point(thisClass.getPosition().x + thisClass.getWidth() / 2,
                                        thisClass.getPosition().y + thisClass.getHeight()));
                    }

                    // reset the stroke and the color
                    ((Graphics2D) graphics).setStroke(new BasicStroke(1));
                    graphics.setColor(Color.BLACK);
                }
            }
        }
    }

    // setup a hastable to store the relations
    //Hashtable<String,StringList> classUsage = new Hashtable<String,StringList>();

    // store compositions
    Hashtable<MyClass, Vector<MyClass>> classCompositions = new Hashtable<MyClass, Vector<MyClass>>();
    // store aggregations
    Hashtable<MyClass, Vector<MyClass>> classAggregations = new Hashtable<MyClass, Vector<MyClass>>();
    // store all relations
    Hashtable<MyClass, Vector<MyClass>> classUsings = new Hashtable<MyClass, Vector<MyClass>>();

    /*
    // iterate through all classes to find compositions
    itr = set.iterator();
    while (itr.hasNext())
    {
      // get the actual classname
      String str = itr.next();
    */

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        String str = entry.getKey();

        // get the corresponding "MyClass" object
        MyClass thisClass = classes.get(str);
        // setup a list to store the relations with this class
        Vector<MyClass> theseCompositions = new Vector<MyClass>();

        // get all fields of this class
        StringList uses = thisClass.getFieldTypes();
        for (int u = 0; u < uses.count(); u++) {
            // try to find the other (used) class
            MyClass otherClass = classes.get(uses.get(u));
            if (otherClass == null)
                otherClass = findByShortName(uses.get(u));
            if (otherClass != null) // means this class uses the other ones
            {
                // add the other class to the list
                theseCompositions.add(otherClass);
            }
        }

        // add the list of used classes to the MyClass object
        thisClass.setUsesMyClass(theseCompositions);
        // store the composition in the general list
        classCompositions.put(thisClass, theseCompositions);
        // store the compositions int eh global relation list
        classUsings.put(thisClass, new Vector<MyClass>(theseCompositions));
        //                        ^^^^^^^^^^^^^^^^^^^^
        //    important !! => create a new vector, otherwise the list
        //                    are the same ...
    }

    /*
    // iterate through all classes to find aggregations
    itr = set.iterator();
    while (itr.hasNext())
    {
      // get the actual class
      String str = itr.next();
    */

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        String str = entry.getKey();

        // get the corresponding "MyClass" object
        MyClass thisClass = classes.get(str);
        // we need a list to store the aggragations with this class
        Vector<MyClass> theseAggregations = new Vector<MyClass>();
        // try to get the list of compositions for this class
        // init if not present
        Vector<MyClass> theseCompositions = classCompositions.get(thisClass);
        if (theseCompositions == null)
            theseCompositions = new Vector<MyClass>();
        // try to get the list of all relations for this class
        // init if not present
        Vector<MyClass> theseClasses = classUsings.get(thisClass);
        if (theseClasses == null)
            theseClasses = new Vector<MyClass>();

        // get the names of the classes that thisclass uses
        StringList foundUsage = thisClass.getUsesWho();
        // go through the list an check to find a corresponding MyClass
        for (int f = 0; f < foundUsage.count(); f++) {
            // get the name of the used class
            String usedClass = foundUsage.get(f);

            MyClass otherClass = classes.get(usedClass);
            if (otherClass == null)
                otherClass = findByShortName(usedClass);
            if (otherClass != null && thisClass != otherClass)
            // meanint "otherClass" is a class used by thisClass
            {
                if (!theseCompositions.contains(otherClass))
                    theseAggregations.add(otherClass);
                if (!theseClasses.contains(otherClass))
                    theseClasses.add(otherClass);
            }
        }

        // get all method types of this class
        StringList uses = thisClass.getMethodTypes();
        for (int u = 0; u < uses.count(); u++) {
            // try to find the other (used) class
            MyClass otherClass = classes.get(uses.get(u));
            if (otherClass == null)
                otherClass = findByShortName(uses.get(u));
            if (otherClass != null) // means this class uses the other ones
            {
                // add the other class to the list
                theseAggregations.add(otherClass);
            }
        }

        // store the relations to the class
        thisClass.setUsesMyClass(theseClasses);
        // store the aggregation to the global list
        classAggregations.put(thisClass, theseAggregations);
        // store all relations to the global list
        classUsings.put(thisClass, theseClasses);
    }

    if (isShowComposition()) {
        /*Set<MyClass> set2 = classCompositions.keySet();
        Iterator<MyClass> itr2 = set2.iterator();
        while (itr2.hasNext())
        {
          MyClass thisClass = itr2.next();
        */

        /* let's try this one ... */
        for (Entry<MyClass, Vector<MyClass>> entry : classCompositions.entrySet()) {
            // get the actual class ...
            MyClass thisClass = entry.getKey();
            if (thisClass.isDisplayUML()) {
                Vector<MyClass> otherClasses = classCompositions.get(thisClass);
                for (MyClass otherClass : otherClasses)
                    drawComposition(g, thisClass, otherClass, classUsings);
            }
        }
    }

    if (isShowAggregation()) {
        /*Set<MyClass> set2 = classAggregations.keySet();
        Iterator<MyClass> itr2 = set2.iterator();
        while (itr2.hasNext())
        {
          MyClass thisClass = itr2.next();
        */

        /* let's try this one ... */
        for (Entry<MyClass, Vector<MyClass>> entry : classAggregations.entrySet()) {
            // get the actual class ...
            MyClass thisClass = entry.getKey();
            if (thisClass.isDisplayUML()) {
                Vector<MyClass> otherClasses = classAggregations.get(thisClass);
                for (MyClass otherClass : otherClasses)
                    drawAggregation(g, thisClass, otherClass, classUsings);
            }
        }
    }

    // draw classes again to put them on top
    // of the arrows
    /*set = classes.keySet();
    itr = set.iterator();
    while (itr.hasNext())
    {
      String str = itr.next();
    */

    /* let's try this one ... */
    for (Entry<String, MyClass> entry : classes.entrySet()) {
        // get the actual class ...
        String str = entry.getKey();

        classes.get(str).setEnabled(this.isEnabled());
        classes.get(str).draw(graphics, showFields, showMethods);

        // push outer box
        MyClass thisClass = classes.get(str);
        if (thisClass.getPosition().y < topLeft.y)
            topLeft.y = thisClass.getPosition().y;
        if (thisClass.getPosition().x < topLeft.x)
            topLeft.x = thisClass.getPosition().x;
        if (thisClass.getPosition().y + thisClass.getHeight() > bottomRight.y)
            bottomRight.y = thisClass.getPosition().y + thisClass.getHeight();
        if (thisClass.getPosition().x + thisClass.getWidth() > bottomRight.x)
            bottomRight.x = thisClass.getPosition().x + thisClass.getWidth();

    }

    // comments
    if (commentString != null) {
        String fontName = g.getFont().getName();
        g.setFont(new Font("Courier", g.getFont().getStyle(), Unimozer.DRAW_FONT_SIZE));

        if (!commentString.trim().equals("")) {
            String myCommentString = new String(commentString);
            Point myCommentPoint = new Point(commentPoint);
            //System.out.println(myCommentString);

            // adjust comment
            myCommentString = myCommentString.trim();
            // adjust position
            myCommentPoint.y = myCommentPoint.y + 16;

            // explode comment
            StringList sl = StringList.explode(myCommentString, "\n");
            // calculate totals
            int totalHeight = 0;
            int totalWidth = 0;
            for (int i = 0; i < sl.count(); i++) {
                String line = sl.get(i).trim();
                int h = (int) g.getFont().getStringBounds(line, g.getFontRenderContext()).getHeight();
                int w = (int) g.getFont().getStringBounds(line, g.getFontRenderContext()).getWidth();
                totalHeight += h;
                totalWidth = Math.max(totalWidth, w);
            }

            // get comment size
            // draw background
            g.setColor(new Color(255, 255, 128, 255));
            g.fillRoundRect(myCommentPoint.x, myCommentPoint.y, totalWidth + 8, totalHeight + 8, 4, 4);
            // draw border
            g.setColor(Color.BLACK);
            g.drawRoundRect(myCommentPoint.x, myCommentPoint.y, totalWidth + 8, totalHeight + 8, 4, 4);

            // draw text
            totalHeight = 0;
            for (int i = 0; i < sl.count(); i++) {
                String line = sl.get(i).trim();
                int h = (int) g.getFont().getStringBounds(myCommentString, g.getFontRenderContext())
                        .getHeight();
                g.drawString(line, myCommentPoint.x + 4, myCommentPoint.y + h + 2 + totalHeight);
                totalHeight += h;
            }

        }

        g.setFont(new Font(fontName, Font.PLAIN, Unimozer.DRAW_FONT_SIZE));

    }

    /*
    if(!isEnabled())
    {
        g.setColor(new Color(128,128,128,128));
        g.fillRect(0,0,getWidth(),getHeight());
            
    }
    */

    this.setPreferredSize(new Dimension(mostRight + 32, mostBottom + 32));
    // THE NEXT LINE MAKES ALL DIALOGUES DISAPEAR!!
    //this.setSize(mostRight+32, mostBottom+32);
    this.validate();
    ((JScrollPane) this.getParent().getParent()).revalidate();

    if (mode == MODE_EXTENDS && extendsFrom != null && extendsDragPoint != null) {
        graphics.setColor(Color.BLUE);
        ((Graphics2D) graphics).setStroke(new BasicStroke(2));
        drawExtends(g, new Point(extendsFrom.getPosition().x + extendsFrom.getWidth() / 2,
                extendsFrom.getPosition().y + extendsFrom.getHeight() / 2), extendsDragPoint);
        graphics.setColor(Color.BLACK);
        ((Graphics2D) graphics).setStroke(new BasicStroke(1));
    }
}