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