01: /*
02: * Copyright (C) 2004 Giuseppe MANNA
03: *
04: * This file is part of FreeReportBuilder
05: *
06: * FreeReportBuilder is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21:
22: package it.frb.tree;
23:
24: public class CustomMouseAdapterWithPopup extends
25: java.awt.event.MouseAdapter {
26:
27: javax.swing.JComponent jComp;
28: CustomJPopupMenu cPopupM;
29:
30: /** Creates new CustomMouseAdapter */
31: public CustomMouseAdapterWithPopup(javax.swing.JComponent jComp) {
32: super ();
33: this .jComp = jComp;
34: cPopupM = new CustomJPopupMenu(jComp);
35: }
36:
37: public void showPopupMenu(java.awt.event.MouseEvent e) {
38: if (e.isPopupTrigger()) {
39: cPopupM.show(e.getComponent(), e.getX(), e.getY());
40: }
41: }
42:
43: public void mouseReleased(java.awt.event.MouseEvent e) {
44: if (jComp.getClass() == CustomTree.class) {
45: CustomTree cjTree = (CustomTree) jComp;
46: int selRow = cjTree.getRowForLocation(e.getX(), e.getY());
47: javax.swing.tree.TreePath selPath = cjTree
48: .getPathForLocation(e.getX(), e.getY());
49: if (selRow != -1) {
50: showPopupMenu(e);
51: }
52: } else {
53: showPopupMenu(e);
54: }
55: }
56:
57: public void mousePressed(java.awt.event.MouseEvent e) {
58: if (jComp.getClass() == CustomTree.class) {
59: CustomTree cjTree = (CustomTree) jComp;
60: int selRow = cjTree.getRowForLocation(e.getX(), e.getY());
61: javax.swing.tree.TreePath selPath = cjTree
62: .getPathForLocation(e.getX(), e.getY());
63: if (selRow != -1) {
64: CustomTreeUtil ctu = new CustomTreeUtil();
65: cjTree.setSelectionPath(selPath);
66: cjTree.pathNodeSelected = selPath;
67: showPopupMenu(e);
68: if (e.getClickCount() == 1) {
69: //System.out.println(selPath.toString());
70: } else if (e.getClickCount() == 2) {
71: if (javax.swing.SwingUtilities.isLeftMouseButton(e)) {
72:
73: }
74: }
75: }
76: } else {
77: showPopupMenu(e);
78: }
79: }
80: }
|