Example usage for javax.swing.tree DefaultMutableTreeNode getUserObjectPath

List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObjectPath

Introduction

In this page you can find the example usage for javax.swing.tree DefaultMutableTreeNode getUserObjectPath.

Prototype

public Object[] getUserObjectPath() 

Source Link

Document

Returns the user object path, from the root, to get to this node.

Usage

From source file:Main.java

public static boolean recursiveTreeNode(DefaultMutableTreeNode node) {
    if (node == null)
        return false;
    Object[] objs = node.getUserObjectPath();
    if (objs == null)
        return false;
    for (int i = 0; i < objs.length; i++) {
        for (int j = i; j < objs.length; j++) {
            if (i == j)
                continue;
            if (objs[i] == objs[j]) {
                return true;
            }//  w  w w  . j  a  v a 2s  . c  o m
        }
    }
    return false;
}

From source file:jeplus.JEPlusProject.java

/**
 * Read a project from an XML file. The members of this project are not updated.
 * @param fn The File object associated with the file
 * @return a new project instance from the file
 *//*from  ww  w.j  a  v a 2 s .c  o m*/
public static JEPlusProject loadAsXML(File fn) {
    JEPlusProject proj;
    try (XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(fn)))) {
        proj = ((JEPlusProject) decoder.readObject());
    } catch (Exception ex) {
        logger.error("Error loading project from file " + fn, ex);
        return null;
    }
    String dir = fn.getAbsoluteFile().getParent();
    dir = dir.concat(dir.endsWith(File.separator) ? "" : File.separator);
    // proj.updateBaseDir(dir);
    proj.setBaseDir(dir);
    if (proj.ParamFile != null) {
        // Load parameters from text file
        proj.importParameterTableFile(new File(RelativeDirUtil.checkAbsolutePath(proj.ParamFile, dir)));
    } else {
        // Reassign reference to project in all parameters
        if (proj.getParamTree() != null) {
            Enumeration params = proj.getParamTree().breadthFirstEnumeration();
            while (params.hasMoreElements()) {
                ((ParameterItem) ((DefaultMutableTreeNode) params.nextElement()).getUserObject())
                        .setProject(proj);
            }
        }
    }
    // Assign the first branch to the Parameters list
    DefaultMutableTreeNode thisleaf = proj.getParamTree().getFirstLeaf();
    Object[] path = thisleaf.getUserObjectPath();
    proj.setParameters(new ArrayList<ParameterItem>());
    for (Object item : path) {
        proj.getParameters().add((ParameterItem) item);
    }
    // Load Rvx if a RVX file is available
    try {
        proj.Rvx = RVX.getRVX(proj.resolveRVIDir() + proj.getRVIFile());
    } catch (IOException ioe) {
        logger.error("Cannot read the project's RVX file", ioe);
    }

    // done            
    return proj;
}

From source file:jeplus.data.ParameterItem.java

private String[] createFormula(String funcstr) {
    // scan for parameter ids in the given string, and replace them with the corresponding search tag
    // 1. locate this parameter in the tree
    Enumeration nodes = Project.getParamTree().depthFirstEnumeration();
    DefaultMutableTreeNode thisnode = Project.getParamTree();
    while (nodes.hasMoreElements()) {
        thisnode = (DefaultMutableTreeNode) nodes.nextElement();
        if (thisnode.getUserObject() == this) {
            break;
        }/*from  ww  w .  j  a v  a 2 s.c  om*/
    }
    Object[] items = thisnode.getUserObjectPath();
    String newstr = "";
    String bufstr = funcstr;
    for (int i = 0; i < items.length - 1; i++) {
        ParameterItem item = (ParameterItem) items[i];
        newstr = bufstr.replace(item.getID(), item.getSearchString());
        bufstr = newstr;
    }
    return new String[] { "?=" + newstr };
}

From source file:jeplus.data.ParameterItem.java

private String[] createScript(String type, String funcstr) {
    // scan for parameter ids in the given string, and replace them with the corresponding search tag
    // 1. locate this parameter in the tree
    Enumeration nodes = Project.getParamTree().depthFirstEnumeration();
    DefaultMutableTreeNode thisnode = Project.getParamTree();
    while (nodes.hasMoreElements()) {
        thisnode = (DefaultMutableTreeNode) nodes.nextElement();
        if (thisnode.getUserObject() == this) {
            break;
        }/*from   w w  w. jav  a 2 s .  c  om*/
    }
    Object[] items = thisnode.getUserObjectPath();
    // 2. split function string into func name and args
    String[] args = funcstr.split("\\s*,\\s*");
    // 3. get a map from parameter id to search tags
    HashMap<String, String> tagmap = new HashMap<>();
    for (int i = 0; i < items.length - 1; i++) {
        ParameterItem item = (ParameterItem) items[i];
        tagmap.put(item.getID(), item.getSearchString());
    }
    // 4. create script def string
    StringBuilder buf = new StringBuilder("call(").append(type);
    buf.append(", ").append(args[0]);
    for (int i = 1; i < args.length; i++) {
        buf.append(", ");
        if (tagmap.containsKey(args[i])) {
            buf.append(tagmap.get(args[i]));
        } else {
            buf.append(args[i]);
        }
    }
    buf.append(")");
    return new String[] { buf.toString() };
}

