From 2b9c27db318b916730aa04f2b41bd3bff795a5dc Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Sat, 14 Mar 2015 13:40:52 -0400 Subject: [PATCH] misc cleanup --- src/jexer/THScroller.java | 2 +- src/jexer/TVScroller.java | 2 +- src/jexer/TWidget.java | 17 ++++++++++++----- src/jexer/TWindow.java | 13 +------------ src/jexer/backend/ECMA48Backend.java | 6 +++--- src/jexer/bits/Cell.java | 18 +++++++++--------- src/jexer/io/ECMA48Screen.java | 5 +++-- src/jexer/io/ECMA48Terminal.java | 6 +++--- src/jexer/menu/TMenuSeparator.java | 2 +- src/jexer/menu/TSubMenu.java | 12 ++++++------ 10 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/jexer/THScroller.java b/src/jexer/THScroller.java index b705fe2..62f6075 100644 --- a/src/jexer/THScroller.java +++ b/src/jexer/THScroller.java @@ -33,6 +33,6 @@ package jexer; /** * THScroller implements a simple horizontal scroll bar. */ -public class THScroller extends TWidget { +public final class THScroller extends TWidget { } diff --git a/src/jexer/TVScroller.java b/src/jexer/TVScroller.java index 50a08a1..a0a5915 100644 --- a/src/jexer/TVScroller.java +++ b/src/jexer/TVScroller.java @@ -33,6 +33,6 @@ package jexer; /** * TVScroller implements a simple vertical scroll bar. */ -public class TVScroller extends TWidget { +public final class TVScroller extends TWidget { } diff --git a/src/jexer/TWidget.java b/src/jexer/TWidget.java index 17f7849..2ca7108 100644 --- a/src/jexer/TWidget.java +++ b/src/jexer/TWidget.java @@ -48,7 +48,7 @@ import static jexer.TKeypress.*; * TWidget is the base class of all objects that can be drawn on screen or * handle user input events. */ -public abstract class TWidget { +public abstract class TWidget implements Comparable { /** * Every widget has a parent widget that it may be "contained" in. For @@ -332,12 +332,19 @@ public abstract class TWidget { private int cursorY = 0; /** - * Comparison operator sorts on tabOrder. + * Comparison operator sorts on tabOrder for TWidgets and z for TWindows. * - * @param that another TWidget instance - * @return difference between this.tabOrder and that.tabOrder + * @param that another TWidget or TWindow instance + * @return difference between this.tabOrder and that.tabOrder, or + * difference between this.z and that.z */ - public final int compare(final TWidget that) { + @Override + public final int compareTo(final TWidget that) { + if ((this instanceof TWindow) + && (that instanceof TWindow) + ) { + return (((TWindow) this).getZ() - ((TWindow) that).getZ()); + } return (this.tabOrder - that.tabOrder); } diff --git a/src/jexer/TWindow.java b/src/jexer/TWindow.java index d57b844..e15092e 100644 --- a/src/jexer/TWindow.java +++ b/src/jexer/TWindow.java @@ -46,7 +46,7 @@ import static jexer.TKeypress.*; /** * TWindow is the top-level container and drawing surface for other widgets. */ -public class TWindow extends TWidget implements Comparable { +public class TWindow extends TWidget { /** * Window's parent TApplication. @@ -305,17 +305,6 @@ public class TWindow extends TWidget implements Comparable { return true; } - /** - * Comparison operator sorts on z. - * - * @param that another TWindow instance - * @return difference between this.z and that.z - */ - @Override - public final int compareTo(final TWindow that) { - return (this.z - that.z); - } - /** * Returns true if the mouse is currently on the close button. * diff --git a/src/jexer/backend/ECMA48Backend.java b/src/jexer/backend/ECMA48Backend.java index a6ae361..99c0200 100644 --- a/src/jexer/backend/ECMA48Backend.java +++ b/src/jexer/backend/ECMA48Backend.java @@ -43,7 +43,7 @@ import jexer.io.ECMA48Terminal; * This class uses an xterm/ANSI X3.64/ECMA-48 type terminal to provide a * screen, keyboard, and mouse to TApplication. */ -public class ECMA48Backend extends Backend { +public final class ECMA48Backend extends Backend { /** * Input events are processed by this Terminal. @@ -84,7 +84,7 @@ public class ECMA48Backend extends Backend { * Sync the logical screen to the physical device. */ @Override - public final void flushScreen() { + public void flushScreen() { screen.flushPhysical(); } @@ -130,7 +130,7 @@ public class ECMA48Backend extends Backend { * Close the I/O, restore the console, etc. */ @Override - public final void shutdown() { + public void shutdown() { terminal.shutdown(); } diff --git a/src/jexer/bits/Cell.java b/src/jexer/bits/Cell.java index f110d33..3c0eb14 100644 --- a/src/jexer/bits/Cell.java +++ b/src/jexer/bits/Cell.java @@ -33,7 +33,7 @@ package jexer.bits; /** * This class represents a single text cell on the screen. */ -public class Cell extends CellAttributes { +public final class Cell extends CellAttributes { /** * The character at this cell. @@ -45,7 +45,7 @@ public class Cell extends CellAttributes { * * @return cell character */ - public final char getChar() { + public char getChar() { return ch; } @@ -54,7 +54,7 @@ public class Cell extends CellAttributes { * * @param ch new cell character */ - public final void setChar(final char ch) { + public void setChar(final char ch) { this.ch = ch; } @@ -62,7 +62,7 @@ public class Cell extends CellAttributes { * Reset this cell to a blank. */ @Override - public final void reset() { + public void reset() { super.reset(); ch = ' '; } @@ -74,7 +74,7 @@ public class Cell extends CellAttributes { * * @return true if this cell has default attributes. */ - public final boolean isBlank() { + public boolean isBlank() { if ((getForeColor().equals(Color.WHITE)) && (getBackColor().equals(Color.BLACK)) && !getBold() @@ -97,7 +97,7 @@ public class Cell extends CellAttributes { * @return true if all fields are equal */ @Override - public final boolean equals(final Object rhs) { + public boolean equals(final Object rhs) { if (!(rhs instanceof Cell)) { return false; } @@ -113,7 +113,7 @@ public class Cell extends CellAttributes { * @param rhs an instance of either Cell or CellAttributes */ @Override - public final void setTo(final Object rhs) { + public void setTo(final Object rhs) { // Let this throw a ClassCastException CellAttributes thatAttr = (CellAttributes) rhs; super.setTo(thatAttr); @@ -129,7 +129,7 @@ public class Cell extends CellAttributes { * * @param that a CellAttributes instance */ - public final void setAttr(final CellAttributes that) { + public void setAttr(final CellAttributes that) { super.setTo(that); } @@ -161,7 +161,7 @@ public class Cell extends CellAttributes { * @return displayable String */ @Override - public final String toString() { + public String toString() { return String.format("fore: %d back: %d bold: %s blink: %s ch %c", getForeColor(), getBackColor(), getBold(), getBlink(), ch); } diff --git a/src/jexer/io/ECMA48Screen.java b/src/jexer/io/ECMA48Screen.java index 659d132..57fa88f 100644 --- a/src/jexer/io/ECMA48Screen.java +++ b/src/jexer/io/ECMA48Screen.java @@ -34,9 +34,10 @@ import jexer.bits.Cell; import jexer.bits.CellAttributes; /** - * This Screen class draws to an xterm/ANSI X3.64/ECMA-48 type terminal. + * This Screen implementation draws to an xterm/ANSI X3.64/ECMA-48 type + * terminal. */ -public class ECMA48Screen extends Screen { +public final class ECMA48Screen extends Screen { /** * Emit debugging to stderr. diff --git a/src/jexer/io/ECMA48Terminal.java b/src/jexer/io/ECMA48Terminal.java index 687d7a2..f6bc0b3 100644 --- a/src/jexer/io/ECMA48Terminal.java +++ b/src/jexer/io/ECMA48Terminal.java @@ -61,7 +61,7 @@ import static jexer.TKeypress.*; * This class reads keystrokes and mouse events and emits output to ANSI * X3.64 / ECMA-48 type terminals e.g. xterm, linux, vt100, ansi.sys, etc. */ -public class ECMA48Terminal implements Runnable { +public final class ECMA48Terminal implements Runnable { /** * The session information. @@ -73,7 +73,7 @@ public class ECMA48Terminal implements Runnable { * * @return the SessionInfo */ - public final SessionInfo getSessionInfo() { + public SessionInfo getSessionInfo() { return sessionInfo; } @@ -243,7 +243,7 @@ public class ECMA48Terminal implements Runnable { }; try { Process process; - if (mode == true) { + if (mode) { process = Runtime.getRuntime().exec(cmdRaw); } else { process = Runtime.getRuntime().exec(cmdCooked); diff --git a/src/jexer/menu/TMenuSeparator.java b/src/jexer/menu/TMenuSeparator.java index b9dc979..e945cc7 100644 --- a/src/jexer/menu/TMenuSeparator.java +++ b/src/jexer/menu/TMenuSeparator.java @@ -36,7 +36,7 @@ import jexer.bits.GraphicsChars; /** * TMenuSeparator is a special case menu item. */ -public class TMenuSeparator extends TMenuItem { +public final class TMenuSeparator extends TMenuItem { /** * Package private constructor. diff --git a/src/jexer/menu/TSubMenu.java b/src/jexer/menu/TSubMenu.java index c37bf3a..4720a70 100644 --- a/src/jexer/menu/TSubMenu.java +++ b/src/jexer/menu/TSubMenu.java @@ -40,7 +40,7 @@ import static jexer.TKeypress.*; /** * TSubMenu is a special case menu item that wraps another TMenu. */ -public class TSubMenu extends TMenuItem { +public final class TSubMenu extends TMenuItem { /** * The menu window. Note package private access. @@ -182,7 +182,7 @@ public class TSubMenu extends TMenuItem { * @param key global keyboard accelerator * @return the new menu item */ - public final TMenuItem addItem(final int id, final String label, + public TMenuItem addItem(final int id, final String label, final TKeypress key) { return menu.addItem(id, label, key); @@ -195,7 +195,7 @@ public class TSubMenu extends TMenuItem { * @param label menu item label * @return the new menu item */ - public final TMenuItem addItem(final int id, final String label) { + public TMenuItem addItem(final int id, final String label) { return menu.addItem(id, label); } @@ -206,14 +206,14 @@ public class TSubMenu extends TMenuItem { * (inclusive). * @return the new menu item */ - public final TMenuItem addDefaultItem(final int id) { + public TMenuItem addDefaultItem(final int id) { return menu.addDefaultItem(id); } /** * Convenience function to add a menu separator. */ - public final void addSeparator() { + public void addSeparator() { menu.addSeparator(); } @@ -224,7 +224,7 @@ public class TSubMenu extends TMenuItem { * denoted by prefixing a letter with "&", e.g. "&File" * @return the new sub-menu */ - public final TSubMenu addSubMenu(final String title) { + public TSubMenu addSubMenu(final String title) { return menu.addSubMenu(title); } -- 2.27.0