Exemplo n.º 1
0
  @Override
  protected void fireActionPerformed(ActionEvent event) {
    try {
      this.setSelected(true);

      // create the dialog if this has not been done yet.
      if (this.dialog == null) {
        // Get the top level ancestor as parent for the new dialog.
        // This ensures that on Mac OS X the global menu bar remains
        // visible while the dialog is open.
        final Container parent = this.getTopLevelAncestor();
        dialog =
            JColorChooser.createDialog(
                parent,
                colorChooserTitle,
                true, // modal
                colorChooser,
                this, // OK button handler
                null); // no CANCEL button handler
        dialog.pack();
        dialog.setResizable(false);
      }

      // show the dialog
      colorChooser.setColor(color);
      dialog.setVisible(true);

      /* A simpler option that is displaying the ugly preview panel:
      Color newColor = JColorChooser.showDialog(this.getTopLevelAncestor(),
              colorChooserTitle, color);
      if (newColor != null){
          // only set color and fire an event when user did not cancel.
          this.setColor(newColor);
          super.fireActionPerformed(event);
      }*/
    } catch (Exception e) {
    } finally {
      this.setSelected(false);
    }
  }
Exemplo n.º 2
0
  public void run() {

    // Collect some user data.
    dlg = new JDialog(console.frame, "Example 1 Setup", true);
    dlg.getContentPane().setLayout(new BorderLayout());

    // Properties area
    propPanel = new JPanel();
    dlg.getContentPane().add(propPanel, BorderLayout.CENTER);

    GridBagLayout gbl = new GridBagLayout();
    propPanel.setLayout(gbl);

    // List of voice resources
    DefaultListModel dlm = new DefaultListModel();
    for (int x = 1; ; x++) {
      try {
        int c = x % 4 == 0 ? 4 : x % 4;
        int b = c == 4 ? x / 4 : x / 4 + 1;
        String devName = "dxxxB" + b + "C" + c;
        int dev = dx.open(devName, 0);
        try {
          // If any of the voice resources _are not_ connected to
          // analog loop-start lines, then they will be suppressed
          // here because sethook() will not be supported.
          dx.sethook(dev, dx.DX_ONHOOK, dx.EV_SYNC);
          dlm.addElement(devName);
        } catch (Exception ignore) {
        }
        dx.close(dev);
      } catch (Exception ignore) {
        break;
      }
    }
    analogDxList = new JList(dlm);
    {
      GridBagConstraints gbc;
      // Choose a voice resource:
      gbc = new GridBagConstraints();
      gbc.gridx = 0;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.BOTH;
      JTextField t = new JTextField("Analog Voice Resource");
      t.setEditable(false);
      gbl.setConstraints(t, gbc);
      propPanel.add(t);
      gbc = new GridBagConstraints();
      gbc.gridx = 1;
      gbc.gridy = 0;
      gbc.fill = GridBagConstraints.BOTH;
      JScrollPane s = new JScrollPane(analogDxList);
      gbl.setConstraints(s, gbc);
      propPanel.add(s);
    }

    // Dialog buttons at the bottom.
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
    dlg.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    // "Run"
    {
      JButton b = new JButton("Run");
      b.addActionListener(
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              final Object[] dx = analogDxList.getSelectedValues();
              if (dx.length != 1) {
                // "Please select one, and only one, voice resource."
                JOptionPane.showMessageDialog(
                    dlg,
                    "Please select one, and only one, resource.",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
                return;
              }
              Thread t =
                  new Thread() {
                    public void run() {
                      runExample((String) dx[0]);
                    }
                  };
              t.start();
              dlg.dispose();
            }
          });
      buttonPanel.add(b);
    }
    // "Cancel"
    {
      JButton b = new JButton("Cancel");
      b.addActionListener(
          new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              dlg.dispose();
            }
          });
      buttonPanel.add(b);
    }

    // Pack and Show
    dlg.pack();
    dlg.setLocationRelativeTo(console.frame);
    dlg.setVisible(true);
  }