Esempio n. 1
0
 protected boolean onMoveHotPoint(MoveHotPointEvent event) {
   NullCheck.notNull(event, "event");
   final int x = event.getNewHotPointX();
   final int y = event.getNewHotPointY();
   final int newY;
   if (y >= getLineCount()) {
     if (event.precisely()) return false;
     newY = getLineCount() - 1;
   } else newY = y;
   if (getItemIndexOnLine(newY) >= 0) {
     // Line with item, not empty
     final Object item = model.getItem(getItemIndexOnLine(newY));
     final int leftBound = appearance.getObservableLeftBound(item);
     final int rightBound = appearance.getObservableRightBound(item);
     if (event.precisely() && (x < leftBound || x > rightBound)) return false;
     hotPointY = newY;
     hotPointX = x;
     if (hotPointX < leftBound) hotPointX = leftBound;
     if (hotPointX > rightBound) hotPointX = rightBound;
     environment.onAreaNewHotPoint(this);
     return true;
   }
   // On empty line
   hotPointY = newY;
   hotPointX = 0;
   environment.onAreaNewHotPoint(this);
   return true;
 }
Esempio n. 2
0
 private boolean onAltLeft(KeyboardEvent event) {
   if (noContent()) return true;
   final Object item = selected();
   if (item == null) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   if (line.isEmpty()) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   final int leftBound = appearance.getObservableLeftBound(item);
   final int rightBound = appearance.getObservableRightBound(item);
   if (hotPointX <= leftBound) {
     environment.hint(Hints.BEGIN_OF_LINE);
     return true;
   }
   final String subline = line.substring(leftBound, rightBound);
   final WordIterator it = new WordIterator(subline, hotPointX - leftBound);
   if (!it.stepBackward()) {
     environment.hint(Hints.BEGIN_OF_LINE);
     return true;
   }
   hotPointX = it.pos() + leftBound;
   environment.say(it.announce());
   environment.onAreaNewHotPoint(this);
   return true;
 }
Esempio n. 3
0
 protected boolean onChar(KeyboardEvent event) {
   if (noContent()) return true;
   final int count = model.getItemCount();
   final char c = event.getChar();
   final String beginning;
   if (selected() != null) {
     if (hotPointX >= appearance.getObservableRightBound(selected())) return false;
     final String name = getObservableSubstr(selected());
     final int pos =
         Math.min(hotPointX - appearance.getObservableLeftBound(selected()), name.length());
     if (pos < 0) return false;
     beginning = name.substring(0, pos);
   } else beginning = "";
   Log.debug("list", "beginning:" + beginning);
   final String mustBegin = beginning + c;
   for (int i = 0; i < count; ++i) {
     Log.debug("list", "checking:" + i);
     final String name = getObservableSubstr(model.getItem(i));
     Log.debug("list", "name:" + name);
     if (!name.startsWith(mustBegin)) continue;
     hotPointY = getLineIndexByItemIndex(i);
     Log.debug("list", "hotPointY:" + hotPointY);
     ++hotPointX;
     appearance.announceItem(model.getItem(hotPointY), NONE_APPEARANCE_FLAGS);
     environment.onAreaNewHotPoint(this);
     return true;
   }
   return false;
 }
Esempio n. 4
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;
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
 /**
  * Refreshes the content of the list. This method calls {@code refresh()} method of the model and
  * displays new items. It does not produce any speech announcement of the change. HotPointY is
  * preserved if it is possible (meaning, the new number of lines not less than old value of
  * hotPointY), but hotPointX is moved to the beginning of the line.
  */
 public void refresh() {
   model.refresh();
   final int count = model.getItemCount();
   if (count == 0) {
     hotPointX = 0;
     hotPointY = 0;
     environment.onAreaNewContent(this);
     environment.onAreaNewHotPoint(this);
     return;
   }
   hotPointY = hotPointY < count ? hotPointY : count - 1;
   final Object item = model.getItem(hotPointY);
   if (item != null) hotPointX = appearance.getObservableLeftBound(item);
   else hotPointX = 0;
   environment.onAreaNewContent(this);
   environment.onAreaNewHotPoint(this);
 }
Esempio n. 7
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);
 }
Esempio n. 8
0
 public void resetHotPoint(boolean introduce) {
   hotPointY = 0;
   final int count = model.getItemCount();
   if (count < 1) {
     hotPointX = 0;
     environment.onAreaNewHotPoint(this);
     return;
   }
   final Object item = model.getItem(0);
   if (item != null) {
     hotPointX = item != null ? appearance.getObservableLeftBound(item) : 0;
     if (introduce) appearance.announceItem(item, NONE_APPEARANCE_FLAGS);
   } else {
     hotPointX = 0;
     environment.hint(Hints.EMPTY_LINE);
   }
   environment.onAreaNewHotPoint(this);
 }
