PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/EnhancedButton.java

#
Java | 114 lines | 69 code | 13 blank | 32 comment | 9 complexity | 32294fc885fa1976b034e78f93b5cc41 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * EnhancedButton.java - Tool bar button
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1999, 2003 Slava Pestov
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package org.gjt.sp.jedit.gui;
  23. //{{{ Imports
  24. import javax.swing.*;
  25. import java.awt.event.*;
  26. import java.awt.*;
  27. import org.gjt.sp.jedit.*;
  28. //}}}
  29. public class EnhancedButton extends RolloverButton
  30. {
  31. //{{{ EnhancedButton constructor
  32. public EnhancedButton(Icon icon, String toolTip, String action,
  33. ActionContext context)
  34. {
  35. super(icon);
  36. this.action = action;
  37. if(action != null)
  38. {
  39. // set the name of this button :
  40. // for instance, if the action is 'vfs.browser.previous'
  41. // the name will be 'previous'
  42. // this helps greatly in testing the UI with Fest-Swing
  43. int iSuffix = action.lastIndexOf('.');
  44. if(iSuffix<0 || iSuffix == action.length()-1)
  45. {
  46. setName(action);
  47. }
  48. else
  49. {
  50. setName(action.substring(iSuffix+1));
  51. }
  52. setEnabled(true);
  53. addActionListener(new EditAction.Wrapper(context,action));
  54. addMouseListener(new MouseHandler());
  55. }
  56. else
  57. setEnabled(false);
  58. setToolTipText(toolTip);
  59. } //}}}
  60. //{{{ isFocusTraversable() method
  61. public boolean isFocusTraversable()
  62. {
  63. return false;
  64. } //}}}
  65. //{{{ Private members
  66. private String action;
  67. //}}}
  68. //{{{ MouseHandler class
  69. class MouseHandler extends MouseAdapter
  70. {
  71. boolean msgSet = false;
  72. public void mouseReleased(MouseEvent evt)
  73. {
  74. if(msgSet)
  75. {
  76. GUIUtilities.getView((Component)evt.getSource())
  77. .getStatus().setMessage(null);
  78. msgSet = false;
  79. }
  80. }
  81. public void mouseEntered(MouseEvent evt)
  82. {
  83. String msg = jEdit.getProperty(action + ".mouse-over");
  84. if(msg != null)
  85. {
  86. GUIUtilities.getView((Component)evt.getSource())
  87. .getStatus().setMessage(msg);
  88. msgSet = true;
  89. }
  90. }
  91. public void mouseExited(MouseEvent evt)
  92. {
  93. if(msgSet)
  94. {
  95. GUIUtilities.getView((Component)evt.getSource())
  96. .getStatus().setMessage(null);
  97. msgSet = false;
  98. }
  99. }
  100. } //}}}
  101. }