public void set(GeoElement geo) {
    GeoSurfaceCartesian3D geoSurface = (GeoSurfaceCartesian3D) geo;

    fun = new Function[3];
    for (int i = 0; i < 3; i++) {
      fun[i] = new FunctionNVar(geoSurface.fun[i], kernel);
      // Application.debug(fun[i].toString());
    }

    startParam = geoSurface.startParam;
    endParam = geoSurface.endParam;
    isDefined = geoSurface.isDefined;

    // macro OUTPUT
    if (geo.getConstruction() != cons && isAlgoMacroOutput()) {
      if (!geo.isIndependent()) {
        // this object is an output object of AlgoMacro
        // we need to check the references to all geos in its function's expression
        AlgoMacro algoMacro = (AlgoMacro) getParentAlgorithm();
        for (int i = 0; i < 3; i++) algoMacro.initFunction(fun[i]);
      }
    }

    // distFun = new ParametricCurveDistanceFunction(this);

  }
Esempio n. 2
0
  private void writeConstructionImages(Construction cons, ZipOutputStream zip, String filePath)
      throws IOException {
    // <-- Modified for Intergeo File Format (Yves Kreis)
    // save all GeoImage images
    // TreeSet images = cons.getGeoSetLabelOrder(GeoElement.GEO_CLASS_IMAGE);
    TreeSet geos = cons.getGeoSetLabelOrder();
    if (geos == null) return;

    Iterator<GeoElement> it = geos.iterator();
    while (it.hasNext()) {
      GeoElement geo = it.next();
      // Michael Borcherds 2007-12-10 this line put back (not needed now
      // MD5 code put in the correct place!)
      String fileName = geo.getImageFileName();
      if (fileName != null) {
        BufferedImage img = geo.getFillImage();
        if (img != null) writeImageToZip(zip, filePath + fileName, img);
      }
    }
  }
Esempio n. 3
0
 public void debug(GeoElement geo) {
   System.out.println("=====================================");
   System.out.println(geo.toString());
   Field[] fields = TraceSettings.class.getDeclaredFields();
   for (Field field : fields) {
     try {
       System.out.println(field.getName() + ": " + field.get(this).toString());
     } catch (Exception e) {
       Application.debug(e.getMessage());
     }
   }
   System.out.println("=====================================");
 }
Esempio n. 4
0
  public GeoElement getResult() {
    if (geoResult != null) {
      // set label of geoResult
      String strLabel;
      try {
        strLabel = app.getKernel().getAlgebraProcessor().parseLabel(tfLabel.getText());
      } catch (Exception e) {
        strLabel = null;
      }
      geoResult.setLabel(strLabel);
    }

    return geoResult;
  }
