View Javadoc

1   // Copyright 2004, FreeHEP.
2   package hep.wired.util;
3   
4   import java.awt.*;
5   import java.awt.event.*;
6   import javax.swing.*;
7   
8   import org.freehep.application.Application;
9   import org.freehep.swing.layout.TableLayout;
10  
11  /***
12   *
13   * @author Mark Donszelmann
14   * @version $Id: OptionButton.java 404 2004-08-17 21:23:12Z duns $
15   */
16  public class OptionButton extends JButton implements ActionListener {
17  
18      private String title;
19      private Container content;
20      private Component component;
21      private JDialog dialog;
22  
23      public OptionButton(String label, String title, Container content, Component component) {
24          super(label);
25          this.title = title;
26          this.content = content;
27          this.component = component;
28          addActionListener(this);
29      }
30  
31      public void actionPerformed(ActionEvent event) {
32          if (dialog == null) {
33              Component root = (Component)SwingUtilities.getRoot(component);
34              dialog = (root instanceof Frame) ? new JDialog((Frame)root, title) : new JDialog((Dialog)root, title);
35              dialog.setContentPane(content);
36              dialog.setLocationRelativeTo(root);
37          }
38          if (dialog.isVisible()) {
39              dialog.toFront();
40          } else {
41              Application application = Application.getApplication();
42              application.showDialog(dialog, content.getName());
43          }
44      }
45  }