From source file:org.kuali.maven.plugins.externals.MojoHelper.java

protected List<Project> getProjectPath(DefaultMutableTreeNode node) {
    Object[] projectObjects = node.getUserObjectPath();
    List<Project> projects = new ArrayList<Project>();
    for (Object projectObject : projectObjects) {
        projects.add((Project) projectObject);
    }/*  w  w  w  . jav  a 2 s. c  om*/
    Collections.reverse(projects);
    return projects;
}

From source file:jeplus.JEPlusProject.java

/**
 * Import parameters in a CSV table (#-commented) and create a new single-branch tree
 * @param file File name of the table//w  ww . j  a  v  a2s  .  c o  m
 * @return import successful or not
 */
public boolean exportParameterTableFile(File file) {
    // Get all parameters in the first branch
    if (ParamTree != null) {
        try (PrintWriter fw = new PrintWriter(new FileWriter(file))) {
            fw.println("# Parameter list for project: " + this.getProjectID() + " (exported at "
                    + new SimpleDateFormat().format(new Date()) + ")");
            fw.println("# Note: this list contains only the first branch of the parameter tree.");
            fw.println("# Parameter definitions in a csv file. Column headings are as below");
            fw.println(
                    "# ID, Name, Parameter Type, Description, Search String, Value Type, Value String, Selected Value Index");
            fw.println(
                    "#           {0}                                         {0, 1, 2}                 {0, .... depending on number of values}");
            fw.println("# ");
            DefaultMutableTreeNode thisleaf = ParamTree.getFirstLeaf();
            Object[] path = thisleaf.getUserObjectPath();
            for (Object obj : path) {
                ParameterItem item = (ParameterItem) obj;
                fw.println(item.toCSVrow());
            }
            return true;
        } catch (Exception ex) {
            logger.error("Error writing parameter table to file " + file.getAbsolutePath(), ex);
        }
    }
    return false;
}

From source file:jeplus.JEPlusProject.java

/**
 * /*from   w ww.j  av  a  2  s . c  o m*/
 * @param sampleSize
 * @param randomsrc
 * @return 
 */
private String[][] getSampleInEqualProbSegments(int sampleSize, Random randomsrc) {
    DefaultMutableTreeNode thisleaf = ParamTree.getFirstLeaf();
    Object[] path = thisleaf.getUserObjectPath();
    int length = path.length + 3; // tree depth plus JobID (reserved space), IDF and Weather
    String[][] SampledValues = new String[length][];
    int n_alt;
    // First element is reserved for job id
    // Weather
    n_alt = this.parseFileListString(this.resolveWeatherDir(), this.getWeatherFile()).size();
    int[] SampledIndex = this.defaultLHSdiscreteSample(sampleSize, n_alt, randomsrc);
    SampledValues[1] = new String[sampleSize];
    for (int j = 0; j < sampleSize; j++) {
        SampledValues[1][j] = Integer.toString(SampledIndex[j]);
    }
    // IDF
    n_alt = this.parseFileListString(this.resolveIDFDir(), this.getIDFTemplate()).size();
    SampledIndex = this.defaultLHSdiscreteSample(sampleSize, n_alt, randomsrc);
    SampledValues[2] = new String[sampleSize];
    for (int j = 0; j < sampleSize; j++) {
        SampledValues[2][j] = Integer.toString(SampledIndex[j]);
    }

    // Parameters
    for (int i = 3; i < length; i++) {
        ParameterItem Param = ((ParameterItem) path[i - 3]);
        if (Param.getValuesString().startsWith("@sample")) {
            // A distribution definition
            SampledValues[i] = this.defaultLHSdistributionSample(sampleSize, Param.getValuesString(),
                    Param.getType(), randomsrc);
        } else {
            // distribution undefined; normal parameter
            n_alt = Param.getNAltValues();
            SampledIndex = this.defaultLHSdiscreteSample(sampleSize, n_alt, randomsrc);
            SampledValues[i] = new String[sampleSize];
            for (int j = 0; j < sampleSize; j++) {
                SampledValues[i][j] = Param.getAlternativeValues()[SampledIndex[j]];
            }
        }
    }
    return SampledValues;
}