Esempio n. 5
0
  /**
   * Renders LaTeX equation using JLaTeXMath
   *
   * @param app
   * @param g2
   * @param x
   * @param y
   * @param text
   * @param font
   * @param serif
   * @param fgColor
   * @param bgColor
   * @return dimension of rendered equation
   */
  public final FormulaDimension drawEquationJLaTeXMath(
      Application app,
      GeoElement geo,
      Graphics2D g2,
      int x,
      int y,
      String text,
      Font font,
      boolean serif,
      Color fgColor,
      Color bgColor,
      boolean useCache,
      Integer maxWidth,
      Float lineSpace) {
    // TODO uncomment when \- works
    // text=addPossibleBreaks(text);

    int width = -1;
    int height = -1;
    int depth = 0;

    if (drawEquationJLaTeXMathFirstCall) { // first call

      drawEquationJLaTeXMathFirstCall = false;

      // initialise definitions
      if (initJLaTeXMath == null)
        initJLaTeXMath =
            new TeXFormula(
                "\\DeclareMathOperator{\\sech}{sech} \\DeclareMathOperator{\\csch}{csch} \\DeclareMathOperator{\\erf}{erf}");

      // make sure cache doesn't get too big
      JLaTeXMathCache.setMaxCachedObjects(100);

      Iterator<String> it = Unicode.getCharMapIterator();

      while (it.hasNext()) {
        String lang = it.next();
        Character ch = Unicode.getTestChar(lang);
        Font testFont = app.getFontCanDisplay(ch.toString(), true, Font.PLAIN, 12);
        if (testFont != null)
          TeXFormula.registerExternalFont(Character.UnicodeBlock.of(ch), testFont.getFontName());
        // Application.debug("LaTeX font registering: "+lang+" "+testFont.getFontName());

      }

      // Arabic is in standard Java fonts, so we don't need to search for a font
      TeXFormula.registerExternalFont(Character.UnicodeBlock.of('\u0681'), "Sans Serif", "Serif");

      try {
        WebStartAlphabetRegistration.register(AlphabetRegistration.JLM_GREEK);
        WebStartAlphabetRegistration.register(AlphabetRegistration.JLM_CYRILLIC);
        // URLAlphabetRegistration.register(new URL(app.getCodeBase()+"jlm_greek.jar"),
        // "greek",URLAlphabetRegistration.JLM_GREEK);
        // URLAlphabetRegistration.register(new URL(app.getCodeBase()+"jlm_cyrillic.jar"),
        // "cyrillic",URLAlphabetRegistration.JLM_CYRILLIC);
      } catch (Exception e) {
        e.printStackTrace();
      }
      LatexConvertorFactory factory = new LatexConvertorFactory(app.getKernel());
      DynamicAtom.setExternalConverterFactory(factory);
    }

    int style = 0;
    if (font.isBold()) style = style | TeXFormula.BOLD;
    if (font.isItalic()) style = style | TeXFormula.ITALIC;
    if (!serif) style = style | TeXFormula.SANSSERIF;

    // if we're exporting, we want to draw it full resolution
    // if it's a \jlmDynamic text, we don't want to add it to the cache
    if (app.exporting || text.indexOf("\\jlmDynamic") > -1 || !useCache) {

      // Application.debug("creating new icon for: "+text);
      TeXFormula formula;
      TeXIcon icon;

      try {
        formula = new TeXFormula(text);

        if (maxWidth == null)
          icon =
              formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, font.getSize() + 3, style, fgColor);
        else
          icon =
              formula.createTeXIcon(
                  TeXConstants.STYLE_DISPLAY,
                  font.getSize() + 3,
                  TeXConstants.UNIT_CM,
                  maxWidth.intValue(),
                  TeXConstants.ALIGN_LEFT,
                  TeXConstants.UNIT_CM,
                  lineSpace.floatValue());
      } catch (MyError e) {
        // e.printStackTrace();
        // Application.debug("MyError LaTeX parse exception: "+e.getMessage()+"\n"+text);
        // Write error message to Graphics View

        formula = TeXFormula.getPartialTeXFormula(text);
        icon =
            formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, font.getSize() + 3, style, fgColor);

        formula.createTeXIcon(
            TeXConstants.STYLE_DISPLAY,
            15,
            TeXConstants.UNIT_CM,
            4f,
            TeXConstants.ALIGN_LEFT,
            TeXConstants.UNIT_CM,
            0.5f);

        // Rectangle rec = drawMultiLineText(e.getMessage()+"\n"+text, x, y +
        // g2.getFont().getSize(), g2);
        // return new Dimension(rec.width, rec.height);
      } catch (Exception e) {
        // e.printStackTrace();
        // Application.debug("LaTeX parse exception: "+e.getMessage()+"\n"+text);
        // Write error message to Graphics View

        formula = TeXFormula.getPartialTeXFormula(text);
        icon =
            formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, font.getSize() + 3, style, fgColor);

        // Rectangle rec = drawMultiLineText(e.getMessage()+"\n"+text, x, y +
        // g2.getFont().getSize(), g2);
        // return new Dimension(rec.width, rec.height);
      }
      icon.setInsets(new Insets(1, 1, 1, 1));

      jl.setForeground(fgColor);
      icon.paintIcon(jl, g2, x, y);
      return new FormulaDimension(icon.getIconWidth(), icon.getIconHeight(), icon.getIconDepth());
    }

    Object key = null;
    Image im = null;
    try {
      // if geoText != null then keep track of which key goes with the GeoText
      // so that we can remove it from the cache if it changes
      // eg for a (regular) dynamic LaTeX text eg "\sqrt{"+a+"}"
      if (geo == null)
        key =
            JLaTeXMathCache.getCachedTeXFormula(
                text,
                TeXConstants.STYLE_DISPLAY,
                style,
                font.getSize() + 3 /*font size*/,
                1 /* inset around the label*/,
                fgColor);
      else key = geo.getLaTeXCache().getCachedLaTeXKey(text, font.getSize() + 3, style, fgColor);

      im = JLaTeXMathCache.getCachedTeXFormulaImage(key);

      int ret[] = JLaTeXMathCache.getCachedTeXFormulaDimensions(key);
      width = ret[0];
      height = ret[1];
      depth = ret[2];

    } catch (Exception e) {
      // Application.debug("LaTeX parse exception: "+e.getMessage()+"\n"+text);
      // Write error message to Graphics View

      TeXFormula formula = TeXFormula.getPartialTeXFormula(text);
      im =
          formula.createBufferedImage(
              TeXConstants.STYLE_DISPLAY, font.getSize() + 3, Color.black, Color.white);

      // Rectangle rec = drawMultiLineText(e.getMessage()+"\n"+text, x, y + g2.getFont().getSize(),
      // g2);
      // return new Dimension(rec.width, rec.height);

    }

    g2.drawImage(im, x, y, null);

    if (width == -1) {
      width = im.getWidth(null);
    }
    if (height == -1) {
      height = im.getHeight(null);
    }

    return new FormulaDimension(width, height, depth);
  }
