Home » openjdk-7 » javax » swing » plaf » basic » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     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    */
   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,
   42                                final boolean clickedToItem,
   43                                final boolean itemSelected) {
   44           processedOnPress = dragEnabled && clickedToItem && !itemSelected;
   45           readyForDrag = dragEnabled && clickedToItem && itemSelected;
   46           shouldProcessOnRelease = dragEnabled && !processedOnPress && !dragStarted;
   47       }
   48   
   49       public boolean shouldProcessOnRelease() {
   50           return shouldProcessOnRelease;
   51       }
   52   
   53       public void mouseReleased(final MouseEvent e) {
   54           dragStarted = false;
   55       }
   56   
   57       public void mouseDragged(final MouseEvent e) {
   58           if (SwingUtilities.isLeftMouseButton(e)
   59               && readyForDrag
   60               && !dragStarted
   61               && dndComponent.getTransferHandler() != null) {
   62   
   63               dndComponent.getTransferHandler().exportAsDrag(dndComponent, e, TransferHandler.COPY);
   64               dragStarted = true;
   65               shouldProcessOnRelease = false;
   66           }
   67       }
   68   
   69       public boolean isDndStarted() {
   70           return dragStarted;
   71       }
   72   }

Home » openjdk-7 » javax » swing » plaf » basic » [javadoc | source]