Esempio n. 9
0
 protected void onNewHotPointY(boolean briefAnnouncement) {
   final int index = selectedIndex();
   if (index < 0) {
     environment.hint(Hints.EMPTY_LINE);
     hotPointX = 0;
     environment.onAreaNewHotPoint(this);
     return;
   }
   final Object item = model.getItem(index);
   if (item == null) {
     environment.hint(Hints.EMPTY_LINE);
     hotPointX = 0;
     environment.onAreaNewHotPoint(this);
     return;
   }
   appearance.announceItem(
       item, briefAnnouncement ? BRIEF_ANNOUNCEMENT_ONLY : NONE_APPEARANCE_FLAGS);
   hotPointX = appearance.getObservableLeftBound(item);
   environment.onAreaNewHotPoint(this);
 }
Esempio n. 10
0
 private boolean onAltHome(KeyboardEvent event) {
   if (noContent()) return true;
   final Object item = selected();
   NullCheck.notNull(item, "item");
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   hotPointX = appearance.getObservableLeftBound(item);
   announceChar(line, hotPointX, appearance.getObservableRightBound(item));
   environment.onAreaNewHotPoint(this);
   return true;
 }
Esempio n. 11
0
 /**
  * Searches for the item in the model and sets hot point on it. Given an arbitrary object, this
  * method looks through all items in the model and does a couple of checks: literal pointers
  * equality and a check with {@code equals()} method. If at least one of these checks succeeds,
  * the item is considered equal to the given one, and hot points is set on it.
  *
  * @param obj The object to search for
  * @param introduce Must be true if it is necessary to introduce the object, once it's found
  * @return True if the request object is found, false otherwise
  */
 public boolean select(Object obj, boolean introduce) {
   NullCheck.notNull(obj, "obj");
   for (int i = 0; i < model.getItemCount(); ++i) {
     final Object o = model.getItem(i);
     if (o == null || (obj != o && !obj.equals(o))) continue;
     hotPointY = i;
     hotPointX = appearance.getObservableLeftBound(o);
     environment.onAreaNewHotPoint(this);
     if (introduce) appearance.announceItem(o, NONE_APPEARANCE_FLAGS);
     return true;
   }
   return false;
 }
Esempio n. 12
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);
 }
Esempio n. 13
0
 private boolean onAltEnd(KeyboardEvent event) {
   if (noContent()) return true;
   final Object item = selected();
   if (item == null) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   hotPointX = appearance.getObservableRightBound(item);
   environment.hint(Hints.END_OF_LINE);
   environment.onAreaNewHotPoint(this);
   return true;
 }
Esempio n. 14
0
 protected boolean onListeningFinishedEvent(ListeningFinishedEvent event) {
   NullCheck.notNull(event, "event");
   if (!(event.getExtraInfo() instanceof ListeningInfo)) return false;
   final ListeningInfo info = (ListeningInfo) event.getExtraInfo();
   final int count = model.getItemCount();
   if (info.itemIndex >= count) return false;
   final Object item = model.getItem(info.itemIndex);
   final int leftBound = appearance.getObservableLeftBound(item);
   final int rightBound = appearance.getObservableRightBound(item);
   if (info.pos < leftBound || info.pos > rightBound) return false;
   hotPointY = getLineIndexByItemIndex(info.itemIndex);
   hotPointX = info.pos;
   environment.onAreaNewHotPoint(this);
   return true;
 }
Esempio n. 15
0
 /**
  * Selects the item by its index. Given the non-negative integer value as an index, this method
  * sets the hot point on the item addressed with this index, checking only that index is in
  * appropriate bounds. Index must address the object as a number in the model, ignoring any empty
  * lines.
  *
  * @param index The item index to select
  * @param announce Must be true, if it is necessary to announce the item , once it has been
  *     selected
  * @return True if the index is valid and the item gets hot point on it
  */
 public boolean select(int index, boolean announce) {
   if (index < 0 || index >= model.getItemCount()) return false;
   final int emptyCountAbove = flags.contains(Flags.EMPTY_LINE_TOP) ? 1 : 0;
   hotPointY = index + emptyCountAbove;
   final Object item = model.getItem(index);
   if (item != null) {
     hotPointX = appearance.getObservableLeftBound(item);
     if (announce) appearance.announceItem(item, NONE_APPEARANCE_FLAGS);
   } else {
     hotPointX = 0;
     if (announce) environment.hint(Hints.EMPTY_LINE);
   }
   environment.onAreaNewHotPoint(this);
   return true;
 }
Esempio n. 16
0
 protected boolean onArrowRight(KeyboardEvent event) {
   if (noContent()) return true;
   final Object item = selected();
   NullCheck.notNull(item, "item");
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   if (line.isEmpty()) {
     environment.hint(Hints.EMPTY_LINE);
     return true;
   }
   final int rightBound = appearance.getObservableRightBound(item);
   if (hotPointX >= rightBound) {
     environment.hint(Hints.END_OF_LINE);
     return true;
   }
   ++hotPointX;
   announceChar(line, hotPointX, rightBound);
   environment.onAreaNewHotPoint(this);
   return true;
 }