1 29 30 package echo2example.email; 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 setModal(true); 93 94 SplitPane splitPane = new SplitPane(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP, new Extent(32)); 95 add(splitPane); 96 97 Row controlsRow = new Row(); 98 controlsRow.setStyleName("ControlPane"); 99 splitPane.add(controlsRow); 100 101 Button button; 102 switch (controlConfiguration) { 103 case CONTROLS_OK: 104 button = new Button(Messages.getString("Generic.Ok"), Styles.ICON_24_YES); 105 button.setStyleName("ControlPane.Button"); 106 button.setActionCommand(COMMAND_OK); 107 button.addActionListener(actionProcessor); 108 controlsRow.add(button); 109 break; 110 case CONTROLS_YES_NO: 111 button = new Button(Messages.getString("Generic.Yes"), Styles.ICON_24_YES); 112 button.setStyleName("ControlPane.Button"); 113 button.setActionCommand(COMMAND_OK); 114 button.addActionListener(actionProcessor); 115 controlsRow.add(button); 116 button = new Button(Messages.getString("Generic.No"), Styles.ICON_24_NO); 117 button.setStyleName("ControlPane.Button"); 118 button.setActionCommand(COMMAND_CANCEL); 119 button.addActionListener(actionProcessor); 120 controlsRow.add(button); 121 break; 122 } 123 124 Label contentLabel = new Label(message); 125 contentLabel.setStyleName("MessageDialog.ContentLabel"); 126 splitPane.add(contentLabel); 127 128 setModal(true); 129 } 130 131 139 public void addActionListener(ActionListener l) { 140 getEventListenerList().addListener(ActionListener.class, l); 141 } 142 143 149 public void removeActionListener(ActionListener l) { 150 getEventListenerList().removeListener(ActionListener.class, l); 151 } 152 } 153 | Popular Tags |