source: other-projects/FileTransfer-WebSocketPair/testGXTWithGreenstone/src/org/greenstone/gatherer/file/RecycleBin.java@ 33053

Last change on this file since 33053 was 33053, checked in by ak19, 5 years ago

I still had some stuff of Nathan Kelly's (FileTransfer-WebSocketPair) sitting on my USB. Had already commited the Themes folder at the time, 2 years back. Not sure if he wanted this additional folder commited. But I didn't want to delete it and decided it will be better off on SVN. When we use his project, if we find we didn't need this test folder, we can remove it from svn then.

File size: 7.5 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37package org.greenstone.gatherer.file;
38
39import java.awt.*;
40import java.awt.dnd.*;
41import java.awt.event.*;
42import java.awt.geom.AffineTransform;
43import java.io.*;
44import java.util.*;
45import javax.swing.*;
46import javax.swing.tree.*;
47import org.greenstone.gatherer.Configuration;
48import org.greenstone.gatherer.Gatherer;
49import org.greenstone.gatherer.gui.GLIButton;
50import org.greenstone.gatherer.util.DragComponent;
51import org.greenstone.gatherer.util.DragGroup;
52import org.greenstone.gatherer.util.JarTools;
53
54
55public class RecycleBin
56 extends GLIButton
57 implements DragComponent, DropTargetListener {
58
59 private boolean ignore = false;
60 /** The group encompasses all of the objects you plan to drag and drop within, and ensures that only one has focus (as clearly identified by the colour of the selection field or, in this particular case, the background) and that actions only occur between components in the same group. */
61 private DragGroup group;
62 /** In order to make this button a drop target we have to create a DropTarget instance with the button as its target. */
63 private DropTarget drop_target;
64 private FileSystemModel model;
65 /** What sort of action should a drag resemble. Not really used as we override with custom drag icon. */
66 private int drag_action = DnDConstants.ACTION_MOVE;
67 /** The last point the mouse was at. Used to repaint 'spoilt' area. */
68 private Point pt_last = null;
69 /** The area covered by the drag ghost, our custom drag icon. */
70 private Rectangle ra_ghost = new Rectangle();
71
72
73 public RecycleBin()
74 {
75 super(JarTools.getImage("bin.gif"));
76 this.drop_target = new DropTarget(this, drag_action, this, true);
77
78 setBackground(Configuration.getColor("coloring.button_background", true));
79 setForeground(Configuration.getColor("coloring.button_foreground", true));
80 setOpaque(true);
81
82 this.model = new FileSystemModel(new RecycleBinNode(new File(Gatherer.getGLIUserDirectoryPath() + "recycle")));
83 }
84
85
86 /** In order for the appearance to be consistant, given we may be in the situation where the pointer has left our focus but the ghost remains, this method allows other members of the GGroup to tell this component to repair the 'spoilt' region left by its ghost. */
87 public void clearGhost(){
88 }
89
90
91 /** Any implementation of DropTargetListener must include this method so we can be notified when the drag focus enters this component. We want to provide some sort of indication whether the current component is an acceptable drop target as well as indicating focus. */
92 public void dragEnter(DropTargetDragEvent event) {
93 group.grabFocus(this);
94 setBackground(Configuration.getColor("coloring.button_selected_background", true));
95 setForeground(Configuration.getColor("coloring.button_selected_foreground", true));
96 }
97
98 /** Any implementation of DropTargetListener must include this method so we can be notified when the drag focus leaves this component. We need to indicate that we have lost focus. */
99 public void dragExit(DropTargetEvent event) {
100 setBackground(Configuration.getColor("coloring.button_background", true));
101 setForeground(Configuration.getColor("coloring.button_foreground", true));
102 }
103
104 /** Any implementation of DropTargetListener must include this method so we can be notified when the drag moves in this component. This is where we repaint our ghost icon at the tip of the mouse pointer. */
105 public void dragOver(DropTargetDragEvent event) {
106 Graphics2D g2 = (Graphics2D) getGraphics();
107 Point pt = event.getLocation();
108 if(pt_last != null && pt.equals(pt_last)) {
109 return;
110 }
111 pt_last = pt;
112 if(!DragSource.isDragImageSupported()) {
113 // Erase the last ghost image and or cue line
114 paintImmediately(ra_ghost.getBounds());
115 // Remember where you are about to draw the new ghost image
116 ra_ghost.setRect(pt.x - group.mouse_offset.x, pt.y - group.mouse_offset.y, group.image_ghost.getWidth(), group.image_ghost.getHeight());
117 // Draw the ghost image
118 g2.drawImage(group.image_ghost, AffineTransform.getTranslateInstance(ra_ghost.getX(), ra_ghost.getY()), null);
119 }
120 }
121
122 /** Any implementation of DropTargetListener must include this method so we can be notified when the drag ends, ie the transferable is dropped. This in turn triggers a series of add events preceded by a pre() and followed by a post(). */
123 public void drop(DropTargetDropEvent event) {
124 ignore = true;
125 group.grabFocus(this);
126 setBackground(Configuration.getColor("coloring.button_background", true));
127 setForeground(Configuration.getColor("coloring.button_foreground", true));
128
129 try {
130 DragComponent source = group.getSource();
131 TreePath[] selection = group.getSelection();
132 FileNode[] source_nodes = new FileNode[selection.length];
133 for(int i = 0; i < source_nodes.length; i++) {
134 source_nodes[i] = (FileNode) selection[i].getLastPathComponent();
135 }
136 event.acceptDrop(drag_action);
137 // Action delete
138 Gatherer.f_man.action(source, source_nodes, this, null);
139 group.setSource(null);
140 group.setSelection(null);
141 }
142 catch(Exception error) {
143 error.printStackTrace();
144 event.rejectDrop();
145 }
146 ignore = false;
147 // Clear up the group.image_ghost
148 paintImmediately(ra_ghost.getBounds());
149 event.getDropTargetContext().dropComplete(true);
150 }
151
152 /** Any implementation of DropTargetListener must include this method so we can be notified when the action to be taken upon drop changes. We never change so we don't do anything here. */
153 public void dropActionChanged(DropTargetDragEvent event) {
154 }
155
156 /** Used to notify this component that it has gained focus by some method other that mouse focus. */
157 public void gainFocus() {
158 }
159
160 /** Any implementation of DragComponent must include this method so that a outsider can get at the underlying tree model behind the component. */
161 public FileSystemModel getTreeModel(){
162 return (FileSystemModel) model;
163 }
164
165 public boolean ignore() {
166 return ignore;
167 }
168
169 /** This method is used to inform this component when it loses focus by means other than a drag mouse event, and should indicate this somehow. */
170 public void loseFocus() {
171 }
172
173 public void setGroup(DragGroup group) {
174 this.group = group;
175 }
176
177
178 public class RecycleBinNode
179 extends FileNode
180 {
181 public RecycleBinNode(File file)
182 {
183 super(file);
184 }
185
186 public FileNode addChildNode(File file) { return null; }
187 }
188}
Note: See TracBrowser for help on using the repository browser.