1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.glass.ui.lens;
  27 
  28 import java.util.HashMap;
  29 
  30 import com.sun.glass.ui.Clipboard;
  31 import com.sun.glass.ui.SystemClipboard;
  32 import com.sun.glass.ui.Application;
  33 
  34 import sun.util.logging.PlatformLogger.Level;
  35 
  36 final class LensDnDClipboard extends SystemClipboard {
  37 
  38     public LensDnDClipboard() {
  39         super(Clipboard.DND);
  40         if (LensLogger.getLogger().isLoggable(Level.FINE)) {
  41             LensLogger.getLogger().fine("constructor called");
  42         }
  43     }
  44 
  45     /**
  46      * Should be called when drag operation completed by the 'system'
  47      *
  48      * @param action mask of actions from Clipboard
  49      */
  50     public void actionPerformed(int action) {
  51         if (LensLogger.getLogger().isLoggable(Level.FINE)) {
  52             LensLogger.getLogger().fine("action =  ["+
  53                                          Integer.toHexString(action)+"]");
  54         }
  55         super.actionPerformed(action);
  56     }
  57 
  58     protected  boolean isOwner() {
  59         //called many time while the hovering over target node
  60         //So reduced log level to finest in order to reduce log clutter
  61         if (LensLogger.getLogger().isLoggable(Level.FINEST)) {
  62             LensLogger.getLogger().finest("returns true");
  63         }
  64         return true;//For DnD its always true
  65     }
  66     /**
  67      * Here the magic happens.
  68      * When this method is called all input events should be grabbed and
  69      * appropriate drag notifications should be sent instead of regular input
  70      * events
  71      */
  72     protected  void pushToSystem(HashMap<String, Object> cacheData, int supportedActions) {
  73         if (LensLogger.getLogger().isLoggable(Level.FINE)) {
  74             LensLogger.getLogger().fine("handling drag");
  75         }
  76 
  77         if (LensLogger.getLogger().isLoggable(Level.FINER)) {
  78             LensLogger.getLogger().finer("data =[cachedData = "+ cacheData+
  79                 " supportedActions= "+Integer.toHexString(supportedActions));
  80         }
  81 
  82         LensApplication lensApp = (LensApplication)Application.GetApplication();
  83         lensApp.notifyDragStart();
  84 
  85         if (LensLogger.getLogger().isLoggable(Level.FINE)) {
  86             LensLogger.getLogger().fine("starting nested event loop");
  87         }
  88 
  89         lensApp.enterDnDEventLoop();
  90         // The loop is exited in LensApplication.LensDragEvent.dispatch()
  91         if (LensLogger.getLogger().isLoggable(Level.FINE)) {
  92             LensLogger.getLogger().fine("nested event loop finished");
  93             LensLogger.getLogger().fine("Drag done - notifying actionPreformed");
  94         }
  95 
  96         actionPerformed(Clipboard.ACTION_COPY_OR_MOVE);
  97     }
  98 
  99 
 100 
 101 
 102     //rest of the functionis should not be called. Only applicable for
 103     //SystemClipboards
 104     //Must be overrided thue as they are abstract functions
 105 
 106     protected  void pushTargetActionToSystem(int actionDone) {
 107         LensLogger.getLogger().warning("Not supported");
 108         if (LensLogger.getLogger().isLoggable(Level.FINE)) {
 109             LensLogger.getLogger().fine("actionDone = "+
 110                                          Integer.toHexString(actionDone));
 111         }
 112 
 113     }
 114 
 115     protected  Object popFromSystem(String mimeType) {
 116         LensLogger.getLogger().warning("Not supported");
 117         if (LensLogger.getLogger().isLoggable(Level.FINE)) {
 118             LensLogger.getLogger().fine("mimeType="+mimeType);
 119         }
 120         return null;
 121     }
 122     protected  int supportedSourceActionsFromSystem() {
 123         LensLogger.getLogger().warning("Not supported");
 124 
 125         return Clipboard.ACTION_COPY_OR_MOVE;
 126     }
 127 
 128     protected  String[] mimesFromSystem() {
 129         LensLogger.getLogger().warning("Not supported");
 130 
 131         return null;
 132     }
 133 
 134 }