PageRenderTime 52ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 175 lines | 109 code | 31 blank | 35 comment | 11 complexity | 600d59cf79e06bbeabd330674727751e 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. * PastePrevious.java - Paste previous dialog
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 1998, 1999, 2001 Slava Pestov
  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 org.gjt.sp.jedit.gui;
  23. //{{{ Imports
  24. import javax.swing.*;
  25. import javax.swing.border.*;
  26. import javax.swing.event.*;
  27. import java.awt.*;
  28. import java.awt.event.*;
  29. import java.util.Vector;
  30. import org.gjt.sp.jedit.*;
  31. //}}}
  32. public class PastePrevious extends EnhancedDialog
  33. implements ActionListener, ListSelectionListener, MouseListener
  34. {
  35. //{{{ PastePrevious constructor
  36. public PastePrevious(View view)
  37. {
  38. super(view,jEdit.getProperty("pasteprev.title"),true);
  39. this.view = view;
  40. JPanel content = new JPanel(new BorderLayout());
  41. content.setBorder(new EmptyBorder(12,12,12,12));
  42. setContentPane(content);
  43. clipHistory = HistoryModel.getModel("clipboard");
  44. clips = new JList(new AbstractListModel() {
  45. public int getSize()
  46. {
  47. return clipHistory.getSize();
  48. }
  49. public Object getElementAt(int index)
  50. {
  51. return clipHistory.getItem(index);
  52. }
  53. });
  54. clips.setVisibleRowCount(16);
  55. clips.addMouseListener(this);
  56. clips.addListSelectionListener(this);
  57. insert = new JButton(jEdit.getProperty("pasteprev.insert"));
  58. cancel = new JButton(jEdit.getProperty("common.cancel"));
  59. JLabel label = new JLabel(jEdit.getProperty("pasteprev.caption"));
  60. label.setBorder(new EmptyBorder(0,0,6,0));
  61. content.add(BorderLayout.NORTH,label);
  62. JScrollPane scroller = new JScrollPane(clips);
  63. Dimension dim = scroller.getPreferredSize();
  64. scroller.setPreferredSize(new Dimension(640,dim.height));
  65. content.add(scroller, BorderLayout.CENTER);
  66. JPanel panel = new JPanel();
  67. panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
  68. panel.setBorder(new EmptyBorder(12,0,0,0));
  69. panel.add(Box.createGlue());
  70. panel.add(insert);
  71. panel.add(Box.createHorizontalStrut(6));
  72. panel.add(cancel);
  73. panel.add(Box.createGlue());
  74. content.add(panel, BorderLayout.SOUTH);
  75. if(clipHistory.getSize() >= 1)
  76. clips.setSelectedIndex(0);
  77. updateButtons();
  78. getRootPane().setDefaultButton(insert);
  79. insert.addActionListener(this);
  80. cancel.addActionListener(this);
  81. GUIUtilities.requestFocus(this,clips);
  82. pack();
  83. setLocationRelativeTo(view);
  84. show();
  85. } //}}}
  86. //{{{ ok() method
  87. public void ok()
  88. {
  89. int selected = clips.getSelectedIndex();
  90. if(selected == -1)
  91. {
  92. view.getToolkit().beep();
  93. return;
  94. }
  95. String clip = clipHistory.getItem(selected);
  96. view.getTextArea().setSelectedText(clip);
  97. dispose();
  98. } //}}}
  99. //{{{ cancel() method
  100. public void cancel()
  101. {
  102. dispose();
  103. } //}}}
  104. //{{{ actionPerformed() method
  105. public void actionPerformed(ActionEvent evt)
  106. {
  107. Object source = evt.getSource();
  108. if(source == insert)
  109. ok();
  110. else if(source == cancel)
  111. cancel();
  112. } //}}}
  113. //{{{ mouseClicked() method
  114. public void mouseClicked(MouseEvent evt)
  115. {
  116. if(evt.getClickCount() == 2)
  117. ok();
  118. } //}}}
  119. //{{{ Crap
  120. public void mouseEntered(MouseEvent evt) {}
  121. public void mouseExited(MouseEvent evt) {}
  122. public void mousePressed(MouseEvent evt) {}
  123. public void mouseReleased(MouseEvent evt) {} //}}}
  124. //{{{ valueChanged() method
  125. public void valueChanged(ListSelectionEvent evt)
  126. {
  127. updateButtons();
  128. } //}}}
  129. //{{{ Private members
  130. //{{{ Instance variables
  131. private View view;
  132. private JList clips;
  133. private HistoryModel clipHistory;
  134. private JButton insert;
  135. private JButton cancel;
  136. //}}}
  137. //{{{ updateButtons() method
  138. private void updateButtons()
  139. {
  140. int selected = clips.getSelectedIndex();
  141. insert.setEnabled(selected != -1);
  142. } //}}}
  143. //}}}
  144. }