Esempio n. 6
0
  private void createGUI() {
    setTitle(textField ? app.getPlain("TextField") : app.getPlain("Button"));
    setResizable(false);

    // create caption panel
    JLabel captionLabel = new JLabel(app.getMenu("Button.Caption") + ":");
    String initString = button == null ? "" : button.getCaption();
    InputPanel ip = new InputPanel(initString, app, 1, 15, true);
    tfCaption = ip.getTextComponent();
    if (tfCaption instanceof AutoCompleteTextField) {
      AutoCompleteTextField atf = (AutoCompleteTextField) tfCaption;
      atf.setAutoComplete(false);
    }

    captionLabel.setLabelFor(tfCaption);
    JPanel captionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    captionPanel.add(captionLabel);
    captionPanel.add(ip);

    // combo box to link GeoElement to TextField
    comboModel = new DefaultComboBoxModel();
    TreeSet sortedSet = app.getKernel().getConstruction().getGeoSetNameDescriptionOrder();

    final JComboBox cbAdd = new JComboBox(comboModel);

    if (textField) {
      // lists for combo boxes to select input and output objects
      // fill combobox models
      Iterator it = sortedSet.iterator();
      comboModel.addElement(null);
      FontMetrics fm = getFontMetrics(getFont());
      int width = (int) cbAdd.getPreferredSize().getWidth();
      while (it.hasNext()) {
        GeoElement geo = (GeoElement) it.next();
        if (!geo.isGeoImage() && !(geo.isGeoButton()) && !(geo.isGeoBoolean())) {
          comboModel.addElement(geo);
          String str = geo.toString();
          if (width < fm.stringWidth(str)) width = fm.stringWidth(str);
        }
      }

      // make sure it's not too wide (eg long GeoList)
      Dimension size =
          new Dimension(
              Math.min(app.getScreenSize().width / 2, width), cbAdd.getPreferredSize().height);
      cbAdd.setMaximumSize(size);
      cbAdd.setPreferredSize(size);

      if (comboModel.getSize() > 1) {

        // listener for the combobox
        MyComboBoxListener ac =
            new MyComboBoxListener() {
              public void doActionPerformed(Object source) {
                GeoElement geo = (GeoElement) cbAdd.getSelectedItem();
                // if (geo == null)
                // {
                //
                //	return;
                // }

                linkedGeo = geo;
                // ((GeoTextField)button).setLinkedGeo(geo);

                cbAdd.removeActionListener(this);

                // cbAdd.setSelectedItem(null);
                cbAdd.addActionListener(this);
              }
            };
        cbAdd.addActionListener(ac);
        cbAdd.addMouseListener(ac);

        captionPanel.add(cbAdd);
      }
    }

    // create script panel
    JLabel scriptLabel = new JLabel(app.getPlain("Script") + ":");
    initString = (button == null) ? "" : button.getClickScript();
    InputPanel ip2 = new InputPanel(initString, app, 10, 40, false);
    tfScript = ip2.getTextComponent();
    if (tfScript instanceof AutoCompleteTextField) {
      AutoCompleteTextField atf = (AutoCompleteTextField) tfScript;
      atf.setAutoComplete(false);
    }

    scriptLabel.setLabelFor(tfScript);
    JPanel scriptPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    scriptPanel.add(scriptLabel);
    scriptPanel.add(ip2);

    JPanel linkedPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JLabel linkedLabel = new JLabel(app.getPlain("LinkedObject") + ":");
    linkedPanel.add(linkedLabel);
    linkedPanel.add(cbAdd);

    // buttons
    btApply = new JButton(app.getPlain("Apply"));
    btApply.setActionCommand("Apply");
    btApply.addActionListener(this);
    btCancel = new JButton(app.getPlain("Cancel"));
    btCancel.setActionCommand("Cancel");
    btCancel.addActionListener(this);
    btPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    btPanel.add(btApply);
    btPanel.add(btCancel);

    // Create the JOptionPane.
    optionPane = new JPanel(new BorderLayout(5, 5));

    // create object list
    optionPane.add(captionPanel, BorderLayout.NORTH);
    if (textField) optionPane.add(linkedPanel, BorderLayout.CENTER);
    else optionPane.add(scriptPanel, BorderLayout.CENTER);
    optionPane.add(btPanel, BorderLayout.SOUTH);
    optionPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // Make this dialog display it.
    setContentPane(optionPane);

    /*

    inputPanel = new InputPanel("ggbApplet.evalCommand('A=(3,4)');", app, 10, 50, false, true, false );
    inputPanel2 = new InputPanel("function func() {\n}", app, 10, 50, false, true, false );

    JPanel centerPanel = new JPanel(new BorderLayout());

    centerPanel.add(inputPanel, BorderLayout.CENTER);
    centerPanel.add(inputPanel2, BorderLayout.SOUTH);
    getContentPane().add(centerPanel, BorderLayout.CENTER);
    //centerOnScreen();

    setContentPane(centerPanel);
    pack();
    setLocationRelativeTo(app.getFrame());	*/
  }
 public void geoElementSelected(GeoElement geo, boolean add) {
   if (geo != null) {
     replaceSelection(" " + geo.getLabel() + " ");
     requestFocusInWindow();
   }
 }
