source: trunk/gli/src/org/greenstone/gatherer/file/FileOpenActionListener.java@ 5153

Last change on this file since 5153 was 4675, checked in by jmt12, 21 years ago

Sunday's work

  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1package org.greenstone.gatherer.file;
2/**
3 *#########################################################################
4 *
5 * A component of the Gatherer application, part of the Greenstone digital
6 * library suite from the New Zealand Digital Library Project at the
7 * University of Waikato, New Zealand.
8 *
9 * <BR><BR>
10 *
11 * Author: John Thompson, Greenstone Digital Library, University of Waikato
12 *
13 * <BR><BR>
14 *
15 * Copyright (C) 1999 New Zealand Digital Library Project
16 *
17 * <BR><BR>
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * <BR><BR>
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * <BR><BR>
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 *########################################################################
37 */
38import java.awt.event.*;
39import java.io.*;
40import javax.swing.*;
41import javax.swing.event.*;
42import javax.swing.tree.*;
43import org.greenstone.gatherer.Gatherer;
44import org.greenstone.gatherer.file.FileNode;
45/** This class listens for mouse clicks and responds to double-clicks (spawn a new application to view the selected file) and right mouse button clicks (popup menu).
46 * @author John Thompson, Greenstone Digital Library, University of Waikato
47 * @version 2.3b
48 */
49public class FileOpenActionListener
50 extends MouseAdapter
51 implements TreeExpansionListener {
52 /** This flag gets toggled to <i>true</i> if the listener determines that the next mouse clicked event it will recieve is actually caused by the tree expanding or collapsing. */
53 private boolean ignore = false;
54 /** The constructor. */
55 public FileOpenActionListener() {
56 }
57 /** Any subclass of MouseAdapter can override this method to respond to mouse click events. In this case we want to start an external application if someone double clicks on an appropriate file record.
58 * @param event A <strong>MouseEvent</strong> containing further information about the mouse click performed.
59 * @see org.greenstone.gatherer.Gatherer
60 * @see org.greenstone.gatherer.collection.FileRecord
61 * @see org.greenstone.gatherer.tree.GTree
62 */
63 public void mouseClicked(MouseEvent event) {
64 ///ystem.err.println("Mouse clicked");
65 if(!ignore) {
66 if(event.getClickCount() >= 2) {
67 // Find the file we're clicking on.
68 JTree tree = (JTree)event.getSource();
69 TreePath path = tree.getClosestPathForLocation(event.getX(), event.getY());
70 if(path != null) {
71 FileNode record = (FileNode)path.getLastPathComponent();
72 ///ystem.err.println("Double clicked on " + record);
73 File file = record.getFile();
74 if(file != null && file.isFile()) {
75 ///ystem.err.println("Running " + file);
76 Gatherer.self.spawnApplication(file);
77 }
78 }
79 }
80 }
81 else {
82 ///ystem.err.println("Caused by tree expansion / collapse. Ignoring.");
83 ignore = false;
84 }
85 }
86 /** Any implementation of TreeExpansionListener must include this method so that we can be informed when a tree node has been collapsed, thus indicating that any mouse click events about to be recieved are most likely related to this event.
87 * @param event A <strong>TreeExpansionEvent</strong> containing information about the node collapsed.
88 */
89 public void treeCollapsed(TreeExpansionEvent event) {
90 ///ystem.err.println("Tree Collapsed");
91 ignore = true;
92 }
93 /** Any implementation of TreeExpansionListener must include this method so that we can be informed when a tree node has been expanded, thus indicating that any mouse click events about to be recieved are most likely related to this event.
94 * @param event A <strong>TreeExpansionEvent</strong> containing information about the node expanded.
95 */
96 public void treeExpanded(TreeExpansionEvent event) {
97 ///ystem.err.println("Tree Expanded");
98 ignore = true;
99 }
100}
Note: See TracBrowser for help on using the repository browser.