21 package net.squiz.matrix.inspector;
23 import net.squiz.matrix.matrixtree.*;
24 import net.squiz.matrix.core.*;
25 import net.squiz.matrix.ui.*;
28 import java.awt.event.*;
29 import javax.swing.tree.*;
30 import java.util.List;
31 import java.util.ArrayList;
39 class InspectorNavigator
extends JPanel {
41 private JButton backBtn;
42 private JButton forwardBtn;
43 private ButtonMenu showPathBtn;
44 private InspectorGadget inspector;
45 private TreePath current;
46 private List backPath =
new ArrayList();
47 private List forwardPath =
new ArrayList();
57 public InspectorNavigator(InspectorGadget inspector) {
58 this.inspector = inspector;
59 setBackground(UIManager.getColor(
"InspectorNavigator.background"));
60 setLayout(
new FlowLayout(FlowLayout.LEADING));
67 public void setCurrentPath(TreePath currentPath) {
68 current = currentPath;
76 public void setBackPath(TreePath path) {
77 if (current != null) backPath.add(current);
88 public void updateBackForward() {
89 if (backPath.size() == 0) backBtn.setEnabled(
false);
90 else backBtn.setEnabled(
true);
91 if (forwardPath.size() == 0) forwardBtn.setEnabled(
false);
92 else forwardBtn.setEnabled(
true);
93 if (current.getPathCount() < 2)
94 showPathBtn.setEnabled(
false);
95 else showPathBtn.setEnabled(
true);
97 Object[] treePathObjects =
new Object[current.getPathCount() - 1];
98 for (
int k = 1; k < current.getPathCount(); k++) {
99 treePathObjects[k-1] = current.getPathComponent(k);
102 showPathBtn.setToolTipText(convertPathToString(
new TreePath(treePathObjects)));
108 public void disablePanel() {
109 forwardBtn.setEnabled(
false);
110 backBtn.setEnabled(
false);
111 showPathBtn.setEnabled(
false);
127 private void init() {
129 setBackground(UIManager.getColor(
"InspectorNavigator.background"));
131 ActionListener btnListener =
new ButtonActionListener();
133 backBtn = (JButton) createButton(
"back", btnListener,
"Back",
false);
134 forwardBtn = (JButton) createButton(
"forward", btnListener,
"Forward",
false);
135 showPathBtn = (ButtonMenu) createButton(
"show_path", btnListener,
"Show Path",
true);
157 private AbstractButton createButton(
159 ActionListener listener,
161 boolean buttonMenu) {
163 Icon icon = GUIUtilities.getAssetMapIcon(iconName +
".png");
164 Icon disabledIcon = GUIUtilities.getAssetMapIcon(iconName +
"_disabled.png");
165 Icon pressedIcon = GUIUtilities.getAssetMapIcon(iconName +
"_on.png");
167 AbstractButton button = null;
169 button =
new ButtonMenu(icon, pressedIcon);
171 button =
new JButton(icon);
173 button.setDisabledIcon(disabledIcon);
174 button.setPressedIcon(pressedIcon);
175 button.setBorderPainted(
false);
177 button.setPreferredSize(
new Dimension(icon.getIconWidth(), icon.getIconHeight()));
179 button.addActionListener(listener);
180 button.setToolTipText(toolTipText);
189 private void navigateBack() {
190 int backLastIndex = backPath.size() - 1;
191 TreePath oldPath = (TreePath) backPath.get(backLastIndex);
192 inspector.populateInspector(oldPath);
193 forwardPath.add(current);
195 backPath.remove(backLastIndex);
203 private void navigateNext() {
204 int forwardLastIndex = forwardPath.size() - 1;
205 TreePath oldPath = (TreePath) forwardPath.get(forwardLastIndex);
206 inspector.populateInspector(oldPath);
207 backPath.add(current);
209 forwardPath.remove(forwardLastIndex);
216 private String convertPathToString(TreePath path) {
217 return convertPathToString(path.getPath());
220 private String convertPathToString(Object[] nodes) {
223 for (
int i = 0; i < nodes.length; i++) {
224 pathStr = pathStr + ((MatrixTreeNode) nodes[i]).getName();
225 if (i != nodes.length - 1)
226 pathStr = pathStr +
" > ";
244 class ButtonActionListener
implements ActionListener {
246 private boolean isVisible =
false;
247 private JPopupMenu menu;
253 public void actionPerformed(ActionEvent evt) {
254 Object source = evt.getSource();
256 if (source == backBtn) navigateBack();
257 else if (source == forwardBtn) navigateNext();
258 else if (source == showPathBtn) {
259 showPathBtn.setPopupMenu(getMenu());
263 private JPopupMenu getMenu() {
264 JPopupMenu menu =
new JPopupMenu();
266 ActionListener matrixListener =
new ActionListener() {
267 public void actionPerformed(ActionEvent e) {
268 MatrixTreeNode rootNode
269 = (MatrixTreeNode) AssetManager.getRootFolderNode();
270 TreePath rootPath = inspector.getTree().getPathToRoot(rootNode);
271 inspector.populateInspector(rootPath);
272 setBackPath(rootPath);
276 JMenuItem matrixItem =
new JMenuItem(
"My Matrix System");
277 matrixItem.addActionListener(matrixListener);
278 menu.add(matrixItem);
280 if (current.getPathCount() > 1) menu.addSeparator();
282 for (
int i = 1; i < current.getPathCount(); i++) {
283 final TreePath path = inspector.getTree().getPathToRoot(
284 (MatrixTreeNode) current.getPathComponent(i));
286 Object[] treePathObjects =
new Object[path.getPathCount() - 1];
287 for (
int k = 1; k < path.getPathCount(); k++)
288 treePathObjects[k - 1] = path.getPathComponent(k);
290 String pathStr = convertPathToString(treePathObjects);
291 ActionListener pathListener =
new ActionListener() {
292 public void actionPerformed(ActionEvent evt) {
293 inspector.populateInspector(path);
298 MatrixTreeNode node = (MatrixTreeNode) path.getLastPathComponent();
299 Icon icon = node.getAsset().getType().getIcon();
300 JMenuItem pathItem =
new JMenuItem(pathStr);
301 pathItem.addActionListener(pathListener);
302 pathItem.setIcon(icon);