Example usage for java.awt Font getStyle

List of usage examples for java.awt Font getStyle

Introduction

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

Prototype

public int getStyle() 

Source Link

Document

Returns the style of this Font .

Usage

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 {// ww w  .ja v  a2 s.c  o  m
            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.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.  ja  va2  s . c  o m
            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:ubic.gemma.web.controller.expression.experiment.ExpressionExperimentQCController.java

/**
 * Write a blank thumbnail image so user doesn't see the broken icon.
 *///  w w  w. ja v a  2s . c  o  m
private void writePlaceholderThumbnailImage(OutputStream os, int placeholderSize) throws IOException {
    // Make the image a bit bigger to account for the empty space around the generated image.
    // If we can find a way to remove this empty space, we don't need to make the chart bigger.
    BufferedImage buffer = new BufferedImage(placeholderSize + 16, placeholderSize + 9,
            BufferedImage.TYPE_INT_RGB);
    Graphics g = buffer.createGraphics();
    g.setColor(Color.white);
    g.fillRect(0, 0, placeholderSize + 16, placeholderSize + 9);
    g.setColor(Color.gray);
    g.drawLine(8, placeholderSize + 5, placeholderSize + 8, placeholderSize + 5); // x-axis
    g.drawLine(8, 5, 8, placeholderSize + 5); // y-axis
    g.setColor(Color.black);
    Font font = g.getFont();
    g.setFont(new Font(font.getName(), font.getStyle(), 8));
    g.drawString("N/A", 9, placeholderSize);
    ImageIO.write(buffer, "png", os);
}

From source file:org.mwc.cmap.xyplot.views.XYPlotView.java

private void storeFont(final IMemento memento, final String entryHeader, final Font theFont) {
    // write elements
    memento.putInteger(entryHeader + "_SIZE", theFont.getSize());
    memento.putString(entryHeader + "_FAMILY", theFont.getFamily());
    memento.putInteger(entryHeader + "_STYLE", theFont.getStyle());
}

From source file:net.ontopia.topicmaps.viz.VizTopicMapConfigurationManager.java

private String serializeFont(Font font) {
    // Fonts are serialized to the form:
    // "<family name>-<style>-<size>"

    StringBuilder buffer = new StringBuilder();
    buffer.append(font.getFamily());//from  w w  w.jav  a 2 s  .  com
    buffer.append("-");
    buffer.append(font.getStyle());
    buffer.append("-");
    buffer.append(font.getSize());

    String result = buffer.toString();

    fontCache.put(result, font);

    return result;
}

From source file:userinterface.graph.Graph.java

/**
 * Allows graphs to be saved to the PRISM 'gra' file format.
 * /* w w  w  .  java2s.c o  m*/
 * @param file
 *            The file to save the graph to.
 * @throws GraphException
 *             If the file cannot be written.
 */
public void save(File file) throws PrismException {
    try {
        JFreeChart chart = getChart();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.newDocument();

        Element chartFormat = doc.createElement("chartFormat");

        chartFormat.setAttribute("versionString", prism.Prism.getVersion());
        chartFormat.setAttribute("graphTitle", getTitle());

        Font titleFont = getTitleFont().f;
        chartFormat.setAttribute("titleFontName", titleFont.getName());
        chartFormat.setAttribute("titleFontSize", "" + titleFont.getSize());
        chartFormat.setAttribute("titleFontStyle", "" + titleFont.getStyle());

        Color titleFontColor = (Color) getTitleFont().c;
        chartFormat.setAttribute("titleFontColourR", "" + titleFontColor.getRed());
        chartFormat.setAttribute("titleFontColourG", "" + titleFontColor.getGreen());
        chartFormat.setAttribute("titleFontColourB", "" + titleFontColor.getBlue());

        chartFormat.setAttribute("legendVisible", isLegendVisible() ? "true" : "false");

        Font legendFont = getLegendFont().f;
        chartFormat.setAttribute("legendFontName", "" + legendFont.getName());
        chartFormat.setAttribute("legendFontSize", "" + legendFont.getSize());
        chartFormat.setAttribute("legendFontStyle", "" + legendFont.getStyle());

        Color legendFontColor = getLegendFont().c;

        chartFormat.setAttribute("legendFontColourR", "" + legendFontColor.getRed());
        chartFormat.setAttribute("legendFontColourG", "" + legendFontColor.getGreen());
        chartFormat.setAttribute("legendFontColourB", "" + legendFontColor.getBlue());

        switch (getLegendPosition()) {
        case LEFT:
            chartFormat.setAttribute("legendPosition", "left");
            break;
        case BOTTOM:
            chartFormat.setAttribute("legendPosition", "bottom");
            break;
        case TOP:
            chartFormat.setAttribute("legendPosition", "top");
            break;
        default:
            chartFormat.setAttribute("legendPosition", "right");
        }

        Element layout = doc.createElement("layout");
        chartFormat.appendChild(layout);

        Element xAxis = doc.createElement("axis");
        getXAxisSettings().save(xAxis);
        chartFormat.appendChild(xAxis);

        Element yAxis = doc.createElement("axis");
        getYAxisSettings().save(yAxis);
        chartFormat.appendChild(yAxis);

        synchronized (getSeriesLock()) {
            /* Make sure we preserve ordering. */
            for (int i = 0; i < seriesList.getSize(); i++) {
                SeriesKey key = seriesList.getKeyAt(i);

                Element series = doc.createElement("graph");
                SeriesSettings seriesSettings = getGraphSeries(key);
                seriesSettings.save(series);

                XYSeries seriesData = getXYSeries(key);

                for (int j = 0; j < seriesData.getItemCount(); j++) {
                    Element point = doc.createElement("point");

                    point.setAttribute("x", "" + seriesData.getX(j));
                    point.setAttribute("y", "" + seriesData.getY(j));

                    series.appendChild(point);
                }

                chartFormat.appendChild(series);
            }
        }

        doc.appendChild(chartFormat);

        // File writing 
        Transformer t = TransformerFactory.newInstance().newTransformer();
        t.setOutputProperty("doctype-system", "chartformat.dtd");
        t.setOutputProperty("indent", "yes");
        t.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(file)));
    } catch (IOException e) {
        throw new PrismException(e.getMessage());
    } catch (DOMException e) {
        throw new PrismException("Problem saving graph: DOM Exception: " + e);
    } catch (ParserConfigurationException e) {
        throw new PrismException("Problem saving graph: Parser Exception: " + e);
    } catch (TransformerConfigurationException e) {
        throw new PrismException("Problem saving graph: Error in creating XML: " + e);
    } catch (TransformerException e) {
        throw new PrismException("Problem saving graph: Transformer Exception: " + e);
    } catch (SettingException e) {
        throw new PrismException(e.getMessage());
    }
}

