?? editableomtext.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/omGraphics/EditableOMText.java,v $// $RCSfile: EditableOMText.java,v $// $Revision: 1.4.2.4 $// $Date: 2005/08/10 22:45:13 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.Color;import java.awt.Component;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseEvent;import java.awt.image.BufferedImage;import javax.swing.ImageIcon;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JTextField;import javax.swing.JToggleButton;import com.bbn.openmap.Environment;import com.bbn.openmap.I18n;import com.bbn.openmap.LatLonPoint;import com.bbn.openmap.layer.util.stateMachine.State;import com.bbn.openmap.omGraphics.editable.GraphicEditState;import com.bbn.openmap.omGraphics.editable.GraphicSelectedState;import com.bbn.openmap.omGraphics.editable.GraphicSetOffsetState;import com.bbn.openmap.omGraphics.editable.GraphicUndefinedState;import com.bbn.openmap.omGraphics.editable.TextStateMachine;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * Wrapper class to edit OMText objects. This component is used by the * OMDrawingTool. */public class EditableOMText extends EditableOMGraphic implements ActionListener { protected GrabPoint gpc; protected OffsetGrabPoint gpo; // offset protected OMText text; public final static int CENTER_POINT_INDEX = 0; public final static int OFFSET_POINT_INDEX = 1; /** * For internationalization. */ protected I18n i18n = Environment.getI18n(); /** * Create the EditableOMText, setting the state machine to create * the point off of the gestures. */ public EditableOMText() { createGraphic(null); } /** * Create an EditableOMText with the pointType and renderType * parameters in the GraphicAttributes object. */ public EditableOMText(GraphicAttributes ga) { createGraphic(ga); } /** * Create the EditableOMText with an OMText already defined, ready * for editing. * * @param omc OMText that should be edited. */ public EditableOMText(OMText omc) { setGraphic(omc); } /** * Create and initialize the state machine that interprets the * modifying gestures/commands, as well as ititialize the grab * points. Also allocates the grab point array needed by the * EditableOMText. */ public void init() { setCanGrabGraphic(false); setStateMachine(new TextStateMachine(this)); gPoints = new GrabPoint[2]; } /** * Set the graphic within the state machine. If the graphic is * null, then one shall be created, and located off screen until * the gestures driving the state machine place it on the map. */ public void setGraphic(OMGraphic graphic) { init(); if (graphic instanceof OMText) { text = (OMText) graphic; stateMachine.setSelected(); setGrabPoints(text); } else { createGraphic(null); } } /** * Create and set the graphic within the state machine. The * GraphicAttributes describe the type of point to create. */ public void createGraphic(GraphicAttributes ga) { init(); stateMachine.setUndefined(); int renderType = OMGraphic.RENDERTYPE_UNKNOWN; if (ga != null) { renderType = ga.getRenderType(); } switch (renderType) { case (OMGraphic.RENDERTYPE_LATLON): text = new OMText(90f, -180f, "Text", OMText.JUSTIFY_LEFT); break; case (OMGraphic.RENDERTYPE_OFFSET): text = new OMText(90f, -180f, 0, 0, "Text", OMText.JUSTIFY_LEFT); break; default: text = new OMText(0, 0, "Text", OMText.JUSTIFY_LEFT); } if (ga != null) { ga.setTo(text); text.setLinePaint(ga.getLinePaint()); } assertGrabPoints(); } /** * Get the OMGraphic being created/modified by the EditableOMText. */ public OMGraphic getGraphic() { return text; } /** * Attach to the Moving OffsetGrabPoint so if it moves, it will * move this EditableOMGraphic with it. EditableOMGraphic version * doesn't do anything, each subclass has to decide which of its * OffsetGrabPoints should be attached to it. */ public void attachToMovingGrabPoint(OffsetGrabPoint gp) { gp.addGrabPoint(gpo); } /** * Detach from a Moving OffsetGrabPoint. The EditableOMGraphic * version doesn't do anything, each subclass should remove * whatever GrabPoint it would have attached to an * OffsetGrabPoint. */ public void detachFromMovingGrabPoint(OffsetGrabPoint gp) { gp.removeGrabPoint(gpo); } /** * Set the GrabPoint that is in the middle of being modified, as a * result of a mouseDragged event, or other selection process. */ public void setMovingPoint(GrabPoint gp) { super.setMovingPoint(gp); } /** * Given a MouseEvent, find a GrabPoint that it is touching, and * set the moving point to that GrabPoint. * * @param e MouseEvent * @return GrabPoint that is touched by the MouseEvent, null if * none are. */ public GrabPoint getMovingPoint(MouseEvent e) { movingPoint = null; GrabPoint[] gb = getGrabPoints(); int x = e.getX(); int y = e.getY(); for (int i = gb.length - 1; i >= 0; i--) { if (gb[i] != null && gb[i].distance(x, y) == 0) { setMovingPoint(gb[i]); // in case the points are on top of each other, the // last point in the array will take precidence. break; } } return movingPoint; } protected int lastRenderType = -1; /** * Check to make sure the grab points are not null. If they are, * allocate them, and them assign them to the array. */ public void assertGrabPoints() { int rt = getGraphic().getRenderType(); if (rt != lastRenderType) { clearGrabPoints(); lastRenderType = rt; } if (gpc == null) { gpc = new GrabPoint(-1, -1); gPoints[CENTER_POINT_INDEX] = gpc; } if (gpo == null) { gpo = new OffsetGrabPoint(-1, -1); gPoints[OFFSET_POINT_INDEX] = gpo; gpo.addGrabPoint(gpc); } } protected void clearGrabPoints() { gpc = null; gpo = null; gPoints[CENTER_POINT_INDEX] = gpc; gPoints[OFFSET_POINT_INDEX] = gpo; } /** * Set the grab points for the graphic provided, setting them on * the extents of the graphic. Called when you want to set the * grab points off the location of the graphic. */ public void setGrabPoints(OMGraphic graphic) { if (!(graphic instanceof OMText)) { return; } assertGrabPoints(); OMText text = (OMText) graphic; boolean ntr = text.getNeedToRegenerate(); int renderType = text.getRenderType(); LatLonPoint llp; int latoffset = 0; int lonoffset = 0; boolean doStraight = true; if (ntr == false) { if (renderType == OMGraphic.RENDERTYPE_LATLON || renderType == OMGraphic.RENDERTYPE_OFFSET) { if (projection != null) { float lon = text.getLon(); float lat = text.getLat(); llp = new LatLonPoint(lat, lon); java.awt.Point p = projection.forward(llp); if (renderType == OMGraphic.RENDERTYPE_LATLON) { doStraight = false; gpc.set((int) p.getX(), (int) p.getY()); } else { latoffset = (int) p.getY(); lonoffset = (int) p.getX(); gpo.set(lonoffset, latoffset); } } } if (doStraight) { gpc.set(lonoffset + text.getX(), latoffset + text.getY()); } if (renderType == OMGraphic.RENDERTYPE_OFFSET) { gpo.updateOffsets(); } } else { System.out.println("EditableOMText.setGrabPoint: graphic needs to be regenerated"); } } /** * Take the current location of the GrabPoints, and modify the * location parameters of the OMPoint with them. Called when you * want the graphic to change according to the grab points. */ public void setGrabPoints() { int renderType = text.getRenderType(); LatLonPoint llp1; Debug.message("eomt", "EditableOMText.setGrabPoints()"); // Do center point for lat/lon or offset points if (renderType == OMGraphic.RENDERTYPE_LATLON) { if (projection != null) { // movingPoint == gpc
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -