Example usage for java.awt Font deriveFont

List of usage examples for java.awt Font deriveFont

Introduction

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

Prototype

public Font deriveFont(int style, AffineTransform trans) 

Source Link

Document

Creates a new Font object by replicating this Font object and applying a new style and transform.

Usage

From source file:ca.sqlpower.architect.swingui.ProfileGraphPanel.java

public ProfileGraphPanel(ProfilePanel panel, int rowCount) {
    this.profilePanel = panel;
    this.rowCount = rowCount;

    FormLayout displayLayout = new FormLayout("4dlu, default, 4dlu, 100dlu, 4dlu, fill:default:grow, 4dlu", // columns
            "4dlu, default, 6dlu"); // rows
    CellConstraints cc = new CellConstraints();

    validResultsPanel = ProfileGraphPanel.logger.isDebugEnabled() ? new FormDebugPanel(displayLayout)
            : new JPanel(displayLayout);
    validResultsPanel.setBorder(BorderFactory.createEtchedBorder());

    Font bodyFont = validResultsPanel.getFont();
    Font titleFont = bodyFont.deriveFont(Font.BOLD, bodyFont.getSize() * 1.25F);

    title = new JLabel("Column Name");
    title.setFont(titleFont);//  w w w .j a va2 s.  c  o m

    PanelBuilder pb = new PanelBuilder(displayLayout, validResultsPanel);
    pb.add(title, cc.xyw(2, 2, 5));

    int row = 4;
    rowCountDisplay = makeInfoRow(pb, "RowCount", row);
    row += 2;
    nullableLabel = makeInfoRow(pb, "Nullable", row);
    row += 2;
    nullCountLabel = makeInfoRow(pb, "Null Count", row);
    row += 2;
    nullPercentLabel = makeInfoRow(pb, "% Null Records", row);
    row += 2;
    minLengthLabel = makeInfoRow(pb, "Minimum Length", row);
    row += 2;
    maxLengthLabel = makeInfoRow(pb, "Maximum Length", row);
    row += 2;
    uniqueCountLabel = makeInfoRow(pb, "Unique Values", row);
    row += 2;
    uniquePercentLabel = makeInfoRow(pb, "% Unique", row);
    row += 2;
    minValue = makeInfoRow(pb, "Minimum Value", row);
    row += 2;
    maxValue = makeInfoRow(pb, "Maximum Value", row);
    row += 2;
    avgValue = makeInfoRow(pb, "Average Value", row);
    row += 2;

    freqValueTable = new FreqValueTable(null);
    freqValueSp = new JScrollPane(freqValueTable);

    pb.appendRow("fill:10dlu:grow");
    pb.appendRow("fill:default:grow");
    pb.add(freqValueSp, cc.xyw(2, row + 1, 3));

    // Now add something to represent the chart
    JFreeChart createPieChart = ChartFactory.createPieChart("", new DefaultPieDataset(new DefaultKeyedValues()),
            false, false, false);
    chartPanel = new ChartPanel(createPieChart);
    chartPanel.setPreferredSize(new Dimension(300, 300));

    if (panel.getProfileManager().getWorkspaceContainer() instanceof ArchitectSession
            && ((ArchitectSession) panel.getProfileManager().getWorkspaceContainer()).isEnterpriseSession()) {
        pb.add(new JLabel("Column Profile Notes"), cc.xy(6, 2));
        notesField = new JTextArea();
        notesField.setLineWrap(true);
        notesField.setWrapStyleWord(true);
        JScrollPane notesScroll = new JScrollPane(notesField);
        notesScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        notesScroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        pb.add(notesScroll, cc.xywh(6, 4, 1, row - 4));

        pb.appendRow("fill:4dlu:grow");
        pb.appendRow("4dlu");

        pb.add(chartPanel, cc.xy(6, row + 1));
    } else {
        pb.appendRow("fill:4dlu:grow");
        pb.appendRow("4dlu");
        pb.add(chartPanel, cc.xywh(6, 4, 1, row - 2));
    }

    invalidResultsPanel = new JPanel(new BorderLayout());
    invalidResultsLabel = new JLabel("No error message yet");
    invalidResultsPanel.add(invalidResultsLabel);

    displayArea = new JPanel(new GridLayout(1, 1));
    displayArea.setPreferredSize(validResultsPanel.getPreferredSize());
}

From source file:nu.nethome.tools.protocol_analyzer.RawMessageDistributionWindow.java

private void configurePanelLooks(JFreeChart chart, int selectionSeries) {
    TextTitle title = chart.getTitle(); // fix title
    Font titleFont = title.getFont();
    titleFont = titleFont.deriveFont(Font.PLAIN, (float) 14.0);
    title.setFont(titleFont);//from w w  w .  j  a  v a  2s.co  m
    title.setPaint(Color.darkGray);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    XYLineAndShapeRenderer signalRenderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
    signalRenderer.setSeriesStroke(selectionSeries, new BasicStroke(5f));
}

From source file:savant.ucscexplorer.UCSCExplorerPlugin.java

private void buildUI() {
    topLevelPanel.removeAll();/*from   ww  w. j ava  2s. co  m*/
    topLevelPanel.setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.insets = new Insets(5, 5, 5, 5);

    try {
        UCSCDataSourcePlugin ucsc = getUCSCPlugin();
        ucsc.getConnection();
        JLabel cladeLabel = new JLabel("Clade:");
        gbc.anchor = GridBagConstraints.EAST;
        topLevelPanel.add(cladeLabel, gbc);

        cladeCombo = new JComboBox();
        cladeCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                UCSCDataSourcePlugin ucsc = getUCSCPlugin();
                String clade = (String) cladeCombo.getSelectedItem();
                genomeCombo.setModel(new DefaultComboBoxModel(ucsc.getCladeGenomes(clade)));
                genomeCombo.setSelectedItem(ucsc.getCurrentGenome(clade));
            }
        });

        gbc.anchor = GridBagConstraints.WEST;
        topLevelPanel.add(cladeCombo, gbc);

        JLabel genomeLabel = new JLabel("Genome:");
        gbc.anchor = GridBagConstraints.EAST;
        topLevelPanel.add(genomeLabel, gbc);

        genomeCombo = new JComboBox();
        genomeCombo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                buildProgressUI();
                new GroupsFetcher(getUCSCPlugin(), (GenomeDef) genomeCombo.getSelectedItem()) {
                    @Override
                    public void done(List<GroupDef> groups) {
                        if (groups != null) {
                            GridBagConstraints gbc = new GridBagConstraints();
                            gbc.gridwidth = GridBagConstraints.REMAINDER;
                            gbc.fill = GridBagConstraints.BOTH;
                            gbc.weightx = 1.0;
                            for (GroupDef g : groups) {
                                groupsPanel.add(new GroupPanel(g), gbc);
                            }

                            // Add a filler panel to force everything to the top.
                            gbc.weighty = 1.0;
                            groupsPanel.add(new JPanel(), gbc);
                            loadButton.setEnabled(true);
                            topLevelPanel.validate();
                        }
                    }

                    @Override
                    public void showProgress(double value) {
                        updateProgress(progressMessage, value);
                    }
                }.execute();
            }
        });
        gbc.anchor = GridBagConstraints.WEST;
        topLevelPanel.add(genomeCombo, gbc);

        loadButton = new JButton("Load Selected Tracks");
        loadButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    loadSelectedTracks();
                } catch (Throwable x) {
                    DialogUtils.displayException(getTitle(), "Unable to load selected tracks.", x);
                }
            }
        });
        gbc.anchor = GridBagConstraints.EAST;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        topLevelPanel.add(loadButton, gbc);

        groupsPanel = new GroupsPanel();
        groupsPanel.setLayout(new GridBagLayout());

        JScrollPane groupsScroller = new JScrollPane(groupsPanel,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        topLevelPanel.add(groupsScroller, gbc);

        buildProgressUI();

        GenomeUtils.addGenomeChangedListener(new Listener<GenomeChangedEvent>() {
            @Override
            public void handleEvent(GenomeChangedEvent event) {
                UCSCDataSourcePlugin ucsc = getUCSCPlugin();
                ucsc.selectGenomeDB(null);
                GenomeAdapter newGenome = event.getNewGenome();
                GenomeDef g = new GenomeDef(newGenome.getName(), null);
                String newClade = ucsc.findCladeForGenome(g);

                // newClade could be null if the user has opened a genome which has no UCSC equivalent.
                if (newClade != null) {
                    cladeCombo.setSelectedItem(newClade);
                }
            }
        });

        ucsc.selectGenomeDB(null);
        new CladesFetcher(getUCSCPlugin()) {
            @Override
            public void done(String selectedClade) {
                cladeCombo.setModel(new DefaultComboBoxModel(UCSCDataSourcePlugin.STANDARD_CLADES));
                if (selectedClade != null) {
                    cladeCombo.setSelectedItem(selectedClade);
                } else {
                    cladeCombo.setSelectedIndex(0);
                }
            }

            @Override
            public void showProgress(double value) {
                updateProgress(progressMessage, value);
            }
        }.execute();
    } catch (Exception x) {
        LOG.error("Unable to connect to UCSC database.", x);
        topLevelPanel.removeAll();
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.gridwidth = GridBagConstraints.REMAINDER;
        gbc.fill = GridBagConstraints.NONE;
        gbc.weightx = 0.0;
        gbc.weighty = 0.0;
        topLevelPanel.add(new JLabel("Unable to connect to UCSC database."), gbc);
        JLabel error = new JLabel(MiscUtils.getMessage(x));
        Font f = topLevelPanel.getFont();
        f = f.deriveFont(Font.ITALIC, f.getSize() - 2.0f);
        error.setFont(f);
        topLevelPanel.add(error, gbc);
    }
}

