View Javadoc
1   /**
2    *
3    */
4   package net.sf.jtreemap.swing.provider;
5   
6   import java.awt.event.ActionEvent;
7   
8   import javax.swing.AbstractAction;
9   import javax.swing.Icon;
10  import javax.swing.tree.TreePath;
11  
12  import net.sf.jtreemap.swing.JTreeMap;
13  import net.sf.jtreemap.swing.TreeMapNode;
14  
15  public class ZoomAction extends AbstractAction {
16      private static final long serialVersionUID = -8559400865920393294L;
17  
18      private final TreeMapNode node;
19      private final JTreeMap jTreeMap;
20  
21      /**
22       * Constructor
23       *
24       * @param node
25       *            where you want to zoom/unzoom
26       * @param icon
27       *            icon corresponding to the operation (zoom or unzoom)
28       */
29      public ZoomAction(final JTreeMap jTreeMap, final TreeMapNode node, final Icon icon) {
30          super(node.getLabel(), icon);
31          this.node = node;
32          this.jTreeMap = jTreeMap;
33      }
34  
35      /*
36       * (non-Javadoc)
37       *
38       * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
39       */
40      @Override
41      public void actionPerformed(final ActionEvent e) {
42          if (jTreeMap.getTreeView() == null) {
43              jTreeMap.zoom(this.node);
44              jTreeMap.repaint();
45          } else {
46              final TreePath path = new TreePath(this.node.getPath());
47              jTreeMap.getTreeView().setSelectionPath(path);
48              jTreeMap.getTreeView().scrollPathToVisible(path);
49          }
50  
51      }
52  
53      /*
54       * (non-Javadoc)
55       *
56       * @see javax.swing.Action#isEnabled()
57       */
58      @Override
59      public boolean isEnabled() {
60          return true;
61      }
62  }