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.heavy;
|
samer@0
|
13 import samer.core.*;
|
samer@0
|
14 import java.awt.*;
|
samer@0
|
15 import java.awt.event.*;
|
samer@0
|
16
|
samer@0
|
17 /**
|
samer@0
|
18 <p>
|
samer@0
|
19 This is a useful kind of framed window that uses
|
samer@0
|
20 the property set to get window size and position
|
samer@0
|
21 and colours. It can also send window closing events
|
samer@0
|
22 to the default command handler (see Agency) as
|
samer@0
|
23 "exit" actions.
|
samer@0
|
24
|
samer@0
|
25 <p>
|
samer@0
|
26 Addition: frame can dispose of itself when last component
|
samer@0
|
27 is removed.
|
samer@0
|
28 */
|
samer@0
|
29
|
samer@0
|
30 public class Frame extends java.awt.Frame
|
samer@0
|
31 implements ComponentListener, ActionListener, Shell.Window
|
samer@0
|
32 {
|
samer@0
|
33 Node node;
|
samer@0
|
34
|
samer@0
|
35 public Frame() { this("frame"); }
|
samer@0
|
36 public Frame( String nm) { node=new Node(nm); init(); }
|
samer@0
|
37
|
samer@0
|
38 public Container container() { return this; }
|
samer@0
|
39
|
samer@0
|
40 public void expose() {
|
samer@0
|
41 // this makes sure we don't show a zero-sized window
|
samer@0
|
42 if (getBounds().isEmpty()) pack();
|
samer@0
|
43 setVisible(true);
|
samer@0
|
44 }
|
samer@0
|
45
|
samer@0
|
46 public Node getNode() { return node; }
|
samer@0
|
47
|
samer@0
|
48 // ..... Event Listener bits .......
|
samer@0
|
49
|
samer@0
|
50 public void componentHidden(ComponentEvent e) {}
|
samer@0
|
51 public void componentShown(ComponentEvent e) {}
|
samer@0
|
52 public void componentMoved(ComponentEvent e) { savepos(); }
|
samer@0
|
53 public void componentResized(ComponentEvent e) { savepos(); }
|
samer@0
|
54 public void actionPerformed(ActionEvent e) {
|
samer@0
|
55 if (e.getActionCommand().equals("pack")) pack();
|
samer@0
|
56 }
|
samer@0
|
57
|
samer@0
|
58
|
samer@0
|
59 // ........... private bits ...............
|
samer@0
|
60
|
samer@0
|
61 private void savepos() { X.store(node.fullNameFor("bounds"),getBounds()); }
|
samer@0
|
62
|
samer@0
|
63 private void init()
|
samer@0
|
64 {
|
samer@0
|
65 Shell.push(node);
|
samer@0
|
66 try {
|
samer@0
|
67 String tit = Shell.getString("title",null);
|
samer@0
|
68 Color bg = Shell.getColor("background",SystemColor.control);
|
samer@0
|
69 Color fg = Shell.getColor("foreground",SystemColor.controlText);
|
samer@0
|
70 Rectangle pos = X.rect(Shell.datum("bounds"),null);
|
samer@0
|
71 Font font = X.font(Shell.datum("font"),null);
|
samer@0
|
72
|
samer@0
|
73 if (tit!=null) setTitle(tit);
|
samer@0
|
74 else {
|
samer@0
|
75 // remove "." from start of name
|
samer@0
|
76 String n=node.fullName();
|
samer@0
|
77 if (n.startsWith(".")) n=n.substring(1);
|
samer@0
|
78 // remove ".window" from end of name
|
samer@0
|
79 if (n.endsWith(".window")) n=n.substring(0,n.length()-7);
|
samer@0
|
80 setTitle(n);
|
samer@0
|
81 }
|
samer@0
|
82
|
samer@0
|
83 if (pos!=null) setBounds(pos);
|
samer@0
|
84 if (font!=null) setFont(font);
|
samer@0
|
85
|
samer@0
|
86 setBackground(bg);
|
samer@0
|
87 setForeground(fg);
|
samer@0
|
88 } finally { Shell.pop(); }
|
samer@0
|
89
|
samer@0
|
90 PopupMenu p=new PopupMenu( "Frame");
|
samer@0
|
91 p.addActionListener(this);
|
samer@0
|
92 p.add("pack");
|
samer@0
|
93 add(p);
|
samer@0
|
94
|
samer@0
|
95 addComponentListener(this);
|
samer@0
|
96 addMouseListener(new PopupHandler(p,true));
|
samer@0
|
97 }
|
samer@0
|
98 }
|
samer@0
|
99
|