gvsig-scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.swing / org.gvsig.scripting.swing.impl / src / main / java / org / gvsig / scripting / swing / impl / JDialog.java @ 165
History | View | Annotate | Download (5.94 KB)
1 |
package org.gvsig.scripting.swing.impl; |
---|---|
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.help.HelpBroker; |
13 |
import javax.help.HelpSet; |
14 |
import javax.swing.BorderFactory; |
15 |
import javax.swing.Box; |
16 |
import javax.swing.BoxLayout; |
17 |
import javax.swing.JButton; |
18 |
import javax.swing.JLabel; |
19 |
import javax.swing.JPanel; |
20 |
|
21 |
import org.gvsig.scripting.swing.api.ScriptingUIManager; |
22 |
import org.gvsig.scripting.swing.impl.composer.JDefaultDialog; |
23 |
import org.gvsig.scripting.swing.impl.composer.JHelpSelection; |
24 |
import org.gvsig.scripting.swing.impl.composer.JImportHelp; |
25 |
import org.gvsig.scripting.swing.impl.composer.JMoveScript; |
26 |
import org.gvsig.scripting.swing.impl.composer.JNewScript; |
27 |
import org.gvsig.scripting.swing.impl.composer.JRemoveHelp; |
28 |
import org.gvsig.scripting.swing.impl.composer.JRenameScript; |
29 |
|
30 |
|
31 |
public class JDialog extends JPanel implements ComponentListener,ActionListener{ |
32 |
/**
|
33 |
*
|
34 |
*/
|
35 |
private static final long serialVersionUID = 1L; |
36 |
protected JPanel PanelDialog = null; |
37 |
static JLabel status; |
38 |
protected ScriptingUIManager uimanager;
|
39 |
protected JButton accept = null; |
40 |
|
41 |
public JDialog(ScriptingUIManager uimanager, String icon, String title, String description, final AbstractJDialogPanel content){ |
42 |
this.uimanager = uimanager;
|
43 |
this.setLayout(new BorderLayout()); |
44 |
|
45 |
// Cabecera
|
46 |
JLabel titleLabel = new JLabel(title); |
47 |
titleLabel.setFont(new Font("Serif",Font.BOLD,15)); |
48 |
|
49 |
JLabel descriptionLabel = new JLabel(description); |
50 |
descriptionLabel.setFont(new Font("Serif",Font.PLAIN,12)); |
51 |
|
52 |
JPanel titlePane = new JPanel(new BorderLayout()); |
53 |
titlePane.add(titleLabel, BorderLayout.CENTER);
|
54 |
titlePane.add(descriptionLabel, BorderLayout.SOUTH);
|
55 |
titlePane.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 120)); |
56 |
|
57 |
JLabel picture = new JLabel(uimanager.getIcon(icon,"big")); |
58 |
picture.setPreferredSize(new Dimension(50,50)); |
59 |
|
60 |
JPanel header = new JPanel(new BorderLayout()); |
61 |
header.add(picture, BorderLayout.EAST);
|
62 |
header.add(titlePane, BorderLayout.CENTER);
|
63 |
header.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 10)); |
64 |
|
65 |
|
66 |
// Contenedor central
|
67 |
JPanel contentPane = new JPanel(new BorderLayout()); |
68 |
contentPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5)); |
69 |
content.setBorder(BorderFactory.createMatteBorder(1, 0, 1, 0, new Color(220,220,220))); |
70 |
contentPane.add(content, BorderLayout.CENTER);
|
71 |
|
72 |
// Botonera
|
73 |
JButton help = new JButton(uimanager.getIcon("help-browser")); |
74 |
help.setPreferredSize(new Dimension(25,25)); |
75 |
help.addActionListener(new ActionListener(){ |
76 |
public void actionPerformed(ActionEvent arg0) { |
77 |
getHelpPanel(); |
78 |
} |
79 |
}); |
80 |
|
81 |
JPanel buttons = new JPanel(new BorderLayout()); |
82 |
|
83 |
JPanel optionsPane = new JPanel(); |
84 |
optionsPane.setLayout(new BoxLayout(optionsPane, BoxLayout.LINE_AXIS)); |
85 |
optionsPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
86 |
optionsPane.add(Box.createHorizontalGlue());
|
87 |
if(content instanceof JNewScript) |
88 |
((JNewScript) content).addComponentListener(this);
|
89 |
else if(content instanceof JMoveScript) |
90 |
((JMoveScript) content).addComponentListener(this);
|
91 |
else if(content instanceof JRenameScript) |
92 |
((JRenameScript) content).addComponentListener(this);
|
93 |
else if(content instanceof JImportHelp) |
94 |
((JImportHelp) content).addComponentListener(this);
|
95 |
else if(content instanceof JRemoveHelp) |
96 |
((JRemoveHelp) content).addComponentListener(this);
|
97 |
else if(content instanceof JHelpSelection){ |
98 |
((JHelpSelection) content).addComponentListener(this);
|
99 |
((JHelpSelection) content).addDefaultActionListener(this);
|
100 |
} |
101 |
else if(content instanceof JDefaultDialog) |
102 |
((JDefaultDialog) content).addComponentListener(this);
|
103 |
|
104 |
if(content.isVisibleAccept()){
|
105 |
accept = new JButton("Accept"); |
106 |
accept.addActionListener(new ActionListener(){ |
107 |
public void actionPerformed(ActionEvent arg0) { |
108 |
content.actionAccept(); |
109 |
} |
110 |
}); |
111 |
|
112 |
optionsPane.add(accept); |
113 |
optionsPane.add(Box.createRigidArea(new Dimension(10, 0))); |
114 |
} |
115 |
|
116 |
if(content.isVisibleCancel()){
|
117 |
JButton cancel = new JButton("Cancel"); |
118 |
cancel.addActionListener(new ActionListener(){ |
119 |
public void actionPerformed(ActionEvent arg0) { |
120 |
content.actionCancel(); |
121 |
} |
122 |
}); |
123 |
|
124 |
optionsPane.add(cancel); |
125 |
optionsPane.add(Box.createRigidArea(new Dimension(10, 0))); |
126 |
} |
127 |
|
128 |
if( content.isVisibleApply()){
|
129 |
JButton apply = new JButton("Apply"); |
130 |
apply.addActionListener(new ActionListener(){ |
131 |
public void actionPerformed(ActionEvent arg0) { |
132 |
content.actionApply(); |
133 |
} |
134 |
}); |
135 |
|
136 |
optionsPane.add(apply); |
137 |
} |
138 |
|
139 |
JPanel helpPane = new JPanel(); |
140 |
helpPane.setLayout(new BoxLayout(helpPane, BoxLayout.LINE_AXIS)); |
141 |
helpPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
142 |
helpPane.add(Box.createHorizontalGlue());
|
143 |
helpPane.add(help); |
144 |
|
145 |
buttons.add(helpPane,BorderLayout.WEST);
|
146 |
buttons.add(optionsPane, BorderLayout.EAST);
|
147 |
|
148 |
|
149 |
// Integramos en el frame
|
150 |
this.add(header, BorderLayout.NORTH); |
151 |
this.add(contentPane, BorderLayout.CENTER); |
152 |
this.add(buttons, BorderLayout.SOUTH); |
153 |
|
154 |
|
155 |
this.uimanager.showDialog(this, title); |
156 |
} |
157 |
|
158 |
public void getHelpPanel(){ |
159 |
uimanager.showWindow(uimanager.getHelp(),"JavaDoc");
|
160 |
} |
161 |
|
162 |
public void componentHidden(ComponentEvent arg0) { |
163 |
this.setVisible(false); |
164 |
|
165 |
} |
166 |
|
167 |
public void componentMoved(ComponentEvent arg0) { |
168 |
// TODO Auto-generated method stub
|
169 |
|
170 |
} |
171 |
|
172 |
public void componentResized(ComponentEvent arg0) { |
173 |
// TODO Auto-generated method stub
|
174 |
|
175 |
} |
176 |
|
177 |
public void componentShown(ComponentEvent arg0) { |
178 |
// TODO Auto-generated method stub
|
179 |
|
180 |
} |
181 |
|
182 |
public void actionPerformed(ActionEvent e) { |
183 |
if(this.accept!=null){ |
184 |
HelpBroker hb; |
185 |
HelpSet hs = uimanager.getManager().getHelpManager().getHelpSet(); |
186 |
|
187 |
hb = hs.createHelpBroker(); |
188 |
hb.enableHelpOnButton(this.accept, e.getActionCommand() , hs);
|
189 |
} |
190 |
} |
191 |
|
192 |
} |