Example usage for java.awt Font getSize

List of usage examples for java.awt Font getSize

Introduction

In this page you can find the example usage for java.awt Font getSize.

Prototype

public int getSize() 

Source Link

Document

Returns the point size of this Font , rounded to an integer.

Usage

From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java

/**
 * @noinspection ALL/*from   w w  w  .  j  av  a  2s . co m*/
 */
private Font $$$getFont$$$(String fontName, int style, int size, Font currentFont) {
    if (currentFont == null)
        return null;
    String resultName;
    if (fontName == null) {
        resultName = currentFont.getName();
    } else {
        Font testFont = new Font(fontName, Font.PLAIN, 10);
        if (testFont.canDisplay('a') && testFont.canDisplay('1')) {
            resultName = fontName;
        } else {
            resultName = currentFont.getName();
        }
    }
    return new Font(resultName, style >= 0 ? style : currentFont.getStyle(),
            size >= 0 ? size : currentFont.getSize());
}

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

private void drawTitle(Graphics2D g2) {
    final Object oldValueAntiAlias = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Color oldColor = g2.getColor();
    final Font oldFont = g2.getFont();

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

    final Font titleFont = oldFont.deriveFont(oldFont.getStyle() | Font.BOLD, (float) oldFont.getSize() * 1.5f);

    final int margin = 5;

    final FontMetrics titleFontMetrics = g2.getFontMetrics(titleFont);
    final FontMetrics oldFontMetrics = g2.getFontMetrics(oldFont);
    final java.text.NumberFormat numberFormat = java.text.NumberFormat.getInstance();
    numberFormat.setMaximumFractionDigits(2);
    numberFormat.setMinimumFractionDigits(2);

    final double totalInvestValue = this.investmentFlowChartJDialog.getTotalInvestValue();
    final double totalROIValue = this.investmentFlowChartJDialog.getTotalROIValue();

    final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace();

    final String invest = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace,
            totalInvestValue);/*  w  ww. java 2s .  co m*/
    final String roi = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, totalROIValue);
    final double gain = totalROIValue - totalInvestValue;
    final double percentage = totalInvestValue > 0.0 ? gain / totalInvestValue * 100.0 : 0.0;
    final String gain_str = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, gain);
    final String percentage_str = numberFormat.format(percentage);

    final String SELECTED = this.investmentFlowChartJDialog.getCurrentSelectedString();
    final String INVEST = GUIBundle.getString("InvestmentFlowLayerUI_Invest");
    final String RETURN = GUIBundle.getString("InvestmentFlowLayerUI_Return");
    final String GAIN = (SELECTED.length() > 0 ? SELECTED + " " : "")
            + GUIBundle.getString("InvestmentFlowLayerUI_Gain");
    final String LOSS = (SELECTED.length() > 0 ? SELECTED + " " : "")
            + GUIBundle.getString("InvestmentFlowLayerUI_Loss");

    final int string_width = oldFontMetrics.stringWidth(INVEST + ": ")
            + titleFontMetrics.stringWidth(invest + " ") + oldFontMetrics.stringWidth(RETURN + ": ")
            + titleFontMetrics.stringWidth(roi + " ")
            + oldFontMetrics.stringWidth((gain >= 0 ? GAIN : LOSS) + ": ")
            + titleFontMetrics.stringWidth(gain_str + " (" + percentage_str + "%)");

    int x = (int) (this.investmentFlowChartJDialog.getChartPanel().getWidth() - string_width) >> 1;
    final int y = margin + titleFontMetrics.getAscent();

    g2.setFont(oldFont);
    g2.drawString(INVEST + ": ", x, y);
    x += oldFontMetrics.stringWidth(INVEST + ": ");
    g2.setFont(titleFont);
    g2.drawString(invest + " ", x, y);
    x += titleFontMetrics.stringWidth(invest + " ");
    g2.setFont(oldFont);
    g2.drawString(RETURN + ": ", x, y);
    x += oldFontMetrics.stringWidth(RETURN + ": ");
    g2.setFont(titleFont);
    g2.drawString(roi + " ", x, y);
    x += titleFontMetrics.stringWidth(roi + " ");
    g2.setFont(oldFont);
    if (gain >= 0) {
        if (gain > 0) {
            if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) {
                g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor());
            } else {
                g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor());
            }
        }
        g2.drawString(GAIN + ": ", x, y);
        x += oldFontMetrics.stringWidth(GAIN + ": ");
    } else {
        if (org.yccheok.jstock.engine.Utils.isFallBelowAndRiseAboveColorReverse()) {
            g2.setColor(JStock.instance().getJStockOptions().getHigherNumericalValueForegroundColor());
        } else {
            g2.setColor(JStock.instance().getJStockOptions().getLowerNumericalValueForegroundColor());
        }
        g2.drawString(LOSS + ": ", x, y);
        x += oldFontMetrics.stringWidth(LOSS + ": ");
    }
    g2.setFont(titleFont);
    g2.drawString(gain_str + " (" + percentage_str + "%)", x, y);

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

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  . ja  va2  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: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);/*from w w w . j  a v  a 2s. 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 updateInvestInformationBox(Graphics2D g2) {
    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 Activities activities = this.investmentFlowChartJDialog.getInvestActivities(this.investPointIndex);

    this.investValues.clear();
    this.investParams.clear();
    this.totalInvestValue = 0.0;

    final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace();

    for (int i = 0, size = activities.size(); i < size; i++) {
        final Activity activity = activities.get(i);
        // Buy only.
        this.investParams.add(activity.getType() + " "
                + org.yccheok.jstock.portfolio.Utils.toQuantity(activity.get(Activity.Param.Quantity)) + " "
                + ((StockInfo) activity.get(Activity.Param.StockInfo)).symbol);

        if (activity.getType() == Activity.Type.Buy) {
            final StockInfo stockInfo = (StockInfo) activity.get(Activity.Param.StockInfo);

            final double amount = convertToPoundIfNecessary(stockInfo.code, activity.getAmount());
            this.totalInvestValue += amount;
            this.investValues
                    .add(org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, amount));
        } else {//from w  w  w  .jav a 2 s.  com
            assert (false);
        }
    }

    final boolean isTotalNeeded = this.investParams.size() > 1;
    final String totalParam = GUIBundle.getString("InvestmentFlowLayerUI_Total_Invest");
    final String totalValue = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace,
            this.totalInvestValue);
    /* This is the height for "total" information. */
    int totalHeight = 0;

    assert (this.investValues.size() == this.investParams.size());

    int index = 0;
    final int paramValueWidthMargin = 10;
    final int paramValueHeightMargin = 0;
    int maxInfoWidth = -1;
    // paramFontMetrics will always "smaller" than valueFontMetrics.
    int totalInfoHeight = Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight())
            * this.investValues.size() + paramValueHeightMargin * (this.investValues.size() - 1);
    for (String param : this.investParams) {
        final String value = this.investValues.get(index++);
        final int paramStringWidth = paramFontMetrics.stringWidth(param + ":") + paramValueWidthMargin
                + valueFontMetrics.stringWidth(value);
        if (maxInfoWidth < paramStringWidth) {
            maxInfoWidth = paramStringWidth;
        }
    }

    if (isTotalNeeded) {
        final int tmp = paramFontMetrics.stringWidth(totalParam + ":") + paramValueWidthMargin
                + valueFontMetrics.stringWidth(totalValue);
        if (maxInfoWidth < tmp) {
            maxInfoWidth = tmp;
        }
        totalHeight = Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight());
    }

    final Date date = activities.getDate().getTime();
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy");
    final String dateString = simpleDateFormat.format(date);
    final int dateStringWidth = dateFontMetrics.stringWidth(dateString);
    final int dateStringHeight = dateFontMetrics.getHeight();
    final int maxStringWidth = Math.max(dateStringWidth, maxInfoWidth);
    final int dateInfoHeightMargin = 5;
    final int infoTotalHeightMargin = 5;
    final int maxStringHeight = isTotalNeeded
            ? (dateStringHeight + dateInfoHeightMargin + totalInfoHeight + infoTotalHeightMargin + totalHeight)
            : (dateStringHeight + dateInfoHeightMargin + totalInfoHeight);

    // Now, We have a pretty good information on maxStringWidth and maxStringHeight.

    final int padding = 5;
    final int boxPointMargin = 8;
    final int width = maxStringWidth + (padding << 1);
    final int height = maxStringHeight + (padding << 1);
    // On left side of the ball.
    final int suggestedX = (int) (this.investPoint.getX() - width - boxPointMargin);
    final int suggestedY = (int) (this.investPoint.getY() - (height >> 1));
    final int x = suggestedX > this.drawArea.getX()
            ? (suggestedX + width) < (this.drawArea.getX() + this.drawArea.getWidth()) ? suggestedX
                    : (int) (this.drawArea.getX() + this.drawArea.getWidth() - width - boxPointMargin)
            : (int) (investPoint.getX() + boxPointMargin);
    final int y = suggestedY > this.drawArea.getY()
            ? (suggestedY + height) < (this.drawArea.getY() + this.drawArea.getHeight()) ? suggestedY
                    : (int) (this.drawArea.getY() + this.drawArea.getHeight() - height - boxPointMargin)
            : (int) (this.drawArea.getY() + boxPointMargin);

    this.investRect.setRect(x, y, width, height);
}

