001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */package org.netbeans.modules.mobility.svgcore.composer.actions;
041:
042: import java.awt.AWTEvent;
043: import java.awt.Graphics;
044: import java.awt.event.MouseEvent;
045: import org.netbeans.modules.mobility.svgcore.composer.AbstractComposerAction;
046: import org.netbeans.modules.mobility.svgcore.composer.ComposerActionFactory;
047: import org.netbeans.modules.mobility.svgcore.composer.SVGObject;
048: import org.netbeans.modules.mobility.svgcore.composer.SVGObjectOutline;
049: import org.netbeans.modules.mobility.svgcore.composer.SceneManager;
050: import org.netbeans.modules.mobility.svgcore.view.svg.SVGViewTopComponent;
051: import org.openide.util.NbBundle;
052: import org.w3c.dom.svg.SVGLocatableElement;
053:
054: /**
055: *
056: * @author Pavel Benes
057: */
058: public final class HighlightAction extends AbstractComposerAction {
059: private final SVGObject m_highlighted;
060:
061: public HighlightAction(ComposerActionFactory factory,
062: SVGObject highlighted) {
063: super (factory);
064: assert highlighted != null : "Null object for highlight"; //NOI18N
065: m_highlighted = highlighted;
066: getScreenManager().getAnimatorView().setToolTipText(
067: getTooltipText());
068: m_highlighted.repaint(SVGObjectOutline.SELECTOR_OVERLAP);
069: }
070:
071: public boolean consumeEvent(AWTEvent evt, boolean isOutsideEvent) {
072: SceneManager sceneMgr = m_factory.getSceneManager();
073: assert sceneMgr.containsAction(HighlightAction.class);
074:
075: if (!isOutsideEvent) {
076: if (evt.getID() == MouseEvent.MOUSE_MOVED) {
077: MouseEvent me = (MouseEvent) evt;
078: SVGObject[] objects = sceneMgr.getPerseusController()
079: .getObjectsAt(me.getX(), me.getY());
080: if (objects == null || objects.length == 0
081: || objects[0] != m_highlighted) {
082: actionCompleted();
083: }
084: } else if (evt.getID() == MouseEvent.MOUSE_EXITED) {
085: actionCompleted();
086: }
087:
088: }
089: return false;
090: }
091:
092: public void paint(Graphics g, int x, int y, boolean isReadOnly) {
093: if (!m_highlighted.isDeleted()) {
094: if (!m_isCompleted
095: && getScreenManager().getHighlightObject()) {
096: m_highlighted.getOutline().highlight(g, x, y);
097: }
098: } else {
099: actionCompleted();
100: }
101: }
102:
103: public void actionCompleted() {
104: super .actionCompleted();
105: getScreenManager().getAnimatorView().setToolTipText("");
106: m_highlighted.repaint(SVGObjectOutline.SELECTOR_OVERLAP);
107: }
108:
109: private String getTooltipText() {
110: String text = ""; //NOI18N
111: String selectedId = m_highlighted.getElementId();
112:
113: if (getScreenManager().getShowTooltip()) {
114: SVGLocatableElement elem = m_highlighted.getSVGElement();
115:
116: String prefix = getPerseusController().getSVGDocument()
117: .toPrefix(elem.getNamespaceURI(), elem);
118: if (prefix == null || prefix.length() == 0) {
119: prefix = elem.getLocalName();
120: }
121: StringBuilder sb = new StringBuilder();
122: sb.append("<html> "); //NOI18N
123: sb.append(NbBundle.getMessage(SVGViewTopComponent.class,
124: "LBL_Type", prefix)); //NOI18N
125: sb.append("<br> "); //NOI18N
126:
127: String id = elem.getId();
128: if (id != null) {
129: sb.append(NbBundle.getMessage(
130: SVGViewTopComponent.class, "LBL_Id", id)); //NOI18N
131: sb.append("<br>"); //NOI18N
132: }
133:
134: sb.append(getDataObject().getModel().describeElement(
135: selectedId /*, false, true, "<br>"*/)); //NOI18N
136: sb.append("</html>"); //NOI18N
137: return sb.toString();
138: }
139:
140: return text;
141: }
142: }
|