PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/BufferSwitcher.java

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