001 /*
002 * Copyright 2002 - 2010 JEuclid, http://jeuclid.sf.net
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 /* $Id $ */
018
019 package net.sourceforge.jeuclid.swing;
020
021 import java.awt.event.MouseEvent;
022 import java.awt.event.MouseListener;
023 import java.util.List;
024
025 import net.sourceforge.jeuclid.layout.JEuclidView.NodeRect;
026
027 import org.w3c.dom.Node;
028
029 /**
030 * A simple mouse listener for Graphics<=>Text association.
031 *
032 * @version $Revision: $
033 */
034 public class JMathComponentMouseListener implements MouseListener {
035
036 /**
037 * math component instance.
038 */
039 private final JMathComponent mathComponent;
040
041 /**
042 * standard constructor.
043 *
044 * @param mathComponentInstance
045 * math component instance
046 */
047 public JMathComponentMouseListener(
048 final JMathComponent mathComponentInstance) {
049 this.mathComponent = mathComponentInstance;
050 }
051
052 /**
053 * mouse click event handler.
054 *
055 * @param e
056 * mouse event
057 */
058 public final void mouseClicked(final MouseEvent e) {
059 final MathComponentUI ui = this.mathComponent.getUI();
060 final List<NodeRect> rectList = ui.getNodesAt(this.mathComponent, e.getX(), e.getY());
061 if (rectList != null && rectList.size() > 0) {
062 final Node lastNode = rectList.get(rectList.size() - 1).getNode();
063 this.mathComponent.getCursorListener().updateCursorPosition(
064 lastNode);
065 }
066 }
067
068 /**
069 * mouse pressed event (unused).
070 *
071 * @param e
072 * mouse event
073 */
074 public final void mousePressed(final MouseEvent e) {
075 }
076
077 /**
078 * mouse pressed event (unused).
079 *
080 * @param e
081 * mouse event
082 */
083 public final void mouseReleased(final MouseEvent e) {
084 }
085
086 /**
087 * mouse pressed event (unused).
088 *
089 * @param e
090 * mouse event
091 */
092 public final void mouseEntered(final MouseEvent e) {
093 }
094
095 /**
096 * mouse pressed event (unused).
097 *
098 * @param e
099 * mouse event
100 */
101 public final void mouseExited(final MouseEvent e) {
102 }
103 }