in languagetool-standalone/src/main/java/org/languagetool/gui/FontChooser.java [120:313]
private void initComponents() {
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "Hide");
getRootPane().getActionMap().put("Hide", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectedFont = null;
setVisible(false);
}
});
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
selectedFont = null;
setVisible(false);
}
});
setTitle(messages.getString("FontChooser.title"));
fontStylesArray = new String[]{
messages.getString("FontChooser.style.plain"),
messages.getString("FontChooser.style.bold"),
messages.getString("FontChooser.style.italic"),
messages.getString("FontChooser.style.bold_italic")
};
String[] fontNamesArray = GraphicsEnvironment
.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
getContentPane()
.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(4, 4, 4, 4);
JPanel fontPanel = new JPanel(new GridBagLayout());
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.HORIZONTAL;
JLabel fontNameLabel
= new JLabel(messages.getString("FontChooser.label.name"));
fontPanel.add(fontNameLabel, c);
c.gridx = 1;
c.gridy = 0;
JLabel fontStyleLabel
= new JLabel(messages.getString("FontChooser.label.style"));
fontPanel.add(fontStyleLabel, c);
c.gridx = 2;
c.gridy = 0;
JLabel fontSizeLabel
= new JLabel(messages.getString("FontChooser.label.size"));
fontPanel.add(fontSizeLabel, c);
c.gridx = 0;
c.gridy = 1;
c.weightx = 1.0;
c.fill = GridBagConstraints.HORIZONTAL;
fontNameTextField = new JTextField();
fontNameTextField.setEnabled(false);
fontNameTextField.getDocument().addDocumentListener(this);
fontPanel.add(fontNameTextField, c);
c.weightx = 0.0;
c.gridx = 1;
c.gridy = 1;
fontStyleTextField = new JTextField();
fontStyleTextField.setEnabled(false);
fontStyleTextField.getDocument().addDocumentListener(this);
fontPanel.add(fontStyleTextField, c);
c.gridx = 2;
c.gridy = 1;
fontSizeTextField = new JTextField();
fontSizeTextField.setColumns(4);
fontSizeTextField.getDocument().addDocumentListener(this);
fontPanel.add(fontSizeTextField, c);
c.gridx = 0;
c.gridy = 2;
c.weightx = 1.0;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
fontNameList = new JList<>(fontNamesArray);
fontNameList.addListSelectionListener(this);
fontNameList.setVisibleRowCount(5);
fontNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane fontNameListPane = new JScrollPane(fontNameList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
fontPanel.add(fontNameListPane, c);
c.gridx = 1;
c.gridy = 2;
c.weightx = 0.5;
fontStyleList = new JList<>(fontStylesArray);
fontStyleList.addListSelectionListener(this);
fontStyleList.setVisibleRowCount(5);
fontStyleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane fontStyleListPane = new JScrollPane(fontStyleList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
fontPanel.add(fontStyleListPane, c);
c.gridx = 2;
c.gridy = 2;
fontSizeList = new JList<>(fontSizesArray);
fontSizeList.addListSelectionListener(this);
fontSizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fontSizeList.setVisibleRowCount(5);
JScrollPane fontSizeListPane = new JScrollPane(fontSizeList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
fontPanel.add(fontSizeListPane, c);
c.insets = new Insets(8, 8, 4, 8);
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.0;
c.weighty = 0.4;
getContentPane().add(fontPanel, c);
c.insets = new Insets(4, 8, 4, 8);
c.gridx = 0;
c.gridy = 1;
c.weightx = 1.0;
c.weighty = 0.6;
previewArea = new JTextArea(messages.getString("FontChooser.pangram"));
previewArea.setLineWrap(true);
previewArea.setRows(4);
JScrollPane pane = new JScrollPane(previewArea);
TitledBorder border = BorderFactory.createTitledBorder(
messages.getString("FontChooser.preview"));
pane.setBorder(border);
getContentPane().add(pane, c);
JPanel buttonPanel = new JPanel(new GridBagLayout());
c.insets = new Insets(4, 4, 4, 4);
c.gridx = 0;
c.gridy = 0;
c.weightx = 1.0;
c.weighty = 0.0;
c.anchor = GridBagConstraints.LINE_START;
c.fill = GridBagConstraints.NONE;
JButton resetButton = new JButton(Tools.getLabel(
messages.getString("FontChooser.reset")));
resetButton.setMnemonic(Tools.getMnemonic(
messages.getString("FontChooser.reset")));
resetButton.setActionCommand(ACTION_COMMAND_RESET);
resetButton.addActionListener(this);
buttonPanel.add(resetButton, c);
c.gridx = 1;
c.gridy = 0;
c.weightx = 0.0;
c.weighty = 0.0;
c.anchor = GridBagConstraints.LINE_END;
c.fill = GridBagConstraints.NONE;
JButton cancelButton = new JButton(Tools.getLabel(
messages.getString("guiCancelButton")));
cancelButton.setMnemonic(Tools.getMnemonic(
messages.getString("guiCancelButton")));
cancelButton.setActionCommand(ACTION_COMMAND_CANCEL);
cancelButton.addActionListener(this);
buttonPanel.add(cancelButton, c);
c.gridx = 2;
c.gridy = 0;
JButton okButton = new JButton(Tools.getLabel(
messages.getString("guiOKButton")));
okButton.setMnemonic(Tools.getMnemonic(
messages.getString("guiOKButton")));
okButton.setActionCommand(ACTION_COMMAND_OK);
okButton.addActionListener(this);
buttonPanel.add(okButton, c);
c.insets = new Insets(4, 8, 8, 8);
c.gridx = 0;
c.gridy = 2;
c.anchor = GridBagConstraints.LINE_START;
c.fill = GridBagConstraints.HORIZONTAL;
getContentPane().add(buttonPanel, c);
this.defaultFont = previewArea.getFont();
setDefaultFont();
getRootPane().setDefaultButton(cancelButton);
this.applyComponentOrientation(
ComponentOrientation.getOrientation(Locale.getDefault()));
pack();
}