Revision 1714 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
LayoutAddRectangleWithDialogListener.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.app.project.documents.layout.tools.listener; |
23 | 23 |
|
24 |
import java.awt.event.ActionEvent; |
|
24 | 25 |
import java.awt.geom.Rectangle2D; |
25 |
|
|
26 |
import org.apache.commons.lang.StringUtils; |
|
26 | 27 |
import org.gvsig.andami.PluginServices; |
27 | 28 |
import org.gvsig.app.project.documents.layout.FLayoutUtilities; |
28 |
import org.gvsig.app.project.documents.layout.LayoutDocument; |
|
29 | 29 |
import org.gvsig.app.project.documents.layout.fframes.IFFrame; |
30 | 30 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.FFrameDialogNotification; |
31 | 31 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog; |
32 |
import org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFramePanel; |
|
32 | 33 |
import org.gvsig.app.project.documents.layout.gui.LayoutPanel; |
33 | 34 |
import org.gvsig.fmap.mapcontrol.tools.BehaviorException; |
34 | 35 |
import org.gvsig.fmap.mapcontrol.tools.Events.EnvelopeEvent; |
35 | 36 |
import org.gvsig.tools.observer.Observable; |
36 |
import org.gvsig.tools.observer.Observer; |
|
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; |
|
37 | 41 |
|
38 | 42 |
/** |
39 | 43 |
* @author gvSIG Team |
... | ... | |
49 | 53 |
public LayoutAddRectangleWithDialogListener(LayoutPanel layoutPanel) { |
50 | 54 |
super(layoutPanel); |
51 | 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(); |
|
52 | 64 |
|
65 |
} |
|
66 |
|
|
67 |
@Override |
|
53 | 68 |
public void rectangle(EnvelopeEvent event) throws BehaviorException { |
54 | 69 |
IFFrame fframe = layoutManager.createFrame(getFFrameName()); |
55 | 70 |
fframe.setDocument(this.layoutPanel.getDocument()); |
56 | 71 |
fframe.setLayoutContext(layoutPanel.getLayoutContext()); |
57 |
Rectangle2D r = new Rectangle2D.Double(); |
|
58 | 72 |
|
59 |
r = getRectangle(TOLERANCE); |
|
73 |
Rectangle2D r = getRectangle(TOLERANCE);
|
|
60 | 74 |
fframe.setBoundBox(FLayoutUtilities.toSheetRect(r, layoutPanel |
61 | 75 |
.getLayoutControl().getAT())); |
62 |
final IFFrameDialog fframedialog = |
|
63 |
layoutManager.createFFrameDialog(fframe, layoutPanel); |
|
64 |
if (fframedialog != null) { |
|
65 |
fframedialog.addObserver(new Observer() { |
|
66 |
public void update(Observable observable, Object notification) { |
|
67 |
if (notification instanceof FFrameDialogNotification && |
|
68 |
((FFrameDialogNotification) notification).getType()==FFrameDialogNotification.DIALOG_CLOSED) { |
|
69 |
IFFrame newFrame = fframedialog.getFFrame(); |
|
70 |
if (newFrame != null) { |
|
71 |
layoutPanel.getLayoutContext().addFFrame(newFrame, true, true); |
|
72 |
} |
|
73 |
PluginServices.getMainFrame().enableControls(); |
|
74 |
layoutPanel.getLayoutControl().refresh(); |
|
75 |
} |
|
76 |
} |
|
77 |
}); |
|
78 |
PluginServices.getMDIManager().addWindow(fframedialog); |
|
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 |
|
|
79 | 101 |
} |
80 | 102 |
} |
81 | 103 |
|
Also available in: Unified diff