1 //--------------------------------------------------------------------------
2 // Copyright (C) 2001  Geoffrey Furnish
3 // Copyright (C) 2001, 2002  Alan W. Irwin
4 // Copyright (C) 2004  Andrew Ross
5 //
6 // This file is part of PLplot.
7 //
8 // PLplot is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU Library General Public License as published by
10 // the Free Software Foundation; version 2 of the License.
11 //
12 // PLplot is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public License
18 // along with PLplot; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
20 //--------------------------------------------------------------------------
21 
22 //--------------------------------------------------------------------------
23 // Implementation of PLplot example 12 in Java.
24 //--------------------------------------------------------------------------
25 
26 package plplot.examples;
27 
28 import plplot.core.*;
29 import static plplot.core.plplotjavacConstants.*;
30 
31 import java.text.*;
32 
33 class x12 {
34     static double   y0[] = { 5., 15., 12., 24., 28., 30., 20., 8., 12., 3. };
35 
36     static double[] pos   = { 0.0, 0.25, 0.5, 0.75, 1.0 };
37     static double[] red   = { 0.0, 0.25, 0.5, 1.0, 1.0 };
38     static double[] green = { 1.0, 0.5, 0.5, 0.5, 1.0 };
39     static double[] blue  = { 1.0, 1.0, 0.5, 0.25, 0.0 };
40 
41 
42     PLStream pls = new PLStream();
43 
main( String[] args )44     public static void main( String[] args )
45     {
46         new x12( args );
47     }
48 
x12( String[] args )49     public x12( String[] args )
50     {
51         NumberFormat nf = NumberFormat.getNumberInstance();
52 //        Change to this custom format to get stupid locale commas
53 //        separating hundreds and thousands place out of labels.
54         DecimalFormat nf4 = new DecimalFormat( "####" );
55         int           i;
56 
57         pls.parseopts( args, PL_PARSE_FULL | PL_PARSE_NOPROGRAM );
58 
59         pls.init();
60 
61         pls.adv( 0 );
62         pls.vsta();
63         pls.wind( 1980.0, 1990.0, 0.0, 35.0 );
64         pls.box( "bc", 1.0, 0, "bcnv", 10.0, 0 );
65         pls.col0( 2 );
66         pls.lab( "Year", "Widget Sales (millions)", "#frPLplot Example 12" );
67 
68         pls.scmap1l( true, pos, red, green, blue );
69 
70         for ( i = 0; i < 10; i++ )
71         {
72 //            pls.col0(i + 1);
73             pls.col1( i / 9.0 );
74             pls.psty( 0 );
75             plfbox( ( 1980. + i ), y0[i] );
76 //	   sprintf(string, "%.0f", y0[i]);
77             String text = nf.format( (int) ( y0[i] + 0.5 ) );
78             pls.ptex( ( 1980. + i + .5 ), ( y0[i] + 1. ), 1.0, 0.0, .5, text );
79 //	   sprintf(string, "%d", 1980 + i);
80             String text1 = nf4.format( 1980 + i );
81             pls.mtex( "b", 1.0, ( ( i + 1 ) * .1 - .05 ), 0.5, text1 );
82         }
83         pls.end();
84     }
85 
plfbox( double x0, double y0 )86     void plfbox( double x0, double y0 )
87     {
88         double[] x = new double[4];
89         double[] y = new double[4];
90 
91         x[0] = x0;
92         y[0] = 0.;
93         x[1] = x0;
94         y[1] = y0;
95         x[2] = x0 + 1.;
96         y[2] = y0;
97         x[3] = x0 + 1.;
98         y[3] = 0.;
99         pls.fill( x, y );
100         pls.col0( 1 );
101         pls.lsty( 1 );
102         pls.line( x, y );
103     }
104 }
105 
106 //--------------------------------------------------------------------------
107 //                              End of x12.java
108 //--------------------------------------------------------------------------
109