Example usage for java.awt FontMetrics stringWidth

List of usage examples for java.awt FontMetrics stringWidth

Introduction

In this page you can find the example usage for java.awt FontMetrics stringWidth.

Prototype

public int stringWidth(String str) 

Source Link

Document

Returns the total advance width for showing the specified String in this Font .

Usage

From source file:pl.otros.logview.gui.LogViewPanel.java

private void updateColumnsSize() {
    FontMetrics fm = table.getFontMetrics(table.getFont());
    updateColumnSizeIfVisible(TableColumns.ID, fm.stringWidth("0000000"), fm.stringWidth("000000000"));
    updateTimeColumnSize();/*from ww w .j a v  a2  s  .  c  om*/
    updateColumnSizeIfVisible(TableColumns.DELTA, 60, 100);
    updateLevelColumnSize();
    updateColumnSizeIfVisible(TableColumns.CLASS, 100, 500);
    updateColumnSizeIfVisible(TableColumns.THREAD, 100, 300);
    updateColumnSizeIfVisible(TableColumns.METHOD, 100, 200);
    updateColumnSizeIfVisible(TableColumns.LINE, fm.stringWidth("0000"), fm.stringWidth("000000"));
    updateColumnSizeIfVisible(TableColumns.MARK, 16, 16);
    updateColumnSizeIfVisible(TableColumns.NOTE, 100, 1500);
}

From source file:au.com.gaiaresources.bdrs.controller.test.TestDataCreator.java

private byte[] createImage(int width, int height, String text) throws IOException {
    if (width < 0) {
        width = random.nextInt(DEFAULT_MAX_IMAGE_WIDTH - DEFAULT_MIN_IMAGE_WIDTH) + DEFAULT_MIN_IMAGE_WIDTH;
    }/*from  w  w w.  j  a  v a 2  s  .  c  o  m*/
    if (height < 0) {
        height = random.nextInt(DEFAULT_MAX_IMAGE_HEIGHT - DEFAULT_MIN_IMAGE_HEIGHT) + DEFAULT_MIN_IMAGE_HEIGHT;
    }

    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2 = (Graphics2D) img.getGraphics();
    g2.setBackground(new Color(220, 220, 220));

    Dimension size;
    float fontSize = g2.getFont().getSize();
    // Make the text as large as possible.
    do {
        g2.setFont(g2.getFont().deriveFont(fontSize));
        FontMetrics metrics = g2.getFontMetrics(g2.getFont());
        int hgt = metrics.getHeight();
        int adv = metrics.stringWidth(text);
        size = new Dimension(adv + 2, hgt + 2);
        fontSize = fontSize + 1f;
    } while (size.width < Math.round(0.9 * width) && size.height < Math.round(0.9 * height));

    g2.setColor(Color.DARK_GRAY);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.drawString(text, (width - size.width) / 2, (height - size.height) / 2);
    g2.setColor(Color.LIGHT_GRAY);
    g2.drawRect(0, 0, width - 1, height - 1);

    ByteArrayOutputStream baos = new ByteArrayOutputStream(width * height);
    ImageIO.write(img, "png", baos);
    baos.flush();
    byte[] rawBytes = baos.toByteArray();
    baos.close();

    return rawBytes;
}

From source file:org.executequery.gui.erd.ErdTable.java

