/*
 * This file is part of Mapyrus, software for plotting maps.
 * Copyright (C) 2003, 2004, 2005, 2006 Simon Chenery.
 *
 * Mapyrus is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Mapyrus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Mapyrus; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

/*
 * @(#) $Id$
 */
package org.mapyrus;

import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

/**
 * Globally useful constants including fixed distance measurements.
 */
public class Constants
{
	public static final String PROGRAM_NAME = "Mapyrus";
	
	/**
	 * Return version number of software.
	 * @return version number.
	 */
	public static String getVersion()
	{
		/*
		 * Current software version number set by ant Replace task during build.
		 */
		return("@software_version_token@");
	}

	/**
	 * Return release date of software.
	 * @return release date.
	 */
	public static String getReleaseDate()
	{
		/*
		 * Release date set by ant Replace task during build.
		 */
		return("@release_date_token@");
	}

	/*
	 * American number formatting used for all output, with '.'
	 * as the decimal separator.
	 */
	public static final DecimalFormatSymbols US_DECIMAL_FORMAT_SYMBOLS =
		new DecimalFormatSymbols(Locale.US); 

	/*
	 * Identity matrix for coordinate transformations.
	 */
	public static final AffineTransform IDENTITY_MATRIX = new AffineTransform();

	/*
	 * Maximum number of threads to run simultaneously handling HTTP requests.
	 */
	public static final int MAX_HTTP_THREADS = 8;

	/*
	 * Time in milliseconds to wait to begin handling an HTTP request.  If
	 * HTTP server is too busy to begin handling request within this time
	 * then request is cancelled and an error is returned to HTTP client.
	 */
	public static final int HTTP_TIMEOUT = 30 * 1000;

	/*
	 * Length of time in milliseconds that temporary files are retained
	 * when running as an HTTP server.
	 */
	public static final int HTTP_TEMPFILE_LIFESPAN = 300 * 1000;

	/*
	 * Timeout in milliseconds for socket communication between Mapyrus
	 * and HTTP client.  A read/write takes longer than this time fails. 
	 */
	public static final int HTTP_SOCKET_TIMEOUT = 30 * 1000;

 	/*
  	 * Maximum amount of time an HTTP request may take to complete.
  	 * Requests will be stopped and return a failure if they run
 	 * for longer than this time.
  	 */
  	public static final int MAX_HTTP_REQUEST_TIME = 600 * 1000;

	/*
	 * Timeout in seconds for connecting to RDBMS and for executing
	 * SQL queries.
	 */
	public static final int DB_CONNECTION_TIMEOUT = 30;

 	/*
 	 * Timeout in seconds after which an idle database connection
 	 * is closed and a new connection is made.
 	 * This prevents a socket timeout.
 	 */
 	public static final int DB_IDLE_TIMEOUT = 600;

	/*
	 * Maximum number of icons to cache in memory.
	 */
	public static final int ICON_CACHE_SIZE = 64;

	/*
	 * Number of points and millimetres per inch.
	 */
	public static final int POINTS_PER_INCH = 72;
	public static final double MM_PER_INCH = 25.4;

	/**
	 * Get screen resolution, in dots per inch.
	 * @return DPI value. 
	 */
	public static final int getScreenResolution()
	{
		int resolution = Toolkit.getDefaultToolkit().getScreenResolution();
		return(resolution);
	}
	
	/**
	 * Get screen width, in millimetres.
	 * @return screen width.
	 */
	public static final double getScreenWidth()
	{
		int resolution = getScreenResolution();
		double width = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
		return(width / (double)resolution * MM_PER_INCH);
	}

	/**
	 * Get screen height, in millimetres.
	 * @return screen width.
	 */
	public static final double getScreenHeight()
	{
		int resolution = getScreenResolution();
		double height = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
		return(height / (double)resolution * MM_PER_INCH);
	}

	/**
	 * Get name of operating system being used.
	 * @return name of operating system, or empty string if not available.
	 */
	public static String getOSName()
	{
		String retval = System.getProperty("os.name");
		if (retval == null)
			retval = "";
		else
			retval = retval.toUpperCase();
		return(retval);
	}

	/*
	 * Line separator in text files.
	 */
	public static final String LINE_SEPARATOR = System.getProperty("line.separator");
}

@@ -3619,21 +3619,61 @@
  25.4;%0A%0A
+%09private static int mScreenResolution;%0A%0A
 %09/**%0A
-
 %09 * Get 
@@ -3783,36 +3783,87 @@
 olution()%0A%09%7B%0A%09%09i
-nt r
+f (mScreenResolution == 0)%0A%09%09%7B%0A%09%09%09try%0A%09%09%09%7B%0A%09%09%09%09mScreenR
 esolution = Tool
@@ -3911,24 +3911,185 @@
 on();%0A%09%09
-return(r
+%09%7D%0A%09%09%09catch (InternalError e)%0A%09%09%09%7B%0A%09%09%09%09/*%0A%09%09%09%09 * No display, or bad display.  So use a reasonable default.%0A%09%09%09%09 */%0A%09%09%09%09mScreenResolution = 96;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return(mScreenR
 esolutio
@@ -4095,17 +4095,16 @@
 on);%0A%09%7D%0A
-%09
 %0A%09/**%0A%09 

Use default for screen resolution if no graphics display available.