예제 #1
0
 @Override
 public void mouseClicked(MouseEvent me) {
   Element el = doc.getCharacterElement(viewToModel(me.getPoint()));
   if (el == null) return;
   AttributeSet as = el.getAttributes();
   if (as.isDefined("ip")) {
     String ip = (String) as.getAttribute("ip");
     ScriptException se = (ScriptException) as.getAttribute("exception");
     Node node = net.getAtIP(ip);
     if (node == null) {
       Utility.displayError("Error", "Computer does not exist");
       return;
     }
     String errorString =
         "--ERROR--\n"
             + "Error at line number "
             + se.getLineNumber()
             + " and column number "
             + se.getColumnNumber()
             + "\n"
             + se.getMessage();
     new ScriptDialog(
             parentFrame,
             str -> {
               if (str != null) {
                 node.setScript(str);
               }
             },
             node.getScript(),
             errorString)
         .setVisible(true);
   }
 }
 @Override
 public void performCopy(DataContext dataContext) {
   final Node selectedNode = getSelectedNode();
   assert selectedNode != null;
   final String plainText = selectedNode.getText(UsageViewImpl.this);
   CopyPasteManager.getInstance().setContents(new StringSelection(plainText.trim()));
 }
예제 #3
0
 FoundItem getFoundItem(Node n, String text) {
   String s = n.getNodeValue();
   if (s == null) s = n.getNodeName();
   String string;
   if (text != null) {
     int index = s.indexOf(text);
     int left = Math.max(0, index - 5);
     int right = Math.min(s.length(), index + text.length() + 20);
     string = s.substring(left, right);
   } else string = s;
   TreeNode tn = jtree.getTreeNode(n);
   TreePath tp = getTreePath(tn);
   return new FoundItem(string, tp);
 }
  static DivisionOperatorWorkspaceObject load(Node node) throws ProgramLoadingException {
    if (!node.getNodeName().equals("division")) throw new ProgramLoadingException();

    DivisionOperatorWorkspaceObject obj =
        new DivisionOperatorWorkspaceObject(Workspace.getWorkspace());
    Node lop = Workspace.getChildElementByName(node, "loperand");
    Node rop = Workspace.getChildElementByName(node, "roperand");

    if (lop != null) {
      Node lopNode = Workspace.getNthChildElement(lop, 0);
      if (lopNode != null) {
        WorkspaceObject lopObj = Workspace.dispatchLoad(lopNode);
        if (lopObj != null) {
          obj.leftSink.progCombine(lopObj);
        }
      }
    }

    if (rop != null) {
      Node ropNode = Workspace.getNthChildElement(rop, 0);
      if (ropNode != null) {
        WorkspaceObject ropObj = Workspace.dispatchLoad(ropNode);
        if (ropObj != null) {
          obj.rightSink.progCombine(ropObj);
        }
      }
    }

    return obj;
  }
 private void checkNodeValidity(@NotNull DefaultMutableTreeNode node) {
   Enumeration enumeration = node.children();
   while (enumeration.hasMoreElements()) {
     checkNodeValidity((DefaultMutableTreeNode) enumeration.nextElement());
   }
   if (node instanceof Node && node != getModelRoot()) ((Node) node).update(this);
 }
예제 #6
0
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      if (isSelected) this.setBackground(table.getSelectionBackground());
      else this.setBackground(table.getBackground());

      Node node = nodes.get(row);
      Request request = nodeIDToRequest.get(node.getNodeID());
      if (request == null) {
        this.setString("NONE");
        this.setValue(0);
      } else {
        int percent = (int) Math.round(request.getPercentDone());
        this.setString(request.getType().toString() + "  " + percent + "%");
        this.setValue(percent);
      }
      return this;
    }
  // ActionListener Interface
  public void actionPerformed(ActionEvent e) {
    OutlinerDocument doc = (OutlinerDocument) Outliner.documents.getMostRecentDocumentTouched();
    OutlinerCellRendererImpl textArea = doc.panel.layout.getUIComponent(doc.tree.getEditingNode());

    if (textArea == null) {
      return;
    }

    Node node = textArea.node;
    JoeTree tree = node.getTree();
    OutlineLayoutManager layout = tree.getDocument().panel.layout;

    if (doc.tree.getComponentFocus() == OutlineLayoutManager.TEXT) {
      ToggleEditableAction.toggleEditableInheritanceText(node, tree, layout);
    } else if (doc.tree.getComponentFocus() == OutlineLayoutManager.ICON) {
      ToggleEditableAction.toggleEditableInheritance(node, tree, layout);
    }
  }
 private Node findNode(Node node, AminoPoint pt) {
   if (!node.isVisible()) return null;
   if (node.contains(pt)) return node;
   if (node instanceof Parent) {
     Parent parent = (Parent) node;
     if (parent.hasChildren()) {
       AminoPoint nc = parent.convertToChildCoords(pt);
       for (int i = parent.childCount() - 1; i >= 0; i--) {
         Node n2 = findNode(parent.getChild(i), nc);
         // u.p("Found " + n2);
         if (n2 != null) {
           return n2;
         }
       }
     }
   }
   return null;
 }
 /* nodes with non-valid data are not included */
 private static Navigatable[] getNavigatablesForNodes(Node[] nodes) {
   if (nodes == null) {
     return null;
   }
   final List<Navigatable> result = new ArrayList<Navigatable>();
   for (final Node node : nodes) {
     /*
     if (!node.isDataValid()) {
       continue;
     }
     */
     Object userObject = node.getUserObject();
     if (userObject instanceof Navigatable) {
       result.add((Navigatable) userObject);
     }
   }
   return result.toArray(new Navigatable[result.size()]);
 }
