Default constructor. @param main main window reference
(final GUI main)
| 38 | * @param main main window reference |
| 39 | */ |
| 40 | GUIInput(final GUI main) { |
| 41 | super(main, true); |
| 42 | gui = main; |
| 43 | |
| 44 | BaseXLayout.resizeFont(this, 1.3f); |
| 45 | |
| 46 | completions = new BaseXCombo(main); |
| 47 | completions.addActionListener(e -> completeInput()); |
| 48 | popup = new GUIInputPopup(completions); |
| 49 | |
| 50 | addKeyListener(new KeyAdapter() { |
| 51 | @Override |
| 52 | public void keyPressed(final KeyEvent e) { |
| 53 | if(ESCAPE.is(e)) { |
| 54 | popup.setVisible(false); |
| 55 | } else if(ENTER.is(e)) { |
| 56 | if(popup.isVisible()) { |
| 57 | completeInput(); |
| 58 | popup.setVisible(false); |
| 59 | } else { |
| 60 | updateHistory(); |
| 61 | // evaluate the input |
| 62 | if(e.getModifiersEx() == 0) gui.execute(); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | final int count = completions.getItemCount(); |
| 67 | if(count == 0) return; |
| 68 | |
| 69 | int bi = completions.getSelectedIndex(); |
| 70 | if(NEXTLINE.is(e)) { |
| 71 | if(popup.isVisible()) { |
| 72 | if(++bi == count) bi = 0; |
| 73 | } else { |
| 74 | popupMenu(); |
| 75 | } |
| 76 | } else if(PREVLINE.is(e)) { |
| 77 | if(popup.isVisible()) { |
| 78 | if(--bi < 0) bi = count - 1; |
| 79 | } else { |
| 80 | popupMenu(); |
| 81 | } |
| 82 | } |
| 83 | if(bi != completions.getSelectedIndex()) completions.setSelectedIndex(bi); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void keyReleased(final KeyEvent e) { |
| 88 | if(!NEXTLINE.is(e) && !PREVLINE.is(e)) { |
| 89 | if(modifier(e) || control(e)) return; |
| 90 | popupMenu(); |
| 91 | if(gui.gopts.get(GUIOptions.EXECRT) && !cmdMode()) main.execute(); |
| 92 | } |
| 93 | } |
| 94 | }); |
| 95 | } |
| 96 | |
| 97 | @Override |
nothing calls this directly
no test coverage detected