Example #1
0
    @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);
      }
    }
  @Override
  public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    Object source = e.getSource();

    if (source == ok) {
      userResponse = APPLY_OPTION;
      this.setVisible(false);
    } else if (source == cancel) {
      userResponse = CANCEL_OPTION;
      this.setVisible(false);
    } else if (source == fontCombo) {
      @SuppressWarnings("unchecked")
      JComboBox<String> cb = (JComboBox<String>) source;
      String s = (String) cb.getSelectedItem();
      Font tmp = example.getFont();
      example.setFont(new Font(s, tmp.getStyle(), tmp.getSize()));
    } else if (source == sizeCombo) {
      @SuppressWarnings("unchecked")
      JComboBox<String> cb = (JComboBox<String>) source;
      String s = (String) cb.getSelectedItem();
      int newSize = Integer.parseInt(s);
      Font tmp = example.getFont();
      example.setFont(new Font(tmp.getFamily(), tmp.getStyle(), newSize));
    } else if (source == foreground) {
      Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground());
      if (tmp != null) example.setForeground(tmp);
    }
  }
Example #3
0
 public static void setColors(JTextField dummy) {
   normBack = dummy.getBackground();
   normText = dummy.getForeground();
   selBack = dummy.getSelectionColor();
   selText = dummy.getSelectedTextColor();
   faintText = dummy.getDisabledTextColor();
   //    findFaint();
 }
  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);
  }
Example #5
0
    @Override
    public void installUI(JComponent c) {
      super.installUI(c);

      jtf = (JTextField) c;

      JTextField editor = jtf;

      UIDefaults uidefaults = XToolkit.getUIDefaults();

      String prefix = getPropertyPrefix();
      Font f = editor.getFont();
      if ((f == null) || (f instanceof UIResource)) {
        editor.setFont(uidefaults.getFont(prefix + ".font"));
      }

      Color bg = editor.getBackground();
      if ((bg == null) || (bg instanceof UIResource)) {
        editor.setBackground(uidefaults.getColor(prefix + ".background"));
      }

      Color fg = editor.getForeground();
      if ((fg == null) || (fg instanceof UIResource)) {
        editor.setForeground(uidefaults.getColor(prefix + ".foreground"));
      }

      Color color = editor.getCaretColor();
      if ((color == null) || (color instanceof UIResource)) {
        editor.setCaretColor(uidefaults.getColor(prefix + ".caretForeground"));
      }

      Color s = editor.getSelectionColor();
      if ((s == null) || (s instanceof UIResource)) {
        editor.setSelectionColor(uidefaults.getColor(prefix + ".selectionBackground"));
      }

      Color sfg = editor.getSelectedTextColor();
      if ((sfg == null) || (sfg instanceof UIResource)) {
        editor.setSelectedTextColor(uidefaults.getColor(prefix + ".selectionForeground"));
      }

      Color dfg = editor.getDisabledTextColor();
      if ((dfg == null) || (dfg instanceof UIResource)) {
        editor.setDisabledTextColor(uidefaults.getColor(prefix + ".inactiveForeground"));
      }

      Border b = editor.getBorder();
      if ((b == null) || (b instanceof UIResource)) {
        editor.setBorder(uidefaults.getBorder(prefix + ".border"));
      }

      Insets margin = editor.getMargin();
      if (margin == null || margin instanceof UIResource) {
        editor.setMargin(uidefaults.getInsets(prefix + ".margin"));
      }
    }
Example #6
0
  private void updateComponentsUI() {
    if (this._changedUI) {
      JTextField t = new JTextField();
      this._fieldPanel.setOpaque(true);
      this._fieldPanel.setBackground(t.getBackground());
      this._fieldPanel.setForeground(t.getForeground());
      this._fieldPanel.setBorder(t.getBorder());

      prepareComponent(this._hourField);
      prepareComponent(this._minuteField);
      prepareComponent(this._secondField);
      prepareComponent(this._hmSeparator);
      prepareComponent(this._msSeparator);
      this._changedUI = false;
    }
  }
 /** 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));
 }
 /** @return Forecolor */
 public Color getForeColor() {
   return example.getForeground();
 }
  /** CONSTRUCTOR */
  public CruiseControl(boolean waitallowed) {
    super();

    this.waitallowed = waitallowed;

    timeformatter = DateFormat.getDateTimeInstance();
    timeformatter.setTimeZone(TimeZone.getTimeZone("UTC"));

    FlowLayout layout = new FlowLayout();
    this.setLayout(layout);

    l_time.setText("-- time --");
    add(l_time);

    final Checkbox c_wait = new Checkbox("wait (global scheduler)");
    c_wait.setState(true);
    c_wait.addItemListener(
        new ItemListener() {

          @Override
          public void itemStateChanged(ItemEvent e) {
            wait = c_wait.getState();
          }
        });
    if (!waitallowed) {
      c_wait.setEnabled(false);
      c_wait.setState(false);
      wait = false;
    }
    this.add(c_wait);

    final Checkbox c_update = new Checkbox("update");
    c_update.setState(true);
    c_update.addItemListener(
        new ItemListener() {

          @Override
          public void itemStateChanged(ItemEvent e) {
            update = c_update.getState();
            if (update) {
              c_wait.setState(true);
              wait = true;
            }
            // TODO @TSC What to do if update == false?
          }
        });
    this.add(c_update);

    JButton b = new JButton("go");
    b.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            synchronized (CruiseControl.this) {
              go = -1;
            }
          }
        });
    this.add(b);

    final JTextField tf = new JTextField(10);
    final Color normalColor = tf.getForeground();
    tf.getDocument()
        .addDocumentListener(
            new DocumentListener() {

              private void checkInput() {
                try {
                  Long.parseLong(tf.getText());
                  // parsed correctly
                  tf.setForeground(normalColor);
                } catch (NumberFormatException e) {
                  tf.setForeground(Color.RED);
                }
              }

              @Override
              public void removeUpdate(DocumentEvent e) {
                checkInput();
              }

              @Override
              public void insertUpdate(DocumentEvent e) {
                checkInput();
              }

              @Override
              public void changedUpdate(DocumentEvent e) {
                checkInput();
              }
            });
    this.add(tf);

    b = new JButton("go to time");
    b.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            synchronized (CruiseControl.this) {
              try {
                go = Long.parseLong(tf.getText());
              } catch (NumberFormatException e1) {
              }
              c_wait.setEnabled(true);
            }
          }
        });
    this.add(b);

    this.setPreferredSize(new Dimension(300, 200));
  }