1 /*
   2  * Copyright (c) 2009, 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.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.awt.BasicStroke;
  25 import java.awt.Color;
  26 import java.awt.Graphics;
  27 import java.awt.Graphics2D;
  28 import java.awt.Toolkit;
  29 import java.awt.Point;
  30 
  31 /**
  32  * An interface provides a set of custom cursors
  33  */
  34 
  35 public interface MyCursor {
  36     public static final java.awt.Cursor NO_DROP = Toolkit.getDefaultToolkit().createCustomCursor(
  37         new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
  38                 @Override public void paint(Graphics gr) {
  39                     gr.setColor(Color.GREEN);
  40                     ((Graphics2D)gr).setStroke(new BasicStroke(3));
  41 
  42                     gr.translate(width/2, height/2);
  43                     int R = width/4;
  44                     gr.drawOval(-R, -R, 2*R, 2*R);
  45                     gr.drawLine(-R, R, R, -R);
  46                 }
  47             }.getImage(),
  48             new Point(0, 0),
  49             "My NoDrop Cursor"
  50     );
  51     public static final java.awt.Cursor MOVE = Toolkit.getDefaultToolkit().createCustomCursor(
  52         new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
  53                 @Override public void paint(Graphics gr) {
  54                     gr.setColor(Color.GREEN);
  55                     ((Graphics2D)gr).setStroke(new BasicStroke(3));
  56 
  57                     gr.drawLine(0, 0, width, height);
  58                     gr.drawLine(0, 0, width/2, 0);
  59                     gr.drawLine(0, 0, 0, height/2);
  60                 }
  61             }.getImage(),
  62             new Point(0, 0),
  63             "My Move Cursor"
  64     );
  65     public static final java.awt.Cursor COPY = Toolkit.getDefaultToolkit().createCustomCursor(
  66         new ImageGenerator(32, 32, new Color(0xff, 0xff, 0xff, 0x00) ) {
  67                 @Override public void paint(Graphics gr) {
  68                     gr.setColor(Color.GREEN);
  69                     ((Graphics2D)gr).setStroke(new BasicStroke(3));
  70                     //arrow
  71                     gr.drawLine(0, 0, width/2, height/2);
  72                     gr.drawLine(0, 0, width/2, 0);
  73                     gr.drawLine(0, 0, 0, height/2);
  74                     //plus
  75                     gr.drawRect(width/2 - 1, height/2 -1, width/2 - 1, height/2 - 1);
  76                     gr.drawLine(width*3/4 - 1, height/2 - 1, width*3/4 - 1, height);
  77                     gr.drawLine(width/2 - 1, height*3/4 - 1, width, height*3/4 - 1);
  78                  }
  79             }.getImage(),
  80             new Point(0, 0),
  81             "My Copy Cursor"
  82     );
  83 }
  84