Example usage for java.awt Font ITALIC

List of usage examples for java.awt Font ITALIC

Introduction

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

Prototype

int ITALIC

To view the source code for java.awt Font ITALIC.

Click Source Link

Document

The italicized style constant.

Usage

From source file:net.sf.jasperreports.engine.util.JRFontUtil.java

/**
 * Returns font information containing the font family, font face and font style.
 * /*from w w w.j a  v a 2s . c om*/
 * @param name the font family or font face name
 * @param locale the locale
 * @return a font info object
 */
public static FontInfo getFontInfo(String name, Locale locale) {
    //FIXMEFONT do some cache
    List<FontFamily> families = ExtensionsEnvironment.getExtensionsRegistry().getExtensions(FontFamily.class);
    for (Iterator<FontFamily> itf = families.iterator(); itf.hasNext();) {
        FontFamily family = itf.next();
        if (locale == null || family.supportsLocale(locale)) {
            if (name.equals(family.getName())) {
                return new FontInfo(family, null, Font.PLAIN);
            }
            FontFace face = family.getNormalFace();
            if (face != null && name.equals(face.getName())) {
                return new FontInfo(family, face, Font.PLAIN);
            }
            face = family.getBoldFace();
            if (face != null && name.equals(face.getName())) {
                return new FontInfo(family, face, Font.BOLD);
            }
            face = family.getItalicFace();
            if (face != null && name.equals(face.getName())) {
                return new FontInfo(family, face, Font.ITALIC);
            }
            face = family.getBoldItalicFace();
            if (face != null && name.equals(face.getName())) {
                return new FontInfo(family, face, Font.BOLD | Font.ITALIC);
            }
        }
    }
    //throw new JRRuntimeException("Font family/face named '" + name + "' not found.");
    return null;
}

From source file:j2se.jfreechart.barchart.BarChartDemo7.java

