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