use of javax.swing.event.TreeSelectionEvent in project sldeditor by robward-scisys.
the class GeoServerStyleTree method createUI.
/**
* Creates the ui.
*/
private void createUI() {
setLayout(new BorderLayout());
styleCardPanel = new JPanel();
styleCardPanel.setLayout(new CardLayout(0, 0));
add(styleCardPanel, BorderLayout.CENTER);
JPanel styleTreePanel = new JPanel();
styleTreePanel.setLayout(new BorderLayout());
styleCardPanel.add(styleTreePanel, STYLE_PANEL);
tree = new JTree(treeModel);
tree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!populating) {
setButtonState(true);
}
}
});
JScrollPane scrollPane = new JScrollPane(tree);
styleTreePanel.add(scrollPane, BorderLayout.CENTER);
JPanel styleButtonsPanel = new JPanel();
styleTreePanel.add(styleButtonsPanel, BorderLayout.SOUTH);
btnApply = new JButton(Localisation.getString(GeoServerStyleTree.class, "common.apply"));
btnApply.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
apply();
}
});
styleButtonsPanel.add(btnApply);
btnRevert = new JButton(Localisation.getString(GeoServerStyleTree.class, "common.revert"));
btnRevert.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
revert();
}
});
styleButtonsPanel.add(btnRevert);
//
// Empty panel
//
JPanel emptyPanel = new JPanel();
emptyPanel.setLayout(new BorderLayout());
styleCardPanel.add(emptyPanel, EMPTY_PANEL);
}
use of javax.swing.event.TreeSelectionEvent in project android by JetBrains.
the class LicenseAgreementStep method createTreeSelectionListener.
private TreeSelectionListener createTreeSelectionListener() {
return new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode selected = (DefaultMutableTreeNode) myChangeTree.getLastSelectedPathComponent();
if (selected != null && selected.isRoot()) {
return;
}
if (selected != null && !selected.isLeaf()) {
License license = (License) selected.getUserObject();
myLicenseTextField.setText(license.getValue());
myCurrentLicense = license.getId();
} else if (selected != null && !selected.isRoot()) {
Change change = (Change) selected.getUserObject();
myLicenseTextField.setText(change.license.getValue());
myCurrentLicense = change.license.getId();
}
if (myAcceptances.get(myCurrentLicense)) {
myAcceptRadioButton.setSelected(true);
} else {
myDeclineRadioButton.setSelected(true);
}
myLicenseTextField.setCaretPosition(0);
}
};
}
use of javax.swing.event.TreeSelectionEvent in project android by JetBrains.
the class LicenseAgreementStep method init.
@Override
public void init() {
super.init();
myChangeTree.setModel(myTreeModel);
myChangeTree.setShowsRootHandles(false);
myLicenseTextField.setEditable(false);
// Initialize radio buttons
ButtonGroup group = new ButtonGroup();
group.add(myDeclineRadioButton);
group.add(myAcceptRadioButton);
myDeclineRadioButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myAcceptances.put(myCurrentLicense, Boolean.FALSE);
invokeUpdate(null);
myChangeTree.repaint();
}
});
myAcceptRadioButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myAcceptances.put(myCurrentLicense, Boolean.TRUE);
invokeUpdate(null);
myChangeTree.repaint();
}
});
myChangeTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode selected = (DefaultMutableTreeNode) myChangeTree.getLastSelectedPathComponent();
if (selected != null && selected.isRoot()) {
return;
}
if (selected != null && !selected.isLeaf()) {
License license = (License) selected.getUserObject();
myLicenseTextField.setText(license.getValue());
myCurrentLicense = license.getId();
} else if (selected != null && !selected.isRoot()) {
Change change = (Change) selected.getUserObject();
myLicenseTextField.setText(change.license.getValue());
myCurrentLicense = change.license.getId();
}
if (myAcceptances.get(myCurrentLicense)) {
myAcceptRadioButton.setSelected(true);
} else {
myDeclineRadioButton.setSelected(true);
}
myLicenseTextField.setCaretPosition(0);
}
});
myChangeTree.setCellRenderer(new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
if (row == 0) {
append("Licenses", SimpleTextAttributes.REGULAR_ATTRIBUTES);
return;
}
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
if (!leaf) {
License license = (License) node.getUserObject();
appendLicenseText(license, license.getId());
} else {
Change change = (Change) node.getUserObject();
if (change == null) {
return;
}
appendLicenseText(change.license, change.toString());
setIcon(change.getIcon());
}
}
private void appendLicenseText(@Nullable License license, String text) {
boolean notAccepted = license != null && !myAcceptances.get(license.getId());
if (notAccepted) {
append("*", SimpleTextAttributes.ERROR_ATTRIBUTES);
append(text, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
} else {
append(text, SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
}
});
setChanges(createChangesList());
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class ModulesDependenciesPanel method installLeftTreeListeners.
private void installLeftTreeListeners() {
myLeftTree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}
@Override
public void treeExpanded(TreeExpansionEvent event) {
DefaultMutableTreeNode expandedNode = (DefaultMutableTreeNode) event.getPath().getLastPathComponent();
for (int i = 0; i < expandedNode.getChildCount(); i++) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) expandedNode.getChildAt(i);
if (child.getChildCount() == 0 && !isLooped(event.getPath(), child)) {
Module module = ((MyUserObject) child.getUserObject()).myModule;
for (Module dependency : getModuleDependencies(module)) {
child.add(new DefaultMutableTreeNode(new MyUserObject(isInCycle(dependency), dependency)));
}
TreeUtil.sortRecursively(child, NODE_COMPARATOR);
}
}
}
private boolean isLooped(TreePath path, DefaultMutableTreeNode child) {
for (Object o : path.getPath()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) o;
if (node != child && Comparing.equal(node.getUserObject(), child.getUserObject())) {
return true;
}
}
return false;
}
});
myLeftTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath selectionPath = myLeftTree.getSelectionPath();
if (selectionPath != null) {
myPathField.setText(StringUtil.join(selectionPath.getPath(), o -> {
Object userObject = ((DefaultMutableTreeNode) o).getUserObject();
return userObject instanceof MyUserObject ? ((MyUserObject) userObject).myModule.getName() : "";
}, " : "));
DefaultMutableTreeNode selection = (DefaultMutableTreeNode) selectionPath.getLastPathComponent();
if (selection != null) {
updateRightTree(((MyUserObject) selection.getUserObject()).myModule);
}
}
}
});
}
use of javax.swing.event.TreeSelectionEvent in project intellij-community by JetBrains.
the class SMTestRunnerResultsForm method addEventsListener.
public void addEventsListener(final EventsListener listener) {
myEventListeners.add(listener);
addTestsTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(final TreeSelectionEvent e) {
//We should fire event only if it was generated by this component,
//e.g. it is focused. Otherwise it is side effect of selecting proxy in
//try by other component
//if (myTreeView.isFocusOwner()) {
@Nullable final SMTestProxy selectedProxy = (SMTestProxy) getTreeView().getSelectedTest();
listener.onSelected(selectedProxy, SMTestRunnerResultsForm.this, SMTestRunnerResultsForm.this);
//}
}
});
}
Aggregations