From source file:org.eclipse.wb.internal.swing.model.property.editor.font.DerivedFontInfo.java

public DerivedFontInfo(Font baseFont, String baseFontSource, String baseFontClipboardSource, String newFamily,
        Boolean newBold, Boolean newItalic, Integer deltaSize, Integer newSize) {
    m_baseFont = baseFont;/*from w ww. ja v a2  s .c  om*/
    m_baseFontSource = baseFontSource;
    m_baseFontClipboardSource = baseFontClipboardSource;
    m_newFamily = newFamily;
    m_newBold = newBold;
    m_newItalic = newItalic;
    m_deltaSize = deltaSize;
    m_newSize = newSize;
    // create derived Font
    {
        String family = newFamily != null ? newFamily : baseFont.getFamily();
        // style
        int style = baseFont.getStyle();
        if (newBold != null) {
            if (newBold.booleanValue()) {
                style |= Font.BOLD;
            } else {
                style &= ~Font.BOLD;
            }
        }
        if (newItalic != null) {
            if (newItalic.booleanValue()) {
                style |= Font.ITALIC;
            } else {
                style &= ~Font.ITALIC;
            }
        }
        // size
        int size = baseFont.getSize();
        if (deltaSize != null) {
            size += deltaSize.intValue();
        } else if (newSize != null) {
            size = newSize.intValue();
        }
        // create derived Font
        m_font = new Font(family, style, size);
    }
}

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

