PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/gui/BufferSwitcher.java

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