/**
 * Creates a sample chart.//w ww. j a  va  2s.c  o  m
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 7", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final IntervalMarker target = new IntervalMarker(4.5, 7.5);
    target.setLabel("Target Range");
    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0.10);

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    //      renderer.setLabelGenerator(new BarChartDemo7.LabelGenerator());
    renderer.setItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT,
            TextAnchor.CENTER_RIGHT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPosition(p);

    final ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPositionFallback(p2);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartSvgRenderer.java

byte[] renderJFreeChart(JFreeChart chart, float width, float height, boolean naked, Date fromDate, Date toDate)
        throws IOException {
    String svgNamespaceUri = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document doc = SVGDOMImplementation.getDOMImplementation().createDocument(svgNamespaceUri, "svg", null);

    String generatedText = "Generated "
            + DateUtils.formatAsStringToLong(new Date(), UserContext.getCurrentLocale()) + " by "
            + MessageAccess.getStringOrNull("global.applicationname", UserContext.getCurrentLocale()) + " "
            + properties.getBuildId();/*from  www  .  jav a  2  s .  c  o  m*/
    String drawingInfo = MessageAccess.getStringOrNull("graphicalExport.timeline.drawInfo",
            UserContext.getCurrentLocale()) + ": "
            + DateUtils.formatAsString(fromDate, UserContext.getCurrentLocale()) + " -> "
            + DateUtils.formatAsString(toDate, UserContext.getCurrentLocale());

    SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc);
    ctx.setComment(generatedText);
    SVGGraphics2D svgGraphics = new SVGGraphics2D(ctx, false);

    if (!naked) {
        //Render the chart to the SVG graphics object
        chart.draw(svgGraphics, new Rectangle(20, 20, Math.round(width - MARGIN), Math.round(height - MARGIN)));

        //Add logo and generated text
        int widthIntForLogo = Math.round(width + 40 - MARGIN);
        int heightIntForLogo = Math.round(height - MARGIN + 20);

        int xLogoUpperRightCorner[] = { widthIntForLogo - 40, widthIntForLogo, widthIntForLogo,
                widthIntForLogo - 8, widthIntForLogo - 8, widthIntForLogo - 40 };
        int yLogoUpperRightCorner[] = { MARGIN_TOP, MARGIN_TOP, MARGIN_TOP + 40, MARGIN_TOP + 40,
                MARGIN_TOP + 8, MARGIN_TOP + 8 };

        GeneralPath logoUpperRightCorner = new GeneralPath();
        logoUpperRightCorner.moveTo(xLogoUpperRightCorner[0], yLogoUpperRightCorner[0]);
        for (int i = 1; i < xLogoUpperRightCorner.length; i++) {
            logoUpperRightCorner.lineTo(xLogoUpperRightCorner[i], yLogoUpperRightCorner[i]);
        }
        logoUpperRightCorner.closePath();
        svgGraphics.setColor(Color.decode(COLOR_LOGO));
        svgGraphics.fill(logoUpperRightCorner);
        svgGraphics.draw(logoUpperRightCorner);

        int xLogoLowerLeftCorner[] = { MARGIN_LEFT, MARGIN_LEFT + 8, MARGIN_LEFT + 8, MARGIN_LEFT + 40,
                MARGIN_LEFT + 40, MARGIN_LEFT };
        int yLogoLowerLeftCorner[] = { heightIntForLogo, heightIntForLogo, heightIntForLogo + 32,
                heightIntForLogo + 32, heightIntForLogo + 40, heightIntForLogo + 40 };

        GeneralPath logoLowerLeftCorner = new GeneralPath();
        logoLowerLeftCorner.moveTo(xLogoLowerLeftCorner[0], yLogoLowerLeftCorner[0]);
        for (int i = 1; i < xLogoLowerLeftCorner.length; i++) {
            logoLowerLeftCorner.lineTo(xLogoLowerLeftCorner[i], yLogoLowerLeftCorner[i]);
        }
        logoLowerLeftCorner.closePath();
        svgGraphics.setColor(Color.BLACK);
        svgGraphics.fill(logoLowerLeftCorner);
        svgGraphics.draw(logoLowerLeftCorner);

        Font f = new Font(null, Font.ITALIC, 12);
        svgGraphics.setFont(f);
        FontMetrics fontMetrics = svgGraphics.getFontMetrics(f);
        int charsWidthInfo = fontMetrics.stringWidth(drawingInfo);
        svgGraphics.drawString(drawingInfo, width - MARGIN - charsWidthInfo,
                height - MARGIN + MARGIN_DOWN_GENERATED_TEXT);
        int charsWidth = fontMetrics.stringWidth(generatedText);
        svgGraphics.drawString(generatedText, width - MARGIN - charsWidth,
                height - MARGIN + MARGIN_DOWN_GENERATED_TEXT + 20);

    } else {
        chart.draw(svgGraphics,
                new Rectangle(20, 20, Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN),
                        Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN)));
    }

    svgGraphics.setSVGCanvasSize(new Dimension((int) width, (int) height));

    //Convert the SVGGraphics2D object to SVG XML 
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer out = new OutputStreamWriter(baos, "UTF-8");
    svgGraphics.stream(out, true);
    byte[] originalSvgXml = baos.toByteArray();

    //    return originalSvgXml;
    return addAdditionalAttributes(originalSvgXml);
}

From source file:org.mars_sim.msp.ui.swing.demo.BarChartDemo7.java

