use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class MapExternalResourceDialog method setupSchemasTree.
private void setupSchemasTree(String uri, @NotNull Project project, @Nullable PsiFile file, @Nullable String location) {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
mySchemasTree.setModel(new DefaultTreeModel(root));
ConfigFileSearcher searcher = new ConfigFileSearcher(file == null ? null : ModuleUtilCore.findModuleForPsiElement(file), project) {
@Override
public Set<PsiFile> search(@Nullable Module module, @NotNull Project project) {
List<IndexedRelevantResource<String, XsdNamespaceBuilder>> resources = XmlNamespaceIndex.getAllResources(module, project, null);
HashSet<PsiFile> files = new HashSet<>();
PsiManager psiManager = PsiManager.getInstance(project);
for (IndexedRelevantResource<String, XsdNamespaceBuilder> resource : resources) {
VirtualFile file = resource.getFile();
PsiFile psiFile = psiManager.findFile(file);
ContainerUtil.addIfNotNull(files, psiFile);
}
return files;
}
};
searcher.search();
new ConfigFilesTreeBuilder(mySchemasTree).buildTree(root, searcher);
TreeUtil.expandAll(mySchemasTree);
mySchemasTree.setRootVisible(false);
mySchemasTree.setShowsRootHandles(true);
ColoredTreeCellRenderer renderer = new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
ConfigFilesTreeBuilder.renderNode(value, expanded, this);
}
};
renderer.setFont(EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN));
mySchemasTree.setCellRenderer(renderer);
MouseAdapter mouseAdapter = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1 && isOKActionEnabled()) {
doOKAction();
}
}
};
mySchemasTree.addMouseListener(mouseAdapter);
mySchemasTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
validateInput();
}
});
mySchemasTree.setSelectionRow(0);
PsiFile schema = null;
if (file != null) {
schema = XmlUtil.findNamespaceByLocation(file, uri);
} else if (location != null) {
VirtualFile virtualFile = VfsUtilCore.findRelativeFile(location, null);
if (virtualFile != null) {
schema = PsiManager.getInstance(project).findFile(virtualFile);
}
}
if (schema != null) {
DefaultMutableTreeNode node = TreeUtil.findNodeWithObject(root, schema);
if (node != null) {
mySchemaFound = true;
TreeUtil.selectNode(mySchemasTree, node);
}
myFileTextField.setText(schema.getVirtualFile().getCanonicalPath());
}
}
use of javax.swing.event.TreeSelectionEvent in project JMRI by JMRI.
the class PaneProgDp3Action method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// NOI18N
log.debug("Pane programmer requested");
if (f == null) {
log.debug("found f==null");
// create the initial frame that steers
// NOI18N
f = new JmriJFrame(apps.gui3.dp3.Bundle.getMessage("FrameProgrammerSetup"));
f.getContentPane().setLayout(new BorderLayout());
// ensure status line is cleared on close so it is normal if re-opened
f.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
// NOI18N
statusLabel.setText(SymbolicProgBundle.getMessage("StateIdle"));
f.windowClosing(we);
}
});
// add the Roster menu
JMenuBar menuBar = new JMenuBar();
// NOI18N
JMenu j = new JMenu(SymbolicProgBundle.getMessage("MenuFile"));
// NOI18N
j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintDecoderDefinitions"), f, false));
// NOI18N
j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintPreviewDecoderDefinitions"), f, true));
menuBar.add(j);
// NOI18N
menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
f.setJMenuBar(menuBar);
final JPanel bottomPanel = new JPanel(new BorderLayout());
// new Loco on programming track
combinedLocoSelTree = new CombinedLocoSelTreePane(statusLabel, modePane) {
@Override
protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String progName) {
// progName is ignored here
log.debug("startProgrammer");
String title = // NOI18N
java.text.MessageFormat.format(// NOI18N
SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), // NOI18N
new Object[] { Bundle.getMessage("NewDecoder") });
if (re != null) {
title = // NOI18N
java.text.MessageFormat.format(// NOI18N
SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), new Object[] { re.getId() });
}
JFrame p;
if (!modePane.isSelected() || modePane.getProgrammer() == null) {
p = new PaneProgFrame(decoderFile, re, // NOI18N
title, // NOI18N
"programmers" + File.separator + "Comprehensive.xml", null, false) {
@Override
protected JPanel getModePane() {
return null;
}
};
} else {
p = new PaneServiceProgFrame(decoderFile, re, // NOI18N
title, // NOI18N
"programmers" + File.separator + "Comprehensive.xml", modePane.getProgrammer());
}
p.pack();
p.setVisible(true);
}
@Override
protected void openNewLoco() {
log.debug("openNewLoco");
// find the decoderFile object
DecoderFile decoderFile = DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
// NOI18N
log.debug("decoder file: {}", decoderFile.getFilename());
if (rosterIdField.getText().equals(SymbolicProgBundle.getMessage("LabelNewDecoder"))) {
// NOI18N
re = new RosterEntry();
re.setDecoderFamily(decoderFile.getFamily());
re.setDecoderModel(decoderFile.getModel());
// NOI18N
re.setId(SymbolicProgBundle.getMessage("LabelNewDecoder"));
//re.writeFile(cvModel, iCvModel, variableModel );
// note that we're leaving the filename null
// add the new roster entry to the in-memory roster
Roster.getDefault().addEntry(re);
} else {
try {
saveRosterEntry();
} catch (JmriException ex) {
// NOI18N
log.warn("Exception while saving roster entry", ex);
return;
}
}
// create a dummy RosterEntry with the decoder info
// no programmer name in this case
startProgrammer(decoderFile, re, "");
//Set our roster entry back to null so that a fresh roster entry can be created if needed
re = null;
}
@Override
protected JPanel layoutRosterSelection() {
log.debug("layoutRosterSelection");
return null;
}
@Override
protected JPanel layoutDecoderSelection() {
log.debug("layoutDecoderSelection");
JPanel pan = super.layoutDecoderSelection();
dTree.removeTreeSelectionListener(dListener);
dTree.addTreeSelectionListener(dListener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!dTree.isSelectionEmpty() && dTree.getSelectionPath() != null && // check that this isn't just a model
((TreeNode) dTree.getSelectionPath().getLastPathComponent()).isLeaf() && // can't be just a mfg, has to be at least a family
dTree.getSelectionPath().getPathCount() > 2 && // can't be a multiple decoder selection
dTree.getSelectionCount() < 2) {
log.debug("Selection event with " + dTree.getSelectionPath().toString());
//if (locoBox != null) locoBox.setSelectedIndex(0);
go2.setEnabled(true);
go2.setRequestFocusEnabled(true);
go2.requestFocus();
// NOI18N
go2.setToolTipText(SymbolicProgBundle.getMessage("TipClickToOpen"));
decoderFile = DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
setUpRosterPanel();
} else {
decoderFile = null;
// decoder not selected - require one
go2.setEnabled(false);
// NOI18N
go2.setToolTipText(SymbolicProgBundle.getMessage("TipSelectLoco"));
setUpRosterPanel();
}
}
});
return pan;
}
@Override
protected void selectDecoder(int mfgID, int modelID, int productID) {
log.debug("selectDecoder");
//On selecting a new decoder start a fresh with a new roster entry
super.selectDecoder(mfgID, modelID, productID);
findDecoderAddress();
}
@Override
protected JPanel createProgrammerSelection() {
log.debug("createProgrammerSelection");
JPanel pane3a = new JPanel();
pane3a.setLayout(new BoxLayout(pane3a, BoxLayout.Y_AXIS));
// NOI18N
go2 = new JButton(Bundle.getMessage("OpenProgrammer"));
go2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
// NOI18N
log.debug("Open programmer pressed");
openButton();
// close this window to prevent having
// two windows processing at the same time
//
// Alternately, could have just cleared out a
// bunch of stuff to force starting over, but
// that seems to be an even more confusing
// user experience.
log.debug("Closing f {}", f);
WindowEvent wev = new WindowEvent(f, WindowEvent.WINDOW_CLOSING);
java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
}
});
go2.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
go2.setEnabled(false);
// NOI18N
go2.setToolTipText(SymbolicProgBundle.getMessage("TipSelectLoco"));
bottomPanel.add(go2, BorderLayout.EAST);
return pane3a;
}
};
// load primary frame
JPanel topPanel = new JPanel();
topPanel.add(modePane);
topPanel.add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
f.getContentPane().add(topPanel, BorderLayout.NORTH);
//f.getContentPane().add(modePane);
//f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
combinedLocoSelTree.setAlignmentX(JLabel.CENTER_ALIGNMENT);
f.getContentPane().add(combinedLocoSelTree, BorderLayout.CENTER);
//f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
//basicRoster.setEnabled(false);
statusLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
bottomPanel.add(statusLabel, BorderLayout.SOUTH);
f.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
f.pack();
// NOI18N
log.debug("Tab-Programmer setup created");
} else {
re = null;
combinedLocoSelTree.resetSelections();
}
f.setVisible(true);
}
use of javax.swing.event.TreeSelectionEvent in project JMRI by JMRI.
the class EcosLocoToRoster method layoutDecoderSelection.
//@TODO this could do with being re-written so that it reuses the combined loco select tree code
protected JPanel layoutDecoderSelection() {
JPanel pane1a = new JPanel();
pane1a.setLayout(new BoxLayout(pane1a, BoxLayout.X_AXIS));
// create the list of manufacturers; get the list of decoders, and add elements
dRoot = new DefaultMutableTreeNode("Root");
dModel = new DefaultTreeModel(dRoot);
dTree = new JTree(dModel) {
@Override
public String getToolTipText(MouseEvent evt) {
if (getRowForLocation(evt.getX(), evt.getY()) == -1) {
return null;
}
TreePath curPath = getPathForLocation(evt.getX(), evt.getY());
return ((DecoderTreeNode) curPath.getLastPathComponent()).getToolTipText();
}
};
dTree.setToolTipText("");
List<DecoderFile> decoders = DecoderIndexFile.instance().matchingDecoderList(null, null, null, null, null, null);
int len = decoders.size();
DefaultMutableTreeNode mfgElement = null;
DefaultMutableTreeNode familyElement = null;
for (int i = 0; i < len; i++) {
DecoderFile decoder = decoders.get(i);
String mfg = decoder.getMfg();
String family = decoder.getFamily();
String model = decoder.getModel();
log.debug(" process " + mfg + "/" + family + "/" + model + " on nodes " + (mfgElement == null ? "<null>" : mfgElement.toString() + "(" + mfgElement.getChildCount() + ")") + "/" + (familyElement == null ? "<null>" : familyElement.toString() + "(" + familyElement.getChildCount() + ")"));
// build elements
if (mfgElement == null || !mfg.equals(mfgElement.toString())) {
// need new mfg node
mfgElement = new DecoderTreeNode(mfg, "CV8 = " + DecoderIndexFile.instance().mfgIdFromName(mfg), "");
dModel.insertNodeInto(mfgElement, dRoot, dRoot.getChildCount());
familyElement = null;
}
String famComment = decoders.get(i).getFamilyComment();
String verString = decoders.get(i).getVersionsAsString();
String hoverText = "";
if (famComment == null || famComment.equals("")) {
if (verString != null && !verString.equals("")) {
hoverText = "CV7=" + verString;
}
} else {
if (verString == null || verString.equals("")) {
hoverText = famComment;
} else {
hoverText = famComment + " CV7=" + verString;
}
}
if (familyElement == null || !family.equals(familyElement.toString())) {
// appears to have decoder names separate from the family name
if ((i + 2 >= len) || decoders.get(i + 2).getFamily().equals(family) || !decoders.get(i + 1).getModel().equals(family)) {
// normal here; insert the new family element & exit
log.debug("normal family update case: " + family);
familyElement = new DecoderTreeNode(family, hoverText, decoders.get(i).titleString());
dModel.insertNodeInto(familyElement, mfgElement, mfgElement.getChildCount());
continue;
} else {
// this is short case; insert decoder entry (next) here
log.debug("short case, i=" + i + " family=" + family + " next " + decoders.get(i + 1).getModel());
if (i + 1 > len) {
log.error("Unexpected single entry for family: " + family);
}
family = decoders.get(i + 1).getModel();
familyElement = new DecoderTreeNode(family, hoverText, decoders.get(i).titleString());
dModel.insertNodeInto(familyElement, mfgElement, mfgElement.getChildCount());
i = i + 1;
continue;
}
}
// insert at the decoder level, except if family name is the same
if (!family.equals(model)) {
dModel.insertNodeInto(new DecoderTreeNode(model, hoverText, decoders.get(i).titleString()), familyElement, familyElement.getChildCount());
}
}
// end of loop over decoders
// build the tree GUI
pane1a.add(new JScrollPane(dTree));
dTree.expandPath(new TreePath(dRoot));
dTree.setRootVisible(false);
dTree.setShowsRootHandles(true);
dTree.setScrollsOnExpand(true);
dTree.setExpandsSelectedPaths(true);
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
// tree listener
dTree.addTreeSelectionListener(dListener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!dTree.isSelectionEmpty() && dTree.getSelectionPath() != null && // can't be just a mfg, has to be at least a family
dTree.getSelectionPath().getPathCount() > 2 && // can't be a multiple decoder selection
dTree.getSelectionCount() < 2) {
// decoder selected - reset and disable loco selection
log.debug("Selection event with " + dTree.getSelectionPath().toString());
if (locoBox != null) {
locoBox.setSelectedIndex(0);
}
}
}
});
// Mouselistener for doubleclick activation of proprammer
dTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
// Clear any status messages and ensure the tree is in single path select mode
//if (_statusLabel != null) _statusLabel.setText("StateIdle");
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
/* check for both double click and that it's a decoder
that is being clicked on. If it's just a Family, the programmer
button is enabled by the TreeSelectionListener, but we don't
want to automatically open a programmer so a user has the opportunity
to select an individual decoder
*/
if (me.getClickCount() == 2) {
if (((TreeNode) dTree.getSelectionPath().getLastPathComponent()).isLeaf()) {
okayButton();
}
}
}
});
this.selectDecoder(ecosLoco.getCVAsString(8), ecosLoco.getCVAsString(7));
return pane1a;
}
use of javax.swing.event.TreeSelectionEvent in project JMRI by JMRI.
the class CombinedLocoSelTreePane method layoutDecoderSelection.
/**
* Create the panel used to select the decoder
*/
@Override
protected JPanel layoutDecoderSelection() {
JPanel pane1a = new JPanel(new BorderLayout());
pane1a.add(new JLabel(Bundle.getMessage("LabelDecoderInstalled")), BorderLayout.NORTH);
// create the list of manufacturers; get the list of decoders, and add elements
dRoot = new DecoderTreeNode("Root");
dModel = new InvisibleTreeModel(dRoot);
dTree = new JTree(dModel) {
@Override
public String getToolTipText(MouseEvent evt) {
if (getRowForLocation(evt.getX(), evt.getY()) == -1) {
return null;
}
TreePath curPath = getPathForLocation(evt.getX(), evt.getY());
return ((DecoderTreeNode) curPath.getLastPathComponent()).getToolTipText();
}
};
dTree.setToolTipText("");
createDecoderTypeContents();
// build the tree GUI
pane1a.add(new JScrollPane(dTree), BorderLayout.CENTER);
dTree.expandPath(new TreePath(dRoot));
dTree.setRootVisible(false);
dTree.setShowsRootHandles(true);
dTree.setScrollsOnExpand(true);
dTree.setExpandsSelectedPaths(true);
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
// tree listener
dTree.addTreeSelectionListener(dListener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
log.debug("selection changed " + dTree.isSelectionEmpty() + " " + dTree.getSelectionPath());
if (!dTree.isSelectionEmpty() && dTree.getSelectionPath() != null && // can't be just a mfg, has to be at least a family
dTree.getSelectionPath().getPathCount() > 2 && // can't be a multiple decoder selection
dTree.getSelectionCount() < 2) {
// decoder selected - reset and disable loco selection
log.debug("Selection event with " + dTree.getSelectionPath().toString());
if (locoBox != null) {
locoBox.setSelectedIndex(0);
}
go2.setEnabled(true);
go2.setRequestFocusEnabled(true);
go2.requestFocus();
go2.setToolTipText(Bundle.getMessage("TipClickToOpen"));
} else {
// decoder not selected - require one
go2.setEnabled(false);
go2.setToolTipText(Bundle.getMessage("TipSelectLoco"));
}
}
});
// Mouselistener for doubleclick activation of programmer
dTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
// Clear any status messages and ensure the tree is in single path select mode
if (_statusLabel != null) {
_statusLabel.setText(Bundle.getMessage("StateIdle"));
}
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
if (me.getClickCount() == 2) {
if (go2.isEnabled() && ((TreeNode) dTree.getSelectionPath().getLastPathComponent()).isLeaf()) {
go2.doClick();
}
}
}
});
viewButtons = new JPanel();
iddecoder = addDecoderIdentButton();
if (iddecoder != null) {
viewButtons.add(iddecoder);
}
showAll = new JRadioButton(Bundle.getMessage("LabelAll"));
showAll.setSelected(true);
showMatched = new JRadioButton(Bundle.getMessage("LabelMatched"));
if (jmri.InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) != null && jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).isGlobalProgrammerAvailable()) {
ButtonGroup group = new ButtonGroup();
group.add(showAll);
group.add(showMatched);
viewButtons.add(showAll);
viewButtons.add(showMatched);
pane1a.add(viewButtons, BorderLayout.SOUTH);
showAll.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (dModel.isActivatedFilter()) {
dModel.activateFilter(false);
dModel.reload();
for (TreePath path : selectedPath) {
dTree.expandPath(path);
dTree.addSelectionPath(path);
dTree.scrollPathToVisible(path);
}
}
}
});
showMatched.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!dModel.isActivatedFilter()) {
dModel.activateFilter(true);
dModel.reload();
for (TreePath path : selectedPath) {
log.debug("action selects path: " + path);
dTree.expandPath(path);
dTree.addSelectionPath(path);
dTree.scrollPathToVisible(path);
}
}
}
});
}
return pane1a;
}
use of javax.swing.event.TreeSelectionEvent in project n2a by frothga.
the class FixedParameterSpacePanel method buildDomainTab.
private void buildDomainTab(ParameterDomain domain) {
TNode nRoot = new TNode(new NodeSimpleLabel(domain.getName()));
populate(nRoot, domain);
FilterableParameterTreePanel pnlFilterableTree = new FilterableParameterTreePanel(nRoot);
final ParameterTree treParams = pnlFilterableTree.getTree();
treParams.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
TreePath path = treParams.getPathForLocation(e.getX(), e.getY());
if (path == null || ((TNode) path.getLastPathComponent()).getUserObject() instanceof NodeSubdomain) {
treParams.setCursor(Cursor.getDefaultCursor());
} else {
treParams.setCursor(DragCursors.getOpenhandcursor());
}
}
});
treParams.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
updateDetailsPanelFromTree(treParams);
}
});
treParams.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1 && treParams.getSelectionCount() != 0) {
List<ParameterBundle> bundles = getSelectedParamsAsBundles(treParams.getSelectionPaths());
if (bundles != null) {
dropIntoGroups(bundles, dropEmphasis);
}
}
}
});
DragSource ds = new DragSource();
ds.createDefaultDragGestureRecognizer(treParams, DnDConstants.ACTION_LINK, this);
int existingIndex = tabParamDomains.indexOfTabByKey(domain.getName());
if (existingIndex != -1) {
tabParamDomains.remove(existingIndex);
}
tabParamDomains.add(domain.getName(), pnlFilterableTree);
int index = tabParamDomains.getTabCount();
tabParamDomains.setIconAt(index - 1, domain.getIcon());
tabParamDomains.setUseBorderAt(index - 1, true);
}
Aggregations