/[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 621 - (show annotations)
Thu Jan 28 10:06:05 2010 UTC (15 years, 1 month ago) by alfonx
Original Path: branches/2.0-RC2/src/skrueger/swing/CancellableTabbedDialogAdapter.java
File MIME type: text/plain
File size: 3089 byte(s)
2.0-RC2 ist für die weiterentwicklung und soll bald in den trunk mergen
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
14 public abstract class CancellableTabbedDialogAdapter extends
15 CancellableDialogAdapter {
16
17 private final JTabbedPane tabbedPane;
18
19 public CancellableTabbedDialogAdapter(Component owner) {
20 super(owner);
21
22 /**
23 * Prepare buttons
24 */
25 final JPanel buttons = createButtons();
26
27 /*** Build GUI ***/
28 tabbedPane = new JTabbedPane(){
29 @Override
30 public void insertTab(String title, Icon icon, Component component,
31 String tip, int index) {
32 super.insertTab(title, icon, component, tip, index);
33 CancellableTabbedDialogAdapter.this.pack();
34 }
35 };
36
37 /**
38 * Building the content pane
39 */
40 final JPanel contentPane = new JPanel(new MigLayout("wrap 1"));
41 contentPane.add(getTabbedPane());
42 contentPane.add(buttons);
43
44 setContentPane(contentPane);
45
46 }
47
48 /**
49 * Is only called once! Doesn't use lazy initialization. Use
50 * <code>super.createButtons.add( newButton )</code> to add buttons.
51 */
52 protected JPanel createButtons() {
53 final JPanel buttonsJPanel = new JPanel(new MigLayout());
54
55 final OkButton okButton = new OkButton(new AbstractAction() {
56 {
57 // Set a mnemonic character. In most look and feels, this
58 // causes the
59 // specified character to be underlined This indicates that
60 // if the component
61 // using this action has the focus and In some look and
62 // feels, this causes
63 // the specified character in the label to be underlined and
64 putValue(Action.MNEMONIC_KEY, new Integer(
65 java.awt.event.KeyEvent.VK_E));
66
67 // Set tool tip text
68 putValue(Action.SHORT_DESCRIPTION,
69 "Accept the changes made in this dialog."); // i8n
70
71 }
72
73 //
74 public void actionPerformed(final ActionEvent evt) {
75 okClose();
76 }
77
78 });
79
80 buttonsJPanel.add(okButton);
81
82 final CancelButton cancelButton = new CancelButton(new AbstractAction(
83 "") {
84 public void actionPerformed(final ActionEvent evt) {
85 cancelClose();
86 }
87 });
88 buttonsJPanel.add(cancelButton);
89
90 return buttonsJPanel;
91 }
92
93 public JTabbedPane getTabbedPane() {
94 return tabbedPane;
95 }
96
97 /**
98 * Calling cancel() will call cancel to all {@link Cancellable} children in the tabbedPane.
99 */
100 @Override
101 public void cancel() {
102 cancelled = true;
103
104 for (int tIdx = 0; tIdx < tabbedPane.getTabCount(); tIdx++) {
105 final Component tab = tabbedPane.getComponentAt(tIdx);
106 if (tab instanceof Cancellable) {
107 ((Cancellable) tab).cancel();
108 }
109 }
110 }
111
112
113 @Override
114 public boolean okClose() {
115 // TranslationAskJDialog.this.firePropertyChange(
116 // PROPERTY_APPLY_AND_CLOSE, null, null);
117 //
118 for (int tIdx = 0; tIdx < tabbedPane.getTabCount(); tIdx++) {
119 final Component tab = tabbedPane.getComponentAt(tIdx);
120 if (tab instanceof Checkable) {
121 if (!((Checkable) tab).checkValidInputs())
122 return false;
123 }
124 }
125
126 dispose();
127
128 return true;
129 }
130 }

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