From source file:org.openmicroscopy.shoola.env.data.util.StatusLabel.java

/** Initializes the components.*/
private void initialize() {
    step = 0;/* ww  w .  j av a 2 s  .  co  m*/
    sizeUpload = 0;
    fileSize = "";
    seriesCount = 0;
    readerType = "";
    markedAsCancel = false;
    cancellable = true;
    totalUploadedSize = 0;
    generalLabel = new JLabel(DEFAULT_TEXT);
    Font f = generalLabel.getFont();
    Font derived = f.deriveFont(f.getStyle(), f.getSize() - 2);
    uploadBar = new JProgressBar(0, MAX);
    uploadBar.setFont(derived);
    uploadBar.setStringPainted(true);
    Dimension d = uploadBar.getPreferredSize();
    uploadBar.setPreferredSize(new Dimension(WIDTH, d.height));
    processingBar = new JProgressBar(0, STEPS.size());
    processingBar.setStringPainted(true);
    processingBar.setString(DEFAULT_TEXT);
    processingBar.setFont(derived);
    uploadBar.setVisible(false);
    processingBar.setVisible(false);
}

From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java

/**
 * Returns the component displaying the description of the script.
 *
 * @return See above./*w w w . j a v a2  s  .  c  om*/
 */
private JComponent buildDescriptionPane() {
    String description = script.getDescription();
    if (StringUtils.isBlank(description))
        return null;
    OMEWikiComponent area = new OMEWikiComponent(false);
    area.setEnabled(false);
    area.setText(description);
    JPanel content = new JPanel();
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    JLabel label = UIUtilities.setTextFont(script.getName());
    Font f = label.getFont();
    label.setFont(f.deriveFont(f.getStyle(), f.getSize() + 2));
    content.add(UIUtilities.buildComponentPanel(label));
    content.add(Box.createVerticalStrut(5));
    JPanel p = UIUtilities.buildComponentPanel(area);
    p.setBackground(BG_COLOR);
    area.setBackground(BG_COLOR);
    content.add(p);
    return content;
}

From source file:view.AppearanceSettingsDialog.java

