#55 restore default attributes on exit
[nikiroo-utils.git] / src / jexer / TTableWindow.java
CommitLineData
1dac6b8d
KL
1/*
2 * Jexer - Java Text User Interface
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (C) 2019 Kevin Lamonte
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 *
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
27 * @version 1
28 */
29package jexer;
30
656c0ddd 31import java.io.File;
759cb83e
KL
32import java.io.IOException;
33import java.text.MessageFormat;
1dac6b8d
KL
34import java.util.ResourceBundle;
35
36import jexer.event.TCommandEvent;
37import jexer.event.TKeypressEvent;
f528c340 38import jexer.event.TMenuEvent;
1dac6b8d
KL
39import jexer.event.TMouseEvent;
40import jexer.event.TResizeEvent;
41import jexer.menu.TMenu;
f528c340 42import jexer.menu.TMenuItem;
1dac6b8d
KL
43import static jexer.TCommand.*;
44import static jexer.TKeypress.*;
45
46/**
47 * TTableWindow is used to display and edit regular two-dimensional tables of
48 * cells.
49 */
50public class TTableWindow extends TScrollableWindow {
51
52 /**
53 * Translated strings.
54 */
55 private static final ResourceBundle i18n = ResourceBundle.getBundle(TTableWindow.class.getName());
56
57 // ------------------------------------------------------------------------
58 // Variables --------------------------------------------------------------
59 // ------------------------------------------------------------------------
60
61 /**
62 * The table widget.
63 */
64 private TTableWidget tableField;
65
66 // ------------------------------------------------------------------------
67 // Constructors -----------------------------------------------------------
68 // ------------------------------------------------------------------------
69
70 /**
71 * Public constructor sets window title.
72 *
73 * @param parent the main application
74 * @param title the window title
75 */
76 public TTableWindow(final TApplication parent, final String title) {
77
78 super(parent, title, 0, 0, parent.getScreen().getWidth() / 2,
79 parent.getScreen().getHeight() / 2 - 2, RESIZABLE | CENTERED);
80
382bc294 81 tableField = addTable(0, 0, getWidth() - 2, getHeight() - 2);
1dac6b8d
KL
82 setupAfterTable();
83 }
84
656c0ddd
KL
85 /**
86 * Public constructor loads a grid from a RFC4180 CSV file.
87 *
88 * @param parent the main application
89 * @param csvFile a File referencing the CSV data
90 * @throws IOException if a java.io operation throws
91 */
92 public TTableWindow(final TApplication parent,
93 final File csvFile) throws IOException {
94
95 super(parent, csvFile.getName(), 0, 0,
96 parent.getScreen().getWidth() / 2,
97 parent.getScreen().getHeight() / 2 - 2,
98 RESIZABLE | CENTERED);
99
100 tableField = addTable(0, 0, getWidth() - 2, getHeight() - 2, 1, 1);
101 setupAfterTable();
102 tableField.loadCsvFile(csvFile);
103 }
104
1dac6b8d
KL
105 // ------------------------------------------------------------------------
106 // Event handlers ---------------------------------------------------------
107 // ------------------------------------------------------------------------
108
109 /**
110 * Called by application.switchWindow() when this window gets the
111 * focus, and also by application.addWindow().
112 */
113 public void onFocus() {
114 // Enable the table menu items.
115 getApplication().enableMenuItem(TMenu.MID_CUT);
2b427404
KL
116 getApplication().enableMenuItem(TMenu.MID_TABLE_RENAME_COLUMN);
117 getApplication().enableMenuItem(TMenu.MID_TABLE_RENAME_ROW);
77961919
KL
118 getApplication().enableMenuItem(TMenu.MID_TABLE_VIEW_ROW_LABELS);
119 getApplication().enableMenuItem(TMenu.MID_TABLE_VIEW_COLUMN_LABELS);
120 getApplication().enableMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW);
121 getApplication().enableMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN);
1dac6b8d
KL
122 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_NONE);
123 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_ALL);
e9bb3c1e
KL
124 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_CELL_NONE);
125 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_CELL_ALL);
1dac6b8d
KL
126 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_RIGHT);
127 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_LEFT);
128 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_TOP);
129 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_BOTTOM);
130 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_DOUBLE_BOTTOM);
131 getApplication().enableMenuItem(TMenu.MID_TABLE_BORDER_THICK_BOTTOM);
132 getApplication().enableMenuItem(TMenu.MID_TABLE_DELETE_LEFT);
133 getApplication().enableMenuItem(TMenu.MID_TABLE_DELETE_UP);
134 getApplication().enableMenuItem(TMenu.MID_TABLE_DELETE_ROW);
135 getApplication().enableMenuItem(TMenu.MID_TABLE_DELETE_COLUMN);
136 getApplication().enableMenuItem(TMenu.MID_TABLE_INSERT_LEFT);
137 getApplication().enableMenuItem(TMenu.MID_TABLE_INSERT_RIGHT);
138 getApplication().enableMenuItem(TMenu.MID_TABLE_INSERT_ABOVE);
139 getApplication().enableMenuItem(TMenu.MID_TABLE_INSERT_BELOW);
140 getApplication().enableMenuItem(TMenu.MID_TABLE_COLUMN_NARROW);
141 getApplication().enableMenuItem(TMenu.MID_TABLE_COLUMN_WIDEN);
f528c340 142 getApplication().enableMenuItem(TMenu.MID_TABLE_FILE_OPEN_CSV);
1dac6b8d
KL
143 getApplication().enableMenuItem(TMenu.MID_TABLE_FILE_SAVE_CSV);
144 getApplication().enableMenuItem(TMenu.MID_TABLE_FILE_SAVE_TEXT);
f528c340
KL
145
146 if (tableField != null) {
147
148 // Set the menu to match the flags.
149 TMenuItem menuItem = getApplication().getMenuItem(TMenu.MID_TABLE_VIEW_ROW_LABELS);
150 if (menuItem != null) {
151 menuItem.setChecked(tableField.getShowRowLabels());
152 }
153 menuItem = getApplication().getMenuItem(TMenu.MID_TABLE_VIEW_COLUMN_LABELS);
154 if (menuItem != null) {
155 menuItem.setChecked(tableField.getShowColumnLabels());
156 }
157 menuItem = getApplication().getMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW);
158 if (menuItem != null) {
159 menuItem.setChecked(tableField.getHighlightRow());
160 }
161 menuItem = getApplication().getMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN);
162 if (menuItem != null) {
163 menuItem.setChecked(tableField.getHighlightColumn());
164 }
165 }
1dac6b8d
KL
166 }
167
168 /**
169 * Called by application.switchWindow() when another window gets the
170 * focus.
171 */
172 public void onUnfocus() {
173 // Disable the table menu items.
174 getApplication().disableMenuItem(TMenu.MID_CUT);
2b427404
KL
175 getApplication().disableMenuItem(TMenu.MID_TABLE_RENAME_COLUMN);
176 getApplication().disableMenuItem(TMenu.MID_TABLE_RENAME_ROW);
77961919
KL
177 getApplication().disableMenuItem(TMenu.MID_TABLE_VIEW_ROW_LABELS);
178 getApplication().disableMenuItem(TMenu.MID_TABLE_VIEW_COLUMN_LABELS);
179 getApplication().disableMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW);
180 getApplication().disableMenuItem(TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN);
1dac6b8d
KL
181 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_NONE);
182 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_ALL);
e9bb3c1e
KL
183 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_CELL_NONE);
184 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_CELL_ALL);
1dac6b8d
KL
185 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_RIGHT);
186 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_LEFT);
187 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_TOP);
188 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_BOTTOM);
189 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_DOUBLE_BOTTOM);
190 getApplication().disableMenuItem(TMenu.MID_TABLE_BORDER_THICK_BOTTOM);
191 getApplication().disableMenuItem(TMenu.MID_TABLE_DELETE_LEFT);
192 getApplication().disableMenuItem(TMenu.MID_TABLE_DELETE_UP);
193 getApplication().disableMenuItem(TMenu.MID_TABLE_DELETE_ROW);
194 getApplication().disableMenuItem(TMenu.MID_TABLE_DELETE_COLUMN);
195 getApplication().disableMenuItem(TMenu.MID_TABLE_INSERT_LEFT);
196 getApplication().disableMenuItem(TMenu.MID_TABLE_INSERT_RIGHT);
197 getApplication().disableMenuItem(TMenu.MID_TABLE_INSERT_ABOVE);
198 getApplication().disableMenuItem(TMenu.MID_TABLE_INSERT_BELOW);
199 getApplication().disableMenuItem(TMenu.MID_TABLE_COLUMN_NARROW);
200 getApplication().disableMenuItem(TMenu.MID_TABLE_COLUMN_WIDEN);
f528c340 201 getApplication().disableMenuItem(TMenu.MID_TABLE_FILE_OPEN_CSV);
1dac6b8d
KL
202 getApplication().disableMenuItem(TMenu.MID_TABLE_FILE_SAVE_CSV);
203 getApplication().disableMenuItem(TMenu.MID_TABLE_FILE_SAVE_TEXT);
204 }
205
206 // ------------------------------------------------------------------------
207 // TWindow ----------------------------------------------------------------
208 // ------------------------------------------------------------------------
209
1dac6b8d
KL
210 /**
211 * Handle mouse press events.
212 *
213 * @param mouse mouse button press event
214 */
215 @Override
216 public void onMouseDown(final TMouseEvent mouse) {
217 // Use TWidget's code to pass the event to the children.
218 super.onMouseDown(mouse);
219
220 if (mouseOnTable(mouse)) {
221 // The table might have changed, update the scollbars.
759cb83e
KL
222 setBottomValue(tableField.getRowCount() - 1);
223 setVerticalValue(tableField.getSelectedRowNumber());
224 setRightValue(tableField.getColumnCount() - 1);
225 setHorizontalValue(tableField.getSelectedColumnNumber());
1dac6b8d
KL
226 }
227 }
228
229 /**
230 * Handle mouse release events.
231 *
232 * @param mouse mouse button release event
233 */
234 @Override
235 public void onMouseUp(final TMouseEvent mouse) {
236 // Use TWidget's code to pass the event to the children.
237 super.onMouseUp(mouse);
238
239 if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) {
759cb83e
KL
240 // Clicked/dragged on vertical scrollbar.
241 tableField.setSelectedRowNumber(getVerticalValue());
242 }
243 if (mouse.isMouse1() && mouseOnHorizontalScroller(mouse)) {
244 // Clicked/dragged on horizontal scrollbar.
245 tableField.setSelectedColumnNumber(getHorizontalValue());
1dac6b8d 246 }
1dac6b8d
KL
247 }
248
249 /**
250 * Method that subclasses can override to handle mouse movements.
251 *
252 * @param mouse mouse motion event
253 */
254 @Override
255 public void onMouseMotion(final TMouseEvent mouse) {
256 // Use TWidget's code to pass the event to the children.
257 super.onMouseMotion(mouse);
258
259 if (mouseOnTable(mouse) && mouse.isMouse1()) {
759cb83e
KL
260 // The table might have changed, update the scollbars.
261 setBottomValue(tableField.getRowCount() - 1);
262 setVerticalValue(tableField.getSelectedRowNumber());
263 setRightValue(tableField.getColumnCount() - 1);
264 setHorizontalValue(tableField.getSelectedColumnNumber());
1dac6b8d
KL
265 } else {
266 if (mouse.isMouse1() && mouseOnVerticalScroller(mouse)) {
759cb83e
KL
267 // Clicked/dragged on vertical scrollbar.
268 tableField.setSelectedRowNumber(getVerticalValue());
269 }
270 if (mouse.isMouse1() && mouseOnHorizontalScroller(mouse)) {
271 // Clicked/dragged on horizontal scrollbar.
272 tableField.setSelectedColumnNumber(getHorizontalValue());
1dac6b8d 273 }
1dac6b8d
KL
274 }
275
276 }
277
278 /**
279 * Handle keystrokes.
280 *
281 * @param keypress keystroke event
282 */
283 @Override
284 public void onKeypress(final TKeypressEvent keypress) {
285 // Use TWidget's code to pass the event to the children.
286 super.onKeypress(keypress);
287
759cb83e
KL
288 // The table might have changed, update the scollbars.
289 setBottomValue(tableField.getRowCount() - 1);
290 setVerticalValue(tableField.getSelectedRowNumber());
291 setRightValue(tableField.getColumnCount() - 1);
292 setHorizontalValue(tableField.getSelectedColumnNumber());
1dac6b8d
KL
293 }
294
295 /**
296 * Handle window/screen resize events.
297 *
298 * @param event resize event
299 */
300 @Override
301 public void onResize(final TResizeEvent event) {
302 if (event.getType() == TResizeEvent.Type.WIDGET) {
303 // Resize the table
304 TResizeEvent tableSize = new TResizeEvent(TResizeEvent.Type.WIDGET,
305 event.getWidth() - 2, event.getHeight() - 2);
306 tableField.onResize(tableSize);
307
308 // Have TScrollableWindow handle the scrollbars
309 super.onResize(event);
310 return;
311 }
312
313 // Pass to children instead
314 for (TWidget widget: getChildren()) {
315 widget.onResize(event);
316 }
317 }
318
759cb83e
KL
319 /**
320 * Method that subclasses can override to handle posted command events.
321 *
322 * @param command command event
323 */
324 @Override
325 public void onCommand(final TCommandEvent command) {
326 if (command.equals(cmOpen)) {
327 try {
328 String filename = fileOpenBox(".");
329 if (filename != null) {
330 try {
656c0ddd 331 new TTableWindow(getApplication(), new File(filename));
759cb83e
KL
332 } catch (IOException e) {
333 messageBox(i18n.getString("errorDialogTitle"),
334 MessageFormat.format(i18n.
335 getString("errorReadingFile"), e.getMessage()));
336 }
337 }
338 } catch (IOException e) {
339 messageBox(i18n.getString("errorDialogTitle"),
340 MessageFormat.format(i18n.
341 getString("errorOpeningFileDialog"), e.getMessage()));
342 }
343 return;
344 }
345
3b14a310
KL
346 if (command.equals(cmSave)) {
347 try {
348 String filename = fileSaveBox(".");
349 if (filename != null) {
350 tableField.saveToCsvFilename(filename);
351 }
352 } catch (IOException e) {
353 messageBox(i18n.getString("errorDialogTitle"),
354 MessageFormat.format(i18n.
355 getString("errorWritingFile"), e.getMessage()));
356 }
357 return;
358 }
359
f528c340
KL
360 // Didn't handle it, let children get it instead
361 super.onCommand(command);
362 }
363
364 /**
365 * Handle posted menu events.
366 *
367 * @param menu menu event
368 */
369 @Override
370 public void onMenu(final TMenuEvent menu) {
656c0ddd
KL
371 TInputBox inputBox = null;
372 String filename = null;
f528c340
KL
373
374 switch (menu.getId()) {
375 case TMenu.MID_TABLE_RENAME_COLUMN:
376 inputBox = inputBox(i18n.getString("renameColumnInputTitle"),
377 i18n.getString("renameColumnInputCaption"),
378 tableField.getColumnLabel(tableField.getSelectedColumnNumber()),
379 TMessageBox.Type.OKCANCEL);
380 if (inputBox.isOk()) {
381 tableField.setColumnLabel(tableField.getSelectedColumnNumber(),
382 inputBox.getText());
759cb83e
KL
383 }
384 return;
f528c340
KL
385 case TMenu.MID_TABLE_RENAME_ROW:
386 inputBox = inputBox(i18n.getString("renameRowInputTitle"),
387 i18n.getString("renameRowInputCaption"),
388 tableField.getRowLabel(tableField.getSelectedRowNumber()),
389 TMessageBox.Type.OKCANCEL);
390 if (inputBox.isOk()) {
391 tableField.setRowLabel(tableField.getSelectedRowNumber(),
392 inputBox.getText());
393 }
394 return;
395 case TMenu.MID_TABLE_VIEW_ROW_LABELS:
396 tableField.setShowRowLabels(getApplication().getMenuItem(
397 menu.getId()).getChecked());
398 return;
399 case TMenu.MID_TABLE_VIEW_COLUMN_LABELS:
400 tableField.setShowColumnLabels(getApplication().getMenuItem(
401 menu.getId()).getChecked());
402 return;
403 case TMenu.MID_TABLE_VIEW_HIGHLIGHT_ROW:
404 tableField.setHighlightRow(getApplication().getMenuItem(
405 menu.getId()).getChecked());
406 return;
407 case TMenu.MID_TABLE_VIEW_HIGHLIGHT_COLUMN:
408 tableField.setHighlightColumn(getApplication().getMenuItem(
409 menu.getId()).getChecked());
410 return;
411 case TMenu.MID_TABLE_BORDER_NONE:
412 tableField.setBorderAllNone();
413 return;
414 case TMenu.MID_TABLE_BORDER_ALL:
415 tableField.setBorderAllSingle();
416 return;
417 case TMenu.MID_TABLE_BORDER_CELL_NONE:
418 tableField.setBorderCellNone();
419 return;
420 case TMenu.MID_TABLE_BORDER_CELL_ALL:
421 tableField.setBorderCellSingle();
422 return;
423 case TMenu.MID_TABLE_BORDER_RIGHT:
424 tableField.setBorderColumnRightSingle();
425 return;
426 case TMenu.MID_TABLE_BORDER_LEFT:
427 tableField.setBorderColumnLeftSingle();
428 return;
429 case TMenu.MID_TABLE_BORDER_TOP:
430 tableField.setBorderRowAboveSingle();
431 return;
432 case TMenu.MID_TABLE_BORDER_BOTTOM:
433 tableField.setBorderRowBelowSingle();
434 return;
435 case TMenu.MID_TABLE_BORDER_DOUBLE_BOTTOM:
436 tableField.setBorderRowBelowDouble();
437 return;
438 case TMenu.MID_TABLE_BORDER_THICK_BOTTOM:
439 tableField.setBorderRowBelowThick();
440 return;
441 case TMenu.MID_TABLE_DELETE_LEFT:
442 tableField.deleteCellShiftLeft();
443 return;
444 case TMenu.MID_TABLE_DELETE_UP:
445 tableField.deleteCellShiftUp();
446 return;
447 case TMenu.MID_TABLE_DELETE_ROW:
448 tableField.deleteRow(tableField.getSelectedRowNumber());
449 return;
450 case TMenu.MID_TABLE_DELETE_COLUMN:
451 tableField.deleteColumn(tableField.getSelectedColumnNumber());
452 return;
453 case TMenu.MID_TABLE_INSERT_LEFT:
454 tableField.insertColumnLeft(tableField.getSelectedColumnNumber());
455 return;
456 case TMenu.MID_TABLE_INSERT_RIGHT:
457 tableField.insertColumnRight(tableField.getSelectedColumnNumber());
458 return;
459 case TMenu.MID_TABLE_INSERT_ABOVE:
460 tableField.insertRowAbove(tableField.getSelectedColumnNumber());
461 return;
462 case TMenu.MID_TABLE_INSERT_BELOW:
463 tableField.insertRowBelow(tableField.getSelectedColumnNumber());
464 return;
465 case TMenu.MID_TABLE_COLUMN_NARROW:
466 tableField.setColumnWidth(tableField.getSelectedColumnNumber(),
467 tableField.getColumnWidth(tableField.getSelectedColumnNumber()) - 1);
468 return;
469 case TMenu.MID_TABLE_COLUMN_WIDEN:
470 tableField.setColumnWidth(tableField.getSelectedColumnNumber(),
471 tableField.getColumnWidth(tableField.getSelectedColumnNumber()) + 1);
472 return;
473 case TMenu.MID_TABLE_FILE_OPEN_CSV:
656c0ddd
KL
474 try {
475 filename = fileOpenBox(".");
476 if (filename != null) {
477 try {
478 new TTableWindow(getApplication(), new File(filename));
479 } catch (IOException e) {
480 messageBox(i18n.getString("errorDialogTitle"),
481 MessageFormat.format(i18n.
482 getString("errorReadingFile"), e.getMessage()));
483 }
484 }
485 } catch (IOException e) {
486 messageBox(i18n.getString("errorDialogTitle"),
487 MessageFormat.format(i18n.
488 getString("errorOpeningFileDialog"), e.getMessage()));
489 }
f528c340
KL
490 return;
491 case TMenu.MID_TABLE_FILE_SAVE_CSV:
656c0ddd
KL
492 try {
493 filename = fileSaveBox(".");
494 if (filename != null) {
495 tableField.saveToCsvFilename(filename);
496 }
497 } catch (IOException e) {
498 messageBox(i18n.getString("errorDialogTitle"),
499 MessageFormat.format(i18n.
500 getString("errorWritingFile"), e.getMessage()));
501 }
f528c340
KL
502 return;
503 case TMenu.MID_TABLE_FILE_SAVE_TEXT:
656c0ddd
KL
504 try {
505 filename = fileSaveBox(".");
506 if (filename != null) {
507 tableField.saveToTextFilename(filename);
508 }
509 } catch (IOException e) {
510 messageBox(i18n.getString("errorDialogTitle"),
511 MessageFormat.format(i18n.
512 getString("errorWritingFile"), e.getMessage()));
513 }
f528c340
KL
514 return;
515 default:
516 break;
759cb83e
KL
517 }
518
f528c340 519 super.onMenu(menu);
759cb83e
KL
520 }
521
1dac6b8d
KL
522 // ------------------------------------------------------------------------
523 // TTableWindow -----------------------------------------------------------
524 // ------------------------------------------------------------------------
525
526 /**
527 * Setup other fields after the table is created.
528 */
529 private void setupAfterTable() {
530 hScroller = new THScroller(this, 17, getHeight() - 2, getWidth() - 20);
531 vScroller = new TVScroller(this, getWidth() - 2, 0, getHeight() - 2);
532 setMinimumWindowWidth(25);
533 setMinimumWindowHeight(10);
759cb83e
KL
534 setTopValue(tableField.getSelectedRowNumber());
535 setBottomValue(tableField.getRowCount() - 1);
536 setLeftValue(tableField.getSelectedColumnNumber());
537 setRightValue(tableField.getColumnCount() - 1);
1dac6b8d
KL
538
539 statusBar = newStatusBar(i18n.getString("statusBar"));
540 statusBar.addShortcutKeypress(kbF1, cmHelp,
541 i18n.getString("statusBarHelp"));
759cb83e 542
1dac6b8d
KL
543 statusBar.addShortcutKeypress(kbF2, cmSave,
544 i18n.getString("statusBarSave"));
545 statusBar.addShortcutKeypress(kbF3, cmOpen,
546 i18n.getString("statusBarOpen"));
1dac6b8d
KL
547 statusBar.addShortcutKeypress(kbF10, cmMenu,
548 i18n.getString("statusBarMenu"));
f528c340
KL
549
550 // Synchronize the menu with tableField's flags.
551 onFocus();
1dac6b8d
KL
552 }
553
554 /**
555 * Check if a mouse press/release/motion event coordinate is over the
556 * table.
557 *
558 * @param mouse a mouse-based event
559 * @return whether or not the mouse is on the table
560 */
561 private boolean mouseOnTable(final TMouseEvent mouse) {
562 if ((mouse.getAbsoluteX() >= getAbsoluteX() + 1)
563 && (mouse.getAbsoluteX() < getAbsoluteX() + getWidth() - 1)
564 && (mouse.getAbsoluteY() >= getAbsoluteY() + 1)
565 && (mouse.getAbsoluteY() < getAbsoluteY() + getHeight() - 1)
566 ) {
567 return true;
568 }
569 return false;
570 }
571
572}