annotate src/samer/core_/shells/AWTShell.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
rev   line source
samer@0 1 /*
samer@0 2 * AWTShell.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.*;
samer@0 21 import samer.core.util.shell.*;
samer@0 22 import samer.core.util.heavy.*;
samer@0 23 import samer.core.util.heavy.Console;
samer@0 24 import samer.core.util.heavy.Frame;
samer@0 25 import samer.core.util.heavy.Dialog;
samer@0 26 import samer.core.NumberViewer;
samer@0 27 import samer.core.viewers.*;
samer@0 28 import samer.core.types.*;
samer@0 29
samer@0 30 public class AWTShell extends AppShellBase
samer@0 31 {
samer@0 32 public AWTShell() { this(getDefaultPropertiesFile()); }
samer@0 33 public AWTShell(String propsFile)
samer@0 34 {
samer@0 35 super(propsFile);
samer@0 36 currentFrame = new java.awt.Frame("dummy"); // temporary dialog owner
samer@0 37
samer@0 38 Shell.setShell(this);
samer@0 39
samer@0 40 // going to cache font and menu font
samer@0 41 Font font=X.font(Shell.datum("font"),null);
samer@0 42 Font menufont=X.font(Shell.datum("menu.font"),null);
samer@0 43 if (font!=null) Shell.put("font", font);
samer@0 44 if (menufont!=null) Shell.put("menu.font", menufont);
samer@0 45
samer@0 46 con = new Console();
samer@0 47 confr = new Frame("console.frame");
samer@0 48 confr.setLayout( new BorderLayout(3,3));
samer@0 49 confr.add(con);
samer@0 50 confr.add( new CommandField(20), "South");
samer@0 51 confr.addWindowListener( Shell.exitListener());
samer@0 52 confr.expose();
samer@0 53 // currentFrame=confr;
samer@0 54
samer@0 55 Shell.registerAgent(this);
samer@0 56 Shell.registerAgent(con);
samer@0 57
samer@0 58 put(VDouble.class,DoubleViewer.class);
samer@0 59 put(VInteger.class,IntegerViewer.class);
samer@0 60 put(VBoolean.class,BooleanViewer.class);
samer@0 61 put(VString.class,StringViewer.class);
samer@0 62 put(VParameter.class,ParameterViewer.class);
samer@0 63 put(VFile.class,FileViewer.class);
samer@0 64 put(VColor.class,ColorButton.class);
samer@0 65 put(Variable.class,StringViewer.class);
samer@0 66 put(Viewable.class,DefaultViewer.class);
samer@0 67
samer@0 68 try { execute("run",Shell.env()); }
samer@0 69 catch (Exception ex) { Shell.trace(ex.toString()); }
samer@0 70 }
samer@0 71
samer@0 72 class VContainer extends WindowAdapter implements ViewableManager.ViewerContainer
samer@0 73 {
samer@0 74 Frame frame;
samer@0 75
samer@0 76 VContainer()
samer@0 77 {
samer@0 78 frame = new Frame("exposed");
samer@0 79 frame.setLayout( new StackLayout());
samer@0 80 frame.expose();
samer@0 81 frame.addWindowListener(this);
samer@0 82 }
samer@0 83
samer@0 84 public void add(java.util.Iterator components)
samer@0 85 {
samer@0 86 Container c=frame.container();
samer@0 87 while (components.hasNext()) {
samer@0 88 c.add((Component)(components.next()));
samer@0 89 }
samer@0 90 c.validate();
samer@0 91 frame.pack();
samer@0 92 }
samer@0 93
samer@0 94 public void removeAll() {
samer@0 95 frame.setVisible(false);
samer@0 96 frame.container().removeAll();
samer@0 97 }
samer@0 98
samer@0 99 public void windowClosing(WindowEvent e) {
samer@0 100 vm.releaseViewerContainer();
samer@0 101 frame.dispose();
samer@0 102 }
samer@0 103 }
samer@0 104
samer@0 105 public ViewableManager.ViewerContainer getViewerContainer() {
samer@0 106 return new VContainer();
samer@0 107 }
samer@0 108
samer@0 109 public Shell.Dialog getDialog(String title) { return new Dialog(currentFrame,title,true); }
samer@0 110 public Shell.Window getWindow(String title) { return new BevelWindow(title); }
samer@0 111 public Viewer createViewerPanel(Viewer vwr) { return new VPanel(vwr); }
samer@0 112 public Container createButtonsFor(Agent agent)
samer@0 113 {
samer@0 114 ButtonBar bbar=new ButtonBar();
samer@0 115 bbar.setTarget(agent);
samer@0 116 agent.getCommands(bbar);
samer@0 117 return bbar.container();
samer@0 118 }
samer@0 119
samer@0 120 public NumberViewer createNumberViewer(String label, int flags, NumberSink s) {
samer@0 121 return new TextualNumberViewer(label,flags,s);
samer@0 122 }
samer@0 123
samer@0 124 public void exposeCommands( Agent agent)
samer@0 125 {
samer@0 126 if (buttonBar==null) {
samer@0 127 buttonBar = new ButtonBar();
samer@0 128 buttonBar.setBroadcaster(am.getBroadcaster());
samer@0 129 confr.add( buttonBar.container(), "North");
samer@0 130 }
samer@0 131
samer@0 132 buttonBar.setTarget(agent);
samer@0 133 agent.getCommands(buttonBar);
samer@0 134 confr.validate();
samer@0 135 }
samer@0 136
samer@0 137 public Component createLabel(String txt) {
samer@0 138 Label l=new Label(txt);
samer@0 139 l.addMouseListener(MouseRetarget.listener);
samer@0 140 return l;
samer@0 141 }
samer@0 142
samer@0 143 // .......... Message printing ..............
samer@0 144
samer@0 145 public PrintWriter getPrintWriter() {
samer@0 146 return new PrintWriter(con.getWriter(),true);
samer@0 147 }
samer@0 148
samer@0 149 public void print(String msg) { con.write(msg); con.write("\n"); }
samer@0 150 public void status(String msg) { con.write(msg); con.write("\n"); }
samer@0 151
samer@0 152
samer@0 153 // ............... Private bits .............
samer@0 154
samer@0 155 private java.awt.Frame currentFrame=null;
samer@0 156
samer@0 157 private Frame confr=null;
samer@0 158 private Console con=null;
samer@0 159 private ButtonBar buttonBar=null;
samer@0 160
samer@0 161 public static void main( String args[]) { new AWTShell(); }
samer@0 162
samer@0 163 }
samer@0 164
samer@0 165
samer@0 166
samer@0 167 class BevelWindow extends Frame implements Shell.Window
samer@0 168 {
samer@0 169 JPanel panel;
samer@0 170
samer@0 171 public BevelWindow(String name)
samer@0 172 {
samer@0 173 super(name);
samer@0 174 Shell.push(getNode());
samer@0 175
samer@0 176 panel = new JPanel( Border.create(
samer@0 177 Border.NONE, Shell.getInt("borderWidth",2)
samer@0 178 ));
samer@0 179
samer@0 180 boolean bw = Shell.getBoolean("bevelChildren",false);
samer@0 181 if (bw) panel.setChildBorder(Border.create(Border.IN,0));
samer@0 182
samer@0 183 Shell.pop();
samer@0 184 add(panel);
samer@0 185 }
samer@0 186
samer@0 187 public Container container() { return panel; }
samer@0 188 }