1 14 package wingset; 15 16 import org.wings.*; 17 import org.wings.border.*; 18 19 import java.awt.*; 20 import java.awt.event.ActionEvent ; 21 import java.awt.event.ActionListener ; 22 23 27 public class BorderExample 28 extends WingSetPane { 29 private static final SIcon WAIT_ICON = new SResourceIcon("org/wings/icons/Wait.gif"); 30 31 final SBorder raised = new SBevelBorder(SBevelBorder.RAISED, new Insets(5, 5, 5, 5)); 32 final SBorder lowered = new SBevelBorder(SBevelBorder.LOWERED, new Insets(5, 5, 5, 5)); 33 final SBorder line = new SLineBorder(2, new Insets(5, 5, 5, 5)); 34 final SBorder titled = new STitledBorder(new SEtchedBorder(SEtchedBorder.LOWERED, new Insets(5, 5, 5, 5)), "This is a title"); 35 36 private SLabel borderLabel; 37 private BorderControls controls; 38 private int thickness = 2; 39 40 public SComponent createExample() { 41 controls = new BorderControls(); 42 43 borderLabel = new SLabel(WAIT_ICON); 44 borderLabel.setBackground(new Color(222, 222, 222)); 45 46 SPanel buttons = new SPanel(); 47 buttons.setLayout(new SGridLayout(1)); 48 SButtonGroup group = new SButtonGroup(); 49 final SRadioButton rb = new SRadioButton("Raised"); 50 group.add(rb); 51 buttons.add(rb); 52 final SRadioButton lb = new SRadioButton("Lowered"); 53 group.add(lb); 54 buttons.add(lb); 55 final SRadioButton lineb = new SRadioButton("Line"); 56 group.add(lineb); 57 buttons.add(lineb); 58 final SRadioButton eb = new SRadioButton("Title"); 59 group.add(eb); 60 buttons.add(eb); 61 62 group.addActionListener(new ActionListener () { 63 public void actionPerformed(ActionEvent e) { 64 SButtonGroup g = (SButtonGroup) e.getSource(); 65 Object button = g.getSelection(); 66 if (button == rb) { 67 borderLabel.setText("Raised Border"); 68 borderLabel.setBorder(raised); 69 } else if (button == lb) { 70 borderLabel.setText("Lowered Border"); 71 borderLabel.setBorder(lowered); 72 } else if (button == lineb) { 73 borderLabel.setText("Line Border"); 74 borderLabel.setBorder(line); 75 } else if (button == eb) { 76 borderLabel.setText("Titled Border"); 77 borderLabel.setBorder(titled); 78 } 79 borderLabel.getBorder().setThickness(thickness); 80 } 81 }); 82 83 rb.setSelected(true); 84 85 controls.addSizable(borderLabel); 86 87 SForm panel = new SForm(new SBorderLayout()); 88 panel.add(controls, SBorderLayout.NORTH); 89 panel.add(buttons, SBorderLayout.WEST); 90 panel.add(borderLabel, SBorderLayout.CENTER); 91 return panel; 92 } 93 94 class BorderControls extends ComponentControls { 95 96 public BorderControls() { 97 final STextField thicknessTextField = new STextField(); 98 addActionListener(new ActionListener () { 99 public void actionPerformed(ActionEvent event) { 100 try { 101 thickness = Integer.parseInt(thicknessTextField.getText()); 102 borderLabel.getBorder().setThickness(thickness); 103 } 104 catch (NumberFormatException e) {} 105 } 106 }); 107 108 add(new SLabel(" thicknessTextField ")); 109 add(thicknessTextField); 110 } 111 } 112 } 113 | Popular Tags |