samer@0
|
1 /*
|
samer@0
|
2 * Frame.java
|
samer@0
|
3 *
|
samer@0
|
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
5 * All rights reserved.
|
samer@0
|
6 *
|
samer@0
|
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
8 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
9 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
10 */
|
samer@0
|
11
|
samer@0
|
12 package samer.core.util.swing;
|
samer@0
|
13 import samer.core.*;
|
samer@0
|
14 import javax.swing.*;
|
samer@0
|
15 import javax.swing.event.*;
|
samer@0
|
16 import java.awt.*;
|
samer@0
|
17 import java.awt.event.*;
|
samer@0
|
18 import java.io.*;
|
samer@0
|
19
|
samer@0
|
20 /**
|
samer@0
|
21 <p>
|
samer@0
|
22 This is a useful kind of framed window that uses
|
samer@0
|
23 the property set to get window size and position
|
samer@0
|
24 and colours. It can also send window closing events
|
samer@0
|
25 to the default command handler (see Agency) as
|
samer@0
|
26 "exit" actions.
|
samer@0
|
27
|
samer@0
|
28 <p>
|
samer@0
|
29 Addition: frame can dispose of itself when last component
|
samer@0
|
30 is removed.
|
samer@0
|
31 */
|
samer@0
|
32
|
samer@0
|
33 public class InternalFrame extends JInternalFrame
|
samer@0
|
34 implements ComponentListener, ActionListener, Shell.Window
|
samer@0
|
35 {
|
samer@0
|
36 Node node;
|
samer@0
|
37
|
samer@0
|
38 public InternalFrame( String nm) {
|
samer@0
|
39 super(nm,true,false,true,true);
|
samer@0
|
40 setClosable(true);
|
samer@0
|
41 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
samer@0
|
42 desktop.add(this);
|
samer@0
|
43 node=new Node(nm);
|
samer@0
|
44 init();
|
samer@0
|
45 }
|
samer@0
|
46
|
samer@0
|
47 public Container container() { return getContentPane(); }
|
samer@0
|
48 public void dispose() { super.dispose(); }
|
samer@0
|
49
|
samer@0
|
50 public void expose() {
|
samer@0
|
51 // this makes sure we don't show a zero-sized window
|
samer@0
|
52 if (getBounds().isEmpty()) pack();
|
samer@0
|
53 setVisible(true);
|
samer@0
|
54 }
|
samer@0
|
55
|
samer@0
|
56 public Node getNode() { return node; }
|
samer@0
|
57
|
samer@0
|
58 // ..... Event Listener bits .......
|
samer@0
|
59
|
samer@0
|
60 public void componentHidden(ComponentEvent e) {}
|
samer@0
|
61 public void componentShown(ComponentEvent e) {}
|
samer@0
|
62 public void componentMoved(ComponentEvent e) { savepos(); }
|
samer@0
|
63 public void componentResized(ComponentEvent e) { savepos(); }
|
samer@0
|
64 public void actionPerformed(ActionEvent e) {
|
samer@0
|
65 if (e.getActionCommand().equals("pack")) pack();
|
samer@0
|
66 }
|
samer@0
|
67
|
samer@0
|
68
|
samer@0
|
69 // ........... private bits ...............
|
samer@0
|
70
|
samer@0
|
71 private void savepos() { X.store(node.fullNameFor("bounds"),getBounds()); }
|
samer@0
|
72
|
samer@0
|
73 private void init()
|
samer@0
|
74 {
|
samer@0
|
75 Shell.push(node);
|
samer@0
|
76 try {
|
samer@0
|
77 String tit = Shell.getString("title",null);
|
samer@0
|
78 Color bg = Shell.getColor("background",SystemColor.control);
|
samer@0
|
79 Color fg = Shell.getColor("foreground",SystemColor.controlText);
|
samer@0
|
80 Rectangle pos = X.rect(Shell.datum("bounds"),null);
|
samer@0
|
81 // Font font = X.font(Shell.datum("font"),null);
|
samer@0
|
82
|
samer@0
|
83 if (tit!=null) setTitle(tit);
|
samer@0
|
84 else setTitle(node.fullName());
|
samer@0
|
85
|
samer@0
|
86 if (pos!=null) setBounds(pos);
|
samer@0
|
87 // if (font!=null) setFont(font);
|
samer@0
|
88
|
samer@0
|
89 setBackground(bg);
|
samer@0
|
90 setForeground(fg);
|
samer@0
|
91 } finally { Shell.pop(); }
|
samer@0
|
92
|
samer@0
|
93 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
samer@0
|
94
|
samer@0
|
95 JPopupMenu p=new JPopupMenu( "Frame");
|
samer@0
|
96 p.add("pack").addActionListener(this);
|
samer@0
|
97
|
samer@0
|
98 addComponentListener(this);
|
samer@0
|
99 MenuBuilder.addPopup(p,getContentPane()).setBackstop(true);
|
samer@0
|
100 }
|
samer@0
|
101
|
samer@0
|
102 public void addWindowListener(final WindowListener l) {
|
samer@0
|
103 addInternalFrameListener( new InternalFrameAdapter() {
|
samer@0
|
104 public void internalFrameClosing(InternalFrameEvent e) {
|
samer@0
|
105 l.windowClosing(null);
|
samer@0
|
106 }
|
samer@0
|
107 } );
|
samer@0
|
108 }
|
samer@0
|
109
|
samer@0
|
110 public static void setDesktop(Container c) { desktop=c; }
|
samer@0
|
111 private static Container desktop;
|
samer@0
|
112 }
|
samer@0
|
113
|