Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / MainWindow.java @ 2480

History | View | Annotate | Download (3.39 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.tools.app.basic;
22

    
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.event.ActionEvent;
26
import java.awt.event.ActionListener;
27

    
28
import javax.swing.JComponent;
29

    
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.andami.ui.mdiManager.WindowInfo;
33
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
34
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
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 DefaultButtonsPanel 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, JComponent preview, String title, int w, int h, ActionListener actionListener) {
52
            this.listener = actionListener;
53
            
54
            setLayout(new GridBagLayout());
55
                GridBagConstraints gbc = new GridBagConstraints();
56
                gbc.fill = GridBagConstraints.BOTH;
57
                gbc.weightx = 1;
58
                gbc.weighty = 1;
59
                add(panel, gbc);
60
                
61
                if(preview != null) {
62
                        gbc.anchor = GridBagConstraints.NORTH;
63
                        gbc.fill = GridBagConstraints.NONE;
64
                        gbc.weightx = 0;
65
                        gbc.weighty = 0;
66
                        gbc.gridx = 1;
67
                        add(preview, gbc);
68
                }
69

    
70
        getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
71
        getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).addActionListener(this);
72
        getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(this);
73
        
74
        info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
75
        info.setTitle(title);
76
        info.setWidth(w);
77
        info.setHeight(h);
78
    }
79

    
80
    public WindowInfo getWindowInfo() {
81
        return info;
82
    }
83

    
84
    public Object getWindowProfile() {
85
        return profile;
86
    }
87

    
88
    public void actionPerformed(ActionEvent e) {
89
            if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT)) {
90
                    listener.actionPerformed(e);
91
                    PluginServices.getMDIManager().closeWindow(this);
92
            }
93
            
94
            if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY)) {
95
                    listener.actionPerformed(e);
96
            }
97
            
98
            if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL)) {
99
                    PluginServices.getMDIManager().closeWindow(this);
100
            }
101
    }
102
}