Mercurial > hg > jslab
view src/samer/core_/util/swing/VContainerBase.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
/* * 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(); } }