1 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 { 30 public BufferSwitcher(final EditPane editPane) 31 { 32 this.editPane = editPane; 33 34 setRenderer(new BufferCellRenderer()); 36 setMaximumRowCount(jEdit.getIntegerProperty("bufferSwitcher.maxRowCount",10)); 37 addActionListener(new ActionHandler()); 38 addPopupMenuListener(new PopupMenuListener() 39 { 40 public void popupMenuWillBecomeVisible( 41 PopupMenuEvent e) {} 42 43 public void popupMenuWillBecomeInvisible( 44 PopupMenuEvent e) 45 { 46 editPane.getTextArea().requestFocus(); 47 } 48 49 public void popupMenuCanceled(PopupMenuEvent e) 50 { 51 editPane.getTextArea().requestFocus(); 52 } 53 }); 54 } 55 56 public void updateBufferList() 57 { 58 if(jEdit.getBufferCount() == 0) 61 return; 62 63 updating = true; 64 setMaximumRowCount(jEdit.getIntegerProperty("bufferSwitcher.maxRowCount",10)); 65 setModel(new DefaultComboBoxModel(jEdit.getBuffers())); 66 setSelectedItem(editPane.getBuffer()); 67 setToolTipText(editPane.getBuffer().getPath()); 68 updating = false; 69 } 70 71 private EditPane editPane; 73 private boolean updating; 74 75 class ActionHandler implements ActionListener 76 { 77 public void actionPerformed(ActionEvent evt) 78 { 79 if(!updating) 80 { 81 Buffer buffer = (Buffer)getSelectedItem(); 82 if(buffer != null) 83 editPane.setBuffer(buffer); 84 } 85 } 86 } 87 88 class BufferCellRenderer extends DefaultListCellRenderer 89 { 90 public Component getListCellRendererComponent( 91 JList list, Object value, int index, 92 boolean isSelected, boolean cellHasFocus) 93 { 94 super.getListCellRendererComponent(list,value,index, 95 isSelected,cellHasFocus); 96 Buffer buffer = (Buffer)value; 97 98 if(buffer == null) 99 setIcon(null); 100 else { 101 setIcon(buffer.getIcon()); 102 setToolTipText(buffer.getPath()); 103 } 104 return this; 105 } 106 } 107 } 108 | Popular Tags |