예제 #10
0
 public void actionPerformed(ActionEvent event) {
   JTree tree = getTree();
   TreePath path = tree.getSelectionPath();
   if (path == null) {
     sheet.getLogger().warning("Warning: User must select a node to delete");
     // XXX add message telling users to select a node
   } else {
     Node selected = (Node) path.getLastPathComponent();
     try {
       Node parent = selected.getParent();
       if (parent != null) {
         parent.removeChild(selected);
         select(parent);
       }
     } catch (UnsupportedOperationException uox) {
       sheet.getLogger().warning("Cannot delete node: " + selected);
     }
   }
 }
    @Override
    public void calcData(final DataKey key, final DataSink sink) {
      Node node = getSelectedNode();

      if (key == PlatformDataKeys.PROJECT) {
        sink.put(PlatformDataKeys.PROJECT, myProject);
      } else if (key == USAGE_VIEW_KEY) {
        sink.put(USAGE_VIEW_KEY, UsageViewImpl.this);
      } else if (key == PlatformDataKeys.NAVIGATABLE_ARRAY) {
        sink.put(PlatformDataKeys.NAVIGATABLE_ARRAY, getNavigatablesForNodes(getSelectedNodes()));
      } else if (key == PlatformDataKeys.EXPORTER_TO_TEXT_FILE) {
        sink.put(PlatformDataKeys.EXPORTER_TO_TEXT_FILE, myTextFileExporter);
      } else if (key == USAGES_KEY) {
        final Set<Usage> selectedUsages = getSelectedUsages();
        sink.put(
            USAGES_KEY,
            selectedUsages != null
                ? selectedUsages.toArray(new Usage[selectedUsages.size()])
                : null);
      } else if (key == USAGE_TARGETS_KEY) {
        sink.put(USAGE_TARGETS_KEY, getSelectedUsageTargets());
      } else if (key == PlatformDataKeys.VIRTUAL_FILE_ARRAY) {
        final Set<Usage> usages = getSelectedUsages();
        Usage[] ua = usages != null ? usages.toArray(new Usage[usages.size()]) : null;
        VirtualFile[] data = UsageDataUtil.provideVirtualFileArray(ua, getSelectedUsageTargets());
        sink.put(PlatformDataKeys.VIRTUAL_FILE_ARRAY, data);
      } else if (key == PlatformDataKeys.HELP_ID) {
        sink.put(PlatformDataKeys.HELP_ID, HELP_ID);
      } else if (key == PlatformDataKeys.COPY_PROVIDER) {
        sink.put(PlatformDataKeys.COPY_PROVIDER, this);
      } else if (node != null) {
        Object userObject = node.getUserObject();
        if (userObject instanceof TypeSafeDataProvider) {
          ((TypeSafeDataProvider) userObject).calcData(key, sink);
        } else if (userObject instanceof DataProvider) {
          DataProvider dataProvider = (DataProvider) userObject;
          Object data = dataProvider.getData(key.getName());
          if (data != null) {
            sink.put(key, data);
          }
        }
      }
    }
 public void mouseReleased(MouseEvent e) {
   _mouse_pressed = false;
   _drag_target = null;
   // send target node event first
   Node node = window.findNode(new AminoPoint(e.getPoint().getX(), e.getPoint().getY()));
   // console.log(node);
   MEvent evt = new MEvent();
   evt.node = node;
   evt.x = e.getX();
   evt.y = e.getY();
   if (node != null) {
     Node start = node;
     while (start != null) {
       fireEvent("MOUSE_RELEASE", start, evt);
       if (start.isMouseBlocked()) return;
       start = (Node) start.getParent();
     }
   }
   // send general events next
   fireEvent("MOUSE_RELEASE", null, evt);
 }
