01: package net.sourceforge.squirrel_sql.client.mainframe.action;
02:
03: /*
04: * Copyright (C) 2002-2003 Colin Bell
05: * colbell@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library 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: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: import java.io.File;
22: import java.io.IOException;
23: import java.net.URL;
24:
25: import net.sourceforge.squirrel_sql.fw.util.BaseException;
26: import net.sourceforge.squirrel_sql.fw.util.ICommand;
27: import net.sourceforge.squirrel_sql.fw.util.StringManager;
28: import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
29: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
30: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
31:
32: import net.sourceforge.squirrel_sql.client.IApplication;
33: import net.sourceforge.squirrel_sql.client.gui.FileViewerFactory;
34: import net.sourceforge.squirrel_sql.client.gui.HtmlViewerSheet;
35:
36: /**
37: * This <CODE>ICommand</CODE> displays the Help window.
38: *
39: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
40: */
41: public class ViewFileCommand implements ICommand {
42: /** Internationalized strings for this class. */
43: private static final StringManager s_stringMgr = StringManagerFactory
44: .getStringManager(ViewFileCommand.class);
45:
46: /** Logger for this class. */
47: private static ILogger s_log = LoggerController
48: .createLogger(ViewFileCommand.class);
49:
50: /** Application API. */
51: private IApplication _app;
52:
53: private File _file;
54:
55: /**
56: * Ctor.
57: *
58: * @param app Application API.
59: * @param file File to be displayed.
60: *
61: * @throws IllegalArgumentException
62: * Thrown if a <TT>null</TT> <TT>IApplication</TT>,
63: * or <TT>File</TT> passed.
64: */
65: public ViewFileCommand(IApplication app, File file) {
66: super ();
67: if (app == null) {
68: throw new IllegalArgumentException(
69: "Null IApplication passed");
70: }
71: if (file == null) {
72: throw new IllegalArgumentException("Null File passed");
73: }
74: _app = app;
75: _file = file;
76: }
77:
78: /**
79: * Display the Dialog
80: */
81: public void execute() throws BaseException {
82: try {
83: URL url = _file.toURL();
84: FileViewerFactory factory = FileViewerFactory.getInstance();
85: HtmlViewerSheet viewer = factory.getViewer(_app
86: .getMainFrame(), url);
87: viewer.setVisible(true);
88: viewer.toFront();
89: viewer.requestFocus();
90: } catch (IOException ex) {
91: final String msg = s_stringMgr
92: .getString("ViewFileCommand.error.reading"
93: + _file.getAbsolutePath());
94: s_log.error(msg, ex);
95: throw new BaseException(ex);
96: }
97: }
98: }
|