private void changeLabel() {
    String fontLocation = getFontCbBox();

    try {// w  ww  .  ja va  2  s . c  o  m
        Font newFont = Font.createFont(Font.TRUETYPE_FONT, new File(getFontLocationByName(fontLocation)));
        Font font = null;

        if (cbBold.isSelected() && cbItalic.isSelected()) {
            font = newFont.deriveFont(Font.ITALIC + Font.BOLD, 36);
        } else if (cbBold.isSelected() && !cbItalic.isSelected()) {
            font = newFont.deriveFont(Font.BOLD, 36);
        } else if (!cbBold.isSelected() && cbItalic.isSelected()) {
            font = newFont.deriveFont(Font.ITALIC, 36);
        } else {
            font = newFont.deriveFont(Font.PLAIN, 36);
        }
        lblSampleText.setFont(font);
        return;
    } catch (FontFormatException ex) {
        Logger.getLogger(AppearanceSettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(AppearanceSettingsDialog.class.getName()).log(Level.SEVERE, null, ex);
    }

    if (cbBold.isSelected() && cbItalic.isSelected()) {
        lblSampleText.setFont(new Font(fontLocation, Font.BOLD + Font.ITALIC, 36));
    } else if (cbBold.isSelected() && !cbItalic.isSelected()) {
        lblSampleText.setFont(new Font(fontLocation, Font.BOLD, 36));
    } else if (!cbBold.isSelected() && cbItalic.isSelected()) {
        lblSampleText.setFont(new Font(fontLocation, Font.ITALIC, (Integer) 36));
    } else {
        lblSampleText.setFont(new Font(cbFontType.getSelectedItem().toString(), Font.PLAIN, (Integer) 36));
    }
}

From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java

/**
 * Builds the component displaying the parameters.
 *
 * @return See above.//from w  w w .j  a  v a 2s.c om
 */
private JPanel buildBody() {
    JPanel p = new JPanel();
    p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    double[] columns = { TableLayout.PREFERRED, 5, TableLayout.FILL };
    TableLayout layout = new TableLayout();
    layout.setColumn(columns);
    p.setLayout(layout);
    int row = 0;
    JComponent area = buildDescriptionPane();
    JComponent authorsPane = buildScriptDetails();
    if (area != null) {
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(area, "0," + row + ", 2, " + row);
        row++;
    }

    if (authorsPane != null) {
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(authorsPane, "0," + row + ", 2, " + row);
        row++;
    }
    layout.insertRow(row, 5);

    row++;
    Entry<String, ScriptComponent> entry;
    Iterator<Entry<String, ScriptComponent>> i = components.entrySet().iterator();
    ScriptComponent comp;
    int required = 0;
    while (i.hasNext()) {
        entry = i.next();
        comp = entry.getValue();
        layout.insertRow(row, TableLayout.PREFERRED);
        comp.buildUI();
        if (comp.isRequired())
            required++;
        p.add(comp, "0," + row + ", 2, " + row);
        row++;
        layout.insertRow(row, 2);
        row++;
    }
    if (required > 0) {
        JLabel label = new JLabel(TEXT_END);
        Font font = label.getFont();
        label.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2));
        label.setForeground(UIUtilities.REQUIRED_FIELDS_COLOR);
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(UIUtilities.buildComponentPanel(label), "0," + row + ",2, " + row);
    }

    JPanel controls = new JPanel();
    controls.setLayout(new BorderLayout(0, 0));
    controls.add(new JScrollPane(p), BorderLayout.CENTER);
    controls.add(buildControlPanel(), BorderLayout.SOUTH);
    return controls;
}

