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 | 5 | jldominguez | /* 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 | 1714 | fdiaz | import java.awt.event.ActionEvent; |
25 | 5 | jldominguez | import java.awt.geom.Rectangle2D; |
26 | 1714 | fdiaz | import org.apache.commons.lang.StringUtils; |
27 | 5 | jldominguez | 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 | 250 | cmartinez | import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameDialogNotification; |
31 | 5 | jldominguez | import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
32 | 1714 | fdiaz | import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFramePanel; |
33 | 5 | jldominguez | 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 | 250 | cmartinez | import org.gvsig.tools.observer.Observable; |
37 | 1714 | fdiaz | 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 | 5 | jldominguez | |
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 | 1714 | fdiaz | |
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 | 5 | jldominguez | |
65 | 1714 | fdiaz | } |
66 | |||
67 | @Override
|
||
68 | 5 | jldominguez | public void rectangle(EnvelopeEvent event) throws BehaviorException { |
69 | IFFrame fframe = layoutManager.createFrame(getFFrameName()); |
||
70 | 147 | cmartinez | fframe.setDocument(this.layoutPanel.getDocument());
|
71 | 145 | cmartinez | fframe.setLayoutContext(layoutPanel.getLayoutContext()); |
72 | 5 | jldominguez | |
73 | 1714 | fdiaz | Rectangle2D r = getRectangle(TOLERANCE);
|
74 | 5 | jldominguez | fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layoutPanel |
75 | .getLayoutControl().getAT())); |
||
76 | 1714 | fdiaz | |
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 | 5 | jldominguez | } |
102 | } |
||
103 | |||
104 | public abstract String getFFrameName(); |
||
105 | } |