/*
   * The following method creates the color chooser dialog box
   */
  public void createColorDialog() {
    colorDialog = new JDialog(this, new String("Choose a color"), true);
    colorDialog.getContentPane().add(createColorPicker(), BorderLayout.CENTER);

    JButton okButton = new JButton("OK");

    // This class is used to create a special ActionListener for
    //    the ok button
    class ButtonListener implements ActionListener {
      /*
       * This method is called whenever the ok button is clicked
       */
      public void actionPerformed(ActionEvent event) {
        currentChoice.changeColor(color_panel.getColor());
        currentChoice.repaint();
        fontColor = color_panel.getColor();
        colorDialog.hide();
      } // end actionPerformed method
    }
    ActionListener listener = new ButtonListener();
    okButton.addActionListener(listener);

    // Add the four font control panels to one big panel using
    //  a grid layout
    JPanel buttonPanel = new JPanel();

    buttonPanel.add(okButton);

    // Add the button panel to the content pane of the ColorDialogue
    colorDialog.getContentPane().add(buttonPanel, BorderLayout.SOUTH);

    colorDialog.pack();
  }
  /*
   * The following method creates the textfield to change the text
   *     and the button to update the label.
   * postcondition: returns the panel containing the textfield and button.
   */
  public JPanel createUpdateButton() {
    JLabel textLabel = new JLabel(new String("Change text to: "));

    textField = new JTextField(new String("Big Java"), 20);
    textField.setFont(new Font(("Times"), Font.PLAIN, 12));

    update = new JButton(new String("Update"));
    update.setDefaultCapable(true);

    // This class is used to create a special ActionListener for this menu item
    class ButtonListener implements ActionListener {
      /*
       * This method is called when the update button is clicked
       */
      public void actionPerformed(ActionEvent event) {
        // Call the method to change the text on the screen.
        setSampleFont();
      } // end actionPerformed method
    }
    ActionListener listener = new ButtonListener();
    update.addActionListener(listener);

    JPanel panel = new JPanel();

    panel.add(textLabel);
    panel.add(textField);
    panel.add(update);

    return panel;
  } // end createUpdateButton method
  /*
   * The following method creates the check boxes for selection bold and
   *     italic styles
   * postcondition: returns the panel containing the facename check box.
   */
  public JPanel createStyleCheckBoxes() {
    italicCheckBox = new JCheckBox(new String("Italic"));
    // italicCheckBox.addActionListener(this);

    boldCheckBox = new JCheckBox(new String("Bold"));
    // boldCheckBox.addActionListener(this);

    JPanel panel = new JPanel();
    panel.add(italicCheckBox);
    panel.add(boldCheckBox);
    panel.setBorder(new TitledBorder(new EtchedBorder(), "Style"));

    return panel;
  } // end createCheckBoxes method
  public void addColorChooserPanel(final AbstractColorChooserPanel ccp) {
    final String displayName = ccp.getDisplayName();
    if (displayName == null) {
      // Return if we haven't initialized yet
      return;
    }

    if (ccp.getClass()
        .getName()
        .equals("ch.randelshofer.quaqua.colorchooser.Quaqua15ColorPicker")) {
      northPanel.add(ccp, BorderLayout.WEST);
    } else {
      Icon displayIcon = ccp.getLargeDisplayIcon();
      JToggleButton tb = new JToggleButton(null, displayIcon);
      tb.setToolTipText(displayName);
      tb.setFocusable(false);
      tb.setHorizontalTextPosition(SwingConstants.CENTER);
      tb.setVerticalTextPosition(SwingConstants.BOTTOM);
      tb.setFont(UIManager.getFont("ColorChooser.font"));
      tb.putClientProperty("Quaqua.Button.style", "toolBarTab");
      JPanel centerView = new JPanel(new BorderLayout());
      centerView.add(ccp);
      chooserPanelHolder.add(centerView, displayName);
      toolBarButtonGroup.add(tb);
      toolBar.add(tb);

      if (toolBar.getComponentCount() == 1
          || lastSelectedChooserName != null && lastSelectedChooserName.equals(displayName)) {
        tb.setSelected(true);
        CardLayout cl = (CardLayout) chooserPanelHolder.getLayout();
        cl.show(chooserPanelHolder, displayName);
      }

      tb.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent evt) {
              if (evt.getStateChange() == ItemEvent.SELECTED) {
                CardLayout cl = (CardLayout) chooserPanelHolder.getLayout();
                cl.show(chooserPanelHolder, displayName);
                lastSelectedChooserName = displayName;
              }
            }
          });
    }
  }
  /**
   * Constrcutor. Draws the dialog.
   *
   * @param parent the parent frame for this dialog.
   * @param oColour the starting colour to select;
   */
  public UIColorChooserDialog(JFrame parent, Color oColour) {
    super(parent, true);

    setTitle("Colour Chooser");

    oParent = parent;

    tcc = new JColorChooser(oColour);
    oContentPane = getContentPane();
    JPanel mainpanel = new JPanel(new BorderLayout());
    mainpanel.setBorder(new EmptyBorder(10, 10, 10, 10));

    mainpanel.add(tcc, BorderLayout.CENTER);

    JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

    // Add export button
    pbSave = new UIButton("Save");
    pbSave.addActionListener(this);
    getRootPane().setDefaultButton(pbSave);
    buttonpanel.add(pbSave);

    // Add close button
    pbCancel = new UIButton("Cancel");
    pbCancel.addActionListener(this);
    buttonpanel.add(pbCancel);

    mainpanel.add(buttonpanel, BorderLayout.SOUTH);
    oContentPane.add(mainpanel);

    pack();
  }
  /*
   * The following method creates the combo box with font size choices
   * postcondition: returns the panel containing the size combo box.
   */
  public JPanel createSizeComboBox() {
    sizeCombo = new JComboBox();
    sizeCombo.addItem(SMALLEST);
    sizeCombo.addItem(SMALL);
    sizeCombo.addItem(SMALL_MEDIUM);
    sizeCombo.addItem(MEDIUM);
    sizeCombo.addItem(MEDIUM_LARGE);
    sizeCombo.addItem(LARGE);
    sizeCombo.addItem(LARGEST);
    sizeCombo.addItem(HUGE);
    sizeCombo.addItem(WOW);
    sizeCombo.setEditable(true);
    // facenameCombo.addActionListener(this);
    sizeCombo.setSelectedIndex(2);

    JPanel panel = new JPanel();
    panel.add(sizeCombo);
    panel.setBorder(new TitledBorder(new EtchedBorder(), "Font Name"));

    return panel;
  } // end createComboBox method
  /** TabbedPaneDemo Constructor */
  public TabbedPaneDemo(SwingSet2 swingset) {
    // Set the title for this demo, and an icon used to represent this
    // demo inside the SwingSet2 app.
    super(swingset, "TabbedPaneDemo", "toolbar/JTabbedPane.gif");

    // create tab position controls
    JPanel tabControls = new JPanel();
    tabControls.add(new JLabel(getString("TabbedPaneDemo.label")));
    top = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.top")));
    left = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.left")));
    bottom = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.bottom")));
    right = (JRadioButton) tabControls.add(new JRadioButton(getString("TabbedPaneDemo.right")));
    getDemoPanel().add(tabControls, BorderLayout.NORTH);

    group = new ButtonGroup();
    group.add(top);
    group.add(bottom);
    group.add(left);
    group.add(right);

    top.setSelected(true);

    top.addActionListener(this);
    bottom.addActionListener(this);
    left.addActionListener(this);
    right.addActionListener(this);

    // create tab
    tabbedpane = new JTabbedPane();
    getDemoPanel().add(tabbedpane, BorderLayout.CENTER);

    String name = getString("TabbedPaneDemo.laine");
    JLabel pix = new JLabel(createImageIcon("tabbedpane/laine.jpg", name));
    tabbedpane.add(name, pix);

    name = getString("TabbedPaneDemo.ewan");
    pix = new JLabel(createImageIcon("tabbedpane/ewan.jpg", name));
    tabbedpane.add(name, pix);

    name = getString("TabbedPaneDemo.hania");
    pix = new JLabel(createImageIcon("tabbedpane/hania.jpg", name));
    tabbedpane.add(name, pix);

    name = getString("TabbedPaneDemo.bounce");
    spin = new HeadSpin();
    tabbedpane.add(name, spin);

    tabbedpane
        .getModel()
        .addChangeListener(
            new ChangeListener() {
              public void stateChanged(ChangeEvent e) {
                SingleSelectionModel model = (SingleSelectionModel) e.getSource();
                if (model.getSelectedIndex() == tabbedpane.getTabCount() - 1) {
                  spin.go();
                }
              }
            });
  }
  public ColorChooserDemo() {
    super(new BorderLayout());

    // 设置一个标签,做广告的。也用来显示用户选择的颜色。
    banner = new JLabel("欢迎使用颜色选择器!", JLabel.CENTER);
    banner.setForeground(Color.yellow);
    banner.setBackground(Color.blue);
    banner.setOpaque(true);
    banner.setFont(new Font("SansSerif", Font.BOLD, 24));
    banner.setPreferredSize(new Dimension(100, 65));

    JPanel bannerPanel = new JPanel(new BorderLayout());
    bannerPanel.add(banner, BorderLayout.CENTER);
    bannerPanel.setBorder(BorderFactory.createTitledBorder("广告"));

    // 设置选择颜色选择器
    tcc = new JColorChooser(banner.getForeground()); // 设置初始颜色
    tcc.getSelectionModel().addChangeListener(this); // 给所有模式添加监听
    tcc.setBorder(BorderFactory.createTitledBorder("选择颜色"));

    add(bannerPanel, BorderLayout.CENTER);
    add(tcc, BorderLayout.PAGE_END);
  }
  /*
   * The following method creates the textfield to change the text
   *     and the button to update the label.
   * postcondition: returns the panel containing the textfield and button.
   */
  public JPanel createChooseColorButton() {
    currentChoice = new ColorChoicePanel();

    choose_color = new JButton(new String("Choose Font Color..."));

    // This class is used to create a special ActionListener for this menu item
    class ButtonListener implements ActionListener {
      /*
       * This method is called when the choose_color button is clicked
       */
      public void actionPerformed(ActionEvent event) {
        colorDialog.show();
      } // end actionPerformed method
    }
    ActionListener listener = new ButtonListener();
    choose_color.addActionListener(listener);

    JPanel panel = new JPanel();

    panel.add(currentChoice);
    panel.add(choose_color);

    return panel;
  } // end createColorPickerButton method
  /*
   * The following method creates the control panel to change the font.
   */
  public void createControlPane() {
    // Create the four panels that control the font change
    JPanel facenamePanel = createFacenameComboBox();
    JPanel styleGroupPanel = createStyleCheckBoxes();
    // JPanel sizeGroupPanel = createRadioButtons();
    JPanel sizeGroupPanel = createSizeComboBox();
    JPanel colorPickerPanel = createChooseColorButton();
    JPanel textUpdatePanel = createUpdateButton();

    // Add the four font control panels to one big panel using
    //  a grid layout
    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new GridLayout(5, 1));
    controlPanel.add(facenamePanel);
    controlPanel.add(sizeGroupPanel);
    controlPanel.add(styleGroupPanel);
    controlPanel.add(colorPickerPanel);
    controlPanel.add(textUpdatePanel);

    // Add the panels to the content pane
    getContentPane().add(controlPanel, BorderLayout.SOUTH);
  }
  public void createFileChooserDemo() {
    theImage = new JLabel("");
    jpgIcon = createImageIcon("filechooser/jpgIcon.jpg", "jpg image");
    gifIcon = createImageIcon("filechooser/gifIcon.gif", "gif image");

    JPanel demoPanel = getDemoPanel();
    demoPanel.setLayout(new BoxLayout(demoPanel, BoxLayout.Y_AXIS));

    JPanel innerPanel = new JPanel();
    innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.X_AXIS));

    demoPanel.add(Box.createRigidArea(VGAP20));
    demoPanel.add(innerPanel);
    demoPanel.add(Box.createRigidArea(VGAP20));

    innerPanel.add(Box.createRigidArea(HGAP20));

    // Create a panel to hold buttons
    JPanel buttonPanel =
        new JPanel() {
          public Dimension getMaximumSize() {
            return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
          }
        };
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));

    buttonPanel.add(Box.createRigidArea(VGAP15));
    buttonPanel.add(createPlainFileChooserButton());
    buttonPanel.add(Box.createRigidArea(VGAP15));
    buttonPanel.add(createPreviewFileChooserButton());
    buttonPanel.add(Box.createRigidArea(VGAP15));
    buttonPanel.add(createCustomFileChooserButton());
    buttonPanel.add(Box.createVerticalGlue());

    // Create a panel to hold the image
    JPanel imagePanel = new JPanel();
    imagePanel.setLayout(new BorderLayout());
    imagePanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
    JScrollPane scroller = new JScrollPane(theImage);
    scroller.getVerticalScrollBar().setUnitIncrement(10);
    scroller.getHorizontalScrollBar().setUnitIncrement(10);
    imagePanel.add(scroller, BorderLayout.CENTER);

    // add buttons and image panels to inner panel
    innerPanel.add(buttonPanel);
    innerPanel.add(Box.createRigidArea(HGAP30));
    innerPanel.add(imagePanel);
    innerPanel.add(Box.createRigidArea(HGAP20));
  }
  /*
   * The following method creates the combo box with font style choices
   * postcondition: returns the panel containing the combo box.
   */
  public JPanel createFacenameComboBox() {
    // YOU MUST ALTER THESE BASED ON YOUR SYSTEM.
    facenameCombo = new JComboBox();
    facenameCombo.addItem(new String("Times"));
    facenameCombo.addItem(new String("Agent Orange"));
    facenameCombo.addItem(new String("Aldo's Nova"));
    facenameCombo.addItem(new String("American Typewriter"));
    facenameCombo.addItem(new String("American Typewriter Condensed"));
    facenameCombo.addItem(new String("American Typewriter Light"));
    facenameCombo.addItem(new String("Andale Mono"));
    facenameCombo.addItem(new String("AntsyPants"));
    facenameCombo.addItem(new String("Apple Chancery"));
    facenameCombo.addItem(new String("Arial"));
    facenameCombo.addItem(new String("Arial Black"));
    facenameCombo.addItem(new String("Arial Narrow"));
    facenameCombo.addItem(new String("Aristocrat LET"));
    facenameCombo.addItem(new String("AstigamaTizm"));
    facenameCombo.addItem(new String("BASEHEAD"));
    facenameCombo.addItem(new String("Baskerville"));
    facenameCombo.addItem(new String("BellBottom"));
    facenameCombo.addItem(new String("Bertram LET"));
    facenameCombo.addItem(new String("BiauKai"));
    facenameCombo.addItem(new String("Bickley Script LET"));
    facenameCombo.addItem(new String("Bite me"));
    facenameCombo.addItem(new String("Bizarro"));
    facenameCombo.addItem(new String("Bodoni Ornaments ITC TT"));
    facenameCombo.addItem(new String("Calaveras"));
    facenameCombo.addItem(new String("Capitals"));
    facenameCombo.addItem(new String("Century Gothic"));
    facenameCombo.addItem(new String("Chalkboard"));
    facenameCombo.addItem(new String("Charcoal"));
    facenameCombo.addItem(new String("Chicago"));
    facenameCombo.addItem(new String("Cochin"));
    facenameCombo.addItem(new String("Comic Sans MS"));
    facenameCombo.addItem(new String("Copperplate"));
    facenameCombo.addItem(new String("Courier"));
    facenameCombo.addItem(new String("Courier New"));
    facenameCombo.addItem(new String("Curlz MT"));
    facenameCombo.addItem(new String("Didot"));
    facenameCombo.addItem(new String("Edwardian Script ITC"));
    facenameCombo.addItem(new String("Fang Song"));
    facenameCombo.addItem(new String("Fortuna Dot"));
    facenameCombo.addItem(new String("Futura"));
    facenameCombo.addItem(new String("Gadget"));
    facenameCombo.addItem(new String("Geeza Pro"));
    facenameCombo.addItem(new String("Geneva"));
    facenameCombo.addItem(new String("Georgia"));
    facenameCombo.addItem(new String("Gill Sans"));
    facenameCombo.addItem(new String("Gringo Nights"));
    facenameCombo.addItem(new String("Hei"));
    facenameCombo.addItem(new String("Helvetica"));
    facenameCombo.addItem(new String("Herculanum"));
    facenameCombo.addItem(new String("Hypmotizin"));
    facenameCombo.addItem(new String("Impact"));
    facenameCombo.addItem(new String("Jokerman LET"));
    facenameCombo.addItem(new String("MadisonSquare"));
    facenameCombo.addItem(new String("MammaGamma"));
    facenameCombo.addItem(new String("Mathmos Original"));
    facenameCombo.addItem(new String("MammaGamma"));
    facenameCombo.addItem(new String("Marker Felt"));
    facenameCombo.addItem(new String("MassiveHeadache3"));
    facenameCombo.addItem(new String("Parry Hotter"));
    facenameCombo.setEditable(true);
    // facenameCombo.addActionListener(this);

    JPanel panel = new JPanel();
    panel.add(facenameCombo);
    panel.setBorder(new TitledBorder(new EtchedBorder(), "Font Name"));

    return panel;
  } // end createComboBox method
