Delete AWT from frameworks/base.
This code was never released and doesn't compile. Note that java.awt.font is a published API that we're stuck with; that code is in libcore. http://b/issue?id=2732079 Change-Id: If9516b63be8cdffc959b540df18615b159361892
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
#
|
||||
# Copyright (C) 2008 The Android Open Source Project
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
||||
|
||||
LOCAL_JAVA_RESOURCE_DIRS := resources
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := core framework
|
||||
|
||||
LOCAL_MODULE:= android.awt
|
||||
|
||||
LOCAL_DX_FLAGS := --core-library
|
||||
|
||||
#include $(BUILD_JAVA_LIBRARY)
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.internal.awt;
|
||||
|
||||
import com.android.internal.awt.AndroidGraphics2D;
|
||||
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.VolatileImage;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
|
||||
public class AndroidGraphicsConfiguration extends GraphicsConfiguration {
|
||||
|
||||
@Override
|
||||
public BufferedImage createCompatibleImage(int width, int height) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage createCompatibleImage(int width, int height,
|
||||
int transparency) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolatileImage createCompatibleVolatileImage(int width, int height) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolatileImage createCompatibleVolatileImage(int width, int height,
|
||||
int transparency) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Rectangle getBounds() {
|
||||
Canvas c = AndroidGraphics2D.getAndroidCanvas();
|
||||
if(c != null)
|
||||
return new Rectangle(0, 0, c.getWidth(), c.getHeight());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorModel getColorModel() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorModel getColorModel(int transparency) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AffineTransform getDefaultTransform() {
|
||||
return new AffineTransform();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphicsDevice getDevice() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AffineTransform getNormalizingTransform() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.internal.awt;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.peer.FontPeer;
|
||||
|
||||
import org.apache.harmony.awt.gl.MultiRectArea;
|
||||
import org.apache.harmony.awt.gl.font.AndroidFont;
|
||||
import org.apache.harmony.awt.gl.font.FontManager;
|
||||
import org.apache.harmony.awt.gl.font.FontMetricsImpl;
|
||||
import org.apache.harmony.awt.gl.font.AndroidFontManager;
|
||||
import org.apache.harmony.awt.wtk.NativeWindow;
|
||||
import org.apache.harmony.awt.wtk.WindowFactory;
|
||||
import org.apache.harmony.awt.gl.CommonGraphics2DFactory;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.content.Context;
|
||||
|
||||
public class AndroidGraphicsFactory extends CommonGraphics2DFactory {
|
||||
|
||||
public GraphicsEnvironment createGraphicsEnvironment(WindowFactory wf) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Font embedFont(String fontFilePath) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public FontManager getFontManager() {
|
||||
return AndroidFontManager.inst;
|
||||
}
|
||||
|
||||
public FontMetrics getFontMetrics(Font font) {
|
||||
return new FontMetricsImpl(font);
|
||||
}
|
||||
|
||||
public FontPeer getFontPeer(Font font) {
|
||||
//return getFontManager().getFontPeer(font.getName(), font.getStyle(), font.getSize());
|
||||
return new AndroidFont(font.getName(), font.getStyle(), font.getSize());
|
||||
}
|
||||
|
||||
public Graphics2D getGraphics2D(NativeWindow win, int translateX,
|
||||
int translateY, MultiRectArea clip) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Graphics2D getGraphics2D(NativeWindow win, int translateX,
|
||||
int translateY, int width, int height) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
public Graphics2D getGraphics2D(Context ctx, Canvas c, Paint p) {
|
||||
return AndroidGraphics2D.getInstance(ctx, c, p);
|
||||
}
|
||||
|
||||
public Graphics2D getGraphics2D(Canvas c, Paint p) {
|
||||
throw new RuntimeException("Not supported!");
|
||||
}
|
||||
|
||||
public Graphics2D getGraphics2D() {
|
||||
return AndroidGraphics2D.getInstance();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,274 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.internal.awt;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
||||
import java.awt.Transparency;
|
||||
import java.awt.color.ColorSpace;
|
||||
//import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ComponentColorModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.DirectColorModel;
|
||||
import java.awt.image.ImageConsumer;
|
||||
import java.awt.image.IndexColorModel;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.harmony.awt.gl.image.DecodingImageSource;
|
||||
import org.apache.harmony.awt.gl.image.ImageDecoder;
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
public class AndroidImageDecoder extends ImageDecoder {
|
||||
|
||||
private static final int hintflags =
|
||||
ImageConsumer.SINGLEFRAME | // PNG is a static image
|
||||
ImageConsumer.TOPDOWNLEFTRIGHT | // This order is only one possible
|
||||
ImageConsumer.COMPLETESCANLINES; // Don't deliver incomplete scanlines
|
||||
|
||||
// Each pixel is a grayscale sample.
|
||||
private static final int PNG_COLOR_TYPE_GRAY = 0;
|
||||
// Each pixel is an R,G,B triple.
|
||||
private static final int PNG_COLOR_TYPE_RGB = 2;
|
||||
// Each pixel is a palette index, a PLTE chunk must appear.
|
||||
private static final int PNG_COLOR_TYPE_PLTE = 3;
|
||||
// Each pixel is a grayscale sample, followed by an alpha sample.
|
||||
private static final int PNG_COLOR_TYPE_GRAY_ALPHA = 4;
|
||||
// Each pixel is an R,G,B triple, followed by an alpha sample.
|
||||
private static final int PNG_COLOR_TYPE_RGBA = 6;
|
||||
|
||||
private static final int NB_OF_LINES_PER_CHUNK = 1; // 0 = full image
|
||||
|
||||
Bitmap bm; // The image as decoded by Android
|
||||
|
||||
// Header information
|
||||
int imageWidth; // Image size
|
||||
int imageHeight;
|
||||
int colorType; // One of the PNG_ constants from above
|
||||
int bitDepth; // Number of bits per color
|
||||
byte cmap[]; // The color palette for index color models
|
||||
ColorModel model; // The corresponding AWT color model
|
||||
|
||||
boolean transferInts; // Is transfer of type int or byte?
|
||||
int dataElementsPerPixel;
|
||||
|
||||
// Buffers for decoded image data
|
||||
byte byteOut[];
|
||||
int intOut[];
|
||||
|
||||
|
||||
public AndroidImageDecoder(DecodingImageSource src, InputStream is) {
|
||||
super(src, is);
|
||||
dataElementsPerPixel = 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* All the decoding is done in Android
|
||||
*
|
||||
* AWT???: Method returns only once the image is completly
|
||||
* decoded; decoding is not done asynchronously
|
||||
*/
|
||||
public void decodeImage() throws IOException {
|
||||
try {
|
||||
bm = BitmapFactory.decodeStream(inputStream);
|
||||
if (bm == null) {
|
||||
throw new IOException("Input stream empty and no image cached");
|
||||
}
|
||||
|
||||
// Check size
|
||||
imageWidth = bm.getWidth();
|
||||
imageHeight = bm.getHeight();
|
||||
if (imageWidth < 0 || imageHeight < 0 ) {
|
||||
throw new RuntimeException("Illegal image size: "
|
||||
+ imageWidth + ", " + imageHeight);
|
||||
}
|
||||
|
||||
// We got the image fully decoded; now send all image data to AWT
|
||||
setDimensions(imageWidth, imageHeight);
|
||||
model = createColorModel();
|
||||
setColorModel(model);
|
||||
setHints(hintflags);
|
||||
setProperties(new Hashtable<Object, Object>()); // Empty
|
||||
sendPixels(NB_OF_LINES_PER_CHUNK != 0 ? NB_OF_LINES_PER_CHUNK : imageHeight);
|
||||
imageComplete(ImageConsumer.STATICIMAGEDONE);
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} catch (RuntimeException e) {
|
||||
imageComplete(ImageConsumer.IMAGEERROR);
|
||||
throw e;
|
||||
} finally {
|
||||
closeStream();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the AWT color model
|
||||
*
|
||||
* ???AWT: Android Bitmaps are always of type: ARGB-8888-Direct color model
|
||||
*
|
||||
* However, we leave the code here for a more powerfull decoder
|
||||
* that returns a native model, and the conversion is then handled
|
||||
* in AWT. With such a decoder, we would need to get the colorType,
|
||||
* the bitDepth, (and the color palette for an index color model)
|
||||
* from the image and construct the correct color model here.
|
||||
*/
|
||||
private ColorModel createColorModel() {
|
||||
ColorModel cm = null;
|
||||
int bmModel = 5; // TODO This doesn't exist: bm.getColorModel();
|
||||
cmap = null;
|
||||
|
||||
switch (bmModel) {
|
||||
// A1_MODEL
|
||||
case 1:
|
||||
colorType = PNG_COLOR_TYPE_GRAY;
|
||||
bitDepth = 1;
|
||||
break;
|
||||
|
||||
// A8_MODEL
|
||||
case 2:
|
||||
colorType = PNG_COLOR_TYPE_GRAY_ALPHA;
|
||||
bitDepth = 8;
|
||||
break;
|
||||
|
||||
// INDEX8_MODEL
|
||||
// RGB_565_MODEL
|
||||
// ARGB_8888_MODEL
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
colorType = bm.hasAlpha() ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB;
|
||||
bitDepth = 8;
|
||||
break;
|
||||
|
||||
default:
|
||||
// awt.3C=Unknown PNG color type
|
||||
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
switch (colorType) {
|
||||
|
||||
case PNG_COLOR_TYPE_GRAY: {
|
||||
if (bitDepth != 8 && bitDepth != 4 && bitDepth != 2 && bitDepth != 1) {
|
||||
// awt.3C=Unknown PNG color type
|
||||
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
// Create gray color model
|
||||
int numEntries = 1 << bitDepth;
|
||||
int scaleFactor = 255 / (numEntries-1);
|
||||
byte comps[] = new byte[numEntries];
|
||||
for (int i = 0; i < numEntries; i++) {
|
||||
comps[i] = (byte) (i * scaleFactor);
|
||||
}
|
||||
cm = new IndexColorModel(bitDepth, numEntries, comps, comps, comps);
|
||||
|
||||
transferInts = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case PNG_COLOR_TYPE_RGB: {
|
||||
if (bitDepth != 8) {
|
||||
// awt.3C=Unknown PNG color type
|
||||
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
cm = new DirectColorModel(24, 0xff0000, 0xFF00, 0xFF);
|
||||
|
||||
transferInts = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case PNG_COLOR_TYPE_PLTE: {
|
||||
if (bitDepth != 8 && bitDepth != 4 && bitDepth != 2 && bitDepth != 1) {
|
||||
// awt.3C=Unknown PNG color type
|
||||
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
if (cmap == null) {
|
||||
throw new IllegalStateException("Palette color type is not supported");
|
||||
}
|
||||
|
||||
cm = new IndexColorModel(bitDepth, cmap.length / 3, cmap, 0, false);
|
||||
|
||||
transferInts = false;
|
||||
break;
|
||||
}
|
||||
|
||||
case PNG_COLOR_TYPE_GRAY_ALPHA: {
|
||||
if (bitDepth != 8) {
|
||||
// awt.3C=Unknown PNG color type
|
||||
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_GRAY),
|
||||
true, false,
|
||||
Transparency.TRANSLUCENT,
|
||||
DataBuffer.TYPE_BYTE);
|
||||
|
||||
transferInts = false;
|
||||
dataElementsPerPixel = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
case PNG_COLOR_TYPE_RGBA: {
|
||||
if (bitDepth != 8) {
|
||||
// awt.3C=Unknown PNG color type
|
||||
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
cm = ColorModel.getRGBdefault();
|
||||
|
||||
transferInts = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// awt.3C=Unknown PNG color type
|
||||
throw new IllegalArgumentException(Messages.getString("awt.3C")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return cm;
|
||||
}
|
||||
|
||||
private void sendPixels(int nbOfLinesPerChunk) {
|
||||
int w = imageWidth;
|
||||
int h = imageHeight;
|
||||
int n = 1;
|
||||
if (nbOfLinesPerChunk > 0 && nbOfLinesPerChunk <= h) {
|
||||
n = nbOfLinesPerChunk;
|
||||
}
|
||||
|
||||
if (transferInts) {
|
||||
// Create output buffer
|
||||
intOut = new int[w * n];
|
||||
for (int yi = 0; yi < h; yi += n) {
|
||||
// Last chunk might contain less liness
|
||||
if (n > 1 && h - yi < n ) {
|
||||
n = h - yi;
|
||||
}
|
||||
bm.getPixels(intOut, 0, w, 0, yi, w, n);
|
||||
setPixels(0, yi, w, n, model, intOut, 0, w);
|
||||
}
|
||||
} else {
|
||||
// Android bitmaps always store ints (ARGB-8888 direct model)
|
||||
throw new RuntimeException("Byte transfer not supported");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,536 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.internal.awt;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import org.apache.harmony.awt.gl.MultiRectArea;
|
||||
import org.apache.harmony.awt.gl.Surface;
|
||||
import org.apache.harmony.awt.gl.XORComposite;
|
||||
import org.apache.harmony.awt.gl.render.Blitter;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
public class AndroidJavaBlitter implements Blitter {
|
||||
|
||||
private Canvas canvas;
|
||||
private Paint paint;
|
||||
private int colorCache;
|
||||
|
||||
public AndroidJavaBlitter(Canvas c) {
|
||||
this.canvas = c;
|
||||
this.paint = new Paint();
|
||||
this.paint.setStrokeWidth(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instead of multiplication and division we are using values from
|
||||
* Lookup tables.
|
||||
*/
|
||||
static byte mulLUT[][]; // Lookup table for multiplication
|
||||
static byte divLUT[][]; // Lookup table for division
|
||||
|
||||
static{
|
||||
mulLUT = new byte[256][256];
|
||||
for(int i = 0; i < 256; i++){
|
||||
for(int j = 0; j < 256; j++){
|
||||
mulLUT[i][j] = (byte)((float)(i * j)/255 + 0.5f);
|
||||
}
|
||||
}
|
||||
divLUT = new byte[256][256];
|
||||
for(int i = 1; i < 256; i++){
|
||||
for(int j = 0; j < i; j++){
|
||||
divLUT[i][j] = (byte)(((float)j / 255) / ((float)i/ 255) * 255 + 0.5f);
|
||||
}
|
||||
for(int j = i; j < 256; j++){
|
||||
divLUT[i][j] = (byte)255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final static int AlphaCompositeMode = 1;
|
||||
final static int XORMode = 2;
|
||||
|
||||
public void blit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY,
|
||||
Surface dstSurf, int width, int height, AffineTransform sysxform,
|
||||
AffineTransform xform, Composite comp, Color bgcolor,
|
||||
MultiRectArea clip) {
|
||||
|
||||
if(xform == null){
|
||||
blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, width, height,
|
||||
sysxform, comp, bgcolor, clip);
|
||||
}else{
|
||||
double scaleX = xform.getScaleX();
|
||||
double scaleY = xform.getScaleY();
|
||||
double scaledX = dstX / scaleX;
|
||||
double scaledY = dstY / scaleY;
|
||||
AffineTransform at = new AffineTransform();
|
||||
at.setToTranslation(scaledX, scaledY);
|
||||
xform.concatenate(at);
|
||||
sysxform.concatenate(xform);
|
||||
blit(srcX, srcY, srcSurf, 0, 0, dstSurf, width, height,
|
||||
sysxform, comp, bgcolor, clip);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void blit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY,
|
||||
Surface dstSurf, int width, int height, AffineTransform sysxform,
|
||||
Composite comp, Color bgcolor, MultiRectArea clip) {
|
||||
|
||||
if(sysxform == null) {
|
||||
sysxform = new AffineTransform();
|
||||
}
|
||||
int type = sysxform.getType();
|
||||
switch(type){
|
||||
case AffineTransform.TYPE_TRANSLATION:
|
||||
dstX += sysxform.getTranslateX();
|
||||
dstY += sysxform.getTranslateY();
|
||||
case AffineTransform.TYPE_IDENTITY:
|
||||
simpleBlit(srcX, srcY, srcSurf, dstX, dstY, dstSurf,
|
||||
width, height, comp, bgcolor, clip);
|
||||
break;
|
||||
default:
|
||||
int srcW = srcSurf.getWidth();
|
||||
int srcH = srcSurf.getHeight();
|
||||
|
||||
int w = srcX + width < srcW ? width : srcW - srcX;
|
||||
int h = srcY + height < srcH ? height : srcH - srcY;
|
||||
|
||||
ColorModel srcCM = srcSurf.getColorModel();
|
||||
Raster srcR = srcSurf.getRaster().createChild(srcX, srcY,
|
||||
w, h, 0, 0, null);
|
||||
|
||||
ColorModel dstCM = dstSurf.getColorModel();
|
||||
WritableRaster dstR = dstSurf.getRaster();
|
||||
|
||||
transformedBlit(srcCM, srcR, 0, 0, dstCM, dstR, dstX, dstY, w, h,
|
||||
sysxform, comp, bgcolor, clip);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void simpleBlit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY,
|
||||
Surface dstSurf, int width, int height, Composite comp,
|
||||
Color bgcolor, MultiRectArea clip) {
|
||||
|
||||
// TODO It's possible, though unlikely that we might encounter non-int[]
|
||||
// data buffers. In this case the following code needs to have several
|
||||
// branches that take this into account.
|
||||
data = (DataBufferInt)srcSurf.getRaster().getDataBuffer();
|
||||
int[] pixels = data.getData();
|
||||
if (!srcSurf.getColorModel().hasAlpha()) {
|
||||
// This wouldn't be necessary if Android supported RGB_888.
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
pixels[i] = pixels[i] | 0xff000000;
|
||||
}
|
||||
}
|
||||
bmap = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
|
||||
canvas.drawBitmap(bmap, dstX, dstY, paint);
|
||||
}
|
||||
|
||||
public void blit(int srcX, int srcY, Surface srcSurf, int dstX, int dstY,
|
||||
Surface dstSurf, int width, int height, Composite comp,
|
||||
Color bgcolor, MultiRectArea clip) {
|
||||
|
||||
javaBlt(srcX, srcY, srcSurf.getWidth(), srcSurf.getHeight(),
|
||||
srcSurf.getColorModel(), srcSurf.getRaster(), dstX, dstY,
|
||||
dstSurf.getWidth(), dstSurf.getHeight(),
|
||||
dstSurf.getColorModel(), dstSurf.getRaster(),
|
||||
width, height, comp, bgcolor, clip);
|
||||
|
||||
}
|
||||
|
||||
public void javaBlt(int srcX, int srcY, int srcW, int srcH,
|
||||
ColorModel srcCM, Raster srcRast, int dstX, int dstY,
|
||||
int dstW, int dstH, ColorModel dstCM, WritableRaster dstRast,
|
||||
int width, int height, Composite comp, Color bgcolor,
|
||||
MultiRectArea clip){
|
||||
|
||||
int srcX2 = srcW - 1;
|
||||
int srcY2 = srcH - 1;
|
||||
int dstX2 = dstW - 1;
|
||||
int dstY2 = dstH - 1;
|
||||
|
||||
if(srcX < 0){
|
||||
width += srcX;
|
||||
srcX = 0;
|
||||
}
|
||||
if(srcY < 0){
|
||||
height += srcY;
|
||||
srcY = 0;
|
||||
}
|
||||
|
||||
if(dstX < 0){
|
||||
width += dstX;
|
||||
srcX -= dstX;
|
||||
dstX = 0;
|
||||
}
|
||||
if(dstY < 0){
|
||||
height += dstY;
|
||||
srcY -= dstY;
|
||||
dstY = 0;
|
||||
}
|
||||
|
||||
if(srcX > srcX2 || srcY > srcY2) {
|
||||
return;
|
||||
}
|
||||
if(dstX > dstX2 || dstY > dstY2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(srcX + width > srcX2) {
|
||||
width = srcX2 - srcX + 1;
|
||||
}
|
||||
if(srcY + height > srcY2) {
|
||||
height = srcY2 - srcY + 1;
|
||||
}
|
||||
if(dstX + width > dstX2) {
|
||||
width = dstX2 - dstX + 1;
|
||||
}
|
||||
if(dstY + height > dstY2) {
|
||||
height = dstY2 - dstY + 1;
|
||||
}
|
||||
|
||||
if(width <= 0 || height <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int clipRects[];
|
||||
if(clip != null) {
|
||||
clipRects = clip.rect;
|
||||
} else {
|
||||
clipRects = new int[]{5, 0, 0, dstW - 1, dstH - 1};
|
||||
}
|
||||
|
||||
boolean isAlphaComp = false;
|
||||
int rule = 0;
|
||||
float alpha = 0;
|
||||
boolean isXORComp = false;
|
||||
Color xorcolor = null;
|
||||
CompositeContext cont = null;
|
||||
|
||||
if(comp instanceof AlphaComposite){
|
||||
isAlphaComp = true;
|
||||
AlphaComposite ac = (AlphaComposite) comp;
|
||||
rule = ac.getRule();
|
||||
alpha = ac.getAlpha();
|
||||
}else if(comp instanceof XORComposite){
|
||||
isXORComp = true;
|
||||
XORComposite xcomp = (XORComposite) comp;
|
||||
xorcolor = xcomp.getXORColor();
|
||||
}else{
|
||||
cont = comp.createContext(srcCM, dstCM, null);
|
||||
}
|
||||
|
||||
for(int i = 1; i < clipRects[0]; i += 4){
|
||||
int _sx = srcX;
|
||||
int _sy = srcY;
|
||||
|
||||
int _dx = dstX;
|
||||
int _dy = dstY;
|
||||
|
||||
int _w = width;
|
||||
int _h = height;
|
||||
|
||||
int cx = clipRects[i]; // Clipping left top X
|
||||
int cy = clipRects[i + 1]; // Clipping left top Y
|
||||
int cx2 = clipRects[i + 2]; // Clipping right bottom X
|
||||
int cy2 = clipRects[i + 3]; // Clipping right bottom Y
|
||||
|
||||
if(_dx > cx2 || _dy > cy2 || dstX2 < cx || dstY2 < cy) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(cx > _dx){
|
||||
int shx = cx - _dx;
|
||||
_w -= shx;
|
||||
_dx = cx;
|
||||
_sx += shx;
|
||||
}
|
||||
|
||||
if(cy > _dy){
|
||||
int shy = cy - _dy;
|
||||
_h -= shy;
|
||||
_dy = cy;
|
||||
_sy += shy;
|
||||
}
|
||||
|
||||
if(_dx + _w > cx2 + 1){
|
||||
_w = cx2 - _dx + 1;
|
||||
}
|
||||
|
||||
if(_dy + _h > cy2 + 1){
|
||||
_h = cy2 - _dy + 1;
|
||||
}
|
||||
|
||||
if(_sx > srcX2 || _sy > srcY2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isAlphaComp){
|
||||
alphaCompose(_sx, _sy, srcCM, srcRast, _dx, _dy,
|
||||
dstCM, dstRast, _w, _h, rule, alpha, bgcolor);
|
||||
}else if(isXORComp){
|
||||
xorCompose(_sx, _sy, srcCM, srcRast, _dx, _dy,
|
||||
dstCM, dstRast, _w, _h, xorcolor);
|
||||
}else{
|
||||
Raster sr = srcRast.createChild(_sx, _sy, _w, _h, 0, 0, null);
|
||||
WritableRaster dr = dstRast.createWritableChild(_dx, _dy,
|
||||
_w, _h, 0, 0, null);
|
||||
cont.compose(sr, dr, dr);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
DataBufferInt data;
|
||||
Bitmap bmap, bmp;
|
||||
|
||||
void alphaCompose(int srcX, int srcY, ColorModel srcCM, Raster srcRast,
|
||||
int dstX, int dstY, ColorModel dstCM, WritableRaster dstRast,
|
||||
int width, int height, int rule, float alpha, Color bgcolor){
|
||||
|
||||
Object srcPixel = getTransferArray(srcRast, 1);
|
||||
data = (DataBufferInt)srcRast.getDataBuffer();
|
||||
int pix[] = data.getData();
|
||||
bmap = Bitmap.createBitmap(pix, width, height, Bitmap.Config.RGB_565);
|
||||
canvas.drawBitmap(bmap, dstX, dstY, paint);
|
||||
}
|
||||
|
||||
void render(int[] img, int x, int y, int width, int height) {
|
||||
canvas.drawBitmap(Bitmap.createBitmap(img, width, height, Bitmap.Config.ARGB_8888), x, y, paint);
|
||||
}
|
||||
|
||||
void xorCompose(int srcX, int srcY, ColorModel srcCM, Raster srcRast,
|
||||
int dstX, int dstY, ColorModel dstCM, WritableRaster dstRast,
|
||||
int width, int height, Color xorcolor){
|
||||
|
||||
data = (DataBufferInt)srcRast.getDataBuffer();
|
||||
int pix[] = data.getData();
|
||||
bmap = Bitmap.createBitmap(pix, width, height, Bitmap.Config.RGB_565);
|
||||
canvas.drawBitmap(bmap, dstX, dstY, paint);
|
||||
}
|
||||
|
||||
private void transformedBlit(ColorModel srcCM, Raster srcR, int srcX, int srcY,
|
||||
ColorModel dstCM, WritableRaster dstR, int dstX, int dstY,
|
||||
int width, int height, AffineTransform at, Composite comp,
|
||||
Color bgcolor, MultiRectArea clip) {
|
||||
|
||||
data = (DataBufferInt)srcR.getDataBuffer();
|
||||
int[] pixels = data.getData();
|
||||
if (!srcCM.hasAlpha()) {
|
||||
// This wouldn't be necessary if Android supported RGB_888.
|
||||
for (int i = 0; i < pixels.length; i++) {
|
||||
pixels[i] = pixels[i] | 0xff000000;
|
||||
}
|
||||
}
|
||||
bmap = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
|
||||
|
||||
Matrix tm = new Matrix();
|
||||
tm.setConcat(canvas.getMatrix(), AndroidGraphics2D.createMatrixObj(at));
|
||||
if(at.getType() > 1) {
|
||||
bmp = Bitmap.createBitmap(bmap, 0, 0, width, height, tm, true);
|
||||
} else {
|
||||
bmp = Bitmap.createBitmap(bmap, 0, 0, width, height, tm, false);
|
||||
}
|
||||
canvas.drawBitmap(bmp, dstX + (float)at.getTranslateX(), dstY + (float)at.getTranslateY(), paint);
|
||||
}
|
||||
|
||||
private Rectangle2D getBounds2D(AffineTransform at, Rectangle r) {
|
||||
int x = r.x;
|
||||
int y = r.y;
|
||||
int width = r.width;
|
||||
int height = r.height;
|
||||
|
||||
float[] corners = {
|
||||
x, y,
|
||||
x + width, y,
|
||||
x + width, y + height,
|
||||
x, y + height
|
||||
};
|
||||
|
||||
at.transform(corners, 0, corners, 0, 4);
|
||||
|
||||
Rectangle2D.Float bounds = new Rectangle2D.Float(corners[0], corners[1], 0 , 0);
|
||||
bounds.add(corners[2], corners[3]);
|
||||
bounds.add(corners[4], corners[5]);
|
||||
bounds.add(corners[6], corners[7]);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
private int compose(int srcRGB, boolean isSrcAlphaPre,
|
||||
int dstRGB, boolean dstHasAlpha, boolean isDstAlphaPre,
|
||||
int rule, int srcConstAlpha){
|
||||
|
||||
int sa, sr, sg, sb, da, dr, dg, db;
|
||||
|
||||
sa = (srcRGB >> 24) & 0xff;
|
||||
sr = (srcRGB >> 16) & 0xff;
|
||||
sg = (srcRGB >> 8) & 0xff;
|
||||
sb = srcRGB & 0xff;
|
||||
|
||||
if(isSrcAlphaPre){
|
||||
sa = mulLUT[srcConstAlpha][sa] & 0xff;
|
||||
sr = mulLUT[srcConstAlpha][sr] & 0xff;
|
||||
sg = mulLUT[srcConstAlpha][sg] & 0xff;
|
||||
sb = mulLUT[srcConstAlpha][sb] & 0xff;
|
||||
}else{
|
||||
sa = mulLUT[srcConstAlpha][sa] & 0xff;
|
||||
sr = mulLUT[sa][sr] & 0xff;
|
||||
sg = mulLUT[sa][sg] & 0xff;
|
||||
sb = mulLUT[sa][sb] & 0xff;
|
||||
}
|
||||
|
||||
da = (dstRGB >> 24) & 0xff;
|
||||
dr = (dstRGB >> 16) & 0xff;
|
||||
dg = (dstRGB >> 8) & 0xff;
|
||||
db = dstRGB & 0xff;
|
||||
|
||||
if(!isDstAlphaPre){
|
||||
dr = mulLUT[da][dr] & 0xff;
|
||||
dg = mulLUT[da][dg] & 0xff;
|
||||
db = mulLUT[da][db] & 0xff;
|
||||
}
|
||||
|
||||
int Fs = 0;
|
||||
int Fd = 0;
|
||||
switch(rule){
|
||||
case AlphaComposite.CLEAR:
|
||||
break;
|
||||
|
||||
case AlphaComposite.DST:
|
||||
Fd = 255;
|
||||
break;
|
||||
|
||||
case AlphaComposite.DST_ATOP:
|
||||
Fs = 255 - da;
|
||||
Fd = sa;
|
||||
break;
|
||||
|
||||
case AlphaComposite.DST_IN:
|
||||
Fd = sa;
|
||||
break;
|
||||
|
||||
case AlphaComposite.DST_OUT:
|
||||
Fd = 255 - sa;
|
||||
break;
|
||||
|
||||
case AlphaComposite.DST_OVER:
|
||||
Fs = 255 - da;
|
||||
Fd = 255;
|
||||
break;
|
||||
|
||||
case AlphaComposite.SRC:
|
||||
Fs = 255;
|
||||
break;
|
||||
|
||||
case AlphaComposite.SRC_ATOP:
|
||||
Fs = da;
|
||||
Fd = 255 - sa;
|
||||
break;
|
||||
|
||||
case AlphaComposite.SRC_IN:
|
||||
Fs = da;
|
||||
break;
|
||||
|
||||
case AlphaComposite.SRC_OUT:
|
||||
Fs = 255 - da;
|
||||
break;
|
||||
|
||||
case AlphaComposite.SRC_OVER:
|
||||
Fs = 255;
|
||||
Fd = 255 - sa;
|
||||
break;
|
||||
|
||||
case AlphaComposite.XOR:
|
||||
Fs = 255 - da;
|
||||
Fd = 255 - sa;
|
||||
break;
|
||||
}
|
||||
dr = (mulLUT[sr][Fs] & 0xff) + (mulLUT[dr][Fd] & 0xff);
|
||||
dg = (mulLUT[sg][Fs] & 0xff) + (mulLUT[dg][Fd] & 0xff);
|
||||
db = (mulLUT[sb][Fs] & 0xff) + (mulLUT[db][Fd] & 0xff);
|
||||
|
||||
da = (mulLUT[sa][Fs] & 0xff) + (mulLUT[da][Fd] & 0xff);
|
||||
|
||||
if(!isDstAlphaPre){
|
||||
if(da != 255){
|
||||
dr = divLUT[da][dr] & 0xff;
|
||||
dg = divLUT[da][dg] & 0xff;
|
||||
db = divLUT[da][db] & 0xff;
|
||||
}
|
||||
}
|
||||
if(!dstHasAlpha) {
|
||||
da = 0xff;
|
||||
}
|
||||
dstRGB = (da << 24) | (dr << 16) | (dg << 8) | db;
|
||||
|
||||
return dstRGB;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocate an array that can be use to store the result for a
|
||||
* Raster.getDataElements call.
|
||||
* @param raster Raster (type) where the getDataElements call will be made.
|
||||
* @param nbPixels How many pixels to store in the array at most
|
||||
* @return the result array or null
|
||||
*/
|
||||
private Object getTransferArray(Raster raster, int nbPixels) {
|
||||
int transferType = raster.getTransferType();
|
||||
int nbDataElements = raster.getSampleModel().getNumDataElements();
|
||||
int n = nbDataElements * nbPixels;
|
||||
switch (transferType) {
|
||||
case DataBuffer.TYPE_BYTE:
|
||||
return new byte[n];
|
||||
case DataBuffer.TYPE_SHORT:
|
||||
case DataBuffer.TYPE_USHORT:
|
||||
return new short[n];
|
||||
case DataBuffer.TYPE_INT:
|
||||
return new int[n];
|
||||
case DataBuffer.TYPE_FLOAT:
|
||||
return new float[n];
|
||||
case DataBuffer.TYPE_DOUBLE:
|
||||
return new double[n];
|
||||
case DataBuffer.TYPE_UNDEFINED:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw a pixel
|
||||
*/
|
||||
private void dot(int x, int y, int clr) {
|
||||
if (colorCache != clr) {
|
||||
paint.setColor(clr);
|
||||
colorCache = clr;
|
||||
}
|
||||
canvas.drawLine(x, y, x + 1, y + 1, paint);
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.internal.awt;
|
||||
|
||||
import org.apache.harmony.awt.wtk.NativeEventQueue;
|
||||
|
||||
public class AndroidNativeEventQueue extends NativeEventQueue {
|
||||
|
||||
private Object eventMonitor;
|
||||
|
||||
public AndroidNativeEventQueue() {
|
||||
super();
|
||||
eventMonitor = getEventMonitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void awake() {
|
||||
synchronized (eventMonitor) {
|
||||
eventMonitor.notify();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchEvent() {
|
||||
//???AWT
|
||||
System.out.println(getClass()+": empty method called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getJavaWindow() {
|
||||
//???AWT
|
||||
System.out.println(getClass()+": empty method called");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performLater(Task task) {
|
||||
//???AWT
|
||||
System.out.println(getClass()+": empty method called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performTask(Task task) {
|
||||
//???AWT
|
||||
System.out.println(getClass()+": empty method called");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean waitEvent() {
|
||||
while (isEmpty() ) {
|
||||
synchronized (eventMonitor) {
|
||||
try {
|
||||
eventMonitor.wait(1000);
|
||||
} catch (InterruptedException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.internal.awt;
|
||||
|
||||
import java.awt.GraphicsDevice;
|
||||
|
||||
import org.apache.harmony.awt.wtk.CursorFactory;
|
||||
import org.apache.harmony.awt.wtk.GraphicsFactory;
|
||||
import org.apache.harmony.awt.wtk.NativeEventQueue;
|
||||
import org.apache.harmony.awt.wtk.NativeIM;
|
||||
import org.apache.harmony.awt.wtk.NativeMouseInfo;
|
||||
import org.apache.harmony.awt.wtk.NativeRobot;
|
||||
import org.apache.harmony.awt.wtk.SystemProperties;
|
||||
import org.apache.harmony.awt.wtk.WTK;
|
||||
import org.apache.harmony.awt.wtk.WindowFactory;
|
||||
|
||||
public class AndroidWTK extends WTK {
|
||||
|
||||
private AndroidGraphicsFactory mAgf;
|
||||
private AndroidNativeEventQueue mAneq;
|
||||
|
||||
@Override
|
||||
public CursorFactory getCursorFactory() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphicsFactory getGraphicsFactory() {
|
||||
if(mAgf == null) {
|
||||
mAgf = new AndroidGraphicsFactory();
|
||||
}
|
||||
return mAgf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeEventQueue getNativeEventQueue() {
|
||||
if(mAneq == null) {
|
||||
mAneq = new AndroidNativeEventQueue();
|
||||
}
|
||||
return mAneq;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeIM getNativeIM() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeMouseInfo getNativeMouseInfo() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NativeRobot getNativeRobot(GraphicsDevice screen) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SystemProperties getSystemProperties() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WindowFactory getWindowFactory() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.internal.awt;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import org.apache.harmony.awt.wtk.GraphicsFactory;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
public class AwtFactory {
|
||||
|
||||
private static GraphicsFactory gf;
|
||||
|
||||
/**
|
||||
* Use this method to get acces to AWT drawing primitives and to
|
||||
* render into the surface area of a Android widget. Origin and
|
||||
* clip of the returned graphics object are the same as in the
|
||||
* corresponding Android widget.
|
||||
*
|
||||
* @param c Canvas of the android widget to draw into
|
||||
* @param p The default drawing parameters such as font,
|
||||
* stroke, foreground and background colors, etc.
|
||||
* @return The AWT Graphics object that makes all AWT
|
||||
* drawing primitives available in the androind world.
|
||||
*/
|
||||
public static Graphics2D getAwtGraphics(Canvas c, Paint p) {
|
||||
// AWT?? TODO: test it!
|
||||
if (null == gf) {
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
gf = tk.getGraphicsFactory();
|
||||
}
|
||||
return gf.getGraphics2D(c, p);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Copyright 2007, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.internal.awt;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class ImageOutputStreamWrapper extends OutputStream {
|
||||
|
||||
protected ImageOutputStream mIos;
|
||||
|
||||
private byte[] mBuff;
|
||||
|
||||
public ImageOutputStreamWrapper(ImageOutputStream ios) {
|
||||
if (null == ios) {
|
||||
throw new IllegalArgumentException("ImageOutputStream must not be null");
|
||||
}
|
||||
this.mIos = ios;
|
||||
this.mBuff = new byte[1];
|
||||
}
|
||||
|
||||
public ImageOutputStream getImageOutputStream() {
|
||||
return mIos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int oneByte) throws IOException {
|
||||
mBuff[0] = (byte)oneByte;
|
||||
mIos.write(mBuff, 0, 1);
|
||||
}
|
||||
|
||||
public void write(byte[] b) throws IOException {
|
||||
mIos.write(b, 0, b.length);
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
mIos.write(b, off, len);
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
mIos.flush();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
if (mIos == null) {
|
||||
throw new IOException("Stream already closed");
|
||||
}
|
||||
mIos = null;
|
||||
}
|
||||
}
|
||||
@@ -1,681 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Dmitry A. Durnev, Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.util.EventObject;
|
||||
import java.util.Hashtable;
|
||||
import java.util.EventListener;
|
||||
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* The abstract class AWTEvent is the base class for all AWT events. This class
|
||||
* and its subclasses supersede the original java.awt.Event class.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class AWTEvent extends EventObject {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -1825314779160409405L;
|
||||
|
||||
/**
|
||||
* The Constant COMPONENT_EVENT_MASK indicates the event relates to a
|
||||
* component.
|
||||
*/
|
||||
public static final long COMPONENT_EVENT_MASK = 1;
|
||||
|
||||
/**
|
||||
* The Constant CONTAINER_EVENT_MASK indicates the event relates to a
|
||||
* container.
|
||||
*/
|
||||
public static final long CONTAINER_EVENT_MASK = 2;
|
||||
|
||||
/**
|
||||
* The Constant FOCUS_EVENT_MASK indicates the event relates to the focus.
|
||||
*/
|
||||
public static final long FOCUS_EVENT_MASK = 4;
|
||||
|
||||
/**
|
||||
* The Constant KEY_EVENT_MASK indicates the event relates to a key.
|
||||
*/
|
||||
public static final long KEY_EVENT_MASK = 8;
|
||||
|
||||
/**
|
||||
* The Constant MOUSE_EVENT_MASK indicates the event relates to the mouse.
|
||||
*/
|
||||
public static final long MOUSE_EVENT_MASK = 16;
|
||||
|
||||
/**
|
||||
* The Constant MOUSE_MOTION_EVENT_MASK indicates the event relates to a
|
||||
* mouse motion.
|
||||
*/
|
||||
public static final long MOUSE_MOTION_EVENT_MASK = 32;
|
||||
|
||||
/**
|
||||
* The Constant WINDOW_EVENT_MASK indicates the event relates to a window.
|
||||
*/
|
||||
public static final long WINDOW_EVENT_MASK = 64;
|
||||
|
||||
/**
|
||||
* The Constant ACTION_EVENT_MASK indicates the event relates to an action.
|
||||
*/
|
||||
public static final long ACTION_EVENT_MASK = 128;
|
||||
|
||||
/**
|
||||
* The Constant ADJUSTMENT_EVENT_MASK indicates the event relates to an
|
||||
* adjustment.
|
||||
*/
|
||||
public static final long ADJUSTMENT_EVENT_MASK = 256;
|
||||
|
||||
/**
|
||||
* The Constant ITEM_EVENT_MASK indicates the event relates to an item.
|
||||
*/
|
||||
public static final long ITEM_EVENT_MASK = 512;
|
||||
|
||||
/**
|
||||
* The Constant TEXT_EVENT_MASK indicates the event relates to text.
|
||||
*/
|
||||
public static final long TEXT_EVENT_MASK = 1024;
|
||||
|
||||
/**
|
||||
* The Constant INPUT_METHOD_EVENT_MASK indicates the event relates to an
|
||||
* input method.
|
||||
*/
|
||||
public static final long INPUT_METHOD_EVENT_MASK = 2048;
|
||||
|
||||
/**
|
||||
* The Constant PAINT_EVENT_MASK indicates the event relates to a paint
|
||||
* method.
|
||||
*/
|
||||
public static final long PAINT_EVENT_MASK = 8192;
|
||||
|
||||
/**
|
||||
* The Constant INVOCATION_EVENT_MASK indicates the event relates to a
|
||||
* method invocation.
|
||||
*/
|
||||
public static final long INVOCATION_EVENT_MASK = 16384;
|
||||
|
||||
/**
|
||||
* The Constant HIERARCHY_EVENT_MASK indicates the event relates to a
|
||||
* hierarchy.
|
||||
*/
|
||||
public static final long HIERARCHY_EVENT_MASK = 32768;
|
||||
|
||||
/**
|
||||
* The Constant HIERARCHY_BOUNDS_EVENT_MASK indicates the event relates to
|
||||
* hierarchy bounds.
|
||||
*/
|
||||
public static final long HIERARCHY_BOUNDS_EVENT_MASK = 65536;
|
||||
|
||||
/**
|
||||
* The Constant MOUSE_WHEEL_EVENT_MASK indicates the event relates to the
|
||||
* mouse wheel.
|
||||
*/
|
||||
public static final long MOUSE_WHEEL_EVENT_MASK = 131072;
|
||||
|
||||
/**
|
||||
* The Constant WINDOW_STATE_EVENT_MASK indicates the event relates to a
|
||||
* window state.
|
||||
*/
|
||||
public static final long WINDOW_STATE_EVENT_MASK = 262144;
|
||||
|
||||
/**
|
||||
* The Constant WINDOW_FOCUS_EVENT_MASK indicates the event relates to a
|
||||
* window focus.
|
||||
*/
|
||||
public static final long WINDOW_FOCUS_EVENT_MASK = 524288;
|
||||
|
||||
/**
|
||||
* The Constant RESERVED_ID_MAX indicates the maximum value for reserved AWT
|
||||
* event IDs.
|
||||
*/
|
||||
public static final int RESERVED_ID_MAX = 1999;
|
||||
|
||||
/**
|
||||
* The Constant eventsMap.
|
||||
*/
|
||||
private static final Hashtable<Integer, EventDescriptor> eventsMap = new Hashtable<Integer, EventDescriptor>();
|
||||
|
||||
/**
|
||||
* The converter.
|
||||
*/
|
||||
private static EventConverter converter;
|
||||
|
||||
/**
|
||||
* The ID of the event.
|
||||
*/
|
||||
protected int id;
|
||||
|
||||
/**
|
||||
* The consumed indicates whether or not the event is sent back down to the
|
||||
* peer once the source has processed it (false means it's sent to the peer,
|
||||
* true means it's not).
|
||||
*/
|
||||
protected boolean consumed;
|
||||
|
||||
/**
|
||||
* The dispatched by kfm.
|
||||
*/
|
||||
boolean dispatchedByKFM;
|
||||
|
||||
/**
|
||||
* The is posted.
|
||||
*/
|
||||
transient boolean isPosted;
|
||||
|
||||
static {
|
||||
eventsMap.put(new Integer(KeyEvent.KEY_TYPED), new EventDescriptor(KEY_EVENT_MASK,
|
||||
KeyListener.class));
|
||||
eventsMap.put(new Integer(KeyEvent.KEY_PRESSED), new EventDescriptor(KEY_EVENT_MASK,
|
||||
KeyListener.class));
|
||||
eventsMap.put(new Integer(KeyEvent.KEY_RELEASED), new EventDescriptor(KEY_EVENT_MASK,
|
||||
KeyListener.class));
|
||||
eventsMap.put(new Integer(MouseEvent.MOUSE_CLICKED), new EventDescriptor(MOUSE_EVENT_MASK,
|
||||
MouseListener.class));
|
||||
eventsMap.put(new Integer(MouseEvent.MOUSE_PRESSED), new EventDescriptor(MOUSE_EVENT_MASK,
|
||||
MouseListener.class));
|
||||
eventsMap.put(new Integer(MouseEvent.MOUSE_RELEASED), new EventDescriptor(MOUSE_EVENT_MASK,
|
||||
MouseListener.class));
|
||||
eventsMap.put(new Integer(MouseEvent.MOUSE_MOVED), new EventDescriptor(
|
||||
MOUSE_MOTION_EVENT_MASK, MouseMotionListener.class));
|
||||
eventsMap.put(new Integer(MouseEvent.MOUSE_ENTERED), new EventDescriptor(MOUSE_EVENT_MASK,
|
||||
MouseListener.class));
|
||||
eventsMap.put(new Integer(MouseEvent.MOUSE_EXITED), new EventDescriptor(MOUSE_EVENT_MASK,
|
||||
MouseListener.class));
|
||||
eventsMap.put(new Integer(MouseEvent.MOUSE_DRAGGED), new EventDescriptor(
|
||||
MOUSE_MOTION_EVENT_MASK, MouseMotionListener.class));
|
||||
eventsMap.put(new Integer(MouseEvent.MOUSE_WHEEL), new EventDescriptor(
|
||||
MOUSE_WHEEL_EVENT_MASK, MouseWheelListener.class));
|
||||
eventsMap.put(new Integer(ComponentEvent.COMPONENT_MOVED), new EventDescriptor(
|
||||
COMPONENT_EVENT_MASK, ComponentListener.class));
|
||||
eventsMap.put(new Integer(ComponentEvent.COMPONENT_RESIZED), new EventDescriptor(
|
||||
COMPONENT_EVENT_MASK, ComponentListener.class));
|
||||
eventsMap.put(new Integer(ComponentEvent.COMPONENT_SHOWN), new EventDescriptor(
|
||||
COMPONENT_EVENT_MASK, ComponentListener.class));
|
||||
eventsMap.put(new Integer(ComponentEvent.COMPONENT_HIDDEN), new EventDescriptor(
|
||||
COMPONENT_EVENT_MASK, ComponentListener.class));
|
||||
eventsMap.put(new Integer(FocusEvent.FOCUS_GAINED), new EventDescriptor(FOCUS_EVENT_MASK,
|
||||
FocusListener.class));
|
||||
eventsMap.put(new Integer(FocusEvent.FOCUS_LOST), new EventDescriptor(FOCUS_EVENT_MASK,
|
||||
FocusListener.class));
|
||||
eventsMap.put(new Integer(PaintEvent.PAINT), new EventDescriptor(PAINT_EVENT_MASK, null));
|
||||
eventsMap.put(new Integer(PaintEvent.UPDATE), new EventDescriptor(PAINT_EVENT_MASK, null));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_OPENED), new EventDescriptor(
|
||||
WINDOW_EVENT_MASK, WindowListener.class));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_CLOSING), new EventDescriptor(
|
||||
WINDOW_EVENT_MASK, WindowListener.class));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_CLOSED), new EventDescriptor(
|
||||
WINDOW_EVENT_MASK, WindowListener.class));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_DEICONIFIED), new EventDescriptor(
|
||||
WINDOW_EVENT_MASK, WindowListener.class));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_ICONIFIED), new EventDescriptor(
|
||||
WINDOW_EVENT_MASK, WindowListener.class));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_STATE_CHANGED), new EventDescriptor(
|
||||
WINDOW_STATE_EVENT_MASK, WindowStateListener.class));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_LOST_FOCUS), new EventDescriptor(
|
||||
WINDOW_FOCUS_EVENT_MASK, WindowFocusListener.class));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_GAINED_FOCUS), new EventDescriptor(
|
||||
WINDOW_FOCUS_EVENT_MASK, WindowFocusListener.class));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_DEACTIVATED), new EventDescriptor(
|
||||
WINDOW_EVENT_MASK, WindowListener.class));
|
||||
eventsMap.put(new Integer(WindowEvent.WINDOW_ACTIVATED), new EventDescriptor(
|
||||
WINDOW_EVENT_MASK, WindowListener.class));
|
||||
eventsMap.put(new Integer(HierarchyEvent.HIERARCHY_CHANGED), new EventDescriptor(
|
||||
HIERARCHY_EVENT_MASK, HierarchyListener.class));
|
||||
eventsMap.put(new Integer(HierarchyEvent.ANCESTOR_MOVED), new EventDescriptor(
|
||||
HIERARCHY_BOUNDS_EVENT_MASK, HierarchyBoundsListener.class));
|
||||
eventsMap.put(new Integer(HierarchyEvent.ANCESTOR_RESIZED), new EventDescriptor(
|
||||
HIERARCHY_BOUNDS_EVENT_MASK, HierarchyBoundsListener.class));
|
||||
eventsMap.put(new Integer(ContainerEvent.COMPONENT_ADDED), new EventDescriptor(
|
||||
CONTAINER_EVENT_MASK, ContainerListener.class));
|
||||
eventsMap.put(new Integer(ContainerEvent.COMPONENT_REMOVED), new EventDescriptor(
|
||||
CONTAINER_EVENT_MASK, ContainerListener.class));
|
||||
eventsMap.put(new Integer(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED), new EventDescriptor(
|
||||
INPUT_METHOD_EVENT_MASK, InputMethodListener.class));
|
||||
eventsMap.put(new Integer(InputMethodEvent.CARET_POSITION_CHANGED), new EventDescriptor(
|
||||
INPUT_METHOD_EVENT_MASK, InputMethodListener.class));
|
||||
eventsMap.put(new Integer(InvocationEvent.INVOCATION_DEFAULT), new EventDescriptor(
|
||||
INVOCATION_EVENT_MASK, null));
|
||||
eventsMap.put(new Integer(ItemEvent.ITEM_STATE_CHANGED), new EventDescriptor(
|
||||
ITEM_EVENT_MASK, ItemListener.class));
|
||||
eventsMap.put(new Integer(TextEvent.TEXT_VALUE_CHANGED), new EventDescriptor(
|
||||
TEXT_EVENT_MASK, TextListener.class));
|
||||
eventsMap.put(new Integer(ActionEvent.ACTION_PERFORMED), new EventDescriptor(
|
||||
ACTION_EVENT_MASK, ActionListener.class));
|
||||
eventsMap.put(new Integer(AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED), new EventDescriptor(
|
||||
ADJUSTMENT_EVENT_MASK, AdjustmentListener.class));
|
||||
converter = new EventConverter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new AWT event from the specified Event object.
|
||||
*
|
||||
* @param event
|
||||
* the Event object.
|
||||
*/
|
||||
public AWTEvent(Event event) {
|
||||
this(event.target, event.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new AWT event with the specified object and type.
|
||||
*
|
||||
* @param source
|
||||
* the source Object.
|
||||
* @param id
|
||||
* the event's type.
|
||||
*/
|
||||
public AWTEvent(Object source, int id) {
|
||||
super(source);
|
||||
this.id = id;
|
||||
consumed = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the event's type.
|
||||
*
|
||||
* @return the event type ID.
|
||||
*/
|
||||
public int getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new source for the AWTEvent.
|
||||
*
|
||||
* @param newSource
|
||||
* the new source Object for the AWTEvent.
|
||||
*/
|
||||
public void setSource(Object newSource) {
|
||||
source = newSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String representation of the AWTEvent.
|
||||
*
|
||||
* @return the String representation of the AWTEvent.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
/*
|
||||
* The format is based on 1.5 release behavior which can be revealed by
|
||||
* the following code: AWTEvent event = new AWTEvent(new Component(){},
|
||||
* 1){}; System.out.println(event);
|
||||
*/
|
||||
String name = ""; //$NON-NLS-1$
|
||||
|
||||
if (source instanceof Component && (source != null)) {
|
||||
Component comp = (Component)getSource();
|
||||
name = comp.getName();
|
||||
if (name == null) {
|
||||
name = ""; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
return (getClass().getName() + "[" + paramString() + "]" //$NON-NLS-1$ //$NON-NLS-2$
|
||||
+ " on " + (name.length() > 0 ? name : source)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the AWTEvent state.
|
||||
*
|
||||
* @return a string representation of the AWTEvent state.
|
||||
*/
|
||||
public String paramString() {
|
||||
// nothing to implement: all event types must override this method
|
||||
return ""; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not this AWTEvent has been consumed.
|
||||
*
|
||||
* @return true, if this AWTEvent has been consumed, false otherwise.
|
||||
*/
|
||||
protected boolean isConsumed() {
|
||||
return consumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes the AWTEvent.
|
||||
*/
|
||||
protected void consume() {
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert AWTEvent object to a corresponding (deprecated) Event object.
|
||||
*
|
||||
* @return new Event object which is a converted AWTEvent object or null if
|
||||
* the conversion is not possible
|
||||
*/
|
||||
Event getEvent() {
|
||||
|
||||
if (id == ActionEvent.ACTION_PERFORMED) {
|
||||
ActionEvent ae = (ActionEvent)this;
|
||||
return converter.convertActionEvent(ae);
|
||||
|
||||
} else if (id == AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED) {
|
||||
AdjustmentEvent ae = (AdjustmentEvent)this;
|
||||
return converter.convertAdjustmentEvent(ae);
|
||||
|
||||
// ???AWT
|
||||
// } else if (id == ComponentEvent.COMPONENT_MOVED
|
||||
// && source instanceof Window) {
|
||||
// //the only type of Component events is COMPONENT_MOVED on window
|
||||
// ComponentEvent ce = (ComponentEvent) this;
|
||||
// return converter.convertComponentEvent(ce);
|
||||
|
||||
} else if (id >= FocusEvent.FOCUS_FIRST && id <= FocusEvent.FOCUS_LAST) {
|
||||
// nothing to convert
|
||||
|
||||
// ???AWT
|
||||
// } else if (id == ItemEvent.ITEM_STATE_CHANGED) {
|
||||
// ItemEvent ie = (ItemEvent) this;
|
||||
// return converter.convertItemEvent(ie);
|
||||
|
||||
} else if (id == KeyEvent.KEY_PRESSED || id == KeyEvent.KEY_RELEASED) {
|
||||
KeyEvent ke = (KeyEvent)this;
|
||||
return converter.convertKeyEvent(ke);
|
||||
} else if (id >= MouseEvent.MOUSE_FIRST && id <= MouseEvent.MOUSE_LAST) {
|
||||
MouseEvent me = (MouseEvent)this;
|
||||
return converter.convertMouseEvent(me);
|
||||
} else if (id == WindowEvent.WINDOW_CLOSING || id == WindowEvent.WINDOW_ICONIFIED
|
||||
|| id == WindowEvent.WINDOW_DEICONIFIED) {
|
||||
// nothing to convert
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return new Event(source, id, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* The class EventDescriptor.
|
||||
*/
|
||||
static final class EventDescriptor {
|
||||
|
||||
/**
|
||||
* The event mask.
|
||||
*/
|
||||
final long eventMask;
|
||||
|
||||
/**
|
||||
* The listener type.
|
||||
*/
|
||||
final Class<? extends EventListener> listenerType;
|
||||
|
||||
/**
|
||||
* Instantiates a new event descriptor.
|
||||
*
|
||||
* @param eventMask
|
||||
* the event mask.
|
||||
* @param listenerType
|
||||
* the listener type.
|
||||
*/
|
||||
EventDescriptor(long eventMask, Class<? extends EventListener> listenerType) {
|
||||
this.eventMask = eventMask;
|
||||
this.listenerType = listenerType;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The class EventTypeLookup.
|
||||
*/
|
||||
static final class EventTypeLookup {
|
||||
|
||||
/**
|
||||
* The last event.
|
||||
*/
|
||||
private AWTEvent lastEvent = null;
|
||||
|
||||
/**
|
||||
* The last event descriptor.
|
||||
*/
|
||||
private EventDescriptor lastEventDescriptor = null;
|
||||
|
||||
/**
|
||||
* Gets the event descriptor.
|
||||
*
|
||||
* @param event
|
||||
* the event.
|
||||
* @return the event descriptor.
|
||||
*/
|
||||
EventDescriptor getEventDescriptor(AWTEvent event) {
|
||||
synchronized (this) {
|
||||
if (event != lastEvent) {
|
||||
lastEvent = event;
|
||||
lastEventDescriptor = eventsMap.get(new Integer(event.id));
|
||||
}
|
||||
|
||||
return lastEventDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the event mask.
|
||||
*
|
||||
* @param event
|
||||
* the event.
|
||||
* @return the event mask.
|
||||
*/
|
||||
long getEventMask(AWTEvent event) {
|
||||
final EventDescriptor ed = getEventDescriptor(event);
|
||||
return ed == null ? -1 : ed.eventMask;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The class EventConverter.
|
||||
*/
|
||||
static final class EventConverter {
|
||||
|
||||
/**
|
||||
* The constant OLD_MOD_MASK.
|
||||
*/
|
||||
static final int OLD_MOD_MASK = Event.ALT_MASK | Event.CTRL_MASK | Event.META_MASK
|
||||
| Event.SHIFT_MASK;
|
||||
|
||||
/**
|
||||
* Convert action event.
|
||||
*
|
||||
* @param ae
|
||||
* the ae.
|
||||
* @return the event.
|
||||
*/
|
||||
Event convertActionEvent(ActionEvent ae) {
|
||||
Event evt = new Event(ae.getSource(), ae.getID(), ae.getActionCommand());
|
||||
evt.when = ae.getWhen();
|
||||
evt.modifiers = ae.getModifiers() & OLD_MOD_MASK;
|
||||
|
||||
/*
|
||||
* if (source instanceof Button) { arg = ((Button)
|
||||
* source).getLabel(); } else if (source instanceof Checkbox) { arg
|
||||
* = new Boolean(((Checkbox) source).getState()); } else if (source
|
||||
* instanceof CheckboxMenuItem) { arg = ((CheckboxMenuItem)
|
||||
* source).getLabel(); } else if (source instanceof Choice) { arg =
|
||||
* ((Choice) source).getSelectedItem(); } else if (source instanceof
|
||||
* List) { arg = ((List) source).getSelectedItem(); } else if
|
||||
* (source instanceof MenuItem) { arg = ((MenuItem)
|
||||
* source).getLabel(); } else if (source instanceof TextField) { arg
|
||||
* = ((TextField) source).getText(); }
|
||||
*/
|
||||
return evt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert adjustment event.
|
||||
*
|
||||
* @param ae
|
||||
* the ae.
|
||||
* @return the event.
|
||||
*/
|
||||
Event convertAdjustmentEvent(AdjustmentEvent ae) {
|
||||
// TODO: Event.SCROLL_BEGIN/SCROLL_END
|
||||
return new Event(ae.source, ae.id + ae.getAdjustmentType() - 1, new Integer(ae
|
||||
.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert component event.
|
||||
*
|
||||
* @param ce
|
||||
* the ce.
|
||||
* @return the event.
|
||||
*/
|
||||
Event convertComponentEvent(ComponentEvent ce) {
|
||||
Component comp = ce.getComponent();
|
||||
Event evt = new Event(comp, Event.WINDOW_MOVED, null);
|
||||
evt.x = comp.getX();
|
||||
evt.y = comp.getY();
|
||||
return evt;
|
||||
}
|
||||
|
||||
// ???AWT
|
||||
/*
|
||||
* Event convertItemEvent(ItemEvent ie) { int oldId = ie.id +
|
||||
* ie.getStateChange() - 1; Object source = ie.source; int idx = -1; if
|
||||
* (source instanceof List) { List list = (List) source; idx =
|
||||
* list.getSelectedIndex(); } else if (source instanceof Choice) {
|
||||
* Choice choice = (Choice) source; idx = choice.getSelectedIndex(); }
|
||||
* Object arg = idx >= 0 ? new Integer(idx) : null; return new
|
||||
* Event(source, oldId, arg); }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Convert key event.
|
||||
*
|
||||
* @param ke
|
||||
* the ke.
|
||||
* @return the event.
|
||||
*/
|
||||
Event convertKeyEvent(KeyEvent ke) {
|
||||
int oldId = ke.id;
|
||||
// leave only old Event's modifiers
|
||||
|
||||
int mod = ke.getModifiers() & OLD_MOD_MASK;
|
||||
Component comp = ke.getComponent();
|
||||
char keyChar = ke.getKeyChar();
|
||||
int keyCode = ke.getKeyCode();
|
||||
int key = convertKey(keyChar, keyCode);
|
||||
if (key >= Event.HOME && key <= Event.INSERT) {
|
||||
oldId += 2; // non-ASCII key -> action key
|
||||
}
|
||||
return new Event(comp, ke.getWhen(), oldId, 0, 0, key, mod);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert mouse event.
|
||||
*
|
||||
* @param me
|
||||
* the me.
|
||||
* @return the event.
|
||||
*/
|
||||
Event convertMouseEvent(MouseEvent me) {
|
||||
int id = me.id;
|
||||
if (id != MouseEvent.MOUSE_CLICKED) {
|
||||
Event evt = new Event(me.source, id, null);
|
||||
evt.x = me.getX();
|
||||
evt.y = me.getY();
|
||||
int mod = me.getModifiers();
|
||||
// in Event modifiers mean button number for mouse events:
|
||||
evt.modifiers = mod & (Event.ALT_MASK | Event.META_MASK);
|
||||
if (id == MouseEvent.MOUSE_PRESSED) {
|
||||
evt.clickCount = me.getClickCount();
|
||||
}
|
||||
return evt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert key.
|
||||
*
|
||||
* @param keyChar
|
||||
* the key char.
|
||||
* @param keyCode
|
||||
* the key code.
|
||||
* @return the int.
|
||||
*/
|
||||
int convertKey(char keyChar, int keyCode) {
|
||||
int key;
|
||||
// F1 - F12
|
||||
if (keyCode >= KeyEvent.VK_F1 && keyCode <= KeyEvent.VK_F12) {
|
||||
key = Event.F1 + keyCode - KeyEvent.VK_F1;
|
||||
} else {
|
||||
switch (keyCode) {
|
||||
default: // non-action key
|
||||
key = keyChar;
|
||||
break;
|
||||
// action keys:
|
||||
case KeyEvent.VK_HOME:
|
||||
key = Event.HOME;
|
||||
break;
|
||||
case KeyEvent.VK_END:
|
||||
key = Event.END;
|
||||
break;
|
||||
case KeyEvent.VK_PAGE_UP:
|
||||
key = Event.PGUP;
|
||||
break;
|
||||
case KeyEvent.VK_PAGE_DOWN:
|
||||
key = Event.PGDN;
|
||||
break;
|
||||
case KeyEvent.VK_UP:
|
||||
key = Event.UP;
|
||||
break;
|
||||
case KeyEvent.VK_DOWN:
|
||||
key = Event.DOWN;
|
||||
break;
|
||||
case KeyEvent.VK_LEFT:
|
||||
key = Event.LEFT;
|
||||
break;
|
||||
case KeyEvent.VK_RIGHT:
|
||||
key = Event.RIGHT;
|
||||
break;
|
||||
case KeyEvent.VK_PRINTSCREEN:
|
||||
key = Event.PRINT_SCREEN;
|
||||
break;
|
||||
case KeyEvent.VK_SCROLL_LOCK:
|
||||
key = Event.SCROLL_LOCK;
|
||||
break;
|
||||
case KeyEvent.VK_CAPS_LOCK:
|
||||
key = Event.CAPS_LOCK;
|
||||
break;
|
||||
case KeyEvent.VK_NUM_LOCK:
|
||||
key = Event.NUM_LOCK;
|
||||
break;
|
||||
case KeyEvent.VK_PAUSE:
|
||||
key = Event.PAUSE;
|
||||
break;
|
||||
case KeyEvent.VK_INSERT:
|
||||
key = Event.INSERT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The AWTException class is used to provide notification and information about
|
||||
* AWT errors.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class AWTException extends Exception {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -1900414231151323879L;
|
||||
|
||||
/**
|
||||
* Instantiates a new AWT exception with the specified message.
|
||||
*
|
||||
* @param msg
|
||||
* the specific message for current exception.
|
||||
*/
|
||||
public AWTException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,712 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Dmitry A. Durnev
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The AWTKeyStroke holds all of the information for the complete act of
|
||||
* typing a character. This includes the events that are generated when
|
||||
* the key is pressed, released, or typed (pressed and released generating
|
||||
* a Unicode character result) which are associated with the event
|
||||
* objects KeyEvent.KEY_PRESSED, KeyEvent.KEY_RELEASED, or KeyEvent.KEY_TYPED.
|
||||
* It also holds information about which modifiers (such as control or
|
||||
* shift) were used in conjunction with the keystroke. The following masks
|
||||
* are available to identify the modifiers:
|
||||
* <ul>
|
||||
* <li>java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK</li>
|
||||
* <li>java.awt.event.InputEvent.ALT_DOWN_MASK</li>
|
||||
* <li>java.awt.event.InputEvent.CTRL_DOWN_MASK</li>
|
||||
* <li>java.awt.event.InputEvent.META_DOWN_MASK</li>
|
||||
* <li>java.awt.event.InputEvent.SHIFT_DOWN_MASK</li>
|
||||
* <li>java.awt.event.InputEvent.ALT_GRAPH_MASK</li>
|
||||
* <li>java.awt.event.InputEvent.ALT_MASK</li>
|
||||
* <li>java.awt.event.InputEvent.CTRL_MASK</li>
|
||||
* <li>java.awt.event.InputEvent.META_MASK</li>
|
||||
* <li>java.awt.event.InputEvent.SHIFT_MASK</li>
|
||||
* </ul>
|
||||
* <br>
|
||||
* The AWTKeyStroke is unique, and applications should not create their own
|
||||
* instances of AWTKeyStroke. All applications should use getAWTKeyStroke
|
||||
* methods for obtaining instances of AWTKeyStroke.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class AWTKeyStroke implements Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -6430539691155161871L;
|
||||
|
||||
/**
|
||||
* The Constant cache.
|
||||
*/
|
||||
private static final Map<AWTKeyStroke, AWTKeyStroke> cache = new HashMap<AWTKeyStroke, AWTKeyStroke>(); // Map
|
||||
|
||||
// <
|
||||
// AWTKeyStroke
|
||||
// ,
|
||||
// ?
|
||||
// extends
|
||||
// AWTKeyStroke
|
||||
// >
|
||||
|
||||
/**
|
||||
* The Constant keyEventTypesMap.
|
||||
*/
|
||||
private static final Map<Integer, String> keyEventTypesMap = new HashMap<Integer, String>(); // Map
|
||||
|
||||
// <
|
||||
// int
|
||||
// ,
|
||||
// String
|
||||
// >
|
||||
|
||||
private static Constructor<?> subConstructor;
|
||||
|
||||
static {
|
||||
keyEventTypesMap.put(new Integer(KeyEvent.KEY_PRESSED), "pressed"); //$NON-NLS-1$
|
||||
keyEventTypesMap.put(new Integer(KeyEvent.KEY_RELEASED), "released"); //$NON-NLS-1$
|
||||
keyEventTypesMap.put(new Integer(KeyEvent.KEY_TYPED), "typed"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* The key char.
|
||||
*/
|
||||
private char keyChar;
|
||||
|
||||
/**
|
||||
* The key code.
|
||||
*/
|
||||
private int keyCode;
|
||||
|
||||
/**
|
||||
* The modifiers.
|
||||
*/
|
||||
private int modifiers;
|
||||
|
||||
/**
|
||||
* The on key release.
|
||||
*/
|
||||
private boolean onKeyRelease;
|
||||
|
||||
/**
|
||||
* Instantiates a new AWTKeyStroke. getAWTKeyStroke method should be used by
|
||||
* applications code.
|
||||
*
|
||||
* @param keyChar
|
||||
* the key char.
|
||||
* @param keyCode
|
||||
* the key code.
|
||||
* @param modifiers
|
||||
* the modifiers.
|
||||
* @param onKeyRelease
|
||||
* true if AWTKeyStroke is for a key release, false otherwise.
|
||||
*/
|
||||
protected AWTKeyStroke(char keyChar, int keyCode, int modifiers, boolean onKeyRelease) {
|
||||
setAWTKeyStroke(keyChar, keyCode, modifiers, onKeyRelease);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the AWT key stroke.
|
||||
*
|
||||
* @param keyChar
|
||||
* the key char.
|
||||
* @param keyCode
|
||||
* the key code.
|
||||
* @param modifiers
|
||||
* the modifiers.
|
||||
* @param onKeyRelease
|
||||
* the on key release.
|
||||
*/
|
||||
private void setAWTKeyStroke(char keyChar, int keyCode, int modifiers, boolean onKeyRelease) {
|
||||
this.keyChar = keyChar;
|
||||
this.keyCode = keyCode;
|
||||
this.modifiers = modifiers;
|
||||
this.onKeyRelease = onKeyRelease;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new AWTKeyStroke with default parameters:
|
||||
* KeyEvent.CHAR_UNDEFINED key char, KeyEvent.VK_UNDEFINED key code, without
|
||||
* modifiers and false key realized value.
|
||||
*/
|
||||
protected AWTKeyStroke() {
|
||||
this(KeyEvent.CHAR_UNDEFINED, KeyEvent.VK_UNDEFINED, 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique number value for AWTKeyStroke object.
|
||||
*
|
||||
* @return the integer unique value of the AWTKeyStroke object.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return modifiers + (keyCode != KeyEvent.VK_UNDEFINED ? keyCode : keyChar)
|
||||
+ (onKeyRelease ? -1 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the set of modifiers for the AWTKeyStroke object.
|
||||
*
|
||||
* @return the integer value which contains modifiers.
|
||||
*/
|
||||
public final int getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this AWTKeyStroke object to the specified object.
|
||||
*
|
||||
* @param anObject
|
||||
* the specified AWTKeyStroke object to compare with this
|
||||
* instance.
|
||||
* @return true if objects are identical, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public final boolean equals(Object anObject) {
|
||||
if (anObject instanceof AWTKeyStroke) {
|
||||
AWTKeyStroke key = (AWTKeyStroke)anObject;
|
||||
return ((key.keyCode == keyCode) && (key.keyChar == keyChar)
|
||||
&& (key.modifiers == modifiers) && (key.onKeyRelease == onKeyRelease));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of the AWTKeyStroke. This string should
|
||||
* contain key stroke properties.
|
||||
*
|
||||
* @return the string representation of the AWTKeyStroke.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
int type = getKeyEventType();
|
||||
return InputEvent.getModifiersExText(getModifiers()) + " " + //$NON-NLS-1$
|
||||
keyEventTypesMap.get(new Integer(type)) + " " + //$NON-NLS-1$
|
||||
(type == KeyEvent.KEY_TYPED ? new String(new char[] {
|
||||
keyChar
|
||||
}) : KeyEvent.getKeyText(keyCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key code for the AWTKeyStroke object.
|
||||
*
|
||||
* @return the key code for the AWTKeyStroke object.
|
||||
*/
|
||||
public final int getKeyCode() {
|
||||
return keyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key character for the AWTKeyStroke object.
|
||||
*
|
||||
* @return the key character for the AWTKeyStroke object.
|
||||
*/
|
||||
public final char getKeyChar() {
|
||||
return keyChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AWT key stroke.
|
||||
*
|
||||
* @param keyChar
|
||||
* the key char.
|
||||
* @param keyCode
|
||||
* the key code.
|
||||
* @param modifiers
|
||||
* the modifiers.
|
||||
* @param onKeyRelease
|
||||
* the on key release.
|
||||
* @return the AWT key stroke.
|
||||
*/
|
||||
private static AWTKeyStroke getAWTKeyStroke(char keyChar, int keyCode, int modifiers,
|
||||
boolean onKeyRelease) {
|
||||
AWTKeyStroke key = newInstance(keyChar, keyCode, modifiers, onKeyRelease);
|
||||
|
||||
AWTKeyStroke value = cache.get(key);
|
||||
if (value == null) {
|
||||
value = key;
|
||||
cache.put(key, value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* New instance.
|
||||
*
|
||||
* @param keyChar
|
||||
* the key char.
|
||||
* @param keyCode
|
||||
* the key code.
|
||||
* @param modifiers
|
||||
* the modifiers.
|
||||
* @param onKeyRelease
|
||||
* the on key release.
|
||||
* @return the AWT key stroke.
|
||||
*/
|
||||
private static AWTKeyStroke newInstance(char keyChar, int keyCode, int modifiers,
|
||||
boolean onKeyRelease) {
|
||||
AWTKeyStroke key;
|
||||
// ???AWT
|
||||
// if (subConstructor == null) {
|
||||
key = new AWTKeyStroke();
|
||||
// ???AWT
|
||||
// } else {
|
||||
// try {
|
||||
// key = (AWTKeyStroke) subConstructor.newInstance();
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
int allModifiers = getAllModifiers(modifiers);
|
||||
key.setAWTKeyStroke(keyChar, keyCode, allModifiers, onKeyRelease);
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the mask.
|
||||
*
|
||||
* @param mod
|
||||
* the mod.
|
||||
* @param mask
|
||||
* the mask.
|
||||
* @return the int.
|
||||
*/
|
||||
private static int addMask(int mod, int mask) {
|
||||
return ((mod & mask) != 0) ? (mod | mask) : mod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all (old & new) modifiers corresponding to.
|
||||
*
|
||||
* @param mod
|
||||
* old or new modifiers.
|
||||
* @return old and new modifiers together.
|
||||
*/
|
||||
static int getAllModifiers(int mod) {
|
||||
int allMod = mod;
|
||||
int shift = (InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK);
|
||||
int ctrl = (InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK);
|
||||
int meta = (InputEvent.META_MASK | InputEvent.META_DOWN_MASK);
|
||||
int alt = (InputEvent.ALT_MASK | InputEvent.ALT_DOWN_MASK);
|
||||
int altGr = (InputEvent.ALT_GRAPH_MASK | InputEvent.ALT_GRAPH_DOWN_MASK);
|
||||
// button modifiers are not converted between old & new
|
||||
|
||||
allMod = addMask(allMod, shift);
|
||||
allMod = addMask(allMod, ctrl);
|
||||
allMod = addMask(allMod, meta);
|
||||
allMod = addMask(allMod, alt);
|
||||
allMod = addMask(allMod, altGr);
|
||||
|
||||
return allMod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of AWTKeyStroke for parsed string. The string must
|
||||
* have the following syntax:
|
||||
*<p>
|
||||
* <modifiers>* (<typedID> | <pressedReleasedID>)
|
||||
*<p>
|
||||
* modifiers := shift | control | ctrl | meta | alt | altGraph <br>
|
||||
* typedID := typed <typedKey> <br>
|
||||
* typedKey := string of length 1 giving the Unicode character. <br>
|
||||
* pressedReleasedID := (pressed | released) <key> <br>
|
||||
* key := KeyEvent key code name, i.e. the name following "VK_".
|
||||
* <p>
|
||||
*
|
||||
* @param s
|
||||
* the String which contains key stroke parameters.
|
||||
* @return the AWTKeyStroke for string.
|
||||
* @throws IllegalArgumentException
|
||||
* if string has incorrect format or null.
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(String s) {
|
||||
if (s == null) {
|
||||
// awt.65=null argument
|
||||
throw new IllegalArgumentException(Messages.getString("awt.65")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
StringTokenizer tokenizer = new StringTokenizer(s);
|
||||
|
||||
Boolean release = null;
|
||||
int modifiers = 0;
|
||||
int keyCode = KeyEvent.VK_UNDEFINED;
|
||||
char keyChar = KeyEvent.CHAR_UNDEFINED;
|
||||
boolean typed = false;
|
||||
long modifier = 0;
|
||||
String token = null;
|
||||
do {
|
||||
token = getNextToken(tokenizer);
|
||||
modifier = parseModifier(token);
|
||||
modifiers |= modifier;
|
||||
} while (modifier > 0);
|
||||
|
||||
typed = parseTypedID(token);
|
||||
|
||||
if (typed) {
|
||||
token = getNextToken(tokenizer);
|
||||
keyChar = parseTypedKey(token);
|
||||
|
||||
}
|
||||
if (keyChar == KeyEvent.CHAR_UNDEFINED) {
|
||||
release = parsePressedReleasedID(token);
|
||||
if (release != null) {
|
||||
token = getNextToken(tokenizer);
|
||||
}
|
||||
keyCode = parseKey(token);
|
||||
}
|
||||
if (tokenizer.hasMoreTokens()) {
|
||||
// awt.66=Invalid format
|
||||
throw new IllegalArgumentException(Messages.getString("awt.66")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return getAWTKeyStroke(keyChar, keyCode, modifiers, release == Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next token.
|
||||
*
|
||||
* @param tokenizer
|
||||
* the tokenizer.
|
||||
* @return the next token.
|
||||
*/
|
||||
private static String getNextToken(StringTokenizer tokenizer) {
|
||||
try {
|
||||
return tokenizer.nextToken();
|
||||
} catch (NoSuchElementException exception) {
|
||||
// awt.66=Invalid format
|
||||
throw new IllegalArgumentException(Messages.getString("awt.66")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key code.
|
||||
*
|
||||
* @param s
|
||||
* the s.
|
||||
* @return the key code.
|
||||
*/
|
||||
static int getKeyCode(String s) {
|
||||
try {
|
||||
Field vk = KeyEvent.class.getField("VK_" + s); //$NON-NLS-1$
|
||||
return vk.getInt(null);
|
||||
} catch (Exception e) {
|
||||
if (s.length() != 1) {
|
||||
// awt.66=Invalid format
|
||||
throw new IllegalArgumentException(Messages.getString("awt.66")); //$NON-NLS-1$
|
||||
}
|
||||
return KeyEvent.VK_UNDEFINED;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an instance of the AWTKeyStroke for specified character.
|
||||
*
|
||||
* @param keyChar
|
||||
* the keyboard character value.
|
||||
* @return a AWTKeyStroke for specified character.
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(char keyChar) {
|
||||
return getAWTKeyStroke(keyChar, KeyEvent.VK_UNDEFINED, 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of AWTKeyStroke for a given key code, set of
|
||||
* modifiers, and specified key released flag value. The key codes are
|
||||
* defined in java.awt.event.KeyEvent class. The set of modifiers is given
|
||||
* as a bitwise combination of masks taken from the following list:
|
||||
* <ul>
|
||||
* <li>java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.ALT_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.CTRL_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.META_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.SHIFT_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.ALT_GRAPH_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.ALT_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.CTRL_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.META_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.SHIFT_MASK</li>
|
||||
* </ul>
|
||||
* <br>
|
||||
*
|
||||
* @param keyCode
|
||||
* the specified key code of keyboard.
|
||||
* @param modifiers
|
||||
* the bit set of modifiers.
|
||||
* @param onKeyRelease
|
||||
* the value which represents whether this AWTKeyStroke shall
|
||||
* represents a key release.
|
||||
* @return the AWTKeyStroke.
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(int keyCode, int modifiers, boolean onKeyRelease) {
|
||||
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, keyCode, modifiers, onKeyRelease);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns AWTKeyStroke for a specified character and set of modifiers. The
|
||||
* set of modifiers is given as a bitwise combination of masks taken from
|
||||
* the following list:
|
||||
* <ul>
|
||||
* <li>java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.ALT_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.CTRL_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.META_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.SHIFT_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.ALT_GRAPH_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.ALT_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.CTRL_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.META_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.SHIFT_MASK</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param keyChar
|
||||
* the Character object which represents keyboard character
|
||||
* value.
|
||||
* @param modifiers
|
||||
* the bit set of modifiers.
|
||||
* @return the AWTKeyStroke object.
|
||||
* @throws IllegalArgumentException
|
||||
* if keyChar value is null.
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(Character keyChar, int modifiers) {
|
||||
if (keyChar == null) {
|
||||
// awt.01='{0}' parameter is null
|
||||
throw new IllegalArgumentException(Messages.getString("awt.01", "keyChar")); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
return getAWTKeyStroke(keyChar.charValue(), KeyEvent.VK_UNDEFINED, modifiers, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of AWTKeyStroke for a specified key code and set of
|
||||
* modifiers. The key codes are defined in java.awt.event.KeyEvent class.
|
||||
* The set of modifiers is given as a bitwise combination of masks taken
|
||||
* from the following list:
|
||||
* <ul>
|
||||
* <li>java.awt.event.InputEvent.ALT_GRAPH_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.ALT_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.CTRL_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.META_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.SHIFT_DOWN_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.ALT_GRAPH_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.ALT_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.CTRL_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.META_MASK</li> <li>
|
||||
* java.awt.event.InputEvent.SHIFT_MASK</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param keyCode
|
||||
* the specified key code of keyboard.
|
||||
* @param modifiers
|
||||
* the bit set of modifiers.
|
||||
* @return the AWTKeyStroke.
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(int keyCode, int modifiers) {
|
||||
return getAWTKeyStroke(keyCode, modifiers, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AWTKeyStroke for a key event. This method obtains the key char
|
||||
* and key code from the specified key event.
|
||||
*
|
||||
* @param anEvent
|
||||
* the key event which identifies the desired AWTKeyStroke.
|
||||
* @return the AWTKeyStroke for the key event.
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {
|
||||
int id = anEvent.getID();
|
||||
char undef = KeyEvent.CHAR_UNDEFINED;
|
||||
char keyChar = (id == KeyEvent.KEY_TYPED ? anEvent.getKeyChar() : undef);
|
||||
int keyCode = (keyChar == undef ? anEvent.getKeyCode() : KeyEvent.VK_UNDEFINED);
|
||||
return getAWTKeyStroke(keyChar, keyCode, anEvent.getModifiersEx(),
|
||||
id == KeyEvent.KEY_RELEASED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key event type for the AWTKeyStroke object.
|
||||
*
|
||||
* @return the key event type: KeyEvent.KEY_PRESSED, KeyEvent.KEY_TYPED, or
|
||||
* KeyEvent.KEY_RELEASED.
|
||||
*/
|
||||
public final int getKeyEventType() {
|
||||
if (keyCode == KeyEvent.VK_UNDEFINED) {
|
||||
return KeyEvent.KEY_TYPED;
|
||||
}
|
||||
return (onKeyRelease ? KeyEvent.KEY_RELEASED : KeyEvent.KEY_PRESSED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the key event is associated with the AWTKeyStroke is
|
||||
* KEY_RELEASED, false otherwise.
|
||||
*
|
||||
* @return true, if if the key event associated with the AWTKeyStroke is
|
||||
* KEY_RELEASED, false otherwise.
|
||||
*/
|
||||
public final boolean isOnKeyRelease() {
|
||||
return onKeyRelease;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read resolve.
|
||||
*
|
||||
* @return the object.
|
||||
* @throws ObjectStreamException
|
||||
* the object stream exception.
|
||||
*/
|
||||
protected Object readResolve() throws ObjectStreamException {
|
||||
return getAWTKeyStroke(this.keyChar, this.keyCode, this.modifiers, this.onKeyRelease);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register subclass.
|
||||
*
|
||||
* @param subclass
|
||||
* the subclass.
|
||||
*/
|
||||
protected static void registerSubclass(Class<?> subclass) {
|
||||
// ???AWT
|
||||
/*
|
||||
* if (subclass == null) { // awt.01='{0}' parameter is null throw new
|
||||
* IllegalArgumentException(Messages.getString("awt.01", "subclass"));
|
||||
* //$NON-NLS-1$ //$NON-NLS-2$ } if (!
|
||||
* AWTKeyStroke.class.isAssignableFrom(subclass)) { // awt.67=subclass
|
||||
* is not derived from AWTKeyStroke throw new
|
||||
* ClassCastException(Messages.getString("awt.67")); //$NON-NLS-1$ } try
|
||||
* { subConstructor = subclass.getDeclaredConstructor();
|
||||
* subConstructor.setAccessible(true); } catch (SecurityException e) {
|
||||
* throw new RuntimeException(e); } catch (NoSuchMethodException e) { //
|
||||
* awt.68=subclass could not be instantiated throw new
|
||||
* IllegalArgumentException(Messages.getString("awt.68")); //$NON-NLS-1$
|
||||
* } cache.clear(); //flush the cache
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the modifier.
|
||||
*
|
||||
* @param strMod
|
||||
* the str mod.
|
||||
* @return the long.
|
||||
*/
|
||||
private static long parseModifier(String strMod) {
|
||||
long modifiers = 0l;
|
||||
if (strMod.equals("shift")) { //$NON-NLS-1$
|
||||
modifiers |= InputEvent.SHIFT_DOWN_MASK;
|
||||
} else if (strMod.equals("control") || strMod.equals("ctrl")) { //$NON-NLS-1$ //$NON-NLS-2$
|
||||
modifiers |= InputEvent.CTRL_DOWN_MASK;
|
||||
} else if (strMod.equals("meta")) { //$NON-NLS-1$
|
||||
modifiers |= InputEvent.META_DOWN_MASK;
|
||||
} else if (strMod.equals("alt")) { //$NON-NLS-1$
|
||||
modifiers |= InputEvent.ALT_DOWN_MASK;
|
||||
} else if (strMod.equals("altGraph")) { //$NON-NLS-1$
|
||||
modifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
|
||||
} else if (strMod.equals("button1")) { //$NON-NLS-1$
|
||||
modifiers |= InputEvent.BUTTON1_DOWN_MASK;
|
||||
} else if (strMod.equals("button2")) { //$NON-NLS-1$
|
||||
modifiers |= InputEvent.BUTTON2_DOWN_MASK;
|
||||
} else if (strMod.equals("button3")) { //$NON-NLS-1$
|
||||
modifiers |= InputEvent.BUTTON3_DOWN_MASK;
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the typed id.
|
||||
*
|
||||
* @param strTyped
|
||||
* the str typed.
|
||||
* @return true, if successful.
|
||||
*/
|
||||
private static boolean parseTypedID(String strTyped) {
|
||||
if (strTyped.equals("typed")) { //$NON-NLS-1$
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the typed key.
|
||||
*
|
||||
* @param strChar
|
||||
* the str char.
|
||||
* @return the char.
|
||||
*/
|
||||
private static char parseTypedKey(String strChar) {
|
||||
char keyChar = KeyEvent.CHAR_UNDEFINED;
|
||||
|
||||
if (strChar.length() != 1) {
|
||||
// awt.66=Invalid format
|
||||
throw new IllegalArgumentException(Messages.getString("awt.66")); //$NON-NLS-1$
|
||||
}
|
||||
keyChar = strChar.charAt(0);
|
||||
return keyChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the pressed released id.
|
||||
*
|
||||
* @param str
|
||||
* the str.
|
||||
* @return the boolean.
|
||||
*/
|
||||
private static Boolean parsePressedReleasedID(String str) {
|
||||
|
||||
if (str.equals("pressed")) { //$NON-NLS-1$
|
||||
return Boolean.FALSE;
|
||||
} else if (str.equals("released")) { //$NON-NLS-1$
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the key.
|
||||
*
|
||||
* @param strCode
|
||||
* the str code.
|
||||
* @return the int.
|
||||
*/
|
||||
private static int parseKey(String strCode) {
|
||||
int keyCode = KeyEvent.VK_UNDEFINED;
|
||||
|
||||
keyCode = getKeyCode(strCode);
|
||||
|
||||
if (keyCode == KeyEvent.VK_UNDEFINED) {
|
||||
// awt.66=Invalid format
|
||||
throw new IllegalArgumentException(Messages.getString("awt.66")); //$NON-NLS-1$
|
||||
}
|
||||
return keyCode;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
import org.apache.harmony.awt.ListenerList;
|
||||
|
||||
final class AWTListenerList<T extends EventListener> extends ListenerList<T> {
|
||||
private static final long serialVersionUID = -2622077171532840953L;
|
||||
|
||||
private final Component owner;
|
||||
|
||||
AWTListenerList() {
|
||||
super();
|
||||
this.owner = null;
|
||||
}
|
||||
|
||||
AWTListenerList(Component owner) {
|
||||
super();
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addUserListener(T listener) {
|
||||
super.addUserListener(listener);
|
||||
|
||||
if (owner != null) {
|
||||
owner.deprecatedEventHandler = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Pavel Dolgov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.security.BasicPermission;
|
||||
|
||||
/**
|
||||
* The AWTPermission specifies the name of the permission and the corresponding
|
||||
* action list.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public final class AWTPermission extends BasicPermission {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 8890392402588814465L;
|
||||
|
||||
/**
|
||||
* Instantiates a new AWTPermission with defined name and actions.
|
||||
*
|
||||
* @param name
|
||||
* the name of a new AWTPermission.
|
||||
* @param actions
|
||||
* the actions of a new AWTPermission.
|
||||
*/
|
||||
public AWTPermission(String name, String actions) {
|
||||
super(name, actions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new AWT permission with the defined name.
|
||||
*
|
||||
* @param name
|
||||
* the name of a new AWTPermission.
|
||||
*/
|
||||
public AWTPermission(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This interface defines events that know how to dispatch themselves. Such
|
||||
* event can be placed upon the event queue and its dispatch method will be
|
||||
* called when the event is dispatched.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface ActiveEvent {
|
||||
|
||||
/**
|
||||
* Dispatches the event to the listeners of the event's source, or does
|
||||
* whatever it is this event is supposed to do.
|
||||
*/
|
||||
public void dispatch();
|
||||
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Pavel Dolgov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.AdjustmentListener;
|
||||
|
||||
/**
|
||||
* The Adjustable interface represents an adjustable numeric value contained
|
||||
* within a bounded range of values, such as the current location in scrollable
|
||||
* region or the value of a gauge.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface Adjustable {
|
||||
|
||||
/**
|
||||
* The Constant HORIZONTAL indicates that the Adjustable's orientation is
|
||||
* horizontal.
|
||||
*/
|
||||
public static final int HORIZONTAL = 0;
|
||||
|
||||
/**
|
||||
* The Constant VERTICAL indicates that the Adjustable's orientation is
|
||||
* vertical.
|
||||
*/
|
||||
public static final int VERTICAL = 1;
|
||||
|
||||
/**
|
||||
* The Constant NO_ORIENTATION indicates that the Adjustable has no
|
||||
* orientation.
|
||||
*/
|
||||
public static final int NO_ORIENTATION = 2;
|
||||
|
||||
/**
|
||||
* Gets the value of the Adjustable.
|
||||
*
|
||||
* @return the current value of the Adjustable.
|
||||
*/
|
||||
public int getValue();
|
||||
|
||||
/**
|
||||
* Sets the value to the Adjustable object.
|
||||
*
|
||||
* @param a0
|
||||
* the new value of the Adjustable object.
|
||||
*/
|
||||
public void setValue(int a0);
|
||||
|
||||
/**
|
||||
* Adds the AdjustmentListener to current Adjustment.
|
||||
*
|
||||
* @param a0
|
||||
* the AdjustmentListener object.
|
||||
*/
|
||||
public void addAdjustmentListener(AdjustmentListener a0);
|
||||
|
||||
/**
|
||||
* Gets the block increment of the Adjustable.
|
||||
*
|
||||
* @return the block increment of the Adjustable.
|
||||
*/
|
||||
public int getBlockIncrement();
|
||||
|
||||
/**
|
||||
* Gets the maximum value of the Adjustable.
|
||||
*
|
||||
* @return the maximum value of the Adjustable.
|
||||
*/
|
||||
public int getMaximum();
|
||||
|
||||
/**
|
||||
* Gets the minimum value of the Adjustable.
|
||||
*
|
||||
* @return the minimum value of the Adjustable.
|
||||
*/
|
||||
public int getMinimum();
|
||||
|
||||
/**
|
||||
* Gets the orientation of the Adjustable.
|
||||
*
|
||||
* @return the orientation of the Adjustable.
|
||||
*/
|
||||
public int getOrientation();
|
||||
|
||||
/**
|
||||
* Gets the unit increment of the Adjustable.
|
||||
*
|
||||
* @return the unit increment of the Adjustable.
|
||||
*/
|
||||
public int getUnitIncrement();
|
||||
|
||||
/**
|
||||
* Gets the visible amount of the Adjustable.
|
||||
*
|
||||
* @return the visible amount of the Adjustable.
|
||||
*/
|
||||
public int getVisibleAmount();
|
||||
|
||||
/**
|
||||
* Removes the adjustment listener of the Adjustable.
|
||||
*
|
||||
* @param a0
|
||||
* the specified AdjustmentListener to be removed.
|
||||
*/
|
||||
public void removeAdjustmentListener(AdjustmentListener a0);
|
||||
|
||||
/**
|
||||
* Sets the block increment for the Adjustable.
|
||||
*
|
||||
* @param a0
|
||||
* the new block increment.
|
||||
*/
|
||||
public void setBlockIncrement(int a0);
|
||||
|
||||
/**
|
||||
* Sets the maximum value of the Adjustable.
|
||||
*
|
||||
* @param a0
|
||||
* the new maximum of the Adjustable.
|
||||
*/
|
||||
public void setMaximum(int a0);
|
||||
|
||||
/**
|
||||
* Sets the minimum value of the Adjustable.
|
||||
*
|
||||
* @param a0
|
||||
* the new minimum of the Adjustable.
|
||||
*/
|
||||
public void setMinimum(int a0);
|
||||
|
||||
/**
|
||||
* Sets the unit increment of the Adjustable.
|
||||
*
|
||||
* @param a0
|
||||
* the new unit increment of the Adjustable.
|
||||
*/
|
||||
public void setUnitIncrement(int a0);
|
||||
|
||||
/**
|
||||
* Sets the visible amount of the Adjustable.
|
||||
*
|
||||
* @param a0
|
||||
* the new visible amount of the Adjustable.
|
||||
*/
|
||||
public void setVisibleAmount(int a0);
|
||||
|
||||
}
|
||||
@@ -1,352 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Igor V. Stolyarov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.Composite;
|
||||
import java.awt.CompositeContext;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.ColorModel;
|
||||
|
||||
import org.apache.harmony.awt.gl.ICompositeContext;
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The AlphaComposite class defines a basic alpha compositing rules for
|
||||
* combining source and destination colors to achieve blending and transparency
|
||||
* effects with graphics and images.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public final class AlphaComposite implements Composite {
|
||||
|
||||
/**
|
||||
* The Constant CLEAR indicates that both the color and the alpha of the
|
||||
* destination are cleared (Porter-Duff Clear rule).
|
||||
*/
|
||||
public static final int CLEAR = 1;
|
||||
|
||||
/**
|
||||
* The Constant SRC indicates that the source is copied to the destination
|
||||
* (Porter-Duff Source rule).
|
||||
*/
|
||||
public static final int SRC = 2;
|
||||
|
||||
/**
|
||||
* The Constant DST indicates that the destination is left untouched
|
||||
* (Porter-Duff Destination rule).
|
||||
*/
|
||||
public static final int DST = 9;
|
||||
|
||||
/**
|
||||
* The Constant SRC_OVER indicates that the source is composited over the
|
||||
* destination (Porter-Duff Source Over Destination rule).
|
||||
*/
|
||||
public static final int SRC_OVER = 3;
|
||||
|
||||
/**
|
||||
* The Constant DST_OVER indicates that The destination is composited over
|
||||
* the source and the result replaces the destination (Porter-Duff
|
||||
* Destination Over Source rule).
|
||||
*/
|
||||
public static final int DST_OVER = 4;
|
||||
|
||||
/**
|
||||
* The Constant SRC_IN indicates that the part of the source lying inside of
|
||||
* the destination replaces the destination (Porter-Duff Source In
|
||||
* Destination rule).
|
||||
*/
|
||||
public static final int SRC_IN = 5;
|
||||
|
||||
/**
|
||||
* The Constant DST_IN indicates that the part of the destination lying
|
||||
* inside of the source replaces the destination (Porter-Duff Destination In
|
||||
* Source rule).
|
||||
*/
|
||||
public static final int DST_IN = 6;
|
||||
|
||||
/**
|
||||
* The Constant SRC_OUT indicates that the part of the source lying outside
|
||||
* of the destination replaces the destination (Porter-Duff Source Held Out
|
||||
* By Destination rule).
|
||||
*/
|
||||
public static final int SRC_OUT = 7;
|
||||
|
||||
/**
|
||||
* The Constant DST_OUT indicates that the part of the destination lying
|
||||
* outside of the source replaces the destination (Porter-Duff Destination
|
||||
* Held Out By Source rule).
|
||||
*/
|
||||
public static final int DST_OUT = 8;
|
||||
|
||||
/**
|
||||
* The Constant SRC_ATOP indicates that the part of the source lying inside
|
||||
* of the destination is composited onto the destination (Porter-Duff Source
|
||||
* Atop Destination rule).
|
||||
*/
|
||||
public static final int SRC_ATOP = 10;
|
||||
|
||||
/**
|
||||
* The Constant DST_ATOP indicates that the part of the destination lying
|
||||
* inside of the source is composited over the source and replaces the
|
||||
* destination (Porter-Duff Destination Atop Source rule).
|
||||
*/
|
||||
public static final int DST_ATOP = 11;
|
||||
|
||||
/**
|
||||
* The Constant XOR indicates that the part of the source that lies outside
|
||||
* of the destination is combined with the part of the destination that lies
|
||||
* outside of the source (Porter-Duff Source Xor Destination rule).
|
||||
*/
|
||||
public static final int XOR = 12;
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque CLEAR rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite Clear = new AlphaComposite(CLEAR);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque SRC rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite Src = new AlphaComposite(SRC);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque DST rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite Dst = new AlphaComposite(DST);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque SRC_OVER rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite SrcOver = new AlphaComposite(SRC_OVER);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque DST_OVER rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite DstOver = new AlphaComposite(DST_OVER);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque SRC_IN rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite SrcIn = new AlphaComposite(SRC_IN);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque DST_IN rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite DstIn = new AlphaComposite(DST_IN);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque SRC_OUT rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite SrcOut = new AlphaComposite(SRC_OUT);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque DST_OUT rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite DstOut = new AlphaComposite(DST_OUT);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque SRC_ATOP rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite SrcAtop = new AlphaComposite(SRC_ATOP);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque DST_ATOP rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite DstAtop = new AlphaComposite(DST_ATOP);
|
||||
|
||||
/**
|
||||
* AlphaComposite object with the opaque XOR rule and an alpha of 1.0f.
|
||||
*/
|
||||
public static final AlphaComposite Xor = new AlphaComposite(XOR);
|
||||
|
||||
/**
|
||||
* The rule.
|
||||
*/
|
||||
private int rule;
|
||||
|
||||
/**
|
||||
* The alpha.
|
||||
*/
|
||||
private float alpha;
|
||||
|
||||
/**
|
||||
* Instantiates a new alpha composite. Creates a context for the compositing
|
||||
* operation. The context contains state that is used in performing the
|
||||
* compositing operation.
|
||||
*
|
||||
* @param rule
|
||||
* the rule.
|
||||
* @param alpha
|
||||
* the alpha.
|
||||
*/
|
||||
private AlphaComposite(int rule, float alpha) {
|
||||
if (rule < CLEAR || rule > XOR) {
|
||||
// awt.11D=Unknown rule
|
||||
throw new IllegalArgumentException(Messages.getString("awt.11D")); //$NON-NLS-1$
|
||||
}
|
||||
if (alpha < 0.0f || alpha > 1.0f) {
|
||||
// awt.11E=Wrong alpha value
|
||||
throw new IllegalArgumentException(Messages.getString("awt.11E")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
this.rule = rule;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new alpha composite.
|
||||
*
|
||||
* @param rule
|
||||
* the rule.
|
||||
*/
|
||||
private AlphaComposite(int rule) {
|
||||
this(rule, 1.0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a CompositeContext object with the specified source ColorModel,
|
||||
* destination ColorModel and RenderingHints parameters for a composing
|
||||
* operation.
|
||||
*
|
||||
* @param srcColorModel
|
||||
* the source's ColorModel.
|
||||
* @param dstColorModel
|
||||
* the destination's ColorModel.
|
||||
* @param hints
|
||||
* the RenderingHints object.
|
||||
* @return the CompositeContext object.
|
||||
* @see java.awt.Composite#createContext(java.awt.image.ColorModel,
|
||||
* java.awt.image.ColorModel, java.awt.RenderingHints)
|
||||
*/
|
||||
public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel,
|
||||
RenderingHints hints) {
|
||||
return new ICompositeContext(this, srcColorModel, dstColorModel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the AlphaComposite object with the specified object.
|
||||
*
|
||||
* @param obj
|
||||
* the Object to be compared.
|
||||
* @return true, if the AlphaComposite object is equal to the specified
|
||||
* object.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof AlphaComposite)) {
|
||||
return false;
|
||||
}
|
||||
AlphaComposite other = (AlphaComposite)obj;
|
||||
return (this.rule == other.getRule() && this.alpha == other.getAlpha());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash code of the AlphaComposite object.
|
||||
*
|
||||
* @return the hash code of the AlphaComposite object.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = Float.floatToIntBits(alpha);
|
||||
int tmp = hash >>> 24;
|
||||
hash <<= 8;
|
||||
hash |= tmp;
|
||||
hash ^= rule;
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compositing rule of this AlphaComposite object.
|
||||
*
|
||||
* @return the compositing rule of this AlphaComposite object.
|
||||
*/
|
||||
public int getRule() {
|
||||
return rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the alpha value of this AlphaComposite object; returns 1.0 if this
|
||||
* AlphaComposite object doesn't have alpha value.
|
||||
*
|
||||
* @return the alpha value of this AlphaComposite object or 1.0 if this
|
||||
* AlphaComposite object doesn't have alpha value.
|
||||
*/
|
||||
public float getAlpha() {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AlphaComposite instance with the specified rule and alpha value.
|
||||
*
|
||||
* @param rule
|
||||
* the compositing rule.
|
||||
* @param alpha
|
||||
* the alpha value.
|
||||
* @return the AlphaComposite instance.
|
||||
*/
|
||||
public static AlphaComposite getInstance(int rule, float alpha) {
|
||||
if (alpha == 1.0f) {
|
||||
return getInstance(rule);
|
||||
}
|
||||
return new AlphaComposite(rule, alpha);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AlphaComposite instance with the specified rule.
|
||||
*
|
||||
* @param rule
|
||||
* the compositing rule.
|
||||
* @return the AlphaComposite instance.
|
||||
*/
|
||||
public static AlphaComposite getInstance(int rule) {
|
||||
switch (rule) {
|
||||
case CLEAR:
|
||||
return Clear;
|
||||
case SRC:
|
||||
return Src;
|
||||
case DST:
|
||||
return Dst;
|
||||
case SRC_OVER:
|
||||
return SrcOver;
|
||||
case DST_OVER:
|
||||
return DstOver;
|
||||
case SRC_IN:
|
||||
return SrcIn;
|
||||
case DST_IN:
|
||||
return DstIn;
|
||||
case SRC_OUT:
|
||||
return SrcOut;
|
||||
case DST_OUT:
|
||||
return DstOut;
|
||||
case SRC_ATOP:
|
||||
return SrcAtop;
|
||||
case DST_ATOP:
|
||||
return DstAtop;
|
||||
case XOR:
|
||||
return Xor;
|
||||
default:
|
||||
// awt.11D=Unknown rule
|
||||
throw new IllegalArgumentException(Messages.getString("awt.11D")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,195 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The BufferCapabilities class represents the capabilities and other properties
|
||||
* of the image buffers.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class BufferCapabilities implements Cloneable {
|
||||
|
||||
/**
|
||||
* The front buffer capabilities.
|
||||
*/
|
||||
private final ImageCapabilities frontBufferCapabilities;
|
||||
|
||||
/**
|
||||
* The back buffer capabilities.
|
||||
*/
|
||||
private final ImageCapabilities backBufferCapabilities;
|
||||
|
||||
/**
|
||||
* The flip contents.
|
||||
*/
|
||||
private final FlipContents flipContents;
|
||||
|
||||
/**
|
||||
* Instantiates a new BufferCapabilities object.
|
||||
*
|
||||
* @param frontBufferCapabilities
|
||||
* the front buffer capabilities, can not be null.
|
||||
* @param backBufferCapabilities
|
||||
* the the back and intermediate buffers capabilities, can not be
|
||||
* null.
|
||||
* @param flipContents
|
||||
* the back buffer contents after page flipping, null if page
|
||||
* flipping is not used.
|
||||
*/
|
||||
public BufferCapabilities(ImageCapabilities frontBufferCapabilities,
|
||||
ImageCapabilities backBufferCapabilities, FlipContents flipContents) {
|
||||
if (frontBufferCapabilities == null || backBufferCapabilities == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
this.frontBufferCapabilities = frontBufferCapabilities;
|
||||
this.backBufferCapabilities = backBufferCapabilities;
|
||||
this.flipContents = flipContents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the BufferCapabilities object.
|
||||
*
|
||||
* @return a copy of the BufferCapabilities object.
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
return new BufferCapabilities(frontBufferCapabilities, backBufferCapabilities, flipContents);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image capabilities of the front buffer.
|
||||
*
|
||||
* @return the ImageCapabilities object represented capabilities of the
|
||||
* front buffer.
|
||||
*/
|
||||
public ImageCapabilities getFrontBufferCapabilities() {
|
||||
return frontBufferCapabilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image capabilities of the back buffer.
|
||||
*
|
||||
* @return the ImageCapabilities object represented capabilities of the back
|
||||
* buffer.
|
||||
*/
|
||||
public ImageCapabilities getBackBufferCapabilities() {
|
||||
return backBufferCapabilities;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the flip contents of the back buffer after page-flipping.
|
||||
*
|
||||
* @return the FlipContents of the back buffer after page-flipping.
|
||||
*/
|
||||
public FlipContents getFlipContents() {
|
||||
return flipContents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the buffer strategy uses page flipping.
|
||||
*
|
||||
* @return true, if the buffer strategy uses page flipping, false otherwise.
|
||||
*/
|
||||
public boolean isPageFlipping() {
|
||||
return flipContents != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if page flipping is only available in full-screen mode.
|
||||
*
|
||||
* @return true, if page flipping is only available in full-screen mode,
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean isFullScreenRequired() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if page flipping can be performed using more than two buffers.
|
||||
*
|
||||
* @return true, if page flipping can be performed using more than two
|
||||
* buffers, false otherwise.
|
||||
*/
|
||||
public boolean isMultiBufferAvailable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The FlipContents class represents a set of possible back buffer contents
|
||||
* after page-flipping.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public static final class FlipContents {
|
||||
|
||||
/**
|
||||
* The back buffered contents are cleared with the background color
|
||||
* after flipping.
|
||||
*/
|
||||
public static final FlipContents BACKGROUND = new FlipContents();
|
||||
|
||||
/**
|
||||
* The back buffered contents are copied to the front buffer before
|
||||
* flipping.
|
||||
*/
|
||||
public static final FlipContents COPIED = new FlipContents();
|
||||
|
||||
/**
|
||||
* The back buffer contents are the prior contents of the front buffer.
|
||||
*/
|
||||
public static final FlipContents PRIOR = new FlipContents();
|
||||
|
||||
/**
|
||||
* The back buffer contents are undefined after flipping
|
||||
*/
|
||||
public static final FlipContents UNDEFINED = new FlipContents();
|
||||
|
||||
/**
|
||||
* Instantiates a new flip contents.
|
||||
*/
|
||||
private FlipContents() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash code of the FlipContents object.
|
||||
*
|
||||
* @return the hash code of the FlipContents object.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the String representation of the FlipContents object.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,990 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Oleg V. Khaschansky
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The Color class defines colors in the default sRGB color space or in the
|
||||
* specified ColorSpace. Every Color contains alpha value. The alpha value
|
||||
* defines the transparency of a color and can be represented by a float value
|
||||
* in the range 0.0 - 1.0 or 0 - 255.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class Color implements Paint, Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 118526816881161077L;
|
||||
|
||||
/*
|
||||
* The values of the following colors are based on 1.5 release behavior
|
||||
* which can be revealed using the following or similar code: Color c =
|
||||
* Color.white; System.out.println(c);
|
||||
*/
|
||||
|
||||
/**
|
||||
* The color white.
|
||||
*/
|
||||
public static final Color white = new Color(255, 255, 255);
|
||||
|
||||
/**
|
||||
* The color white.
|
||||
*/
|
||||
public static final Color WHITE = white;
|
||||
|
||||
/**
|
||||
* The color light gray.
|
||||
*/
|
||||
public static final Color lightGray = new Color(192, 192, 192);
|
||||
|
||||
/**
|
||||
* The color light gray.
|
||||
*/
|
||||
public static final Color LIGHT_GRAY = lightGray;
|
||||
|
||||
/**
|
||||
* The color gray.
|
||||
*/
|
||||
public static final Color gray = new Color(128, 128, 128);
|
||||
|
||||
/**
|
||||
* The color gray.
|
||||
*/
|
||||
public static final Color GRAY = gray;
|
||||
|
||||
/**
|
||||
* The color dark gray.
|
||||
*/
|
||||
public static final Color darkGray = new Color(64, 64, 64);
|
||||
|
||||
/**
|
||||
* The color dark gray.
|
||||
*/
|
||||
public static final Color DARK_GRAY = darkGray;
|
||||
|
||||
/**
|
||||
* The color black.
|
||||
*/
|
||||
public static final Color black = new Color(0, 0, 0);
|
||||
|
||||
/**
|
||||
* The color black.
|
||||
*/
|
||||
public static final Color BLACK = black;
|
||||
|
||||
/**
|
||||
* The color red.
|
||||
*/
|
||||
public static final Color red = new Color(255, 0, 0);
|
||||
|
||||
/**
|
||||
* The color red.
|
||||
*/
|
||||
public static final Color RED = red;
|
||||
|
||||
/**
|
||||
* The color pink.
|
||||
*/
|
||||
public static final Color pink = new Color(255, 175, 175);
|
||||
|
||||
/**
|
||||
* The color pink.
|
||||
*/
|
||||
public static final Color PINK = pink;
|
||||
|
||||
/**
|
||||
* The color orange.
|
||||
*/
|
||||
public static final Color orange = new Color(255, 200, 0);
|
||||
|
||||
/**
|
||||
* The color orange.
|
||||
*/
|
||||
public static final Color ORANGE = orange;
|
||||
|
||||
/**
|
||||
* The color yellow.
|
||||
*/
|
||||
public static final Color yellow = new Color(255, 255, 0);
|
||||
|
||||
/**
|
||||
* The color yellow.
|
||||
*/
|
||||
public static final Color YELLOW = yellow;
|
||||
|
||||
/**
|
||||
* The color green.
|
||||
*/
|
||||
public static final Color green = new Color(0, 255, 0);
|
||||
|
||||
/**
|
||||
* The color green.
|
||||
*/
|
||||
public static final Color GREEN = green;
|
||||
|
||||
/**
|
||||
* The color magenta.
|
||||
*/
|
||||
public static final Color magenta = new Color(255, 0, 255);
|
||||
|
||||
/**
|
||||
* The color magenta.
|
||||
*/
|
||||
public static final Color MAGENTA = magenta;
|
||||
|
||||
/**
|
||||
* The color cyan.
|
||||
*/
|
||||
public static final Color cyan = new Color(0, 255, 255);
|
||||
|
||||
/**
|
||||
* The color cyan.
|
||||
*/
|
||||
public static final Color CYAN = cyan;
|
||||
|
||||
/**
|
||||
* The color blue.
|
||||
*/
|
||||
public static final Color blue = new Color(0, 0, 255);
|
||||
|
||||
/**
|
||||
* The color blue.
|
||||
*/
|
||||
public static final Color BLUE = blue;
|
||||
|
||||
/**
|
||||
* integer RGB value.
|
||||
*/
|
||||
int value;
|
||||
|
||||
/**
|
||||
* Float sRGB value.
|
||||
*/
|
||||
private float[] frgbvalue;
|
||||
|
||||
/**
|
||||
* Color in an arbitrary color space with <code>float</code> components. If
|
||||
* null, other value should be used.
|
||||
*/
|
||||
private float fvalue[];
|
||||
|
||||
/**
|
||||
* Float alpha value. If frgbvalue is null, this is not valid data.
|
||||
*/
|
||||
private float falpha;
|
||||
|
||||
/**
|
||||
* The color's color space if applicable.
|
||||
*/
|
||||
private ColorSpace cs;
|
||||
|
||||
/*
|
||||
* The value of the SCALE_FACTOR is based on 1.5 release behavior which can
|
||||
* be revealed using the following code: Color c = new Color(100, 100, 100);
|
||||
* Color bc = c.brighter(); System.out.println("Brighter factor: " +
|
||||
* ((float)c.getRed())/((float)bc.getRed())); Color dc = c.darker();
|
||||
* System.out.println("Darker factor: " +
|
||||
* ((float)dc.getRed())/((float)c.getRed())); The result is the same for
|
||||
* brighter and darker methods, so we need only one scale factor for both.
|
||||
*/
|
||||
/**
|
||||
* The Constant SCALE_FACTOR.
|
||||
*/
|
||||
private static final double SCALE_FACTOR = 0.7;
|
||||
|
||||
/**
|
||||
* The Constant MIN_SCALABLE.
|
||||
*/
|
||||
private static final int MIN_SCALABLE = 3; // should increase when
|
||||
|
||||
// multiplied by SCALE_FACTOR
|
||||
|
||||
/**
|
||||
* The current paint context.
|
||||
*/
|
||||
transient private PaintContext currentPaintContext;
|
||||
|
||||
/**
|
||||
* Creates a color in the specified ColorSpace, the specified color
|
||||
* components and the specified alpha.
|
||||
*
|
||||
* @param cspace
|
||||
* the ColorSpace to be used to define the components.
|
||||
* @param components
|
||||
* the components.
|
||||
* @param alpha
|
||||
* the alpha.
|
||||
*/
|
||||
public Color(ColorSpace cspace, float[] components, float alpha) {
|
||||
int nComps = cspace.getNumComponents();
|
||||
float comp;
|
||||
fvalue = new float[nComps];
|
||||
|
||||
for (int i = 0; i < nComps; i++) {
|
||||
comp = components[i];
|
||||
if (comp < 0.0f || comp > 1.0f) {
|
||||
// awt.107=Color parameter outside of expected range: component
|
||||
// {0}.
|
||||
throw new IllegalArgumentException(Messages.getString("awt.107", i)); //$NON-NLS-1$
|
||||
}
|
||||
fvalue[i] = components[i];
|
||||
}
|
||||
|
||||
if (alpha < 0.0f || alpha > 1.0f) {
|
||||
// awt.108=Alpha value outside of expected range.
|
||||
throw new IllegalArgumentException(Messages.getString("awt.108")); //$NON-NLS-1$
|
||||
}
|
||||
falpha = alpha;
|
||||
|
||||
cs = cspace;
|
||||
|
||||
frgbvalue = cs.toRGB(fvalue);
|
||||
|
||||
value = ((int)(frgbvalue[2] * 255 + 0.5)) | (((int)(frgbvalue[1] * 255 + 0.5)) << 8)
|
||||
| (((int)(frgbvalue[0] * 255 + 0.5)) << 16) | (((int)(falpha * 255 + 0.5)) << 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new sRGB color with the specified combined RGBA value
|
||||
* consisting of the alpha component in bits 24-31, the red component in
|
||||
* bits 16-23, the green component in bits 8-15, and the blue component in
|
||||
* bits 0-7. If the hasalpha argument is false, the alpha has default value
|
||||
* - 255.
|
||||
*
|
||||
* @param rgba
|
||||
* the RGBA components.
|
||||
* @param hasAlpha
|
||||
* the alpha parameter is true if alpha bits are valid, false
|
||||
* otherwise.
|
||||
*/
|
||||
public Color(int rgba, boolean hasAlpha) {
|
||||
if (!hasAlpha) {
|
||||
value = rgba | 0xFF000000;
|
||||
} else {
|
||||
value = rgba;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new color with the specified red, green, blue and alpha
|
||||
* components.
|
||||
*
|
||||
* @param r
|
||||
* the red component.
|
||||
* @param g
|
||||
* the green component.
|
||||
* @param b
|
||||
* the blue component.
|
||||
* @param a
|
||||
* the alpha component.
|
||||
*/
|
||||
public Color(int r, int g, int b, int a) {
|
||||
if ((r & 0xFF) != r || (g & 0xFF) != g || (b & 0xFF) != b || (a & 0xFF) != a) {
|
||||
// awt.109=Color parameter outside of expected range.
|
||||
throw new IllegalArgumentException(Messages.getString("awt.109")); //$NON-NLS-1$
|
||||
}
|
||||
value = b | (g << 8) | (r << 16) | (a << 24);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new opaque sRGB color with the specified red, green, and
|
||||
* blue values. The Alpha component is set to the default - 1.0.
|
||||
*
|
||||
* @param r
|
||||
* the red component.
|
||||
* @param g
|
||||
* the green component.
|
||||
* @param b
|
||||
* the blue component.
|
||||
*/
|
||||
public Color(int r, int g, int b) {
|
||||
if ((r & 0xFF) != r || (g & 0xFF) != g || (b & 0xFF) != b) {
|
||||
// awt.109=Color parameter outside of expected range.
|
||||
throw new IllegalArgumentException(Messages.getString("awt.109")); //$NON-NLS-1$
|
||||
}
|
||||
// 0xFF for alpha channel
|
||||
value = b | (g << 8) | (r << 16) | 0xFF000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new sRGB color with the specified RGB value consisting of
|
||||
* the red component in bits 16-23, the green component in bits 8-15, and
|
||||
* the blue component in bits 0-7. Alpha has default value - 255.
|
||||
*
|
||||
* @param rgb
|
||||
* the RGB components.
|
||||
*/
|
||||
public Color(int rgb) {
|
||||
value = rgb | 0xFF000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new color with the specified red, green, blue and alpha
|
||||
* components.
|
||||
*
|
||||
* @param r
|
||||
* the red component.
|
||||
* @param g
|
||||
* the green component.
|
||||
* @param b
|
||||
* the blue component.
|
||||
* @param a
|
||||
* the alpha component.
|
||||
*/
|
||||
public Color(float r, float g, float b, float a) {
|
||||
this((int)(r * 255 + 0.5), (int)(g * 255 + 0.5), (int)(b * 255 + 0.5), (int)(a * 255 + 0.5));
|
||||
falpha = a;
|
||||
fvalue = new float[3];
|
||||
fvalue[0] = r;
|
||||
fvalue[1] = g;
|
||||
fvalue[2] = b;
|
||||
frgbvalue = fvalue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new color with the specified red, green, and blue
|
||||
* components and default alpha value - 1.0.
|
||||
*
|
||||
* @param r
|
||||
* the red component.
|
||||
* @param g
|
||||
* the green component.
|
||||
* @param b
|
||||
* the blue component.
|
||||
*/
|
||||
public Color(float r, float g, float b) {
|
||||
this(r, g, b, 1.0f);
|
||||
}
|
||||
|
||||
public PaintContext createContext(ColorModel cm, Rectangle r, Rectangle2D r2d,
|
||||
AffineTransform xform, RenderingHints rhs) {
|
||||
if (currentPaintContext != null) {
|
||||
return currentPaintContext;
|
||||
}
|
||||
currentPaintContext = new Color.ColorPaintContext(value);
|
||||
return currentPaintContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the Color object.
|
||||
*
|
||||
* @return the string representation of the Color object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
/*
|
||||
* The format of the string is based on 1.5 release behavior which can
|
||||
* be revealed using the following code: Color c = new Color(1, 2, 3);
|
||||
* System.out.println(c);
|
||||
*/
|
||||
|
||||
return getClass().getName() + "[r=" + getRed() + //$NON-NLS-1$
|
||||
",g=" + getGreen() + //$NON-NLS-1$
|
||||
",b=" + getBlue() + //$NON-NLS-1$
|
||||
"]"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the specified Object to the Color.
|
||||
*
|
||||
* @param obj
|
||||
* the Object to be compared.
|
||||
* @return true, if the specified Object is a Color whose value is equal to
|
||||
* this Color, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof Color) {
|
||||
return ((Color)obj).value == this.value;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a float array containing the color and alpha components of the
|
||||
* Color in the specified ColorSpace.
|
||||
*
|
||||
* @param colorSpace
|
||||
* the specified ColorSpace.
|
||||
* @param components
|
||||
* the results of this method will be written to this float
|
||||
* array. If null, a float array will be created.
|
||||
* @return the color and alpha components in a float array.
|
||||
*/
|
||||
public float[] getComponents(ColorSpace colorSpace, float[] components) {
|
||||
int nComps = colorSpace.getNumComponents();
|
||||
if (components == null) {
|
||||
components = new float[nComps + 1];
|
||||
}
|
||||
|
||||
getColorComponents(colorSpace, components);
|
||||
|
||||
if (frgbvalue != null) {
|
||||
components[nComps] = falpha;
|
||||
} else {
|
||||
components[nComps] = getAlpha() / 255f;
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a float array containing the color components of the Color in the
|
||||
* specified ColorSpace.
|
||||
*
|
||||
* @param colorSpace
|
||||
* the specified ColorSpace.
|
||||
* @param components
|
||||
* the results of this method will be written to this float
|
||||
* array. If null, a float array will be created.
|
||||
* @return the color components in a float array.
|
||||
*/
|
||||
public float[] getColorComponents(ColorSpace colorSpace, float[] components) {
|
||||
float[] cieXYZComponents = getColorSpace().toCIEXYZ(getColorComponents(null));
|
||||
float[] csComponents = colorSpace.fromCIEXYZ(cieXYZComponents);
|
||||
|
||||
if (components == null) {
|
||||
return csComponents;
|
||||
}
|
||||
|
||||
for (int i = 0; i < csComponents.length; i++) {
|
||||
components[i] = csComponents[i];
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ColorSpace of this Color.
|
||||
*
|
||||
* @return the ColorSpace object.
|
||||
*/
|
||||
public ColorSpace getColorSpace() {
|
||||
if (cs == null) {
|
||||
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
|
||||
}
|
||||
|
||||
return cs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Color which is a darker than this Color according to a
|
||||
* fixed scale factor.
|
||||
*
|
||||
* @return the darker Color.
|
||||
*/
|
||||
public Color darker() {
|
||||
return new Color((int)(getRed() * SCALE_FACTOR), (int)(getGreen() * SCALE_FACTOR),
|
||||
(int)(getBlue() * SCALE_FACTOR));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Color which is a brighter than this Color.
|
||||
*
|
||||
* @return the brighter Color.
|
||||
*/
|
||||
public Color brighter() {
|
||||
|
||||
int r = getRed();
|
||||
int b = getBlue();
|
||||
int g = getGreen();
|
||||
|
||||
if (r == 0 && b == 0 && g == 0) {
|
||||
return new Color(MIN_SCALABLE, MIN_SCALABLE, MIN_SCALABLE);
|
||||
}
|
||||
|
||||
if (r < MIN_SCALABLE && r != 0) {
|
||||
r = MIN_SCALABLE;
|
||||
} else {
|
||||
r = (int)(r / SCALE_FACTOR);
|
||||
r = (r > 255) ? 255 : r;
|
||||
}
|
||||
|
||||
if (b < MIN_SCALABLE && b != 0) {
|
||||
b = MIN_SCALABLE;
|
||||
} else {
|
||||
b = (int)(b / SCALE_FACTOR);
|
||||
b = (b > 255) ? 255 : b;
|
||||
}
|
||||
|
||||
if (g < MIN_SCALABLE && g != 0) {
|
||||
g = MIN_SCALABLE;
|
||||
} else {
|
||||
g = (int)(g / SCALE_FACTOR);
|
||||
g = (g > 255) ? 255 : g;
|
||||
}
|
||||
|
||||
return new Color(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a float array containing the color and alpha components of the
|
||||
* Color in the default sRGB color space.
|
||||
*
|
||||
* @param components
|
||||
* the results of this method will be written to this float
|
||||
* array. A new float array will be created if this argument is
|
||||
* null.
|
||||
* @return the RGB color and alpha components in a float array.
|
||||
*/
|
||||
public float[] getRGBComponents(float[] components) {
|
||||
if (components == null) {
|
||||
components = new float[4];
|
||||
}
|
||||
|
||||
if (frgbvalue != null) {
|
||||
components[3] = falpha;
|
||||
} else {
|
||||
components[3] = getAlpha() / 255f;
|
||||
}
|
||||
|
||||
getRGBColorComponents(components);
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a float array containing the color components of the Color in the
|
||||
* default sRGB color space.
|
||||
*
|
||||
* @param components
|
||||
* the results of this method will be written to this float
|
||||
* array. A new float array will be created if this argument is
|
||||
* null.
|
||||
* @return the RGB color components in a float array.
|
||||
*/
|
||||
public float[] getRGBColorComponents(float[] components) {
|
||||
if (components == null) {
|
||||
components = new float[3];
|
||||
}
|
||||
|
||||
if (frgbvalue != null) {
|
||||
components[2] = frgbvalue[2];
|
||||
components[1] = frgbvalue[1];
|
||||
components[0] = frgbvalue[0];
|
||||
} else {
|
||||
components[2] = getBlue() / 255f;
|
||||
components[1] = getGreen() / 255f;
|
||||
components[0] = getRed() / 255f;
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a float array which contains the color and alpha components of
|
||||
* the Color in the ColorSpace of the Color.
|
||||
*
|
||||
* @param components
|
||||
* the results of this method will be written to this float
|
||||
* array. A new float array will be created if this argument is
|
||||
* null.
|
||||
* @return the color and alpha components in a float array.
|
||||
*/
|
||||
public float[] getComponents(float[] components) {
|
||||
if (fvalue == null) {
|
||||
return getRGBComponents(components);
|
||||
}
|
||||
|
||||
int nColorComps = fvalue.length;
|
||||
|
||||
if (components == null) {
|
||||
components = new float[nColorComps + 1];
|
||||
}
|
||||
|
||||
getColorComponents(components);
|
||||
|
||||
components[nColorComps] = falpha;
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a float array which contains the color components of the Color in
|
||||
* the ColorSpace of the Color.
|
||||
*
|
||||
* @param components
|
||||
* the results of this method will be written to this float
|
||||
* array. A new float array will be created if this argument is
|
||||
* null.
|
||||
* @return the color components in a float array.
|
||||
*/
|
||||
public float[] getColorComponents(float[] components) {
|
||||
if (fvalue == null) {
|
||||
return getRGBColorComponents(components);
|
||||
}
|
||||
|
||||
if (components == null) {
|
||||
components = new float[fvalue.length];
|
||||
}
|
||||
|
||||
for (int i = 0; i < fvalue.length; i++) {
|
||||
components[i] = fvalue[i];
|
||||
}
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code of this Color object.
|
||||
*
|
||||
* @return a hash code of this Color object.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getTransparency() {
|
||||
switch (getAlpha()) {
|
||||
case 0xff:
|
||||
return Transparency.OPAQUE;
|
||||
case 0:
|
||||
return Transparency.BITMASK;
|
||||
default:
|
||||
return Transparency.TRANSLUCENT;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the red component of the Color in the range 0-255.
|
||||
*
|
||||
* @return the red component of the Color.
|
||||
*/
|
||||
public int getRed() {
|
||||
return (value >> 16) & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the RGB value that represents the color in the default sRGB
|
||||
* ColorModel.
|
||||
*
|
||||
* @return the RGB color value in the default sRGB ColorModel.
|
||||
*/
|
||||
public int getRGB() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the green component of the Color in the range 0-255.
|
||||
*
|
||||
* @return the green component of the Color.
|
||||
*/
|
||||
public int getGreen() {
|
||||
return (value >> 8) & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the blue component of the Color in the range 0-255.
|
||||
*
|
||||
* @return the blue component of the Color.
|
||||
*/
|
||||
public int getBlue() {
|
||||
return value & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the alpha component of the Color in the range 0-255.
|
||||
*
|
||||
* @return the alpha component of the Color.
|
||||
*/
|
||||
public int getAlpha() {
|
||||
return (value >> 24) & 0xFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Color from the specified string, or returns the Color specified
|
||||
* by the second parameter.
|
||||
*
|
||||
* @param nm
|
||||
* the specified string.
|
||||
* @param def
|
||||
* the default Color.
|
||||
* @return the color from the specified string, or the Color specified by
|
||||
* the second parameter.
|
||||
*/
|
||||
public static Color getColor(String nm, Color def) {
|
||||
Integer integer = Integer.getInteger(nm);
|
||||
|
||||
if (integer == null) {
|
||||
return def;
|
||||
}
|
||||
|
||||
return new Color(integer.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Color from the specified string, or returns the Color converted
|
||||
* from the second parameter.
|
||||
*
|
||||
* @param nm
|
||||
* the specified string.
|
||||
* @param def
|
||||
* the default Color.
|
||||
* @return the color from the specified string, or the Color converted from
|
||||
* the second parameter.
|
||||
*/
|
||||
public static Color getColor(String nm, int def) {
|
||||
Integer integer = Integer.getInteger(nm);
|
||||
|
||||
if (integer == null) {
|
||||
return new Color(def);
|
||||
}
|
||||
|
||||
return new Color(integer.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Color from the specified String.
|
||||
*
|
||||
* @param nm
|
||||
* the specified string.
|
||||
* @return the Color object, or null.
|
||||
*/
|
||||
public static Color getColor(String nm) {
|
||||
Integer integer = Integer.getInteger(nm);
|
||||
|
||||
if (integer == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Color(integer.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a String to an integer and returns the specified opaque Color.
|
||||
*
|
||||
* @param nm
|
||||
* the String which represents an opaque color as a 24-bit
|
||||
* integer.
|
||||
* @return the Color object from the given String.
|
||||
* @throws NumberFormatException
|
||||
* if the specified string can not be converted to an integer.
|
||||
*/
|
||||
public static Color decode(String nm) throws NumberFormatException {
|
||||
Integer integer = Integer.decode(nm);
|
||||
return new Color(integer.intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Color object using the specified values of the HSB color model.
|
||||
*
|
||||
* @param h
|
||||
* the hue component of the Color.
|
||||
* @param s
|
||||
* the saturation of the Color.
|
||||
* @param b
|
||||
* the brightness of the Color.
|
||||
* @return a color object with the specified hue, saturation and brightness
|
||||
* values.
|
||||
*/
|
||||
public static Color getHSBColor(float h, float s, float b) {
|
||||
return new Color(HSBtoRGB(h, s, b));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Color specified by the RGB model to an equivalent color in
|
||||
* the HSB model.
|
||||
*
|
||||
* @param r
|
||||
* the red component.
|
||||
* @param g
|
||||
* the green component.
|
||||
* @param b
|
||||
* the blue component.
|
||||
* @param hsbvals
|
||||
* the array of result hue, saturation, brightness values or
|
||||
* null.
|
||||
* @return the float array of hue, saturation, brightness values.
|
||||
*/
|
||||
public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals) {
|
||||
if (hsbvals == null) {
|
||||
hsbvals = new float[3];
|
||||
}
|
||||
|
||||
int V = Math.max(b, Math.max(r, g));
|
||||
int temp = Math.min(b, Math.min(r, g));
|
||||
|
||||
float H, S, B;
|
||||
|
||||
B = V / 255.f;
|
||||
|
||||
if (V == temp) {
|
||||
H = S = 0;
|
||||
} else {
|
||||
S = (V - temp) / ((float)V);
|
||||
|
||||
float Cr = (V - r) / (float)(V - temp);
|
||||
float Cg = (V - g) / (float)(V - temp);
|
||||
float Cb = (V - b) / (float)(V - temp);
|
||||
|
||||
if (r == V) {
|
||||
H = Cb - Cg;
|
||||
} else if (g == V) {
|
||||
H = 2 + Cr - Cb;
|
||||
} else {
|
||||
H = 4 + Cg - Cr;
|
||||
}
|
||||
|
||||
H /= 6.f;
|
||||
if (H < 0) {
|
||||
H++;
|
||||
}
|
||||
}
|
||||
|
||||
hsbvals[0] = H;
|
||||
hsbvals[1] = S;
|
||||
hsbvals[2] = B;
|
||||
|
||||
return hsbvals;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Color specified by the HSB model to an equivalent color in
|
||||
* the default RGB model.
|
||||
*
|
||||
* @param hue
|
||||
* the hue component of the Color.
|
||||
* @param saturation
|
||||
* the saturation of the Color.
|
||||
* @param brightness
|
||||
* the brightness of the Color.
|
||||
* @return the RGB value of the color with the specified hue, saturation and
|
||||
* brightness.
|
||||
*/
|
||||
public static int HSBtoRGB(float hue, float saturation, float brightness) {
|
||||
float fr, fg, fb;
|
||||
|
||||
if (saturation == 0) {
|
||||
fr = fg = fb = brightness;
|
||||
} else {
|
||||
float H = (hue - (float)Math.floor(hue)) * 6;
|
||||
int I = (int)Math.floor(H);
|
||||
float F = H - I;
|
||||
float M = brightness * (1 - saturation);
|
||||
float N = brightness * (1 - saturation * F);
|
||||
float K = brightness * (1 - saturation * (1 - F));
|
||||
|
||||
switch (I) {
|
||||
case 0:
|
||||
fr = brightness;
|
||||
fg = K;
|
||||
fb = M;
|
||||
break;
|
||||
case 1:
|
||||
fr = N;
|
||||
fg = brightness;
|
||||
fb = M;
|
||||
break;
|
||||
case 2:
|
||||
fr = M;
|
||||
fg = brightness;
|
||||
fb = K;
|
||||
break;
|
||||
case 3:
|
||||
fr = M;
|
||||
fg = N;
|
||||
fb = brightness;
|
||||
break;
|
||||
case 4:
|
||||
fr = K;
|
||||
fg = M;
|
||||
fb = brightness;
|
||||
break;
|
||||
case 5:
|
||||
fr = brightness;
|
||||
fg = M;
|
||||
fb = N;
|
||||
break;
|
||||
default:
|
||||
fr = fb = fg = 0; // impossible, to supress compiler error
|
||||
}
|
||||
}
|
||||
|
||||
int r = (int)(fr * 255. + 0.5);
|
||||
int g = (int)(fg * 255. + 0.5);
|
||||
int b = (int)(fb * 255. + 0.5);
|
||||
|
||||
return (r << 16) | (g << 8) | b | 0xFF000000;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class ColorPaintContext.
|
||||
*/
|
||||
class ColorPaintContext implements PaintContext {
|
||||
|
||||
/**
|
||||
* The RGB value.
|
||||
*/
|
||||
int rgbValue;
|
||||
|
||||
/**
|
||||
* The saved raster.
|
||||
*/
|
||||
WritableRaster savedRaster = null;
|
||||
|
||||
/**
|
||||
* Instantiates a new color paint context.
|
||||
*
|
||||
* @param rgb
|
||||
* the RGB value.
|
||||
*/
|
||||
protected ColorPaintContext(int rgb) {
|
||||
rgbValue = rgb;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
savedRaster = null;
|
||||
}
|
||||
|
||||
public ColorModel getColorModel() {
|
||||
return ColorModel.getRGBdefault();
|
||||
}
|
||||
|
||||
public Raster getRaster(int x, int y, int w, int h) {
|
||||
if (savedRaster == null || w != savedRaster.getWidth() || h != savedRaster.getHeight()) {
|
||||
savedRaster = getColorModel().createCompatibleWritableRaster(w, h);
|
||||
|
||||
// Suppose we have here simple INT/RGB color/sample model
|
||||
DataBufferInt intBuffer = (DataBufferInt)savedRaster.getDataBuffer();
|
||||
int rgbValues[] = intBuffer.getData();
|
||||
int rgbFillValue = rgbValue;
|
||||
Arrays.fill(rgbValues, rgbFillValue);
|
||||
}
|
||||
|
||||
return savedRaster;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Dmitry A. Durnev
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt;
|
||||
|
||||
import org.apache.harmony.awt.wtk.NativeWindow;
|
||||
|
||||
/**
|
||||
* The interface of the helper object that encapsulates the difference
|
||||
* between lightweight and heavyweight components.
|
||||
*/
|
||||
interface ComponentBehavior {
|
||||
|
||||
void addNotify();
|
||||
|
||||
void setBounds(int x, int y, int w, int h, int bMask);
|
||||
|
||||
void setVisible(boolean b);
|
||||
|
||||
Graphics getGraphics(int translationX, int translationY, int width, int height);
|
||||
|
||||
NativeWindow getNativeWindow();
|
||||
|
||||
boolean isLightweight();
|
||||
|
||||
void onMove(int x, int y);
|
||||
|
||||
boolean isOpaque();
|
||||
|
||||
boolean isDisplayable();
|
||||
|
||||
void setEnabled(boolean value);
|
||||
|
||||
void removeNotify();
|
||||
|
||||
void setZOrder(int newIndex, int oldIndex);
|
||||
|
||||
boolean setFocus(boolean focus, Component opposite);
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov, Dmitry A. Durnev
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The ComponentOrientation class specifies the language-sensitive orientation
|
||||
* of component's elements or text. It is used to reflect the differences in
|
||||
* this ordering between different writing systems. The ComponentOrientation
|
||||
* class indicates the orientation of the elements/text in the horizontal
|
||||
* direction ("left to right" or "right to left") and in the vertical direction
|
||||
* ("top to bottom" or "bottom to top").
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public final class ComponentOrientation implements Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -4113291392143563828L;
|
||||
|
||||
/**
|
||||
* The Constant LEFT_TO_RIGHT indicates that items run left to right.
|
||||
*/
|
||||
public static final ComponentOrientation LEFT_TO_RIGHT = new ComponentOrientation(true, true);
|
||||
|
||||
/**
|
||||
* The Constant RIGHT_TO_LEFT indicates that items run right to left.
|
||||
*/
|
||||
public static final ComponentOrientation RIGHT_TO_LEFT = new ComponentOrientation(true, false);
|
||||
|
||||
/**
|
||||
* The Constant UNKNOWN indicates that a component's orientation is not set.
|
||||
*/
|
||||
public static final ComponentOrientation UNKNOWN = new ComponentOrientation(true, true);
|
||||
|
||||
/**
|
||||
* The Constant rlLangs.
|
||||
*/
|
||||
private static final Set<String> rlLangs = new HashSet<String>(); // RIGHT_TO_LEFT
|
||||
|
||||
// languages
|
||||
|
||||
/**
|
||||
* The horizontal.
|
||||
*/
|
||||
private final boolean horizontal;
|
||||
|
||||
/**
|
||||
* The left2right.
|
||||
*/
|
||||
private final boolean left2right;
|
||||
|
||||
static {
|
||||
rlLangs.add("ar"); //$NON-NLS-1$
|
||||
rlLangs.add("fa"); //$NON-NLS-1$
|
||||
rlLangs.add("iw"); //$NON-NLS-1$
|
||||
rlLangs.add("ur"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the orientation for the given ResourceBundle's localization.
|
||||
*
|
||||
* @param bdl
|
||||
* the ResourceBundle.
|
||||
* @return the ComponentOrientation.
|
||||
* @deprecated Use getOrientation(java.util.Locale) method.
|
||||
*/
|
||||
@Deprecated
|
||||
public static ComponentOrientation getOrientation(ResourceBundle bdl) {
|
||||
Object obj = null;
|
||||
try {
|
||||
obj = bdl.getObject("Orientation"); //$NON-NLS-1$
|
||||
} catch (MissingResourceException mre) {
|
||||
obj = null;
|
||||
}
|
||||
if (obj instanceof ComponentOrientation) {
|
||||
return (ComponentOrientation)obj;
|
||||
}
|
||||
Locale locale = bdl.getLocale();
|
||||
if (locale == null) {
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
return getOrientation(locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the orientation for the specified locale.
|
||||
*
|
||||
* @param locale
|
||||
* the specified Locale.
|
||||
* @return the ComponentOrientation.
|
||||
*/
|
||||
public static ComponentOrientation getOrientation(Locale locale) {
|
||||
String lang = locale.getLanguage();
|
||||
return rlLangs.contains(lang) ? RIGHT_TO_LEFT : LEFT_TO_RIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new component orientation.
|
||||
*
|
||||
* @param hor
|
||||
* whether the items should be arranged horizontally.
|
||||
* @param l2r
|
||||
* whether this orientation specifies a left-to-right flow.
|
||||
*/
|
||||
private ComponentOrientation(boolean hor, boolean l2r) {
|
||||
horizontal = hor;
|
||||
left2right = l2r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the text of the of writing systems arranged horizontally.
|
||||
*
|
||||
* @return true, if the text is written horizontally, false for a vertical
|
||||
* arrangement.
|
||||
*/
|
||||
public boolean isHorizontal() {
|
||||
return horizontal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the text is arranged from left to right.
|
||||
*
|
||||
* @return true, for writing systems written from left to right; false for
|
||||
* right-to-left.
|
||||
*/
|
||||
public boolean isLeftToRight() {
|
||||
return left2right;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Igor V. Stolyarov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.ColorModel;
|
||||
|
||||
/**
|
||||
* The Composite interface allows the methods to compose a draw primitive on the
|
||||
* graphics area. The classes implementing this interface provides the rules and
|
||||
* a method to create the context for a particular operation.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface Composite {
|
||||
|
||||
/**
|
||||
* Creates a CompositeContext which defines the encapsulated and optimized
|
||||
* environment for a compositing operation. Several contexts can exist for a
|
||||
* single Composite object.
|
||||
*
|
||||
* @param srcColorModel
|
||||
* the source's ColorModel.
|
||||
* @param dstColorModel
|
||||
* the destination's ColorModel.
|
||||
* @param hints
|
||||
* the RenderingHints.
|
||||
* @return the CompositeContext object.
|
||||
*/
|
||||
public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel,
|
||||
RenderingHints hints);
|
||||
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Igor V. Stolyarov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
/**
|
||||
* The CompositeContext interface specifies the encapsulated and optimized
|
||||
* environment for a compositing operation.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface CompositeContext {
|
||||
|
||||
/**
|
||||
* Composes the two source Raster objects and places the result in the
|
||||
* destination WritableRaster.
|
||||
*
|
||||
* @param src
|
||||
* the source Raster.
|
||||
* @param dstIn
|
||||
* the destination Raster.
|
||||
* @param dstOut
|
||||
* the WritableRaster object where the result of composing
|
||||
* operation is stored.
|
||||
*/
|
||||
public void compose(Raster src, Raster dstIn, WritableRaster dstOut);
|
||||
|
||||
/**
|
||||
* Releases resources allocated for a context.
|
||||
*/
|
||||
public void dispose();
|
||||
|
||||
}
|
||||
@@ -1,427 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Dmitry A. Durnev
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
import org.apache.harmony.awt.wtk.NativeCursor;
|
||||
|
||||
/**
|
||||
* The Cursor class represents the bitmap of the mouse cursor.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class Cursor implements Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 8028237497568985504L;
|
||||
|
||||
/**
|
||||
* The Constant DEFAULT_CURSOR indicates the default cursor type.
|
||||
*/
|
||||
public static final int DEFAULT_CURSOR = 0;
|
||||
|
||||
/**
|
||||
* The Constant CROSSHAIR_CURSOR cursor type.
|
||||
*/
|
||||
public static final int CROSSHAIR_CURSOR = 1;
|
||||
|
||||
/**
|
||||
* The Constant TEXT_CURSOR cursor type.
|
||||
*/
|
||||
public static final int TEXT_CURSOR = 2;
|
||||
|
||||
/**
|
||||
* The Constant WAIT_CURSOR cursor type.
|
||||
*/
|
||||
public static final int WAIT_CURSOR = 3;
|
||||
|
||||
/**
|
||||
* The Constant SW_RESIZE_CURSOR cursor type.
|
||||
*/
|
||||
public static final int SW_RESIZE_CURSOR = 4;
|
||||
|
||||
/**
|
||||
* The Constant SE_RESIZE_CURSOR cursor type.
|
||||
*/
|
||||
public static final int SE_RESIZE_CURSOR = 5;
|
||||
|
||||
/**
|
||||
* The Constant NW_RESIZE_CURSOR cursor type.
|
||||
*/
|
||||
public static final int NW_RESIZE_CURSOR = 6;
|
||||
|
||||
/**
|
||||
* The Constant NE_RESIZE_CURSOR cursor type.
|
||||
*/
|
||||
public static final int NE_RESIZE_CURSOR = 7;
|
||||
|
||||
/**
|
||||
* The Constant N_RESIZE_CURSOR cursor type.
|
||||
*/
|
||||
public static final int N_RESIZE_CURSOR = 8;
|
||||
|
||||
/**
|
||||
* The Constant S_RESIZE_CURSOR cursor type.
|
||||
*/
|
||||
public static final int S_RESIZE_CURSOR = 9;
|
||||
|
||||
/**
|
||||
* The Constant W_RESIZE_CURSOR cursor type.
|
||||
*/
|
||||
public static final int W_RESIZE_CURSOR = 10;
|
||||
|
||||
/**
|
||||
* The Constant E_RESIZE_CURSOR cursor type.
|
||||
*/
|
||||
public static final int E_RESIZE_CURSOR = 11;
|
||||
|
||||
/**
|
||||
* The Constant HAND_CURSOR cursor type.
|
||||
*/
|
||||
public static final int HAND_CURSOR = 12;
|
||||
|
||||
/**
|
||||
* The Constant MOVE_CURSOR cursor type.
|
||||
*/
|
||||
public static final int MOVE_CURSOR = 13;
|
||||
|
||||
/**
|
||||
* A mapping from names to system custom cursors.
|
||||
*/
|
||||
static Map<String, Cursor> systemCustomCursors;
|
||||
|
||||
/**
|
||||
* The cursor props.
|
||||
*/
|
||||
static Properties cursorProps;
|
||||
|
||||
/**
|
||||
* The Constant predefinedNames.
|
||||
*/
|
||||
static final String[] predefinedNames = {
|
||||
"Default", "Crosshair", "Text", "Wait", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
"Southwest Resize", "Southeast Resize", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
"Northwest Resize", "Northeast Resize", //$NON-NLS-1$ //$NON-NLS-2$
|
||||
"North Resize", "South Resize", "West Resize", "East Resize", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
|
||||
"Hand", "Move" //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* The predefined set of cursors.
|
||||
*/
|
||||
protected static Cursor[] predefined = {
|
||||
new Cursor(DEFAULT_CURSOR), null, null, null, null, null, null, null, null, null, null,
|
||||
null, null, null
|
||||
};
|
||||
|
||||
/**
|
||||
* The Constant CUSTOM_CURSOR is associated with all custom cursor types.
|
||||
* (Those which are not predefined)
|
||||
*/
|
||||
public static final int CUSTOM_CURSOR = -1;
|
||||
|
||||
/**
|
||||
* The name of the cursor.
|
||||
*/
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* The type of the cursor, chosen from the list of cursor type constants.
|
||||
*/
|
||||
private final int type;
|
||||
|
||||
/**
|
||||
* The native cursor.
|
||||
*/
|
||||
private transient NativeCursor nativeCursor;
|
||||
|
||||
/**
|
||||
* The exact point on the cursor image that indicates which point the cursor
|
||||
* is selecting (pointing to). The coordinates are given with respect the
|
||||
* origin of the Image (its upper left corner).
|
||||
*/
|
||||
private Point hotSpot;
|
||||
|
||||
/**
|
||||
* The image to draw on the screen representing the cursor.
|
||||
*/
|
||||
private Image image;
|
||||
|
||||
/**
|
||||
* Instantiates a new cursor with the specified name.
|
||||
*
|
||||
* @param name
|
||||
* the name of cursor.
|
||||
*/
|
||||
protected Cursor(String name) {
|
||||
this(name, null, new Point());
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new cursor of the specified type.
|
||||
*
|
||||
* @param type
|
||||
* the type of cursor.
|
||||
*/
|
||||
public Cursor(int type) {
|
||||
checkType(type);
|
||||
this.type = type;
|
||||
if ((type >= 0) && (type < predefinedNames.length)) {
|
||||
name = predefinedNames[type] + " Cursor"; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new cursor.
|
||||
*
|
||||
* @param name
|
||||
* the name.
|
||||
* @param img
|
||||
* the img.
|
||||
* @param hotSpot
|
||||
* the hot spot.
|
||||
*/
|
||||
Cursor(String name, Image img, Point hotSpot) {
|
||||
this.name = name;
|
||||
type = CUSTOM_CURSOR;
|
||||
this.hotSpot = hotSpot;
|
||||
image = img;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize method overrides the finalize method from Object class.
|
||||
*
|
||||
* @throws Throwable
|
||||
* if the native cursor is not null and throws a Throwable when
|
||||
* destroyed.
|
||||
*/
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
if (nativeCursor != null) {
|
||||
nativeCursor.destroyCursor();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the cursor.
|
||||
*
|
||||
* @return the name of the cursor.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the String representation of the cursor.
|
||||
*
|
||||
* @return the String representation of the cursor.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getName() + "[" + name + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cursor type.
|
||||
*
|
||||
* @return the cursor type.
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the predefined cursor with the specified type.
|
||||
*
|
||||
* @param type
|
||||
* the type of cursor.
|
||||
* @return the predefined cursor with the specified type.
|
||||
*/
|
||||
public static Cursor getPredefinedCursor(int type) {
|
||||
checkType(type);
|
||||
Cursor cursor = predefined[type];
|
||||
if (cursor == null) {
|
||||
cursor = new Cursor(type);
|
||||
predefined[type] = cursor;
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default cursor.
|
||||
*
|
||||
* @return the default cursor.
|
||||
*/
|
||||
public static Cursor getDefaultCursor() {
|
||||
return getPredefinedCursor(DEFAULT_CURSOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the specified system custom cursor.
|
||||
*
|
||||
* @param name
|
||||
* the name of the desired system cursor.
|
||||
* @return the specific system cursor with the specified name.
|
||||
* @throws AWTException
|
||||
* if the desired cursor has malformed data such as an
|
||||
* incorrectly defined hot spot.
|
||||
* @throws HeadlessException
|
||||
* if the isHeadless method of the GraphicsEnvironment returns
|
||||
* true.
|
||||
*/
|
||||
public static Cursor getSystemCustomCursor(String name) throws AWTException, HeadlessException {
|
||||
Toolkit.checkHeadless();
|
||||
return getSystemCustomCursorFromMap(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the specified system custom cursor from the map of system custom
|
||||
* cursors.
|
||||
*
|
||||
* @param name
|
||||
* the name of the desired cursor.
|
||||
* @return the desired system custom cursor from the map of system custom
|
||||
* cursors.
|
||||
* @throws AWTException
|
||||
* the AWT exception.
|
||||
*/
|
||||
private static Cursor getSystemCustomCursorFromMap(String name) throws AWTException {
|
||||
loadCursorProps();
|
||||
if (systemCustomCursors == null) {
|
||||
systemCustomCursors = new HashMap<String, Cursor>();
|
||||
}
|
||||
Cursor cursor = systemCustomCursors.get(name);
|
||||
if (cursor != null) {
|
||||
return cursor;
|
||||
}
|
||||
// awt.141=failed to parse hotspot property for cursor:
|
||||
String exMsg = Messages.getString("awt.141") + name; //$NON-NLS-1$
|
||||
String nm = "Cursor." + name; //$NON-NLS-1$
|
||||
String nameStr = cursorProps.getProperty(nm + ".Name"); //$NON-NLS-1$
|
||||
String hotSpotStr = cursorProps.getProperty(nm + ".HotSpot"); //$NON-NLS-1$
|
||||
String fileStr = cursorProps.getProperty(nm + ".File"); //$NON-NLS-1$
|
||||
int idx = hotSpotStr.indexOf(',');
|
||||
if (idx < 0) {
|
||||
throw new AWTException(exMsg);
|
||||
}
|
||||
int x, y;
|
||||
try {
|
||||
x = new Integer(hotSpotStr.substring(0, idx)).intValue();
|
||||
y = new Integer(hotSpotStr.substring(idx + 1, hotSpotStr.length())).intValue();
|
||||
} catch (NumberFormatException nfe) {
|
||||
throw new AWTException(exMsg);
|
||||
}
|
||||
Image img = Toolkit.getDefaultToolkit().createImage(fileStr);
|
||||
cursor = new Cursor(nameStr, img, new Point(x, y));
|
||||
systemCustomCursors.put(name, cursor);
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load cursor props.
|
||||
*
|
||||
* @throws AWTException
|
||||
* the AWT exception.
|
||||
*/
|
||||
private static void loadCursorProps() throws AWTException {
|
||||
if (cursorProps != null) {
|
||||
return;
|
||||
}
|
||||
String sep = File.separator;
|
||||
String cursorsDir = "lib" + sep + "images" + sep + "cursors"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
String cursorsAbsDir = System.getProperty("java.home") + sep + //$NON-NLS-1$
|
||||
cursorsDir;
|
||||
String cursorPropsFileName = "cursors.properties"; //$NON-NLS-1$
|
||||
String cursorPropsFullFileName = (cursorsAbsDir + sep + cursorPropsFileName);
|
||||
cursorProps = new Properties();
|
||||
try {
|
||||
cursorProps.load(new FileInputStream(new File(cursorPropsFullFileName)));
|
||||
} catch (FileNotFoundException e) {
|
||||
// awt.142=Exception: class {0} {1} occurred while loading: {2}
|
||||
throw new AWTException(Messages.getString("awt.142",//$NON-NLS-1$
|
||||
new Object[] {
|
||||
e.getClass(), e.getMessage(), cursorPropsFullFileName
|
||||
}));
|
||||
} catch (IOException e) {
|
||||
throw new AWTException(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check type.
|
||||
*
|
||||
* @param type
|
||||
* the type.
|
||||
*/
|
||||
static void checkType(int type) {
|
||||
// can't use predefined array here because it may not have been
|
||||
// initialized yet
|
||||
if ((type < 0) || (type >= predefinedNames.length)) {
|
||||
// awt.143=illegal cursor type
|
||||
throw new IllegalArgumentException(Messages.getString("awt.143")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
// "lazily" create native cursors:
|
||||
/**
|
||||
* Gets the native cursor.
|
||||
*
|
||||
* @return the native cursor.
|
||||
*/
|
||||
NativeCursor getNativeCursor() {
|
||||
if (nativeCursor != null) {
|
||||
return nativeCursor;
|
||||
}
|
||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
if (type != CUSTOM_CURSOR) {
|
||||
nativeCursor = toolkit.createNativeCursor(type);
|
||||
} else {
|
||||
nativeCursor = toolkit.createCustomNativeCursor(image, hotSpot, name);
|
||||
}
|
||||
return nativeCursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the native cursor.
|
||||
*
|
||||
* @param nativeCursor
|
||||
* the new native cursor.
|
||||
*/
|
||||
void setNativeCursor(NativeCursor nativeCursor) {
|
||||
this.nativeCursor = nativeCursor;
|
||||
}
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Denis M. Kishenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.Dimension2D;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.harmony.misc.HashCode;
|
||||
|
||||
/**
|
||||
* The Dimension represents the size (width and height) of a component. The
|
||||
* width and height values can be negative, but in that case the behavior of
|
||||
* some methods is unexpected.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class Dimension extends Dimension2D implements Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 4723952579491349524L;
|
||||
|
||||
/**
|
||||
* The width dimension.
|
||||
*/
|
||||
public int width;
|
||||
|
||||
/**
|
||||
* The height dimension.
|
||||
*/
|
||||
public int height;
|
||||
|
||||
/**
|
||||
* Instantiates a new Dimension with the same data as the specified
|
||||
* Dimension.
|
||||
*
|
||||
* @param d
|
||||
* the Dimension to copy the data from when creating the new
|
||||
* Dimension object.
|
||||
*/
|
||||
public Dimension(Dimension d) {
|
||||
this(d.width, d.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Dimension with zero width and height.
|
||||
*/
|
||||
public Dimension() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new Dimension with the specified width and height.
|
||||
*
|
||||
* @param width
|
||||
* the width of the new Dimension.
|
||||
* @param height
|
||||
* the height of the new Dimension.
|
||||
*/
|
||||
public Dimension(int width, int height) {
|
||||
setSize(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash code of the Dimension.
|
||||
*
|
||||
* @return the hash code of the Dimension.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
HashCode hash = new HashCode();
|
||||
hash.append(width);
|
||||
hash.append(height);
|
||||
return hash.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares this Dimension object with the specified object.
|
||||
*
|
||||
* @param obj
|
||||
* the Object to be compared.
|
||||
* @return true, if the specified Object is a Dimension with the same width
|
||||
* and height data as this Dimension.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof Dimension) {
|
||||
Dimension d = (Dimension)obj;
|
||||
return (d.width == width && d.height == height);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the String associated to this Dimension object.
|
||||
*
|
||||
* @return the String associated to this Dimension object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// The output format based on 1.5 release behaviour. It could be
|
||||
// obtained in the following way
|
||||
// System.out.println(new Dimension().toString())
|
||||
return getClass().getName() + "[width=" + width + ",height=" + height + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of this Dimension object with the specified width and
|
||||
* height.
|
||||
*
|
||||
* @param width
|
||||
* the width of the Dimension.
|
||||
* @param height
|
||||
* the height of the Dimension.
|
||||
*/
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of this Dimension object by copying the data from the
|
||||
* specified Dimension object.
|
||||
*
|
||||
* @param d
|
||||
* the Dimension that gives the new size values.
|
||||
*/
|
||||
public void setSize(Dimension d) {
|
||||
setSize(d.width, d.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of this Dimension object with the specified double width
|
||||
* and height.
|
||||
*
|
||||
* @param width
|
||||
* the width of the Dimension.
|
||||
* @param height
|
||||
* the height of the Dimension.
|
||||
* @see java.awt.geom.Dimension2D#setSize(double, double)
|
||||
*/
|
||||
@Override
|
||||
public void setSize(double width, double height) {
|
||||
setSize((int)Math.ceil(width), (int)Math.ceil(height));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the Dimension.
|
||||
*
|
||||
* @return the size of the Dimension.
|
||||
*/
|
||||
public Dimension getSize() {
|
||||
return new Dimension(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height of the Dimension.
|
||||
*
|
||||
* @return the height of the Dimension.
|
||||
* @see java.awt.geom.Dimension2D#getHeight()
|
||||
*/
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the Dimension.
|
||||
*
|
||||
* @return the width of the Dimension.
|
||||
* @see java.awt.geom.Dimension2D#getWidth()
|
||||
*/
|
||||
@Override
|
||||
public double getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,723 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov, Dmitry A. Durnev
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
import org.apache.harmony.awt.wtk.NativeEvent;
|
||||
import org.apache.harmony.awt.wtk.NativeWindow;
|
||||
|
||||
|
||||
/**
|
||||
* Helper package-private class for managing lightweight components &
|
||||
* dispatching events from heavyweight source
|
||||
*/
|
||||
class Dispatcher {
|
||||
|
||||
//???AWT: final PopupDispatcher popupDispatcher = new PopupDispatcher();
|
||||
|
||||
//???AWT: final FocusDispatcher focusDispatcher;
|
||||
|
||||
final MouseGrabManager mouseGrabManager = new MouseGrabManager();
|
||||
|
||||
final MouseDispatcher mouseDispatcher;
|
||||
|
||||
private final ComponentDispatcher componentDispatcher = new ComponentDispatcher();
|
||||
|
||||
private final KeyDispatcher keyDispatcher = new KeyDispatcher();
|
||||
|
||||
private final Toolkit toolkit;
|
||||
|
||||
int clickInterval = 250;
|
||||
|
||||
/**
|
||||
* @param toolkit - AWT toolkit
|
||||
*/
|
||||
Dispatcher(Toolkit toolkit) {
|
||||
this.toolkit = toolkit;
|
||||
|
||||
//???AWT: focusDispatcher = new FocusDispatcher(toolkit);
|
||||
mouseDispatcher = new MouseDispatcher(mouseGrabManager, toolkit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatch native event: produce appropriate AWT events,
|
||||
* update component's fields when needed
|
||||
* @param event - native event to dispatch
|
||||
* @return - true means default processing by OS is not needed
|
||||
*/
|
||||
public boolean onEvent(NativeEvent event) {
|
||||
int eventId = event.getEventId();
|
||||
|
||||
if (eventId == NativeEvent.ID_CREATED) {
|
||||
return toolkit.onWindowCreated(event.getWindowId());
|
||||
} else if (eventId == NativeEvent.ID_MOUSE_GRAB_CANCELED) {
|
||||
return mouseGrabManager.onGrabCanceled();
|
||||
//???AWT
|
||||
// } else if (popupDispatcher.onEvent(event)) {
|
||||
// return false;
|
||||
} else {
|
||||
Component src = toolkit.getComponentById(event.getWindowId());
|
||||
|
||||
if (src != null) {
|
||||
if (((eventId >= ComponentEvent.COMPONENT_FIRST) && (eventId <= ComponentEvent.COMPONENT_LAST))
|
||||
|| ((eventId >= WindowEvent.WINDOW_FIRST) && (eventId <= WindowEvent.WINDOW_LAST))
|
||||
|| (eventId == NativeEvent.ID_INSETS_CHANGED)
|
||||
|| (eventId == NativeEvent.ID_BOUNDS_CHANGED)
|
||||
|| (eventId == NativeEvent.ID_THEME_CHANGED)) {
|
||||
return componentDispatcher.dispatch(src, event);
|
||||
} else if ((eventId >= MouseEvent.MOUSE_FIRST)
|
||||
&& (eventId <= MouseEvent.MOUSE_LAST)) {
|
||||
return mouseDispatcher.dispatch(src, event);
|
||||
} else if (eventId == PaintEvent.PAINT) {
|
||||
//???AWT: src.redrawManager.addPaintRegion(src, event.getClipRects());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ((eventId >= FocusEvent.FOCUS_FIRST)
|
||||
&& (eventId <= FocusEvent.FOCUS_LAST)) {
|
||||
|
||||
//???AWT: return focusDispatcher.dispatch(src, event);
|
||||
return false;
|
||||
} else if ((eventId >= KeyEvent.KEY_FIRST)
|
||||
&& (eventId <= KeyEvent.KEY_LAST)) {
|
||||
return keyDispatcher.dispatch(src, event);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dispatcher of native events that affect
|
||||
* component's state or bounds
|
||||
*/
|
||||
final class ComponentDispatcher {
|
||||
|
||||
/**
|
||||
* Handle native event that affects component's state or bounds
|
||||
* @param src - the component updated by the event
|
||||
* @param event - the native event
|
||||
* @return - as in Dispatcher.onEvent()
|
||||
* @see Dispatcher#onEvent(NativeEvent)
|
||||
*/
|
||||
boolean dispatch(Component src, NativeEvent event) {
|
||||
int id = event.getEventId();
|
||||
|
||||
if ((id == NativeEvent.ID_INSETS_CHANGED)
|
||||
|| (id == NativeEvent.ID_THEME_CHANGED)) {
|
||||
return dispatchInsets(event, src);
|
||||
} else if ((id >= WindowEvent.WINDOW_FIRST)
|
||||
&& (id <= WindowEvent.WINDOW_LAST)) {
|
||||
return dispatchWindow(event, src);
|
||||
} else {
|
||||
return dispatchPureComponent(event, src);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the change of top-level window's native decorations
|
||||
* @param event - the native event
|
||||
* @param src - the component updated by the event
|
||||
* @return - as in Dispatcher.onEvent()
|
||||
* @see Dispatcher#onEvent(NativeEvent)
|
||||
*/
|
||||
boolean dispatchInsets(NativeEvent event, Component src) {
|
||||
//???AWT
|
||||
/*
|
||||
if (src instanceof Window) {
|
||||
((Window) src).setNativeInsets(event.getInsets());
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the change of top-level window's state
|
||||
* @param event - the native event
|
||||
* @param src - the component updated by the event
|
||||
* @return - as in Dispatcher.onEvent()
|
||||
* @see Dispatcher#onEvent(NativeEvent)
|
||||
*/
|
||||
boolean dispatchWindow(NativeEvent event, Component src) {
|
||||
//???AWT
|
||||
/*
|
||||
Window window = (Window) src;
|
||||
int id = event.getEventId();
|
||||
|
||||
if (id == WindowEvent.WINDOW_CLOSING) {
|
||||
toolkit.getSystemEventQueueImpl().postEvent(
|
||||
new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
|
||||
|
||||
return true;
|
||||
} else if (id == WindowEvent.WINDOW_STATE_CHANGED) {
|
||||
if (window instanceof Frame) {
|
||||
((Frame) window)
|
||||
.updateExtendedState(event.getWindowState());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the change of component's size and/or position
|
||||
* @param event - the native event
|
||||
* @param src - the component updated by the event
|
||||
* @return - as in Dispatcher.onEvent()
|
||||
* @see Dispatcher#onEvent(NativeEvent)
|
||||
*/
|
||||
private boolean dispatchPureComponent(NativeEvent event, Component src) {
|
||||
Rectangle rect = event.getWindowRect();
|
||||
Point loc = rect.getLocation();
|
||||
int mask;
|
||||
|
||||
switch (event.getEventId()) {
|
||||
case NativeEvent.ID_BOUNDS_CHANGED:
|
||||
mask = 0;
|
||||
break;
|
||||
case ComponentEvent.COMPONENT_MOVED:
|
||||
mask = NativeWindow.BOUNDS_NOSIZE;
|
||||
break;
|
||||
case ComponentEvent.COMPONENT_RESIZED:
|
||||
mask = NativeWindow.BOUNDS_NOMOVE;
|
||||
break;
|
||||
default:
|
||||
// awt.12E=Unknown component event id.
|
||||
throw new RuntimeException(Messages.getString("awt.12E")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
//???AWT
|
||||
/*
|
||||
if (!(src instanceof Window)) {
|
||||
Component compTo = src.getParent();
|
||||
Component compFrom = src.getHWAncestor();
|
||||
|
||||
if ((compTo != null) && (compFrom != null)) {
|
||||
loc = MouseDispatcher.convertPoint(compFrom, loc, compTo);
|
||||
}
|
||||
} else {
|
||||
int windowState = event.getWindowState();
|
||||
|
||||
if ((windowState >= 0) && (src instanceof Frame)) {
|
||||
((Frame) src).updateExtendedState(windowState);
|
||||
}
|
||||
}
|
||||
src.setBounds(loc.x, loc.y, rect.width, rect.height, mask, false);
|
||||
*/
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The dispatcher of the keyboard events
|
||||
*/
|
||||
final class KeyDispatcher {
|
||||
|
||||
/**
|
||||
* Handle the keyboard event using the KeyboardFocusManager
|
||||
* @param src - the component receiving the event
|
||||
* @param event - the native event
|
||||
* @return - as in Dispatcher.onEvent()
|
||||
* @see Dispatcher#onEvent(NativeEvent)
|
||||
*/
|
||||
boolean dispatch(Component src, NativeEvent event) {
|
||||
int id = event.getEventId();
|
||||
int modifiers = event.getInputModifiers();
|
||||
int location = event.getKeyLocation();
|
||||
int code = event.getVKey();
|
||||
StringBuffer chars = event.getKeyChars();
|
||||
int charsLength = chars.length();
|
||||
long time = event.getTime();
|
||||
char keyChar = event.getLastChar();
|
||||
|
||||
//???AWT
|
||||
/*
|
||||
if (src == null) {
|
||||
//retarget focus proxy key events to focusOwner:
|
||||
Window focusProxyOwner = toolkit.getFocusProxyOwnerById(event
|
||||
.getWindowId());
|
||||
if (focusProxyOwner == null) {
|
||||
return false;
|
||||
}
|
||||
src = KeyboardFocusManager.actualFocusOwner;
|
||||
}
|
||||
*/
|
||||
|
||||
EventQueue eventQueue = toolkit.getSystemEventQueueImpl();
|
||||
|
||||
if (src != null) {
|
||||
eventQueue.postEvent(new KeyEvent(src, id, time, modifiers,
|
||||
code, keyChar, location));
|
||||
// KEY_TYPED goes after KEY_PRESSED
|
||||
if (id == KeyEvent.KEY_PRESSED) {
|
||||
for (int i = 0; i < charsLength; i++) {
|
||||
keyChar = chars.charAt(i);
|
||||
if (keyChar != KeyEvent.CHAR_UNDEFINED) {
|
||||
eventQueue.postEvent(new KeyEvent(src,
|
||||
KeyEvent.KEY_TYPED, time, modifiers,
|
||||
KeyEvent.VK_UNDEFINED, keyChar,
|
||||
KeyEvent.KEY_LOCATION_UNKNOWN));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retargets the mouse events to the grab owner when mouse is grabbed,
|
||||
* grab and ungrab mouse when mouse buttons are pressed and released
|
||||
*/
|
||||
|
||||
static final class MouseGrabManager {
|
||||
|
||||
/**
|
||||
* The top-level window holding the mouse grab
|
||||
* that was explicitly started by startGrab() method
|
||||
*/
|
||||
//???AWT: private Window nativeGrabOwner = null;
|
||||
/**
|
||||
* The component that owns the synthetic
|
||||
* mouse grab while at least one of the
|
||||
* mouse buttons is pressed
|
||||
*/
|
||||
private Component syntheticGrabOwner = null;
|
||||
|
||||
/**
|
||||
* Previous value of syntheticGrabOwner
|
||||
*/
|
||||
private Component lastSyntheticGrabOwner = null;
|
||||
|
||||
/**
|
||||
* Number of mouse buttons currently pressed
|
||||
*/
|
||||
private int syntheticGrabDepth = 0;
|
||||
|
||||
/**
|
||||
* The callback to be called when the explicit mouse grab ends
|
||||
*/
|
||||
private Runnable whenCanceled;
|
||||
|
||||
/**
|
||||
* Explicitly start the mouse grab
|
||||
* @param grabWindow - the window that will own the grab
|
||||
* @param whenCanceled - the callback to call when the grab ends.
|
||||
* This parameter can be null
|
||||
*/
|
||||
//???AWT
|
||||
/*
|
||||
void startGrab(Window grabWindow, Runnable whenCanceled) {
|
||||
|
||||
if (nativeGrabOwner != null) {
|
||||
// awt.12F=Attempt to start nested mouse grab
|
||||
throw new RuntimeException(Messages.getString("awt.12F")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
NativeWindow win = grabWindow.getNativeWindow();
|
||||
if (win == null) {
|
||||
// awt.130=Attempt to grab mouse in not displayable window
|
||||
throw new RuntimeException(Messages.getString("awt.130")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
nativeGrabOwner = grabWindow;
|
||||
this.whenCanceled = whenCanceled;
|
||||
win.grabMouse();
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Ends the explicit mouse grab. If the non-null callback was provided
|
||||
* in the startGrab() method, this callback is called
|
||||
*/
|
||||
void endGrab() {
|
||||
//???AWT
|
||||
/*
|
||||
if (nativeGrabOwner == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Window grabWindow = nativeGrabOwner;
|
||||
nativeGrabOwner = null;
|
||||
NativeWindow win = grabWindow.getNativeWindow();
|
||||
|
||||
if (win != null) {
|
||||
win.ungrabMouse();
|
||||
if (whenCanceled != null) {
|
||||
whenCanceled.run();
|
||||
whenCanceled = null;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends both explicit and synthetic grans
|
||||
* @return - always returns false
|
||||
*/
|
||||
boolean onGrabCanceled() {
|
||||
endGrab();
|
||||
resetSyntheticGrab();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the synthetic mouse grab, increases the counter
|
||||
* of currently pressed mouse buttons
|
||||
* @param source - the component where mouse press event occured
|
||||
* @return - the component that owns the synthetic grab
|
||||
*/
|
||||
Component onMousePressed(Component source) {
|
||||
if (syntheticGrabDepth == 0) {
|
||||
syntheticGrabOwner = source;
|
||||
lastSyntheticGrabOwner = source;
|
||||
}
|
||||
syntheticGrabDepth++;
|
||||
|
||||
return syntheticGrabOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decreases the counter of currently pressed mouse buttons,
|
||||
* ends the synthetic mouse grab, when this counter becomes zero
|
||||
* @param source - the component where mouse press event occured
|
||||
* @return - the component that owns the synthetic grab,
|
||||
* or source parameter if mouse grab was released
|
||||
*/
|
||||
Component onMouseReleased(Component source) {
|
||||
Component ret = source;
|
||||
|
||||
//???AWT
|
||||
/*
|
||||
if (syntheticGrabOwner != null && nativeGrabOwner == null) {
|
||||
ret = syntheticGrabOwner;
|
||||
}
|
||||
*/
|
||||
syntheticGrabDepth--;
|
||||
if (syntheticGrabDepth <= 0) {
|
||||
resetSyntheticGrab();
|
||||
lastSyntheticGrabOwner = null;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the state of synthetic ouse gram
|
||||
* when the mouse is moved/dragged
|
||||
* @param event - the native event
|
||||
*/
|
||||
void preprocessEvent(NativeEvent event) {
|
||||
int id = event.getEventId();
|
||||
switch (id) {
|
||||
case MouseEvent.MOUSE_MOVED:
|
||||
if (syntheticGrabOwner != null) {
|
||||
syntheticGrabOwner = null;
|
||||
syntheticGrabDepth = 0;
|
||||
}
|
||||
if (lastSyntheticGrabOwner != null) {
|
||||
lastSyntheticGrabOwner = null;
|
||||
}
|
||||
case MouseEvent.MOUSE_DRAGGED:
|
||||
if (syntheticGrabOwner == null
|
||||
&& lastSyntheticGrabOwner != null) {
|
||||
syntheticGrabOwner = lastSyntheticGrabOwner;
|
||||
syntheticGrabDepth = 0;
|
||||
int mask = event.getInputModifiers();
|
||||
syntheticGrabDepth += (mask & InputEvent.BUTTON1_DOWN_MASK) != 0 ? 1
|
||||
: 0;
|
||||
syntheticGrabDepth += (mask & InputEvent.BUTTON2_DOWN_MASK) != 0 ? 1
|
||||
: 0;
|
||||
syntheticGrabDepth += (mask & InputEvent.BUTTON3_DOWN_MASK) != 0 ? 1
|
||||
: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the component that currently owns the synthetic grab
|
||||
*/
|
||||
Component getSyntheticGrabOwner() {
|
||||
return syntheticGrabOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* ends synthetic grab
|
||||
*/
|
||||
private void resetSyntheticGrab() {
|
||||
syntheticGrabOwner = null;
|
||||
syntheticGrabDepth = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches native events related to the pop-up boxes
|
||||
* (the non-component windows such as menus and drop lists)
|
||||
*/
|
||||
// final class PopupDispatcher {
|
||||
//
|
||||
// private PopupBox activePopup;
|
||||
//
|
||||
// private PopupBox underCursor;
|
||||
//
|
||||
// private final MouseGrab grab = new MouseGrab();
|
||||
//
|
||||
// /**
|
||||
// * Handles the mouse grab for pop-up boxes
|
||||
// */
|
||||
// private final class MouseGrab {
|
||||
// private int depth;
|
||||
//
|
||||
// private PopupBox owner;
|
||||
//
|
||||
// private final Point start = new Point();
|
||||
//
|
||||
// /**
|
||||
// * Starts the grab when mouse is pressed
|
||||
// * @param src - the pop-up box where mouse event has occured
|
||||
// * @param where - the mouse pointer location
|
||||
// * @return - the grab owner
|
||||
// */
|
||||
// PopupBox mousePressed(PopupBox src, Point where) {
|
||||
// if (depth == 0) {
|
||||
// owner = src;
|
||||
// start.setLocation(where);
|
||||
// }
|
||||
// depth++;
|
||||
// return owner;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Ends the grab when all mousebuttons are released
|
||||
// * @param src - the pop-up box where mouse event has occured
|
||||
// * @param where - the mouse pointer location
|
||||
// * @return - the grab owner, or src parameter if the grab has ended
|
||||
// */
|
||||
// PopupBox mouseReleased(PopupBox src, Point where) {
|
||||
// PopupBox ret = (owner != null) ? owner : src;
|
||||
// if (depth == 0) {
|
||||
// return ret;
|
||||
// }
|
||||
// depth--;
|
||||
// if (depth == 0) {
|
||||
// PopupBox tgt = owner;
|
||||
// owner = null;
|
||||
// if (tgt != null && src == null) {
|
||||
// Point a = new Point(start);
|
||||
// Point b = new Point(where);
|
||||
// Point pos = tgt.getScreenLocation();
|
||||
// a.translate(-pos.x, -pos.y);
|
||||
// b.translate(-pos.x, -pos.y);
|
||||
// if (tgt.closeOnUngrab(a, b)) {
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return ret;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Set the grab owner to null
|
||||
// */
|
||||
// void reset() {
|
||||
// depth = 0;
|
||||
// owner = null;
|
||||
// start.setLocation(0, 0);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return - the pop-up box currently owning the grab
|
||||
// */
|
||||
// public PopupBox getOwner() {
|
||||
// return owner;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Call the mouse event handler of the pop-up box
|
||||
// * @param src - the pop-up box where the mouse event occured
|
||||
// * @param eventId - the event ID, one of MouseEvent.MOUSE_* constants
|
||||
// * @param where - the mouse pointer location
|
||||
// * @param event - native event
|
||||
// */
|
||||
// private void mouseEvent(PopupBox src, int eventId, Point where,
|
||||
// NativeEvent event) {
|
||||
// Point pos = src.getScreenLocation();
|
||||
// pos.setLocation(where.x - pos.x, where.y - pos.y);
|
||||
//
|
||||
// src.onMouseEvent(eventId, pos, event.getMouseButton(), event
|
||||
// .getTime(), event.getInputModifiers(), event
|
||||
// .getWheelRotation());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Handle the native event targeted by a pop-up box. This could be
|
||||
// * paint event, mouse or keyboard event.
|
||||
// * @param event - the native event
|
||||
// * @return - false if the event was handled and doesn't
|
||||
// * need the further processing; true when the further
|
||||
// * processing is needed
|
||||
// */
|
||||
// boolean onEvent(NativeEvent event) {
|
||||
// PopupBox src = toolkit.getPopupBoxById(event.getWindowId());
|
||||
// int id = event.getEventId();
|
||||
//
|
||||
// if ((id == PaintEvent.PAINT)) {
|
||||
// if (src != null) {
|
||||
// src.paint(event.getClipRects());
|
||||
// return true;
|
||||
// }
|
||||
// Component c = toolkit.getComponentById(event.getWindowId());
|
||||
// if ((c != null) && (c instanceof Frame)) {
|
||||
// ((Frame) c).paintMenuBar(event.getClipRects());
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if ((id >= MouseEvent.MOUSE_FIRST) && (id <= MouseEvent.MOUSE_LAST)) {
|
||||
// Point where = event.getScreenPos();
|
||||
//
|
||||
// if (src != underCursor) {
|
||||
// if (underCursor != null) {
|
||||
// mouseEvent(underCursor, MouseEvent.MOUSE_EXITED, where,
|
||||
// event);
|
||||
// }
|
||||
// underCursor = src;
|
||||
// if (underCursor != null) {
|
||||
// mouseEvent(underCursor, MouseEvent.MOUSE_ENTERED,
|
||||
// where, event);
|
||||
// underCursor.setDefaultCursor();
|
||||
// }
|
||||
// }
|
||||
// if (id == MouseEvent.MOUSE_EXITED) {
|
||||
// underCursor = null;
|
||||
// }
|
||||
//
|
||||
// if ((activePopup == null) && (src == null || !src.isMenuBar())) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if (id == MouseEvent.MOUSE_PRESSED) {
|
||||
// src = grab.mousePressed(src, where);
|
||||
// } else if (id == MouseEvent.MOUSE_RELEASED) {
|
||||
// src = grab.mouseReleased(src, where);
|
||||
// } else if (src == null) {
|
||||
// src = grab.getOwner();
|
||||
// }
|
||||
//
|
||||
// PopupBox wasActive = activePopup;
|
||||
//
|
||||
// if (src != null) {
|
||||
// mouseEvent(src, id, where, event);
|
||||
// return src.isMenu() || src.contains(where);
|
||||
// }
|
||||
//
|
||||
// if (wasActive != null && activePopup == null) {
|
||||
// return wasActive.isMenu();
|
||||
// }
|
||||
//
|
||||
// if ((id == MouseEvent.MOUSE_PRESSED)
|
||||
// || (id == MouseEvent.MOUSE_RELEASED)) {
|
||||
// boolean isMenu = activePopup.isMenu();
|
||||
// deactivateAll();
|
||||
// return !isMenu;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// if (activePopup == null) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// if ((id >= KeyEvent.KEY_FIRST) && (id <= KeyEvent.KEY_LAST)) {
|
||||
// boolean isMenu = activePopup.isMenu();
|
||||
// activePopup.dispatchKeyEvent(id, event.getVKey(), event
|
||||
// .getTime(), event.getInputModifiers());
|
||||
//
|
||||
// return isMenu;
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Remember the pop-up as active and grab the mouse on it
|
||||
// * @param popup - the pop-up box to activate
|
||||
// */
|
||||
// void activate(final PopupBox popup) {
|
||||
// if (activePopup == null) {
|
||||
//
|
||||
// activePopup = popup;
|
||||
// mouseGrabManager.startGrab(popup.getOwner(), new Runnable() {
|
||||
// public void run() {
|
||||
// deactivate(popup);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Deactivate the currently active pop-up box
|
||||
// */
|
||||
// void deactivateAll() {
|
||||
// deactivate(activePopup);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Deactivate the pop-up box, end the mouse grab
|
||||
// */
|
||||
// void deactivate(PopupBox popup) {
|
||||
// grab.reset();
|
||||
//
|
||||
// if (activePopup != null && activePopup == popup) {
|
||||
// activePopup = null;
|
||||
// mouseGrabManager.endGrab();
|
||||
// popup.hide();
|
||||
// underCursor = null;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Check that the pop-up box is currently active
|
||||
// * @param popup - the pop-up box to check
|
||||
// * @return - true if active
|
||||
// */
|
||||
// boolean isActive(PopupBox popup) {
|
||||
// return (popup == activePopup) && (popup != null);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The DisplayMode class contains the bit depth, height, width and refresh rate
|
||||
* of a GraphicsDevice.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public final class DisplayMode {
|
||||
|
||||
/**
|
||||
* The width.
|
||||
*/
|
||||
private final int width;
|
||||
|
||||
/**
|
||||
* The height.
|
||||
*/
|
||||
private final int height;
|
||||
|
||||
/**
|
||||
* The bit depth.
|
||||
*/
|
||||
private final int bitDepth;
|
||||
|
||||
/**
|
||||
* The refresh rate.
|
||||
*/
|
||||
private final int refreshRate;
|
||||
|
||||
/**
|
||||
* The Constant Value BIT_DEPTH_MULTI indicates the bit depth
|
||||
*/
|
||||
|
||||
public static final int BIT_DEPTH_MULTI = -1;
|
||||
|
||||
/**
|
||||
* The Constant REFRESH_RATE_UNKNOWN indicates the refresh rate.
|
||||
*/
|
||||
public static final int REFRESH_RATE_UNKNOWN = 0;
|
||||
|
||||
/**
|
||||
* Creates a new DisplayMode object with the specified parameters.
|
||||
*
|
||||
* @param width
|
||||
* the width of the display.
|
||||
* @param height
|
||||
* the height of the display.
|
||||
* @param bitDepth
|
||||
* the bit depth of the display.
|
||||
* @param refreshRate
|
||||
* the refresh rate of the display.
|
||||
*/
|
||||
|
||||
public DisplayMode(int width, int height, int bitDepth, int refreshRate) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.bitDepth = bitDepth;
|
||||
this.refreshRate = refreshRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares if this DisplayMode is equal to the specified object or not.
|
||||
*
|
||||
* @param dm
|
||||
* the Object to be compared.
|
||||
* @return true, if the specified object is a DisplayMode with the same data
|
||||
* values as this DisplayMode, false otherwise.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean equals(Object dm) {
|
||||
if (dm instanceof DisplayMode) {
|
||||
return equals((DisplayMode)dm);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares if this DisplayMode is equal to the specified DisplayMode object
|
||||
* or not.
|
||||
*
|
||||
* @param dm
|
||||
* the DisplayMode to be compared.
|
||||
* @return true, if all of the data values of this DisplayMode are equal to
|
||||
* the values of the specified DisplayMode object, false otherwise.
|
||||
*/
|
||||
public boolean equals(DisplayMode dm) {
|
||||
if (dm == null) {
|
||||
return false;
|
||||
}
|
||||
if (dm.bitDepth != bitDepth) {
|
||||
return false;
|
||||
}
|
||||
if (dm.refreshRate != refreshRate) {
|
||||
return false;
|
||||
}
|
||||
if (dm.width != width) {
|
||||
return false;
|
||||
}
|
||||
if (dm.height != height) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bit depth of the DisplayMode, returns BIT_DEPTH_MULTI value if
|
||||
* multiple bit depths are supported in this display mode.
|
||||
*
|
||||
* @return the bit depth of the DisplayMode.
|
||||
*/
|
||||
public int getBitDepth() {
|
||||
return bitDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height of the DisplayMode.
|
||||
*
|
||||
* @return the height of the DisplayMode.
|
||||
*/
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the refresh rate of the DisplayMode, returns REFRESH_RATE_UNKNOWN
|
||||
* value if the information is not available.
|
||||
*
|
||||
* @return the refresh rate of the DisplayMode.
|
||||
*/
|
||||
public int getRefreshRate() {
|
||||
return refreshRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the DisplayMode.
|
||||
*
|
||||
* @return the width of the DisplayMode.
|
||||
*/
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
}
|
||||
@@ -1,596 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Dmitry A. Durnev
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The Event class is obsolete and has been replaced by AWTEvent class.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class Event implements Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 5488922509400504703L;
|
||||
|
||||
/**
|
||||
* The Constant SHIFT_MASK indicates that the Shift key is down when the
|
||||
* event occurred.
|
||||
*/
|
||||
public static final int SHIFT_MASK = 1;
|
||||
|
||||
/**
|
||||
* The Constant CTRL_MASK indicates that the Control key is down when the
|
||||
* event occurred.
|
||||
*/
|
||||
public static final int CTRL_MASK = 2;
|
||||
|
||||
/**
|
||||
* The Constant META_MASK indicates that the Meta key is down when t he
|
||||
* event occurred (or the right mouse button).
|
||||
*/
|
||||
public static final int META_MASK = 4;
|
||||
|
||||
/**
|
||||
* The Constant ALT_MASK indicates that the Alt key is down when the event
|
||||
* occurred (or the middle mouse button).
|
||||
*/
|
||||
public static final int ALT_MASK = 8;
|
||||
|
||||
/**
|
||||
* The Constant HOME indicates Home key.
|
||||
*/
|
||||
public static final int HOME = 1000;
|
||||
|
||||
/**
|
||||
* The Constant END indicates End key.
|
||||
*/
|
||||
public static final int END = 1001;
|
||||
|
||||
/**
|
||||
* The Constant PGUP indicates Page Up key.
|
||||
*/
|
||||
public static final int PGUP = 1002;
|
||||
|
||||
/**
|
||||
* The Constant PGDN indicates Page Down key.
|
||||
*/
|
||||
public static final int PGDN = 1003;
|
||||
|
||||
/**
|
||||
* The Constant UP indicates Up key.
|
||||
*/
|
||||
public static final int UP = 1004;
|
||||
|
||||
/**
|
||||
* The Constant DOWN indicates Down key.
|
||||
*/
|
||||
public static final int DOWN = 1005;
|
||||
|
||||
/**
|
||||
* The Constant LEFT indicates Left key.
|
||||
*/
|
||||
public static final int LEFT = 1006;
|
||||
|
||||
/**
|
||||
* The Constant RIGHT indicates Right key.
|
||||
*/
|
||||
public static final int RIGHT = 1007;
|
||||
|
||||
/**
|
||||
* The Constant F1 indicates F1 key.
|
||||
*/
|
||||
public static final int F1 = 1008;
|
||||
|
||||
/**
|
||||
* The Constant F2 indicates F2 key.
|
||||
*/
|
||||
public static final int F2 = 1009;
|
||||
|
||||
/**
|
||||
* The Constant F3 indicates F3 key.
|
||||
*/
|
||||
public static final int F3 = 1010;
|
||||
|
||||
/**
|
||||
* The Constant F4 indicates F4 key.
|
||||
*/
|
||||
public static final int F4 = 1011;
|
||||
|
||||
/**
|
||||
* The Constant F5 indicates F5 key.
|
||||
*/
|
||||
public static final int F5 = 1012;
|
||||
|
||||
/**
|
||||
* The Constant F6 indicates F6 key.
|
||||
*/
|
||||
public static final int F6 = 1013;
|
||||
|
||||
/**
|
||||
* The Constant F7 indicates F7 key.
|
||||
*/
|
||||
public static final int F7 = 1014;
|
||||
|
||||
/**
|
||||
* The Constant F8 indicates F8 key.
|
||||
*/
|
||||
public static final int F8 = 1015;
|
||||
|
||||
/**
|
||||
* The Constant F9 indicates F9 key.
|
||||
*/
|
||||
public static final int F9 = 1016;
|
||||
|
||||
/**
|
||||
* The Constant F10 indicates F10 key.
|
||||
*/
|
||||
public static final int F10 = 1017;
|
||||
|
||||
/**
|
||||
* The Constant F11 indicates F11 key.
|
||||
*/
|
||||
public static final int F11 = 1018;
|
||||
|
||||
/**
|
||||
* The Constant F12 indicates F12 key.
|
||||
*/
|
||||
public static final int F12 = 1019;
|
||||
|
||||
/**
|
||||
* The Constant PRINT_SCREEN indicates Print Screen key.
|
||||
*/
|
||||
public static final int PRINT_SCREEN = 1020;
|
||||
|
||||
/**
|
||||
* The Constant SCROLL_LOCK indicates Scroll Lock key.
|
||||
*/
|
||||
public static final int SCROLL_LOCK = 1021;
|
||||
|
||||
/**
|
||||
* The Constant CAPS_LOCK indicates Caps Lock key.
|
||||
*/
|
||||
public static final int CAPS_LOCK = 1022;
|
||||
|
||||
/**
|
||||
* The Constant NUM_LOCK indicates Num Lock key.
|
||||
*/
|
||||
public static final int NUM_LOCK = 1023;
|
||||
|
||||
/**
|
||||
* The Constant PAUSE indicates Pause key.
|
||||
*/
|
||||
public static final int PAUSE = 1024;
|
||||
|
||||
/**
|
||||
* The Constant INSERT indicates Insert key.
|
||||
*/
|
||||
public static final int INSERT = 1025;
|
||||
|
||||
/**
|
||||
* The Constant ENTER indicates Enter key.
|
||||
*/
|
||||
public static final int ENTER = 10;
|
||||
|
||||
/**
|
||||
* The Constant BACK_SPACE indicates Back Space key.
|
||||
*/
|
||||
public static final int BACK_SPACE = 8;
|
||||
|
||||
/**
|
||||
* The Constant TAB indicates TAb key.
|
||||
*/
|
||||
public static final int TAB = 9;
|
||||
|
||||
/**
|
||||
* The Constant ESCAPE indicates Escape key.
|
||||
*/
|
||||
public static final int ESCAPE = 27;
|
||||
|
||||
/**
|
||||
* The Constant DELETE indicates Delete key.
|
||||
*/
|
||||
public static final int DELETE = 127;
|
||||
|
||||
/**
|
||||
* The Constant WINDOW_DESTROY indicates an event when the user has asked
|
||||
* the window manager to kill the window.
|
||||
*/
|
||||
public static final int WINDOW_DESTROY = 201;
|
||||
|
||||
/**
|
||||
* The Constant WINDOW_EXPOSE indicates an event when the user has asked the
|
||||
* window manager to expose the window.
|
||||
*/
|
||||
public static final int WINDOW_EXPOSE = 202;
|
||||
|
||||
/**
|
||||
* The Constant WINDOW_ICONIFY indicates an event when the user has asked
|
||||
* the window manager to iconify the window.
|
||||
*/
|
||||
public static final int WINDOW_ICONIFY = 203;
|
||||
|
||||
/**
|
||||
* The Constant WINDOW_DEICONIFY indicates an event when the user has asked
|
||||
* the window manager to deiconify the window.
|
||||
*/
|
||||
public static final int WINDOW_DEICONIFY = 204;
|
||||
|
||||
/**
|
||||
* The Constant WINDOW_MOVED indicates an event when the user has asked the
|
||||
* window manager to move the window.
|
||||
*/
|
||||
public static final int WINDOW_MOVED = 205;
|
||||
|
||||
/**
|
||||
* The Constant KEY_PRESS indicates an event when the user presses a normal
|
||||
* key.
|
||||
*/
|
||||
public static final int KEY_PRESS = 401;
|
||||
|
||||
/**
|
||||
* The Constant KEY_RELEASE indicates an event when the user releases a
|
||||
* normal key.
|
||||
*/
|
||||
public static final int KEY_RELEASE = 402;
|
||||
|
||||
/**
|
||||
* The Constant KEY_ACTION indicates an event when the user pressed a
|
||||
* non-ASCII action key.
|
||||
*/
|
||||
public static final int KEY_ACTION = 403;
|
||||
|
||||
/**
|
||||
* The Constant KEY_ACTION_RELEASE indicates an event when the user released
|
||||
* a non-ASCII action key.
|
||||
*/
|
||||
public static final int KEY_ACTION_RELEASE = 404;
|
||||
|
||||
/**
|
||||
* The Constant MOUSE_DOWN indicates an event when the user has pressed the
|
||||
* mouse button.
|
||||
*/
|
||||
public static final int MOUSE_DOWN = 501;
|
||||
|
||||
/**
|
||||
* The Constant MOUSE_UP indicates an event when the user has released the
|
||||
* mouse button.
|
||||
*/
|
||||
public static final int MOUSE_UP = 502;
|
||||
|
||||
/**
|
||||
* The Constant MOUSE_MOVE indicates an event when the user has moved the
|
||||
* mouse with no button pressed.
|
||||
*/
|
||||
public static final int MOUSE_MOVE = 503;
|
||||
|
||||
/**
|
||||
* The Constant MOUSE_ENTER indicates an event when the mouse has entered a
|
||||
* component.
|
||||
*/
|
||||
public static final int MOUSE_ENTER = 504;
|
||||
|
||||
/**
|
||||
* The Constant MOUSE_EXIT indicates an event when the mouse has exited a
|
||||
* component.
|
||||
*/
|
||||
public static final int MOUSE_EXIT = 505;
|
||||
|
||||
/**
|
||||
* The Constant MOUSE_DRAG indicates an event when the user has moved a
|
||||
* mouse with the pressed button.
|
||||
*/
|
||||
public static final int MOUSE_DRAG = 506;
|
||||
|
||||
/**
|
||||
* The Constant SCROLL_LINE_UP indicates an event when the user has
|
||||
* activated line-up area of scrollbar.
|
||||
*/
|
||||
public static final int SCROLL_LINE_UP = 601;
|
||||
|
||||
/**
|
||||
* The Constant SCROLL_LINE_DOWN indicates an event when the user has
|
||||
* activated line-down area of scrollbar.
|
||||
*/
|
||||
public static final int SCROLL_LINE_DOWN = 602;
|
||||
|
||||
/**
|
||||
* The Constant SCROLL_PAGE_UP indicates an event when the user has
|
||||
* activated page up area of scrollbar.
|
||||
*/
|
||||
public static final int SCROLL_PAGE_UP = 603;
|
||||
|
||||
/**
|
||||
* The Constant SCROLL_PAGE_DOWN indicates an event when the user has
|
||||
* activated page down area of scrollbar.
|
||||
*/
|
||||
public static final int SCROLL_PAGE_DOWN = 604;
|
||||
|
||||
/**
|
||||
* The Constant SCROLL_ABSOLUTE indicates an event when the user has moved
|
||||
* the bubble in a scroll bar.
|
||||
*/
|
||||
public static final int SCROLL_ABSOLUTE = 605;
|
||||
|
||||
/**
|
||||
* The Constant SCROLL_BEGIN indicates a scroll begin event.
|
||||
*/
|
||||
public static final int SCROLL_BEGIN = 606;
|
||||
|
||||
/**
|
||||
* The Constant SCROLL_END indicates a scroll end event.
|
||||
*/
|
||||
public static final int SCROLL_END = 607;
|
||||
|
||||
/**
|
||||
* The Constant LIST_SELECT indicates that an item in a list has been
|
||||
* selected.
|
||||
*/
|
||||
public static final int LIST_SELECT = 701;
|
||||
|
||||
/**
|
||||
* The Constant LIST_DESELECT indicates that an item in a list has been
|
||||
* unselected.
|
||||
*/
|
||||
public static final int LIST_DESELECT = 702;
|
||||
|
||||
/**
|
||||
* The Constant ACTION_EVENT indicates that the user wants some action to
|
||||
* occur.
|
||||
*/
|
||||
public static final int ACTION_EVENT = 1001;
|
||||
|
||||
/**
|
||||
* The Constant LOAD_FILE indicates a file loading event.
|
||||
*/
|
||||
public static final int LOAD_FILE = 1002;
|
||||
|
||||
/**
|
||||
* The Constant SAVE_FILE indicates a file saving event.
|
||||
*/
|
||||
public static final int SAVE_FILE = 1003;
|
||||
|
||||
/**
|
||||
* The Constant GOT_FOCUS indicates that a component got the focus.
|
||||
*/
|
||||
public static final int GOT_FOCUS = 1004;
|
||||
|
||||
/**
|
||||
* The Constant LOST_FOCUS indicates that the component lost the focus.
|
||||
*/
|
||||
public static final int LOST_FOCUS = 1005;
|
||||
|
||||
/**
|
||||
* The target is the component with which the event is associated.
|
||||
*/
|
||||
public Object target;
|
||||
|
||||
/**
|
||||
* The when is timestamp when event has occured.
|
||||
*/
|
||||
public long when;
|
||||
|
||||
/**
|
||||
* The id indicates the type of the event.
|
||||
*/
|
||||
public int id;
|
||||
|
||||
/**
|
||||
* The x coordinate of event.
|
||||
*/
|
||||
public int x;
|
||||
|
||||
/**
|
||||
* The y coordinate of event.
|
||||
*/
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* The key code of key event.
|
||||
*/
|
||||
public int key;
|
||||
|
||||
/**
|
||||
* The state of the modifier keys (given by a bitmask).
|
||||
*/
|
||||
public int modifiers;
|
||||
|
||||
/**
|
||||
* The click count indicates the number of consecutive clicks.
|
||||
*/
|
||||
public int clickCount;
|
||||
|
||||
/**
|
||||
* The argument of the event.
|
||||
*/
|
||||
public Object arg;
|
||||
|
||||
/**
|
||||
* The next event.
|
||||
*/
|
||||
public Event evt;
|
||||
|
||||
/**
|
||||
* Instantiates a new event with the specified target component, event type,
|
||||
* and argument.
|
||||
*
|
||||
* @param target
|
||||
* the target component.
|
||||
* @param id
|
||||
* the event type.
|
||||
* @param arg
|
||||
* the argument.
|
||||
*/
|
||||
public Event(Object target, int id, Object arg) {
|
||||
this(target, 0l, id, 0, 0, 0, 0, arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new event with the specified target component, time stamp,
|
||||
* event type, x and y coordinates, keyboard key, state of the modifier
|
||||
* keys, and an argument set to null.
|
||||
*
|
||||
* @param target
|
||||
* the target component.
|
||||
* @param when
|
||||
* the time stamp.
|
||||
* @param id
|
||||
* the event type.
|
||||
* @param x
|
||||
* the x coordinate.
|
||||
* @param y
|
||||
* the y coordinate.
|
||||
* @param key
|
||||
* the key.
|
||||
* @param modifiers
|
||||
* the modifier keys state.
|
||||
*/
|
||||
public Event(Object target, long when, int id, int x, int y, int key, int modifiers) {
|
||||
this(target, when, id, x, y, key, modifiers, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new event with the specified target component, time stamp,
|
||||
* event type, x and y coordinates, keyboard key, state of the modifier
|
||||
* keys, and an argument.
|
||||
*
|
||||
* @param target
|
||||
* the target component.
|
||||
* @param when
|
||||
* the time stamp.
|
||||
* @param id
|
||||
* the event type.
|
||||
* @param x
|
||||
* the x coordinate.
|
||||
* @param y
|
||||
* the y coordinate.
|
||||
* @param key
|
||||
* the key.
|
||||
* @param modifiers
|
||||
* the modifier keys state.
|
||||
* @param arg
|
||||
* the specified argument.
|
||||
*/
|
||||
public Event(Object target, long when, int id, int x, int y, int key, int modifiers, Object arg) {
|
||||
this.target = target;
|
||||
this.when = when;
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.key = key;
|
||||
this.modifiers = modifiers;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this Event.
|
||||
*
|
||||
* @return a string representation of this Event.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
/*
|
||||
* The format is based on 1.5 release behavior which can be revealed by
|
||||
* the following code: Event e = new Event(new Button(), 0l,
|
||||
* Event.KEY_PRESS, 0, 0, Event.TAB, Event.SHIFT_MASK, "arg");
|
||||
* System.out.println(e);
|
||||
*/
|
||||
|
||||
return getClass().getName() + "[" + paramString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representing the state of this Event.
|
||||
*
|
||||
* @return a string representing the state of this Event.
|
||||
*/
|
||||
protected String paramString() {
|
||||
return "id=" + id + ",x=" + x + ",y=" + y + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
(key != 0 ? ",key=" + key + getModifiersString() : "") + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
",target=" + target + //$NON-NLS-1$
|
||||
(arg != null ? ",arg=" + arg : ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a string representation of the modifiers.
|
||||
*
|
||||
* @return a string representation of the modifiers.
|
||||
*/
|
||||
private String getModifiersString() {
|
||||
String strMod = ""; //$NON-NLS-1$
|
||||
if (shiftDown()) {
|
||||
strMod += ",shift"; //$NON-NLS-1$
|
||||
}
|
||||
if (controlDown()) {
|
||||
strMod += ",control"; //$NON-NLS-1$
|
||||
}
|
||||
if (metaDown()) {
|
||||
strMod += ",meta"; //$NON-NLS-1$
|
||||
}
|
||||
return strMod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates x and y coordinates of his event to the x+dx and x+dy
|
||||
* coordinates.
|
||||
*
|
||||
* @param dx
|
||||
* the distance by which the event's x coordinate is increased.
|
||||
* @param dy
|
||||
* the distance by which the event's y coordinate is increased.
|
||||
*/
|
||||
public void translate(int dx, int dy) {
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Control key is down or not.
|
||||
*
|
||||
* @return true, if Control key is down; false otherwise.
|
||||
*/
|
||||
public boolean controlDown() {
|
||||
return (modifiers & CTRL_MASK) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Meta key is down or not.
|
||||
*
|
||||
* @return true, if Meta key is down; false otherwise.
|
||||
*/
|
||||
public boolean metaDown() {
|
||||
return (modifiers & META_MASK) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Shift key is down or not.
|
||||
*
|
||||
* @return true, if Shift key is down; false otherwise.
|
||||
*/
|
||||
public boolean shiftDown() {
|
||||
return (modifiers & SHIFT_MASK) != 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov, Pavel Dolgov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt;
|
||||
|
||||
import org.apache.harmony.awt.wtk.NativeEvent;
|
||||
import org.apache.harmony.awt.wtk.NativeEventQueue;
|
||||
|
||||
class EventDispatchThread extends Thread {
|
||||
|
||||
private static final class MarkerEvent extends AWTEvent {
|
||||
MarkerEvent(Object source, int id) {
|
||||
super(source, id);
|
||||
}
|
||||
}
|
||||
|
||||
final Dispatcher dispatcher;
|
||||
final Toolkit toolkit;
|
||||
private NativeEventQueue nativeQueue;
|
||||
|
||||
protected volatile boolean shutdownPending = false;
|
||||
|
||||
/**
|
||||
* Initialise and run the main event loop
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
nativeQueue = toolkit.getNativeEventQueue();
|
||||
|
||||
try {
|
||||
runModalLoop(null);
|
||||
} finally {
|
||||
toolkit.shutdownWatchdog.forceShutdown();
|
||||
}
|
||||
}
|
||||
|
||||
void runModalLoop(ModalContext context) {
|
||||
long lastPaintTime = System.currentTimeMillis();
|
||||
while (!shutdownPending && (context == null || context.isModalLoopRunning())) {
|
||||
try {
|
||||
EventQueue eventQueue = toolkit.getSystemEventQueueImpl();
|
||||
|
||||
NativeEvent ne = nativeQueue.getNextEvent();
|
||||
if (ne != null) {
|
||||
dispatcher.onEvent(ne);
|
||||
MarkerEvent marker = new MarkerEvent(this, 0);
|
||||
eventQueue.postEvent(marker);
|
||||
for (AWTEvent ae = eventQueue.getNextEventNoWait();
|
||||
(ae != null) && (ae != marker);
|
||||
ae = eventQueue.getNextEventNoWait()) {
|
||||
eventQueue.dispatchEvent(ae);
|
||||
}
|
||||
} else {
|
||||
toolkit.shutdownWatchdog.setNativeQueueEmpty(true);
|
||||
AWTEvent ae = eventQueue.getNextEventNoWait();
|
||||
if (ae != null) {
|
||||
eventQueue.dispatchEvent(ae);
|
||||
long curTime = System.currentTimeMillis();
|
||||
if (curTime - lastPaintTime > 10) {
|
||||
toolkit.onQueueEmpty();
|
||||
lastPaintTime = System.currentTimeMillis();
|
||||
}
|
||||
} else {
|
||||
toolkit.shutdownWatchdog.setAwtQueueEmpty(true);
|
||||
toolkit.onQueueEmpty();
|
||||
lastPaintTime = System.currentTimeMillis();
|
||||
waitForAnyEvent();
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
// TODO: Exception handler should be implemented
|
||||
// t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void waitForAnyEvent() {
|
||||
EventQueue eventQueue = toolkit.getSystemEventQueueImpl();
|
||||
if (!eventQueue.isEmpty() || !nativeQueue.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Object eventMonitor = nativeQueue.getEventMonitor();
|
||||
synchronized(eventMonitor) {
|
||||
try {
|
||||
eventMonitor.wait();
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
void shutdown() {
|
||||
shutdownPending = true;
|
||||
}
|
||||
|
||||
EventDispatchThread(Toolkit toolkit, Dispatcher dispatcher ) {
|
||||
this.toolkit = toolkit;
|
||||
this.dispatcher = dispatcher;
|
||||
setName("AWT-EventDispatchThread"); //$NON-NLS-1$
|
||||
setDaemon(true);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov, Pavel Dolgov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.InvocationEvent;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.EmptyStackException;
|
||||
|
||||
/**
|
||||
* The EventQueue class manages events. It is a platform-independent class that
|
||||
* queues events both from the underlying peer classes and from trusted
|
||||
* application classes.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class EventQueue {
|
||||
|
||||
/**
|
||||
* The core ref.
|
||||
*/
|
||||
private final EventQueueCoreAtomicReference coreRef = new EventQueueCoreAtomicReference();
|
||||
|
||||
/**
|
||||
* The Class EventQueueCoreAtomicReference.
|
||||
*/
|
||||
private static final class EventQueueCoreAtomicReference {
|
||||
|
||||
/**
|
||||
* The core.
|
||||
*/
|
||||
private EventQueueCore core;
|
||||
|
||||
/* synchronized */
|
||||
/**
|
||||
* Gets the.
|
||||
*
|
||||
* @return the event queue core.
|
||||
*/
|
||||
EventQueueCore get() {
|
||||
return core;
|
||||
}
|
||||
|
||||
/* synchronized */
|
||||
/**
|
||||
* Sets the.
|
||||
*
|
||||
* @param newCore
|
||||
* the new core.
|
||||
*/
|
||||
void set(EventQueueCore newCore) {
|
||||
core = newCore;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the calling thread is the current AWT EventQueue's
|
||||
* dispatch thread.
|
||||
*
|
||||
* @return true, if the calling thread is the current AWT EventQueue's
|
||||
* dispatch thread; false otherwise.
|
||||
*/
|
||||
public static boolean isDispatchThread() {
|
||||
return Thread.currentThread() instanceof EventDispatchThread;
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts an InvocationEvent which executes the run() method on a Runnable
|
||||
* when dispatched by the AWT event dispatcher thread.
|
||||
*
|
||||
* @param runnable
|
||||
* the Runnable whose run method should be executed synchronously
|
||||
* on the EventQueue.
|
||||
*/
|
||||
public static void invokeLater(Runnable runnable) {
|
||||
Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
InvocationEvent event = new InvocationEvent(toolkit, runnable);
|
||||
toolkit.getSystemEventQueueImpl().postEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts an InvocationEvent which executes the run() method on a Runnable
|
||||
* when dispatched by the AWT event dispatcher thread and the notifyAll
|
||||
* method is called on it immediately after run returns.
|
||||
*
|
||||
* @param runnable
|
||||
* the Runnable whose run method should be executed synchronously
|
||||
* on the EventQueue.
|
||||
* @throws InterruptedException
|
||||
* if another thread has interrupted this thread.
|
||||
* @throws InvocationTargetException
|
||||
* if an error occurred while running the runnable.
|
||||
*/
|
||||
public static void invokeAndWait(Runnable runnable) throws InterruptedException,
|
||||
InvocationTargetException {
|
||||
|
||||
if (isDispatchThread()) {
|
||||
throw new Error();
|
||||
}
|
||||
|
||||
final Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
final Object notifier = new Object(); // $NON-LOCK-1$
|
||||
InvocationEvent event = new InvocationEvent(toolkit, runnable, notifier, true);
|
||||
|
||||
synchronized (notifier) {
|
||||
toolkit.getSystemEventQueueImpl().postEvent(event);
|
||||
notifier.wait();
|
||||
}
|
||||
|
||||
Exception exception = event.getException();
|
||||
|
||||
if (exception != null) {
|
||||
throw new InvocationTargetException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the system event queue.
|
||||
*
|
||||
* @return the system event queue.
|
||||
*/
|
||||
private static EventQueue getSystemEventQueue() {
|
||||
Thread th = Thread.currentThread();
|
||||
if (th instanceof EventDispatchThread) {
|
||||
return ((EventDispatchThread)th).toolkit.getSystemEventQueueImpl();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the most recent event's timestamp. This event was dispatched from
|
||||
* the EventQueue associated with the calling thread.
|
||||
*
|
||||
* @return the timestamp of the last Event to be dispatched, or
|
||||
* System.currentTimeMillis() if this method is invoked from a
|
||||
* thread other than an event-dispatching thread.
|
||||
*/
|
||||
public static long getMostRecentEventTime() {
|
||||
EventQueue eq = getSystemEventQueue();
|
||||
return (eq != null) ? eq.getMostRecentEventTimeImpl() : System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the most recent event time impl.
|
||||
*
|
||||
* @return the most recent event time impl.
|
||||
*/
|
||||
private long getMostRecentEventTimeImpl() {
|
||||
return getCore().getMostRecentEventTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the the currently dispatched event by the EventQueue associated
|
||||
* with the calling thread.
|
||||
*
|
||||
* @return the currently dispatched event or null if this method is invoked
|
||||
* from a thread other than an event-dispatching thread.
|
||||
*/
|
||||
public static AWTEvent getCurrentEvent() {
|
||||
EventQueue eq = getSystemEventQueue();
|
||||
return (eq != null) ? eq.getCurrentEventImpl() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current event impl.
|
||||
*
|
||||
* @return the current event impl.
|
||||
*/
|
||||
private AWTEvent getCurrentEventImpl() {
|
||||
return getCore().getCurrentEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new event queue.
|
||||
*/
|
||||
public EventQueue() {
|
||||
setCore(new EventQueueCore(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new event queue.
|
||||
*
|
||||
* @param t
|
||||
* the t.
|
||||
*/
|
||||
EventQueue(Toolkit t) {
|
||||
setCore(new EventQueueCore(this, t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts a event to the EventQueue.
|
||||
*
|
||||
* @param event
|
||||
* AWTEvent.
|
||||
*/
|
||||
public void postEvent(AWTEvent event) {
|
||||
event.isPosted = true;
|
||||
getCore().postEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an event from the EventQueue and removes it from this queue.
|
||||
*
|
||||
* @return the next AWTEvent.
|
||||
* @throws InterruptedException
|
||||
* is thrown if another thread interrupts this thread.
|
||||
*/
|
||||
public AWTEvent getNextEvent() throws InterruptedException {
|
||||
return getCore().getNextEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next event no wait.
|
||||
*
|
||||
* @return the next event no wait.
|
||||
*/
|
||||
AWTEvent getNextEventNoWait() {
|
||||
return getCore().getNextEventNoWait();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first event of the EventQueue (without removing it from the
|
||||
* queue).
|
||||
*
|
||||
* @return the the first AWT event of the EventQueue.
|
||||
*/
|
||||
public AWTEvent peekEvent() {
|
||||
return getCore().peekEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first event of the EventQueue with the specified ID (without
|
||||
* removing it from the queue).
|
||||
*
|
||||
* @param id
|
||||
* the type ID of event.
|
||||
* @return the first event of the EventQueue with the specified ID.
|
||||
*/
|
||||
public AWTEvent peekEvent(int id) {
|
||||
return getCore().peekEvent(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the existing EventQueue with the specified EventQueue. Any
|
||||
* pending events are transferred to the new EventQueue.
|
||||
*
|
||||
* @param newEventQueue
|
||||
* the new event queue.
|
||||
*/
|
||||
public void push(EventQueue newEventQueue) {
|
||||
getCore().push(newEventQueue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops dispatching events using this EventQueue. Any pending events are
|
||||
* transferred to the previous EventQueue.
|
||||
*
|
||||
* @throws EmptyStackException
|
||||
* is thrown if no previous push was made on this EventQueue.
|
||||
*/
|
||||
protected void pop() throws EmptyStackException {
|
||||
getCore().pop();
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches the specified event.
|
||||
*
|
||||
* @param event
|
||||
* the AWTEvent.
|
||||
*/
|
||||
protected void dispatchEvent(AWTEvent event) {
|
||||
getCore().dispatchEventImpl(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the queue is empty.
|
||||
*
|
||||
* @return true, if is empty.
|
||||
*/
|
||||
boolean isEmpty() {
|
||||
return getCore().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the core.
|
||||
*
|
||||
* @return the core.
|
||||
*/
|
||||
EventQueueCore getCore() {
|
||||
return coreRef.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the core.
|
||||
*
|
||||
* @param newCore
|
||||
* the new core.
|
||||
*/
|
||||
void setCore(EventQueueCore newCore) {
|
||||
coreRef.set((newCore != null) ? newCore : new EventQueueCore(this));
|
||||
}
|
||||
}
|
||||
@@ -1,253 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Pavel Dolgov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.InputMethodEvent;
|
||||
import java.awt.event.InvocationEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The events storage for EventQueue
|
||||
*/
|
||||
final class EventQueueCore {
|
||||
|
||||
private final LinkedList<EventQueue> queueStack = new LinkedList<EventQueue>();
|
||||
private final LinkedList<AWTEvent> events = new LinkedList<AWTEvent>();
|
||||
|
||||
private Toolkit toolkit;
|
||||
private EventQueue activeQueue;
|
||||
private Thread dispatchThread;
|
||||
|
||||
AWTEvent currentEvent;
|
||||
long mostRecentEventTime = System.currentTimeMillis();
|
||||
|
||||
EventQueueCore(EventQueue eq) {
|
||||
synchronized (this) {
|
||||
queueStack.addLast(eq);
|
||||
activeQueue = eq;
|
||||
}
|
||||
}
|
||||
|
||||
EventQueueCore(EventQueue eq, Toolkit t) {
|
||||
synchronized (this) {
|
||||
queueStack.addLast(eq);
|
||||
activeQueue = eq;
|
||||
setToolkit(t);
|
||||
}
|
||||
}
|
||||
|
||||
synchronized long getMostRecentEventTime() {
|
||||
return mostRecentEventTime;
|
||||
}
|
||||
|
||||
synchronized AWTEvent getCurrentEvent() {
|
||||
return currentEvent;
|
||||
}
|
||||
|
||||
synchronized boolean isSystemEventQueue() {
|
||||
return toolkit != null;
|
||||
}
|
||||
|
||||
private void setToolkit(Toolkit t) {
|
||||
toolkit = t;
|
||||
if (toolkit != null) {
|
||||
toolkit.setSystemEventQueueCore(this);
|
||||
dispatchThread = toolkit.dispatchThread;
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void postEvent(AWTEvent event) {
|
||||
//???AWT
|
||||
/*
|
||||
events.addLast(event);
|
||||
if ((toolkit == null) && (dispatchThread == null)) {
|
||||
dispatchThread = new EventQueueThread(this);
|
||||
dispatchThread.start();
|
||||
}
|
||||
// TODO: add event coalescing
|
||||
if (toolkit != null) {
|
||||
toolkit.shutdownWatchdog.setAwtQueueEmpty(false);
|
||||
if (!GraphicsEnvironment.getLocalGraphicsEnvironment().isHeadlessInstance()) {
|
||||
notifyEventMonitor(toolkit);
|
||||
}
|
||||
}
|
||||
notifyAll();
|
||||
*/
|
||||
}
|
||||
|
||||
void notifyEventMonitor(Toolkit t) {
|
||||
Object em = t.getNativeEventQueue().getEventMonitor();
|
||||
synchronized (em) {
|
||||
em.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
synchronized AWTEvent getNextEvent() throws InterruptedException {
|
||||
while (events.isEmpty()) {
|
||||
wait();
|
||||
}
|
||||
AWTEvent event = events.removeFirst();
|
||||
// TODO: add event coalescing
|
||||
return event;
|
||||
}
|
||||
|
||||
synchronized AWTEvent peekEvent() {
|
||||
return events.isEmpty() ? null : events.getFirst();
|
||||
}
|
||||
|
||||
synchronized AWTEvent peekEvent(int id) {
|
||||
for (AWTEvent event : events) {
|
||||
if (event.getID() == id) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
synchronized void dispatchEvent(AWTEvent event) {
|
||||
updateCurrentEventAndTime(event);
|
||||
try {
|
||||
activeQueue.dispatchEvent(event);
|
||||
} finally {
|
||||
currentEvent = null;
|
||||
}
|
||||
}
|
||||
|
||||
void dispatchEventImpl(AWTEvent event) {
|
||||
if (event instanceof ActiveEvent) {
|
||||
updateCurrentEventAndTime(event);
|
||||
try {
|
||||
((ActiveEvent) event).dispatch();
|
||||
} finally {
|
||||
currentEvent = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Object src = event.getSource();
|
||||
|
||||
if (src instanceof Component) {
|
||||
if (preprocessComponentEvent(event)) {
|
||||
((Component) src).dispatchEvent(event);
|
||||
}
|
||||
} else {
|
||||
if (toolkit != null) {
|
||||
toolkit.dispatchAWTEvent(event);
|
||||
}
|
||||
if (src instanceof MenuComponent) {
|
||||
((MenuComponent) src).dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final boolean preprocessComponentEvent(AWTEvent event) {
|
||||
if (event instanceof MouseEvent) {
|
||||
return preprocessMouseEvent((MouseEvent)event);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private final boolean preprocessMouseEvent(MouseEvent event) {
|
||||
//???AWT
|
||||
/*
|
||||
if (toolkit != null && toolkit.mouseEventPreprocessor != null) {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
return toolkit.mouseEventPreprocessor.preprocess(event);
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateCurrentEventAndTime(AWTEvent event) {
|
||||
currentEvent = event;
|
||||
long when = 0;
|
||||
if (event instanceof ActionEvent) {
|
||||
when = ((ActionEvent) event).getWhen();
|
||||
} else if (event instanceof InputEvent) {
|
||||
when = ((InputEvent) event).getWhen();
|
||||
} else if (event instanceof InputMethodEvent) {
|
||||
when = ((InputMethodEvent) event).getWhen();
|
||||
} else if (event instanceof InvocationEvent) {
|
||||
when = ((InvocationEvent) event).getWhen();
|
||||
}
|
||||
if (when != 0) {
|
||||
mostRecentEventTime = when;
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void push(EventQueue newEventQueue) {
|
||||
// TODO: handle incorrect situations
|
||||
if (queueStack.isEmpty()) {
|
||||
// awt.6B=Queue stack is empty
|
||||
throw new IllegalStateException(Messages.getString("awt.6B")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
queueStack.addLast(newEventQueue);
|
||||
activeQueue = newEventQueue;
|
||||
activeQueue.setCore(this);
|
||||
}
|
||||
|
||||
synchronized void pop() {
|
||||
EventQueue removed = queueStack.removeLast();
|
||||
if (removed != activeQueue) {
|
||||
// awt.6C=Event queue stack is broken
|
||||
throw new IllegalStateException(Messages.getString("awt.6C")); //$NON-NLS-1$
|
||||
}
|
||||
activeQueue = queueStack.getLast();
|
||||
removed.setCore(null);
|
||||
}
|
||||
|
||||
synchronized AWTEvent getNextEventNoWait() {
|
||||
try {
|
||||
return events.isEmpty() ? null : activeQueue.getNextEvent();
|
||||
} catch (InterruptedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
synchronized boolean isEmpty() {
|
||||
return (currentEvent == null) && events.isEmpty();
|
||||
}
|
||||
|
||||
synchronized boolean isEmpty(long timeout) {
|
||||
if (!isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
wait(timeout);
|
||||
} catch (InterruptedException e) {}
|
||||
return isEmpty();
|
||||
}
|
||||
|
||||
synchronized EventQueue getActiveEventQueue() {
|
||||
return activeQueue;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Ilya S. Okomin
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The FontFormatException class is used to provide notification and information
|
||||
* that font can't be created.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class FontFormatException extends Exception {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -4481290147811361272L;
|
||||
|
||||
/**
|
||||
* Instantiates a new font format exception with detailed message.
|
||||
*
|
||||
* @param reason
|
||||
* the detailed message.
|
||||
*/
|
||||
public FontFormatException(String reason) {
|
||||
super(reason);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,466 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Ilya S. Okomin
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.Serializable;
|
||||
import java.text.CharacterIterator;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The FontMetrics class contains information about the rendering of a
|
||||
* particular font on a particular screen.
|
||||
* <p>
|
||||
* Each character in the Font has three values that help define where to place
|
||||
* it: an ascent, a descent, and an advance. The ascent is the distance the
|
||||
* character extends above the baseline. The descent is the distance the
|
||||
* character extends below the baseline. The advance width defines the position
|
||||
* at which the next character should be placed.
|
||||
* <p>
|
||||
* An array of characters or a string has an ascent, a descent, and an advance
|
||||
* width too. The ascent or descent of the array is specified by the maximum
|
||||
* ascent or descent of the characters in the array. The advance width is the
|
||||
* sum of the advance widths of each of the characters in the character array.
|
||||
* </p>
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class FontMetrics implements Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1681126225205050147L;
|
||||
|
||||
/**
|
||||
* The font from which the FontMetrics is created.
|
||||
*/
|
||||
protected Font font;
|
||||
|
||||
/**
|
||||
* Instantiates a new font metrics from the specified Font.
|
||||
*
|
||||
* @param fnt
|
||||
* the Font.
|
||||
*/
|
||||
protected FontMetrics(Font fnt) {
|
||||
this.font = fnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the String representation of this FontMetrics.
|
||||
*
|
||||
* @return the string.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getName() + "[font=" + this.getFont() + //$NON-NLS-1$
|
||||
"ascent=" + this.getAscent() + //$NON-NLS-1$
|
||||
", descent=" + this.getDescent() + //$NON-NLS-1$
|
||||
", height=" + this.getHeight() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the font associated with this FontMetrics.
|
||||
*
|
||||
* @return the font associated with this FontMetrics.
|
||||
*/
|
||||
public Font getFont() {
|
||||
return font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height of the text line in this Font.
|
||||
*
|
||||
* @return the height of the text line in this Font.
|
||||
*/
|
||||
public int getHeight() {
|
||||
return this.getAscent() + this.getDescent() + this.getLeading();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the font ascent of the Font associated with this FontMetrics. The
|
||||
* font ascent is the distance from the font's baseline to the top of most
|
||||
* alphanumeric characters.
|
||||
*
|
||||
* @return the ascent of the Font associated with this FontMetrics.
|
||||
*/
|
||||
public int getAscent() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the font descent of the Font associated with this FontMetrics. The
|
||||
* font descent is the distance from the font's baseline to the bottom of
|
||||
* most alphanumeric characters with descenders.
|
||||
*
|
||||
* @return the descent of the Font associated with this FontMetrics.
|
||||
*/
|
||||
public int getDescent() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the leading of the Font associated with this FontMetrics.
|
||||
*
|
||||
* @return the leading of the Font associated with this FontMetrics.
|
||||
*/
|
||||
public int getLeading() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the LineMetrics object for the specified CharacterIterator in the
|
||||
* specified Graphics.
|
||||
*
|
||||
* @param ci
|
||||
* the CharacterIterator.
|
||||
* @param beginIndex
|
||||
* the offset.
|
||||
* @param limit
|
||||
* the number of characters to be used.
|
||||
* @param context
|
||||
* the Graphics.
|
||||
* @return the LineMetrics object for the specified CharacterIterator in the
|
||||
* specified Graphics.
|
||||
*/
|
||||
public LineMetrics getLineMetrics(CharacterIterator ci, int beginIndex, int limit,
|
||||
Graphics context) {
|
||||
return font.getLineMetrics(ci, beginIndex, limit, this.getFRCFromGraphics(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the LineMetrics object for the specified String in the specified
|
||||
* Graphics.
|
||||
*
|
||||
* @param str
|
||||
* the String.
|
||||
* @param context
|
||||
* the Graphics.
|
||||
* @return the LineMetrics object for the specified String in the specified
|
||||
* Graphics.
|
||||
*/
|
||||
public LineMetrics getLineMetrics(String str, Graphics context) {
|
||||
return font.getLineMetrics(str, this.getFRCFromGraphics(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the LineMetrics object for the specified character array in the
|
||||
* specified Graphics.
|
||||
*
|
||||
* @param chars
|
||||
* the character array.
|
||||
* @param beginIndex
|
||||
* the offset of array.
|
||||
* @param limit
|
||||
* the number of characters to be used.
|
||||
* @param context
|
||||
* the Graphics.
|
||||
* @return the LineMetrics object for the specified character array in the
|
||||
* specified Graphics.
|
||||
*/
|
||||
public LineMetrics getLineMetrics(char[] chars, int beginIndex, int limit, Graphics context) {
|
||||
return font.getLineMetrics(chars, beginIndex, limit, this.getFRCFromGraphics(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the LineMetrics object for the specified String in the specified
|
||||
* Graphics.
|
||||
*
|
||||
* @param str
|
||||
* the String.
|
||||
* @param beginIndex
|
||||
* the offset.
|
||||
* @param limit
|
||||
* the number of characters to be used.
|
||||
* @param context
|
||||
* the Graphics.
|
||||
* @return the LineMetrics object for the specified String in the specified
|
||||
* Graphics.
|
||||
*/
|
||||
public LineMetrics getLineMetrics(String str, int beginIndex, int limit, Graphics context) {
|
||||
return font.getLineMetrics(str, beginIndex, limit, this.getFRCFromGraphics(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the character's maximum bounds in the specified Graphics context.
|
||||
*
|
||||
* @param context
|
||||
* the Graphics context.
|
||||
* @return the character's maximum bounds in the specified Graphics context.
|
||||
*/
|
||||
public Rectangle2D getMaxCharBounds(Graphics context) {
|
||||
return this.font.getMaxCharBounds(this.getFRCFromGraphics(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounds of the specified CharacterIterator in the specified
|
||||
* Graphics context.
|
||||
*
|
||||
* @param ci
|
||||
* the CharacterIterator.
|
||||
* @param beginIndex
|
||||
* the begin offset of the array.
|
||||
* @param limit
|
||||
* the number of characters.
|
||||
* @param context
|
||||
* the Graphics.
|
||||
* @return the bounds of the specified CharacterIterator in the specified
|
||||
* Graphics context.
|
||||
*/
|
||||
public Rectangle2D getStringBounds(CharacterIterator ci, int beginIndex, int limit,
|
||||
Graphics context) {
|
||||
return font.getStringBounds(ci, beginIndex, limit, this.getFRCFromGraphics(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounds of the specified String in the specified Graphics
|
||||
* context.
|
||||
*
|
||||
* @param str
|
||||
* the String.
|
||||
* @param beginIndex
|
||||
* the begin offset of the array.
|
||||
* @param limit
|
||||
* the number of characters.
|
||||
* @param context
|
||||
* the Graphics.
|
||||
* @return the bounds of the specified String in the specified Graphics
|
||||
* context.
|
||||
*/
|
||||
public Rectangle2D getStringBounds(String str, int beginIndex, int limit, Graphics context) {
|
||||
return font.getStringBounds(str, beginIndex, limit, this.getFRCFromGraphics(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounds of the specified characters array in the specified
|
||||
* Graphics context.
|
||||
*
|
||||
* @param chars
|
||||
* the characters array.
|
||||
* @param beginIndex
|
||||
* the begin offset of the array.
|
||||
* @param limit
|
||||
* the number of characters.
|
||||
* @param context
|
||||
* the Graphics.
|
||||
* @return the bounds of the specified characters array in the specified
|
||||
* Graphics context.
|
||||
*/
|
||||
public Rectangle2D getStringBounds(char[] chars, int beginIndex, int limit, Graphics context) {
|
||||
return font.getStringBounds(chars, beginIndex, limit, this.getFRCFromGraphics(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounds of the specified String in the specified Graphics
|
||||
* context.
|
||||
*
|
||||
* @param str
|
||||
* the String.
|
||||
* @param context
|
||||
* the Graphics.
|
||||
* @return the bounds of the specified String in the specified Graphics
|
||||
* context.
|
||||
*/
|
||||
public Rectangle2D getStringBounds(String str, Graphics context) {
|
||||
return font.getStringBounds(str, this.getFRCFromGraphics(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the Font has uniform line metrics or not. The Font can contain
|
||||
* characters of other fonts for covering character set. In this case the
|
||||
* Font isn't uniform.
|
||||
*
|
||||
* @return true, if the Font has uniform line metrics, false otherwise.
|
||||
*/
|
||||
public boolean hasUniformLineMetrics() {
|
||||
return this.font.hasUniformLineMetrics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the distance from the leftmost point to the rightmost point on
|
||||
* the string's baseline showing the specified array of bytes in this Font.
|
||||
*
|
||||
* @param data
|
||||
* the array of bytes to be measured.
|
||||
* @param off
|
||||
* the start offset.
|
||||
* @param len
|
||||
* the number of bytes to be measured.
|
||||
* @return the advance width of the array.
|
||||
*/
|
||||
public int bytesWidth(byte[] data, int off, int len) {
|
||||
int width = 0;
|
||||
if ((off >= data.length) || (off < 0)) {
|
||||
// awt.13B=offset off is out of range
|
||||
throw new IllegalArgumentException(Messages.getString("awt.13B")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
if ((off + len > data.length)) {
|
||||
// awt.13C=number of elemets len is out of range
|
||||
throw new IllegalArgumentException(Messages.getString("awt.13C")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
for (int i = off; i < off + len; i++) {
|
||||
width += charWidth(data[i]);
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the distance from the leftmost point to the rightmost point on
|
||||
* the string's baseline showing the specified array of characters in this
|
||||
* Font.
|
||||
*
|
||||
* @param data
|
||||
* the array of characters to be measured.
|
||||
* @param off
|
||||
* the start offset.
|
||||
* @param len
|
||||
* the number of bytes to be measured.
|
||||
* @return the advance width of the array.
|
||||
*/
|
||||
public int charsWidth(char[] data, int off, int len) {
|
||||
int width = 0;
|
||||
if ((off >= data.length) || (off < 0)) {
|
||||
// awt.13B=offset off is out of range
|
||||
throw new IllegalArgumentException(Messages.getString("awt.13B")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
if ((off + len > data.length)) {
|
||||
// awt.13C=number of elemets len is out of range
|
||||
throw new IllegalArgumentException(Messages.getString("awt.13C")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
for (int i = off; i < off + len; i++) {
|
||||
width += charWidth(data[i]);
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the distance from the leftmost point to the rightmost point of
|
||||
* the specified character in this Font.
|
||||
*
|
||||
* @param ch
|
||||
* the specified Unicode point code of character to be measured.
|
||||
* @return the advance width of the character.
|
||||
*/
|
||||
public int charWidth(int ch) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the distance from the leftmost point to the rightmost point of
|
||||
* the specified character in this Font.
|
||||
*
|
||||
* @param ch
|
||||
* the specified character to be measured.
|
||||
* @return the advance width of the character.
|
||||
*/
|
||||
public int charWidth(char ch) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum advance width of character in this Font.
|
||||
*
|
||||
* @return the maximum advance width of character in this Font.
|
||||
*/
|
||||
public int getMaxAdvance() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum font ascent of the Font associated with this
|
||||
* FontMetrics.
|
||||
*
|
||||
* @return the maximum font ascent of the Font associated with this
|
||||
* FontMetrics.
|
||||
*/
|
||||
public int getMaxAscent() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum font descent of character in this Font.
|
||||
*
|
||||
* @return the maximum font descent of character in this Font.
|
||||
* @deprecated Replaced by getMaxDescent() method.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getMaxDecent() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum font descent of character in this Font.
|
||||
*
|
||||
* @return the maximum font descent of character in this Font.
|
||||
*/
|
||||
public int getMaxDescent() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the advance widths of the characters in the Font.
|
||||
*
|
||||
* @return the advance widths of the characters in the Font.
|
||||
*/
|
||||
public int[] getWidths() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the advance width for the specified String in this Font.
|
||||
*
|
||||
* @param str
|
||||
* String to be measured.
|
||||
* @return the the advance width for the specified String in this Font.
|
||||
*/
|
||||
public int stringWidth(String str) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a FontRenderContext instance of the Graphics context specified.
|
||||
*
|
||||
* @param context
|
||||
* the specified Graphics context.
|
||||
* @return a FontRenderContext of the specified Graphics context.
|
||||
*/
|
||||
private FontRenderContext getFRCFromGraphics(Graphics context) {
|
||||
FontRenderContext frc;
|
||||
if (context instanceof Graphics2D) {
|
||||
frc = ((Graphics2D)context).getFontRenderContext();
|
||||
} else {
|
||||
frc = new FontRenderContext(null, false, false);
|
||||
}
|
||||
|
||||
return frc;
|
||||
}
|
||||
}
|
||||
@@ -1,255 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ColorModel;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The GradientPaint class defines a way to fill a Shape with a linear color
|
||||
* gradient pattern.
|
||||
* <p>
|
||||
* The GradientPaint's fill pattern is determined by two points and two colors,
|
||||
* plus the cyclic mode option. Each of the two points is painted with its
|
||||
* corresponding color, and on the line segment connecting the two points, the
|
||||
* color is proportionally changed between the two colors. For points on the
|
||||
* same line which are not between the two specified points (outside of the
|
||||
* connecting segment) their color is determined by the cyclic mode option. If
|
||||
* the mode is cyclic, then the rest of the line repeats the color pattern of
|
||||
* the connecting segment, cycling back and forth between the two colors. If
|
||||
* not, the mode is acyclic which means that all points on the line outside the
|
||||
* connecting line segment are given the same color as the closest of the two
|
||||
* specified points.
|
||||
* <p>
|
||||
* The color of points that are not on the line connecting the two specified
|
||||
* points are given by perpendicular projection: by taking the set of lines
|
||||
* perpendicular to the connecting line and for each one, the whole line is
|
||||
* colored with the same color.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class GradientPaint implements Paint {
|
||||
|
||||
/**
|
||||
* The start point color.
|
||||
*/
|
||||
Color color1;
|
||||
|
||||
/**
|
||||
* The end color point.
|
||||
*/
|
||||
Color color2;
|
||||
|
||||
/**
|
||||
* The location of the start point.
|
||||
*/
|
||||
Point2D point1;
|
||||
|
||||
/**
|
||||
* The location of the end point.
|
||||
*/
|
||||
Point2D point2;
|
||||
|
||||
/**
|
||||
* The indicator of cycle filling. If TRUE filling repeated outside points
|
||||
* stripe, if FALSE solid color filling outside.
|
||||
*/
|
||||
boolean cyclic;
|
||||
|
||||
/**
|
||||
* Instantiates a new GradientPaint with cyclic or acyclic mode.
|
||||
*
|
||||
* @param point1
|
||||
* the first specified point.
|
||||
* @param color1
|
||||
* the Color of the first specified point.
|
||||
* @param point2
|
||||
* the second specified point.
|
||||
* @param color2
|
||||
* the Color of the second specified point.
|
||||
* @param cyclic
|
||||
* the cyclic mode - true if the gradient pattern should cycle
|
||||
* repeatedly between the two colors; false otherwise.
|
||||
*/
|
||||
public GradientPaint(Point2D point1, Color color1, Point2D point2, Color color2, boolean cyclic) {
|
||||
if (point1 == null || point2 == null) {
|
||||
// awt.6D=Point is null
|
||||
throw new NullPointerException(Messages.getString("awt.6D")); //$NON-NLS-1$
|
||||
}
|
||||
if (color1 == null || color2 == null) {
|
||||
// awt.6E=Color is null
|
||||
throw new NullPointerException(Messages.getString("awt.6E")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
this.point1 = point1;
|
||||
this.point2 = point2;
|
||||
this.color1 = color1;
|
||||
this.color2 = color2;
|
||||
this.cyclic = cyclic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new GradientPaint with cyclic or acyclic mode; points are
|
||||
* specified by coordinates.
|
||||
*
|
||||
* @param x1
|
||||
* the X coordinate of the first point.
|
||||
* @param y1
|
||||
* the Y coordinate of the first point.
|
||||
* @param color1
|
||||
* the color of the first point.
|
||||
* @param x2
|
||||
* the X coordinate of the second point.
|
||||
* @param y2
|
||||
* the Y coordinate of the second point.
|
||||
* @param color2
|
||||
* the color of the second point.
|
||||
* @param cyclic
|
||||
* the cyclic mode - true if the gradient pattern should cycle
|
||||
* repeatedly between the two colors; false otherwise.
|
||||
*/
|
||||
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2,
|
||||
boolean cyclic) {
|
||||
this(new Point2D.Float(x1, y1), color1, new Point2D.Float(x2, y2), color2, cyclic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new acyclic GradientPaint; points are specified by
|
||||
* coordinates.
|
||||
*
|
||||
* @param x1
|
||||
* the X coordinate of the first point.
|
||||
* @param y1
|
||||
* the Y coordinate of the first point.
|
||||
* @param color1
|
||||
* the color of the first point.
|
||||
* @param x2
|
||||
* the X coordinate of the second point.
|
||||
* @param y2
|
||||
* the Y coordinate of the second point.
|
||||
* @param color2
|
||||
* the color of the second point.
|
||||
*/
|
||||
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2) {
|
||||
this(x1, y1, color1, x2, y2, color2, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new acyclic GradientPaint.
|
||||
*
|
||||
* @param point1
|
||||
* the first specified point.
|
||||
* @param color1
|
||||
* the Color of the first specified point.
|
||||
* @param point2
|
||||
* the second specified point.
|
||||
* @param color2
|
||||
* the Color of the second specified point.
|
||||
*/
|
||||
public GradientPaint(Point2D point1, Color color1, Point2D point2, Color color2) {
|
||||
this(point1, color1, point2, color2, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates PaintContext for a color pattern generating.
|
||||
*
|
||||
* @param cm
|
||||
* the ColorModel of the Paint data.
|
||||
* @param deviceBounds
|
||||
* the bounding Rectangle of graphics primitives being rendered
|
||||
* in the device space.
|
||||
* @param userBounds
|
||||
* the bounding Rectangle of graphics primitives being rendered
|
||||
* in the user space.
|
||||
* @param t
|
||||
* the AffineTransform from user space into device space.
|
||||
* @param hints
|
||||
* the RrenderingHints object.
|
||||
* @return the PaintContext for color pattern generating.
|
||||
* @see java.awt.Paint#createContext(java.awt.image.ColorModel,
|
||||
* java.awt.Rectangle, java.awt.geom.Rectangle2D,
|
||||
* java.awt.geom.AffineTransform, java.awt.RenderingHints)
|
||||
*/
|
||||
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
|
||||
Rectangle2D userBounds, AffineTransform t, RenderingHints hints) {
|
||||
return new GradientPaintContext(cm, t, point1, color1, point2, color2, cyclic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color of the first point.
|
||||
*
|
||||
* @return the color of the first point.
|
||||
*/
|
||||
public Color getColor1() {
|
||||
return color1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the color of the second point.
|
||||
*
|
||||
* @return the color of the second point.
|
||||
*/
|
||||
public Color getColor2() {
|
||||
return color2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the first point.
|
||||
*
|
||||
* @return the Point object - the first point.
|
||||
*/
|
||||
public Point2D getPoint1() {
|
||||
return point1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the second point.
|
||||
*
|
||||
* @return the Point object - the second point.
|
||||
*/
|
||||
public Point2D getPoint2() {
|
||||
return point2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transparency mode for the GradientPaint.
|
||||
*
|
||||
* @return the transparency mode for the GradientPaint.
|
||||
* @see java.awt.Transparency#getTransparency()
|
||||
*/
|
||||
public int getTransparency() {
|
||||
int a1 = color1.getAlpha();
|
||||
int a2 = color2.getAlpha();
|
||||
return (a1 == 0xFF && a2 == 0xFF) ? OPAQUE : TRANSLUCENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GradientPaint mode: true for cyclic mode, false for acyclic
|
||||
* mode.
|
||||
*
|
||||
* @return true if the gradient cycles repeatedly between the two colors;
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean isCyclic() {
|
||||
return cyclic;
|
||||
}
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Denis M. Kishenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
class GradientPaintContext implements PaintContext {
|
||||
|
||||
/**
|
||||
* The size of noncyclic part of color lookup table
|
||||
*/
|
||||
static int LOOKUP_SIZE = 256;
|
||||
|
||||
/**
|
||||
* The index mask to lookup color in the table
|
||||
*/
|
||||
static int LOOKUP_MASK = 0x1FF;
|
||||
|
||||
/**
|
||||
* The min value equivalent to zero. If absolute value less then ZERO it considered as zero.
|
||||
*/
|
||||
static double ZERO = 1E-10;
|
||||
|
||||
/**
|
||||
* The ColorModel user defined for PaintContext
|
||||
*/
|
||||
ColorModel cm;
|
||||
|
||||
/**
|
||||
* The indicator of cycle filling.
|
||||
*/
|
||||
boolean cyclic;
|
||||
|
||||
/**
|
||||
* The integer color value of the start point
|
||||
*/
|
||||
int c1;
|
||||
|
||||
/**
|
||||
* The integer color value of the end point
|
||||
*/
|
||||
int c2;
|
||||
|
||||
/**
|
||||
* The lookup gradient color table
|
||||
*/
|
||||
int[] table;
|
||||
|
||||
/**
|
||||
* The tempopary pre-calculated value to evalutae color index
|
||||
*/
|
||||
int dx;
|
||||
|
||||
/**
|
||||
* The tempopary pre-calculated value to evalutae color index
|
||||
*/
|
||||
int dy;
|
||||
|
||||
/**
|
||||
* The tempopary pre-calculated value to evalutae color index
|
||||
*/
|
||||
int delta;
|
||||
|
||||
/**
|
||||
* Constructs a new GradientPaintcontext
|
||||
* @param cm - not used
|
||||
* @param t - the fill transformation
|
||||
* @param point1 - the start fill point
|
||||
* @param color1 - color of the start point
|
||||
* @param point2 - the end fill point
|
||||
* @param color2 - color of the end point
|
||||
* @param cyclic - the indicator of cycle filling
|
||||
*/
|
||||
GradientPaintContext(ColorModel cm, AffineTransform t, Point2D point1, Color color1, Point2D point2, Color color2, boolean cyclic) {
|
||||
this.cyclic = cyclic;
|
||||
this.cm = ColorModel.getRGBdefault();
|
||||
|
||||
c1 = color1.getRGB();
|
||||
c2 = color2.getRGB();
|
||||
|
||||
double px = point2.getX() - point1.getX();
|
||||
double py = point2.getY() - point1.getY();
|
||||
|
||||
Point2D p = t.transform(point1, null);
|
||||
Point2D bx = new Point2D.Double(px, py);
|
||||
Point2D by = new Point2D.Double(py, -px);
|
||||
|
||||
t.deltaTransform(bx, bx);
|
||||
t.deltaTransform(by, by);
|
||||
|
||||
double vec = bx.getX() * by.getY() - bx.getY() * by.getX();
|
||||
|
||||
if (Math.abs(vec) < ZERO) {
|
||||
dx = dy = delta = 0;
|
||||
table = new int[1];
|
||||
table[0] = c1;
|
||||
} else {
|
||||
double mult = LOOKUP_SIZE * 256 / vec;
|
||||
dx = (int)(by.getX() * mult);
|
||||
dy = (int)(by.getY() * mult);
|
||||
delta = (int)((p.getX() * by.getY() - p.getY() * by.getX()) * mult);
|
||||
createTable();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create color index lookup table. Calculate 256 step trasformation from
|
||||
* the start point color to the end point color. Colors multiplied by 256 to do integer calculations.
|
||||
*/
|
||||
void createTable() {
|
||||
double ca = (c1 >> 24) & 0xFF;
|
||||
double cr = (c1 >> 16) & 0xFF;
|
||||
double cg = (c1 >> 8) & 0xFF;
|
||||
double cb = c1 & 0xFF;
|
||||
|
||||
double k = 1.0 / LOOKUP_SIZE;
|
||||
double da = (((c2 >> 24) & 0xFF) - ca) * k;
|
||||
double dr = (((c2 >> 16) & 0xFF) - cr) * k;
|
||||
double dg = (((c2 >> 8) & 0xFF) - cg) * k;
|
||||
double db = ((c2 & 0xFF) - cb) * k;
|
||||
|
||||
table = new int[cyclic ? LOOKUP_SIZE + LOOKUP_SIZE : LOOKUP_SIZE];
|
||||
for(int i = 0; i < LOOKUP_SIZE; i++) {
|
||||
table[i] =
|
||||
(int)ca << 24 |
|
||||
(int)cr << 16 |
|
||||
(int)cg << 8 |
|
||||
(int)cb;
|
||||
ca += da;
|
||||
cr += dr;
|
||||
cg += dg;
|
||||
cb += db;
|
||||
}
|
||||
if (cyclic) {
|
||||
for(int i = 0; i < LOOKUP_SIZE; i++) {
|
||||
table[LOOKUP_SIZE + LOOKUP_SIZE - 1 - i] = table[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ColorModel getColorModel() {
|
||||
return cm;
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
public Raster getRaster(int x, int y, int w, int h) {
|
||||
WritableRaster rast = cm.createCompatibleWritableRaster(w, h);
|
||||
|
||||
int[] buf = ((DataBufferInt)rast.getDataBuffer()).getData();
|
||||
|
||||
int c = x * dy - y * dx - delta;
|
||||
int cx = dy;
|
||||
int cy = - w * dy - dx;
|
||||
int k = 0;
|
||||
|
||||
if (cyclic) {
|
||||
for(int j = 0; j < h; j++) {
|
||||
for(int i = 0; i < w; i++) {
|
||||
buf[k++] = table[(c >> 8) & LOOKUP_MASK];
|
||||
c += cx;
|
||||
}
|
||||
c += cy;
|
||||
}
|
||||
} else {
|
||||
for(int j = 0; j < h; j++) {
|
||||
for(int i = 0; i < w; i++) {
|
||||
int index = c >> 8;
|
||||
buf[k++] = index < 0 ? c1 : index >= LOOKUP_SIZE ? c2 : table[index];
|
||||
c += cx;
|
||||
}
|
||||
c += cy;
|
||||
}
|
||||
}
|
||||
|
||||
return rast;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,924 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
|
||||
/**
|
||||
* The abstract Graphics class allows applications to draw on a screen or other
|
||||
* rendering target. There are several properties which define rendering
|
||||
* options: origin point, clipping area, color, font. <br>
|
||||
* <br>
|
||||
* The origin point specifies the beginning of the clipping area coordinate
|
||||
* system. All coordinates used in rendering operations are computed with
|
||||
* respect to this point. The clipping area defines the boundaries where
|
||||
* rendering operations can be performed. Rendering operations can't modify
|
||||
* pixels outside of the clipping area. <br>
|
||||
* <br>
|
||||
* The draw and fill methods allow applications to drawing shapes, text, images
|
||||
* with specified font and color options in the specified part of the screen.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class Graphics {
|
||||
|
||||
// Constructors
|
||||
|
||||
/**
|
||||
* Instantiates a new Graphics. This constructor is default for Graphics and
|
||||
* can not be called directly.
|
||||
*/
|
||||
protected Graphics() {
|
||||
}
|
||||
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* Creates a copy of the Graphics object with a new origin and a new
|
||||
* specified clip area. The new clip area is the rectangle defined by the
|
||||
* origin point with coordinates X,Y and the given width and height. The
|
||||
* coordinates of all subsequent rendering operations will be computed with
|
||||
* respect to the new origin and can be performed only within the range of
|
||||
* the clipping area dimensions.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the original point.
|
||||
* @param y
|
||||
* the Y coordinate of the original point.
|
||||
* @param width
|
||||
* the width of clipping area.
|
||||
* @param height
|
||||
* the height of clipping area.
|
||||
* @return the Graphics object with new origin point and clipping area.
|
||||
*/
|
||||
public Graphics create(int x, int y, int width, int height) {
|
||||
Graphics res = create();
|
||||
res.translate(x, y);
|
||||
res.clipRect(0, 0, width, height);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the highlighted outline of a rectangle.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle's top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle's top left corner.
|
||||
* @param width
|
||||
* the width of rectangle.
|
||||
* @param height
|
||||
* the height of rectangle.
|
||||
* @param raised
|
||||
* a boolean value that determines whether the rectangle is drawn
|
||||
* as raised or indented.
|
||||
*/
|
||||
public void draw3DRect(int x, int y, int width, int height, boolean raised) {
|
||||
// Note: lighter/darker colors should be used to draw 3d rect.
|
||||
// The resulting rect is (width+1)x(height+1). Stroke and paint
|
||||
// attributes of
|
||||
// the Graphics2D should be reset to the default values.
|
||||
// fillRect is used instead of drawLine to bypass stroke
|
||||
// reset/set and rasterization.
|
||||
|
||||
Color color = getColor();
|
||||
Color colorUp, colorDown;
|
||||
if (raised) {
|
||||
colorUp = color.brighter();
|
||||
colorDown = color.darker();
|
||||
} else {
|
||||
colorUp = color.darker();
|
||||
colorDown = color.brighter();
|
||||
}
|
||||
|
||||
setColor(colorUp);
|
||||
fillRect(x, y, width, 1);
|
||||
fillRect(x, y + 1, 1, height);
|
||||
|
||||
setColor(colorDown);
|
||||
fillRect(x + width, y, 1, height);
|
||||
fillRect(x + 1, y + height, width, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the text represented by byte array. This method uses the current
|
||||
* font and color for rendering.
|
||||
*
|
||||
* @param bytes
|
||||
* the byte array which contains the text to be drawn.
|
||||
* @param off
|
||||
* the offset within the byte array of the text to be drawn.
|
||||
* @param len
|
||||
* the number of bytes of text to draw.
|
||||
* @param x
|
||||
* the X coordinate where the text is to be drawn.
|
||||
* @param y
|
||||
* the Y coordinate where the text is to be drawn.
|
||||
*/
|
||||
public void drawBytes(byte[] bytes, int off, int len, int x, int y) {
|
||||
drawString(new String(bytes, off, len), x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the text represented by character array. This method uses the
|
||||
* current font and color for rendering.
|
||||
*
|
||||
* @param chars
|
||||
* the character array.
|
||||
* @param off
|
||||
* the offset within the character array of the text to be drawn.
|
||||
* @param len
|
||||
* the number of characters which will be drawn.
|
||||
* @param x
|
||||
* the X coordinate where the text is to be drawn.
|
||||
* @param y
|
||||
* the Y coordinate where the text is to be drawn.
|
||||
*/
|
||||
public void drawChars(char[] chars, int off, int len, int x, int y) {
|
||||
drawString(new String(chars, off, len), x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the outline of a polygon which is defined by Polygon object.
|
||||
*
|
||||
* @param p
|
||||
* the Polygon object.
|
||||
*/
|
||||
public void drawPolygon(Polygon p) {
|
||||
drawPolygon(p.xpoints, p.ypoints, p.npoints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the rectangle with the specified width and length and top left
|
||||
* corner coordinates.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle's top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle's top left corner.
|
||||
* @param width
|
||||
* the width of the rectangle.
|
||||
* @param height
|
||||
* the height of the rectangle.
|
||||
*/
|
||||
public void drawRect(int x, int y, int width, int height) {
|
||||
int[] xpoints = {
|
||||
x, x, x + width, x + width
|
||||
};
|
||||
int[] ypoints = {
|
||||
y, y + height, y + height, y
|
||||
};
|
||||
|
||||
drawPolygon(xpoints, ypoints, 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the highlighted outline of a rectangle.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle's top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle's top left corner.
|
||||
* @param width
|
||||
* the width of the rectangle.
|
||||
* @param height
|
||||
* the height of the rectangle.
|
||||
* @param raised
|
||||
* a boolean value that determines whether the rectangle is drawn
|
||||
* as raised or indented.
|
||||
*/
|
||||
public void fill3DRect(int x, int y, int width, int height, boolean raised) {
|
||||
// Note: lighter/darker colors should be used to draw 3d rect.
|
||||
// The resulting rect is (width)x(height), same as fillRect.
|
||||
// Stroke and paint attributes of the Graphics2D should be reset
|
||||
// to the default values. fillRect is used instead of drawLine to
|
||||
// bypass stroke reset/set and line rasterization.
|
||||
|
||||
Color color = getColor();
|
||||
Color colorUp, colorDown;
|
||||
if (raised) {
|
||||
colorUp = color.brighter();
|
||||
colorDown = color.darker();
|
||||
setColor(color);
|
||||
} else {
|
||||
colorUp = color.darker();
|
||||
colorDown = color.brighter();
|
||||
setColor(colorUp);
|
||||
}
|
||||
|
||||
width--;
|
||||
height--;
|
||||
fillRect(x + 1, y + 1, width - 1, height - 1);
|
||||
|
||||
setColor(colorUp);
|
||||
fillRect(x, y, width, 1);
|
||||
fillRect(x, y + 1, 1, height);
|
||||
|
||||
setColor(colorDown);
|
||||
fillRect(x + width, y, 1, height);
|
||||
fillRect(x + 1, y + height, width, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the polygon with the current color.
|
||||
*
|
||||
* @param p
|
||||
* the Polygon object.
|
||||
*/
|
||||
public void fillPolygon(Polygon p) {
|
||||
fillPolygon(p.xpoints, p.ypoints, p.npoints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disposes of the Graphics.
|
||||
*/
|
||||
@Override
|
||||
public void finalize() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounds of the current clipping area as a rectangle and copies it
|
||||
* to an existing rectangle.
|
||||
*
|
||||
* @param r
|
||||
* a Rectangle object where the current clipping area bounds are
|
||||
* to be copied.
|
||||
* @return the bounds of the current clipping area.
|
||||
*/
|
||||
public Rectangle getClipBounds(Rectangle r) {
|
||||
Shape clip = getClip();
|
||||
|
||||
if (clip != null) {
|
||||
// TODO: Can we get shape bounds without creating Rectangle object?
|
||||
Rectangle b = clip.getBounds();
|
||||
r.x = b.x;
|
||||
r.y = b.y;
|
||||
r.width = b.width;
|
||||
r.height = b.height;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounds of the current clipping area as a rectangle.
|
||||
*
|
||||
* @return a Rectangle object.
|
||||
* @deprecated Use {@link #getClipBounds()}
|
||||
*/
|
||||
@Deprecated
|
||||
public Rectangle getClipRect() {
|
||||
return getClipBounds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the font metrics of the current font. The font metrics object
|
||||
* contains information about the rendering of a particular font.
|
||||
*
|
||||
* @return the font metrics of current font.
|
||||
*/
|
||||
public FontMetrics getFontMetrics() {
|
||||
return getFontMetrics(getFont());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not the specified rectangle intersects the current
|
||||
* clipping area.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle.
|
||||
* @param width
|
||||
* the width of the rectangle.
|
||||
* @param height
|
||||
* the height of the rectangle.
|
||||
* @return true, if the specified rectangle intersects the current clipping
|
||||
* area, false otherwise.
|
||||
*/
|
||||
public boolean hitClip(int x, int y, int width, int height) {
|
||||
// TODO: Create package private method Rectangle.intersects(int, int,
|
||||
// int, int);
|
||||
return getClipBounds().intersects(new Rectangle(x, y, width, height));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string which represents this Graphics object.
|
||||
*
|
||||
* @return the string which represents this Graphics object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// TODO: Think about string representation of Graphics.
|
||||
return "Graphics"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
// Abstract methods
|
||||
|
||||
/**
|
||||
* Clears the specified rectangle. This method fills specified rectangle
|
||||
* with background color.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle.
|
||||
* @param width
|
||||
* the width of the rectangle.
|
||||
* @param height
|
||||
* the height of the rectangle.
|
||||
*/
|
||||
public abstract void clearRect(int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Intersects the current clipping area with a new rectangle. If the current
|
||||
* clipping area is not defined, the rectangle becomes a new clipping area.
|
||||
* Rendering operations are only allowed within the new the clipping area.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle for intersection.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle for intersection.
|
||||
* @param width
|
||||
* the width of the rectangle for intersection.
|
||||
* @param height
|
||||
* the height of the rectangle for intersection.
|
||||
*/
|
||||
public abstract void clipRect(int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Copies the rectangle area to another area specified by a distance (dx,
|
||||
* dy) from the original rectangle's location. Positive dx and dy values
|
||||
* give a new location defined by translation to the right and down from the
|
||||
* original location, negative dx and dy values - to the left and up.
|
||||
*
|
||||
* @param sx
|
||||
* the X coordinate of the rectangle which will be copied.
|
||||
* @param sy
|
||||
* the Y coordinate of the rectangle which will be copied.
|
||||
* @param width
|
||||
* the width of the rectangle which will be copied.
|
||||
* @param height
|
||||
* the height of the rectangle which will be copied.
|
||||
* @param dx
|
||||
* the horizontal distance from the source rectangle's location
|
||||
* to the copy's location.
|
||||
* @param dy
|
||||
* the vertical distance from the source rectangle's location to
|
||||
* the copy's location.
|
||||
*/
|
||||
public abstract void copyArea(int sx, int sy, int width, int height, int dx, int dy);
|
||||
|
||||
/**
|
||||
* Creates a new copy of this Graphics.
|
||||
*
|
||||
* @return a new Graphics context which is a copy of this Graphics.
|
||||
*/
|
||||
public abstract Graphics create();
|
||||
|
||||
/**
|
||||
* Disposes of the Graphics. This Graphics object can not be used after
|
||||
* calling this method.
|
||||
*/
|
||||
public abstract void dispose();
|
||||
|
||||
/**
|
||||
* Draws the arc covering the specified rectangle and using the current
|
||||
* color. The rectangle is defined by the origin point (X, Y) and dimensions
|
||||
* (width and height). The arc center is the the center of specified
|
||||
* rectangle. The angle origin is 3 o'clock position, the positive angle is
|
||||
* counted as a counter-clockwise rotation, the negative angle is counted as
|
||||
* clockwise rotation.
|
||||
*
|
||||
* @param x
|
||||
* the X origin coordinate of the rectangle which scales the arc.
|
||||
* @param y
|
||||
* the Y origin coordinate of the rectangle which scales the arc.
|
||||
* @param width
|
||||
* the width of the rectangle which scales the arc.
|
||||
* @param height
|
||||
* the height of the rectangle which scales the arc.
|
||||
* @param sa
|
||||
* start angle - the origin angle of arc.
|
||||
* @param ea
|
||||
* arc angle - the angular arc value relative to the start angle.
|
||||
*/
|
||||
public abstract void drawArc(int x, int y, int width, int height, int sa, int ea);
|
||||
|
||||
/**
|
||||
* Draws the specified image with the defined background color. The top left
|
||||
* corner of image will be drawn at point (x, y) in current coordinate
|
||||
* system. The image loading process notifies the specified Image Observer.
|
||||
* This method returns true if the image has loaded, otherwise it returns
|
||||
* false.
|
||||
*
|
||||
* @param img
|
||||
* the image which will be drawn.
|
||||
* @param x
|
||||
* the X coordinate of the image top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the image top left corner.
|
||||
* @param bgcolor
|
||||
* the background color.
|
||||
* @param observer
|
||||
* the ImageObserver object which should be notified about image
|
||||
* loading process.
|
||||
* @return true, if loading image is successful or image is null, false
|
||||
* otherwise.
|
||||
*/
|
||||
public abstract boolean drawImage(Image img, int x, int y, Color bgcolor, ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Draws the specified image. The top left corner of image will be drawn at
|
||||
* point (x, y) in current coordinate system. The image loading process
|
||||
* notifies the specified Image Observer. This method returns true if the
|
||||
* image has loaded, otherwise it returns false.
|
||||
*
|
||||
* @param img
|
||||
* the image which will be drawn.
|
||||
* @param x
|
||||
* the X coordinate of the image top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the image top left corner.
|
||||
* @param observer
|
||||
* the ImageObserver object which should be notified about image
|
||||
* loading process.
|
||||
* @return true, if loading image is successful or image is null, otherwise
|
||||
* false.
|
||||
*/
|
||||
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Scales the specified image to fit in the specified rectangle and draws it
|
||||
* with the defined background color. The top left corner of the image will
|
||||
* be drawn at the point (x, y) in current coordinate system. The non-opaque
|
||||
* pixels will be drawn in the background color. The image loading process
|
||||
* notifies the specified Image Observer. This method returns true if the
|
||||
* image has loaded, otherwise it returns false.
|
||||
*
|
||||
* @param img
|
||||
* the image which will be drawn.
|
||||
* @param x
|
||||
* the X coordinate of the image's top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the image's top left corner.
|
||||
* @param width
|
||||
* the width of rectangle which scales the image.
|
||||
* @param height
|
||||
* the height of rectangle which scales the image.
|
||||
* @param bgcolor
|
||||
* the background color.
|
||||
* @param observer
|
||||
* the ImageObserver object which should be notified about image
|
||||
* loading process.
|
||||
* @return true, if loading image is successful or image is null, otherwise
|
||||
* false.
|
||||
*/
|
||||
public abstract boolean drawImage(Image img, int x, int y, int width, int height,
|
||||
Color bgcolor, ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Scales the specified image to fit in the specified rectangle and draws
|
||||
* it. The top left corner of the image will be drawn at the point (x, y) in
|
||||
* current coordinate system. The image loading process notifies the
|
||||
* specified Image Observer. This method returns true if the image has
|
||||
* loaded, otherwise it returns false.
|
||||
*
|
||||
* @param img
|
||||
* the image which will be drawn.
|
||||
* @param x
|
||||
* the X coordinate of the image top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the image top left corner.
|
||||
* @param width
|
||||
* the width of rectangle which scales the image.
|
||||
* @param height
|
||||
* the height of rectangle which scales the image.
|
||||
* @param observer
|
||||
* the ImageObserver object which should be notified about image
|
||||
* loading process.
|
||||
* @return true, if loading image is successful or image is null, otherwise
|
||||
* false.
|
||||
*/
|
||||
public abstract boolean drawImage(Image img, int x, int y, int width, int height,
|
||||
ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Scales the specified area of the specified image to fit in the rectangle
|
||||
* area defined by its corners coordinates and draws the sub-image with the
|
||||
* specified background color. The sub-image to be drawn is defined by its
|
||||
* top left corner coordinates (sx1, sy1) and bottom right corner
|
||||
* coordinates (sx2, sy2) computed with respect to the origin (top left
|
||||
* corner) of the source image. The non opaque pixels will be drawn in the
|
||||
* background color. The image loading process notifies specified Image
|
||||
* Observer. This method returns true if the image has loaded, otherwise it
|
||||
* returns false.
|
||||
*
|
||||
* @param img
|
||||
* the image which will be drawn.
|
||||
* @param dx1
|
||||
* the X top left corner coordinate of the destination rectangle
|
||||
* area.
|
||||
* @param dy1
|
||||
* the Y top left corner coordinate of the destination rectangle
|
||||
* area.
|
||||
* @param dx2
|
||||
* the X bottom right corner coordinate of the destination
|
||||
* rectangle area.
|
||||
* @param dy2
|
||||
* the Y bottom right corner coordinate of the destination
|
||||
* rectangle area.
|
||||
* @param sx1
|
||||
* the X top left corner coordinate of the area to be drawn
|
||||
* within the source image.
|
||||
* @param sy1
|
||||
* the Y top left corner coordinate of the area to be drawn
|
||||
* within the source image.
|
||||
* @param sx2
|
||||
* the X bottom right corner coordinate of the area to be drawn
|
||||
* within the source image.
|
||||
* @param sy2
|
||||
* the Y bottom right corner coordinate of the area to be drawn
|
||||
* within the source image.
|
||||
* @param bgcolor
|
||||
* the background color.
|
||||
* @param observer
|
||||
* the ImageObserver object which should be notified about image
|
||||
* loading process.
|
||||
* @return true, if loading image is successful or image is null, false
|
||||
* otherwise.
|
||||
*/
|
||||
public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1,
|
||||
int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Scales the specified area of the specified image to fit in the rectangle
|
||||
* area defined by its corners coordinates and draws the sub-image. The
|
||||
* sub-image to be drawn is defined by its top left corner coordinates (sx1,
|
||||
* sy1) and bottom right corner coordinates (sx2, sy2) computed with respect
|
||||
* to the origin (top left corner) of the source image. The image loading
|
||||
* process notifies specified Image Observer. This method returns true if
|
||||
* the image has loaded, otherwise it returns false.
|
||||
*
|
||||
* @param img
|
||||
* the image which will be drawn.
|
||||
* @param dx1
|
||||
* the X top left corner coordinate of the destination rectangle
|
||||
* area.
|
||||
* @param dy1
|
||||
* the Y top left corner coordinate of the destination rectangle
|
||||
* area.
|
||||
* @param dx2
|
||||
* the X bottom right corner coordinate of the destination
|
||||
* rectangle area.
|
||||
* @param dy2
|
||||
* the Y bottom right corner coordinate of the destination
|
||||
* rectangle area.
|
||||
* @param sx1
|
||||
* the X top left corner coordinate of the area to be drawn
|
||||
* within the source image.
|
||||
* @param sy1
|
||||
* the Y top left corner coordinate of the area to be drawn
|
||||
* within the source image.
|
||||
* @param sx2
|
||||
* the X bottom right corner coordinate of the area to be drawn
|
||||
* within the source image.
|
||||
* @param sy2
|
||||
* the Y bottom right corner coordinate of the area to be drawn
|
||||
* within the source image.
|
||||
* @param observer
|
||||
* the ImageObserver object which should be notified about image
|
||||
* loading process.
|
||||
* @return true, if loading image is successful or image is null, false
|
||||
* otherwise.
|
||||
*/
|
||||
public abstract boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1,
|
||||
int sy1, int sx2, int sy2, ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Draws a line from the point (x1, y1) to the point (x2, y2). This method
|
||||
* draws the line with current color which can be changed by setColor(Color
|
||||
* c) method.
|
||||
*
|
||||
* @param x1
|
||||
* the X coordinate of the first point.
|
||||
* @param y1
|
||||
* the Y coordinate of the first point.
|
||||
* @param x2
|
||||
* the X coordinate of the second point.
|
||||
* @param y2
|
||||
* the Y coordinate of the second point.
|
||||
*/
|
||||
public abstract void drawLine(int x1, int y1, int x2, int y2);
|
||||
|
||||
/**
|
||||
* Draws the outline of an oval to fit in the rectangle defined by the given
|
||||
* width, height, and top left corner.
|
||||
*
|
||||
* @param x
|
||||
* the X top left corner oval coordinate.
|
||||
* @param y
|
||||
* the Y top left corner oval coordinate.
|
||||
* @param width
|
||||
* the oval width.
|
||||
* @param height
|
||||
* the oval height.
|
||||
*/
|
||||
public abstract void drawOval(int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Draws the outline of a polygon. The polygon vertices are defined by
|
||||
* points with xpoints[i], ypoints[i] as coordinates. The polygon edges are
|
||||
* the lines from the points with (xpoints[i-1], ypoints[i-1]) coordinates
|
||||
* to the points with (xpoints[i], ypoints[i]) coordinates, for 0 < i <
|
||||
* npoints +1.
|
||||
*
|
||||
* @param xpoints
|
||||
* the array of X coordinates of the polygon vertices.
|
||||
* @param ypoints
|
||||
* the array of Y coordinates of the polygon vertices.
|
||||
* @param npoints
|
||||
* the number of polygon vertices/points.
|
||||
*/
|
||||
public abstract void drawPolygon(int[] xpoints, int[] ypoints, int npoints);
|
||||
|
||||
/**
|
||||
* Draws a set of connected lines which are defined by the x and y
|
||||
* coordinate arrays. The polyline is closed if coordinates of the first
|
||||
* point are the same as coordinates of the last point.
|
||||
*
|
||||
* @param xpoints
|
||||
* the array of X point coordinates.
|
||||
* @param ypoints
|
||||
* the array of Y point coordinates.
|
||||
* @param npoints
|
||||
* the number of points.
|
||||
*/
|
||||
public abstract void drawPolyline(int[] xpoints, int[] ypoints, int npoints);
|
||||
|
||||
/**
|
||||
* Draws the outline of a rectangle with round corners.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle's top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle's top left corner.
|
||||
* @param width
|
||||
* the width of the rectangle.
|
||||
* @param height
|
||||
* the height of the rectangle.
|
||||
* @param arcWidth
|
||||
* the arc width for the corners.
|
||||
* @param arcHeight
|
||||
* the arc height for the corners.
|
||||
*/
|
||||
public abstract void drawRoundRect(int x, int y, int width, int height, int arcWidth,
|
||||
int arcHeight);
|
||||
|
||||
/**
|
||||
* Draws a text defined by an iterator. The iterator should specify the font
|
||||
* for every character.
|
||||
*
|
||||
* @param iterator
|
||||
* the iterator.
|
||||
* @param x
|
||||
* the X coordinate of the first character.
|
||||
* @param y
|
||||
* the Y coordinate of the first character.
|
||||
*/
|
||||
public abstract void drawString(AttributedCharacterIterator iterator, int x, int y);
|
||||
|
||||
/**
|
||||
* Draws a text defined by a string. This method draws the text with current
|
||||
* font and color.
|
||||
*
|
||||
* @param str
|
||||
* the string.
|
||||
* @param x
|
||||
* the X coordinate of the first character.
|
||||
* @param y
|
||||
* the Y coordinate of the first character.
|
||||
*/
|
||||
public abstract void drawString(String str, int x, int y);
|
||||
|
||||
/**
|
||||
* Fills the arc covering the rectangle and using the current color. The
|
||||
* rectangle is defined by the origin point (X, Y) and dimensions (width and
|
||||
* height). The arc center is the the center of specified rectangle. The
|
||||
* angle origin is at the 3 o'clock position, and a positive angle gives
|
||||
* counter-clockwise rotation, a negative angle gives clockwise rotation.
|
||||
*
|
||||
* @param x
|
||||
* the X origin coordinate of the rectangle which scales the arc.
|
||||
* @param y
|
||||
* the Y origin coordinate of the rectangle which scales the arc.
|
||||
* @param width
|
||||
* the width of the rectangle which scales the arc.
|
||||
* @param height
|
||||
* the height of the rectangle which scales the arc.
|
||||
* @param sa
|
||||
* start angle - the origin angle of arc.
|
||||
* @param ea
|
||||
* arc angle - the angular arc value relative to the start angle.
|
||||
*/
|
||||
public abstract void fillArc(int x, int y, int width, int height, int sa, int ea);
|
||||
|
||||
/**
|
||||
* Fills an oval with the current color where the oval is defined by the
|
||||
* bounding rectangle with the given width, height, and top left corner.
|
||||
*
|
||||
* @param x
|
||||
* the X top left corner oval coordinate.
|
||||
* @param y
|
||||
* the Y top left corner oval coordinate.
|
||||
* @param width
|
||||
* the oval width.
|
||||
* @param height
|
||||
* the oval height.
|
||||
*/
|
||||
public abstract void fillOval(int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Fills a polygon with the current color. The polygon vertices are defined
|
||||
* by the points with xpoints[i], ypoints[i] as coordinates. The polygon
|
||||
* edges are the lines from the points with (xpoints[i-1], ypoints[i-1])
|
||||
* coordinates to the points with (xpoints[i], ypoints[i]) coordinates, for
|
||||
* 0 < i < npoints +1.
|
||||
*
|
||||
* @param xpoints
|
||||
* the array of X coordinates of the polygon vertices.
|
||||
* @param ypoints
|
||||
* the array of Y coordinates of the polygon vertices.
|
||||
* @param npoints
|
||||
* the number of polygon vertices/points.
|
||||
*/
|
||||
public abstract void fillPolygon(int[] xpoints, int[] ypoints, int npoints);
|
||||
|
||||
/**
|
||||
* Fills a rectangle with the current color. The rectangle is defined by its
|
||||
* width and length and top left corner coordinates.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle's top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle's top left corner.
|
||||
* @param width
|
||||
* the width of rectangle.
|
||||
* @param height
|
||||
* the height of rectangle.
|
||||
*/
|
||||
public abstract void fillRect(int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Fills a round cornered rectangle with the current color.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the top left corner of the bounding
|
||||
* rectangle.
|
||||
* @param y
|
||||
* the Y coordinate of the top left corner of the bounding
|
||||
* rectangle.
|
||||
* @param width
|
||||
* the width of the bounding rectangle.
|
||||
* @param height
|
||||
* the height of the bounding rectangle.
|
||||
* @param arcWidth
|
||||
* the arc width at the corners.
|
||||
* @param arcHeight
|
||||
* the arc height at the corners.
|
||||
*/
|
||||
public abstract void fillRoundRect(int x, int y, int width, int height, int arcWidth,
|
||||
int arcHeight);
|
||||
|
||||
/**
|
||||
* Gets the clipping area. <br>
|
||||
* <br>
|
||||
*
|
||||
* @return a Shape object of the clipping area or null if it is not set.
|
||||
*/
|
||||
public abstract Shape getClip();
|
||||
|
||||
/**
|
||||
* Gets the bounds of the current clipping area as a rectangle.
|
||||
*
|
||||
* @return a Rectangle object which represents the bounds of the current
|
||||
* clipping area.
|
||||
*/
|
||||
public abstract Rectangle getClipBounds();
|
||||
|
||||
/**
|
||||
* Gets the current color of Graphics.
|
||||
*
|
||||
* @return the current color.
|
||||
*/
|
||||
public abstract Color getColor();
|
||||
|
||||
/**
|
||||
* Gets the current font of Graphics.
|
||||
*
|
||||
* @return the current font.
|
||||
*/
|
||||
public abstract Font getFont();
|
||||
|
||||
/**
|
||||
* Gets the font metrics of the specified font. The font metrics object
|
||||
* contains information about the rendering of a particular font.
|
||||
*
|
||||
* @param font
|
||||
* the specified font.
|
||||
* @return the font metrics for the specified font.
|
||||
*/
|
||||
public abstract FontMetrics getFontMetrics(Font font);
|
||||
|
||||
/**
|
||||
* Sets the new clipping area specified by rectangle. The new clipping area
|
||||
* doesn't depend on the window's visibility. Rendering operations can't be
|
||||
* performed outside new clipping area.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the new clipping rectangle.
|
||||
* @param y
|
||||
* the Y coordinate of the new clipping rectangle.
|
||||
* @param width
|
||||
* the width of the new clipping rectangle.
|
||||
* @param height
|
||||
* the height of the new clipping rectangle.
|
||||
*/
|
||||
public abstract void setClip(int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* Sets the new clipping area to be the area specified by Shape object. The
|
||||
* new clipping area doesn't depend on the window's visibility. Rendering
|
||||
* operations can't be performed outside new clipping area.
|
||||
*
|
||||
* @param clip
|
||||
* the Shape object which represents new clipping area.
|
||||
*/
|
||||
public abstract void setClip(Shape clip);
|
||||
|
||||
/**
|
||||
* Sets the current Graphics color. All rendering operations with this
|
||||
* Graphics will use this color.
|
||||
*
|
||||
* @param c
|
||||
* the new color.
|
||||
*/
|
||||
public abstract void setColor(Color c);
|
||||
|
||||
/**
|
||||
* Sets the current Graphics font. All rendering operations with this
|
||||
* Graphics will use this font.
|
||||
*
|
||||
* @param font
|
||||
* the new font.
|
||||
*/
|
||||
public abstract void setFont(Font font);
|
||||
|
||||
/**
|
||||
* Sets the paint mode for the Graphics which overwrites all rendering
|
||||
* operations with the current color.
|
||||
*/
|
||||
public abstract void setPaintMode();
|
||||
|
||||
/**
|
||||
* Sets the XOR mode for the Graphics which changes a pixel from the current
|
||||
* color to the specified XOR color. <br>
|
||||
* <br>
|
||||
*
|
||||
* @param color
|
||||
* the new XOR mode.
|
||||
*/
|
||||
public abstract void setXORMode(Color color);
|
||||
|
||||
/**
|
||||
* Translates the origin of Graphics current coordinate system to the point
|
||||
* with X, Y coordinates in the current coordinate system. All rendering
|
||||
* operation in this Graphics will be related to the new origin.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the origin.
|
||||
* @param y
|
||||
* the Y coordinate of the origin.
|
||||
*/
|
||||
public abstract void translate(int x, int y);
|
||||
}
|
||||
@@ -1,513 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.BufferedImageOp;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.awt.image.renderable.RenderableImage;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Graphics2D class extends Graphics class and provides more capabilities
|
||||
* for rendering text, images, shapes. This provides methods to perform
|
||||
* transformation of coordinate system, color management, and text layout. The
|
||||
* following attributes exist for rendering:
|
||||
* <ul>
|
||||
* <li>Color - current Graphics2D color;</li>
|
||||
* <li>Font - current Graphics2D font;</li>
|
||||
* <li>Stroke - pen with a width of 1 pixel;</li>
|
||||
* <li>Transform - current Graphics2D Transformation;</li>
|
||||
* <li>Composite - alpha compositing rules for combining source and destination
|
||||
* colors.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class Graphics2D extends Graphics {
|
||||
|
||||
/**
|
||||
* Instantiates a new Graphics2D object. This constructor should never be
|
||||
* called directly.
|
||||
*/
|
||||
protected Graphics2D() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds preferences for the rendering algorithms. The preferences are
|
||||
* arbitrary and specified by Map objects. All specified by Map object
|
||||
* preferences can be modified.
|
||||
*
|
||||
* @param hints
|
||||
* the rendering hints.
|
||||
*/
|
||||
public abstract void addRenderingHints(Map<?, ?> hints);
|
||||
|
||||
/**
|
||||
* Intersects the current clipping area with the specified Shape and the
|
||||
* result becomes a new clipping area. If current clipping area is not
|
||||
* defined, the Shape becomes the new clipping area. No rendering operations
|
||||
* are allowed outside the clipping area.
|
||||
*
|
||||
* @param s
|
||||
* the specified Shape object which will be intersected with
|
||||
* current clipping area.
|
||||
*/
|
||||
public abstract void clip(Shape s);
|
||||
|
||||
/**
|
||||
* Draws the outline of the specified Shape.
|
||||
*
|
||||
* @param s
|
||||
* the Shape which outline is drawn.
|
||||
*/
|
||||
public abstract void draw(Shape s);
|
||||
|
||||
/**
|
||||
* Draws the specified GlyphVector object's text at the point x, y.
|
||||
*
|
||||
* @param g
|
||||
* the GlyphVector object to be drawn.
|
||||
* @param x
|
||||
* the X position where the GlyphVector's text should be
|
||||
* rendered.
|
||||
* @param y
|
||||
* the Y position where the GlyphVector's text should be
|
||||
* rendered.
|
||||
*/
|
||||
public abstract void drawGlyphVector(GlyphVector g, float x, float y);
|
||||
|
||||
/**
|
||||
* Draws the BufferedImage -- modified according to the operation
|
||||
* BufferedImageOp -- at the point x, y.
|
||||
*
|
||||
* @param img
|
||||
* the BufferedImage to be rendered.
|
||||
* @param op
|
||||
* the filter to be applied to the image before rendering.
|
||||
* @param x
|
||||
* the X coordinate of the point where the image's upper left
|
||||
* corner will be placed.
|
||||
* @param y
|
||||
* the Y coordinate of the point where the image's upper left
|
||||
* corner will be placed.
|
||||
*/
|
||||
public abstract void drawImage(BufferedImage img, BufferedImageOp op, int x, int y);
|
||||
|
||||
/**
|
||||
* Draws BufferedImage transformed from image space into user space
|
||||
* according to the AffineTransform xform and notifies the ImageObserver.
|
||||
*
|
||||
* @param img
|
||||
* the BufferedImage to be rendered.
|
||||
* @param xform
|
||||
* the affine transformation from the image to the user space.
|
||||
* @param obs
|
||||
* the ImageObserver to be notified about the image conversion.
|
||||
* @return true, if the image is successfully loaded and rendered, or it's
|
||||
* null, otherwise false.
|
||||
*/
|
||||
public abstract boolean drawImage(Image img, AffineTransform xform, ImageObserver obs);
|
||||
|
||||
/**
|
||||
* Draws a RenderableImage which is transformed from image space into user
|
||||
* according to the AffineTransform xform.
|
||||
*
|
||||
* @param img
|
||||
* the RenderableImage to be rendered.
|
||||
* @param xform
|
||||
* the affine transformation from image to user space.
|
||||
*/
|
||||
public abstract void drawRenderableImage(RenderableImage img, AffineTransform xform);
|
||||
|
||||
/**
|
||||
* Draws a RenderedImage which is transformed from image space into user
|
||||
* according to the AffineTransform xform.
|
||||
*
|
||||
* @param img
|
||||
* the RenderedImage to be rendered.
|
||||
* @param xform
|
||||
* the affine transformation from image to user space.
|
||||
*/
|
||||
public abstract void drawRenderedImage(RenderedImage img, AffineTransform xform);
|
||||
|
||||
/**
|
||||
* Draws the string specified by the AttributedCharacterIterator. The first
|
||||
* character's position is specified by the X, Y parameters.
|
||||
*
|
||||
* @param iterator
|
||||
* whose text is drawn.
|
||||
* @param x
|
||||
* the X position where the first character is drawn.
|
||||
* @param y
|
||||
* the Y position where the first character is drawn.
|
||||
*/
|
||||
public abstract void drawString(AttributedCharacterIterator iterator, float x, float y);
|
||||
|
||||
/**
|
||||
* Draws the string specified by the AttributedCharacterIterator. The first
|
||||
* character's position is specified by the X, Y parameters.
|
||||
*
|
||||
* @param iterator
|
||||
* whose text is drawn.
|
||||
* @param x
|
||||
* the X position where the first character is drawn.
|
||||
* @param y
|
||||
* the Y position where the first character is drawn.
|
||||
* @see java.awt.Graphics#drawString(AttributedCharacterIterator, int, int)
|
||||
*/
|
||||
@Override
|
||||
public abstract void drawString(AttributedCharacterIterator iterator, int x, int y);
|
||||
|
||||
/**
|
||||
* Draws the String whose the first character position is specified by the
|
||||
* parameters X, Y.
|
||||
*
|
||||
* @param s
|
||||
* the String to be drawn.
|
||||
* @param x
|
||||
* the X position of the first character.
|
||||
* @param y
|
||||
* the Y position of the first character.
|
||||
*/
|
||||
public abstract void drawString(String s, float x, float y);
|
||||
|
||||
/**
|
||||
* Draws the String whose the first character coordinates are specified by
|
||||
* the parameters X, Y.
|
||||
*
|
||||
* @param str
|
||||
* the String to be drawn.
|
||||
* @param x
|
||||
* the X coordinate of the first character.
|
||||
* @param y
|
||||
* the Y coordinate of the first character.
|
||||
* @see java.awt.Graphics#drawString(String, int, int)
|
||||
*/
|
||||
@Override
|
||||
public abstract void drawString(String str, int x, int y);
|
||||
|
||||
/**
|
||||
* Fills the interior of the specified Shape.
|
||||
*
|
||||
* @param s
|
||||
* the Shape to be filled.
|
||||
*/
|
||||
public abstract void fill(Shape s);
|
||||
|
||||
/**
|
||||
* Gets the background color.
|
||||
*
|
||||
* @return the current background color.
|
||||
*/
|
||||
public abstract Color getBackground();
|
||||
|
||||
/**
|
||||
* Gets the current composite of the Graphics2D.
|
||||
*
|
||||
* @return the current composite which specifies the compositing style.
|
||||
*/
|
||||
public abstract Composite getComposite();
|
||||
|
||||
/**
|
||||
* Gets the device configuration.
|
||||
*
|
||||
* @return the device configuration.
|
||||
*/
|
||||
public abstract GraphicsConfiguration getDeviceConfiguration();
|
||||
|
||||
/**
|
||||
* Gets the rendering context of the Font.
|
||||
*
|
||||
* @return the FontRenderContext.
|
||||
*/
|
||||
public abstract FontRenderContext getFontRenderContext();
|
||||
|
||||
/**
|
||||
* Gets the current Paint of Graphics2D.
|
||||
*
|
||||
* @return the current Paint of Graphics2D.
|
||||
*/
|
||||
public abstract Paint getPaint();
|
||||
|
||||
/**
|
||||
* Gets the value of single preference for specified key.
|
||||
*
|
||||
* @param key
|
||||
* the specified key of the rendering hint.
|
||||
* @return the value of rendering hint for specified key.
|
||||
*/
|
||||
public abstract Object getRenderingHint(RenderingHints.Key key);
|
||||
|
||||
/**
|
||||
* Gets the set of the rendering preferences as a collection of key/value
|
||||
* pairs.
|
||||
*
|
||||
* @return the RenderingHints which contains the rendering preferences.
|
||||
*/
|
||||
public abstract RenderingHints getRenderingHints();
|
||||
|
||||
/**
|
||||
* Gets current stroke of the Graphics2D.
|
||||
*
|
||||
* @return current stroke of the Graphics2D.
|
||||
*/
|
||||
public abstract Stroke getStroke();
|
||||
|
||||
/**
|
||||
* Gets current affine transform of the Graphics2D.
|
||||
*
|
||||
* @return current AffineTransform of the Graphics2D.
|
||||
*/
|
||||
public abstract AffineTransform getTransform();
|
||||
|
||||
/**
|
||||
* Determines whether or not the specified Shape intersects the specified
|
||||
* Rectangle. If the onStroke parameter is true, this method checks whether
|
||||
* or not the specified Shape outline intersects the specified Rectangle,
|
||||
* otherwise this method checks whether or not the specified Shape's
|
||||
* interior intersects the specified Rectangle.
|
||||
*
|
||||
* @param rect
|
||||
* the specified Rectangle.
|
||||
* @param s
|
||||
* the Shape to check for intersection.
|
||||
* @param onStroke
|
||||
* the parameter determines whether or not this method checks for
|
||||
* intersection of the Shape outline or of the Shape interior
|
||||
* with the Rectangle.
|
||||
* @return true, if there is a hit, false otherwise.
|
||||
*/
|
||||
public abstract boolean hit(Rectangle rect, Shape s, boolean onStroke);
|
||||
|
||||
/**
|
||||
* Performs a rotation transform relative to current Graphics2D Transform.
|
||||
* The coordinate system is rotated by the specified angle in radians
|
||||
* relative to current origin.
|
||||
*
|
||||
* @param theta
|
||||
* the angle of rotation in radians.
|
||||
*/
|
||||
public abstract void rotate(double theta);
|
||||
|
||||
/**
|
||||
* Performs a translated rotation transform relative to current Graphics2D
|
||||
* Transform. The coordinate system is rotated by the specified angle in
|
||||
* radians relative to current origin and then moved to point (x, y). Is
|
||||
* this right?
|
||||
*
|
||||
* @param theta
|
||||
* the angle of rotation in radians.
|
||||
* @param x
|
||||
* the X coordinate.
|
||||
* @param y
|
||||
* the Y coordinate.
|
||||
*/
|
||||
public abstract void rotate(double theta, double x, double y);
|
||||
|
||||
/**
|
||||
* Performs a linear scale transform relative to current Graphics2D
|
||||
* Transform. The coordinate system is rescaled vertically and horizontally
|
||||
* by the specified parameters.
|
||||
*
|
||||
* @param sx
|
||||
* the scaling factor by which the X coordinate is multiplied.
|
||||
* @param sy
|
||||
* the scaling factor by which the Y coordinate is multiplied.
|
||||
*/
|
||||
public abstract void scale(double sx, double sy);
|
||||
|
||||
/**
|
||||
* Sets a new background color for clearing rectangular areas. The clearRect
|
||||
* method uses the current background color.
|
||||
*
|
||||
* @param color
|
||||
* the new background color.
|
||||
*/
|
||||
public abstract void setBackground(Color color);
|
||||
|
||||
/**
|
||||
* Sets the current composite for Graphics2D.
|
||||
*
|
||||
* @param comp
|
||||
* the Composite object.
|
||||
*/
|
||||
public abstract void setComposite(Composite comp);
|
||||
|
||||
/**
|
||||
* Sets the paint for Graphics2D.
|
||||
*
|
||||
* @param paint
|
||||
* the Paint object.
|
||||
*/
|
||||
public abstract void setPaint(Paint paint);
|
||||
|
||||
/**
|
||||
* Sets a key-value pair in the current RenderingHints map.
|
||||
*
|
||||
* @param key
|
||||
* the key of the rendering hint to set.
|
||||
* @param value
|
||||
* the value to set for the rendering hint.
|
||||
*/
|
||||
public abstract void setRenderingHint(RenderingHints.Key key, Object value);
|
||||
|
||||
/**
|
||||
* Replaces the current rendering hints with the specified rendering
|
||||
* preferences.
|
||||
*
|
||||
* @param hints
|
||||
* the new Map of rendering hints.
|
||||
*/
|
||||
public abstract void setRenderingHints(Map<?, ?> hints);
|
||||
|
||||
/**
|
||||
* Sets the stroke for the Graphics2D.
|
||||
*
|
||||
* @param s
|
||||
* the Stroke object.
|
||||
*/
|
||||
public abstract void setStroke(Stroke s);
|
||||
|
||||
/**
|
||||
* Overwrite the current Transform of the Graphics2D. The specified
|
||||
* Transform should be received from the getTransform() method and should be
|
||||
* used only for restoring the original Graphics2D transform after calling
|
||||
* draw or fill methods.
|
||||
*
|
||||
* @param Tx
|
||||
* the specified Transform.
|
||||
*/
|
||||
public abstract void setTransform(AffineTransform Tx);
|
||||
|
||||
/**
|
||||
* Performs a shear transform relative to current Graphics2D Transform. The
|
||||
* coordinate system is shifted by the specified multipliers relative to
|
||||
* current position.
|
||||
*
|
||||
* @param shx
|
||||
* the multiplier by which the X coordinates shift position along
|
||||
* X axis as a function of Y coordinates.
|
||||
* @param shy
|
||||
* the multiplier by which the Y coordinates shift position along
|
||||
* Y axis as a function of X coordinates.
|
||||
*/
|
||||
public abstract void shear(double shx, double shy);
|
||||
|
||||
/**
|
||||
* Concatenates the AffineTransform object with current Transform of this
|
||||
* Graphics2D. The transforms are applied in reverse order with the last
|
||||
* specified transform applied first and the next transformation applied to
|
||||
* the result of previous transformation. More precisely, if Cx is the
|
||||
* current Graphics2D transform, the transform method's result with Tx as
|
||||
* the parameter is the transformation Rx, where Rx(p) = Cx(Tx(p)), for p -
|
||||
* a point in current coordinate system. Rx becomes the current Transform
|
||||
* for this Graphics2D.
|
||||
*
|
||||
* @param Tx
|
||||
* the AffineTransform object to be concatenated with current
|
||||
* Transform.
|
||||
*/
|
||||
public abstract void transform(AffineTransform Tx);
|
||||
|
||||
/**
|
||||
* Performs a translate transform relative to current Graphics2D Transform.
|
||||
* The coordinate system is moved by the specified distance relative to
|
||||
* current position.
|
||||
*
|
||||
* @param tx
|
||||
* the translation distance along the X axis.
|
||||
* @param ty
|
||||
* the translation distance along the Y axis.
|
||||
*/
|
||||
public abstract void translate(double tx, double ty);
|
||||
|
||||
/**
|
||||
* Moves the origin Graphics2D Transform to the point with x, y coordinates
|
||||
* in current coordinate system. The new origin of coordinate system is
|
||||
* moved to the (x, y) point accordingly. All rendering and transform
|
||||
* operations are performed relative to this new origin.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate.
|
||||
* @param y
|
||||
* the Y coordinate.
|
||||
* @see java.awt.Graphics#translate(int, int)
|
||||
*/
|
||||
@Override
|
||||
public abstract void translate(int x, int y);
|
||||
|
||||
/**
|
||||
* Fills a 3D rectangle with the current color. The rectangle is specified
|
||||
* by its width, height, and top left corner coordinates.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle's top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle's top left corner.
|
||||
* @param width
|
||||
* the width of rectangle.
|
||||
* @param height
|
||||
* the height of rectangle.
|
||||
* @param raised
|
||||
* a boolean value that determines whether the rectangle is drawn
|
||||
* as raised or indented.
|
||||
* @see java.awt.Graphics#fill3DRect(int, int, int, int, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void fill3DRect(int x, int y, int width, int height, boolean raised) {
|
||||
// According to the spec, color should be used instead of paint,
|
||||
// so Graphics.fill3DRect resets paint and
|
||||
// it should be restored after the call
|
||||
Paint savedPaint = getPaint();
|
||||
super.fill3DRect(x, y, width, height, raised);
|
||||
setPaint(savedPaint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws the highlighted outline of a rectangle.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle's top left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle's top left corner.
|
||||
* @param width
|
||||
* the width of rectangle.
|
||||
* @param height
|
||||
* the height of rectangle.
|
||||
* @param raised
|
||||
* a boolean value that determines whether the rectangle is drawn
|
||||
* as raised or indented.
|
||||
* @see java.awt.Graphics#draw3DRect(int, int, int, int, boolean)
|
||||
*/
|
||||
@Override
|
||||
public void draw3DRect(int x, int y, int width, int height, boolean raised) {
|
||||
// According to the spec, color should be used instead of paint,
|
||||
// so Graphics.draw3DRect resets paint and
|
||||
// it should be restored after the call
|
||||
Paint savedPaint = getPaint();
|
||||
super.draw3DRect(x, y, width, height, raised);
|
||||
setPaint(savedPaint);
|
||||
}
|
||||
}
|
||||
@@ -1,226 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.VolatileImage;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The GraphicsConfiguration class contains the characteristics of graphics
|
||||
* devices such as a printer or monitor, and represents device's capabilities
|
||||
* and modes. Many GraphicsConfiguration objects can be associated with single
|
||||
* graphics device.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class GraphicsConfiguration {
|
||||
|
||||
/**
|
||||
* Constructor could not be used directly and should be obtained in extended
|
||||
* classes.
|
||||
*/
|
||||
protected GraphicsConfiguration() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates BufferedImage image object with a data layout and color model
|
||||
* compatible with this GraphicsConfiguration with specified width and
|
||||
* height parameters.
|
||||
*
|
||||
* @param width
|
||||
* the width of BufferedImage.
|
||||
* @param height
|
||||
* the height of BufferedImage.
|
||||
* @return the BufferedImage object with specified width and height
|
||||
* parameters.
|
||||
*/
|
||||
public abstract BufferedImage createCompatibleImage(int width, int height);
|
||||
|
||||
/**
|
||||
* Creates a BufferedImage that has the specified width, height,
|
||||
* transparency and has a data layout and color model compatible with this
|
||||
* GraphicsConfiguration.
|
||||
*
|
||||
* @param width
|
||||
* the width of image.
|
||||
* @param height
|
||||
* the height of image.
|
||||
* @param transparency
|
||||
* the transparency mode.
|
||||
* @return the BufferedImage object.
|
||||
*/
|
||||
public abstract BufferedImage createCompatibleImage(int width, int height, int transparency);
|
||||
|
||||
/**
|
||||
* Creates a VolatileImage that has the specified width and height and has a
|
||||
* data layout and color model compatible with this GraphicsConfiguration.
|
||||
*
|
||||
* @param width
|
||||
* the width of image.
|
||||
* @param height
|
||||
* the height of image.
|
||||
* @return the VolatileImage object.
|
||||
*/
|
||||
public abstract VolatileImage createCompatibleVolatileImage(int width, int height);
|
||||
|
||||
/**
|
||||
* Creates a VolatileImage that supports the specified width, height,
|
||||
* transparency and has a data layout and color model compatible with this
|
||||
* GraphicsConfiguration.
|
||||
*
|
||||
* @param width
|
||||
* the width of image.
|
||||
* @param height
|
||||
* the height of image.
|
||||
* @param transparency
|
||||
* the transparency mode.
|
||||
* @return the VolatileImage object.
|
||||
*/
|
||||
public abstract VolatileImage createCompatibleVolatileImage(int width, int height,
|
||||
int transparency);
|
||||
|
||||
/**
|
||||
* Gets the bounds of area covered by the GraphicsConfiguration in the
|
||||
* device coordinates space.
|
||||
*
|
||||
* @return the Rectangle of GraphicsConfiguration's bounds.
|
||||
*/
|
||||
public abstract Rectangle getBounds();
|
||||
|
||||
/**
|
||||
* Gets the ColorModel of the GraphicsConfiguration.
|
||||
*
|
||||
* @return the ColorModel object of the GraphicsConfiguration.
|
||||
*/
|
||||
public abstract ColorModel getColorModel();
|
||||
|
||||
/**
|
||||
* Gets the ColorModel of the GraphicsConfiguration which supports specified
|
||||
* Transparency.
|
||||
*
|
||||
* @param transparency
|
||||
* the Transparency mode: OPAQUE, BITMASK, or TRANSLUCENT.
|
||||
* @return the ColorModel of the GraphicsConfiguration which supports
|
||||
* specified Transparency.
|
||||
*/
|
||||
public abstract ColorModel getColorModel(int transparency);
|
||||
|
||||
/**
|
||||
* Gets the default AffineTransform of the GraphicsConfiguration. This
|
||||
* method translates user coordinates to device coordinates.
|
||||
*
|
||||
* @return the default AffineTransform of the GraphicsConfiguration.
|
||||
*/
|
||||
public abstract AffineTransform getDefaultTransform();
|
||||
|
||||
/**
|
||||
* Gets the GraphicsDevice of the GraphicsConfiguration.
|
||||
*
|
||||
* @return the GraphicsDevice of the GraphicsConfiguration.
|
||||
*/
|
||||
public abstract GraphicsDevice getDevice();
|
||||
|
||||
/**
|
||||
* Gets the normalizing AffineTransform of the GraphicsConfiguration.
|
||||
*
|
||||
* @return the normalizing AffineTransform of the GraphicsConfiguration.
|
||||
*/
|
||||
public abstract AffineTransform getNormalizingTransform();
|
||||
|
||||
/**
|
||||
* Creates VolatileImage with specified width, height, ImageCapabilities; a
|
||||
* data layout and color model compatible with this GraphicsConfiguration.
|
||||
*
|
||||
* @param width
|
||||
* the width of image.
|
||||
* @param height
|
||||
* the height of image.
|
||||
* @param caps
|
||||
* the ImageCapabilities object.
|
||||
* @return the VolatileImage which data layout and color model compatible
|
||||
* with this GraphicsConfiguration.
|
||||
* @throws AWTException
|
||||
* if ImageCapabilities is not supported by the
|
||||
* GraphicsConfiguration.
|
||||
*/
|
||||
public VolatileImage createCompatibleVolatileImage(int width, int height, ImageCapabilities caps)
|
||||
throws AWTException {
|
||||
VolatileImage res = createCompatibleVolatileImage(width, height);
|
||||
if (!res.getCapabilities().equals(caps)) {
|
||||
// awt.14A=Can not create VolatileImage with specified capabilities
|
||||
throw new AWTException(Messages.getString("awt.14A")); //$NON-NLS-1$
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a VolatileImage with specified width, height, transparency and
|
||||
* ImageCapabilities; a data layout and color model compatible with this
|
||||
* GraphicsConfiguration.
|
||||
*
|
||||
* @param width
|
||||
* the width of image.
|
||||
* @param height
|
||||
* the height of image.
|
||||
* @param caps
|
||||
* the ImageCapabilities object.
|
||||
* @param transparency
|
||||
* the Transparency mode: OPAQUE, BITMASK, or TRANSLUCENT.
|
||||
* @return the VolatileImage which data layout and color model compatible
|
||||
* with this GraphicsConfiguration.
|
||||
* @throws AWTException
|
||||
* if ImageCapabilities is not supported by the
|
||||
* GraphicsConfiguration.
|
||||
*/
|
||||
public VolatileImage createCompatibleVolatileImage(int width, int height,
|
||||
ImageCapabilities caps, int transparency) throws AWTException {
|
||||
VolatileImage res = createCompatibleVolatileImage(width, height, transparency);
|
||||
if (!res.getCapabilities().equals(caps)) {
|
||||
// awt.14A=Can not create VolatileImage with specified capabilities
|
||||
throw new AWTException(Messages.getString("awt.14A")); //$NON-NLS-1$
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the buffering capabilities of the GraphicsConfiguration.
|
||||
*
|
||||
* @return the BufferCapabilities object.
|
||||
*/
|
||||
public BufferCapabilities getBufferCapabilities() {
|
||||
return new BufferCapabilities(new ImageCapabilities(false), new ImageCapabilities(false),
|
||||
BufferCapabilities.FlipContents.UNDEFINED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the image capabilities of the GraphicsConfiguration.
|
||||
*
|
||||
* @return the ImageCapabilities object.
|
||||
*/
|
||||
public ImageCapabilities getImageCapabilities() {
|
||||
return new ImageCapabilities(false);
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The GraphicsDevice class describes the graphics devices (such as screens or
|
||||
* printers) which are available in a particular graphics environment. Many
|
||||
* GraphicsDevice instances can be associated with a single GraphicsEnvironment.
|
||||
* Each GraphicsDevice has one or more GraphicsConfiguration objects which
|
||||
* specify the different configurations and modes of GraphicsDevice.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class GraphicsDevice {
|
||||
|
||||
/**
|
||||
* The display mode.
|
||||
*/
|
||||
private DisplayMode displayMode;
|
||||
|
||||
// ???AWT
|
||||
// private Window fullScreenWindow = null;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_IMAGE_BUFFER indicates a image buffer device.
|
||||
*/
|
||||
|
||||
public static final int TYPE_IMAGE_BUFFER = 2;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_PRINTER indicates a printer device.
|
||||
*/
|
||||
public static final int TYPE_PRINTER = 1;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_RASTER_SCREEN indicates a raster screen device.
|
||||
*/
|
||||
public static final int TYPE_RASTER_SCREEN = 0;
|
||||
|
||||
/**
|
||||
* Constructor is not to be used directly as this class is abstract.
|
||||
*/
|
||||
protected GraphicsDevice() {
|
||||
displayMode = new DisplayMode(0, 0, DisplayMode.BIT_DEPTH_MULTI,
|
||||
DisplayMode.REFRESH_RATE_UNKNOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of GraphicsConfiguration objects associated with the
|
||||
* GraphicsDevice.
|
||||
*
|
||||
* @return an array of GraphicsConfiguration objects associated with the
|
||||
* GraphicsDevice.
|
||||
*/
|
||||
public abstract GraphicsConfiguration[] getConfigurations();
|
||||
|
||||
/**
|
||||
* Gets the default configuration for the GraphicsDevice.
|
||||
*
|
||||
* @return the default GraphicsConfiguration object for the GraphicsDevice.
|
||||
*/
|
||||
public abstract GraphicsConfiguration getDefaultConfiguration();
|
||||
|
||||
/**
|
||||
* Gets the String identifier which associated with the GraphicsDevice in
|
||||
* the GraphicsEnvironment.
|
||||
*
|
||||
* @return the String identifier of the GraphicsDevice in the
|
||||
* GraphicsEnvironment.
|
||||
*/
|
||||
public abstract String getIDstring();
|
||||
|
||||
/**
|
||||
* Gets the type of this GraphicsDevice: TYPE_IMAGE_BUFFER, TYPE_PRINTER or
|
||||
* TYPE_RASTER_SCREEN.
|
||||
*
|
||||
* @return the type of this GraphicsDevice: TYPE_IMAGE_BUFFER, TYPE_PRINTER
|
||||
* or TYPE_RASTER_SCREEN.
|
||||
*/
|
||||
public abstract int getType();
|
||||
|
||||
/**
|
||||
* Returns the number of bytes available in accelerated memory on this
|
||||
* device.
|
||||
*
|
||||
* @return the number of bytes available accelerated memory.
|
||||
*/
|
||||
public int getAvailableAcceleratedMemory() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* ???AWT public GraphicsConfiguration
|
||||
* getBestConfiguration(GraphicsConfigTemplate gct) { return
|
||||
* gct.getBestConfiguration(getConfigurations()); }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the current display mode of the GraphicsDevice.
|
||||
*
|
||||
* @return the current display mode of the GraphicsDevice.
|
||||
*/
|
||||
public DisplayMode getDisplayMode() {
|
||||
return displayMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of display modes available in this GraphicsDevice.
|
||||
*
|
||||
* @return an array of display modes available in this GraphicsDevice.
|
||||
*/
|
||||
public DisplayMode[] getDisplayModes() {
|
||||
DisplayMode[] dms = {
|
||||
displayMode
|
||||
};
|
||||
return dms;
|
||||
}
|
||||
|
||||
/*
|
||||
* ???AWT public Window getFullScreenWindow() { return fullScreenWindow; }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns true if this GraphicsDevice supports low-level display changes.
|
||||
*
|
||||
* @return true, if this GraphicsDevice supports low-level display changes;
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean isDisplayChangeSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this GraphicsDevice supports full screen mode.
|
||||
*
|
||||
* @return true, if this GraphicsDevice supports full screen mode, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean isFullScreenSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// an array of display modes available in this GraphicsDevice.
|
||||
|
||||
/**
|
||||
* Sets the display mode of this GraphicsDevice.
|
||||
*
|
||||
* @param dm
|
||||
* the new display mode of this GraphicsDevice.
|
||||
*/
|
||||
public void setDisplayMode(DisplayMode dm) {
|
||||
if (!isDisplayChangeSupported()) {
|
||||
// awt.122=Does not support display mode changes
|
||||
throw new UnsupportedOperationException(Messages.getString("awt.122")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
DisplayMode[] dms = getDisplayModes();
|
||||
for (DisplayMode element : dms) {
|
||||
if (element.equals(dm)) {
|
||||
displayMode = dm;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// awt.123=Unsupported display mode: {0}
|
||||
throw new IllegalArgumentException(Messages.getString("awt.123", dm)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/*
|
||||
* ???AWT public void setFullScreenWindow(Window w) { if (w == null) {
|
||||
* fullScreenWindow = null; return; } fullScreenWindow = w; if
|
||||
* (isFullScreenSupported()) { w.enableInputMethods(false); } else {
|
||||
* w.setSize(displayMode.getWidth(), displayMode.getHeight());
|
||||
* w.setLocation(0, 0); } w.setVisible(true); w.setAlwaysOnTop(true); }
|
||||
*/
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Oleg V. Khaschansky
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.harmony.awt.ContextStorage;
|
||||
import org.apache.harmony.awt.gl.CommonGraphics2DFactory;
|
||||
|
||||
/**
|
||||
* The GraphicsEnvironment class defines a collection of GraphicsDevice objects
|
||||
* and Font objects which are available for Java application on current
|
||||
* platform.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class GraphicsEnvironment {
|
||||
|
||||
/**
|
||||
* Constructor could not be used directly and should be obtained in extended
|
||||
* classes.
|
||||
*/
|
||||
protected GraphicsEnvironment() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the local GraphicsEnvironment.
|
||||
*
|
||||
* @return the local GraphicsEnvironment.
|
||||
*/
|
||||
public static GraphicsEnvironment getLocalGraphicsEnvironment() {
|
||||
synchronized (ContextStorage.getContextLock()) {
|
||||
if (ContextStorage.getGraphicsEnvironment() == null) {
|
||||
if (isHeadless()) {
|
||||
ContextStorage.setGraphicsEnvironment(new HeadlessGraphicsEnvironment());
|
||||
} else {
|
||||
CommonGraphics2DFactory g2df = (CommonGraphics2DFactory)Toolkit
|
||||
.getDefaultToolkit().getGraphicsFactory();
|
||||
|
||||
ContextStorage.setGraphicsEnvironment(g2df
|
||||
.createGraphicsEnvironment(ContextStorage.getWindowFactory()));
|
||||
}
|
||||
}
|
||||
|
||||
return ContextStorage.getGraphicsEnvironment();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not a display, keyboard, and mouse are supported in
|
||||
* this graphics environment.
|
||||
*
|
||||
* @return true, if HeadlessException will be thrown from areas of the
|
||||
* graphics environment that are dependent on a display, keyboard,
|
||||
* or mouse, false otherwise.
|
||||
*/
|
||||
public boolean isHeadlessInstance() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not a display, keyboard, and mouse are supported in
|
||||
* this environment.
|
||||
*
|
||||
* @return true, if a HeadlessException is thrown from areas of the Toolkit
|
||||
* and GraphicsEnvironment that are dependent on a display,
|
||||
* keyboard, or mouse, false otherwise.
|
||||
*/
|
||||
public static boolean isHeadless() {
|
||||
return "true".equals(System.getProperty("java.awt.headless"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum bounds of system centered windows.
|
||||
*
|
||||
* @return the maximum bounds of system centered windows.
|
||||
* @throws HeadlessException
|
||||
* if isHeadless() method returns true.
|
||||
*/
|
||||
public Rectangle getMaximumWindowBounds() throws HeadlessException {
|
||||
return getDefaultScreenDevice().getDefaultConfiguration().getBounds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Point which should defines the center of system window.
|
||||
*
|
||||
* @return the Point where the system window should be centered.
|
||||
* @throws HeadlessException
|
||||
* if isHeadless() method returns true.
|
||||
*/
|
||||
public Point getCenterPoint() throws HeadlessException {
|
||||
Rectangle mwb = getMaximumWindowBounds();
|
||||
return new Point(mwb.width >> 1, mwb.height >> 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates that the primary font should be used. Primary font is specified
|
||||
* by initial system locale or default encoding).
|
||||
*/
|
||||
public void preferLocaleFonts() {
|
||||
// Note: API specification says following:
|
||||
// "The actual change in font rendering behavior resulting
|
||||
// from a call to this method is implementation dependent;
|
||||
// it may have no effect at all." So, doing nothing is an
|
||||
// acceptable behavior for this method.
|
||||
|
||||
// For now FontManager uses 1.4 font.properties scheme for font mapping,
|
||||
// so
|
||||
// this method doesn't make any sense. The implementation of this method
|
||||
// which will influence font mapping is postponed until
|
||||
// 1.5 mapping scheme not implemented.
|
||||
|
||||
// todo - Implement non-default behavior with 1.5 font mapping scheme
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates that a proportional preference of the font should be used.
|
||||
*/
|
||||
public void preferProportionalFonts() {
|
||||
// Note: API specification says following:
|
||||
// "The actual change in font rendering behavior resulting
|
||||
// from a call to this method is implementation dependent;
|
||||
// it may have no effect at all." So, doing nothing is an
|
||||
// acceptable behavior for this method.
|
||||
|
||||
// For now FontManager uses 1.4 font.properties scheme for font mapping,
|
||||
// so
|
||||
// this method doesn't make any sense. The implementation of this method
|
||||
// which will influence font mapping is postponed until
|
||||
// 1.5 mapping scheme not implemented.
|
||||
|
||||
// todo - Implement non-default behavior with 1.5 font mapping scheme
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Graphics2D object for rendering to the specified
|
||||
* BufferedImage.
|
||||
*
|
||||
* @param bufferedImage
|
||||
* the BufferedImage object.
|
||||
* @return the Graphics2D object which allows to render to the specified
|
||||
* BufferedImage.
|
||||
*/
|
||||
public abstract Graphics2D createGraphics(BufferedImage bufferedImage);
|
||||
|
||||
/**
|
||||
* Gets the array of all available fonts instances in this
|
||||
* GraphicsEnviroments.
|
||||
*
|
||||
* @return the array of all available fonts instances in this
|
||||
* GraphicsEnviroments.
|
||||
*/
|
||||
public abstract Font[] getAllFonts();
|
||||
|
||||
/**
|
||||
* Gets the array of all available font family names.
|
||||
*
|
||||
* @return the array of all available font family names.
|
||||
*/
|
||||
public abstract String[] getAvailableFontFamilyNames();
|
||||
|
||||
/**
|
||||
* Gets the array of all available font family names for the specified
|
||||
* locale.
|
||||
*
|
||||
* @param locale
|
||||
* the Locale object which represents geographical region. The
|
||||
* default locale is used if locale is null.
|
||||
* @return the array of available font family names for the specified
|
||||
* locale.
|
||||
*/
|
||||
public abstract String[] getAvailableFontFamilyNames(Locale locale);
|
||||
|
||||
/**
|
||||
* Gets the default screen device as GraphicDevice object.
|
||||
*
|
||||
* @return the GraphicDevice object which represents default screen device.
|
||||
* @throws HeadlessException
|
||||
* if isHeadless() returns true.
|
||||
*/
|
||||
public abstract GraphicsDevice getDefaultScreenDevice() throws HeadlessException;
|
||||
|
||||
/**
|
||||
* Gets an array of all available screen devices.
|
||||
*
|
||||
* @return the array of GraphicsDevice objects which represents all
|
||||
* available screen devices.
|
||||
* @throws HeadlessException
|
||||
* if isHeadless() returns true.
|
||||
*/
|
||||
public abstract GraphicsDevice[] getScreenDevices() throws HeadlessException;
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The HeadlessException class provides notifications and error messages when
|
||||
* code that is dependent on a keyboard, display, or mouse is called in an
|
||||
* environment that does not support a keyboard, display, or mouse.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class HeadlessException extends UnsupportedOperationException {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 167183644944358563L;
|
||||
|
||||
/**
|
||||
* Instantiates a new headless exception.
|
||||
*/
|
||||
public HeadlessException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new headless exception with the specified message.
|
||||
*
|
||||
* @param msg
|
||||
* the String which represents error message.
|
||||
*/
|
||||
public HeadlessException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.HeadlessException;
|
||||
|
||||
import org.apache.harmony.awt.gl.CommonGraphicsEnvironment;
|
||||
|
||||
/**
|
||||
* The HeadlessGraphicsEnvironment class is the CommonGraphicsEnvironment
|
||||
* implementation to use in the case where the environment lacks display,
|
||||
* keyboard, and mouse support.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class HeadlessGraphicsEnvironment extends CommonGraphicsEnvironment {
|
||||
|
||||
/**
|
||||
* Returns whether or not a display, keyboard, and mouse are supported in
|
||||
* this graphics environment.
|
||||
*
|
||||
* @return true, if HeadlessException will be thrown from areas of the
|
||||
* graphics environment that are dependent on a display, keyboard,
|
||||
* or mouse, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean isHeadlessInstance() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default screen device as GraphicDevice object.
|
||||
*
|
||||
* @return the GraphicDevice object which represents default screen device.
|
||||
* @throws HeadlessException
|
||||
* if isHeadless() returns true.
|
||||
*/
|
||||
@Override
|
||||
public GraphicsDevice getDefaultScreenDevice() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of all available screen devices.
|
||||
*
|
||||
* @return the array of GraphicsDevice objects which represents all
|
||||
* available screen devices.
|
||||
* @throws HeadlessException
|
||||
* if isHeadless() returns true.
|
||||
*/
|
||||
@Override
|
||||
public GraphicsDevice[] getScreenDevices() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,226 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
//???AWT
|
||||
//import java.awt.datatransfer.Clipboard;
|
||||
//import java.awt.dnd.DragGestureEvent;
|
||||
//import java.awt.dnd.DragGestureListener;
|
||||
//import java.awt.dnd.DragGestureRecognizer;
|
||||
//import java.awt.dnd.DragSource;
|
||||
//import java.awt.dnd.InvalidDnDOperationException;
|
||||
//import java.awt.dnd.peer.DragSourceContextPeer;
|
||||
import java.awt.im.InputMethodHighlight;
|
||||
import java.awt.image.ColorModel; //import java.awt.peer.*;
|
||||
//import java.beans.PropertyChangeSupport;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.harmony.awt.ComponentInternals; //import org.apache.harmony.awt.datatransfer.DTK;
|
||||
import org.apache.harmony.awt.wtk.GraphicsFactory;
|
||||
import org.apache.harmony.awt.wtk.NativeEventQueue;
|
||||
import org.apache.harmony.awt.wtk.WindowFactory;
|
||||
|
||||
/**
|
||||
* The HeadlessToolkit class is a subclass of ToolkitImpl to be used for
|
||||
* graphical environments that lack keyboard and mouse capabilities.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public final class HeadlessToolkit extends ToolkitImpl {
|
||||
|
||||
// ???AWT
|
||||
/*
|
||||
* @Override protected ButtonPeer createButton(Button a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected CheckboxPeer createCheckbox(Checkbox a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected CheckboxMenuItemPeer
|
||||
* createCheckboxMenuItem(CheckboxMenuItem a0) throws HeadlessException {
|
||||
* throw new HeadlessException(); }
|
||||
* @Override protected ChoicePeer createChoice(Choice a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); } public Cursor
|
||||
* createCustomCursor(Image img, Point hotSpot, String name) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected DialogPeer createDialog(Dialog a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override public <T extends DragGestureRecognizer> T
|
||||
* createDragGestureRecognizer( Class<T> recognizerAbstractClass, DragSource
|
||||
* ds, Component c, int srcActions, DragGestureListener dgl) { return null;
|
||||
* }
|
||||
* @Override public DragSourceContextPeer
|
||||
* createDragSourceContextPeer(DragGestureEvent dge) throws
|
||||
* InvalidDnDOperationException { throw new InvalidDnDOperationException();
|
||||
* }
|
||||
* @Override protected FileDialogPeer createFileDialog(FileDialog a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected FramePeer createFrame(Frame a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected LabelPeer createLabel(Label a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected ListPeer createList(List a0) throws HeadlessException
|
||||
* { throw new HeadlessException(); }
|
||||
* @Override protected MenuPeer createMenu(Menu a0) throws HeadlessException
|
||||
* { throw new HeadlessException(); }
|
||||
* @Override protected MenuBarPeer createMenuBar(MenuBar a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected MenuItemPeer createMenuItem(MenuItem a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected PopupMenuPeer createPopupMenu(PopupMenu a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected ScrollbarPeer createScrollbar(Scrollbar a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected ScrollPanePeer createScrollPane(ScrollPane a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected TextAreaPeer createTextArea(TextArea a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected TextFieldPeer createTextField(TextField a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
* @Override protected WindowPeer createWindow(Window a0) throws
|
||||
* HeadlessException { throw new HeadlessException(); }
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Dimension getBestCursorSize(int prefWidth, int prefHeight) throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorModel getColorModel() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphicsFactory getGraphicsFactory() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getLockingKeyState(int keyCode) throws UnsupportedOperationException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaximumCursorColors() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMenuShortcutKeyMask() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
// ???AWT
|
||||
/*
|
||||
* @Override NativeEventQueue getNativeEventQueue() throws HeadlessException
|
||||
* { throw new HeadlessException(); }
|
||||
* @Override public PrintJob getPrintJob(Frame frame, String jobtitle,
|
||||
* JobAttributes jobAttributes, PageAttributes pageAttributes) throws
|
||||
* IllegalArgumentException { throw new IllegalArgumentException(); }
|
||||
* @Override public PrintJob getPrintJob(Frame frame, String jobtitle,
|
||||
* Properties props) throws NullPointerException { throw new
|
||||
* NullPointerException(); }
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Insets getScreenInsets(GraphicsConfiguration gc) throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScreenResolution() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getScreenSize() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
// ???AWT
|
||||
/*
|
||||
* @Override public Clipboard getSystemClipboard() throws HeadlessException
|
||||
* { throw new HeadlessException(); }
|
||||
* @Override public Clipboard getSystemSelection() throws HeadlessException
|
||||
* { throw new HeadlessException(); }
|
||||
* @Override WindowFactory getWindowFactory() throws HeadlessException {
|
||||
* throw new HeadlessException(); }
|
||||
*/
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
lockAWT();
|
||||
try {
|
||||
ComponentInternals.setComponentInternals(new ComponentInternalsImpl());
|
||||
// ???AWT: new EventQueue(this); // create the system EventQueue
|
||||
// ???AWT: dispatcher = new Dispatcher(this);
|
||||
desktopProperties = new HashMap<String, Object>();
|
||||
// ???AWT: desktopPropsSupport = new PropertyChangeSupport(this);
|
||||
// ???AWT: awtEventsManager = new AWTEventsManager();
|
||||
// ???AWT: dispatchThread = new HeadlessEventDispatchThread(this,
|
||||
// dispatcher);
|
||||
// ???AWT: dtk = DTK.getDTK();
|
||||
dispatchThread.start();
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDynamicLayoutActive() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isDynamicLayoutSet() throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFrameStateSupported(int state) throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadSystemColors(int[] systemColors) throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(
|
||||
InputMethodHighlight highlight) throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlightImpl(InputMethodHighlight highlight)
|
||||
throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDynamicLayout(boolean dynamic) throws HeadlessException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLockingKeyState(int keyCode, boolean on) throws UnsupportedOperationException {
|
||||
throw new HeadlessException();
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The IllegalComponentStateException class is used to provide notification that
|
||||
* AWT component is not in an appropriate state for the requested operation.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class IllegalComponentStateException extends IllegalStateException {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -1889339587208144238L;
|
||||
|
||||
/**
|
||||
* Instantiates a new IllegalComponentStateException with the specified
|
||||
* message.
|
||||
*
|
||||
* @param s
|
||||
* the String message which describes the exception.
|
||||
*/
|
||||
public IllegalComponentStateException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new IllegalComponentStateException without detailed
|
||||
* message.
|
||||
*/
|
||||
public IllegalComponentStateException() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Igor V. Stolyarov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.AreaAveragingScaleFilter;
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.ImageFilter;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.image.ReplicateScaleFilter;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The Image abstract class represents the graphic images.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class Image {
|
||||
|
||||
/**
|
||||
* The UndefinedProperty object should be returned if property is not
|
||||
* defined for a particular image.
|
||||
*/
|
||||
public static final Object UndefinedProperty = new Object(); // $NON-LOCK-1$
|
||||
|
||||
/**
|
||||
* The Constant SCALE_DEFAULT indicates the default image scaling algorithm.
|
||||
*/
|
||||
public static final int SCALE_DEFAULT = 1;
|
||||
|
||||
/**
|
||||
* The Constant SCALE_FAST indicates an image scaling algorithm which places
|
||||
* a higher priority on scaling speed than on the image's smoothness.
|
||||
*/
|
||||
public static final int SCALE_FAST = 2;
|
||||
|
||||
/**
|
||||
* The Constant SCALE_SMOOTH indicates an image scaling algorithm which
|
||||
* places a higher priority on image smoothness than on scaling speed.
|
||||
*/
|
||||
public static final int SCALE_SMOOTH = 4;
|
||||
|
||||
/**
|
||||
* The Constant SCALE_REPLICATE indicates the image scaling algorithm in the
|
||||
* ReplicateScaleFilter class.
|
||||
*/
|
||||
public static final int SCALE_REPLICATE = 8;
|
||||
|
||||
/**
|
||||
* The Constant SCALE_AREA_AVERAGING indicates the area averaging image
|
||||
* scaling algorithm.
|
||||
*/
|
||||
public static final int SCALE_AREA_AVERAGING = 16;
|
||||
|
||||
/**
|
||||
* The acceleration priority indicates image acceleration.
|
||||
*/
|
||||
protected float accelerationPriority = 0.5f;
|
||||
|
||||
/**
|
||||
* The Constant capabilities.
|
||||
*/
|
||||
private static final ImageCapabilities capabilities = new ImageCapabilities(false);
|
||||
|
||||
/**
|
||||
* Gets the image property with the specified name. The UndefinedProperty
|
||||
* object should be return if the property is not specified for this image.
|
||||
* The return value should be null if the property is currently unknown yet
|
||||
* and the specified ImageObserver is to be notified later.
|
||||
*
|
||||
* @param name
|
||||
* the name of image's property.
|
||||
* @param observer
|
||||
* the ImageObserver.
|
||||
* @return the Object which represents value of the specified property.
|
||||
*/
|
||||
public abstract Object getProperty(String name, ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Gets the ImageProducer object which represents data of this Image.
|
||||
*
|
||||
* @return the ImageProducer object which represents data of this Image.
|
||||
*/
|
||||
public abstract ImageProducer getSource();
|
||||
|
||||
/**
|
||||
* Gets the width of this image. The specified ImageObserver object is
|
||||
* notified when the width of this image is available.
|
||||
*
|
||||
* @param observer
|
||||
* the ImageObserver object which is is notified when the width
|
||||
* of this image is available.
|
||||
* @return the width of image, or -1 if the width of this image is not
|
||||
* available.
|
||||
*/
|
||||
public abstract int getWidth(ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Gets the height of this image. The specified ImageObserver object is
|
||||
* notified when the height of this image is available.
|
||||
*
|
||||
* @param observer
|
||||
* the ImageObserver object which is is notified when the height
|
||||
* of this image is available.
|
||||
* @return the height of image, or -1 if the height of this image is not
|
||||
* available.
|
||||
*/
|
||||
public abstract int getHeight(ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Gets the scaled instance of this Image. This method returns an Image
|
||||
* object constructed from the source of this image with the specified
|
||||
* width, height, and applied scaling algorithm.
|
||||
*
|
||||
* @param width
|
||||
* the width of scaled Image.
|
||||
* @param height
|
||||
* the height of scaled Image.
|
||||
* @param hints
|
||||
* the constant which indicates scaling algorithm.
|
||||
* @return the scaled Image.
|
||||
*/
|
||||
public Image getScaledInstance(int width, int height, int hints) {
|
||||
ImageFilter filter;
|
||||
if ((hints & (SCALE_SMOOTH | SCALE_AREA_AVERAGING)) != 0) {
|
||||
filter = new AreaAveragingScaleFilter(width, height);
|
||||
} else {
|
||||
filter = new ReplicateScaleFilter(width, height);
|
||||
}
|
||||
ImageProducer producer = new FilteredImageSource(getSource(), filter);
|
||||
return Toolkit.getDefaultToolkit().createImage(producer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a Graphics object for rendering this image. This method can be used
|
||||
* for off-screen images.
|
||||
*
|
||||
* @return a Graphics object for rendering to this image.
|
||||
*/
|
||||
public abstract Graphics getGraphics();
|
||||
|
||||
/**
|
||||
* Flushes resources which are used by this Image object. This method resets
|
||||
* the image to the reconstructed state from the image's source.
|
||||
*/
|
||||
public abstract void flush();
|
||||
|
||||
/**
|
||||
* Gets the acceleration priority of this image.
|
||||
*
|
||||
* @return the acceleration priority of this image.
|
||||
*/
|
||||
public float getAccelerationPriority() {
|
||||
return accelerationPriority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the acceleration priority for this image.
|
||||
*
|
||||
* @param priority
|
||||
* the new acceleration priority (value in the range 0-1).
|
||||
*/
|
||||
public void setAccelerationPriority(float priority) {
|
||||
if (priority < 0 || priority > 1) {
|
||||
// awt.10A=Priority must be a value between 0 and 1, inclusive
|
||||
throw new IllegalArgumentException(Messages.getString("awt.10A")); //$NON-NLS-1$
|
||||
}
|
||||
accelerationPriority = priority;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an ImageCapabilities object of this Image object for the specified
|
||||
* GraphicsConfiguration.
|
||||
*
|
||||
* @param gc
|
||||
* the specified GraphicsConfiguration object (null value means
|
||||
* default GraphicsConfiguration).
|
||||
* @return an ImageCapabilities object of this Image object for the
|
||||
* specified GraphicsConfiguration.
|
||||
*/
|
||||
public ImageCapabilities getCapabilities(GraphicsConfiguration gc) {
|
||||
// Note: common image is not accelerated.
|
||||
return capabilities;
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The ImageCapabilities class gives information about an image's capabilities.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class ImageCapabilities implements Cloneable {
|
||||
|
||||
/**
|
||||
* The accelerated.
|
||||
*/
|
||||
private final boolean accelerated;
|
||||
|
||||
/**
|
||||
* Instantiates a new ImageCapabilities with the specified acceleration flag
|
||||
* which indicates whether acceleration is desired or not.
|
||||
*
|
||||
* @param accelerated
|
||||
* the accelerated flag.
|
||||
*/
|
||||
public ImageCapabilities(boolean accelerated) {
|
||||
this.accelerated = accelerated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of this ImageCapabilities object.
|
||||
*
|
||||
* @return the copy of this ImageCapabilities object.
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
return new ImageCapabilities(accelerated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the Image of this ImageCapabilities is or can be
|
||||
* accelerated.
|
||||
*
|
||||
* @return true, if the Image of this ImageCapabilities is or can be
|
||||
* accelerated, false otherwise.
|
||||
*/
|
||||
public boolean isAccelerated() {
|
||||
return accelerated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this ImageCapabilities applies to the VolatileImage which
|
||||
* can lose its surfaces.
|
||||
*
|
||||
* @return true if this ImageCapabilities applies to the VolatileImage which
|
||||
* can lose its surfaces, false otherwise.
|
||||
*/
|
||||
public boolean isTrueVolatile() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Dmitry A. Durnev
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.harmony.misc.HashCode;
|
||||
|
||||
/**
|
||||
* The Insets class represents the borders of a container. This class describes
|
||||
* the space that a container should leave at each edge: the top, the bottom,
|
||||
* the right side, and the left side. The space can be filled with a border, a
|
||||
* blank space, or a title.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class Insets implements Cloneable, Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -2272572637695466749L;
|
||||
|
||||
/**
|
||||
* The top inset indicates the size of the space added to the top of the
|
||||
* rectangle.
|
||||
*/
|
||||
public int top;
|
||||
|
||||
/**
|
||||
* The left inset indicates the size of the space added to the left side of
|
||||
* the rectangle.
|
||||
*/
|
||||
public int left;
|
||||
|
||||
/**
|
||||
* The bottom inset indicates the size of the space subtracted from the
|
||||
* bottom of the rectangle.
|
||||
*/
|
||||
public int bottom;
|
||||
|
||||
/**
|
||||
* The right inset indicates the size of the space subtracted from the right
|
||||
* side of the rectangle.
|
||||
*/
|
||||
public int right;
|
||||
|
||||
/**
|
||||
* Instantiates a new Inset object with the specified top, left, bottom,
|
||||
* right parameters.
|
||||
*
|
||||
* @param top
|
||||
* the top inset.
|
||||
* @param left
|
||||
* the left inset.
|
||||
* @param bottom
|
||||
* the bottom inset.
|
||||
* @param right
|
||||
* the right inset.
|
||||
*/
|
||||
public Insets(int top, int left, int bottom, int right) {
|
||||
setValues(top, left, bottom, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code of the Insets object.
|
||||
*
|
||||
* @return a hash code of the Insets object.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = HashCode.EMPTY_HASH_CODE;
|
||||
hashCode = HashCode.combine(hashCode, top);
|
||||
hashCode = HashCode.combine(hashCode, left);
|
||||
hashCode = HashCode.combine(hashCode, bottom);
|
||||
hashCode = HashCode.combine(hashCode, right);
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of this Insets object.
|
||||
*
|
||||
* @return a copy of this Insets object.
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
return new Insets(top, left, bottom, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this Insets object is equal to the specified object.
|
||||
*
|
||||
* @param o
|
||||
* the Object to be compared.
|
||||
* @return true, if the object is an Insets object whose data values are
|
||||
* equal to those of this object, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
if (o instanceof Insets) {
|
||||
Insets i = (Insets)o;
|
||||
return ((i.left == left) && (i.bottom == bottom) && (i.right == right) && (i.top == top));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String representation of this Insets object.
|
||||
*
|
||||
* @return a String representation of this Insets object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
/*
|
||||
* The format is based on 1.5 release behavior which can be revealed by
|
||||
* the following code: System.out.println(new Insets(1, 2, 3, 4));
|
||||
*/
|
||||
|
||||
return (getClass().getName() + "[left=" + left + ",top=" + top + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
",right=" + right + ",bottom=" + bottom + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets top, left, bottom, and right insets to the specified values.
|
||||
*
|
||||
* @param top
|
||||
* the top inset.
|
||||
* @param left
|
||||
* the left inset.
|
||||
* @param bottom
|
||||
* the bottom inset.
|
||||
* @param right
|
||||
* the right inset.
|
||||
*/
|
||||
public void set(int top, int left, int bottom, int right) {
|
||||
setValues(top, left, bottom, right);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the values.
|
||||
*
|
||||
* @param top
|
||||
* the top.
|
||||
* @param left
|
||||
* the left.
|
||||
* @param bottom
|
||||
* the bottom.
|
||||
* @param right
|
||||
* the right.
|
||||
*/
|
||||
private void setValues(int top, int left, int bottom, int right) {
|
||||
this.top = top;
|
||||
this.left = left;
|
||||
this.bottom = bottom;
|
||||
this.right = right;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
/**
|
||||
* The ItemSelectable interface represents a set of items which can be selected.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface ItemSelectable {
|
||||
|
||||
/**
|
||||
* Adds an ItemListener for receiving item events when the state of an item
|
||||
* is changed by the user.
|
||||
*
|
||||
* @param l
|
||||
* the ItemListener.
|
||||
*/
|
||||
public void addItemListener(ItemListener l);
|
||||
|
||||
/**
|
||||
* Gets an array of the selected objects or null if there is no selected
|
||||
* object.
|
||||
*
|
||||
* @return an array of the selected objects or null if there is no selected
|
||||
* object.
|
||||
*/
|
||||
public Object[] getSelectedObjects();
|
||||
|
||||
/**
|
||||
* Removes the specified ItemListener.
|
||||
*
|
||||
* @param l
|
||||
* the ItemListener which will be removed.
|
||||
*/
|
||||
public void removeItemListener(ItemListener l);
|
||||
|
||||
}
|
||||
@@ -1,783 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.peer.MenuComponentPeer;
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale; //import javax.accessibility.Accessible;
|
||||
//import javax.accessibility.AccessibleComponent;
|
||||
//import javax.accessibility.AccessibleContext;
|
||||
//import javax.accessibility.AccessibleRole;
|
||||
//import javax.accessibility.AccessibleSelection;
|
||||
//import javax.accessibility.AccessibleStateSet;
|
||||
import org.apache.harmony.awt.gl.MultiRectArea;
|
||||
import org.apache.harmony.awt.state.MenuItemState;
|
||||
import org.apache.harmony.awt.state.MenuState;
|
||||
import org.apache.harmony.luni.util.NotImplementedException;
|
||||
|
||||
/**
|
||||
* The MenuComponent abstract class is the superclass for menu components. Menu
|
||||
* components receive and process AWT events.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class MenuComponent implements Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -4536902356223894379L;
|
||||
|
||||
/**
|
||||
* The name.
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* The font.
|
||||
*/
|
||||
private Font font;
|
||||
|
||||
/**
|
||||
* The parent.
|
||||
*/
|
||||
MenuContainer parent;
|
||||
|
||||
/**
|
||||
* The deprecated event handler.
|
||||
*/
|
||||
boolean deprecatedEventHandler = true;
|
||||
|
||||
/**
|
||||
* The selected item index.
|
||||
*/
|
||||
private int selectedItemIndex;
|
||||
|
||||
// ???AWT: private AccessibleContext accessibleContext;
|
||||
|
||||
/**
|
||||
* The toolkit.
|
||||
*/
|
||||
final Toolkit toolkit = Toolkit.getDefaultToolkit();
|
||||
|
||||
// ???AWT
|
||||
/*
|
||||
* protected abstract class AccessibleAWTMenuComponent extends
|
||||
* AccessibleContext implements Serializable, AccessibleComponent,
|
||||
* AccessibleSelection { private static final long serialVersionUID =
|
||||
* -4269533416223798698L; public void addFocusListener(FocusListener
|
||||
* listener) { } public boolean contains(Point pt) { return false; } public
|
||||
* Accessible getAccessibleAt(Point pt) { return null; } public Color
|
||||
* getBackground() { return null; } public Rectangle getBounds() { return
|
||||
* null; } public Cursor getCursor() { return null; } public Font getFont()
|
||||
* { return MenuComponent.this.getFont(); } public FontMetrics
|
||||
* getFontMetrics(Font font) { return null; } public Color getForeground() {
|
||||
* return null; } public Point getLocation() { return null; } public Point
|
||||
* getLocationOnScreen() { return null; } public Dimension getSize() {
|
||||
* return null; } public boolean isEnabled() { return true; // always
|
||||
* enabled } public boolean isFocusTraversable() { return true; // always
|
||||
* focus traversable } public boolean isShowing() { return true;// always
|
||||
* showing } public boolean isVisible() { return true; // always visible }
|
||||
* public void removeFocusListener(FocusListener listener) { } public void
|
||||
* requestFocus() { } public void setBackground(Color color) { } public void
|
||||
* setBounds(Rectangle rect) { } public void setCursor(Cursor cursor) { }
|
||||
* public void setEnabled(boolean enabled) { } public void setFont(Font
|
||||
* font) { MenuComponent.this.setFont(font); } public void
|
||||
* setForeground(Color color) { } public void setLocation(Point pt) { }
|
||||
* public void setSize(Dimension pt) { } public void setVisible(boolean
|
||||
* visible) { } public void addAccessibleSelection(int index) { } public
|
||||
* void clearAccessibleSelection() { } public Accessible
|
||||
* getAccessibleSelection(int index) { return null; } public int
|
||||
* getAccessibleSelectionCount() { return 0; } public boolean
|
||||
* isAccessibleChildSelected(int index) { return false; } public void
|
||||
* removeAccessibleSelection(int index) { } public void
|
||||
* selectAllAccessibleSelection() { }
|
||||
* @Override public Accessible getAccessibleChild(int index) { return null;
|
||||
* }
|
||||
* @Override public int getAccessibleChildrenCount() { return 0; }
|
||||
* @Override public AccessibleComponent getAccessibleComponent() { return
|
||||
* this; }
|
||||
* @Override public String getAccessibleDescription() { return
|
||||
* super.getAccessibleDescription(); }
|
||||
* @Override public int getAccessibleIndexInParent() { toolkit.lockAWT();
|
||||
* try { Accessible aParent = getAccessibleParent(); int aIndex = -1; if
|
||||
* (aParent instanceof MenuComponent) { MenuComponent parent =
|
||||
* (MenuComponent) aParent; int count = parent.getItemCount(); for (int i =
|
||||
* 0; i < count; i++) { MenuComponent comp = parent.getItem(i); if (comp
|
||||
* instanceof Accessible) { aIndex++; if (comp == MenuComponent.this) {
|
||||
* return aIndex; } } } } return -1; } finally { toolkit.unlockAWT(); } }
|
||||
* @Override public String getAccessibleName() { return
|
||||
* super.getAccessibleName(); }
|
||||
* @Override public Accessible getAccessibleParent() { toolkit.lockAWT();
|
||||
* try { Accessible aParent = super.getAccessibleParent(); if (aParent !=
|
||||
* null) { return aParent; } MenuContainer parent = getParent(); if (parent
|
||||
* instanceof Accessible) { aParent = (Accessible) parent; } return aParent;
|
||||
* } finally { toolkit.unlockAWT(); } }
|
||||
* @Override public AccessibleRole getAccessibleRole() { return
|
||||
* AccessibleRole.AWT_COMPONENT; }
|
||||
* @Override public AccessibleSelection getAccessibleSelection() { return
|
||||
* this; }
|
||||
* @Override public AccessibleStateSet getAccessibleStateSet() { return new
|
||||
* AccessibleStateSet(); }
|
||||
* @Override public Locale getLocale() { return Locale.getDefault(); } }
|
||||
*/
|
||||
|
||||
/**
|
||||
* The accessor to MenuComponent internal state, utilized by the visual
|
||||
* theme.
|
||||
*
|
||||
* @throws HeadlessException
|
||||
* the headless exception.
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* class State implements MenuState { Dimension size; Dimension getSize() {
|
||||
* if (size == null) { calculate(); } return size; } public int getWidth() {
|
||||
* return getSize().width; } public int getHeight() { return
|
||||
* getSize().height; } public Font getFont() { return
|
||||
* MenuComponent.this.getFont(); } public int getItemCount() { return
|
||||
* MenuComponent.this.getItemCount(); } public int getSelectedItemIndex() {
|
||||
* return MenuComponent.this.getSelectedItemIndex(); } public boolean
|
||||
* isFontSet() { return MenuComponent.this.isFontSet(); }
|
||||
* @SuppressWarnings("deprecation") public FontMetrics getFontMetrics(Font
|
||||
* f) { return MenuComponent.this.toolkit.getFontMetrics(f); } public Point
|
||||
* getLocation() { return MenuComponent.this.getLocation(); } public
|
||||
* MenuItemState getItem(int index) { MenuItem item =
|
||||
* MenuComponent.this.getItem(index); return item.itemState; } public void
|
||||
* setSize(int w, int h) { this.size = new Dimension(w, h); } void
|
||||
* calculate() { size = new Dimension();
|
||||
* size.setSize(toolkit.theme.calculateMenuSize(this)); } void reset() { for
|
||||
* (int i = 0; i < getItemCount(); i++) { ((MenuItem.State)
|
||||
* getItem(i)).reset(); } } }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Pop-up box for menu. It transfers the paint events, keyboard and mouse
|
||||
* events to the menu component itself.
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* class MenuPopupBox extends PopupBox { private final Point lastMousePos =
|
||||
* new Point();
|
||||
* @Override boolean isMenu() { return true; }
|
||||
* @Override void paint(Graphics gr) { MenuComponent.this.paint(gr); }
|
||||
* @Override void onKeyEvent(int eventId, int vKey, long when, int
|
||||
* modifiers) { MenuComponent.this.onKeyEvent(eventId, vKey, when,
|
||||
* modifiers); }
|
||||
* @Override void onMouseEvent(int eventId, Point where, int mouseButton,
|
||||
* long when, int modifiers, int wheelRotation) { // prevent conflict of
|
||||
* mouse and keyboard // when sub-menu drops down due to keyboard navigation
|
||||
* if (lastMousePos.equals(where) && (eventId == MouseEvent.MOUSE_MOVED ||
|
||||
* eventId == MouseEvent.MOUSE_ENTERED)) { return; }
|
||||
* lastMousePos.setLocation(where); MenuComponent.this.onMouseEvent(eventId,
|
||||
* where, mouseButton, when, modifiers); } }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Instantiates a new MenuComponent object.
|
||||
*
|
||||
* @throws HeadlessException
|
||||
* if the graphical interface environment can't support
|
||||
* MenuComponents.
|
||||
*/
|
||||
public MenuComponent() throws HeadlessException {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
Toolkit.checkHeadless();
|
||||
name = autoName();
|
||||
selectedItemIndex = -1;
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the MenuComponent object.
|
||||
*
|
||||
* @return the name of the MenuComponent object.
|
||||
*/
|
||||
public String getName() {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
return name;
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String representation of the MenuComponent object.
|
||||
*
|
||||
* @return a String representation of the MenuComponent object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
return getClass().getName() + "[" + paramString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent menu container.
|
||||
*
|
||||
* @return the parent.
|
||||
*/
|
||||
public MenuContainer getParent() {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
return parent;
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the MenuComponent to the specified string.
|
||||
*
|
||||
* @param name
|
||||
* the new name of the MenuComponent object.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
this.name = name;
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches AWT event.
|
||||
*
|
||||
* @param event
|
||||
* the AWTEvent.
|
||||
*/
|
||||
public final void dispatchEvent(AWTEvent event) {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
processEvent(event);
|
||||
if (deprecatedEventHandler) {
|
||||
postDeprecatedEvent(event);
|
||||
}
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Post deprecated event.
|
||||
*
|
||||
* @param event
|
||||
* the event.
|
||||
*/
|
||||
void postDeprecatedEvent(AWTEvent event) {
|
||||
Event evt = event.getEvent();
|
||||
if (evt != null) {
|
||||
postEvent(evt);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the peer of the MenuComponent; an application must not use this
|
||||
* method directly.
|
||||
*
|
||||
* @return the MenuComponentPeer object.
|
||||
* @throws NotImplementedException
|
||||
* if this method is not implemented by a subclass.
|
||||
* @deprecated an application must not use this method directly.
|
||||
*/
|
||||
@Deprecated
|
||||
public MenuComponentPeer getPeer() throws org.apache.harmony.luni.util.NotImplementedException {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
if (true) {
|
||||
throw new RuntimeException("Method is not implemented"); //TODO: implement //$NON-NLS-1$
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the locking object of this MenuComponent.
|
||||
*
|
||||
* @return the locking object of this MenuComponent.
|
||||
*/
|
||||
protected final Object getTreeLock() {
|
||||
return toolkit.awtTreeLock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts the Event to the MenuComponent.
|
||||
*
|
||||
* @param e
|
||||
* the Event.
|
||||
* @return true, if the event is posted successfully, false otherwise.
|
||||
* @deprecated Replaced dispatchEvent method.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@Deprecated
|
||||
public boolean postEvent(Event e) {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
if (parent != null) {
|
||||
return parent.postEvent(e);
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of the MenuComponent state.
|
||||
*
|
||||
* @return returns the string representation of the MenuComponent state.
|
||||
*/
|
||||
protected String paramString() {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
return getName();
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
// ???AWT
|
||||
/*
|
||||
* public AccessibleContext getAccessibleContext() { toolkit.lockAWT(); try
|
||||
* { if (accessibleContext == null) { accessibleContext =
|
||||
* createAccessibleContext(); } return accessibleContext; } finally {
|
||||
* toolkit.unlockAWT(); } }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Gets the font of the MenuComponent object.
|
||||
*
|
||||
* @return the Font of the MenuComponent object.
|
||||
*/
|
||||
public Font getFont() {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
if (font == null && hasDefaultFont()) {
|
||||
return toolkit.getDefaultFont();
|
||||
}
|
||||
if (font == null && parent != null) {
|
||||
return parent.getFont();
|
||||
}
|
||||
return font;
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is font set.
|
||||
*
|
||||
* @return true, if is font set
|
||||
*/
|
||||
boolean isFontSet() {
|
||||
return font != null
|
||||
|| ((parent instanceof MenuComponent) && ((MenuComponent)parent).isFontSet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for default font.
|
||||
*
|
||||
* @return true, if successful.
|
||||
*/
|
||||
boolean hasDefaultFont() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes an AWTEevent on this menu component.
|
||||
*
|
||||
* @param event
|
||||
* the AWTEvent.
|
||||
*/
|
||||
protected void processEvent(AWTEvent event) {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
// do nothing
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the peer of the MenuComponent.
|
||||
*/
|
||||
public void removeNotify() {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Font for this MenuComponent object.
|
||||
*
|
||||
* @param font
|
||||
* the new Font to be used for this MenuComponent.
|
||||
*/
|
||||
public void setFont(Font font) {
|
||||
toolkit.lockAWT();
|
||||
try {
|
||||
this.font = font;
|
||||
} finally {
|
||||
toolkit.unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent.
|
||||
*
|
||||
* @param parent
|
||||
* the new parent.
|
||||
*/
|
||||
void setParent(MenuContainer parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location.
|
||||
*
|
||||
* @return the location.
|
||||
*/
|
||||
Point getLocation() {
|
||||
// to be overridden
|
||||
return new Point(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width.
|
||||
*
|
||||
* @return the width.
|
||||
*/
|
||||
int getWidth() {
|
||||
// to be overridden
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height.
|
||||
*
|
||||
* @return the height.
|
||||
*/
|
||||
int getHeight() {
|
||||
// to be overridden
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively find the menu item for a menu shortcut.
|
||||
*
|
||||
* @param gr
|
||||
* the gr.
|
||||
* @return the menu item; or null if the item is not available for this
|
||||
* shortcut.
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* MenuItem getShortcutMenuItemImpl(MenuShortcut ms) { if (ms == null) {
|
||||
* return null; } for (int i = 0; i < getItemCount(); i++) { MenuItem mi =
|
||||
* getItem(i); if (mi instanceof Menu) { mi = ((Menu)
|
||||
* mi).getShortcutMenuItemImpl(ms); if (mi != null) { return mi; } } else if
|
||||
* (ms.equals(mi.getShortcut())) { return mi; } } return null; }
|
||||
*/
|
||||
|
||||
void paint(Graphics gr) {
|
||||
gr.setColor(Color.LIGHT_GRAY);
|
||||
gr.fillRect(0, 0, getWidth(), getHeight());
|
||||
gr.setColor(Color.BLACK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mouse events handler.
|
||||
*
|
||||
* @param eventId
|
||||
* one of the MouseEvent.MOUSE_* constants.
|
||||
* @param where
|
||||
* mouse location.
|
||||
* @param mouseButton
|
||||
* mouse button that was pressed or released.
|
||||
* @param when
|
||||
* event time.
|
||||
* @param modifiers
|
||||
* input event modifiers.
|
||||
*/
|
||||
void onMouseEvent(int eventId, Point where, int mouseButton, long when, int modifiers) {
|
||||
// to be overridden
|
||||
}
|
||||
|
||||
/**
|
||||
* Keyboard event handler.
|
||||
*
|
||||
* @param eventId
|
||||
* one of the KeyEvent.KEY_* constants.
|
||||
* @param vKey
|
||||
* the key code.
|
||||
* @param when
|
||||
* event time.
|
||||
* @param modifiers
|
||||
* input event modifiers.
|
||||
*/
|
||||
void onKeyEvent(int eventId, int vKey, long when, int modifiers) {
|
||||
// to be overridden
|
||||
}
|
||||
|
||||
/**
|
||||
* Post the ActionEvent or ItemEvent, depending on type of the menu item.
|
||||
*
|
||||
* @param index
|
||||
* the index.
|
||||
* @return the item rect.
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* void fireItemAction(int item, long when, int modifiers) { MenuItem mi =
|
||||
* getItem(item); mi.itemSelected(when, modifiers); } MenuItem getItem(int
|
||||
* index) { // to be overridden return null; } int getItemCount() { return
|
||||
* 0; }
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return The sub-menu of currently selecetd item, or null if such a
|
||||
* sub-menu is not available.
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* Menu getSelectedSubmenu() { if (selectedItemIndex < 0) { return null; }
|
||||
* MenuItem item = getItem(selectedItemIndex); return (item instanceof Menu)
|
||||
* ? (Menu) item : null; }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Convenience method for selectItem(index, true).
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* void selectItem(int index) { selectItem(index, true); }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Change the selection in the menu.
|
||||
*
|
||||
* @param index
|
||||
* new selecetd item's index.
|
||||
* @param showSubMenu
|
||||
* if new selected item has a sub-menu, should that sub-menu be
|
||||
* displayed.
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* void selectItem(int index, boolean showSubMenu) { if (selectedItemIndex
|
||||
* == index) { return; } if (selectedItemIndex >= 0 &&
|
||||
* getItem(selectedItemIndex) instanceof Menu) { ((Menu)
|
||||
* getItem(selectedItemIndex)).hide(); } MultiRectArea clip =
|
||||
* getUpdateClip(index, selectedItemIndex); selectedItemIndex = index;
|
||||
* Graphics gr = getGraphics(clip); if (gr != null) { paint(gr); } if
|
||||
* (showSubMenu) { showSubMenu(selectedItemIndex); } }
|
||||
*/
|
||||
|
||||
/**
|
||||
* Change the selected item to the next one in the requested direction
|
||||
* moving cyclically, skipping separators
|
||||
*
|
||||
* @param forward
|
||||
* the direction to move the selection.
|
||||
* @param showSubMenu
|
||||
* if new selected item has a sub-menu, should that sub-menu be
|
||||
* displayed.
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* void selectNextItem(boolean forward, boolean showSubMenu) { int selected
|
||||
* = getSelectedItemIndex(); int count = getItemCount(); if (count == 0) {
|
||||
* return; } if (selected < 0) { selected = (forward ? count - 1 : 0); } int
|
||||
* i = selected; do { i = (forward ? (i + 1) : (i + count - 1)) % count; i
|
||||
* %= count; MenuItem item = getItem(i); if (!"-".equals(item.getLabel())) {
|
||||
* //$NON-NLS-1$ selectItem(i, showSubMenu); return; } } while (i !=
|
||||
* selected); } void showSubMenu(int index) { if ((index < 0) ||
|
||||
* !isActive()) { return; } MenuItem item = getItem(index); if (item
|
||||
* instanceof Menu) { Menu menu = ((Menu) getItem(index)); if
|
||||
* (menu.getItemCount() == 0) { return; } Point location =
|
||||
* getSubmenuLocation(index); menu.show(location.x, location.y, false); } }
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return the menu bar which is the root of current menu's hierarchy; or
|
||||
* null if the hierarchy root is not a menu bar.
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* MenuBar getMenuBar() { if (parent instanceof MenuBar) { return (MenuBar)
|
||||
* parent; } if (parent instanceof MenuComponent) { return ((MenuComponent)
|
||||
* parent).getMenuBar(); } return null; } PopupBox getPopupBox() { return
|
||||
* null; }
|
||||
*/
|
||||
|
||||
Rectangle getItemRect(int index) {
|
||||
// to be overridden
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the clip region when menu selection is changed from index1 to
|
||||
* index2.
|
||||
*
|
||||
* @param index1
|
||||
* old selected item.
|
||||
* @param index2
|
||||
* new selected item.
|
||||
* @return the region to repaint.
|
||||
*/
|
||||
final MultiRectArea getUpdateClip(int index1, int index2) {
|
||||
MultiRectArea clip = new MultiRectArea();
|
||||
if (index1 >= 0) {
|
||||
clip.add(getItemRect(index1));
|
||||
}
|
||||
if (index2 >= 0) {
|
||||
clip.add(getItemRect(index2));
|
||||
}
|
||||
return clip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the submenu location.
|
||||
*
|
||||
* @param index
|
||||
* the index.
|
||||
* @return the submenu location.
|
||||
*/
|
||||
Point getSubmenuLocation(int index) {
|
||||
// to be overridden
|
||||
return new Point(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected item index.
|
||||
*
|
||||
* @return the selected item index.
|
||||
*/
|
||||
int getSelectedItemIndex() {
|
||||
return selectedItemIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide.
|
||||
*/
|
||||
void hide() {
|
||||
selectedItemIndex = -1;
|
||||
if (parent instanceof MenuComponent) {
|
||||
((MenuComponent)parent).itemHidden(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Item hidden.
|
||||
*
|
||||
* @param mc
|
||||
* the mc.
|
||||
*/
|
||||
void itemHidden(MenuComponent mc) {
|
||||
// to be overridden
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is visible.
|
||||
*
|
||||
* @return true, if is visible.
|
||||
*/
|
||||
boolean isVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is active.
|
||||
*
|
||||
* @return true, if is active.
|
||||
*/
|
||||
boolean isActive() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide all menu hierarchy.
|
||||
*/
|
||||
void endMenu() {
|
||||
// ???AWT: toolkit.dispatcher.popupDispatcher.deactivateAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the mouse click or Enter key event on a menu's item.
|
||||
*
|
||||
* @param when
|
||||
* the event time.
|
||||
* @param modifiers
|
||||
* input event modifiers.
|
||||
*/
|
||||
void itemSelected(long when, int modifiers) {
|
||||
endMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto name.
|
||||
*
|
||||
* @return the string.
|
||||
*/
|
||||
String autoName() {
|
||||
String name = getClass().getName();
|
||||
if (name.indexOf("$") != -1) { //$NON-NLS-1$
|
||||
return null;
|
||||
}
|
||||
// ???AWT: int number = toolkit.autoNumber.nextMenuComponent++;
|
||||
int number = 0;
|
||||
name = name.substring(name.lastIndexOf(".") + 1) + Integer.toString(number); //$NON-NLS-1$
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the Graphics object for the pop-up box of this menu component.
|
||||
*
|
||||
* @param clip
|
||||
* the clip to set on this Graphics.
|
||||
* @return the created Graphics object, or null if such object is not
|
||||
* available.
|
||||
*/
|
||||
Graphics getGraphics(MultiRectArea clip) {
|
||||
// to be overridden
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return accessible context specific for particular menu component.
|
||||
*/
|
||||
// ???AWT
|
||||
/*
|
||||
* AccessibleContext createAccessibleContext() { return null; }
|
||||
*/
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Pavel Dolgov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The MenuContainer interface represents all menu containers.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface MenuContainer {
|
||||
|
||||
/**
|
||||
* Removes the specified MenuComponent from the MenuContainer.
|
||||
*
|
||||
* @param c
|
||||
* the MenuComponent.
|
||||
*/
|
||||
public void remove(MenuComponent c);
|
||||
|
||||
/**
|
||||
* Gets the Font of the MenuContainer.
|
||||
*
|
||||
* @return the font of the MenuContainer.
|
||||
*/
|
||||
public Font getFont();
|
||||
|
||||
/**
|
||||
* Posts an Event.
|
||||
*
|
||||
* @param e
|
||||
* the Event.
|
||||
* @return true if the event is posted successfully, false otherwise.
|
||||
* @deprecated Replaced by dispatchEvent method.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean postEvent(Event e);
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Pavel Dolgov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
*
|
||||
* The context for nested event loop. It can be dialog, popup menu etc.
|
||||
*/
|
||||
class ModalContext {
|
||||
|
||||
private boolean running = false;
|
||||
|
||||
private final Toolkit toolkit;
|
||||
|
||||
ModalContext() {
|
||||
toolkit = Toolkit.getDefaultToolkit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up and run modal loop in this context
|
||||
*
|
||||
*/
|
||||
void runModalLoop() {
|
||||
running = true;
|
||||
toolkit.dispatchThread.runModalLoop(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Leave the modal loop running in this context
|
||||
* This method doesn't stops the loop immediately,
|
||||
* it just sets the flag that says the modal loop to stop
|
||||
*
|
||||
*/
|
||||
void endModalLoop() {
|
||||
running = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return modal loop is currently running in this context
|
||||
*/
|
||||
boolean isModalLoopRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,418 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Dmitry A. Durnev, Michael Danilov, Pavel Dolgov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
import java.awt.Dispatcher.MouseGrabManager;
|
||||
import java.util.EventListener;
|
||||
|
||||
import org.apache.harmony.awt.wtk.NativeEvent;
|
||||
import org.apache.harmony.awt.wtk.NativeWindow;
|
||||
|
||||
|
||||
class MouseDispatcher {
|
||||
|
||||
// Fields for synthetic mouse click events generation
|
||||
private static final int clickDelta = 5;
|
||||
private final long[] lastPressTime = new long[] {0l, 0l, 0l};
|
||||
private final Point[] lastPressPos = new Point[] {null, null, null};
|
||||
private final boolean[] buttonPressed = new boolean[] {false, false, false};
|
||||
private final int[] clickCount = new int[] {0, 0, 0};
|
||||
|
||||
// Fields for mouse entered/exited support
|
||||
private Component lastUnderPointer = null;
|
||||
private final Point lastScreenPos = new Point(-1, -1);
|
||||
|
||||
// Fields for redundant mouse moved/dragged filtering
|
||||
private Component lastUnderMotion = null;
|
||||
private Point lastLocalPos = new Point(-1, -1);
|
||||
|
||||
private final MouseGrabManager mouseGrabManager;
|
||||
private final Toolkit toolkit;
|
||||
|
||||
static Point convertPoint(Component src, int x, int y, Component dest) {
|
||||
Point srcPoint = getAbsLocation(src);
|
||||
Point destPoint = getAbsLocation(dest);
|
||||
|
||||
return new Point(x + (srcPoint.x - destPoint.x),
|
||||
y + (srcPoint.y - destPoint.y));
|
||||
}
|
||||
|
||||
static Point convertPoint(Component src, Point p, Component dst) {
|
||||
return convertPoint(src, p.x, p.y, dst);
|
||||
}
|
||||
|
||||
private static Point getAbsLocation(Component comp) {
|
||||
Point location = new Point(0, 0);
|
||||
// BEGIN android-changed: AWT components not supported
|
||||
// for (Component parent = comp; parent != null; parent = parent.parent) {
|
||||
// Point parentPos = (parent instanceof EmbeddedWindow ?
|
||||
// parent.getNativeWindow().getScreenPos() :
|
||||
// parent.getLocation());
|
||||
//
|
||||
// location.translate(parentPos.x, parentPos.y);
|
||||
//
|
||||
// if (parent instanceof Window) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// END android-changed
|
||||
|
||||
return location;
|
||||
}
|
||||
|
||||
MouseDispatcher(MouseGrabManager mouseGrabManager,
|
||||
Toolkit toolkit) {
|
||||
this.mouseGrabManager = mouseGrabManager;
|
||||
this.toolkit = toolkit;
|
||||
}
|
||||
|
||||
Point getPointerPos() {
|
||||
return lastScreenPos;
|
||||
}
|
||||
|
||||
boolean dispatch(Component src, NativeEvent event) {
|
||||
int id = event.getEventId();
|
||||
|
||||
lastScreenPos.setLocation(event.getScreenPos());
|
||||
checkMouseEnterExit(event.getInputModifiers(), event.getTime());
|
||||
|
||||
if (id == MouseEvent.MOUSE_WHEEL) {
|
||||
// BEGIN android-changed: AWT components not supported
|
||||
// dispatchWheelEvent(src, event);
|
||||
// END android-changed
|
||||
} else if ((id != MouseEvent.MOUSE_ENTERED) &&
|
||||
(id != MouseEvent.MOUSE_EXITED)) {
|
||||
PointerInfo info = new PointerInfo(src, event.getLocalPos());
|
||||
|
||||
mouseGrabManager.preprocessEvent(event);
|
||||
findEventSource(info);
|
||||
if ((id == MouseEvent.MOUSE_PRESSED) ||
|
||||
(id == MouseEvent.MOUSE_RELEASED)) {
|
||||
|
||||
dispatchButtonEvent(info, event);
|
||||
} else if ((id == MouseEvent.MOUSE_MOVED) ||
|
||||
(id == MouseEvent.MOUSE_DRAGGED)) {
|
||||
|
||||
dispatchMotionEvent(info, event);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void checkMouseEnterExit(int modifiers, long when) {
|
||||
// BEGIN android-changed: AWT components not supported
|
||||
// PointerInfo info = findComponentUnderPointer();
|
||||
// Component curUnderPointer =
|
||||
// propagateEvent(info, AWTEvent.MOUSE_EVENT_MASK,
|
||||
// MouseListener.class, false).src;
|
||||
//
|
||||
// if (curUnderPointer != lastUnderPointer) {
|
||||
// Point pos = info.position;
|
||||
// if ((lastUnderPointer != null) &&
|
||||
// lastUnderPointer.isMouseExitedExpected()) {
|
||||
//
|
||||
// Point exitPos = convertPoint(null, lastScreenPos.x,
|
||||
// lastScreenPos.y, lastUnderPointer);
|
||||
//
|
||||
// postMouseEnterExit(MouseEvent.MOUSE_EXITED, modifiers, when,
|
||||
// exitPos.x, exitPos.y, lastUnderPointer);
|
||||
// }
|
||||
// setCursor(curUnderPointer);
|
||||
// if (curUnderPointer != null) {
|
||||
// postMouseEnterExit(MouseEvent.MOUSE_ENTERED, modifiers, when,
|
||||
// pos.x, pos.y, curUnderPointer);
|
||||
// }
|
||||
// lastUnderPointer = curUnderPointer;
|
||||
// }
|
||||
// END android-changed
|
||||
}
|
||||
|
||||
private void setCursor(Component comp) {
|
||||
if (comp == null) {
|
||||
return;
|
||||
}
|
||||
Component grabOwner = mouseGrabManager.getSyntheticGrabOwner();
|
||||
Component cursorComp = ((grabOwner != null) &&
|
||||
grabOwner.isShowing() ? grabOwner : comp);
|
||||
cursorComp.setCursor();
|
||||
}
|
||||
|
||||
private void postMouseEnterExit(int id, int mod, long when,
|
||||
int x, int y, Component comp) {
|
||||
if (comp.isIndirectlyEnabled()) {
|
||||
toolkit.getSystemEventQueueImpl().postEvent(
|
||||
new MouseEvent(comp, id, when, mod, x, y, 0, false));
|
||||
comp.setMouseExitedExpected(id == MouseEvent.MOUSE_ENTERED);
|
||||
} else {
|
||||
comp.setMouseExitedExpected(false);
|
||||
}
|
||||
}
|
||||
|
||||
// BEGIN android-changed: AWT components not supported
|
||||
// private PointerInfo findComponentUnderPointer() {
|
||||
// NativeWindow nativeWindow = toolkit.getWindowFactory().
|
||||
// getWindowFromPoint(lastScreenPos);
|
||||
//
|
||||
// if (nativeWindow != null) {
|
||||
// Component comp = toolkit.getComponentById(nativeWindow.getId());
|
||||
//
|
||||
// if (comp != null) {
|
||||
// Window window = comp.getWindowAncestor();
|
||||
// Point pointerPos = convertPoint(null, lastScreenPos.x,
|
||||
// lastScreenPos.y, window);
|
||||
//
|
||||
// if (window.getClient().contains(pointerPos)) {
|
||||
// PointerInfo info = new PointerInfo(window, pointerPos);
|
||||
//
|
||||
// fall2Child(info);
|
||||
//
|
||||
// return info;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return new PointerInfo(null, null);
|
||||
// }
|
||||
// END android-changed
|
||||
|
||||
private void findEventSource(PointerInfo info) {
|
||||
Component grabOwner = mouseGrabManager.getSyntheticGrabOwner();
|
||||
|
||||
if (grabOwner != null && grabOwner.isShowing()) {
|
||||
info.position = convertPoint(info.src, info.position, grabOwner);
|
||||
info.src = grabOwner;
|
||||
} else {
|
||||
//???AWT: rise2TopLevel(info);
|
||||
//???AWT: fall2Child(info);
|
||||
}
|
||||
}
|
||||
|
||||
// BEGIN android-changed: AWT components not supported
|
||||
// private void rise2TopLevel(PointerInfo info) {
|
||||
// while (!(info.src instanceof Window)) {
|
||||
// info.position.translate(info.src.x, info.src.y);
|
||||
// info.src = info.src.parent;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void fall2Child(PointerInfo info) {
|
||||
// Insets insets = info.src.getInsets();
|
||||
//
|
||||
// final Point pos = info.position;
|
||||
// final int x = pos.x;
|
||||
// final int y = pos.y;
|
||||
// if ((x >= insets.left) && (y >= insets.top) &&
|
||||
// (x < (info.src.w - insets.right)) &&
|
||||
// (y < (info.src.h - insets.bottom)))
|
||||
// {
|
||||
// Component[] children = ((Container) info.src).getComponents();
|
||||
//
|
||||
// for (Component child : children) {
|
||||
// if (child.isShowing()) {
|
||||
// if (child.contains(x - child.getX(),
|
||||
// y - child.getY()))
|
||||
// {
|
||||
// info.src = child;
|
||||
// pos.translate(-child.x, -child.y);
|
||||
//
|
||||
// if (child instanceof Container) {
|
||||
// fall2Child(info);
|
||||
// }
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// END android-changed
|
||||
|
||||
private void dispatchButtonEvent(PointerInfo info, NativeEvent event) {
|
||||
int button = event.getMouseButton();
|
||||
long time = event.getTime();
|
||||
int id = event.getEventId();
|
||||
int index = button - 1;
|
||||
boolean clickRequired = false;
|
||||
|
||||
propagateEvent(info, AWTEvent.MOUSE_EVENT_MASK,
|
||||
MouseListener.class, false);
|
||||
if (id == MouseEvent.MOUSE_PRESSED) {
|
||||
int clickInterval = toolkit.dispatcher.clickInterval;
|
||||
mouseGrabManager.onMousePressed(info.src);
|
||||
buttonPressed[index] = true;
|
||||
clickCount[index] = (!deltaExceeded(index, info) &&
|
||||
((time - lastPressTime[index]) <= clickInterval)) ?
|
||||
clickCount[index] + 1 : 1;
|
||||
lastPressTime[index] = time;
|
||||
lastPressPos[index] = info.position;
|
||||
} else {
|
||||
mouseGrabManager.onMouseReleased(info.src);
|
||||
// set cursor back on synthetic mouse grab end:
|
||||
// BEGIN android-changed: AWT components not supported
|
||||
// setCursor(findComponentUnderPointer().src);
|
||||
// END android-changed
|
||||
if (buttonPressed[index]) {
|
||||
buttonPressed[index] = false;
|
||||
clickRequired = !deltaExceeded(index, info);
|
||||
} else {
|
||||
clickCount[index] = 0;
|
||||
}
|
||||
}
|
||||
if (info.src.isIndirectlyEnabled()) {
|
||||
final Point pos = info.position;
|
||||
final int mod = event.getInputModifiers();
|
||||
toolkit.getSystemEventQueueImpl().postEvent(
|
||||
new MouseEvent(info.src, id, time, mod, pos.x,
|
||||
pos.y, clickCount[index],
|
||||
event.getTrigger(), button));
|
||||
if (clickRequired) {
|
||||
toolkit.getSystemEventQueueImpl().postEvent(
|
||||
new MouseEvent(info.src,
|
||||
MouseEvent.MOUSE_CLICKED,
|
||||
time, mod, pos.x, pos.y,
|
||||
clickCount[index], false,
|
||||
button));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean deltaExceeded(int index, PointerInfo info) {
|
||||
final Point lastPos = lastPressPos[index];
|
||||
if (lastPos == null) {
|
||||
return true;
|
||||
}
|
||||
return ((Math.abs(lastPos.x - info.position.x) > clickDelta) ||
|
||||
(Math.abs(lastPos.y - info.position.y) > clickDelta));
|
||||
}
|
||||
|
||||
private void dispatchMotionEvent(PointerInfo info, NativeEvent event) {
|
||||
propagateEvent(info, AWTEvent.MOUSE_MOTION_EVENT_MASK,
|
||||
MouseMotionListener.class, false);
|
||||
final Point pos = info.position;
|
||||
if ((lastUnderMotion != info.src) ||
|
||||
!lastLocalPos.equals(pos)) {
|
||||
|
||||
lastUnderMotion = info.src;
|
||||
lastLocalPos = pos;
|
||||
|
||||
if (info.src.isIndirectlyEnabled()) {
|
||||
toolkit.getSystemEventQueueImpl().postEvent(
|
||||
new MouseEvent(info.src, event.getEventId(),
|
||||
event.getTime(),
|
||||
event.getInputModifiers(),
|
||||
pos.x, pos.y, 0, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseWheelEvent createWheelEvent(Component src, NativeEvent event,
|
||||
Point where) {
|
||||
|
||||
Integer scrollAmountProperty =
|
||||
(Integer)toolkit.getDesktopProperty("awt.wheelScrollingSize"); //$NON-NLS-1$
|
||||
int amount = 1;
|
||||
int type = MouseWheelEvent.WHEEL_UNIT_SCROLL;
|
||||
|
||||
if (scrollAmountProperty != null) {
|
||||
amount = scrollAmountProperty.intValue();
|
||||
if (amount == -1) {
|
||||
type = MouseWheelEvent.WHEEL_BLOCK_SCROLL;
|
||||
amount = 1;
|
||||
}
|
||||
}
|
||||
return new MouseWheelEvent(src, event.getEventId(),
|
||||
event.getTime(), event.getInputModifiers(),
|
||||
where.x, where.y, 0, false, type, amount,
|
||||
event.getWheelRotation());
|
||||
}
|
||||
|
||||
// BEGIN android-changed: AWT components not supported
|
||||
// private void dispatchWheelEvent(Component src, NativeEvent event) {
|
||||
// PointerInfo info = findComponentUnderPointer();
|
||||
//
|
||||
// if (info.src == null) {
|
||||
// info.src = src;
|
||||
// info.position = event.getLocalPos();
|
||||
// }
|
||||
//
|
||||
// propagateEvent(info, AWTEvent.MOUSE_WHEEL_EVENT_MASK,
|
||||
// MouseWheelListener.class, true);
|
||||
// if ((info.src != null) && info.src.isIndirectlyEnabled()) {
|
||||
// toolkit.getSystemEventQueueImpl().postEvent(
|
||||
// createWheelEvent(info.src, event, info.position));
|
||||
// }
|
||||
// }
|
||||
// END android-changed
|
||||
|
||||
private PointerInfo propagateEvent(PointerInfo info, long mask,
|
||||
Class<? extends EventListener> type, boolean pierceHW) {
|
||||
Component src = info.src;
|
||||
while ((src != null) &&
|
||||
(src.isLightweight() || pierceHW) &&
|
||||
!(src.isMouseEventEnabled(mask) ||
|
||||
(src.getListeners(type).length > 0))) {
|
||||
|
||||
info.position.translate(src.x, src.y);
|
||||
// BEGIN android-changed: AWT components not supported
|
||||
// src = src.parent;
|
||||
// END android-changed
|
||||
info.src = src;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
// BEGIN android-changed: AWT components not supported
|
||||
// Window findWindowAt(Point p) {
|
||||
// NativeWindow nativeWindow =
|
||||
// toolkit.getWindowFactory().getWindowFromPoint(p);
|
||||
//
|
||||
// Window window = null;
|
||||
// if (nativeWindow != null) {
|
||||
// Component comp = toolkit.getComponentById(nativeWindow.getId());
|
||||
//
|
||||
// if (comp != null) {
|
||||
// window = comp.getWindowAncestor();
|
||||
// }
|
||||
// }
|
||||
// return window;
|
||||
// }
|
||||
// END android-changed
|
||||
|
||||
private class PointerInfo {
|
||||
|
||||
Component src;
|
||||
Point position;
|
||||
|
||||
PointerInfo(Component src, Point position) {
|
||||
this.src = src;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ColorModel;
|
||||
|
||||
/**
|
||||
* The Paint interface provides possibility of generating color patterns in
|
||||
* device space for fill, draw, or stroke operations in a Graphics2D.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface Paint extends Transparency {
|
||||
|
||||
/**
|
||||
* Creates the PaintContext which is used to generate color patterns for
|
||||
* rendering operations of Graphics2D.
|
||||
*
|
||||
* @param cm
|
||||
* the ColorModel object, or null.
|
||||
* @param deviceBounds
|
||||
* the Rectangle represents the bounding box of device space for
|
||||
* the graphics rendering operations.
|
||||
* @param userBounds
|
||||
* the Rectangle represents bounding box of user space for the
|
||||
* graphics rendering operations.
|
||||
* @param xform
|
||||
* the AffineTransform for translation from user space to device
|
||||
* space.
|
||||
* @param hints
|
||||
* the RenderingHints preferences.
|
||||
* @return the PaintContext for generating color patterns.
|
||||
*/
|
||||
PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds,
|
||||
AffineTransform xform, RenderingHints hints);
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.Raster;
|
||||
|
||||
/**
|
||||
* The PaintContext interface determines the specific environment for generating
|
||||
* color patterns in device space for fill, draw, or stroke rendering operations
|
||||
* using Graphics2D. This interface provides colors through the Raster object
|
||||
* associated with the specific ColorModel for Graphics2D rendering operations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface PaintContext {
|
||||
|
||||
/**
|
||||
* Releases the resources allocated for the operation.
|
||||
*/
|
||||
void dispose();
|
||||
|
||||
/**
|
||||
* Gets the color model.
|
||||
*
|
||||
* @return the ColorModel object.
|
||||
*/
|
||||
ColorModel getColorModel();
|
||||
|
||||
/**
|
||||
* Gets the Raster which defines the colors of the specified rectangular
|
||||
* area for Graphics2D rendering operations.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the device space area for which colors are
|
||||
* generated.
|
||||
* @param y
|
||||
* the Y coordinate of the device space area for which colors are
|
||||
* generated.
|
||||
* @param w
|
||||
* the width of the device space area for which colors are
|
||||
* generated.
|
||||
* @param h
|
||||
* the height of the device space area for which colors are
|
||||
* generated.
|
||||
* @return the Raster object which contains the colors of the specified
|
||||
* rectangular area for Graphics2D rendering operations.
|
||||
*/
|
||||
Raster getRaster(int x, int y, int w, int h);
|
||||
}
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Denis M. Kishenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The Point class represents a point location with coordinates X, Y in current
|
||||
* coordinate system.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class Point extends Point2D implements Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -5276940640259749850L;
|
||||
|
||||
/**
|
||||
* The X coordinate of Point.
|
||||
*/
|
||||
public int x;
|
||||
|
||||
/**
|
||||
* The Y coordinate of Point.
|
||||
*/
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* Instantiates a new point with (0, O) coordinates, the origin of
|
||||
* coordinate system.
|
||||
*/
|
||||
public Point() {
|
||||
setLocation(0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new point with (x, y) coordinates.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of Point.
|
||||
* @param y
|
||||
* the Y coordinate of Point.
|
||||
*/
|
||||
public Point(int x, int y) {
|
||||
setLocation(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new point, giving it the same location as the parameter p.
|
||||
*
|
||||
* @param p
|
||||
* the Point object giving the coordinates of the new point.
|
||||
*/
|
||||
public Point(Point p) {
|
||||
setLocation(p.x, p.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares current Point with the specified object.
|
||||
*
|
||||
* @param obj
|
||||
* the Object to be compared.
|
||||
* @return true, if the Object being compared is a Point whose coordinates
|
||||
* are equal to the coordinates of this Point, false otherwise.
|
||||
* @see java.awt.geom.Point2D#equals(Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof Point) {
|
||||
Point p = (Point)obj;
|
||||
return x == p.x && y == p.y;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns string representation of the current Point object.
|
||||
*
|
||||
* @return a string representation of the current Point object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getName() + "[x=" + x + ",y=" + y + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets X coordinate of Point as a double.
|
||||
*
|
||||
* @return X coordinate of the point as a double.
|
||||
* @see java.awt.geom.Point2D#getX()
|
||||
*/
|
||||
@Override
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets Y coordinate of Point as a double.
|
||||
*
|
||||
* @return Y coordinate of the point as a double.
|
||||
* @see java.awt.geom.Point2D#getY()
|
||||
*/
|
||||
@Override
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location of the Point as a new Point object.
|
||||
*
|
||||
* @return a copy of the Point.
|
||||
*/
|
||||
public Point getLocation() {
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of the Point to the same coordinates as p.
|
||||
*
|
||||
* @param p
|
||||
* the Point that gives the new location.
|
||||
*/
|
||||
public void setLocation(Point p) {
|
||||
setLocation(p.x, p.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of the Point to the coordinates X, Y.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the Point's new location.
|
||||
* @param y
|
||||
* the Y coordinate of the Point's new location.
|
||||
*/
|
||||
public void setLocation(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of Point to the specified double coordinates.
|
||||
*
|
||||
* @param x
|
||||
* the X the Point's new location.
|
||||
* @param y
|
||||
* the Y the Point's new location.
|
||||
* @see java.awt.geom.Point2D#setLocation(double, double)
|
||||
*/
|
||||
@Override
|
||||
public void setLocation(double x, double y) {
|
||||
x = x < Integer.MIN_VALUE ? Integer.MIN_VALUE : x > Integer.MAX_VALUE ? Integer.MAX_VALUE
|
||||
: x;
|
||||
y = y < Integer.MIN_VALUE ? Integer.MIN_VALUE : y > Integer.MAX_VALUE ? Integer.MAX_VALUE
|
||||
: y;
|
||||
setLocation((int)Math.round(x), (int)Math.round(y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the Point to the specified (x, y) location.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the new location.
|
||||
* @param y
|
||||
* the Y coordinate of the new location.
|
||||
*/
|
||||
public void move(int x, int y) {
|
||||
setLocation(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates current Point moving it from the position (x, y) to the new
|
||||
* position given by (x+dx, x+dy) coordinates.
|
||||
*
|
||||
* @param dx
|
||||
* the horizontal delta - the Point is moved to this distance
|
||||
* along X axis.
|
||||
* @param dy
|
||||
* the vertical delta - the Point is moved to this distance along
|
||||
* Y axis.
|
||||
*/
|
||||
public void translate(int dx, int dy) {
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,515 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Denis M. Kishenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.Serializable;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.apache.harmony.awt.gl.*;
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The Polygon class defines an closed area specified by n vertices and n edges.
|
||||
* The coordinates of the vertices are specified by x, y arrays. The edges are
|
||||
* the line segments from the point (x[i], y[i]) to the point (x[i+1], y[i+1]),
|
||||
* for -1 < i < (n-1) plus the line segment from the point (x[n-1], y[n-1]) to
|
||||
* the point (x[0], y[0]) point. The Polygon is empty if the number of vertices
|
||||
* is zero.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class Polygon implements Shape, Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -6460061437900069969L;
|
||||
|
||||
/**
|
||||
* The points buffer capacity.
|
||||
*/
|
||||
private static final int BUFFER_CAPACITY = 4;
|
||||
|
||||
/**
|
||||
* The number of Polygon vertices.
|
||||
*/
|
||||
public int npoints;
|
||||
|
||||
/**
|
||||
* The array of X coordinates of the vertices.
|
||||
*/
|
||||
public int[] xpoints;
|
||||
|
||||
/**
|
||||
* The array of Y coordinates of the vertices.
|
||||
*/
|
||||
public int[] ypoints;
|
||||
|
||||
/**
|
||||
* The smallest Rectangle that completely contains this Polygon.
|
||||
*/
|
||||
protected Rectangle bounds;
|
||||
|
||||
/*
|
||||
* Polygon path iterator
|
||||
*/
|
||||
/**
|
||||
* The internal Class Iterator.
|
||||
*/
|
||||
class Iterator implements PathIterator {
|
||||
|
||||
/**
|
||||
* The source Polygon object.
|
||||
*/
|
||||
public Polygon p;
|
||||
|
||||
/**
|
||||
* The path iterator transformation.
|
||||
*/
|
||||
public AffineTransform t;
|
||||
|
||||
/**
|
||||
* The current segment index.
|
||||
*/
|
||||
public int index;
|
||||
|
||||
/**
|
||||
* Constructs a new Polygon.Iterator for the given polygon and
|
||||
* transformation
|
||||
*
|
||||
* @param at
|
||||
* the AffineTransform object to apply rectangle path.
|
||||
* @param p
|
||||
* the p.
|
||||
*/
|
||||
public Iterator(AffineTransform at, Polygon p) {
|
||||
this.p = p;
|
||||
this.t = at;
|
||||
if (p.npoints == 0) {
|
||||
index = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public int getWindingRule() {
|
||||
return WIND_EVEN_ODD;
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return index > p.npoints;
|
||||
}
|
||||
|
||||
public void next() {
|
||||
index++;
|
||||
}
|
||||
|
||||
public int currentSegment(double[] coords) {
|
||||
if (isDone()) {
|
||||
// awt.110=Iterator out of bounds
|
||||
throw new NoSuchElementException(Messages.getString("awt.110")); //$NON-NLS-1$
|
||||
}
|
||||
if (index == p.npoints) {
|
||||
return SEG_CLOSE;
|
||||
}
|
||||
coords[0] = p.xpoints[index];
|
||||
coords[1] = p.ypoints[index];
|
||||
if (t != null) {
|
||||
t.transform(coords, 0, coords, 0, 1);
|
||||
}
|
||||
return index == 0 ? SEG_MOVETO : SEG_LINETO;
|
||||
}
|
||||
|
||||
public int currentSegment(float[] coords) {
|
||||
if (isDone()) {
|
||||
// awt.110=Iterator out of bounds
|
||||
throw new NoSuchElementException(Messages.getString("awt.110")); //$NON-NLS-1$
|
||||
}
|
||||
if (index == p.npoints) {
|
||||
return SEG_CLOSE;
|
||||
}
|
||||
coords[0] = p.xpoints[index];
|
||||
coords[1] = p.ypoints[index];
|
||||
if (t != null) {
|
||||
t.transform(coords, 0, coords, 0, 1);
|
||||
}
|
||||
return index == 0 ? SEG_MOVETO : SEG_LINETO;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new empty polygon.
|
||||
*/
|
||||
public Polygon() {
|
||||
xpoints = new int[BUFFER_CAPACITY];
|
||||
ypoints = new int[BUFFER_CAPACITY];
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new polygon with the specified number of vertices, and the
|
||||
* given arrays of x, y vertex coordinates. The length of each coordinate
|
||||
* array may not be less than the specified number of vertices but may be
|
||||
* greater. Only the first n elements are used from each coordinate array.
|
||||
*
|
||||
* @param xpoints
|
||||
* the array of X vertex coordinates.
|
||||
* @param ypoints
|
||||
* the array of Y vertex coordinates.
|
||||
* @param npoints
|
||||
* the number vertices of the polygon.
|
||||
* @throws IndexOutOfBoundsException
|
||||
* if the length of xpoints or ypoints is less than n.
|
||||
* @throws NegativeArraySizeException
|
||||
* if n is negative.
|
||||
*/
|
||||
public Polygon(int[] xpoints, int[] ypoints, int npoints) {
|
||||
if (npoints > xpoints.length || npoints > ypoints.length) {
|
||||
// awt.111=Parameter npoints is greater than array length
|
||||
throw new IndexOutOfBoundsException(Messages.getString("awt.111")); //$NON-NLS-1$
|
||||
}
|
||||
if (npoints < 0) {
|
||||
// awt.112=Negative number of points
|
||||
throw new NegativeArraySizeException(Messages.getString("awt.112")); //$NON-NLS-1$
|
||||
}
|
||||
this.npoints = npoints;
|
||||
this.xpoints = new int[npoints];
|
||||
this.ypoints = new int[npoints];
|
||||
System.arraycopy(xpoints, 0, this.xpoints, 0, npoints);
|
||||
System.arraycopy(ypoints, 0, this.ypoints, 0, npoints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the current Polygon to an empty Polygon. More precisely, the
|
||||
* number of Polygon vertices is set to zero, but x, y coordinates arrays
|
||||
* are not affected.
|
||||
*/
|
||||
public void reset() {
|
||||
npoints = 0;
|
||||
bounds = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidates the data that depends on the vertex coordinates. This method
|
||||
* should be called after direct manipulations of the x, y vertex
|
||||
* coordinates arrays to avoid unpredictable results of methods which rely
|
||||
* on the bounding box.
|
||||
*/
|
||||
public void invalidate() {
|
||||
bounds = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the point to the Polygon and updates the bounding box accordingly.
|
||||
*
|
||||
* @param px
|
||||
* the X coordinate of the added vertex.
|
||||
* @param py
|
||||
* the Y coordinate of the added vertex.
|
||||
*/
|
||||
public void addPoint(int px, int py) {
|
||||
if (npoints == xpoints.length) {
|
||||
int[] tmp;
|
||||
|
||||
tmp = new int[xpoints.length + BUFFER_CAPACITY];
|
||||
System.arraycopy(xpoints, 0, tmp, 0, xpoints.length);
|
||||
xpoints = tmp;
|
||||
|
||||
tmp = new int[ypoints.length + BUFFER_CAPACITY];
|
||||
System.arraycopy(ypoints, 0, tmp, 0, ypoints.length);
|
||||
ypoints = tmp;
|
||||
}
|
||||
|
||||
xpoints[npoints] = px;
|
||||
ypoints[npoints] = py;
|
||||
npoints++;
|
||||
|
||||
if (bounds != null) {
|
||||
bounds.setFrameFromDiagonal(Math.min(bounds.getMinX(), px), Math.min(bounds.getMinY(),
|
||||
py), Math.max(bounds.getMaxX(), px), Math.max(bounds.getMaxY(), py));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounding rectangle of the Polygon. The bounding rectangle is the
|
||||
* smallest rectangle which contains the Polygon.
|
||||
*
|
||||
* @return the bounding rectangle of the Polygon.
|
||||
* @see java.awt.Shape#getBounds()
|
||||
*/
|
||||
public Rectangle getBounds() {
|
||||
if (bounds != null) {
|
||||
return bounds;
|
||||
}
|
||||
if (npoints == 0) {
|
||||
return new Rectangle();
|
||||
}
|
||||
|
||||
int bx1 = xpoints[0];
|
||||
int by1 = ypoints[0];
|
||||
int bx2 = bx1;
|
||||
int by2 = by1;
|
||||
|
||||
for (int i = 1; i < npoints; i++) {
|
||||
int x = xpoints[i];
|
||||
int y = ypoints[i];
|
||||
if (x < bx1) {
|
||||
bx1 = x;
|
||||
} else if (x > bx2) {
|
||||
bx2 = x;
|
||||
}
|
||||
if (y < by1) {
|
||||
by1 = y;
|
||||
} else if (y > by2) {
|
||||
by2 = y;
|
||||
}
|
||||
}
|
||||
|
||||
return bounds = new Rectangle(bx1, by1, bx2 - bx1, by2 - by1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounding rectangle of the Polygon. The bounding rectangle is the
|
||||
* smallest rectangle which contains the Polygon.
|
||||
*
|
||||
* @return the bounding rectangle of the Polygon.
|
||||
* @deprecated Use getBounds() method.
|
||||
*/
|
||||
@Deprecated
|
||||
public Rectangle getBoundingBox() {
|
||||
return getBounds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Rectangle2D which represents Polygon bounds. The bounding
|
||||
* rectangle is the smallest rectangle which contains the Polygon.
|
||||
*
|
||||
* @return the bounding rectangle of the Polygon.
|
||||
* @see java.awt.Shape#getBounds2D()
|
||||
*/
|
||||
public Rectangle2D getBounds2D() {
|
||||
return getBounds().getBounds2D();
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates all vertices of Polygon the specified distances along X, Y
|
||||
* axis.
|
||||
*
|
||||
* @param mx
|
||||
* the distance to translate horizontally.
|
||||
* @param my
|
||||
* the distance to translate vertically.
|
||||
*/
|
||||
public void translate(int mx, int my) {
|
||||
for (int i = 0; i < npoints; i++) {
|
||||
xpoints[i] += mx;
|
||||
ypoints[i] += my;
|
||||
}
|
||||
if (bounds != null) {
|
||||
bounds.translate(mx, my);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the point given by the coordinates x, y lies inside
|
||||
* the Polygon.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the point to check.
|
||||
* @param y
|
||||
* the Y coordinate of the point to check.
|
||||
* @return true, if the specified point lies inside the Polygon, false
|
||||
* otherwise.
|
||||
* @deprecated Use contains(int, int) method.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean inside(int x, int y) {
|
||||
return contains((double)x, (double)y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the point given by the coordinates x, y lies inside
|
||||
* the Polygon.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the point to check.
|
||||
* @param y
|
||||
* the Y coordinate of the point to check.
|
||||
* @return true, if the specified point lies inside the Polygon, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean contains(int x, int y) {
|
||||
return contains((double)x, (double)y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the point with specified double coordinates lies
|
||||
* inside the Polygon.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the point to check.
|
||||
* @param y
|
||||
* the Y coordinate of the point to check.
|
||||
* @return true, if the point given by the double coordinates lies inside
|
||||
* the Polygon, false otherwise.
|
||||
* @see java.awt.Shape#contains(double, double)
|
||||
*/
|
||||
public boolean contains(double x, double y) {
|
||||
return Crossing.isInsideEvenOdd(Crossing.crossShape(this, x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the rectangle determined by the parameters [x, y,
|
||||
* width, height] lies inside the Polygon.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangles's left upper corner as a
|
||||
* double.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangles's left upper corner as a
|
||||
* double.
|
||||
* @param width
|
||||
* the width of rectangle as a double.
|
||||
* @param height
|
||||
* the height of rectangle as a double.
|
||||
* @return true, if the specified rectangle lies inside the Polygon, false
|
||||
* otherwise.
|
||||
* @see java.awt.Shape#contains(double, double, double, double)
|
||||
*/
|
||||
public boolean contains(double x, double y, double width, double height) {
|
||||
int cross = Crossing.intersectShape(this, x, y, width, height);
|
||||
return cross != Crossing.CROSSING && Crossing.isInsideEvenOdd(cross);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the rectangle determined by the parameters [x, y,
|
||||
* width, height] intersects the interior of the Polygon.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangles's left upper corner as a
|
||||
* double.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangles's left upper corner as a
|
||||
* double.
|
||||
* @param width
|
||||
* the width of rectangle as a double.
|
||||
* @param height
|
||||
* the height of rectangle as a double.
|
||||
* @return true, if the specified rectangle intersects the interior of the
|
||||
* Polygon, false otherwise.
|
||||
* @see java.awt.Shape#intersects(double, double, double, double)
|
||||
*/
|
||||
public boolean intersects(double x, double y, double width, double height) {
|
||||
int cross = Crossing.intersectShape(this, x, y, width, height);
|
||||
return cross == Crossing.CROSSING || Crossing.isInsideEvenOdd(cross);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the specified rectangle lies inside the Polygon.
|
||||
*
|
||||
* @param rect
|
||||
* the Rectangle2D object.
|
||||
* @return true, if the specified rectangle lies inside the Polygon, false
|
||||
* otherwise.
|
||||
* @see java.awt.Shape#contains(java.awt.geom.Rectangle2D)
|
||||
*/
|
||||
public boolean contains(Rectangle2D rect) {
|
||||
return contains(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the specified Point lies inside the Polygon.
|
||||
*
|
||||
* @param point
|
||||
* the Point object.
|
||||
* @return true, if the specified Point lies inside the Polygon, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean contains(Point point) {
|
||||
return contains(point.getX(), point.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the specified Point2D lies inside the Polygon.
|
||||
*
|
||||
* @param point
|
||||
* the Point2D object.
|
||||
* @return true, if the specified Point2D lies inside the Polygon, false
|
||||
* otherwise.
|
||||
* @see java.awt.Shape#contains(java.awt.geom.Point2D)
|
||||
*/
|
||||
public boolean contains(Point2D point) {
|
||||
return contains(point.getX(), point.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the interior of rectangle specified by the
|
||||
* Rectangle2D object intersects the interior of the Polygon.
|
||||
*
|
||||
* @param rect
|
||||
* the Rectangle2D object.
|
||||
* @return true, if the Rectangle2D intersects the interior of the Polygon,
|
||||
* false otherwise.
|
||||
* @see java.awt.Shape#intersects(java.awt.geom.Rectangle2D)
|
||||
*/
|
||||
public boolean intersects(Rectangle2D rect) {
|
||||
return intersects(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PathIterator object which gives the coordinates of the polygon,
|
||||
* transformed according to the specified AffineTransform.
|
||||
*
|
||||
* @param t
|
||||
* the specified AffineTransform object or null.
|
||||
* @return PathIterator object for the Polygon.
|
||||
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform)
|
||||
*/
|
||||
public PathIterator getPathIterator(AffineTransform t) {
|
||||
return new Iterator(t, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PathIterator object which gives the coordinates of the polygon,
|
||||
* transformed according to the specified AffineTransform. The flatness
|
||||
* parameter is ignored.
|
||||
*
|
||||
* @param t
|
||||
* the specified AffineTransform object or null.
|
||||
* @param flatness
|
||||
* the maximum number of the control points for a given curve
|
||||
* which varies from colinear before a subdivided curve is
|
||||
* replaced by a straight line connecting the endpoints. This
|
||||
* parameter is ignored for the Polygon class.
|
||||
* @return PathIterator object for the Polygon.
|
||||
* @see java.awt.Shape#getPathIterator(java.awt.geom.AffineTransform,
|
||||
* double)
|
||||
*/
|
||||
public PathIterator getPathIterator(AffineTransform t, double flatness) {
|
||||
return new Iterator(t, this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,723 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Denis M. Kishenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The Rectangle class defines the rectangular area in terms of its upper left
|
||||
* corner coordinates [x,y], its width, and its height. A Rectangle specified by
|
||||
* [x, y, width, height] parameters has an outline path with corners at [x, y],
|
||||
* [x + width,y], [x + width,y + height], and [x, y + height]. <br>
|
||||
* <br>
|
||||
* The rectangle is empty if the width or height is negative or zero. In this
|
||||
* case the isEmpty method returns true.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class Rectangle extends Rectangle2D implements Shape, Serializable {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -4345857070255674764L;
|
||||
|
||||
/**
|
||||
* The X coordinate of the rectangle's left upper corner.
|
||||
*/
|
||||
public int x;
|
||||
|
||||
/**
|
||||
* The Y coordinate of the rectangle's left upper corner.
|
||||
*/
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* The width of rectangle.
|
||||
*/
|
||||
public int width;
|
||||
|
||||
/**
|
||||
* The height of rectangle.
|
||||
*/
|
||||
public int height;
|
||||
|
||||
/**
|
||||
* Instantiates a new rectangle with [0, 0] upper left corner coordinates,
|
||||
* the width and the height are zero.
|
||||
*/
|
||||
public Rectangle() {
|
||||
setBounds(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new rectangle whose upper left corner coordinates are
|
||||
* given by the Point object (p.X and p.Y), and the width and the height are
|
||||
* zero.
|
||||
*
|
||||
* @param p
|
||||
* the Point specifies the upper left corner coordinates of the
|
||||
* rectangle.
|
||||
*/
|
||||
public Rectangle(Point p) {
|
||||
setBounds(p.x, p.y, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new rectangle whose upper left corner coordinates are
|
||||
* given by the Point object (p.X and p.Y), and the width and the height are
|
||||
* given by Dimension object (d.width and d.height).
|
||||
*
|
||||
* @param p
|
||||
* the point specifies the upper left corner coordinates of the
|
||||
* rectangle.
|
||||
* @param d
|
||||
* the dimension specifies the width and the height of the
|
||||
* rectangle.
|
||||
*/
|
||||
public Rectangle(Point p, Dimension d) {
|
||||
setBounds(p.x, p.y, d.width, d.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new rectangle determined by the upper left corner
|
||||
* coordinates (x, y), width and height.
|
||||
*
|
||||
* @param x
|
||||
* the X upper left corner coordinate of the rectangle.
|
||||
* @param y
|
||||
* the Y upper left corner coordinate of the rectangle.
|
||||
* @param width
|
||||
* the width of rectangle.
|
||||
* @param height
|
||||
* the height of rectangle.
|
||||
*/
|
||||
public Rectangle(int x, int y, int width, int height) {
|
||||
setBounds(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new rectangle with [0, 0] as its upper left corner
|
||||
* coordinates and the specified width and height.
|
||||
*
|
||||
* @param width
|
||||
* the width of rectangle.
|
||||
* @param height
|
||||
* the height of rectangle.
|
||||
*/
|
||||
public Rectangle(int width, int height) {
|
||||
setBounds(0, 0, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new rectangle with the same coordinates as the given
|
||||
* source rectangle.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle object which parameters will be used for
|
||||
* instantiating a new Rectangle.
|
||||
*/
|
||||
public Rectangle(Rectangle r) {
|
||||
setBounds(r.x, r.y, r.width, r.height);
|
||||
}
|
||||
|
||||
/*
|
||||
* public Rectangle(Dimension d) { setBounds(0, 0, d.width, d.height); }
|
||||
*/
|
||||
/**
|
||||
* Gets the X coordinate of bound as a double.
|
||||
*
|
||||
* @return the X coordinate of bound as a double.
|
||||
* @see java.awt.geom.RectangularShape#getX()
|
||||
*/
|
||||
@Override
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Y coordinate of bound as a double.
|
||||
*
|
||||
* @return the Y coordinate of bound as a double.
|
||||
* @see java.awt.geom.RectangularShape#getY()
|
||||
*/
|
||||
@Override
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height of the rectangle as a double.
|
||||
*
|
||||
* @return the height of the rectangle as a double.
|
||||
* @see java.awt.geom.RectangularShape#getHeight()
|
||||
*/
|
||||
@Override
|
||||
public double getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of the rectangle as a double.
|
||||
*
|
||||
* @return the width of the rectangle as a double.
|
||||
* @see java.awt.geom.RectangularShape#getWidth()
|
||||
*/
|
||||
@Override
|
||||
public double getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not the rectangle is empty. The rectangle is empty
|
||||
* if its width or height is negative or zero.
|
||||
*
|
||||
* @return true, if the rectangle is empty, otherwise false.
|
||||
* @see java.awt.geom.RectangularShape#isEmpty()
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return width <= 0 || height <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of a Rectangle as Dimension object.
|
||||
*
|
||||
* @return a Dimension object which represents size of the rectangle.
|
||||
*/
|
||||
public Dimension getSize() {
|
||||
return new Dimension(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of the Rectangle.
|
||||
*
|
||||
* @param width
|
||||
* the new width of the rectangle.
|
||||
* @param height
|
||||
* the new height of the rectangle.
|
||||
*/
|
||||
public void setSize(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of a Rectangle specified as Dimension object.
|
||||
*
|
||||
* @param d
|
||||
* a Dimension object which represents new size of a rectangle.
|
||||
*/
|
||||
public void setSize(Dimension d) {
|
||||
setSize(d.width, d.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the location of a rectangle's upper left corner as a Point object.
|
||||
*
|
||||
* @return the Point object with coordinates equal to the upper left corner
|
||||
* of the rectangle.
|
||||
*/
|
||||
public Point getLocation() {
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of the rectangle in terms of its upper left corner
|
||||
* coordinates X and Y.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the rectangle's upper left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the rectangle's upper left corner.
|
||||
*/
|
||||
public void setLocation(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the location of a rectangle using a Point object to give the
|
||||
* coordinates of the upper left corner.
|
||||
*
|
||||
* @param p
|
||||
* the Point object which represents the new upper left corner
|
||||
* coordinates of rectangle.
|
||||
*/
|
||||
public void setLocation(Point p) {
|
||||
setLocation(p.x, p.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a rectangle to the new location by moving its upper left corner to
|
||||
* the point with coordinates X and Y.
|
||||
*
|
||||
* @param x
|
||||
* the new X coordinate of the rectangle's upper left corner.
|
||||
* @param y
|
||||
* the new Y coordinate of the rectangle's upper left corner.
|
||||
* @deprecated Use setLocation(int, int) method.
|
||||
*/
|
||||
@Deprecated
|
||||
public void move(int x, int y) {
|
||||
setLocation(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the rectangle to be the nearest rectangle with integer coordinates
|
||||
* bounding the rectangle defined by the double-valued parameters.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the upper left corner of the double-valued
|
||||
* rectangle to be bounded.
|
||||
* @param y
|
||||
* the Y coordinate of the upper left corner of the double-valued
|
||||
* rectangle to be bounded.
|
||||
* @param width
|
||||
* the width of the rectangle to be bounded.
|
||||
* @param height
|
||||
* the height of the rectangle to be bounded.
|
||||
* @see java.awt.geom.Rectangle2D#setRect(double, double, double, double)
|
||||
*/
|
||||
@Override
|
||||
public void setRect(double x, double y, double width, double height) {
|
||||
int x1 = (int)Math.floor(x);
|
||||
int y1 = (int)Math.floor(y);
|
||||
int x2 = (int)Math.ceil(x + width);
|
||||
int y2 = (int)Math.ceil(y + height);
|
||||
setBounds(x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new size for the rectangle.
|
||||
*
|
||||
* @param width
|
||||
* the rectangle's new width.
|
||||
* @param height
|
||||
* the rectangle's new height.
|
||||
* @deprecated use the setSize(int, int) method.
|
||||
*/
|
||||
@Deprecated
|
||||
public void resize(int width, int height) {
|
||||
setBounds(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the bounds of a rectangle to the specified x, y, width and height
|
||||
* parameters.
|
||||
*
|
||||
* @param x
|
||||
* the new X coordinate of the upper left corner.
|
||||
* @param y
|
||||
* the new Y coordinate of the upper left corner.
|
||||
* @param width
|
||||
* the new width of rectangle.
|
||||
* @param height
|
||||
* the new height of rectangle.
|
||||
* @deprecated use setBounds(int, int, int, int) method
|
||||
*/
|
||||
@Deprecated
|
||||
public void reshape(int x, int y, int width, int height) {
|
||||
setBounds(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets bounds of the rectangle as a new Rectangle object.
|
||||
*
|
||||
* @return the Rectangle object with the same bounds as the original
|
||||
* rectangle.
|
||||
* @see java.awt.geom.RectangularShape#getBounds()
|
||||
*/
|
||||
@Override
|
||||
public Rectangle getBounds() {
|
||||
return new Rectangle(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bounds of the original rectangle as a Rectangle2D object.
|
||||
*
|
||||
* @return the Rectangle2D object which represents the bounds of the
|
||||
* original rectangle.
|
||||
* @see java.awt.geom.Rectangle2D#getBounds2D()
|
||||
*/
|
||||
@Override
|
||||
public Rectangle2D getBounds2D() {
|
||||
return getBounds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bounds of a rectangle to the specified x, y, width, and height
|
||||
* parameters.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate of the upper left corner.
|
||||
* @param y
|
||||
* the Y coordinate of the upper left corner.
|
||||
* @param width
|
||||
* the width of rectangle.
|
||||
* @param height
|
||||
* the height of rectangle.
|
||||
*/
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bounds of the rectangle to match the bounds of the Rectangle
|
||||
* object sent as a parameter.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle object which specifies the new bounds.
|
||||
*/
|
||||
public void setBounds(Rectangle r) {
|
||||
setBounds(r.x, r.y, r.width, r.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlarges the rectangle by moving each corner outward from the center by a
|
||||
* distance of dx horizonally and a distance of dy vertically. Specifically,
|
||||
* changes a rectangle with [x, y, width, height] parameters to a rectangle
|
||||
* with [x-dx, y-dy, width+2*dx, height+2*dy] parameters.
|
||||
*
|
||||
* @param dx
|
||||
* the horizontal distance to move each corner coordinate.
|
||||
* @param dy
|
||||
* the vertical distance to move each corner coordinate.
|
||||
*/
|
||||
public void grow(int dx, int dy) {
|
||||
x -= dx;
|
||||
y -= dy;
|
||||
width += dx + dx;
|
||||
height += dy + dy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves a rectangle a distance of mx along the x coordinate axis and a
|
||||
* distance of my along y coordinate axis.
|
||||
*
|
||||
* @param mx
|
||||
* the horizontal translation increment.
|
||||
* @param my
|
||||
* the vertical translation increment.
|
||||
*/
|
||||
public void translate(int mx, int my) {
|
||||
x += mx;
|
||||
y += my;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlarges the rectangle to cover the specified point.
|
||||
*
|
||||
* @param px
|
||||
* the X coordinate of the new point to be covered by the
|
||||
* rectangle.
|
||||
* @param py
|
||||
* the Y coordinate of the new point to be covered by the
|
||||
* rectangle.
|
||||
*/
|
||||
public void add(int px, int py) {
|
||||
int x1 = Math.min(x, px);
|
||||
int x2 = Math.max(x + width, px);
|
||||
int y1 = Math.min(y, py);
|
||||
int y2 = Math.max(y + height, py);
|
||||
setBounds(x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlarges the rectangle to cover the specified point with the new point
|
||||
* given as a Point object.
|
||||
*
|
||||
* @param p
|
||||
* the Point object that specifies the new point to be covered by
|
||||
* the rectangle.
|
||||
*/
|
||||
public void add(Point p) {
|
||||
add(p.x, p.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new rectangle to the original rectangle, the result is an union of
|
||||
* the specified specified rectangle and original rectangle.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle which is added to the original rectangle.
|
||||
*/
|
||||
public void add(Rectangle r) {
|
||||
int x1 = Math.min(x, r.x);
|
||||
int x2 = Math.max(x + width, r.x + r.width);
|
||||
int y1 = Math.min(y, r.y);
|
||||
int y2 = Math.max(y + height, r.y + r.height);
|
||||
setBounds(x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not the point with specified coordinates [px, py]
|
||||
* is within the bounds of the rectangle.
|
||||
*
|
||||
* @param px
|
||||
* the X coordinate of point.
|
||||
* @param py
|
||||
* the Y coordinate of point.
|
||||
* @return true, if the point with specified coordinates [px, py] is within
|
||||
* the bounds of the rectangle, false otherwise.
|
||||
*/
|
||||
public boolean contains(int px, int py) {
|
||||
if (isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (px < x || py < y) {
|
||||
return false;
|
||||
}
|
||||
px -= x;
|
||||
py -= y;
|
||||
return px < width && py < height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not the point given as a Point object is within the
|
||||
* bounds of the rectangle.
|
||||
*
|
||||
* @param p
|
||||
* the Point object
|
||||
* @return true, if the point p is within the bounds of the rectangle,
|
||||
* otherwise false.
|
||||
*/
|
||||
public boolean contains(Point p) {
|
||||
return contains(p.x, p.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not the rectangle specified by [rx, ry, rw, rh]
|
||||
* parameters is located inside the original rectangle.
|
||||
*
|
||||
* @param rx
|
||||
* the X coordinate of the rectangle to compare.
|
||||
* @param ry
|
||||
* the Y coordinate of the rectangle to compare.
|
||||
* @param rw
|
||||
* the width of the rectangle to compare.
|
||||
* @param rh
|
||||
* the height of the rectangle to compare.
|
||||
* @return true, if a rectangle with [rx, ry, rw, rh] parameters is entirely
|
||||
* contained in the original rectangle, false otherwise.
|
||||
*/
|
||||
public boolean contains(int rx, int ry, int rw, int rh) {
|
||||
return contains(rx, ry) && contains(rx + rw - 1, ry + rh - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares whether or not the rectangle specified by the Rectangle object
|
||||
* is located inside the original rectangle.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle object.
|
||||
* @return true, if the rectangle specified by Rectangle object is entirely
|
||||
* contained in the original rectangle, false otherwise.
|
||||
*/
|
||||
public boolean contains(Rectangle r) {
|
||||
return contains(r.x, r.y, r.width, r.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares whether or not a point with specified coordinates [px, py]
|
||||
* belongs to a rectangle.
|
||||
*
|
||||
* @param px
|
||||
* the X coordinate of a point.
|
||||
* @param py
|
||||
* the Y coordinate of a point.
|
||||
* @return true, if a point with specified coordinates [px, py] belongs to a
|
||||
* rectangle, otherwise false.
|
||||
* @deprecated use contains(int, int) method.
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean inside(int px, int py) {
|
||||
return contains(px, py);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the intersection of the original rectangle with the specified
|
||||
* Rectangle2D.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle2D object.
|
||||
* @return the Rectangle2D object that is the result of intersecting the
|
||||
* original rectangle with the specified Rectangle2D.
|
||||
* @see java.awt.geom.Rectangle2D#createIntersection(java.awt.geom.Rectangle2D)
|
||||
*/
|
||||
@Override
|
||||
public Rectangle2D createIntersection(Rectangle2D r) {
|
||||
if (r instanceof Rectangle) {
|
||||
return intersection((Rectangle)r);
|
||||
}
|
||||
Rectangle2D dst = new Rectangle2D.Double();
|
||||
Rectangle2D.intersect(this, r, dst);
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the intersection of the original rectangle with the specified
|
||||
* rectangle. An empty rectangle is returned if there is no intersection.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle object.
|
||||
* @return the Rectangle object is result of the original rectangle with the
|
||||
* specified rectangle.
|
||||
*/
|
||||
public Rectangle intersection(Rectangle r) {
|
||||
int x1 = Math.max(x, r.x);
|
||||
int y1 = Math.max(y, r.y);
|
||||
int x2 = Math.min(x + width, r.x + r.width);
|
||||
int y2 = Math.min(y + height, r.y + r.height);
|
||||
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not the original rectangle intersects the specified
|
||||
* rectangle.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle object.
|
||||
* @return true, if the two rectangles overlap, false otherwise.
|
||||
*/
|
||||
public boolean intersects(Rectangle r) {
|
||||
return !intersection(r).isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines where the specified Point is located with respect to the
|
||||
* rectangle. This method computes whether the point is to the right or to
|
||||
* the left of the rectangle and whether it is above or below the rectangle,
|
||||
* and packs the result into an integer by using a binary OR operation with
|
||||
* the following masks:
|
||||
* <ul>
|
||||
*<li>Rectangle2D.OUT_LEFT</li>
|
||||
*<li>Rectangle2D.OUT_TOP</li>
|
||||
*<li>Rectangle2D.OUT_RIGHT</li>
|
||||
*<li>Rectangle2D.OUT_BOTTOM</li>
|
||||
*</ul>
|
||||
* If the rectangle is empty, all masks are set, and if the point is inside
|
||||
* the rectangle, none are set.
|
||||
*
|
||||
* @param px
|
||||
* the X coordinate of the specified point.
|
||||
* @param py
|
||||
* the Y coordinate of the specified point.
|
||||
* @return the location of the Point relative to the rectangle as the result
|
||||
* of logical OR operation with all out masks.
|
||||
* @see java.awt.geom.Rectangle2D#outcode(double, double)
|
||||
*/
|
||||
@Override
|
||||
public int outcode(double px, double py) {
|
||||
int code = 0;
|
||||
|
||||
if (width <= 0) {
|
||||
code |= OUT_LEFT | OUT_RIGHT;
|
||||
} else if (px < x) {
|
||||
code |= OUT_LEFT;
|
||||
} else if (px > x + width) {
|
||||
code |= OUT_RIGHT;
|
||||
}
|
||||
|
||||
if (height <= 0) {
|
||||
code |= OUT_TOP | OUT_BOTTOM;
|
||||
} else if (py < y) {
|
||||
code |= OUT_TOP;
|
||||
} else if (py > y + height) {
|
||||
code |= OUT_BOTTOM;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlarges the rectangle to cover the specified Rectangle2D.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle2D object.
|
||||
* @return the union of the original and the specified Rectangle2D.
|
||||
* @see java.awt.geom.Rectangle2D#createUnion(java.awt.geom.Rectangle2D)
|
||||
*/
|
||||
@Override
|
||||
public Rectangle2D createUnion(Rectangle2D r) {
|
||||
if (r instanceof Rectangle) {
|
||||
return union((Rectangle)r);
|
||||
}
|
||||
Rectangle2D dst = new Rectangle2D.Double();
|
||||
Rectangle2D.union(this, r, dst);
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlarges the rectangle to cover the specified rectangle.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle.
|
||||
* @return the union of the original and the specified rectangle.
|
||||
*/
|
||||
public Rectangle union(Rectangle r) {
|
||||
Rectangle dst = new Rectangle(this);
|
||||
dst.add(r);
|
||||
return dst;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the original Rectangle with the specified object.
|
||||
*
|
||||
* @param obj
|
||||
* the specified Object for comparison.
|
||||
* @return true, if the specified Object is a rectangle with the same
|
||||
* dimensions as the original rectangle, false otherwise.
|
||||
* @see java.awt.geom.Rectangle2D#equals(Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof Rectangle) {
|
||||
Rectangle r = (Rectangle)obj;
|
||||
return r.x == x && r.y == y && r.width == width && r.height == height;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the rectangle; the string contains [x,
|
||||
* y, width, height] parameters of the rectangle.
|
||||
*
|
||||
* @return the string representation of the rectangle.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// The output format based on 1.5 release behaviour. It could be
|
||||
// obtained in the following way
|
||||
// System.out.println(new Rectangle().toString())
|
||||
return getClass().getName() + "[x=" + x + ",y=" + y + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
",width=" + width + ",height=" + height + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,606 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The RenderingHints class represents preferences for the rendering algorithms.
|
||||
* The preferences are arbitrary and can be specified by Map objects or by
|
||||
* key-value pairs.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class RenderingHints implements Map<Object, Object>, Cloneable {
|
||||
|
||||
/**
|
||||
* The Constant KEY_ALPHA_INTERPOLATION - alpha interpolation rendering hint
|
||||
* key.
|
||||
*/
|
||||
public static final Key KEY_ALPHA_INTERPOLATION = new KeyImpl(1);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_ALPHA_INTERPOLATION_DEFAULT - alpha interpolation
|
||||
* rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT = new KeyValue(
|
||||
KEY_ALPHA_INTERPOLATION);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_ALPHA_INTERPOLATION_SPEED - alpha interpolation
|
||||
* rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_ALPHA_INTERPOLATION_SPEED = new KeyValue(
|
||||
KEY_ALPHA_INTERPOLATION);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_ALPHA_INTERPOLATION_QUALITY - alpha interpolation
|
||||
* rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY = new KeyValue(
|
||||
KEY_ALPHA_INTERPOLATION);
|
||||
|
||||
/**
|
||||
* The Constant KEY_ANTIALIASING - antialiasing rendering hint key.
|
||||
*/
|
||||
public static final Key KEY_ANTIALIASING = new KeyImpl(2);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_ANTIALIAS_DEFAULT - antialiasing rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_ANTIALIAS_DEFAULT = new KeyValue(KEY_ANTIALIASING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_ANTIALIAS_ON - antialiasing rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_ANTIALIAS_ON = new KeyValue(KEY_ANTIALIASING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_ANTIALIAS_OFF - antialiasing rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_ANTIALIAS_OFF = new KeyValue(KEY_ANTIALIASING);
|
||||
|
||||
/**
|
||||
* The Constant KEY_COLOR_RENDERING - color rendering hint key.
|
||||
*/
|
||||
public static final Key KEY_COLOR_RENDERING = new KeyImpl(3);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_COLOR_RENDER_DEFAULT - color rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_COLOR_RENDER_DEFAULT = new KeyValue(KEY_COLOR_RENDERING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_COLOR_RENDER_SPEED - color rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_COLOR_RENDER_SPEED = new KeyValue(KEY_COLOR_RENDERING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_COLOR_RENDER_QUALITY - color rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_COLOR_RENDER_QUALITY = new KeyValue(KEY_COLOR_RENDERING);
|
||||
|
||||
/**
|
||||
* The Constant KEY_DITHERING - dithering rendering hint key.
|
||||
*/
|
||||
public static final Key KEY_DITHERING = new KeyImpl(4);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_DITHER_DEFAULT - dithering rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_DITHER_DEFAULT = new KeyValue(KEY_DITHERING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_DITHER_DISABLE - dithering rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_DITHER_DISABLE = new KeyValue(KEY_DITHERING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_DITHER_DISABLE - dithering rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_DITHER_ENABLE = new KeyValue(KEY_DITHERING);
|
||||
|
||||
/**
|
||||
* The Constant KEY_FRACTIONALMETRICS - fractional metrics rendering hint
|
||||
* key.
|
||||
*/
|
||||
public static final Key KEY_FRACTIONALMETRICS = new KeyImpl(5);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_FRACTIONALMETRICS_DEFAULT - fractional metrics
|
||||
* rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_FRACTIONALMETRICS_DEFAULT = new KeyValue(KEY_FRACTIONALMETRICS);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_FRACTIONALMETRICS_ON - fractional metrics rendering
|
||||
* hint value.
|
||||
*/
|
||||
public static final Object VALUE_FRACTIONALMETRICS_ON = new KeyValue(KEY_FRACTIONALMETRICS);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_FRACTIONALMETRICS_OFF - fractional metrics rendering
|
||||
* hint value.
|
||||
*/
|
||||
public static final Object VALUE_FRACTIONALMETRICS_OFF = new KeyValue(KEY_FRACTIONALMETRICS);
|
||||
|
||||
/**
|
||||
* The Constant KEY_INTERPOLATION - interpolation rendering hint key.
|
||||
*/
|
||||
public static final Key KEY_INTERPOLATION = new KeyImpl(6);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_INTERPOLATION_BICUBIC - interpolation rendering hint
|
||||
* value.
|
||||
*/
|
||||
public static final Object VALUE_INTERPOLATION_BICUBIC = new KeyValue(KEY_INTERPOLATION);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_INTERPOLATION_BILINEAR - interpolation rendering hint
|
||||
* value.
|
||||
*/
|
||||
public static final Object VALUE_INTERPOLATION_BILINEAR = new KeyValue(KEY_INTERPOLATION);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_INTERPOLATION_NEAREST_NEIGHBOR - interpolation
|
||||
* rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR = new KeyValue(
|
||||
KEY_INTERPOLATION);
|
||||
|
||||
/**
|
||||
* The Constant KEY_RENDERING - rendering hint key.
|
||||
*/
|
||||
public static final Key KEY_RENDERING = new KeyImpl(7);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_RENDER_DEFAULT - rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_RENDER_DEFAULT = new KeyValue(KEY_RENDERING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_RENDER_SPEED - rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_RENDER_SPEED = new KeyValue(KEY_RENDERING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_RENDER_QUALITY - rendering hint value.
|
||||
*/
|
||||
public static final Object VALUE_RENDER_QUALITY = new KeyValue(KEY_RENDERING);
|
||||
|
||||
/**
|
||||
* The Constant KEY_STROKE_CONTROL - stroke control hint key.
|
||||
*/
|
||||
public static final Key KEY_STROKE_CONTROL = new KeyImpl(8);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_STROKE_DEFAULT - stroke hint value.
|
||||
*/
|
||||
public static final Object VALUE_STROKE_DEFAULT = new KeyValue(KEY_STROKE_CONTROL);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_STROKE_NORMALIZE - stroke hint value.
|
||||
*/
|
||||
public static final Object VALUE_STROKE_NORMALIZE = new KeyValue(KEY_STROKE_CONTROL);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_STROKE_PURE - stroke hint value.
|
||||
*/
|
||||
public static final Object VALUE_STROKE_PURE = new KeyValue(KEY_STROKE_CONTROL);
|
||||
|
||||
/**
|
||||
* The Constant KEY_TEXT_ANTIALIASING - text antialiasing hint key.
|
||||
*/
|
||||
public static final Key KEY_TEXT_ANTIALIASING = new KeyImpl(9);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_TEXT_ANTIALIAS_DEFAULT - text antialiasing hint key.
|
||||
*/
|
||||
public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT = new KeyValue(KEY_TEXT_ANTIALIASING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_TEXT_ANTIALIAS_ON - text antialiasing hint key.
|
||||
*/
|
||||
public static final Object VALUE_TEXT_ANTIALIAS_ON = new KeyValue(KEY_TEXT_ANTIALIASING);
|
||||
|
||||
/**
|
||||
* The Constant VALUE_TEXT_ANTIALIAS_OFF - text antialiasing hint key.
|
||||
*/
|
||||
public static final Object VALUE_TEXT_ANTIALIAS_OFF = new KeyValue(KEY_TEXT_ANTIALIASING);
|
||||
|
||||
/** The map. */
|
||||
private HashMap<Object, Object> map = new HashMap<Object, Object>();
|
||||
|
||||
/**
|
||||
* Instantiates a new rendering hints object from specified Map object with
|
||||
* defined key/value pairs or null for empty RenderingHints.
|
||||
*
|
||||
* @param map
|
||||
* the Map object with defined key/value pairs or null for empty
|
||||
* RenderingHints.
|
||||
*/
|
||||
public RenderingHints(Map<Key, ?> map) {
|
||||
super();
|
||||
if (map != null) {
|
||||
putAll(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new rendering hints object with the specified key/value
|
||||
* pair.
|
||||
*
|
||||
* @param key
|
||||
* the key of hint property.
|
||||
* @param value
|
||||
* the value of hint property.
|
||||
*/
|
||||
public RenderingHints(Key key, Object value) {
|
||||
super();
|
||||
put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the properties represented by key/value pairs from the specified
|
||||
* RenderingHints object to current object.
|
||||
*
|
||||
* @param hints
|
||||
* the RenderingHints to be added.
|
||||
*/
|
||||
public void add(RenderingHints hints) {
|
||||
map.putAll(hints.map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts the specified value to the specified key. Neither the key nor the
|
||||
* value can be null.
|
||||
*
|
||||
* @param key
|
||||
* the rendering hint key.
|
||||
* @param value
|
||||
* the rendering hint value.
|
||||
* @return the previous rendering hint value assigned to the key or null.
|
||||
*/
|
||||
public Object put(Object key, Object value) {
|
||||
if (!((Key)key).isCompatibleValue(value)) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
return map.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified key and corresponding value from the RenderingHints
|
||||
* object.
|
||||
*
|
||||
* @param key
|
||||
* the specified hint key to be removed.
|
||||
* @return the object of previous rendering hint value which is assigned to
|
||||
* the specified key, or null.
|
||||
*/
|
||||
public Object remove(Object key) {
|
||||
return map.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value assigned to the specified key.
|
||||
*
|
||||
* @param key
|
||||
* the rendering hint key.
|
||||
* @return the object assigned to the specified key.
|
||||
*/
|
||||
public Object get(Object key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of rendering hints keys for current RenderingHints object.
|
||||
*
|
||||
* @return the set of rendering hints keys.
|
||||
*/
|
||||
public Set<Object> keySet() {
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of Map.Entry objects which contain current RenderingHint
|
||||
* key/value pairs.
|
||||
*
|
||||
* @return the a set of mapped RenderingHint key/value pairs.
|
||||
*/
|
||||
public Set<Map.Entry<Object, Object>> entrySet() {
|
||||
return map.entrySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts all of the preferences from the specified Map into the current
|
||||
* RenderingHints object. These mappings replace all existing preferences.
|
||||
*
|
||||
* @param m
|
||||
* the specified Map of preferences.
|
||||
*/
|
||||
public void putAll(Map<?, ?> m) {
|
||||
if (m instanceof RenderingHints) {
|
||||
map.putAll(((RenderingHints)m).map);
|
||||
} else {
|
||||
Set<?> entries = m.entrySet();
|
||||
|
||||
if (entries != null) {
|
||||
Iterator<?> it = entries.iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)it.next();
|
||||
Key key = (Key)entry.getKey();
|
||||
Object val = entry.getValue();
|
||||
put(key, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Collection of values contained in current RenderingHints
|
||||
* object.
|
||||
*
|
||||
* @return the Collection of RenderingHints's values.
|
||||
*/
|
||||
public Collection<Object> values() {
|
||||
return map.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not current RenderingHints object contains at least one
|
||||
* the value which is equal to the specified Object.
|
||||
*
|
||||
* @param value
|
||||
* the specified Object.
|
||||
* @return true, if the specified object is assigned to at least one
|
||||
* RenderingHint's key, false otherwise.
|
||||
*/
|
||||
public boolean containsValue(Object value) {
|
||||
return map.containsValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not current RenderingHints object contains the key
|
||||
* which is equal to the specified Object.
|
||||
*
|
||||
* @param key
|
||||
* the specified Object.
|
||||
* @return true, if the RenderingHints object contains the specified Object
|
||||
* as a key, false otherwise.
|
||||
*/
|
||||
public boolean containsKey(Object key) {
|
||||
if (key == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the RenderingHints object contains any key/value
|
||||
* pairs.
|
||||
*
|
||||
* @return true, if the RenderingHints object is empty, false otherwise.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return map.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the RenderingHints of all key/value pairs.
|
||||
*/
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of key/value pairs in the RenderingHints.
|
||||
*
|
||||
* @return the number of key/value pairs.
|
||||
*/
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the RenderingHints object with the specified object.
|
||||
*
|
||||
* @param o
|
||||
* the specified Object to be compared.
|
||||
* @return true, if the Object is a Map whose key/value pairs match this
|
||||
* RenderingHints' key/value pairs, false otherwise.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Map)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<?, ?> m = (Map<?, ?>)o;
|
||||
Set<?> keys = keySet();
|
||||
if (!keys.equals(m.keySet())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Iterator<?> it = keys.iterator();
|
||||
while (it.hasNext()) {
|
||||
Key key = (Key)it.next();
|
||||
Object v1 = get(key);
|
||||
Object v2 = m.get(key);
|
||||
if (!(v1 == null ? v2 == null : v1.equals(v2))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash code for this RenderingHints object.
|
||||
*
|
||||
* @return the hash code for this RenderingHints object.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return map.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the clone of the RenderingHints object with the same contents.
|
||||
*
|
||||
* @return the clone of the RenderingHints instance.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Object clone() {
|
||||
RenderingHints clone = new RenderingHints(null);
|
||||
clone.map = (HashMap<Object, Object>)this.map.clone();
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string representation of the RenderingHints object.
|
||||
*
|
||||
* @return the String object which represents RenderingHints object.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RenderingHints[" + map.toString() + "]"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
/**
|
||||
* The RenderingHints.Key class is abstract and defines a base type for all
|
||||
* RenderingHints keys.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract static class Key {
|
||||
|
||||
/** The key. */
|
||||
private final int key;
|
||||
|
||||
/**
|
||||
* Instantiates a new key with unique integer identifier. No two objects
|
||||
* of the same subclass with the same integer key can be instantiated.
|
||||
*
|
||||
* @param key
|
||||
* the unique key.
|
||||
*/
|
||||
protected Key(int key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the Key object with the specified object.
|
||||
*
|
||||
* @param o
|
||||
* the specified Object to be compared.
|
||||
* @return true, if the Key is equal to the specified object, false
|
||||
* otherwise.
|
||||
*/
|
||||
@Override
|
||||
public final boolean equals(Object o) {
|
||||
return this == o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash code for this Key object.
|
||||
*
|
||||
* @return the hash code for this Key object.
|
||||
*/
|
||||
@Override
|
||||
public final int hashCode() {
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns integer unique key with which this Key object has been
|
||||
* instantiated.
|
||||
*
|
||||
* @return the integer unique key with which this Key object has been
|
||||
* instantiated.
|
||||
*/
|
||||
protected final int intKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not specified value is compatible with the Key.
|
||||
*
|
||||
* @param val
|
||||
* the Object.
|
||||
* @return true, if the specified value is compatible with the Key,
|
||||
* false otherwise.
|
||||
*/
|
||||
public abstract boolean isCompatibleValue(Object val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Private implementation of Key class.
|
||||
*/
|
||||
private static class KeyImpl extends Key {
|
||||
|
||||
/**
|
||||
* Instantiates a new key implementation.
|
||||
*
|
||||
* @param key
|
||||
* the key.
|
||||
*/
|
||||
protected KeyImpl(int key) {
|
||||
super(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatibleValue(Object val) {
|
||||
if (!(val instanceof KeyValue)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ((KeyValue)val).key == this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Private class KeyValue is used as value for Key class instance.
|
||||
*/
|
||||
private static class KeyValue {
|
||||
|
||||
/**
|
||||
* The key.
|
||||
*/
|
||||
private final Key key;
|
||||
|
||||
/**
|
||||
* Instantiates a new key value.
|
||||
*
|
||||
* @param key
|
||||
* the key.
|
||||
*/
|
||||
protected KeyValue(Key key) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
/**
|
||||
* The Shape interface defines a geometric shape defined by a boundary (outline)
|
||||
* path. The path outline can be accessed through a PathIterator object. The
|
||||
* Shape interface provides methods for obtaining the bounding box (which is the
|
||||
* smallest rectangle containing the shape and for obtaining a PathIterator
|
||||
* object for current Shape, as well as utility methods which determine if the
|
||||
* Shape contains or intersects a Rectangle or contains a Point.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface Shape {
|
||||
|
||||
/**
|
||||
* Checks whether or not the point with specified coordinates lies inside
|
||||
* the Shape.
|
||||
*
|
||||
* @param x
|
||||
* the X coordinate.
|
||||
* @param y
|
||||
* the Y coordinate.
|
||||
* @return true, if the specified coordinates lie inside the Shape, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean contains(double x, double y);
|
||||
|
||||
/**
|
||||
* Checks whether or not the rectangle with specified [x, y, width, height]
|
||||
* parameters lies inside the Shape.
|
||||
*
|
||||
* @param x
|
||||
* the X double coordinate of the rectangle's upper left corner.
|
||||
* @param y
|
||||
* the Y double coordinate of the rectangle's upper left corner.
|
||||
* @param w
|
||||
* the width of rectangle.
|
||||
* @param h
|
||||
* the height of rectangle.
|
||||
* @return true, if the specified rectangle lies inside the Shape, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean contains(double x, double y, double w, double h);
|
||||
|
||||
/**
|
||||
* Checks whether or not the specified Point2D lies inside the Shape.
|
||||
*
|
||||
* @param point
|
||||
* the Point2D object.
|
||||
* @return true, if the specified Point2D lies inside the Shape, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean contains(Point2D point);
|
||||
|
||||
/**
|
||||
* Checks whether or not the specified rectangle lies inside the Shape.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle2D object.
|
||||
* @return true, if the specified rectangle lies inside the Shape, false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean contains(Rectangle2D r);
|
||||
|
||||
/**
|
||||
* Gets the bounding rectangle of the Shape. The bounding rectangle is the
|
||||
* smallest rectangle which contains the Shape.
|
||||
*
|
||||
* @return the bounding rectangle of the Shape.
|
||||
*/
|
||||
public Rectangle getBounds();
|
||||
|
||||
/**
|
||||
* Gets the Rectangle2D which represents Shape bounds. The bounding
|
||||
* rectangle is the smallest rectangle which contains the Shape.
|
||||
*
|
||||
* @return the bounding rectangle of the Shape.
|
||||
*/
|
||||
public Rectangle2D getBounds2D();
|
||||
|
||||
/**
|
||||
* Gets the PathIterator object of the Shape which provides access to the
|
||||
* shape's boundary modified by the specified AffineTransform.
|
||||
*
|
||||
* @param at
|
||||
* the specified AffineTransform object or null.
|
||||
* @return PathIterator object for the Shape.
|
||||
*/
|
||||
public PathIterator getPathIterator(AffineTransform at);
|
||||
|
||||
/**
|
||||
* Gets the PathIterator object of the Shape which provides access to the
|
||||
* coordinates of the shapes boundary modified by the specified
|
||||
* AffineTransform. The flatness parameter defines the amount of subdivision
|
||||
* of the curved segments and specifies the maximum distance which every
|
||||
* point on the unflattened transformed curve can deviate from the returned
|
||||
* flattened path segments.
|
||||
*
|
||||
* @param at
|
||||
* the specified AffineTransform object or null.
|
||||
* @param flatness
|
||||
* the maximum number of the control points for a given curve
|
||||
* which varies from colinear before a subdivided curve is
|
||||
* replaced by a straight line connecting the endpoints.
|
||||
* @return PathIterator object for the Shape.
|
||||
*/
|
||||
public PathIterator getPathIterator(AffineTransform at, double flatness);
|
||||
|
||||
/**
|
||||
* Checks whether or not the interior of rectangular specified by [x, y,
|
||||
* width, height] parameters intersects the interior of the Shape.
|
||||
*
|
||||
* @param x
|
||||
* the X double coordinate of the rectangle's upper left corner.
|
||||
* @param y
|
||||
* the Y double coordinate of the rectangle's upper left corner.
|
||||
* @param w
|
||||
* the width of rectangle.
|
||||
* @param h
|
||||
* the height of rectangle.
|
||||
* @return true, if the rectangle specified by [x, y, width, height]
|
||||
* parameters intersects the interior of the Shape, false otherwise.
|
||||
*/
|
||||
public boolean intersects(double x, double y, double w, double h);
|
||||
|
||||
/**
|
||||
* Checks whether or not the interior of rectangle specified by Rectangle2D
|
||||
* object intersects the interior of the Shape.
|
||||
*
|
||||
* @param r
|
||||
* the Rectangle2D object.
|
||||
* @return true, if the Rectangle2D intersects the interior of the Shape,
|
||||
* otherwise false.
|
||||
*/
|
||||
public boolean intersects(Rectangle2D r);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Alexey A. Petrenko
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The Stroke interface gives a pen style to be used by the Graphics2D
|
||||
* interface. It provides a means for getting a stroked version of a shape,
|
||||
* which is the version that is suitable for drawing via the Graphics2D
|
||||
* interface. Stroking a shape gives the shape's outline a width or drawing
|
||||
* style.
|
||||
* <p>
|
||||
* The Draw methods from Graphics2D interface should use the Stroke object for
|
||||
* rendering the shape's outline. The stroke should be set by
|
||||
* setStroke(java.awt.Stroke) method of the Graphics2D interface.
|
||||
*
|
||||
* @see java.awt.Graphics2D#setStroke(java.awt.Stroke)
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface Stroke {
|
||||
|
||||
/**
|
||||
* Creates the stroked shape, which is the version that is suitable for
|
||||
* drawing via the Graphics2D interface. Stroking a shape gives the shape's
|
||||
* outline a width or drawing style.
|
||||
*
|
||||
* @param p
|
||||
* the original shape.
|
||||
* @return the stroked shape.
|
||||
*/
|
||||
public Shape createStrokedShape(Shape p);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,255 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.im.InputMethodHighlight;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.peer.*;
|
||||
import java.io.Serializable;
|
||||
import java.net.URL;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import org.apache.harmony.awt.gl.image.*;
|
||||
import org.apache.harmony.awt.wtk.GraphicsFactory;
|
||||
|
||||
class ToolkitImpl extends Toolkit {
|
||||
|
||||
static final Hashtable<Serializable, Image> imageCache = new Hashtable<Serializable, Image>();
|
||||
|
||||
@Override
|
||||
public void sync() {
|
||||
lockAWT();
|
||||
try {
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int checkImage(Image image, int width, int height, ImageObserver observer) {
|
||||
lockAWT();
|
||||
try {
|
||||
if (width == 0 || height == 0) {
|
||||
return ImageObserver.ALLBITS;
|
||||
}
|
||||
if (!(image instanceof OffscreenImage)) {
|
||||
return ImageObserver.ALLBITS;
|
||||
}
|
||||
OffscreenImage oi = (OffscreenImage) image;
|
||||
return oi.checkImage(observer);
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image createImage(ImageProducer producer) {
|
||||
lockAWT();
|
||||
try {
|
||||
return new OffscreenImage(producer);
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image createImage(byte[] imagedata, int imageoffset, int imagelength) {
|
||||
lockAWT();
|
||||
try {
|
||||
return new OffscreenImage(new ByteArrayDecodingImageSource(imagedata, imageoffset,
|
||||
imagelength));
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image createImage(URL url) {
|
||||
lockAWT();
|
||||
try {
|
||||
return new OffscreenImage(new URLDecodingImageSource(url));
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image createImage(String filename) {
|
||||
lockAWT();
|
||||
try {
|
||||
return new OffscreenImage(new FileDecodingImageSource(filename));
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorModel getColorModel() {
|
||||
lockAWT();
|
||||
try {
|
||||
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
|
||||
.getDefaultConfiguration().getColorModel();
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Deprecated
|
||||
public FontMetrics getFontMetrics(Font font) {
|
||||
lockAWT();
|
||||
try {
|
||||
GraphicsFactory gf = getGraphicsFactory();
|
||||
return gf.getFontMetrics(font);
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prepareImage(Image image, int width, int height, ImageObserver observer) {
|
||||
lockAWT();
|
||||
try {
|
||||
if (width == 0 || height == 0) {
|
||||
return true;
|
||||
}
|
||||
if (!(image instanceof OffscreenImage)) {
|
||||
return true;
|
||||
}
|
||||
OffscreenImage oi = (OffscreenImage) image;
|
||||
return oi.prepareImage(observer);
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beep() {
|
||||
lockAWT();
|
||||
try {
|
||||
// ???AWT: is there nothing to be implemented here?
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Deprecated
|
||||
public String[] getFontList() {
|
||||
lockAWT();
|
||||
try {
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
@Deprecated
|
||||
protected FontPeer getFontPeer(String a0, int a1) {
|
||||
lockAWT();
|
||||
try {
|
||||
return null;
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(String filename) {
|
||||
return getImage(filename, this);
|
||||
}
|
||||
|
||||
static Image getImage(String filename, Toolkit toolkit) {
|
||||
synchronized (imageCache) {
|
||||
Image im = (filename == null ? null : imageCache.get(filename));
|
||||
|
||||
if (im == null) {
|
||||
try {
|
||||
im = toolkit.createImage(filename);
|
||||
imageCache.put(filename, im);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
return im;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(URL url) {
|
||||
return getImage(url, this);
|
||||
}
|
||||
|
||||
static Image getImage(URL url, Toolkit toolkit) {
|
||||
synchronized (imageCache) {
|
||||
Image im = imageCache.get(url);
|
||||
if (im == null) {
|
||||
try {
|
||||
im = toolkit.createImage(url);
|
||||
imageCache.put(url, im);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
return im;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScreenResolution() throws HeadlessException {
|
||||
lockAWT();
|
||||
try {
|
||||
return 62;
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension getScreenSize() {
|
||||
lockAWT();
|
||||
try {
|
||||
DisplayMode dm = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDisplayMode();
|
||||
return new Dimension(dm.getWidth(), dm.getHeight());
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<java.awt.font.TextAttribute, ?> mapInputMethodHighlight(
|
||||
InputMethodHighlight highlight) throws HeadlessException {
|
||||
lockAWT();
|
||||
try {
|
||||
return mapInputMethodHighlightImpl(highlight);
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EventQueue getSystemEventQueueImpl() {
|
||||
return getSystemEventQueueCore().getActiveEventQueue();
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Pavel Dolgov
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* The Transparency interface defines transparency's general modes.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface Transparency {
|
||||
|
||||
/**
|
||||
* The Constant OPAQUE represents completely opaque data, all pixels have an
|
||||
* alpha value of 1.0.
|
||||
*/
|
||||
public static final int OPAQUE = 1;
|
||||
|
||||
/**
|
||||
* The Constant BITMASK represents data which can be either completely
|
||||
* opaque, with an alpha value of 1.0, or completely transparent, with an
|
||||
* alpha value of 0.0.
|
||||
*/
|
||||
public static final int BITMASK = 2;
|
||||
|
||||
/**
|
||||
* The Constant TRANSLUCENT represents data which alpha value can vary
|
||||
* between and including 0.0 and 1.0.
|
||||
*/
|
||||
public static final int TRANSLUCENT = 3;
|
||||
|
||||
/**
|
||||
* Gets the transparency mode.
|
||||
*
|
||||
* @return the transparency mode: OPAQUE, BITMASK or TRANSLUCENT.
|
||||
*/
|
||||
public int getTransparency();
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Oleg V. Khaschansky
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.color;
|
||||
|
||||
/**
|
||||
* The CMMException is thrown as soon as a native CMM error occurs.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class CMMException extends java.lang.RuntimeException {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 5775558044142994965L;
|
||||
|
||||
/**
|
||||
* Instantiates a new CMM exception with detail message.
|
||||
*
|
||||
* @param s
|
||||
* the detail message of the exception.
|
||||
*/
|
||||
public CMMException (String s) {
|
||||
super (s);
|
||||
}
|
||||
}
|
||||
@@ -1,414 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Oleg V. Khaschansky
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.color;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.harmony.awt.gl.color.LUTColorConverter;
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The ColorSpace class defines a color space type for a Color and provides
|
||||
* methods for arrays of color component operations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class ColorSpace implements Serializable {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = -409452704308689724L;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_XYZ indicates XYZ color space type.
|
||||
*/
|
||||
public static final int TYPE_XYZ = 0;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_Lab indicates Lab color space type.
|
||||
*/
|
||||
public static final int TYPE_Lab = 1;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_Luv indicates Luv color space type.
|
||||
*/
|
||||
public static final int TYPE_Luv = 2;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_YCbCr indicates YCbCr color space type.
|
||||
*/
|
||||
public static final int TYPE_YCbCr = 3;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_Yxy indicates Yxy color space type.
|
||||
*/
|
||||
public static final int TYPE_Yxy = 4;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_RGB indicates RGB color space type.
|
||||
*/
|
||||
public static final int TYPE_RGB = 5;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_GRAY indicates Gray color space type.
|
||||
*/
|
||||
public static final int TYPE_GRAY = 6;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_HSV indicates HSV color space type.
|
||||
*/
|
||||
public static final int TYPE_HSV = 7;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_HLS indicates HLS color space type.
|
||||
*/
|
||||
public static final int TYPE_HLS = 8;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_CMYK indicates CMYK color space type.
|
||||
*/
|
||||
public static final int TYPE_CMYK = 9;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_CMY indicates CMY color space type.
|
||||
*/
|
||||
public static final int TYPE_CMY = 11;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_2CLR indicates color spaces with 2 components.
|
||||
*/
|
||||
public static final int TYPE_2CLR = 12;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_3CLR indicates color spaces with 3 components.
|
||||
*/
|
||||
public static final int TYPE_3CLR = 13;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_4CLR indicates color spaces with 4 components.
|
||||
*/
|
||||
public static final int TYPE_4CLR = 14;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_5CLR indicates color spaces with 5 components.
|
||||
*/
|
||||
public static final int TYPE_5CLR = 15;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_6CLR indicates color spaces with 6 components.
|
||||
*/
|
||||
public static final int TYPE_6CLR = 16;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_7CLR indicates color spaces with 7 components.
|
||||
*/
|
||||
public static final int TYPE_7CLR = 17;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_8CLR indicates color spaces with 8 components.
|
||||
*/
|
||||
public static final int TYPE_8CLR = 18;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_9CLR indicates color spaces with 9 components.
|
||||
*/
|
||||
public static final int TYPE_9CLR = 19;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_ACLR indicates color spaces with 10 components.
|
||||
*/
|
||||
public static final int TYPE_ACLR = 20;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_BCLR indicates color spaces with 11 components.
|
||||
*/
|
||||
public static final int TYPE_BCLR = 21;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_CCLR indicates color spaces with 12 components.
|
||||
*/
|
||||
public static final int TYPE_CCLR = 22;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_DCLR indicates color spaces with 13 components.
|
||||
*/
|
||||
public static final int TYPE_DCLR = 23;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_ECLR indicates color spaces with 14 components.
|
||||
*/
|
||||
public static final int TYPE_ECLR = 24;
|
||||
|
||||
/**
|
||||
* The Constant TYPE_FCLR indicates color spaces with 15 components.
|
||||
*/
|
||||
public static final int TYPE_FCLR = 25;
|
||||
|
||||
/**
|
||||
* The Constant CS_sRGB indicates standard RGB color space.
|
||||
*/
|
||||
public static final int CS_sRGB = 1000;
|
||||
|
||||
/**
|
||||
* The Constant CS_LINEAR_RGB indicates linear RGB color space.
|
||||
*/
|
||||
public static final int CS_LINEAR_RGB = 1004;
|
||||
|
||||
/**
|
||||
* The Constant CS_CIEXYZ indicates CIEXYZ conversion color space.
|
||||
*/
|
||||
public static final int CS_CIEXYZ = 1001;
|
||||
|
||||
/**
|
||||
* The Constant CS_PYCC indicates Photo YCC conversion color space.
|
||||
*/
|
||||
public static final int CS_PYCC = 1002;
|
||||
|
||||
/**
|
||||
* The Constant CS_GRAY indicates linear gray scale color space.
|
||||
*/
|
||||
public static final int CS_GRAY = 1003;
|
||||
|
||||
/**
|
||||
* The cs_ gray.
|
||||
*/
|
||||
private static ColorSpace cs_Gray = null;
|
||||
|
||||
/**
|
||||
* The cs_ pycc.
|
||||
*/
|
||||
private static ColorSpace cs_PYCC = null;
|
||||
|
||||
/**
|
||||
* The cs_ ciexyz.
|
||||
*/
|
||||
private static ColorSpace cs_CIEXYZ = null;
|
||||
|
||||
/**
|
||||
* The cs_ lrgb.
|
||||
*/
|
||||
private static ColorSpace cs_LRGB = null;
|
||||
|
||||
/**
|
||||
* The cs_s rgb.
|
||||
*/
|
||||
private static ColorSpace cs_sRGB = null;
|
||||
|
||||
/**
|
||||
* The type.
|
||||
*/
|
||||
private int type;
|
||||
|
||||
/**
|
||||
* The num components.
|
||||
*/
|
||||
private int numComponents;
|
||||
|
||||
/**
|
||||
* Instantiates a ColorSpace with the specified ColorSpace type and number
|
||||
* of components.
|
||||
*
|
||||
* @param type
|
||||
* the type of color space.
|
||||
* @param numcomponents
|
||||
* the number of components.
|
||||
*/
|
||||
protected ColorSpace(int type, int numcomponents) {
|
||||
this.numComponents = numcomponents;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the component for the specified component index.
|
||||
*
|
||||
* @param idx
|
||||
* the index of the component.
|
||||
* @return the name of the component.
|
||||
*/
|
||||
public String getName(int idx) {
|
||||
if (idx < 0 || idx > numComponents - 1) {
|
||||
// awt.16A=Invalid component index: {0}
|
||||
throw new IllegalArgumentException(Messages.getString("awt.16A", idx)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return "Unnamed color component #" + idx; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the transformation of a color from this ColorSpace into the RGB
|
||||
* color space.
|
||||
*
|
||||
* @param colorvalue
|
||||
* the color value in this ColorSpace.
|
||||
* @return the float array with color components in the RGB color space.
|
||||
*/
|
||||
public abstract float[] toRGB(float[] colorvalue);
|
||||
|
||||
/**
|
||||
* Performs the transformation of a color from this ColorSpace into the
|
||||
* CS_CIEXYZ color space.
|
||||
*
|
||||
* @param colorvalue
|
||||
* the color value in this ColorSpace.
|
||||
* @return the float array with color components in the CS_CIEXYZ color
|
||||
* space.
|
||||
*/
|
||||
public abstract float[] toCIEXYZ(float[] colorvalue);
|
||||
|
||||
/**
|
||||
* Performs the transformation of a color from the RGB color space into this
|
||||
* ColorSpace.
|
||||
*
|
||||
* @param rgbvalue
|
||||
* the float array representing a color in the RGB color space.
|
||||
* @return the float array with the transformed color components.
|
||||
*/
|
||||
public abstract float[] fromRGB(float[] rgbvalue);
|
||||
|
||||
/**
|
||||
* Performs the transformation of a color from the CS_CIEXYZ color space
|
||||
* into this ColorSpace.
|
||||
*
|
||||
* @param colorvalue
|
||||
* the float array representing a color in the CS_CIEXYZ color
|
||||
* space.
|
||||
* @return the float array with the transformed color components.
|
||||
*/
|
||||
public abstract float[] fromCIEXYZ(float[] colorvalue);
|
||||
|
||||
/**
|
||||
* Gets the minimum normalized color component value for the specified
|
||||
* component.
|
||||
*
|
||||
* @param component
|
||||
* the component to determine the minimum value.
|
||||
* @return the minimum normalized value of the component.
|
||||
*/
|
||||
public float getMinValue(int component) {
|
||||
if (component < 0 || component > numComponents - 1) {
|
||||
// awt.16A=Invalid component index: {0}
|
||||
throw new IllegalArgumentException(Messages.getString("awt.16A", component)); //$NON-NLS-1$
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum normalized color component value for the specified
|
||||
* component.
|
||||
*
|
||||
* @param component
|
||||
* the component to determine the maximum value.
|
||||
* @return the maximum normalized value of the component.
|
||||
*/
|
||||
public float getMaxValue(int component) {
|
||||
if (component < 0 || component > numComponents - 1) {
|
||||
// awt.16A=Invalid component index: {0}
|
||||
throw new IllegalArgumentException(Messages.getString("awt.16A", component)); //$NON-NLS-1$
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if this ColorSpace has CS_sRGB type or not.
|
||||
*
|
||||
* @return true, if this ColorSpace has CS_sRGB type, false otherwise.
|
||||
*/
|
||||
public boolean isCS_sRGB() {
|
||||
// If our color space is sRGB, then cs_sRGB
|
||||
// is already initialized
|
||||
return (this == cs_sRGB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of the ColorSpace.
|
||||
*
|
||||
* @return the type of the ColorSpace.
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of components for this ColorSpace.
|
||||
*
|
||||
* @return the number of components.
|
||||
*/
|
||||
public int getNumComponents() {
|
||||
return numComponents;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the single instance of ColorSpace with the specified ColorSpace:
|
||||
* CS_sRGB, CS_LINEAR_RGB, CS_CIEXYZ, CS_GRAY, or CS_PYCC.
|
||||
*
|
||||
* @param colorspace
|
||||
* the identifier of the specified Colorspace.
|
||||
* @return the single instance of the desired ColorSpace.
|
||||
*/
|
||||
public static ColorSpace getInstance(int colorspace) {
|
||||
switch (colorspace) {
|
||||
case CS_sRGB:
|
||||
if (cs_sRGB == null) {
|
||||
cs_sRGB = new ICC_ColorSpace(
|
||||
new ICC_ProfileStub(CS_sRGB));
|
||||
LUTColorConverter.sRGB_CS = cs_sRGB;
|
||||
//ICC_Profile.getInstance (CS_sRGB));
|
||||
}
|
||||
return cs_sRGB;
|
||||
case CS_CIEXYZ:
|
||||
if (cs_CIEXYZ == null) {
|
||||
cs_CIEXYZ = new ICC_ColorSpace(
|
||||
new ICC_ProfileStub(CS_CIEXYZ));
|
||||
//ICC_Profile.getInstance (CS_CIEXYZ));
|
||||
}
|
||||
return cs_CIEXYZ;
|
||||
case CS_GRAY:
|
||||
if (cs_Gray == null) {
|
||||
cs_Gray = new ICC_ColorSpace(
|
||||
new ICC_ProfileStub(CS_GRAY));
|
||||
LUTColorConverter.LINEAR_GRAY_CS = cs_Gray;
|
||||
//ICC_Profile.getInstance (CS_GRAY));
|
||||
}
|
||||
return cs_Gray;
|
||||
case CS_PYCC:
|
||||
if (cs_PYCC == null) {
|
||||
cs_PYCC = new ICC_ColorSpace(
|
||||
new ICC_ProfileStub(CS_PYCC));
|
||||
//ICC_Profile.getInstance (CS_PYCC));
|
||||
}
|
||||
return cs_PYCC;
|
||||
case CS_LINEAR_RGB:
|
||||
if (cs_LRGB == null) {
|
||||
cs_LRGB = new ICC_ColorSpace(
|
||||
new ICC_ProfileStub(CS_LINEAR_RGB));
|
||||
LUTColorConverter.LINEAR_GRAY_CS = cs_Gray;
|
||||
//ICC_Profile.getInstance (CS_LINEAR_RGB));
|
||||
}
|
||||
return cs_LRGB;
|
||||
default:
|
||||
}
|
||||
|
||||
// Unknown argument passed
|
||||
// awt.16B=Not a predefined colorspace
|
||||
throw new IllegalArgumentException(Messages.getString("Not a predefined colorspace")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,468 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Oleg V. Khaschansky
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.color;
|
||||
|
||||
import org.apache.harmony.awt.gl.color.ColorConverter;
|
||||
import org.apache.harmony.awt.gl.color.ColorScaler;
|
||||
import org.apache.harmony.awt.gl.color.ICC_Transform;
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This class implements the abstract class ColorSpace and represents device
|
||||
* independent and device dependent color spaces. This color space is based on
|
||||
* the International Color Consortium Specification (ICC) File Format for Color
|
||||
* Profiles: <a href="http://www.color.org">http://www.color.org</a>
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class ICC_ColorSpace extends ColorSpace {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 3455889114070431483L;
|
||||
|
||||
// Need to keep compatibility with serialized form
|
||||
/**
|
||||
* The Constant serialPersistentFields.
|
||||
*/
|
||||
private static final ObjectStreamField[]
|
||||
serialPersistentFields = {
|
||||
new ObjectStreamField("thisProfile", ICC_Profile.class), //$NON-NLS-1$
|
||||
new ObjectStreamField("minVal", float[].class), //$NON-NLS-1$
|
||||
new ObjectStreamField("maxVal", float[].class), //$NON-NLS-1$
|
||||
new ObjectStreamField("diffMinMax", float[].class), //$NON-NLS-1$
|
||||
new ObjectStreamField("invDiffMinMax", float[].class), //$NON-NLS-1$
|
||||
new ObjectStreamField("needScaleInit", Boolean.TYPE) //$NON-NLS-1$
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* According to ICC specification (from http://www.color.org) "For the
|
||||
* CIEXYZ encoding, each component (X, Y, and Z) is encoded as a
|
||||
* u1Fixed15Number". This means that max value for this encoding is 1 +
|
||||
* (32767/32768)
|
||||
*/
|
||||
private static final float MAX_XYZ = 1f + (32767f/32768f);
|
||||
|
||||
/**
|
||||
* The Constant MAX_SHORT.
|
||||
*/
|
||||
private static final float MAX_SHORT = 65535f;
|
||||
|
||||
/**
|
||||
* The Constant INV_MAX_SHORT.
|
||||
*/
|
||||
private static final float INV_MAX_SHORT = 1f/MAX_SHORT;
|
||||
|
||||
/**
|
||||
* The Constant SHORT2XYZ_FACTOR.
|
||||
*/
|
||||
private static final float SHORT2XYZ_FACTOR = MAX_XYZ/MAX_SHORT;
|
||||
|
||||
/**
|
||||
* The Constant XYZ2SHORT_FACTOR.
|
||||
*/
|
||||
private static final float XYZ2SHORT_FACTOR = MAX_SHORT/MAX_XYZ;
|
||||
|
||||
/**
|
||||
* The profile.
|
||||
*/
|
||||
private ICC_Profile profile = null;
|
||||
|
||||
/**
|
||||
* The min values.
|
||||
*/
|
||||
private float minValues[] = null;
|
||||
|
||||
/**
|
||||
* The max values.
|
||||
*/
|
||||
private float maxValues[] = null;
|
||||
|
||||
// cache transforms here - performance gain
|
||||
/**
|
||||
* The to rgb transform.
|
||||
*/
|
||||
private ICC_Transform toRGBTransform = null;
|
||||
|
||||
/**
|
||||
* The from rgb transform.
|
||||
*/
|
||||
private ICC_Transform fromRGBTransform = null;
|
||||
|
||||
/**
|
||||
* The to xyz transform.
|
||||
*/
|
||||
private ICC_Transform toXYZTransform = null;
|
||||
|
||||
/**
|
||||
* The from xyz transform.
|
||||
*/
|
||||
private ICC_Transform fromXYZTransform = null;
|
||||
|
||||
/**
|
||||
* The converter.
|
||||
*/
|
||||
private final ColorConverter converter = new ColorConverter();
|
||||
|
||||
/**
|
||||
* The scaler.
|
||||
*/
|
||||
private final ColorScaler scaler = new ColorScaler();
|
||||
|
||||
/**
|
||||
* The scaling data loaded.
|
||||
*/
|
||||
private boolean scalingDataLoaded = false;
|
||||
|
||||
/**
|
||||
* The resolved deserialized inst.
|
||||
*/
|
||||
private ICC_ColorSpace resolvedDeserializedInst;
|
||||
|
||||
/**
|
||||
* Instantiates a new ICC color space from an ICC_Profile object.
|
||||
*
|
||||
* @param pf
|
||||
* the ICC_Profile object.
|
||||
*/
|
||||
public ICC_ColorSpace(ICC_Profile pf) {
|
||||
super(pf.getColorSpaceType(), pf.getNumComponents());
|
||||
|
||||
int pfClass = pf.getProfileClass();
|
||||
|
||||
switch (pfClass) {
|
||||
case ICC_Profile.CLASS_COLORSPACECONVERSION:
|
||||
case ICC_Profile.CLASS_DISPLAY:
|
||||
case ICC_Profile.CLASS_OUTPUT:
|
||||
case ICC_Profile.CLASS_INPUT:
|
||||
break; // OK, it is color conversion profile
|
||||
default:
|
||||
// awt.168=Invalid profile class.
|
||||
throw new IllegalArgumentException(Messages.getString("awt.168")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
profile = pf;
|
||||
fillMinMaxValues();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ICC_Profile for this ICC_ColorSpace.
|
||||
*
|
||||
* @return the ICC_Profile for this ICC_ColorSpace.
|
||||
*/
|
||||
public ICC_Profile getProfile() {
|
||||
if (profile instanceof ICC_ProfileStub) {
|
||||
profile = ((ICC_ProfileStub) profile).loadProfile();
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the transformation of a color from this ColorSpace into the RGB
|
||||
* color space.
|
||||
*
|
||||
* @param colorvalue
|
||||
* the color value in this ColorSpace.
|
||||
* @return the float array with color components in the RGB color space.
|
||||
*/
|
||||
@Override
|
||||
public float[] toRGB(float[] colorvalue) {
|
||||
if (toRGBTransform == null) {
|
||||
ICC_Profile sRGBProfile =
|
||||
((ICC_ColorSpace) ColorSpace.getInstance(CS_sRGB)).getProfile();
|
||||
ICC_Profile[] profiles = {getProfile(), sRGBProfile};
|
||||
toRGBTransform = new ICC_Transform(profiles);
|
||||
if (!scalingDataLoaded) {
|
||||
scaler.loadScalingData(this);
|
||||
scalingDataLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
short[] data = new short[getNumComponents()];
|
||||
|
||||
scaler.scale(colorvalue, data, 0);
|
||||
|
||||
short[] converted =
|
||||
converter.translateColor(toRGBTransform, data, null);
|
||||
|
||||
// unscale to sRGB
|
||||
float[] res = new float[3];
|
||||
|
||||
res[0] = ((converted[0] & 0xFFFF)) * INV_MAX_SHORT;
|
||||
res[1] = ((converted[1] & 0xFFFF)) * INV_MAX_SHORT;
|
||||
res[2] = ((converted[2] & 0xFFFF)) * INV_MAX_SHORT;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the transformation of a color from this ColorSpace into the
|
||||
* CS_CIEXYZ color space.
|
||||
*
|
||||
* @param colorvalue
|
||||
* the color value in this ColorSpace.
|
||||
* @return the float array with color components in the CS_CIEXYZ color
|
||||
* space.
|
||||
*/
|
||||
@Override
|
||||
public float[] toCIEXYZ(float[] colorvalue) {
|
||||
if (toXYZTransform == null) {
|
||||
ICC_Profile xyzProfile =
|
||||
((ICC_ColorSpace) ColorSpace.getInstance(CS_CIEXYZ)).getProfile();
|
||||
ICC_Profile[] profiles = {getProfile(), xyzProfile};
|
||||
try {
|
||||
int[] intents = {
|
||||
ICC_Profile.icRelativeColorimetric,
|
||||
ICC_Profile.icPerceptual};
|
||||
toXYZTransform = new ICC_Transform(profiles, intents);
|
||||
} catch (CMMException e) { // No such tag, use what we can
|
||||
toXYZTransform = new ICC_Transform(profiles);
|
||||
}
|
||||
|
||||
if (!scalingDataLoaded) {
|
||||
scaler.loadScalingData(this);
|
||||
scalingDataLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
short[] data = new short[getNumComponents()];
|
||||
|
||||
scaler.scale(colorvalue, data, 0);
|
||||
|
||||
short[] converted =
|
||||
converter.translateColor(toXYZTransform, data, null);
|
||||
|
||||
// unscale to XYZ
|
||||
float[] res = new float[3];
|
||||
|
||||
res[0] = ((converted[0] & 0xFFFF)) * SHORT2XYZ_FACTOR;
|
||||
res[1] = ((converted[1] & 0xFFFF)) * SHORT2XYZ_FACTOR;
|
||||
res[2] = ((converted[2] & 0xFFFF)) * SHORT2XYZ_FACTOR;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the transformation of a color from the RGB color space into this
|
||||
* ColorSpace.
|
||||
*
|
||||
* @param rgbvalue
|
||||
* the float array representing a color in the RGB color space.
|
||||
* @return the float array with the transformed color components.
|
||||
*/
|
||||
@Override
|
||||
public float[] fromRGB(float[] rgbvalue) {
|
||||
if (fromRGBTransform == null) {
|
||||
ICC_Profile sRGBProfile =
|
||||
((ICC_ColorSpace) ColorSpace.getInstance(CS_sRGB)).getProfile();
|
||||
ICC_Profile[] profiles = {sRGBProfile, getProfile()};
|
||||
fromRGBTransform = new ICC_Transform(profiles);
|
||||
if (!scalingDataLoaded) {
|
||||
scaler.loadScalingData(this);
|
||||
scalingDataLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// scale rgb value to short
|
||||
short[] scaledRGBValue = new short[3];
|
||||
scaledRGBValue[0] = (short)(rgbvalue[0] * MAX_SHORT + 0.5f);
|
||||
scaledRGBValue[1] = (short)(rgbvalue[1] * MAX_SHORT + 0.5f);
|
||||
scaledRGBValue[2] = (short)(rgbvalue[2] * MAX_SHORT + 0.5f);
|
||||
|
||||
short[] converted =
|
||||
converter.translateColor(fromRGBTransform, scaledRGBValue, null);
|
||||
|
||||
float[] res = new float[getNumComponents()];
|
||||
|
||||
scaler.unscale(res, converted, 0);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the transformation of a color from the CS_CIEXYZ color space
|
||||
* into this ColorSpace.
|
||||
*
|
||||
* @param xyzvalue
|
||||
* the float array representing a color in the CS_CIEXYZ color
|
||||
* space.
|
||||
* @return the float array with the transformed color components.
|
||||
*/
|
||||
@Override
|
||||
public float[] fromCIEXYZ(float[] xyzvalue) {
|
||||
if (fromXYZTransform == null) {
|
||||
ICC_Profile xyzProfile =
|
||||
((ICC_ColorSpace) ColorSpace.getInstance(CS_CIEXYZ)).getProfile();
|
||||
ICC_Profile[] profiles = {xyzProfile, getProfile()};
|
||||
try {
|
||||
int[] intents = {
|
||||
ICC_Profile.icPerceptual,
|
||||
ICC_Profile.icRelativeColorimetric};
|
||||
fromXYZTransform = new ICC_Transform(profiles, intents);
|
||||
} catch (CMMException e) { // No such tag, use what we can
|
||||
fromXYZTransform = new ICC_Transform(profiles);
|
||||
}
|
||||
|
||||
if (!scalingDataLoaded) {
|
||||
scaler.loadScalingData(this);
|
||||
scalingDataLoaded = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// scale xyz value to short
|
||||
short[] scaledXYZValue = new short[3];
|
||||
scaledXYZValue[0] = (short)(xyzvalue[0] * XYZ2SHORT_FACTOR + 0.5f);
|
||||
scaledXYZValue[1] = (short)(xyzvalue[1] * XYZ2SHORT_FACTOR + 0.5f);
|
||||
scaledXYZValue[2] = (short)(xyzvalue[2] * XYZ2SHORT_FACTOR + 0.5f);
|
||||
|
||||
short[] converted =
|
||||
converter.translateColor(fromXYZTransform, scaledXYZValue, null);
|
||||
|
||||
float[] res = new float[getNumComponents()];
|
||||
|
||||
scaler.unscale(res, converted, 0);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the minimum normalized color component value for the specified
|
||||
* component.
|
||||
*
|
||||
* @param component
|
||||
* the component to determine the minimum value.
|
||||
* @return the minimum normalized value of the component.
|
||||
*/
|
||||
@Override
|
||||
public float getMinValue(int component) {
|
||||
if ((component < 0) || (component > this.getNumComponents() - 1)) {
|
||||
// awt.169=Component index out of range
|
||||
throw new IllegalArgumentException(Messages.getString("awt.169")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return minValues[component];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the maximum normalized color component value for the specified
|
||||
* component.
|
||||
*
|
||||
* @param component
|
||||
* the component to determine the maximum value.
|
||||
* @return the maximum normalized value of the component.
|
||||
*/
|
||||
@Override
|
||||
public float getMaxValue(int component) {
|
||||
if ((component < 0) || (component > this.getNumComponents() - 1)) {
|
||||
// awt.169=Component index out of range
|
||||
throw new IllegalArgumentException(Messages.getString("awt.169")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return maxValues[component];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill min max values.
|
||||
*/
|
||||
private void fillMinMaxValues() {
|
||||
int n = getNumComponents();
|
||||
maxValues = new float[n];
|
||||
minValues = new float[n];
|
||||
switch (getType()) {
|
||||
case ColorSpace.TYPE_XYZ:
|
||||
minValues[0] = 0;
|
||||
minValues[1] = 0;
|
||||
minValues[2] = 0;
|
||||
maxValues[0] = MAX_XYZ;
|
||||
maxValues[1] = MAX_XYZ;
|
||||
maxValues[2] = MAX_XYZ;
|
||||
break;
|
||||
case ColorSpace.TYPE_Lab:
|
||||
minValues[0] = 0;
|
||||
minValues[1] = -128;
|
||||
minValues[2] = -128;
|
||||
maxValues[0] = 100;
|
||||
maxValues[1] = 127;
|
||||
maxValues[2] = 127;
|
||||
break;
|
||||
default:
|
||||
for(int i=0; i<n; i++) {
|
||||
minValues[i] = 0;
|
||||
maxValues[i] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write object.
|
||||
*
|
||||
* @param out
|
||||
* the out
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
|
||||
fields.put("thisProfile", profile); //$NON-NLS-1$
|
||||
fields.put("minVal", null); //$NON-NLS-1$
|
||||
fields.put("maxVal", null); //$NON-NLS-1$
|
||||
fields.put("diffMinMax", null); //$NON-NLS-1$
|
||||
fields.put("invDiffMinMax", null); //$NON-NLS-1$
|
||||
fields.put("needScaleInit", true); //$NON-NLS-1$
|
||||
|
||||
out.writeFields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Read object.
|
||||
*
|
||||
* @param in
|
||||
* the in
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
* @throws ClassNotFoundException
|
||||
* the class not found exception
|
||||
*/
|
||||
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
|
||||
ObjectInputStream.GetField fields = in.readFields();
|
||||
resolvedDeserializedInst =
|
||||
new ICC_ColorSpace((ICC_Profile) fields.get("thisProfile", null)); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Read resolve.
|
||||
*
|
||||
* @return the object
|
||||
* @throws ObjectStreamException
|
||||
* the object stream exception
|
||||
*/
|
||||
Object readResolve() throws ObjectStreamException {
|
||||
return resolvedDeserializedInst;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Oleg V. Khaschansky
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.color;
|
||||
|
||||
/**
|
||||
* The ICC_ProfileGray class represent profiles with TYPE_GRAY color space type,
|
||||
* and includes the grayTRCTag and mediaWhitePointTag tags. The gray component
|
||||
* can be transformed from a GRAY device profile color space to the CIEXYZ
|
||||
* Profile through the tone reproduction curve (TRC):
|
||||
* <p>
|
||||
* PCSY = grayTRC[deviceGray]
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class ICC_ProfileGray extends ICC_Profile {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = -1124721290732002649L;
|
||||
|
||||
/**
|
||||
* Instantiates a new iC c_ profile gray.
|
||||
*
|
||||
* @param profileHandle
|
||||
* the profile handle
|
||||
*/
|
||||
ICC_ProfileGray(long profileHandle) {
|
||||
super(profileHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the TRC as an array of shorts.
|
||||
*
|
||||
* @return the short array of the TRC.
|
||||
*/
|
||||
public short[] getTRC() {
|
||||
return super.getTRC(icSigGrayTRCTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the media white point.
|
||||
*
|
||||
* @return the media white point
|
||||
*/
|
||||
@Override
|
||||
public float[] getMediaWhitePoint() {
|
||||
return super.getMediaWhitePoint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a gamma value representing the tone reproduction curve (TRC).
|
||||
*
|
||||
* @return the gamma value representing the tone reproduction curve (TRC).
|
||||
*/
|
||||
public float getGamma() {
|
||||
return super.getGamma(icSigGrayTRCTag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Oleg V. Khaschansky
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.color;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* The ICC_ProfileRGB class represents profiles with RGB color space type and
|
||||
* contains the redColorantTag, greenColorantTag, blueColorantTag, redTRCTag,
|
||||
* greenTRCTag, blueTRCTag, and mediaWhitePointTag tags.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class ICC_ProfileRGB extends ICC_Profile {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 8505067385152579334L;
|
||||
|
||||
/**
|
||||
* Instantiates a new RGB ICC_Profile.
|
||||
*
|
||||
* @param profileHandle
|
||||
* the profile handle
|
||||
*/
|
||||
ICC_ProfileRGB(long profileHandle) {
|
||||
super(profileHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Constant REDCOMPONENT indicates the red component.
|
||||
*/
|
||||
public static final int REDCOMPONENT = 0;
|
||||
|
||||
/**
|
||||
* The Constant GREENCOMPONENT indicates the green component.
|
||||
*/
|
||||
public static final int GREENCOMPONENT = 1;
|
||||
|
||||
/**
|
||||
* The Constant BLUECOMPONENT indicates the blue component.
|
||||
*/
|
||||
public static final int BLUECOMPONENT = 2;
|
||||
|
||||
// awt.15E=Unknown component. Must be REDCOMPONENT, GREENCOMPONENT or BLUECOMPONENT.
|
||||
/**
|
||||
* The Constant UNKNOWN_COMPONENT_MSG.
|
||||
*/
|
||||
private static final String UNKNOWN_COMPONENT_MSG = Messages
|
||||
.getString("awt.15E"); //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Gets the TRC.
|
||||
*
|
||||
* @param component
|
||||
* the tag signature.
|
||||
* @return the TRC value.
|
||||
*/
|
||||
@Override
|
||||
public short[] getTRC(int component) {
|
||||
switch (component) {
|
||||
case REDCOMPONENT:
|
||||
return super.getTRC(icSigRedTRCTag);
|
||||
case GREENCOMPONENT:
|
||||
return super.getTRC(icSigGreenTRCTag);
|
||||
case BLUECOMPONENT:
|
||||
return super.getTRC(icSigBlueTRCTag);
|
||||
default:
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(UNKNOWN_COMPONENT_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the gamma.
|
||||
*
|
||||
* @param component
|
||||
* the tag signature.
|
||||
* @return the gamma value.
|
||||
*/
|
||||
@Override
|
||||
public float getGamma(int component) {
|
||||
switch (component) {
|
||||
case REDCOMPONENT:
|
||||
return super.getGamma(icSigRedTRCTag);
|
||||
case GREENCOMPONENT:
|
||||
return super.getGamma(icSigGreenTRCTag);
|
||||
case BLUECOMPONENT:
|
||||
return super.getGamma(icSigBlueTRCTag);
|
||||
default:
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(UNKNOWN_COMPONENT_MSG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a float matrix which contains the X, Y, and Z components of the
|
||||
* profile's redColorantTag, greenColorantTag, and blueColorantTag.
|
||||
*
|
||||
* @return the float matrix which contains the X, Y, and Z components of the
|
||||
* profile's redColorantTag, greenColorantTag, and blueColorantTag.
|
||||
*/
|
||||
public float[][] getMatrix() {
|
||||
float [][] m = new float[3][3]; // The matrix
|
||||
|
||||
float[] redXYZ = getXYZValue(icSigRedColorantTag);
|
||||
float[] greenXYZ = getXYZValue(icSigGreenColorantTag);
|
||||
float[] blueXYZ = getXYZValue(icSigBlueColorantTag);
|
||||
|
||||
m[0][0] = redXYZ[0];
|
||||
m[1][0] = redXYZ[1];
|
||||
m[2][0] = redXYZ[2];
|
||||
|
||||
m[0][1] = greenXYZ[0];
|
||||
m[1][1] = greenXYZ[1];
|
||||
m[2][1] = greenXYZ[2];
|
||||
|
||||
m[0][2] = blueXYZ[0];
|
||||
m[1][2] = blueXYZ[1];
|
||||
m[2][2] = blueXYZ[2];
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the media white point.
|
||||
*
|
||||
* @return the media white point.
|
||||
*/
|
||||
@Override
|
||||
public float[] getMediaWhitePoint() {
|
||||
return super.getMediaWhitePoint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Oleg V. Khaschansky
|
||||
* @version $Revision$
|
||||
*/
|
||||
|
||||
package java.awt.color;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
final class ICC_ProfileStub extends ICC_Profile {
|
||||
private static final long serialVersionUID = 501389760875253507L;
|
||||
|
||||
transient int colorspace;
|
||||
|
||||
public ICC_ProfileStub(int csSpecifier) {
|
||||
switch (csSpecifier) {
|
||||
case ColorSpace.CS_sRGB:
|
||||
case ColorSpace.CS_CIEXYZ:
|
||||
case ColorSpace.CS_LINEAR_RGB:
|
||||
case ColorSpace.CS_PYCC:
|
||||
case ColorSpace.CS_GRAY:
|
||||
break;
|
||||
default:
|
||||
// awt.15D=Invalid colorspace
|
||||
throw new IllegalArgumentException(Messages.getString("awt.15D")); //$NON-NLS-1$
|
||||
}
|
||||
colorspace = csSpecifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(String fileName) throws IOException {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializable implementation
|
||||
*
|
||||
* @throws ObjectStreamException
|
||||
*/
|
||||
private Object writeReplace() throws ObjectStreamException {
|
||||
return loadProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(OutputStream s) throws IOException {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(int tagSignature, byte[] tagData) {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getData(int tagSignature) {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getData() {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProfileClass() {
|
||||
return CLASS_COLORSPACECONVERSION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPCSType() {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNumComponents() {
|
||||
switch (colorspace) {
|
||||
case ColorSpace.CS_sRGB:
|
||||
case ColorSpace.CS_CIEXYZ:
|
||||
case ColorSpace.CS_LINEAR_RGB:
|
||||
case ColorSpace.CS_PYCC:
|
||||
return 3;
|
||||
case ColorSpace.CS_GRAY:
|
||||
return 1;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColorSpaceType() {
|
||||
switch (colorspace) {
|
||||
case ColorSpace.CS_sRGB:
|
||||
case ColorSpace.CS_LINEAR_RGB:
|
||||
return ColorSpace.TYPE_RGB;
|
||||
case ColorSpace.CS_CIEXYZ:
|
||||
return ColorSpace.TYPE_XYZ;
|
||||
case ColorSpace.CS_PYCC:
|
||||
return ColorSpace.TYPE_3CLR;
|
||||
case ColorSpace.CS_GRAY:
|
||||
return ColorSpace.TYPE_GRAY;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public static ICC_Profile getInstance(String fileName) throws IOException {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public static ICC_Profile getInstance(InputStream s) throws IOException {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public static ICC_Profile getInstance(byte[] data) {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public static ICC_Profile getInstance(int cspace) {
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public ICC_Profile loadProfile() {
|
||||
switch (colorspace) {
|
||||
case ColorSpace.CS_sRGB:
|
||||
return ICC_Profile.getInstance(ColorSpace.CS_sRGB);
|
||||
case ColorSpace.CS_GRAY:
|
||||
return ICC_Profile.getInstance(ColorSpace.CS_GRAY);
|
||||
case ColorSpace.CS_CIEXYZ:
|
||||
return ICC_Profile.getInstance(ColorSpace.CS_CIEXYZ);
|
||||
case ColorSpace.CS_LINEAR_RGB:
|
||||
return ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB);
|
||||
case ColorSpace.CS_PYCC:
|
||||
return ICC_Profile.getInstance(ColorSpace.CS_PYCC);
|
||||
default:
|
||||
throw new UnsupportedOperationException("Stub cannot perform this operation"); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Oleg V. Khaschansky
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.color;
|
||||
|
||||
/**
|
||||
* The ProfileDataException class represents an error which occurs while
|
||||
* accessing or processing an ICC_Profile object.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class ProfileDataException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* The Constant serialVersionUID.
|
||||
*/
|
||||
private static final long serialVersionUID = 7286140888240322498L;
|
||||
|
||||
/**
|
||||
* Instantiates a new profile data exception with detailed message.
|
||||
*
|
||||
* @param s
|
||||
* the detailed message of the exception.
|
||||
*/
|
||||
public ProfileDataException(String s) {
|
||||
super(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
<p>
|
||||
This package contains classes representing color spaces and profiles based on the International Color Consortium (ICC) Profile Format Specification.
|
||||
</p>
|
||||
@since Android 1.0
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface AWTEventListener extends EventListener {
|
||||
|
||||
public void eventDispatched(AWTEvent event);
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
|
||||
import java.util.EventListenerProxy;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class AWTEventListenerProxy extends EventListenerProxy implements AWTEventListener {
|
||||
|
||||
private AWTEventListener listener;
|
||||
private long eventMask;
|
||||
|
||||
public AWTEventListenerProxy(long eventMask, AWTEventListener listener) {
|
||||
super(listener);
|
||||
|
||||
// awt.193=Listener can't be zero
|
||||
assert listener != null : Messages.getString("awt.193"); //$NON-NLS-1$
|
||||
|
||||
this.listener = listener;
|
||||
this.eventMask = eventMask;
|
||||
}
|
||||
|
||||
public void eventDispatched(AWTEvent evt) {
|
||||
listener.eventDispatched(evt);
|
||||
}
|
||||
|
||||
public long getEventMask() {
|
||||
return eventMask;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class ActionEvent extends AWTEvent {
|
||||
|
||||
private static final long serialVersionUID = -7671078796273832149L;
|
||||
|
||||
public static final int SHIFT_MASK = 1;
|
||||
|
||||
public static final int CTRL_MASK = 2;
|
||||
|
||||
public static final int META_MASK = 4;
|
||||
|
||||
public static final int ALT_MASK = 8;
|
||||
|
||||
public static final int ACTION_FIRST = 1001;
|
||||
|
||||
public static final int ACTION_LAST = 1001;
|
||||
|
||||
public static final int ACTION_PERFORMED = 1001;
|
||||
|
||||
private long when;
|
||||
private int modifiers;
|
||||
private String command;
|
||||
|
||||
public ActionEvent(Object source, int id, String command) {
|
||||
this(source, id, command, 0);
|
||||
}
|
||||
|
||||
public ActionEvent(Object source, int id, String command, int modifiers) {
|
||||
this(source, id, command, 0l, modifiers);
|
||||
}
|
||||
|
||||
public ActionEvent(Object source, int id, String command, long when, int modifiers) {
|
||||
super(source, id);
|
||||
|
||||
this.command = command;
|
||||
this.when = when;
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
public int getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
public String getActionCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
public long getWhen() {
|
||||
return when;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String paramString() {
|
||||
/* The format is based on 1.5 release behavior
|
||||
* which can be revealed by the following code:
|
||||
*
|
||||
* ActionEvent e = new ActionEvent(new Component(){},
|
||||
* ActionEvent.ACTION_PERFORMED, "Command",
|
||||
* ActionEvent.SHIFT_MASK|ActionEvent.CTRL_MASK|
|
||||
* ActionEvent.META_MASK|ActionEvent.ALT_MASK);
|
||||
* System.out.println(e);
|
||||
*/
|
||||
|
||||
String idString = (id == ACTION_PERFORMED) ?
|
||||
"ACTION_PERFORMED" : "unknown type"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String modifiersString = ""; //$NON-NLS-1$
|
||||
|
||||
if ((modifiers & SHIFT_MASK) > 0) {
|
||||
modifiersString += "Shift"; //$NON-NLS-1$
|
||||
}
|
||||
if ((modifiers & CTRL_MASK) > 0) {
|
||||
modifiersString += modifiersString.length() == 0 ? "Ctrl" : "+Ctrl"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
if ((modifiers & META_MASK) > 0) {
|
||||
modifiersString += modifiersString.length() == 0 ? "Meta" : "+Meta"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
if ((modifiers & ALT_MASK) > 0) {
|
||||
modifiersString += modifiersString.length() == 0 ? "Alt" : "+Alt"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
return (idString + ",cmd=" + command + ",when=" + when + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
",modifiers=" + modifiersString); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface ActionListener extends EventListener {
|
||||
|
||||
public void actionPerformed(ActionEvent e);
|
||||
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Adjustable;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class AdjustmentEvent extends AWTEvent {
|
||||
|
||||
private static final long serialVersionUID = 5700290645205279921L;
|
||||
|
||||
public static final int ADJUSTMENT_FIRST = 601;
|
||||
|
||||
public static final int ADJUSTMENT_LAST = 601;
|
||||
|
||||
public static final int ADJUSTMENT_VALUE_CHANGED = 601;
|
||||
|
||||
public static final int UNIT_INCREMENT = 1;
|
||||
|
||||
public static final int UNIT_DECREMENT = 2;
|
||||
|
||||
public static final int BLOCK_DECREMENT = 3;
|
||||
|
||||
public static final int BLOCK_INCREMENT = 4;
|
||||
|
||||
public static final int TRACK = 5;
|
||||
|
||||
private int type;
|
||||
private int value;
|
||||
private boolean isAdjusting;
|
||||
|
||||
public AdjustmentEvent(Adjustable source, int id, int type, int value) {
|
||||
this(source, id, type, value, false);
|
||||
}
|
||||
|
||||
public AdjustmentEvent(Adjustable source, int id, int type, int value,
|
||||
boolean isAdjusting) {
|
||||
super(source, id);
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.isAdjusting = isAdjusting;
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getAdjustmentType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public boolean getValueIsAdjusting() {
|
||||
return isAdjusting;
|
||||
}
|
||||
|
||||
public Adjustable getAdjustable() {
|
||||
return (Adjustable) source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String paramString() {
|
||||
/* The format is based on 1.5 release behavior
|
||||
* which can be revealed by the following code:
|
||||
*
|
||||
* AdjustmentEvent e = new AdjustmentEvent(new Scrollbar(),
|
||||
* AdjustmentEvent.ADJUSTMENT_VALUE_CHANGED,
|
||||
* AdjustmentEvent.UNIT_INCREMENT, 1);
|
||||
* System.out.println(e);
|
||||
*/
|
||||
|
||||
String idString = (id == ADJUSTMENT_VALUE_CHANGED ?
|
||||
"ADJUSTMENT_VALUE_CHANGED" : "unknown type"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
String adjType = null;
|
||||
|
||||
switch (type) {
|
||||
case UNIT_INCREMENT:
|
||||
adjType = "UNIT_INCREMENT"; //$NON-NLS-1$
|
||||
break;
|
||||
case UNIT_DECREMENT:
|
||||
adjType = "UNIT_DECREMENT"; //$NON-NLS-1$
|
||||
break;
|
||||
case BLOCK_INCREMENT:
|
||||
adjType = "BLOCK_INCREMENT"; //$NON-NLS-1$
|
||||
break;
|
||||
case BLOCK_DECREMENT:
|
||||
adjType = "BLOCK_DECREMENT"; //$NON-NLS-1$
|
||||
break;
|
||||
case TRACK:
|
||||
adjType = "TRACK"; //$NON-NLS-1$
|
||||
break;
|
||||
default:
|
||||
adjType = "unknown type"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return (idString + ",adjType=" + adjType + ",value=" + value + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
",isAdjusting=" + isAdjusting); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface AdjustmentListener extends EventListener {
|
||||
|
||||
public void adjustmentValueChanged(AdjustmentEvent e);
|
||||
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class ComponentAdapter implements ComponentListener {
|
||||
|
||||
public ComponentAdapter() {
|
||||
}
|
||||
|
||||
public void componentHidden(ComponentEvent e) {
|
||||
}
|
||||
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
}
|
||||
|
||||
public void componentResized(ComponentEvent e) {
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent e) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Component;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class ComponentEvent extends AWTEvent {
|
||||
|
||||
private static final long serialVersionUID = 8101406823902992965L;
|
||||
|
||||
public static final int COMPONENT_FIRST = 100;
|
||||
|
||||
public static final int COMPONENT_LAST = 103;
|
||||
|
||||
public static final int COMPONENT_MOVED = 100;
|
||||
|
||||
public static final int COMPONENT_RESIZED = 101;
|
||||
|
||||
public static final int COMPONENT_SHOWN = 102;
|
||||
|
||||
public static final int COMPONENT_HIDDEN = 103;
|
||||
|
||||
public ComponentEvent(Component source, int id) {
|
||||
super(source, id);
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return (Component) source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String paramString() {
|
||||
/* The format is based on 1.5 release behavior
|
||||
* which can be revealed by the following code:
|
||||
*
|
||||
* ComponentEvent e = new ComponentEvent(new Button("Button"),
|
||||
* ComponentEvent.COMPONENT_SHOWN);
|
||||
* System.out.println(e);
|
||||
*/
|
||||
|
||||
String idString = null;
|
||||
Component c = getComponent();
|
||||
|
||||
switch (id) {
|
||||
case COMPONENT_MOVED:
|
||||
idString = "COMPONENT_MOVED"; //$NON-NLS-1$
|
||||
break;
|
||||
case COMPONENT_RESIZED:
|
||||
idString = "COMPONENT_RESIZED"; //$NON-NLS-1$
|
||||
break;
|
||||
case COMPONENT_SHOWN:
|
||||
return "COMPONENT_SHOWN"; //$NON-NLS-1$
|
||||
case COMPONENT_HIDDEN:
|
||||
return "COMPONENT_HIDDEN"; //$NON-NLS-1$
|
||||
default:
|
||||
return "unknown type"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return (idString + " (" + c.getX() + "," + c.getY() + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
" " + c.getWidth()+ "x" + c.getHeight() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface ComponentListener extends EventListener {
|
||||
|
||||
public void componentHidden(ComponentEvent e);
|
||||
|
||||
public void componentMoved(ComponentEvent e);
|
||||
|
||||
public void componentResized(ComponentEvent e);
|
||||
|
||||
public void componentShown(ComponentEvent e);
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class ContainerAdapter implements ContainerListener {
|
||||
|
||||
public ContainerAdapter() {
|
||||
}
|
||||
|
||||
public void componentAdded(ContainerEvent e) {
|
||||
}
|
||||
|
||||
public void componentRemoved(ContainerEvent e) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.Component;
|
||||
//???AWT: import java.awt.Container;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class ContainerEvent extends ComponentEvent {
|
||||
|
||||
private static final long serialVersionUID = -4114942250539772041L;
|
||||
|
||||
public static final int CONTAINER_FIRST = 300;
|
||||
|
||||
public static final int CONTAINER_LAST = 301;
|
||||
|
||||
public static final int COMPONENT_ADDED = 300;
|
||||
|
||||
public static final int COMPONENT_REMOVED = 301;
|
||||
|
||||
private Component child;
|
||||
|
||||
public ContainerEvent(Component src, int id, Component child) {
|
||||
super(src, id);
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
public Component getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
//???AWT
|
||||
/*
|
||||
public Container getContainer() {
|
||||
return (Container) source;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String paramString() {
|
||||
/* The format is based on 1.5 release behavior
|
||||
* which can be revealed by the following code:
|
||||
*
|
||||
* ContainerEvent e = new ContainerEvent(new Panel(),
|
||||
* ContainerEvent.COMPONENT_ADDED,
|
||||
* new Button("Button"));
|
||||
* System.out.println(e);
|
||||
*/
|
||||
|
||||
String idString = null;
|
||||
|
||||
switch (id) {
|
||||
case COMPONENT_ADDED:
|
||||
idString = "COMPONENT_ADDED"; //$NON-NLS-1$
|
||||
break;
|
||||
case COMPONENT_REMOVED:
|
||||
idString = "COMPONENT_REMOVED"; //$NON-NLS-1$
|
||||
break;
|
||||
default:
|
||||
idString = "unknown type"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return (idString + ",child=" + child.getName()); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface ContainerListener extends EventListener {
|
||||
|
||||
public void componentAdded(ContainerEvent e);
|
||||
|
||||
public void componentRemoved(ContainerEvent e);
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class FocusAdapter implements FocusListener {
|
||||
|
||||
public FocusAdapter() {
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent e) {
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class FocusEvent extends ComponentEvent {
|
||||
|
||||
private static final long serialVersionUID = 523753786457416396L;
|
||||
|
||||
public static final int FOCUS_FIRST = 1004;
|
||||
|
||||
public static final int FOCUS_LAST = 1005;
|
||||
|
||||
public static final int FOCUS_GAINED = 1004;
|
||||
|
||||
public static final int FOCUS_LOST = 1005;
|
||||
|
||||
private boolean temporary;
|
||||
private Component opposite;
|
||||
|
||||
public FocusEvent(Component source, int id) {
|
||||
this(source, id, false);
|
||||
}
|
||||
|
||||
public FocusEvent(Component source, int id, boolean temporary) {
|
||||
this(source, id, temporary, null);
|
||||
}
|
||||
|
||||
public FocusEvent(Component source, int id, boolean temporary, Component opposite) {
|
||||
super(source, id);
|
||||
this.temporary = temporary;
|
||||
this.opposite = opposite;
|
||||
}
|
||||
|
||||
public Component getOppositeComponent() {
|
||||
return opposite;
|
||||
}
|
||||
|
||||
public boolean isTemporary() {
|
||||
return temporary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String paramString() {
|
||||
/* The format is based on 1.5 release behavior
|
||||
* which can be revealed by the following code:
|
||||
*
|
||||
* FocusEvent e = new FocusEvent(new Button("Button0"),
|
||||
* FocusEvent.FOCUS_GAINED, false, new Button("Button1"));
|
||||
* System.out.println(e);
|
||||
*/
|
||||
|
||||
String idString = null;
|
||||
|
||||
switch (id) {
|
||||
case FOCUS_GAINED:
|
||||
idString = "FOCUS_GAINED"; //$NON-NLS-1$
|
||||
break;
|
||||
case FOCUS_LOST:
|
||||
idString = "FOCUS_LOST"; //$NON-NLS-1$
|
||||
break;
|
||||
default:
|
||||
idString = "unknown type"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return (idString +
|
||||
(temporary ? ",temporary" : ",permanent") + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
",opposite=" + opposite); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface FocusListener extends EventListener {
|
||||
|
||||
public void focusGained(FocusEvent e);
|
||||
|
||||
public void focusLost(FocusEvent e);
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class HierarchyBoundsAdapter implements HierarchyBoundsListener {
|
||||
|
||||
public HierarchyBoundsAdapter() {
|
||||
}
|
||||
|
||||
public void ancestorMoved(HierarchyEvent e) {
|
||||
}
|
||||
|
||||
public void ancestorResized(HierarchyEvent e) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface HierarchyBoundsListener extends EventListener {
|
||||
|
||||
public void ancestorMoved(HierarchyEvent e);
|
||||
|
||||
public void ancestorResized(HierarchyEvent e);
|
||||
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Component;
|
||||
//???AWT: import java.awt.Container;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class HierarchyEvent extends AWTEvent {
|
||||
|
||||
private static final long serialVersionUID = -5337576970038043990L;
|
||||
|
||||
public static final int HIERARCHY_FIRST = 1400;
|
||||
|
||||
public static final int HIERARCHY_CHANGED = 1400;
|
||||
|
||||
public static final int ANCESTOR_MOVED = 1401;
|
||||
|
||||
public static final int ANCESTOR_RESIZED = 1402;
|
||||
|
||||
public static final int HIERARCHY_LAST = 1402;
|
||||
|
||||
public static final int PARENT_CHANGED = 1;
|
||||
|
||||
public static final int DISPLAYABILITY_CHANGED = 2;
|
||||
|
||||
public static final int SHOWING_CHANGED = 4;
|
||||
|
||||
//???AWT: private Container changedParent;
|
||||
private Component changed;
|
||||
private long changeFlag;
|
||||
|
||||
//???AWT
|
||||
/*
|
||||
public HierarchyEvent(Component source, int id, Component changed,
|
||||
Container changedParent) {
|
||||
this(source, id, changed, changedParent, 0l);
|
||||
}
|
||||
*/
|
||||
|
||||
//???AWT
|
||||
/*
|
||||
public HierarchyEvent(Component source, int id, Component changed,
|
||||
Container changedParent, long changeFlags) {
|
||||
super(source, id);
|
||||
|
||||
this.changed = changed;
|
||||
this.changedParent = changedParent;
|
||||
this.changeFlag = changeFlags;
|
||||
}
|
||||
*/
|
||||
//???AWT: Fake constructor, should be as above.
|
||||
public HierarchyEvent(Component source, int id, Component changed,
|
||||
Object changedParent, long changeFlags) {
|
||||
super(source, id);
|
||||
|
||||
// this.changed = changed;
|
||||
// this.changedParent = changedParent;
|
||||
// this.changeFlag = changeFlags;
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return (Component) source;
|
||||
}
|
||||
|
||||
public long getChangeFlags() {
|
||||
return changeFlag;
|
||||
}
|
||||
|
||||
public Component getChanged() {
|
||||
return changed;
|
||||
}
|
||||
|
||||
//???AWT
|
||||
/*
|
||||
public Container getChangedParent() {
|
||||
return changedParent;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public String paramString() {
|
||||
/* The format is based on 1.5 release behavior
|
||||
* which can be revealed by the following code:
|
||||
*
|
||||
* HierarchyEvent e = new HierarchyEvent(new Button("Button"),
|
||||
* HierarchyEvent.HIERARCHY_CHANGED,
|
||||
* new Panel(), new Container());
|
||||
* System.out.println(e);
|
||||
*/
|
||||
String paramString = null;
|
||||
|
||||
switch (id) {
|
||||
case HIERARCHY_CHANGED:
|
||||
paramString = "HIERARCHY_CHANGED"; //$NON-NLS-1$
|
||||
break;
|
||||
case ANCESTOR_MOVED:
|
||||
paramString = "ANCESTOR_MOVED"; //$NON-NLS-1$
|
||||
break;
|
||||
case ANCESTOR_RESIZED:
|
||||
paramString = "ANCESTOR_RESIZED"; //$NON-NLS-1$
|
||||
break;
|
||||
default:
|
||||
paramString = "unknown type"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
paramString += " ("; //$NON-NLS-1$
|
||||
|
||||
if (id == HIERARCHY_CHANGED) {
|
||||
if ((changeFlag & PARENT_CHANGED) > 0) {
|
||||
paramString += "PARENT_CHANGED,"; //$NON-NLS-1$
|
||||
}
|
||||
if ((changeFlag & DISPLAYABILITY_CHANGED) > 0) {
|
||||
paramString += "DISPLAYABILITY_CHANGED,"; //$NON-NLS-1$
|
||||
}
|
||||
if ((changeFlag & SHOWING_CHANGED) > 0) {
|
||||
paramString += "SHOWING_CHANGED,"; //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
//???AWT
|
||||
/*
|
||||
return paramString + "changed=" + changed + //$NON-NLS-1$
|
||||
",changedParent=" + changedParent + ")"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
*/
|
||||
return paramString;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface HierarchyListener extends EventListener {
|
||||
|
||||
public void hierarchyChanged(HierarchyEvent e);
|
||||
|
||||
}
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.Component;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public abstract class InputEvent extends ComponentEvent {
|
||||
|
||||
private static final long serialVersionUID = -2482525981698309786L;
|
||||
|
||||
public static final int SHIFT_MASK = 1;
|
||||
|
||||
public static final int CTRL_MASK = 2;
|
||||
|
||||
public static final int META_MASK = 4;
|
||||
|
||||
public static final int ALT_MASK = 8;
|
||||
|
||||
public static final int ALT_GRAPH_MASK = 32;
|
||||
|
||||
public static final int BUTTON1_MASK = 16;
|
||||
|
||||
public static final int BUTTON2_MASK = 8;
|
||||
|
||||
public static final int BUTTON3_MASK = 4;
|
||||
|
||||
public static final int SHIFT_DOWN_MASK = 64;
|
||||
|
||||
public static final int CTRL_DOWN_MASK = 128;
|
||||
|
||||
public static final int META_DOWN_MASK = 256;
|
||||
|
||||
public static final int ALT_DOWN_MASK = 512;
|
||||
|
||||
public static final int BUTTON1_DOWN_MASK = 1024;
|
||||
|
||||
public static final int BUTTON2_DOWN_MASK = 2048;
|
||||
|
||||
public static final int BUTTON3_DOWN_MASK = 4096;
|
||||
|
||||
public static final int ALT_GRAPH_DOWN_MASK = 8192;
|
||||
|
||||
private static final int DOWN_MASKS = SHIFT_DOWN_MASK | CTRL_DOWN_MASK |
|
||||
META_DOWN_MASK | ALT_DOWN_MASK | BUTTON1_DOWN_MASK |
|
||||
BUTTON2_DOWN_MASK | BUTTON3_DOWN_MASK | ALT_GRAPH_DOWN_MASK;
|
||||
|
||||
private long when;
|
||||
private int modifiersEx;
|
||||
|
||||
public static String getModifiersExText(int modifiers/*Ex*/) {
|
||||
return MouseEvent.addMouseModifiersExText(
|
||||
KeyEvent.getKeyModifiersExText(modifiers), modifiers);
|
||||
}
|
||||
|
||||
static int extractExFlags(int modifiers) {
|
||||
int exFlags = modifiers & DOWN_MASKS;
|
||||
|
||||
if ((modifiers & SHIFT_MASK) != 0) {
|
||||
exFlags |= SHIFT_DOWN_MASK;
|
||||
}
|
||||
if ((modifiers & CTRL_MASK) != 0) {
|
||||
exFlags |= CTRL_DOWN_MASK;
|
||||
}
|
||||
if ((modifiers & META_MASK) != 0) {
|
||||
exFlags |= META_DOWN_MASK;
|
||||
}
|
||||
if ((modifiers & ALT_MASK) != 0) {
|
||||
exFlags |= ALT_DOWN_MASK;
|
||||
}
|
||||
if ((modifiers & ALT_GRAPH_MASK) != 0) {
|
||||
exFlags |= ALT_GRAPH_DOWN_MASK;
|
||||
}
|
||||
if ((modifiers & BUTTON1_MASK) != 0) {
|
||||
exFlags |= BUTTON1_DOWN_MASK;
|
||||
}
|
||||
if ((modifiers & BUTTON2_MASK) != 0) {
|
||||
exFlags |= BUTTON2_DOWN_MASK;
|
||||
}
|
||||
if ((modifiers & BUTTON3_MASK) != 0) {
|
||||
exFlags |= BUTTON3_DOWN_MASK;
|
||||
}
|
||||
|
||||
return exFlags;
|
||||
}
|
||||
|
||||
InputEvent(Component source, int id, long when, int modifiers) {
|
||||
super(source, id);
|
||||
|
||||
this.when = when;
|
||||
modifiersEx = extractExFlags(modifiers);
|
||||
}
|
||||
|
||||
public int getModifiers() {
|
||||
int modifiers = 0;
|
||||
|
||||
if ((modifiersEx & SHIFT_DOWN_MASK) != 0) {
|
||||
modifiers |= SHIFT_MASK;
|
||||
}
|
||||
if ((modifiersEx & CTRL_DOWN_MASK) != 0) {
|
||||
modifiers |= CTRL_MASK;
|
||||
}
|
||||
if ((modifiersEx & META_DOWN_MASK) != 0) {
|
||||
modifiers |= META_MASK;
|
||||
}
|
||||
if ((modifiersEx & ALT_DOWN_MASK) != 0) {
|
||||
modifiers |= ALT_MASK;
|
||||
}
|
||||
if ((modifiersEx & ALT_GRAPH_DOWN_MASK) != 0) {
|
||||
modifiers |= ALT_GRAPH_MASK;
|
||||
}
|
||||
if ((modifiersEx & BUTTON1_DOWN_MASK) != 0) {
|
||||
modifiers |= BUTTON1_MASK;
|
||||
}
|
||||
if ((modifiersEx & BUTTON2_DOWN_MASK) != 0) {
|
||||
modifiers |= BUTTON2_MASK;
|
||||
}
|
||||
if ((modifiersEx & BUTTON3_DOWN_MASK) != 0) {
|
||||
modifiers |= BUTTON3_MASK;
|
||||
}
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
public int getModifiersEx() {
|
||||
return modifiersEx;
|
||||
}
|
||||
|
||||
void setModifiers(int modifiers) {
|
||||
modifiersEx = extractExFlags(modifiers);
|
||||
}
|
||||
|
||||
public boolean isAltDown() {
|
||||
return ((modifiersEx & ALT_DOWN_MASK) != 0);
|
||||
}
|
||||
|
||||
public boolean isAltGraphDown() {
|
||||
return ((modifiersEx & ALT_GRAPH_DOWN_MASK) != 0);
|
||||
}
|
||||
|
||||
public boolean isControlDown() {
|
||||
return ((modifiersEx & CTRL_DOWN_MASK) != 0);
|
||||
}
|
||||
|
||||
public boolean isMetaDown() {
|
||||
return ((modifiersEx & META_DOWN_MASK) != 0);
|
||||
}
|
||||
|
||||
public boolean isShiftDown() {
|
||||
return ((modifiersEx & SHIFT_DOWN_MASK) != 0);
|
||||
}
|
||||
|
||||
public long getWhen() {
|
||||
return when;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consume() {
|
||||
super.consume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsumed() {
|
||||
return super.isConsumed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Component;
|
||||
import java.awt.font.TextHitInfo;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class InputMethodEvent extends AWTEvent {
|
||||
|
||||
private static final long serialVersionUID = 4727190874778922661L;
|
||||
|
||||
public static final int INPUT_METHOD_FIRST = 1100;
|
||||
|
||||
public static final int INPUT_METHOD_TEXT_CHANGED = 1100;
|
||||
|
||||
public static final int CARET_POSITION_CHANGED = 1101;
|
||||
|
||||
public static final int INPUT_METHOD_LAST = 1101;
|
||||
|
||||
private AttributedCharacterIterator text;
|
||||
private TextHitInfo visiblePosition;
|
||||
private TextHitInfo caret;
|
||||
private int committedCharacterCount;
|
||||
private long when;
|
||||
|
||||
public InputMethodEvent(Component src, int id,
|
||||
TextHitInfo caret,
|
||||
TextHitInfo visiblePos) {
|
||||
this(src, id, null, 0, caret, visiblePos);
|
||||
}
|
||||
|
||||
public InputMethodEvent(Component src, int id,
|
||||
AttributedCharacterIterator text,
|
||||
int commitedCharCount,
|
||||
TextHitInfo caret,
|
||||
TextHitInfo visiblePos) {
|
||||
this(src, id, 0l, text, commitedCharCount, caret, visiblePos);
|
||||
}
|
||||
|
||||
public InputMethodEvent(Component src, int id, long when,
|
||||
AttributedCharacterIterator text,
|
||||
int committedCharacterCount,
|
||||
TextHitInfo caret,
|
||||
TextHitInfo visiblePos) {
|
||||
super(src, id);
|
||||
|
||||
if ((id < INPUT_METHOD_FIRST) || (id > INPUT_METHOD_LAST)) {
|
||||
// awt.18E=Wrong event id
|
||||
throw new IllegalArgumentException(Messages.getString("awt.18E")); //$NON-NLS-1$
|
||||
}
|
||||
if ((id == CARET_POSITION_CHANGED) && (text != null)) {
|
||||
// awt.18F=Text must be null for CARET_POSITION_CHANGED
|
||||
throw new IllegalArgumentException(Messages.getString("awt.18F")); //$NON-NLS-1$
|
||||
}
|
||||
if ((text != null) &&
|
||||
((committedCharacterCount < 0) ||
|
||||
(committedCharacterCount >
|
||||
(text.getEndIndex() - text.getBeginIndex())))) {
|
||||
// awt.190=Wrong committedCharacterCount
|
||||
throw new IllegalArgumentException(Messages.getString("awt.190")); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
this.when = when;
|
||||
this.text = text;
|
||||
this.caret = caret;
|
||||
this.visiblePosition = visiblePos;
|
||||
this.committedCharacterCount = committedCharacterCount;
|
||||
}
|
||||
|
||||
public TextHitInfo getCaret() {
|
||||
return caret;
|
||||
}
|
||||
|
||||
public int getCommittedCharacterCount() {
|
||||
return committedCharacterCount;
|
||||
}
|
||||
|
||||
public AttributedCharacterIterator getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public TextHitInfo getVisiblePosition() {
|
||||
return visiblePosition;
|
||||
}
|
||||
|
||||
public long getWhen() {
|
||||
return when;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void consume() {
|
||||
super.consume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConsumed() {
|
||||
return super.isConsumed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String paramString() {
|
||||
/* The format is based on 1.5 release behavior
|
||||
* which can be revealed by the following code:
|
||||
*
|
||||
* InputMethodEvent e = new InputMethodEvent(new Component(){},
|
||||
* InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
|
||||
* TextHitInfo.leading(1), TextHitInfo.trailing(2));
|
||||
* System.out.println(e);
|
||||
*/
|
||||
String typeString = null;
|
||||
|
||||
switch (id) {
|
||||
case INPUT_METHOD_TEXT_CHANGED:
|
||||
typeString = "INPUT_METHOD_TEXT_CHANGED"; //$NON-NLS-1$
|
||||
break;
|
||||
case CARET_POSITION_CHANGED:
|
||||
typeString = "CARET_POSITION_CHANGED"; //$NON-NLS-1$
|
||||
break;
|
||||
default:
|
||||
typeString = "unknown type"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return typeString + ",text=" + text + //$NON-NLS-1$
|
||||
",commitedCharCount=" + committedCharacterCount + //$NON-NLS-1$
|
||||
",caret=" + caret + ",visiblePosition=" + visiblePosition; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public interface InputMethodListener extends EventListener {
|
||||
|
||||
public void caretPositionChanged(InputMethodEvent e);
|
||||
|
||||
public void inputMethodTextChanged(InputMethodEvent e);
|
||||
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.ActiveEvent;
|
||||
|
||||
import org.apache.harmony.awt.internal.nls.Messages;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class InvocationEvent extends AWTEvent implements ActiveEvent {
|
||||
|
||||
private static final long serialVersionUID = 436056344909459450L;
|
||||
|
||||
public static final int INVOCATION_FIRST = 1200;
|
||||
|
||||
public static final int INVOCATION_DEFAULT = 1200;
|
||||
|
||||
public static final int INVOCATION_LAST = 1200;
|
||||
|
||||
protected Runnable runnable;
|
||||
|
||||
protected Object notifier;
|
||||
|
||||
protected boolean catchExceptions;
|
||||
|
||||
private long when;
|
||||
private Throwable throwable;
|
||||
|
||||
public InvocationEvent(Object source, Runnable runnable) {
|
||||
this(source, runnable, null, false);
|
||||
}
|
||||
|
||||
public InvocationEvent(Object source, Runnable runnable,
|
||||
Object notifier, boolean catchExceptions) {
|
||||
this(source, INVOCATION_DEFAULT, runnable, notifier, catchExceptions);
|
||||
}
|
||||
|
||||
protected InvocationEvent(Object source, int id, Runnable runnable,
|
||||
Object notifier, boolean catchExceptions)
|
||||
{
|
||||
super(source, id);
|
||||
|
||||
// awt.18C=Cannot invoke null runnable
|
||||
assert runnable != null : Messages.getString("awt.18C"); //$NON-NLS-1$
|
||||
|
||||
if (source == null) {
|
||||
// awt.18D=Source is null
|
||||
throw new IllegalArgumentException(Messages.getString("awt.18D")); //$NON-NLS-1$
|
||||
}
|
||||
this.runnable = runnable;
|
||||
this.notifier = notifier;
|
||||
this.catchExceptions = catchExceptions;
|
||||
|
||||
throwable = null;
|
||||
when = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void dispatch() {
|
||||
if (!catchExceptions) {
|
||||
runAndNotify();
|
||||
} else {
|
||||
try {
|
||||
runAndNotify();
|
||||
} catch (Throwable t) {
|
||||
throwable = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void runAndNotify() {
|
||||
if (notifier != null) {
|
||||
synchronized(notifier) {
|
||||
try {
|
||||
runnable.run();
|
||||
} finally {
|
||||
notifier.notifyAll();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
public Exception getException() {
|
||||
return (throwable != null && throwable instanceof Exception) ?
|
||||
(Exception)throwable : null;
|
||||
}
|
||||
|
||||
public Throwable getThrowable() {
|
||||
return throwable;
|
||||
}
|
||||
|
||||
public long getWhen() {
|
||||
return when;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String paramString() {
|
||||
/* The format is based on 1.5 release behavior
|
||||
* which can be revealed by the following code:
|
||||
*
|
||||
* InvocationEvent e = new InvocationEvent(new Component(){},
|
||||
* new Runnable() { public void run(){} });
|
||||
* System.out.println(e);
|
||||
*/
|
||||
|
||||
return ((id == INVOCATION_DEFAULT ? "INVOCATION_DEFAULT" : "unknown type") + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
",runnable=" + runnable + //$NON-NLS-1$
|
||||
",notifier=" + notifier + //$NON-NLS-1$
|
||||
",catchExceptions=" + catchExceptions + //$NON-NLS-1$
|
||||
",when=" + when); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/**
|
||||
* @author Michael Danilov
|
||||
* @version $Revision$
|
||||
*/
|
||||
package java.awt.event;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.ItemSelectable;
|
||||
|
||||
/**
|
||||
* This class is not supported in Android 1.0. It is merely provided to maintain
|
||||
* interface compatibility with desktop Java implementations.
|
||||
*
|
||||
* @since Android 1.0
|
||||
*/
|
||||
public class ItemEvent extends AWTEvent {
|
||||
|
||||
private static final long serialVersionUID = -608708132447206933L;
|
||||
|
||||
public static final int ITEM_FIRST = 701;
|
||||
|
||||
public static final int ITEM_LAST = 701;
|
||||
|
||||
public static final int ITEM_STATE_CHANGED = 701;
|
||||
|
||||
public static final int SELECTED = 1;
|
||||
|
||||
public static final int DESELECTED = 2;
|
||||
|
||||
private Object item;
|
||||
private int stateChange;
|
||||
|
||||
public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) {
|
||||
super(source, id);
|
||||
|
||||
this.item = item;
|
||||
this.stateChange = stateChange;
|
||||
}
|
||||
|
||||
public Object getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public int getStateChange() {
|
||||
return stateChange;
|
||||
}
|
||||
|
||||
public ItemSelectable getItemSelectable() {
|
||||
return (ItemSelectable) source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String paramString() {
|
||||
/* The format is based on 1.5 release behavior
|
||||
* which can be revealed by the following code:
|
||||
*
|
||||
* Checkbox c = new Checkbox("Checkbox", true);
|
||||
* ItemEvent e = new ItemEvent(c, ItemEvent.ITEM_STATE_CHANGED,
|
||||
* c, ItemEvent.SELECTED);
|
||||
* System.out.println(e);
|
||||
*/
|
||||
|
||||
String stateString = null;
|
||||
|
||||
switch (stateChange) {
|
||||
case SELECTED:
|
||||
stateString = "SELECTED"; //$NON-NLS-1$
|
||||
break;
|
||||
case DESELECTED:
|
||||
stateString = "DESELECTED"; //$NON-NLS-1$
|
||||
break;
|
||||
default:
|
||||
stateString = "unknown type"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
return ((id == ITEM_STATE_CHANGED ? "ITEM_STATE_CHANGED" : "unknown type") + //$NON-NLS-1$ //$NON-NLS-2$
|
||||
",item=" + item + ",stateChange=" + stateString); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user