boolean (Object component, boolean shiftdown, boolean controldown, int modifiers, int keychar, int keycode) { String classname = getClass(component); if ("button" == classname) { if (keychar == KeyEvent.VK_SPACE || ((keycode == KeyEvent.VK_ENTER) && (getString(component, "type", null) == "default")) || ((keycode == KeyEvent.VK_ESCAPE) && //... (getString(component, "type", null) == "cancel"))) { //pressedkey = keychar; invoke(component, "action"); repaint(component); return true; } } else if ("checkbox" == classname) { if (keychar == KeyEvent.VK_SPACE) { changeCheck(component, true); repaint(component); return true; } } else if ("combobox" == classname) { Object combolist = get(component, "combolist"); if (combolist == null) { if (getBoolean(component, "editable", true) && processField(component, shiftdown, controldown, modifiers, keychar, keycode, false, false)) { setInteger(component, "selected", -1, -1); return true; } if ((keychar == KeyEvent.VK_SPACE) || (keycode == KeyEvent.VK_DOWN)) { combolist = popup(component, classname); int selected = getInteger(component, "selected", -1); set(combolist, "inside", (selected != -1) ? getItemImpl(component, "choice", selected) : get(component, "choice")); //scroll to it! } else { return false; } } else { if ((keycode == KeyEvent.VK_UP) || (keycode == KeyEvent.VK_DOWN) || (keycode == KeyEvent.VK_PAGE_UP) || (keycode == KeyEvent.VK_PAGE_DOWN) || (keycode == KeyEvent.VK_HOME) || (keycode == KeyEvent.VK_END)) { Object selected = get(combolist, "inside"); Object next = getListItem(component, combolist, keycode, selected, "choice", null); if (next != null) { set(combolist, "inside", next); Rectangle r = getRectangle(next, "bounds"); scrollToVisible(combolist, r.x, r.y, 0, r.height); if (selected != null) { repaint(combolist, "combolist", selected); } repaint(combolist, "combolist", next); } } else if ((keycode == KeyEvent.VK_ENTER) || (keychar == KeyEvent.VK_SPACE)) { closeup(component, combolist, get(combolist, "inside")); //Alt+Up } else if (keycode == KeyEvent.VK_ESCAPE) { closeup(component, combolist, null); } else { return processField(component, shiftdown, controldown, modifiers, keychar, keycode, false, false); } } return true; } else if (("textfield" == classname) || ("passwordfield" == classname)) { return processField(component, shiftdown, controldown, modifiers, keychar, keycode, false, ("passwordfield" == classname)); } else if ("textarea" == classname) { String text = getString(component, "text", ""); int start = getInteger(component, "start", 0); int end = getInteger(component, "end", 0); int istart = start; int iend = end; String insert = null; if ((keycode == KeyEvent.VK_HOME) && !controldown) { while ((iend > 0) && (text.charAt(iend - 1) != '\n')) { iend--; } if (!shiftdown) { istart = iend; } } else if ((keycode == KeyEvent.VK_END) && !controldown) { iend = text.indexOf('\n', end); if (iend == -1) { iend = text.length(); } if (!shiftdown) { istart = iend; } } else if ((keycode == KeyEvent.VK_UP) || (keycode == KeyEvent.VK_PAGE_UP)) { int prev = end; while ((prev > 0) && (text.charAt(prev - 1) != '\n')) { prev--; } if (prev != 0) { int dx = end - prev; int lines = (keycode == KeyEvent.VK_PAGE_UP) ? (getRectangle(component, ":port").height / getFontMetrics(getFont()).getHeight()) : 1; int first = prev; do { prev = first; first--; lines--; while ((first > 0) && (text.charAt(first - 1) != '\n')) { first--; } } while ((first > 0) && (lines > 0)); iend = Math.min(first + dx, prev - 1); if (!shiftdown) { istart = iend; } } } else if ((keycode == KeyEvent.VK_DOWN) || (keycode == KeyEvent.VK_PAGE_DOWN)) { int next = text.indexOf('\n', end); if (next != -1) { int prev = end; while ((prev > 0) && (text.charAt(prev - 1) != '\n')) { prev--; } if (keycode == KeyEvent.VK_PAGE_DOWN) { int lines = getRectangle(component, ":port").height / getFontMetrics(getFont()).getHeight(); for (int more = 0; (lines > 1) && ((more = text.indexOf('\n', next + 1)) != -1); next = more) { lines--; } } int last = text.indexOf('\n', next + 1); iend = Math.min(next + 1 + end - prev, (last == -1) ? (text.length() + 1) : last); if (!shiftdown) { istart = iend; } } } return changeField(component, text, insert, istart, iend, start, end) ? true : processField(component, shiftdown, controldown, modifiers, keychar, keycode, true, false); } else if ("tabbedpane" == classname) { if ((keycode == KeyEvent.VK_RIGHT) || (keycode == KeyEvent.VK_DOWN) || (keycode == KeyEvent.VK_LEFT) || (keycode == KeyEvent.VK_UP)) { int selected = getInteger(component, "selected", 0); boolean increase = (keycode == KeyEvent.VK_RIGHT) || (keycode == KeyEvent.VK_DOWN); int newvalue = selected; int n = increase ? getItemCountImpl(component, "tab") : 0; int d = (increase ? 1 : -1); for (int i = selected + d; increase ? (i < n) : (i >= 0); i += d) { if (getBoolean(getItemImpl(component, "tab", i), "enabled", true)) { newvalue = i; break; } } if (newvalue != selected) { setInteger(component, "selected", newvalue, 0); repaint(component); invoke(component, "action"); } } } else if ("spinbox" == classname) { if ((keycode == KeyEvent.VK_UP) || (keycode == KeyEvent.VK_DOWN)) { processSpin(component, (keycode == KeyEvent.VK_UP) ? "up" : "down"); return true; } return processField(component, shiftdown, controldown, modifiers, keychar, keycode, false, false); } else if ("slider" == classname) { int value = getInteger(component, "value", 0); int d = 0; if ((keycode == KeyEvent.VK_HOME) || (keycode == KeyEvent.VK_LEFT) || (keycode == KeyEvent.VK_UP) || (keycode == KeyEvent.VK_PAGE_UP)) { d = getInteger(component, "minimum", 0) - value; if ((keycode == KeyEvent.VK_LEFT) || (keycode == KeyEvent.VK_UP)) { d = Math.max(d, -getInteger(component, "unit", 5)); } else if (keycode == KeyEvent.VK_PAGE_UP) { d = Math.max(d, -getInteger(component, "block", 25)); } } else if ((keycode == KeyEvent.VK_END) || (keycode == KeyEvent.VK_RIGHT) || (keycode == KeyEvent.VK_DOWN) || (keycode == KeyEvent.VK_PAGE_DOWN)) { d = getInteger(component, "maximum", 100) - value; if ((keycode == KeyEvent.VK_RIGHT) || (keycode == KeyEvent.VK_DOWN)) { d = Math.min(d, getInteger(component, "unit", 5)); } else if (keycode == KeyEvent.VK_PAGE_DOWN) { d = Math.min(d, getInteger(component, "block", 25)); } } if (d != 0) { setInteger(component, "value", value + d, 0); repaint(component); invoke(component, "action"); } } else if ("splitpane" == classname) { int divider = getInteger(component, "divider", -1); int d = 0; if (keycode == KeyEvent.VK_HOME) { d = -divider; } else if ((keycode == KeyEvent.VK_LEFT) || (keycode == KeyEvent.VK_UP)) { d = Math.max(-10, -divider); } else if ((keycode == KeyEvent.VK_END) || (keycode == KeyEvent.VK_RIGHT) || (keycode == KeyEvent.VK_DOWN)) { boolean horizontal = ("vertical" != get(component, "orientation")); Rectangle bounds = getRectangle(component, "bounds"); int max = (horizontal ? bounds.width : bounds.height) - 5; d = max - divider; if (keycode != KeyEvent.VK_END) { d = Math.min(d, 10); } } if (d != 0) { setInteger(component, "divider", divider + d, -1); validate(component); } } else if ("list" == classname) { return processList(component, shiftdown, controldown, keychar, keycode, "item", null); } else if ("table" == classname) { return processList(component, shiftdown, controldown, keychar, keycode, "row", null); } else if ("tree" == classname) { //? clear childs' selection, select this is its subnode was selected if (keycode == KeyEvent.VK_LEFT) { Object lead = get(component, "lead"); if ((get(lead, "node") != null) && getBoolean(lead, "expanded", true)) { setBoolean(lead, "expanded", false, true); selectItem(component, lead, "node", "node"); validate(component); invoke(component, "collapse"); //lead return true; } else { Object parent = getParent(lead); if (parent != component) { selectItem(component, parent, "node", "node"); setLead(component, lead, parent); return true; } } } //? for interval mode select its all subnode or deselect all after else if (keycode == KeyEvent.VK_RIGHT) { Object lead = get(component, "lead"); Object node = get(lead, "node"); if (node != null) { if (getBoolean(lead, "expanded", true)) { selectItem(component, node, "node", "node"); setLead(component, lead, node); } else { setBoolean(lead, "expanded", true, true); selectItem(component, lead, "node", "node"); validate(component); invoke(component, "expand"); //lead } return true; } } return processList(component, shiftdown, controldown, keychar, keycode, "node", "node"); } else if ("menubar" == classname) { Object previous = null; Object last = null; for (Object i = get(component, "popupmenu"); i != null; i = get(i, "popupmenu")) { previous = last; last = i; } Object selected = get(last, "selected"); Object hotpopup = ((selected != null) || (previous == null)) ? last : previous; if ((selected == null) && (previous != null)) { selected = get(previous, "selected"); } if ((keycode == KeyEvent.VK_UP) || (keycode == KeyEvent.VK_DOWN)) { set(hotpopup, "selected", null); popup(hotpopup, "popupmenu"); selected = getMenu(hotpopup, selected, keycode == KeyEvent.VK_DOWN, true); set(hotpopup, "selected", selected); repaint(hotpopup); } else if (keycode == KeyEvent.VK_LEFT) { if (previous != null) { selected = get(previous, "selected"); set(previous, "selected", null); popup(previous, "popupmenu"); set(previous, "selected", selected); repaint(previous); // , selected } else { selected = getMenu(component, get(component, "selected"), false, false); set(component, "selected", selected); Object popup = popup(component, "menubar"); set(popup, "selected", getMenu(popup, null, true, true)); repaint(component); // , selected } } else if (keycode == KeyEvent.VK_RIGHT) { if ((previous != null) && (selected == null)) { set(last, "selected", get(get(last, "menu"), "menu")); repaint(last); // , selected } else if ((selected != null) && (getClass(selected) == "menu")) { Object popup = popup(last, "popupmenu"); set(popup, "selected", get(get(popup, "menu"), "menu")); } else { selected = getMenu(component, get(component, "selected"), true, false); set(component, "selected", selected); Object popup = popup(component, "menubar"); set(popup, "selected", getMenu(popup, null, true, true)); repaint(component); // , selected } } else if ((keycode == KeyEvent.VK_ENTER) || (keychar == KeyEvent.VK_SPACE) || (keycode == KeyEvent.VK_ESCAPE)) { if ((keycode != KeyEvent.VK_ESCAPE) && getBoolean(selected, "enabled", true)) { if ((selected != null) && (getClass(selected) == "checkboxmenuitem")) { changeCheck(selected, false); } else { invoke(selected, "action"); } } closeup(component); } else { return false; } return true; } return false; }