Debian Codegraph @

demo/src/main/java/FileView.java

raw
1 /*
2 * Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Distribution License v. 1.0, which is available at
6 * http://www.eclipse.org/org/documents/edl-v10.php.
7 *
8 * SPDX-License-Identifier: BSD-3-Clause
9 */
10
11 import java.awt.*;
12 import java.beans.*;
13 import java.net.*;
14 import jakarta.activation.*;
15
16 public class FileView {
17 private Frame frame;
18
19 public static void main(String args[]) throws Exception {
20 FileView fv = new FileView();
21 if (args.length == 0) {
22 System.out.println("usage: FileView file.txt");
23 System.exit(1);
24 }
25 fv.view(args[0]);
26 }
27
28 private void view(String filename) throws Exception {
29 FileDataSource fds = new FileDataSource(filename);
30 DataHandler dh = new DataHandler(fds);
31 // comment out previous two lines, and uncomment next
32 // line and pass in a URL on the command line.
33 // DataHandler dh = new DataHandler(new URL(filename));
34
35 CommandInfo bi = dh.getCommand("view");
36
37 if (bi == null) {
38 System.out.println("no viewer found, exiting");
39 System.exit(1);
40 }
41
42 frame = new Frame("Viewer");
43 frame.add((Component)dh.getBean(bi));
44 frame.setSize(new Dimension(400,300));
45 frame.show();
46 }
47 }