public StringBuffer saveStringBuffer() {
   StringBuffer save = new StringBuffer();
   for (java.util.Enumeration<Editor> e = pageList.elements(); e.hasMoreElements(); ) {
     Editor page = e.nextElement();
     save.append(
         "<"
             + name
             + ".Page>\n"
             + "<Type>"
             + typeOfPage(page)
             + "</Type>\n"
             + "<Name>"
             + page.getName()
             + "</Name>\n"
             + "<Active>"
             + page.isActive()
             + "</Active>\n"
             + "<"
             + contentDelim
             + ">\n");
     save.append(page.saveStringBuffer());
     save.append("</" + contentDelim + ">\n" + "</" + name + ".Page>\n");
   }
   return save;
 }
 private void moveUpAndDownPage(boolean _up) {
   int index = tabbedPanel.getSelectedIndex();
   if (index < 0) return;
   Editor page = pageList.get(index);
   if (page == null) return;
   if (_up) {
     if (index == 0) return;
     pageList.removeElementAt(index);
     pageList.insertElementAt(page, index - 1);
     tabbedPanel.removeTabAt(index);
     tabbedPanel.insertTab(
         page.isActive() ? page.getName() : page.getName() + " (D)",
         null,
         page.getComponent(),
         tooltip,
         index - 1);
   } else {
     if (index == (pageList.size() - 1)) return;
     pageList.removeElementAt(index);
     pageList.insertElementAt(page, index + 1);
     tabbedPanel.removeTabAt(index);
     tabbedPanel.insertTab(
         page.isActive() ? page.getName() : page.getName() + " (D)",
         null,
         page.getComponent(),
         tooltip,
         index + 1);
   }
   tabbedPanel.setSelectedComponent(page.getComponent());
   changed = true;
 }
 public StringBuffer generateCode(int _type, String _info) {
   StringBuffer code = new StringBuffer();
   String genName, passName;
   int index = name.lastIndexOf('.');
   if (index >= 0) genName = name.substring(index + 1).toLowerCase();
   else genName = name.toLowerCase();
   if (_info != null && _info.trim().length() > 0) passName = _info;
   else {
     passName = getName();
     if (passName.startsWith("Osejs.")) passName = passName.substring(6);
   }
   index = 0;
   for (Editor editor : pageList) {
     if (editor instanceof CodeEditor) {
       index++;
       ((CodeEditor) editor).setCodeName(genName + index);
     } else if (editor instanceof EquationEditor) {
       index++;
       ((EquationEditor) editor).setCodeName(genName + index);
     }
     // if (editor.isActive())
     code.append(editor.generateCode(_type, passName));
   }
   return code;
 }
 /** Creates a new page of the given type with the given code */
 protected Editor createPage(String _type, String _name, String _code) {
   Editor page = new CodeEditor(ejs, this);
   page.setName(_name);
   if (_code != null) page.readString(_code);
   else page.clear();
   return page;
 }
 private void renameCurrentPage(String _name) {
   int index = tabbedPanel.getSelectedIndex();
   if (index < 0) return;
   _name = getUniqueName(_name); // Gonzalo 070128
   tabbedPanel.setTitleAt(index, _name);
   Editor page = pageList.get(index);
   page.setName(_name);
   if (!page.isActive()) tabbedPanel.setTitleAt(index, page.getName() + " (D)");
   changed = true;
 }
 public void showPage(Editor anEditor) {
   for (int i = 0, n = tabbedPanel.getComponentCount(); i < n; i++) {
     if (tabbedPanel.getComponent(i) == anEditor.getComponent()) {
       //        System.out.println ("Found editor "+anEditor.getName()+ " at i="+i);
       ejs.showPanel(defaultHeader);
       cardLayout.show(finalPanel, anEditor.getName());
       tabbedPanel.setSelectedComponent(anEditor.getComponent());
       return;
     }
   }
 }
 private void copyPage() {
   int index = tabbedPanel.getSelectedIndex();
   if (index < 0) return;
   Editor page = pageList.get(index);
   if (page == null) return;
   addPage(
       typeOfPage(page),
       this.getUniqueName(page.getName()),
       page.saveStringBuffer().toString(),
       true);
   changed = true;
 }
