Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / project / document / table / gui / FeatureTableDocumentPanel.java @ 25778

History | View | Annotate | Download (7.43 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Gobernment (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {TableDocument implementation based on the gvSIG DAL API}
26
 */
27
package org.gvsig.project.document.table.gui;
28

    
29
import java.awt.BorderLayout;
30
import java.awt.FlowLayout;
31

    
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34
import javax.swing.ListSelectionModel;
35

    
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.feature.FeatureQuery;
38
import org.gvsig.fmap.dal.feature.FeatureSelection;
39
import org.gvsig.fmap.dal.feature.FeatureStore;
40
import org.gvsig.fmap.data.feature.swing.FeatureTablePanel;
41
import org.gvsig.fmap.data.feature.swing.FeatureTypesTablePanel;
42
import org.gvsig.project.document.table.FeatureTableDocument;
43
import org.gvsig.tools.observer.Observable;
44
import org.gvsig.tools.observer.Observer;
45

    
46
import com.iver.andami.PluginServices;
47
import com.iver.andami.ui.mdiManager.IWindowTransform;
48
import com.iver.andami.ui.mdiManager.SingletonWindow;
49
import com.iver.andami.ui.mdiManager.WindowInfo;
50
import javax.swing.JButton;
51
import java.awt.GridBagLayout;
52

    
53
/**
54
 * Feature table visualization panel.
55
 *
56
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
57
 */
58
public class FeatureTableDocumentPanel extends FeatureTypesTablePanel implements
59
        SingletonWindow, IWindowTransform, Observer {
60
    private boolean showTypes=false;
61
    private static final long serialVersionUID = -1003263265311764630L;
62

    
63
    private static final int DEFAULT_HEIGHT = 200;
64

    
65
    private static final int DEFAULT_WIDTH = 300;
66

    
67
    private boolean isPalette=false;
68

    
69
    private WindowInfo windowInfo = null;
70

    
71
    private FeatureTableDocument model = null;
72

    
73
        private JPanel jPanel;  //  @jve:decl-index=0:
74

    
75
        private JLabel jLabel;
76

    
77
        private JButton bShowFeatureTypes = null;
78
        private JPanel jPanel1 = null;
79

    
80
    /**
81
     * @see FeatureTablePanel#FeatureTablePanel(FeatureStore)
82
     */
83
    public FeatureTableDocumentPanel(FeatureStore featureStore)
84
            throws DataException {
85
        super(featureStore);
86
    }
87

    
88
    /**
89
     * @see FeatureTablePanel#FeatureTablePanel(FeatureStore, FeatureQuery)
90
     */
91
    public FeatureTableDocumentPanel(FeatureStore featureStore,
92
            FeatureQuery featureQuery) throws DataException {
93
        super(featureStore, featureQuery);
94
    }
95

    
96
    /**
97
     * @see FeatureTablePanel#FeatureTablePanel(FeatureStore, boolean)
98
     */
99
    public FeatureTableDocumentPanel(FeatureStore featureStore,
100
            boolean isDoubleBuffered) throws DataException {
101
        super(featureStore, isDoubleBuffered);
102
    }
103

    
104
    /**
105
     * @see FeatureTablePanel#FeatureTablePanel(FeatureStore, FeatureQuery,
106
     *      boolean)
107
     */
108
    public FeatureTableDocumentPanel(FeatureStore featureStore,
109
            FeatureQuery featureQuery, boolean isDoubleBuffered)
110
            throws DataException {
111
        super(featureStore, featureQuery, isDoubleBuffered);
112
    }
113

    
114
    // IWindow interface
115

    
116
    public WindowInfo getWindowInfo() {
117
            if (windowInfo==null) {
118
            windowInfo = new WindowInfo(WindowInfo.ICONIFIABLE
119
                | WindowInfo.MAXIMIZABLE | WindowInfo.RESIZABLE);
120

    
121
        // TODO: RETURN MORE USEFUL INFO ABOUT DATA VIEWED AND ADD I18N FOR
122
        // TEXTS
123
        windowInfo.setTitle("Tabla");
124

    
125
        windowInfo.setWidth(DEFAULT_WIDTH);
126
        windowInfo.setHeight(DEFAULT_HEIGHT);
127
            }
128
        return windowInfo;
129
    }
130

    
131
    // SingletonWindow interface
132

    
133
    public Object getWindowModel() {
134
        return getTableModel();
135
    }
136

    
137
    public void toPalette() {
138
                isPalette=true;
139
                windowInfo.toPalette(true);
140
                windowInfo.setClosed(false);
141
                PluginServices.getMDIManager().changeWindowInfo(this,getWindowInfo());
142
        }
143

    
144
        public void restore() {
145
                isPalette=false;
146
                windowInfo.toPalette(false);
147
                windowInfo.setClosed(false);
148
                PluginServices.getMDIManager().changeWindowInfo(this,getWindowInfo());
149
        }
150

    
151
        public boolean isPalette() {
152
                return isPalette;
153
        }
154
        public void setModel(FeatureTableDocument ftd){
155
                model=ftd;
156
                initialize();
157
        }
158

    
159
        public FeatureTableDocument getModel() {
160
                return model;
161
        }
162

    
163
        public void update(Observable arg0, Object arg1) {
164
                updateSelection();
165
                repaint();
166
        }
167

    
168
        public void updateSelection() {
169
                try {
170
                        ListSelectionModel sm=getTablePanel().getTable().getSelectionModel();
171
                        sm.clearSelection();
172
                        //TODO falta que implentar como transformar la selecci?n del store en la selecci?n de la tabla.
173
                        FeatureSelection selection=(FeatureSelection)getModel().getStore().getSelection();
174
                        jLabel.setText(selection.getSize() + " / " + getTableModel().getHelper().getTotalSize() + " " +
175
                                        PluginServices.getText(this, "registros_seleccionados_total") +
176
                        ".");
177
                } catch (DataException e) {
178
                        e.printStackTrace();
179
                }
180
        }
181

    
182
        public void stopEditing() {
183
                // TODO Auto-generated method stub
184

    
185
        }
186
        /**
187
         * This method initializes jPanel
188
         *
189
         * @return javax.swing.JPanel
190
         */
191
        private JPanel getJPanel() {
192
                if (jPanel == null) {
193

    
194
                        jLabel = new JLabel();
195
                        jLabel.setText(PluginServices.getText(this,"seleccionados")+ ":   ");
196
                        try {
197
                                FeatureStore store=getModel().getStore();
198
                                FeatureSelection selection = (FeatureSelection)store.getSelection();
199
                                jLabel.setText(selection.getSize() + " / " + getTableModel().getHelper().getTotalSize() + " " +
200
                        PluginServices.getText(this, "registros_seleccionados_total") +
201
                        ".");
202
                                jPanel = new JPanel();
203
                                BorderLayout borderLayout=new BorderLayout();
204
                                jPanel.setLayout(borderLayout);
205
                                jPanel.add(jLabel, BorderLayout.EAST);
206
                                jPanel.add(getJPanel1(), BorderLayout.WEST);
207
                        } catch (DataException e) {
208
                                e.printStackTrace();
209
                        }
210
                }
211
                return jPanel;
212
        }
213
        private void initialize(){
214
                add(getJPanel(),BorderLayout.SOUTH);
215
        }
216

    
217
        /**
218
         * This method initializes bShowFeatureTypes
219
         *
220
         * @return javax.swing.JButton
221
         */
222
        private JButton getBShowFeatureTypes() {
223
                if (bShowFeatureTypes == null) {
224
                        bShowFeatureTypes = new JButton();
225
                        bShowFeatureTypes.setText(PluginServices.getText(this,"show_types"));
226
                        bShowFeatureTypes.addActionListener(new java.awt.event.ActionListener() {
227
                                public void actionPerformed(java.awt.event.ActionEvent e) {
228
                                        showTypes=!showTypes;
229
                                        if (showTypes){
230
                                                bShowFeatureTypes.setText(PluginServices.getText(this,"hide_types"));
231
                                                showTypes();
232
                                        }else{
233
                                                bShowFeatureTypes.setText(PluginServices.getText(this,"show_types"));
234
                                                hideTypes();
235
                                        }
236
                                }
237
                        });
238
                }
239
                return bShowFeatureTypes;
240
        }
241

    
242
        /**
243
         * This method initializes jPanel1
244
         *
245
         * @return javax.swing.JPanel
246
         */
247
        private JPanel getJPanel1() {
248
                if (jPanel1 == null) {
249
                        jPanel1 = new JPanel();
250
                        jPanel1.setLayout(new GridBagLayout());
251
                        jPanel1.add(getBShowFeatureTypes(), null);
252
                }
253
                return jPanel1;
254
        }
255
}