@Override public void execute(final GUI gui) { final DialogExport dialog = new DialogExport(gui); if (!dialog.ok()) return; final IOFile root = new IOFile(dialog.path()); // check if existing files will be overwritten if (root.exists()) { IO file = null; boolean overwrite = false; final Data d = gui.context.data(); final IntList il = d.resources.docs(); final int is = il.size(); for (int i = 0; i < is; i++) { file = root.merge(Token.string(d.text(il.get(i), true))); if (file.exists()) { if (overwrite) { // more than one file will be overwritten; check remaining tests file = null; break; } overwrite = true; } } if (overwrite) { // show message for overwriting files or directories final String msg = file == null ? FILES_REPLACE_X : FILE_EXISTS_X; if (file == null) file = root; if (!BaseXDialog.confirm(gui, Util.info(msg, file))) return; } } DialogProgress.execute(gui, new Export(root.path())); }
/** 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); } }
/** * Sets a syntax highlighter, based on the file format. * * @param file file reference * @param opened indicates if file was opened from disk */ protected final void setSyntax(final IO file, final boolean opened) { setSyntax( !opened || file.hasSuffix(IO.XQSUFFIXES) ? new XQuerySyntax() : file.hasSuffix(IO.JSONSUFFIX) ? new JSONSyntax() : file.hasSuffix(IO.XMLSUFFIXES) || file.hasSuffix(IO.HTMLSUFFIXES) ? new XMLSyntax() : BaseXSyntax.SIMPLE); }
public Overlord(String fileName) throws IOException { this(); io = new IO(this); io.getInfoFromFile(fileName); cd = new ChessDisplay(this); getManip(); }
public void getManip() throws IOException { boolean exit = false; while (!exit) { run(); this.io = new IO(this); io.getInfoFromString(cd.displayMoves()); } }
/** * Sets a syntax highlighter, based on the file format. * * @param file file reference * @param opened indicates if file was opened from disk */ protected final void setSyntax(final IO file, final boolean opened) { setSyntax( !opened || file.hasSuffix(IO.XQSUFFIXES) ? new SyntaxXQuery() : file.hasSuffix(IO.JSONSUFFIX) ? new SyntaxJSON() : file.hasSuffix(IO.JSSUFFIX) ? new SyntaxJS() : file.hasSuffix(IO.XMLSUFFIXES) || file.hasSuffix(IO.HTMLSUFFIXES) || file.hasSuffix(IO.XSLSUFFIXES) || file.hasSuffix(IO.BXSSUFFIX) ? new SyntaxXML() : Syntax.SIMPLE); }
/** * Refreshes the list of recent query files and updates the query path. * * @param file new file */ void refreshHistory(final IOFile file) { final StringList sl = new StringList(); String path = null; if (file != null) { path = file.path(); gui.gprop.set(GUIProp.WORKPATH, file.dirPath()); sl.add(path); tabs.setToolTipTextAt(tabs.getSelectedIndex(), path); } final String[] qu = gui.gprop.strings(GUIProp.EDITOR); for (int q = 0; q < qu.length && q < 19; q++) { final String f = qu[q]; if (!f.equalsIgnoreCase(path) && IO.get(f).exists()) sl.add(f); } // store sorted history gui.gprop.set(GUIProp.EDITOR, sl.toArray()); hist.setEnabled(!sl.isEmpty()); }
/** * Handles info messages resulting from a query execution. * * @param msg info message * @return true if error was found */ private boolean error(final String msg) { final String line = msg.replaceAll("[\\r\\n].*", ""); Matcher m = XQERROR.matcher(line); int el, ec = 2; if (!m.matches()) { m = XMLERROR.matcher(line); if (!m.matches()) return true; el = Integer.parseInt(m.group(1)); errFile = getEditor().file.path(); } else { el = Integer.parseInt(m.group(1)); ec = Integer.parseInt(m.group(2)); errFile = m.group(3); } final EditorArea edit = find(IO.get(errFile), false); if (edit == null) return true; // find approximate error position final int ll = edit.last.length; int ep = ll; for (int e = 1, l = 1, c = 1; e < ll; ++c, e += cl(edit.last, e)) { if (l > el || l == el && c == ec) { ep = e; break; } if (edit.last[e] == '\n') { ++l; c = 0; } } if (ep < ll && Character.isLetterOrDigit(cp(edit.last, ep))) { while (ep > 0 && Character.isLetterOrDigit(cp(edit.last, ep - 1))) ep--; } edit.error(ep); errPos = ep; return true; }
public void run() { for (Behavior bee : io.getBehaviors()) { // Getting Pieces if (bee.getPiece() != null) { placePiece(bee.getStartPoint(), bee.getPiece()); System.out.println(bee.toString()); } else if (isWhitesTurn == b.get(bee.getStartPoint()).getColor()) { // make into methods // Taking pieces if (this.b.get(bee.getEndPoint()) != null) { if (takePiece(bee.getStartPoint(), bee.getEndPoint())) { System.out.println(bee.toString()); } else { System.err.println("Cannot take " + bee.toString()); } pawnPromotion(bee.getEndPoint()); } // castling else if (bee.getP3() != null && bee.getP4() != null) { if (castling(bee.getStartPoint(), bee.getEndPoint(), bee.getP3(), bee.getP4())) { System.out.println(bee.toString()); } else { System.err.println("Cannot move " + bee.toString()); } } // moving pieces else if (this.b.get(bee.getEndPoint()) == null) { if (movePiece(bee.getStartPoint(), bee.getEndPoint())) { System.out.println(bee.toString()); } else { System.err.println("Cannot move " + bee.toString()); } pawnPromotion(bee.getEndPoint()); } isWhitesTurn = !isWhitesTurn; if (checkForCheckMate() && isWhitesTurn) { System.out.println("Checkmate. Black wins!"); } else if (checkForCheckMate() && !isWhitesTurn) { System.out.println("Checkmate. White wins!"); } else if (checkForCheckMate() && !isKingInCheck()) { System.out.println("StaleMate."); } else if (isKingInCheck()) { System.out.println("The King is in check"); } } else { if (isWhitesTurn) { System.out.println("Its not Black's turn!"); } else if (!isWhitesTurn) { System.out.println("Its not White's turn!"); } } cd.displayBoard(); } }