PageRenderTime 467ms CodeModel.GetById 6ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/CommonControls/common/gui/itemfinder/ItemFinderWindow.java

#
Java | 113 lines | 49 code | 8 blank | 56 comment | 0 complexity | 4738daf1c8a47d940a72adf836cc31a0 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. * ItemFinderWindow.java
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2011 Matthieu Casanova
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. */
  22. package common.gui.itemfinder;
  23. //{{{ Imports
  24. import java.awt.EventQueue;
  25. import java.awt.event.WindowAdapter;
  26. import java.awt.event.WindowEvent;
  27. import javax.swing.JDialog;
  28. import org.gjt.sp.jedit.View;
  29. //}}}
  30. /** A Window that contains a SearchField and a list of items.
  31. * When typing in the search field, the item list is updated,
  32. * and when selecting an item of that list, an action is
  33. * triggered.
  34. * To use it, you have to implement {@link ItemFinder}.
  35. *
  36. * Then you have two choices : instantiate {@link ItemFinderWindow} and make it visible,
  37. * or use {@link ItemFinderWindow#showWindow(View, ItemFinder)} that will create the window and show it.
  38. * @author Matthieu Casanova
  39. */
  40. public class ItemFinderWindow<E> extends JDialog
  41. {
  42. private final ItemFinderPanel<E> itemFinderPanel;
  43. public final Runnable requestFocusWorker;
  44. //{{{ ItemFinderWindow constructor
  45. public ItemFinderWindow(ItemFinder<E> itemFinder)
  46. {
  47. setUndecorated(true);
  48. itemFinderPanel = new ItemFinderPanel<E>(this, itemFinder);
  49. requestFocusWorker = itemFinderPanel.requestFocusWorker;
  50. setContentPane(itemFinderPanel);
  51. pack();
  52. addWindowListener(new WindowAdapter()
  53. {
  54. @Override
  55. public void windowDeactivated(WindowEvent e)
  56. {
  57. dispose();
  58. }
  59. });
  60. } //}}}
  61. //{{{ getItemFinderPanel() method
  62. /**
  63. * Returns the ItemFinderPanel.
  64. * This is a JPanel using BorderLayout. The textfield is in the Center,
  65. * the NORTH is a label, you can modify that if you like.
  66. * @return the itemFinderPanel
  67. */
  68. public ItemFinderPanel<E> getItemFinderPanel()
  69. {
  70. return itemFinderPanel;
  71. } //}}}
  72. //{{{ showWindow() methods
  73. /**
  74. * Show the ItemFinderWindow
  75. * @param view the parent view
  76. * @param itemFinder the itemFinder object
  77. * @param <E>
  78. */
  79. public static <E> void showWindow(View view, ItemFinder<E> itemFinder)
  80. {
  81. showWindow(view, itemFinder, "");
  82. }
  83. /**
  84. * Show the ItemFinderWindow
  85. * @param view the parent view
  86. * @param itemFinder the itemFinder object
  87. * @param defaultText the default text
  88. * @param <E>
  89. * @since CommonControls 1.4.1
  90. */
  91. public static <E> void showWindow(View view, ItemFinder<E> itemFinder, final String defaultText)
  92. {
  93. final ItemFinderWindow<E> itemFinderWindow = new ItemFinderWindow<E>(itemFinder);
  94. itemFinderWindow.setLocationRelativeTo(view);
  95. itemFinderWindow.setVisible(true);
  96. EventQueue.invokeLater(new Runnable()
  97. {
  98. @Override
  99. public void run()
  100. {
  101. itemFinderWindow.getItemFinderPanel().setText(defaultText);
  102. }
  103. });
  104. } //}}}
  105. }