PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 113 lines | 71 code | 9 blank | 33 comment | 5 complexity | 70e173c09b69dcd4133b8e04fd26de72 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. * MultiSelectWidgetFactory.java - The clock widget service
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2008 Matthieu Casanova
  7. * Portions Copyright (C) 2001, 2004 Slava Pestov
  8. * Portions copyright (C) 2001 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.statusbar;
  25. //{{{ Imports
  26. import java.awt.*;
  27. import java.awt.event.MouseAdapter;
  28. import java.awt.event.MouseEvent;
  29. import javax.swing.*;
  30. import org.gjt.sp.jedit.GUIUtilities;
  31. import org.gjt.sp.jedit.View;
  32. import org.gjt.sp.jedit.gui.CompletionPopup;
  33. import org.gjt.sp.jedit.jEdit;
  34. import org.gjt.sp.jedit.textarea.JEditTextArea;
  35. //}}}
  36. /**
  37. * @author Matthieu Casanova
  38. * @since jEdit 4.3pre14
  39. */
  40. public class MultiSelectWidgetFactory implements StatusWidgetFactory
  41. {
  42. //{{{ getWidget() method
  43. public Widget getWidget(View view)
  44. {
  45. Widget multiSelect = new MultiSelectWidget(view);
  46. return multiSelect;
  47. } //}}}
  48. //{{{ MultiSelectWidget class
  49. private static class MultiSelectWidget implements Widget
  50. {
  51. private final JLabel multiSelect;
  52. private final View view;
  53. MultiSelectWidget(final View view)
  54. {
  55. multiSelect = new ToolTipLabel();
  56. multiSelect.setHorizontalAlignment(SwingConstants.CENTER);
  57. multiSelect.setToolTipText(jEdit.getProperty("view.status.multi-tooltip"));
  58. this.view = view;
  59. multiSelect.addMouseListener(new MouseAdapter()
  60. {
  61. @Override
  62. public void mouseClicked(MouseEvent e)
  63. {
  64. JEditTextArea textArea = view.getTextArea();
  65. if (textArea != null)
  66. textArea.toggleMultipleSelectionEnabled();
  67. }
  68. });
  69. }
  70. public JComponent getComponent()
  71. {
  72. return multiSelect;
  73. }
  74. public void update()
  75. {
  76. JEditTextArea textArea = view.getTextArea();
  77. if (textArea != null)
  78. {
  79. if (textArea.isMultipleSelectionEnabled())
  80. {
  81. multiSelect.setText("M");
  82. multiSelect.setEnabled(true);
  83. }
  84. else
  85. {
  86. multiSelect.setText("m");
  87. multiSelect.setEnabled(false);
  88. }
  89. }
  90. }
  91. public void propertiesChanged()
  92. {
  93. // retarded GTK look and feel!
  94. Font font = new JLabel().getFont();
  95. //UIManager.getFont("Label.font");
  96. FontMetrics fm = multiSelect.getFontMetrics(font);
  97. Dimension dim = new Dimension(
  98. Math.max(fm.charWidth('m'),fm.charWidth('M')) + 1,
  99. fm.getHeight());
  100. multiSelect.setPreferredSize(dim);
  101. multiSelect.setMaximumSize(dim);
  102. }
  103. } //}}}
  104. }