comparison src/samer/core_/util/swing/InternalFrame.java @ 0:bf79fb79ee13

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