Beispiel #8
0
  public void mousePressed(MouseEvent e) {
    
    // jdf
    if (!isEnabled())
      return;
    
    final int x = e.getX();
    final int y = e.getY();

    int sel = findSelection(x, y);
    ///if (sel == -1) return false;
    if (sel == -1) return;
    currentRollover = -1;

    switch (sel) {
    case RUN:
      editor.handleRun(e.isShiftDown());
      break;

//    case STOP:
//      editor.handleStop();
//      break;
//
    case OPEN:
      popup = menu.getPopupMenu();
      popup.show(EditorToolbar.this, x, y);
      break;

    case NEW:
      if (shiftPressed) {
        editor.base.handleNew();
      } else {
      editor.base.handleNewReplace();
      }
      break;

    case SAVE:
      editor.handleSave(false);
      break;

    case EXPORT:
      boolean t = e.isControlDown();
      editor.handleExport(e.isShiftDown(),autoOpenSerialMonitor ? !t : t); // Control is down if autoOpenSerialMonitor is true in preferences
      break;

    case SERIAL:
      editor.handleSerial();
      handleMouse(e);
      break;
    }
  }
Beispiel #9
0
 /** Add an assignment to a specific client for processing. */
 public void addAssignment(int ClientID, Assignment a) throws Exception {
   try {
     editor.addAssignment(ClientID, a);
   } catch (Exception e) {
     throw (e);
   }
 }
Beispiel #10
0
 /** Add an assignment to the Editor for processing. */
 public void addAssignment(Assignment a) throws Exception {
   try {
     editor.addAssignment(a);
   } catch (Exception e) {
     throw (e);
   }
 }
Beispiel #11
0
  /**
   * shows a color chooser dialog
   *
   * @param initialColor the initial Color set when the color-chooser is shown
   * @return the selected color or <code>null</code> if the user opted out
   */
  public Color showColorChooserDialog(Color initialColor) {

    setColor(initialColor);
    SVGColorTracker ok = new SVGColorTracker(this);
    JDialog dialog = createDialog(Editor.getParent(), "", true, this, ok, null);
    dialog.setVisible(true);

    return ok.getColor();
  }
 private void toggleCurrentPage() {
   int index = tabbedPanel.getSelectedIndex();
   if (index < 0) return;
   Editor page = pageList.get(index);
   if (page.isActive()) {
     page.setActive(false);
     tabbedPanel.setTitleAt(index, page.getName() + " (D)");
   } else {
     page.setActive(true);
     tabbedPanel.setTitleAt(index, page.getName());
   }
   changed = true;
   ejs.getModelEditor().getVariablesEditor().updateControlValues(false);
 }
  public void mousePressed(MouseEvent e) {
    final int x = e.getX();
    final int y = e.getY();

    int sel = findSelection(x, y);
    /// if (sel == -1) return false;
    if (sel == -1) return;
    currentRollover = -1;
    // int currentSelection = sel;
    // if (!(disableRun && ((sel == RUN) || (sel == STOP)))) {
    // moving the handling of this over into the editor
    // setState(sel, ACTIVE, true);
    // }

    // if (currentSelection == OPEN) {
    // switch (currentSelection) {
    switch (sel) {
      case RUN:
        // if (!disableRun) {
        editor.handleRun(e.isShiftDown());
        // }
        break;

      case STOP:
        // if (!disableRun) {
        // setState(RUN, INACTIVE, true);
        // setInactive();
        editor.handleStop();
        // }
        break;

      case OPEN:
        if (popup == null) {
          // popup = new JPopupMenu();
          popup = editor.sketchbook.getPopupMenu();
          // no events properly being fired, so nevermind
          /*
          popup.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                System.out.println("action " + e);
              }
            });
          popup.addComponentListener(new ComponentAdapter() {
              public void componentHidden(ComponentEvent e) {
                System.out.println("hidden " + e);
              }
            });
          */
          add(popup);
        }
        // activate(OPEN);
        // SwingUtilities.invokeLater(new Runnable() {
        // public void run() {
        popup.show(EditorButtons.this, x, y);
        // }});
        break;

      case NEW:
        editor.handleNew(e.isShiftDown());
        break;

      case SAVE:
        editor.handleSave(false);
        break;

      case EXPORT:
        editor.handleExport();
        break;

      case SERIAL:
        editor.handleSerial();
        break;
    }
  }
 public void statusError(String what) {
   super.statusError(what);
   //    new Exception("deactivating RUN").printStackTrace();
   toolbar.deactivate(JavaToolbar.RUN);
 }
 public void handleSave() {
   toolbar.activate(JavaToolbar.SAVE);
   // handleStop();
   super.handleSave(true);
   toolbar.deactivate(JavaToolbar.SAVE);
 }
Beispiel #16
0
 /** An editor represents the server for distributing Assignments. And is required. */
 public void setEditor(Editor editor) {
   this.editor = editor;
   editor.setIParty(this);
 }