/**
 * Creates a sample chart./*from   w  ww  . j a  v a  2 s  . c om*/
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
*/
private JFreeChart createChart(final CategoryDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo 7", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            false, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final IntervalMarker target = new IntervalMarker(4.5, 7.5);
    target.setLabel("Target Range");
    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    final BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    //renderer.setItemMargin(0.10);
    renderer.setMaximumBarWidth(.5); // set maximum width to 35% of chart

    // set up gradient paints for series...
    final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    //      renderer.setLabelGenerator(new BarChartDemo7.LabelGenerator());
    renderer.setDefaultItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT,
            TextAnchor.CENTER_RIGHT, -Math.PI / 2.0);
    renderer.setDefaultPositiveItemLabelPosition(p);

    final ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPositionFallback(p2);
    final CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:net.sf.dynamicreports.test.jasper.chart.XyBlockChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/*  w w  w . j  av  a 2 s . co m*/

    JFreeChart chart = getChart("summary.chart1", 0);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    Assert.assertEquals("renderer", XYBlockRenderer.class, renderer.getClass());
    Assert.assertEquals("block width", 1.1, ((XYBlockRenderer) renderer).getBlockWidth());
    Assert.assertEquals("block height", 0.9, ((XYBlockRenderer) renderer).getBlockHeight());
    Assert.assertEquals("block anchor", org.jfree.ui.RectangleAnchor.BOTTOM_LEFT,
            ((XYBlockRenderer) renderer).getBlockAnchor());

    Assert.assertEquals("paintScale", LookupPaintScale.class,
            ((XYBlockRenderer) renderer).getPaintScale().getClass());
    LookupPaintScale paintScale = (LookupPaintScale) ((XYBlockRenderer) renderer).getPaintScale();
    Assert.assertEquals("paintScale default lower bound", 0.1, paintScale.getLowerBound());
    Assert.assertEquals("paintScale default upper bound", 5d, paintScale.getUpperBound());
    Assert.assertEquals("paintScale default paint", Color.WHITE, paintScale.getDefaultPaint());
    Assert.assertEquals("paintScale paint 1", Color.RED, paintScale.getPaint(1));
    Assert.assertEquals("paintScale paint 2", Color.GREEN, paintScale.getPaint(2));
    Assert.assertEquals("paintScale paint 3", Color.BLUE, paintScale.getPaint(3));

    LegendItemCollection legendItems = chart.getXYPlot().getLegendItems();
    Assert.assertEquals("legend item 1 label", "1", legendItems.get(0).getLabel());
    Assert.assertEquals("legend item 1 paint", Color.RED, legendItems.get(0).getFillPaint());
    Assert.assertEquals("legend item 2 label", "2", legendItems.get(1).getLabel());
    Assert.assertEquals("legend item 2 paint", Color.GREEN, legendItems.get(1).getFillPaint());
    Assert.assertEquals("legend item 3 label", "3", legendItems.get(2).getLabel());
    Assert.assertEquals("legend item 3 paint", Color.BLUE, legendItems.get(2).getFillPaint());

    xyzChartDataTest(chart, 0, "serie0",
            new Number[][] { { 1d, 2d, 0d }, { 2d, 3d, 1d }, { 3d, 4d, 2d }, { 4d, 5d, 3d } });

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getXYPlot().getDomainAxis();
    Assert.assertEquals("category label", "category", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());

    chart = getChart("summary.chart3", 0);
    axis = chart.getXYPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
}

From source file:FontPicker.java

protected void updatePreviewFont() {
    String name = StyleConstants.getFontFamily(attributes);
    boolean bold = StyleConstants.isBold(attributes);
    boolean ital = StyleConstants.isItalic(attributes);
    int size = StyleConstants.getFontSize(attributes);

    //Bold and italic don't work properly in beta 4.
    Font f = new Font(name, (bold ? Font.BOLD : 0) + (ital ? Font.ITALIC : 0), size);
    previewLabel.setFont(f);// w w  w . j  av a2s  .  c o m
}

From source file:co.foldingmap.mapImportExport.SvgExporter.java

