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/Shared/Divider.java
/* |
File: Divider.java |
Description: * Sample showing how to send and receive AppleEvents using JDirect 3. |
Author: LB |
Copyright: © Copyright 1999 - 2002 Apple Computer, Inc. All rights reserved. |
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. |
("Apple") in consideration of your agreement to the following terms, and your |
use, installation, modification or redistribution of this Apple software |
constitutes acceptance of these terms. If you do not agree with these terms, |
please do not use, install, modify or redistribute this Apple software. |
In consideration of your agreement to abide by the following terms, and subject |
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs |
copyrights in this original Apple software (the "Apple Software"), to use, |
reproduce, modify and redistribute the Apple Software, with or without |
modifications, in source and/or binary forms; provided that if you redistribute |
the Apple Software in its entirety and without modifications, you must retain |
this notice and the following text and disclaimers in all such redistributions of |
the Apple Software. Neither the name, trademarks, service marks or logos of |
Apple Computer, Inc. may be used to endorse or promote products derived from the |
Apple Software without specific prior written permission from Apple. Except as |
expressly stated in this notice, no other rights or licenses, express or implied, |
are granted by Apple herein, including but not limited to any patent rights that |
may be infringed by your derivative works or by other works in which the Apple |
Software may be incorporated. |
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO |
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN |
COMBINATION WITH YOUR PRODUCTS. |
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION |
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT |
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Change History (most recent first): |
* version 1.0 |
* 4/15/1999 Shipped as 'AppleEvent Send and Receive' sample. |
* Draws a horizontal divider of the form: |
* |
* 122222222~22222222 |
* 233333333~33333333 |
* |
* or a vertical divider of the form: |
* |
* 12 |
* 23 |
* 23 |
* 23 |
* 23 |
* ~~ |
* 23 |
* 23 |
* 23 |
* 23 |
* |
* Where each number represents a pixel: |
* 1 is R:126, G:126, B:126. |
* 2 is R:194, G:194, B:194. |
* 3 is R:242, G:242, B:242. |
*/ |
package com.apple.dts.samplecode.aesendandreceive.shared; |
import java.awt.Graphics; |
import java.awt.Dimension; |
import java.awt.Component; |
import java.awt.Color; |
import java.awt.Container; |
public class Divider extends java.awt.Component |
{ |
/** |
* Constructs a new horizontal Divider. |
*/ |
public Divider() |
{ |
isHorizontal = true; |
color1 = new Color(126, 126, 126); |
color2 = new Color(194, 194, 194); |
color3 = new Color(242, 242, 242); |
} |
/** |
* Changes the orientation of the Divider between horizontal and vertical. |
* param if true, the Divider will be horizontal, |
* if false it will be vertical. |
* see #isHorizontal |
*/ |
public void setHorizontal(boolean isHorizontal) |
{ |
if (this.isHorizontal != isHorizontal) |
{ |
this.isHorizontal = isHorizontal; |
invalidate(); |
Container parent = getParent(); |
if (parent != null) |
parent.validate(); |
} |
} |
/** |
* The orientation of the Divider |
* return if true, the Divider is horizontal, |
* if false it is vertical. |
* see #setHorizontal |
*/ |
public boolean isHorizontal() |
{ |
return isHorizontal; |
} |
/** |
* Returns the preferred size of this component. |
* see #getMinimumSize |
* see LayoutManager |
*/ |
public Dimension getPreferredSize() |
{ |
Dimension s = getSize(); |
if (isHorizontal) |
{ |
return new Dimension(s.width, 2); |
} |
else |
{ |
return new Dimension(2, s.height); |
} |
} |
/** |
* Paints the component. This method is called when the contents |
* of the component should be painted in response to the component |
* first being shown or damage needing repair. The clip rectangle |
* in the Graphics parameter will be set to the area which needs |
* to be painted. |
* param g the specified Graphics window |
* see #update |
*/ |
public void paint(Graphics g) |
{ |
super.paint(g); |
Dimension s = getSize(); |
if (isHorizontal) |
{ |
g.setColor(color1); |
g.drawLine(0, 0, 0, 0); |
g.setColor(color2); |
g.drawLine(1, 0, s.width, 0); |
g.drawLine(0, 1, 0, 1); |
g.setColor(color3); |
g.drawLine(1, 1, s.width, 1); |
} |
else |
{ |
g.setColor(color1); |
g.drawLine(0, 0, 0, 0); |
g.setColor(color2); |
g.drawLine(0, 1, 0, s.height); |
g.drawLine(1, 0, 1, 0); |
g.setColor(color3); |
g.drawLine(1, 1, 1, s.height); |
} |
} |
protected boolean isHorizontal; |
protected Color color1; |
protected Color color2; |
protected Color color3; |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14