Java Image createCursor(Image cursorImage, Point hotSpot, String name)

Here you can find the source of createCursor(Image cursorImage, Point hotSpot, String name)

Description

create Cursor

License

Open Source License

Declaration

public static Cursor createCursor(Image cursorImage, Point hotSpot, String name) 

Method Source Code

//package com.java2s;
/*//from w  ww  . j  ava  2  s  .  c om
 *   Copyright (C) 2006  The Concord Consortium, Inc.,
 *   25 Love Lane, Concord, MA 01742
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * END LICENSE */

import java.awt.Cursor;

import java.awt.Dimension;

import java.awt.Image;
import java.awt.Point;

import java.awt.Toolkit;

import java.net.URL;

import javax.swing.ImageIcon;

public class Main {
    public static Cursor createCursor(URL url, Point hotSpot, String name) {
        return createCursor(new ImageIcon(url), hotSpot, name);
    }

    public static Cursor createCursor(ImageIcon cursorIcon, Point hotSpot, String name) {
        return createCursor(cursorIcon.getImage(), hotSpot, name);
    }

    public static Cursor createCursor(Image cursorImage, Point hotSpot, String name) {
        if (hotSpot == null)
            hotSpot = new Point();
        Dimension prefDimension = Toolkit.getDefaultToolkit().getBestCursorSize(hotSpot.x, hotSpot.y);
        if (hotSpot.x > prefDimension.width - 1)
            hotSpot.x = prefDimension.width - 1;
        else if (hotSpot.x < 0)
            hotSpot.x = 0;
        if (hotSpot.y > prefDimension.height - 1)
            hotSpot.y = prefDimension.height - 1;
        else if (hotSpot.y < 0)
            hotSpot.y = 0;
        return Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, hotSpot, name);
    }
}

Related

  1. absoluteDifferenceImage(int[] rgb1, int[] rgb2, double scale)
  2. checkLosslessImageExt(Component parent, File f)
  3. configureMacOSApplication(String appName, String dockImagePath)
  4. CreateCopy(Image srcImg)
  5. createCursor(Image image, Point hotspot, String name)
  6. createMemoryImage(int width, int height, Color colour, JComponent someComponent)
  7. createQualityResizedImage( Image orginalImage, int width, int height, boolean keepRatio)
  8. createScaledImage(Image inImage, int inWidth, int inHeight)