svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / propertypage / BasePropertiesPageDialog.java @ 43743
History | View | Annotate | Download (5.27 KB)
1 |
|
---|---|
2 |
package org.gvsig.propertypage; |
3 |
|
4 |
import java.awt.BorderLayout; |
5 |
import java.awt.Component; |
6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.event.ActionListener; |
8 |
import java.util.List; |
9 |
import javax.swing.JComponent; |
10 |
import javax.swing.JTabbedPane; |
11 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
12 |
import org.gvsig.propertypage.PropertiesPage.SetPageEnabledEvent; |
13 |
import org.gvsig.tools.ToolsLocator; |
14 |
import org.gvsig.tools.i18n.I18nManager; |
15 |
import org.gvsig.tools.swing.api.ActionListenerSupport; |
16 |
import org.gvsig.tools.util.Invocable; |
17 |
|
18 |
|
19 |
public class BasePropertiesPageDialog extends BasePropertiesPagePanelLayout implements org.gvsig.tools.swing.api.Component { |
20 |
public static final int ACTION_CANCEL = 0; |
21 |
public static final int ACTION_ACCEPT = 1; |
22 |
public static final int ACTION_APPLY = 2; |
23 |
|
24 |
private Object obj; |
25 |
private String groupID; |
26 |
private List<PropertiesPage> pages = null; |
27 |
private int userAction = ACTION_ACCEPT; |
28 |
private JTabbedPane tabbedPane = null; |
29 |
|
30 |
public BasePropertiesPageDialog() {
|
31 |
} |
32 |
|
33 |
public BasePropertiesPageDialog(Object obj, String groupID) { |
34 |
init(groupID, obj); |
35 |
} |
36 |
|
37 |
protected void init(String groupID, Object obj) { |
38 |
this.obj = obj;
|
39 |
this.groupID = groupID;
|
40 |
PropertiesPageManager manager = MapControlLocator.getPropertiesPageManager(); |
41 |
this.pages = manager.getPages(this.groupID,this.obj); |
42 |
initComponents(); |
43 |
} |
44 |
|
45 |
protected void initComponents() { |
46 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
47 |
|
48 |
this.content.setLayout(new BorderLayout()); |
49 |
Component contents = createPropertiesPagesPanel();
|
50 |
if( contents instanceof JTabbedPane ) { |
51 |
this.tabbedPane = (JTabbedPane) contents; |
52 |
} |
53 |
this.content.add(contents, BorderLayout.CENTER ); |
54 |
|
55 |
this.titleLabel.setText(""); |
56 |
|
57 |
this.acceptButton.setText(i18nManager.getTranslation("accept")); |
58 |
this.acceptButton.addActionListener( new ActionListener() { |
59 |
@Override
|
60 |
public void actionPerformed(ActionEvent ae) { |
61 |
whenAccept(); |
62 |
} |
63 |
}); |
64 |
this.applyButton.setText(i18nManager.getTranslation("apply")); |
65 |
this.applyButton.addActionListener( new ActionListener() { |
66 |
@Override
|
67 |
public void actionPerformed(ActionEvent ae) { |
68 |
whenApply(); |
69 |
} |
70 |
}); |
71 |
this.cancelButton.setText(i18nManager.getTranslation("cancel")); |
72 |
this.cancelButton.addActionListener( new ActionListener() { |
73 |
@Override
|
74 |
public void actionPerformed(ActionEvent ae) { |
75 |
whenCancel(); |
76 |
} |
77 |
}); |
78 |
|
79 |
} |
80 |
|
81 |
protected Component createPropertiesPagesPanel() { |
82 |
if( this.pages.size()==1 && !useTabsAlwais() ) { |
83 |
PropertiesPage page = this.pages.get(0); |
84 |
return page.asJComponent();
|
85 |
} else {
|
86 |
JTabbedPane tabbedPane = new JTabbedPane(); |
87 |
for( int i=0; i<this.pages.size(); i++ ) { |
88 |
PropertiesPage page = this.pages.get(i);
|
89 |
if( page instanceof ActionListenerSupport ) { |
90 |
((ActionListenerSupport)page).addActionListener(new ActionListener() { |
91 |
@Override
|
92 |
public void actionPerformed(ActionEvent e) { |
93 |
if( e instanceof SetPageEnabledEvent ) { |
94 |
SetPageEnabledEvent ee = (SetPageEnabledEvent) e; |
95 |
setEnabledAt(ee.getFilter(), ee.isEnabled()); |
96 |
} |
97 |
} |
98 |
}); |
99 |
} |
100 |
tabbedPane.addTab(page.getTitle(), page.asJComponent()); |
101 |
} |
102 |
return tabbedPane;
|
103 |
} |
104 |
} |
105 |
|
106 |
protected boolean useTabsAlwais() { |
107 |
return false; |
108 |
} |
109 |
|
110 |
public void whenAccept() { |
111 |
for( int i=0; i<this.pages.size(); i++ ) { |
112 |
PropertiesPage page = this.pages.get(i);
|
113 |
if( ! page.whenAccept() ) {
|
114 |
return;
|
115 |
} |
116 |
} |
117 |
this.userAction = ACTION_ACCEPT;
|
118 |
this.closeDialog();
|
119 |
} |
120 |
|
121 |
public void whenApply() { |
122 |
for( int i=0; i<this.pages.size(); i++ ) { |
123 |
PropertiesPage page = this.pages.get(i);
|
124 |
if( ! page.whenApply() ) {
|
125 |
return;
|
126 |
} |
127 |
} |
128 |
this.userAction = ACTION_APPLY;
|
129 |
} |
130 |
|
131 |
public void whenCancel() { |
132 |
for( int i=0; i<this.pages.size(); i++ ) { |
133 |
PropertiesPage page = this.pages.get(i);
|
134 |
if( ! page.whenCancel() ) {
|
135 |
return;
|
136 |
} |
137 |
} |
138 |
this.userAction = ACTION_CANCEL;
|
139 |
this.closeDialog();
|
140 |
} |
141 |
|
142 |
public int getUserAction() { |
143 |
return this.userAction; |
144 |
} |
145 |
|
146 |
protected void closeDialog() { |
147 |
this.setVisible(false); |
148 |
} |
149 |
|
150 |
@Override
|
151 |
public JComponent asJComponent() { |
152 |
return this; |
153 |
} |
154 |
|
155 |
public void setEnabledAt(Invocable filter, boolean enabled) { |
156 |
if( this.tabbedPane==null ) { |
157 |
return;
|
158 |
} |
159 |
for( int i=0; i<this.pages.size(); i++ ) { |
160 |
PropertiesPage page = this.pages.get(i);
|
161 |
if( (Boolean)(filter.call(page)) ) { |
162 |
this.tabbedPane.setEnabledAt(i, enabled);
|
163 |
} |
164 |
} |
165 |
} |
166 |
|
167 |
} |