mirror of
https://github.com/2009scape/2009Scape-mobile.git
synced 2026-08-01 14:19:12 -06:00
AWT
This commit is contained in:
parent
acaed5a179
commit
368fa5d305
22 changed files with 2471 additions and 64 deletions
Binary file not shown.
|
|
@ -4,36 +4,29 @@ import java.awt.image.*;
|
|||
import net.kdt.pojavlaunch.*;
|
||||
|
||||
public class Canvas extends Component {
|
||||
private Graphics mGraphics;
|
||||
private Dimension mSize;
|
||||
private Graphics graphics;
|
||||
|
||||
public Canvas() {
|
||||
mSize = new Dimension(1280, 720);
|
||||
mGraphics = new Graphics(new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB));
|
||||
graphics = new Graphics(new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB));
|
||||
}
|
||||
|
||||
public void setPreferredSize(Dimension dim){
|
||||
mSize = dim;
|
||||
}
|
||||
|
||||
public void setFocusTraversalKeysEnabled(boolean b) {
|
||||
System.out.println("java.awt.Canvas.setFocusTraversalKeysEnabled(" + b + ")");
|
||||
}
|
||||
|
||||
public boolean isDisplayable(){
|
||||
return true;
|
||||
}
|
||||
|
||||
public Graphics getGraphics() {
|
||||
return mGraphics;
|
||||
return graphics;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return (int) mSize.getWidth();
|
||||
return 1280;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return (int) mSize.getHeight();
|
||||
return 720;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import java.awt.mod.*;
|
|||
|
||||
public class Desktop
|
||||
{
|
||||
private Activity currentActivity;
|
||||
private MainActivity currentActivity;
|
||||
public enum Action
|
||||
{
|
||||
BROWSE, EDIT, MAIL, OPEN, PRINT
|
||||
|
|
@ -22,36 +22,43 @@ public class Desktop
|
|||
public Desktop()
|
||||
{
|
||||
peer = Toolkit.getDefaultToolkit().createDesktopPeer();
|
||||
try {
|
||||
try
|
||||
{
|
||||
if (currentActivity == null) currentActivity = ModdingKit.getCurrentActivity();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Desktop getDesktop() {
|
||||
public static Desktop getDesktop()
|
||||
{
|
||||
return new Desktop();
|
||||
}
|
||||
|
||||
public static boolean isDesktopSupported() {
|
||||
public static boolean isDesktopSupported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isSupported(Action action) {
|
||||
public boolean isSupported(Action action)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void browse(URI uri) {
|
||||
public void browse(URI uri)
|
||||
{
|
||||
try {
|
||||
URL url = uri.toURL();
|
||||
if(url.toString().startsWith("file:")){
|
||||
String fPath = url.toString().replace("file:", "");
|
||||
System.out.println("PojavLauncher:java.awt.Desktop: Browse folder: " + fPath);
|
||||
Log.d("MineDebug:java.awt.Desktop", "Browse folder: " + fPath);
|
||||
|
||||
// Current not implemented
|
||||
}
|
||||
else{
|
||||
System.out.println("PojavLauncher:java.awt.Desktop: Browse URL: " + url.toString());
|
||||
Log.d("MineDebug:java.awt.Desktop", "Browse URL: " + url.toString());
|
||||
if (!url.toString().startsWith("http://") && !url.toString().startsWith("https://")){
|
||||
url = new URL("http://" + url.toString());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package java.awt;
|
||||
|
||||
import android.graphics.*;
|
||||
import java.awt.image.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
public class Graphics {
|
||||
private Paint androidPaint;
|
||||
|
|
@ -32,24 +33,10 @@ public class Graphics {
|
|||
}
|
||||
|
||||
public boolean drawImage(Image image, int x, int y, ImageObserver observer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean drawImage(Image image, ImageObserver observer) {
|
||||
return drawImage(image, 0, 0, observer);
|
||||
}
|
||||
|
||||
public boolean drawImage(Image image, int x, int y, int width, int height, ImageObserver observer) {
|
||||
return drawImage(image, x ,y ,x + width, y + height, observer);
|
||||
}
|
||||
|
||||
public boolean drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) {
|
||||
if (image instanceof BufferedImage) {
|
||||
((BufferedImage) image).getAndroidBitmap().reconfigure(dx2 - dx1, dy2 - dy1, Bitmap.Config.ARGB_8888);
|
||||
this.androidCanvas.drawBitmap(((BufferedImage) image).getAndroidBitmap(), (float) dx1, (float) dy1, null);
|
||||
return true;
|
||||
if (image instanceof BufferedImage) {
|
||||
this.androidCanvas.drawBitmap(((BufferedImage) image).getAndroidBitmap(), (float) x, (float) y, null);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
57
app/src/main/java/java/awt/Paint.java
Normal file
57
app/src/main/java/java/awt/Paint.java
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
69
app/src/main/java/java/awt/PaintContext.java
Normal file
69
app/src/main/java/java/awt/PaintContext.java
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
515
app/src/main/java/java/awt/Polygon.java
Normal file
515
app/src/main/java/java/awt/Polygon.java
Normal file
|
|
@ -0,0 +1,515 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
606
app/src/main/java/java/awt/RenderingHints.java
Normal file
606
app/src/main/java/java/awt/RenderingHints.java
Normal file
|
|
@ -0,0 +1,606 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
50
app/src/main/java/java/awt/Stroke.java
Normal file
50
app/src/main/java/java/awt/Stroke.java
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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);
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ public class Clipboard extends Object
|
|||
public void run()
|
||||
{
|
||||
ClipboardManager clipboard = (ClipboardManager) act.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = ClipData.newPlainText("Minecraft", ((StringSelection) contents).getString());
|
||||
ClipData clip = ClipData.newPlainText("Copied text", ((StringSelection) contents).getString());
|
||||
clipboard.setPrimaryClip(clip);
|
||||
|
||||
Toast.makeText(act, "Copied to clipboard!", Toast.LENGTH_SHORT).show();
|
||||
|
|
@ -30,15 +30,4 @@ public class Clipboard extends Object
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Transferable getContents(Object requestor) {
|
||||
try {
|
||||
final Activity act = ModdingKit.getCurrentActivity();
|
||||
ClipboardManager clipboard = (ClipboardManager) act.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
return new StringSelection(clipboard.getText().toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -233,7 +233,7 @@ public class FlatteningPathIterator implements PathIterator {
|
|||
bufIndex -= 6;
|
||||
buf[bufIndex + 0] = px;
|
||||
buf[bufIndex + 1] = py;
|
||||
net.kdt.pojavlaunch.SystemCrackResolver.arraycopy(coords, 0, buf, bufIndex + 2, 4);
|
||||
System.arraycopy(coords, 0, buf, bufIndex + 2, 4);
|
||||
bufSubdiv = 0;
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ public class FlatteningPathIterator implements PathIterator {
|
|||
// Realloc buffer
|
||||
if (bufIndex <= 4) {
|
||||
double tmp[] = new double[bufSize + BUFFER_CAPACITY];
|
||||
net.kdt.pojavlaunch.SystemCrackResolver.arraycopy(buf, bufIndex, tmp, bufIndex + BUFFER_CAPACITY, bufSize
|
||||
System.arraycopy(buf, bufIndex, tmp, bufIndex + BUFFER_CAPACITY, bufSize
|
||||
- bufIndex);
|
||||
buf = tmp;
|
||||
bufSize += BUFFER_CAPACITY;
|
||||
|
|
@ -275,7 +275,7 @@ public class FlatteningPathIterator implements PathIterator {
|
|||
bufIndex -= 8;
|
||||
buf[bufIndex + 0] = px;
|
||||
buf[bufIndex + 1] = py;
|
||||
net.kdt.pojavlaunch.SystemCrackResolver.arraycopy(coords, 0, buf, bufIndex + 2, 6);
|
||||
System.arraycopy(coords, 0, buf, bufIndex + 2, 6);
|
||||
bufSubdiv = 0;
|
||||
}
|
||||
|
||||
|
|
@ -287,7 +287,7 @@ public class FlatteningPathIterator implements PathIterator {
|
|||
// Realloc buffer
|
||||
if (bufIndex <= 6) {
|
||||
double tmp[] = new double[bufSize + BUFFER_CAPACITY];
|
||||
net.kdt.pojavlaunch.SystemCrackResolver.arraycopy(buf, bufIndex, tmp, bufIndex + BUFFER_CAPACITY, bufSize
|
||||
System.arraycopy(buf, bufIndex, tmp, bufIndex + BUFFER_CAPACITY, bufSize
|
||||
- bufIndex);
|
||||
buf = tmp;
|
||||
bufSize += BUFFER_CAPACITY;
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ public final class GeneralPath implements Shape, Cloneable {
|
|||
}
|
||||
int type = p.types[typeIndex];
|
||||
int count = GeneralPath.pointShift[type];
|
||||
net.kdt.pojavlaunch.SystemCrackResolver.arraycopy(p.points, pointIndex, coords, 0, count);
|
||||
System.arraycopy(p.points, pointIndex, coords, 0, count);
|
||||
if (t != null) {
|
||||
t.transform(coords, 0, coords, 0, count / 2);
|
||||
}
|
||||
|
|
@ -290,12 +290,12 @@ public final class GeneralPath implements Shape, Cloneable {
|
|||
}
|
||||
if (typeSize == types.length) {
|
||||
byte tmp[] = new byte[typeSize + BUFFER_CAPACITY];
|
||||
net.kdt.pojavlaunch.SystemCrackResolver.arraycopy(types, 0, tmp, 0, typeSize);
|
||||
System.arraycopy(types, 0, tmp, 0, typeSize);
|
||||
types = tmp;
|
||||
}
|
||||
if (pointSize + pointCount > points.length) {
|
||||
float tmp[] = new float[pointSize + Math.max(BUFFER_CAPACITY * 2, pointCount)];
|
||||
net.kdt.pojavlaunch.SystemCrackResolver.arraycopy(points, 0, tmp, 0, pointSize);
|
||||
System.arraycopy(points, 0, tmp, 0, pointSize);
|
||||
points = tmp;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ public class BufferedImage extends Image implements RenderedImage {
|
|||
private Bitmap mkBitmap(int width, int height, Config mode) {
|
||||
return Bitmap.createBitmap(width, height, mode);
|
||||
}
|
||||
|
||||
public BufferedImage(Bitmap bitmap) {
|
||||
if (bitmap != null) {
|
||||
this.bitmap = bitmap;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,15 @@
|
|||
package java.awt.mod;
|
||||
|
||||
import android.app.*;
|
||||
import android.graphics.*;
|
||||
import android.util.*;
|
||||
import java.awt.image.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
import net.kdt.pojavlaunch.*;
|
||||
|
||||
public class ModdingKit
|
||||
{
|
||||
public static Activity getCurrentActivity()
|
||||
public static MainActivity getCurrentActivity()
|
||||
{
|
||||
try {
|
||||
Class activityThreadClass = Class.forName("android.app.ActivityThread");
|
||||
|
|
@ -26,7 +27,7 @@ public class ModdingKit
|
|||
if (!pausedField.getBoolean(activityRecord)) {
|
||||
Field activityField = activityRecordClass.getDeclaredField("activity");
|
||||
activityField.setAccessible(true);
|
||||
Activity activity = (Activity) activityField.get(activityRecord);
|
||||
MainActivity activity = (MainActivity) activityField.get(activityRecord);
|
||||
return activity;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
234
app/src/main/java/java/beans/FeatureDescriptor.java
Normal file
234
app/src/main/java/java/beans/FeatureDescriptor.java
Normal file
|
|
@ -0,0 +1,234 @@
|
|||
/*
|
||||
* 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.beans;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Common base class for Descriptors.
|
||||
*/
|
||||
public class FeatureDescriptor {
|
||||
|
||||
private Map<String, Object> values;
|
||||
|
||||
boolean preferred, hidden, expert;
|
||||
|
||||
String shortDescription;
|
||||
|
||||
String name;
|
||||
|
||||
String displayName;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructs an instance.
|
||||
* </p>
|
||||
*/
|
||||
public FeatureDescriptor() {
|
||||
this.values = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the value for the named attribute.
|
||||
* </p>
|
||||
*
|
||||
* @param attributeName
|
||||
* The name of the attribute to set a value with.
|
||||
* @param value
|
||||
* The value to set.
|
||||
*/
|
||||
public void setValue(String attributeName, Object value) {
|
||||
if (attributeName == null || value == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
values.put(attributeName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the value associated with the named attribute.
|
||||
* </p>
|
||||
*
|
||||
* @param attributeName
|
||||
* The name of the attribute to get a value for.
|
||||
* @return The attribute's value.
|
||||
*/
|
||||
public Object getValue(String attributeName) {
|
||||
Object result = null;
|
||||
if (attributeName != null) {
|
||||
result = values.get(attributeName);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Enumerates the attribute names.
|
||||
* </p>
|
||||
*
|
||||
* @return An instance of {@link Enumeration}.
|
||||
*/
|
||||
public Enumeration<String> attributeNames() {
|
||||
// Create a new list, so that the references are copied
|
||||
return Collections.enumeration(new LinkedList<String>(values.keySet()));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the short description.
|
||||
* </p>
|
||||
*
|
||||
* @param text
|
||||
* The description to set.
|
||||
*/
|
||||
public void setShortDescription(String text) {
|
||||
this.shortDescription = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the name.
|
||||
* </p>
|
||||
*
|
||||
* @param name
|
||||
* The name to set.
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the display name.
|
||||
* </p>
|
||||
*
|
||||
* @param displayName
|
||||
* The display name to set.
|
||||
*/
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the short description or {@link #getDisplayName()} if not set.
|
||||
* </p>
|
||||
*
|
||||
* @return The description.
|
||||
*/
|
||||
public String getShortDescription() {
|
||||
return shortDescription == null ? getDisplayName() : shortDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the name.
|
||||
* </p>
|
||||
*
|
||||
* @return The name.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the display name or {@link #getName()} if not set.
|
||||
* </p>
|
||||
*
|
||||
* @return The display name.
|
||||
*/
|
||||
public String getDisplayName() {
|
||||
return displayName == null ? getName() : displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the preferred indicator.
|
||||
* </p>
|
||||
*
|
||||
* @param preferred
|
||||
* <code>true</code> if preferred, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public void setPreferred(boolean preferred) {
|
||||
this.preferred = preferred;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the hidden indicator.
|
||||
* </p>
|
||||
*
|
||||
* @param hidden
|
||||
* <code>true</code> if hidden, <code>false</code> otherwise.
|
||||
*/
|
||||
public void setHidden(boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Sets the expert indicator.
|
||||
* </p>
|
||||
*
|
||||
* @param expert
|
||||
* <code>true</code> if expert, <code>false</code> otherwise.
|
||||
*/
|
||||
public void setExpert(boolean expert) {
|
||||
this.expert = expert;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Indicates if this feature is preferred.
|
||||
* </p>
|
||||
*
|
||||
* @return <code>true</code> if preferred, <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean isPreferred() {
|
||||
return preferred;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Indicates if this feature is hidden.
|
||||
* </p>
|
||||
*
|
||||
* @return <code>true</code> if hidden, <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Indicates if this feature is an expert feature.
|
||||
* </p>
|
||||
*
|
||||
* @return <code>true</code> if hidden, <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean isExpert() {
|
||||
return expert;
|
||||
}
|
||||
}
|
||||
227
app/src/main/java/java/beans/IndexedPropertyDescriptor.java
Normal file
227
app/src/main/java/java/beans/IndexedPropertyDescriptor.java
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
/*
|
||||
* 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.beans;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import org.apache.harmony.beans.internal.nls.Messages;
|
||||
|
||||
public class IndexedPropertyDescriptor extends PropertyDescriptor {
|
||||
private Method indexedGetter;
|
||||
|
||||
private Method indexedSetter;
|
||||
|
||||
public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass,
|
||||
String getterName, String setterName, String indexedGetterName,
|
||||
String indexedSetterName) throws IntrospectionException {
|
||||
super(propertyName, beanClass, getterName, setterName);
|
||||
|
||||
// RI behaves like this
|
||||
if (indexedGetterName == null && indexedSetterName == null &&
|
||||
(getterName != null || setterName != null)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.50"));
|
||||
}
|
||||
setIndexedReadMethod(beanClass, indexedGetterName);
|
||||
setIndexedWriteMethod(beanClass, indexedSetterName);
|
||||
}
|
||||
|
||||
public IndexedPropertyDescriptor(String propertyName, Method getter, Method setter,
|
||||
Method indexedGetter, Method indexedSetter) throws IntrospectionException {
|
||||
super(propertyName, getter, setter);
|
||||
|
||||
// we need this in order to be compatible with RI
|
||||
if (indexedGetter == null && indexedSetter == null &&
|
||||
(getter != null || setter != null)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.50"));
|
||||
}
|
||||
setIndexedReadMethod(indexedGetter);
|
||||
setIndexedWriteMethod(indexedSetter);
|
||||
}
|
||||
|
||||
public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass)
|
||||
throws IntrospectionException {
|
||||
super(propertyName, beanClass, null, null);
|
||||
String getterName;
|
||||
String setterName;
|
||||
String indexedGetterName;
|
||||
String indexedSetterName;
|
||||
|
||||
// array getter
|
||||
getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
|
||||
if (hasMethod(beanClass, getterName)) {
|
||||
setReadMethod(beanClass, getterName);
|
||||
}
|
||||
// array setter
|
||||
setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
|
||||
if (hasMethod(beanClass, setterName)) {
|
||||
setWriteMethod(beanClass, setterName);
|
||||
}
|
||||
// indexed getter
|
||||
indexedGetterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
|
||||
if (hasMethod(beanClass, indexedGetterName)) {
|
||||
setIndexedReadMethod(beanClass, indexedGetterName);
|
||||
}
|
||||
// indexed setter
|
||||
indexedSetterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
|
||||
if (hasMethod(beanClass, indexedSetterName)) {
|
||||
setIndexedWriteMethod(beanClass, indexedSetterName);
|
||||
}
|
||||
// RI seems to behave a bit differently
|
||||
if (indexedGetter == null && indexedSetter == null &&
|
||||
getReadMethod() == null && getWriteMethod() == null) {
|
||||
throw new IntrospectionException(
|
||||
Messages.getString("beans.01", propertyName)); //$NON-NLS-1$
|
||||
}
|
||||
if (indexedGetter == null && indexedSetter == null) {
|
||||
// not an indexed property indeed
|
||||
throw new IntrospectionException(Messages.getString("beans.50"));
|
||||
}
|
||||
}
|
||||
|
||||
public void setIndexedReadMethod(Method indexedGetter) throws IntrospectionException {
|
||||
if (indexedGetter != null) {
|
||||
int modifiers = indexedGetter.getModifiers();
|
||||
Class<?>[] parameterTypes;
|
||||
Class<?> returnType;
|
||||
Class<?> indexedPropertyType;
|
||||
|
||||
if (!Modifier.isPublic(modifiers)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.21")); //$NON-NLS-1$
|
||||
}
|
||||
parameterTypes = indexedGetter.getParameterTypes();
|
||||
if (parameterTypes.length != 1) {
|
||||
throw new IntrospectionException(Messages.getString("beans.22")); //$NON-NLS-1$
|
||||
}
|
||||
if (!parameterTypes[0].equals(int.class)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.23")); //$NON-NLS-1$
|
||||
}
|
||||
returnType = indexedGetter.getReturnType();
|
||||
indexedPropertyType = getIndexedPropertyType();
|
||||
if ((indexedPropertyType != null) && !returnType.equals(indexedPropertyType)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.24")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
this.indexedGetter = indexedGetter;
|
||||
}
|
||||
|
||||
public void setIndexedWriteMethod(Method indexedSetter) throws IntrospectionException {
|
||||
if (indexedSetter != null) {
|
||||
int modifiers = indexedSetter.getModifiers();
|
||||
Class<?>[] parameterTypes;
|
||||
Class<?> firstParameterType;
|
||||
Class<?> secondParameterType;
|
||||
Class<?> propType;
|
||||
|
||||
if (!Modifier.isPublic(modifiers)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.25")); //$NON-NLS-1$
|
||||
}
|
||||
parameterTypes = indexedSetter.getParameterTypes();
|
||||
if (parameterTypes.length != 2) {
|
||||
throw new IntrospectionException(Messages.getString("beans.26")); //$NON-NLS-1$
|
||||
}
|
||||
firstParameterType = parameterTypes[0];
|
||||
if (!firstParameterType.equals(int.class)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.27")); //$NON-NLS-1$
|
||||
}
|
||||
secondParameterType = parameterTypes[1];
|
||||
propType = getIndexedPropertyType();
|
||||
if (propType != null && !secondParameterType.equals(propType)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.28")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
this.indexedSetter = indexedSetter;
|
||||
}
|
||||
|
||||
public Method getIndexedWriteMethod() {
|
||||
return indexedSetter;
|
||||
}
|
||||
|
||||
public Method getIndexedReadMethod() {
|
||||
return indexedGetter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
boolean result = super.equals(obj);
|
||||
|
||||
if (result) {
|
||||
IndexedPropertyDescriptor pd = (IndexedPropertyDescriptor) obj;
|
||||
|
||||
if (indexedGetter != null) {
|
||||
result = indexedGetter.equals(pd.getIndexedReadMethod());
|
||||
} else if (result && indexedGetter == null) {
|
||||
result = pd.getIndexedReadMethod() == null;
|
||||
}
|
||||
|
||||
if (result) {
|
||||
if (indexedSetter != null) {
|
||||
result = indexedSetter.equals(pd.getIndexedWriteMethod());
|
||||
} else if (indexedSetter == null) {
|
||||
result = pd.getIndexedWriteMethod() == null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Class<?> getIndexedPropertyType() {
|
||||
Class<?> result = null;
|
||||
|
||||
if (indexedGetter != null) {
|
||||
result = indexedGetter.getReturnType();
|
||||
} else if (indexedSetter != null) {
|
||||
Class<?>[] parameterTypes = indexedSetter.getParameterTypes();
|
||||
|
||||
result = parameterTypes[1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void setIndexedReadMethod(Class<?> beanClass, String indexedGetterName) {
|
||||
Method[] getters = findMethods(beanClass, indexedGetterName);
|
||||
boolean result = false;
|
||||
|
||||
for (Method element : getters) {
|
||||
try {
|
||||
setIndexedReadMethod(element);
|
||||
result = true;
|
||||
} catch (IntrospectionException ie) {}
|
||||
|
||||
if (result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setIndexedWriteMethod(Class<?> beanClass, String indexedSetterName) {
|
||||
Method[] setters = findMethods(beanClass, indexedSetterName);
|
||||
boolean result = false;
|
||||
|
||||
for (Method element : setters) {
|
||||
try {
|
||||
setIndexedWriteMethod(element);
|
||||
result = true;
|
||||
} catch (IntrospectionException ie) {}
|
||||
|
||||
if (result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
app/src/main/java/java/beans/IntrospectionException.java
Normal file
27
app/src/main/java/java/beans/IntrospectionException.java
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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.beans;
|
||||
|
||||
public class IntrospectionException extends Exception {
|
||||
|
||||
static final long serialVersionUID = -3728150539969542619L;
|
||||
|
||||
public IntrospectionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
300
app/src/main/java/java/beans/PropertyDescriptor.java
Normal file
300
app/src/main/java/java/beans/PropertyDescriptor.java
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
/*
|
||||
* 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.beans;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Vector;
|
||||
import org.apache.harmony.beans.internal.nls.Messages;
|
||||
|
||||
public class PropertyDescriptor extends FeatureDescriptor {
|
||||
private Method getter;
|
||||
|
||||
private Method setter;
|
||||
|
||||
private Class<?> propertyEditorClass;
|
||||
|
||||
private boolean constrained;
|
||||
|
||||
private boolean bound;
|
||||
|
||||
public PropertyDescriptor(String propertyName, Class<?> beanClass, String getterName,
|
||||
String setterName) throws IntrospectionException {
|
||||
super();
|
||||
if (beanClass == null) {
|
||||
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
|
||||
}
|
||||
if (propertyName == null || propertyName.length() == 0) {
|
||||
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
|
||||
}
|
||||
this.setName(propertyName);
|
||||
this.setDisplayName(propertyName);
|
||||
if (setterName != null) {
|
||||
if (hasMethod(beanClass, setterName)) {
|
||||
setWriteMethod(beanClass, setterName);
|
||||
} else {
|
||||
throw new IntrospectionException(Messages.getString("beans.20")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
if (getterName != null) {
|
||||
if (hasMethod(beanClass, getterName)) {
|
||||
setReadMethod(beanClass, getterName);
|
||||
} else {
|
||||
throw new IntrospectionException(Messages.getString("beans.1F")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyDescriptor(String propertyName, Method getter, Method setter)
|
||||
throws IntrospectionException {
|
||||
super();
|
||||
if (propertyName == null || propertyName.length() == 0) {
|
||||
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
|
||||
}
|
||||
this.setName(propertyName);
|
||||
this.setDisplayName(propertyName);
|
||||
setWriteMethod(setter);
|
||||
setReadMethod(getter);
|
||||
}
|
||||
|
||||
public PropertyDescriptor(String propertyName, Class<?> beanClass)
|
||||
throws IntrospectionException {
|
||||
String getterName;
|
||||
String setterName;
|
||||
if (beanClass == null) {
|
||||
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
|
||||
}
|
||||
if (propertyName == null || propertyName.length() == 0) {
|
||||
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
|
||||
}
|
||||
this.setName(propertyName);
|
||||
this.setDisplayName(propertyName);
|
||||
getterName = createDefaultMethodName(propertyName, "is"); //$NON-NLS-1$
|
||||
if (hasMethod(beanClass, getterName)) {
|
||||
setReadMethod(beanClass, getterName);
|
||||
} else {
|
||||
getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
|
||||
if (hasMethod(beanClass, getterName)) {
|
||||
setReadMethod(beanClass, getterName);
|
||||
}
|
||||
}
|
||||
setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
|
||||
if (hasMethod(beanClass, setterName)) {
|
||||
setWriteMethod(beanClass, setterName);
|
||||
}
|
||||
if (getter == null && setter == null) {
|
||||
throw new IntrospectionException(Messages.getString("beans.01", propertyName)); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
public void setWriteMethod(Method setter) throws IntrospectionException {
|
||||
if (setter != null) {
|
||||
int modifiers = setter.getModifiers();
|
||||
if (!Modifier.isPublic(modifiers)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.05")); //$NON-NLS-1$
|
||||
}
|
||||
Class<?>[] parameterTypes = setter.getParameterTypes();
|
||||
if (parameterTypes.length != 1) {
|
||||
throw new IntrospectionException(Messages.getString("beans.06")); //$NON-NLS-1$
|
||||
}
|
||||
Class<?> parameterType = parameterTypes[0];
|
||||
Class<?> propertyType = getPropertyType();
|
||||
if (propertyType != null && !propertyType.equals(parameterType)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.07")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
this.setter = setter;
|
||||
}
|
||||
|
||||
public void setReadMethod(Method getter) throws IntrospectionException {
|
||||
if (getter != null) {
|
||||
int modifiers = getter.getModifiers();
|
||||
if (!Modifier.isPublic(modifiers)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.0A")); //$NON-NLS-1$
|
||||
}
|
||||
Class<?>[] parameterTypes = getter.getParameterTypes();
|
||||
if (parameterTypes.length != 0) {
|
||||
throw new IntrospectionException(Messages.getString("beans.08")); //$NON-NLS-1$
|
||||
}
|
||||
Class<?> returnType = getter.getReturnType();
|
||||
if (returnType.equals(Void.TYPE)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.33")); //$NON-NLS-1$
|
||||
}
|
||||
Class<?> propertyType = getPropertyType();
|
||||
if ((propertyType != null) && !returnType.equals(propertyType)) {
|
||||
throw new IntrospectionException(Messages.getString("beans.09")); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
this.getter = getter;
|
||||
}
|
||||
|
||||
public Method getWriteMethod() {
|
||||
return setter;
|
||||
}
|
||||
|
||||
public Method getReadMethod() {
|
||||
return getter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
boolean result = (object != null && object instanceof PropertyDescriptor);
|
||||
if (result) {
|
||||
PropertyDescriptor pd = (PropertyDescriptor) object;
|
||||
boolean gettersAreEqual = (this.getter == null) && (pd.getReadMethod() == null)
|
||||
|| (this.getter != null) && (this.getter.equals(pd.getReadMethod()));
|
||||
boolean settersAreEqual = (this.setter == null) && (pd.getWriteMethod() == null)
|
||||
|| (this.setter != null) && (this.setter.equals(pd.getWriteMethod()));
|
||||
boolean propertyTypesAreEqual = this.getPropertyType() == pd.getPropertyType();
|
||||
boolean propertyEditorClassesAreEqual = this.getPropertyEditorClass() == pd
|
||||
.getPropertyEditorClass();
|
||||
boolean boundPropertyAreEqual = this.isBound() == pd.isBound();
|
||||
boolean constrainedPropertyAreEqual = this.isConstrained() == pd.isConstrained();
|
||||
result = gettersAreEqual && settersAreEqual && propertyTypesAreEqual
|
||||
&& propertyEditorClassesAreEqual && boundPropertyAreEqual
|
||||
&& constrainedPropertyAreEqual;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setPropertyEditorClass(Class<?> propertyEditorClass) {
|
||||
this.propertyEditorClass = propertyEditorClass;
|
||||
}
|
||||
|
||||
public Class<?> getPropertyType() {
|
||||
Class<?> result = null;
|
||||
if (getter != null) {
|
||||
result = getter.getReturnType();
|
||||
} else if (setter != null) {
|
||||
Class<?>[] parameterTypes = setter.getParameterTypes();
|
||||
result = parameterTypes[0];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Class<?> getPropertyEditorClass() {
|
||||
return propertyEditorClass;
|
||||
}
|
||||
|
||||
public void setConstrained(boolean constrained) {
|
||||
this.constrained = constrained;
|
||||
}
|
||||
|
||||
public void setBound(boolean bound) {
|
||||
this.bound = bound;
|
||||
}
|
||||
|
||||
public boolean isConstrained() {
|
||||
return constrained;
|
||||
}
|
||||
|
||||
public boolean isBound() {
|
||||
return bound;
|
||||
}
|
||||
|
||||
boolean hasMethod(Class<?> beanClass, String methodName) {
|
||||
Method[] methods = findMethods(beanClass, methodName);
|
||||
return (methods.length > 0);
|
||||
}
|
||||
|
||||
String createDefaultMethodName(String propertyName, String prefix) {
|
||||
String result = null;
|
||||
if (propertyName != null) {
|
||||
String bos = propertyName.substring(0, 1).toUpperCase();
|
||||
String eos = propertyName.substring(1, propertyName.length());
|
||||
result = prefix + bos + eos;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Method[] findMethods(Class<?> aClass, String methodName) {
|
||||
Method[] allMethods = aClass.getMethods();
|
||||
Vector<Method> matchedMethods = new Vector<Method>();
|
||||
Method[] result;
|
||||
for (Method method : allMethods) {
|
||||
if (method.getName().equals(methodName)) {
|
||||
matchedMethods.add(method);
|
||||
}
|
||||
}
|
||||
result = new Method[matchedMethods.size()];
|
||||
for (int j = 0; j < matchedMethods.size(); ++j) {
|
||||
result[j] = matchedMethods.elementAt(j);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void setReadMethod(Class<?> beanClass, String getterName) {
|
||||
boolean result = false;
|
||||
Method[] getters = findMethods(beanClass, getterName);
|
||||
for (Method element : getters) {
|
||||
try {
|
||||
setReadMethod(element);
|
||||
result = true;
|
||||
} catch (IntrospectionException ie) {
|
||||
}
|
||||
if (result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setWriteMethod(Class<?> beanClass, String setterName) throws IntrospectionException {
|
||||
boolean result = false;
|
||||
Method[] setters = findMethods(beanClass, setterName);
|
||||
for (Method element : setters) {
|
||||
try {
|
||||
setWriteMethod(element);
|
||||
result = true;
|
||||
} catch (IntrospectionException ie) {
|
||||
}
|
||||
if (result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyEditor createPropertyEditor(Object bean) {
|
||||
PropertyEditor editor;
|
||||
if (propertyEditorClass == null) {
|
||||
return null;
|
||||
}
|
||||
if (!PropertyEditor.class.isAssignableFrom(propertyEditorClass)) {
|
||||
// beans.48=Property editor is not assignable from the
|
||||
// PropertyEditor interface
|
||||
throw new ClassCastException(Messages.getString("beans.48")); //$NON-NLS-1$
|
||||
}
|
||||
try {
|
||||
Constructor<?> constr;
|
||||
try {
|
||||
// try to look for the constructor with single Object argument
|
||||
constr = propertyEditorClass.getConstructor(Object.class);
|
||||
editor = (PropertyEditor) constr.newInstance(bean);
|
||||
} catch (NoSuchMethodException e) {
|
||||
// try no-argument constructor
|
||||
constr = propertyEditorClass.getConstructor();
|
||||
editor = (PropertyEditor) constr.newInstance();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// beans.47=Unable to instantiate property editor
|
||||
RuntimeException re = new RuntimeException(Messages.getString("beans.47"), e); //$NON-NLS-1$
|
||||
throw re;
|
||||
}
|
||||
return editor;
|
||||
}
|
||||
}
|
||||
49
app/src/main/java/java/beans/PropertyEditor.java
Normal file
49
app/src/main/java/java/beans/PropertyEditor.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* 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.beans;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
public interface PropertyEditor {
|
||||
|
||||
public void paintValue(Graphics gfx, Rectangle box);
|
||||
|
||||
public void setAsText(String text) throws IllegalArgumentException;
|
||||
|
||||
public String[] getTags();
|
||||
|
||||
public String getJavaInitializationString();
|
||||
|
||||
public String getAsText();
|
||||
|
||||
public void setValue(Object value);
|
||||
|
||||
public Object getValue();
|
||||
|
||||
public void removePropertyChangeListener(PropertyChangeListener listener);
|
||||
|
||||
public void addPropertyChangeListener(PropertyChangeListener listener);
|
||||
|
||||
public Component getCustomEditor();
|
||||
|
||||
public boolean supportsCustomEditor();
|
||||
|
||||
public boolean isPaintable();
|
||||
}
|
||||
114
app/src/main/java/java/beans/PropertyEditorManager.java
Normal file
114
app/src/main/java/java/beans/PropertyEditorManager.java
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* 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.beans;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PropertyEditorManager {
|
||||
|
||||
private static String[] path = { "org.apache.harmony.beans.editors" }; //$NON-NLS-1$
|
||||
|
||||
private static final Map<Class<?>, Class<?>> registeredEditors = new HashMap<Class<?>, Class<?>>();
|
||||
|
||||
public PropertyEditorManager() {
|
||||
}
|
||||
|
||||
public static void registerEditor(Class<?> targetType, Class<?> editorClass) {
|
||||
if (targetType == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPropertiesAccess();
|
||||
}
|
||||
if (editorClass != null) {
|
||||
registeredEditors.put(targetType, editorClass);
|
||||
} else {
|
||||
registeredEditors.remove(targetType);
|
||||
}
|
||||
}
|
||||
|
||||
public static synchronized PropertyEditor findEditor(Class<?> targetType) {
|
||||
if (targetType == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
Class<?> editorClass = null;
|
||||
PropertyEditor editor = null;
|
||||
|
||||
editorClass = registeredEditors.get(targetType);
|
||||
|
||||
if (editorClass == null) {
|
||||
String editorClassName = targetType.getName() + "Editor"; //$NON-NLS-1$
|
||||
ClassLoader loader = targetType.getClassLoader();
|
||||
|
||||
if (loader == null) {
|
||||
loader = Thread.currentThread().getContextClassLoader();
|
||||
}
|
||||
|
||||
try {
|
||||
editorClass = Class.forName(editorClassName, true, loader);
|
||||
} catch (ClassNotFoundException cnfe) {
|
||||
String shortEditorClassName = editorClassName
|
||||
.substring(editorClassName.lastIndexOf(".") + 1); //$NON-NLS-1$
|
||||
|
||||
if (targetType.isPrimitive()) {
|
||||
shortEditorClassName = shortEditorClassName.substring(0, 1)
|
||||
.toUpperCase()
|
||||
+ shortEditorClassName.substring(1);
|
||||
}
|
||||
|
||||
for (String element : path) {
|
||||
editorClassName = element + "." + shortEditorClassName; //$NON-NLS-1$
|
||||
|
||||
try {
|
||||
editorClass = Class.forName(editorClassName, true,
|
||||
loader);
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (editorClass != null) {
|
||||
try {
|
||||
editor = (PropertyEditor) editorClass.newInstance();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
public static synchronized void setEditorSearchPath(String[] apath) {
|
||||
SecurityManager sm = System.getSecurityManager();
|
||||
if (sm != null) {
|
||||
sm.checkPropertiesAccess();
|
||||
}
|
||||
|
||||
path = apath;
|
||||
}
|
||||
|
||||
public static synchronized String[] getEditorSearchPath() {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
129
app/src/main/java/java/beans/PropertyEditorSupport.java
Normal file
129
app/src/main/java/java/beans/PropertyEditorSupport.java
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* 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.beans;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.harmony.beans.internal.nls.Messages;
|
||||
|
||||
public class PropertyEditorSupport implements PropertyEditor {
|
||||
|
||||
Object source = null;
|
||||
|
||||
List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
|
||||
|
||||
Object oldValue = null;
|
||||
|
||||
Object newValue = null;
|
||||
|
||||
public PropertyEditorSupport(Object source) {
|
||||
if (source == null) {
|
||||
throw new NullPointerException(Messages.getString("beans.0C")); //$NON-NLS-1$
|
||||
}
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public PropertyEditorSupport() {
|
||||
source = this;
|
||||
}
|
||||
|
||||
public void paintValue(Graphics gfx, Rectangle box) {
|
||||
}
|
||||
|
||||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
if (newValue instanceof String) {
|
||||
setValue(text);
|
||||
} else {
|
||||
throw new IllegalArgumentException(text);
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getTags() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getJavaInitializationString() {
|
||||
return "???"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public String getAsText() {
|
||||
return newValue == null ? "null" : newValue.toString(); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.oldValue = this.newValue;
|
||||
this.newValue = value;
|
||||
firePropertyChange();
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public void setSource(Object source) {
|
||||
if (source == null) {
|
||||
throw new NullPointerException(Messages.getString("beans.0C")); //$NON-NLS-1$
|
||||
}
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public Object getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public synchronized void removePropertyChangeListener(
|
||||
PropertyChangeListener listener) {
|
||||
if (listeners != null) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addPropertyChangeListener(
|
||||
PropertyChangeListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
public Component getCustomEditor() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean supportsCustomEditor() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPaintable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void firePropertyChange() {
|
||||
if (listeners.size() > 0) {
|
||||
PropertyChangeEvent event = new PropertyChangeEvent(source, null,
|
||||
oldValue, newValue);
|
||||
Iterator<PropertyChangeListener> iterator = listeners.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
PropertyChangeListener listener = iterator.next();
|
||||
listener.propertyChange(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
54
app/src/main/java/java/beans/PropertyVetoException.java
Normal file
54
app/src/main/java/java/beans/PropertyVetoException.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* 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.beans;
|
||||
|
||||
/**
|
||||
* Indicates that a proposed property change is unacceptable.
|
||||
*/
|
||||
public class PropertyVetoException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 129596057694162164L;
|
||||
|
||||
private final PropertyChangeEvent evt;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructs an instance with a message and the change event.
|
||||
* </p>
|
||||
*
|
||||
* @param message
|
||||
* A description of the veto.
|
||||
* @param event
|
||||
* The event that was vetoed.
|
||||
*/
|
||||
public PropertyVetoException(String message, PropertyChangeEvent event) {
|
||||
super(message);
|
||||
this.evt = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gets the property change event.
|
||||
* </p>
|
||||
*
|
||||
* @return An instance of {@link PropertyChangeEvent}
|
||||
*/
|
||||
public PropertyChangeEvent getPropertyChangeEvent() {
|
||||
return evt;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue