01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Anton Avtamonov
19: * @version $Revision$
20: */package javax.swing.plaf.basic;
21:
22: import java.awt.event.MouseEvent;
23:
24: import javax.swing.JComponent;
25: import javax.swing.SwingUtilities;
26: import javax.swing.TransferHandler;
27:
28: final class DnDMouseHelper {
29: private final JComponent dndComponent;
30:
31: private boolean dragStarted;
32: private boolean readyForDrag;
33: private boolean processedOnPress;
34: private boolean shouldProcessOnRelease;
35:
36: public DnDMouseHelper(final JComponent c) {
37: dndComponent = c;
38: }
39:
40: public void mousePressed(final MouseEvent e,
41: final boolean dragEnabled, final boolean clickedToItem,
42: final boolean itemSelected) {
43: processedOnPress = dragEnabled && clickedToItem
44: && !itemSelected;
45: readyForDrag = dragEnabled && clickedToItem && itemSelected;
46: shouldProcessOnRelease = dragEnabled && !processedOnPress
47: && !dragStarted;
48: }
49:
50: public boolean shouldProcessOnRelease() {
51: return shouldProcessOnRelease;
52: }
53:
54: public void mouseReleased(final MouseEvent e) {
55: dragStarted = false;
56: }
57:
58: public void mouseDragged(final MouseEvent e) {
59: if (SwingUtilities.isLeftMouseButton(e) && readyForDrag
60: && !dragStarted
61: && dndComponent.getTransferHandler() != null) {
62:
63: dndComponent.getTransferHandler().exportAsDrag(
64: dndComponent, e, TransferHandler.COPY);
65: dragStarted = true;
66: shouldProcessOnRelease = false;
67: }
68: }
69:
70: public boolean isDndStarted() {
71: return dragStarted;
72: }
73: }
|