public void treeStructureChanged(TreeModelEvent e) {
}
});
configTree = new JTree(treeModel);
Language lang = config.getLanguage();
if (lang == null) {
lang = Language.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);
MouseAdapter ma = new MouseAdapter() {
private void handlePopupEvent(MouseEvent e) {
final JTree tree = (JTree) e.getSource();
TreePath path = tree.getPathForLocation(e.getX(), e.getY());
if (path == null) {
return;
}
DefaultMutableTreeNode node
= (DefaultMutableTreeNode) path.getLastPathComponent();
TreePath[] paths = tree.getSelectionPaths();
boolean isSelected = false;
if (paths != null) {
for (TreePath selectionPath : paths) {
if (selectionPath.equals(path)) {
isSelected = true;
}
}
}
if (!isSelected) {
tree.setSelectionPath(path);
}
if (node.isLeaf()) {
JPopupMenu popup = new JPopupMenu();
final JMenuItem aboutRuleMenuItem = new JMenuItem(messages.getString("guiAboutRuleMenu"));
aboutRuleMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
RuleNode node = (RuleNode) tree.getSelectionPath().getLastPathComponent();
Rule rule = node.getRule();
Language lang = config.getLanguage();
if(lang == null) {
lang = Language.getLanguageForLocale(Locale.getDefault());
}
Tools.showRuleInfoDialog(tree, messages.getString("guiAboutRuleTitle"),
rule.getDescription(), rule, messages,
lang.getShortNameWithCountryAndVariant());
}
});
popup.add(aboutRuleMenuItem);
popup.show(tree, e.getX(), e.getY());
}
}
@Override
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopupEvent(e);
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
handlePopupEvent(e);
}
}
};
configTree.addMouseListener(ma);
final JPanel treeButtonPanel = new JPanel();
cons = new GridBagConstraints();
cons.gridx = 0;
cons.gridy = 0;
final JButton expandAllButton = new JButton(messages.getString("guiExpandAll"));
treeButtonPanel.add(expandAllButton, cons);
expandAllButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TreeNode root = (TreeNode) configTree.getModel().getRoot();
TreePath parent = new TreePath(root);
for (Enumeration categ = root.children(); categ.hasMoreElements();) {
TreeNode n = (TreeNode) categ.nextElement();
TreePath child = parent.pathByAddingChild(n);
configTree.expandPath(child);
}
}
});
cons.gridx = 1;
cons.gridy = 0;
final JButton collapseAllButton = new JButton(messages.getString("guiCollapseAll"));
treeButtonPanel.add(collapseAllButton, cons);
collapseAllButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
TreeNode root = (TreeNode) configTree.getModel().getRoot();
TreePath parent = new TreePath(root);
for (Enumeration categ = root.children(); categ.hasMoreElements();) {
TreeNode n = (TreeNode) categ.nextElement();
TreePath child = parent.pathByAddingChild(n);
configTree.collapsePath(child);
}
}
});
final JPanel motherTonguePanel = new JPanel();
motherTonguePanel.add(new JLabel(messages.getString("guiMotherTongue")), cons);
motherTongueBox = new JComboBox(getPossibleMotherTongues());
if (config.getMotherTongue() != null) {
motherTongueBox.setSelectedItem(config.getMotherTongue().getTranslatedName(messages));
}
motherTongueBox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.SELECTED) {
Language motherTongue;
if (motherTongueBox.getSelectedItem() instanceof String) {
motherTongue = getLanguageForLocalizedName(motherTongueBox.getSelectedItem().toString());
} else {
motherTongue = (Language) motherTongueBox.getSelectedItem();
}