Mercurial > hg > jslab
view src/samer/core_/util/heavy/Frame.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
/* * Frame.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.util.heavy; import samer.core.*; import java.awt.*; import java.awt.event.*; /** <p> This is a useful kind of framed window that uses the property set to get window size and position and colours. It can also send window closing events to the default command handler (see Agency) as "exit" actions. <p> Addition: frame can dispose of itself when last component is removed. */ public class Frame extends java.awt.Frame implements ComponentListener, ActionListener, Shell.Window { Node node; public Frame() { this("frame"); } public Frame( String nm) { node=new Node(nm); init(); } public Container container() { return this; } public void expose() { // this makes sure we don't show a zero-sized window if (getBounds().isEmpty()) pack(); setVisible(true); } public Node getNode() { return node; } // ..... Event Listener bits ....... public void componentHidden(ComponentEvent e) {} public void componentShown(ComponentEvent e) {} public void componentMoved(ComponentEvent e) { savepos(); } public void componentResized(ComponentEvent e) { savepos(); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("pack")) pack(); } // ........... private bits ............... private void savepos() { X.store(node.fullNameFor("bounds"),getBounds()); } private void init() { Shell.push(node); try { String tit = Shell.getString("title",null); Color bg = Shell.getColor("background",SystemColor.control); Color fg = Shell.getColor("foreground",SystemColor.controlText); Rectangle pos = X.rect(Shell.datum("bounds"),null); Font font = X.font(Shell.datum("font"),null); if (tit!=null) setTitle(tit); else { // remove "." from start of name String n=node.fullName(); if (n.startsWith(".")) n=n.substring(1); // remove ".window" from end of name if (n.endsWith(".window")) n=n.substring(0,n.length()-7); setTitle(n); } if (pos!=null) setBounds(pos); if (font!=null) setFont(font); setBackground(bg); setForeground(fg); } finally { Shell.pop(); } PopupMenu p=new PopupMenu( "Frame"); p.addActionListener(this); p.add("pack"); add(p); addComponentListener(this); addMouseListener(new PopupHandler(p,true)); } }