OptionsDialog.java
上传用户:shengda799
上传日期:2007-01-10
资源大小:68k
文件大小:9k
源码类别:

图片显示

开发平台:

Java

  1. import java.awt.*;
  2. import java.io.*;
  3. /**
  4.  * OptionsDialog - this code used to be in the clss PicWeb (removed to
  5.  * a separate class in Version 7, using package wide access [i.e., not private
  6.  * or protected] of class PicWeb option variables).
  7.  */
  8. public class OptionsDialog extends Dialog implements java.io.Serializable {
  9.     private Button close;
  10.     private TextArea text;
  11.     private DialogFrame my_frame;
  12.     private PicWeb picweb;
  13.     private Options options;
  14.     private Checkbox cbShowLogo;
  15.     private Checkbox cbFileNames;
  16.     private Checkbox cbSkipDirs;
  17.     private Checkbox cbSkipFiles;
  18.     private Checkbox cbSort;
  19.     private Checkbox cbThumbs;
  20.     private Choice choice;
  21.     private TextField html_filename;
  22.     OptionsDialog(DialogFrame parent, PicWeb picweb, Options options) {
  23.         super(parent, "Options Dialog", true);
  24.         my_frame = parent;
  25.         this.picweb = picweb;
  26.         this.options = options;
  27.         my_frame.setLayout(null);
  28.         my_frame.setOptions(this);
  29.         my_frame.setTitle("PicWeb " + picweb.version + " - Options");
  30. options.updateFromFile();
  31.         cbShowLogo = new Checkbox("Show images while calculated", options.showLogo);
  32.         cbFileNames= new Checkbox("Include image file names in HTML documents", options.fileNamesFlag);
  33.         cbSkipDirs = new Checkbox("Skip already processed sub-directories", options.skipProcessedDirs);
  34.         cbSkipFiles = new Checkbox("Skip already processed files", options.skipProcessedFiles);
  35.         cbSort = new Checkbox("Sort files and directories", options.sort);
  36.         cbThumbs = new Checkbox("Make thumb nail images", options.thumbs);
  37.         Label l1 = new Label("Set options");
  38.         l1.setFont(new Font("Dialog", Font.BOLD, options.fontSizes[3]));
  39.         my_frame.add(l1);
  40.         l1.setBounds(5, 180, 480, 28);
  41.         my_frame.add(cbShowLogo);
  42.         cbShowLogo.setBounds(5, 210, 480, 28);
  43.         my_frame.add(cbFileNames);
  44.         cbFileNames.setBounds(5, 240, 480, 28);
  45.         my_frame.add(cbSkipDirs);
  46.         cbSkipDirs.setBounds(5, 270, 480, 28);
  47.         my_frame.add(cbSkipFiles);
  48.         cbSkipFiles.setBounds(5, 300, 480, 28);
  49.         my_frame.add(cbSort);
  50.         cbSort.setBounds(5, 330, 480, 28);
  51.         my_frame.add(cbThumbs);
  52.         cbThumbs.setBounds(5, 360, 480, 28);
  53.         choice = new Choice();
  54.         choice.add("generate small size thumbnail images");
  55.         choice.add("generate medium size thumbnail images");
  56.         choice.add("generate large size thumbnail images");
  57.         choice.add("generate extra large size thumbnail images");
  58.         choice.select(options.imageSizeChoice);
  59.         my_frame.add(choice);
  60.         choice.setBounds(5, 390, 300, 28);
  61.         // (ta 4.1) allow the HTML filename to be selected...
  62.         Label html = new Label("HTML Filename:");
  63.         my_frame.add(html);
  64.         html.setBounds(5, 425, 100, 30);
  65.         html_filename = new TextField(options.HTMLFilename, 15);
  66.         my_frame.add(html_filename);
  67.         html_filename.setBounds(110, 425, 180, 28);
  68.         String str =
  69.             "PicWeb(tm) Copyright 1997-1999 by Mark Watson." + nl + nl + "ALL RIGHTS RESERVED" +
  70.             nl + "Single User License." + nl +
  71.             "The JpegEncoder class is  Copyright (C) 1998, James R. Weeks and BioElectroMech" + nl +
  72.             "And is based on the work of the Independent JPEG Group" + nl +
  73.             "and was inspired by the original Java port by Florian Raemy." + nl +
  74.             "Please see the source code file JpegEncoder.java for full copyright" + nl +
  75.             "and license information." + nl + nl +
  76.             "THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''" + nl +
  77.             "AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO," + nl +
  78.             "THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR" + nl +
  79.             "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR" + nl +
  80.             "OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT," + nl +
  81.             "INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING," + nl +
  82.             "BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF" + nl +
  83.             "USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER" + nl +
  84.             "CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT," + nl +
  85.             "STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)" + nl +
  86.             "ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF" + nl +
  87.             "ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." + nl + nl +
  88.             "Visit my We site for update information: www.markwatson.com" + nl + nl +
  89.             // (ta 4.1) ...
  90.             "Also, thanks to:" + nl +
  91.             "Achille Petrilli <Achille.Petrilli@cern.ch> (directory pop-up, new fonts, larger icons)" + nl +
  92.             "Tony Allan <tony@apms.com.au> (sorted files, selectable html filename, saved options)" + nl + nl +
  93.             "NOTICE: THIS SOFTWARE CAN NOT BE USED FOR ANY ILLEGAL OR NON-PEACEFUL PURPOSE" + nl + nl +
  94.             "-----------------------------------------------------------------------" + nl + nl +
  95.             "HELP" + nl + nl +
  96.             "Use the forward slash: / as a file separator.  If possible, use a Java" + nl +
  97.             "runtime system with a just in time compiler to decrease the runtime for" + nl +
  98.             "generating many thumbnail image files." + nl + nl +
  99.             "In the 'Browse...' file selection dialog, you must select a file (or just leave the 'dummy'" + nl +
  100.             "file) in order to change the directory." + nl + nl +
  101.             "If the sort option is selected, and directories contain dates, it is better to specify" + nl +
  102.             "dates with year first (i.e. 1998-12-25)." + nl +
  103.             nl;
  104.         Label l = new Label("Copyright information and help");
  105.         l.setFont(new Font("Dialog", Font.BOLD, options.fontSizes[4]));
  106.         my_frame.add(l);
  107.         l.setBounds(5, 25, 480, 30);
  108.         text = new TextArea(str, 7, 72);
  109.         text.setEditable(false);
  110.         text.setFont(new Font("Dialog", Font.PLAIN, options.fontSizes[0]));
  111.         text.setEditable(false);
  112.         my_frame.add(text);
  113.         text.setBounds(5, 60, 480, 110);
  114.         Label l9 = new Label("Close this window to save options!");
  115.         l9.setFont(new Font("Dialog", Font.BOLD, options.fontSizes[3]));
  116.         my_frame.add(l9);
  117.         l9.setBounds(5, 470, 480, 25);
  118.         my_frame.setBounds(100, 100, 515, 490);
  119.         my_frame.pack();
  120.         my_frame.setSize(500, 520);
  121.         myself=this;
  122.     }
  123.     public void setVisible(boolean b) {
  124.         my_frame.setVisible(b);
  125.     }
  126.     private OptionsDialog myself;
  127.     public void saveOptions() {
  128.         boolean changed = false;
  129.         if (options.showLogo != cbShowLogo.getState()) {
  130.             options.showLogo = cbShowLogo.getState();
  131.             options.ini.put("showLogo", (new Boolean(options.showLogo)).toString());
  132.             changed = true;
  133.         }
  134.         if (options.fileNamesFlag != cbFileNames.getState()) {
  135.             options.fileNamesFlag = cbFileNames.getState();
  136.             options.ini.put("fileNamesFlag", (new Boolean(options.fileNamesFlag)).toString());
  137.             changed = true;
  138.         }
  139.         if (options.skipProcessedDirs != cbSkipDirs.getState()) {
  140.             options.skipProcessedDirs = cbSkipDirs.getState();
  141.             options.ini.put("skipProcessedDirs", (new Boolean(options.skipProcessedDirs)).toString());
  142.             changed = true;
  143.         }
  144.         if (options.skipProcessedFiles != cbSkipFiles.getState()) {
  145.             options.skipProcessedFiles = cbSkipFiles.getState();
  146.             options.ini.put("skipProcessedFiles", (new Boolean(options.skipProcessedFiles)).toString());
  147.             changed = true;
  148.         }
  149.         if (options.sort != cbSort.getState()) {
  150.             options.sort = cbSort.getState();
  151.             options.ini.put("sort", (new Boolean(options.sort)).toString());
  152.             changed = true;
  153.         }
  154.         if (options.thumbs != cbThumbs.getState()) {
  155.             options.thumbs = cbThumbs.getState();
  156.             options.ini.put("thumbs", (new Boolean(options.thumbs)).toString());
  157.             changed = true;
  158.         }
  159.         if (options.imageSizeChoice != choice.getSelectedIndex()) {
  160.             options.imageSizeChoice = choice.getSelectedIndex();
  161.             options.ini.put("imageSizeChoice", Integer.toString(options.imageSizeChoice));
  162.             changed = true;
  163.         }
  164.         System.out.println("options="+options);
  165.         System.out.println("html_filename="+html_filename);
  166.         if (!options.HTMLFilename.equals(html_filename.getText().trim())) {
  167.             options.HTMLFilename = html_filename.getText().trim();
  168.             options.ini.put("HTMLFilename", options.HTMLFilename);
  169.             changed = true;
  170.         }
  171.         if (changed) {
  172.             try {
  173.                 OutputStream out = new BufferedOutputStream(new FileOutputStream(options.iniFile));
  174.                 options.ini.store(out, "PicWeb (" + picweb.version + ") properties");
  175.                 out.close();
  176.             } catch (IOException e) {System.out.println(e);}
  177.             picweb.print(options.iniFile + " updated." + nl);
  178.         }
  179.         myself.setVisible(false);
  180.     }
  181.     /** The 'nl' and 'fs' objects are define for string constants
  182.      * instead of using literal strings in order to pass the
  183.      * "100% Pure" Java certification by Key Labs
  184.      */
  185.     private String nl = System.getProperty("line.separator");
  186.     private String fs = System.getProperty("file.separator");
  187. }