?? omdrawingtoollauncher.java
字號:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/tools/drawing/OMDrawingToolLauncher.java,v $// $RCSfile: OMDrawingToolLauncher.java,v $// $Revision: 1.15.2.4 $// $Date: 2005/08/10 22:45:11 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.tools.drawing;import java.awt.Component;import java.awt.Container;import java.awt.Frame;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.beans.PropertyChangeEvent;import java.beans.PropertyChangeListener;import java.util.Enumeration;import java.util.Iterator;import java.util.Properties;import java.util.Vector;import javax.swing.BoxLayout;import javax.swing.ButtonGroup;import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JPanel;import javax.swing.JToggleButton;import javax.swing.JToolBar;import com.bbn.openmap.Environment;import com.bbn.openmap.I18n;import com.bbn.openmap.InformationDelegator;import com.bbn.openmap.MapHandler;import com.bbn.openmap.gui.OMToolComponent;import com.bbn.openmap.gui.WindowSupport;import com.bbn.openmap.omGraphics.GraphicAttributes;import com.bbn.openmap.omGraphics.OMGraphic;import com.bbn.openmap.util.Debug;import com.bbn.openmap.util.PaletteHelper;import com.bbn.openmap.util.PropUtils;/** * This tool is a widget that calls the OMDrawingTool to create a * specific graphic. The launcher is completely configured by * EditToolLaunchers it gets told about from the DrawingTool, and * OMGraphicHandlers that it finds in a MapHandler. There are no * methods to manually add stuff to this GUI. * <p> * * There are two properties that can be set for the launcher: * * <pre> * * * * * # Number of launcher buttons to place in a row in that part of the * # GUI. -1 (the default) is to keep them all on one line. * omdtl.horizNumLoaderButtons=-1 * * # If set to true, a text popup will be used for the OMGraphic * # loaders instead of buttons (false is default). * omdtl.useTextLabels=false * * * * </pre> */public class OMDrawingToolLauncher extends OMToolComponent implements ActionListener, PropertyChangeListener { protected I18n i18n = Environment.getI18n(); protected DrawingTool drawingTool; protected boolean useTextEditToolTitles = false; protected GraphicAttributes defaultGraphicAttributes = new GraphicAttributes(); public int maxHorNumLoaderButtons = -1; // Places buttons in alphabetical order // protected TreeMap loaders = new TreeMap(); protected Vector loaders = new Vector(); protected Vector drawingToolRequestors = new Vector(); protected DrawingToolRequestor currentRequestor; protected String currentCreation; protected JComboBox requestors; /** * Property for setting the maximum number of loader buttons to * allow in the horizontal direction in the GUI * (horizNumLoaderButtons). -1 means to just lay them out in one * row. */ public final static String HorizontalNumberOfLoaderButtonsProperty = "horizNumLoaderButtons"; public final static String UseLoaderTextProperty = "useTextLabels"; String[] rtc = { i18n.get(OMDrawingToolLauncher.class, "renderingType.LatLon", "Lat/Lon"), i18n.get(OMDrawingToolLauncher.class, "renderingType.XY", "X/Y"), i18n.get(OMDrawingToolLauncher.class, "renderingType.XYOffset", "X/Y Offset") }; public final static String CreateCmd = "CREATE"; /** Default key for the DrawingToolLauncher Tool. */ public static final String defaultKey = "omdrawingtoollauncher"; public OMDrawingToolLauncher() { super(); setWindowSupport(new WindowSupport(this, i18n.get(OMDrawingToolLauncher.class, "omdrawingtoollauncher", "Drawing Tool Launcher"))); setKey(defaultKey); defaultGraphicAttributes.setRenderType(OMGraphic.RENDERTYPE_LATLON); defaultGraphicAttributes.setLineType(OMGraphic.LINETYPE_GREATCIRCLE); resetGUI(); } /** * Set the DrawingTool for this launcher. */ public void setDrawingTool(DrawingTool dt) { if (drawingTool != null && drawingTool instanceof OMDrawingTool) { ((OMDrawingTool) drawingTool).removePropertyChangeListener(this); } drawingTool = dt; if (drawingTool != null && drawingTool instanceof OMDrawingTool) { ((OMDrawingTool) drawingTool).addPropertyChangeListener(this); } } public DrawingTool getDrawingTool() { return drawingTool; } public void actionPerformed(ActionEvent ae) { String command = ae.getActionCommand().intern(); Debug.message("drawingtool", "DrawingToolLauncher.actionPerformed(): " + command); // This is important. We need to set the current projection // before setting the projection in the MapBean. That way, // the projectionChanged method actions won't get fired if (command == CreateCmd) { // Get the active EditToolLoader DrawingTool dt = getDrawingTool(); if (dt instanceof OMDrawingTool) { OMDrawingTool omdt = (OMDrawingTool) dt; if (omdt.isActivated()) { omdt.deactivate(); } } if (dt != null && currentCreation != null && currentRequestor != null) { // Copy the default GraphicAttributes into another // copy... GraphicAttributes ga = (GraphicAttributes) defaultGraphicAttributes.clone(); // fire it up! dt.setBehaviorMask(OMDrawingTool.DEFAULT_BEHAVIOR_MASK); dt.create(currentCreation, ga, currentRequestor); } else { StringBuffer sb = new StringBuffer(); StringBuffer em = new StringBuffer(); if (dt == null) { sb.append(" No drawing tool is available!\n"); em.append(i18n.get(OMDrawingToolLauncher.class, "noDrowingTool", " No drawing tool is available!\n")); } else { sb.append(" Drawing tool OK.\n"); } if (currentCreation == null) { sb.append(" No valid choice of graphic to create.\n"); em.append(i18n.get(OMDrawingToolLauncher.class, "noValidChoice", " No valid choice of graphic to create.\n")); } else { sb.append(" Graphic choice OK.\n"); } if (currentRequestor == null) { sb.append(" No valid receiver for the created graphic.\n"); em.append(i18n.get(OMDrawingToolLauncher.class, "noValidReceiver", " No valid receiver for the created graphic.\n")); } else { sb.append(" Graphic receiver OK.\n"); } Debug.output("OMDrawingToolLauncher: Something is not set:\n" + sb.toString()); MapHandler mapHandler = (MapHandler) getBeanContext(); if (mapHandler != null) { InformationDelegator id = (InformationDelegator) mapHandler.get("com.bbn.openmap.InformationDelegator"); if (id != null) { id.displayMessage(i18n.get(OMDrawingToolLauncher.class, "problem", "Problem"), i18n.get(OMDrawingToolLauncher.class, "problemCreatingGraphic", "Problem creating new graphic:\n") + em.toString()); } } } } } /** * Set the current requestor to receive a requested OMGraphic. * Changes are reflected in the GUI, and setCurrentRequestor() * will eventually be called. */ public void setRequestor(String aName) { if (requestors != null) { if (aName != null) { requestors.setSelectedItem(aName); } else { if (drawingToolRequestors.size() > 0) { setRequestor(((DrawingToolRequestor) drawingToolRequestors.elementAt(0)).getName()); } } } } /** * Fillse combobox with recent values. */ private void resetCombo() { Object oldChoice = null; if (requestors != null) { oldChoice = requestors.getSelectedItem(); } ActionListener[] actions = requestors.getActionListeners(); for (int loop = 0; loop < actions.length; loop++) { requestors.removeActionListener(actions[loop]); } requestors.removeAllItems(); for (Iterator it = drawingToolRequestors.iterator(); it.hasNext();) { requestors.addItem(((DrawingToolRequestor) it.next()).getName()); } if (oldChoice != null) { requestors.setSelectedItem(oldChoice); } for (int loop = 0; loop < actions.length; loop++) { requestors.addActionListener(actions[loop]); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -