Exemplo n.º 1
0
 public ListPopupBase(Luwrain luwrain, ListArea.Params params, Set<Popup.Flags> popupFlags) {
   super(params);
   NullCheck.notNull(luwrain, "luwrain");
   NullCheck.notNull(popupFlags, "popupFlags");
   this.luwrain = luwrain;
   this.popupFlags = popupFlags;
 }
Exemplo n.º 2
0
 protected String getObservableSubstr(Object item) {
   NullCheck.notNull(item, "item");
   final String line = appearance.getScreenAppearance(item, NONE_APPEARANCE_FLAGS);
   NullCheck.notNull(line, "line");
   if (line.isEmpty()) return "";
   final int leftBound = Math.min(appearance.getObservableLeftBound(item), line.length());
   final int rightBound = Math.min(appearance.getObservableRightBound(item), line.length());
   if (leftBound >= rightBound) return "";
   return line.substring(leftBound, rightBound);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 @Override
 public boolean onEnvironmentEvent(EnvironmentEvent event) {
   NullCheck.notNull(event, "event");
   if (event.getType() != EnvironmentEvent.Type.REGULAR) return false;
   switch (event.getCode()) {
     case REFRESH:
       refresh();
       return true;
     case INTRODUCE:
       return onAnnounce();
     case ANNOUNCE_LINE:
       return onAnnounceLine();
     case OK:
       return onOk(event);
     case LISTENING_FINISHED:
       if (event instanceof ListeningFinishedEvent)
         return onListeningFinishedEvent((ListeningFinishedEvent) event);
       return false;
     case MOVE_HOT_POINT:
       if (event instanceof MoveHotPointEvent) return onMoveHotPoint((MoveHotPointEvent) event);
       return false;
     default:
       return region.onEnvironmentEvent(event, hotPointX, hotPointY);
   }
 }
Exemplo n.º 5
0
 protected boolean onBeginListeningQuery(BeginListeningQuery query) {
   NullCheck.notNull(query, "query");
   final int index = selectedIndex();
   if (index < 0) return false;
   final int count = model.getItemCount();
   if (index >= count) return false;
   final Object current = model.getItem(index);
   final String text =
       appearance
           .getScreenAppearance(current, NONE_APPEARANCE_FLAGS)
           .substring(hotPointX, appearance.getObservableRightBound(current));
   //	Log.debug("listen", appearance.getScreenAppearance(current, NONE_APPEARANCE_FLAGS));
   //	Log.debug("listen", "" + hotPointX);
   if (text.isEmpty() && index + 1 >= count) return false;
   if (index + 1 < count) {
     final Object next = model.getItem(index + 1);
     query.answer(
         new BeginListeningQuery.Answer(
             text, new ListeningInfo(index + 1, appearance.getObservableLeftBound(next))));
   } else
     query.answer(
         new BeginListeningQuery.Answer(
             text, new ListeningInfo(index, appearance.getObservableRightBound(current))));
   return true;
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 private KeyboardEvent getKeyboardEventFromRegistry(String path) {
   NullCheck.notNull(path, "path");
   final Settings.HotKey proxy = Settings.createHotKey(registry, path);
   KeyboardEvent.Special special = null;
   char c = ' ';
   final String specialStr = proxy.getSpecial("");
   if (!specialStr.trim().isEmpty()) {
     special = KeyboardEvent.translateSpecial(specialStr);
     if (special == null) {
       Log.error(
           "core",
           "registry path "
               + path
               + " tries to use an unknown special keyboard code \'"
               + specialStr
               + "\'");
       return null;
     }
   } else {
     final String charStr = proxy.getCharacter("");
     if (charStr.isEmpty()) {
       Log.error(
           "core",
           "registry path "
               + path
               + " does not contain neither \'special\' nor \'character\' values");
       return null;
     }
     c = charStr.charAt(0);
   }
   final boolean withControl = proxy.getWithControl(false);
   final boolean withShift = proxy.getWithShift(false);
   final boolean withAlt = proxy.getWithAlt(false);
   return new KeyboardEvent(special != null, special, c, withShift, withControl, withAlt);
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
0
 @Override
 public boolean onKeyboardEvent(KeyboardEvent event) {
   NullCheck.notNull(event, "event");
   System.out.println(event.toString());
   if (closing.onKeyboardEvent(event)) return true;
   return super.onKeyboardEvent(event);
 }
Exemplo n.º 10
0
 protected boolean onTransition(Transition.Type type, int hint, boolean briefAnnouncement) {
   NullCheck.notNull(type, "type");
   //	NullCheck.notNull(hint, "hint");
   if (noContent()) return true;
   final int index = selectedIndex();
   final int count = model.getItemCount();
   final int emptyCountTop = flags.contains(Flags.EMPTY_LINE_TOP) ? 1 : 0;
   final Transition.State current;
   if (index >= 0) current = new Transition.State(index);
   else if (flags.contains(Flags.EMPTY_LINE_TOP) && hotPointY == 0)
     current = new Transition.State(Transition.State.Type.EMPTY_LINE_TOP);
   else if (flags.contains(Flags.EMPTY_LINE_BOTTOM) && hotPointY == count + emptyCountTop)
     current = new Transition.State(Transition.State.Type.EMPTY_LINE_BOTTOM);
   else return false;
   final Transition.State newState =
       transition.transition(
           type,
           current,
           count,
           flags.contains(Flags.EMPTY_LINE_TOP),
           flags.contains(Flags.EMPTY_LINE_BOTTOM));
   NullCheck.notNull(newState, "newState");
   Log.debug("list", "newState=" + newState.type);
   switch (newState.type) {
     case NO_TRANSITION:
       environment.hint(hint);
       return true;
     case EMPTY_LINE_TOP:
       if (!flags.contains(Flags.EMPTY_LINE_TOP)) return false;
       hotPointY = 0;
       break;
     case EMPTY_LINE_BOTTOM:
       if (!flags.contains(Flags.EMPTY_LINE_BOTTOM)) return false;
       hotPointY = count + emptyCountTop;
       break;
     case ITEM_INDEX:
       if (newState.itemIndex < 0 || newState.itemIndex >= count) return false;
       hotPointY = newState.itemIndex + emptyCountTop;
       break;
     default:
       return false;
   }
   onNewHotPointY(briefAnnouncement);
   return true;
 }
Exemplo n.º 11
0
 UserInterface(ControlPanel controlPanel) {
   super(
       new DefaultControlEnvironment(controlPanel.getCoreInterface()),
       controlPanel.getCoreInterface().i18n().getStaticStr("CpUserInterfaceGeneral"));
   NullCheck.notNull(controlPanel, "controlPanel");
   this.controlPanel = controlPanel;
   this.luwrain = controlPanel.getCoreInterface();
   this.sett = Settings.createUserInterface(luwrain.getRegistry());
   fillForm();
 }
Exemplo n.º 12
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;
 }
Exemplo n.º 13
0
 @Override
 public boolean onAreaQuery(AreaQuery query) {
   NullCheck.notNull(query, "query");
   switch (query.getQueryCode()) {
     case AreaQuery.BEGIN_LISTENING:
       if (query instanceof BeginListeningQuery)
         return onBeginListeningQuery((BeginListeningQuery) query);
       return false;
     default:
       return region.onAreaQuery(query, hotPointX, hotPointY);
   }
 }
Exemplo n.º 14
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;
 }
Exemplo n.º 15
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;
 }
