/** Saves the displayed text. */ private void save() { final BaseXFileChooser fc = new BaseXFileChooser(SAVE_AS, gui.gopts.get(GUIOptions.WORKPATH), gui).suffix(IO.XMLSUFFIX); final IO file = fc.select(Mode.FSAVE); if (file == null) return; gui.gopts.set(GUIOptions.WORKPATH, file.path()); gui.cursor(CURSORWAIT, true); final MainOptions opts = gui.context.options; final int mh = opts.get(MainOptions.MAXHITS); opts.set(MainOptions.MAXHITS, -1); opts.set(MainOptions.CACHEQUERY, false); try (final PrintOutput out = new PrintOutput(file.toString())) { if (cmd != null) { cmd.execute(gui.context, out); } else if (ns != null) { ns.serialize(Serializer.get(out)); } else { final byte[] txt = text.getText(); for (final byte t : txt) if (t < 0 || t > ' ' || ws(t)) out.write(t); } } catch (final IOException ex) { BaseXDialog.error(gui, Util.info(FILE_NOT_SAVED_X, file)); } finally { opts.set(MainOptions.MAXHITS, mh); opts.set(MainOptions.CACHEQUERY, true); gui.cursor(CURSORARROW, true); } }
/** * Handles key down events. Cursor keys are handled by the view the other key events are * delegated to the currently active tool. */ public void keyPressed(KeyEvent e) { int code = e.getKeyCode(); if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_DELETE)) { if (deleteCmd.isExecutable()) { deleteCmd.execute(); // deleteCmd.viewSelectionChanged(this); } } else if ((code == KeyEvent.VK_DOWN) || (code == KeyEvent.VK_UP) || (code == KeyEvent.VK_RIGHT) || (code == KeyEvent.VK_LEFT)) { handleCursorKey(code); } else { tool().keyDown(e, code); } checkDamage(); }
public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); if (command.equals("OK")) { double x = Double.parseDouble(firstNumber.getText()); double y = Double.parseDouble(secondNumber.getText()); calculate(x, y); } else { Command.setText(command); lastCommand = command; } }
/** * Caches the output. * * @param out cached output * @param c command * @param r result * @throws QueryException query exception */ public void cacheText(final ArrayOutput out, final Command c, final Result r) throws QueryException { // cache command or node set cmd = null; ns = null; final int mh = gui.context.options.get(MainOptions.MAXHITS); boolean parse = false; if (mh >= 0 && r != null && r.size() >= mh) { parse = true; } else if (out.finished()) { if (r instanceof DBNodes) ns = (DBNodes) r; else parse = true; } // create new command instance if (parse) cmd = new CommandParser(c.toString(), gui.context).parseSingle(); }
public CalculatorPanel() { result = 0; lastCommand = "+"; ActionListener command = new CommandAction(); GridLayout layout = new GridLayout(2, 5); layout.setHgap(5); layout.setVgap(5); panel = new JPanel(); panel.setLayout(layout); panel.setPreferredSize(new Dimension(400, 200)); // add display display = new JTextField(); Command = new JTextField("+"); firstNumber = new JTextField(); secondNumber = new JTextField(); JTextField equal = new JTextField("="); equal.setEnabled(false); display.setEnabled(false); Command.setEnabled(false); panel.add(firstNumber); panel.add(Command); panel.add(secondNumber); panel.add(equal); panel.add(display); addButton("+", command); addButton("-", command); addButton("*", command); addButton("/", command); addButton("OK", command); add(panel, BorderLayout.CENTER); }
/** * This method implements ActionListener, which is a super-interface of Action. When a component * generates an ActionEvent, it is passed to this method. This method simply passes it on to the * Command object which is also an ActionListener object */ public void actionPerformed(ActionEvent e) { command.actionPerformed(e); }