private void exportMapLabel(BufferedWriter outputStream, MapLabel label) {

    Color outlineColor, fillColor;
    float x, y;//from   w  w w .j ava2 s .  c  o  m
    Font labelFont;
    String style, fontStyle;

    try {
        labelFont = label.getFont();

        //construct style
        if (label.getFillColor() != null) {
            fillColor = label.getFillColor();
        } else {
            fillColor = Color.BLACK;
        }

        if (label.getOutlineColor() != null) {
            outlineColor = label.getOutlineColor();
        } else {
            outlineColor = Color.WHITE;
        }

        if (labelFont.getStyle() == Font.BOLD) {
            fontStyle = "font-weight=\"bold\"";
        } else if (labelFont.getStyle() == Font.PLAIN) {
            fontStyle = "font-style=\"normal\"";
        } else if (labelFont.getStyle() == Font.ITALIC) {
            fontStyle = "font-style=\"italic\"";
        } else {
            fontStyle = "";
        }

        style = "font-family=\"" + labelFont.getFamily() + "\" font-size=\"" + labelFont.getSize() + "\" "
                + fontStyle + " ";

        outputStream.write(getIndent());
        outputStream.write("<g " + style + ">\n");
        addIndent();

        style = "fill:#" + getHexColor(fillColor) + ";stroke:#" + getHexColor(outlineColor);

        if (label instanceof PointLabel) {
            PointLabel pointLabel = (PointLabel) label;

            x = pointLabel.getLine1StartPoint().x;
            y = pointLabel.getLine1StartPoint().y;

            outputStream.write(getIndent());
            outputStream.write("<text x=\"");
            outputStream.write(Float.toString(x));
            outputStream.write("\" y=\"");
            outputStream.write(Float.toString(y));
            outputStream.write("\" style=\"");
            outputStream.write(style);
            outputStream.write("\">\n");

            addIndent();
            outputStream.write(getIndent());
            outputStream.write("<tspan x=\"");
            outputStream.write(Float.toString(x));
            outputStream.write("\" y=\"");
            outputStream.write(Float.toString(y));
            outputStream.write("\">");
            outputStream.write(pointLabel.getLine1Text());
            outputStream.write("</tspan>\n");

            if (pointLabel.getLine2Text() != null && pointLabel.getLine2Text().length() > 0) {
                x = pointLabel.getLine2StartPoint().x;
                y = pointLabel.getLine2StartPoint().y;

                if (x != 0 && y != 0) {
                    outputStream.write(getIndent());
                    outputStream.write("<tspan x=\"");
                    outputStream.write(Float.toString(x));
                    outputStream.write("\" y=\"");
                    outputStream.write(Float.toString(y));
                    outputStream.write("\">");
                    outputStream.write(pointLabel.getLine2Text());
                    outputStream.write("</tspan>\n");
                }
            }

            removeIndent();
            outputStream.write(getIndent());
            outputStream.write("</text>\n");

            removeIndent();
            outputStream.write(getIndent());
            outputStream.write("</g>\n");
        } else if (label instanceof LineStringLabel) {
            LineStringLabel lineLabel = (LineStringLabel) label;

        } else if (label instanceof PolygonLabel) {
            PolygonLabel polyLabel = (PolygonLabel) label;

        }

    } catch (Exception e) {
        Logger.log(Logger.ERR, "Error in SvgExporter.exportMapLabel(BufferedWriter, MapLabel) - " + e);
    }
}

From source file:wef.articulab.view.ui.CombinedBNXYPlot.java

public IntervalXYDataset refreshDataset(ChartContainer chartContainer) {
    if (chartContainer.behaviors != null) {
        double max = 0;
        int sizeSeries = chartContainer.series.length - 1;

        //keep number of samples no bigger than maxNumSamples
        if (chartContainer.behaviors[0].size() > maxNumSamples) {
            for (int i = 0; i < sizeSeries; i++) {
                chartContainer.behaviors[i].remove(0);
            }/*w w w . ja v  a  2s  . com*/
            chartContainer.thresholds.remove(0);
            chartContainer.activations.remove(0);
            chartContainer.offset++;
        }

        //Activation thresholds
        XYSeries ts = chartContainer.dataset.getSeries(chartContainer.series[sizeSeries]);
        ts.clear();
        for (int j = 0; j < chartContainer.thresholds.size(); j++) {
            ts.addOrUpdate(j + chartContainer.offset, chartContainer.thresholds.get(j).doubleValue());
        }
        chartContainer.target.setStartValue(chartContainer.minThreshold);
        chartContainer.target.setEndValue(chartContainer.maxThreshold);

        //behaviors
        for (int i = 0; i < sizeSeries; i++) {
            int size = chartContainer.behaviors[i].size();
            ts = chartContainer.dataset.getSeries(chartContainer.series[i]);
            ts.clear();
            for (int j = 0; j < size; j++) {
                double behActivation = chartContainer.behaviors[i].get(j);
                if (behActivation > max) {
                    max = behActivation;
                }
                ts.add(j + chartContainer.offset, behActivation);
            }
        }

        //who is activated?
        for (int x = 0; x < chartContainer.activations.size(); x++) {
            String name = (String) chartContainer.activations.get(x)[0];
            double y = (Double) chartContainer.activations.get(x)[1];
            if (name != null && !name.isEmpty()) {
                XYTextAnnotation annotation = new XYTextAnnotation(name, (x + chartContainer.offset), y);
                annotation.setFont(new Font("SansSerif", Font.ITALIC, 11));
                chartContainer.plot.addAnnotation(annotation);
            }
        }

        // container range
        chartContainer.plot.getDomainAxis().setRange(chartContainer.offset,
                chartContainer.offset + maxNumSamples - 1);
        chartContainer.plot.getRangeAxis().setRange(0, max + 5);
        chartContainer.chart.fireChartChanged();
    }
    return chartContainer.dataset;
}

