samer@0
|
1 /*
|
samer@0
|
2 * AppShell.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.shells;
|
samer@0
|
13
|
samer@0
|
14 import java.awt.*;
|
samer@0
|
15 import java.awt.event.*;
|
samer@0
|
16 import java.io.*;
|
samer@0
|
17 import java.util.*;
|
samer@0
|
18
|
samer@0
|
19 import samer.core.*;
|
samer@0
|
20 import samer.core.util.shell.*;
|
samer@0
|
21 import samer.core.util.*;
|
samer@0
|
22 import samer.core.util.swing.*;
|
samer@0
|
23 import samer.core.util.swing.Frame;
|
samer@0
|
24 import samer.core.util.swing.Console;
|
samer@0
|
25 import samer.core.util.swing.Dialog;
|
samer@0
|
26 import samer.core.NumberViewer;
|
samer@0
|
27 import samer.core.viewers.swing.*;
|
samer@0
|
28 import samer.core.types.*;
|
samer@0
|
29
|
samer@0
|
30 import javax.swing.*;
|
samer@0
|
31 import javax.swing.event.*;
|
samer@0
|
32
|
samer@0
|
33 public class DesktopShell extends AppShellBase
|
samer@0
|
34 {
|
samer@0
|
35 public DesktopShell() { this(getDefaultPropertiesFile()); }
|
samer@0
|
36 public DesktopShell(String props) {
|
samer@0
|
37 super(props);
|
samer@0
|
38 Shell.setShell(this);
|
samer@0
|
39
|
samer@0
|
40 desktop = new JDesktopPane();
|
samer@0
|
41 desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
|
samer@0
|
42 mainFrame = new Frame("Desktop");
|
samer@0
|
43 mainFrame.container().setLayout(new BorderLayout());
|
samer@0
|
44 mainFrame.container().add(desktop);
|
samer@0
|
45 mainFrame.expose();
|
samer@0
|
46 mainFrame.addWindowListener( new WindowAdapter() {
|
samer@0
|
47 public void windowClosing(WindowEvent e) { Shell.exit(); }
|
samer@0
|
48 } );
|
samer@0
|
49
|
samer@0
|
50 InternalFrame.setDesktop(desktop);
|
samer@0
|
51
|
samer@0
|
52 // con = new Console();
|
samer@0
|
53 // confr = new InternalFrame("console.frame");
|
samer@0
|
54 // JScrollPane scroller = new JScrollPane(con);
|
samer@0
|
55
|
samer@0
|
56 // JComponent jc=new javax.swing.JPanel();
|
samer@0
|
57 // jc.setBorder(BorderFactory.createEmptyBorder(1,1,1,1));
|
samer@0
|
58 // jc.setLayout( new BorderLayout(4,5));
|
samer@0
|
59 // jc.add(scroller);
|
samer@0
|
60 // jc.add(new CommandField(20), "South");
|
samer@0
|
61 //confr.container().add(jc);
|
samer@0
|
62 // confr.setContentPane(jc);
|
samer@0
|
63 // confr.pack();
|
samer@0
|
64 // confr.expose();
|
samer@0
|
65
|
samer@0
|
66 Shell.registerAgent(this);
|
samer@0
|
67 // Shell.registerAgent(con);
|
samer@0
|
68
|
samer@0
|
69 // javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(false);
|
samer@0
|
70
|
samer@0
|
71 put(VDouble.class,DoubleViewer.class);
|
samer@0
|
72 put(VInteger.class,IntegerViewer.class);
|
samer@0
|
73 put(VBoolean.class,BooleanViewer.class);
|
samer@0
|
74 put(VString.class,StringViewer.class);
|
samer@0
|
75 put(VParameter.class,ParameterViewer.class);
|
samer@0
|
76 put(VFile.class,FileViewer.class);
|
samer@0
|
77 put(VColor.class,ColorButton.class);
|
samer@0
|
78 put(Variable.class,StringViewer.class);
|
samer@0
|
79 put(Viewable.class,DefaultViewer.class);
|
samer@0
|
80
|
samer@0
|
81 try { execute("run",Shell.env()); }
|
samer@0
|
82 catch (Exception ex) { Shell.trace(ex.toString()); }
|
samer@0
|
83 }
|
samer@0
|
84
|
samer@0
|
85 class VContainer extends InternalFrameAdapter implements ViewableManager.ViewerContainer
|
samer@0
|
86 {
|
samer@0
|
87 InternalFrame frame;
|
samer@0
|
88 Box box;
|
samer@0
|
89 Component glue;
|
samer@0
|
90
|
samer@0
|
91 VContainer()
|
samer@0
|
92 {
|
samer@0
|
93 frame = new InternalFrame("exposed");
|
samer@0
|
94 box = Box.createVerticalBox();
|
samer@0
|
95 glue = Box.createVerticalGlue();
|
samer@0
|
96
|
samer@0
|
97 JScrollPane scr=new JScrollPane(box);
|
samer@0
|
98 scr.setBorder(null);
|
samer@0
|
99
|
samer@0
|
100 box.add(glue);
|
samer@0
|
101 frame.container().add(scr);
|
samer@0
|
102 frame.pack();
|
samer@0
|
103 frame.expose();
|
samer@0
|
104 frame.setClosable(true);
|
samer@0
|
105 frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
|
samer@0
|
106 frame.addInternalFrameListener(this);
|
samer@0
|
107 }
|
samer@0
|
108
|
samer@0
|
109 public void removeAll() { box.removeAll(); }
|
samer@0
|
110 public void add(java.util.Iterator components)
|
samer@0
|
111 {
|
samer@0
|
112 box.remove(glue);
|
samer@0
|
113 while (components.hasNext()) {
|
samer@0
|
114 box.add((Component)(components.next()));
|
samer@0
|
115 }
|
samer@0
|
116 box.add(glue);
|
samer@0
|
117 box.validate();
|
samer@0
|
118 frame.pack();
|
samer@0
|
119 }
|
samer@0
|
120
|
samer@0
|
121 public void internalFrameClosing(InternalFrameEvent e) {
|
samer@0
|
122 Shell.print("internal frame closing");
|
samer@0
|
123 vm.releaseViewerContainer();
|
samer@0
|
124 frame.dispose();
|
samer@0
|
125 }
|
samer@0
|
126 }
|
samer@0
|
127
|
samer@0
|
128 public ViewableManager.ViewerContainer getViewerContainer() {
|
samer@0
|
129 return new VContainer();
|
samer@0
|
130 }
|
samer@0
|
131
|
samer@0
|
132 // ............. Factory methods ............
|
samer@0
|
133
|
samer@0
|
134 public Shell.Window getWindow(String title) { return new InternalFrame(title); }
|
samer@0
|
135 public Shell.Dialog getDialog(String title) { return new Dialog(mainFrame,title,true); }
|
samer@0
|
136
|
samer@0
|
137 public Component createLabel(String txt) { return new JLabel(txt); }
|
samer@0
|
138 public Viewer createViewerPanel(Viewer vwr) { return new VPanel(vwr); }
|
samer@0
|
139 public Container createButtonsFor(Agent agent)
|
samer@0
|
140 {
|
samer@0
|
141 ButtonBar bbar=new ButtonBar();
|
samer@0
|
142 bbar.setTarget(agent);
|
samer@0
|
143 agent.getCommands( bbar);
|
samer@0
|
144 return bbar;
|
samer@0
|
145 }
|
samer@0
|
146
|
samer@0
|
147 public NumberViewer createNumberViewer(String label, int flags, NumberSink s) {
|
samer@0
|
148 return new TextualNumberViewer(label);
|
samer@0
|
149 }
|
samer@0
|
150
|
samer@0
|
151 public void exposeCommands( Agent agent)
|
samer@0
|
152 {
|
samer@0
|
153 if (buttonBar==null) {
|
samer@0
|
154 buttonBar = new ButtonBar();
|
samer@0
|
155 buttonBar.setBroadcaster(am.getBroadcaster());
|
samer@0
|
156 mainFrame.container().add( buttonBar, "North");
|
samer@0
|
157 }
|
samer@0
|
158
|
samer@0
|
159 buttonBar.setTarget(agent);
|
samer@0
|
160 agent.getCommands(buttonBar);
|
samer@0
|
161 mainFrame.validate();
|
samer@0
|
162 }
|
samer@0
|
163
|
samer@0
|
164 // .......... Message printing ..............
|
samer@0
|
165
|
samer@0
|
166 public void print(String msg) { System.out.println(msg); }
|
samer@0
|
167 public void status(String msg) { System.out.println(msg); }
|
samer@0
|
168
|
samer@0
|
169 private PrintWriter writer=null;
|
samer@0
|
170 public PrintWriter getPrintWriter()
|
samer@0
|
171 {
|
samer@0
|
172 if (writer==null)
|
samer@0
|
173 writer = new PrintWriter( new OutputStreamWriter(System.out));
|
samer@0
|
174 return writer;
|
samer@0
|
175 };
|
samer@0
|
176 /*
|
samer@0
|
177 public PrintWriter getPrintWriter() {
|
samer@0
|
178 return new PrintWriter(con.getWriter(),true);
|
samer@0
|
179 }
|
samer@0
|
180
|
samer@0
|
181 public void print(String msg) { con.write(msg); con.write("\n"); }
|
samer@0
|
182 public void status(String msg) { con.write(msg); con.write("\n"); }
|
samer@0
|
183 */
|
samer@0
|
184
|
samer@0
|
185 // ............... Private bits .............
|
samer@0
|
186
|
samer@0
|
187 private Frame mainFrame;
|
samer@0
|
188 private JDesktopPane desktop;
|
samer@0
|
189 private InternalFrame confr=null;
|
samer@0
|
190 private Console con=null;
|
samer@0
|
191 private ButtonBar buttonBar=null;
|
samer@0
|
192 private Component glue;
|
samer@0
|
193
|
samer@0
|
194 public static void main( String args[]) { new DesktopShell(); }
|
samer@0
|
195 }
|
samer@0
|
196
|