protected void drawTable(Graphics2D g, int offsetX, int offsetY) {

    if (parent == null) {

        return;/*from w  w  w.j  av  a2  s  .c o m*/
    }

    Font tableNameFont = parent.getTableNameFont();
    Font columnNameFont = parent.getColumnNameFont();

    // set the table value background
    g.setColor(TITLE_BAR_BG_COLOR);
    g.fillRect(offsetX, offsetY, FINAL_WIDTH - 1, TITLE_BAR_HEIGHT);

    // set the table value
    FontMetrics fm = g.getFontMetrics(tableNameFont);
    int lineHeight = fm.getHeight();
    int titleXPosn = (FINAL_WIDTH / 2) - (fm.stringWidth(tableName) / 2) + offsetX;

    g.setColor(Color.BLACK);
    g.setFont(tableNameFont);
    g.drawString(tableName, titleXPosn, lineHeight + offsetY);

    // draw the line separator
    lineHeight = TITLE_BAR_HEIGHT + offsetY - 1;
    g.drawLine(offsetX, lineHeight, offsetX + FINAL_WIDTH - 1, lineHeight);

    // fill the white background
    g.setColor(tableBackground);
    g.fillRect(offsetX, TITLE_BAR_HEIGHT + offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - TITLE_BAR_HEIGHT - 1);

    // add the column names
    fm = g.getFontMetrics(columnNameFont);
    int heightPlusSep = 1 + TITLE_BAR_HEIGHT + offsetY;
    int leftMargin = 5 + offsetX;

    lineHeight = fm.getHeight();
    g.setColor(Color.BLACK);
    g.setFont(columnNameFont);

    int drawCount = 0;
    String value = null;
    if (ArrayUtils.isNotEmpty(columns)) {

        for (int i = 0; i < columns.length; i++) {
            ColumnData column = columns[i];
            if (displayReferencedKeysOnly && !column.isKey()) {
                continue;
            }

            int y = (((drawCount++) + 1) * lineHeight) + heightPlusSep;
            int x = leftMargin;

            // draw the column value string
            value = column.getColumnName();
            g.drawString(value, x, y);

            // draw the data type and size string
            x = leftMargin + dataTypeOffset;
            value = column.getFormattedDataType();
            g.drawString(value, x, y);

            // draw the key label
            if (column.isKey()) {

                if (column.isPrimaryKey() && column.isForeignKey()) {

                    value = PRIMARY + FOREIGN;

                } else if (column.isPrimaryKey()) {

                    value = PRIMARY;

                } else if (column.isForeignKey()) {

                    value = FOREIGN;
                }

                x = leftMargin + dataTypeOffset + keyLabelOffset;
                g.drawString(value, x, y);
            }

        }

    }

    // draw the rectangle border
    double scale = g.getTransform().getScaleX();

    if (selected && scale != ErdPrintable.PRINT_SCALE) {
        g.setStroke(focusBorderStroke);
        g.setColor(Color.BLUE);
    } else {
        g.setColor(Color.BLACK);
    }

    g.drawRect(offsetX, offsetY, FINAL_WIDTH - 1, FINAL_HEIGHT - 1);
    //    g.setColor(Color.DARK_GRAY);
    //    g.draw3DRect(offsetX, offsetY, FINAL_WIDTH - 2, FINAL_HEIGHT - 2, true);
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreeRenderer.java

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

    Dimension d = getSize();/*from   w  w  w  .  ja  v  a2  s .c  o m*/
    //System.out.println("d: "+d+"     "+g.getClipBounds());

    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHints(renderingHints);

    FontMetrics fm = g2d.getFontMetrics();
    int imgY = img1 != null ? (d.height - 24) / 2 : 0;
    int imgY2 = img1 != null ? (d.height - 16) / 2 : 0;
    int txtY = ((d.height - fm.getHeight()) / 2) + fm.getAscent();
    int x = 0;

    Color color = g2d.getColor();

    if (img1 != null) {
        g2d.drawImage(img1.getImage(), x, imgY, null);
        x += img1.getIconWidth();
    }

    int iconInx = 0;

    if (txt1 != null) {
        x += getIconTextGap();
        g2d.setColor(getForeground());
        g.drawString(txt1, x, txtY);
        x += fm.stringWidth(txt1);
        g2d.setColor(color);
    }

    if (isContainer) {
        //if (isSelected  && isEditable)
        //{
        //    x += drawIcon(g2d, x, imgY2, delImgIcon, iconInx++); // Delete the container
        //}

        if (hasColObj) {
            if (img2 != null) {
                x += 1;
                x += iconSep;
                g2d.drawImage(img2.getImage(), x, imgY2, null);
                x += img2.getIconWidth();
            }

            if (txt2 != null) {
                x += getIconTextGap();
                g2d.setColor(getForeground());
                g.drawString(txt2, x, txtY);
                x += fm.stringWidth(txt2);
                g2d.setColor(color);
            }

            if (isSelected) {
                x += iconSep;
                x += drawIcon(g2d, x, imgY2, viewImgIcon, iconInx++);

                if (isEditable) {
                    x += drawIcon(g2d, x, imgY2, delImgIcon, iconInx++);
                }
            }
        } else if (isSelected) // No Col Obj
        {
            x += iconSep;
            x += drawIcon(g2d, x, imgY2, schImgIcon, iconInx++);
            x += drawIcon(g2d, x, imgY2, addImgIcon, iconInx++);
        }

    } else if (isSelected) {
        x += iconSep;
        x += drawIcon(g2d, x, imgY2, viewImgIcon, iconInx++); // View for Collection Object

        //if (!isViewMode)
        //{
        //    x += iconSep;
        //    x += drawIcon(g2d, x, imgY2, delImgIcon, iconInx++); // Delete for Collection Object
        //}
    }

    g2d.dispose();
}

