demolayer.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,056 行 · 第 1/3 页
JAVA
1,056 行
box.add(button); button = new JButton("Reset filter"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { resetFiltering(); repaint(); } }); box.add(button); // button = new JButton("Create XY Rect"); // button.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent event) { // DrawingTool dt = getDrawingTool(); // GraphicAttributes ga = new GraphicAttributes(); // ga.setRenderType(OMGraphic.RENDERTYPE_XY); // if (dt != null) { // OMRect rect = (OMRect) // getDrawingTool().create("com.bbn.openmap.omGraphics.OMRect", // ga, layer); // if (rect != null) { // getList().add(rect); // } else { // Debug.error("DemoLayer: Drawing tool can't create OMRect"); // } // } else { // Debug.output("DemoLayer can't find a drawing tool"); // } // } // }); // box.add(button); // button = new JButton("Create Offset Rect"); // button.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent event) { // DrawingTool dt = getDrawingTool(); // GraphicAttributes ga = new GraphicAttributes(); // ga.setRenderType(OMGraphic.RENDERTYPE_OFFSET); // ga.setFillPaint(Color.red); // if (dt != null) { // OMRect rect = (OMRect) // getDrawingTool().create("com.bbn.openmap.omGraphics.OMRect", // ga, layer); // if (rect != null) { // getList().add(rect); // } else { // Debug.error("DemoLayer: Drawing tool can't create OMRect"); // } // } else { // Debug.output("DemoLayer can't find a drawing tool"); // } // } // }); // box.add(button); // button = new JButton("Create RangeRings"); // button.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent event) { // DrawingTool dt = getDrawingTool(); // GraphicAttributes ga = new GraphicAttributes(); // ga.setLinePaint(Color.yellow); // if (dt != null) { // OMRangeRings rr = (OMRangeRings) // getDrawingTool().create("com.bbn.openmap.omGraphics.OMRangeRings", // ga, layer); // if (rr != null) { // // rr.setInterval(25, Length.MILE); // } else { // Debug.error("DemoLayer: Drawing tool can't create // OMRangeRings"); // } // } else { // Debug.output("DemoLayer can't find a drawing tool"); // } // } // }); // box.add(button); // button = new JButton("Create XY Poly"); // button.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent event) { // DrawingTool dt = getDrawingTool(); // GraphicAttributes ga = new GraphicAttributes(); // ga.setRenderType(OMGraphic.RENDERTYPE_XY); // ga.setLinePaint(Color.red); // ga.setFillPaint(Color.red); // if (dt != null) { // OMPoly point = (OMPoly) // getDrawingTool().create("com.bbn.openmap.omGraphics.OMPoly", // ga, layer); // if (point != null) { // } else { // Debug.error("DemoLayer: Drawing tool can't create OMPoly"); // } // } else { // Debug.output("DemoLayer can't find a drawing tool"); // } // } // }); // box.add(button); // button = new JButton("Create LatLon Labeled Poly"); // button.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent event) { // DrawingTool dt = getDrawingTool(); // GraphicAttributes ga = new GraphicAttributes(); // ga.setRenderType(OMGraphic.RENDERTYPE_LATLON); // ga.setLinePaint(Color.green); // ga.setFillPaint(Color.green); // if (dt != null) { // LabeledOMPoly point = (LabeledOMPoly) // getDrawingTool().create("com.bbn.openmap.omGraphics.labeled.LabeledOMPoly", // ga, layer); // if (point != null) { // // point.setOval(true); // // point.setRadius(8); // point.setText("Active Testing"); // } else { // Debug.error("DemoLayer: Drawing tool can't create OMPoly"); // } // } else { // Debug.output("DemoLayer can't find a drawing tool"); // } // } // }); // box.add(button); // button = new JButton("Create LatLon Offset Poly"); // button.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent event) { // DrawingTool dt = getDrawingTool(); // GraphicAttributes ga = new GraphicAttributes(); // ga.setRenderType(OMGraphic.RENDERTYPE_OFFSET); // ga.setLinePaint(Color.green); // ga.setFillPaint(Color.green); // if (dt != null) { // OMPoly point = (OMPoly) // getDrawingTool().create("com.bbn.openmap.omGraphics.OMPoly", // ga, layer); // if (point != null) { // // rr.setInterval(25, Length.MILE); // } else { // Debug.error("DemoLayer: Drawing tool can't create OMPoly"); // } // } else { // Debug.output("DemoLayer can't find a drawing tool"); // } // } // }); // box.add(button); gridbag.setConstraints(box, c); panel.add(box); return panel; } public DrawingTool getDrawingTool() { // Usually set in the findAndInit() method. return drawingTool; } public void setDrawingTool(DrawingTool dt) { // Called by the findAndInit method. drawingTool = dt; } /** * Called when the DrawingTool is complete, providing the layer with the * modified OMGraphic. */ public void drawingComplete(OMGraphic omg, OMAction action) { Debug.message("demo", "DemoLayer: DrawingTool complete"); Object obj = omg.getAppObject(); if (obj != null && (obj == internalKey || obj == externalKey) && !action.isMask(OMGraphicConstants.DELETE_GRAPHIC_MASK)) { java.awt.Shape filterShape = omg.getShape(); OMGraphicList filteredList = filter(filterShape, (omg.getAppObject() == internalKey)); if (Debug.debugging("demo")) { Debug.output("DemoLayer filter: " + filteredList.getDescription()); } } else { if (!doAction(omg, action)) { // null OMGraphicList on failure, should only occur if // OMGraphic is added to layer before it's ever been // on the map. setList(new OMGraphicList()); doAction(omg, action); } } repaint(); } /** * Called when a component that is needed, and not available with an * appropriate interator from the BeanContext. This lets this object hook up * with what it needs. For Layers, this method doesn't do anything by * default. If you need your layer to get ahold of another object, then you * can use the Iterator to go through the objects to look for the one you * need. */ public void findAndInit(Object someObj) { if (someObj instanceof DrawingTool) { Debug.message("demo", "DemoLayer: found a drawing tool"); setDrawingTool((DrawingTool) someObj); } if (someObj instanceof SymbolReferenceLibrary) { setSymbolReferenceLibrary((SymbolReferenceLibrary) someObj); } } /** * Set the MilStd2525 SymbolReferenceLibrary object used to create symbols. * * @param library */ public void setSymbolReferenceLibrary(SymbolReferenceLibrary library) { srl = library; } public SymbolReferenceLibrary getSymbolReferenceLibrary() { return srl; } /** * BeanContextMembershipListener method. Called when a new object is removed * from the BeanContext of this object. For the Layer, this method doesn't * do anything. If your layer does something with the childrenAdded method, * or findAndInit, you should take steps in this method to unhook the layer * from the object used in those methods. */ public void findAndUndo(Object someObj) { if (someObj instanceof DrawingTool) { if (getDrawingTool() == (DrawingTool) someObj) { setDrawingTool(null); } } } /** * Query that an OMGraphic can be highlighted when the mouse moves over it. * If the answer is true, then highlight with this OMGraphics will be * called. */ public boolean isHighlightable(OMGraphic omg) { return true; } /** * Query that an OMGraphic is selectable. */ public boolean isSelectable(OMGraphic omg) { DrawingTool dt = getDrawingTool(); return (dt != null && dt.canEdit(omg.getClass())); } /** * Query for what text should be placed over the information bar when the * mouse is over a particular OMGraphic. */ public String getInfoText(OMGraphic omg) { DrawingTool dt = getDrawingTool(); if (dt != null && dt.canEdit(omg.getClass())) { return "Click to edit graphic."; } else { return null; } } /** * Query for what tooltip to display for an OMGraphic when the mouse is over * it. */ public String getToolTipTextFor(OMGraphic omg) { Object tt = omg.getAttribute(OMGraphic.TOOLTIP); if (tt instanceof String) { return (String) tt; } return "Demo Layer Object"; } /** * Called if isSelectable(OMGraphic) was true, so the list has the * OMGraphic. A list is used in case underlying code is written to handle * more than one OMGraphic being selected at a time. */ public void select(OMGraphicList list) { if (list != null && list.size() > 0) { OMGraphic omg = list.getOMGraphicAt(0); DrawingTool dt = getDrawingTool(); if (dt != null && dt.canEdit(omg.getClass())) { dt.setBehaviorMask(OMDrawingTool.QUICK_CHANGE_BEHAVIOR_MASK); if (dt.edit(omg, this) == null) { // Shouldn't see this because we checked, but ... fireRequestInfoLine("Can't figure out how to modify this object."); } } } } public List getItemsForMapMenu(MapMouseEvent me) { List l = new ArrayList(); l.add(new JMenuItem("When")); l.add(new JMenuItem("Where")); l.add(new JMenuItem("How")); return l; } public List getItemsForOMGraphicMenu(OMGraphic omg) { List l = new ArrayList(); l.add(new JMenuItem("Which")); l.add(new JMenuItem("Why")); return l; } /** * OMGraphicHandlerLayer method that is called to ask if you want * notifications when mouse events occur over the map, and not over any * OMGraphics. */ // public boolean receivesMapEvents() { // return true; // } /** * If receivesMapEvents() returns true, this method gets called when the * left mouse button is clicked on the map and not on an OMGraphic. */ // public boolean leftClick(MapMouseEvent mme) { // OMGraphicList searchList = getList().findAll(mme.getX(), mme.getY(), // 100); // Debug.output(searchList.getDescription()); // return false; // } /** * If receivesMapEvents() returns true, this method gets called when the * left mouse button is moved on the map and not over an OMGraphic. */// public boolean mouseOver(MapMouseEvent mme) {// return false;// }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?