/[schmitzm]/trunk/src/skrueger/swing/CancellableTabbedDialogAdapter.java
ViewVC logotype

Contents of /trunk/src/skrueger/swing/CancellableTabbedDialogAdapter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 434 - (show annotations)
Sun Oct 4 18:38:11 2009 UTC (15 years, 4 months ago) by alfonx
Original Path: branches/1.0-gt2-2.6/src/skrueger/swing/CancellableTabbedDialogAdapter.java
File MIME type: text/plain
File size: 3190 byte(s)
* EditMapJDialog now also uses the new DialogManager 

1 package skrueger.swing;
2
3 import java.awt.Component;
4 import java.awt.event.ActionEvent;
5
6 import javax.swing.AbstractAction;
7 import javax.swing.Action;
8 import javax.swing.Icon;
9 import javax.swing.JTabbedPane;
10
11 import net.miginfocom.swing.MigLayout;
12 import schmitzm.swing.JPanel;
13 import schmitzm.swing.SwingUtil;
14
15 public abstract class CancellableTabbedDialogAdapter extends
16 CancellableDialogAdapter {
17
18 private final JTabbedPane tabbedPane;
19
20 public CancellableTabbedDialogAdapter(Component owner) {
21 super(owner);
22
23 /**
24 * Prepare buttons
25 */
26 final JPanel buttons = createButtons();
27
28 /*** Build GUI ***/
29 tabbedPane = new JTabbedPane(){
30 @Override
31 public void insertTab(String title, Icon icon, Component component,
32 String tip, int index) {
33 super.insertTab(title, icon, component, tip, index);
34 CancellableTabbedDialogAdapter.this.pack();
35 }
36 };
37
38 /**
39 * Building the content pane
40 */
41 final JPanel contentPane = new JPanel(new MigLayout("wrap 1"));
42 contentPane.add(getTabbedPane());
43 contentPane.add(buttons);
44
45 setContentPane(contentPane);
46 SwingUtil.centerFrameOnScreen(this);
47
48 }
49
50 /**
51 * Is only called once! Doesn't use lazy initialization. Use
52 * <code>super.createButtons.add( newButton )</code> to add buttons.
53 *
54 * @return
55 */
56 protected JPanel createButtons() {
57 final JPanel buttonsJPanel = new JPanel(new MigLayout("width 100%"));
58
59 final OkButton okButton = new OkButton(new AbstractAction() {
60 {
61 // Set a mnemonic character. In most look and feels, this
62 // causes the
63 // specified character to be underlined This indicates that
64 // if the component
65 // using this action has the focus and In some look and
66 // feels, this causes
67 // the specified character in the label to be underlined and
68 putValue(Action.MNEMONIC_KEY, new Integer(
69 java.awt.event.KeyEvent.VK_E));
70
71 // Set tool tip text
72 putValue(Action.SHORT_DESCRIPTION,
73 "Accept the changes made in this dialog."); // i8n
74
75 }
76
77 //
78 public void actionPerformed(final ActionEvent evt) {
79 okClose();
80 }
81
82 });
83
84 buttonsJPanel.add(okButton);
85
86 final CancelButton cancelButton = new CancelButton(new AbstractAction(
87 "") {
88 public void actionPerformed(final ActionEvent evt) {
89 cancelClose();
90 }
91 });
92 buttonsJPanel.add(cancelButton);
93
94 return buttonsJPanel;
95 }
96
97 public JTabbedPane getTabbedPane() {
98 return tabbedPane;
99 }
100
101 /**
102 * Calling cancel() will call cancel to all {@link Cancellable} children in the tabbedPane.
103 */
104 @Override
105 public void cancel() {
106 cancelled = true;
107
108 for (int tIdx = 0; tIdx < tabbedPane.getTabCount(); tIdx++) {
109 final Component tab = tabbedPane.getComponentAt(tIdx);
110 if (tab instanceof Cancellable) {
111 ((Cancellable) tab).cancel();
112 }
113 }
114 }
115
116
117 @Override
118 public boolean okClose() {
119 // TranslationAskJDialog.this.firePropertyChange(
120 // PROPERTY_APPLY_AND_CLOSE, null, null);
121 //
122 for (int tIdx = 0; tIdx < tabbedPane.getTabCount(); tIdx++) {
123 final Component tab = tabbedPane.getComponentAt(tIdx);
124 if (tab instanceof Checkable) {
125 if (!((Checkable) tab).checkValidInputs())
126 return false;
127 }
128 }
129
130 dispose();
131
132 return true;
133 }
134 }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26