*/
private boolean focusFollowsMouse = false;
+ /**
+ * If true, display a text-based mouse cursor.
+ */
+ private boolean textMouse = true;
+
+ /**
+ * If true, hide the mouse after typing a keystroke.
+ */
+ private boolean hideMouseWhenTyping = false;
+
+ /**
+ * If true, the mouse should not be displayed because a keystroke was
+ * typed.
+ */
+ private boolean typingHidMouse = false;
+
/**
* The list of commands to run before the next I/O check.
*/
);
}
}
+
+ // Text block mouse option
+ if (System.getProperty("jexer.textMouse", "true").equals("false")) {
+ textMouse = false;
+ }
+
+ // Hide mouse when typing option
+ if (System.getProperty("jexer.hideMouseWhenTyping",
+ "false").equals("true")) {
+
+ hideMouseWhenTyping = true;
+ }
+
}
// ------------------------------------------------------------------------
// Special application-wide events -----------------------------------
+ if (event instanceof TKeypressEvent) {
+ if (hideMouseWhenTyping) {
+ typingHidMouse = true;
+ }
+ }
+
// Peek at the mouse position
if (event instanceof TMouseEvent) {
+ typingHidMouse = false;
+
TMouseEvent mouse = (TMouseEvent) event;
if ((mouseX != mouse.getX()) || (mouseY != mouse.getY())) {
oldMouseX = mouseX;
// Peek at the mouse position
if (event instanceof TMouseEvent) {
+ typingHidMouse = false;
+
TMouseEvent mouse = (TMouseEvent) event;
if ((mouseX != mouse.getX()) || (mouseY != mouse.getY())) {
oldMouseX = mouseX;
}
}
- // Draw mouse at the new position.
- invertCell(mouseX, mouseY);
+ if ((textMouse == true) && (typingHidMouse == false)) {
+ // Draw mouse at the new position.
+ invertCell(mouseX, mouseY);
+ }
oldDrawnMouseX = mouseX;
oldDrawnMouseY = mouseY;
getScreen().unsetImageRow(mouseY);
}
}
- invertCell(mouseX, mouseY);
+ if ((textMouse == true) && (typingHidMouse == false)) {
+ invertCell(mouseX, mouseY);
+ }
oldDrawnMouseX = mouseX;
oldDrawnMouseY = mouseY;
*/
private long lastUpdateTime = 0;
+ /**
+ * If true, hide the mouse after typing a keystroke.
+ */
+ private boolean hideMouseWhenTyping = true;
+
+ /**
+ * If true, the mouse should not be displayed because a keystroke was
+ * typed.
+ */
+ private boolean typingHidMouse = false;
+
// ------------------------------------------------------------------------
// Constructors -----------------------------------------------------------
// ------------------------------------------------------------------------
*/
@Override
public void onKeypress(final TKeypressEvent keypress) {
+ if (hideMouseWhenTyping) {
+ typingHidMouse = true;
+ }
// Scrollback up/down
if (keypress.equals(kbShiftPgUp)
return;
}
+ if (hideMouseWhenTyping) {
+ typingHidMouse = false;
+ }
+
// If the emulator is tracking mouse buttons, it needs to see wheel
// events.
if (emulator.getMouseProtocol() == ECMA48.MouseProtocol.OFF) {
return;
}
+ if (hideMouseWhenTyping) {
+ typingHidMouse = false;
+ }
+
if (mouseOnEmulator(mouse)) {
mouse.setX(mouse.getX() - 1);
mouse.setY(mouse.getY() - 1);
return;
}
+ if (hideMouseWhenTyping) {
+ typingHidMouse = false;
+ }
+
if (mouseOnEmulator(mouse)) {
mouse.setX(mouse.getX() - 1);
mouse.setY(mouse.getY() - 1);
// TTerminalWindow --------------------------------------------------------
// ------------------------------------------------------------------------
+ /**
+ * Returns true if this window does not want the application-wide mouse
+ * cursor drawn over it.
+ *
+ * @return true if this window does not want the application-wide mouse
+ * cursor drawn over it
+ */
+ @Override
+ public boolean hasHiddenMouse() {
+ return (super.hasHiddenMouse() || typingHidMouse);
+ }
+
/**
* Claim the keystrokes the emulator will need.
*/
// Pass the correct text cell width/height to the emulator
emulator.setTextWidth(getScreen().getTextWidth());
emulator.setTextHeight(getScreen().getTextHeight());
+
+ // Hide mouse when typing option
+ if (System.getProperty("jexer.TTerminal.hideMouseWhenTyping",
+ "true").equals("false")) {
+
+ hideMouseWhenTyping = false;
+ }
}
/**
import java.awt.event.WindowListener;
import java.awt.image.BufferedImage;
import java.awt.image.BufferStrategy;
+import java.io.IOException;
+import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public void setupComponent() {
component.setBackground(Color.black);
- // Kill the X11 cursor
- // Transparent 16 x 16 pixel cursor image.
- BufferedImage cursorImg = new BufferedImage(16, 16,
- BufferedImage.TYPE_INT_ARGB);
- // Create a new blank cursor.
- Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
- cursorImg, new Point(0, 0), "blank cursor");
- component.setCursor(blankCursor);
+ if (System.getProperty("jexer.Swing.mouseImage") != null) {
+ component.setCursor(getMouseImage());
+ } else if (System.getProperty("jexer.Swing.mouseStyle") != null) {
+ component.setCursor(getMouseCursor());
+ } else if (System.getProperty("jexer.textMouse",
+ "true").equals("false")
+ ) {
+ // If the user has suppressed the text mouse, don't kill the X11
+ // mouse.
+ component.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+ } else {
+ // Kill the X11 cursor
+ // Transparent 16 x 16 pixel cursor image.
+ BufferedImage cursorImg = new BufferedImage(16, 16,
+ BufferedImage.TYPE_INT_ARGB);
+ // Create a new blank cursor.
+ Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
+ cursorImg, new Point(0, 0), "blank cursor");
+ component.setCursor(blankCursor);
+ }
// Be capable of seeing Tab / Shift-Tab
component.setFocusTraversalKeysEnabled(false);
frame.setBackground(Color.black);
frame.pack();
- // Kill the X11 cursor
- // Transparent 16 x 16 pixel cursor image.
- BufferedImage cursorImg = new BufferedImage(16, 16,
- BufferedImage.TYPE_INT_ARGB);
- // Create a new blank cursor.
- Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
- cursorImg, new Point(0, 0), "blank cursor");
- frame.setCursor(blankCursor);
+ if (System.getProperty("jexer.Swing.mouseImage") != null) {
+ frame.setCursor(getMouseImage());
+ } else if (System.getProperty("jexer.Swing.mouseStyle") != null) {
+ frame.setCursor(getMouseCursor());
+ } else if (System.getProperty("jexer.textMouse",
+ "true").equals("false")
+ ) {
+ // If the user has suppressed the text mouse, don't kill the X11
+ // mouse.
+ frame.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
+ } else {
+ // Kill the X11 cursor
+ // Transparent 16 x 16 pixel cursor image.
+ BufferedImage cursorImg = new BufferedImage(16, 16,
+ BufferedImage.TYPE_INT_ARGB);
+ // Create a new blank cursor.
+ Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
+ cursorImg, new Point(0, 0), "blank cursor");
+ frame.setCursor(blankCursor);
+ }
// Be capable of seeing Tab / Shift-Tab
frame.setFocusTraversalKeysEnabled(false);
}
}
+ /**
+ * 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;
+ }
+
/**
* Set the window title.
*