示例#1
0
 public void setSelectedFont(Font font) {
   selectedFont = font;
   family = font.getFamily();
   style = font.getStyle();
   size = font.getSize();
   preview.setFont(font);
 }
示例#2
0
 public static JTextArea getTextArea(String s) {
   JTextArea ret = new JTextArea(s);
   ret.setFont(new Font("Courier", Font.PLAIN, 12));
   ret.setTabSize(4);
   return ret;
 }
示例#3
0
  void jbInit() throws Exception {
    titledBorder1 =
        new TitledBorder(
            BorderFactory.createLineBorder(new Color(153, 153, 153), 2), "Assembler messages");
    this.getContentPane().setLayout(borderLayout1);

    this.setIconifiable(true);
    this.setMaximizable(true);
    this.setResizable(true);

    this.setTitle("EDIT");

    splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    splitPane.setDividerLocation(470);
    sourceArea.setFont(new java.awt.Font("Monospaced", 0, 12));
    controlPanel.setLayout(gridBagLayout1);
    controlPanel.setBorder(BorderFactory.createLoweredBevelBorder());
    positionPanel.setLayout(gridBagLayout2);
    fileLabel.setText("Source file:");
    fileText.setEditable(false);
    browseButton.setSelected(false);
    browseButton.setText("Browse ...");
    assembleButton.setEnabled(false);
    assembleButton.setText("Assemble file");
    saveButton.setEnabled(false);
    saveButton.setText("Save file");
    lineLabel.setText("Line:");
    lineText.setMinimumSize(new Dimension(50, 20));
    lineText.setPreferredSize(new Dimension(50, 20));
    lineText.setEditable(false);
    columnLabel.setText("Column:");
    columnText.setMinimumSize(new Dimension(41, 20));
    columnText.setPreferredSize(new Dimension(41, 20));
    columnText.setEditable(false);
    columnText.setText("");
    messageScrollPane.setBorder(titledBorder1);
    messageScrollPane.setMinimumSize(new Dimension(33, 61));
    messageScrollPane.setPreferredSize(new Dimension(60, 90));
    optionsButton.setEnabled(false);
    optionsButton.setText("Assembler options ...");
    messageScrollPane.getViewport().add(messageList, null);
    messageList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    this.getContentPane().add(splitPane, BorderLayout.CENTER);
    splitPane.add(textScrollPane, JSplitPane.TOP);
    splitPane.add(controlPanel, JSplitPane.BOTTOM);
    textScrollPane.getViewport().add(sourceArea, null);

    controlPanel.add(
        fileLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        fileText,
        new GridBagConstraints(
            1,
            0,
            3,
            1,
            1.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        browseButton,
        new GridBagConstraints(
            4,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));
    controlPanel.add(
        optionsButton,
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            1.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        assembleButton,
        new GridBagConstraints(
            3,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        saveButton,
        new GridBagConstraints(
            4,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 5),
            0,
            0));
    controlPanel.add(
        positionPanel,
        new GridBagConstraints(
            0,
            1,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(5, 5, 0, 0),
            0,
            0));
    positionPanel.add(
        lineLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0));
    positionPanel.add(
        lineText,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 0, 0),
            0,
            0));
    positionPanel.add(
        columnLabel,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 10, 0, 0),
            0,
            0));
    positionPanel.add(
        columnText,
        new GridBagConstraints(
            3,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(0, 5, 0, 0),
            0,
            0));
    controlPanel.add(
        messageScrollPane,
        new GridBagConstraints(
            0,
            2,
            5,
            1,
            1.0,
            1.0,
            GridBagConstraints.CENTER,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));
  }
示例#4
0
  /** Create a font chooser dialog for the specified frame. */
  public FontChooser(Frame owner) {
    super(owner, "Choose a Font"); // Set dialog frame and title

    // This dialog must be used as a modal dialog.  In order to be used
    // as a modeless dialog, it would have to fire a PropertyChangeEvent
    // whenever the selected font changed, so that applications could be
    // notified of the user's selections.
    setModal(true);

    // Figure out what fonts are available on the system
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    fontFamilies = env.getAvailableFontFamilyNames();

    // Set initial values for the properties
    family = fontFamilies[0];
    style = Font.PLAIN;
    size = 18;
    selectedFont = new Font(family, style, size);

    // Create ItemChooser objects that allow the user to select font
    // family, style, and size.
    families = new ItemChooser("Family", fontFamilies, null, 0, ItemChooser.COMBOBOX);
    styles = new ItemChooser("Style", styleNames, styleValues, 0, ItemChooser.COMBOBOX);
    sizes = new ItemChooser("Size", sizeNames, null, 4, ItemChooser.COMBOBOX);

    // Now register event listeners to handle selections
    families.addItemChooserListener(
        new ItemChooser.Listener() {
          public void itemChosen(ItemChooser.Event e) {
            setFontFamily((String) e.getSelectedValue());
          }
        });
    styles.addItemChooserListener(
        new ItemChooser.Listener() {
          public void itemChosen(ItemChooser.Event e) {
            setFontStyle(((Integer) e.getSelectedValue()).intValue());
          }
        });
    sizes.addItemChooserListener(
        new ItemChooser.Listener() {
          public void itemChosen(ItemChooser.Event e) {
            setFontSize(Integer.parseInt((String) e.getSelectedValue()));
          }
        });

    // Create a component to preview the font.
    preview = new JTextArea(defaultPreviewString, 5, 40);
    preview.setFont(selectedFont);

    // Create buttons to dismiss the dialog, and set handlers on them
    okay = new JButton("Okay");
    cancel = new JButton("Cancel");
    okay.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            hide();
          }
        });
    cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            selectedFont = null;
            hide();
          }
        });

    // Put the ItemChoosers in a Box
    Box choosersBox = Box.createHorizontalBox();
    choosersBox.add(Box.createHorizontalStrut(15));
    choosersBox.add(families);
    choosersBox.add(Box.createHorizontalStrut(15));
    choosersBox.add(styles);
    choosersBox.add(Box.createHorizontalStrut(15));
    choosersBox.add(sizes);
    choosersBox.add(Box.createHorizontalStrut(15));
    choosersBox.add(Box.createGlue());

    // Put the dismiss buttons in another box
    Box buttonBox = Box.createHorizontalBox();
    buttonBox.add(Box.createGlue());
    buttonBox.add(okay);
    buttonBox.add(Box.createGlue());
    buttonBox.add(cancel);
    buttonBox.add(Box.createGlue());

    // Put the choosers at the top, the buttons at the bottom, and
    // the preview in the middle.
    Container contentPane = getContentPane();
    contentPane.add(new JScrollPane(preview), BorderLayout.CENTER);
    contentPane.add(choosersBox, BorderLayout.NORTH);
    contentPane.add(buttonBox, BorderLayout.SOUTH);

    // Set the dialog size based on the component size.
    pack();
  }
示例#5
0
 // This method is called when the family, style, or size changes
 protected void changeFont() {
   selectedFont = new Font(family, style, size);
   preview.setFont(selectedFont);
 }