Esempio n. 8
0
  protected void createGUI() {
    setTitle(app.getPlain("Substitute") + " - " + app.getCommand("Row") + " " + (editRow + 1));
    setResizable(true);

    GeoCasCell cell = casView.getConsoleTable().getGeoCasCell(editRow);

    HashSet<GeoElement> vars = cell.getInputVE().getVariables();
    Vector<String> row;
    if (vars != null) {
      data = new Vector<Vector<String>>(vars.size() + 1);
      Iterator<GeoElement> iter = vars.iterator();
      while (iter.hasNext()) {
        row = new Vector<String>(2);
        GeoElement var = iter.next();
        String nextVar = var.getLabel();
        int i = 0;
        for (i = 0; i < data.size(); i++) {
          if (data.get(i).firstElement().compareTo(nextVar) >= 0) {
            break;
          }
        }
        if (i == data.size() || !data.get(i).firstElement().equals(nextVar)) {
          row.add(nextVar);
          row.add("");
          data.insertElementAt(row, i);
        }
      }
    } else {
      data = new Vector<Vector<String>>(1);
    }
    row = new Vector<String>(2);
    row.add("");
    row.add("");
    data.add(row);

    Vector<String> header = new Vector<String>();
    header.add(app.getPlain("OldExpression"));
    header.add(app.getPlain("NewExpression"));
    replaceTable = new JTable(data, header);
    replaceTable.setDefaultEditor(Object.class, new MathTextCellEditor());
    replaceTable.getTableHeader().setReorderingAllowed(false);
    double fontFactor = Math.max(1, app.getGUIFontSize() / DEFAULT_FONT_SIZE);
    replaceTable.setRowHeight((int) (DEFAULT_TABLE_CELL_HEIGHT * fontFactor));

    replaceTable.setPreferredScrollableViewportSize(
        new Dimension(
            (int) (DEFAULT_TABLE_WIDTH * fontFactor), (int) (DEFAULT_TABLE_HEIGHT * fontFactor)));
    scrollPane = new JScrollPane(replaceTable);

    captionPanel = new JPanel(new BorderLayout(5, 0));

    captionPanel.add(scrollPane, BorderLayout.CENTER);

    replaceTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    replaceTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {

              public void valueChanged(ListSelectionEvent e) {
                addRow(false);
              }
            });

    replaceTable.addKeyListener(
        new KeyAdapter() {
          public void keyTyped(KeyEvent e) {
            if (e.getKeyChar() != KeyEvent.CHAR_UNDEFINED && e.getKeyChar() != '\t') addRow(true);
          }
        });

    // buttons
    btEval = new JButton("=");
    btEval.setToolTipText(app.getCommandTooltip("Evaluate"));
    btEval.setActionCommand("Evaluate");
    btEval.addActionListener(this);

    btNumeric = new JButton("\u2248");
    btNumeric.setToolTipText(app.getCommandTooltip("Numeric"));
    btNumeric.setActionCommand("Numeric");
    btNumeric.addActionListener(this);

    btSub = new JButton(app.getPlain("\u2713"));
    btSub.setToolTipText(app.getCommandTooltip("Substitute"));
    btSub.setActionCommand("Substitute");
    btSub.addActionListener(this);

    btPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

    btPanel.add(btEval);
    btPanel.add(btNumeric);
    btPanel.add(btSub);

    // Create the JOptionPane.
    optionPane = new JPanel(new BorderLayout(5, 5));

    // create object list
    optionPane.add(captionPanel, BorderLayout.CENTER);

    optionPane.add(btPanel, BorderLayout.SOUTH);
    optionPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    // Make this dialog display it.
    setContentPane(optionPane);
  }
 public void set(GeoElement geo) {
   if (geo instanceof GeoCoordSys1D) {
     if (!geo.isDefined()) setUndefined();
     else setCoord((GeoCoordSys1D) geo);
   }
 }
Esempio n. 10
0
 public final String toString() {
   return app.getPlain("LineThroughAPerpendicularToB", point.getLabel(), inputOrtho.getLabel());
 }
Esempio n. 11
0
 public void removeFromEuclidianView(GeoElement geo) {
   super.removeFromEuclidianView(geo);
   geo.removeView(getEuclidianView3D());
   getEuclidianView3D().remove(geo);
 }
Esempio n. 12
0
 public void addToEuclidianView(GeoElement geo) {
   super.addToEuclidianView(geo);
   geo.addView(getEuclidianView3D());
   getEuclidianView3D().add(geo);
 }