Package org.openquark.gems.client

Examples of org.openquark.gems.client.Gem


        // We want to show the proper gem inputs too.
        Gem.PartInput[] inputs = gem.getInputParts();
        for (final PartInput input : inputs) {
           
            if (input.isConnected()) {
                Gem sourceGem = input.getConnection().getSource().getGem();
                node.add(growTree(sourceGem));
               
            } else {
                ExplorerInputNode mutableTreeNode = createNewExplorerGemNode(input);
                node.add(mutableTreeNode);       
View Full Code Here


    /**
     * @see org.openquark.gems.client.GemGraphChangeListener#gemRemoved(GemGraphRemovalEvent)
     */
    public void gemRemoved(GemGraphRemovalEvent e) {
       
        Gem gem = (Gem)e.getSource();
       
        // If we want to remove a gem, we need to remove all of its inputs from our cache
        // we also need to add its dependents onto the root. (We shouldn't really have to, since the gemGraph should've done
        // disconnections before the deletion. but just to be safe
        ExplorerGemNode node = gemToNodesMap.get(gem);
       
        // This is possible, in the case of unconnected emitters and thus is nothing to worry about.
        if (node == null) {
            return;
        }
       
        for (int i = 0; i < node.getChildCount(); i++) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode)node.getChildAt(i);
           
            // So if it was an input, we remove it from our map, if it's a gem, then we disconect it by adding
            // it onto the root
            if (child instanceof ExplorerInputNode) {
                ExplorerInputNode inputNode = (ExplorerInputNode) child;
                inputsToNodeMap.remove(inputNode.getPartInput());
                i--;
            } else {
                explorerTreeRoot.add(child);
            }
           
            child.removeFromParent();
        }
       
        // We need to recreate the input of this node's parent (There was no input node because that spot was taken up by this gem
        // we go through the inputs and if the input doesn't exist, we create it.
        DefaultMutableTreeNode parent  =(DefaultMutableTreeNode)node.getParent();
        if (parent instanceof ExplorerGemNode) {
            ExplorerGemNode explorerGemNode = (ExplorerGemNode) parent;
            Gem parentGem = explorerGemNode.getGem();
           
            // cycle through the input parts and see if they are all there.
            Gem.PartInput[] inputs = parentGem.getInputParts();
            for (int i = 0; i < inputs.length; i++) {
                // we create a new input only if there's supposed to be an input there!
                if (!inputsToNodeMap.containsKey(inputs[i]) && !inputs[i].isConnected()) {
                    ExplorerInputNode mutableTreeNode = createNewExplorerGemNode(inputs[i]);
                    parent.add(mutableTreeNode);       
View Full Code Here

     * @see org.openquark.gems.client.GemGraphChangeListener#gemDisconnected(GemGraphDisconnectionEvent)
     */
    public void gemDisconnected(GemGraphDisconnectionEvent e) {
       
        Connection connection = (Connection)e.getSource();
        Gem sourceGem = connection.getSource().getGem();
        Gem destinationGem = connection.getDestination().getGem();
        ExplorerGemNode sourceGemNode = gemToNodesMap.get(sourceGem);
        ExplorerGemNode destinationGemNode = gemToNodesMap.get(destinationGem);
       
        // This scope may not be showing the gem that triggered the event so there may be nothing to do.
        if (sourceGemNode == null) {
            return;
        }

        // We add the disconnected node (the source gem) onto the root.
        sourceGemNode.removeFromParent();
        explorerTreeRoot.add(sourceGemNode);
       
        // Add the missing input to the destination gem's node.
        Gem.PartInput[] inputs = destinationGem.getInputParts();
        for (int i = 0; i < inputs.length; i++) {
            if (!inputsToNodeMap.containsKey(inputs[i]) && !inputs[i].isConnected()) {
                ExplorerInputNode inputNode = createNewExplorerGemNode(inputs[i]);   
                inputsToNodeMap.put(inputs[i], inputNode);
                destinationGemNode.insert(inputNode, i);
View Full Code Here

            child.removeFromParent();
            inputsToNodeMap.remove(child.getUserObject());
        }
       
        // And repopulate with the new ones. (provided that they are not connected)
        Gem gem = explorerGemNode.getGem();
        Gem.PartInput[] partInputs = gem.getInputParts();
       
        for (final PartInput partInput : partInputs) {
           
            if (partInput.isConnected()) {
               
                // Due to the order that the events are handled, it is possible that the gem to which this input is
                // connected has not been added to the tree yet.
                // If this is the case, then a new node will be created for it (even though the tree will likely be
                // rebuilt with the new structure afterwards anyway).
                Gem sourceGem = partInput.getConnectedGem();
                ExplorerGemNode source = gemToNodesMap.containsKey(sourceGem) ? gemToNodesMap.get(sourceGem) : createNewExplorerGemNode(sourceGem);               

                // This is done for a special reason
                // in a connection to a code gem, where the type of the expression was ambiguous,
                // a definition update event may be generated, and in fact, it is generated before the connection
View Full Code Here

        // Now we 'tweak' the component a bit to get the look we want.
        if (value instanceof ExplorerGemNode) {

            ExplorerGemNode explorerNode = (ExplorerGemNode) value;
            Gem gem = explorerNode.getGem();

            // Get the customized name and icon
            customIcon = getGemDisplayIcon(gem);
            customText = getGemDisplayString(gem);           
View Full Code Here

       
        // If we are dragging the gems...
        if (treeNode instanceof ExplorerGemNode) {
            ExplorerGemNode explorerGemNode = (ExplorerGemNode) treeNode;
           
            Gem gem = explorerGemNode.getGem();
           
            if (gem instanceof CollectorGem) {
                CollectorGem collectorGem = (CollectorGem) gem;
                gem = new ReflectorGem(collectorGem);
            }
View Full Code Here

    /**
     * @see javax.swing.tree.DefaultMutableTreeNode#add(javax.swing.tree.MutableTreeNode)
     * This method searches the children (using binary search) and inserts the gem in the right place
     */
    public void add(ExplorerGemNode gemNode){
        Gem gem1 = gemNode.getGem();
        int lowerBound = 0;
        int upperBound = getChildCount();
        while (upperBound - lowerBound > 3) {
            int i = (upperBound + lowerBound) / 2;
            int results =  rootSorter.compare(gem1, ((ExplorerGemNode)getChildAt(i)).getGem());
View Full Code Here

     * i specified
     * @param gemNode
     * @param startingIndex the starting index
     */
    private void insertSearchingFrom(ExplorerGemNode gemNode, int startingIndex){
        Gem gem = gemNode.getGem();
       
        for (int size = getChildCount(); startingIndex < size; startingIndex++) {
            if (rootSorter.compare(gem, ((ExplorerGemNode)getChildAt(startingIndex)).getGem()) < 0) {
                break;
            }
View Full Code Here

        CollectorGem listCollector = new CollectorGem();
        listCollector.setName("list");
        gemGraph.addGem(listCollector);
       
        // Construct the test for checking whether the 'list' value is the empty list.
        Gem isEmptyGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.isEmpty);
        gemGraph.addGem(isEmptyGem);
       
        ReflectorGem listReflector1 = new ReflectorGem(listCollector);
        gemGraph.addGem(listReflector1);

        // Construct the gem tree for the case when 'list' is not empty.
       
        // The head of the returned Cons is: mapFunction (List.head list)
        // which uses the apply gem to apply the mapFunction to its argument.
        gemGraph.connectGems(listReflector1.getOutputPart(), isEmptyGem.getInputPart(0));

        Gem headGem = gemFactory.makeFunctionalAgentGem(CAL_List.Functions.head);
        gemGraph.addGem(headGem);
       
        ReflectorGem listReflector2 = new ReflectorGem(listCollector);
        gemGraph.addGem(listReflector2);
       
        gemGraph.connectGems(listReflector2.getOutputPart(), headGem.getInputPart(0));
       
        Gem applyGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.apply);
        gemGraph.addGem(applyGem);
       
        ReflectorGem mapFunctionReflector1 = new ReflectorGem(mapFunctionCollector);
        gemGraph.addGem(mapFunctionReflector1);
       
        gemGraph.connectGems(mapFunctionReflector1.getOutputPart(), applyGem.getInputPart(0));
        gemGraph.connectGems(headGem.getOutputPart(), applyGem.getInputPart(1));
       
        // The tail of the returned Cons is: demoMap mapFunction (List.tail list)
        Gem tailGem = gemFactory.makeFunctionalAgentGem(CAL_List.Functions.tail);
        gemGraph.addGem(tailGem);

        ReflectorGem listReflector3 = new ReflectorGem(listCollector);
        gemGraph.addGem(listReflector3);
       
        gemGraph.connectGems(listReflector3.getOutputPart(), tailGem.getInputPart(0));
       
        ReflectorGem demoMapReflector = new ReflectorGem(gemGraph.getTargetCollector());
        gemGraph.addGem(demoMapReflector);
       
        ReflectorGem mapFunctionReflector2 = new ReflectorGem(mapFunctionCollector);
        gemGraph.addGem(mapFunctionReflector2);
       
        Gem consGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.DataConstructors.Cons);
        gemGraph.addGem(consGem);
       
        gemGraph.connectGems(applyGem.getOutputPart(), consGem.getInputPart(0));
        gemGraph.connectGems(demoMapReflector.getOutputPart(), consGem.getInputPart(1));
       
        // Construct the conditional branch (using the iff gem). The false case returns the value
        // generated by the gem tree defined above. In the true case, Nil (the empty list) is returned.
        Gem iffGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.iff);
        gemGraph.addGem(iffGem);
       
        Gem nilGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.DataConstructors.Nil);
        gemGraph.addGem(nilGem);
       
        gemGraph.connectGems(isEmptyGem.getOutputPart(), iffGem.getInputPart(0));
        gemGraph.connectGems(nilGem.getOutputPart(), iffGem.getInputPart(1));
        gemGraph.connectGems(consGem.getOutputPart(), iffGem.getInputPart(2));
       
        // Connect the gems to the target collector
        gemGraph.connectGems(iffGem.getOutputPart(), gemGraph.getTargetCollector().getInputPart(0));
       
View Full Code Here

        // 7) Typecheck the GemGraph to ensure that it is consistent
       
        GemGraph gemGraph = new GemGraph();
        gemGraph.getTargetCollector().setName("factorial");
       
        Gem productGem = gemFactory.makeFunctionalAgentGem(CAL_List.Functions.product);
        gemGraph.addGem(productGem);
       
        Gem upFromToGem = gemFactory.makeFunctionalAgentGem(CAL_Prelude.Functions.upFromTo);
        gemGraph.addGem(upFromToGem);

        // Create a Value gem to represent a BigInteger (Prelude.Integer) value for the number 1.
        Gem oneGem = new ValueGem(new LiteralValueNode(BigInteger.valueOf(1), calServices.getPreludeTypeConstants().getIntegerType()));
           
        gemGraph.addGem(oneGem);
       
        gemGraph.connectGems(oneGem.getOutputPart(), upFromToGem.getInputPart(0));
       
        gemGraph.connectGems(upFromToGem.getOutputPart(), productGem.getInputPart(0));
       
        gemGraph.connectGems(productGem.getOutputPart(), gemGraph.getTargetCollector().getInputPart(0));
       
View Full Code Here

TOP

Related Classes of org.openquark.gems.client.Gem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.