01: package com.vividsolutions.jump.workbench.ui.plugin;
02:
03: import java.awt.event.ContainerAdapter;
04: import java.awt.event.ContainerEvent;
05: import java.awt.event.MouseAdapter;
06: import java.awt.event.MouseEvent;
07: import java.util.ArrayList;
08: import java.util.Arrays;
09: import java.util.Collection;
10: import java.util.Iterator;
11:
12: import javax.swing.JInternalFrame;
13: import javax.swing.SwingUtilities;
14:
15: import com.vividsolutions.jts.io.ParseException;
16: import com.vividsolutions.jts.io.WKTReader;
17: import com.vividsolutions.jts.util.Assert;
18: import com.vividsolutions.jump.I18N;
19: import com.vividsolutions.jump.feature.BasicFeature;
20: import com.vividsolutions.jump.workbench.model.Layer;
21: import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
22: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
23: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
24: import com.vividsolutions.jump.workbench.ui.GUIUtil;
25: import com.vividsolutions.jump.workbench.ui.TreeLayerNamePanel;
26:
27: public class AddWMSDemoBoxEasterEggPlugIn extends AbstractPlugIn {
28: private Collection panelsEncountered = new ArrayList();
29:
30: public void initialize(PlugInContext context) throws Exception {
31: context.getWorkbenchFrame().getDesktopPane()
32: .addContainerListener(new ContainerAdapter() {
33: public void componentAdded(ContainerEvent e) {
34: if (!(e.getChild() instanceof JInternalFrame)) {
35: return;
36: }
37:
38: installListener((JInternalFrame) e.getChild());
39: }
40: });
41: for (Iterator i = Arrays.asList(
42: context.getWorkbenchFrame().getInternalFrames())
43: .iterator(); i.hasNext();) {
44: JInternalFrame internalFrame = (JInternalFrame) i.next();
45: installListener(internalFrame);
46: }
47: }
48:
49: private void installListener(JInternalFrame internalFrame) {
50: final TreeLayerNamePanel panel = (TreeLayerNamePanel) GUIUtil
51: .getDescendantOfClass(TreeLayerNamePanel.class,
52: internalFrame);
53:
54: if ((panel == null) || panelsEncountered.contains(panel)) {
55: //#componentAdded is called twice in JDK 1.3.1_04 for some reason. [Jon Aquino]
56: return;
57: }
58:
59: panelsEncountered.add(panel);
60: panel.getTree().addMouseListener(new MouseAdapter() {
61: public void mouseClicked(MouseEvent e) {
62: if (SwingUtilities.isRightMouseButton(e)
63: && (e.getClickCount() == 3)) {
64: Layer layer = panel
65: .getLayerManager()
66: .addLayer(
67: StandardCategoryNames.WORKING,
68: I18N
69: .get("ui.plugin.AddWMSDemoBoxEasterEggPlugIn.wms-demo-box"),
70: AddNewLayerPlugIn
71: .createBlankFeatureCollection());
72: BasicFeature feature = new BasicFeature(layer
73: .getFeatureCollectionWrapper()
74: .getFeatureSchema());
75:
76: try {
77: feature
78: .setGeometry(new WKTReader()
79: .read("LINESTRING (1455960 703340, 1455960 701960, 1457540 701960, 1457540 703340, 1455960 703340)"));
80: } catch (ParseException x) {
81: Assert.shouldNeverReachHere();
82: }
83:
84: layer.getFeatureCollectionWrapper().add(feature);
85: }
86: }
87: });
88: }
89: }
|