1 | // Copyright 2004-2007 Jean-Francois Poilpret |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package net.sourceforge.hivegui.dialog; |
16 | |
17 | import java.awt.GridBagConstraints; |
18 | import java.awt.GridBagLayout; |
19 | import java.awt.Insets; |
20 | import java.util.ArrayList; |
21 | import java.util.List; |
22 | |
23 | import javax.swing.JTabbedPane; |
24 | |
25 | abstract public class AbstractTabbedDialogPanel extends AbstractDialogPanel |
26 | { |
27 | protected AbstractTabbedDialogPanel(String id) |
28 | { |
29 | super(id); |
30 | _tabbedPane.setName(id + "-tabs"); |
31 | setLayout(new GridBagLayout()); |
32 | GridBagConstraints constraints = new GridBagConstraints(); |
33 | constraints.gridx = 0; |
34 | constraints.gridy = 0; |
35 | constraints.gridwidth = 1; |
36 | constraints.gridheight = 1; |
37 | constraints.anchor = GridBagConstraints.NORTHWEST; |
38 | constraints.fill = GridBagConstraints.BOTH; |
39 | constraints.weightx = 1.0; |
40 | constraints.weighty = 1.0; |
41 | constraints.insets = new Insets(INSETS, INSETS, INSETS, INSETS); |
42 | add(_tabbedPane, constraints); |
43 | } |
44 | |
45 | @Override protected void initLayout() |
46 | { |
47 | int index = 0; |
48 | for (DialogTabPanel tab: _tabs) |
49 | { |
50 | tab.setContext(_context); |
51 | String title = tab.getDialogTitle(); |
52 | if (title != null) |
53 | { |
54 | _tabbedPane.setTitleAt(index, title); |
55 | } |
56 | index++; |
57 | } |
58 | } |
59 | |
60 | final protected void acceptAllTabs() |
61 | { |
62 | for (DialogTabPanel tab: _tabs) |
63 | { |
64 | tab.accept(); |
65 | } |
66 | } |
67 | |
68 | @Override public void reset() |
69 | { |
70 | for (DialogTabPanel panel: _tabs) |
71 | { |
72 | panel.reset(); |
73 | } |
74 | } |
75 | |
76 | @Override public boolean canClose() |
77 | { |
78 | for (DialogTabPanel panel: _tabs) |
79 | { |
80 | if (!panel.canClose()) |
81 | { |
82 | return false; |
83 | } |
84 | } |
85 | return true; |
86 | } |
87 | |
88 | final public void addTabPane(DialogTabPanel tabPane) |
89 | { |
90 | _tabs.add(tabPane); |
91 | _tabbedPane.add(tabPane.getPanel()); |
92 | } |
93 | |
94 | static final private int INSETS = 4; |
95 | protected JTabbedPane _tabbedPane = new JTabbedPane(); |
96 | protected List<DialogTabPanel> _tabs = new ArrayList<DialogTabPanel>(); |
97 | } |