001: package org.columba.mail.gui.message.viewer;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Dimension;
005: import java.awt.Frame;
006: import java.awt.HeadlessException;
007: import java.awt.event.ActionEvent;
008: import java.awt.event.ActionListener;
009: import java.awt.event.KeyEvent;
010:
011: import javax.swing.BorderFactory;
012: import javax.swing.DefaultListSelectionModel;
013: import javax.swing.JButton;
014: import javax.swing.JComponent;
015: import javax.swing.JDialog;
016: import javax.swing.JLabel;
017: import javax.swing.JPanel;
018: import javax.swing.JScrollPane;
019: import javax.swing.KeyStroke;
020: import javax.swing.SwingConstants;
021: import javax.swing.event.ListSelectionEvent;
022: import javax.swing.event.ListSelectionListener;
023:
024: import org.columba.core.gui.base.SingleSideEtchedBorder;
025: import org.columba.core.gui.util.DialogHeaderPanel;
026: import org.frapuccino.checkablelist.CheckableItemImpl;
027: import org.frapuccino.checkablelist.CheckableItemListTableModel;
028: import org.frapuccino.checkablelist.CheckableList;
029:
030: import com.jgoodies.forms.builder.ButtonBarBuilder;
031: import com.jgoodies.forms.builder.ButtonStackBuilder;
032: import com.jgoodies.forms.layout.CellConstraints;
033: import com.jgoodies.forms.layout.FormLayout;
034:
035: public class AddressListDialog extends JDialog implements
036: ActionListener, ListSelectionListener {
037:
038: private JButton addContactButton;
039:
040: private JButton composeButton;
041:
042: private JButton replyButton;
043:
044: private JButton forwardButton;
045:
046: private JButton closeButton;
047:
048: private JButton helpButton;
049:
050: private CheckableList list;
051:
052: private int index;
053:
054: private CheckableItemImpl selection;
055:
056: public AddressListDialog(Frame owner) throws HeadlessException {
057: super (owner, true);
058:
059: setTitle("Address Manager");
060:
061: initComponents();
062:
063: layoutComponents();
064:
065: getRootPane().registerKeyboardAction(this , "CLOSE",
066: KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
067: JComponent.WHEN_IN_FOCUSED_WINDOW);
068: pack();
069: setLocationRelativeTo(null);
070: setVisible(true);
071: }
072:
073: private void layoutComponents() {
074: setLayout(new BorderLayout());
075:
076: add(new DialogHeaderPanel("Manage Address List",
077: "Select email addresses for mass actions"),
078: BorderLayout.NORTH);
079:
080: getContentPane().add(createPanel(), BorderLayout.CENTER);
081:
082: add(createBottomPanel(), BorderLayout.SOUTH);
083:
084: }
085:
086: private JPanel createEastPanel() {
087: JPanel eastPanel = new JPanel();
088: ButtonStackBuilder builder = new ButtonStackBuilder(eastPanel);
089: builder.addGridded(addContactButton);
090: builder.addUnrelatedGap();
091: builder.addGridded(composeButton);
092: builder.addRelatedGap();
093: builder.addGridded(replyButton);
094: builder.addRelatedGap();
095: builder.addGridded(forwardButton);
096: return eastPanel;
097: }
098:
099: private JPanel createPanel() {
100: JPanel jpanel1 = new JPanel();
101: FormLayout formlayout1 = new FormLayout(
102: "FILL:DEFAULT:GROW(1.0),3DLU,FILL:DEFAULT:NONE",
103: "CENTER:DEFAULT:NONE,1DLU,FILL:DEFAULT:GROW(1.0),3DLU,CENTER:DEFAULT:NONE");
104: CellConstraints cc = new CellConstraints();
105: jpanel1.setBorder(BorderFactory.createEmptyBorder(12, 12, 12,
106: 12));
107: jpanel1.setLayout(formlayout1);
108:
109: JLabel jlabel1 = new JLabel();
110: jlabel1.setText("Email Address:");
111: jpanel1.add(jlabel1, cc.xy(1, 1));
112:
113: JScrollPane scrollPane = new JScrollPane(list);
114: scrollPane.setPreferredSize(new Dimension(250, 200));
115: jpanel1.add(scrollPane, cc.xy(1, 3));
116:
117: jpanel1.add(createEastPanel(), new CellConstraints(3, 3, 1, 1,
118: CellConstraints.DEFAULT, CellConstraints.TOP));
119:
120: return jpanel1;
121: }
122:
123: private JPanel createBottomPanel() {
124: JPanel bottomPanel = new JPanel(new BorderLayout());
125: bottomPanel.setBorder(new SingleSideEtchedBorder(
126: SwingConstants.TOP));
127:
128: JPanel buttonPanel = new JPanel();
129: buttonPanel.setBorder(BorderFactory.createEmptyBorder(12, 12,
130: 12, 12));
131:
132: ButtonBarBuilder builder2 = new ButtonBarBuilder(buttonPanel);
133: // builder.setDefaultButtonBarGapBorder();
134: builder2.addGlue();
135: builder2.addGriddedButtons(new JButton[] { closeButton,
136: helpButton });
137:
138: bottomPanel.add(buttonPanel, BorderLayout.EAST);
139:
140: return bottomPanel;
141: }
142:
143: private void initComponents() {
144:
145: list = new CheckableList();
146: list.getSelectionModel().addListSelectionListener(this );
147:
148: addContactButton = new JButton("Add Contacts");
149:
150: composeButton = new JButton("Compose");
151:
152: replyButton = new JButton("Reply");
153:
154: forwardButton = new JButton("Forward");
155:
156: // TODO i18n "Close" button
157: closeButton = new JButton("Close");
158: closeButton.setDefaultCapable(true);
159: closeButton.setMnemonic('C');
160: closeButton.addActionListener(new ActionListener() {
161: public void actionPerformed(ActionEvent event) {
162: setVisible(false);
163: }
164: });
165:
166: // TODO i18n "Help" button
167: helpButton = new JButton("Help");
168: helpButton.setMnemonic('h');
169: }
170:
171: public void valueChanged(ListSelectionEvent e) {
172: if (e.getValueIsAdjusting()) {
173: return;
174: }
175:
176: DefaultListSelectionModel theList = (DefaultListSelectionModel) e
177: .getSource();
178: if (!theList.isSelectionEmpty()) {
179: index = theList.getAnchorSelectionIndex();
180:
181: selection = (CheckableItemImpl) ((CheckableItemListTableModel) list
182: .getModel()).getElement(index);
183:
184: }
185: }
186:
187: public void actionPerformed(ActionEvent e) {
188: String action = e.getActionCommand();
189:
190: if (action.equals("OK")) {
191: } else if (action.equals("CANCEL")) {
192: setVisible(false);
193: }
194: }
195:
196: }
|