From source file:com.lp.client.frame.component.PanelDokumentenablage.java

@Override
public void treeExpanded(TreeExpansionEvent event) {
    if (treeInProgress)
        return;//from   w ww  .  ja v  a 2s.co m
    setBusy(true);

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
    DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode) node.getFirstChild();
    TreePath selectionPath = tree.getSelectionPath();
    if (MUST_LOAD_CHILDREN.equals(firstChild.getUserObject())) {

        node.removeAllChildren();
        DocPath expandPath = new DocPath();

        for (Object obj : node.getUserObjectPath()) {
            try {
                expandPath.add((DocNodeBase) obj);
            } catch (ClassCastException ex) {
                expandPath.add(new DocNodeLiteral(obj.toString()));
            }
        }

        List<DocNodeBase> childList;
        try {
            childList = DelegateFactory.getInstance().getJCRDocDelegate()
                    .getDocNodeChildrenFromNode(expandPath);
            setDocNodesOnTree(node, childList, expandPath);
        } catch (Throwable e) {
            treeModel.insertNodeInto(new DefaultMutableTreeNode(e), node, 0);
        }
        tree.expandPath(new TreePath(node.getPath()));
        tree.setSelectionPath(selectionPath);
    }
    setBusy(false);
}

From source file:com.lp.client.frame.component.PanelDokumentenablage.java

public void valueChanged(TreeSelectionEvent arg0) {

    DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();

    if (tree.getPathBounds(arg0.getPath()) != null)
        tree.scrollRectToVisible(tree.getPathBounds(arg0.getPath()));

    jcrDocDto = null;//from   w  w  w .j  a  v  a  2  s  . c om
    file = null;
    clearComponents();
    enableAllComponents(this, false);
    wcbVersteckteAnzeigen.setEnabled(true);
    wtfSuche.setEditable(true);
    wbuSuche.setEnabled(true);
    wmcMedia.setMimeType(null);
    if (node != null) {
        enableToolsPanelButtons(false, PanelBasis.ACTION_SAVE, PanelBasis.ACTION_DISCARD);
        if (node.getUserObject() instanceof DocNodeBase) {
            Object[] objectPath = node.getUserObjectPath();
            DocPath selectionDocPath = new DocPath();
            for (Object object : objectPath) {
                if (object instanceof DocNodeBase) {
                    selectionDocPath.add((DocNodeBase) object);
                } else if (object instanceof String) {
                    selectionDocPath.add(new DocNodeLiteral(object.toString() + "_string"));
                }
            }
            DocNodeBase selectedDocNode = (DocNodeBase) node.getUserObject();

            if (selectedDocNode.getNodeType() == DocNodeBase.FILE && node.isLeaf()) {
                jcrDocDto = ((DocNodeFile) selectedDocNode).getJcrDocDto();
            } else if (selectedDocNode.getNodeType() == DocNodeBase.VERSION) {
                jcrDocDto = ((DocNodeVersion) selectedDocNode).getJCRDocDto();
            } else {
                jcrDocDto = null;
            }
            if (jcrDocDto != null) {
                if (!jcrDocDto.getbVersteckt() || bVersteckteAnzeigen) {
                    dto2Components();
                    dropArea.setVisible(false);
                    enableToolsPanelButtons(false, PanelBasis.ACTION_NEW, BUTTON_SCAN);
                    enableToolsPanelButtons(
                            selectedDocNode.getNodeType() == DocNodeBase.FILE
                                    || selectedDocNode.getNodeType() == DocNodeBase.VERSION
                                            && bHatMindestensEineSicherheitsStufe() && bHatDokumentenablage,
                            PanelBasis.ACTION_UPDATE);

                    wbuShowDoc.setEnabled(true);
                    wbuSaveDoc.setEnabled(true);
                }
            } else {
                enableToolsPanelButtons(false, PanelBasis.ACTION_UPDATE);
                boolean b = fullDocPath.asDocNodeList().size() > 0 && selectedDocNode instanceof DocNodeJCR
                        && bHatMindestensEineSicherheitsStufe() && bHatDokumentenablage;
                enableToolsPanelButtons(b, PanelBasis.ACTION_NEW, BUTTON_SCAN);
                dropArea.setVisible(b);
            }
        }
    } else {
        enableToolsPanelButtons(false, ACTION_UPDATE, PanelBasis.ACTION_NEW, BUTTON_SCAN);
        dropArea.setVisible(false);
    }
}