Esempio n. 1
0
  public WebColorChooserField(final Color color) {
    super();

    // Pipette color picker
    updatePipette();

    // Trailing color choose button
    colorButton = new WebButton(ImageUtils.createColorChooserIcon(color));
    colorButton.setFocusable(false);
    colorButton.setShadeWidth(0);
    colorButton.setMoveIconOnPress(false);
    colorButton.setRolloverDecoratedOnly(true);
    colorButton.setCursor(Cursor.getDefaultCursor());
    colorButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            showColorChooserPopup();
          }
        });
    setTrailingComponent(colorButton);

    // Actions
    addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            updateColorFromField();
          }
        });
    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mousePressed(final MouseEvent e) {
            if (isEnabled() && SwingUtilities.isRightMouseButton(e)) {
              showColorChooserPopup();
            }
          }
        });
    addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(final FocusEvent e) {
            updateColorFromField();
          }
        });
    addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(final KeyEvent e) {
            if (isEnabled()) {
              if (Hotkey.ESCAPE.isTriggered(e)) {
                updateViewFromColor();
              } else if (Hotkey.DOWN.isTriggered(e)) {
                showColorChooserPopup();
              }
            }
          }
        });

    // Initial data
    setFieldType(ColorChooserFieldType.rgb);
    setColor(color);

    // Initial styling settings
    updateMargin();
    setHorizontalAlignment(CENTER);
  }
Esempio n. 2
0
 /** Private update methods */
 private void updateViewFromColor() {
   colorButton.setIcon(ImageUtils.createColorChooserIcon(color));
   updateText();
 }