private void updateROIInformationBox(Graphics2D g2) {
    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 Activities activities = this.investmentFlowChartJDialog.getROIActivities(this.ROIPointIndex);

    this.ROIValues.clear();
    this.ROIParams.clear();
    this.totalROIValue = 0.0;

    final DecimalPlace decimalPlace = JStock.instance().getJStockOptions().getDecimalPlace();

    for (int i = 0, size = activities.size(); i < size; i++) {
        final Activity activity = activities.get(i);
        // Buy, Sell or Dividend only.
        if (activity.getType() == Activity.Type.Buy) {
            final double quantity = (Double) activity.get(Activity.Param.Quantity);
            final StockInfo stockInfo = (StockInfo) activity.get(Activity.Param.StockInfo);
            this.ROIParams.add(GUIBundle.getString("InvestmentFlowLayerUI_Own") + " "
                    + org.yccheok.jstock.portfolio.Utils.toQuantity(quantity) + " " + stockInfo.symbol);
            final double amount = convertToPoundIfNecessary(stockInfo.code,
                    quantity * this.investmentFlowChartJDialog.getStockPrice(stockInfo.code));
            this.totalROIValue += amount;
            this.ROIValues.add(org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, amount));
        } else if (activity.getType() == Activity.Type.Sell) {
            final double quantity = (Double) activity.get(Activity.Param.Quantity);
            final StockInfo stockInfo = (StockInfo) activity.get(Activity.Param.StockInfo);
            this.ROIParams.add(activity.getType() + " "
                    + org.yccheok.jstock.portfolio.Utils.toQuantity(quantity) + " " + stockInfo.symbol);
            final double amount = convertToPoundIfNecessary(stockInfo.code, activity.getAmount());
            this.totalROIValue += amount;
            this.ROIValues.add(org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, amount));
        } else if (activity.getType() == Activity.Type.Dividend) {
            final StockInfo stockInfo = (StockInfo) activity.get(Activity.Param.StockInfo);
            this.ROIParams.add(activity.getType() + " " + stockInfo.symbol);
            final double amount = activity.getAmount();
            this.totalROIValue += amount;
            this.ROIValues.add(org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace, amount));
        } else {// w  ww.  j  a  v  a  2  s.  com
            assert (false);
        }
    }

    final boolean isTotalNeeded = this.ROIParams.size() > 1;
    final String totalParam = GUIBundle.getString("InvestmentFlowLayerUI_Total_Return");
    final String totalValue = org.yccheok.jstock.portfolio.Utils.toCurrencyWithSymbol(decimalPlace,
            this.totalROIValue);
    /* This is the height for "total" information. */
    int totalHeight = 0;

    assert (this.ROIParams.size() == this.ROIValues.size());

    int index = 0;
    final int paramValueWidthMargin = 10;
    final int paramValueHeightMargin = 0;
    int maxInfoWidth = -1;
    // paramFontMetrics will always "smaller" than valueFontMetrics.
    int totalInfoHeight = Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight())
            * this.ROIValues.size() + paramValueHeightMargin * (this.ROIValues.size() - 1);
    for (String param : this.ROIParams) {
        final String value = this.ROIValues.get(index++);
        final int paramStringWidth = paramFontMetrics.stringWidth(param + ":") + paramValueWidthMargin
                + valueFontMetrics.stringWidth(value);
        if (maxInfoWidth < paramStringWidth) {
            maxInfoWidth = paramStringWidth;
        }
    }

    if (isTotalNeeded) {
        final int tmp = paramFontMetrics.stringWidth(totalParam + ":") + paramValueWidthMargin
                + valueFontMetrics.stringWidth(totalValue);
        if (maxInfoWidth < tmp) {
            maxInfoWidth = tmp;
        }
        totalHeight = Math.max(paramFontMetrics.getHeight(), valueFontMetrics.getHeight());
    }

    final Date date = activities.getDate().getTime();
    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEEE, MMMM d, yyyy");
    final String dateString = simpleDateFormat.format(date);
    final int dateStringWidth = dateFontMetrics.stringWidth(dateString);
    final int dateStringHeight = dateFontMetrics.getHeight();
    final int maxStringWidth = Math.max(dateStringWidth, maxInfoWidth);
    final int dateInfoHeightMargin = 5;
    final int infoTotalHeightMargin = 5;
    final int maxStringHeight = isTotalNeeded
            ? (dateStringHeight + dateInfoHeightMargin + totalInfoHeight + infoTotalHeightMargin + totalHeight)
            : (dateStringHeight + dateInfoHeightMargin + totalInfoHeight);

    // Now, We have a pretty good information on maxStringWidth and maxStringHeight.

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

    final int borderWidth = width + 2;
    final int borderHeight = height + 2;
    // On left side of the ball.
    final double suggestedBorderX = this.ROIPoint.getX() - borderWidth - boxPointMargin;
    final double suggestedBorderY = this.ROIPoint.getY() - (borderHeight >> 1);
    final double bestBorderX = suggestedBorderX > this.drawArea.getX()
            ? (suggestedBorderX + borderWidth) < (this.drawArea.getX() + this.drawArea.getWidth())
                    ? suggestedBorderX
                    : this.drawArea.getX() + this.drawArea.getWidth() - borderWidth - boxPointMargin
            : this.ROIPoint.getX() + boxPointMargin;
    final double bestBorderY = suggestedBorderY > this.drawArea.getY()
            ? (suggestedBorderY + borderHeight) < (this.drawArea.getY() + this.drawArea.getHeight())
                    ? suggestedBorderY
                    : this.drawArea.getY() + this.drawArea.getHeight() - borderHeight - boxPointMargin
            : this.drawArea.getY() + boxPointMargin;

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

    this.ROIRect.setRect(x, y, width, height);
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.UserProfile.java

