PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/gui/EnhancedButton.java

#
Java | 102 lines | 62 code | 12 blank | 28 comment | 6 complexity | b5119a53dad8f7a221b1b991dc23ff08 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. this.context = context;
  38. if(action != null)
  39. {
  40. setEnabled(true);
  41. addActionListener(new EditAction.Wrapper(context,action));
  42. addMouseListener(new MouseHandler());
  43. }
  44. else
  45. setEnabled(false);
  46. setToolTipText(toolTip);
  47. } //}}}
  48. //{{{ isFocusTraversable() method
  49. public boolean isFocusTraversable()
  50. {
  51. return false;
  52. } //}}}
  53. //{{{ Private members
  54. private ActionContext context;
  55. private String action;
  56. //}}}
  57. //{{{ MouseHandler class
  58. class MouseHandler extends MouseAdapter
  59. {
  60. boolean msgSet = false;
  61. public void mouseReleased(MouseEvent evt)
  62. {
  63. if(msgSet)
  64. {
  65. GUIUtilities.getView((Component)evt.getSource())
  66. .getStatus().setMessage(null);
  67. msgSet = false;
  68. }
  69. }
  70. public void mouseEntered(MouseEvent evt)
  71. {
  72. String msg = jEdit.getProperty(action + ".mouse-over");
  73. if(msg != null)
  74. {
  75. GUIUtilities.getView((Component)evt.getSource())
  76. .getStatus().setMessage(msg);
  77. msgSet = true;
  78. }
  79. }
  80. public void mouseExited(MouseEvent evt)
  81. {
  82. if(msgSet)
  83. {
  84. GUIUtilities.getView((Component)evt.getSource())
  85. .getStatus().setMessage(null);
  86. msgSet = false;
  87. }
  88. }
  89. } //}}}
  90. }