/** * Make all tableaux associated with this effigy and any effigies it contains visible by raising * or deiconifying them. If there is no tableau contained directly by this effigy, then create one * by calling createPrimaryTableau() in the configuration. * * @return The first tableau encountered, or a new one if there are none. */ public Tableau showTableaux() { Iterator effigies = entityList(Effigy.class).iterator(); while (effigies.hasNext()) { Effigy effigy = (Effigy) effigies.next(); effigy.showTableaux(); } Iterator tableaux = entityList(Tableau.class).iterator(); Tableau result = null; while (tableaux.hasNext()) { Tableau tableau = (Tableau) tableaux.next(); tableau.show(); if (result == null) { result = tableau; } } if (result == null) { // Create a new tableau. Configuration configuration = (Configuration) toplevel(); result = configuration.createPrimaryTableau(this); } return result; }
/** * If the argument is the <i>identifier</i> parameter, then set the title of all contained * Tableaux to the value of the parameter; if the argument is the <i>uri</i> parameter, then check * to see whether it is writable, and call setModifiable() appropriately. * * @param attribute The attribute that changed. * @exception IllegalActionException If the base class throws it. */ @Override public void attributeChanged(Attribute attribute) throws IllegalActionException { if (attribute == identifier) { Iterator tableaux = entityList(Tableau.class).iterator(); while (tableaux.hasNext()) { Tableau tableau = (Tableau) tableaux.next(); tableau.setTitle(identifier.getExpression()); } } else if (attribute == uri) { URI uriValue = uri.getURI(); if (uriValue == null) { // A new model, with no URI, is by default modifiable. _modifiableURI = true; } else { String protocol = uriValue.getScheme(); if (!protocol.equals("file")) { _modifiableURI = false; } else { // Use just the path here in case we // are passed a URI that has a fragment. // If we had file:/C%7C/foo.txt#bar // then bar is the fragment. Unfortunately, // new File(file:/C%7C/foo.txt#bar) will fail, // so we add the path. String path = uriValue.getPath(); if (path != null) { File file = new File(path); try { if (path.indexOf("%20") == -1) { _modifiableURI = file.canWrite(); } else { // FIXME: we need a better way to check if // a URL is writable. // Sigh. If the filename has spaces in it, // then the URL will have %20s. However, // the file does not have %20s. // See // https://chess.eecs.berkeley.edu/bugzilla/show_bug.cgi?id=153 path = StringUtilities.substitute(path, "%20", " "); file = new File(path); _modifiableURI = file.canWrite(); } } catch (java.security.AccessControlException accessControl) { // If we are running in a sandbox, then canWrite() // may throw an AccessControlException. _modifiableURI = false; } } } } } else { super.attributeChanged(attribute); } }
public void capture(int x, int y, Tableau tableau) { int xCapt = 0; int yCapt = 0; if (this.x - x < 0) { xCapt = x - 1; } else if (this.x - x > 0) { xCapt = x + 1; } if (this.y - y < 0) { yCapt = y - 1; } else if (this.y - y > 0) { yCapt = y + 1; } tableau.pions[tableau.trouvePion(xCapt, yCapt)].viv = false; tableau.pions[tableau.trouvePion(xCapt, yCapt)].x = -1; tableau.pions[tableau.trouvePion(-1, yCapt)].y = -1; tableau.monde[xCapt][yCapt] = 0; this.deplacement(x, y, tableau); this.dame = this.promotion(tableau); }
/** * Close all tableaux contained by this effigy, and by any effigies it contains. * * @return False if the user cancels on a save query, and true if all tableaux are successfully * closed. */ public boolean closeTableaux() { Iterator effigies = entityList(Effigy.class).iterator(); while (effigies.hasNext()) { Effigy effigy = (Effigy) effigies.next(); if (!effigy.closeTableaux()) { return false; } } Iterator tableaux = entityList(Tableau.class).iterator(); while (tableaux.hasNext()) { Tableau tableau = (Tableau) tableaux.next(); if (!tableau.close()) { return false; } } return true; }