Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Source/PointStruct.java
import com.apple.mrj.jdirect.Struct; |
import com.apple.mrj.jdirect.ByteArrayStruct; |
/** |
* Apple Worldwide Developer Technical Support |
* |
* A simple example of how to obtain the mouse location using the Mac OS Toolbox through JDirect 2. |
* |
* File: PointStruct.java |
* |
* <CODE>PointStruct</CODE> is a class which mimics the C struct <CODE>Point</CODE> defined in <CODE>MacTypes.h</CODE><BR><BR> |
* This class contains a get and set method for each field in <CODE>Point</CODE>.<BR><BR> |
* Using JDirect 2.0, a <CODE>PointStruct</CODE> can be passed to a native toolbox function |
* that expects a pointer to a <CODE>Point</CODE> by using the <CODE>getByteArray()</CODE> method. |
* |
* @author Apple Computer, Inc. |
* |
* Copyright ©1999 Apple Computer, Inc. |
* All rights reserved. |
* |
* @version 1.0 |
* 4/15/1999 Shipped as 'JDirectMouse' sample. |
* |
* You may incorporate this sample code into your applications without |
* restriction, though the sample code has been provided "AS IS" and the |
* responsibility for its operation is 100% yours. However, what you are |
* not permitted to do is to redistribute the source as "Apple Sample |
* Code" after having made changes. If you're going to re-distribute the |
* source, we require that you make it clear in the source that the code |
* was descended from Apple Sample Code, but that you've made changes. |
*/ |
public class PointStruct extends ByteArrayStruct |
{ |
/** |
* Constructs an uninitialized <CODE>PointStruct</CODE> |
*/ |
public PointStruct() { |
super(sizeOfPoint); |
} |
/** |
* Constructs a <CODE>PointStruct</CODE> and initializes it with the data in another <CODE>Struct</CODE>. |
* Useful when a C struct <CODE>Point</CODE> is embedded in another C struct and you want to |
* copy it out. |
* @param src the <CODE>Struct</CODE> containing the data to be copied |
* @param offsetInSrc the offest in of the data in <CODE>src</CODE> |
*/ |
public PointStruct(Struct src, int offsetInSrc) { |
super(sizeOfPoint); |
byte[] bytes = src.getBytesAt(offsetInSrc, sizeOfPoint); |
this.setBytesAt(0, bytes); |
} |
/** |
* Used only by subclasses of <CODE>PointStruct</CODE> |
*/ |
protected PointStruct(int size) { |
super(size); |
} |
/** |
* in C: <CODE>short v</CODE> |
* @return field <CODE>v</CODE> of <CODE>struct Point</CODE> |
*/ |
public final short getV() { |
return getShortAt(0); |
} |
/** |
* in C: <CODE>short v</CODE> |
* @param v sets field <CODE>v</CODE> of <CODE>struct Point</CODE> |
*/ |
public final void setV(short v) { |
setShortAt(0, v); |
} |
/** |
* in C: <CODE>short h</CODE> |
* @return field <CODE>h</CODE> of <CODE>struct Point</CODE> |
*/ |
public final short getH() { |
return getShortAt(2); |
} |
/** |
* in C: <CODE>short h</CODE> |
* @param h sets field <CODE>h</CODE> of <CODE>struct Point</CODE> |
*/ |
public final void setH(short h) { |
setShortAt(2, h); |
} |
/** |
* Size of <CODE>struct Point</CODE> in bytes |
*/ |
public final static int sizeOfPoint = 4; |
public int getValue() { |
return getIntAt(0); |
} |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-07-22