import jexer.bits.CellAttributes;
import jexer.bits.ColorTheme;
-import jexer.bits.GraphicsChars;
import jexer.event.TCommandEvent;
import jexer.event.TInputEvent;
import jexer.event.TKeypressEvent;
return result;
}
+ /**
+ * If true, focus follows mouse: windows automatically raised if the
+ * mouse passes over them.
+ */
+ private boolean focusFollowsMouse = false;
+
+ /**
+ * Get focusFollowsMouse flag.
+ *
+ * @return true if focus follows mouse: windows automatically raised if
+ * the mouse passes over them
+ */
+ public boolean getFocusFollowsMouse() {
+ return focusFollowsMouse;
+ }
+
+ /**
+ * Set focusFollowsMouse flag.
+ *
+ * @param focusFollowsMouse if true, focus follows mouse: windows
+ * automatically raised if the mouse passes over them
+ */
+ public void setFocusFollowsMouse(final boolean focusFollowsMouse) {
+ this.focusFollowsMouse = focusFollowsMouse;
+ }
+
// ------------------------------------------------------------------------
// General behavior -------------------------------------------------------
// ------------------------------------------------------------------------
switch (backendType) {
case SWING:
+ // The default SwingBackend is 80x25, 20 pt font. If you want to
+ // change that, you can pass the extra arguments to the
+ // SwingBackend constructor here. For example, if you wanted
+ // 90x30, 16 pt font:
+ //
+ // backend = new SwingBackend(this, 90, 30, 16);
backend = new SwingBackend(this);
break;
case XTERM:
}
/**
- * Return the number of windows that are visible.
+ * Return the number of windows that are showing.
*
- * @return the number of windows that are visible
+ * @return the number of windows that are showing on screen
*/
public final int shownWindowCount() {
int n = 0;
return n;
}
+ /**
+ * Return the number of windows that are hidden.
+ *
+ * @return the number of windows that are hidden
+ */
+ public final int hiddenWindowCount() {
+ int n = 0;
+ for (TWindow w: windows) {
+ if (w.isHidden()) {
+ n++;
+ }
+ }
+ return n;
+ }
+
/**
* Check if a window instance is in this application's window list.
*
}
for (TWindow w: windows) {
if (w == window) {
+ assert (window.getApplication() == this);
return true;
}
}
* otherwise switch to the previous window in the list
*/
public final void switchWindow(final boolean forward) {
- // Only switch if there are multiple windows
- if (windows.size() < 2) {
+ // Only switch if there are multiple visible windows
+ if (shownWindowCount() < 2) {
return;
}
assert (activeWindow != null);
return;
}
- int nextWindowI;
- if (forward) {
- nextWindowI = (activeWindowI + 1) % windows.size();
- } else {
- if (activeWindowI == 0) {
- nextWindowI = windows.size() - 1;
+ int nextWindowI = activeWindowI;
+ for (;;) {
+ if (forward) {
+ nextWindowI++;
+ nextWindowI %= windows.size();
} else {
- nextWindowI = activeWindowI - 1;
+ nextWindowI--;
+ if (nextWindowI < 0) {
+ nextWindowI = windows.size() - 1;
+ }
}
- }
- activateWindow(windows.get(nextWindowI));
+ if (windows.get(nextWindowI).isShown()) {
+ activateWindow(windows.get(nextWindowI));
+ break;
+ }
+ }
} // synchronized (windows)
}
continue;
}
for (int x = w.getX(); x < w.getX() + w.getWidth(); x++) {
- if (x == width) {
+ if (x >= width) {
continue;
}
for (int y = w.getY(); y < w.getY() + w.getHeight(); y++) {
- if (y == height) {
+ if (y >= height) {
continue;
}
overlapMatrix[x][y]++;
long newOverlapN = 0;
// Start by adding each new cell.
for (int wx = x; wx < x + window.getWidth(); wx++) {
- if (wx == width) {
+ if (wx >= width) {
continue;
}
for (int wy = y; wy < y + window.getHeight(); wy++) {
- if (wy == height) {
+ if (wy >= height) {
continue;
}
newMatrix[wx][wy]++;
return;
}
- // Only switch if there are multiple windows
- if (windows.size() < 2) {
+ // If a menu is still active, don't switch windows
+ if (activeMenu != null) {
return;
}
- // Switch on the upclick
- if (mouse.getType() != TMouseEvent.Type.MOUSE_UP) {
+ // Only switch if there are multiple windows
+ if (windows.size() < 2) {
return;
}
- synchronized (windows) {
- Collections.sort(windows);
- if (windows.get(0).isModal()) {
- // Modal windows don't switch
- return;
- }
+ if (((focusFollowsMouse == true)
+ && (mouse.getType() == TMouseEvent.Type.MOUSE_MOTION))
+ || (mouse.getType() == TMouseEvent.Type.MOUSE_UP)
+ ) {
+ synchronized (windows) {
+ Collections.sort(windows);
+ if (windows.get(0).isModal()) {
+ // Modal windows don't switch
+ return;
+ }
- for (TWindow window: windows) {
- assert (!window.isModal());
+ for (TWindow window: windows) {
+ assert (!window.isModal());
- if (window.isHidden()) {
- assert (!window.isActive());
- continue;
- }
+ if (window.isHidden()) {
+ assert (!window.isActive());
+ continue;
+ }
- if (window.mouseWouldHit(mouse)) {
- if (window == windows.get(0)) {
- // Clicked on the same window, nothing to do
- assert (window.isActive());
+ if (window.mouseWouldHit(mouse)) {
+ if (window == windows.get(0)) {
+ // Clicked on the same window, nothing to do
+ assert (window.isActive());
+ return;
+ }
+
+ // We will be switching to another window
+ assert (windows.get(0).isActive());
+ assert (windows.get(0) == activeWindow);
+ assert (!window.isActive());
+ activeWindow.onUnfocus();
+ activeWindow.setActive(false);
+ activeWindow.setZ(window.getZ());
+ activeWindow = window;
+ window.setZ(0);
+ window.setActive(true);
+ window.onFocus();
return;
}
-
- // We will be switching to another window
- assert (windows.get(0).isActive());
- assert (windows.get(0) == activeWindow);
- assert (!window.isActive());
- activeWindow.onUnfocus();
- activeWindow.setActive(false);
- activeWindow.setZ(window.getZ());
- activeWindow = window;
- window.setZ(0);
- window.setActive(true);
- window.onFocus();
- return;
}
}
+
+ // Clicked on the background, nothing to do
+ return;
}
- // Clicked on the background, nothing to do
+ // Nothing to do: this isn't a mouse up, or focus isn't following
+ // mouse.
return;
}
/**
* Convenience function to create a new window and make it active.
*
- * @param application TApplication that manages this window
* @param title window title, will be centered along the top border
* @param x column relative to parent
* @param y row relative to parent