/** Initializes the components composing this display. */
private void initComponents() {
    admin = false;/* w  ww . j  av a 2 s .  c o  m*/
    active = false;
    groupOwner = false;

    userPicture = new UserProfileCanvas();
    userPicture.setBackground(UIUtilities.BACKGROUND_COLOR);

    IconManager icons = IconManager.getInstance();
    changePhoto = new JLabel("Change Photo");
    changePhoto.setToolTipText("Upload your photo.");
    changePhoto.setForeground(UIUtilities.HYPERLINK_COLOR);
    Font font = changePhoto.getFont();
    changePhoto.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2));
    changePhoto.setBackground(UIUtilities.BACKGROUND_COLOR);
    deletePhoto = new JButton(icons.getIcon(IconManager.DELETE_12));
    boolean b = canModifyPhoto();
    changePhoto.setVisible(b);
    deletePhoto.setToolTipText("Delete the photo.");
    deletePhoto.setBackground(UIUtilities.BACKGROUND_COLOR);
    UIUtilities.unifiedButtonLookAndFeel(deletePhoto);
    deletePhoto.setVisible(false);
    loginArea = new JTextField();
    boolean a = MetadataViewerAgent.isAdministrator();
    loginArea.setEnabled(a);
    loginArea.setEditable(a);
    adminBox = new JCheckBox();
    adminBox.setVisible(false);
    adminBox.setBackground(UIUtilities.BACKGROUND_COLOR);
    ownerBox = new JCheckBox();
    ownerBox.setBackground(UIUtilities.BACKGROUND_COLOR);
    activeBox = new JCheckBox();
    activeBox.setBackground(UIUtilities.BACKGROUND_COLOR);
    activeBox.setVisible(false);
    passwordButton = new JButton("Change password");
    passwordButton.setEnabled(false);
    passwordButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    passwordButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            changePassword();
        }
    });
    saveButton = new JButton("Save");
    saveButton.setEnabled(false);
    saveButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            GroupData g = getSelectedGroup();
            ExperimenterData exp = (ExperimenterData) model.getRefObject();
            if (exp.getDefaultGroup().getId() != g.getId())
                model.fireAdminSaving(g, true);
            view.saveData(true);
        }
    });
    manageButton = new JButton("Group");
    manageButton.setEnabled(false);
    manageButton.setBackground(UIUtilities.BACKGROUND_COLOR);
    manageButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            manageGroup();
        }
    });
    passwordNew = new JPasswordField();
    passwordNew.setBackground(UIUtilities.BACKGROUND_COLOR);
    passwordConfirm = new JPasswordField();
    passwordConfirm.setBackground(UIUtilities.BACKGROUND_COLOR);
    oldPassword = new JPasswordField();
    oldPassword.setBackground(UIUtilities.BACKGROUND_COLOR);
    items = new HashMap<String, JTextField>();
    ExperimenterData user = (ExperimenterData) model.getRefObject();
    Collection<GroupData> groups = user.getGroups();

    GroupData defaultGroup = user.getDefaultGroup();

    groupsBox = new JComboBox();
    SelectableComboBoxModel m = new SelectableComboBoxModel();
    Iterator<GroupData> i = groups.iterator();
    GroupData g;
    Selectable<DataNode> node, selected = null;
    while (i.hasNext()) {
        g = i.next();
        if (!model.isSystemGroup(g.getId(), GroupData.USER)) {
            node = new Selectable<DataNode>(new DataNode(g), true);
            if (g.getId() == defaultGroup.getId())
                selected = node;
            m.addElement(node);
        }
    }
    groupsBox.setModel(m);
    if (selected != null)
        groupsBox.setSelectedItem(selected);
    permissionsPane = new PermissionsPane(defaultGroup.getPermissions(), UIUtilities.BACKGROUND_COLOR);
    permissionsPane.disablePermissions();

    ExperimenterData logUser = model.getCurrentUser();
    if (MetadataViewerAgent.isAdministrator()) {
        //Check that the user is not the one currently logged.
        oldPassword.setVisible(false);
        adminBox.setVisible(true);
        activeBox.setVisible(true);
        adminBox.addChangeListener(this);
        active = user.isActive();
        activeBox.setSelected(active);
        activeBox.setEnabled(!model.isSelf() && !model.isSystemUser(user.getId()));
        activeBox.addChangeListener(this);
        //indicate if the user is an administrator
        admin = isUserAdministrator();
        adminBox.setSelected(admin);
        adminBox.setEnabled(!model.isSelf() && !model.isSystemUser(user.getId()));
        ownerBox.addChangeListener(this);
        ownerBox.setEnabled(!model.isSystemUser(user.getId()));
    } else {
        ownerBox.setEnabled(false);
        passwordConfirm.getDocument().addDocumentListener(new DocumentListener() {

            /**
             * Allows the user to interact with the password controls
             * depending on the value entered.
             * @see DocumentListener#removeUpdate(DocumentEvent)
             */
            public void removeUpdate(DocumentEvent e) {
                handlePasswordEntered();
            }

            /**
             * Allows the user to interact with the password controls
             * depending on the value entered.
             * @see DocumentListener#insertUpdate(DocumentEvent)
             */
            public void insertUpdate(DocumentEvent e) {
                handlePasswordEntered();
            }

            /**
             * Required by the {@link DocumentListener} I/F but 
             * no-operation implementation in our case.
             * @see DocumentListener#changedUpdate(DocumentEvent)
             */
            public void changedUpdate(DocumentEvent e) {
            }
        });
    }
    passwordNew.getDocument().addDocumentListener(new DocumentListener() {

        /**
         * Allows the user to interact with the password controls
         * depending on the value entered.
         * @see DocumentListener#removeUpdate(DocumentEvent)
         */
        public void removeUpdate(DocumentEvent e) {
            handlePasswordEntered();
        }

        /**
         * Allows the user to interact with the password controls
         * depending on the value entered.
         * @see DocumentListener#insertUpdate(DocumentEvent)
         */
        public void insertUpdate(DocumentEvent e) {
            handlePasswordEntered();
        }

        /**
         * Required by the {@link DocumentListener} I/F but
         * no-operation implementation in our case.
         * @see DocumentListener#changedUpdate(DocumentEvent)
         */
        public void changedUpdate(DocumentEvent e) {
        }
    });
    if (user.getId() == logUser.getId()) {
        MouseAdapter adapter = new MouseAdapter() {

            /** Brings up a chooser to load the user image. */
            public void mouseReleased(MouseEvent e) {
                uploadPicture();
            }

        };
        changePhoto.addMouseListener(adapter);
        deletePhoto.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                model.deletePicture();
                setUserPhoto(null);
            }
        });
        if (groups.size() > 1) {
            groupsBox.addActionListener(new ActionListener() {

                /**
                 * Listens to the change of default group.
                 */
                public void actionPerformed(ActionEvent evt) {
                    GroupData g = getSelectedGroup();
                    //update the default group
                    permissionsPane.resetPermissions(g.getPermissions());
                    permissionsPane.disablePermissions();
                    setGroupOwner(g);
                    ExperimenterData exp = (ExperimenterData) model.getRefObject();
                    saveButton.setEnabled(exp.getDefaultGroup().getId() != g.getId());
                }
            });
        }
    }
}

