001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Mikael MARCHE, Fayçal SOUGRATI, Vincent PAUTRET
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package org.objectweb.salome_tmf.ihm.models;
025:
026: import java.awt.event.MouseAdapter;
027:
028: import java.awt.event.MouseEvent;
029:
030: import javax.swing.JPopupMenu;
031:
032: import javax.swing.JTree;
033:
034: import javax.swing.tree.TreePath;
035:
036: /**
037:
038: * Classe repr?sentant un nouvel ?couteur pour un menu popup
039:
040: * @author teaml039
041:
042: * @version 0.1
043:
044: */
045:
046: public class PopupListener extends MouseAdapter {
047:
048: /**
049:
050: * Menu popup
051:
052: */
053:
054: private JPopupMenu _popup;
055:
056: /**
057:
058: * Arbre sur lequel le menu est affich?
059:
060: */
061:
062: private JTree _tree;
063:
064: /******************************************************************************/
065:
066: /** CONSTRUCTEUR ***/
067:
068: /******************************************************************************/
069:
070: /**
071:
072: * Constructeur du listener
073:
074: * @param popupMenu le menu ? afficher
075:
076: * @param tree l'arbre sur lequel on affihce le menu
077:
078: */
079:
080: public PopupListener(JPopupMenu popupMenu, JTree tree) {
081:
082: _popup = popupMenu;
083:
084: _tree = tree;
085:
086: } // Fin du constructeur PopupListener/2
087:
088: /******************************************************************************/
089:
090: /** METHODES PUBLIQUES ***/
091:
092: /******************************************************************************/
093:
094: /**
095:
096: * Appel?e si on appuie sur un bouton de la souris
097:
098: * @param e un ?v?nement venant de la souris
099:
100: */
101:
102: public void mousePressed(MouseEvent e) {
103:
104: maybeShowPopup(e);
105:
106: } // Fin de la m?thode mousePressed/1
107:
108: /**
109:
110: * Appel?e si on relache un bouton de la souris
111:
112: * @param e un ?v?nement venant de la souris
113:
114: */
115:
116: public void mouseReleased(MouseEvent e) {
117:
118: maybeShowPopup(e);
119:
120: } // Fin de la m?thode mouseReleased/1
121:
122: /**
123:
124: * Traite le clic du bouton droit pour afficher le menu popup.
125:
126: * @param e un ?v?nement venant de la souris
127:
128: */
129:
130: private void maybeShowPopup(MouseEvent e) {
131:
132: if (e.getButton() == MouseEvent.BUTTON3) { //click droit isPopupTrigger()
133:
134: TreePath path = _tree.getClosestPathForLocation(e.getX(), e
135: .getY());
136:
137: _tree.makeVisible(path);
138:
139: _tree.setSelectionRow(_tree.getRowForPath(path));
140:
141: _popup.show(e.getComponent(), e.getX(), e.getY());
142:
143: }
144:
145: } // Fin de la m?thode maybeShowPopup/1
146:
147: } // Fin de la classe PopupListener
|