PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/gui/BufferSwitcher.java

#
Java | 88 lines | 57 code | 9 blank | 22 comment | 7 complexity | a84348ca629cf328a01d89abd0eddd5a 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(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		setModel(new DefaultComboBoxModel(jEdit.getBuffers()));
51		setSelectedItem(editPane.getBuffer());
52		updating = false;
53	}
54
55	// private members
56	private EditPane editPane;
57	private boolean updating;
58
59	class ActionHandler implements ActionListener
60	{
61		public void actionPerformed(ActionEvent evt)
62		{
63			if(!updating)
64			{
65				Buffer buffer = (Buffer)getSelectedItem();
66				if(buffer != null)
67					editPane.setBuffer(buffer);
68			}
69		}
70	}
71
72	class BufferCellRenderer extends DefaultListCellRenderer
73	{
74		public Component getListCellRendererComponent(
75			JList list, Object value, int index,
76			boolean isSelected, boolean cellHasFocus)
77		{
78			super.getListCellRendererComponent(list,value,index,
79				isSelected,cellHasFocus);
80			Buffer buffer = (Buffer)value;
81			if(buffer == null)
82				setIcon(null);
83			else
84				setIcon(buffer.getIcon());
85			return this;
86		}
87	}
88}