Example #1
0
 private boolean noProperContent() {
   return model == null
       || model.getRowCount() <= 0
       || model.getColCount() <= 0
       || colWidth == null
       || colWidth.length <= 0;
 }
Example #2
0
 @Override
 public boolean onKeyboardEvent(KeyboardEvent event) {
   if (event == null) throw new NullPointerException("event may not be null");
   if (!event.isSpecial() || event.isModified()) return false;
   switch (event.getSpecial()) {
     case ARROW_DOWN:
       return onArrowDown(event, false);
     case ARROW_UP:
       return onArrowUp(event, false);
     case ARROW_RIGHT:
       return onArrowRight(event);
     case ARROW_LEFT:
       return onArrowLeft(event);
     case ALTERNATIVE_ARROW_DOWN:
       return onArrowDown(event, true);
     case ALTERNATIVE_ARROW_UP:
       return onArrowUp(event, true);
       // FIXME:case KeyboardEvent.ALTERNATIVE_ARROW_RIGHT:
       // FIXME:case KeyboardEvent.ALTERNATIVE_ARROW_LEFT:
     case HOME:
       return onHome(event);
     case END:
       return onEnd(event);
     case ALTERNATIVE_HOME:
       return onLineHome(event);
     case ALTERNATIVE_END:
       return onLineEnd(event);
     case PAGE_DOWN:
       return onPageDown(event, false);
     case PAGE_UP:
       return onPageUp(event, false);
     case ALTERNATIVE_PAGE_DOWN:
       return onPageDown(event, true);
     case ALTERNATIVE_PAGE_UP:
       return onPageUp(event, true);
     case ENTER:
       if (noProperContent()
           || clickHandler == null
           || hotPointY < 0
           || hotPointY >= model.getRowCount()
           || getColUnderPos(hotPointX) < 0) return false;
       return clickHandler.onClick(
           model,
           getColUnderPos(hotPointX),
           hotPointY,
           model.getCell(getColUnderPos(hotPointX), hotPointY));
     default:
       return false;
   }
 }
Example #3
0
 private boolean onEnd(KeyboardEvent event) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   hotPointY = count;
   onNewHotPointY(false);
   return true;
 }
Example #4
0
 private void onNewHotPointY(boolean briefIntroduction) {
   final int count = model.getRowCount();
   hotPointX = hotPointY < count ? initialHotPointX : 0;
   cellShift = 0;
   environment.onAreaNewHotPoint(this);
   if (hotPointY < count)
     appearance.introduceRow(model, hotPointY, briefIntroduction ? INTRODUCTION_BRIEF : 0);
   else environment.hint(Hints.EMPTY_LINE);
 }
Example #5
0
 private boolean onArrowDown(KeyboardEvent event, boolean briefIntroduction) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY >= count) {
     environment.hint(Hints.TABLE_NO_ROWS_BELOW);
     return true;
   }
   ++hotPointY;
   onNewHotPointY(briefIntroduction);
   return true;
 }
Example #6
0
 private boolean onPageDown(KeyboardEvent event, boolean briefIntroduction) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY >= count) {
     environment.hint(Hints.TABLE_NO_ROWS_BELOW);
     return true;
   }
   hotPointY += environment.getAreaVisibleHeight(this);
   if (hotPointY >= count) hotPointY = count;
   onNewHotPointY(briefIntroduction);
   return true;
 }
Example #7
0
 private boolean onArrowUp(KeyboardEvent event, boolean briefIntroduction) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY <= 0) {
     environment.hint(Hints.TABLE_NO_ROWS_ABOVE);
     return true;
   }
   --hotPointY;
   if (hotPointY >= count) hotPointY = count - 1;
   onNewHotPointY(briefIntroduction);
   return true;
 }
Example #8
0
 public void refresh(boolean refreshModel) {
   if (model == null) {
     colWidth = null;
     cellShift = 0;
     hotPointX = 0;
     hotPointY = 0;
     environment.onAreaNewContent(this);
     environment.onAreaNewHotPoint(this);
     return;
   }
   if (refreshModel) model.refresh();
   final int colCount = model.getColCount();
   final int rowCount = model.getRowCount();
   if (colCount <= 0 || rowCount <= 0) {
     colWidth = null;
     cellShift = 0;
     hotPointX = 0;
     hotPointY = 0;
     environment.onAreaNewContent(this);
     environment.onAreaNewHotPoint(this);
     return;
   }
   initialHotPointX = appearance.getInitialHotPointX(model);
   colWidth = new int[colCount];
   int totalWidth = initialHotPointX;
   for (int i = 0; i < colCount; ++i) {
     final int width = appearance.getColWidth(model, i);
     colWidth[i] = width >= 1 ? width : 1;
     totalWidth += (colWidth[i] + 1);
   }
   if (hotPointY > rowCount) hotPointY = rowCount;
   if (hotPointY < rowCount && hotPointX >= totalWidth)
     hotPointX =
         totalWidth - 1; // totalWidth may not be zero as always we have at least one column here;
   if (hotPointY == rowCount) hotPointX = 0;
   environment.onAreaNewContent(this);
   environment.onAreaNewHotPoint(this);
 }
