private void createRatTreeNodes(DefaultMutableTreeNode parentNode, RandomUnitGenerator.RatTreeNode ratTreeNode) { for (RandomUnitGenerator.RatTreeNode child : ratTreeNode.children) { DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(child.name); if (child.children.size() > 0) { createRatTreeNodes(newNode, child); } parentNode.add(newNode); } }
private TreePath findPathByName(String[] nodeNames) { TreeNode root = (TreeNode)m_treeRAT.getModel().getRoot(); return findNextNode(new TreePath(root), nodeNames, 0); }
.getString("RandomArmyDialog.ratStatusLoading")); updatePlayerChoice(); asd = new AdvancedSearchDialog(m_clientgui.frame, m_client.getGame().getOptions().intOption(OptionsConstants.ALLOWED_YEAR)); m_chkCanon.setSelected(m_client.getGame().getOptions().booleanOption( OptionsConstants.ALLOWED_CANON_ONLY)); updateTechChoice(); setLayout(new BorderLayout()); this.setPreferredSize(new Dimension(800,500)); add(m_pButtons, BorderLayout.SOUTH); add(m_pSplit, BorderLayout.CENTER); validate(); pack(); setLocationRelativeTo(cl.frame);
autoSetSkillsAndName(e); e.setOwner(c.getLocalPlayer()); if (c.getGame().getPhase() != Phase.PHASE_LOUNGE){ setVisible(false); } else if (ev.getSource().equals(m_bClear)) { armyModel.clearData(); armyModel.clearData(); unitsModel.clearData(); setVisible(false); } else if (ev.getSource().equals(m_bAddAll)) { for (MechSummary m : unitsModel.getAllUnits()) { m_bAdvSearchClear.setEnabled(false); } else if (ev.getSource().equals(m_bRoll)) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); try { if(m_pMain.getSelectedIndex() == TAB_RAT) { setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); generateRAT(); } else if (ev.getSource().equals(m_bAddToForce)) { for(int sel : m_lRAT.getSelectedRows()) { m_ratStatus.setText(Messages .getString("RandomArmyDialog.ratStatusDoneLoading")); updateRATs();
private void updateRATs() { Iterator<String> rats = rug.getRatList(); if(null == rats) { return; } RandomUnitGenerator.RatTreeNode ratTree = rug.getRatTree(); DefaultMutableTreeNode root = new DefaultMutableTreeNode(ratTree.name); createRatTreeNodes(root, ratTree); m_treeRAT.setModel(new DefaultTreeModel(root)); String selectedRATPath = GUIPreferences.getInstance().getRATSelectedRAT(); if (!selectedRATPath.equals("")) { String[] nodes = selectedRATPath.replace('[', ' ') .replace(']', ' ').split(","); TreePath path = findPathByName(nodes); m_treeRAT.setSelectionPath(path); } }
randomArmyDialog = new RandomArmyDialog(this); randomSkillDialog = new RandomSkillDialog(this); randomNameDialog = new RandomNameDialog(this);
private TreePath findNextNode(TreePath parent, String[] nodes, int depth) { TreeNode node = (TreeNode)parent.getLastPathComponent(); String currNode = node.toString(); // If equal, go down the branch if (currNode.equals(nodes[depth].trim())) { // If at end, return match if (depth == nodes.length-1) { return parent; } // Traverse children if (node.getChildCount() >= 0) { for (Enumeration<?> e = node.children(); e.hasMoreElements(); ) { TreeNode n = (TreeNode)e.nextElement(); TreePath path = parent.pathByAddingChild(n); TreePath result = findNextNode(path, nodes, depth + 1); // Found a match if (result != null) { return result; } } } } // No match at this branch return null; }