Source code: com/simscomputing/swing/WindowInternalFrame.java
1 package com.simscomputing.swing;
2
3 import java.awt.event.ActionEvent;
4 import java.awt.event.ActionListener;
5 import java.beans.PropertyVetoException;
6
7 import javax.swing.JInternalFrame;
8 import javax.swing.JMenu;
9 import javax.swing.JRadioButtonMenuItem;
10 import javax.swing.event.InternalFrameEvent;
11 import javax.swing.event.InternalFrameListener;
12
13 /**
14 These internal frames automatically update a Window menu. The Window
15 menu has a group of radio buttons to indicate which InternalFrames are
16 in a JDesktopPane and which one is selected.
17
18 @author David Sims
19 @version $Revision: 1.1.1.1 $ $Date: 2000/02/21 21:22:37 $ */
20 public class WindowInternalFrame extends JInternalFrame
21 implements InternalFrameListener, ActionListener {
22 private JMenu windowMenu;
23 JRadioButtonMenuItem radioButtonMenuItem;
24 boolean isUnique;
25
26 public WindowInternalFrame(JMenu windowMenu) {
27 this(windowMenu, false);
28 } // constructor
29
30 public WindowInternalFrame(JMenu windowMenu, boolean isUnique) {
31 this.windowMenu = windowMenu;
32 this.isUnique = isUnique;
33 addInternalFrameListener(this);
34 } // constructor
35
36 //////////////////////////////////////////
37 // InternalFrameListener implementation //
38 //////////////////////////////////////////
39
40 public void internalFrameOpened(InternalFrameEvent e) {
41 radioButtonMenuItem = new JRadioButtonMenuItem(getTitle());
42 radioButtonMenuItem.addActionListener(this);
43 windowMenu.add(radioButtonMenuItem);
44 } // internalFrameOpened()
45
46 public void internalFrameActivated(InternalFrameEvent e) {
47 // fixme: workaround for JDKs prior to 1.3
48 if (radioButtonMenuItem != null) {
49 radioButtonMenuItem.setSelected(true);
50 } // if
51 } // internalFrameActivated()
52
53 public void internalFrameDeactivated(InternalFrameEvent e) {
54 // fixme: workaround for JDKs prior to 1.3
55 if (radioButtonMenuItem != null) {
56 radioButtonMenuItem.setSelected(false);
57 } // if
58 } // internalFrameDeactivated()
59
60 public void internalFrameClosed(InternalFrameEvent e) {
61 // fixme: workaround for JDKs prior to 1.3
62 if (radioButtonMenuItem != null) {
63 windowMenu.remove(radioButtonMenuItem);
64 } // if
65 } // internalFrameClosed()
66
67 public void internalFrameClosing(InternalFrameEvent e) {
68 } // internalFrameClosing()
69
70 public void internalFrameIconified(InternalFrameEvent e) {
71 // fixme: workaround for JDKs prior to 1.3
72 if (radioButtonMenuItem != null) {
73 radioButtonMenuItem.setSelected(false);
74 } // if
75 } // internalFrameIconified()
76
77 public void internalFrameDeiconified(InternalFrameEvent e) {
78 } // internalFrameDeiconified()
79
80 ///////////////////////////////////
81 // ActionListener implementation //
82 ///////////////////////////////////
83
84 public void actionPerformed(ActionEvent e) {
85 try {
86 setIcon(false);
87 toFront();
88 setSelected(true);
89 } // try
90 catch (PropertyVetoException ex) {
91 // ignore it
92 } // catch
93 } // actionPerformed()
94 } // class WindowInternalFrame