From source file:com.att.aro.ui.view.waterfalltab.WaterfallPanel.java

/**
 * @return the timeAxis/*from   w  w  w.j a  v  a2s  .  c om*/
 */
private NumberAxis getTimeAxis() {
    if (timeAxis == null) {
        timeAxis = new NumberAxis(ResourceBundleHelper.getMessageString("waterfall.time")) {
            private static final long serialVersionUID = 1L;

            /**
             * This override prevents the tick units from changing
             * as the timeline is scrolled to numbers with more digits
             */
            @Override
            protected double estimateMaximumTickLabelWidth(Graphics2D g2d, TickUnit unit) {

                if (isVerticalTickLabels()) {
                    return super.estimateMaximumTickLabelWidth(g2d, unit);
                } else {
                    RectangleInsets tickLabelInsets = getTickLabelInsets();
                    double result = tickLabelInsets.getLeft() + tickLabelInsets.getRight();

                    // look at lower and upper bounds...
                    FontMetrics fMetrics = g2d.getFontMetrics(getTickLabelFont());
                    double upper = traceDuration;
                    String upperStr = "";
                    NumberFormat formatter = getNumberFormatOverride();
                    if (formatter == null) {
                        upperStr = unit.valueToString(upper);
                    } else {
                        upperStr = formatter.format(upper);
                    }
                    double width2 = fMetrics.stringWidth(upperStr);
                    result += width2;
                    return result;
                }

            }

        };
        timeAxis.setRange(new Range(0, DEFAULT_TIMELINE));
        timeAxis.setStandardTickUnits(units);
    }
    return timeAxis;
}

From source file:uk.co.real_logic.aeron.tools.perf_tools.AeronLatencyUnderLoadPublisher.java

