16 package net.squiz.matrix.ui;
18 import net.squiz.matrix.matrixtree.*;
19 import net.squiz.matrix.core.*;
21 import javax.swing.tree.*;
23 import java.awt.event.*;
24 import javax.swing.border.*;
31 private SelectionTree selectionTree;
32 private DefaultMutableTreeNode parentNode;
33 private JPopupMenu removeMenu;
39 JPanel contentPane =
new JPanel(
new BorderLayout());
40 setContentPane(contentPane);
42 Border border =
new CompoundBorder(
43 new EmptyBorder(12, 12, 12, 12),
44 new TitledBorder(Matrix.translate(
"asset_map_dialog_title_current_selection"))
46 Border border2 =
new CompoundBorder(
48 new EmptyBorder(8, 8, 8, 8)
50 contentPane.setBorder(border2);
51 contentPane.add(getSelectionPanel());
54 JMenuItem removeItem =
new JMenuItem(Matrix.translate(
"asset_map_menu_remove"));
55 removeItem.addActionListener(
new removeSelectionNodesAction());
56 removeMenu =
new JPopupMenu();
57 removeMenu.add(removeItem);
75 selectionDialog.toFront();
77 return selectionDialog;
84 private void setNodes(
MatrixTreeNode[] nodes,
boolean updateModel) {
87 parentNode.removeAllChildren();
88 for (
int i = 0; i < nodes.length; i++) {
89 parentNode.add(nodes[i]);
92 DefaultTreeModel model = (DefaultTreeModel) selectionTree.getModel();
93 model.nodeStructureChanged(parentNode);
103 setNodes(nodes,
true);
111 parentNode.removeAllChildren();
112 ((DefaultTreeModel) selectionTree.getModel()).nodeStructureChanged(parentNode);
120 private JPanel getSelectionPanel() {
124 parentNode =
new DefaultMutableTreeNode();
125 setNodes(nodes,
false);
126 selectionTree =
new SelectionTree(
new DefaultTreeModel(parentNode));
127 selectionTree.setRootVisible(
false);
129 selectionTree.setCellRenderer(MatrixTreeBus.getCellRenderer());
131 JScrollPane treePane =
new JScrollPane(selectionTree);
132 JButton removeAllBtn =
new JButton(Matrix.translate(
"asset_map_button_remove_all"));
133 JButton removeSelectionBtn =
new JButton(Matrix.translate(
"asset_map_button_remove_selection"));
135 removeAllBtn.addActionListener(
new removeAllNodesAction());
136 removeSelectionBtn.addActionListener(
new removeSelectionNodesAction());
138 GridBagLayout gb =
new GridBagLayout();
139 GridBagConstraints c =
new GridBagConstraints();
140 JPanel selectionPanel =
new JPanel(gb);
143 c.fill = GridBagConstraints.BOTH;
144 c.gridwidth = GridBagConstraints.REMAINDER;
147 gb.setConstraints(treePane, c);
148 selectionPanel.add(treePane);
153 gb.setConstraints(removeAllBtn, c);
154 selectionPanel.add(removeAllBtn);
155 gb.setConstraints(removeSelectionBtn, c);
156 selectionPanel.add(removeSelectionBtn);
158 return selectionPanel;
166 class removeSelectionNodesAction
implements ActionListener {
167 public void actionPerformed(ActionEvent evt) {
168 TreePath[] paths = selectionTree.getSelectionPaths();
172 for (
int i = 0; i < paths.length; i++) {
173 MatrixTreeNode node = (MatrixTreeNode) paths[i].getLastPathComponent();
174 ((DefaultTreeModel) selectionTree.getModel()).removeNodeFromParent(node);
176 Selection.removeNodes(paths);
183 class removeAllNodesAction
implements ActionListener {
184 public void actionPerformed(ActionEvent evt) {
186 Selection.removeAllNodes();
195 class SelectionTree
extends MatrixTree {
200 public SelectionTree(TreeModel model) {
202 setMoveEnabled(
false);
209 protected MenuHandler getMenuHandler() {
210 return new SelectionTreeMenuHandler();
240 if (!isEmptySelection())