Statistics
| Revision:

gvsig-raster / org.gvsig.raster.multifile / trunk / org.gvsig.raster.multifile / org.gvsig.raster.multifile.app.multifileclient / src / main / java / org / gvsig / raster / multifile / app / panel / MainWindow.java @ 2178

History | View | Annotate | Download (5.29 KB)

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

    
23
import java.awt.BorderLayout;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26

    
27
import javax.swing.JComponent;
28

    
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.ui.mdiManager.IWindow;
31
import org.gvsig.andami.ui.mdiManager.WindowInfo;
32
import org.gvsig.i18n.Messages;
33
import org.gvsig.raster.swing.basepanel.AbstractButtonsPanel;
34
import org.gvsig.raster.swing.basepanel.IButtonsPanel;
35

    
36

    
37
/**
38
 * Basic frame for a gvSIG <code>IWindow</code> object. This frame adds buttons 
39
 * of Cancel, Accept and others.
40
 * 
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public class MainWindow extends AbstractButtonsPanel implements IWindow, ActionListener {
44
    
45
    private static final long  serialVersionUID = -4401123724140025094L;
46
    private ActionListener     listener         = null;
47
    private WindowInfo         info             = null;
48

    
49
    private Object profile = WindowInfo.EDITOR_PROFILE;
50

    
51
    public MainWindow(JComponent panel, String title, int w, int h, ActionListener actionListener) {
52
            this.listener = actionListener;
53
            
54
            setLayout(new BorderLayout());
55
                add(panel, BorderLayout.CENTER);
56

    
57
                getButtonsPanel().getButton(IButtonsPanel.BUTTON_APPLY).setVisible(false);
58
        getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
59
        getButtonsPanel().getButton(IButtonsPanel.BUTTON_CANCEL).addActionListener(this);
60
        
61
        info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
62
        info.setTitle(title);
63
        info.setWidth(w);
64
        info.setHeight(h);
65
    }
66
    
67
    public MainWindow(JComponent panel, String title, int w, int h, ActionListener actionListener, boolean mainPanel) {
68
            this.listener = actionListener;
69
            
70
            setLayout(new BorderLayout());
71
                add(panel, BorderLayout.CENTER);
72

    
73
                getButtonsPanel().getButton(IButtonsPanel.BUTTON_APPLY).setVisible(false);
74
                
75
                if(mainPanel) {
76
                        getButtonsPanel().addButton(Messages.getText("load_layer"), IButtonsPanel.BUTTON_USR1);
77
                        getButtonsPanel().addButton(Messages.getText("generate_file"), IButtonsPanel.BUTTON_USR2);
78
                        getButtonsPanel().getButton(IButtonsPanel.BUTTON_APPLY).setVisible(false);
79
                        getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT).setVisible(false);
80
                        getButtonsPanel().getButton(IButtonsPanel.BUTTON_CANCEL).setVisible(false);
81
                        getButtonsPanel().addClose();
82
                        getButtonsPanel().getButton(IButtonsPanel.BUTTON_CLOSE).addActionListener(this);
83
                getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR1).addActionListener(this);
84
                getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR2).addActionListener(this);
85
                } else {
86
                        getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
87
                        getButtonsPanel().getButton(IButtonsPanel.BUTTON_CANCEL).addActionListener(this);
88
                }
89
        
90
        info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE);
91
        info.setTitle(title);
92
        info.setWidth(w);
93
        info.setHeight(h);
94
    }
95

    
96
    public WindowInfo getWindowInfo() {
97
        return info;
98
    }
99

    
100
    public Object getWindowProfile() {
101
        return profile;
102
    }
103

    
104
    public void actionPerformed(ActionEvent e) {
105
            if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR1)) {
106
                    listener.actionPerformed(new ActionEvent(e.getSource(), IButtonsPanel.BUTTON_USR1, e.getActionCommand()));
107
                    PluginServices.getMDIManager().closeWindow(this);
108
            }
109
            
110
            if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR2)) {
111
                    listener.actionPerformed(new ActionEvent(e.getSource(), IButtonsPanel.BUTTON_USR2, e.getActionCommand()));
112
                    PluginServices.getMDIManager().closeWindow(this);
113
            }
114
            
115
            if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT)) {
116
                    listener.actionPerformed(new ActionEvent(e.getSource(), IButtonsPanel.BUTTON_ACCEPT, e.getActionCommand()));
117
                    PluginServices.getMDIManager().closeWindow(this);
118
            }
119
            
120
            if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_APPLY)) {
121
                    listener.actionPerformed(new ActionEvent(e.getSource(), IButtonsPanel.BUTTON_APPLY, e.getActionCommand()));
122
            }
123
            
124
            if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_CANCEL)) {
125
                    PluginServices.getMDIManager().closeWindow(this);
126
            }
127
            
128
            if(e.getSource() == getButtonsPanel().getButton(IButtonsPanel.BUTTON_CLOSE)) {
129
                    PluginServices.getMDIManager().closeWindow(this);
130
            }
131
    }
132
}