Mercurial > hg > jslab
view src/samer/core_/shells/SwingShell.java @ 8:5e3cbbf173aa tip
Reorganise some more
author | samer |
---|---|
date | Fri, 05 Apr 2019 22:41:58 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * AppShell.java * * Copyright (c) 2000, Samer Abdallah, King's College London. * All rights reserved. * * This software is provided AS iS and WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. */ package samer.core.shells; import java.awt.*; import java.awt.event.*; import java.io.*; import java.util.*; import javax.swing.*; import samer.core.*; import samer.core.util.*; import samer.core.util.shell.*; import samer.core.util.swing.*; import samer.core.util.swing.Frame; import samer.core.util.swing.Console; import samer.core.util.swing.Dialog; import samer.core.NumberViewer; import samer.core.viewers.swing.*; import samer.core.types.*; public class SwingShell extends AppShellBase { public SwingShell() { this(getDefaultPropertiesFile()); } public SwingShell(String props) { super(props); Shell.trace("SwingShell constructor"); Shell.setShell(this); Shell.registerAgent(this); // Shell.trace("creating console"); // con = new Console(); // JScrollPane scroller = new JScrollPane(con); // JComponent jc = (JComponent)(confr.getContentPane()); // jc.setBorder(BorderFactory.createEmptyBorder(1,1,1,1)); // Shell.registerAgent(con); // confr.container().setLayout( new BorderLayout(4,5)); // confr.container().add(scroller); // confr.container().add( new CommandField(20), "South"); // confr.expose(); javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(false); Shell.trace("registering viewer classes"); mput("VDouble","DoubleViewer"); mput("VInteger","IntegerViewer"); mput("VBoolean","BooleanViewer"); mput("VString","StringViewer"); mput("VParameter","ParameterViewer"); mput("VFile","FileViewer"); mput("VColor","ColorButton"); put(Variable.class,StringViewer.class); put(Viewable.class,DefaultViewer.class); try { execute("run",Shell.env()); } catch (Exception ex) { Shell.trace(ex.toString()); } } private static void mput(String cl, String vwr) { samer.core.Registry.put("samer.core.types."+cl, "samer.core.viewers.swing."+vwr); } class VContainer extends VContainerBase implements ViewableManager.ViewerContainer { VContainer() { super("exposed"); box.add(buttonBar); } public void add(java.util.Iterator components) { adding=true; box.remove(glue); box.remove(buttonBar); while (components.hasNext()) { box.add((Component)(components.next())); } box.add(glue); box.add(buttonBar); box.validate(); if (noScrollBars() || frame.getBounds().isEmpty()) frame.pack(); else frame.validate(); adding=false; } public void windowClosing(WindowEvent e) { vm.releaseViewerContainer(); super.windowClosing(e); } } public ViewableManager.ViewerContainer getViewerContainer() { if (buttonBar==null) { buttonBar = new ButtonBar(); buttonBar.setBroadcaster(am.getBroadcaster()); buttonBar.setTarget(this); buttonBar.add("set").add("get").add("load").add("save").add("exit"); } return new VContainer(); } // ............. Factory methods ............ public Shell.Window getWindow(String title) { return new Frame(title); } public Shell.Dialog getDialog(String title) { // if (currentFrame==null) currentFrame=new JFrame("dialog owner"); // return new Dialog(currentFrame,title,true); return new Dialog(title,true); } public Component createLabel(String txt) { JLabel l=new JLabel(Node.lastPart(txt)) { public void setName(String txt) { super.setName(txt); setText(Node.lastPart(txt)); setToolTipText(txt); } }; l.setToolTipText(txt); MouseRetarget.mouseInvisibilityFor(l); return l; } public Viewer createViewerPanel(Viewer vwr) { return new VPanel(vwr); } public Container createButtonsFor(Agent agent) { ButtonBar bbar=new ButtonBar(); bbar.setTarget(agent); agent.getCommands( bbar); return bbar; } public NumberViewer createNumberViewer(String label, int flags, NumberSink s) { return new TextualNumberViewer(label); } public void exposeCommands( Agent agent) { buttonBar.setTarget(agent); agent.getCommands(buttonBar); } // .......... Message printing .............. public void print(String msg) { System.out.println(msg); } public void status(String msg) { System.out.println(msg); } private PrintWriter writer=null; public PrintWriter getPrintWriter() { if (writer==null) writer = new PrintWriter( new OutputStreamWriter(System.out)); return writer; }; // public PrintWriter getPrintWriter() { // return new PrintWriter(con.getWriter(),true); // } // public void print(String msg) { con.write(msg); con.write("\n"); } // public void status(String msg) { con.write(msg); con.write("\n"); } // ............... Private bits ............. // private JFrame currentFrame=null; private JFrame confr=null; private Console con=null; private ButtonBar buttonBar=null; private Component glue; public static void main( String args[]) { new SwingShell(); } }