annotate 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
rev   line source
samer@0 1 /*
samer@0 2 * VContainerBase.java
samer@0 3 *
samer@0 4 * Copyright (c) 2011, Samer Abdallah, Queen Mary, University of London
samer@0 5 * All rights reserved.
samer@0 6 *
samer@0 7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
samer@0 8 * without even the implied warranty of MERCHANTABILITY or
samer@0 9 * FITNESS FOR A PARTICULAR PURPOSE.
samer@0 10 */
samer@0 11
samer@0 12 package samer.core.util.swing;
samer@0 13
samer@0 14 import java.awt.*;
samer@0 15 import java.awt.event.*;
samer@0 16 import java.io.*;
samer@0 17 import java.util.*;
samer@0 18 import javax.swing.*;
samer@0 19
samer@0 20 import samer.core.*;
samer@0 21 import samer.core.util.*;
samer@0 22 import samer.core.util.shell.*;
samer@0 23 import samer.core.util.swing.*;
samer@0 24 import samer.core.util.swing.Frame;
samer@0 25 import samer.core.util.swing.Console;
samer@0 26 import samer.core.util.swing.Dialog;
samer@0 27 import samer.core.NumberViewer;
samer@0 28 import samer.core.viewers.swing.*;
samer@0 29 import samer.core.types.*;
samer@0 30
samer@0 31
samer@0 32 public class VContainerBase extends WindowAdapter implements ContainerListener
samer@0 33 {
samer@0 34 protected Frame frame;
samer@0 35 protected Box box;
samer@0 36 protected Component glue;
samer@0 37 protected JScrollPane scr;
samer@0 38 protected boolean adding=false;
samer@0 39
samer@0 40 public VContainerBase(String name)
samer@0 41 {
samer@0 42 frame = new Frame(name);
samer@0 43 box = Box.createVerticalBox();
samer@0 44 glue = Box.createVerticalGlue();
samer@0 45
samer@0 46 scr=new JScrollPane(box);
samer@0 47 scr.setBorder(null);
samer@0 48 box.add(glue); // box.add(buttonBar);
samer@0 49 box.addContainerListener(this);
samer@0 50 box.getParent().setBackground(SystemColor.control);
samer@0 51 frame.container().add(scr);
samer@0 52 frame.expose();
samer@0 53 frame.addWindowListener(this);
samer@0 54 }
samer@0 55
samer@0 56 public void pack() { frame.pack(); }
samer@0 57 public void validate() { box.validate(); frame.validate(); }
samer@0 58 public void removeAll() { frame.setVisible(false); box.removeAll(); }
samer@0 59 public void add(Component comp) { box.remove(glue); box.add(comp); box.add(glue); }
samer@0 60 public void close() { frame.dispose(); }
samer@0 61
samer@0 62 public void windowClosing(WindowEvent e) { frame.dispose(); }
samer@0 63
samer@0 64 public void componentAdded(ContainerEvent e) {}
samer@0 65 public void componentRemoved(ContainerEvent e) {
samer@0 66 box.validate(); frame.validate();
samer@0 67 if (!adding && noScrollBars()) frame.pack();
samer@0 68 // else frame.validate();
samer@0 69 }
samer@0 70
samer@0 71 protected boolean noScrollBars() {
samer@0 72 JScrollBar sb=scr.getVerticalScrollBar();
samer@0 73 if (sb==null) return true;
samer@0 74 return !sb.isVisible();
samer@0 75 }
samer@0 76 }