1 29 30 package echo2example.chatclient; 31 32 import java.util.EventListener ; 33 34 import nextapp.echo2.app.Button; 35 import nextapp.echo2.app.Extent; 36 import nextapp.echo2.app.Label; 37 import nextapp.echo2.app.Row; 38 import nextapp.echo2.app.SplitPane; 39 import nextapp.echo2.app.WindowPane; 40 import nextapp.echo2.app.event.ActionEvent; 41 import nextapp.echo2.app.event.ActionListener; 42 43 46 public class MessageDialog extends WindowPane { 47 48 public static final int TYPE_ERROR = 1; 49 public static final int TYPE_CONFIRM = 1; 50 51 public static final int CONTROLS_OK = 1; 52 public static final int CONTROLS_YES_NO = 2; 53 54 public static final String COMMAND_OK = "ok"; 55 public static final String COMMAND_CANCEL = "cancel"; 56 57 private ActionListener actionProcessor = new ActionListener() { 58 59 62 public void actionPerformed(ActionEvent e) { 63 getParent().remove(MessageDialog.this); 64 EventListener [] listeners = getEventListenerList().getListeners(ActionListener.class); 65 ActionEvent outgoingEvent = new ActionEvent(this, e.getActionCommand()); 66 for (int i = 0; i < listeners.length; ++i) { 67 ((ActionListener) listeners[i]).actionPerformed(outgoingEvent); 68 } 69 } 70 }; 71 72 89 public MessageDialog(String title, String message, int type, int controlConfiguration) { 90 super(title, new Extent(320), new Extent(240)); 91 setStyleName("Default"); 92 setClosable(false); 93 setModal(true); 94 95 SplitPane splitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(32)); 96 add(splitPane); 97 98 Row controlsRow = new Row(); 99 controlsRow.setStyleName("ControlPane"); 100 splitPane.add(controlsRow); 101 102 Button button; 103 switch (controlConfiguration) { 104 case CONTROLS_OK: 105 button = new Button(Messages.getString("Generic.Ok"), Styles.ICON_24_YES); 106 button.setStyleName("ControlPane.Button"); 107 button.setActionCommand(COMMAND_OK); 108 button.addActionListener(actionProcessor); 109 controlsRow.add(button); 110 break; 111 case CONTROLS_YES_NO: 112 button = new Button(Messages.getString("Generic.Yes"), Styles.ICON_24_YES); 113 button.setStyleName("ControlPane.Button"); 114 button.setActionCommand(COMMAND_OK); 115 button.addActionListener(actionProcessor); 116 controlsRow.add(button); 117 button = new Button(Messages.getString("Generic.No"), Styles.ICON_24_NO); 118 button.setStyleName("ControlPane.Button"); 119 button.setActionCommand(COMMAND_CANCEL); 120 button.addActionListener(actionProcessor); 121 controlsRow.add(button); 122 break; 123 } 124 125 Label contentLabel = new Label(message); 126 contentLabel.setStyleName("MessageDialog.ContentLabel"); 127 splitPane.add(contentLabel); 128 129 setModal(true); 130 } 131 132 140 public void addActionListener(ActionListener l) { 141 getEventListenerList().addListener(ActionListener.class, l); 142 } 143 144 150 public void removeActionListener(ActionListener l) { 151 getEventListenerList().removeListener(ActionListener.class, l); 152 } 153 } 154 | Popular Tags |