From source file:literarytermsquestionbank.AChristmasCarol.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    // Set window icon
    this.setIconImage(Toolkit.getDefaultToolkit()
            .getImage(getClass().getResource("/Resources/Images/book-icon_acc.png")));

    // Set custom fonts
    try {/*from   w  ww . ja  va  2  s  . c  o  m*/
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

        // Load Gill Sans from resources
        Font gillSansFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/GILLSANS.TTF"));
        ge.registerFont(gillSansFontFace);

        tabbedPane.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        questionLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));
        checkButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        youAreViewingLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));
        quoteIndexTextField.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 24f));
        totalNumberLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 36f));
        goButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 20f));
        randomButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 20f));
        backButton.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        clueLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        passageLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));
        exampleLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));
        commentsLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        realAnswerLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 14f));
        realAnswerTitleLabel.setFont(gillSansFontFace.deriveFont(Font.PLAIN, 18f));

        // Load the FreeStyle Script font from resources
        Font freeStyleFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/FREESCPT.TTF"));
        ge.registerFont(freeStyleFontFace);
        salutationLabel.setFont(freeStyleFontFace.deriveFont(Font.PLAIN, 30f));
        signatureLabel.setFont(freeStyleFontFace.deriveFont(Font.PLAIN, 30f));

    } catch (FontFormatException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    }

    JSONParser parser = new JSONParser();

    try {
        // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package.
        Object quoteObj = parser
                .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json")));

        // This casts the object to a JSONObject for future manipulation
        JSONObject jsonObject = (JSONObject) quoteObj;

        // This array holds all the quotes
        JSONArray quotesArray = (JSONArray) jsonObject.get("A Christmas Carol");
        Iterator<JSONObject> iterator = quotesArray.iterator();

        // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList
        while (iterator.hasNext()) {
            Collections.addAll(quotesList, iterator.next());
            totalNumberOfQuotes++;
        }

        // Init randomizer
        Random rand = new Random();

        // Generate a random integer between 1 and size of the ArrayList
        quoteIndex = rand.nextInt(quotesList.size()) + 1;

        generateQuote(quoteIndex); // This calls a method to generate a quote and display it
    } catch (Exception e) { // This means something went very wrong when starting the program
        System.out.println("Uh oh, something bad happened. Possible database corruption.");
        JOptionPane.showMessageDialog(null,
                "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }
}

From source file:view.AppearanceSettingsDialog.java

/**
 * Creates new form NewJDialog//from  w w  w.  j  a v  a2 s . 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();
}

From source file:literarytermsquestionbank.RomeoAndJuliet.java

private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
    // Set custom  icon
    this.setIconImage(
            Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Resources/Images/book-icon_rj.png")));

    // Set custom fonts
    try {//  w  w w .j  a  va  2 s .  c o m
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();

        // Load Old English from resources
        Font englishFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/OLDENGL.TTF"));
        ge.registerFont(englishFontFace);
        actLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 30f));
        sceneLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 16f));
        lineNumberLabel.setFont(englishFontFace.deriveFont(Font.PLAIN, 16f));

        // Load Matura Script font from resources
        Font maturaFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/MATURASC.TTF"));
        ge.registerFont(maturaFontFace);
        tabbedPane.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        questionLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        checkButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        stuckLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        rescueButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        answerLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        youAreViewingLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        quoteIndexTextField.setFont(maturaFontFace.deriveFont(Font.PLAIN, 24f));
        totalNumberLabel.setFont(maturaFontFace.deriveFont(Font.PLAIN, 36f));
        goButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 24f));
        randomButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 18f));
        previousButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        nextButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));
        backButton.setFont(maturaFontFace.deriveFont(Font.PLAIN, 14f));

        // Load Corsova font from resources
        Font corsovaFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/MTCORSVA.TTF"));
        ge.registerFont(corsovaFontFace);
        clueLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f));
        passageLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f));
        examplesLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 18f));
        commentsLabel.setFont(corsovaFontFace.deriveFont(Font.PLAIN, 14f));

        // Load Imprint font from resources
        Font imprintFontFace = Font.createFont(Font.TRUETYPE_FONT,
                getClass().getResourceAsStream("/Resources/Fonts/IMPRISHA.TTF"));
        ge.registerFont(imprintFontFace);
        quoteTopLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
        quoteBottomLabel.setFont(imprintFontFace.deriveFont(Font.PLAIN, 48f));
    } catch (FontFormatException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(RomeoAndJuliet.class.getName()).log(Level.SEVERE, null, ex);
    }

    JSONParser parser = new JSONParser();

    try {
        // This object is the result of parsing the JSON file at the relative filepath as defined above; the JSON file is in the Resources source package.
        Object quoteObj = parser
                .parse(new InputStreamReader(getClass().getResourceAsStream("/Resources/Files/db.json")));

        // This casts the object to a JSONObject for future manipulation
        JSONObject jsonObject = (JSONObject) quoteObj;

        // This array holds all the quotes
        JSONArray quotesArray = (JSONArray) jsonObject.get("Romeo and Juliet");
        Iterator<JSONObject> iterator = quotesArray.iterator();

        // Using the iterator as declared above, add each JSONObject in the Romeo and Juliet array to the ArrayList
        while (iterator.hasNext()) {
            Collections.addAll(quotesList, iterator.next());
            totalNumberOfQuotes++;
        }

        // Init randomizer
        Random rand = new Random();

        // Generate a random integer between 1 and size of the ArrayList
        quoteIndex = rand.nextInt(quotesList.size()) + 1;

        generateQuote(quoteIndex); // This calls a method to generate a quote and display it
    } catch (Exception e) { // This means something went very wrong when starting the program
        System.out.println("Uh oh, something bad happened. Possible database corruption.");
        JOptionPane.showMessageDialog(null,
                "Something went wrong while starting the app! Please tell Aaron with code 129.", "Uh-oh!",
                JOptionPane.ERROR_MESSAGE);
        e.printStackTrace();
    }
}