Example #9
0
 @Override
 public String getLine(int index) {
   if (noProperContent())
     return index <= 0 ? environment.staticStr(LangStatic.TABLE_NO_CONTENT) : "";
   if (index < 0 || index >= model.getRowCount()) return "";
   final int currentCol = getColUnderPos(hotPointX);
   String line = getStringOfLen(appearance.getRowPrefix(model, index), initialHotPointX, "", "");
   if (index != hotPointY || currentCol < 0) {
     for (int i = 0; i < model.getColCount(); ++i)
       line += getStringOfLen(appearance.getCellText(model, i, index), colWidth[i], ">", " ");
     return line;
   }
   if (currentCol > 0)
     for (int i = 0; i < currentCol; ++i)
       line += getStringOfLen(appearance.getCellText(model, i, index), colWidth[i], ">", " ");
   String currentColText = appearance.getCellText(model, currentCol, index);
   if (cellShift > 0 && cellShift < currentColText.length())
     currentColText = currentColText.substring(cellShift);
   line += getStringOfLen(currentColText, colWidth[currentCol], ">", " ");
   if (currentCol + 1 < colWidth.length)
     for (int i = currentCol + 1; i < colWidth.length; ++i)
       line += getStringOfLen(appearance.getCellText(model, i, index), colWidth[i], ">", " ");
   return line;
 }
Example #10
0
 private boolean onArrowLeft(KeyboardEvent event) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY < 0 || hotPointY >= count) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   if (hotPointX < initialHotPointX) hotPointX = initialHotPointX;
   if (getColUnderPos(hotPointX) < 0) hotPointX = initialHotPointX;
   final int currentCol = getColUnderPos(hotPointX);
   final int currentColWidth = colWidth[currentCol];
   final int colStartPos = getColStartPos(currentCol);
   final TableCell c =
       new TableCell(
           hotPointX - colStartPos,
           cellShift,
           currentColWidth,
           appearance.getCellText(model, currentCol, hotPointY));
   if (!c.movePrev()) {
     if (currentCol <= 0) {
       environment.hint(Hints.TABLE_BEGIN_OF_ROW);
       return true;
     }
     final String prevColText = appearance.getCellText(model, currentCol - 1, hotPointY);
     final int prevColWidth = colWidth[currentCol - 1];
     final int prevColStartPos = getColStartPos(currentCol - 1);
     if (prevColText.length() > prevColWidth) {
       hotPointX = prevColStartPos + prevColWidth;
       cellShift = prevColText.length() - prevColWidth;
     } else {
       cellShift = 0;
       hotPointX = prevColStartPos + prevColText.length();
     }
     environment.hint(Hints.TABLE_END_OF_COL);
     environment.onAreaNewContent(this);
     environment.onAreaNewHotPoint(this);
     return true;
   }
   cellShift = c.shift;
   hotPointX = c.pos + colStartPos;
   if (c.pos == c.width) // Should never happen;
   environment.hint(Hints.TABLE_END_OF_COL);
   else environment.sayLetter(c.line.charAt(c.pos + c.shift));
   environment.onAreaNewContent(this);
   environment.onAreaNewHotPoint(this);
   return true;
 }
Example #11
0
 private boolean onArrowRight(KeyboardEvent event) {
   if (noContentCheck()) return true;
   final int count = model.getRowCount();
   if (hotPointY < 0 || hotPointY >= count) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   // Checking that hot point not before proper line begin;
   if (hotPointX < initialHotPointX) hotPointX = initialHotPointX;
   if (getColUnderPos(hotPointX) < 0) hotPointX = initialHotPointX;
   final int currentCol = getColUnderPos(hotPointX);
   final int currentColWidth = colWidth[currentCol];
   final int colStartPos = getColStartPos(currentCol);
   final int nextColStartPos = colStartPos + colWidth[currentCol] + 1;
   final TableCell c =
       new TableCell(
           hotPointX - colStartPos,
           cellShift,
           currentColWidth,
           appearance.getCellText(model, currentCol, hotPointY));
   if (!c.moveNext()) {
     if (currentCol + 1 >= colWidth.length) {
       environment.hint(Hints.TABLE_END_OF_ROW);
       return true;
     }
     cellShift = 0;
     hotPointX = nextColStartPos;
     final String nextColText = appearance.getCellText(model, currentCol + 1, hotPointY);
     if (!nextColText.isEmpty()) environment.sayLetter(nextColText.charAt(0));
     else
       environment.hint(
           currentCol + 2 < colWidth.length ? Hints.TABLE_END_OF_COL : Hints.TABLE_END_OF_ROW);
     environment.onAreaNewContent(this);
     environment.onAreaNewHotPoint(this);
     return true;
   }
   cellShift = c.shift;
   hotPointX = c.pos + colStartPos;
   if (c.pos + c.shift >= c.line.length())
     environment.hint(
         currentCol + 1 < colWidth.length ? Hints.TABLE_END_OF_COL : Hints.TABLE_END_OF_ROW);
   else environment.sayLetter(c.line.charAt(c.pos + c.shift));
   environment.onAreaNewContent(this);
   environment.onAreaNewHotPoint(this);
   return true;
 }
Example #12
0
 @Override
 public int getLineCount() {
   if (noProperContent()) return 2;
   return model.getRowCount() + 1;
 }
Example #13
0
 public int getSelectedRowIndex() {
   return hotPointY < model.getRowCount() ? hotPointY : -1;
 }
Example #14
0
 public Object getSelectedRow() {
   final int index = getSelectedRowIndex();
   if (index < 0) return null;
   return model.getRow(index);
 }