PageRenderTime 43ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/EnhancedButton.java

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