Exemplo n.º 16
0
 @Override
 public boolean onEnvironmentEvent(EnvironmentEvent event) {
   NullCheck.notNull(event, "event");
   if (closing.onEnvironmentEvent(event)) return true;
   switch (event.getCode()) {
     case INTRODUCE:
       luwrain.silence();
       luwrain.playSound(Sounds.INTRO_POPUP);
       luwrain.say(getAreaName());
       return true;
     default:
       return super.onEnvironmentEvent(event);
   }
 }
Exemplo n.º 17
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;
 }
Exemplo n.º 18
0
 @Override
 public boolean onKeyboardEvent(KeyboardEvent event) {
   NullCheck.notNull(event, "event");
   if (!event.isSpecial() && (!event.isModified() || event.withShiftOnly())) return onChar(event);
   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);
     case ALTERNATIVE_ARROW_RIGHT:
       return onAltRight(event);
     case ALTERNATIVE_ARROW_LEFT:
       return onAltLeft(event);
     case HOME:
       return onHome(event);
     case END:
       return onEnd(event);
     case ALTERNATIVE_HOME:
       return onAltHome(event);
     case ALTERNATIVE_END:
       return onAltEnd(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 INSERT:
       return onInsert(event);
     case ENTER:
       return onEnter(event);
     default:
       return false;
   }
 }
