当前位置: 首页>>代码示例>>Java>>正文


Java Toolkit.createCustomCursor方法代码示例

本文整理汇总了Java中java.awt.Toolkit.createCustomCursor方法的典型用法代码示例。如果您正苦于以下问题:Java Toolkit.createCustomCursor方法的具体用法?Java Toolkit.createCustomCursor怎么用?Java Toolkit.createCustomCursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Toolkit的用法示例。


在下文中一共展示了Toolkit.createCustomCursor方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCustomCursor

import java.awt.Toolkit; //导入方法依赖的package包/类
public static Cursor createCustomCursor(Component component, Image icon, String name) {
    Toolkit t = component.getToolkit();
    Dimension d = t.getBestCursorSize(16, 16);
    Image i = icon;

    if (d.width != icon.getWidth(null)) {
        if (((d.width) == 0) && (d.height == 0)) {
            // system doesn't support custom cursors, falling back
            return Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        }

        // need to resize the icon
        Image empty = ImageUtilities.createBufferedImage(d.width, d.height);
        i = ImageUtilities.mergeImages(icon, empty, 0, 0);
    }

    return t.createCustomCursor(i, new Point(1, 1), name);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:Utilities.java

示例2: FontCanvas

import java.awt.Toolkit; //导入方法依赖的package包/类
public FontCanvas() {
    this.addMouseListener( this );
    this.addMouseMotionListener( this );
    this.setForeground( Color.black );
    this.setBackground( Color.white );

    /// Creates an invisble pointer by giving it bogus image
    /// Possibly find a workaround for this...
    Toolkit tk = Toolkit.getDefaultToolkit();
    byte bogus[] = { (byte) 0 };
    blankCursor =
      tk.createCustomCursor( tk.createImage( bogus ), new Point(0, 0), "" );

    zoomWindow = new JWindow( parent ) {
        public void paint( Graphics g ) {
            g.drawImage( zoomImage, 0, 0, zoomWindow );
        }
    };
    zoomWindow.setCursor( blankCursor );
    zoomWindow.pack();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:FontPanel.java

示例3: keyPressed

import java.awt.Toolkit; //导入方法依赖的package包/类
public void keyPressed(KeyEvent e) {
	if ( e.getKeyCode() == KeyEvent.VK_SPACE) {
		setSpaceBarPress(true);
	}

	if(getSpaceBarPress()) {
		// Set locations
		screenPressedX = MouseInfo.getPointerInfo().getLocation().x;
		screenPressedY = MouseInfo.getPointerInfo().getLocation().y;
		pressedX = scrollPane.getHorizontalScrollBar().getValue();
		pressedY = scrollPane.getVerticalScrollBar().getValue();

		// Set cursor to closed hand
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
		String path = "org/geomapapp/resources/icons/close_hand.png";
		java.net.URL url = loader.getResource(path);
		try {
			BufferedImage im = ImageIO.read(url);
			Cursor closeHandCursor = toolkit.createCustomCursor( im, new Point(0,0), "close_hand");
			setCursor(closeHandCursor);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:27,代码来源:XMap.java

示例4: keyReleased

import java.awt.Toolkit; //导入方法依赖的package包/类
public void keyReleased(KeyEvent e) {
	if ( e.getKeyCode() == KeyEvent.VK_SPACE) {
		setSpaceBarPress(false);
	}
	// If pan button in toolbar is selected replace with open hand cursor
	if(((MapApp)app).tools.panB.isSelected() ){
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
		String pathB = "org/geomapapp/resources/icons/open_hand.png";
		java.net.URL url = loader.getResource(pathB);
		setSpaceBarPress(false);
		try {
			BufferedImage im = ImageIO.read(url);
			Cursor openHandCursor = toolkit.createCustomCursor( im, new Point(0,0), "close_hand");
			setCursor(openHandCursor);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}
	else if(!getSpaceBarPress()){
		setCursor(Cursor.getDefaultCursor());
		setSpaceBarPress(false);
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:25,代码来源:XMap.java

示例5: mouseReleased

import java.awt.Toolkit; //导入方法依赖的package包/类
public void mouseReleased(MouseEvent e) {
	
	// If pan button in toolbar is selected replace with open hand cursor
	if(((MapApp)app).tools.panB.isSelected() ){
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
		String pathB = "org/geomapapp/resources/icons/open_hand.png";
		java.net.URL url = loader.getResource(pathB);
		try {
			BufferedImage im = ImageIO.read(url);
			Cursor openHandCursor = toolkit.createCustomCursor( im, new Point(0,0), "close_hand");
			setCursor(openHandCursor);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	} // Otherwise set to the default cursor
	else {
		setCursor(Cursor.getDefaultCursor());
	}
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:21,代码来源:XMap.java

示例6: createCursor

import java.awt.Toolkit; //导入方法依赖的package包/类
/** Creates a named cursor from a given file. */
static private Cursor createCursor(String name, ImageIcon icon) {
    if (GraphicsEnvironment.isHeadless()) {
        // The environtment variable DISPLAY is not set. We can't call
        // createCustomCursor from the awt toolkit because this causes
        // a java.awt.HeadlessException. In any case we don't need the
        // cursor because we are running without GUI, so we just abort.
        return null;
    } else {
        Toolkit tk = Toolkit.getDefaultToolkit();
        Image cursorImage = icon.getImage();
        return tk.createCustomCursor(cursorImage, new Point(0, 0), name);
    }
}
 
开发者ID:meteoorkip,项目名称:JavaGraph,代码行数:15,代码来源:Icons.java

示例7: getCursor

import java.awt.Toolkit; //导入方法依赖的package包/类
/**
 * Get a suitable cursor for the given component.
 *
 * @param c The component to consider.
 * @return A suitable {@code Cursor}, or null on failure.
 */
private Cursor getCursor(JComponent c) {
    if (c instanceof JLabel
        && ((JLabel)c).getIcon() instanceof ImageIcon) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        ImageIcon imageIcon = ((ImageIcon)((JLabel)c).getIcon());
        Dimension bestSize = tk.getBestCursorSize(imageIcon.getIconWidth(),
            imageIcon.getIconHeight());
            
        if (bestSize.width == 0 || bestSize.height == 0) return null;
           
        if (bestSize.width > bestSize.height) {
            bestSize.height = (int)((((double)bestSize.width)
                    / ((double)imageIcon.getIconWidth()))
                * imageIcon.getIconHeight());
        } else {
            bestSize.width = (int)((((double)bestSize.height)
                    / ((double)imageIcon.getIconHeight()))
                * imageIcon.getIconWidth());
        }
        BufferedImage scaled = ImageLibrary
            .createResizedImage(imageIcon.getImage(),
                                bestSize.width, bestSize.height);
        Point point = new Point(bestSize.width / 2,
                                bestSize.height / 2);
        try {
            return tk.createCustomCursor(scaled, point,
                                         "freeColDragIcon");
        } catch (Exception ex) {
            ; // Fall through
        }
    }
    return null;
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:40,代码来源:DefaultTransferHandler.java

示例8: mousePressed

import java.awt.Toolkit; //导入方法依赖的package包/类
public void mousePressed(MouseEvent e) {
//		***** GMA 1.6.4: Record screen position when user presses mouse button
//		System.out.println("Pressed value: " + e.getX());
//		System.out.println("Pressed value: " + e.getY());
//		pressedX = e.getX();
//		pressedY = e.getY();
		pressedX = scrollPane.getHorizontalScrollBar().getValue();
		pressedY = scrollPane.getVerticalScrollBar().getValue();
		screenPressedX = MouseInfo.getPointerInfo().getLocation().x;
		screenPressedY = MouseInfo.getPointerInfo().getLocation().y;

		// Set cursor to closed hand while right button pressed
		if(((MapApp)app).tools.panB.isSelected() ) {
			if (e.getModifiers()==4 || e.getModifiers()==16) {
				Toolkit toolkit = Toolkit.getDefaultToolkit();
				ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
				String path = "org/geomapapp/resources/icons/close_hand.png";
				java.net.URL url = loader.getResource(path);
				try {
					BufferedImage im = ImageIO.read(url);
					Cursor closeHandCursor = toolkit.createCustomCursor( im, new Point(0,0), "close_hand");
					setCursor(closeHandCursor);
				} catch (IOException e1) {
					e1.printStackTrace();
				}
			} else {
				setSpaceBarPress(false);
				setCursor(Cursor.getDefaultCursor());
			}
		}
		
		//check Profile button in the main tool bar
		if (((MapApp)app).tools.profileB.isSelected()) {
			setCursor(Cursor.getDefaultCursor());
		}
		
		// Request focus on click so that KeyEvents work again
		requestFocusInWindow();
	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:40,代码来源:XMap.java

示例9: getCurrentCursor

import java.awt.Toolkit; //导入方法依赖的package包/类
public Cursor getCurrentCursor() {
		if (!map.baseCursor.equals(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)))
			return map.baseCursor;

		if (tb[0].isSelected() || tb[3].isSelected()) {
			return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
		}

		if (panB.isSelected()) {
			Toolkit toolkit = Toolkit.getDefaultToolkit();
			ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
			String path = "org/geomapapp/resources/icons/open_hand.png";
			java.net.URL url = loader.getResource(path);
			try {
				BufferedImage im = ImageIO.read(url);
//				Image image = toolkit.getImage("img.gif");
				Cursor brokenCursor = toolkit.createCustomCursor( im, new Point(0,0), "open_hand" );
				return brokenCursor;
			} catch (IOException e1) {
				e1.printStackTrace();
				return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
			}
		}
		if (tb[1].isSelected()) {
			return Zoomer.ZOOM_IN;
		}
		if (tb[2].isSelected()) {
			return Zoomer.ZOOM_OUT;
		}
		return Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:32,代码来源:MapTools.java

示例10: createCursor

import java.awt.Toolkit; //导入方法依赖的package包/类
@Override
public Cursor createCursor(int xHotspot, int yHotspot, BufferedImage image) 
{
	Toolkit tk = Toolkit.getDefaultToolkit();
	return new JOGLCursor(tk.createCustomCursor(image, new Point(xHotspot, yHotspot), null), component);
}
 
开发者ID:ec-europa,项目名称:sumo,代码行数:7,代码来源:JOGLCursorFactory.java

示例11: mouseDragged

import java.awt.Toolkit; //导入方法依赖的package包/类
public void mouseDragged(MouseEvent e) {

		// GMA 1.6.4: Perform pan while "Pan" button is selected by performing a centering on the point that is dragged to.
		// Pan with right click of mouse equivalent of modifier 4
		if ( (((MapApp)app).tools.panB.isSelected() && e.getModifiers()==16) ||
				((e.getModifiers()==4)) ) {
			// Set cursor to closed hand while drag
			Toolkit toolkit = Toolkit.getDefaultToolkit();
			ClassLoader loader = org.geomapapp.util.Icons.class.getClassLoader();
			String path = "org/geomapapp/resources/icons/close_hand.png";
			java.net.URL url = loader.getResource(path);
			try {
				BufferedImage im = ImageIO.read(url);
				Cursor closeHandCursor = toolkit.createCustomCursor( im, new Point(0,0), "close_hand");
				setCursor(closeHandCursor);
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			int newX = pressedX - ( MouseInfo.getPointerInfo().getLocation().x - screenPressedX );
			if (wrap > 0) {
				double dx = wrap * zoom;
				while (newX < 0) {
					newX += dx;
				}
				int test = getPreferredSize().width - getVisibleRect().width;
				while (newX > test)
					newX -= dx;
			}
			scrollPane.getHorizontalScrollBar().setValue( newX );
			/*if ( screenPressedX < MouseInfo.getPointerInfo().getLocation().x ) {
				scrollPane.getHorizontalScrollBar().setValue( newX );
			}
			else {
				scrollPane.getHorizontalScrollBar().setValue( newX );
			} */
			if ( screenPressedY < MouseInfo.getPointerInfo().getLocation().y ) {
				scrollPane.getVerticalScrollBar().setValue( pressedY - ( MouseInfo.getPointerInfo().getLocation().y - screenPressedY ) );
			}
			else {
				scrollPane.getVerticalScrollBar().setValue( pressedY + ( screenPressedY - MouseInfo.getPointerInfo().getLocation().y ) );
			}
			revalidate();
			repaint();
		} 
		else {
			setSpaceBarPress(false);
		}
		// Request focus on so that KeyEvents work again
		requestFocusInWindow();
	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:51,代码来源:XMap.java


注:本文中的java.awt.Toolkit.createCustomCursor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。