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