Mercurial > hg > jslab
diff src/samer/core_/util/swing/VContainerBase.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/core_/util/swing/VContainerBase.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,76 @@ +/* + * VContainerBase.java + * + * Copyright (c) 2011, Samer Abdallah, Queen Mary, University of 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 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 VContainerBase extends WindowAdapter implements ContainerListener +{ + protected Frame frame; + protected Box box; + protected Component glue; + protected JScrollPane scr; + protected boolean adding=false; + + public VContainerBase(String name) + { + frame = new Frame(name); + box = Box.createVerticalBox(); + glue = Box.createVerticalGlue(); + + scr=new JScrollPane(box); + scr.setBorder(null); + box.add(glue); // box.add(buttonBar); + box.addContainerListener(this); + box.getParent().setBackground(SystemColor.control); + frame.container().add(scr); + frame.expose(); + frame.addWindowListener(this); + } + + public void pack() { frame.pack(); } + public void validate() { box.validate(); frame.validate(); } + public void removeAll() { frame.setVisible(false); box.removeAll(); } + public void add(Component comp) { box.remove(glue); box.add(comp); box.add(glue); } + public void close() { frame.dispose(); } + + public void windowClosing(WindowEvent e) { frame.dispose(); } + + public void componentAdded(ContainerEvent e) {} + public void componentRemoved(ContainerEvent e) { + box.validate(); frame.validate(); + if (!adding && noScrollBars()) frame.pack(); + // else frame.validate(); + } + + protected boolean noScrollBars() { + JScrollBar sb=scr.getVerticalScrollBar(); + if (sb==null) return true; + return !sb.isVisible(); + } +}