Statistics
| Revision:

gvsig-scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.api / src / main / java / org / gvsig / scripting / swing / JDialog.java @ 35

History | View | Annotate | Download (4.79 KB)

1
package org.gvsig.scripting.swing;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Dimension;
6
import java.awt.Font;
7
import java.awt.event.ActionEvent;
8
import java.awt.event.ActionListener;
9
import java.awt.event.ComponentEvent;
10
import java.awt.event.ComponentListener;
11

    
12
import javax.swing.BorderFactory;
13
import javax.swing.Box;
14
import javax.swing.BoxLayout;
15
import javax.swing.JButton;
16
import javax.swing.JFrame;
17
import javax.swing.JLabel;
18
import javax.swing.JPanel;
19

    
20
import org.gvsig.scripting.ScriptingUIManager;
21
import org.gvsig.scripting.swing.composer.JMoveScript;
22
import org.gvsig.scripting.swing.composer.JNewScript;
23
import org.gvsig.scripting.swing.composer.JRenameScript;
24

    
25
public class JDialog extends JFrame implements ComponentListener{
26
        /**
27
         * 
28
         */
29
        private static final long serialVersionUID = 1L;
30
        protected JPanel PanelDialog = null;
31
        static JLabel status;
32

    
33
        public JDialog(ScriptingUIManager uimanager, String icon, String title, String description, final AbstractJDialogPanel content){
34
                super(title);
35
                this.setLayout(new BorderLayout());
36
                this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
37

    
38
                // Cabecera
39
        JLabel titleLabel = new JLabel(title);
40
                titleLabel.setFont(new Font("Serif",Font.BOLD,15));
41
                
42
                JLabel descriptionLabel = new JLabel(description);
43
                descriptionLabel.setFont(new Font("Serif",Font.PLAIN,12));
44
                
45
                JPanel titlePane = new JPanel(new BorderLayout());
46
                titlePane.add(titleLabel, BorderLayout.CENTER);
47
                titlePane.add(descriptionLabel, BorderLayout.SOUTH);
48
                titlePane.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 120));
49
                
50
        JLabel picture = new JLabel(uimanager.getIcon(icon,"big"));
51
        picture.setPreferredSize(new Dimension(50,50));
52
       
53
        JPanel header = new JPanel(new BorderLayout());
54
                header.add(picture, BorderLayout.EAST);
55
                header.add(titlePane, BorderLayout.CENTER);
56
                header.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 10));
57

    
58
                
59
                // Contenedor central
60
                JPanel contentPane = new JPanel(new BorderLayout());
61
                contentPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
62
                content.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, new Color(220,220,220)));
63
                contentPane.add(content, BorderLayout.CENTER);
64
                
65
                // Botonera
66
                JButton help = new JButton(uimanager.getIcon("help-browser"));
67
                help.setPreferredSize(new Dimension(25,25));
68
                help.addActionListener(new ActionListener(){
69
                        public void actionPerformed(ActionEvent arg0) {
70
                                
71
                        }
72
                });
73
                
74
                JPanel buttons = new JPanel(new BorderLayout());
75
                
76
                JPanel optionsPane = new JPanel();
77
                optionsPane.setLayout(new BoxLayout(optionsPane, BoxLayout.LINE_AXIS));
78
                optionsPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
79
                optionsPane.add(Box.createHorizontalGlue());
80
                if(content instanceof JNewScript)
81
                        ((JNewScript) content).addComponentListener(this);
82
                else if(content instanceof JMoveScript)
83
                        ((JMoveScript) content).addComponentListener(this);
84
                else if(content instanceof JRenameScript)
85
                        ((JRenameScript) content).addComponentListener(this);
86
                
87
                if(content.isVisibleAccept()){
88
                        JButton accept = new JButton("Accept");
89
                        accept.addActionListener(new ActionListener(){
90
                                public void actionPerformed(ActionEvent arg0) {
91
                                        content.actionAccept();
92
                                }
93
                        });
94
                        
95
                        optionsPane.add(accept);
96
                        optionsPane.add(Box.createRigidArea(new Dimension(10, 0)));
97
                }
98
                
99
                if(content.isVisibleCancel()){
100
                        JButton cancel = new JButton("Cancel");
101
                        cancel.addActionListener(new ActionListener(){
102
                                public void actionPerformed(ActionEvent arg0) {
103
                                         content.actionCancel();
104
                                }
105
                        });
106
                        
107
                        optionsPane.add(cancel);
108
                        optionsPane.add(Box.createRigidArea(new Dimension(10, 0)));
109
                }
110
                
111
                if( content.isVisibleApply()){
112
                        JButton apply = new JButton("Apply");
113
                        apply.addActionListener(new ActionListener(){
114
                                public void actionPerformed(ActionEvent arg0) {
115
                                        content.actionApply();
116
                                }
117
                        });
118
                        
119
                        optionsPane.add(apply);
120
                }
121

    
122
                JPanel helpPane = new JPanel();
123
                helpPane.setLayout(new BoxLayout(helpPane, BoxLayout.LINE_AXIS));
124
                helpPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
125
                helpPane.add(Box.createHorizontalGlue());
126
                helpPane.add(help);
127
        
128
                buttons.add(helpPane,BorderLayout.WEST);
129
                buttons.add(optionsPane, BorderLayout.EAST);
130
                
131
                
132
                // Integramos en el frame
133
                this.add(header, BorderLayout.NORTH);
134
                this.add(contentPane, BorderLayout.CENTER);
135
                this.add(buttons, BorderLayout.SOUTH);
136
                
137
                this.setSize(400,400);
138
                this.pack();
139
                this.setVisible(true);
140
                
141
        }
142

    
143
        public void componentHidden(ComponentEvent arg0) {
144
                this.setVisible(false);
145
                
146
        }
147

    
148
        public void componentMoved(ComponentEvent arg0) {
149
                // TODO Auto-generated method stub
150
                
151
        }
152

    
153
        public void componentResized(ComponentEvent arg0) {
154
                // TODO Auto-generated method stub
155
                
156
        }
157

    
158
        public void componentShown(ComponentEvent arg0) {
159
                // TODO Auto-generated method stub
160
                
161
        }
162
        
163
}