Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/gjt/sp/jedit/gui/BufferSwitcher.java


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  
20  package org.gjt.sp.jedit.gui;
21  
22  import javax.swing.*;
23  import java.awt.event.*;
24  import java.awt.*;
25  import org.gjt.sp.jedit.*;
26  
27  public class BufferSwitcher extends JComboBox
28  {
29    public BufferSwitcher(EditPane editPane)
30    {
31      this.editPane = editPane;
32  
33      //setFont(new Font("Dialog",Font.BOLD,10));
34      setRenderer(new BufferCellRenderer());
35      setMaximumRowCount(jEdit.getIntegerProperty("bufferSwitcher.maxRowCount",10));
36      addActionListener(new ActionHandler());
37    }
38  
39    public void updateBufferList()
40    {
41      // if the buffer count becomes 0, then it is guaranteed to
42      // become 1 very soon, so don't do anything in that case.
43      if(jEdit.getBufferCount() == 0)
44        return;
45  
46      updating = true;
47      setMaximumRowCount(jEdit.getIntegerProperty("bufferSwitcher.maxRowCount",10));
48      setModel(new DefaultComboBoxModel(jEdit.getBuffers()));
49      setSelectedItem(editPane.getBuffer());
50      updating = false;
51    }
52  
53    // private members
54    private EditPane editPane;
55    private boolean updating;
56  
57    class ActionHandler implements ActionListener
58    {
59      public void actionPerformed(ActionEvent evt)
60      {
61        if(!updating)
62        {
63          Buffer buffer = (Buffer)getSelectedItem();
64          if(buffer != null)
65            editPane.setBuffer(buffer);
66        }
67      }
68    }
69  
70    class BufferCellRenderer extends DefaultListCellRenderer
71    {
72      public Component getListCellRendererComponent(
73        JList list, Object value, int index,
74        boolean isSelected, boolean cellHasFocus)
75      {
76        super.getListCellRendererComponent(list,value,index,
77          isSelected,cellHasFocus);
78        Buffer buffer = (Buffer)value;
79        if(buffer == null)
80          setIcon(null);
81        else
82          setIcon(buffer.getIcon());
83        return this;
84      }
85    }
86  }