001 package com.croftsoft.apps.skipper; 002 003 import java.awt.*; 004 import java.io.*; 005 import java.util.logging.*; 006 007 import com.croftsoft.core.CroftSoftConstants; 008 import com.croftsoft.core.beans.XmlBeanCoder; 009 010 /*********************************************************************** 011 * Skipper persistent configuration. 012 * 013 * Copyright 2007 David Wallace Croft. 014 * 015 * @version 016 * $Date: 2007/07/28 17:59:46 $ $Author: croft $ 017 * @since 018 * 2006-12-19 019 * @author 020 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 021 ***********************************************************************/ 022 023 public final class SkipperConfig 024 //////////////////////////////////////////////////////////////////////// 025 //////////////////////////////////////////////////////////////////////// 026 { 027 028 private static final String 029 VERSION = "$Date: 2007/07/28 17:59:46 $", 030 CLASS_NAME = SkipperConfig.class.getName ( ), 031 TITLE = "CroftSoft Skipper"; 032 033 private static final String INFO 034 = TITLE + "\n" 035 + "Version " + VERSION + "\n" 036 + CroftSoftConstants.COPYRIGHT + "\n" 037 + CroftSoftConstants.DEFAULT_LICENSE + "\n" 038 + CroftSoftConstants.HOME_PAGE + "\n"; 039 040 private static final int 041 FRAME_WIDTH = 600, 042 FRAME_HEIGHT = 400; 043 044 private static final double UPDATE_RATE = 1.0; 045 046 private static final String SHUTDOWN_CONFIRMATION_PROMPT = null; 047 048 private static final Font FONT 049 = new Font ( "Arioso", Font.BOLD, 20 ); 050 051 private static final Color 052 BACKGROUND_COLOR = Color.BLACK, 053 FOREGROUND_COLOR = Color.GREEN; 054 055 private static final String 056 CROFTSOFT_DIRECTORY = ".croftsoft", 057 SKIPPER_DIRECTORY = "skipper", 058 CONFIG_FILENAME = "skipper.cfg", 059 DEFAULT_PICTURES_PATH = "My Documents/My Pictures", 060 WEIGHTS_FILENAME = "skipper.dat"; 061 062 private static final String SKIPPER_PATH 063 = System.getProperty ( "user.home" ) 064 + File.separator 065 + CROFTSOFT_DIRECTORY 066 + File.separator 067 + SKIPPER_DIRECTORY; 068 069 // default values 070 071 private static final long DEFAULT_DISPLAY_TIME = 60; 072 073 private static final Boolean DEFAULT_DISPLAYING_IMAGE_FILENAME 074 = Boolean.FALSE; 075 076 // instance variables 077 078 private Boolean displayingImageFilename; 079 080 private long displayTime; 081 082 private String picturesPath; 083 084 //////////////////////////////////////////////////////////////////////// 085 // static methods 086 //////////////////////////////////////////////////////////////////////// 087 088 public static File createWeightsFile ( ) 089 //////////////////////////////////////////////////////////////////////// 090 { 091 final File skipperPathFile = new File ( SKIPPER_PATH ); 092 093 skipperPathFile.mkdirs ( ); 094 095 return new File ( skipperPathFile, WEIGHTS_FILENAME ); 096 } 097 098 public static SkipperConfig load ( String [ ] args ) 099 //////////////////////////////////////////////////////////////////////// 100 { 101 try 102 { 103 final File configFile = new File ( SKIPPER_PATH, CONFIG_FILENAME ); 104 105 if ( configFile.exists ( ) ) 106 { 107 return ( SkipperConfig ) 108 XmlBeanCoder.loadFromXmlFile ( configFile ); 109 } 110 } 111 catch ( final Exception ex ) 112 { 113 Logger.getLogger ( CLASS_NAME ).throwing ( CLASS_NAME, "load", ex ); 114 } 115 116 return new SkipperConfig ( ); 117 } 118 119 //////////////////////////////////////////////////////////////////////// 120 // accessor methods 121 //////////////////////////////////////////////////////////////////////// 122 123 public Color getBackgroundColor ( ) { return BACKGROUND_COLOR; } 124 125 public Color getForegroundColor ( ) { return FOREGROUND_COLOR; } 126 127 public String getInfo ( ) { return INFO; } 128 129 public Font getFont ( ) { return FONT; } 130 131 public Dimension getFrameSize ( ) 132 { return new Dimension ( FRAME_WIDTH, FRAME_HEIGHT ); } 133 134 public String getFrameTitle ( ) { return TITLE; } 135 136 public String getPicturesPath ( ) { return picturesPath; } 137 138 public String getShutdownConfirmationPrompt ( ) 139 { return SHUTDOWN_CONFIRMATION_PROMPT; } 140 141 public String getThreadName ( ) { return TITLE; } 142 143 public double getUpdateRate ( ) { return UPDATE_RATE; } 144 145 public long getDisplayTime ( ) { return displayTime; } 146 147 public long getDefaultDisplayTime ( ) { return DEFAULT_DISPLAY_TIME; } 148 149 public String getDefaultPicturesPath ( ) 150 { return DEFAULT_PICTURES_PATH; } 151 152 public Boolean getDisplayingImageFilename ( ) 153 { return displayingImageFilename; } 154 155 public Boolean getDefaultDisplayingImageFilename ( ) 156 { return DEFAULT_DISPLAYING_IMAGE_FILENAME; } 157 158 //////////////////////////////////////////////////////////////////////// 159 // mutator methods 160 //////////////////////////////////////////////////////////////////////// 161 162 public void setDisplayingImageFilename ( 163 final Boolean displayingImageFilename ) 164 //////////////////////////////////////////////////////////////////////// 165 { 166 this.displayingImageFilename = displayingImageFilename; 167 } 168 169 public void setDisplayTime ( final long displayTime ) 170 //////////////////////////////////////////////////////////////////////// 171 { 172 this.displayTime = displayTime; 173 } 174 175 public void setPicturesPath ( final String picturesPath ) 176 //////////////////////////////////////////////////////////////////////// 177 { 178 this.picturesPath = picturesPath; 179 } 180 181 //////////////////////////////////////////////////////////////////////// 182 // persistence method 183 //////////////////////////////////////////////////////////////////////// 184 185 public void save ( ) 186 throws IOException 187 //////////////////////////////////////////////////////////////////////// 188 { 189 final File skipperPathFile = new File ( SKIPPER_PATH ); 190 191 skipperPathFile.mkdirs ( ); 192 193 XmlBeanCoder.saveToXmlFile ( 194 this, 195 new File ( skipperPathFile, CONFIG_FILENAME ) ); 196 } 197 198 //////////////////////////////////////////////////////////////////////// 199 //////////////////////////////////////////////////////////////////////// 200 }