PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/org/dotuseful/ui/tree/MouseAdaptedTree.java

https://bitbucket.org/synic/jbother
Java | 120 lines | 22 code | 6 blank | 92 comment | 0 complexity | 105817bdb0a13072c42bcbc9c8dc5fbd MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1
  1. /*
  2. * Created on 21/7/2004
  3. *
  4. * Copyright (C) 2004 Denis Krukovsky. All rights reserved.
  5. * ====================================================================
  6. * The Software License (based on Apache Software License, Version 1.1)
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by
  23. * Denis Krukovsky (dkrukovsky at yahoo.com)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "dot useful" and "Denis Krukovsky" must not be used to
  28. * endorse or promote products derived from this software without
  29. * prior written permission. For written permission, please
  30. * contact dkrukovsky at yahoo.com.
  31. *
  32. * 5. Products derived from this software may not be called "useful",
  33. * nor may "useful" appear in their name, without prior written
  34. * permission of Denis Krukovsky.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL JIVE SOFTWARE OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. */
  50. package org.dotuseful.ui.tree;
  51. import javax.swing.JTree;
  52. import javax.swing.tree.DefaultTreeModel;
  53. import javax.swing.tree.TreeModel;
  54. import javax.swing.tree.TreeNode;
  55. /**
  56. * A tree control which transmits mouse events to its nodes. Its nodes must
  57. * implement MouseListener interface.
  58. *
  59. * To work with this tree, you <br>- provide it with TreeModel which contains
  60. * tree nodes which implement MouseListener, or <br>- provide it with TreeNode
  61. * root which and all its descendants are implement MouseListener.
  62. *
  63. * @author Denis Krukovsky
  64. *
  65. */
  66. public class MouseAdaptedTree extends JTree {
  67. /**
  68. * Returns an instance of <code>MouseAdaptedTree</code> which displays the
  69. * root node -- the tree is created using the specified data model.
  70. *
  71. * @param newModel
  72. * the <code>TreeModel</code> to use as the data model
  73. */
  74. public MouseAdaptedTree(TreeModel newModel) {
  75. super(newModel);
  76. addMouseHandler();
  77. }
  78. /**
  79. * Returns a <code>MouseAdaptedTree</code> with the specified
  80. * <code>TreeNode</code> as its root, which displays the root node. By
  81. * default, the tree defines a leaf node as any node without children.
  82. *
  83. * @param root
  84. * a <code>TreeNode</code> object
  85. * @see DefaultTreeModel#asksAllowsChildren
  86. */
  87. public MouseAdaptedTree(TreeNode root) {
  88. super(root);
  89. addMouseHandler();
  90. }
  91. /**
  92. * Returns a <code>MouseAdaptedTree</code> with the specified
  93. * <code>TreeNode</code> as its root, which displays the root node and
  94. * which decides whether a node is a leaf node in the specified manner.
  95. *
  96. * @param root
  97. * a <code>TreeNode</code> object
  98. * @param asksAllowsChildren
  99. * if false, any node without children is a leaf node; if true,
  100. * only nodes that do not allow children are leaf nodes
  101. * @see DefaultTreeModel#asksAllowsChildren
  102. */
  103. public MouseAdaptedTree(TreeNode root, boolean asksAllowsChildren) {
  104. super(root, asksAllowsChildren);
  105. addMouseHandler();
  106. }
  107. /**
  108. * Adds MouseAdaptedTreeMouseHandler mouse listener to transmit mouse events
  109. * to corresponding nodes.
  110. */
  111. protected void addMouseHandler() {
  112. addMouseListener(new MouseAdaptedTreeMouseHandler());
  113. }
  114. }