01: /*
02: * Copyright (c) 2000, Jacob Smullyan.
03: *
04: * This is part of SkunkDAV, a WebDAV client. See http://skunkdav.sourceforge.net/
05: * for the latest version.
06: *
07: * SkunkDAV is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License as published
09: * by the Free Software Foundation; either version 2, or (at your option)
10: * any later version.
11: *
12: * SkunkDAV is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with SkunkDAV; see the file COPYING. If not, write to the Free
19: * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20: * 02111-1307, USA.
21: */
22:
23: package org.skunk.dav.client.gui.editor.action;
24:
25: import java.awt.event.ActionEvent;
26: import javax.swing.AbstractAction;
27: import javax.swing.JComponent;
28: import org.skunk.dav.client.gui.Buffer;
29: import org.skunk.dav.client.gui.ExplorerApp;
30: import org.skunk.dav.client.gui.ResourceManager;
31: import org.skunk.dav.client.gui.StatusInputPanel;
32: import org.skunk.dav.client.gui.View;
33: import org.skunk.dav.client.gui.editor.SimpleTextEditor;
34: import org.skunk.swing.text.PositiveIntegerEntryFilter;
35: import org.skunk.trace.Debug;
36:
37: public class GotoLineAction extends AbstractAction {
38: public void actionPerformed(ActionEvent ae) {
39: Object source = ae.getSource();
40: View currentView = ExplorerApp.getAppContext().getCurrentView();
41:
42: if (source instanceof StatusInputPanel) {
43: StatusInputPanel panel = (StatusInputPanel) source;
44: Buffer buffy = currentView.getFocussedBuffer();
45: if (buffy != null && buffy instanceof SimpleTextEditor) {
46: SimpleTextEditor editor = (SimpleTextEditor) buffy;
47: try {
48: String s = panel.getInputText();
49: if (s != null) {
50: int i = Integer.parseInt(s);
51: editor.gotoLine(i - 1);
52: }
53: } catch (NumberFormatException nafta) {
54: Debug.trace(this , Debug.DP3, nafta);
55: }
56: }
57: panel.removeActionListener(this );
58: currentView.undockStatus(panel);
59: panel = null;
60: buffy.getComponent().requestFocus();
61: } else {
62: String label = ResourceManager
63: .getMessage(ResourceManager.GOTO_LINE_PROMPT);
64: int length = 5;
65: PositiveIntegerEntryFilter filter = new PositiveIntegerEntryFilter(
66: 1, Integer.MAX_VALUE);
67: StatusInputPanel sip = new StatusInputPanel(label, length,
68: filter);
69: sip.addActionListener(new GotoLineAction());
70: currentView.dockStatus(sip);
71: sip.focus();
72: }
73: }
74: }
|