svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / tools / listener / LayoutAddRectangleWithDialogListener.java @ 1714
History | View | Annotate | Download (4.3 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.project.documents.layout.tools.listener; |
23 |
|
24 |
import java.awt.event.ActionEvent; |
25 |
import java.awt.geom.Rectangle2D; |
26 |
import org.apache.commons.lang.StringUtils; |
27 |
import org.gvsig.andami.PluginServices; |
28 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
29 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
30 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameDialogNotification; |
31 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
32 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFramePanel; |
33 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
34 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
35 |
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
36 |
import org.gvsig.tools.observer.Observable; |
37 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
38 |
import org.gvsig.tools.swing.api.windowmanager.Dialog; |
39 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
40 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
41 |
|
42 |
/**
|
43 |
* @author gvSIG Team
|
44 |
* @version $Id$
|
45 |
*
|
46 |
*/
|
47 |
public abstract class LayoutAddRectangleWithDialogListener extends |
48 |
LayoutAddRectangleListener { |
49 |
|
50 |
/**
|
51 |
* @param layoutPanel
|
52 |
*/
|
53 |
public LayoutAddRectangleWithDialogListener(LayoutPanel layoutPanel) {
|
54 |
super(layoutPanel);
|
55 |
} |
56 |
|
57 |
private void doPanelAccept(IFFramePanel panel) { |
58 |
IFFrame newFrame = panel.getFFrame(); |
59 |
if (newFrame != null) { |
60 |
layoutPanel.getLayoutContext().addFFrame(newFrame, true, true); |
61 |
} |
62 |
PluginServices.getMainFrame().enableControls(); |
63 |
layoutPanel.getLayoutControl().refresh(); |
64 |
|
65 |
} |
66 |
|
67 |
@Override
|
68 |
public void rectangle(EnvelopeEvent event) throws BehaviorException { |
69 |
IFFrame fframe = layoutManager.createFrame(getFFrameName()); |
70 |
fframe.setDocument(this.layoutPanel.getDocument());
|
71 |
fframe.setLayoutContext(layoutPanel.getLayoutContext()); |
72 |
|
73 |
Rectangle2D r = getRectangle(TOLERANCE);
|
74 |
fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layoutPanel |
75 |
.getLayoutControl().getAT())); |
76 |
|
77 |
IFFramePanel panel = layoutManager.createFFrameDialog(fframe, layoutPanel); |
78 |
if (panel instanceof IFFrameDialog) { |
79 |
IFFrameDialog fframeDialog = (IFFrameDialog) panel; |
80 |
fframeDialog.addObserver((Observable observable, Object notification) -> { |
81 |
if (notification instanceof FFrameDialogNotification |
82 |
&& StringUtils.equals(((FFrameDialogNotification) notification).getType(), FFrameDialogNotification.DIALOG_CLOSED)) { |
83 |
doPanelAccept(panel); |
84 |
} |
85 |
}); |
86 |
PluginServices.getMDIManager().addWindow(fframeDialog); |
87 |
} else if (panel != null) { |
88 |
WindowManager_v2 winManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
89 |
Dialog dialog = winManager.createDialog(
|
90 |
panel.asJComponent(), |
91 |
panel.getTitle(), |
92 |
"",
|
93 |
WindowManager_v2.BUTTONS_OK_CANCEL); |
94 |
dialog.addActionListener((ActionEvent e) -> {
|
95 |
if(dialog.getAction() == WindowManager_v2.BUTTON_OK) {
|
96 |
doPanelAccept(panel); |
97 |
} |
98 |
}); |
99 |
dialog.show(WindowManager.MODE.DIALOG); |
100 |
|
101 |
} |
102 |
} |
103 |
|
104 |
public abstract String getFFrameName(); |
105 |
} |