PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/org/gjt/sp/jedit/gui/BufferSwitcher.java

#
Java | 88 lines | 57 code | 9 blank | 22 comment | 7 complexity | a84348ca629cf328a01d89abd0eddd5a 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(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. setModel(new DefaultComboBoxModel(jEdit.getBuffers()));
  45. setSelectedItem(editPane.getBuffer());
  46. updating = false;
  47. }
  48. // private members
  49. private EditPane editPane;
  50. private boolean updating;
  51. class ActionHandler implements ActionListener
  52. {
  53. public void actionPerformed(ActionEvent evt)
  54. {
  55. if(!updating)
  56. {
  57. Buffer buffer = (Buffer)getSelectedItem();
  58. if(buffer != null)
  59. editPane.setBuffer(buffer);
  60. }
  61. }
  62. }
  63. class BufferCellRenderer extends DefaultListCellRenderer
  64. {
  65. public Component getListCellRendererComponent(
  66. JList list, Object value, int index,
  67. boolean isSelected, boolean cellHasFocus)
  68. {
  69. super.getListCellRendererComponent(list,value,index,
  70. isSelected,cellHasFocus);
  71. Buffer buffer = (Buffer)value;
  72. if(buffer == null)
  73. setIcon(null);
  74. else
  75. setIcon(buffer.getIcon());
  76. return this;
  77. }
  78. }
  79. }