/*
* @(#)SwingUtilities.java 1.80 99/04/22
*
* Copyright 1997-1999 by Sun Microsystems, Inc.,
* 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information
* of Sun Microsystems, Inc. ("Confidential Information"). You
* shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement
* you entered into with Sun.
*/
package javax.swing;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import java.util.Hashtable;
import java.lang.reflect.*;
import javax.accessibility.*;
import javax.swing.text.View;
/**
* A collection of utility methods for Swing.
*
* @version 1.80 04/22/99
* @author unknown
*/
public class SwingUtilities implements SwingConstants
{
// These states are system-wide, rather than AppContext wide.
private static boolean canAccessEventQueue = false;
private static boolean eventQueueTested = false;
/**
* Return true if <code>a</code> contains <code>b</code>
*/
public static final boolean isRectangleContainingRectangle(Rectangle a,Rectangle b) {
if (b.x >= a.x && (b.x + b.width) <= (a.x + a.width) &&
b.y >= a.y && (b.y + b.height) <= (a.y + a.height)) {
return true;
}
return false;
}
/**
* Return the rectangle (0,0,bounds.width,bounds.height) for the component <code>aComponent</code>
*/
public static Rectangle getLocalBounds(Component aComponent) {
Rectangle b = new Rectangle(aComponent.getBounds());
b.x = b.y = 0;
return b;
}
/**
* @return the first Window ancestor of c
*/
private static Window getWindowAncestor(Component c) {
for(Container p = c.getParent(); p != null; p = p.getParent()) {
if (p instanceof Window) {
return (Window)p;
}
}
return null;
}
/**
* Convert a <code>aPoint</code> in <code>source</code> coordinate system to
* <code>destination</code> coordinate system.
* If <code>source></code>is null,<code>aPoint</code> is assumed to be in <code>destination</code>'s
* root component coordinate system.
* If <code>destination</code>is null, <code>aPoint</code> will be converted to <code>source</code>'s
* root component coordinate system.
* If both <code>source</code> and <code>destination</code> are null, return <code>aPoint</code>
* without any conversion.
*/
public static Point convertPoint(Component source,Point aPoint,Component destination) {
Point p;
if(source == null && destination == null)
return aPoint;
if(source == null) {
source = getWindowAncestor(destination);
if(source == null)
throw new Error("Source component not connected to component tree hierarchy");
}
p = new Point(aPoint);
convertPointToScreen(p,source);
if(destination == null) {
destination = getWindowAncestor(source);
if(destination == null)
throw new Error("Destination component not connected to component tree hierarchy");
}
convertPointFromScreen(p,destination);
return p;
}
/**
* Convert the point <code>(x,y)</code> in <code>source</code> coordinate system to
* <code>destination</code> coordinate system.
* If <code>source></code>is null,<code>(x,y)</code> is assumed to be in <code>destination</code>'s
* root component coordinate system.
* If <code>destination</code>is null, <code>(x,y)</code> will be converted to <code>source</code>'s
* root component coordinate system.
* If both <code>source</code> and <code>destination</code> are null, return <code>(x,y)</code>
* without any conversion.
*/
public static Point convertPoint(Component source,int x, int y,Component destination) {
Point point = new Point(x,y);
return convertPoint(source,point,destination);
}
/**
* Convert the rectangle <code>aRectangle</code> in <code>source</code> coordinate system to
* <code>destination</code> coordinate system.
* If <code>source></code>is null,<code>aRectangle</code> is assumed to be in <code>destination</code>'s
* root component coordinate system.
* If <code>destination</code>is null, <code>aRectangle</code> will be converted to <code>source</code>'s
* root component coordinate system.
* If both <code>source</code> and <code>destination</code> are null, return <code>aRectangle</code>
* without any conversion.
*/
public static Rectangle convertRectangle(Component source,Rectangle aRectangle,Component destination) {
Point point = new Point(aRectangle.x,aRectangle.y);
point = convertPoint(source,point,destination);
return new Rectangle(point.x,point.y,aRectangle.width,aRectangle.height);
}
/**
* Convenience method for searching above <code>comp</code> in the
* component hierarchy and returns the first object of class <code>c</code> it
* finds. Can return null, if a class <code>c</code> cannot be found.
*/
public static Container getAncestorOfClass(Class c, Component comp) {
if(comp == null || c == null)
return null;
Container parent = comp.getParent();
while(parent != null && !(c.isInstance(parent)))
parent = parent.getParent();
return parent;
}
/**
* Convenience method for searching above <code>comp</code> in the
* component hierarchy and returns the first object of <code>name</code> it
* finds. Can return null, if <code>name</code> cannot be found.
*/
public static Container getAncestorNamed(String name, Component comp) {
if(comp == null || name == null)
return null;
Container parent = comp.getParent();
while(parent != null && !(name.equals(parent.getName())))
parent = parent.getParent();
return parent;
}
/**
* Returns the deepest visible descendent Component of <code>parent</code>
* that contains the location <code>x</code>, <code>y</code>.
* If <code>parent</code> does not contain the specified location,
* then <code>null</code> is returned. If <code>parent</code> is not a
* container, or none of <code>parent</code>'s visible descendents
* contain the specified location, <code>parent</code> is returned.
*
* @param parent the root component to begin the search
* @param x the x target location
* @param y the y target location
*/
public static Component getDeepestComponentAt(Component parent, int x, int y) {
if (!parent.contains(x, y)) {
return null;
}
if (parent instanceof Container) {
Component components[] = ((Container)parent).getComponents();
for (int i = 0 ; i < components.length ; i++) {
Component comp = components[i];
if (comp != null && comp.isVisible()) {
Point loc = comp.getLocation();
if (comp instanceof Container) {
comp = getDeepestComponentAt(comp, x - loc.x, y - loc.y);
} else {
comp = comp.getComponentAt(x - loc.x, y - loc.y);
}
if (comp != null && comp.isVisible()) {
return comp;
}
}
}
}
return parent;
}
/**
* Returns a MouseEvent similar to <code>sourceEv
没有合适的资源?快使用搜索试试~ 我知道了~
JavaME源程序代码
共312个文件
java:189个
png:25个
jar:15个
需积分: 10 74 下载量 118 浏览量
2008-11-14
08:11:47
上传
评论 5
收藏 9.64MB RAR 举报
温馨提示
JavaME源程序代码 JavaME源程序代码 JavaME源程序代码
资源推荐
资源详情
资源评论
收起资源包目录
JavaME源程序代码 (312个子文件)
TestApp.aif 2KB
TestApp.app 16B
compile.bat 46B
UserDataServlet.class 2KB
MIDletUserDataUpdateServlet.class 2KB
MIDletUserDataServlet.class 2KB
AccessDAO.class 1KB
Main.class 894B
Main.class 799B
MyHandler.class 374B
MyHandler.class 374B
MyAdapter.class 347B
MyAdapter.class 347B
Thumbs.db 58KB
Thumbs.db 7KB
Thumbs.db 7KB
Thumbs.db 7KB
index.html 402B
UIDemo.jad 771B
MyEnterpriseClient.jad 447B
MyFirst.jad 344B
MySocketClient.jad 265B
MyHttpClient.jad 255B
FlowControl.jad 250B
swingall_fix.jar 2.31MB
修正 -swingall.jar 2.31MB
swingall.jar 2.31MB
swingall.jar 2.31MB
retroguard.jar 141KB
retroguard.jar 141KB
retroguard.jar 141KB
retroguard.jar 141KB
retroguard.jar 141KB
retroguard.jar 141KB
retroguard.jar 141KB
retroguard.jar 141KB
retroguard.jar 141KB
servlet.jar 77KB
MyGUI.jar 28KB
SwingUtilities.java 60KB
原始 -SwingUtilities.java 58KB
RunRetro.java 9KB
AlertDemo.java 5KB
Table.java 5KB
MyGameCanStopWithRateWithDoubleBuffer.java 4KB
ListDemo.java 4KB
TankSprite2.java 4KB
MyGameWithColliCanvas.java 4KB
MyGameWithTiledLayerCanvas.java 4KB
MyGameCanStopWithRate1.java 4KB
MyGameCanStopWithRate.java 4KB
TextBoxDemo.java 3KB
RMSUtil.java 3KB
RMSUtil.java 3KB
MyGameWithSpriteCanvas2.java 3KB
MyGameWithSpriteRotateCanvas.java 3KB
CalendarTestQuery.java 3KB
DisplayTestCnavas.java 3KB
MyGameWithSpriteCanvas1.java 3KB
ProGuardWTKGlue.java 3KB
MyGameCanStop.java 3KB
MyGameWithSpriteRotateCanvas3.java 3KB
MyGameWithSpriteCanvas.java 3KB
StringItemDemo.java 3KB
KeyEventTestCanvas2.java 3KB
MyGameWithSpriteRotateCanvas2.java 3KB
RMSMonitorTest.java 3KB
PowerListenerTest.java 2KB
ChoiceGroupDemo.java 2KB
ChoiceGroupWithItemStateListenerMIDlet.java 2KB
GaugeDemo.java 2KB
BadSprite.java 2KB
TelephonyTest.java 2KB
Navigator.java 2KB
ImplicitListwithFitPolicyMIDlet.java 2KB
MyGameWithInputCanvas.java 2KB
DisplayableTestMIDlet.java 2KB
DataRecordStoreTest.java 2KB
MyGame.java 2KB
RecordEnumerationTest.java 2KB
ImplicitListwithSetCommandMIDlet.java 2KB
ImplicitListMIDlet.java 2KB
FriendDataEntity.java 2KB
GaugeIndefinite.java 2KB
KeyEventWithCommandActionTestCanvas.java 2KB
AlertWithIndicatorMIDlet.java 2KB
ImageItemWithDefaultCommandMIDlet.java 2KB
GameMIDlet.java 2KB
AlertTypeMIDlet.java 2KB
UpdateUserDataThread.java 2KB
AlertWithImageAndThreadMIDlet.java 2KB
MyGameCanvas.java 2KB
MultipleListMIDlet.java 2KB
GameMIDlet.java 2KB
PowerMonitorTest.java 2KB
TextFieldDemo.java 2KB
UserDataServlet.java 2KB
NonInteractiveGaugeRunnable.java 2KB
AlertWithIndicatorAndThreadMIDlet.java 2KB
ExclusiveListMIDlet.java 2KB
共 312 条
- 1
- 2
- 3
- 4
资源评论
zxl359592450
- 粉丝: 25
- 资源: 68
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功