Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.framework / org.gvsig.andami / src / main / java / org / gvsig / andami / ui / ToolsWindowManager.java @ 41854

History | View | Annotate | Download (4.81 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.andami.ui;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Dimension;
28
import java.awt.GridBagConstraints;
29
import java.awt.event.ComponentEvent;
30
import java.awt.event.ComponentListener;
31

    
32
import javax.swing.JComponent;
33
import javax.swing.JPanel;
34
import javax.swing.event.AncestorEvent;
35
import javax.swing.event.AncestorListener;
36

    
37
import org.gvsig.andami.PluginServices;
38
import org.gvsig.andami.ui.mdiManager.IWindow;
39
import org.gvsig.andami.ui.mdiManager.MDIManager;
40
import org.gvsig.andami.ui.mdiManager.WindowInfo;
41
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
42

    
43

    
44
/**
45
 * @author gvSIG Team
46
 * @version $Id$
47
 *
48
 */
49
public class ToolsWindowManager implements WindowManager {
50

    
51
    public void showWindow(JComponent contents, String title, MODE mode) {
52
        int align;
53
        switch(mode) {
54
        case DIALOG:
55
            align = GridBagConstraints.CENTER;
56
            break;
57
        case TOOL:
58
            align = GridBagConstraints.FIRST_LINE_END;
59
            break;
60
        case WINDOW:
61
        default:
62
            align = GridBagConstraints.FIRST_LINE_START;
63
            break;
64
        }
65
        showWindow(contents, title, mode, align);
66
    }
67

    
68
    public void showWindow(JComponent contents, String title, MODE mode, int align ) {
69
        MDIManager manager = PluginServices.getMDIManager();
70
        IWindow window = new Window(contents, title, mode);
71
        manager.addWindow(window,align);
72
    }
73

    
74
    public class Window extends JPanel implements IWindow, ComponentListener {
75

    
76
        /**
77
         * 
78
         */
79
        private static final long serialVersionUID = -6688594664366192449L;
80
        protected WindowInfo windowInfo;
81
        protected Object profile;
82
        protected JComponent contents;
83
        
84
        public Window(JComponent contents, String title, MODE mode) {
85
            int code = WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE | WindowInfo.ICONIFIABLE; 
86
            switch(mode) {
87
            case DIALOG:
88
                code |= WindowInfo.MODALDIALOG;
89
                profile = WindowInfo.DIALOG_PROFILE;
90
                break;
91
            case TOOL:
92
                code |= WindowInfo.MODELESSDIALOG | WindowInfo.PALETTE;
93
                profile = WindowInfo.TOOL_PROFILE;
94
                break;
95
            case WINDOW:
96
            default:
97
                profile = WindowInfo.EDITOR_PROFILE;
98
                break;
99
            }
100
            
101
            this.contents = contents;
102
            
103
            this.windowInfo = new WindowInfo(code);
104
            this.windowInfo.setTitle(title);
105
            
106
            Dimension size = this.contents.getPreferredSize(); 
107
            this.windowInfo.setHeight(size.height);
108
            this.windowInfo.setWidth(size.width);
109
            
110
            this.setLayout(new BorderLayout());
111
            this.add(this.contents,BorderLayout.CENTER);
112
            
113
            this.contents.addComponentListener(this);
114
        }
115
        
116
        public void fireClosingWindow() {
117
            this.contents.removeComponentListener(this);
118
            ComponentListener[] l = this.contents.getComponentListeners();
119
            for( int i=0; i<l.length; i++) {
120
                l[i].componentHidden(new ComponentEvent(this, i));
121
            }
122
        }
123
        
124
        public WindowInfo getWindowInfo() {
125
            return this.windowInfo;
126
        }
127

    
128
        public Object getWindowProfile() {
129
            return this.profile;
130
        }
131

    
132
        public void componentHidden(ComponentEvent arg0) {
133
            // Close window when hide contents panel.
134
            MDIManager manager = PluginServices.getMDIManager();
135
            manager.closeWindow(this);
136
        }
137

    
138
        public void componentMoved(ComponentEvent arg0) {
139
            // Do nothing
140
        }
141

    
142
        public void componentResized(ComponentEvent arg0) {
143
            // Do nothing
144
        }
145

    
146
        public void componentShown(ComponentEvent arg0) {
147
            // Do nothing
148
        }
149

    
150
    }
151
}