コード例 #1
0
ファイル: TextEdit.java プロジェクト: gaurinicky/Paint
    @Override
    public void actionPerformed(ActionEvent e) {
      // TODO Auto-generated method stub

      Object source = e.getSource();
      if (source == ok) {
        response = APPLY_OPTION;
        this.setVisible(false);
      } else if (source == cancel) {
        response = CANCEL_OPTION;
        this.setVisible(false);
      } else if (source == sizeCombo) {
        // get the number from the source
        JComboBox number = (JComboBox) source;
        String numberItem = (String) number.getSelectedItem();
        Font temp = example.getFont();
        // then set the font
        int newSize = Integer.parseInt(numberItem);
        example.setFont(new Font(temp.getFamily(), temp.getStyle(), newSize));
      } else if (source == fontCombo) {
        JComboBox font = (JComboBox) source;
        String s = (String) font.getSelectedItem();
        Font tmp = example.getFont();
        example.setFont(new Font(s, tmp.getStyle(), tmp.getSize()));
      } else if (source == foreground) {
        Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground());
        MenuBar.shapeLBG.setBackground(tmp);
        if (tmp != null) example.setForeground(tmp);
      }
    }
コード例 #2
0
  private void buildUI() {
    Box.Filler divider =
        new Box.Filler(new Dimension(1, 1), new Dimension(1, 1), new Dimension(1, 1));
    divider.setBackground(field.getForeground());
    divider.setOpaque(true);

    GridBagConstraints gbcLabel =
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.NONE,
            new Insets(0, 0, 0, 0),
            0,
            0);
    GridBagConstraints gbcDivider =
        new GridBagConstraints(
            2,
            1,
            1,
            1,
            0,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.VERTICAL,
            new Insets(0, 2, 0, 2),
            0,
            0);
    GridBagConstraints gbcField =
        new GridBagConstraints(
            3,
            1,
            1,
            1,
            1,
            1,
            GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 0, 0, 0),
            0,
            0);

    setLayout(new GridBagLayout());
    add(label, gbcLabel);
    add(divider, gbcDivider);
    add(field, gbcField);

    setBorder(field.getBorder());
    setBackground(field.getBackground());
    setOpaque(true);
    label.setBackground(field.getBackground());
    label.setOpaque(true);
    field.setBorder(null);
  }
コード例 #3
0
 /** The constructor */
 private BranchNameEditor() {
   myDefaultForeground = myTextField.getForeground();
   myTextField
       .getDocument()
       .addDocumentListener(
           new DocumentAdapter() {
             @Override
             protected void textChanged(DocumentEvent e) {
               String s = myTextField.getText();
               if ((myInvalidValues == null || !myInvalidValues.contains(s))
                   && (s.length() == 0 || BranchNameValidator.INSTANCE.checkInput(s))) {
                 myTextField.setForeground(myDefaultForeground);
               } else {
                 myTextField.setForeground(Color.RED);
               }
             }
           });
   myTextField.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           stopCellEditing();
         }
       });
   myPanel.add(
       myTextField,
       new GridBagConstraints(
           0,
           0,
           1,
           1,
           1.0,
           1.0,
           GridBagConstraints.CENTER,
           GridBagConstraints.BOTH,
           new Insets(0, 0, 0, 0),
           0,
           0));
 }
コード例 #4
0
ファイル: TextEdit.java プロジェクト: gaurinicky/Paint
 public Color getForeColor() {
   return example.getForeground();
 }