Hi Jacky et al,
You can get the DisplayImpl from a BasicSSCell (a spreadsheet cell)
by calling BasicSSCell.getDisplay(). However, whenever a BasicSSCell
switches dimensions, a new DisplayImpl must be initialized. So, the
best way to insure the spreadsheet always has cells with white
backgrounds is to make a simple extension.
Below is an extension of visad.ss.FancySSCell that will hopefully do
the trick for you.
-Curtis
At 02:10 3/9/01, Ugo Taddei wrote:
>Hi Jacky,
>
>Jacky Saint wrote:
>> Hi,
>> I'm grateful for the help I recieved previously. Currently I am using
>> SpreadSheet.java to implement my program. The problem is when I print a cell
>> the background comes out as black. However I would like to change this so
>> that the background is white, but I am having problem locating the class
>> file that specifies the background. Please can someone tell me where I
>> should look to find this class, or maybe if someone has already implemented
>> this can you give me some guidance on how I can do this.
>
>VisAD Tutorial shows you in section 4.14 how to change the display's
>background color.
>
>First do
>
>DisplayRenderer dRenderer = display.getDisplayRenderer();
>
>then do
>
>float[] backColor = colorToFloats(Color.lightGray);
>dRenderer.setBackgroundColor(backColor[0], backColor[1],backColor[2]);
>
>Please see the whole section for more details:
> http://www.ssec.wisc.edu/~billh/tutorial/s4/Section4.html#section4_14
>
>However, when using the SpreadSheet, you'll have to know where the
>display is. I'm not sure how to get the display from a SpreadSheet cell
>but I believe Curtis can show you the way.
>
>Cheers,
>
>Ugo
-----------------------
//
// MySS.java
//
import java.io.*;
import java.awt.Frame;
import java.rmi.*;
import visad.*;
import visad.formula.*;
import visad.ss.*;
/** An extension of visad.ss.FancySSCell for cells with white backgrounds. */
public class MySS extends FancySSCell {
/** Extended from visad.ss.FancySSCell. */
public MySS(String name, FormulaManager fman, RemoteServer rs,
boolean slave, String save, Frame parent) throws VisADException,
RemoteException
{
super(name, fman, rs, slave, save, parent);
}
/**
* Extends visad.ss.FancySSCell.constructDisplay so that whenever a
* new DisplayImpl is constructed, its background is set to white.
*/
public synchronized boolean constructDisplay() {
boolean success = super.constructDisplay();
if (success) {
DisplayRenderer dRenderer = VDisplay.getDisplayRenderer();
try {
// set background color
dRenderer.setBackgroundColor(1.0f, 1.0f, 1.0f); // white
dRenderer.setBoxColor(0.0f, 0.0f, 0.0f); // black
}
catch (VisADException exc) { exc.printStackTrace(); }
catch (RemoteException exc) { exc.printStackTrace(); }
}
return success;
}
/**
* Launches MySS, copied largely from visad.ss.SpreadSheet.
* To run, type "java MySS" at the command prompt.
*/
public static void main(String[] argv) {
String usage = "\n" +
"Usage: java [-mx###m] MySS [cols rows]\n" +
" [-gui] [-no3d] [-debug]\n" +
" [-server name] [-client address] [-slave address]\n\n" +
"###\n" +
" Maximum megabytes of memory to use.\n" +
"cols\n" +
" Number of columns in this spreadsheet.\n" +
"rows\n" +
" Number of rows in this spreadsheet.\n" +
"-gui\n" +
" Pop up an options window so that the user can\n" +
" select spreadsheet settings graphically.\n" +
"-no3d\n" +
" Disable Java3D.\n" +
"-debug\n" +
" Print stack traces for all errors.\n" +
"-server name\n" +
" Initialize this spreadsheet as an RMI server\n" +
" with the given name.\n" +
"-client address\n" +
" Initialize this spreadsheet as a clone of\n" +
" the server at the given RMI address.\n" +
"-slave address\n" +
" Initialize this spreadsheet as a slaved clone\n" +
" of the server at the given RMI address.";
int cols = 2;
int rows = 2;
String servname = null;
String clonename = null;
boolean guiOptions = false;
int len = argv.length;
if (len > 0) {
int ix = 0;
// parse command line flags
while (ix < len) {
if (argv[ix].charAt(0) == '-') {
if (argv[ix].equals("-server")) {
if (clonename != null) {
System.out.println("A spreadsheet cannot be both a server " +
"and a clone!");
System.out.println(usage);
System.exit(3);
}
else if (ix < len - 1) servname = argv[++ix];
else {
System.out.println("You must specify a server name after " +
"the '-server' flag!");
System.out.println(usage);
System.exit(4);
}
}
else if (argv[ix].equals("-client") || argv[ix].equals("-slave")) {
if (servname != null) {
System.out.println("A spreadsheet cannot be both a server " +
"and a clone!");
System.out.println(usage);
System.exit(3);
}
else if (ix < len - 1) {
clonename = argv[ix + 1];
if (argv[ix].equals("-slave")) clonename = "slave:" + clonename;
ix++;
}
else {
System.out.println("You must specify a server after " +
"the '" + argv[ix] + "' flag!");
System.out.println(usage);
System.exit(5);
}
}
else if (argv[ix].equals("-gui")) guiOptions = true;
else if (argv[ix].equals("-no3d")) BasicSSCell.disable3D();
else if (argv[ix].equals("-debug")) {
BasicSSCell.DEBUG = true;
FormulaVar.DEBUG = true;
}
else {
// unknown flag
if (!argv[ix].equals("-help")) {
System.out.println("Unknown option: " + argv[ix]);
}
System.out.println(usage);
System.exit(1);
}
}
else {
// parse number of rows and columns
boolean success = true;
if (ix < len - 1) {
try {
cols = Integer.parseInt(argv[ix]);
rows = Integer.parseInt(argv[ix + 1]);
ix++;
if (rows < 1 || cols < 1) {
success = false;
}
}
catch (NumberFormatException exc) {
success = false;
}
if (!success) {
System.out.println("Invalid number of columns and rows: " +
argv[ix] + " x " + argv[ix + 1]);
System.out.println(usage);
System.exit(2);
}
}
else {
System.out.println("Unknown option: " + argv[ix]);
System.out.println(usage);
System.exit(1);
}
}
ix++;
}
}
final SpreadSheet ss = new SpreadSheet(60, 70,
cols, rows, servname, clonename, "VisAD SpreadSheet", null, guiOptions)
{
protected FancySSCell createCell(String name, RemoteServer rs)
throws VisADException, RemoteException
{
return new MySS(name, fm, rs, IsSlave, null, this);
}
};
}
}
-----------------------