Example #13
0
  /** OptionPaneDemo Constructor */
  public OptionPaneDemo(SwingSet2 swingset) {
    // Set the title for this demo, and an icon used to represent this
    // demo inside the SwingSet2 app.
    super(swingset, "OptionPaneDemo", "toolbar/JOptionPane.gif");

    JPanel demo = getDemoPanel();

    demo.setLayout(new BoxLayout(demo, BoxLayout.X_AXIS));

    JPanel bp =
        new JPanel() {
          public Dimension getMaximumSize() {
            return new Dimension(getPreferredSize().width, super.getMaximumSize().height);
          }
        };
    bp.setLayout(new BoxLayout(bp, BoxLayout.Y_AXIS));

    bp.add(Box.createRigidArea(VGAP30));
    bp.add(Box.createRigidArea(VGAP30));

    bp.add(createInputDialogButton());
    bp.add(Box.createRigidArea(VGAP15));
    bp.add(createWarningDialogButton());
    bp.add(Box.createRigidArea(VGAP15));
    bp.add(createMessageDialogButton());
    bp.add(Box.createRigidArea(VGAP15));
    bp.add(createComponentDialogButton());
    bp.add(Box.createRigidArea(VGAP15));
    bp.add(createConfirmDialogButton());
    bp.add(Box.createVerticalGlue());

    demo.add(Box.createHorizontalGlue());
    demo.add(bp);
    demo.add(Box.createHorizontalGlue());
  }