PageRenderTime 123ms CodeModel.GetById 100ms app.highlight 6ms RepoModel.GetById 14ms app.codeStats 0ms

/jEdit/tags/jedit-4-1-pre5/org/gjt/sp/jedit/gui/BufferSwitcher.java

#
Java | 89 lines | 58 code | 9 blank | 22 comment | 7 complexity | c3010a85909219c198ebdf2975587752 MD5 | raw file
 1/*
 2 * BufferSwitcher.java - Status bar
 3 * Copyright (C) 2000 Slava Pestov
 4 *
 5 * This program is free software; you can redistribute it and/or
 6 * modify it under the terms of the GNU General Public License
 7 * as published by the Free Software Foundation; either version 2
 8 * of the License, or any later version.
 9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20package org.gjt.sp.jedit.gui;
21
22import javax.swing.border.*;
23import javax.swing.*;
24import java.awt.event.*;
25import java.awt.*;
26import org.gjt.sp.jedit.textarea.JEditTextArea;
27import org.gjt.sp.jedit.*;
28import org.gjt.sp.util.*;
29
30public class BufferSwitcher extends JComboBox
31{
32	public BufferSwitcher(EditPane editPane)
33	{
34		this.editPane = editPane;
35
36		//setFont(new Font("Dialog",Font.BOLD,10));
37		setRenderer(new BufferCellRenderer());
38		setMaximumRowCount(jEdit.getIntegerProperty("bufferSwitcher.maxRowCount",10));
39		addActionListener(new ActionHandler());
40	}
41
42	public void updateBufferList()
43	{
44		// if the buffer count becomes 0, then it is guaranteed to
45		// become 1 very soon, so don't do anything in that case.
46		if(jEdit.getBufferCount() == 0)
47			return;
48
49		updating = true;
50		setMaximumRowCount(jEdit.getIntegerProperty("bufferSwitcher.maxRowCount",10));
51		setModel(new DefaultComboBoxModel(jEdit.getBuffers()));
52		setSelectedItem(editPane.getBuffer());
53		updating = false;
54	}
55
56	// private members
57	private EditPane editPane;
58	private boolean updating;
59
60	class ActionHandler implements ActionListener
61	{
62		public void actionPerformed(ActionEvent evt)
63		{
64			if(!updating)
65			{
66				Buffer buffer = (Buffer)getSelectedItem();
67				if(buffer != null)
68					editPane.setBuffer(buffer);
69			}
70		}
71	}
72
73	class BufferCellRenderer extends DefaultListCellRenderer
74	{
75		public Component getListCellRendererComponent(
76			JList list, Object value, int index,
77			boolean isSelected, boolean cellHasFocus)
78		{
79			super.getListCellRendererComponent(list,value,index,
80				isSelected,cellHasFocus);
81			Buffer buffer = (Buffer)value;
82			if(buffer == null)
83				setIcon(null);
84			else
85				setIcon(buffer.getIcon());
86			return this;
87		}
88	}
89}