Horus Doc || Java GUI Reference || Doxygen's quick Index  

MatrixChoice Class Reference

A CorbaObjectChoice for Matrix's. More...

Inheritance diagram for MatrixChoice::

InterfaceChoice CorbaObjectChoice List of all members.

Public Methods

 MatrixChoice (org.omg.CORBA.TypeCode tc)
JComponent inputArg ()
 Dialog component where the user specifies the result. More...

java.lang.Object asObject (String name) throws InvalidChoiceException
 Returns the object introduced as that text. More...


Static Public Methods

HxCorba.Matrix getMatrix (String type, String values) throws InvalidChoiceException

Detailed Description

A CorbaObjectChoice for Matrix's.


Constructor & Destructor Documentation

MatrixChoice::MatrixChoice org.omg.CORBA.TypeCode    tc [inline]
 

00025 {
00026     super(tc);
00027     _objectName = null;
00028 }


Member Function Documentation

JComponent MatrixChoice::inputArg   [inline, virtual]
 

Dialog component where the user specifies the result.

Reimplemented from InterfaceChoice.

00031 {
00032     if(_input == null) {
00033         _input = (JComboBox)super.inputArg();
00034         _input.addItem("rotate: 1.0");
00035         _input.addItem("trans: 1.0 1.0");
00036         _input.addItem("scale: 1.0 1.0");
00037 
00038         _input.setEditable(true);
00039         _input.getEditor().getEditorComponent().addFocusListener(new HxJava.Util.SelectOnFocus());
00040 
00041         _input.setSelectedIndex(0);
00042     }
00043     return _input;
00044 }

HxCorba.Matrix MatrixChoice::getMatrix String    type,
String    values
[inline, static]
 

00048 {
00049     HxCorba.MatrixFactory factory;
00050     try {
00051         org.omg.CORBA.Object obj =
00052             CorbaMediator.instance().getInitialObject("Constructor");
00053         factory = HxCorba.MatrixFactoryHelper.narrow(obj);
00054     }catch(Exception e) {
00055         throw new InvalidChoiceException("Cannot find HORUS server");
00056     }
00057 
00058     try {
00059         StringTokenizer tok = new StringTokenizer(values);
00060         double[] dValues = new double[3];
00061         int nDValues = 0;
00062         while(tok.hasMoreTokens() && nDValues < 3) {
00063            dValues[nDValues] = Double.parseDouble(tok.nextToken());
00064            nDValues++;
00065         };
00066 
00067         if(type.equals("rotate:")) {
00068             if(nDValues < 1)
00069                 throw new InvalidChoiceException("Rotate requires 1 double");
00070             return factory.rotate2d(dValues[0]);
00071         }
00072 
00073         if(type.equals("trans:")) {
00074             if(nDValues < 2)
00075                 throw new InvalidChoiceException("Translation requires 2 doubles");
00076             return factory.translate2d(dValues[0], dValues[1]);
00077         }
00078 
00079         if(type.equals("scale:")) {
00080             if(nDValues < 2)
00081                 throw new InvalidChoiceException("Scaling requires 2 doubles");
00082             return factory.scale2d(dValues[0], dValues[1]);
00083         }
00084 
00085     }catch(NumberFormatException e) {
00086     }
00087 
00088     throw new InvalidChoiceException("Wrong number");
00089 }

java.lang.Object MatrixChoice::asObject String    name [inline, virtual]
 

Returns the object introduced as that text.

Useful method to implement setArgument.

Reimplemented from InterfaceChoice.

00092 {
00093     if(name.equals(_objectName)) return _object; //already computed
00094 
00095     String type = null;
00096     if(name.startsWith("rotate:")) type = "rotate:";
00097     else if(name.startsWith("trans:")) type = "trans:";
00098     else if(name.startsWith("scale:")) type = "scale:";
00099 
00100     if(type == null) _object = super.asObject(name);
00101     else {
00102         try {
00103             String values = name.substring(type.length()).trim();
00104             _object = getMatrix(type, values);
00105         }catch(InvalidChoiceException e) {
00106             _input.requestFocus();
00107             _objectName = null;
00108             throw e;
00109         }
00110     }
00111 
00112     _objectName = name;
00113     return _object;
00114 }


The documentation for this class was generated from the following file:
Generated on Tue Feb 3 14:19:48 2004 for JavaReference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001