本文整理汇总了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);
}
示例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();
}
示例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();
}
}
}
示例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);
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}