예제 #13
0
  @Override
  public void actionPerformed(ActionEvent e) {
    // System.out.println("MergeAction");

    OutlinerCellRendererImpl textArea = null;
    boolean isIconFocused = true;
    Component c = (Component) e.getSource();
    if (c instanceof OutlineButton) {
      textArea = ((OutlineButton) c).renderer;
    } else if (c instanceof OutlineLineNumber) {
      textArea = ((OutlineLineNumber) c).renderer;
    } else if (c instanceof OutlineCommentIndicator) {
      textArea = ((OutlineCommentIndicator) c).renderer;
    } else if (c instanceof OutlinerCellRendererImpl) {
      textArea = (OutlinerCellRendererImpl) c;
      isIconFocused = false;
    }

    // Shorthand
    Node node = textArea.node;
    JoeTree tree = node.getTree();
    OutlineLayoutManager layout = tree.getDocument().panel.layout;

    // System.out.println(e.getModifiers());
    switch (e.getModifiers()) {
      case 2:
        if (isIconFocused) {
          merge(node, tree, layout, false);
        }
        break;

      case 3:
        if (isIconFocused) {
          merge(node, tree, layout, true);
        }
        break;
    }
  }
  static RandomIntegerWorkspaceObject load(Node node) throws ProgramLoadingException {
    if (!node.getNodeName().equals("randint")) throw new ProgramLoadingException();

    RandomIntegerWorkspaceObject obj = new RandomIntegerWorkspaceObject(Workspace.getWorkspace());

    Node subNode = Workspace.getNthChildElement(node, 0);
    if (subNode != null) {
      WorkspaceObject wsObj = Workspace.dispatchLoad(subNode);
      if (wsObj != null) {
        obj.sink.progCombine(wsObj);
      }
    }
    return obj;
  }
    public void mouseDragged(MouseEvent e) {
      if (_mouse_pressed) {
        Node node = window.findNode(new AminoPoint(e.getPoint().getX(), e.getPoint().getY()));
        MEvent evt = new MEvent();

        // redirect events to current drag target, if applicable
        if (_drag_target != null) {
          node = _drag_target;
        }
        evt.node = node;
        evt.x = e.getX();
        evt.y = e.getY();
        if (node != null) {
          Node start = node;
          while (start != null) {
            fireEvent("MOUSE_DRAG", start, evt);
            if (start.isMouseBlocked()) return;
            start = (Node) start.getParent();
          }
        }
        // send general events next
        fireEvent("MOUSE_DRAG", null, evt);
      }
    }
예제 #16
0
  public synchronized Object getValueAt(int row, int col) {
    Node node = nodes.get(row);

    switch (col) {
      case 0:
        return node.getNodeID();
      case 1:
        return node.getCurrState();
      case 2:
        return node.getTailBlockID();
      case 3:
        return node.getHeadBlockID();
      case 4:
        return node.getLocalTime();
      case 5:
        return node.getGlobalTime();
      case 6:
        return node.getIsTimeSynchronized();
      case 7:
        return new LastRequestCellRendererClass();
      default:
        return "UNKNOWN";
    }
  }
예제 #17
0
  // IconFocusedMethods
  public static void merge(
      Node currentNode, JoeTree tree, OutlineLayoutManager layout, boolean withSpaces) {
    JoeNodeList nodeList = tree.getSelectedNodes();

    // Get merged text
    StringBuffer buf = new StringBuffer();
    boolean didMerge = false;

    if (withSpaces) {
      for (int i = 0, limit = nodeList.size(); i < limit; i++) {
        Node node = nodeList.get(i);

        // Skip if node is not editable
        if (!node.isEditable()) {
          continue;
        }

        didMerge = true;
        node.getMergedValueWithSpaces(buf, i);
      }
    } else {
      for (int i = 0, limit = nodeList.size(); i < limit; i++) {
        Node node = nodeList.get(i);

        // Skip if node is not editable
        if (!node.isEditable()) {
          continue;
        }

        didMerge = true;
        node.getMergedValue(buf);
      }
    }

    // It's possible all nodes were read-only. If so then abort.
    if (!didMerge) {
      return;
    }

    // Get youngest editable node
    Node youngestNode = null;
    for (int i = 0, limit = nodeList.size(); i < limit; i++) {
      Node node = nodeList.get(i);

      if (node.isEditable()) {
        youngestNode = node;
        break;
      }
    }

    // Abort if no editable nodes found.
    if (youngestNode == null) {
      return;
    }

    Node parent = youngestNode.getParent();
    CompoundUndoableReplace undoable = new CompoundUndoableReplace(parent);

    Node newNode = new NodeImpl(tree, buf.toString());
    newNode.setDepth(youngestNode.getDepth());
    newNode.setCommentState(youngestNode.getCommentState());

    undoable.addPrimitive(new PrimitiveUndoableReplace(parent, youngestNode, newNode));

    // Iterate over the remaining selected nodes deleting each one
    int mergeCount = 1;
    for (int i = 0, limit = nodeList.size(); i < limit; i++) {
      Node node = nodeList.get(i);

      // Abort if node is not editable
      if (!node.isEditable() || node == youngestNode) {
        continue;
      }

      undoable.addPrimitive(new PrimitiveUndoableReplace(parent, node, null));
      mergeCount++;
    }

    if (!undoable.isEmpty()) {
      if (withSpaces) {
        if (mergeCount == 1) {
          undoable.setName("Merge Node with Spaces");
        } else {
          undoable.setName(
              new StringBuffer()
                  .append("Merge ")
                  .append(mergeCount)
                  .append(" Nodes with Spaces")
                  .toString());
        }
      } else {
        if (mergeCount == 1) {
          undoable.setName("Merge Node");
        } else {
          undoable.setName(
              new StringBuffer().append("Merge ").append(mergeCount).append(" Nodes").toString());
        }
      }
      tree.getDocument().getUndoQueue().add(undoable);
      undoable.redo();
    }

    return;
  }