From source file:processing.app.EditorTab.java

public void applyPreferences() {
    textarea.setCodeFoldingEnabled(PreferencesData.getBoolean("editor.code_folding"));
    scrollPane.setFoldIndicatorEnabled(PreferencesData.getBoolean("editor.code_folding"));
    scrollPane.setLineNumbersEnabled(PreferencesData.getBoolean("editor.linenumbers"));

    // apply the setting for 'use external editor', but only if it changed
    if (external != PreferencesData.getBoolean("editor.external")) {
        external = !external;//from w  w  w.  j av a2s.  co m
        if (external) {
            // disable line highlight and turn off the caret when disabling
            textarea.setBackground(Theme.getColor("editor.external.bgcolor"));
            textarea.setHighlightCurrentLine(false);
            textarea.setEditable(false);
            // Detach from the code, since we are no longer the authoritative source
            // for file contents.
            file.setStorage(null);
            // Reload, in case the file contents already changed.
            reload();
        } else {
            textarea.setBackground(Theme.getColor("editor.bgcolor"));
            textarea.setHighlightCurrentLine(Theme.getBoolean("editor.linehighlight"));
            textarea.setEditable(true);
            file.setStorage(this);
            // Reload once just before disabling external mode, to ensure we have
            // the latest contents.
            reload();
        }
    }
    // apply changes to the font size for the editor
    Font editorFont = scale(PreferencesData.getFont("editor.font"));

    // check whether a theme-defined editor font is available
    Font themeFont = Theme.getFont("editor.font");
    if (themeFont != null) {
        // Apply theme font if the editor font has *not* been changed by the user,
        // This allows themes to specify an editor font which will only be applied
        // if the user hasn't already changed their editor font via preferences.txt
        String defaultFontName = StringUtils.defaultIfEmpty(PreferencesData.getDefault("editor.font"), "")
                .split(",")[0];
        if (defaultFontName.equals(editorFont.getName())) {
            editorFont = new Font(themeFont.getName(), themeFont.getStyle(), editorFont.getSize());
        }
    }

    textarea.setFont(editorFont);
    scrollPane.getGutter().setLineNumberFont(editorFont);
}

From source file:base.BasePlayer.AddGenome.java

public static void setFonts(Font menuFont) {
    if (menuFont == null) {
        menuFont = new Font("SansSerif", Font.BOLD, Main.defaultFontSize);
    }/*from   www  .j a  v  a2  s . c om*/
    for (int i = 0; i < panel.getComponentCount(); i++) {
        panel.getComponent(i).setFont(menuFont);
    }
    AddGenome.genometable.getTableHeader().setFont(menuFont);
    AddGenome.genometable.setFont(menuFont);
    AddGenome.genometable.setRowHeight(menuFont.getSize() + 2);
    tree.setFont(menuFont);
    tree.setRowHeight(menuFont.getSize() + 2);
    frame.pack();

}