use of javax.swing.tree.TreePath in project pcgen by PCGen.
the class SpellsPreparedTab method getCurrentSpellListName.
/**
* Identify the current spell list, being the spell list that spell should
* be added to. If no lists exist then a default one will be created.
*
* @param character The character qwe are checking for.
* @return The name of the 'current' spell list.
*/
String getCurrentSpellListName(CharacterFacade character) {
String spellList = "";
Object selectedObject = selectedTable.getSelectedObject();
if (selectedObject != null) {
if (selectedObject instanceof SpellNode) {
spellList = ((SpellNode) selectedObject).getRootNode().toString();
} else {
JTree tree = selectedTable.getTree();
TreePath path = tree.getSelectionPath();
while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) {
path = path.getParentPath();
}
spellList = path.getLastPathComponent().toString();
}
}
if (StringUtils.isEmpty(spellList)) {
spellList = spellListField.getText();
}
if (StringUtils.isEmpty(spellList)) {
ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel();
if (!data.isEmpty()) {
Object firstElem = data.getElementAt(0);
if (firstElem instanceof SpellNode) {
spellList = ((SpellNode) firstElem).getRootNode().toString();
}
}
}
if (StringUtils.isEmpty(spellList)) {
// No lists exist, so create a default one!
spellList = "Prepared Spells";
character.getSpellSupport().addSpellList(spellList);
}
return spellList;
}
use of javax.swing.tree.TreePath in project pcgen by PCGen.
the class ClassInfoHandler method valueChanged.
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
TreePath path;
if (e.getSource() == availableTable.getSelectionModel()) {
path = availableTable.getTree().getSelectionPath();
} else {
path = selectedTable.getTree().getSelectionPath();
}
if (path == null) {
return;
}
ClassFacade c = null;
DefaultMutableTreeNode treenode = (DefaultMutableTreeNode) path.getLastPathComponent();
Object[] objs = treenode.getUserObjectPath();
for (Object object : objs) {
if (object instanceof ClassFacade) {
c = (ClassFacade) object;
break;
}
}
if (c != null) {
text = character.getSpellSupport().getClassInfo(c);
classPane.setText(text);
}
}
}
use of javax.swing.tree.TreePath in project pcgen by PCGen.
the class PreferencesPluginsPanel method getCenter.
@Override
protected JComponent getCenter() {
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode characterNode;
DefaultMutableTreeNode pcGenNode;
DefaultMutableTreeNode appearanceNode;
DefaultMutableTreeNode gameModeNode;
panelList = new ArrayList<>(15);
// Build the settings panel
settingsPanel = new JPanel();
settingsPanel.setLayout(new CardLayout());
settingsPanel.setPreferredSize(new Dimension(780, 420));
// Build the selection tree
characterNode = new DefaultMutableTreeNode(in_character);
settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_charTip")), in_character);
characterStatsPanel = new CharacterStatsPanel(this);
addPanelToTree(characterNode, characterStatsPanel);
hitPointsPanel = new HitPointsPanel();
addPanelToTree(characterNode, hitPointsPanel);
houseRulesPanel = new HouseRulesPanel();
addPanelToTree(characterNode, houseRulesPanel);
monsterPanel = new MonsterPanel();
addPanelToTree(characterNode, monsterPanel);
defaultsPanel = new DefaultsPanel();
addPanelToTree(characterNode, defaultsPanel);
rootNode.add(characterNode);
appearanceNode = new DefaultMutableTreeNode(in_appearance);
settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_appearanceTip")), in_appearance);
colorsPanel = new ColorsPanel();
addPanelToTree(appearanceNode, colorsPanel);
displayOptionsPanel = new DisplayOptionsPanel();
addPanelToTree(appearanceNode, displayOptionsPanel);
levelUpPanel = new LevelUpPanel();
addPanelToTree(appearanceNode, levelUpPanel);
lookAndFeelPanel = new LookAndFeelPanel(this);
addPanelToTree(appearanceNode, lookAndFeelPanel);
// tabsPanel = new TabsPanel();
// addPanelToTree(appearanceNode, tabsPanel);
rootNode.add(appearanceNode);
pcGenNode = new DefaultMutableTreeNode(Constants.APPLICATION_NAME);
settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_pcgenTip")), Constants.APPLICATION_NAME);
equipmentPanel = new EquipmentPanel();
addPanelToTree(pcGenNode, equipmentPanel);
languagePanel = new LanguagePanel();
addPanelToTree(pcGenNode, languagePanel);
locationPanel = new LocationPanel();
addPanelToTree(pcGenNode, locationPanel);
inputPanel = new InputPanel();
addPanelToTree(pcGenNode, inputPanel);
outputPanel = new OutputPanel();
addPanelToTree(pcGenNode, outputPanel);
sourcesPanel = new SourcesPanel();
addPanelToTree(pcGenNode, sourcesPanel);
rootNode.add(pcGenNode);
String in_gamemode = LanguageBundle.getString("in_mnuSettingsCampaign");
gameModeNode = new DefaultMutableTreeNode(in_gamemode);
settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_mnuSettingsCampaignTip")), in_gamemode);
copySettingsPanel = new CopySettingsPanel();
addPanelToTree(gameModeNode, copySettingsPanel);
rootNode.add(gameModeNode);
DefaultMutableTreeNode pluginNode = new DefaultMutableTreeNode(//$NON-NLS-1$
LanguageBundle.getString("in_Prefs_plugins"));
addPluginPanes(rootNode, pluginNode);
settingsModel = new DefaultTreeModel(rootNode);
settingsTree = new JTree(settingsModel);
settingsTree.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
settingsTree.setRootVisible(false);
settingsTree.setShowsRootHandles(true);
settingsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
settingsScroll = new JScrollPane(settingsTree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
// Turn off the icons
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(null);
renderer.setOpenIcon(null);
renderer.setClosedIcon(null);
settingsTree.setCellRenderer(renderer);
// Expand all of the branch nodes
settingsTree.expandPath(new TreePath(characterNode.getPath()));
settingsTree.expandPath(new TreePath(pcGenNode.getPath()));
settingsTree.expandPath(new TreePath(appearanceNode.getPath()));
settingsTree.expandPath(new TreePath(gameModeNode.getPath()));
settingsTree.expandPath(new TreePath(pluginNode.getPath()));
// Add the listener which switches panels when a node of the tree is selected
settingsTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) settingsTree.getLastSelectedPathComponent();
if (node == null) {
return;
}
CardLayout cl = (CardLayout) (settingsPanel.getLayout());
cl.show(settingsPanel, String.valueOf(node));
}
});
// Build the split pane
splitPane = new FlippingSplitPane(JSplitPane.HORIZONTAL_SPLIT, settingsScroll, settingsPanel, "Prefs");
splitPane.setOneTouchExpandable(true);
splitPane.setDividerSize(10);
return splitPane;
}
use of javax.swing.tree.TreePath in project intellij-plugins by StepicOrg.
the class NavigationUtils method collapseNonSelected.
private static void collapseNonSelected(@NotNull PsiFileSystemItem file) {
ProjectView projectView = ProjectView.getInstance(file.getProject());
if (projectView == null) {
return;
}
AbstractProjectViewPane projectViewPane = projectView.getCurrentProjectViewPane();
if (projectViewPane == null) {
return;
}
JTree tree = projectViewPane.getTree();
Set<TreePath> paths = new HashSet<>(TreeUtil.collectExpandedPaths(tree));
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
DefaultMutableTreeNode selectionNode = findNodeWithObject(root, file);
if (selectionNode != null) {
List<TreePath> toCollapse = new ArrayList<>();
TreePath selectedPath = getPathFromRoot(selectionNode);
for (TreePath treePath : paths) {
if (treePath.isDescendant(selectedPath)) {
continue;
}
TreePath currPath = treePath;
TreePath parent = treePath.getParentPath();
while (parent != null) {
if (parent.isDescendant(selectedPath)) {
toCollapse.add(currPath);
break;
}
currPath = parent;
parent = parent.getParentPath();
}
}
for (TreePath path : toCollapse) {
tree.collapsePath(path);
tree.fireTreeCollapsed(path);
}
}
}
use of javax.swing.tree.TreePath in project intellij-community by JetBrains.
the class MavenArtifactSearchPanel method initComponents.
private void initComponents(String initialText) {
myResultList = new Tree();
myResultList.setExpandableItemsEnabled(false);
myResultList.getEmptyText().setText("Loading...");
myResultList.setRootVisible(false);
myResultList.setShowsRootHandles(true);
myResultList.setModel(null);
MyArtifactCellRenderer renderer = myClassMode ? new MyClassCellRenderer(myResultList) : new MyArtifactCellRenderer(myResultList);
myResultList.setCellRenderer(renderer);
myResultList.setRowHeight(renderer.getPreferredSize().height);
mySearchField = new JTextField(initialText);
mySearchField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
int d;
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
d = 1;
} else if (e.getKeyCode() == KeyEvent.VK_UP) {
d = -1;
} else {
return;
}
int row = myResultList.getSelectionModel().getLeadSelectionRow();
row += d;
if (row >= 0 && row < myResultList.getRowCount()) {
myResultList.setSelectionRow(row);
}
}
});
setLayout(new BorderLayout());
add(mySearchField, BorderLayout.NORTH);
JScrollPane pane = ScrollPaneFactory.createScrollPane(myResultList);
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
// Don't remove this line.
pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
// Without VERTICAL_SCROLLBAR_ALWAYS policy our custom layout
// works incorrectly, see https://youtrack.jetbrains.com/issue/IDEA-72986
add(pane, BorderLayout.CENTER);
mySearchField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
scheduleSearch();
}
});
myResultList.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!myAlarm.isEmpty())
return;
boolean hasSelection = !myResultList.isSelectionEmpty();
myListener.canSelectStateChanged(MavenArtifactSearchPanel.this, hasSelection);
}
});
myResultList.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER && myResultList.getLastSelectedPathComponent() != null) {
myListener.itemSelected();
e.consume();
}
}
});
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
final TreePath path = myResultList.getPathForLocation(e.getX(), e.getY());
if (path != null && myResultList.isPathSelected(path)) {
Object sel = path.getLastPathComponent();
if (sel != null && myResultList.getModel().isLeaf(sel)) {
myListener.itemSelected();
return true;
}
}
return false;
}
}.installOn(myResultList);
}
Aggregations