//Main
static public void main(String[] args)
{
ORB orb = null;
Frame frame = null;
try
{
System.out.println("Initializing ORB");
//Get a reference to the ORB
orb = ORB.init(args, null);
//read the chartServer component IOR from the file
org.omg.CORBA.Object objref = null;
System.out.println ("Read IOR from file");
objref = getIOR (orb, "chart.ior");
//create the chart object, add it to a frame,
//resize it and make it visible
.........
}
catch(org.omg.CORBA.SystemException se)
{
System.out.println("Unexpected exception : " + se);
System.exit(1);
}
}
//Gets bar properties from the server and initialize various
//private members.
public void init()
{
try
{
String rs;
barProperties bpProp = null;
barPropertiesHolder bpHolder = new barPropertiesHolder();
//set the title font properties
..........
//call the chartServer component member function to get the
//number of scale, columns and orientation
StringHolder scaleH = new StringHolder();
StringHolder columnH = new StringHolder();
IntHolder orientH = new IntHolder();
System.out.println ("Calling 'getCommonProperties()' ");
chartSer.getCommonProperties(scaleH,columnH,orientH);
//retieve the unmarshaled values
scale = Integer.parseInt( scaleH.value);
columns = Integer.parseInt( columnH.value);
orientation = orientH.value;
//inititalize the various value and graphic property arrays
//based on the number of columns
.........
//store the bar properties in the arrays for each column
for (int i=0; i < columns; i++)
{
//call the chartServer component member function
//to get the properties for each column bar
chartSer.getBarProperties((i+1),bpHolder);
//retrieve the unmarshaled barProperties object.
bpProp = bpHolder.value;
if (bpHolder != null)
{
try
{
// get the values and labels for this column
.......
}
catch (Exception e){...}
}
else
break;
//set number of max values
if (values[i] > max)
max = values[i];
// adjust label width for this column
..........
// get the bar style
styles[i] = bpProp.barStyle.value();
// parse the color attribute for this column
rs = bpProp.color;
................
}
//set the graphical properties based on orientation
switch (orientation)
{
case VERTICAL:
default:
.............
break;
case HORIZONTAL:
...............
break;
}
}
catch (Exception exp) {.....}
}
//display the chart
public synchronized void paint(Graphics g)
{
.........
System.out.println ("Executing 'paint()' from client");
// draw the title centered at the bottom of the bar graph
.............
//for each column calculate x, y positions based on orientation
//then draw the label, the bar in the specified color as solid
//or striped.
for (i=0; i < columns; i++)
{
switch (orientation)
{
case VERTICAL:
default:
// set the next X coordinate to account for the label
// being wider than the bar getSize().width.
.......
// center the bar chart
.........
// set the next Y coordinate to account for the
//getSize().height of the bar as well as the title
//and labels painted at the bottom of the chart.
...........
// draw the label
........
// draw the shadow bar
.........
// draw the bar with the specified color
.........
switch (styles[i])
{
case SOLID:
default:
...............
break;
case STRIPED:
...............
break;
}
g.drawString("" + values[i],
cx,
cy - titleFontMetrics.getDescent());
break;
case HORIZONTAL:
// set the Y coordinate
...........
// set the X coordinate to be the getSize().width of
//the widest label
............
// draw the labels and the shadow
..............
// draw the bar in the current color
g.setColor((Color)(colors[i]));
//fill the bar rectangle according to the set style
switch (styles[i]) {
case SOLID:
default:
..............
break;
case STRIPED:
..............
break;
}
...............
break;
}//end switch
}//end for
}
End of Listing