01: /*
02: * BufferSwitcher.java - Status bar
03: * Copyright (C) 2000, 2004 Slava Pestov
04: *
05: * This program is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU General Public License
07: * as published by the Free Software Foundation; either version 2
08: * of the License, or any later version.
09: *
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:
20: package org.gjt.sp.jedit.gui;
21:
22: import javax.swing.event.*;
23: import javax.swing.*;
24: import java.awt.event.*;
25: import java.awt.*;
26: import org.gjt.sp.jedit.*;
27:
28: public class BufferSwitcher extends JComboBox {
29: public BufferSwitcher(final EditPane editPane) {
30: this .editPane = editPane;
31:
32: //setFont(new Font("Dialog",Font.BOLD,10));
33: setRenderer(new BufferCellRenderer());
34: setMaximumRowCount(jEdit.getIntegerProperty(
35: "bufferSwitcher.maxRowCount", 10));
36: addActionListener(new ActionHandler());
37: addPopupMenuListener(new PopupMenuListener() {
38: public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
39: }
40:
41: public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
42: editPane.getTextArea().requestFocus();
43: }
44:
45: public void popupMenuCanceled(PopupMenuEvent e) {
46: editPane.getTextArea().requestFocus();
47: }
48: });
49: }
50:
51: public void updateBufferList() {
52: // if the buffer count becomes 0, then it is guaranteed to
53: // become 1 very soon, so don't do anything in that case.
54: if (jEdit.getBufferCount() == 0)
55: return;
56:
57: updating = true;
58: setMaximumRowCount(jEdit.getIntegerProperty(
59: "bufferSwitcher.maxRowCount", 10));
60: setModel(new DefaultComboBoxModel(jEdit.getBuffers()));
61: setSelectedItem(editPane.getBuffer());
62: setToolTipText(editPane.getBuffer().getPath());
63: updating = false;
64: }
65:
66: // private members
67: private EditPane editPane;
68: private boolean updating;
69:
70: class ActionHandler implements ActionListener {
71: public void actionPerformed(ActionEvent evt) {
72: if (!updating) {
73: Buffer buffer = (Buffer) getSelectedItem();
74: if (buffer != null)
75: editPane.setBuffer(buffer);
76: }
77: }
78: }
79:
80: class BufferCellRenderer extends DefaultListCellRenderer {
81: public Component getListCellRendererComponent(JList list,
82: Object value, int index, boolean isSelected,
83: boolean cellHasFocus) {
84: super .getListCellRendererComponent(list, value, index,
85: isSelected, cellHasFocus);
86: Buffer buffer = (Buffer) value;
87:
88: if (buffer == null)
89: setIcon(null);
90: else {
91: setIcon(buffer.getIcon());
92: setToolTipText(buffer.getPath());
93: }
94: return this;
95: }
96: }
97: }
|