// ********************************************************************** // $Date: 2003/07/16 15:05:07 $ // $Author: pitek $ // // ********************************************************************** package com.obrctm.openmap.editor; import com.bbn.openmap.event.*; import com.bbn.openmap.proj.*; import com.bbn.openmap.omGraphics.*; import com.bbn.openmap.Layer; import com.bbn.openmap.layer.*; import com.bbn.openmap.layer.location.*; import com.bbn.openmap.layer.util.LayerUtils; import com.bbn.openmap.tools.drawing.DrawingTool; import com.bbn.openmap.tools.drawing.DrawingToolRequestor; import com.bbn.openmap.util.*; import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.Properties; import javax.swing.*; /** * This layer can receive graphics from the OMDrawingToolLauncher, and * also sent it's graphics to the OMDrawingTool for editing. */ public class GraphicEditLayer extends OMGraphicHandlerLayer implements MapMouseListener, DrawingToolRequestor { /** Get a handle on the DrawingTool. */ protected DrawingTool drawingTool; /** For callbacks on editing... */ protected final com.bbn.openmap.tools.drawing.DrawingToolRequestor layer = this; /** Nazwa zmiennej property do określenia wejściowego pliku.xml */ public final static String graphicEditorFileProperty = "graphicEditorFile"; protected String graphicEditorFile = null; protected GraphicEditToolLauncher graphicEditToolLauncher = null; public void setProperties(String prefix, Properties props) { super.setProperties(prefix,props); setAddToBeanContext(true); prefix = PropUtils.getScopedPropertyPrefix(prefix); String[] paths = LayerUtils.initPathsFromProperties(props, prefix + graphicEditorFileProperty); if(paths != null) { graphicEditorFile = paths[0]; graphicEditorFile = graphicEditorFile.replace('\\','/'); GraphicEditImport gei = new GraphicEditImport(); setList(gei.importFromFile(graphicEditorFile)); getList().generate(getProjection()); } } /** * Kodowanie i ustawienie zmiennych properties i prefix dla standardowego wykorzystania * przez warstwę GraphicEditLayer. * * @param prefix String używany w pliku property do identyfikacji tej warstwy. * @param properties Parametry umieszczone w pliku property. */ public Properties getPropertyInfo(Properties properties) { properties = super.getPropertyInfo(properties); properties.put(initPropertiesProperty, graphicEditorFileProperty); properties.put(graphicEditorFileProperty, "Location of GraphicEditor file - .xxx (File, URL or relative file path)."); properties.put(graphicEditorFileProperty + ScopedEditorProperty, "com.bbn.openmap.util.propertyEditor.FUPropertyEditor"); return properties; } public void paint(java.awt.Graphics g) { OMGraphicList omgl = super.getList(); omgl.render(g); } /** * Overriding the OMGraphicHandlerMethod, creating a list if it's null. */ public OMGraphicList getList() { OMGraphicList list = super.getList(); if (list == null) { list = new OMGraphicList(); super.setList(list); } return list; } /** * Implementing the ProjectionPainter interface. */ public synchronized void renderDataForProjection(Projection proj, java.awt.Graphics g) { if (proj != null && !proj.equals(getProjection())) { setProjection(proj.makeClone()); getList().generate(proj); } paint(g); } /** From the ProjectionListener interface. */ public void projectionChanged(com.bbn.openmap.event.ProjectionEvent pe) { Projection proj = setProjection(pe); if (proj != null) { getList().generate(proj); repaint(); } fireStatusUpdate(LayerStatusEvent.FINISH_WORKING); } public DrawingTool getDrawingTool() { return drawingTool; } public void setDrawingTool(DrawingTool dt) { drawingTool = dt; } /** * DrawingToolRequestor method. */ public void drawingComplete(OMGraphic omg, OMAction action) { getList(); // create a list if there isn't one. 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(Iterator it) { Object someObj; while (it.hasNext()) { someObj = it.next(); if (someObj instanceof DrawingTool) { setDrawingTool((DrawingTool)someObj); } else if (someObj instanceof GraphicEditToolLauncher) { graphicEditToolLauncher = (GraphicEditToolLauncher)someObj; } } } /** * 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 childrenRemoved(java.beans.beancontext.BeanContextMembershipEvent bcme) { Iterator it = bcme.iterator(); Object someObj; while (it.hasNext()) { someObj = it.next(); if (someObj instanceof DrawingTool) { if (getDrawingTool() == (DrawingTool)someObj) { setDrawingTool(null); } } } } /** * Note: A layer interested in receiving amouse events should * implement this function . Otherwise, return the default, which * is null. */ public synchronized MapMouseListener getMapMouseListener() { return this; } /** * Return a list of the modes that are interesting to the * MapMouseListener. You MUST override this with the modes you're * interested in. */ public String[] getMouseModeServiceList() { String[] services = {SelectMouseMode.modeID, NavMouseMode.modeID};// what are other possibilities in OpenMap return services; } //////////////////////// // Mouse Listener events //////////////////////// /** * Invoked when a mouse button has been pressed on a component. * @param e MouseEvent * @return false */ public boolean mousePressed(MouseEvent e) { return false; } /** * Invoked when a mouse button has been released on a component. * @param e MouseEvent * @return false */ public boolean mouseReleased(MouseEvent e) { return false; } /** * Invoked when the mouse has been clicked on a component. * @param e MouseEvent * @return false */ public boolean mouseClicked(MouseEvent e) { boolean ret = false; OMGraphic omgr = ((OMGraphicList)getList()).findClosest(e.getX(), e.getY(), 4); if (omgr != null) { DrawingTool dt = getDrawingTool(); if (dt != null) { dt.edit(omgr, layer); } ret = true; } return ret; } /** * Invoked when the mouse enters a component. * @param e MouseEvent */ public void mouseEntered(MouseEvent e) { return; } /** * Invoked when the mouse exits a component. * @param e MouseEvent */ public void mouseExited(MouseEvent e) { return; } /////////////////////////////// // Mouse Motion Listener events /////////////////////////////// /** * Invoked when a mouse button is pressed on a component and then * dragged. The listener will receive these events if it * @param e MouseEvent * @return false */ public boolean mouseDragged(MouseEvent e) { return false; } OMGraphic lastSelected = null; /** * Invoked when the mouse button has been moved on a component * (with no buttons down). * @param e MouseEvent * @return false */ public boolean mouseMoved(MouseEvent e) { OMGraphic omgr = ((OMGraphicList)getList()).findClosest(e.getX(),e.getY(),4.0f); boolean ret = false; if (omgr != null) { fireRequestToolTip(e, "Editable Graphic"); ret = true; } else { fireHideToolTip(e); if (lastSelected != null) { lastSelected.deselect(); lastSelected.generate(getProjection()); lastSelected = null; repaint(); } } return ret; } /** * Handle a mouse cursor moving without the button being pressed. * Another layer has consumed the event. */ public void mouseMoved() { } public java.awt.Component getGUI() { JPanel box = PaletteHelper.createVerticalPanel(""); box.setLayout(new java.awt.GridLayout(0, 1)); JPanel box1 = PaletteHelper.createVerticalPanel("Edit Layer Graphics"); box1.setLayout(new java.awt.GridLayout(0, 1)); JButton button = new JButton("Edit Layer"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { if(graphicEditToolLauncher != null) { graphicEditToolLauncher.setRequestor(getName()); graphicEditToolLauncher.getWindowSupport().displayInWindow(); } //System.out.println("SetVisible OMToolLuncher for " + getName()); } }); box1.add(button); box.add(box1); box1 = PaletteHelper.createVerticalPanel("Save Layer Graphics"); box1.setLayout(new java.awt.GridLayout(0, 1)); button = new JButton("Save Layer"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { GraphicEditExport gee = new GraphicEditExport(); gee.exportToFile(getList()); } }); box1.add(button); box.add(box1); box1 = PaletteHelper.createVerticalPanel("Remove Layer Graphics"); box1.setLayout(new java.awt.GridLayout(0, 1)); button = new JButton("Clear Layer"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { OMGraphicList omgl = getList(); omgl.clear(); repaint(); } }); box1.add(button); box.add(box1); return box; } }