PicWeb.java
资源名称:picweb.zip [点击查看]
上传用户:shengda799
上传日期:2007-01-10
资源大小:68k
文件大小:10k
源码类别:
图片显示
开发平台:
Java
- // PicWeb.java
- //
- // This software is Copyright 1998, 2000, 2001 by Mark Watson.
- // This software may be freely used for any purpose
- // and may be modified for any purpose as long as
- // you agree to the following:
- //
- // 1. Any bug fixes or enhancements that you make must be emailed
- // back to Mark Watson (markw@markwatson.com) for possible
- // inclusion in the source code base that is available at
- // the web site www.markwatson.com (credit will be given
- // to contributers).
- //
- // 2. This copyright notice must be kept with the source code
- // and duplicated if you distribute a modified verison of
- // this software in binary form.
- //
- // 3. You will not re-distribute the source code. Rather, any
- // improvements to this program will be returned to Mark
- // Watson so that there is always one source base at
- // the web site www.markwatson.com (you may freely
- // distribute compiled derived versions of this program
- // without any restrictions as long as this entire
- // copyright notice is reproduced with the application
- // (e.g., in the 'help' or 'about' dialog box).
- //
- // 4. This software may not be used for any illegal purpose.
- //
- // 5. You take all responsibility for the use of this software:
- //
- // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- // SUCH DAMAGE.
- // OpenSource contributers: Original program: Mark Watson (markw@markwatson.com)
- //
- // Name Email (optional) + changes
- // ---- --------------------------
- // 3.0 Achille Petrilli Achille.Petrilli@cern.ch (directory pop-up, new fonts, larger icons)
- // 4.1 Tony Allan tony@apms.com.au (sorted files, selectable html filename, saved options)
- // 4.2 Tony Allan tony@apms.com.au (fix .html bug, added height/width to HTML, don't write any
- // entry if the subdirectory doesn't have any images, add option
- // to select if thumbnails are reprocessed)
- // 4.3 Reinout van Schouwen rmvschou@cs.vu.nl (added tables and cleaned up HTML generation)
- // 6.0 Mark Watson: added an option to not generate thumbnail images
- // 7.0 Mark Watson: separated PicWeb.java into two parts: a GUI (PicWeb.java) and and
- // engine to generate thumbnail image files and HTML files (Engine.java)
- import java.applet.*;
- import java.awt.*;
- import java.awt.image.*;
- import java.awt.event.*;
- import java.awt.Image;
- import java.awt.Graphics;
- import java.io.*;
- import java.net.*;
- import java.util.*;
- /** PicWeb class contains both the user interface and uses the separate class
- * Engine to produce Thumbnail image files and HTML files
- */
- public class PicWeb extends Panel implements Serializable, Runnable {
- protected static final String version = "7.0";
- private static final int[] ALLFS = {10, 12, 14, 20, 24};
- private static final int[] MACFS = {8, 10, 12, 14, 18};
- Options options;
- private OptionsDialog optionsDialog;
- private FileDialog f_dialog;
- private Logo logo;
- private transient TextField root_dir;
- private transient TextArea outputText;
- private transient Button p_button;
- private transient PicWeb picweb;
- private boolean process;
- private Thread workThread;
- /**
- * work engine tht generate thumbnail images nd HTML code
- */
- private Engine engine;
- public static void main(String args []) {
- String initializationFileName = "PicWeb.ini";
- if (args.length >0) {
- initializationFileName = args[0];
- }
- AppFrame f = new AppFrame();
- PicWeb pw = new PicWeb(initializationFileName);
- f.add(pw);
- f.pack();
- f.show();
- }
- /** PicWeb class constructor creates the user interface Panel
- * and initializes a work thread
- */
- public PicWeb(String initializationFileName) {
- options = new Options();
- options.iniFile = initializationFileName;
- options.ini = new Properties(); // (ta 4.1) properties support
- try {
- options.ini.load(new BufferedInputStream(new FileInputStream(options.iniFile)));
- }
- catch (FileNotFoundException e) {} // use defaults if file not found
- catch (IOException e) {System.out.println(e);} // print error then use defaults for other errors
- options.updateFromFile();
- try {
- options.imageSizeChoice = Integer.parseInt(options.ini.getProperty("imageSizeChoice" ,"3"));
- } catch (NumberFormatException e) {options.imageSizeChoice = 3;}
- options.HTMLFilename = options.ini.getProperty("HTMLFilename" ,"pics.htm");
- String os = System.getProperty("os.name","not found");
- if (os.startsWith("Mac"))
- options.fontSizes = MACFS;
- else
- options.fontSizes = ALLFS;
- DialogFrame o_frame = new DialogFrame();
- optionsDialog = new OptionsDialog(o_frame, this, options);
- process = false;
- setFont(new Font("Dialog", Font.PLAIN, options.fontSizes[1]));
- setLayout(null);
- Label l0 = new Label("PicWeb Builder " + version + " www.markwatson.com");
- l0.setFont(new Font("Dialog", Font.BOLD, options.fontSizes[3]));
- add(l0);
- l0.setBounds(5, 3, 414, 30);
- Label l1 = new Label("directory:");
- add(l1);
- l1.setBounds(5, 50, 60, 30);
- options.dirSpec = options.ini.getProperty("directory", (new File("").getAbsolutePath()));
- root_dir = new TextField(options.dirSpec, 40);
- add(root_dir);
- root_dir.setBounds(65, 50, 170, 30);
- f_dialog = new FileDialog(o_frame,"PicWeb - Select a directory...");
- f_dialog.setModal(true);
- f_dialog.setDirectory(root_dir.getText());
- Button b_button = new Button("Browse...");
- b_button.addActionListener(new Dbrowser());
- add(b_button);
- b_button.setBounds(240, 50, 60, 30);
- p_button = new Button("Process");
- p_button.addActionListener(new MouseProcess());
- add(p_button);
- p_button.setBounds(370, 50, 60, 30);
- Button help_button = new Button("Options...");
- help_button.addActionListener(new MouseOptions());
- add(help_button);
- help_button.setBounds(305, 50, 60, 30);
- logo = new Logo(this, 50, 50);
- add(logo);
- logo.setBounds(440, 6, 50, 50);
- int scrollBars = 0;
- try {
- scrollBars =
- Integer.parseInt(options.ini.getProperty("scrollBars" ,
- Integer.toString(TextArea.SCROLLBARS_BOTH)));
- } catch (NumberFormatException e) {options.imageSizeChoice = TextArea.SCROLLBARS_BOTH;}
- outputText = new TextArea(copyright, 6, 82, scrollBars);
- add(outputText);
- outputText.setBounds(5, 115, 550, 110);
- setBounds(20, 40, 580, 230);
- engine = new Engine(this, logo, options);
- picweb = this; // used to start work thread in inner class MouseProcess
- }
- /**
- * callback used by the Engine class
- */
- public void print(String s) {
- outputText.append(s);
- }
- // ----------------------------------------------------------------------
- class Dbrowser implements ActionListener, Serializable {
- public void actionPerformed(ActionEvent e) {
- f_dialog.setDirectory(root_dir.getText());
- f_dialog.setFile("dummy.txt");
- f_dialog.show();
- String d = f_dialog.getDirectory();
- if (d == null)
- d = "";
- if (d.length() <= 1)
- d = "";
- if (d.endsWith(File.separator))
- d = d.substring(0, d.length() - 1);
- root_dir.setText(d);
- }
- }
- /** The inner class MouseOptions is used to detect a mouse
- * release event that occurs when a user clicks the 'Options'
- * button. The mouseReleased method makes the 'options' object
- * visible
- */
- class MouseOptions implements ActionListener, Serializable {
- public void actionPerformed(ActionEvent e) {
- optionsDialog.setVisible(true);
- }
- }
- /** The 'nl' and 'fs' objects are define for string constants
- * instead of using literal strings in order to pass the
- * "100% Pure" Java certification by Key Labs
- */
- private String nl = System.getProperty("line.separator");
- private String fs = System.getProperty("file.separator");
- /** The 'run' method is called when the work thread is started.
- * The work thread sleeps until there is work to be done. We
- * use a separate work thread so that the user interface does not
- * "freeze up" when PicWeb is processing image files and generating
- * HTML documents.
- */
- public void run() {
- engine.process(root_dir.getText().trim(), logo);
- p_button.setEnabled(true);
- print("Done." + nl);
- }
- /** The inner MouseProcess class is used to detect mouse released
- * events in the 'Process' button. The boolean flag 'process' is
- * set to 'true' which causes the 'run' method to process a
- * directory tree
- */
- class MouseProcess implements ActionListener, Serializable {
- public void actionPerformed(ActionEvent e) {
- p_button.setEnabled(false);
- workThread = new Thread(picweb);
- workThread.start();
- }
- }
- String copyright =
- "PicWeb(tm) Copyright 1997-1999 by Mark Watson." + nl +
- "The JpegEncoder class is ' Copyright (C) 1998, James R. Weeks and BioElectroMech.'" + nl + nl +
- "READ FULL COPYRIGHT NOTICES ON OPTIONS SCREEN" + nl;
- }
English
