PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 166 lines | 99 code | 18 blank | 49 comment | 5 complexity | 763a3ead6a6c4c17316efb1d1e7d7654 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. * FontSelector.java - Font selector
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2000, 2003 Slava Pestov
  7. * Portions copyright (C) 1999 Jason Ginchereau
  8. * Portions copyright (C) 2003 mike dillon
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. */
  24. package org.gjt.sp.jedit.gui;
  25. //{{{ Imports
  26. import java.awt.event.*;
  27. import java.awt.*;
  28. import java.util.ArrayList;
  29. import java.util.List;
  30. import javax.swing.border.*;
  31. import javax.swing.event.*;
  32. import javax.swing.*;
  33. import org.gjt.sp.jedit.*;
  34. import org.gjt.sp.util.Log;
  35. //}}}
  36. //{{{ FontSelector class
  37. /**
  38. * A font chooser widget.
  39. * @author Slava Pestov
  40. * @version $Id: FontSelector.java 17430 2010-03-07 03:16:20Z vanza $
  41. */
  42. public class FontSelector extends JButton
  43. {
  44. //{{{ FontSelector constructor
  45. /**
  46. * Creates a new font selector control.
  47. * @param font The font
  48. */
  49. public FontSelector(Font font)
  50. {
  51. this(font,false);
  52. } //}}}
  53. //{{{ FontSelector constructor
  54. /**
  55. * Creates a new font selector control.
  56. * @param font The font
  57. * @param antiAlias Is anti-aliasing enabled?
  58. * @since jEdit 4.2pre7
  59. */
  60. public FontSelector(Font font, boolean antiAlias)
  61. {
  62. setFont(font);
  63. this.antiAlias = antiAlias;
  64. updateText();
  65. setRequestFocusEnabled(false);
  66. addActionListener(new ActionHandler());
  67. } //}}}
  68. //{{{ paintComponent() method
  69. public void paintComponent(Graphics g)
  70. {
  71. setAntiAliasEnabled(g);
  72. super.paintComponent(g);
  73. } //}}}
  74. //{{{ isAntiAliasEnabled() method
  75. public boolean isAntiAliasEnabled()
  76. {
  77. return antiAlias;
  78. } //}}}
  79. //{{{ setAntiAliasEnabled() method
  80. public void setAntiAliasEnabled(boolean antiAlias)
  81. {
  82. this.antiAlias = antiAlias;
  83. } //}}}
  84. //{{{ updateText() method
  85. private void updateText()
  86. {
  87. Font font = getFont();
  88. String styleString;
  89. switch(font.getStyle())
  90. {
  91. case Font.PLAIN:
  92. styleString = jEdit.getProperty("font-selector.plain");
  93. break;
  94. case Font.BOLD:
  95. styleString = jEdit.getProperty("font-selector.bold");
  96. break;
  97. case Font.ITALIC:
  98. styleString = jEdit.getProperty("font-selector.italic");
  99. break;
  100. case Font.BOLD | Font.ITALIC:
  101. styleString = jEdit.getProperty("font-selector.bolditalic");
  102. break;
  103. default:
  104. styleString = "UNKNOWN!!!???";
  105. break;
  106. }
  107. setText(font.getName() + ' ' + font.getSize() + ' ' + styleString);
  108. } //}}}
  109. //{{{ setAntiAliasEnabled() method
  110. void setAntiAliasEnabled(Graphics g)
  111. {
  112. if (antiAlias)
  113. {
  114. Graphics2D g2 = (Graphics2D)g;
  115. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
  116. RenderingHints.VALUE_ANTIALIAS_ON);
  117. }
  118. } //}}}
  119. private boolean antiAlias;
  120. //{{{ ActionHandler class
  121. class ActionHandler implements ActionListener
  122. {
  123. public void actionPerformed(ActionEvent evt)
  124. {
  125. Font font;
  126. JDialog dialog = GUIUtilities.getParentDialog(FontSelector.this);
  127. if(dialog == null)
  128. {
  129. font = new FontSelectorDialog(
  130. JOptionPane.getFrameForComponent(
  131. FontSelector.this),getFont(),
  132. FontSelector.this)
  133. .getSelectedFont();
  134. }
  135. else
  136. {
  137. font = new FontSelectorDialog(dialog,getFont(),
  138. FontSelector.this)
  139. .getSelectedFont();
  140. }
  141. if(font != null)
  142. {
  143. setFont(font);
  144. updateText();
  145. }
  146. }
  147. } //}}}
  148. } //}}}