+ /**
+ * Load an image named in jexer.Swing.mouseImage as the mouse cursor.
+ * The image must be on the classpath.
+ *
+ * @return the cursor
+ */
+ private Cursor getMouseImage() {
+ Cursor cursor = Cursor.getDefaultCursor();
+ String filename = System.getProperty("jexer.Swing.mouseImage");
+ assert (filename != null);
+
+ try {
+ ClassLoader loader = Thread.currentThread().
+ getContextClassLoader();
+
+ java.net.URL url = loader.getResource(filename);
+ if (url == null) {
+ // User named a file, but it's not on the classpath. Bail
+ // out.
+ return cursor;
+ }
+
+ BufferedImage cursorImage = ImageIO.read(url);
+ java.awt.Dimension cursorSize = Toolkit.getDefaultToolkit().
+ getBestCursorSize(
+ cursorImage.getWidth(), cursorImage.getHeight());
+
+ cursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImage,
+ new Point((int) Math.min(cursorImage.getWidth() / 2,
+ cursorSize.getWidth() - 1),
+ (int) Math.min(cursorImage.getHeight() / 2,
+ cursorSize.getHeight() - 1)),
+ "custom cursor");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return cursor;
+ }
+
+ /**
+ * Get the appropriate mouse cursor based on jexer.Swing.mouseStyle.
+ *
+ * @return the cursor
+ */
+ private Cursor getMouseCursor() {
+ Cursor cursor = Cursor.getDefaultCursor();
+ String style = System.getProperty("jexer.Swing.mouseStyle");
+ assert (style != null);
+
+ style = style.toLowerCase();
+
+ if (style.equals("none")) {
+ // Transparent 16 x 16 pixel cursor image.
+ BufferedImage cursorImg = new BufferedImage(16, 16,
+ BufferedImage.TYPE_INT_ARGB);
+ // Create a new blank cursor.
+ cursor = Toolkit.getDefaultToolkit().createCustomCursor(
+ cursorImg, new Point(0, 0), "blank cursor");
+ } else if (style.equals("default")) {
+ cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
+ } else if (style.equals("hand")) {
+ cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
+ } else if (style.equals("text")) {
+ cursor = Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR);
+ } else if (style.equals("move")) {
+ cursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
+ } else if (style.equals("crosshair")) {
+ cursor = Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR);
+ }
+
+ return cursor;
+ }
+