root / org.gvsig.legend.urbanhorizontalsignage / trunk / org.gvsig.legend.urbanhorizontalsignage / org.gvsig.legend.urbanhorizontalsignage.app / org.gvsig.legend.urbanhorizontalsignage.app.mainplugin / src / main / java / org / gvsig / legend / urbanhorizontalsignage / app / rotate / RotatePointExtension.java @ 5239
History | View | Annotate | Download (3.8 KB)
1 |
package org.gvsig.legend.urbanhorizontalsignage.app.rotate; |
---|---|
2 |
|
3 |
import org.gvsig.andami.plugins.Extension; |
4 |
import org.gvsig.app.ApplicationLocator; |
5 |
import org.gvsig.app.ApplicationManager; |
6 |
import org.gvsig.app.project.documents.view.ViewDocument; |
7 |
import org.gvsig.app.project.documents.view.ViewManager; |
8 |
import org.gvsig.app.project.documents.view.gui.IView; |
9 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
11 |
import org.gvsig.fmap.mapcontext.MapContext; |
12 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
13 |
import org.gvsig.fmap.mapcontrol.MapControl; |
14 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
15 |
import org.gvsig.legend.urbanverticalsignage.lib.api.PictureMarkerSymbolTableLegend; |
16 |
import org.slf4j.Logger; |
17 |
import org.slf4j.LoggerFactory; |
18 |
|
19 |
@SuppressWarnings("UseSpecificCatch") |
20 |
public class RotatePointExtension extends Extension { |
21 |
|
22 |
private static final Logger LOGGER = LoggerFactory.getLogger(RotatePointExtension.class); |
23 |
|
24 |
@Override
|
25 |
public void initialize() { |
26 |
// IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-urbanhorizontalsignage", this);
|
27 |
// IconThemeHelper.registerIcon("legend", "legend-overview-vectorial-picturemarkersymboltable", this);
|
28 |
// IconThemeHelper.registerIcon("action", "layer-modify-clipboard-copy-as-polygons", this);
|
29 |
|
30 |
} |
31 |
|
32 |
@Override
|
33 |
public void execute(String actionCommand) { |
34 |
|
35 |
if (actionCommand.compareToIgnoreCase("layer-modify-rotatepoint") != 0) { |
36 |
return;
|
37 |
} |
38 |
|
39 |
ApplicationManager application = ApplicationLocator.getManager(); |
40 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
41 |
if (view == null) { |
42 |
return;
|
43 |
} |
44 |
MapControl mapControl = view.getMapControl(); |
45 |
if (mapControl == null) { |
46 |
return;
|
47 |
} |
48 |
MapContext mapContext = mapControl.getMapContext(); |
49 |
if (mapContext == null) { |
50 |
return;
|
51 |
} |
52 |
FLyrVect layer = mapContext.getLayers().getFirstActiveVectorLayer(); |
53 |
if (layer == null) { |
54 |
return;
|
55 |
} |
56 |
if (!mapControl.hasTool(RotatePointListenerImpl.ROTATE_TOOL_NAME)) {
|
57 |
RotatePointListenerImpl listener = new RotatePointListenerImpl();
|
58 |
Behavior behavior = new RotatePointBehavior(listener);
|
59 |
mapControl.addBehavior(RotatePointListenerImpl.ROTATE_TOOL_NAME, behavior); |
60 |
} |
61 |
mapControl.setTool(RotatePointListenerImpl.ROTATE_TOOL_NAME); |
62 |
} |
63 |
|
64 |
|
65 |
@Override
|
66 |
public boolean isEnabled() { |
67 |
ApplicationManager application = ApplicationLocator.getManager(); |
68 |
ViewDocument viewdoc = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
69 |
if (viewdoc == null) { |
70 |
return false; |
71 |
} |
72 |
MapContext mapContext = viewdoc.getMapContext(); |
73 |
FLyrVect layer = mapContext.getLayers().getFirstActiveVectorLayer(); |
74 |
if (layer == null) { |
75 |
return false; |
76 |
} |
77 |
if (!layer.isAvailable()) {
|
78 |
// This can happen when opening a persisted project
|
79 |
// and there is a "slow" layer (GeoDB)
|
80 |
return false; |
81 |
} |
82 |
try {
|
83 |
FeatureStore store = layer.getFeatureStore(); |
84 |
FeatureSelection selection = store.getFeatureSelection(); |
85 |
if (selection.isEmpty()) {
|
86 |
return false; |
87 |
} |
88 |
return (layer.getLegend() instanceof PictureMarkerSymbolTableLegend); |
89 |
} catch (Exception ex) { |
90 |
LOGGER.warn("Can't get selection from layer '" + layer.getName() + "'.", ex); |
91 |
return false; |
92 |
} |
93 |
} |
94 |
|
95 |
@Override
|
96 |
public boolean isVisible() { |
97 |
ApplicationManager application = ApplicationLocator.getManager(); |
98 |
return application.getActiveDocument(ViewManager.TYPENAME) != null; |
99 |
} |
100 |
|
101 |
} |