gvsig-raster / org.gvsig.raster.tools / trunk / templates / examples / org.gvsig.raster.roimask / org.gvsig.raster.roimask.app / org.gvsig.raster.roimask.app.client / src / main / java / org / gvsig / raster / roimask / app / ROIMaskWindow.java @ 1860
History | View | Annotate | Download (4.22 KB)
1 | 1843 | nbrodin | package org.gvsig.raster.roimask.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 ROIMaskWindow 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 ROIMaskWindow(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).addActionListener(this);
|
||
46 | getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(this);
|
||
47 | |||
48 | info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE);
|
||
49 | info.setTitle(title); |
||
50 | info.setWidth(w); |
||
51 | info.setHeight(h); |
||
52 | } |
||
53 | |||
54 | private void fixedPreview(JComponent panel, JComponent preview) { |
||
55 | setLayout(new GridBagLayout()); |
||
56 | GridBagConstraints gbc = new GridBagConstraints(); |
||
57 | gbc.fill = GridBagConstraints.BOTH;
|
||
58 | gbc.weightx = 1;
|
||
59 | gbc.weighty = 1;
|
||
60 | add(panel, gbc); |
||
61 | |||
62 | if(preview != null) { |
||
63 | gbc.anchor = GridBagConstraints.NORTH;
|
||
64 | gbc.fill = GridBagConstraints.NONE;
|
||
65 | gbc.weightx = 0;
|
||
66 | gbc.weighty = 0;
|
||
67 | gbc.gridx = 1;
|
||
68 | add(preview, gbc); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | private void redimPreview(JComponent panel, JComponent preview) { |
||
73 | setLayout(new BorderLayout()); |
||
74 | JSplitPane splitPane = new JSplitPane(); |
||
75 | splitPane.setLeftComponent(panel); |
||
76 | splitPane.setRightComponent(getPreviewForRedimPreviewPanel(preview)); |
||
77 | splitPane.setResizeWeight(1.0);
|
||
78 | splitPane.setContinuousLayout(true);
|
||
79 | splitPane.setOneTouchExpandable(true);
|
||
80 | splitPane.setUI(new BasicSplitPaneUI() { |
||
81 | public BasicSplitPaneDivider createDefaultDivider() { |
||
82 | return new BasicSplitPaneDivider(this) { |
||
83 | private static final long serialVersionUID = 1L; |
||
84 | |||
85 | public void setBorder(Border b) { |
||
86 | } |
||
87 | }; |
||
88 | } |
||
89 | }); |
||
90 | splitPane.setBorder(null);
|
||
91 | add(splitPane, BorderLayout.CENTER);
|
||
92 | } |
||
93 | |||
94 | private JSplitPane getPreviewForRedimPreviewPanel(JComponent preview) { |
||
95 | JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
||
96 | splitPane.setTopComponent(preview); |
||
97 | splitPane.setBottomComponent(new JPanel()); |
||
98 | splitPane.setResizeWeight(0);
|
||
99 | splitPane.setContinuousLayout(true);
|
||
100 | splitPane.setOneTouchExpandable(true);
|
||
101 | splitPane.setUI(new BasicSplitPaneUI() { |
||
102 | public BasicSplitPaneDivider createDefaultDivider() { |
||
103 | return new BasicSplitPaneDivider(this) { |
||
104 | private static final long serialVersionUID = 1L; |
||
105 | |||
106 | public void setBorder(Border b) { |
||
107 | } |
||
108 | }; |
||
109 | } |
||
110 | }); |
||
111 | splitPane.setBorder(null);
|
||
112 | return splitPane;
|
||
113 | } |
||
114 | |||
115 | public WindowInfo getWindowInfo() {
|
||
116 | return info;
|
||
117 | } |
||
118 | |||
119 | public Object getWindowProfile() { |
||
120 | return profile;
|
||
121 | } |
||
122 | |||
123 | public void actionPerformed(ActionEvent e) { |
||
124 | if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT)) {
|
||
125 | listener.actionPerformed(e); |
||
126 | PluginServices.getMDIManager().closeWindow(this);
|
||
127 | } |
||
128 | |||
129 | if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY)) {
|
||
130 | listener.actionPerformed(e); |
||
131 | } |
||
132 | |||
133 | if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL)) {
|
||
134 | PluginServices.getMDIManager().closeWindow(this);
|
||
135 | } |
||
136 | } |
||
137 | } |