use of javax.swing.tree.DefaultMutableTreeNode in project processing by processing.
the class ExamplesFrame method buildContribTree.
protected DefaultMutableTreeNode buildContribTree() {
DefaultMutableTreeNode contribExamplesNode = new DefaultMutableTreeNode(Language.text("examples.contributed"));
try {
File[] subfolders = ContributionType.EXAMPLES.listCandidates(examplesContribFolder);
if (subfolders != null) {
for (File sub : subfolders) {
StringDict props = Contribution.loadProperties(sub, ContributionType.EXAMPLES);
if (props != null) {
if (ExamplesContribution.isCompatible(base, props)) {
DefaultMutableTreeNode subNode = new DefaultMutableTreeNode(props.get("name"));
if (base.addSketches(subNode, sub, true)) {
contribExamplesNode.add(subNode);
// TODO there has to be a simpler way of handling this along
// with addSketches() as well [fry 150811]
int exampleNodeNumber = -1;
// The contrib may have other items besides the examples folder
for (int i = 0; i < subNode.getChildCount(); i++) {
if (subNode.getChildAt(i).toString().equals("examples")) {
exampleNodeNumber = i;
}
}
if (exampleNodeNumber != -1) {
TreeNode exampleNode = subNode.getChildAt(exampleNodeNumber);
subNode.remove(exampleNodeNumber);
int count = exampleNode.getChildCount();
for (int j = 0; j < count; j++) {
subNode.add((DefaultMutableTreeNode) exampleNode.getChildAt(0));
}
}
// if (subNode.getChildCount() != 1) {
// System.err.println("more children than expected when one is enough");
// }
// TreeNode exampleNode = subNode.getChildAt(0);
// subNode.add((DefaultMutableTreeNode) exampleNode.getChildAt(0));
}
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
return contribExamplesNode;
}
use of javax.swing.tree.DefaultMutableTreeNode in project jadx by skylot.
the class MainWindow method initUI.
private void initUI() {
mainPanel = new JPanel(new BorderLayout());
JSplitPane splitPane = new JSplitPane();
splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
mainPanel.add(splitPane);
DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
treeModel = new DefaultTreeModel(treeRoot);
tree = new JTree(treeModel);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
treeClickAction();
}
});
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
treeClickAction();
}
}
});
tree.setCellRenderer(new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
if (value instanceof JNode) {
setIcon(((JNode) value).getIcon());
}
return c;
}
});
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
TreePath path = event.getPath();
Object node = path.getLastPathComponent();
if (node instanceof JClass) {
JClass cls = (JClass) node;
cls.getRootClass().load();
}
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
}
});
progressPane = new ProgressPanel(this, true);
JPanel leftPane = new JPanel(new BorderLayout());
leftPane.add(new JScrollPane(tree), BorderLayout.CENTER);
leftPane.add(progressPane, BorderLayout.PAGE_END);
splitPane.setLeftComponent(leftPane);
tabbedPane = new TabbedPane(this);
splitPane.setRightComponent(tabbedPane);
dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
setContentPane(mainPanel);
setTitle(DEFAULT_TITLE);
}
use of javax.swing.tree.DefaultMutableTreeNode in project antlrworks by antlr.
the class Usages method addMatch.
public void addMatch(ElementRule rule, ATEToken token) {
if (lastRule == null || !lastRule.equals(rule.name)) {
node = new DefaultMutableTreeNode();
node.setUserObject(rule.name);
root.add(node);
lastRule = rule.name;
}
DefaultMutableTreeNode matchNode = new DefaultMutableTreeNode();
matchNode.setUserObject(new UsageMatch(rule, token));
node.add(matchNode);
model.reload();
}
use of javax.swing.tree.DefaultMutableTreeNode in project languagetool by languagetool-org.
the class ConfigurationDialog method getTreeModel.
@NotNull
private DefaultTreeModel getTreeModel(DefaultMutableTreeNode rootNode) {
DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
treeModel.addTreeModelListener(new TreeModelListener() {
@Override
public void treeNodesChanged(TreeModelEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getTreePath().getLastPathComponent();
int index = e.getChildIndices()[0];
node = (DefaultMutableTreeNode) node.getChildAt(index);
if (node instanceof RuleNode) {
RuleNode o = (RuleNode) node;
if (o.getRule().isDefaultOff() || o.getRule().getCategory().isDefaultOff()) {
if (o.isEnabled()) {
config.getEnabledRuleIds().add(o.getRule().getId());
config.getDisabledRuleIds().remove(o.getRule().getId());
} else {
config.getEnabledRuleIds().remove(o.getRule().getId());
config.getDisabledRuleIds().add(o.getRule().getId());
}
} else {
if (o.isEnabled()) {
config.getDisabledRuleIds().remove(o.getRule().getId());
} else {
config.getDisabledRuleIds().add(o.getRule().getId());
}
}
}
if (node instanceof CategoryNode) {
CategoryNode o = (CategoryNode) node;
if (o.isEnabled()) {
config.getDisabledCategoryNames().remove(o.getCategory().getName());
} else {
config.getDisabledCategoryNames().add(o.getCategory().getName());
}
}
}
@Override
public void treeNodesInserted(TreeModelEvent e) {
}
@Override
public void treeNodesRemoved(TreeModelEvent e) {
}
@Override
public void treeStructureChanged(TreeModelEvent e) {
}
});
return treeModel;
}
use of javax.swing.tree.DefaultMutableTreeNode in project languagetool by languagetool-org.
the class ConfigurationDialog method show.
public void show(List<Rule> rules) {
if (original != null) {
config.restoreState(original);
}
dialog = new JDialog(owner, true);
dialog.setTitle(messages.getString("guiConfigWindowTitle"));
// close dialog when user presses Escape key:
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
ActionListener actionListener = new ActionListener() {
@Override
public void actionPerformed(@SuppressWarnings("unused") ActionEvent actionEvent) {
dialog.setVisible(false);
}
};
JRootPane rootPane = dialog.getRootPane();
rootPane.registerKeyboardAction(actionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
JPanel checkBoxPanel = new JPanel();
checkBoxPanel.setLayout(new GridBagLayout());
GridBagConstraints cons = new GridBagConstraints();
cons.anchor = GridBagConstraints.NORTHWEST;
cons.gridx = 0;
cons.weightx = 1.0;
cons.weighty = 1.0;
cons.fill = GridBagConstraints.BOTH;
Collections.sort(rules, new CategoryComparator());
DefaultMutableTreeNode rootNode = createTree(rules);
configTree = new JTree(getTreeModel(rootNode));
Language lang = config.getLanguage();
if (lang == null) {
lang = Languages.getLanguageForLocale(Locale.getDefault());
}
configTree.applyComponentOrientation(ComponentOrientation.getOrientation(lang.getLocale()));
configTree.setRootVisible(false);
configTree.setEditable(false);
configTree.setCellRenderer(new CheckBoxTreeCellRenderer());
TreeListener.install(configTree);
checkBoxPanel.add(configTree, cons);
configTree.addMouseListener(getMouseAdapter());
JPanel portPanel = new JPanel();
portPanel.setLayout(new GridBagLayout());
cons = new GridBagConstraints();
cons.insets = new Insets(0, 4, 0, 0);
cons.gridx = 0;
cons.gridy = 0;
cons.anchor = GridBagConstraints.WEST;
cons.fill = GridBagConstraints.NONE;
cons.weightx = 0.0f;
if (!insideOffice) {
createNonOfficeElements(cons, portPanel);
}
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
JButton okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton")));
okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton")));
okButton.setActionCommand(ACTION_COMMAND_OK);
okButton.addActionListener(this);
JButton cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton")));
cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton")));
cancelButton.setActionCommand(ACTION_COMMAND_CANCEL);
cancelButton.addActionListener(this);
cons = new GridBagConstraints();
cons.insets = new Insets(0, 4, 0, 0);
buttonPanel.add(okButton, cons);
buttonPanel.add(cancelButton, cons);
Container contentPane = dialog.getContentPane();
contentPane.setLayout(new GridBagLayout());
cons = new GridBagConstraints();
cons.insets = new Insets(4, 4, 4, 4);
cons.gridx = 0;
cons.gridy = 0;
cons.weightx = 10.0f;
cons.weighty = 10.0f;
cons.fill = GridBagConstraints.BOTH;
contentPane.add(new JScrollPane(checkBoxPanel), cons);
cons.weightx = 0.0f;
cons.weighty = 0.0f;
cons.gridx = 0;
cons.gridy++;
cons.fill = GridBagConstraints.NONE;
cons.anchor = GridBagConstraints.LINE_END;
contentPane.add(getTreeButtonPanel(), cons);
cons.gridy++;
cons.anchor = GridBagConstraints.WEST;
contentPane.add(getMotherTonguePanel(cons), cons);
cons.gridy++;
cons.anchor = GridBagConstraints.WEST;
contentPane.add(getNgramPanel(cons), cons);
cons.gridy++;
cons.anchor = GridBagConstraints.WEST;
contentPane.add(portPanel, cons);
cons.fill = GridBagConstraints.HORIZONTAL;
cons.anchor = GridBagConstraints.WEST;
for (JPanel extra : extraPanels) {
cons.gridy++;
contentPane.add(extra, cons);
}
cons.fill = GridBagConstraints.NONE;
cons.gridy++;
cons.anchor = GridBagConstraints.EAST;
contentPane.add(buttonPanel, cons);
dialog.pack();
dialog.setSize(500, 500);
// center on screen:
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = dialog.getSize();
dialog.setLocation(screenSize.width / 2 - frameSize.width / 2, screenSize.height / 2 - frameSize.height / 2);
dialog.setLocationByPlatform(true);
for (JPanel extra : this.extraPanels) {
if (extra instanceof SavablePanel) {
((SavablePanel) extra).componentShowing();
}
}
dialog.setVisible(true);
}
Aggregations