use of javax.swing.event.TreeSelectionEvent 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.event.TreeSelectionEvent 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);
}
use of javax.swing.event.TreeSelectionEvent in project pcgen by PCGen.
the class NotesView method initTree.
//Initialization methods
private void initTree() {
dataDir.listFiles();
root = new NotesTreeNode(dataDir.getName(), dataDir, notesTree);
TreeModel model = new DefaultTreeModel(root);
notesTree.setModel(model);
notesTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent evt) {
notesTreeActionPerformed();
}
});
notesTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
notesTree.setEditable(true);
model.addTreeModelListener(new TreeModelListener() {
@Override
public void treeNodesChanged(TreeModelEvent e) {
notesTreeNodesChanged();
}
@Override
public void treeNodesInserted(TreeModelEvent e) {
// TODO: Method does nothing?
}
@Override
public void treeNodesRemoved(TreeModelEvent e) {
// TODO: Method does nothing?
}
@Override
public void treeStructureChanged(TreeModelEvent e) {
// TODO: Method does nothing?
}
});
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class ChooseLibrariesDialogBase method createCenterPanel.
@Override
@Nullable
protected JComponent createCenterPanel() {
myBuilder = new SimpleTreeBuilder(myTree, new DefaultTreeModel(new DefaultMutableTreeNode()), new MyStructure(getProject()), WeightBasedComparator.FULL_INSTANCE);
myBuilder.initRootNode();
myTree.setDragEnabled(false);
myTree.setShowsRootHandles(true);
UIUtil.setLineStyleAngled(myTree);
myTree.setRootVisible(false);
myTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent e) {
updateOKAction();
}
});
new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent e) {
if (isOKActionEnabled()) {
doOKAction();
return true;
}
return false;
}
}.installOn(myTree);
myTree.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ENTER");
myTree.getActionMap().put("ENTER", getOKAction());
final JScrollPane pane = ScrollPaneFactory.createScrollPane(myTree);
pane.setPreferredSize(JBUI.size(500, 400));
return pane;
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class XWatchesViewImpl method installEditListeners.
private void installEditListeners() {
final XDebuggerTree watchTree = getTree();
final Alarm quitePeriod = new Alarm();
final Alarm editAlarm = new Alarm();
final ClickListener mouseListener = new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent event, int clickCount) {
if (!SwingUtilities.isLeftMouseButton(event) || ((event.getModifiers() & (InputEvent.SHIFT_MASK | InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) != 0)) {
return false;
}
boolean sameRow = isAboveSelectedItem(event, watchTree, false);
if (!sameRow || clickCount > 1) {
editAlarm.cancelAllRequests();
return false;
}
final AnAction editWatchAction = ActionManager.getInstance().getAction(XDebuggerActions.XEDIT_WATCH);
Presentation presentation = editWatchAction.getTemplatePresentation().clone();
DataContext context = DataManager.getInstance().getDataContext(watchTree);
final AnActionEvent actionEvent = new AnActionEvent(null, context, "WATCH_TREE", presentation, ActionManager.getInstance(), 0);
Runnable runnable = () -> editWatchAction.actionPerformed(actionEvent);
if (editAlarm.isEmpty() && quitePeriod.isEmpty()) {
editAlarm.addRequest(runnable, UIUtil.getMultiClickInterval());
} else {
editAlarm.cancelAllRequests();
}
return false;
}
};
final ClickListener mouseEmptySpaceListener = new DoubleClickListener() {
@Override
protected boolean onDoubleClick(MouseEvent event) {
if (!isAboveSelectedItem(event, watchTree, true)) {
myRootNode.addNewWatch();
return true;
}
return false;
}
};
ListenerUtil.addClickListener(watchTree, mouseListener);
ListenerUtil.addClickListener(watchTree, mouseEmptySpaceListener);
final FocusListener focusListener = new FocusListener() {
@Override
public void focusGained(@NotNull FocusEvent e) {
quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
}
@Override
public void focusLost(@NotNull FocusEvent e) {
editAlarm.cancelAllRequests();
}
};
ListenerUtil.addFocusListener(watchTree, focusListener);
final TreeSelectionListener selectionListener = new TreeSelectionListener() {
@Override
public void valueChanged(@NotNull TreeSelectionEvent e) {
quitePeriod.addRequest(EmptyRunnable.getInstance(), UIUtil.getMultiClickInterval());
}
};
watchTree.addTreeSelectionListener(selectionListener);
myDisposables.add(new Disposable() {
@Override
public void dispose() {
ListenerUtil.removeClickListener(watchTree, mouseListener);
ListenerUtil.removeClickListener(watchTree, mouseEmptySpaceListener);
ListenerUtil.removeFocusListener(watchTree, focusListener);
watchTree.removeTreeSelectionListener(selectionListener);
}
});
}
Aggregations