From source file:lcmc.common.ui.ResourceGraph.java

/** Returns layout of the text that will be drawn on the vertex. */
private TextLayout getVertexTextLayout(final Graphics2D g2d, final String text, final double fontSizeFactor) {
    final TextLayout ctl = textLayoutCache.get(fontSizeFactor + ":" + text);
    if (ctl != null) {
        return ctl;
    }/*from   w  w w .j  a v  a  2 s  .  co  m*/
    final Font font = mainData.getMainFrame().getFont();
    final FontRenderContext context = g2d.getFontRenderContext();
    final TextLayout tl = new TextLayout(text,
            new Font(font.getName(), font.getStyle(), (int) (font.getSize() * fontSizeFactor)), context);
    textLayoutCache.put(fontSizeFactor + ":" + text, tl);
    return tl;
}

From source file:lcmc.gui.ResourceGraph.java

/** Returns layout of the text that will be drawn on the vertex. */
private TextLayout getVertexTextLayout(final Graphics2D g2d, final String text, final double fontSizeFactor) {
    final TextLayout ctl = textLayoutCache.get(fontSizeFactor + ':' + text);
    if (ctl != null) {
        return ctl;
    }//from ww w.  j  a v a2s  .  c o m
    final Font font = Tools.getGUIData().getMainFrame().getFont();
    final FontRenderContext context = g2d.getFontRenderContext();
    TextLayout tl = new TextLayout(text,
            new Font(font.getName(), font.getStyle(), (int) (font.getSize() * fontSizeFactor)), context);
    textLayoutCache.put(fontSizeFactor + ':' + text, tl);
    return tl;
}

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

/**
 * Reset all day labels back to plain font.
 *//*from w  w w .  j  a va2s. c om*/
private void resetAllDayLabels() {
    JLabel[] labels = { jLabel9, jLabel10, jLabel11, jLabel12, jLabel13, jLabel14, jLabel5, jLabel6 };
    for (JLabel label : labels) {
        final Font oldFont = label.getFont();
        // Reset BOLD attribute.
        final Font font = oldFont.deriveFont(oldFont.getStyle() & ~Font.BOLD);
        label.setFont(font);
    }
}

From source file:v800_trainer.JCicloTronic.java

public static void setFontSizeGlobal(String font, int size) {
    for (Enumeration e = UIManager.getDefaults().keys(); e.hasMoreElements();) {
        Object key = e.nextElement();
        Object value = UIManager.get(key);

        if (value instanceof Font) {
            Font f = (Font) value;

            UIManager.put(key, new javax.swing.plaf.FontUIResource(font, f.getStyle(), size));
        }/*  w  ww  .jav a2s . co m*/
    }
}