private void generateScatterPlot() throws IOException {
    final BufferedImage image = new BufferedImage(1800, 1000, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2 = image.createGraphics();
    final FontMetrics fm = g2.getFontMetrics();
    final String filename = "throughputency.png";
    final File imageFile = new File(filename);

    final int height = 940;
    double min = Double.MAX_VALUE;
    double max = Double.MIN_VALUE;
    for (final long timestamp : timestamps) {
        final double ts = timestamp / 1000.0;
        if (ts < min) {
            min = ts;//from  w w w .  ja v  a2s. com
        }
        if (ts > max) {
            max = ts;
        }
    }
    final double stepY = height / max;

    g2.setColor(Color.white);
    g2.fillRect(0, 0, 1800, 1000);
    g2.setColor(Color.black);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.drawString("Latency ScatterPlot (microseconds)",
            900 - fm.stringWidth("Latency ScatterPlot (microseconds)") / 2, 20);
    g2.drawString("" + max, 10, 20);
    g2.drawLine(100, 20, 100, 960);
    g2.drawLine(100, 960, 1790, 960);
    int start = 0;
    int end = 100;
    final double width = 1690.0 / 7.0;
    g2.setColor(Color.red);
    plotSubset(g2, start, end, "10 msgs/sec", 100, width, stepY, means[0]);

    start = 100;
    end = 1100;
    g2.setColor(Color.green);
    plotSubset(g2, start, end, "100 msgs/sec", 100 + width, width, stepY, means[1]);

    start = 1100;
    end = 11100;
    g2.setColor(Color.blue);
    plotSubset(g2, start, end, "1K msgs/sec", 100 + width * 2, width, stepY, means[2]);

    start = 11100;
    end = 111100;
    g2.setColor(Color.cyan);
    plotSubset(g2, start, end, "10K msgs/sec", 100 + width * 3, width, stepY, means[3]);

    start = 111100;
    end = 1111100;
    g2.setColor(Color.magenta);
    plotSubset(g2, start, end, "100K msgs/sec", 100 + width * 4, width, stepY, means[4]);

    start = 1111100;
    end = 11111100;
    g2.setColor(Color.yellow);
    plotSubset(g2, start, end, "1M msgs/sec", 100 + width * 5, width, stepY, means[5]);

    start = 11111100;
    end = 41111100;
    g2.setColor(Color.orange);
    plotSubset(g2, start, end, "3M msgs/sec", 100 + width * 6, width, stepY, means[6]);

    ImageIO.write(image, "png", imageFile);
}

From source file:lu.lippmann.cdb.graph.GraphViewImpl.java

/**
 * {@inheritDoc}//from   www  . j  a  v  a2  s. c om
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void init() {
    this.setBackground(new Color(235, 240, 245));
    //this.setBackground(Color.WHITE);

    this.removeAll();

    //normal init
    final CadralShapeRenderer vlasr = new CadralShapeRenderer(null, vv.getRenderContext());

    // -----------------------------
    // customize the render context
    // -----------------------------
    final Transformer<CNode, String> vertexLabelTransformer = new Transformer<CNode, String>() {
        @Override
        public String transform(final CNode node) {
            final String tagString = (!node.getTags().isEmpty()) ? " [TAGGED!]" : "";
            final FontMetrics fm = vv.getFontMetrics(vv.getFont());
            final int textWidth = fm.stringWidth(node.getName());
            final int tagWidth = fm.stringWidth(tagString);
            int nodeWidth = (int) ShapeFactory.createShape(node.getShape()).getBounds().getWidth();
            final boolean hasTags = !node.getTags().isEmpty();
            final int realTextWidth = textWidth + (hasTags ? tagWidth : 0);
            final String modifiedNodeName = node.getName() + (hasTags ? tagString : "");
            if (realTextWidth > nodeWidth - 10) {
                int maxSubStringIndex = -1;
                for (int subStringIndex = node.getName().length(); subStringIndex >= 1; subStringIndex--) {
                    String newString = node.getName().substring(0, subStringIndex) + "..." + tagString;
                    if (fm.stringWidth(newString) < nodeWidth - 10) {
                        maxSubStringIndex = subStringIndex;
                        break;
                    }
                }
                return node.getName().substring(0, maxSubStringIndex) + "..." + tagString;
            } else {
                return modifiedNodeName;
            }
        }
    };

    vv.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);
    vv2.getRenderContext().setVertexLabelTransformer(vertexLabelTransformer);

    final Transformer<CNode, String> vertexTooltipTransformer = new Transformer<CNode, String>() {
        @Override
        public String transform(final CNode input) {
            if (!input.getTags().isEmpty()) {
                return buildTooltipFromTags(input.getName(), input.getTags());
            } else {
                if (!input.getName().equals(vertexLabelTransformer.transform(input))) {
                    return input.getName();
                } else {
                    return null;
                }
            }
        }
    };
    vv.setVertexToolTipTransformer(vertexTooltipTransformer);
    vv2.setVertexToolTipTransformer(vertexTooltipTransformer);

    final Transformer<CEdge, String> edgeTooltipTransformer = new Transformer<CEdge, String>() {
        @Override
        public String transform(final CEdge input) {
            if (!input.getTags().isEmpty()) {
                return buildTooltipFromTags(input.getName(), input.getTags());
            } else {
                return input.getName();
            }
        }
    };
    vv.setEdgeToolTipTransformer(edgeTooltipTransformer);
    vv2.setEdgeToolTipTransformer(edgeTooltipTransformer);

    vv.getRenderContext().setVertexFillPaintTransformer(new CadralVertexColorRenderer());
    vv2.getRenderContext().setVertexFillPaintTransformer(new CadralVertexColorRenderer());

    final CadralFontTransformer cadralFontTransformer = new CadralFontTransformer();
    vv.getRenderContext().setVertexFontTransformer(cadralFontTransformer);

    vv.getRenderContext().setVertexShapeTransformer(vlasr);
    vv2.getRenderContext().setVertexShapeTransformer(vlasr);

    //VERTEX LABEL RENDERER
    vv.getRenderer().setVertexLabelRenderer(vlasr);
    vv2.getRenderer().setVertexLabelRenderer(vlasr);

    //FIXME : magic number
    vv.getRenderContext().setLabelOffset(16);
    vv2.getRenderContext().setLabelOffset(16);

    // custom edges
    final Transformer<CEdge, String> edgeLabelTransformer = new Transformer<CEdge, String>() {
        @Override
        public String transform(final CEdge input) {
            return input.getExpression() + (input.getTags().isEmpty() ? "" : " [TAGGED!]");
        }
    };
    vv.getRenderContext().setEdgeLabelTransformer(edgeLabelTransformer);
    vv2.getRenderContext().setEdgeLabelTransformer(edgeLabelTransformer);

    final Font myFont = new Font("Helvetica", 0, 12);

    //FAST EDGE LABEL RENDERER BUT NOT GOOD ENOUGH
    //sun.font.FontManager.getFont2D(myFont);   

    vv.getRenderContext().setEdgeFontTransformer(cadralFontTransformer);
    vv2.getRenderContext().setEdgeFontTransformer(new ConstantTransformer(myFont));

    vv.getRenderContext().setEdgeLabelClosenessTransformer(new ConstantTransformer(0.5));
    vv2.getRenderContext().setEdgeLabelClosenessTransformer(new ConstantTransformer(0.5));

    vv.getRenderContext().setEdgeDrawPaintTransformer(getDefaultEdgeDrawPaintTransformer());
    vv2.getRenderContext().setEdgeDrawPaintTransformer(getDefaultEdgeDrawPaintTransformer());

    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.BLUE, false));
    vv2.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.BLUE, false));

    vv.getRenderContext().setArrowDrawPaintTransformer(
            new PickableEdgePaintTransformer<CEdge>(vv.getPickedEdgeState(), Color.BLACK, Color.BLUE));
    vv.getRenderContext().setArrowFillPaintTransformer(
            new PickableEdgePaintTransformer<CEdge>(vv.getPickedEdgeState(), Color.BLACK, Color.BLUE));

    vv2.getRenderContext().setArrowDrawPaintTransformer(
            new PickableEdgePaintTransformer<CEdge>(vv.getPickedEdgeState(), Color.BLACK, Color.BLUE));
    vv2.getRenderContext().setArrowFillPaintTransformer(
            new PickableEdgePaintTransformer<CEdge>(vv.getPickedEdgeState(), Color.BLACK, Color.BLUE));

    //Manage Zoom
    vv.addMouseWheelListener(new MouseWheelListener() {

        private int zoom = 0;

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {

            if (e.getWheelRotation() < 0) {
                zoom++;
            } else {
                zoom--;
            }

            if (zoom > 0) {
                if (zoom < 9) {
                    double scale = 1 + zoom / 6.0;
                    CadralShapeRenderer.setScale(scale);
                    cadralFontTransformer.setScale(scale);
                }
            } else {
                CadralShapeRenderer.setScale(1);
                cadralFontTransformer.setScale(1);
            }
        }
    });

    final Container panel = new JPanel(new BorderLayout());
    final Container rightPanel = new JPanel(new GridLayout(2, 1));
    panel.add(vv);
    final JPanel top = new JPanel();
    final JButton button = new JButton("Rescale");
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            rescaleSatelliteView();
        }
    });
    top.add(button);
    rightPanel.add(top);
    rightPanel.add(vv2);
    panel.add(rightPanel, BorderLayout.EAST);

    setLayout(new BorderLayout());

    add(metaInfosPanel, BorderLayout.NORTH);

    if (!USE_EXPERIMENTAL_SATELLITE_VIEW) {
        add(vv, BorderLayout.EAST);
    } else {
        add(panel, BorderLayout.EAST);
    }

    add(sharedLabel, BorderLayout.SOUTH);

    add(aboutPanel, BorderLayout.CENTER);

    validate();
    repaint();
}

From source file:VASSAL.build.module.map.LOS_Thread.java

/**
 * Writes text showing the range//from  w w w  .j a va 2s  . co  m
 *
 * @param range the range to display, in whatever units returned
 * by the {@link MapGrid} containing the thread */
public void drawRange(Graphics g, int range) {
    Point mapArrow = map.componentCoordinates(arrow);
    Point mapAnchor = map.componentCoordinates(anchor);
    g.setColor(Color.black);
    g.setFont(RANGE_FONT);
    final FontMetrics fm = g.getFontMetrics();
    final StringBuilder buffer = new StringBuilder();
    int dummy = range;
    while (dummy >= 1) {
        dummy = dummy / 10;
        buffer.append("8");
    }
    if (buffer.length() == 0) {
        buffer.append("8");
    }
    String rangeMess = Resources.getString("LOS_Thread.range");
    int wid = fm.stringWidth(" " + rangeMess + "  " + buffer.toString());
    int hgt = fm.getAscent() + 2;
    int w = mapArrow.x - mapAnchor.x;
    int h = mapArrow.y - mapAnchor.y;
    int x0 = mapArrow.x + (int) ((wid / 2 + 20) * w / Math.sqrt(w * w + h * h));
    int y0 = mapArrow.y + (int) ((hgt / 2 + 20) * h / Math.sqrt(w * w + h * h));
    g.fillRect(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid, hgt);
    g.setColor(Color.white);
    g.drawString(rangeMess + " " + range, x0 - wid / 2 + fm.stringWidth(" "), y0 + hgt / 2);
    lastRangeRect = new Rectangle(x0 - wid / 2, y0 + hgt / 2 - fm.getAscent(), wid + 1, hgt + 1);
    Point np = map.mapCoordinates(new Point(lastRangeRect.x, lastRangeRect.y));
    lastRangeRect.x = np.x;
    lastRangeRect.y = np.y;
    lastRange = String.valueOf(range);
}

From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextFieldSingle.java

@Override
public void paint(Graphics g) {
    super.paint(g);

    String text = getText();/*from   w ww .jav  a 2  s. c  om*/

    //System.err.println("isViewOnly "+isViewOnly+"  isEnabled() "+isEnabled()+ "  ["+text+"]  "+(text.length() < bgStr.length()));
    if (!isViewOnly && needsUpdating && isEnabled() && text != null && text.length() < bgStr.length()) {
        FontMetrics fm = g.getFontMetrics();
        int w = fm.stringWidth(text);
        pnt = new Point(inner.left + w, inner.top + fm.getAscent());

        Rectangle r = g.getClipBounds();
        Dimension s = getSize();
        Insets i2 = getBorder().getBorderInsets(this);
        int x = i2.left - 1;
        int y = i2.top - 1;
        //int ww = s.width - i2.right + 1;
        int hh = s.height - i2.bottom + 1;

        String str = bgStr.substring(text.length(), bgStr.length());
        int bgW = fm.stringWidth(str);

        g.setClip(x + w, y, Math.min(x + bgW, g.getClipBounds().width - x), hh);

        g.setColor(textColor);
        g.drawString(str, pnt.x, pnt.y);

        g.setClip(r.x, r.y, r.width, r.height); // reset clip
    }

    //System.out.println(hashCode() + " isNew: " +isNew+"  valState: "+valState+"    isEnabled: "+isEnabled());
    // 3/2/09 - rods - removing !isNew from the condition
    //if (!isNew && valState == UIValidatable.ErrorType.Error && isEnabled())
    if (valState == UIValidatable.ErrorType.Error && isEnabled()) {
        UIHelper.drawRoundedRect((Graphics2D) g, isNew ? new Color(249, 249, 0) : valTextColor.getColor(),
                getSize(), 1);
    } else if (valState == UIValidatable.ErrorType.Incomplete && isEnabled()) {
        UIHelper.drawRoundedRect((Graphics2D) g, new Color(249, 249, 0), getSize(), 1);
    }
}

From source file:org.executequery.gui.erd.ErdTable.java

/** <p>Initialises the state of this instance. */
private void jbInit() throws Exception {
    Font tableNameFont = parent.getTableNameFont();
    Font columnNameFont = parent.getColumnNameFont();

    FontMetrics fmColumns = getFontMetrics(columnNameFont);
    FontMetrics fmTitle = getFontMetrics(tableNameFont);

    if (columns != null) {
        for (int i = 0; i < columns.length; i++) {
            ColumnData column = columns[i];

            int valueWidth = fmColumns.stringWidth(column.getColumnName());
            dataTypeOffset = Math.max(dataTypeOffset, valueWidth);

            valueWidth = fmColumns.stringWidth(column.getFormattedDataType());
            keyLabelOffset = Math.max(keyLabelOffset, valueWidth);
        }//from www . ja  v a  2s.co m
    }

    // add a further offset to the data type and key label offsets
    dataTypeOffset += 10;
    keyLabelOffset += 2;

    int keyWidth = fmColumns.stringWidth(PRIMARY + FOREIGN);
    int maxWordLength = dataTypeOffset + keyLabelOffset + keyWidth + 10;

    // compare to the title length
    maxWordLength = Math.max(fmTitle.stringWidth(tableName), maxWordLength);

    // add 20px to the final width
    FINAL_WIDTH = maxWordLength;// + 20;

    if (ArrayUtils.isEmpty(columns)) {

        FINAL_WIDTH += 80;
    }

    // minimum width is 130px
    //      if (FINAL_WIDTH < 130)
    //        FINAL_WIDTH = 130;

    TITLE_BAR_HEIGHT = fmTitle.getHeight() + 5;

    int keysCount = 0;
    for (int i = 0; i < columns.length; i++) {
        if (columns[i].isKey()) {
            keysCount++;
        }
    }

    if (columns.length > 0) {
        if (displayReferencedKeysOnly) {
            if (keysCount > 0) {
                FINAL_HEIGHT = (fmColumns.getHeight() * keysCount) + TITLE_BAR_HEIGHT + 10;
            } else {
                FINAL_HEIGHT = fmColumns.getHeight() + TITLE_BAR_HEIGHT + 8;
            }
        } else {
            FINAL_HEIGHT = (fmColumns.getHeight() * columns.length) + TITLE_BAR_HEIGHT + 10;
        }
    } else {
        // have one blank row (column) on the table
        FINAL_HEIGHT = fmColumns.getHeight() + TITLE_BAR_HEIGHT + 10;
    }

    int joinSpacing = 10;
    int vertSize = (FINAL_HEIGHT / joinSpacing) - 1;
    int horizSize = (FINAL_WIDTH / joinSpacing) - 1;

    verticalLeftJoins = new ErdTableConnectionPoint[vertSize];
    verticalRightJoins = new ErdTableConnectionPoint[vertSize];
    horizontalTopJoins = new ErdTableConnectionPoint[horizSize];
    horizontalBottomJoins = new ErdTableConnectionPoint[horizSize];

    int midPointVert = FINAL_HEIGHT / 2;
    int midPointHoriz = FINAL_WIDTH / 2;

    int aboveMidPoint = midPointHoriz;
    int belowMidPoint = midPointHoriz;

    for (int i = 0; i < horizontalTopJoins.length; i++) {
        horizontalTopJoins[i] = new ErdTableConnectionPoint(TOP_JOIN);
        horizontalBottomJoins[i] = new ErdTableConnectionPoint(BOTTOM_JOIN);

        if (i == 0) {
            horizontalTopJoins[i].setPosition(midPointHoriz);
            horizontalBottomJoins[i].setPosition(midPointHoriz);
        }

        else if (i % 2 == 0) {
            belowMidPoint -= joinSpacing;

            if (belowMidPoint > 10) {
                horizontalTopJoins[i].setPosition(belowMidPoint);
                horizontalBottomJoins[i].setPosition(belowMidPoint);
            }

        }

        else {
            aboveMidPoint += joinSpacing;

            if (aboveMidPoint < FINAL_WIDTH - 10) {
                horizontalTopJoins[i].setPosition(belowMidPoint);
                horizontalBottomJoins[i].setPosition(belowMidPoint);
            }

            horizontalTopJoins[i].setPosition(aboveMidPoint);
            horizontalBottomJoins[i].setPosition(aboveMidPoint);
        }

    }

    aboveMidPoint = midPointVert;
    belowMidPoint = midPointVert;

    for (int i = 0; i < verticalLeftJoins.length; i++) {
        verticalLeftJoins[i] = new ErdTableConnectionPoint(LEFT_JOIN);
        verticalRightJoins[i] = new ErdTableConnectionPoint(RIGHT_JOIN);

        if (i == 0) {
            verticalLeftJoins[i].setPosition(midPointVert);
            verticalRightJoins[i].setPosition(midPointVert);
        } else if (i % 2 == 0) {
            belowMidPoint -= joinSpacing;

            if (belowMidPoint < FINAL_HEIGHT - 10) {
                verticalLeftJoins[i].setPosition(belowMidPoint);
                verticalRightJoins[i].setPosition(belowMidPoint);
            }

        } else {
            aboveMidPoint += joinSpacing;

            if (aboveMidPoint > 10) {
                verticalLeftJoins[i].setPosition(aboveMidPoint);
                verticalRightJoins[i].setPosition(aboveMidPoint);
            }

        }

    }

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

            originalData = new ColumnData[columns.length];

            for (int i = 0; i < columns.length; i++) {
                originalData[i] = new ColumnData();
                originalData[i].setValues(columns[i]);
            }

        }
    });

}