PageRenderTime 381ms CodeModel.GetById 373ms app.highlight 6ms 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
  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
 23package org.gjt.sp.jedit.gui;
 24
 25//{{{ Imports
 26import javax.swing.*;
 27import javax.swing.border.*;
 28import javax.swing.event.*;
 29import java.awt.*;
 30import java.awt.event.*;
 31import java.util.Vector;
 32import org.gjt.sp.jedit.*;
 33//}}}
 34
 35public class PastePrevious extends EnhancedDialog
 36implements ActionListener, ListSelectionListener, MouseListener
 37{
 38	//{{{ PastePrevious constructor
 39	public PastePrevious(View view)
 40	{
 41		super(view,jEdit.getProperty("pasteprev.title"),true);
 42		this.view = view;
 43
 44		JPanel content = new JPanel(new BorderLayout());
 45		content.setBorder(new EmptyBorder(12,12,12,12));
 46		setContentPane(content);
 47
 48		clipHistory = HistoryModel.getModel("clipboard");
 49
 50		clips = new JList(new AbstractListModel() {
 51			public int getSize()
 52			{
 53				return clipHistory.getSize();
 54			}
 55
 56			public Object getElementAt(int index)
 57			{
 58				return clipHistory.getItem(index);
 59			}
 60		});
 61
 62		clips.setVisibleRowCount(16);
 63
 64		clips.addMouseListener(this);
 65		clips.addListSelectionListener(this);
 66
 67		insert = new JButton(jEdit.getProperty("pasteprev.insert"));
 68		cancel = new JButton(jEdit.getProperty("common.cancel"));
 69
 70		JLabel label = new JLabel(jEdit.getProperty("pasteprev.caption"));
 71		label.setBorder(new EmptyBorder(0,0,6,0));
 72		content.add(BorderLayout.NORTH,label);
 73
 74		JScrollPane scroller = new JScrollPane(clips);
 75		Dimension dim = scroller.getPreferredSize();
 76		scroller.setPreferredSize(new Dimension(640,dim.height));
 77
 78		content.add(scroller, BorderLayout.CENTER);
 79
 80		JPanel panel = new JPanel();
 81		panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));
 82		panel.setBorder(new EmptyBorder(12,0,0,0));
 83		panel.add(Box.createGlue());
 84		panel.add(insert);
 85		panel.add(Box.createHorizontalStrut(6));
 86		panel.add(cancel);
 87		panel.add(Box.createGlue());
 88		content.add(panel, BorderLayout.SOUTH);
 89
 90		if(clipHistory.getSize() >= 1)
 91			clips.setSelectedIndex(0);
 92		updateButtons();
 93
 94		getRootPane().setDefaultButton(insert);
 95		insert.addActionListener(this);
 96		cancel.addActionListener(this);
 97
 98		GUIUtilities.requestFocus(this,clips);
 99
100		pack();
101		setLocationRelativeTo(view);
102		show();
103	} //}}}
104
105	//{{{ ok() method
106	public void ok()
107	{
108		int selected = clips.getSelectedIndex();
109
110		if(selected == -1)
111		{
112			view.getToolkit().beep();
113			return;
114		}
115
116		String clip = clipHistory.getItem(selected);
117		view.getTextArea().setSelectedText(clip);
118
119		dispose();
120	} //}}}
121
122	//{{{ cancel() method
123	public void cancel()
124	{
125		dispose();
126	} //}}}
127
128	//{{{ actionPerformed() method
129	public void actionPerformed(ActionEvent evt)
130	{
131		Object source = evt.getSource();
132		if(source == insert)
133			ok();
134		else if(source == cancel)
135			cancel();
136	} //}}}
137
138	//{{{ mouseClicked() method
139	public void mouseClicked(MouseEvent evt)
140	{
141		if(evt.getClickCount() == 2)
142			ok();
143	} //}}}
144
145	//{{{ Crap
146	public void mouseEntered(MouseEvent evt) {}
147	public void mouseExited(MouseEvent evt) {}
148	public void mousePressed(MouseEvent evt) {}
149	public void mouseReleased(MouseEvent evt) {} //}}}
150
151	//{{{ valueChanged() method
152	public void valueChanged(ListSelectionEvent evt)
153	{
154		updateButtons();
155	} //}}}
156
157	//{{{ Private members
158
159	//{{{ Instance variables
160	private View view;
161	private JList clips;
162	private HistoryModel clipHistory;
163	private JButton insert;
164	private JButton cancel;
165	//}}}
166
167	//{{{ updateButtons() method
168	private void updateButtons()
169	{
170		int selected = clips.getSelectedIndex();
171		insert.setEnabled(selected != -1);
172	} //}}}
173
174	//}}}
175}