Mercurial > hg > jslab
view src/samer/core_/util/swing/InternalFrame.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.swing; import samer.core.*; import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.io.*; /** <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 InternalFrame extends JInternalFrame implements ComponentListener, ActionListener, Shell.Window { Node node; public InternalFrame( String nm) { super(nm,true,false,true,true); setClosable(true); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); desktop.add(this); node=new Node(nm); init(); } public Container container() { return getContentPane(); } public void dispose() { super.dispose(); } 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 setTitle(node.fullName()); if (pos!=null) setBounds(pos); // if (font!=null) setFont(font); setBackground(bg); setForeground(fg); } finally { Shell.pop(); } setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); JPopupMenu p=new JPopupMenu( "Frame"); p.add("pack").addActionListener(this); addComponentListener(this); MenuBuilder.addPopup(p,getContentPane()).setBackstop(true); } public void addWindowListener(final WindowListener l) { addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameClosing(InternalFrameEvent e) { l.windowClosing(null); } } ); } public static void setDesktop(Container c) { desktop=c; } private static Container desktop; }