/[schmitzm]/branches/2.4.x/src/skrueger/swing/CancellableTabbedDialogAdapter.java
ViewVC logotype

Annotation of /branches/2.4.x/src/skrueger/swing/CancellableTabbedDialogAdapter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1370 - (hide annotations)
Mon Jan 17 15:18:04 2011 UTC (14 years, 1 month ago) by alfonx
Original Path: trunk/src/skrueger/swing/CancellableTabbedDialogAdapter.java
File MIME type: text/plain
File size: 3261 byte(s)
Gp-Feature: The position of the maplogo can now be defined: TOP-LEFT, BOTTOM-RIGHT etc...
1 alfonx 434 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 alfonx 1370 public CancellableTabbedDialogAdapter(Component owner, String title) {
20     super(owner, title);
21 alfonx 434
22     /**
23     * Prepare buttons
24     */
25     final JPanel buttons = createButtons();
26    
27     /*** Build GUI ***/
28 alfonx 1370 tabbedPane = new JTabbedPane() {
29 alfonx 434 @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 alfonx 1370 public CancellableTabbedDialogAdapter(Component parentWindow) {
49     this(parentWindow, null);
50     }
51    
52 alfonx 434 /**
53     * Is only called once! Doesn't use lazy initialization. Use
54     * <code>super.createButtons.add( newButton )</code> to add buttons.
55     */
56     protected JPanel createButtons() {
57 alfonx 497 final JPanel buttonsJPanel = new JPanel(new MigLayout());
58 alfonx 434
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 alfonx 1370 "Accept the changes made in this dialog."); // i8n i8n
74     // i8n
75 alfonx 434 }
76    
77     //
78     public void actionPerformed(final ActionEvent evt) {
79     okClose();
80     }
81    
82     });
83    
84 alfonx 711 buttonsJPanel.add(okButton, "tag ok");
85 alfonx 434
86     final CancelButton cancelButton = new CancelButton(new AbstractAction(
87     "") {
88     public void actionPerformed(final ActionEvent evt) {
89     cancelClose();
90     }
91     });
92 alfonx 711 buttonsJPanel.add(cancelButton, "tag cancel");
93 alfonx 434
94     return buttonsJPanel;
95     }
96    
97     public JTabbedPane getTabbedPane() {
98     return tabbedPane;
99     }
100 alfonx 1370
101 alfonx 434 /**
102 alfonx 1370 * Calling cancel() will call cancel to all {@link Cancellable} children in
103     * the tabbedPane.
104 alfonx 434 */
105     @Override
106     public void cancel() {
107     cancelled = true;
108    
109     for (int tIdx = 0; tIdx < tabbedPane.getTabCount(); tIdx++) {
110     final Component tab = tabbedPane.getComponentAt(tIdx);
111     if (tab instanceof Cancellable) {
112     ((Cancellable) tab).cancel();
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