1 22 23 package swingwtx.swing; 24 25 import swingwt.awt.Component; 26 import swingwt.awt.Container; 27 import swingwt.awt.Dimension; 28 29 34 public class Box extends JPanel { 35 36 public Box(int axis) { 37 this(null, axis); 38 } 39 40 public Box(Container target, int axis) { 41 42 if (target != null) { 43 target.add(this); 44 setLayout(new BoxLayout(target, axis)); 45 } 46 else 47 setLayout(new BoxLayout(this, axis)); 48 } 49 50 public static Box createHorizontalBox() { 51 return new Box(BoxLayout.X_AXIS); 52 } 53 54 public static Box createVerticalBox() { 55 return new Box(BoxLayout.Y_AXIS); 56 } 57 58 public static Box createHorizontalBox(Container target) { 59 return new Box(target, BoxLayout.X_AXIS); 60 } 61 62 public static Box createVerticalBox(Container target) { 63 return new Box(target, BoxLayout.Y_AXIS); 64 } 65 66 public static Component createRigidArea(Dimension d) { 67 return new Filler(d, d, d); 68 } 69 70 public static Component createHorizontalStrut(int width) { 71 return new Filler(new Dimension(width,0), new Dimension(width,0), new Dimension(width, Short.MAX_VALUE)); 74 } 75 76 public static Component createVerticalStrut(int height) { 77 return new Filler(new Dimension(0,height), new Dimension(0,height), new Dimension(Short.MAX_VALUE, height)); 80 } 81 82 public static Component createGlue() { 83 return new Filler(new Dimension(0,0), new Dimension(0,0), new Dimension(Short.MAX_VALUE, Short.MAX_VALUE)); 86 } 87 88 public static Component createHorizontalGlue() { 89 return new Filler(new Dimension(0,0), new Dimension(0,0), new Dimension(Short.MAX_VALUE, 0)); 92 } 93 94 public static Component createVerticalGlue() { 95 return new Filler(new Dimension(0,0), new Dimension(0,0), new Dimension(0, Short.MAX_VALUE)); 98 } 99 100 public static class Filler extends JPanel { 101 102 public Filler(Dimension min, Dimension pref, Dimension max) { 103 reqMin = min; 104 reqPref = pref; 105 reqMax = max; 106 } 107 108 public void changeShape(Dimension min, Dimension pref, Dimension max) { 109 reqMin = min; 110 reqPref = pref; 111 reqMax = max; 112 } 114 115 public Dimension getMinimumSize() { 116 return reqMin; 117 } 118 119 public Dimension getPreferredSize() { 120 return reqPref; 121 } 122 123 public Dimension getMaximumSize() { 124 return reqMax; 125 } 126 127 private Dimension reqMin; 128 private Dimension reqPref; 129 private Dimension reqMax; 130 } 131 } 132 | Popular Tags |