Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.fmap.control / src / main / java / org / gvsig / propertypage / BasePropertiesPageDialog.java @ 42174

History | View | Annotate | Download (3.91 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.tools.ToolsLocator;
13
import org.gvsig.tools.i18n.I18nManager;
14

    
15

    
16
public class BasePropertiesPageDialog extends BasePropertiesPagePanelLayout implements org.gvsig.tools.swing.api.Component {
17
    public static final int ACTION_CANCEL = 0;
18
    public static final int ACTION_ACCEPT = 1;
19
    public static final int ACTION_APPLY = 2;
20

    
21
    private Object obj;
22
    private String groupID;
23
    private List<PropertiesPage> pages = null;
24
    private int userAction = ACTION_ACCEPT;
25
    
26
    public BasePropertiesPageDialog() {
27
    }
28

    
29
    public BasePropertiesPageDialog(Object obj, String groupID) {
30
        init(groupID, obj);
31
    }
32

    
33
    protected void init(String groupID, Object obj) {
34
        this.obj = obj;
35
        this.groupID = groupID;
36
        PropertiesPageManager manager = MapControlLocator.getPropertiesPageManager();
37
        this.pages = manager.getPages(this.groupID,this.obj);        
38
        initComponents();
39
    }
40
    
41
    protected void initComponents() {
42
        I18nManager i18nManager = ToolsLocator.getI18nManager(); 
43

    
44
        this.content.setLayout(new BorderLayout());
45
        this.content.add(createPropertiesPagesPanel(), BorderLayout.CENTER );
46

    
47
        this.titleLabel.setText("");
48
        
49
        this.acceptButton.setText(i18nManager.getTranslation("ok"));
50
        this.acceptButton.addActionListener( new ActionListener() {
51
            public void actionPerformed(ActionEvent ae) {
52
                whenAccept();
53
            }
54
        });
55
        this.applyButton.setText(i18nManager.getTranslation("apply"));
56
        this.applyButton.addActionListener( new ActionListener() {
57
            public void actionPerformed(ActionEvent ae) {
58
                whenApply();
59
            }
60
        });
61
        this.cancelButton.setText(i18nManager.getTranslation("cancel"));
62
        this.cancelButton.addActionListener( new ActionListener() {
63
            public void actionPerformed(ActionEvent ae) {
64
                whenCancel();
65
            }
66
        });
67

    
68
    }
69

    
70
    protected Component createPropertiesPagesPanel() {
71
        if( this.pages.size()==1 && !useTabsAlwais() ) {
72
            PropertiesPage page = this.pages.get(0);
73
            return page.asJComponent();
74
        } else {
75
            JTabbedPane tabbedPane = new JTabbedPane();
76
            for( int i=0; i<this.pages.size(); i++ ) {
77
                PropertiesPage page = this.pages.get(i);
78
                tabbedPane.addTab(page.getTitle(), page.asJComponent());
79
            }
80
            return tabbedPane;
81
        }
82
    }
83
    
84
    protected boolean useTabsAlwais() {
85
        return false;
86
    }
87
    
88
    public void whenAccept() {
89
        for( int i=0; i<this.pages.size(); i++ ) {
90
            PropertiesPage page = this.pages.get(i);
91
            if( ! page.whenAccept() ) {
92
                return;
93
            }
94
        }
95
        this.userAction = ACTION_ACCEPT;
96
        this.closeDialog();
97
    }
98
    
99
    public void whenApply() {
100
        for( int i=0; i<this.pages.size(); i++ ) {
101
            PropertiesPage page = this.pages.get(i);
102
            if( ! page.whenApply() ) {
103
                return;
104
            }
105
        }
106
        this.userAction = ACTION_APPLY;
107
    }
108
    
109
    public void whenCancel() {
110
        for( int i=0; i<this.pages.size(); i++ ) {
111
            PropertiesPage page = this.pages.get(i);
112
            if( ! page.whenCancel() ) {
113
                return;
114
            }
115
        }
116
        this.userAction = ACTION_CANCEL;
117
        this.closeDialog();
118
    }
119
    
120
    public int getUserAction() {
121
        return this.userAction;
122
    }
123
    
124
    protected void closeDialog() {
125
        this.setVisible(false);
126
    }
127

    
128
    public JComponent asJComponent() {
129
        return this;
130
    }
131
    
132
    
133
}