samer@0: /* samer@0: * VContainerBase.java samer@0: * samer@0: * Copyright (c) 2011, Samer Abdallah, Queen Mary, University of London samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.core.util.swing; samer@0: samer@0: import java.awt.*; samer@0: import java.awt.event.*; samer@0: import java.io.*; samer@0: import java.util.*; samer@0: import javax.swing.*; samer@0: samer@0: import samer.core.*; samer@0: import samer.core.util.*; samer@0: import samer.core.util.shell.*; samer@0: import samer.core.util.swing.*; samer@0: import samer.core.util.swing.Frame; samer@0: import samer.core.util.swing.Console; samer@0: import samer.core.util.swing.Dialog; samer@0: import samer.core.NumberViewer; samer@0: import samer.core.viewers.swing.*; samer@0: import samer.core.types.*; samer@0: samer@0: samer@0: public class VContainerBase extends WindowAdapter implements ContainerListener samer@0: { samer@0: protected Frame frame; samer@0: protected Box box; samer@0: protected Component glue; samer@0: protected JScrollPane scr; samer@0: protected boolean adding=false; samer@0: samer@0: public VContainerBase(String name) samer@0: { samer@0: frame = new Frame(name); samer@0: box = Box.createVerticalBox(); samer@0: glue = Box.createVerticalGlue(); samer@0: samer@0: scr=new JScrollPane(box); samer@0: scr.setBorder(null); samer@0: box.add(glue); // box.add(buttonBar); samer@0: box.addContainerListener(this); samer@0: box.getParent().setBackground(SystemColor.control); samer@0: frame.container().add(scr); samer@0: frame.expose(); samer@0: frame.addWindowListener(this); samer@0: } samer@0: samer@0: public void pack() { frame.pack(); } samer@0: public void validate() { box.validate(); frame.validate(); } samer@0: public void removeAll() { frame.setVisible(false); box.removeAll(); } samer@0: public void add(Component comp) { box.remove(glue); box.add(comp); box.add(glue); } samer@0: public void close() { frame.dispose(); } samer@0: samer@0: public void windowClosing(WindowEvent e) { frame.dispose(); } samer@0: samer@0: public void componentAdded(ContainerEvent e) {} samer@0: public void componentRemoved(ContainerEvent e) { samer@0: box.validate(); frame.validate(); samer@0: if (!adding && noScrollBars()) frame.pack(); samer@0: // else frame.validate(); samer@0: } samer@0: samer@0: protected boolean noScrollBars() { samer@0: JScrollBar sb=scr.getVerticalScrollBar(); samer@0: if (sb==null) return true; samer@0: return !sb.isVisible(); samer@0: } samer@0: }