gvsig-raster / org.gvsig.raster.tools / trunk / templates / rasterTaskProjectTemplate / alg_with_preview_template / sources / app / ProjectTemplateWindow.java @ 2356
History | View | Annotate | Download (4.33 KB)
1 |
package org.gvsig.raster.projecttemplate.app; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.GridBagConstraints; |
5 |
import java.awt.GridBagLayout; |
6 |
import java.awt.event.ActionEvent; |
7 |
import java.awt.event.ActionListener; |
8 |
|
9 |
import javax.swing.JComponent; |
10 |
import javax.swing.JPanel; |
11 |
import javax.swing.JSplitPane; |
12 |
import javax.swing.border.Border; |
13 |
import javax.swing.plaf.basic.BasicSplitPaneDivider; |
14 |
import javax.swing.plaf.basic.BasicSplitPaneUI; |
15 |
|
16 |
import org.gvsig.andami.PluginServices; |
17 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
18 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
19 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
20 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
21 |
|
22 |
public class ProjectTemplateWindow extends DefaultButtonsPanel implements IWindow, ActionListener { |
23 |
|
24 |
private static final long serialVersionUID = -4401123724140025094L; |
25 |
private ActionListener listener = null; |
26 |
private WindowInfo info = null; |
27 |
|
28 |
private Object profile = WindowInfo.EDITOR_PROFILE; |
29 |
|
30 |
public ProjectTemplateWindow(JComponent panel, |
31 |
JComponent preview,
|
32 |
String title,
|
33 |
int w,
|
34 |
int h,
|
35 |
boolean fixedPreview,
|
36 |
ActionListener actionListener) {
|
37 |
this.listener = actionListener;
|
38 |
|
39 |
if(fixedPreview)
|
40 |
fixedPreview(panel, preview); |
41 |
else
|
42 |
redimPreview(panel, preview); |
43 |
|
44 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).addActionListener(this);
|
45 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setVisible(false);
|
46 |
//getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).addActionListener(this);
|
47 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(this);
|
48 |
|
49 |
info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
|
50 |
info.setTitle(title); |
51 |
info.setWidth(w); |
52 |
info.setHeight(h); |
53 |
} |
54 |
|
55 |
private void fixedPreview(JComponent panel, JComponent preview) { |
56 |
setLayout(new GridBagLayout()); |
57 |
GridBagConstraints gbc = new GridBagConstraints(); |
58 |
gbc.fill = GridBagConstraints.BOTH;
|
59 |
gbc.weightx = 1;
|
60 |
gbc.weighty = 1;
|
61 |
add(panel, gbc); |
62 |
|
63 |
if(preview != null) { |
64 |
gbc.anchor = GridBagConstraints.NORTH;
|
65 |
gbc.fill = GridBagConstraints.NONE;
|
66 |
gbc.weightx = 0;
|
67 |
gbc.weighty = 0;
|
68 |
gbc.gridx = 1;
|
69 |
add(preview, gbc); |
70 |
} |
71 |
} |
72 |
|
73 |
private void redimPreview(JComponent panel, JComponent preview) { |
74 |
setLayout(new BorderLayout()); |
75 |
JSplitPane splitPane = new JSplitPane(); |
76 |
splitPane.setLeftComponent(panel); |
77 |
splitPane.setRightComponent(getPreviewForRedimPreviewPanel(preview)); |
78 |
splitPane.setResizeWeight(1.0);
|
79 |
splitPane.setContinuousLayout(true);
|
80 |
splitPane.setOneTouchExpandable(true);
|
81 |
splitPane.setUI(new BasicSplitPaneUI() { |
82 |
public BasicSplitPaneDivider createDefaultDivider() { |
83 |
return new BasicSplitPaneDivider(this) { |
84 |
private static final long serialVersionUID = 1L; |
85 |
|
86 |
public void setBorder(Border b) { |
87 |
} |
88 |
}; |
89 |
} |
90 |
}); |
91 |
splitPane.setBorder(null);
|
92 |
add(splitPane, BorderLayout.CENTER);
|
93 |
} |
94 |
|
95 |
private JSplitPane getPreviewForRedimPreviewPanel(JComponent preview) { |
96 |
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
97 |
splitPane.setTopComponent(preview); |
98 |
splitPane.setBottomComponent(new JPanel()); |
99 |
splitPane.setResizeWeight(0);
|
100 |
splitPane.setContinuousLayout(true);
|
101 |
splitPane.setOneTouchExpandable(true);
|
102 |
splitPane.setUI(new BasicSplitPaneUI() { |
103 |
public BasicSplitPaneDivider createDefaultDivider() { |
104 |
return new BasicSplitPaneDivider(this) { |
105 |
private static final long serialVersionUID = 1L; |
106 |
|
107 |
public void setBorder(Border b) { |
108 |
} |
109 |
}; |
110 |
} |
111 |
}); |
112 |
splitPane.setBorder(null);
|
113 |
return splitPane;
|
114 |
} |
115 |
|
116 |
public WindowInfo getWindowInfo() {
|
117 |
return info;
|
118 |
} |
119 |
|
120 |
public Object getWindowProfile() { |
121 |
return profile;
|
122 |
} |
123 |
|
124 |
public void actionPerformed(ActionEvent e) { |
125 |
if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT)) {
|
126 |
listener.actionPerformed(e); |
127 |
PluginServices.getMDIManager().closeWindow(this);
|
128 |
} |
129 |
|
130 |
if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY)) {
|
131 |
listener.actionPerformed(e); |
132 |
} |
133 |
|
134 |
if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL)) {
|
135 |
PluginServices.getMDIManager().closeWindow(this);
|
136 |
} |
137 |
} |
138 |
} |