1 14 package wingset; 15 16 import org.wings.*; 17 import org.wings.style.CSSProperty; 18 19 import java.awt.event.ActionEvent ; 20 import java.awt.event.ActionListener ; 21 import java.util.Iterator ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 25 29 public class ComponentControls 30 extends SToolbar { 31 protected final List components = new LinkedList (); 32 protected final STextField widthTextField; 33 protected final STextField heightTextField; 34 protected final SButton applyButton; 35 36 public ComponentControls() { 37 setAttribute(CSSProperty.BORDER_BOTTOM,"1px solid #cccccc"); 38 applyButton = new SButton("apply"); 39 applyButton.setActionCommand("apply"); 40 widthTextField = new STextField(); 41 heightTextField = new STextField(); 42 43 add(applyButton); 44 add(new SLabel("<html> width ")); 45 add(widthTextField); 46 add(new SLabel("<html> height ")); 47 add(heightTextField); 48 49 addActionListener(new ActionListener () { 50 public void actionPerformed(ActionEvent e) { 51 SDimension preferredSize = new SDimension(); 52 String width = widthTextField.getText(); 53 if (width != null && width.length() > 0) { 54 int widthInt; 55 try { 56 widthInt = Integer.parseInt(width); 57 } catch (NumberFormatException nfe) { 58 widthInt = Integer.MIN_VALUE; 59 } 60 if (widthInt == Integer.MIN_VALUE) { 61 preferredSize.setWidth(width); 62 } else { 63 preferredSize.setWidth(widthInt); 64 } 65 } 66 String height = heightTextField.getText(); 67 if (height != null && height.length() > 0) { 68 int heightInt; 69 try { 70 heightInt = Integer.parseInt(height); 71 } catch (NumberFormatException nfe) { 72 heightInt = Integer.MIN_VALUE; 73 } 74 if (heightInt == Integer.MIN_VALUE) { 75 preferredSize.setHeight(height); 76 } else { 77 preferredSize.setHeight(heightInt); 78 } 79 } 80 for (Iterator iterator = components.iterator(); iterator.hasNext();) { 81 SComponent component = (SComponent) iterator.next(); 82 component.setPreferredSize(preferredSize); 83 } 84 } 85 }); 86 } 87 88 public void addSizable(SComponent component) { 89 components.add(component); 90 } 91 92 protected void addActionListener(ActionListener actionListener) { 93 applyButton.addActionListener(actionListener); 94 } 95 } 96 | Popular Tags |