From source file:edu.ku.brc.specify.utilapps.ERDTable.java

/**
 * @param font/* w w  w . j  a  va 2 s.c o m*/
 */
public void build(final Font font) {
    int numRows = 7;
    switch (displayType) {
    case All:
        numRows = 7;
        break;
    case MainFields:
        numRows = 7;
        break;
    case Title:
        numRows = 1;
        break;
    case TitleAndRel:
        numRows = 4;
        break;

    }
    Font bold = new Font(font.getFamily(), Font.BOLD, font.getSize());
    Font italic = new Font(font.getFamily(), Font.ITALIC, font.getSize());
    PanelBuilder pb = new PanelBuilder(
            new FormLayout("f:p:g", UIHelper.createDuplicateJGoodiesDef("p", "2px", numRows)));
    CellConstraints cc = new CellConstraints();

    String className = StringUtils.substringAfterLast(table.getClassName(), ".");
    DBTableInfo tblInfo = DBTableIdMgr.getInstance().getByShortClassName(className);
    if (tblInfo == null) {
        throw new RuntimeException("Couldn't find table for className[" + className + "]");
    }
    String tblName = tblInfo.getTitle();
    int y = 1;
    pb.add(ERDVisualizer.mkLabel(bold, tblName, SwingConstants.CENTER), cc.xy(1, y));
    y += 2;

    boolean doingAll = displayType == DisplayType.All;
    if (displayType == DisplayType.All || displayType == DisplayType.MainFields) {
        pb.addSeparator("", cc.xy(1, y));
        y += 2;

        pb.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_FIELDS"), SwingConstants.CENTER),
                cc.xy(1, y));
        y += 2;

        String colsDef = "p:g,4px,p:g,4px" + (doingAll ? ",p:g,4px,p:g,4px" : "") + ",f:p:g";
        PanelBuilder fieldsPB = new PanelBuilder(new FormLayout(colsDef,
                UIHelper.createDuplicateJGoodiesDef("p", "2px", table.getFields().size() + 2)));
        int yy = 1;

        fieldsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_FIELD"), SwingConstants.LEFT),
                cc.xy(1, yy));
        fieldsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_TYPE"), SwingConstants.CENTER),
                cc.xy(3, yy));
        fieldsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_LENGTH"), SwingConstants.CENTER),
                cc.xy(5, yy));
        if (doingAll) {
            fieldsPB.add(
                    ERDVisualizer.mkLabel(italic, getResourceString("ERD_REQUIRED"), SwingConstants.CENTER),
                    cc.xy(7, yy));
            fieldsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_UNIQUE"), SwingConstants.CENTER),
                    cc.xy(9, yy));
        }
        yy += 2;

        if (StringUtils.isNotEmpty(table.getIdColumnName())) {
            build(fieldsPB, table, font, yy, doingAll); // does ID
            yy += 2;
        }

        for (DBFieldInfo f : table.getFields()) {
            build(fieldsPB, f, font, yy, doingAll);
            yy += 2;
        }
        pb.add(fieldsPB.getPanel(), cc.xy(1, y));
        y += 2;

    }

    if ((displayType == DisplayType.All || displayType == DisplayType.TitleAndRel)
            && table.getRelationships().size() > 0) {
        pb.addSeparator("", cc.xy(1, y));
        y += 2;

        pb.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_RELATIONSHIPS"), SwingConstants.CENTER),
                cc.xy(1, y));
        y += 2;

        String colsDef = "p:g,4px,p:g,4px" + (doingAll ? ",p:g,4px" : "") + ",f:p:g";
        PanelBuilder relsPB = new PanelBuilder(new FormLayout(colsDef,
                UIHelper.createDuplicateJGoodiesDef("p", "2px", table.getRelationships().size() + 1)));
        int yy = 1;

        relsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_TABLE"), SwingConstants.LEFT),
                cc.xy(1, yy));
        relsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_NAME"), SwingConstants.CENTER),
                cc.xy(3, yy));
        relsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_TYPE"), SwingConstants.CENTER),
                cc.xy(5, yy));
        if (doingAll) {
            relsPB.add(ERDVisualizer.mkLabel(italic, getResourceString("ERD_REQUIRED"), SwingConstants.CENTER),
                    cc.xy(7, yy));
        }
        yy += 2;

        Vector<DBRelationshipInfo> orderedList = new Vector<DBRelationshipInfo>(table.getRelationships());
        Collections.sort(orderedList, new Comparator<DBRelationshipInfo>() {
            public int compare(DBRelationshipInfo o1, DBRelationshipInfo o2) {
                String name1 = ((DBRelationshipInfo) o1).getClassName();
                if (name1.startsWith("Sp")) {
                    name1 = name1.substring(2, name1.length());
                }
                String name2 = ((DBRelationshipInfo) o2).getClassName();
                if (name2.startsWith("Sp")) {
                    name2 = name2.substring(2, name2.length());
                }
                return name1.compareTo(name2);
            }
        });

        for (DBRelationshipInfo r : orderedList) {
            //System.out.println(r.getName()+" "+r.getType());
            if (!r.getName().toLowerCase().endsWith("iface")) {
                JComponent p = build(relsPB, r, font, yy, doingAll);
                relUIHash.put(r, p);
                yy += 2;
            }
        }
        pb.add(relsPB.getPanel(), cc.xy(1, y));
        y += 2;

        //fieldsPB.getPanel().setBackground(Color.GREEN);
        //relsPB.getPanel().setBackground(Color.BLUE);
    }

    inner = pb.getPanel();
    //inner.setBorder(BorderFactory.createEmptyBorder(BRD_GAP, BRD_GAP, BRD_GAP, BRD_GAP));

    inner.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK),
            BorderFactory.createEmptyBorder(BRD_GAP, BRD_GAP, BRD_GAP, BRD_GAP)));

    setBackground(Color.WHITE);
    add(inner, BorderLayout.CENTER);
}

