X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjexer%2FTEditorWindow.java;h=5bf664d254e515f95d41418ef383ae01559dcdb4;hb=fe0770f988e64fc0ccafd3d3b086b4a0eb559d3b;hp=69e254b9df70f2b4303edc9a9806b64bacd90eb1;hpb=df602ccf5e32585c26dc618dd3b4a759b6820943;p=nikiroo-utils.git diff --git a/src/jexer/TEditorWindow.java b/src/jexer/TEditorWindow.java index 69e254b..5bf664d 100644 --- a/src/jexer/TEditorWindow.java +++ b/src/jexer/TEditorWindow.java @@ -41,6 +41,7 @@ import jexer.TWidget; import jexer.bits.CellAttributes; import jexer.bits.GraphicsChars; import jexer.event.TCommandEvent; +import jexer.event.TKeypressEvent; import jexer.event.TMouseEvent; import jexer.event.TResizeEvent; import static jexer.TCommand.*; @@ -201,7 +202,7 @@ public class TEditorWindow extends TScrollableWindow { * editor. * * @param mouse a mouse-based event - * @return whether or not the mouse is on the emulator + * @return whether or not the mouse is on the editor */ private final boolean mouseOnEditor(final TMouseEvent mouse) { if ((mouse.getAbsoluteX() >= getAbsoluteX() + 1) @@ -235,8 +236,69 @@ public class TEditorWindow extends TScrollableWindow { // Vertical scrollbar actions editField.setEditingRowNumber(getVerticalValue()); } + } + } + + /** + * Handle mouse release events. + * + * @param mouse mouse button release event + */ + @Override + public void onMouseUp(final TMouseEvent mouse) { + // Use TWidget's code to pass the event to the children. + super.onMouseUp(mouse); + + if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) { + // Clicked on vertical scrollbar + editField.setEditingRowNumber(getVerticalValue()); + } + + // TODO: horizontal scrolling + } + + /** + * Method that subclasses can override to handle mouse movements. + * + * @param mouse mouse motion event + */ + @Override + public void onMouseMotion(final TMouseEvent mouse) { + // Use TWidget's code to pass the event to the children. + super.onMouseMotion(mouse); + + if (mouseOnEditor(mouse) && mouse.isMouse1()) { + // The editor might have changed, update the scollbars. + setBottomValue(editField.getMaximumRowNumber()); + setVerticalValue(editField.getEditingRowNumber()); + setRightValue(editField.getMaximumColumnNumber()); + setHorizontalValue(editField.getEditingColumnNumber()); + } else { + if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) { + // Clicked/dragged on vertical scrollbar + editField.setEditingRowNumber(getVerticalValue()); + } + // TODO: horizontal scrolling } + + } + + /** + * Handle keystrokes. + * + * @param keypress keystroke event + */ + @Override + public void onKeypress(final TKeypressEvent keypress) { + // Use TWidget's code to pass the event to the children. + super.onKeypress(keypress); + + // The editor might have changed, update the scollbars. + setBottomValue(editField.getMaximumRowNumber()); + setVerticalValue(editField.getEditingRowNumber()); + setRightValue(editField.getMaximumColumnNumber()); + setHorizontalValue(editField.getEditingColumnNumber()); } /**