1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
// (jEdit options) :folding=explicit:collapseFolds=1:
//{{{ Package, imports
//import java.awt.*;
//import java.awt.event.*;
import java.io.*;
import java.net.URL;
import java.text.DecimalFormat;
import java.util.*;
//import java.util.regex.*;
//import javax.swing.*;
//import driftwood.*;
//}}}
/**
* <code>ZoomTest</code> has not yet been documented.
*
* <p>Copyright (C) 2003 by Ian W. Davis. All rights reserved.
* <br>Begun on Wed Oct 29 08:17:41 EST 2003
*/
public class ZoomTest //extends ... implements ...
{
//{{{ Constants
//}}}
//{{{ Variable definitions
//##############################################################################
//}}}
//{{{ Constructor(s)
//##############################################################################
public ZoomTest()
{
super();
}
//}}}
//{{{ empty_code_segment
//##############################################################################
//}}}
//{{{ Main, main
//##############################################################################
/**
* Main() function for running as an application
*/
public void Main()
{
final double LOG_2 = Math.log(2.0);
final double SPAN = Math.PI * 100.0;
for(int i = -200; i <= 200; i++)
{
float v = (float)( SPAN / Math.pow(2.0, i/16.0) );
int j = (int)Math.round(16.0 * Math.log(SPAN / v) / LOG_2);
if(i != j)
System.err.println("Failed for "+i+" != "+j);
}
}
public static void main(String[] args)
{
ZoomTest mainprog = new ZoomTest();
try
{
mainprog.parseArguments(args);
mainprog.Main();
}
catch(IllegalArgumentException ex)
{
ex.printStackTrace();
System.err.println();
mainprog.showHelp(true);
System.err.println();
System.err.println("*** Error parsing arguments: "+ex.getMessage());
System.exit(1);
}
}
//}}}
//{{{ parseArguments, showHelp
//##############################################################################
/**
* Parse the command-line options for this program.
* @param args the command-line options, as received by main()
* @throws IllegalArgumentException if any argument is unrecognized, ambiguous, missing
* a required parameter, has a malformed parameter, or is otherwise unacceptable.
*/
void parseArguments(String[] args)
{
String arg, flag, param;
boolean interpFlags = true;
for(int i = 0; i < args.length; i++)
{
arg = args[i];
if(!arg.startsWith("-") || !interpFlags || arg.equals("-"))
{
// This is probably a filename or something
interpretArg(arg);
}
else if(arg.equals("--"))
{
// Stop treating things as flags once we find --
interpFlags = false;
}
else
{
// This is a flag. It may have a param after the = sign
int eq = arg.indexOf('=');
if(eq != -1)
{
flag = arg.substring(0, eq);
param = arg.substring(eq+1);
}
else
{
flag = arg;
param = null;
}
try { interpretFlag(flag, param); }
catch(NullPointerException ex)
{ throw new IllegalArgumentException("'"+arg
+"' expects to be followed by a parameter"); }
}
}//for(each arg in args)
}
// Display help information
void showHelp(boolean showAll)
{
if(showAll)
{
InputStream is = getClass().getResourceAsStream("ZoomTest.help");
if(is == null)
System.err.println("\n*** Unable to locate help information in 'ZoomTest.help' ***\n");
else
{
try { streamcopy(is, System.out); }
catch(IOException ex) { ex.printStackTrace(); }
}
}
System.err.println(".ZoomTest");
System.err.println("Copyright (C) 2003 by Ian W. Davis. All rights reserved.");
}
// Copies src to dst until we hit EOF
void streamcopy(InputStream src, OutputStream dst) throws IOException
{
byte[] buffer = new byte[2048];
int len;
while((len = src.read(buffer)) != -1) dst.write(buffer, 0, len);
}
//}}}
//{{{ interpretArg, interpretFlag
//##############################################################################
void interpretArg(String arg)
{
// Handle files, etc. here
}
void interpretFlag(String flag, String param)
{
if(flag.equals("-help") || flag.equals("-h"))
{
showHelp(true);
System.exit(0);
}
else if(flag.equals("-dummy_option"))
{
// handle option here
}
else throw new IllegalArgumentException("'"+flag+"' is not recognized as a valid flag");
}
//}}}
}//class
|