From source file:view.AppearanceSettingsDialog.java

/**
 * Creates new form NewJDialog// w  w  w. j  a  va  2s  . c o  m
 *
 * @param parent
 * @param modal
 * @param signatureSettings
 */
public AppearanceSettingsDialog(java.awt.Frame parent, boolean modal, CCSignatureSettings signatureSettings) {
    super(parent, modal);
    initComponents();
    this.signatureSettings = signatureSettings;

    updateText();

    // Pastas conforme o SO
    ArrayList<String> dirs = new ArrayList<>();
    if (SystemUtils.IS_OS_WINDOWS) {
        dirs.add(System.getenv("windir") + File.separator + "fonts");
    } else if (SystemUtils.IS_OS_LINUX) {
        dirs.add("/usr/share/fonts/truetype/");
        dirs.add("/usr/X11R6/lib/X11/fonts/");
    } else if (SystemUtils.IS_OS_MAC_OSX) {
        dirs.add("/Library/Fonts");
        dirs.add("/System/Library/Fonts");
    }
    dirs.add("extrafonts");

    // Hashmap com fonts
    hmFonts = getAllFonts(dirs);
    ArrayList<com.itextpdf.text.Font> alFonts = new ArrayList<>(hmFonts.keySet());

    Collections.sort(alFonts, new Comparator<com.itextpdf.text.Font>() {
        @Override
        public int compare(com.itextpdf.text.Font f1, com.itextpdf.text.Font f2) {
            return f1.getFamilyname().compareToIgnoreCase(f2.getFamilyname());
        }
    });

    DefaultComboBoxModel dcbm = new DefaultComboBoxModel();
    for (com.itextpdf.text.Font font : alFonts) {
        dcbm.addElement(font.getFamilyname());
    }
    cbFontType.setModel(dcbm);

    String fontLocation = signatureSettings.getAppearance().getFontLocation();
    boolean italic = signatureSettings.getAppearance().isItalic();
    boolean bold = signatureSettings.getAppearance().isBold();
    boolean showName = signatureSettings.getAppearance().isShowName();
    boolean showLocation = signatureSettings.getAppearance().isShowLocation();
    boolean showReason = signatureSettings.getAppearance().isShowReason();
    boolean showDate = signatureSettings.getAppearance().isShowDate();
    int align = signatureSettings.getAppearance().getAlign();

    switch (align) {
    case 0:
        cbAlign.setSelectedIndex(0);
        break;
    case 1:
        cbAlign.setSelectedIndex(1);
        break;
    case 2:
        cbAlign.setSelectedIndex(2);
        break;
    default:
        cbAlign.setSelectedIndex(0);
    }

    previewPanel1.setReason(signatureSettings.getReason());
    previewPanel1.setShowDate(showDate);

    if (signatureSettings.getCcAlias() != null) {
        previewPanel1.setAliasName(signatureSettings.getCcAlias().getName());
    } else {
        previewPanel1.setAliasName(Bundle.getBundle().getString("name"));
    }

    if (!signatureSettings.getLocation().isEmpty()) {
        previewPanel1.setLocation(signatureSettings.getLocation());
        cbShowLocation.setSelected(showLocation);
        previewPanel1.setShowLocation(showLocation);
    } else {
        cbShowLocation.setEnabled(false);
        cbShowLocation.setSelected(false);
    }

    cbShowName.setSelected(showName);
    previewPanel1.setShowName(showName);

    if (!signatureSettings.getReason().isEmpty()) {
        previewPanel1.setReason(signatureSettings.getReason());
        cbShowReason.setSelected(showReason);
        previewPanel1.setShowReason(showReason);
    } else {
        cbShowReason.setEnabled(false);
        cbShowReason.setSelected(false);
    }
    previewPanel1.setText(signatureSettings.getText());
    previewPanel1.setAlign(align);
    colorChooser.setPreviewPanel(new JPanel());
    Color color = signatureSettings.getAppearance().getFontColor();
    colorChooser.setColor(color);
    lblSampleText.setForeground(color);
    cbShowReason.setSelected(showReason);
    cbShowLocation.setSelected(showLocation);
    cbShowDateTime.setSelected(showDate);

    ColorSelectionModel model = colorChooser.getSelectionModel();
    ChangeListener changeListener = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent changeEvent) {
            Color newForegroundColor = colorChooser.getColor();
            lblSampleText.setForeground(newForegroundColor);
        }
    };
    model.addChangeListener(changeListener);

    if (fontLocation.contains("aCCinaPDF" + File.separator + "extrafonts")) {
        try {
            Font newFont = Font.createFont(Font.TRUETYPE_FONT, new File(fontLocation));
            Font font = null;
            if (italic && bold) {
                font = newFont.deriveFont(Font.ITALIC + Font.BOLD, 36);
            } else if (italic && !bold) {
                font = newFont.deriveFont(Font.ITALIC, 36);
            } else if (!italic && bold) {
                font = newFont.deriveFont(Font.BOLD, 36);
            } else {
                font = newFont.deriveFont(Font.PLAIN, 36);
            }
            lblSampleText.setFont(font);
        } catch (FontFormatException | IOException ex) {
        }
    } else {
        if (italic && bold) {
            lblSampleText.setFont(new Font(fontLocation, Font.ITALIC + Font.BOLD, 36));
        } else if (italic && !bold) {
            lblSampleText.setFont(new Font(fontLocation, Font.ITALIC, 36));
        } else if (!italic && bold) {
            lblSampleText.setFont(new Font(fontLocation, Font.BOLD, 36));
        } else {
            lblSampleText.setFont(new Font(fontLocation, Font.PLAIN, 36));
        }
    }

    cbBold.setSelected(bold);
    cbItalic.setSelected(italic);

    updateSettings(fontLocation, bold, italic);

    previewPanel1.repaint();
}