/**
   * @param command command name in local language
   * @return syntax description of command as html text or null
   */
  private String getCmdSyntax(String command) {
    if (command == null || command.length() == 0) return null;

    // try macro first
    Macro macro = app.getKernel().getMacro(command);
    if (macro != null) {
      return macro.toString();
    }

    // translate command to internal name and get syntax description
    // note: the translation ignores the case of command
    String internalCmd = app.translateCommand(command);
    // String key = internalCmd + "Syntax";
    // String syntax = app.getCommand(key);
    String syntax;
    if (isCASInput) {
      syntax = app.getCommandSyntaxCAS(internalCmd);
    } else {
      syntax = app.getCommandSyntax(internalCmd);
    }

    // check if we really found syntax information
    // if (key.equals(syntax)) return null;
    if (syntax.indexOf(app.syntaxStr) == -1) return null;

    // build html tooltip
    syntax = syntax.replaceAll("<", "&lt;");
    syntax = syntax.replaceAll(">", "&gt;");
    syntax = syntax.replaceAll("\n", "<br>");
    StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    sb.append(syntax);
    sb.append("</html>");
    return sb.toString();
  }
  /*
   * Take a list of commands and return all possible syntaxes
   * for these commands
   */
  private List<String> getSyntaxes(List<String> commands) {
    if (commands == null) {
      return null;
    }
    ArrayList<String> syntaxes = new ArrayList<String>();
    for (String cmd : commands) {

      String cmdInt = app.getInternalCommand(cmd);

      String syntaxString;
      if (isCASInput) {
        syntaxString = app.getCommandSyntaxCAS(cmdInt);
      } else {
        syntaxString = app.getCommandSyntax(cmdInt);
      }
      if (syntaxString.endsWith(isCASInput ? app.syntaxCAS : app.syntaxStr)) {

        // command not found, check for macros
        Macro macro = isCASInput ? null : app.getKernel().getMacro(cmd);
        if (macro != null) {
          syntaxes.add(macro.toString());
        } else {
          // syntaxes.add(cmdInt + "[]");
          Application.debug("Can't find syntax for: " + cmd);
        }

        continue;
      }
      for (String syntax : syntaxString.split("\\n")) {
        syntaxes.add(syntax);
      }
    }
    return syntaxes;
  }
Exemplo n.º 3
0
  private void init() {
    // copy the construction
    Qin = locusPoint.getAllPredecessors(); // all parents of Q

    // get intersection of all children of P and all parents of Q
    locusConsOrigElements = new TreeSet<ConstructionElement>();
    TreeSet<Long> usedAlgoIds = new TreeSet<Long>();
    Iterator<GeoElement> it = Qin.iterator();
    while (it.hasNext()) {
      GeoElement parent = it.next();

      if (parent.isLabelSet() && parent.isChildOf(movingPoint)) {
        // note: locusConsOrigElements will contain AlgoElement and GeoElement objects
        Macro.addDependentElement(parent, locusConsOrigElements, usedAlgoIds);
      }
    }

    // ensure that P and Q have labels set
    // Note: we have to undo this at the end of this method !!!
    boolean isLabeledP = movingPoint.isLabelSet();
    if (!isLabeledP) {
      movingPoint.label = movingPoint.getDefaultLabel();
      movingPoint.labelSet = true;
    }
    boolean isLabeledQ = locusPoint.isLabelSet();
    if (!isLabeledQ) {
      locusPoint.label = locusPoint.getDefaultLabel();
      locusPoint.labelSet = true;
    }

    // add moving point on line
    locusConsOrigElements.add(movingPoint);

    // add locus creating point and its algorithm to locusConsOrigElements
    Macro.addDependentElement(locusPoint, locusConsOrigElements, usedAlgoIds);

    // create macro construction
    buildLocusMacroConstruction(locusConsOrigElements);

    // if we used temp labels remove them again
    if (!isLabeledP) movingPoint.labelSet = false;
    if (!isLabeledQ) locusPoint.labelSet = false;
  }
Exemplo n.º 4
0
  private void buildLocusMacroConstruction(TreeSet<ConstructionElement> locusConsElements) {
    // build macro construction
    macroKernel = new MacroKernel((Kernel) kernel);
    macroKernel.setGlobalVariableLookup(true);

    // tell the macro construction about reserved names:
    // these names will not be looked up in the parent
    // construction
    Iterator<ConstructionElement> it = locusConsElements.iterator();
    while (it.hasNext()) {
      ConstructionElement ce = it.next();
      if (ce.isGeoElement()) {
        GeoElement geo = (GeoElement) ce;
        macroKernel.addReservedLabel(geo.getLabel());
      }
    }

    try {
      // get XML for macro construction of P -> Q
      String locusConsXML = Macro.buildMacroXML((Kernel) kernel, locusConsElements);

      macroKernel.loadXML(locusConsXML);

      // get the copies of P and Q from the macro kernel
      Pcopy = (GeoPoint2) macroKernel.lookupLabel(movingPoint.label);
      Pcopy.setFixed(false);
      Pcopy.setPath(movingPoint.getPath());

      Qcopy = (GeoPoint2) macroKernel.lookupLabel(locusPoint.label);
      macroCons = macroKernel.getConstruction();

      /*
      // make sure that the references to e.g. start/end point of a segment are not
      // changed later on. This is achieved by setting isMacroOutput to true
      it = macroCons.getGeoElementsIterator();
          	while (it.hasNext()) {
           	GeoElement geo = (GeoElement) it.next();
           	geo.isAlgoMacroOutput = true;
          	}
          	Pcopy.isAlgoMacroOutput = false;
          	*/
    } catch (Exception e) {
      e.printStackTrace();
      locus.setUndefined();
      macroCons = null;
    }

    //    	//Application.debug("P: " + P + ", kernel class: " + P.kernel.getClass());
    //    	Application.debug("Pcopy: " + Pcopy  + ", kernel class: " + Pcopy.kernel.getClass());
    //    	//Application.debug("P == Pcopy: " + (P == Pcopy));
    //    	//Application.debug("Q: " + Q  + ", kernel class: " + Q.kernel.getClass());
    //    	Application.debug("Qcopy: " + Qcopy  + ", kernel class: " + Qcopy.kernel.getClass());
    //    	//Application.debug("Q == Qcopy: " + (Q == Qcopy));
  }
Exemplo n.º 5
0
  private void writeMacroImages(ArrayList macros, ZipOutputStream zip, String filePath)
      throws IOException {
    // <-- Modified for Intergeo File Format (Yves Kreis)
    if (macros == null) return;

    for (int i = 0; i < macros.size(); i++) {
      // save all images in macro construction
      Macro macro = (Macro) macros.get(i);
      // Modified for Intergeo File Format (Yves Kreis) -->
      // writeConstructionImages(macro.getMacroConstruction(), zip);
      writeConstructionImages(macro.getMacroConstruction(), zip, filePath);
      // <-- Modified for Intergeo File Format (Yves Kreis)

      // save macro icon
      String fileName = macro.getIconFileName();
      BufferedImage img = app.getExternalImage(fileName);
      if (img != null)
        // Modified for Intergeo File Format (Yves Kreis) -->
        // writeImageToZip(zip, fileName, img);
        writeImageToZip(zip, filePath + fileName, img);
      // <-- Modified for Intergeo File Format (Yves Kreis)
    }
  }