예제 #1
0
  // implementation of java.awt.event.ActionListener interface
  public void actionPerformed(JCActionEvent e) {
    if (e.getSource() == ok || e.getSource() == cancel) {
      if (e.getSource() == ok) {
        accept = true;
      } else {
        accept = false;
      }

      dialog.dispose();
    } else {
      JCButton b = (JCButton) e.getSource();
      Color c = b.getBackground();

      updateColor(c, e.getSource());
    }
  }
예제 #2
0
  public ColorChooser(Dialog d) {
    dialog = d;

    JCContainer spinboxContainer = new JCContainer();

    cs = new ColorSpace();
    cs.addMouseListener(this);
    cs.addMouseMotionListener(this);

    Layout.fill(this, cs, 0, 0, GridBagConstraints.BOTH);

    JCLabel redLabel = new JCLabel("Red");
    red = new JCSpinBox(3);
    red.setAutoArrowDisable(false);
    red.setMinimum(0);
    red.setMaximum(255);

    JCLabel greenLabel = new JCLabel("Green");
    green = new JCSpinBox(3);
    green.setMinimum(0);
    green.setMaximum(255);

    JCLabel blueLabel = new JCLabel("Blue");
    blue = new JCSpinBox(3);
    blue.setMinimum(0);
    blue.setMaximum(255);

    Layout.fill(spinboxContainer, redLabel, 0, 0, GridBagConstraints.NONE);
    Layout.fill(spinboxContainer, red, 1, 0, GridBagConstraints.NONE);

    Layout.fill(spinboxContainer, greenLabel, 0, 1, GridBagConstraints.NONE);
    Layout.fill(spinboxContainer, green, 1, 1, GridBagConstraints.NONE);

    Layout.fill(spinboxContainer, blueLabel, 0, 2, GridBagConstraints.NONE);
    Layout.fill(spinboxContainer, blue, 1, 2, GridBagConstraints.NONE);

    JCLabel thisColor = new JCLabel("New");
    colorSample = new Panel();

    // common colours

    JCContainer commonContainer = new JCContainer();

    String commonColors[] = {
      "red",
      "orange",
      "brown",
      "yellow",
      "green",
      "blue",
      "cyan",
      "magenta",
      "purple",
      "white",
      "lightgrey",
      "grey",
      "darkgrey",
      "black"
    };

    for (int i = 0; i < commonColors.length; i++) {
      JCButton b = new JCButton();
      b.setPreferredSize(2, 10);
      b.setBackground(new Color(Color32.getColorFromName(commonColors[i])));
      b.addActionListener(this);
      Layout.fill(commonContainer, b, i, 0, GridBagConstraints.NONE);
    }

    Layout.fill(this, commonContainer, 0, 1, GridBagConstraints.HORIZONTAL);

    JCLabel hexLabel = new JCLabel("Hex");
    hexText = new TextField("");
    hexText.setColumns(6);
    hexText.setFont(new Font("courier", Font.PLAIN, 9));
    hexText.addActionListener(this);

    Layout.fill(spinboxContainer, hexLabel, 0, 4, GridBagConstraints.HORIZONTAL);
    Layout.fill(spinboxContainer, hexText, 1, 4, GridBagConstraints.HORIZONTAL);

    Layout.fill(spinboxContainer, thisColor, 0, 5, GridBagConstraints.HORIZONTAL);
    Layout.fill(spinboxContainer, colorSample, 1, 5, GridBagConstraints.HORIZONTAL);

    Layout.fill(this, spinboxContainer, 1, 0, GridBagConstraints.NONE);

    JCContainer buttonContainer = new JCContainer();

    ok = new JCButton("OK");
    ok.addActionListener(this);
    cancel = new JCButton("Cancel");
    cancel.addActionListener(this);

    Layout.fill(buttonContainer, ok, 0, 0, GridBagConstraints.NONE);
    Layout.fill(buttonContainer, cancel, 1, 0, GridBagConstraints.NONE);

    Layout.fill(this, buttonContainer, 0, 2, GridBagConstraints.NONE);

    doLayout();
  }