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