Exemplo n.º 19
0
 @Override
 public boolean onEnvironmentEvent(EnvironmentEvent event) {
   NullCheck.notNull(event, "event");
   if (closing.onEnvironmentEvent(event)) return true;
   if (region.onEnvironmentEvent(event, hotPointX, hotPointY)) return false;
   switch (event.getCode()) {
     case REFRESH:
       refresh();
       return true;
     case INTRODUCE:
       luwrain.silence();
       luwrain.playSound(Sounds.INTRO_POPUP);
       luwrain.say(getAreaName());
       return true;
     default:
       return false;
   }
 }
Exemplo n.º 20
0
 public ListArea(Params params) {
   NullCheck.notNull(params, "params");
   NullCheck.notNull(params.environment, "params.environment");
   NullCheck.notNull(params.model, "params.model");
   NullCheck.notNull(params.appearance, "params.appearance");
   NullCheck.notNull(params.transition, "params.transition");
   NullCheck.notNull(params.name, "params.name");
   NullCheck.notNull(params.flags, "params.flags");
   this.environment = params.environment;
   this.model = params.model;
   this.appearance = params.appearance;
   this.transition = params.transition;
   this.clickHandler = params.clickHandler;
   this.areaName = params.name;
   this.flags = params.flags;
   //	itemsLayout.setFlags(params.flags);
   resetHotPoint();
 }
Exemplo n.º 21
0
 public State(Type type) {
   NullCheck.notNull(type, "type");
   this.type = type;
   this.itemIndex = -1;
 }
Exemplo n.º 22
0
 @Override
 public String getAreaName() {
   NullCheck.notNull(areaName, "areaName");
   return areaName;
 }
Exemplo n.º 23
0
 public void setAreaName(String areaName) {
   NullCheck.notNull(areaName, "areaName");
   this.areaName = areaName;
   environment.onAreaNewName(this);
 }
Exemplo n.º 24
0
 static UserInterface create(ControlPanel controlPanel) {
   NullCheck.notNull(controlPanel, "controlPanel");
   return new UserInterface(controlPanel);
 }
Exemplo n.º 25
0
 @Override
 public boolean onEnvironmentEvent(EnvironmentEvent event) {
   NullCheck.notNull(event, "event");
   if (controlPanel.onEnvironmentEvent(event)) return true;
   return super.onEnvironmentEvent(event);
 }
Exemplo n.º 26
0
 @Override
 public boolean onKeyboardEvent(KeyboardEvent event) {
   NullCheck.notNull(event, "event");
   if (controlPanel.onKeyboardEvent(event)) return true;
   return super.onKeyboardEvent(event);
 }
Exemplo n.º 27
0
 protected void announceChar(String line, int pos, int rightBound) {
   NullCheck.notNull(line, "line");
   if (pos < rightBound) environment.sayLetter(line.charAt(pos));
   else environment.hint(Hints.END_OF_LINE);
 }