drawingtoollayer.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 750 行 · 第 1/2 页
JAVA
750 行
interString = i18n.get(DrawingToolLayer.class, "OK", I18n.TOOLTIP, "Do action and dismiss window."); button.setToolTipText(interString); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { doIt(); hidePalette(); } }); goPanel.add(button); interString = i18n.get(DrawingToolLayer.class, "Apply", "Apply"); button = new JButton(interString); interString = i18n.get(DrawingToolLayer.class, "Apply", I18n.TOOLTIP, "Do action and leave window up."); button.setToolTipText(interString); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { doIt(); } }); goPanel.add(button); interString = i18n.get(DrawingToolLayer.class, "Cancel", "Cancel"); button = new JButton(interString); interString = i18n.get(DrawingToolLayer.class, "Cancel", I18n.TOOLTIP, "Do nothing and dismiss window."); button.setToolTipText(interString); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { hidePalette(); } }); goPanel.add(button); } return box; } protected void doIt() { if (jcb != null) { ((javax.swing.Action) jcb.getSelectedItem()).actionPerformed(null); } } /** * You can override this class if you want to provide more, fewer or * different actions to the user. * * @return Vector of Actions */ protected Vector getActions() { Vector actions = new Vector(); actions.add(new AbstractAction() { public void actionPerformed(ActionEvent e) { saveOMGraphics(); } public String toString() { return i18n.get(DrawingToolLayer.class, "SAVE_MAP", "Save map"); } }); actions.add(new AbstractAction() { public void actionPerformed(ActionEvent e) { OMGraphicList list = getList(); if (list != null && list.size() > 0) { EsriShapeExport ese = new EsriShapeExport(list, getProjection(), null); ese.export(); } else { String message = i18n.get(DrawingToolLayer.class, "SHAPE_ERROR_MESSAGE", "There's nothing on the map for this layer to save."); fireRequestMessage(message); } } public String toString() { return i18n.get(DrawingToolLayer.class, "SHAPE_SAVE_MAP", "Save map as Shape file(s)"); } }); actions.add(new AbstractAction() { public void actionPerformed(ActionEvent e) { setList(load()); doPrepare(); } public String toString() { return i18n.get(DrawingToolLayer.class, "RELOAD", "Re-load map from file"); } }); actions.add(new AbstractAction() { public void actionPerformed(ActionEvent e) { Inspector inspector = new Inspector(); inspector.inspectPropertyConsumer(DrawingToolLayer.this); } public String toString() { return i18n.get(DrawingToolLayer.class, "PREFERENCES", "Change preferences"); } }); return actions; } /** * Get the current OMGraphicList and save it out to the file named in this * class. If that's null, the user will be asked for one. * */ public void saveOMGraphics() { if (fileName == null) { fileName = new String[1]; } if (fileName[0] == null) { fileName[0] = FileUtils.getFilePathToSaveFromUser(i18n.get(DrawingToolLayer.class, "CHOOSE_SAVE", "Choose file to use to save layer:")); } if (fileName[0] != null) { OMGraphicList list = getList(); if (list != null) { try { FileOutputStream fos = new FileOutputStream(new File(fileName[0])); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(list); oos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } } /** * Load the data from the file set in this layer. * * @return OMGraphicList loaded from fileName. */ public OMGraphicList load() { OMGraphicList list = null; if (fileName != null) { try { List graphicList = new ArrayList(); for (int i = 0; i < fileName.length; i++) { URL url = PropUtils.getResourceOrFileOrURL(fileName[i]); if (url != null) { if (fileName[i].endsWith("shp")) { DbfTableModel dbf = DbfTableModel.getDbfTableModel(PropUtils.getResourceOrFileOrURL(fileName[i].replaceAll(".shp", ".dbf"))); ; list = EsriGraphicList.getEsriGraphicList(url, null, dbf); } else { ObjectInputStream ois = new ObjectInputStream(url.openStream()); list = (OMGraphicList) ois.readObject(); ois.close(); } for (int j = 0; j < list.size(); j++) { graphicList.add(list.getOMGraphicAt(j)); } } } OMGraphicList fullList = new OMGraphicList(graphicList); return fullList; } catch (FileNotFoundException e) { if (DTL_DEBUG) { e.printStackTrace(); } } catch (StreamCorruptedException sce) { sce.printStackTrace(); fireRequestMessage(i18n.get(DrawingToolLayer.class, "LOAD_ERROR", "The file doesn't appear to be a valid map file")); } catch (IOException e) { if (DTL_DEBUG) { e.printStackTrace(); } } catch (ClassNotFoundException e) { if (DTL_DEBUG) { e.printStackTrace(); } } catch (ClassCastException cce) { if (DTL_DEBUG) { cce.printStackTrace(); } } } // Something went wrong, we don't want to overwrite something // that might potentially be something else if a save is // called for later. fileName = null; return new OMGraphicList(); } /** * A flag to provide a tooltip over OMGraphics to click to edit. */ public void setShowHints(boolean show) { showHints = show; } public boolean getShowHints() { return showHints; } /** * 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, in addition to getInfoText() and getToolTipTextFor() */ public boolean isHighlightable(OMGraphic omg) { return showHints; } /** * Query that an OMGraphic is selectable. */ public boolean isSelectable(OMGraphic omg) { DrawingTool dt = getDrawingTool(); return (shouldEdit(omg) && dt != null && dt.canEdit(omg.getClass())); } String editInstruction = i18n.get(DrawingToolLayer.class, "CLICK_TO_EDIT", "Click to edit."); /** * 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 editInstruction; } else { return null; } } /** * Query for what tooltip to display for an OMGraphic when the mouse is over * it. */ public String getToolTipTextFor(OMGraphic omgr) { OMDrawingTool dt = getDrawingTool(); if (shouldEdit(omgr) && dt.canEdit(omgr.getClass()) && !dt.isActivated()) { return editInstruction; } else { return null; } } /** * GestureResponsePolicy method. */ public void select(OMGraphicList omgl) { super.select(omgl); if (omgl != null && omgl.size() > 0) { if (omgl.size() == 1) { edit(omgl.getOMGraphicAt(0)); } else { edit(omgl); } } } public void edit(OMGraphic omg) { OMDrawingTool dt = getDrawingTool(); if (dt != null && dt.canEdit(omg.getClass())) { // if (dt.isEditing(omg)) { // dt.deselect(omg); // return; // } dt.resetBehaviorMask(); MapMouseMode omdtmm = dt.getMouseMode(); if (!omdtmm.isVisible()) { dt.setMask(OMDrawingTool.PASSIVE_MOUSE_EVENT_BEHAVIOR_MASK); } MapMouseInterpreter mmi = (MapMouseInterpreter) getMapMouseListener(); MouseEvent mevent = null; if (mmi != null) { mevent = mmi.getCurrentMouseEvent(); } if (omg.isSelected()) { omg.deselect(); } if (dt.select(omg, this, mevent)) { // OK, means we're editing - let's lock up the // MouseMode if (DTL_DEBUG) { Debug.output("DTL: starting edit of OMGraphic..."); } // Check to see if the DrawingToolMouseMode wants to // be invisible. If it does, ask the current // active MouseMode to be the proxy for it... if (!omdtmm.isVisible() && mevent instanceof MapMouseEvent) { MapMouseMode mmm = ((MapMouseEvent) mevent).getMapMouseMode(); if (mmm.actAsProxyFor(omdtmm, MapMouseSupport.PROXY_DISTRIB_MOUSE_MOVED & MapMouseSupport.PROXY_DISTRIB_MOUSE_DRAGGED)) { if (DTL_DEBUG) { Debug.output("DTL: Setting " + mmm.getID() + " as proxy for drawing tool"); } setProxyMouseMode(mmm); } else { // WHOA, couldn't get proxy lock - bail if (DTL_DEBUG) { Debug.output("DTL: couldn't get proxy lock on " + mmm.getID() + " deactivating internal drawing tool"); } dt.deactivate(); } } else { if (DTL_DEBUG) { Debug.output("DTL: MouseMode wants to be visible(" + (omdtmm.isVisible()) + "), or MouseEvent is not a MapMouseEvent(" + !(mevent instanceof MapMouseEvent) + ")"); } } } else { if (DTL_DEBUG) { Debug.output("DTL.edit: dt.select returns false, avoiding modification over " + omg.getClass().getName()); } } } } public String getFileName() { return fileName[0]; } public void setSFileName(String serializedFile) { this.fileName[0] = serializedFile; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?