Beispiel #17
0
 /** An editor represents the server for distributing Assignments. And is required. */
 public IParty(Editor editor) {
   this.editor = editor;
   editor.setIParty(this);
 }
 protected void addPage(String _typeOfPage, String _name, String _code, boolean _enabled) {
   cardLayout.show(finalPanel, "TabbedPanel");
   _name = getUniqueName(_name);
   Editor page = createPage(_typeOfPage, _name, _code);
   page.setFont(myFont);
   page.setColor(myColor);
   int index = tabbedPanel.getSelectedIndex();
   if (index == -1) {
     pageList.addElement(page);
     if (tabbedPanel.getTabCount() == 0) {
       tabbedPanel.addTab(
           page.getName(),
           null,
           page.getComponent(),
           tooltip); // This causes an exception sometimes
     } else {
       tabbedPanel.insertTab(
           page.getName(), null, page.getComponent(), tooltip, tabbedPanel.getTabCount());
     }
     index = 0;
   } else {
     index++;
     pageList.insertElementAt(page, index);
     tabbedPanel.insertTab(page.getName(), null, page.getComponent(), tooltip, index);
   }
   tabbedPanel.setSelectedComponent(page.getComponent());
   page.setActive(_enabled);
   if (!_enabled) tabbedPanel.setTitleAt(index, page.getName() + " (D)");
   updatePageCounterField(pageList.size());
   // tabbedPanel.validate(); This hangs the computer when reading a file at start-up !!!???
   tabbedPanel.repaint();
   changed = true;
 }
  public SketchProperties(Editor e, Sketch s) {
    super();

    editor = e;
    sketch = s;

    fields = new HashMap<String, JComponent>();

    this.setPreferredSize(new Dimension(500, 400));
    this.setMinimumSize(new Dimension(500, 400));
    this.setMaximumSize(new Dimension(500, 400));
    this.setSize(new Dimension(500, 400));
    Point eLoc = editor.getLocation();
    int x = eLoc.x;
    int y = eLoc.y;

    Dimension eSize = editor.getSize();
    int w = eSize.width;
    int h = eSize.height;

    int cx = x + (w / 2);
    int cy = y + (h / 2);

    this.setLocation(new Point(cx - 250, cy - 200));
    this.setModal(true);

    outer = new JPanel(new BorderLayout());
    outer.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    this.add(outer);

    win = new JPanel();
    win.setLayout(new BorderLayout());
    outer.add(win, BorderLayout.CENTER);

    buttonBar = new JPanel(new FlowLayout(FlowLayout.RIGHT));

    saveButton = new JButton("OK");
    saveButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            save();
            SketchProperties.this.dispose();
          }
        });

    cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            SketchProperties.this.dispose();
          }
        });

    buttonBar.add(saveButton);
    buttonBar.add(cancelButton);

    win.add(buttonBar, BorderLayout.SOUTH);

    tabs = new JTabbedPane();

    overviewPane = new JPanel();
    overviewPane.setLayout(new BoxLayout(overviewPane, BoxLayout.PAGE_AXIS));
    overviewPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    addTextField(overviewPane, "author", "Sketch author:");
    addTextArea(overviewPane, "summary", "Summary:");
    addTextArea(overviewPane, "license", "Copyright / License:");
    tabs.add("Overview", overviewPane);

    objectsPane = new JPanel();
    objectsPane.setLayout(new BoxLayout(objectsPane, BoxLayout.PAGE_AXIS));
    objectsPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    addTextField(objectsPane, "board", "Board:");
    addTextField(objectsPane, "core", "Core:");
    addTextField(objectsPane, "compiler", "Compiler:");
    addTextField(objectsPane, "port", "Serial port:");
    addTextField(objectsPane, "programmer", "Programmer:");
    JButton setDef = new JButton("Set to current IDE values");
    setDef.setMaximumSize(setDef.getPreferredSize());
    setDef.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setObjectValues();
          }
        });
    objectsPane.add(Box.createVerticalGlue());
    objectsPane.add(setDef);

    tabs.add("Objects", objectsPane);

    win.add(tabs, BorderLayout.CENTER);

    this.setTitle("Sketch Properties");

    this.pack();
    this.setVisible(true);
  }
 public void mousePressed(MouseEvent me) {
   super.mousePressed(me);
   Editor ce = Globals.curEditor();
   Selection sel = ce.getSelectionManager().findSelectionFor(this);
   if (sel instanceof SelectionComponentInstance) ((SelectionComponentInstance) sel).hideButtons();
 }