*/
private int oldMouseY;
+ /**
+ * The last mouse up click time, used to determine if this is a mouse
+ * double-click.
+ */
+ private long lastMouseUpTime;
+
+ /**
+ * The amount of millis between mouse up events to assume a double-click.
+ */
+ private long doubleClickTime = 250;
+
/**
* Event queue that is filled by run().
*/
if (debugEvents) {
System.err.printf("Handle event: %s\n", event);
}
+ TMouseEvent doubleClick = null;
// Special application-wide events -----------------------------------
oldMouseY = mouseY;
mouseX = mouse.getX();
mouseY = mouse.getY();
+ } else {
+ if (mouse.getType() == TMouseEvent.Type.MOUSE_UP) {
+ if ((mouse.getTime().getTime() - lastMouseUpTime) <
+ doubleClickTime) {
+
+ // This is a double-click.
+ doubleClick = new TMouseEvent(TMouseEvent.Type.
+ MOUSE_DOUBLE_CLICK,
+ mouse.getX(), mouse.getY(),
+ mouse.getAbsoluteX(), mouse.getAbsoluteY(),
+ mouse.isMouse1(), mouse.isMouse2(),
+ mouse.isMouse3(),
+ mouse.isMouseWheelUp(), mouse.isMouseWheelDown());
+
+ } else {
+ // The first click of a potential double-click.
+ lastMouseUpTime = mouse.getTime().getTime();
+ }
+ }
}
// See if we need to switch focus to another window or the menu
mouse.setX(mouse.getX() - window.getX());
mouse.setY(mouse.getY() - window.getY());
+ if (doubleClick != null) {
+ doubleClick.setX(doubleClick.getX() - window.getX());
+ doubleClick.setY(doubleClick.getY() - window.getY());
+ }
+
if (window.mouseWouldHit(mouse)) {
dispatchToDesktop = false;
}
event);
}
window.handleEvent(event);
+ if (doubleClick != null) {
+ window.handleEvent(doubleClick);
+ }
}
if (dispatchToDesktop) {
// This event is fair game for the desktop to process.
if (desktop != null) {
desktop.handleEvent(event);
+ if (doubleClick != null) {
+ desktop.handleEvent(doubleClick);
+ }
}
}
}
* @see #primaryHandleEvent(TInputEvent event)
*/
private void secondaryHandleEvent(final TInputEvent event) {
+ TMouseEvent doubleClick = null;
+
// Peek at the mouse position
if (event instanceof TMouseEvent) {
TMouseEvent mouse = (TMouseEvent) event;
oldMouseY = mouseY;
mouseX = mouse.getX();
mouseY = mouse.getY();
+ } else {
+ if (mouse.getType() == TMouseEvent.Type.MOUSE_UP) {
+ if ((mouse.getTime().getTime() - lastMouseUpTime) <
+ doubleClickTime) {
+
+ // This is a double-click.
+ doubleClick = new TMouseEvent(TMouseEvent.Type.
+ MOUSE_DOUBLE_CLICK,
+ mouse.getX(), mouse.getY(),
+ mouse.getAbsoluteX(), mouse.getAbsoluteY(),
+ mouse.isMouse1(), mouse.isMouse2(),
+ mouse.isMouse3(),
+ mouse.isMouseWheelUp(), mouse.isMouseWheelDown());
+
+ } else {
+ // The first click of a potential double-click.
+ lastMouseUpTime = mouse.getTime().getTime();
+ }
+ }
}
}
secondaryEventReceiver.handleEvent(event);
+ if (doubleClick != null) {
+ secondaryEventReceiver.handleEvent(doubleClick);
+ }
}
/**
return document.getLineCount();
}
+ /**
+ * Get the current visible top row number. 1-based.
+ *
+ * @return the visible top row number. Row 1 is the first row.
+ */
+ public int getVisibleRowNumber() {
+ return topLine + 1;
+ }
+
+ /**
+ * Set the current visible row number. 1-based.
+ *
+ * @param row the new visible row number. Row 1 is the first row.
+ */
+ public void setVisibleRowNumber(final int row) {
+ assert (row > 0);
+ if ((row > 0) && (row < document.getLineCount())) {
+ topLine = row - 1;
+ alignDocument(true);
+ }
+ }
+
/**
* Get the current editing row number. 1-based.
*
if (mouseOnEditor(mouse)) {
// The editor might have changed, update the scollbars.
setBottomValue(editField.getMaximumRowNumber());
- setVerticalValue(editField.getEditingRowNumber());
+ setVerticalValue(editField.getVisibleRowNumber());
setRightValue(editField.getMaximumColumnNumber());
setHorizontalValue(editField.getEditingColumnNumber());
} else {
if (mouse.isMouseWheelUp() || mouse.isMouseWheelDown()) {
// Vertical scrollbar actions
- editField.setEditingRowNumber(getVerticalValue());
+ editField.setVisibleRowNumber(getVerticalValue());
}
}
}
if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) {
// Clicked on vertical scrollbar
- editField.setEditingRowNumber(getVerticalValue());
+ editField.setVisibleRowNumber(getVerticalValue());
}
// TODO: horizontal scrolling
if (mouseOnEditor(mouse) && mouse.isMouse1()) {
// The editor might have changed, update the scollbars.
setBottomValue(editField.getMaximumRowNumber());
- setVerticalValue(editField.getEditingRowNumber());
+ setVerticalValue(editField.getVisibleRowNumber());
setRightValue(editField.getMaximumColumnNumber());
setHorizontalValue(editField.getEditingColumnNumber());
} else {
if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) {
// Clicked/dragged on vertical scrollbar
- editField.setEditingRowNumber(getVerticalValue());
+ editField.setVisibleRowNumber(getVerticalValue());
}
// TODO: horizontal scrolling
// The editor might have changed, update the scollbars.
setBottomValue(editField.getMaximumRowNumber());
- setVerticalValue(editField.getEditingRowNumber());
+ setVerticalValue(editField.getVisibleRowNumber());
setRightValue(editField.getMaximumColumnNumber());
setHorizontalValue(editField.getEditingColumnNumber());
}
&& (mouse.getY() < getHeight() - 1)) {
if (getVerticalValue() + mouse.getY() < strings.size()) {
selectedString = getVerticalValue() + mouse.getY();
- dispatchEnter();
}
return;
}
super.onMouseDown(mouse);
}
+ /**
+ * Handle mouse double click.
+ *
+ * @param mouse mouse double click event
+ */
+ @Override
+ public void onMouseDoubleClick(final TMouseEvent mouse) {
+ if ((mouse.getX() < getWidth() - 1)
+ && (mouse.getY() < getHeight() - 1)) {
+ if (getVerticalValue() + mouse.getY() < strings.size()) {
+ selectedString = getVerticalValue() + mouse.getY();
+ dispatchEnter();
+ }
+ return;
+ }
+
+ // Pass to children
+ super.onMouseDoubleClick(mouse);
+ }
+
/**
* Handle keystrokes.
*
}
}
+ /**
+ * Method that subclasses can override to handle mouse button
+ * double-clicks.
+ *
+ * @param mouse mouse button event
+ */
+ public void onMouseDoubleClick(final TMouseEvent mouse) {
+ // Default: do nothing, pass to children instead
+ for (int i = children.size() - 1 ; i >= 0 ; i--) {
+ TWidget widget = children.get(i);
+ if (widget.mouseWouldHit(mouse)) {
+ // Dispatch to this child, also activate it
+ activate(widget);
+
+ // Set x and y relative to the child's coordinates
+ mouse.setX(mouse.getAbsoluteX() - widget.getAbsoluteX());
+ mouse.setY(mouse.getAbsoluteY() - widget.getAbsoluteY());
+ widget.handleEvent(mouse);
+ return;
+ }
+ }
+ }
+
/**
* Method that subclasses can override to handle window/screen resize
* events.
onMouseMotion(mouse);
break;
+ case MOUSE_DOUBLE_CLICK:
+ onMouseDoubleClick(mouse);
+ break;
+
default:
throw new IllegalArgumentException("Invalid mouse event type: "
+ mouse.getType());
color.setBold(true);
colors.put("tcheckbox.active", color);
-
// TRadioButton
color = new CellAttributes();
color.setForeColor(Color.WHITE);
color.setBold(false);
colors.put("ttreeview.unreadable", color);
color = new CellAttributes();
- color.setForeColor(Color.BLACK);
+ // color.setForeColor(Color.BLACK);
+ // color.setBackColor(Color.BLUE);
+ // color.setBold(true);
+ color.setForeColor(Color.WHITE);
color.setBackColor(Color.BLUE);
- color.setBold(true);
+ color.setBold(false);
colors.put("ttreeview.inactive", color);
// TList
color.setBold(false);
colors.put("tlist.unreadable", color);
color = new CellAttributes();
- color.setForeColor(Color.BLACK);
+ // color.setForeColor(Color.BLACK);
+ // color.setBackColor(Color.BLUE);
+ // color.setBold(true);
+ color.setForeColor(Color.WHITE);
color.setBackColor(Color.BLUE);
- color.setBold(true);
+ color.setBold(false);
colors.put("tlist.inactive", color);
// TStatusBar
/**
* Mouse button up. X and Y will have screen coordinates.
*/
- MOUSE_UP
+ MOUSE_UP,
+
+ /**
+ * Mouse double-click. X and Y will have screen coordinates.
+ */
+ MOUSE_DOUBLE_CLICK
}
/**