mirror of
https://github.com/openRuyi-Project/gcc.git
synced 2026-06-16 00:16:04 +00:00
Initial revision
From-SVN: r102074
This commit is contained in:
@@ -0,0 +1,524 @@
|
||||
/* Applet.java -- Java base applet class
|
||||
Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.applet;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.Image;
|
||||
import java.awt.Panel;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
import javax.accessibility.AccessibleState;
|
||||
import javax.accessibility.AccessibleStateSet;
|
||||
|
||||
/**
|
||||
* This is the base applet class. An applet is a Java program that
|
||||
* runs inside a web browser or other applet viewer in a restricted
|
||||
* environment.
|
||||
*
|
||||
* <p>To be useful, a subclass should override at least start(). Also useful
|
||||
* are init, stop, and destroy for control purposes, and getAppletInfo and
|
||||
* getParameterInfo for descriptive purposes.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class Applet extends Panel
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -5836846270535785031L;
|
||||
|
||||
/** The applet stub for this applet. */
|
||||
private transient AppletStub stub;
|
||||
|
||||
/** Some applets call setSize in their constructors. In that case,
|
||||
these fields are used to store width and height values until a
|
||||
stub is set. */
|
||||
private transient int width;
|
||||
private transient int height;
|
||||
|
||||
/**
|
||||
* The accessibility context for this applet.
|
||||
*
|
||||
* @serial the accessibleContext for this
|
||||
* @since 1.2
|
||||
*/
|
||||
private AccessibleContext accessibleContext;
|
||||
|
||||
/**
|
||||
* Default constructor for subclasses.
|
||||
*
|
||||
* @throws HeadlessException if in a headless environment
|
||||
*/
|
||||
public Applet()
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException();
|
||||
}
|
||||
|
||||
/**
|
||||
* The browser calls this method to set the applet's stub, which is the
|
||||
* low level interface to the browser. Manually setting this to null is
|
||||
* asking for problems down the road.
|
||||
*
|
||||
* @param stub the applet stub for this applet
|
||||
*/
|
||||
public final void setStub(AppletStub stub)
|
||||
{
|
||||
this.stub = stub;
|
||||
|
||||
if (width != 0 && height != 0)
|
||||
stub.appletResize (width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not this applet is currently active. An applet is active
|
||||
* just before the browser invokes start(), and becomes inactive just
|
||||
* before the browser invokes stop().
|
||||
*
|
||||
* @return <code>true</code> if this applet is active
|
||||
*/
|
||||
public boolean isActive()
|
||||
{
|
||||
return stub.isActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the basename URL of the document this applet is embedded in. This
|
||||
* is everything up to the final '/'.
|
||||
*
|
||||
* @return the URL of the document this applet is embedded in
|
||||
* @see #getCodeBase()
|
||||
*/
|
||||
public URL getDocumentBase()
|
||||
{
|
||||
return stub.getDocumentBase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL of the code base for this applet.
|
||||
*
|
||||
* @return the URL of the code base for this applet
|
||||
*/
|
||||
public URL getCodeBase()
|
||||
{
|
||||
return stub.getCodeBase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the specified parameter that was specified in
|
||||
* the <code><APPLET></code> tag for this applet.
|
||||
*
|
||||
* @param name the parameter name
|
||||
* @return the parameter value, or null if the parameter does not exist
|
||||
* @throws NullPointerException if name is null
|
||||
*/
|
||||
public String getParameter(String name)
|
||||
{
|
||||
return stub.getParameter(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the applet context for this applet.
|
||||
*
|
||||
* @return the applet context for this applet
|
||||
*/
|
||||
public AppletContext getAppletContext()
|
||||
{
|
||||
return stub.getAppletContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the applet window for this applet be resized.
|
||||
*
|
||||
* @param width the new width in pixels
|
||||
* @param height the new height in pixels
|
||||
*/
|
||||
public void resize(int width, int height)
|
||||
{
|
||||
if (stub == null)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
else
|
||||
stub.appletResize(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the applet window for this applet be resized.
|
||||
*
|
||||
* @param dim the requested dimensions
|
||||
* @throws NullPointerException if dim is null
|
||||
*/
|
||||
public void resize(Dimension dim)
|
||||
{
|
||||
resize(dim.width, dim.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the specified message in the status window if that window
|
||||
* exists.
|
||||
*
|
||||
* @param message the status message, may be null
|
||||
*/
|
||||
public void showStatus(String message)
|
||||
{
|
||||
getAppletContext().showStatus(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image from the specified URL. Note that the image is not
|
||||
* actually retrieved until the applet attempts to display it, so this
|
||||
* method returns immediately.
|
||||
*
|
||||
* @param url the URL of the image
|
||||
* @return the retrieved image
|
||||
* @throws NullPointerException if url is null
|
||||
*/
|
||||
public Image getImage(URL url)
|
||||
{
|
||||
return getAppletContext().getImage(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image from the specified absolute URL, and relative path
|
||||
* from that URL. Note that the image is not actually retrieved until the
|
||||
* applet attempts to display it, so this method returns immediately.
|
||||
* This calls <code>getImage(new URL(url, name))</code>, but if building
|
||||
* the new URL fails, this returns null.
|
||||
*
|
||||
* @param url the base URL of the image
|
||||
* @param name the name of the image relative to the URL
|
||||
* @return the retrieved image, or null on failure
|
||||
* @see #getImage(URL)
|
||||
*/
|
||||
public Image getImage(URL url, String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getImage(new URL(url, name));
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an audio clip from the specified URL. This clip is not tied to
|
||||
* any particular applet.
|
||||
*
|
||||
* XXX Classpath does not yet implement this.
|
||||
*
|
||||
* @param url the URL of the audio clip
|
||||
* @return the retrieved audio clip
|
||||
* @throws NullPointerException if url is null
|
||||
* @see #getAudioClip(URL)
|
||||
* @since 1.2
|
||||
*/
|
||||
public static final AudioClip newAudioClip(URL url)
|
||||
{
|
||||
// This requires an implementation of AudioClip in gnu.java.applet.
|
||||
throw new Error("Not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an audio clip from the specified URL. Note that the clip is not
|
||||
* actually retrieved until the applet attempts to play it, so this method
|
||||
* returns immediately.
|
||||
*
|
||||
* @param url the URL of the audio clip
|
||||
* @return the retrieved audio clip
|
||||
* @throws NullPointerException if url is null
|
||||
*/
|
||||
public AudioClip getAudioClip(URL url)
|
||||
{
|
||||
return getAppletContext().getAudioClip(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an audio clip from the specified absolute URL, and relative path
|
||||
* from that URL. Note that the clip is not actually retrieved until the
|
||||
* applet attempts to play it, so this method returns immediately. This
|
||||
* calls <code>getAudioClip(new URL(url, name))</code>, but if building
|
||||
* the new URL fails, this returns null.
|
||||
*
|
||||
* @param url the base URL of the audio clip
|
||||
* @param name the name of the clip relative to the URL
|
||||
* @return the retrieved audio clip, or null on failure
|
||||
* @see #getAudioClip(URL)
|
||||
*/
|
||||
public AudioClip getAudioClip(URL url, String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getAudioClip(new URL(url, name));
|
||||
}
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a descriptive string with applet defined information. The
|
||||
* implementation in this class returns <code>null</code>, so subclasses
|
||||
* must override to return information.
|
||||
*
|
||||
* @return a string describing the author, version, and applet copyright
|
||||
*/
|
||||
public String getAppletInfo()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale for this applet, if it has been set. If no applet
|
||||
* specific locale has been set, the default locale is returned.
|
||||
*
|
||||
* @return the locale for this applet
|
||||
* @see Component#setLocale(Locale)
|
||||
* @since 1.1
|
||||
*/
|
||||
public Locale getLocale()
|
||||
{
|
||||
return super.getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of parameters this applet supports. Each element of
|
||||
* the outer array is an array of three strings with the name of the
|
||||
* parameter, the data type or valid values, and a description. This
|
||||
* method is optional and the default implementation returns null.
|
||||
*
|
||||
* @return the list of parameters supported by this applet
|
||||
*/
|
||||
public String[][] getParameterInfo()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and plays the audio clip pointed to by the specified URL. This does
|
||||
* nothing if the URL does not point to a valid audio clip.
|
||||
*
|
||||
* @param url the URL of the audio clip
|
||||
* @throws NullPointerException if url is null
|
||||
* @see #getAudioClip(URL)
|
||||
*/
|
||||
public void play(URL url)
|
||||
{
|
||||
AudioClip ac = getAudioClip(url);
|
||||
try
|
||||
{
|
||||
ac.play();
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads and plays the audio clip pointed to by the specified absolute URL,
|
||||
* and relative path from that URL. This does nothing if the URL cannot be
|
||||
* constructed, or if it does not point to a valid audio clip.
|
||||
*
|
||||
* @param url the base URL of the audio clip
|
||||
* @param name the name of the audio clip relative to the URL
|
||||
* @see #getAudioClip(URL, String)
|
||||
* @see #play(URL)
|
||||
*/
|
||||
public void play(URL url, String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
getAudioClip(url, name).play();
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the applet is first loaded, before start().
|
||||
* The default implementation does nothing; override to do any one-time
|
||||
* initialization.
|
||||
*
|
||||
* @see #start()
|
||||
* @see #stop()
|
||||
* @see #destroy()
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the applet should start running. This is
|
||||
* normally each time a web page containing it is loaded. The default
|
||||
* implemention does nothing; override for your applet to be useful.
|
||||
*
|
||||
* @see #init()
|
||||
* @see #stop()
|
||||
* @see #destroy()
|
||||
*/
|
||||
public void start()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the applet should stop running. This is
|
||||
* normally when the next web page is loaded. The default implementation
|
||||
* does nothing; override for your applet to stop using resources when
|
||||
* it is no longer visible, but may be restarted soon.
|
||||
*
|
||||
* @see #init()
|
||||
* @see #start()
|
||||
* @see #destroy()
|
||||
*/
|
||||
public void stop()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when the applet is being unloaded. The default
|
||||
* implementation does nothing; override for your applet to clean up
|
||||
* resources on exit.
|
||||
*
|
||||
* @see #init()
|
||||
* @see #start()
|
||||
* @see #stop()
|
||||
*/
|
||||
public void destroy()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this applet, creating one if
|
||||
* necessary. This always returns an instance of {@link AccessibleApplet}.
|
||||
*
|
||||
* @return the accessibility context of this applet
|
||||
* @since 1.3
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleApplet();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an applet from an object stream. This checks for a headless
|
||||
* environment, then does the normal read.
|
||||
*
|
||||
* @param s the stream to read from
|
||||
* @throws ClassNotFoundException if a class is not found
|
||||
* @throws IOException if deserialization fails
|
||||
* @throws HeadlessException if this is a headless environment
|
||||
* @see GraphicsEnvironment#isHeadless()
|
||||
* @since 1.4
|
||||
*/
|
||||
private void readObject(ObjectInputStream s)
|
||||
throws ClassNotFoundException, IOException
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException();
|
||||
s.defaultReadObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides accessibility support for Applets, and is the
|
||||
* runtime type returned by {@link #getAccessibleContext()}.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.3
|
||||
*/
|
||||
protected class AccessibleApplet extends AccessibleAWTPanel
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.4+.
|
||||
*/
|
||||
private static final long serialVersionUID = 8127374778187708896L;
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
protected AccessibleApplet()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the role of this accessible object, a frame.
|
||||
*
|
||||
* @return the role of the object
|
||||
* @see AccessibleRole#FRAME
|
||||
*/
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.FRAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the state set of this accessible object. In addition to the default
|
||||
* states of a Component, the applet can also be active.
|
||||
*
|
||||
* @return the role of the object
|
||||
* @see AccessibleState
|
||||
*/
|
||||
public AccessibleStateSet getAccessibleStateSet()
|
||||
{
|
||||
AccessibleStateSet s = super.getAccessibleStateSet();
|
||||
if (isActive())
|
||||
s.add(AccessibleState.ACTIVE);
|
||||
return s;
|
||||
}
|
||||
} // class AccessibleApplet
|
||||
} // class Applet
|
||||
@@ -0,0 +1,154 @@
|
||||
/* AppletContext.java -- access the applet's runtime environment
|
||||
Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.applet;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* This interface allows an applet access to the browser to retrieve
|
||||
* additional data files and display documents. It also allows the
|
||||
* applet to find out other applets in the same document.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface AppletContext
|
||||
{
|
||||
/**
|
||||
* Returns an audio clip from the specified URL.
|
||||
*
|
||||
* @param url the URL of the audio clip
|
||||
* @return the retrieved audio clip
|
||||
* @throws NullPointerException if url is null
|
||||
*/
|
||||
AudioClip getAudioClip(URL url);
|
||||
|
||||
/**
|
||||
* Returns an image from the specified URL. Note that the image is not
|
||||
* actually retrieved until the applet attempts to display it, so this
|
||||
* method returns immediately.
|
||||
*
|
||||
* @param url the absolute URL of the image
|
||||
* @return the retrieved image
|
||||
* @throws NullPointerException if url is null
|
||||
*/
|
||||
Image getImage(URL url);
|
||||
|
||||
/**
|
||||
* Returns the applet in the document for this object that has the
|
||||
* specified name.
|
||||
*
|
||||
* @param name the applet name
|
||||
* @return the requested applet, or <code>null</code> if not found
|
||||
*/
|
||||
Applet getApplet(String name);
|
||||
|
||||
/**
|
||||
* Returns a list of all the applets in the document for this object.
|
||||
*
|
||||
* @return a list of all the applets
|
||||
*/
|
||||
Enumeration getApplets();
|
||||
|
||||
/**
|
||||
* Displays the web page pointed to by the specified URL in the window
|
||||
* for this object. This page replaces the document that is currently
|
||||
* there.
|
||||
*
|
||||
* @param url the URL of the web page to load; unspecified on an error
|
||||
*/
|
||||
void showDocument(URL url);
|
||||
|
||||
/**
|
||||
* Displays the web page pointed to be the sepcified URL in the window
|
||||
* with the specified name. The standard names "_top", "_blank",
|
||||
* "_parent", and "_self" are allowed. An applet viewer may disregard
|
||||
* this request.
|
||||
*
|
||||
* @param url the URL of the web page to load
|
||||
* @param target the target window
|
||||
*/
|
||||
void showDocument(URL url, String target);
|
||||
|
||||
/**
|
||||
* Displays the specified message in the status window if that window
|
||||
* exists.
|
||||
*
|
||||
* @param message the status message, may be null
|
||||
*/
|
||||
void showStatus(String message);
|
||||
|
||||
/**
|
||||
* Associate a stream to a key for this applet context, possibly replacing
|
||||
* the old value. Stream associations are local to the applet context, for
|
||||
* security purposes.
|
||||
*
|
||||
* @param key the key to associate with
|
||||
* @param stream the stream value to tie to the key, or null to remove
|
||||
* @throws IOException if the stream is too large
|
||||
* @since 1.4
|
||||
*/
|
||||
void setStream(String key, InputStream stream) throws IOException;
|
||||
|
||||
/**
|
||||
* Return the stream associated with a given key in this applet context, or
|
||||
* null if nothing is associated. Stream associations are local to the
|
||||
* applet context, for security purposes.
|
||||
*
|
||||
* @param key the key to look up
|
||||
* @return the associated stream, or null
|
||||
* @since 1.4
|
||||
*/
|
||||
InputStream getStream(String key);
|
||||
|
||||
/**
|
||||
* Iterate over all keys that have associated streams. Stream associated
|
||||
* are local to the applet context, for security purposes.
|
||||
*
|
||||
* @return an iterator over the association keys
|
||||
* @since 1.4
|
||||
*/
|
||||
Iterator getStreamKeys();
|
||||
} // interface AppletContext
|
||||
@@ -0,0 +1,103 @@
|
||||
/* AppletStub.java -- low level interface to the browser
|
||||
Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.applet;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* This interface is the low level interface between the applet and the
|
||||
* browser.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @see Applet#setStub(AppletStub)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface AppletStub
|
||||
{
|
||||
/**
|
||||
* Tests whether or not this applet is currently active. An applet is active
|
||||
* just before the browser invokes start(), and becomes inactive just
|
||||
* before the browser invokes stop().
|
||||
*
|
||||
* @return <code>true</code> if this applet is active
|
||||
*/
|
||||
boolean isActive();
|
||||
|
||||
/**
|
||||
* Returns the basename URL of the document this applet is embedded in. This
|
||||
* is everything up to the final '/'.
|
||||
*
|
||||
* @return the URL of the document this applet is embedded in
|
||||
* @see #getCodeBase()
|
||||
*/
|
||||
URL getDocumentBase();
|
||||
|
||||
/**
|
||||
* Returns the URL of the code base for this applet.
|
||||
*
|
||||
* @return the URL of the code base for this applet
|
||||
*/
|
||||
URL getCodeBase();
|
||||
|
||||
/**
|
||||
* Returns the value of the specified parameter that was specified in
|
||||
* the <code><APPLET></code> tag for this applet.
|
||||
*
|
||||
* @param name the parameter name
|
||||
* @return the parameter value, or null if the parameter does not exist
|
||||
* @throws NullPointerException if name is null
|
||||
*/
|
||||
String getParameter(String name);
|
||||
|
||||
/**
|
||||
* Returns the applet context for this applet.
|
||||
*
|
||||
* @return the applet context for this applet
|
||||
*/
|
||||
AppletContext getAppletContext();
|
||||
|
||||
/**
|
||||
* Requests that the applet window for this applet be resized.
|
||||
*
|
||||
* @param width the new width in pixels
|
||||
* @param height the new height in pixels
|
||||
*/
|
||||
void appletResize(int width, int height);
|
||||
} // interface AppletStub
|
||||
@@ -0,0 +1,68 @@
|
||||
/* AudioClip.java -- play an audio clip in an applet
|
||||
Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.applet;
|
||||
|
||||
|
||||
/**
|
||||
* This interface provides a simple mechanism for playing audio clips.
|
||||
* If multiple clips are played at once, the browser combines them into a
|
||||
* composite clip.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface AudioClip
|
||||
{
|
||||
/**
|
||||
* Plays the audio clip starting from the beginning.
|
||||
*/
|
||||
void play();
|
||||
|
||||
/**
|
||||
* Stops playing this audio clip. There is no mechanism for restarting
|
||||
* at the point where the clip is stopped.
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Plays this audio clip in a continuous loop.
|
||||
*/
|
||||
void loop();
|
||||
} // interface AudioClip
|
||||
@@ -0,0 +1,47 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<!-- package.html - describes classes in java.applet package.
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. -->
|
||||
|
||||
<html>
|
||||
<head><title>GNU Classpath - java.applet</title></head>
|
||||
|
||||
<body>
|
||||
<p>Classes and interfaces for small embeddable applications
|
||||
often used in web pages.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,64 @@
|
||||
/* AWTError.java -- A serious AWT error occurred.
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This error is thrown when a critical Abstract Window Toolkit (AWT) error
|
||||
* occurs.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class AWTError extends Error
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -1819846354050686206L;
|
||||
|
||||
/**
|
||||
* Create a new instance with the specified descriptive error message.
|
||||
*
|
||||
* @param message the descriptive error message
|
||||
*/
|
||||
public AWTError(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
} // class AWTError
|
||||
@@ -0,0 +1,278 @@
|
||||
|
||||
/* AWTEvent.java -- the root event in AWT
|
||||
Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
/**
|
||||
* AWTEvent is the root event class for all AWT events in the JDK 1.1 event
|
||||
* model. It supersedes the Event class from JDK 1.0. Subclasses outside of
|
||||
* the java.awt package should have IDs greater than RESERVED_ID_MAX.
|
||||
*
|
||||
* <p>Event masks defined here are used by components in
|
||||
* <code>enableEvents</code> to select event types not selected by registered
|
||||
* listeners. Event masks are appropriately set when registering on
|
||||
* components.
|
||||
*
|
||||
* @author Warren Levy (warrenl@cygnus.com)
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public abstract class AWTEvent extends EventObject
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.1+.
|
||||
*/
|
||||
private static final long serialVersionUID = -1825314779160409405L;
|
||||
|
||||
/**
|
||||
* The ID of the event.
|
||||
*
|
||||
* @see #getID()
|
||||
* @see #AWTEvent(Object, int)
|
||||
* @serial the identifier number of this event
|
||||
*/
|
||||
protected int id;
|
||||
|
||||
/**
|
||||
* Indicates if the event has been consumed. False mean it is passed to
|
||||
* the peer, true means it has already been processed. Semantic events
|
||||
* generated by low-level events always have the value true.
|
||||
*
|
||||
* @see #consume()
|
||||
* @see #isConsumed()
|
||||
* @serial whether the event has been consumed
|
||||
*/
|
||||
protected boolean consumed;
|
||||
|
||||
/**
|
||||
* Who knows? It's in the serial version.
|
||||
*
|
||||
* @serial No idea what this is for.
|
||||
*/
|
||||
byte[] bdata;
|
||||
|
||||
/** Mask for selecting component events. */
|
||||
public static final long COMPONENT_EVENT_MASK = 0x00001;
|
||||
|
||||
/** Mask for selecting container events. */
|
||||
public static final long CONTAINER_EVENT_MASK = 0x00002;
|
||||
|
||||
/** Mask for selecting component focus events. */
|
||||
public static final long FOCUS_EVENT_MASK = 0x00004;
|
||||
|
||||
/** Mask for selecting keyboard events. */
|
||||
public static final long KEY_EVENT_MASK = 0x00008;
|
||||
|
||||
/** Mask for mouse button events. */
|
||||
public static final long MOUSE_EVENT_MASK = 0x00010;
|
||||
|
||||
/** Mask for mouse motion events. */
|
||||
public static final long MOUSE_MOTION_EVENT_MASK = 0x00020;
|
||||
|
||||
/** Mask for window events. */
|
||||
public static final long WINDOW_EVENT_MASK = 0x00040;
|
||||
|
||||
/** Mask for action events. */
|
||||
public static final long ACTION_EVENT_MASK = 0x00080;
|
||||
|
||||
/** Mask for adjustment events. */
|
||||
public static final long ADJUSTMENT_EVENT_MASK = 0x00100;
|
||||
|
||||
/** Mask for item events. */
|
||||
public static final long ITEM_EVENT_MASK = 0x00200;
|
||||
|
||||
/** Mask for text events. */
|
||||
public static final long TEXT_EVENT_MASK = 0x00400;
|
||||
|
||||
/**
|
||||
* Mask for input method events.
|
||||
* @since 1.3
|
||||
*/
|
||||
public static final long INPUT_METHOD_EVENT_MASK = 0x00800;
|
||||
|
||||
/**
|
||||
* Mask if input methods are enabled. Package visible only.
|
||||
*/
|
||||
static final long INPUT_ENABLED_EVENT_MASK = 0x01000;
|
||||
|
||||
/**
|
||||
* Mask for paint events.
|
||||
* @since 1.3
|
||||
*/
|
||||
public static final long PAINT_EVENT_MASK = 0x02000;
|
||||
|
||||
/**
|
||||
* Mask for invocation events.
|
||||
* @since 1.3
|
||||
*/
|
||||
public static final long INVOCATION_EVENT_MASK = 0x04000;
|
||||
|
||||
/**
|
||||
* Mask for hierarchy events.
|
||||
* @since 1.3
|
||||
*/
|
||||
public static final long HIERARCHY_EVENT_MASK = 0x08000;
|
||||
|
||||
/**
|
||||
* Mask for hierarchy bounds events.
|
||||
* @since 1.3
|
||||
*/
|
||||
public static final long HIERARCHY_BOUNDS_EVENT_MASK = 0x10000;
|
||||
|
||||
/**
|
||||
* Mask for mouse wheel events.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static final long MOUSE_WHEEL_EVENT_MASK = 0x20000;
|
||||
|
||||
/**
|
||||
* Mask for window state events.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static final long WINDOW_STATE_EVENT_MASK = 0x40000;
|
||||
|
||||
/**
|
||||
* Mask for window focus events.
|
||||
* @since 1.4
|
||||
*/
|
||||
public static final long WINDOW_FOCUS_EVENT_MASK = 0x80000;
|
||||
|
||||
/**
|
||||
* This is the highest number for event ids that are reserved for use by
|
||||
* the AWT system itself. Subclasses outside of java.awt should use higher
|
||||
* ids.
|
||||
*/
|
||||
public static final int RESERVED_ID_MAX = 1999;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes a new AWTEvent from the old Java 1.0 event object.
|
||||
*
|
||||
* @param event the old-style event
|
||||
* @throws NullPointerException if event is null
|
||||
*/
|
||||
public AWTEvent(Event event)
|
||||
{
|
||||
this(event.target, event.id);
|
||||
consumed = event.consumed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an event on the specified source object and id.
|
||||
*
|
||||
* @param source the object that caused the event
|
||||
* @param id the event id
|
||||
* @throws IllegalArgumentException if source is null
|
||||
*/
|
||||
public AWTEvent(Object source, int id)
|
||||
{
|
||||
super(source);
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retarget the event, such as converting a heavyweight component to a
|
||||
* lightweight child of the original. This is not for general use, but
|
||||
* is for event targeting systems like KeyboardFocusManager.
|
||||
*
|
||||
* @param source the new source
|
||||
*/
|
||||
public void setSource(Object source)
|
||||
{
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the event type id.
|
||||
*
|
||||
* @return the id number of this event
|
||||
*/
|
||||
public int getID()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a string that represents this event in the format
|
||||
* <code>classname[eventstring] on sourcecomponentname</code>.
|
||||
*
|
||||
* @return a string representing this event
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
String string = getClass ().getName () + "[" + paramString () + "] on "
|
||||
+ source;
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the state of this event. It may be
|
||||
* empty, but must not be null; it is implementation defined.
|
||||
*
|
||||
* @return a string representation of this event
|
||||
*/
|
||||
public String paramString()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes this event so that it will not be processed in the default
|
||||
* manner.
|
||||
*/
|
||||
protected void consume()
|
||||
{
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether not not this event has been consumed. A consumed event
|
||||
* is not processed in the default manner.
|
||||
*
|
||||
* @return true if this event has been consumed
|
||||
*/
|
||||
protected boolean isConsumed()
|
||||
{
|
||||
return consumed;
|
||||
}
|
||||
} // class AWTEvent
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,64 @@
|
||||
/* AWTException.java -- Generic AWT exception
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This is a generic exception that indicates an exception occurred in the
|
||||
* Abstract Window Toolkit (AWT) system.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class AWTException extends Exception
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -1900414231151323879L;
|
||||
|
||||
/**
|
||||
* Create a new instance with the specified detailed error message.
|
||||
*
|
||||
* @param message the detailed error message
|
||||
*/
|
||||
public AWTException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
} // class AWTException
|
||||
@@ -0,0 +1,660 @@
|
||||
/* AWTKeyStroke.java -- an immutable key stroke
|
||||
Copyright (C) 2002, 2004, 2005 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.ObjectStreamException;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* This class mirrors KeyEvents, representing both low-level key presses and
|
||||
* key releases, and high level key typed inputs. However, this class forms
|
||||
* immutable strokes, and can be efficiently reused via the factory methods
|
||||
* for creating them.
|
||||
*
|
||||
* <p>For backwards compatibility with Swing, this supports a way to build
|
||||
* instances of a subclass, using reflection, provided the subclass has a
|
||||
* no-arg constructor (of any accessibility).
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see #getAWTKeyStroke(char)
|
||||
* @since 1.4
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class AWTKeyStroke implements Serializable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.4+.
|
||||
*/
|
||||
private static final long serialVersionUID = -6430539691155161871L;
|
||||
|
||||
/** The mask for modifiers. */
|
||||
private static final int MODIFIERS_MASK = 0x3fef;
|
||||
|
||||
/**
|
||||
* The cache of recently created keystrokes. This maps KeyStrokes to
|
||||
* KeyStrokes in a cache which removes the least recently accessed entry,
|
||||
* under the assumption that garbage collection of a new keystroke is
|
||||
* easy when we find the old one that it matches in the cache.
|
||||
*/
|
||||
private static final LinkedHashMap cache = new LinkedHashMap(11, 0.75f, true)
|
||||
{
|
||||
/** The largest the keystroke cache can grow. */
|
||||
private static final int MAX_CACHE_SIZE = 2048;
|
||||
|
||||
/** Prune stale entries. */
|
||||
protected boolean removeEldestEntry(Map.Entry eldest)
|
||||
{ // XXX - FIXME Use Map.Entry, not just Entry as gcj 3.1 workaround.
|
||||
return size() > MAX_CACHE_SIZE;
|
||||
}
|
||||
};
|
||||
|
||||
/** The most recently generated keystroke, or null. */
|
||||
private static AWTKeyStroke recent;
|
||||
|
||||
/**
|
||||
* The no-arg constructor of a subclass, or null to use AWTKeyStroke. Note
|
||||
* that this will be left accessible, to get around private access; but
|
||||
* it should not be a security risk as it is highly unlikely that creating
|
||||
* protected instances of the subclass via reflection will do much damage.
|
||||
*/
|
||||
private static Constructor ctor;
|
||||
|
||||
/**
|
||||
* A table of keyCode names to values. This is package-private to
|
||||
* avoid an accessor method.
|
||||
*
|
||||
* @see #getAWTKeyStroke(String)
|
||||
*/
|
||||
static final HashMap vktable = new HashMap();
|
||||
static
|
||||
{
|
||||
// Using reflection saves the hassle of keeping this in sync with KeyEvent,
|
||||
// at the price of an expensive initialization.
|
||||
AccessController.doPrivileged(new PrivilegedAction()
|
||||
{
|
||||
public Object run()
|
||||
{
|
||||
Field[] fields = KeyEvent.class.getFields();
|
||||
int i = fields.length;
|
||||
try
|
||||
{
|
||||
while (--i >= 0)
|
||||
{
|
||||
Field f = fields[i];
|
||||
String name = f.getName();
|
||||
if (name.startsWith("VK_"))
|
||||
vktable.put(name.substring(3), f.get(null));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw (Error) new InternalError().initCause(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The typed character, or CHAR_UNDEFINED for key presses and releases.
|
||||
*
|
||||
* @serial the keyChar
|
||||
*/
|
||||
private char keyChar;
|
||||
|
||||
/**
|
||||
* The virtual key code, or VK_UNDEFINED for key typed. Package visible for
|
||||
* use by Component.
|
||||
*
|
||||
* @serial the keyCode
|
||||
*/
|
||||
int keyCode;
|
||||
|
||||
/**
|
||||
* The modifiers in effect. To match Sun, this stores the old style masks
|
||||
* for shift, control, alt, meta, and alt-graph (but not button1); as well
|
||||
* as the new style of extended modifiers for all modifiers.
|
||||
*
|
||||
* @serial bitwise or of the *_DOWN_MASK modifiers
|
||||
*/
|
||||
private int modifiers;
|
||||
|
||||
/**
|
||||
* True if this is a key release; should only be true if keyChar is
|
||||
* CHAR_UNDEFINED.
|
||||
*
|
||||
* @serial true to distinguish key pressed from key released
|
||||
*/
|
||||
private boolean onKeyRelease;
|
||||
|
||||
/**
|
||||
* Construct a keystroke with default values: it will be interpreted as a
|
||||
* key typed event with an invalid character and no modifiers. Client code
|
||||
* should use the factory methods instead.
|
||||
*
|
||||
* @see #getAWTKeyStroke(char)
|
||||
* @see #getAWTKeyStroke(Character, int)
|
||||
* @see #getAWTKeyStroke(int, int, boolean)
|
||||
* @see #getAWTKeyStroke(int, int)
|
||||
* @see #getAWTKeyStrokeForEvent(KeyEvent)
|
||||
* @see #getAWTKeyStroke(String)
|
||||
*/
|
||||
protected AWTKeyStroke()
|
||||
{
|
||||
keyChar = KeyEvent.CHAR_UNDEFINED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a keystroke with the given values. Client code should use the
|
||||
* factory methods instead.
|
||||
*
|
||||
* @param keyChar the character entered, if this is a key typed
|
||||
* @param keyCode the key pressed or released, or VK_UNDEFINED for key typed
|
||||
* @param modifiers the modifier keys for the keystroke, in old or new style
|
||||
* @param onKeyRelease true if this is a key release instead of a press
|
||||
* @see #getAWTKeyStroke(char)
|
||||
* @see #getAWTKeyStroke(Character, int)
|
||||
* @see #getAWTKeyStroke(int, int, boolean)
|
||||
* @see #getAWTKeyStroke(int, int)
|
||||
* @see #getAWTKeyStrokeForEvent(KeyEvent)
|
||||
* @see #getAWTKeyStroke(String)
|
||||
*/
|
||||
protected AWTKeyStroke(char keyChar, int keyCode, int modifiers,
|
||||
boolean onKeyRelease)
|
||||
{
|
||||
this.keyChar = keyChar;
|
||||
this.keyCode = keyCode;
|
||||
// No need to call extend(), as only trusted code calls this constructor.
|
||||
this.modifiers = modifiers;
|
||||
this.onKeyRelease = onKeyRelease;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new subclass as being the type of keystrokes to generate in
|
||||
* the factory methods. This operation flushes the cache of stored keystrokes
|
||||
* if the class differs from the current one. The new class must be
|
||||
* AWTKeyStroke or a subclass, and must have a no-arg constructor (which may
|
||||
* be private).
|
||||
*
|
||||
* @param subclass the new runtime type of generated keystrokes
|
||||
* @throws IllegalArgumentException subclass doesn't have no-arg constructor
|
||||
* @throws ClassCastException subclass doesn't extend AWTKeyStroke
|
||||
*/
|
||||
protected static void registerSubclass(final Class subclass)
|
||||
{
|
||||
if (subclass == null)
|
||||
throw new IllegalArgumentException();
|
||||
if (subclass.equals(ctor == null ? AWTKeyStroke.class
|
||||
: ctor.getDeclaringClass()))
|
||||
return;
|
||||
if (subclass.equals(AWTKeyStroke.class))
|
||||
{
|
||||
cache.clear();
|
||||
recent = null;
|
||||
ctor = null;
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
ctor = (Constructor) AccessController.doPrivileged
|
||||
(new PrivilegedExceptionAction()
|
||||
{
|
||||
public Object run()
|
||||
throws NoSuchMethodException, InstantiationException,
|
||||
IllegalAccessException, InvocationTargetException
|
||||
{
|
||||
Constructor c = subclass.getDeclaredConstructor(null);
|
||||
c.setAccessible(true);
|
||||
// Create a new instance, to make sure that we can, and
|
||||
// to cause any ClassCastException.
|
||||
AWTKeyStroke dummy = (AWTKeyStroke) c.newInstance(null);
|
||||
return c;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (PrivilegedActionException e)
|
||||
{
|
||||
// e.getCause() will not ever be ClassCastException; that should
|
||||
// escape on its own.
|
||||
throw (RuntimeException)
|
||||
new IllegalArgumentException().initCause(e.getCause());
|
||||
}
|
||||
cache.clear();
|
||||
recent = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a keystroke representing a typed character.
|
||||
*
|
||||
* @param keyChar the typed character
|
||||
* @return the specified keystroke
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(char keyChar)
|
||||
{
|
||||
return getAWTKeyStroke(keyChar, KeyEvent.VK_UNDEFINED, 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a keystroke representing a typed character with the given
|
||||
* modifiers. Note that keyChar is a <code>Character</code> instead of a
|
||||
* <code>char</code> to avoid accidental ambiguity with
|
||||
* <code>getAWTKeyStroke(int, int)</code>. The modifiers are the bitwise
|
||||
* or of the masks found in {@link InputEvent}; the new style (*_DOWN_MASK)
|
||||
* is preferred, but the old style will work.
|
||||
*
|
||||
* @param keyChar the typed character
|
||||
* @param modifiers the modifiers, or 0
|
||||
* @return the specified keystroke
|
||||
* @throws IllegalArgumentException if keyChar is null
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(Character keyChar, int modifiers)
|
||||
{
|
||||
if (keyChar == null)
|
||||
throw new IllegalArgumentException();
|
||||
return getAWTKeyStroke(keyChar.charValue(), KeyEvent.VK_UNDEFINED,
|
||||
extend(modifiers), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a keystroke representing a pressed or released key event, with
|
||||
* the given modifiers. The "virtual key" should be one of the VK_*
|
||||
* constants in {@link KeyEvent}. The modifiers are the bitwise or of the
|
||||
* masks found in {@link InputEvent}; the new style (*_DOWN_MASK) is
|
||||
* preferred, but the old style will work.
|
||||
*
|
||||
* @param keyCode the virtual key
|
||||
* @param modifiers the modifiers, or 0
|
||||
* @param release true if this is a key release instead of a key press
|
||||
* @return the specified keystroke
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(int keyCode, int modifiers,
|
||||
boolean release)
|
||||
{
|
||||
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, keyCode,
|
||||
extend(modifiers), release);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a keystroke representing a pressed key event, with the given
|
||||
* modifiers. The "virtual key" should be one of the VK_* constants in
|
||||
* {@link KeyEvent}. The modifiers are the bitwise or of the masks found
|
||||
* in {@link InputEvent}; the new style (*_DOWN_MASK) is preferred, but the
|
||||
* old style will work.
|
||||
*
|
||||
* @param keyCode the virtual key
|
||||
* @param modifiers the modifiers, or 0
|
||||
* @return the specified keystroke
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(int keyCode, int modifiers)
|
||||
{
|
||||
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, keyCode,
|
||||
extend(modifiers), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a keystroke representing what caused the key event.
|
||||
*
|
||||
* @param event the key event to convert
|
||||
* @return the specified keystroke, or null if the event is invalid
|
||||
* @throws NullPointerException if event is null
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent event)
|
||||
{
|
||||
switch (event.id)
|
||||
{
|
||||
case KeyEvent.KEY_TYPED:
|
||||
return getAWTKeyStroke(event.getKeyChar(), KeyEvent.VK_UNDEFINED,
|
||||
extend(event.getModifiersEx()), false);
|
||||
case KeyEvent.KEY_PRESSED:
|
||||
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, event.getKeyCode(),
|
||||
extend(event.getModifiersEx()), false);
|
||||
case KeyEvent.KEY_RELEASED:
|
||||
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, event.getKeyCode(),
|
||||
extend(event.getModifiersEx()), true);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a string and returns the keystroke that it represents. The syntax
|
||||
* for keystrokes is listed below, with tokens separated by an arbitrary
|
||||
* number of spaces:
|
||||
* <pre>
|
||||
* keyStroke := <modifiers>* ( <typedID> | <codeID> )
|
||||
* modifiers := ( shift | control | ctrl | meta | alt
|
||||
* | button1 | button2 | button3 )
|
||||
* typedID := typed <single Unicode character>
|
||||
* codeID := ( pressed | released )? <name>
|
||||
* name := <the KeyEvent field name less the leading "VK_">
|
||||
* </pre>
|
||||
*
|
||||
* <p>Note that the grammar is rather weak, and not all valid keystrokes
|
||||
* can be generated in this manner (for example, a typed space, or anything
|
||||
* with the alt-graph modifier!). The output of AWTKeyStroke.toString()
|
||||
* will not meet the grammar. If pressed or released is not specified,
|
||||
* pressed is assumed. Examples:<br>
|
||||
* <code>
|
||||
* "INSERT" => getAWTKeyStroke(KeyEvent.VK_INSERT, 0);<br>
|
||||
* "control DELETE" =>
|
||||
* getAWTKeyStroke(KeyEvent.VK_DELETE, InputEvent.CTRL_MASK);<br>
|
||||
* "alt shift X" => getAWTKeyStroke(KeyEvent.VK_X,
|
||||
* InputEvent.ALT_MASK | InputEvent.SHIFT_MASK);<br>
|
||||
* "alt shift released X" => getAWTKeyStroke(KeyEvent.VK_X,
|
||||
* InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, true);<br>
|
||||
* "typed a" => getAWTKeyStroke('a');
|
||||
* </code>
|
||||
*
|
||||
* @param s the string to parse
|
||||
* @throws IllegalArgumentException if s is null or cannot be parsed
|
||||
* @return the specified keystroke
|
||||
*/
|
||||
public static AWTKeyStroke getAWTKeyStroke(String s)
|
||||
{
|
||||
if (s == null)
|
||||
throw new IllegalArgumentException("null argument");
|
||||
StringTokenizer t = new StringTokenizer(s, " ");
|
||||
if (! t.hasMoreTokens())
|
||||
throw new IllegalArgumentException("no tokens '" + s + "'");
|
||||
int modifiers = 0;
|
||||
boolean released = false;
|
||||
String token = null;
|
||||
do
|
||||
{
|
||||
token = t.nextToken();
|
||||
if ("shift".equals(token))
|
||||
modifiers |= KeyEvent.SHIFT_DOWN_MASK;
|
||||
else if ("ctrl".equals(token) || "control".equals(token))
|
||||
modifiers |= KeyEvent.CTRL_DOWN_MASK;
|
||||
else if ("meta".equals(token))
|
||||
modifiers |= KeyEvent.META_DOWN_MASK;
|
||||
else if ("alt".equals(token))
|
||||
modifiers |= KeyEvent.ALT_DOWN_MASK;
|
||||
else if ("button1".equals(token))
|
||||
modifiers |= KeyEvent.BUTTON1_DOWN_MASK;
|
||||
else if ("button2".equals(token))
|
||||
modifiers |= KeyEvent.BUTTON2_DOWN_MASK;
|
||||
else if ("button3".equals(token))
|
||||
modifiers |= KeyEvent.BUTTON3_DOWN_MASK;
|
||||
else if ("typed".equals(token))
|
||||
{
|
||||
if (t.hasMoreTokens())
|
||||
{
|
||||
token = t.nextToken();
|
||||
if (! t.hasMoreTokens() && token.length() == 1)
|
||||
return getAWTKeyStroke(token.charAt(0),
|
||||
KeyEvent.VK_UNDEFINED, modifiers,
|
||||
false);
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid 'typed' argument '"
|
||||
+ s + "'");
|
||||
}
|
||||
else if ("pressed".equals(token))
|
||||
{
|
||||
if (t.hasMoreTokens())
|
||||
token = t.nextToken();
|
||||
break;
|
||||
}
|
||||
else if ("released".equals(token))
|
||||
{
|
||||
released = true;
|
||||
if (t.hasMoreTokens())
|
||||
token = t.nextToken();
|
||||
break;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
while (t.hasMoreTokens());
|
||||
// Now token contains the VK name we must parse.
|
||||
Integer code = (Integer) vktable.get(token);
|
||||
if (code == null)
|
||||
throw new IllegalArgumentException("Unknown token '" + token
|
||||
+ "' in '" + s + "'");
|
||||
if (t.hasMoreTokens())
|
||||
throw new IllegalArgumentException("Too many tokens: " + s);
|
||||
return getAWTKeyStroke(KeyEvent.CHAR_UNDEFINED, code.intValue(),
|
||||
modifiers, released);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the character of this keystroke, if it was typed.
|
||||
*
|
||||
* @return the character value, or CHAR_UNDEFINED
|
||||
* @see #getAWTKeyStroke(char)
|
||||
*/
|
||||
public final char getKeyChar()
|
||||
{
|
||||
return keyChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the virtual key code of this keystroke, if it was pressed or
|
||||
* released. This will be a VK_* constant from KeyEvent.
|
||||
*
|
||||
* @return the virtual key code value, or VK_UNDEFINED
|
||||
* @see #getAWTKeyStroke(int, int)
|
||||
*/
|
||||
public final int getKeyCode()
|
||||
{
|
||||
return keyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the modifiers for this keystroke. This will be a bitwise or of
|
||||
* constants from InputEvent; it includes the old style masks for shift,
|
||||
* control, alt, meta, and alt-graph (but not button1); as well as the new
|
||||
* style of extended modifiers for all modifiers.
|
||||
*
|
||||
* @return the modifiers
|
||||
* @see #getAWTKeyStroke(Character, int)
|
||||
* @see #getAWTKeyStroke(int, int)
|
||||
*/
|
||||
public final int getModifiers()
|
||||
{
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if this keystroke is a key release.
|
||||
*
|
||||
* @return true if this is a key release
|
||||
* @see #getAWTKeyStroke(int, int, boolean)
|
||||
*/
|
||||
public final boolean isOnKeyRelease()
|
||||
{
|
||||
return onKeyRelease;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the AWT event type of this keystroke. This is one of
|
||||
* {@link KeyEvent#KEY_TYPED}, {@link KeyEvent#KEY_PRESSED}, or
|
||||
* {@link KeyEvent#KEY_RELEASED}.
|
||||
*
|
||||
* @return the key event type
|
||||
*/
|
||||
public final int getKeyEventType()
|
||||
{
|
||||
return keyCode == KeyEvent.VK_UNDEFINED ? KeyEvent.KEY_TYPED
|
||||
: onKeyRelease ? KeyEvent.KEY_RELEASED : KeyEvent.KEY_PRESSED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hashcode for this key event. It is not documented, but appears
|
||||
* to be: <code>(getKeyChar() + 1) * (getKeyCode() + 1)
|
||||
* * (getModifiers() + 1) * 2 + (isOnKeyRelease() ? 1 : 2)</code>.
|
||||
*
|
||||
* @return the hashcode
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return (keyChar + 1) * (keyCode + 1) * (modifiers + 1) * 2
|
||||
+ (onKeyRelease ? 1 : 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests two keystrokes for equality.
|
||||
*
|
||||
* @param o the object to test
|
||||
* @return true if it is equal
|
||||
*/
|
||||
public final boolean equals(Object o)
|
||||
{
|
||||
if (! (o instanceof AWTKeyStroke))
|
||||
return false;
|
||||
AWTKeyStroke s = (AWTKeyStroke) o;
|
||||
return this == o || (keyChar == s.keyChar && keyCode == s.keyCode
|
||||
&& modifiers == s.modifiers
|
||||
&& onKeyRelease == s.onKeyRelease);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this keystroke. For typed keystrokes,
|
||||
* this is <code>"keyChar " + KeyEvent.getKeyModifiersText(getModifiers())
|
||||
+ getKeyChar()</code>; for pressed and released keystrokes, this is
|
||||
* <code>"keyCode " + KeyEvent.getKeyModifiersText(getModifiers())
|
||||
* + KeyEvent.getKeyText(getKeyCode())
|
||||
* + (isOnKeyRelease() ? "-R" : "-P")</code>.
|
||||
*
|
||||
* @return a string representation
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
if (keyCode == KeyEvent.VK_UNDEFINED)
|
||||
return "keyChar " + KeyEvent.getKeyModifiersText(modifiers) + keyChar;
|
||||
return "keyCode " + KeyEvent.getKeyModifiersText(modifiers)
|
||||
+ KeyEvent.getKeyText(keyCode) + (onKeyRelease ? "-R" : "-P");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cached version of the deserialized keystroke, if available.
|
||||
*
|
||||
* @return a cached replacement
|
||||
* @throws ObjectStreamException if something goes wrong
|
||||
*/
|
||||
protected Object readResolve() throws ObjectStreamException
|
||||
{
|
||||
AWTKeyStroke s = (AWTKeyStroke) cache.get(this);
|
||||
if (s != null)
|
||||
return s;
|
||||
cache.put(this, this);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the appropriate keystroke, creating one if necessary.
|
||||
*
|
||||
* @param keyChar the keyChar
|
||||
* @param keyCode the keyCode
|
||||
* @param modifiers the modifiers
|
||||
* @param release true for key release
|
||||
* @return the specified keystroke
|
||||
*/
|
||||
private static AWTKeyStroke getAWTKeyStroke(char keyChar, int keyCode,
|
||||
int modifiers, boolean release)
|
||||
{
|
||||
// Check level 0 cache.
|
||||
AWTKeyStroke stroke = recent; // Avoid thread races.
|
||||
if (stroke != null && stroke.keyChar == keyChar
|
||||
&& stroke.keyCode == keyCode && stroke.modifiers == modifiers
|
||||
&& stroke.onKeyRelease == release)
|
||||
return stroke;
|
||||
// Create a new object, on the assumption that if it has a match in the
|
||||
// cache, the VM can easily garbage collect it as it is temporary.
|
||||
Constructor c = ctor; // Avoid thread races.
|
||||
if (c == null)
|
||||
stroke = new AWTKeyStroke(keyChar, keyCode, modifiers, release);
|
||||
else
|
||||
try
|
||||
{
|
||||
stroke = (AWTKeyStroke) c.newInstance(null);
|
||||
stroke.keyChar = keyChar;
|
||||
stroke.keyCode = keyCode;
|
||||
stroke.modifiers = modifiers;
|
||||
stroke.onKeyRelease = release;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw (Error) new InternalError().initCause(e);
|
||||
}
|
||||
// Check level 1 cache.
|
||||
AWTKeyStroke cached = (AWTKeyStroke) cache.get(stroke);
|
||||
if (cached == null)
|
||||
cache.put(stroke, stroke);
|
||||
else
|
||||
stroke = cached;
|
||||
return recent = stroke;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the modifiers to the appropriate format.
|
||||
*
|
||||
* @param mod the modifiers to convert
|
||||
* @return the adjusted modifiers
|
||||
*/
|
||||
private static int extend(int mod)
|
||||
{
|
||||
if ((mod & (KeyEvent.SHIFT_MASK | KeyEvent.SHIFT_DOWN_MASK)) != 0)
|
||||
mod |= KeyEvent.SHIFT_MASK | KeyEvent.SHIFT_DOWN_MASK;
|
||||
if ((mod & (KeyEvent.CTRL_MASK | KeyEvent.CTRL_DOWN_MASK)) != 0)
|
||||
mod |= KeyEvent.CTRL_MASK | KeyEvent.CTRL_DOWN_MASK;
|
||||
if ((mod & (KeyEvent.META_MASK | KeyEvent.META_DOWN_MASK)) != 0)
|
||||
mod |= KeyEvent.META_MASK | KeyEvent.META_DOWN_MASK;
|
||||
if ((mod & (KeyEvent.ALT_MASK | KeyEvent.ALT_DOWN_MASK)) != 0)
|
||||
mod |= KeyEvent.ALT_MASK | KeyEvent.ALT_DOWN_MASK;
|
||||
if ((mod & (KeyEvent.ALT_GRAPH_MASK | KeyEvent.ALT_GRAPH_DOWN_MASK)) != 0)
|
||||
mod |= KeyEvent.ALT_GRAPH_MASK | KeyEvent.ALT_GRAPH_DOWN_MASK;
|
||||
if ((mod & KeyEvent.BUTTON1_MASK) != 0)
|
||||
mod |= KeyEvent.BUTTON1_DOWN_MASK;
|
||||
return mod & MODIFIERS_MASK;
|
||||
}
|
||||
} // class AWTKeyStroke
|
||||
@@ -0,0 +1,121 @@
|
||||
/* AWTPermission.java -- AWT related permissions
|
||||
Copyright (C) 2000, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.security.BasicPermission;
|
||||
|
||||
/**
|
||||
* This class implements permissions for AWT. This is a named
|
||||
* permission. No actions are defined.
|
||||
*
|
||||
* <p>The following table provides a list of all the possible AWTPermission
|
||||
* permission names with a description of what that permission allows.<br>
|
||||
* <table border=1>
|
||||
* <tr><th>Permission Name</th><th>Permission Allows</th><th>Risks</th</tr>
|
||||
* <tr>
|
||||
* <td><code>accessClipboard</code></td>
|
||||
* <td>posting and reading the AWT clipboard</td>
|
||||
* <td>the clipboard may contain sensitive data</td></tr>
|
||||
* <tr>
|
||||
* <td><code>accessEventQueue</code></td>
|
||||
* <td>access to the AWT event queue</td>
|
||||
* <td>malicious code could remove real events and replace them with bogus
|
||||
* ones, including simulating the user granting permission</td></tr>
|
||||
* <tr>
|
||||
* <td><code>listenToAllAWTEvents</code></td>
|
||||
* <td>listen to system-wide AWT events</td>
|
||||
* <td>malicious code can read passwords entered in an AWT event, and in
|
||||
* combination with accessEventQueue, could fake system events</td></tr>
|
||||
* <tr>
|
||||
* <td><code>showWindowWithoutWarningBanner</code></td>
|
||||
* <td>display a window without a banner notification of insecurity</td>
|
||||
* <td>malicious code could install a Trojan horse applet that looks like
|
||||
* a normal window, and thus steal data like passwords</td></tr>
|
||||
* <tr>
|
||||
* <td><code>readDisplayPixels</code></td>
|
||||
* <td>read back pixels from the display screen</td>
|
||||
* <td>malicious code could snoop on the user's actions</td></tr>
|
||||
* <tr>
|
||||
* <td><code>createRobot</code></td>
|
||||
* <td>create an instance of java.awt.Robot</td>
|
||||
* <td>these objects can generate events as though they were the user; so
|
||||
* malicious code could control the system</td></tr>
|
||||
* <tr>
|
||||
* <td><code>fullScreenExclusive</code></td>
|
||||
* <td>enter full-screen exclusive mode</td>
|
||||
* <td>malicious code could masquerade as a trusted program</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @since 1.2
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class AWTPermission extends BasicPermission
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.2+.
|
||||
*/
|
||||
private static final long serialVersionUID = 8890392402588814465L;
|
||||
|
||||
/**
|
||||
* Construct a AWTPermission with the given name.
|
||||
*
|
||||
* @param name the permission name
|
||||
* @throws NullPointerException if name is null
|
||||
* @throws IllegalArgumentException if name is invalid
|
||||
*/
|
||||
public AWTPermission(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new permission with the specified name. The actions argument
|
||||
* is ignored, as AWT permissions have no actions.
|
||||
*
|
||||
* @param name the permission name
|
||||
* @param actions ignored
|
||||
* @throws NullPointerException if name is null
|
||||
* @throws IllegalArgumentException if name is invalid
|
||||
*/
|
||||
public AWTPermission(String name, String actions)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
} // class AWTPermission
|
||||
@@ -0,0 +1,61 @@
|
||||
/* ActiveEvent.java -- a self-dispatching event
|
||||
Copyright (C) 2000, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* An interface for events which can dispatch themselves in another thread.
|
||||
* This has two uses: first, if your code is in a critical section, calling a
|
||||
* synchronized method might deadlock. But by using an ActiveEvent to call
|
||||
* the second section, it will not obtain the lock until you have left the
|
||||
* critical section, avoiding deadlock. The second use is for calling
|
||||
* untrusted code. For example, system code should use an ActiveEvent to
|
||||
* invoke user code securely.
|
||||
*
|
||||
* @author Tom Tromey (tromey@cygnus.com)
|
||||
* @since 1.2
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface ActiveEvent
|
||||
{
|
||||
/**
|
||||
* Dispatch the event, according to what the event needs done. Invoked
|
||||
* automatically if this is placed on the <code>EventDispatchQueue</code>.
|
||||
*/
|
||||
void dispatch();
|
||||
} // interface ActiveEvent
|
||||
@@ -0,0 +1,171 @@
|
||||
/* Adjustable.java -- Objects with a numeric adjustment scale
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.AdjustmentListener;
|
||||
|
||||
/**
|
||||
* This interface is for objects that take a numeric value that can be
|
||||
* adjusted within a bounded range. For example, a scroll bar.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface Adjustable
|
||||
{
|
||||
/** Constant for an adjustable object with horizontal orientation. */
|
||||
int HORIZONTAL = 0;
|
||||
|
||||
/** Constant for an adjustable object with vertical orientation. */
|
||||
int VERTICAL = 1;
|
||||
|
||||
/** Constant for an adjustable object with no orientation. */
|
||||
int NO_ORIENTATION = 2;
|
||||
|
||||
/**
|
||||
* Returns a constant representing the orientation of the object.
|
||||
*
|
||||
* @return the orientation of this object
|
||||
* @see #HORIZONTAL
|
||||
* @see #VERTICAL
|
||||
* @see #NO_ORIENTATION
|
||||
*/
|
||||
int getOrientation();
|
||||
|
||||
/**
|
||||
* Sets the minimum value this object can have.
|
||||
*
|
||||
* @param minimum the new minimum value
|
||||
*/
|
||||
void setMinimum(int minimum);
|
||||
|
||||
/**
|
||||
* Returns the minimum value this object can have.
|
||||
*
|
||||
* @return the minimum value
|
||||
*/
|
||||
int getMinimum();
|
||||
|
||||
/**
|
||||
* Sets the maximum value this object can have.
|
||||
*
|
||||
* @param maximum the new maximum value
|
||||
*/
|
||||
void setMaximum(int maximum);
|
||||
|
||||
/**
|
||||
* Returns the maximum value this object can have.
|
||||
*
|
||||
* @return the maximum value
|
||||
*/
|
||||
int getMaximum();
|
||||
|
||||
/**
|
||||
* Sets the increment value for incrementing the value by units.
|
||||
*
|
||||
* @param increment the unit increment value
|
||||
*/
|
||||
void setUnitIncrement(int increment);
|
||||
|
||||
/**
|
||||
* Returns the increment value for incrementing the value by units.
|
||||
*
|
||||
* @return the unit increment value
|
||||
*/
|
||||
int getUnitIncrement();
|
||||
|
||||
/**
|
||||
* Sets the increment value for incrementing the value by blocks.
|
||||
*
|
||||
* @param increment the block increment value
|
||||
*/
|
||||
void setBlockIncrement(int increment);
|
||||
|
||||
/**
|
||||
* Returns the increment value for incrementing the value by blocks.
|
||||
*
|
||||
* @return the block increment value
|
||||
*/
|
||||
int getBlockIncrement();
|
||||
|
||||
/**
|
||||
* Sets the length of the indicator for this object to the specified value.
|
||||
*
|
||||
* @param length the indicator length
|
||||
*/
|
||||
void setVisibleAmount(int length);
|
||||
|
||||
/**
|
||||
* Returns the length of the indicator for this object.
|
||||
*
|
||||
* @return the indicator length
|
||||
*/
|
||||
int getVisibleAmount();
|
||||
|
||||
/**
|
||||
* Sets the current value of the object.
|
||||
*
|
||||
* @param value the new value
|
||||
*/
|
||||
void setValue(int value);
|
||||
|
||||
/**
|
||||
* Returns the current value of the object.
|
||||
*
|
||||
* @return the current value
|
||||
*/
|
||||
int getValue();
|
||||
|
||||
/**
|
||||
* Adds a listener that will receive adjustment events for this object.
|
||||
*
|
||||
* @param listener the adjustment listener to add
|
||||
* @see java.awt.event.AdjustmentEvent
|
||||
*/
|
||||
void addAdjustmentListener(AdjustmentListener listener);
|
||||
|
||||
/**
|
||||
* Removes an adjustment listener from this object.
|
||||
*
|
||||
* @param listener the adjustment listener to remove
|
||||
* @see java.awt.event.AdjustmentEvent
|
||||
*/
|
||||
void removeAdjustmentListener(AdjustmentListener listener);
|
||||
} // interface Adjustable
|
||||
@@ -0,0 +1,167 @@
|
||||
/* AlphaComposite.java -- provides a context for performing alpha compositing
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.ColorModel;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Composite
|
||||
* @see CompositeContext
|
||||
* @since 1.3
|
||||
* @status updated to 1.4 except for createContext, needs documentation
|
||||
*/
|
||||
public final class AlphaComposite implements Composite
|
||||
{
|
||||
/** Map Long to AlphaComposites. See getInstance for details. */
|
||||
private static final LinkedHashMap cache = new LinkedHashMap(11, 0.75f, true)
|
||||
{
|
||||
/** The largest the alpha composite cache can grow. */
|
||||
private static final int MAX_CACHE_SIZE = 2048;
|
||||
|
||||
/** Prune stale entries. */
|
||||
protected boolean removeEldestEntry(Map.Entry eldest)
|
||||
{ // XXX - FIXME Use Map.Entry, not just Entry as gcj 3.1 workaround.
|
||||
return size() > MAX_CACHE_SIZE;
|
||||
}
|
||||
};
|
||||
|
||||
public static final int CLEAR = 1;
|
||||
public static final int SRC = 2;
|
||||
public static final int DST = 9;
|
||||
public static final int SRC_OVER = 3;
|
||||
public static final int DST_OVER = 4;
|
||||
public static final int SRC_IN = 5;
|
||||
public static final int DST_IN = 6;
|
||||
public static final int SRC_OUT = 7;
|
||||
public static final int DST_OUT = 8;
|
||||
public static final int SRC_ATOP = 10;
|
||||
public static final int DST_ATOP = 11;
|
||||
public static final int XOR = 12;
|
||||
public static final AlphaComposite Clear = getInstance(CLEAR);
|
||||
public static final AlphaComposite Src = getInstance(SRC);
|
||||
public static final AlphaComposite Dst = getInstance(DST);
|
||||
public static final AlphaComposite SrcOver = getInstance(SRC_OVER);
|
||||
public static final AlphaComposite DstOver = getInstance(DST_OVER);
|
||||
public static final AlphaComposite SrcIn = getInstance(SRC_IN);
|
||||
public static final AlphaComposite DstIn = getInstance(DST_IN);
|
||||
public static final AlphaComposite SrcOut = getInstance(SRC_OUT);
|
||||
public static final AlphaComposite DstOut = getInstance(DST_OUT);
|
||||
public static final AlphaComposite SrcAtop = getInstance(SRC_ATOP);
|
||||
public static final AlphaComposite DstAtop = getInstance(DST_ATOP);
|
||||
public static final AlphaComposite Xor = getInstance(XOR);
|
||||
|
||||
private final int rule;
|
||||
private final float alpha;
|
||||
private AlphaComposite(int rule, float alpha)
|
||||
{
|
||||
this.rule = rule;
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AlphaComposite object with the specified rule.
|
||||
*
|
||||
* @param rule The compositing rule.
|
||||
*
|
||||
* @exception IllegalArgumentException If rule is not one of the following:
|
||||
* CLEAR, SRC, DST, SRC_OVER, DST_OVER, SRC_IN, DST_IN, SRC_OUT, DST_OUT,
|
||||
* SRC_ATOP, DST_ATOP, or XOR.
|
||||
*/
|
||||
public static AlphaComposite getInstance(int rule)
|
||||
{
|
||||
return getInstance(rule, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AlphaComposite object with the specified rule and the constant
|
||||
* alpha to multiply with the alpha of the source. The source is multiplied
|
||||
* with the specified alpha before being composited with the destination.
|
||||
*
|
||||
* @param rule The compositing rule.
|
||||
*
|
||||
* @exception IllegalArgumentException If rule is not one of the following:
|
||||
* CLEAR, SRC, DST, SRC_OVER, DST_OVER, SRC_IN, DST_IN, SRC_OUT, DST_OUT,
|
||||
* SRC_ATOP, DST_ATOP, or XOR.
|
||||
*/
|
||||
public static AlphaComposite getInstance(int rule, float alpha)
|
||||
{
|
||||
if (rule < CLEAR || rule > XOR || ! (alpha >= 0 && alpha <= 1))
|
||||
throw new IllegalArgumentException();
|
||||
// This long is guaranteed unique for all valid alpha composites.
|
||||
Long l = new Long(rule + Double.doubleToLongBits(alpha));
|
||||
AlphaComposite a = (AlphaComposite) cache.get(l);
|
||||
if (a == null)
|
||||
{
|
||||
a = new AlphaComposite(rule, alpha);
|
||||
cache.put(l, a);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
public CompositeContext createContext(ColorModel srcColorModel,
|
||||
ColorModel dstColorModel,
|
||||
RenderingHints hints)
|
||||
{
|
||||
// XXX Implement. Sun uses undocumented implementation class
|
||||
// sun.java2d.SunCompositeContext.
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
public float getAlpha()
|
||||
{
|
||||
return alpha;
|
||||
}
|
||||
public int getRule()
|
||||
{
|
||||
return rule;
|
||||
}
|
||||
public int hashCode()
|
||||
{
|
||||
return 31 * Float.floatToIntBits(alpha) + rule;
|
||||
}
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (! (o instanceof AlphaComposite))
|
||||
return false;
|
||||
AlphaComposite a = (AlphaComposite) o;
|
||||
return rule == a.rule && alpha == a.alpha;
|
||||
}
|
||||
} // class AlphaComposite
|
||||
@@ -0,0 +1,98 @@
|
||||
/* AttributeValue.java -- parent of type-safe enums of attributes
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This class is undocumented by Sun, but it is the parent of several other
|
||||
* classes, all of which are type-safe enumerations. This takes care of
|
||||
* <code>equals</code>, <code>toString</code>, and <code>hashCode</code>, so
|
||||
* that you don't have to (although hashCode is commonly overridden).
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
*/
|
||||
class AttributeValue
|
||||
{
|
||||
/** The value of the enumeration. Package visible for speed. */
|
||||
final int value;
|
||||
|
||||
/** The list of enumeration names for the given subclass. */
|
||||
private final String[] names;
|
||||
|
||||
/**
|
||||
* Construct a type-safe enumeration element. For example,<br>
|
||||
* <pre>
|
||||
* class Foo extends AttributeValue
|
||||
* {
|
||||
* private static final String[] names = { "one", "two" }
|
||||
* public static final Foo ONE = new Foo(0);
|
||||
* public static final Foo TWO = new Foo(1);
|
||||
* private Foo(int value) { super(value, names); }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @param value the position of this enumeration element, consecutive from 0
|
||||
* @param names the constant list of enumeration names for the subclass
|
||||
*/
|
||||
AttributeValue(int value, String[] names)
|
||||
{
|
||||
this.value = value;
|
||||
this.names = names;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hashcode of this element. This is the index of the element
|
||||
* in the enumeration. Note that equals defaults to the == relation.
|
||||
*
|
||||
* @return the hashcode
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this enumeration element.
|
||||
*
|
||||
* @return the element name
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return names[value];
|
||||
}
|
||||
} // class AttributeValue
|
||||
@@ -0,0 +1,248 @@
|
||||
/* BasicStroke.java --
|
||||
Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* STUB CLASS ONLY
|
||||
*/
|
||||
public class BasicStroke implements Stroke
|
||||
{
|
||||
public static final int JOIN_MITER = 0;
|
||||
public static final int JOIN_ROUND = 1;
|
||||
public static final int JOIN_BEVEL = 2;
|
||||
|
||||
public static final int CAP_BUTT = 0;
|
||||
public static final int CAP_ROUND = 1;
|
||||
public static final int CAP_SQUARE = 2;
|
||||
|
||||
private final float width;
|
||||
private final int cap;
|
||||
private final int join;
|
||||
private final float limit;
|
||||
private final float[] dash;
|
||||
private final float phase;
|
||||
|
||||
/**
|
||||
* Creates a basic stroke.
|
||||
*
|
||||
* @param width May not be negative .
|
||||
* @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE.
|
||||
* @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
|
||||
* @param miterlimit the limit to trim the miter join. The miterlimit must be
|
||||
* greater than or equal to 1.0f.
|
||||
* @param dash The array representing the dashing pattern. There must be at
|
||||
* least one non-zero entry.
|
||||
* @param dashPhase is negative and dash is not null.
|
||||
*
|
||||
* @exception IllegalArgumentException If one input parameter doesn't meet
|
||||
* its needs.
|
||||
*/
|
||||
public BasicStroke(float width, int cap, int join, float miterlimit,
|
||||
float[] dash, float dashPhase)
|
||||
{
|
||||
if (width < 0.0f )
|
||||
throw new IllegalArgumentException("width " + width + " < 0");
|
||||
else if (cap < CAP_BUTT || cap > CAP_SQUARE)
|
||||
throw new IllegalArgumentException("cap " + cap + " out of range ["
|
||||
+ CAP_BUTT + ".." + CAP_SQUARE + "]");
|
||||
else if (miterlimit < 1.0f && join == JOIN_MITER)
|
||||
throw new IllegalArgumentException("miterlimit " + miterlimit
|
||||
+ " < 1.0f while join == JOIN_MITER");
|
||||
else if (join < JOIN_MITER || join > JOIN_BEVEL)
|
||||
throw new IllegalArgumentException("join " + join + " out of range ["
|
||||
+ JOIN_MITER + ".." + JOIN_BEVEL
|
||||
+ "]");
|
||||
else if (dashPhase < 0.0f && dash != null)
|
||||
throw new IllegalArgumentException("dashPhase " + dashPhase
|
||||
+ " < 0.0f while dash != null");
|
||||
else if (dash != null)
|
||||
if (dash.length == 0)
|
||||
throw new IllegalArgumentException("dash.length is 0");
|
||||
else
|
||||
{
|
||||
boolean allZero = true;
|
||||
|
||||
for ( int i = 0; i < dash.length; ++i)
|
||||
{
|
||||
if (dash[i] != 0.0f)
|
||||
{
|
||||
allZero = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allZero)
|
||||
throw new IllegalArgumentException("all dashes are 0.0f");
|
||||
}
|
||||
|
||||
this.width = width;
|
||||
this.cap = cap;
|
||||
this.join = join;
|
||||
limit = miterlimit;
|
||||
this.dash = dash == null ? null : (float[]) dash.clone();
|
||||
phase = dashPhase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a basic stroke.
|
||||
*
|
||||
* @param width The width of the BasicStroke. May not be negative .
|
||||
* @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE.
|
||||
* @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
|
||||
* @param miterlimit the limit to trim the miter join. The miterlimit must be
|
||||
* greater than or equal to 1.0f.
|
||||
*
|
||||
* @exception IllegalArgumentException If one input parameter doesn't meet
|
||||
* its needs.
|
||||
*/
|
||||
public BasicStroke(float width, int cap, int join, float miterlimit)
|
||||
{
|
||||
this(width, cap, join, miterlimit, null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a basic stroke.
|
||||
*
|
||||
* @param width The width of the BasicStroke. May not be nehative.
|
||||
* @param cap May be either CAP_BUTT, CAP_ROUND or CAP_SQUARE.
|
||||
* @param join May be either JOIN_ROUND, JOIN_BEVEL, or JOIN_MITER.
|
||||
*
|
||||
* @exception IllegalArgumentException If one input parameter doesn't meet
|
||||
* its needs.
|
||||
* @exception IllegalArgumentException FIXME
|
||||
*/
|
||||
public BasicStroke(float width, int cap, int join)
|
||||
{
|
||||
this(width, cap, join, 10, null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a basic stroke.
|
||||
*
|
||||
* @param width The width of the BasicStroke.
|
||||
*
|
||||
* @exception IllegalArgumentException If width is negative.
|
||||
*/
|
||||
public BasicStroke(float width)
|
||||
{
|
||||
this(width, CAP_SQUARE, JOIN_MITER, 10, null, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a basic stroke.
|
||||
*/
|
||||
public BasicStroke()
|
||||
{
|
||||
this(1, CAP_SQUARE, JOIN_MITER, 10, null, 0);
|
||||
}
|
||||
|
||||
public Shape createStrokedShape(Shape s)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public float getLineWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getEndCap()
|
||||
{
|
||||
return cap;
|
||||
}
|
||||
|
||||
public int getLineJoin()
|
||||
{
|
||||
return join;
|
||||
}
|
||||
|
||||
public float getMiterLimit()
|
||||
{
|
||||
return limit;
|
||||
}
|
||||
|
||||
public float[] getDashArray()
|
||||
{
|
||||
return dash;
|
||||
}
|
||||
|
||||
public float getDashPhase()
|
||||
{
|
||||
return phase;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hash code for this object. The hash is calculated by
|
||||
* xoring the hash, cap, join, limit, dash array and phase values
|
||||
* (converted to <code>int</code> first with
|
||||
* <code>Float.floatToIntBits()</code> if the value is a
|
||||
* <code>float</code>).
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = Float.floatToIntBits(width);
|
||||
hash ^= cap;
|
||||
hash ^= join;
|
||||
hash ^= Float.floatToIntBits(limit);
|
||||
|
||||
if (dash != null)
|
||||
for (int i = 0; i < dash.length; i++)
|
||||
hash ^= Float.floatToIntBits(dash[i]);
|
||||
|
||||
hash ^= Float.floatToIntBits(phase);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given Object is an instance of BasicStroke
|
||||
* and the width, cap, join, limit, dash array and phase are all
|
||||
* equal.
|
||||
*/
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (! (o instanceof BasicStroke))
|
||||
return false;
|
||||
BasicStroke s = (BasicStroke) o;
|
||||
return width == s.width && cap == s.cap && join == s.join
|
||||
&& limit == s.limit && Arrays.equals(dash, s.dash) && phase == s.phase;
|
||||
}
|
||||
} // class BasicStroke
|
||||
@@ -0,0 +1,731 @@
|
||||
/* BorderLayout.java -- A layout manager class
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This class implements a layout manager that positions components
|
||||
* in certain sectors of the parent container.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
|
||||
*/
|
||||
public class BorderLayout implements LayoutManager2, java.io.Serializable
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constant indicating the top of the container
|
||||
*/
|
||||
public static final String NORTH = "North";
|
||||
|
||||
/**
|
||||
* Constant indicating the bottom of the container
|
||||
*/
|
||||
public static final String SOUTH = "South";
|
||||
|
||||
/**
|
||||
* Constant indicating the right side of the container
|
||||
*/
|
||||
public static final String EAST = "East";
|
||||
|
||||
/**
|
||||
* Constant indicating the left side of the container
|
||||
*/
|
||||
public static final String WEST = "West";
|
||||
|
||||
/**
|
||||
* Constant indicating the center of the container
|
||||
*/
|
||||
public static final String CENTER = "Center";
|
||||
|
||||
|
||||
/**
|
||||
* The constant indicating the position before the first line of the
|
||||
* layout. The exact position depends on the writing system: For a
|
||||
* top-to-bottom orientation, it is the same as {@link #NORTH}, for
|
||||
* a bottom-to-top orientation, it is the same as {@link #SOUTH}.
|
||||
*
|
||||
* <p>This constant is an older name for {@link #PAGE_START} which
|
||||
* has exactly the same value.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public static final String BEFORE_FIRST_LINE = "First";
|
||||
|
||||
|
||||
/**
|
||||
* The constant indicating the position after the last line of the
|
||||
* layout. The exact position depends on the writing system: For a
|
||||
* top-to-bottom orientation, it is the same as {@link #SOUTH}, for
|
||||
* a bottom-to-top orientation, it is the same as {@link #NORTH}.
|
||||
*
|
||||
* <p>This constant is an older name for {@link #PAGE_END} which
|
||||
* has exactly the same value.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public static final String AFTER_LAST_LINE = "Last";
|
||||
|
||||
|
||||
/**
|
||||
* The constant indicating the position before the first item of the
|
||||
* layout. The exact position depends on the writing system: For a
|
||||
* left-to-right orientation, it is the same as {@link #WEST}, for
|
||||
* a right-to-left orientation, it is the same as {@link #EAST}.
|
||||
*
|
||||
* <p>This constant is an older name for {@link #LINE_START} which
|
||||
* has exactly the same value.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public static final String BEFORE_LINE_BEGINS = "Before";
|
||||
|
||||
|
||||
/**
|
||||
* The constant indicating the position after the last item of the
|
||||
* layout. The exact position depends on the writing system: For a
|
||||
* left-to-right orientation, it is the same as {@link #EAST}, for
|
||||
* a right-to-left orientation, it is the same as {@link #WEST}.
|
||||
*
|
||||
* <p>This constant is an older name for {@link #LINE_END} which
|
||||
* has exactly the same value.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public static final String AFTER_LINE_ENDS = "After";
|
||||
|
||||
|
||||
/**
|
||||
* The constant indicating the position before the first line of the
|
||||
* layout. The exact position depends on the writing system: For a
|
||||
* top-to-bottom orientation, it is the same as {@link #NORTH}, for
|
||||
* a bottom-to-top orientation, it is the same as {@link #SOUTH}.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public static final String PAGE_START = BEFORE_FIRST_LINE;
|
||||
|
||||
|
||||
/**
|
||||
* The constant indicating the position after the last line of the
|
||||
* layout. The exact position depends on the writing system: For a
|
||||
* top-to-bottom orientation, it is the same as {@link #SOUTH}, for
|
||||
* a bottom-to-top orientation, it is the same as {@link #NORTH}.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public static final String PAGE_END = AFTER_LAST_LINE;
|
||||
|
||||
|
||||
/**
|
||||
* The constant indicating the position before the first item of the
|
||||
* layout. The exact position depends on the writing system: For a
|
||||
* left-to-right orientation, it is the same as {@link #WEST}, for
|
||||
* a right-to-left orientation, it is the same as {@link #EAST}.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public static final String LINE_START = BEFORE_LINE_BEGINS;
|
||||
|
||||
|
||||
/**
|
||||
* The constant indicating the position after the last item of the
|
||||
* layout. The exact position depends on the writing system: For a
|
||||
* left-to-right orientation, it is the same as {@link #EAST}, for
|
||||
* a right-to-left orientation, it is the same as {@link #WEST}.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public static final String LINE_END = AFTER_LINE_ENDS;
|
||||
|
||||
|
||||
|
||||
// Serialization constant
|
||||
private static final long serialVersionUID = -8658291919501921765L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial
|
||||
*/
|
||||
private Component north;
|
||||
|
||||
/**
|
||||
* @serial
|
||||
*/
|
||||
private Component south;
|
||||
|
||||
/**
|
||||
* @serial
|
||||
*/
|
||||
private Component east;
|
||||
|
||||
/**
|
||||
* @serial
|
||||
*/
|
||||
private Component west;
|
||||
|
||||
/**
|
||||
* @serial
|
||||
*/
|
||||
private Component center;
|
||||
|
||||
/**
|
||||
* @serial
|
||||
*/
|
||||
private Component firstLine;
|
||||
|
||||
/**
|
||||
* @serial
|
||||
*/
|
||||
private Component lastLine;
|
||||
|
||||
/**
|
||||
* @serial
|
||||
*/
|
||||
private Component firstItem;
|
||||
|
||||
/**
|
||||
* @serial
|
||||
*/
|
||||
private Component lastItem;
|
||||
|
||||
/**
|
||||
* @serial The horizontal gap between components
|
||||
*/
|
||||
private int hgap;
|
||||
|
||||
/**
|
||||
* @serial The vertical gap between components
|
||||
*/
|
||||
private int vgap;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>BorderLayout</code> with no
|
||||
* horiztonal or vertical gaps between components.
|
||||
*/
|
||||
public
|
||||
BorderLayout()
|
||||
{
|
||||
this(0,0);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>BorderLayout</code> with the
|
||||
* specified horiztonal and vertical gaps between components.
|
||||
*
|
||||
* @param hgap The horizontal gap between components.
|
||||
* @param vgap The vertical gap between components.
|
||||
*/
|
||||
public
|
||||
BorderLayout(int hgap, int vgap)
|
||||
{
|
||||
this.hgap = hgap;
|
||||
this.vgap = vgap;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the horitzontal gap value.
|
||||
*
|
||||
* @return The horitzontal gap value.
|
||||
*/
|
||||
public int
|
||||
getHgap()
|
||||
{
|
||||
return(hgap);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the horizontal gap to the specified value.
|
||||
*
|
||||
* @param hgap The new horizontal gap.
|
||||
*/
|
||||
public void
|
||||
setHgap(int hgap)
|
||||
{
|
||||
this.hgap = hgap;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the vertical gap value.
|
||||
*
|
||||
* @return The vertical gap value.
|
||||
*/
|
||||
public int
|
||||
getVgap()
|
||||
{
|
||||
return(vgap);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the vertical gap to the specified value.
|
||||
*
|
||||
* @param vgap The new vertical gap value.
|
||||
*/
|
||||
public void
|
||||
setVgap(int vgap)
|
||||
{
|
||||
this.vgap = vgap;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds a component to the layout in the specified constraint position,
|
||||
* which must be one of the string constants defined in this class.
|
||||
*
|
||||
* @param component The component to add.
|
||||
* @param constraints The constraint string.
|
||||
*
|
||||
* @exception IllegalArgumentException If the constraint object is not
|
||||
* a string, or is not one of the specified constants in this class.
|
||||
*/
|
||||
public void
|
||||
addLayoutComponent(Component component, Object constraints)
|
||||
{
|
||||
if (constraints != null && ! (constraints instanceof String))
|
||||
throw new IllegalArgumentException("Constraint must be a string");
|
||||
|
||||
addLayoutComponent((String) constraints, component);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds a component to the layout in the specified constraint position,
|
||||
* which must be one of the string constants defined in this class.
|
||||
*
|
||||
* @param constraints The constraint string.
|
||||
* @param component The component to add.
|
||||
*
|
||||
* @exception IllegalArgumentException If the constraint object is not
|
||||
* one of the specified constants in this class.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>addLayoutComponent(Component, Object)</code>.
|
||||
*/
|
||||
public void
|
||||
addLayoutComponent(String constraints, Component component)
|
||||
{
|
||||
String str = constraints;
|
||||
|
||||
if (str == null || str.equals(CENTER))
|
||||
center = component;
|
||||
else if (str.equals(NORTH))
|
||||
north = component;
|
||||
else if (str.equals(SOUTH))
|
||||
south = component;
|
||||
else if (str.equals(EAST))
|
||||
east = component;
|
||||
else if (str.equals(WEST))
|
||||
west = component;
|
||||
else if (str.equals(BEFORE_FIRST_LINE))
|
||||
firstLine = component;
|
||||
else if (str.equals(AFTER_LAST_LINE))
|
||||
lastLine = component;
|
||||
else if (str.equals(BEFORE_LINE_BEGINS))
|
||||
firstItem = component;
|
||||
else if (str.equals(AFTER_LINE_ENDS))
|
||||
lastItem = component;
|
||||
else
|
||||
throw new IllegalArgumentException("Constraint value not valid: " + str);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes the specified component from the layout.
|
||||
*
|
||||
* @param component The component to remove from the layout.
|
||||
*/
|
||||
public void
|
||||
removeLayoutComponent(Component component)
|
||||
{
|
||||
if (north == component)
|
||||
north = null;
|
||||
if (south == component)
|
||||
south = null;
|
||||
if (east == component)
|
||||
east = null;
|
||||
if (west == component)
|
||||
west = null;
|
||||
if (center == component)
|
||||
center = null;
|
||||
if (firstItem == component)
|
||||
firstItem = null;
|
||||
if (lastItem == component)
|
||||
lastItem = null;
|
||||
if (firstLine == component)
|
||||
firstLine = null;
|
||||
if (lastLine == component)
|
||||
lastLine = null;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the minimum size of the specified container using this layout.
|
||||
*
|
||||
* @param target The container to calculate the minimum size for.
|
||||
*
|
||||
* @return The minimum size of the container
|
||||
*/
|
||||
public Dimension
|
||||
minimumLayoutSize(Container target)
|
||||
{
|
||||
return calcSize(target, MIN);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the preferred size of the specified container using this layout.
|
||||
*
|
||||
* @param target The container to calculate the preferred size for.
|
||||
*
|
||||
* @return The preferred size of the container
|
||||
*/
|
||||
public Dimension
|
||||
preferredLayoutSize(Container target)
|
||||
{
|
||||
return calcSize(target, PREF);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the maximum size of the specified container using this layout.
|
||||
*
|
||||
* @param target The container to calculate the maximum size for.
|
||||
*
|
||||
* @return The maximum size of the container
|
||||
*/
|
||||
public Dimension
|
||||
maximumLayoutSize(Container target)
|
||||
{
|
||||
return calcSize(target, MAX);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the X axis alignment, which is a <code>float</code> indicating
|
||||
* where along the X axis this container wishs to position its layout.
|
||||
* 0 indicates align to the left, 1 indicates align to the right, and 0.5
|
||||
* indicates align to the center.
|
||||
*
|
||||
* @param parent The parent container.
|
||||
*
|
||||
* @return The X alignment value.
|
||||
*/
|
||||
public float
|
||||
getLayoutAlignmentX(Container parent)
|
||||
{
|
||||
return(parent.getAlignmentX());
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the Y axis alignment, which is a <code>float</code> indicating
|
||||
* where along the Y axis this container wishs to position its layout.
|
||||
* 0 indicates align to the top, 1 indicates align to the bottom, and 0.5
|
||||
* indicates align to the center.
|
||||
*
|
||||
* @param parent The parent container.
|
||||
*
|
||||
* @return The Y alignment value.
|
||||
*/
|
||||
public float
|
||||
getLayoutAlignmentY(Container parent)
|
||||
{
|
||||
return(parent.getAlignmentY());
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Instructs this object to discard any layout information it might
|
||||
* have cached.
|
||||
*
|
||||
* @param parent The parent container.
|
||||
*/
|
||||
public void
|
||||
invalidateLayout(Container parent)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Lays out the specified container according to the constraints
|
||||
* in this object.
|
||||
*
|
||||
* @param target The container to lay out.
|
||||
*/
|
||||
public void
|
||||
layoutContainer(Container target)
|
||||
{
|
||||
synchronized (target.getTreeLock ())
|
||||
{
|
||||
Insets i = target.getInsets();
|
||||
|
||||
ComponentOrientation orient = target.getComponentOrientation ();
|
||||
boolean left_to_right = orient.isLeftToRight ();
|
||||
|
||||
Component my_north = north;
|
||||
Component my_east = east;
|
||||
Component my_south = south;
|
||||
Component my_west = west;
|
||||
|
||||
// Note that we currently don't handle vertical layouts. Neither
|
||||
// does JDK 1.3.
|
||||
if (firstLine != null)
|
||||
my_north = firstLine;
|
||||
if (lastLine != null)
|
||||
my_south = lastLine;
|
||||
if (firstItem != null)
|
||||
{
|
||||
if (left_to_right)
|
||||
my_west = firstItem;
|
||||
else
|
||||
my_east = firstItem;
|
||||
}
|
||||
if (lastItem != null)
|
||||
{
|
||||
if (left_to_right)
|
||||
my_east = lastItem;
|
||||
else
|
||||
my_west = lastItem;
|
||||
}
|
||||
|
||||
Dimension c = calcCompSize(center, PREF);
|
||||
Dimension n = calcCompSize(my_north, PREF);
|
||||
Dimension s = calcCompSize(my_south, PREF);
|
||||
Dimension e = calcCompSize(my_east, PREF);
|
||||
Dimension w = calcCompSize(my_west, PREF);
|
||||
Dimension t = target.getSize();
|
||||
|
||||
/*
|
||||
<-> hgap <-> hgap
|
||||
+----------------------------+ }
|
||||
|t | } i.top
|
||||
| +----------------------+ | --- y1 }
|
||||
| |n | |
|
||||
| +----------------------+ | } vgap
|
||||
| +---+ +----------+ +---+ | --- y2 } }
|
||||
| |w | |c | |e | | } hh
|
||||
| +---+ +----------+ +---+ | } vgap }
|
||||
| +----------------------+ | --- y3 }
|
||||
| |s | |
|
||||
| +----------------------+ | }
|
||||
| | } i.bottom
|
||||
+----------------------------+ }
|
||||
|x1 |x2 |x3
|
||||
<---------------------->
|
||||
<--> ww <-->
|
||||
i.left i.right
|
||||
*/
|
||||
|
||||
int x1 = i.left;
|
||||
int x2 = x1 + w.width + hgap;
|
||||
int x3;
|
||||
if (t.width <= i.right + e.width)
|
||||
x3 = x2 + w.width + hgap;
|
||||
else
|
||||
x3 = t.width - i.right - e.width;
|
||||
int ww = t.width - i.right - i.left;
|
||||
|
||||
int y1 = i.top;
|
||||
int y2 = y1 + n.height + vgap;
|
||||
int midh = Math.max(e.height, Math.max(w.height, c.height));
|
||||
int y3;
|
||||
if (t.height <= i.bottom + s.height)
|
||||
y3 = y2 + midh + vgap;
|
||||
else
|
||||
y3 = t.height - i.bottom - s.height;
|
||||
int hh = y3-y2-vgap;
|
||||
|
||||
setBounds(center, x2, y2, x3-x2-hgap, hh);
|
||||
setBounds(my_north, x1, y1, ww, n.height);
|
||||
setBounds(my_south, x1, y3, ww, s.height);
|
||||
setBounds(my_west, x1, y2, w.width, hh);
|
||||
setBounds(my_east, x3, y2, e.width, hh);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a string representation of this layout manager.
|
||||
*
|
||||
* @return A string representation of this object.
|
||||
*/
|
||||
public String
|
||||
toString()
|
||||
{
|
||||
return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]";
|
||||
}
|
||||
|
||||
private void
|
||||
setBounds(Component comp, int x, int y, int w, int h)
|
||||
{
|
||||
if (comp == null)
|
||||
return;
|
||||
comp.setBounds(x, y, w, h);
|
||||
}
|
||||
|
||||
// Some constants for use with calcSize().
|
||||
private static final int MIN = 0;
|
||||
private static final int MAX = 1;
|
||||
private static final int PREF = 2;
|
||||
|
||||
private Dimension
|
||||
calcCompSize(Component comp, int what)
|
||||
{
|
||||
if (comp == null || !comp.isVisible())
|
||||
return new Dimension(0, 0);
|
||||
if (what == MIN)
|
||||
return comp.getMinimumSize();
|
||||
else if (what == MAX)
|
||||
return comp.getMaximumSize();
|
||||
return comp.getPreferredSize();
|
||||
}
|
||||
|
||||
// This is a helper function used to compute the various sizes for
|
||||
// this layout.
|
||||
private Dimension
|
||||
calcSize(Container target, int what)
|
||||
{
|
||||
synchronized (target.getTreeLock ())
|
||||
{
|
||||
Insets ins = target.getInsets();
|
||||
|
||||
ComponentOrientation orient = target.getComponentOrientation ();
|
||||
boolean left_to_right = orient.isLeftToRight ();
|
||||
|
||||
Component my_north = north;
|
||||
Component my_east = east;
|
||||
Component my_south = south;
|
||||
Component my_west = west;
|
||||
|
||||
// Note that we currently don't handle vertical layouts. Neither
|
||||
// does JDK 1.3.
|
||||
if (firstLine != null)
|
||||
my_north = firstLine;
|
||||
if (lastLine != null)
|
||||
my_south = lastLine;
|
||||
if (firstItem != null)
|
||||
{
|
||||
if (left_to_right)
|
||||
my_west = firstItem;
|
||||
else
|
||||
my_east = firstItem;
|
||||
}
|
||||
if (lastItem != null)
|
||||
{
|
||||
if (left_to_right)
|
||||
my_east = lastItem;
|
||||
else
|
||||
my_west = lastItem;
|
||||
}
|
||||
|
||||
Dimension ndim = calcCompSize(my_north, what);
|
||||
Dimension sdim = calcCompSize(my_south, what);
|
||||
Dimension edim = calcCompSize(my_east, what);
|
||||
Dimension wdim = calcCompSize(my_west, what);
|
||||
Dimension cdim = calcCompSize(center, what);
|
||||
|
||||
int width = edim.width + cdim.width + wdim.width + (hgap * 2);
|
||||
// check for overflow
|
||||
if (width < edim.width || width < cdim.width || width < cdim.width)
|
||||
width = Integer.MAX_VALUE;
|
||||
|
||||
if (ndim.width > width)
|
||||
width = ndim.width;
|
||||
if (sdim.width > width)
|
||||
width = sdim.width;
|
||||
|
||||
width += (ins.left + ins.right);
|
||||
|
||||
int height = edim.height;
|
||||
if (cdim.height > height)
|
||||
height = cdim.height;
|
||||
if (wdim.height > height)
|
||||
height = wdim.height;
|
||||
|
||||
int addedHeight = height + (ndim.height + sdim.height + (vgap * 2)
|
||||
+ ins.top + ins.bottom);
|
||||
// check for overflow
|
||||
if (addedHeight < height)
|
||||
height = Integer.MAX_VALUE;
|
||||
else
|
||||
height = addedHeight;
|
||||
|
||||
return(new Dimension(width, height));
|
||||
}
|
||||
}
|
||||
} // class BorderLayout
|
||||
@@ -0,0 +1,253 @@
|
||||
/* BufferCapabilities.java -- double-buffering capabilities descriptor
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.BufferStrategy;
|
||||
|
||||
/**
|
||||
* A double-buffering capability descriptor. This class exposes
|
||||
* details about the double-buffering algorithms used by image
|
||||
* buffers.
|
||||
*
|
||||
* BufferCapabilities represents algorithms that involve at least two
|
||||
* buffers but it can also specify so-called "multi-buffer" schemes
|
||||
* involving more than two buffers. This class describes the
|
||||
* capabilities of the front and back buffers as well as the results
|
||||
* of "flipping" -- that is, what happens when an image is transferred
|
||||
* from the back buffer to the front buffer.
|
||||
*
|
||||
* Flipping may or may not be supported or may be supported only in
|
||||
* fullscreen mode. If it is not supported then "blitting" is implied
|
||||
* -- that is, the contents of the back buffer are copied using a fast
|
||||
* block transfer operation from the back buffer to the front buffer.
|
||||
*
|
||||
* The front buffer is the one that is displayed.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
*
|
||||
* @see BufferStrategy#getCapabilities()
|
||||
* @see GraphicsConfiguration#getBufferCapabilities()
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public class BufferCapabilities implements Cloneable
|
||||
{
|
||||
/**
|
||||
* A type-safe enumeration of buffer flipping results.
|
||||
*
|
||||
* @see AttributeValue
|
||||
*/
|
||||
public static final class FlipContents extends AttributeValue
|
||||
{
|
||||
/**
|
||||
* The names of the different flipping results.
|
||||
*/
|
||||
private static final String[] NAMES
|
||||
= { "undefined", "background", "prior", "copied" };
|
||||
|
||||
/**
|
||||
* The contents of the back buffer are undefined after flipping.
|
||||
*/
|
||||
public static final FlipContents UNDEFINED = new FlipContents(0);
|
||||
|
||||
/**
|
||||
* The back buffer is cleared with the background color after
|
||||
* flipping.
|
||||
*/
|
||||
public static final FlipContents BACKGROUND = new FlipContents(1);
|
||||
|
||||
/**
|
||||
* The back buffer contains the pre-flipping contents of the front
|
||||
* buffer after flipping. In other words a true "flip" has been
|
||||
* performed.
|
||||
*/
|
||||
public static final FlipContents PRIOR = new FlipContents(2);
|
||||
|
||||
/**
|
||||
* The back buffer has the same contents as the front buffer after
|
||||
* flipping.
|
||||
*/
|
||||
public static final FlipContents COPIED = new FlipContents(3);
|
||||
|
||||
/**
|
||||
* Create a new flipping result descriptor.
|
||||
*
|
||||
* @param value the enumeration value
|
||||
*/
|
||||
private FlipContents(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Front buffer capabilities descriptor.
|
||||
*/
|
||||
private final ImageCapabilities front;
|
||||
|
||||
/**
|
||||
* Back buffer capabilities descriptor.
|
||||
*/
|
||||
private final ImageCapabilities back;
|
||||
|
||||
/**
|
||||
* Describes the results of a "flip" operation.
|
||||
*/
|
||||
private final FlipContents flip;
|
||||
|
||||
/**
|
||||
* Creates a buffer capabilities object.
|
||||
*
|
||||
* @param frontCaps front buffer capabilities descriptor
|
||||
* @param backCaps back buffer capabilities descriptor
|
||||
* @param flip the results of a flip operation or null if
|
||||
* flipping is not supported
|
||||
*
|
||||
* @exception IllegalArgumentException if frontCaps or backCaps is
|
||||
* null
|
||||
*/
|
||||
public BufferCapabilities(ImageCapabilities frontCaps,
|
||||
ImageCapabilities backCaps,
|
||||
FlipContents flip)
|
||||
{
|
||||
if (frontCaps == null || backCaps == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.front = frontCaps;
|
||||
this.back = backCaps;
|
||||
this.flip = flip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the front buffer's image capabilities.
|
||||
*
|
||||
* @return the front buffer's image capabilities
|
||||
*/
|
||||
public ImageCapabilities getFrontBufferCapabilities()
|
||||
{
|
||||
return front;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the back buffer's image capabilities.
|
||||
*
|
||||
* @return the back buffer's image capabilities
|
||||
*/
|
||||
public ImageCapabilities getBackBufferCapabilities()
|
||||
{
|
||||
return back;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether or not flipping is supported.
|
||||
*
|
||||
* @return true if flipping is supported, false otherwise
|
||||
*/
|
||||
public boolean isPageFlipping()
|
||||
{
|
||||
return flip != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the result of a flipping operation. If this method
|
||||
* returns null then flipping is not supported. This implies that
|
||||
* "blitting", a fast block transfer, is used to copy the contents
|
||||
* of the back buffer to the front buffer. Other possible return
|
||||
* values are:
|
||||
* <ul>
|
||||
* <li><code>FlipContents.UNDEFINED</code> the contents of the
|
||||
* back buffer are undefined after flipping.</li>
|
||||
* <li><code>FlipContents.BACKGROUND</code> the contents of the
|
||||
* back buffer are cleared to the background color after
|
||||
* flipping.</li>
|
||||
* <li><code>FlipContents.PRIOR</code> the back buffer contains
|
||||
* the pre-flipping contents of the front * buffer after
|
||||
* flipping.</li>
|
||||
* <li><code>FlipContents.COPIED</code> the back buffer has the
|
||||
* same contents as the front buffer after flipping.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return the result of a flipping operation or null if flipping is
|
||||
* not supported
|
||||
*/
|
||||
public FlipContents getFlipContents()
|
||||
{
|
||||
return flip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if flipping is only supported in fullscreen mode.
|
||||
*
|
||||
* @return true if flipping is only supported in fullscreen mode,
|
||||
* false otherwise
|
||||
*/
|
||||
public boolean isFullScreenRequired()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if flipping can involve more than two buffers. One
|
||||
* or more intermediate buffers may be available in addition to the
|
||||
* front and back buffers.
|
||||
*
|
||||
* @return true if there are more than two buffers available for
|
||||
* flipping, false otherwise
|
||||
*/
|
||||
public boolean isMultiBufferAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone this buffering capability descriptor.
|
||||
*
|
||||
* @return a clone of this buffer capability descriptor
|
||||
*/
|
||||
public Object clone()
|
||||
{
|
||||
try
|
||||
{
|
||||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
throw (Error) new InternalError().initCause(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,466 @@
|
||||
/* Button.java -- AWT button widget
|
||||
Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.peer.ButtonPeer;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.EventListener;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleAction;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
import javax.accessibility.AccessibleValue;
|
||||
|
||||
/**
|
||||
* This class provides a button widget for the AWT.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Tom Tromey (tromey@cygnus.com)
|
||||
*/
|
||||
public class Button extends Component
|
||||
implements java.io.Serializable, Accessible
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// FIXME: Need readObject/writeObject for serialization
|
||||
|
||||
// Serialization version constant
|
||||
private static final long serialVersionUID = -8774683716313001058L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The action command name for this button.
|
||||
* This is package-private to avoid an accessor method.
|
||||
*/
|
||||
String actionCommand;
|
||||
|
||||
/**
|
||||
* @serial The label for this button.
|
||||
* This is package-private to avoid an accessor method.
|
||||
*/
|
||||
String label;
|
||||
|
||||
// List of ActionListeners for this class.
|
||||
private transient ActionListener action_listeners;
|
||||
|
||||
/*
|
||||
* The number used to generate the name returned by getName.
|
||||
*/
|
||||
private static transient long next_button_number;
|
||||
|
||||
protected class AccessibleAWTButton extends AccessibleAWTComponent
|
||||
implements AccessibleAction, AccessibleValue
|
||||
{
|
||||
protected AccessibleAWTButton()
|
||||
{
|
||||
// Do nothing here.
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleAction#getAccessibleActionCount()
|
||||
*/
|
||||
public int getAccessibleActionCount()
|
||||
{
|
||||
// Only 1 action possible
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int)
|
||||
*/
|
||||
public String getAccessibleActionDescription(int i)
|
||||
{
|
||||
// JDK 1.4.2 returns the string "click" for action 0. However, the API
|
||||
// docs don't say what the string to be returned is, beyond being a
|
||||
// description of the action. So we return the same thing for
|
||||
// compatibility with 1.4.2.
|
||||
if (i == 0)
|
||||
return "click";
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleAction#doAccessibleAction(int)
|
||||
*/
|
||||
public boolean doAccessibleAction(int i)
|
||||
{
|
||||
if (i != 0)
|
||||
return false;
|
||||
processActionEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand));
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getAccessibleName()
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
public AccessibleAction getAccessibleAction()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccessibleValue getAccessibleValue()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue()
|
||||
*/
|
||||
public Number getCurrentAccessibleValue()
|
||||
{
|
||||
// Docs say return 1 if selected, but buttons can't be selected, right?
|
||||
return new Integer(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number)
|
||||
*/
|
||||
public boolean setCurrentAccessibleValue(Number number)
|
||||
{
|
||||
// Since there's no selection with buttons, we're ignoring this.
|
||||
// TODO someone who knows shoulw check this.
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue()
|
||||
*/
|
||||
public Number getMinimumAccessibleValue()
|
||||
{
|
||||
return new Integer(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue()
|
||||
*/
|
||||
public Number getMaximumAccessibleValue()
|
||||
{
|
||||
return new Integer(0);
|
||||
}
|
||||
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.PUSH_BUTTON;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Button</code> with no label.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
*/
|
||||
public
|
||||
Button()
|
||||
{
|
||||
this("");
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Button</code> with the specified
|
||||
* label. The action command name is also initialized to this value.
|
||||
*
|
||||
* @param label The label to display on the button.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
*/
|
||||
public
|
||||
Button(String label)
|
||||
{
|
||||
this.label = label;
|
||||
actionCommand = label;
|
||||
|
||||
if (GraphicsEnvironment.isHeadless ())
|
||||
throw new HeadlessException ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the label for this button.
|
||||
*
|
||||
* @return The label for this button.
|
||||
*/
|
||||
public String
|
||||
getLabel()
|
||||
{
|
||||
return(label);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the label for this button to the specified value.
|
||||
*
|
||||
* @param label The new label for this button.
|
||||
*/
|
||||
public synchronized void
|
||||
setLabel(String label)
|
||||
{
|
||||
this.label = label;
|
||||
actionCommand = label;
|
||||
if (peer != null)
|
||||
{
|
||||
ButtonPeer bp = (ButtonPeer) peer;
|
||||
bp.setLabel (label);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the action command name for this button.
|
||||
*
|
||||
* @return The action command name for this button.
|
||||
*/
|
||||
public String
|
||||
getActionCommand()
|
||||
{
|
||||
return(actionCommand);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the action command name for this button to the specified value.
|
||||
*
|
||||
* @param actionCommand The new action command name.
|
||||
*/
|
||||
public void
|
||||
setActionCommand(String actionCommand)
|
||||
{
|
||||
this.actionCommand = actionCommand == null ? label : actionCommand;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds a new entry to the list of listeners that will receive
|
||||
* action events from this button.
|
||||
*
|
||||
* @param listener The listener to add.
|
||||
*/
|
||||
public synchronized void
|
||||
addActionListener(ActionListener listener)
|
||||
{
|
||||
action_listeners = AWTEventMulticaster.add(action_listeners, listener);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes the specified listener from the list of listeners that will
|
||||
* receive action events from this button.
|
||||
*
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
public synchronized void
|
||||
removeActionListener(ActionListener listener)
|
||||
{
|
||||
action_listeners = AWTEventMulticaster.remove(action_listeners, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all added <code>ActionListener</code> objects.
|
||||
*
|
||||
* @return an array of listeners
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public synchronized ActionListener[] getActionListeners()
|
||||
{
|
||||
return (ActionListener[])
|
||||
AWTEventMulticaster.getListeners(action_listeners,
|
||||
ActionListener.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all registered EventListers of the given listenerType.
|
||||
* listenerType must be a subclass of EventListener, or a
|
||||
* ClassClassException is thrown.
|
||||
*
|
||||
* @param listenerType the listener type to return
|
||||
*
|
||||
* @return an array of listeners
|
||||
*
|
||||
* @exception ClassCastException If listenerType doesn't specify a class or
|
||||
* interface that implements @see java.util.EventListener.
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
public EventListener[] getListeners(Class listenerType)
|
||||
{
|
||||
if (listenerType == ActionListener.class)
|
||||
return getActionListeners();
|
||||
return (EventListener[]) Array.newInstance(listenerType, 0);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Notifies this button that it should create its native peer object.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit ().createButton (this);
|
||||
super.addNotify();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Processes an event for this button. If the specified event is an
|
||||
* instance of <code>ActionEvent</code>, then the
|
||||
* <code>processActionEvent()</code> method is called to dispatch it
|
||||
* to any registered listeners. Otherwise, the superclass method
|
||||
* will be invoked. Note that this method will not be called at all
|
||||
* unless <code>ActionEvent</code>'s are enabled. This will be done
|
||||
* implicitly if any listeners are added.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void
|
||||
processEvent(AWTEvent event)
|
||||
{
|
||||
if (event instanceof ActionEvent)
|
||||
processActionEvent((ActionEvent)event);
|
||||
else
|
||||
super.processEvent(event);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method dispatches an action event for this button to any
|
||||
* registered listeners.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void
|
||||
processActionEvent(ActionEvent event)
|
||||
{
|
||||
if (action_listeners != null)
|
||||
action_listeners.actionPerformed(event);
|
||||
}
|
||||
|
||||
void
|
||||
dispatchEventImpl(AWTEvent e)
|
||||
{
|
||||
if (e.id <= ActionEvent.ACTION_LAST
|
||||
&& e.id >= ActionEvent.ACTION_FIRST
|
||||
&& (action_listeners != null
|
||||
|| (eventMask & AWTEvent.ACTION_EVENT_MASK) != 0))
|
||||
processEvent(e);
|
||||
else
|
||||
super.dispatchEventImpl(e);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this button.
|
||||
*
|
||||
* @return A debugging string for this button.
|
||||
*/
|
||||
protected String
|
||||
paramString()
|
||||
{
|
||||
return getName () + "," + getX () + "," + getY () + ","
|
||||
+ getWidth () + "x" + getHeight () + ",label=" + getLabel ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>Button</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTButton();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique name for this button.
|
||||
*
|
||||
* @return A unique name for this button.
|
||||
*/
|
||||
String generateName ()
|
||||
{
|
||||
return "button" + getUniqueLong ();
|
||||
}
|
||||
|
||||
private static synchronized long getUniqueLong ()
|
||||
{
|
||||
return next_button_number++;
|
||||
}
|
||||
|
||||
} // class Button
|
||||
|
||||
@@ -0,0 +1,354 @@
|
||||
/* Canvas.java --
|
||||
Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.BufferStrategy;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
|
||||
/**
|
||||
* The <code>Canvas</code> component provides a blank rectangular
|
||||
* area, which the client application can use for drawing and for
|
||||
* capturing events. By overriding the <code>paint()</code> method,
|
||||
* the canvas can be used for anything from simple line drawings to
|
||||
* full-scale custom components.
|
||||
*
|
||||
* @author Original author unknown
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
public class Canvas
|
||||
extends Component
|
||||
implements Serializable, Accessible
|
||||
{
|
||||
|
||||
/**
|
||||
* Compatible with Sun's JDK.
|
||||
*/
|
||||
private static final long serialVersionUID = -2284879212465893870L;
|
||||
|
||||
/**
|
||||
* The graphics configuration associated with the canvas.
|
||||
*/
|
||||
transient GraphicsConfiguration graphicsConfiguration;
|
||||
|
||||
/**
|
||||
* The buffer strategy associated with this canvas.
|
||||
*/
|
||||
transient BufferStrategy bufferStrategy;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Canvas</code>.
|
||||
*/
|
||||
public Canvas()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Canvas</code>
|
||||
* with the supplied graphics configuration.
|
||||
*
|
||||
* @param graphicsConfiguration the graphics configuration to use
|
||||
* for this particular canvas.
|
||||
*/
|
||||
public Canvas(GraphicsConfiguration graphicsConfiguration)
|
||||
{
|
||||
this.graphicsConfiguration = graphicsConfiguration;
|
||||
}
|
||||
|
||||
GraphicsConfiguration getGraphicsConfigurationImpl()
|
||||
{
|
||||
if (graphicsConfiguration != null)
|
||||
return graphicsConfiguration;
|
||||
return super.getGraphicsConfigurationImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the native peer for this object.
|
||||
*/
|
||||
public void addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = (ComponentPeer) getToolkit().createCanvas(this);
|
||||
super.addNotify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Repaints the canvas window. This method should be overridden by
|
||||
* a subclass to do something useful, as this method simply paints
|
||||
* the window with the background color.
|
||||
*
|
||||
* @param gfx the <code>Graphics</code> to use for painting
|
||||
*/
|
||||
public void paint(Graphics gfx)
|
||||
{
|
||||
/* This implementation doesn't make much sense since the filling
|
||||
of background color is guaranteed for heavyweight components
|
||||
such as this. But there's no need to worry, since paint() is
|
||||
usually overridden anyway. */
|
||||
gfx.setColor(getBackground());
|
||||
Dimension size = getSize();
|
||||
gfx.fillRect(0, 0, size.width, size.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides accessibility support for the canvas.
|
||||
*/
|
||||
protected class AccessibleAWTCanvas
|
||||
extends AccessibleAWTComponent
|
||||
{
|
||||
/**
|
||||
* For compatability with Sun's JDK
|
||||
*/
|
||||
private static final long serialVersionUID = -6325592262103146699L;
|
||||
|
||||
/**
|
||||
* Constructor for the accessible canvas.
|
||||
*/
|
||||
protected AccessibleAWTCanvas()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the accessible role for the canvas.
|
||||
*
|
||||
* @return an instance of <code>AccessibleRole</code>, describing
|
||||
* the role of the canvas.
|
||||
*/
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.CANVAS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>Canvas</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTCanvas();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* A BltBufferStrategy for canvases.
|
||||
*/
|
||||
private class CanvasBltBufferStrategy extends BltBufferStrategy
|
||||
{
|
||||
/**
|
||||
* Creates a block transfer strategy for this canvas.
|
||||
*
|
||||
* @param numBuffers the number of buffers in this strategy
|
||||
* @param accelerated true if the buffer should be accelerated,
|
||||
* false otherwise
|
||||
*/
|
||||
CanvasBltBufferStrategy(int numBuffers, boolean accelerated)
|
||||
{
|
||||
super(numBuffers,
|
||||
new BufferCapabilities(new ImageCapabilities(accelerated),
|
||||
new ImageCapabilities(accelerated),
|
||||
BufferCapabilities.FlipContents.COPIED));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A FlipBufferStrategy for canvases.
|
||||
*/
|
||||
private class CanvasFlipBufferStrategy extends FlipBufferStrategy
|
||||
{
|
||||
/**
|
||||
* Creates a flip buffer strategy for this canvas.
|
||||
*
|
||||
* @param numBuffers the number of buffers in this strategy
|
||||
*
|
||||
* @throws AWTException if the requested number of buffers is not
|
||||
* supported
|
||||
*/
|
||||
CanvasFlipBufferStrategy(int numBuffers)
|
||||
throws AWTException
|
||||
{
|
||||
super(numBuffers,
|
||||
new BufferCapabilities(new ImageCapabilities(true),
|
||||
new ImageCapabilities(true),
|
||||
BufferCapabilities.FlipContents.COPIED));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a buffering strategy that manages how this canvas is
|
||||
* repainted. This method attempts to create the optimum strategy
|
||||
* based on the desired number of buffers. Hardware or software
|
||||
* acceleration may be used.
|
||||
*
|
||||
* createBufferStrategy attempts different levels of optimization,
|
||||
* but guarantees that some strategy with the requested number of
|
||||
* buffers will be created even if it is not optimal. First it
|
||||
* attempts to create a page flipping strategy, then an accelerated
|
||||
* blitting strategy, then an unaccelerated blitting strategy.
|
||||
*
|
||||
* Calling this method causes any existing buffer strategy to be
|
||||
* destroyed.
|
||||
*
|
||||
* @param numBuffers the number of buffers in this strategy
|
||||
*
|
||||
* @throws IllegalArgumentException if requested number of buffers
|
||||
* is less than one
|
||||
* @throws IllegalStateException if this canvas is not displayable
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void createBufferStrategy(int numBuffers)
|
||||
{
|
||||
if (numBuffers < 1)
|
||||
throw new IllegalArgumentException("Canvas.createBufferStrategy: number"
|
||||
+ " of buffers is less than one");
|
||||
|
||||
if (!isDisplayable())
|
||||
throw new IllegalStateException("Canvas.createBufferStrategy: canvas is"
|
||||
+ " not displayable");
|
||||
|
||||
BufferStrategy newStrategy = null;
|
||||
|
||||
// try a flipping strategy
|
||||
try
|
||||
{
|
||||
newStrategy = new CanvasFlipBufferStrategy(numBuffers);
|
||||
}
|
||||
catch (AWTException e)
|
||||
{
|
||||
}
|
||||
|
||||
// fall back to an accelerated blitting strategy
|
||||
if (newStrategy == null)
|
||||
newStrategy = new CanvasBltBufferStrategy(numBuffers, true);
|
||||
|
||||
bufferStrategy = newStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a buffering strategy that manages how this canvas is
|
||||
* repainted. This method attempts to create a strategy based on
|
||||
* the specified capabilities and throws an exception if the
|
||||
* requested strategy is not supported.
|
||||
*
|
||||
* Calling this method causes any existing buffer strategy to be
|
||||
* destroyed.
|
||||
*
|
||||
* @param numBuffers the number of buffers in this strategy
|
||||
* @param caps the requested buffering capabilities
|
||||
*
|
||||
* @throws AWTException if the requested capabilities are not
|
||||
* supported
|
||||
* @throws IllegalArgumentException if requested number of buffers
|
||||
* is less than one or if caps is null
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void createBufferStrategy(int numBuffers,
|
||||
BufferCapabilities caps)
|
||||
{
|
||||
if (numBuffers < 1)
|
||||
throw new IllegalArgumentException("Canvas.createBufferStrategy: number"
|
||||
+ " of buffers is less than one");
|
||||
|
||||
if (caps == null)
|
||||
throw new IllegalArgumentException("Canvas.createBufferStrategy:"
|
||||
+ " capabilities object is null");
|
||||
|
||||
// a flipping strategy was requested
|
||||
if (caps.isPageFlipping())
|
||||
{
|
||||
try
|
||||
{
|
||||
bufferStrategy = new CanvasFlipBufferStrategy(numBuffers);
|
||||
}
|
||||
catch (AWTException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
else
|
||||
bufferStrategy = new CanvasBltBufferStrategy(numBuffers, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the buffer strategy used by the canvas.
|
||||
*
|
||||
* @return the buffer strategy.
|
||||
* @since 1.4
|
||||
*/
|
||||
public BufferStrategy getBufferStrategy()
|
||||
{
|
||||
return bufferStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the canvas in response to a request to
|
||||
* <code>repaint()</code> it. The canvas is cleared
|
||||
* with the current background colour, before <code>paint()</code>
|
||||
* is called to add the new contents. Subclasses
|
||||
* which override this method should either call this
|
||||
* method via <code>super.update(graphics)</code> or re-implement
|
||||
* this behaviour, so as to ensure that the canvas is
|
||||
* clear before painting takes place.
|
||||
*
|
||||
* @param graphics the graphics context.
|
||||
*/
|
||||
public void update(Graphics graphics)
|
||||
{
|
||||
Dimension size;
|
||||
|
||||
/* Clear the canvas */
|
||||
size = getSize();
|
||||
graphics.clearRect(0, 0, size.width, size.height);
|
||||
/* Call the paint method */
|
||||
paint(graphics);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,483 @@
|
||||
/* CardLayout.java -- Card-based layout engine
|
||||
Copyright (C) 1999, 2000, 2002, 2003, 2004 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* This class implements a card-based layout scheme. Each included
|
||||
* component is treated as a card. Only one card can be shown at a
|
||||
* time. This class includes methods for changing which card is
|
||||
* shown.
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class CardLayout implements LayoutManager2, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -4328196481005934313L;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>CardLayout</code> with horizontal
|
||||
* and vertical gaps of 0.
|
||||
*/
|
||||
public CardLayout ()
|
||||
{
|
||||
this (0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new <code>CardLayout</code> object with the specified
|
||||
* horizontal and vertical gaps.
|
||||
*
|
||||
* @param hgap The horizontal gap
|
||||
* @param vgap The vertical gap
|
||||
*/
|
||||
public CardLayout (int hgap, int vgap)
|
||||
{
|
||||
this.hgap = hgap;
|
||||
this.vgap = vgap;
|
||||
this.tab = new Hashtable ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new component to the layout. The constraint must be a
|
||||
* string which is used to name the component. This string can
|
||||
* later be used to refer to the particular component.
|
||||
*
|
||||
* @param comp The component to add
|
||||
* @param constraints The name by which the component can later be called
|
||||
*
|
||||
* @exception IllegalArgumentException If `constraints' is not a
|
||||
* <code>String</code>
|
||||
*/
|
||||
public void addLayoutComponent (Component comp, Object constraints)
|
||||
{
|
||||
if (! (constraints instanceof String))
|
||||
throw new IllegalArgumentException ("Object " + constraints
|
||||
+ " is not a string");
|
||||
addLayoutComponent ((String) constraints, comp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new component to the layout. The name can be used later
|
||||
* to refer to the component.
|
||||
*
|
||||
* @param name The name by which the component can later be called
|
||||
* @param comp The component to add
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>addLayoutComponent(Component, Object)</code>.
|
||||
*/
|
||||
public void addLayoutComponent (String name, Component comp)
|
||||
{
|
||||
tab.put (name, comp);
|
||||
// First component added is the default component.
|
||||
comp.setVisible(tab.size() == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cause the first component in the container to be displayed.
|
||||
*
|
||||
* @param parent The parent container
|
||||
*/
|
||||
public void first (Container parent)
|
||||
{
|
||||
gotoComponent (parent, FIRST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this layout manager's horizontal gap.
|
||||
*
|
||||
* @return the horizontal gap
|
||||
*/
|
||||
public int getHgap ()
|
||||
{
|
||||
return hgap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this layout manager's x alignment. This method always
|
||||
* returns Component.CENTER_ALIGNMENT.
|
||||
*
|
||||
* @param parent Container using this layout manager instance
|
||||
*
|
||||
* @return the x-axis alignment
|
||||
*/
|
||||
public float getLayoutAlignmentX (Container parent)
|
||||
{
|
||||
return Component.CENTER_ALIGNMENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this layout manager's y alignment. This method always
|
||||
* returns Component.CENTER_ALIGNMENT.
|
||||
*
|
||||
* @param parent Container using this layout manager instance
|
||||
*
|
||||
* @return the y-axis alignment
|
||||
*/
|
||||
public float getLayoutAlignmentY (Container parent)
|
||||
{
|
||||
return Component.CENTER_ALIGNMENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this layout manager's vertical gap.
|
||||
*
|
||||
* @return the vertical gap
|
||||
*/
|
||||
public int getVgap ()
|
||||
{
|
||||
return vgap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate this layout manager's state.
|
||||
*/
|
||||
public void invalidateLayout (Container target)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Cause the last component in the container to be displayed.
|
||||
*
|
||||
* @param parent The parent container
|
||||
*/
|
||||
public void last (Container parent)
|
||||
{
|
||||
gotoComponent (parent, LAST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lays out the container. This is done by resizing the child components
|
||||
* to be the same size as the parent, less insets and gaps.
|
||||
*
|
||||
* @param parent The parent container.
|
||||
*/
|
||||
public void layoutContainer (Container parent)
|
||||
{
|
||||
synchronized (parent.getTreeLock ())
|
||||
{
|
||||
int width = parent.width;
|
||||
int height = parent.height;
|
||||
|
||||
Insets ins = parent.getInsets ();
|
||||
|
||||
int num = parent.ncomponents;
|
||||
Component[] comps = parent.component;
|
||||
|
||||
int x = ins.left + hgap;
|
||||
int y = ins.top + vgap;
|
||||
width = width - 2 * hgap - ins.left - ins.right;
|
||||
height = height - 2 * vgap - ins.top - ins.bottom;
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
comps[i].setBounds (x, y, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum layout size of the container.
|
||||
*
|
||||
* @param target The parent container
|
||||
*
|
||||
* @return the maximum layout size
|
||||
*/
|
||||
public Dimension maximumLayoutSize (Container target)
|
||||
{
|
||||
// The JCL says that this returns Integer.MAX_VALUE for both
|
||||
// dimensions. But that just seems wrong to me.
|
||||
return getSize (target, MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the minimum layout size of the container.
|
||||
*
|
||||
* @param target The parent container
|
||||
*
|
||||
* @return the minimum layout size
|
||||
*/
|
||||
public Dimension minimumLayoutSize (Container target)
|
||||
{
|
||||
return getSize (target, MIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cause the next component in the container to be displayed. If
|
||||
* this current card is the last one in the deck, the first
|
||||
* component is displayed.
|
||||
*
|
||||
* @param parent The parent container
|
||||
*/
|
||||
public void next (Container parent)
|
||||
{
|
||||
gotoComponent (parent, NEXT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the preferred layout size of the container.
|
||||
*
|
||||
* @param parent The parent container
|
||||
*
|
||||
* @return the preferred layout size
|
||||
*/
|
||||
public Dimension preferredLayoutSize (Container parent)
|
||||
{
|
||||
return getSize (parent, PREF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cause the previous component in the container to be displayed.
|
||||
* If this current card is the first one in the deck, the last
|
||||
* component is displayed.
|
||||
*
|
||||
* @param parent The parent container
|
||||
*/
|
||||
public void previous (Container parent)
|
||||
{
|
||||
gotoComponent (parent, PREV);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the indicated component from this layout manager.
|
||||
*
|
||||
* @param comp The component to remove
|
||||
*/
|
||||
public void removeLayoutComponent (Component comp)
|
||||
{
|
||||
Enumeration e = tab.keys ();
|
||||
while (e.hasMoreElements ())
|
||||
{
|
||||
Object key = e.nextElement ();
|
||||
if (tab.get (key) == comp)
|
||||
{
|
||||
tab.remove (key);
|
||||
Container parent = comp.getParent();
|
||||
next(parent);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this layout manager's horizontal gap.
|
||||
*
|
||||
* @param hgap The new gap
|
||||
*/
|
||||
public void setHgap (int hgap)
|
||||
{
|
||||
this.hgap = hgap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this layout manager's vertical gap.
|
||||
*
|
||||
* @param vgap The new gap
|
||||
*/
|
||||
public void setVgap (int vgap)
|
||||
{
|
||||
this.vgap = vgap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cause the named component to be shown. If the component name is
|
||||
* unknown, this method does nothing.
|
||||
*
|
||||
* @param parent The parent container
|
||||
* @param name The name of the component to show
|
||||
*/
|
||||
public void show (Container parent, String name)
|
||||
{
|
||||
Object target = tab.get (name);
|
||||
if (target != null)
|
||||
{
|
||||
int num = parent.ncomponents;
|
||||
// This is more efficient than calling getComponents().
|
||||
Component[] comps = parent.component;
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
if (comps[i].isVisible())
|
||||
{
|
||||
if (target == comps[i])
|
||||
return;
|
||||
comps[i].setVisible (false);
|
||||
}
|
||||
}
|
||||
((Component) target).setVisible (true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this layout manager.
|
||||
*
|
||||
* @return A string representation of this object.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return getClass ().getName () + "[" + hgap + "," + vgap + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* This implements first(), last(), next(), and previous().
|
||||
*
|
||||
* @param parent The parent container
|
||||
* @param what The type of goto: FIRST, LAST, NEXT or PREV
|
||||
*/
|
||||
private void gotoComponent (Container parent, int what)
|
||||
{
|
||||
synchronized (parent.getTreeLock ())
|
||||
{
|
||||
int num = parent.ncomponents;
|
||||
// This is more efficient than calling getComponents().
|
||||
Component[] comps = parent.component;
|
||||
|
||||
if (num == 1)
|
||||
{
|
||||
comps[0].setVisible(true);
|
||||
return;
|
||||
}
|
||||
|
||||
int choice = -1;
|
||||
|
||||
if (what == FIRST)
|
||||
choice = 0;
|
||||
else if (what == LAST)
|
||||
choice = num - 1;
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
if (comps[i].isVisible ())
|
||||
{
|
||||
if (what == NEXT)
|
||||
{
|
||||
choice = i + 1;
|
||||
if (choice == num)
|
||||
choice = 0;
|
||||
}
|
||||
else if (what == PREV)
|
||||
{
|
||||
choice = i - 1;
|
||||
if (choice < 0)
|
||||
choice = num - 1;
|
||||
}
|
||||
else if (choice == i)
|
||||
{
|
||||
// Do nothing if we're already looking at the right
|
||||
// component.
|
||||
return;
|
||||
}
|
||||
comps[i].setVisible (false);
|
||||
|
||||
if (choice >= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (choice >= 0 && choice < num)
|
||||
comps[choice].setVisible (true);
|
||||
}
|
||||
}
|
||||
|
||||
// Compute the size according to WHAT.
|
||||
private Dimension getSize (Container parent, int what)
|
||||
{
|
||||
synchronized (parent.getTreeLock ())
|
||||
{
|
||||
int w = 0, h = 0, num = parent.ncomponents;
|
||||
Component[] comps = parent.component;
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
Dimension d;
|
||||
|
||||
if (what == MIN)
|
||||
d = comps[i].getMinimumSize ();
|
||||
else if (what == MAX)
|
||||
d = comps[i].getMaximumSize ();
|
||||
else
|
||||
d = comps[i].getPreferredSize ();
|
||||
|
||||
w = Math.max (d.width, w);
|
||||
h = Math.max (d.height, h);
|
||||
}
|
||||
|
||||
Insets i = parent.getInsets ();
|
||||
w += 2 * hgap + i.right + i.left;
|
||||
h += 2 * vgap + i.bottom + i.top;
|
||||
|
||||
// Handle overflow.
|
||||
if (w < 0)
|
||||
w = Integer.MAX_VALUE;
|
||||
if (h < 0)
|
||||
h = Integer.MAX_VALUE;
|
||||
|
||||
return new Dimension (w, h);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @serial Horizontal gap value.
|
||||
*/
|
||||
private int hgap;
|
||||
|
||||
/**
|
||||
* @serial Vertical gap value.
|
||||
*/
|
||||
private int vgap;
|
||||
|
||||
/**
|
||||
* @serial Table of named components.
|
||||
*/
|
||||
private Hashtable tab;
|
||||
|
||||
// These constants are used by the private gotoComponent method.
|
||||
private static final int FIRST = 0;
|
||||
private static final int LAST = 1;
|
||||
private static final int NEXT = 2;
|
||||
private static final int PREV = 3;
|
||||
|
||||
// These constants are used by the private getSize method.
|
||||
private static final int MIN = 0;
|
||||
private static final int MAX = 1;
|
||||
private static final int PREF = 2;
|
||||
}
|
||||
@@ -0,0 +1,649 @@
|
||||
/* Checkbox.java -- An AWT checkbox widget
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.peer.CheckboxPeer;
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleAction;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
import javax.accessibility.AccessibleState;
|
||||
import javax.accessibility.AccessibleStateSet;
|
||||
import javax.accessibility.AccessibleValue;
|
||||
|
||||
/**
|
||||
* This class implements a component which has an on/off state. Two
|
||||
* or more Checkboxes can be grouped by a CheckboxGroup.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
*/
|
||||
public class Checkbox extends Component
|
||||
implements ItemSelectable, Accessible, Serializable
|
||||
{
|
||||
|
||||
// FIXME: Need readObject/writeObject for this.
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization Constant
|
||||
private static final long serialVersionUID = 7270714317450821763L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The checkbox group for this checkbox.
|
||||
*/
|
||||
private CheckboxGroup group;
|
||||
|
||||
/**
|
||||
* @serial The label on this checkbox.
|
||||
*/
|
||||
private String label;
|
||||
|
||||
/**
|
||||
* @serial The state of this checkbox.
|
||||
* This is package-private to avoid an accessor method.
|
||||
*/
|
||||
boolean state;
|
||||
|
||||
// The list of listeners for this object.
|
||||
private transient ItemListener item_listeners;
|
||||
|
||||
/*
|
||||
* The number used to generate the name returned by getName.
|
||||
*/
|
||||
private static transient long next_checkbox_number;
|
||||
|
||||
/**
|
||||
* This class provides accessibility support for the
|
||||
* checkbox.
|
||||
*
|
||||
* @author Jerry Quinn (jlquinn@optonline.net)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
*/
|
||||
protected class AccessibleAWTCheckbox
|
||||
extends AccessibleAWTComponent
|
||||
implements ItemListener, AccessibleAction, AccessibleValue
|
||||
{
|
||||
/**
|
||||
* Serialization constant to match JDK 1.5
|
||||
*/
|
||||
private static final long serialVersionUID = 7881579233144754107L;
|
||||
|
||||
/**
|
||||
* Default constructor which simply calls the
|
||||
* super class for generic component accessibility
|
||||
* handling.
|
||||
*/
|
||||
public AccessibleAWTCheckbox()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures changes to the state of the checkbox and
|
||||
* fires appropriate accessible property change events.
|
||||
*
|
||||
* @param event the event fired.
|
||||
* @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent)
|
||||
*/
|
||||
public void itemStateChanged(ItemEvent event)
|
||||
{
|
||||
firePropertyChange(ACCESSIBLE_STATE_PROPERTY,
|
||||
state ? null : AccessibleState.CHECKED,
|
||||
state ? AccessibleState.CHECKED : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an implementation of the <code>AccessibleAction</code>
|
||||
* interface for this accessible object. In this case, the
|
||||
* current instance is simply returned (with a more appropriate
|
||||
* type), as it also implements the accessible action as well as
|
||||
* the context.
|
||||
*
|
||||
* @return the accessible action associated with this context.
|
||||
* @see javax.accessibility.AccessibleAction
|
||||
*/
|
||||
public AccessibleAction getAccessibleAction()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an implementation of the <code>AccessibleValue</code>
|
||||
* interface for this accessible object. In this case, the
|
||||
* current instance is simply returned (with a more appropriate
|
||||
* type), as it also implements the accessible value as well as
|
||||
* the context.
|
||||
*
|
||||
* @return the accessible value associated with this context.
|
||||
* @see javax.accessibility.AccessibleValue
|
||||
*/
|
||||
public AccessibleValue getAccessibleValue()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/*
|
||||
* The following methods are implemented in the JDK (up to
|
||||
* 1.5) as stubs. We do likewise here.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the number of actions associated with this accessible
|
||||
* object. This default implementation returns 0.
|
||||
*
|
||||
* @return the number of accessible actions available.
|
||||
* @see javax.accessibility.AccessibleAction#getAccessibleActionCount()
|
||||
*/
|
||||
public int getAccessibleActionCount()
|
||||
{
|
||||
// 1.4.1 and 1.5 do this
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a description of the action with the supplied id.
|
||||
* This default implementation always returns null.
|
||||
*
|
||||
* @param i the id of the action whose description should be
|
||||
* retrieved.
|
||||
* @return a <code>String</code> describing the action.
|
||||
* @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int)
|
||||
*/
|
||||
public String getAccessibleActionDescription(int i)
|
||||
{
|
||||
// 1.5 does this
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the action with the specified id. This
|
||||
* default implementation simply returns false.
|
||||
*
|
||||
* @param i the id of the action to perform.
|
||||
* @return true if the action was performed.
|
||||
* @see javax.accessibility.AccessibleAction#doAccessibleAction(int)
|
||||
*/
|
||||
public boolean doAccessibleAction(int i)
|
||||
{
|
||||
// 1.5 does this
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current value of this accessible object.
|
||||
* If no value has been set, null is returned. This
|
||||
* default implementation always returns null, regardless.
|
||||
*
|
||||
* @return the numeric value of this object, or null if
|
||||
* no value has been set.
|
||||
* @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue()
|
||||
*/
|
||||
public Number getCurrentAccessibleValue()
|
||||
{
|
||||
// 1.5 does this
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current value of this accessible object
|
||||
* to that supplied. In this default implementation,
|
||||
* the value is never set and the method always returns
|
||||
* false.
|
||||
*
|
||||
* @param number the new accessible value.
|
||||
* @return true if the value was set.
|
||||
* @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number)
|
||||
*/
|
||||
public boolean setCurrentAccessibleValue(Number number)
|
||||
{
|
||||
// 1.5 does this
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum acceptable accessible value used
|
||||
* by this object, or null if no minimum value exists.
|
||||
* This default implementation always returns null.
|
||||
*
|
||||
* @return the minimum acceptable accessible value, or null
|
||||
* if there is no minimum.
|
||||
* @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue()
|
||||
*/
|
||||
public Number getMinimumAccessibleValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum acceptable accessible value used
|
||||
* by this object, or null if no maximum value exists.
|
||||
* This default implementation always returns null.
|
||||
*
|
||||
* @return the maximum acceptable accessible value, or null
|
||||
* if there is no maximum.
|
||||
* @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue()
|
||||
*/
|
||||
public Number getMaximumAccessibleValue()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the role of this accessible object.
|
||||
*
|
||||
* @return the instance of <code>AccessibleRole</code>,
|
||||
* which describes this object.
|
||||
* @see javax.accessibility.AccessibleRole
|
||||
*/
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.CHECK_BOX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state set of this accessible object.
|
||||
*
|
||||
* @return a set of <code>AccessibleState</code>s
|
||||
* which represent the current state of the
|
||||
* accessible object.
|
||||
* @see javax.accessibility.AccessibleState
|
||||
* @see javax.accessibility.AccessibleStateSet
|
||||
*/
|
||||
public AccessibleStateSet getAccessibleStateSet()
|
||||
{
|
||||
AccessibleStateSet set = super.getAccessibleStateSet();
|
||||
if (state)
|
||||
set.add(AccessibleState.CHECKED);
|
||||
return set;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Checkbox</code> with no label,
|
||||
* an initial state of off, and that is not part of any checkbox group.
|
||||
*/
|
||||
public
|
||||
Checkbox()
|
||||
{
|
||||
this("", false, null);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Checkbox</code> with the specified
|
||||
* label, an initial state of off, and that is not part of any checkbox
|
||||
* group.
|
||||
*
|
||||
* @param label The label for this checkbox.
|
||||
*/
|
||||
public
|
||||
Checkbox(String label)
|
||||
{
|
||||
this(label, false, null);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Checkbox</code> with the specified
|
||||
* label and initial state, and that is not part of any checkbox
|
||||
* group.
|
||||
*
|
||||
* @param label The label for this checkbox.
|
||||
* @param state The initial state of the checkbox, <code>true</code> for
|
||||
* on, <code>false</code> for off.
|
||||
*/
|
||||
public
|
||||
Checkbox(String label, boolean state)
|
||||
{
|
||||
this(label, state, null);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Checkbox</code> with the specified
|
||||
* label, initial state, and checkbox group.
|
||||
*
|
||||
* @param label The label for this checkbox.
|
||||
* @param group The checkbox group for this box, or <code>null</code>
|
||||
* if there is no checkbox group.
|
||||
* @param state The initial state of the checkbox, <code>true</code> for
|
||||
* on, <code>false</code> for off.
|
||||
*/
|
||||
public
|
||||
Checkbox(String label, CheckboxGroup group, boolean state)
|
||||
{
|
||||
this(label, state, group);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Checkbox</code> with the specified
|
||||
* label, initial state, and checkbox group.
|
||||
*
|
||||
* @param label The label for this checkbox.
|
||||
* @param state The initial state of the checkbox, <code>true</code> for
|
||||
* on, <code>false</code> for off.
|
||||
* @param group The checkbox group for this box, or <code>null</code>
|
||||
* if there is no checkbox group.
|
||||
*/
|
||||
public
|
||||
Checkbox(String label, boolean state, CheckboxGroup group)
|
||||
{
|
||||
this.label = label;
|
||||
this.state = state;
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the label for this checkbox.
|
||||
*
|
||||
* @return The label for this checkbox.
|
||||
*/
|
||||
public String
|
||||
getLabel()
|
||||
{
|
||||
return(label);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the label for this checkbox to the specified value.
|
||||
*
|
||||
* @param label The new checkbox label.
|
||||
*/
|
||||
public synchronized void
|
||||
setLabel(String label)
|
||||
{
|
||||
this.label = label;
|
||||
if (peer != null)
|
||||
{
|
||||
CheckboxPeer cp = (CheckboxPeer) peer;
|
||||
cp.setLabel(label);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the state of this checkbox.
|
||||
*
|
||||
* @return The state of this checkbox, which will be <code>true</code> for
|
||||
* on and <code>false</code> for off.
|
||||
*/
|
||||
public boolean
|
||||
getState()
|
||||
{
|
||||
return(state);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the state of this checkbox to the specified value.
|
||||
*
|
||||
* @param state The new state of the checkbox, which will be <code>true</code>
|
||||
* for on or <code>false</code> for off.
|
||||
*/
|
||||
public synchronized void
|
||||
setState(boolean state)
|
||||
{
|
||||
this.state = state;
|
||||
if (peer != null)
|
||||
{
|
||||
CheckboxPeer cp = (CheckboxPeer) peer;
|
||||
cp.setState (state);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns an array of length one containing the checkbox label if this
|
||||
* checkbox is selected. Otherwise <code>null</code> is returned.
|
||||
*
|
||||
* @return The selection state of this checkbox.
|
||||
*/
|
||||
public Object[]
|
||||
getSelectedObjects()
|
||||
{
|
||||
if (state == false)
|
||||
return(null);
|
||||
|
||||
Object[] objs = new Object[1];
|
||||
objs[0] = label;
|
||||
|
||||
return(objs);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the checkbox group this object is a member of, if any.
|
||||
*
|
||||
* @return This object's checkbox group, of <code>null</code> if it is
|
||||
* not a member of any group.
|
||||
*/
|
||||
public CheckboxGroup
|
||||
getCheckboxGroup()
|
||||
{
|
||||
return(group);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets this object's checkbox group to the specified group.
|
||||
*
|
||||
* @param group The new checkbox group, or <code>null</code> to make this
|
||||
* object part of no checkbox group.
|
||||
*/
|
||||
public synchronized void
|
||||
setCheckboxGroup(CheckboxGroup group)
|
||||
{
|
||||
this.group = group;
|
||||
if (peer != null)
|
||||
{
|
||||
CheckboxPeer cp = (CheckboxPeer) peer;
|
||||
cp.setCheckboxGroup (group);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Creates this object's native peer.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit ().createCheckbox (this);
|
||||
super.addNotify ();
|
||||
}
|
||||
|
||||
public ItemListener[] getItemListeners ()
|
||||
{
|
||||
return (ItemListener[])
|
||||
AWTEventMulticaster.getListeners (item_listeners, ItemListener.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new listeners to the list of registered listeners for this object.
|
||||
*
|
||||
* @param listener The new listener to add.
|
||||
*/
|
||||
public synchronized void
|
||||
addItemListener(ItemListener listener)
|
||||
{
|
||||
item_listeners = AWTEventMulticaster.add(item_listeners, listener);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes a listener from the list of registered listeners for this object.
|
||||
*
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
public synchronized void
|
||||
removeItemListener(ItemListener listener)
|
||||
{
|
||||
item_listeners = AWTEventMulticaster.remove(item_listeners, listener);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Processes this event by calling <code>processItemEvent()</code> if it
|
||||
* is any instance of <code>ItemEvent</code>. Otherwise it is passed to
|
||||
* the superclass for processing.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void
|
||||
processEvent(AWTEvent event)
|
||||
{
|
||||
if (event instanceof ItemEvent)
|
||||
processItemEvent((ItemEvent)event);
|
||||
else
|
||||
super.processEvent(event);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Processes this event by dispatching it to any registered listeners.
|
||||
*
|
||||
* @param event The <code>ItemEvent</code> to process.
|
||||
*/
|
||||
protected void
|
||||
processItemEvent(ItemEvent event)
|
||||
{
|
||||
if (item_listeners != null)
|
||||
item_listeners.itemStateChanged(event);
|
||||
}
|
||||
|
||||
void
|
||||
dispatchEventImpl(AWTEvent e)
|
||||
{
|
||||
if (e.id <= ItemEvent.ITEM_LAST
|
||||
&& e.id >= ItemEvent.ITEM_FIRST
|
||||
&& (item_listeners != null
|
||||
|| (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0))
|
||||
processEvent(e);
|
||||
else
|
||||
super.dispatchEventImpl(e);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this object.
|
||||
*/
|
||||
protected String
|
||||
paramString()
|
||||
{
|
||||
return ("label=" + label + ",state=" + state + ",group=" + group
|
||||
+ "," + super.paramString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>Checkbox</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
{
|
||||
AccessibleAWTCheckbox ac = new AccessibleAWTCheckbox();
|
||||
accessibleContext = ac;
|
||||
addItemListener(ac);
|
||||
}
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique name for this checkbox.
|
||||
*
|
||||
* @return A unique name for this checkbox.
|
||||
*/
|
||||
String generateName()
|
||||
{
|
||||
return "checkbox" + getUniqueLong();
|
||||
}
|
||||
|
||||
private static synchronized long getUniqueLong()
|
||||
{
|
||||
return next_checkbox_number++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/* CheckboxGroup.java -- A grouping class for checkboxes.
|
||||
Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This class if for combining checkboxes into groups so that only
|
||||
* one checkbox in the group can be selected at any one time.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
*/
|
||||
public class CheckboxGroup implements java.io.Serializable
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization constant
|
||||
private static final long serialVersionUID = 3729780091441768983L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The currently selected checkbox.
|
||||
*/
|
||||
private Checkbox selectedCheckbox;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>CheckboxGroup</code>.
|
||||
*/
|
||||
public
|
||||
CheckboxGroup()
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the currently selected checkbox, or <code>null</code> if none
|
||||
* of the checkboxes in this group are selected.
|
||||
*
|
||||
* @return The selected checkbox.
|
||||
*/
|
||||
public Checkbox
|
||||
getSelectedCheckbox()
|
||||
{
|
||||
return getCurrent ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the currently selected checkbox, or <code>null</code> if none
|
||||
* of the checkboxes in this group are selected.
|
||||
*
|
||||
* @return The selected checkbox.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getSelectedCheckbox()</code>.
|
||||
*/
|
||||
public Checkbox
|
||||
getCurrent()
|
||||
{
|
||||
return(selectedCheckbox);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method sets the specified checkbox to be the selected on in this
|
||||
* group, and unsets all others.
|
||||
*
|
||||
* @param selectedCheckbox The new selected checkbox.
|
||||
*/
|
||||
public void
|
||||
setSelectedCheckbox(Checkbox selectedCheckbox)
|
||||
{
|
||||
setCurrent (selectedCheckbox);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method sets the specified checkbox to be the selected on in this
|
||||
* group, and unsets all others.
|
||||
*
|
||||
* @param selectedCheckbox The new selected checkbox.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>setSelectedCheckbox()</code>.
|
||||
*/
|
||||
public void
|
||||
setCurrent(Checkbox selectedCheckbox)
|
||||
{
|
||||
if (this.selectedCheckbox != null)
|
||||
{
|
||||
if (this.selectedCheckbox.getCheckboxGroup() != this)
|
||||
return;
|
||||
|
||||
this.selectedCheckbox.setState(false);
|
||||
}
|
||||
|
||||
this.selectedCheckbox = selectedCheckbox;
|
||||
if (selectedCheckbox != null)
|
||||
selectedCheckbox.setState(true);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a string representation of this checkbox group.
|
||||
*
|
||||
* @return A string representation of this checkbox group.
|
||||
*/
|
||||
public String
|
||||
toString()
|
||||
{
|
||||
return(getClass().getName() + "[selectedCheckbox=" + selectedCheckbox + "]");
|
||||
}
|
||||
|
||||
} // class CheckboxGroup
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
/* CheckboxMenuItem.java -- A menu option with a checkbox on it.
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.peer.CheckboxMenuItemPeer;
|
||||
import java.util.EventListener;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleAction;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleValue;
|
||||
|
||||
/**
|
||||
* This class implements a menu item that has a checkbox on it indicating
|
||||
* the selected state of some option.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
*/
|
||||
public class CheckboxMenuItem extends MenuItem
|
||||
implements ItemSelectable, Accessible
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization constant
|
||||
private static final long serialVersionUID = 6190621106981774043L;
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The state of the checkbox, with <code>true</code> being on and
|
||||
* <code>false</code> being off.
|
||||
*/
|
||||
private boolean state;
|
||||
|
||||
// List of registered ItemListeners
|
||||
private transient ItemListener item_listeners;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>CheckboxMenuItem</code> with no
|
||||
* label and an initial state of off.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
||||
* returns true.
|
||||
*/
|
||||
public
|
||||
CheckboxMenuItem()
|
||||
{
|
||||
this("", false);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>CheckboxMenuItem</code> with the
|
||||
* specified label and an initial state of off.
|
||||
*
|
||||
* @param label The label of the menu item.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
||||
* returns true.
|
||||
*/
|
||||
public
|
||||
CheckboxMenuItem(String label)
|
||||
{
|
||||
this(label, false);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>CheckboxMenuItem</code> with the
|
||||
* specified label and initial state.
|
||||
*
|
||||
* @param label The label of the menu item.
|
||||
* @param state The initial state of the menu item, where <code>true</code>
|
||||
* is on, and <code>false</code> is off.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
||||
* returns true.
|
||||
*/
|
||||
public
|
||||
CheckboxMenuItem(String label, boolean state)
|
||||
{
|
||||
super(label);
|
||||
this.state = state;
|
||||
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the state of this menu item.
|
||||
*
|
||||
* @return The state of this menu item.
|
||||
*/
|
||||
public boolean
|
||||
getState()
|
||||
{
|
||||
return(state);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the state of this menu item.
|
||||
*
|
||||
* @param state The initial state of the menu item, where <code>true</code>
|
||||
* is on, and <code>false</code> is off.
|
||||
*/
|
||||
public synchronized void
|
||||
setState(boolean state)
|
||||
{
|
||||
this.state = state;
|
||||
if (peer != null)
|
||||
{
|
||||
CheckboxMenuItemPeer cp = (CheckboxMenuItemPeer) peer;
|
||||
cp.setState (state);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns an array of length 1 with the menu item label for this object
|
||||
* if the state is on. Otherwise <code>null</code> is returned.
|
||||
*
|
||||
* @return An array with this menu item's label if it has a state of on,
|
||||
* or <code>null</code> otherwise.
|
||||
*/
|
||||
public Object[]
|
||||
getSelectedObjects()
|
||||
{
|
||||
if (state == false)
|
||||
return(null);
|
||||
|
||||
Object[] obj = new Object[1];
|
||||
obj[0] = getLabel();
|
||||
|
||||
return(obj);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Create's this object's native peer
|
||||
*/
|
||||
public synchronized void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit().createCheckboxMenuItem(this);
|
||||
|
||||
super.addNotify ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds the specified listener to the list of registered item listeners
|
||||
* for this object.
|
||||
*
|
||||
* @param listener The listener to add.
|
||||
*/
|
||||
public synchronized void
|
||||
addItemListener(ItemListener listener)
|
||||
{
|
||||
item_listeners = AWTEventMulticaster.add(item_listeners, listener);
|
||||
|
||||
enableEvents(AWTEvent.ITEM_EVENT_MASK);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes the specified listener from the list of registered item
|
||||
* listeners for this object.
|
||||
*
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
public synchronized void
|
||||
removeItemListener(ItemListener listener)
|
||||
{
|
||||
item_listeners = AWTEventMulticaster.remove(item_listeners, listener);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Processes the specified event by calling <code>processItemEvent()</code>
|
||||
* if it is an instance of <code>ItemEvent</code> or calling the superclass
|
||||
* method otherwise.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void
|
||||
processEvent(AWTEvent event)
|
||||
{
|
||||
if (event instanceof ItemEvent)
|
||||
processItemEvent((ItemEvent)event);
|
||||
else
|
||||
super.processEvent(event);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Processes the specified event by dispatching it to any registered listeners.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void
|
||||
processItemEvent(ItemEvent event)
|
||||
{
|
||||
if (item_listeners != null)
|
||||
item_listeners.itemStateChanged(event);
|
||||
}
|
||||
|
||||
void
|
||||
dispatchEventImpl(AWTEvent e)
|
||||
{
|
||||
if (e instanceof ItemEvent)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
state = (((ItemEvent) e).getStateChange() == ItemEvent.SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
if (e.id <= ItemEvent.ITEM_LAST
|
||||
&& e.id >= ItemEvent.ITEM_FIRST
|
||||
&& (item_listeners != null
|
||||
|| (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0))
|
||||
processEvent(e);
|
||||
else
|
||||
super.dispatchEventImpl(e);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this object.
|
||||
*
|
||||
* @return A debugging string for this object.
|
||||
*/
|
||||
public String
|
||||
paramString()
|
||||
{
|
||||
return ("label=" + getLabel() + ",state=" + state
|
||||
+ "," + super.paramString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the objects currently registered as FooListeners
|
||||
* upon this <code>CheckboxMenuItem</code>. FooListeners are registered using
|
||||
* the addFooListener method.
|
||||
*
|
||||
* @exception ClassCastException If listenerType doesn't specify a class or
|
||||
* interface that implements java.util.EventListener.
|
||||
*/
|
||||
public EventListener[] getListeners (Class listenerType)
|
||||
{
|
||||
if (listenerType == ItemListener.class)
|
||||
return AWTEventMulticaster.getListeners (item_listeners, listenerType);
|
||||
|
||||
return super.getListeners (listenerType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an aray of all item listeners currently registered to this
|
||||
* <code>CheckBoxMenuItem</code>.
|
||||
*/
|
||||
public ItemListener[] getItemListeners ()
|
||||
{
|
||||
return (ItemListener[]) getListeners (ItemListener.class);
|
||||
}
|
||||
|
||||
|
||||
protected class AccessibleAWTCheckboxMenuItem extends AccessibleAWTMenuItem
|
||||
implements AccessibleAction, AccessibleValue
|
||||
{
|
||||
// I think the base class provides the necessary implementation
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>CheckboxMenuItem</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTCheckboxMenuItem();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
} // class CheckboxMenuItem
|
||||
|
||||
@@ -0,0 +1,638 @@
|
||||
/* Choice.java -- Java choice button widget.
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.awt.peer.ChoicePeer;
|
||||
import java.io.Serializable;
|
||||
import java.util.EventListener;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleAction;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
|
||||
/**
|
||||
* This class implements a drop down choice list.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class Choice extends Component
|
||||
implements ItemSelectable, Serializable, Accessible
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization constant
|
||||
private static final long serialVersionUID = -4075310674757313071L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial A list of items for the choice box, which can be <code>null</code>.
|
||||
* This is package-private to avoid an accessor method.
|
||||
*/
|
||||
Vector pItems = new Vector();
|
||||
|
||||
/**
|
||||
* @serial The index of the selected item in the choice box.
|
||||
*/
|
||||
private int selectedIndex = -1;
|
||||
|
||||
// Listener chain
|
||||
private ItemListener item_listeners;
|
||||
|
||||
/**
|
||||
* This class provides accessibility support for the
|
||||
* combo box.
|
||||
*
|
||||
* @author Jerry Quinn (jlquinn@optonline.net)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
*/
|
||||
protected class AccessibleAWTChoice
|
||||
extends AccessibleAWTComponent
|
||||
implements AccessibleAction
|
||||
{
|
||||
|
||||
/**
|
||||
* Serialization constant to match JDK 1.5
|
||||
*/
|
||||
private static final long serialVersionUID = 7175603582428509322L;
|
||||
|
||||
/**
|
||||
* Default constructor which simply calls the
|
||||
* super class for generic component accessibility
|
||||
* handling.
|
||||
*/
|
||||
public AccessibleAWTChoice()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an implementation of the <code>AccessibleAction</code>
|
||||
* interface for this accessible object. In this case, the
|
||||
* current instance is simply returned (with a more appropriate
|
||||
* type), as it also implements the accessible action as well as
|
||||
* the context.
|
||||
*
|
||||
* @return the accessible action associated with this context.
|
||||
* @see javax.accessibility.AccessibleAction
|
||||
*/
|
||||
public AccessibleAction getAccessibleAction()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the role of this accessible object.
|
||||
*
|
||||
* @return the instance of <code>AccessibleRole</code>,
|
||||
* which describes this object.
|
||||
* @see javax.accessibility.AccessibleRole
|
||||
*/
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.COMBO_BOX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of actions associated with this accessible
|
||||
* object. In this case, it is the number of choices available.
|
||||
*
|
||||
* @return the number of choices available.
|
||||
* @see javax.accessibility.AccessibleAction#getAccessibleActionCount()
|
||||
*/
|
||||
public int getAccessibleActionCount()
|
||||
{
|
||||
return pItems.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a description of the action with the supplied id.
|
||||
* In this case, it is the text used in displaying the particular
|
||||
* choice on-screen.
|
||||
*
|
||||
* @param i the id of the choice whose description should be
|
||||
* retrieved.
|
||||
* @return the <code>String</code> used to describe the choice.
|
||||
* @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int)
|
||||
*/
|
||||
public String getAccessibleActionDescription(int i)
|
||||
{
|
||||
return (String) pItems.get(i);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the action with the specified id. In this case,
|
||||
* calling this method provides the same behaviour as would
|
||||
* choosing a choice from the list in a visual manner.
|
||||
*
|
||||
* @param i the id of the choice to select.
|
||||
* @return true if a valid choice was specified.
|
||||
* @see javax.accessibility.AccessibleAction#doAccessibleAction(int)
|
||||
*/
|
||||
public boolean doAccessibleAction(int i)
|
||||
{
|
||||
if (i < 0 || i >= pItems.size())
|
||||
return false;
|
||||
|
||||
Choice.this.processItemEvent(new ItemEvent(Choice.this,
|
||||
ItemEvent.ITEM_STATE_CHANGED,
|
||||
this, ItemEvent.SELECTED));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Choice</code>.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
||||
* returns true
|
||||
*/
|
||||
public Choice()
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the number of items in the list.
|
||||
*
|
||||
* @return The number of items in the list.
|
||||
*/
|
||||
public int
|
||||
getItemCount()
|
||||
{
|
||||
return countItems ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the number of items in the list.
|
||||
*
|
||||
* @return The number of items in the list.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of <code>getItemCount</code>.
|
||||
*/
|
||||
public int
|
||||
countItems()
|
||||
{
|
||||
return(pItems.size());
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the item at the specified index in the list.
|
||||
*
|
||||
* @param index The index into the list to return the item from.
|
||||
*
|
||||
* @exception ArrayIndexOutOfBoundsException If the index is invalid.
|
||||
*/
|
||||
public String
|
||||
getItem(int index)
|
||||
{
|
||||
return((String)pItems.elementAt(index));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds the specified item to this choice box.
|
||||
*
|
||||
* @param item The item to add.
|
||||
*
|
||||
* @exception NullPointerException If the item's value is null
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public synchronized void
|
||||
add(String item)
|
||||
{
|
||||
if (item == null)
|
||||
throw new NullPointerException ("item must be non-null");
|
||||
|
||||
pItems.addElement(item);
|
||||
|
||||
int i = pItems.size () - 1;
|
||||
if (peer != null)
|
||||
{
|
||||
ChoicePeer cp = (ChoicePeer) peer;
|
||||
cp.add (item, i);
|
||||
}
|
||||
else if (selectedIndex == -1)
|
||||
select(0);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds the specified item to this choice box.
|
||||
*
|
||||
* This method is oboslete since Java 2 platform 1.1. Please use @see add
|
||||
* instead.
|
||||
*
|
||||
* @param item The item to add.
|
||||
*
|
||||
* @exception NullPointerException If the item's value is equal to null
|
||||
*/
|
||||
public synchronized void
|
||||
addItem(String item)
|
||||
{
|
||||
add(item);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/** Inserts an item into this Choice. Existing items are shifted
|
||||
* upwards. If the new item is the only item, then it is selected.
|
||||
* If the currently selected item is shifted, then the first item is
|
||||
* selected. If the currently selected item is not shifted, then it
|
||||
* remains selected.
|
||||
*
|
||||
* @param item The item to add.
|
||||
* @param index The index at which the item should be inserted.
|
||||
*
|
||||
* @exception IllegalArgumentException If index is less than 0
|
||||
*/
|
||||
public synchronized void
|
||||
insert(String item, int index)
|
||||
{
|
||||
if (index < 0)
|
||||
throw new IllegalArgumentException ("index may not be less then 0");
|
||||
|
||||
if (index > getItemCount ())
|
||||
index = getItemCount ();
|
||||
|
||||
pItems.insertElementAt(item, index);
|
||||
|
||||
if (peer != null)
|
||||
{
|
||||
ChoicePeer cp = (ChoicePeer) peer;
|
||||
cp.add (item, index);
|
||||
}
|
||||
else if (selectedIndex == -1 || selectedIndex >= index)
|
||||
select(0);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes the specified item from the choice box.
|
||||
*
|
||||
* @param item The item to remove.
|
||||
*
|
||||
* @exception IllegalArgumentException If the specified item doesn't exist.
|
||||
*/
|
||||
public synchronized void
|
||||
remove(String item)
|
||||
{
|
||||
int index = pItems.indexOf(item);
|
||||
if (index == -1)
|
||||
throw new IllegalArgumentException ("item \""
|
||||
+ item + "\" not found in Choice");
|
||||
remove(index);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes the item at the specified index from the choice box.
|
||||
*
|
||||
* @param index The index of the item to remove.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the index is not valid.
|
||||
*/
|
||||
public synchronized void
|
||||
remove(int index)
|
||||
{
|
||||
if ((index < 0) || (index > getItemCount()))
|
||||
throw new IllegalArgumentException("Bad index: " + index);
|
||||
|
||||
pItems.removeElementAt(index);
|
||||
|
||||
if (peer != null)
|
||||
{
|
||||
ChoicePeer cp = (ChoicePeer) peer;
|
||||
cp.remove (index);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (getItemCount() == 0)
|
||||
selectedIndex = -1;
|
||||
else if (index == selectedIndex)
|
||||
select(0);
|
||||
}
|
||||
|
||||
if (selectedIndex > index)
|
||||
--selectedIndex;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes all of the objects from this choice box.
|
||||
*/
|
||||
public synchronized void
|
||||
removeAll()
|
||||
{
|
||||
if (getItemCount() <= 0)
|
||||
return;
|
||||
|
||||
pItems.removeAllElements ();
|
||||
|
||||
if (peer != null)
|
||||
{
|
||||
ChoicePeer cp = (ChoicePeer) peer;
|
||||
cp.removeAll ();
|
||||
}
|
||||
|
||||
selectedIndex = -1;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the currently selected item, or null if no item is
|
||||
* selected.
|
||||
*
|
||||
* @return The currently selected item.
|
||||
*/
|
||||
public synchronized String
|
||||
getSelectedItem()
|
||||
{
|
||||
return (selectedIndex == -1
|
||||
? null
|
||||
: ((String)pItems.elementAt(selectedIndex)));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns an array with one row containing the selected item.
|
||||
*
|
||||
* @return An array containing the selected item.
|
||||
*/
|
||||
public synchronized Object[]
|
||||
getSelectedObjects()
|
||||
{
|
||||
if (selectedIndex == -1)
|
||||
return null;
|
||||
|
||||
Object[] objs = new Object[1];
|
||||
objs[0] = pItems.elementAt(selectedIndex);
|
||||
|
||||
return(objs);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the index of the selected item.
|
||||
*
|
||||
* @return The index of the selected item.
|
||||
*/
|
||||
public int
|
||||
getSelectedIndex()
|
||||
{
|
||||
return(selectedIndex);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Forces the item at the specified index to be selected.
|
||||
*
|
||||
* @param index The index of the row to make selected.
|
||||
*
|
||||
* @exception IllegalArgumentException If the specified index is invalid.
|
||||
*/
|
||||
public synchronized void
|
||||
select(int index)
|
||||
{
|
||||
if ((index < 0) || (index > getItemCount()))
|
||||
throw new IllegalArgumentException("Bad index: " + index);
|
||||
|
||||
this.selectedIndex = index;
|
||||
if (peer != null)
|
||||
{
|
||||
ChoicePeer cp = (ChoicePeer) peer;
|
||||
cp.select (index);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Forces the named item to be selected.
|
||||
*
|
||||
* @param item The item to be selected.
|
||||
*
|
||||
* @exception IllegalArgumentException If the specified item does not exist.
|
||||
*/
|
||||
public synchronized void
|
||||
select(String item)
|
||||
{
|
||||
int index = pItems.indexOf(item);
|
||||
if (index >= 0)
|
||||
select(index);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Creates the native peer for this object.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit ().createChoice (this);
|
||||
super.addNotify ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds the specified listener to the list of registered listeners for
|
||||
* this object.
|
||||
*
|
||||
* @param listener The listener to add.
|
||||
*/
|
||||
public synchronized void
|
||||
addItemListener(ItemListener listener)
|
||||
{
|
||||
item_listeners = AWTEventMulticaster.add(item_listeners, listener);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes the specified listener from the list of registered listeners for
|
||||
* this object.
|
||||
*
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
public synchronized void
|
||||
removeItemListener(ItemListener listener)
|
||||
{
|
||||
item_listeners = AWTEventMulticaster.remove(item_listeners, listener);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Processes this event by invoking <code>processItemEvent()</code> if the
|
||||
* event is an instance of <code>ItemEvent</code>, otherwise the event
|
||||
* is passed to the superclass.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void
|
||||
processEvent(AWTEvent event)
|
||||
{
|
||||
if (event instanceof ItemEvent)
|
||||
processItemEvent((ItemEvent)event);
|
||||
else
|
||||
super.processEvent(event);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Processes item event by dispatching to any registered listeners.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void
|
||||
processItemEvent(ItemEvent event)
|
||||
{
|
||||
if (item_listeners != null)
|
||||
item_listeners.itemStateChanged(event);
|
||||
}
|
||||
|
||||
void
|
||||
dispatchEventImpl(AWTEvent e)
|
||||
{
|
||||
if (e.id <= ItemEvent.ITEM_LAST
|
||||
&& e.id >= ItemEvent.ITEM_FIRST
|
||||
&& (item_listeners != null
|
||||
|| (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0))
|
||||
processEvent(e);
|
||||
else
|
||||
super.dispatchEventImpl(e);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this object.
|
||||
*
|
||||
* @return A debugging string for this object.
|
||||
*/
|
||||
protected String
|
||||
paramString()
|
||||
{
|
||||
return ("selectedIndex=" + selectedIndex + "," + super.paramString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the objects currently registered as FooListeners
|
||||
* upon this Choice. FooListeners are registered using the addFooListener
|
||||
* method.
|
||||
*
|
||||
* @exception ClassCastException If listenerType doesn't specify a class or
|
||||
* interface that implements java.util.EventListener.
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
public EventListener[] getListeners (Class listenerType)
|
||||
{
|
||||
if (listenerType == ItemListener.class)
|
||||
return AWTEventMulticaster.getListeners (item_listeners, listenerType);
|
||||
|
||||
return super.getListeners (listenerType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all registered item listeners.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public ItemListener[] getItemListeners ()
|
||||
{
|
||||
return (ItemListener[]) getListeners (ItemListener.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>Choice</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTChoice();
|
||||
return accessibleContext;
|
||||
}
|
||||
} // class Choice
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,195 @@
|
||||
/* ColorPaintContext.java -- context for painting solid colors
|
||||
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.Raster;
|
||||
|
||||
/**
|
||||
* This class provides a paint context which will fill a rectanglar region of
|
||||
* a raster scan with the given color. However, it is not yet completely
|
||||
* implemented.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
*/
|
||||
class ColorPaintContext implements PaintContext
|
||||
{
|
||||
/**
|
||||
* The color to fill any raster with. Package visible for use in
|
||||
* SystemColor.
|
||||
*/
|
||||
final int color;
|
||||
final ColorModel colorModel;
|
||||
|
||||
private ColorRaster cachedRaster;
|
||||
|
||||
|
||||
/**
|
||||
* Create the context for a given color.
|
||||
*
|
||||
* @param c The solid color to use.
|
||||
*/
|
||||
ColorPaintContext(int colorRGB)
|
||||
{
|
||||
this(ColorModel.getRGBdefault(), colorRGB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the context for a given color.
|
||||
*
|
||||
* @param cm The color model of this context.
|
||||
* @param c The solid color to use.
|
||||
*/
|
||||
ColorPaintContext(ColorModel cm,int colorRGB)
|
||||
{
|
||||
color = colorRGB;
|
||||
colorModel = cm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the resources allocated for the paint. As the color is constant,
|
||||
* there aren't any resources.
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the color model of this context.
|
||||
*
|
||||
* @return the context color model
|
||||
*/
|
||||
public ColorModel getColorModel()
|
||||
{
|
||||
return colorModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a raster containing the colors for the graphics operation.
|
||||
*
|
||||
* @param x the x-coordinate, in device space
|
||||
* @param y the y-coordinate, in device space
|
||||
* @param width the width, in device space
|
||||
* @param height the height, in device space
|
||||
* @return a raster for the given area and color
|
||||
*/
|
||||
public Raster getRaster(int x, int y, int width, int height)
|
||||
{
|
||||
if( cachedRaster == null
|
||||
|| cachedRaster.getWidth() < width
|
||||
|| cachedRaster.getHeight() < height)
|
||||
{
|
||||
cachedRaster = new ColorRaster(colorModel, 0, 0, width, height, color);
|
||||
}
|
||||
return cachedRaster.createChild(0 ,0 ,width ,height ,x ,y , null);
|
||||
}
|
||||
|
||||
/**
|
||||
* A ColorRaster is a raster that is completely filled with one color. The
|
||||
* data layout is taken from the color model given to the constructor.
|
||||
*/
|
||||
private class ColorRaster extends Raster
|
||||
{
|
||||
|
||||
/**
|
||||
* Create a raster that is compaltible with the given color model and
|
||||
* filled with the given color.
|
||||
* @param cm The color model for this raster.
|
||||
* @param x The smallest horizontal corrdinate in the raster.
|
||||
* @param y The smallest vertical coordinate in the raster.
|
||||
* @param width The width of the raster.
|
||||
* @param height The height of the raster.
|
||||
* @param rgbPixel The RGB value of the color for this raster.
|
||||
*/
|
||||
ColorRaster(ColorModel cm,int x, int y, int width, int height, int rgbPixel)
|
||||
{
|
||||
super(cm.createCompatibleSampleModel(width,height),new Point(x,y));
|
||||
Object pixel = cm.getDataElements(rgbPixel,null);
|
||||
getSampleModel().setDataElements(0, 0,
|
||||
width, height,
|
||||
multiplyData(pixel,null,width*height),
|
||||
dataBuffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Object multiplyData(Object src, Object dest, int factor)
|
||||
{
|
||||
Object from;
|
||||
int srcLength = 0;
|
||||
if (src instanceof byte[])
|
||||
{
|
||||
srcLength = ((byte[])src).length;
|
||||
|
||||
if (dest == null) dest = new byte[factor * srcLength];
|
||||
}
|
||||
else if (src instanceof short[])
|
||||
{
|
||||
srcLength = ((short[])src).length;
|
||||
if (dest == null) dest = new short[factor * srcLength];
|
||||
}
|
||||
else if (src instanceof int[])
|
||||
{
|
||||
srcLength = ((int[]) src).length;
|
||||
if (dest == null) dest = new int[factor * srcLength];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ClassCastException("Unknown data buffer type");
|
||||
}
|
||||
|
||||
System.arraycopy(src,0,dest,0,srcLength);
|
||||
|
||||
int count = 1;
|
||||
while(count*2 < factor)
|
||||
{
|
||||
System.arraycopy(dest, 0, dest, count * srcLength, count*srcLength);
|
||||
count *= 2;
|
||||
}
|
||||
|
||||
if(factor > count)
|
||||
System.arraycopy(dest,0, dest, count * srcLength,
|
||||
(factor - count) * srcLength );
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // class ColorPaintContext
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,215 @@
|
||||
/* ComponentOrientation.java -- describes a component's orientation
|
||||
Copyright (C) 2000, 2001, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* This class is used to differentiate different orientations for text layout.
|
||||
* It controls whether text flows left-to-right or right-to-left, and whether
|
||||
* lines are horizontal or vertical, as in this table:<br>
|
||||
* <pre>
|
||||
* LT RT TL TR
|
||||
* A B C C B A A D G G D A
|
||||
* D E F F E D B E H H E B
|
||||
* G H I I H G C F I I F C
|
||||
* </pre>
|
||||
* <b>LT</b> languages are most common (left-to-right lines, top-to-bottom).
|
||||
* This includes Western European languages, and optionally includes Japanese,
|
||||
* Chinese, and Korean. <b>RT</b> languages (right-to-left lines,
|
||||
* top-to-bottom) are mainly middle eastern, such as Hebrew and Arabic.
|
||||
* <b>TR</b> languages flow top-to-bottom in a line, right-to-left, and are
|
||||
* the basis of Japanese, Chinese, and Korean. Finally, <b>TL</b> languages
|
||||
* flow top-to-bottom in a line, left-to-right, as in Mongolian.
|
||||
*
|
||||
* <p>This is a pretty poor excuse for a type-safe enum, since it is not
|
||||
* guaranteed that orientation objects are unique (thanks to serialization),
|
||||
* yet there is no equals() method. You would be wise to compare the output
|
||||
* of isHorizontal() and isLeftToRight() rather than comparing objects with
|
||||
* ==, especially since more constants may be added in the future.
|
||||
*
|
||||
* @author Bryce McKinlay (bryce@albatross.co.nz)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class ComponentOrientation implements Serializable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -4113291392143563828L;
|
||||
|
||||
/** Constant for unknown orientation. */
|
||||
private static final int UNKNOWN_ID = 1;
|
||||
|
||||
/** Constant for horizontal line orientation. */
|
||||
private static final int HORIZONTAL_ID = 2;
|
||||
|
||||
/** Constant for left-to-right orientation. */
|
||||
private static final int LEFT_TO_RIGHT_ID = 4;
|
||||
|
||||
/**
|
||||
* Items run left to right, and lines flow top to bottom. Examples: English,
|
||||
* French.
|
||||
*/
|
||||
public static final ComponentOrientation LEFT_TO_RIGHT
|
||||
= new ComponentOrientation(HORIZONTAL_ID | LEFT_TO_RIGHT_ID);
|
||||
|
||||
/**
|
||||
* Items run right to left, and lines flow top to bottom. Examples: Arabic,
|
||||
* Hebrew.
|
||||
*/
|
||||
public static final ComponentOrientation RIGHT_TO_LEFT
|
||||
= new ComponentOrientation(HORIZONTAL_ID);
|
||||
|
||||
/**
|
||||
* The orientation is unknown for the locale. For backwards compatibility,
|
||||
* this behaves like LEFT_TO_RIGHT in the instance methods.
|
||||
*/
|
||||
public static final ComponentOrientation UNKNOWN
|
||||
= new ComponentOrientation(UNKNOWN_ID | HORIZONTAL_ID | LEFT_TO_RIGHT_ID);
|
||||
|
||||
/**
|
||||
* The orientation of this object; bitwise-or of unknown (1), horizontal (2),
|
||||
* and left-to-right (4).
|
||||
*
|
||||
* @serial the orientation
|
||||
*/
|
||||
private final int orientation;
|
||||
|
||||
/**
|
||||
* Construct a given orientation.
|
||||
*
|
||||
* @param orientation the orientation
|
||||
*/
|
||||
private ComponentOrientation(int orientation)
|
||||
{
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the lines are horizontal, in which case lines flow
|
||||
* top-to-bottom. For example, English, Hebrew. Counterexamples: Japanese,
|
||||
* Chinese, Korean, Mongolian.
|
||||
*
|
||||
* @return true if this orientation has horizontal lines
|
||||
*/
|
||||
public boolean isHorizontal()
|
||||
{
|
||||
return (orientation & HORIZONTAL_ID) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If isHorizontal() returns true, then this determines whether items in
|
||||
* the line flow left-to-right. If isHorizontal() returns false, items in
|
||||
* a line flow top-to-bottom, and this determines if lines flow
|
||||
* left-to-right.
|
||||
*
|
||||
* @return true if this orientation flows left-to-right
|
||||
*/
|
||||
public boolean isLeftToRight()
|
||||
{
|
||||
return (orientation & LEFT_TO_RIGHT_ID) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an orientation appropriate for the locale.
|
||||
*
|
||||
* @param locale the locale
|
||||
* @return the orientation for that locale
|
||||
* @throws NullPointerException if locale is null
|
||||
*/
|
||||
public static ComponentOrientation getOrientation(Locale locale)
|
||||
{
|
||||
// Based on iterating over all languages defined in JDK 1.4, this behavior
|
||||
// matches Sun's. However, it makes me wonder if any non-horizontal
|
||||
// orientations even exist, as it sure contradicts their documentation.
|
||||
String language = locale.getLanguage();
|
||||
if ("ar".equals(language) || "fa".equals(language) || "iw".equals(language)
|
||||
|| "ur".equals(language))
|
||||
return RIGHT_TO_LEFT;
|
||||
return LEFT_TO_RIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an orientation from a resource bundle. This tries the following:
|
||||
*
|
||||
* <ul>
|
||||
* <li>Use the key "Orientation" to find an instance of ComponentOrientation
|
||||
* in the bundle.</li>
|
||||
* <li>Get the locale of the resource bundle, and get the orientation of
|
||||
* that locale.</li>
|
||||
* <li>Give up and get the orientation of the default locale.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param bdl the bundle to use
|
||||
* @return the orientation
|
||||
* @throws NullPointerException if bdl is null
|
||||
* @deprecated use {@link #getOrientation(Locale)} instead
|
||||
*/
|
||||
public static ComponentOrientation getOrientation(ResourceBundle bdl)
|
||||
{
|
||||
ComponentOrientation r;
|
||||
try
|
||||
{
|
||||
r = (ComponentOrientation) bdl.getObject("Orientation");
|
||||
if (r != null)
|
||||
return r;
|
||||
}
|
||||
catch (MissingResourceException ignored)
|
||||
{
|
||||
}
|
||||
catch (ClassCastException ignored)
|
||||
{
|
||||
}
|
||||
try
|
||||
{
|
||||
r = getOrientation(bdl.getLocale());
|
||||
if (r != null)
|
||||
return r;
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
return getOrientation(Locale.getDefault());
|
||||
}
|
||||
} // class ComponentOrientation
|
||||
@@ -0,0 +1,73 @@
|
||||
/* Composite.java -- graphics formed from composite layers
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.ColorModel;
|
||||
|
||||
/**
|
||||
* This interface is for graphics which are formed as composites of others.
|
||||
* It combines {@link Graphics2D} shapes according to defined rules to form
|
||||
* the new image. Implementations of this interface must be immutable, because
|
||||
* they are not cloned when a Graphics2D container is cloned.
|
||||
*
|
||||
* <p>Since this can expose pixels to untrusted code, there is a security
|
||||
* check on custom objects, <code>readDisplayPixels</code>, to prevent leaking
|
||||
* restricted information graphically.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see AlphaComposite
|
||||
* @see CompositeContext
|
||||
* @see Graphics2D#setComposite(Composite)
|
||||
* @since 1.2
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface Composite
|
||||
{
|
||||
/**
|
||||
* Create a context state for performing the compositing operation. Several
|
||||
* contexts may exist for this object, in a multi-threaded environment.
|
||||
*
|
||||
* @param srcColorModel the color model of the source
|
||||
* @param dstColorModel the color model of the destination
|
||||
* @param hints hints for choosing between rendering alternatives
|
||||
*/
|
||||
CompositeContext createContext(ColorModel srcColorModel,
|
||||
ColorModel dstColorModel,
|
||||
RenderingHints hints);
|
||||
} // interface Composite
|
||||
@@ -0,0 +1,71 @@
|
||||
/* Composite.java -- the context for compositing graphics layers
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
/**
|
||||
* This interface provides an optimized environment for compositing graphics.
|
||||
* Several such contexts may exist for a given <code>Composite</code> object.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Composite
|
||||
* @since 1.2
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface CompositeContext
|
||||
{
|
||||
/**
|
||||
* Release resources allocated for the compositing.
|
||||
*/
|
||||
void dispose();
|
||||
|
||||
/**
|
||||
* Compose the two source images into the composite image. The destination
|
||||
* can be the same as one of the two inputs, and the destination must be
|
||||
* compatible with the ColorModel chosen in {@link Composite#createContext}.
|
||||
*
|
||||
* @param src the lower image source in compositing
|
||||
* @param dstIn the upper image source in compositing
|
||||
* @param dstOut the destination for the composite
|
||||
* @see Composite
|
||||
*/
|
||||
void compose(Raster src, Raster dstIn, WritableRaster dstOut);
|
||||
} // interface CompositeContext
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,413 @@
|
||||
/* ContainerOrderFocusTraversalPolicy.java --
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* ContainerOrderFocusTraversalPolicy defines a focus traversal order
|
||||
* based on the order in which Components were packed in a Container.
|
||||
* This policy performs a pre-order traversal of the Component
|
||||
* hierarchy starting from a given focus cycle root. Portions of the
|
||||
* hierarchy that are not visible and displayable are skipped.
|
||||
*
|
||||
* By default, this policy transfers focus down-cycle implicitly.
|
||||
* That is, if a forward traversal is requested on a focus cycle root
|
||||
* and the focus cycle root has focusable children, the focus will
|
||||
* automatically be transfered down to the lower focus cycle.
|
||||
*
|
||||
* The default implementation of accept accepts only Components that
|
||||
* are visible, displayable, enabled and focusable. Derived classes
|
||||
* can override these acceptance criteria by overriding accept.
|
||||
*
|
||||
* @author Michael Koch
|
||||
* @author Thomas Fitzsimmons (fitzsim@redhat.com)
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ContainerOrderFocusTraversalPolicy extends FocusTraversalPolicy
|
||||
implements Serializable
|
||||
{
|
||||
/**
|
||||
* Compatible to JDK 1.4+
|
||||
*/
|
||||
static final long serialVersionUID = 486933713763926351L;
|
||||
|
||||
/**
|
||||
* True if implicit down cycling is enabled.
|
||||
*/
|
||||
private boolean implicitDownCycleTraversal = true;
|
||||
|
||||
/**
|
||||
* Creates the <code>ContainerOrderFocusTraversalPolicy</code> object.
|
||||
*/
|
||||
public ContainerOrderFocusTraversalPolicy ()
|
||||
{
|
||||
// Nothing to do here
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Component that should receive the focus after current.
|
||||
* root must be a focus cycle root of current.
|
||||
*
|
||||
* @param root a focus cycle root of current
|
||||
* @param current a (possibly indirect) child of root, or root itself
|
||||
*
|
||||
* @return the next Component in the focus traversal order for root,
|
||||
* or null if no acceptable Component exists.
|
||||
*
|
||||
* @exception IllegalArgumentException If root is not a focus cycle
|
||||
* root of current, or if either root or current is null.
|
||||
*/
|
||||
public Component getComponentAfter (Container root, Component current)
|
||||
{
|
||||
if (root == null)
|
||||
throw new IllegalArgumentException ("focus cycle root is null");
|
||||
if (current == null)
|
||||
throw new IllegalArgumentException ("current component is null");
|
||||
|
||||
if (!root.isFocusCycleRoot ())
|
||||
throw new IllegalArgumentException ("root is not a focus cycle root");
|
||||
|
||||
Container ancestor = current.getFocusCycleRootAncestor ();
|
||||
Container prevAncestor = ancestor;
|
||||
while (ancestor != root)
|
||||
{
|
||||
ancestor = current.getFocusCycleRootAncestor ();
|
||||
if (ancestor == prevAncestor)
|
||||
{
|
||||
// We've reached the top focus cycle root ancestor. Check
|
||||
// if it is root.
|
||||
if (ancestor != root)
|
||||
throw new IllegalArgumentException ("the given container is not"
|
||||
+ " a focus cycle root of the"
|
||||
+ " current component");
|
||||
else
|
||||
break;
|
||||
}
|
||||
prevAncestor = ancestor;
|
||||
}
|
||||
|
||||
// FIXME: is this the right thing to do here? It moves the context
|
||||
// for traversal up one focus traversal cycle. We'll need a test
|
||||
// for this.
|
||||
if ((Component) root == current)
|
||||
root = current.getFocusCycleRootAncestor ();
|
||||
|
||||
// Check if we've reached the top of the component hierarchy. If
|
||||
// so then we want to loop around to the first component in the
|
||||
// focus traversal cycle.
|
||||
if (current instanceof Window)
|
||||
return getFirstComponent ((Container) current);
|
||||
|
||||
Container parent = current.getParent ();
|
||||
|
||||
synchronized (parent.getTreeLock ())
|
||||
{
|
||||
Component[] components = parent.getComponents ();
|
||||
int componentIndex = 0;
|
||||
int numComponents = parent.getComponentCount ();
|
||||
|
||||
// Find component's index.
|
||||
for (int i = 0; i < numComponents; i++)
|
||||
{
|
||||
if (components[i] == current)
|
||||
componentIndex = i;
|
||||
}
|
||||
|
||||
// Search forward for the next acceptable component.
|
||||
for (int i = componentIndex + 1; i < numComponents; i++)
|
||||
{
|
||||
if (accept (components[i]))
|
||||
return components[i];
|
||||
|
||||
if (components[i] instanceof Container)
|
||||
{
|
||||
Component result = getFirstComponent ((Container) components[i]);
|
||||
|
||||
if (result != null
|
||||
&& implicitDownCycleTraversal)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// No focusable components after current in its Container. So go
|
||||
// to the next Component after current's Container (parent).
|
||||
Component result = getComponentAfter (root, parent);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Component that should receive the focus before
|
||||
* <code>current</code>. <code>root</code> must be a focus cycle
|
||||
* root of current.
|
||||
*
|
||||
* @param root a focus cycle root of current
|
||||
* @param current a (possibly indirect) child of root, or root itself
|
||||
*
|
||||
* @return the previous Component in the focus traversal order for
|
||||
* root, or null if no acceptable Component exists.
|
||||
*
|
||||
* @exception IllegalArgumentException If root is not a focus cycle
|
||||
* root of current, or if either root or current is null.
|
||||
*/
|
||||
public Component getComponentBefore (Container root, Component current)
|
||||
{
|
||||
if (root == null)
|
||||
throw new IllegalArgumentException ("focus cycle root is null");
|
||||
if (current == null)
|
||||
throw new IllegalArgumentException ("current component is null");
|
||||
|
||||
if (!root.isFocusCycleRoot ())
|
||||
throw new IllegalArgumentException ("root is not a focus cycle root");
|
||||
|
||||
Container ancestor = current.getFocusCycleRootAncestor ();
|
||||
Container prevAncestor = ancestor;
|
||||
while (ancestor != root)
|
||||
{
|
||||
ancestor = current.getFocusCycleRootAncestor ();
|
||||
if (ancestor == prevAncestor)
|
||||
{
|
||||
// We've reached the top focus cycle root ancestor. Check
|
||||
// if it is root.
|
||||
if (ancestor != root)
|
||||
throw new IllegalArgumentException ("the given container is not"
|
||||
+ " a focus cycle root of the"
|
||||
+ " current component");
|
||||
else
|
||||
break;
|
||||
}
|
||||
prevAncestor = ancestor;
|
||||
}
|
||||
|
||||
// FIXME: is this the right thing to do here? It moves the context
|
||||
// for traversal up one focus traversal cycle. We'll need a test
|
||||
// for this.
|
||||
if ((Component) root == current)
|
||||
root = current.getFocusCycleRootAncestor ();
|
||||
|
||||
// Check if we've reached the top of the component hierarchy. If
|
||||
// so then we want to loop around to the last component in the
|
||||
// focus traversal cycle.
|
||||
if (current instanceof Window)
|
||||
return getLastComponent ((Container) current);
|
||||
|
||||
Container parent = current.getParent ();
|
||||
|
||||
synchronized (parent.getTreeLock ())
|
||||
{
|
||||
Component[] components = parent.getComponents ();
|
||||
int componentIndex = 0;
|
||||
int numComponents = parent.getComponentCount ();
|
||||
|
||||
// Find component's index.
|
||||
for (int i = 0; i < numComponents; i++)
|
||||
{
|
||||
if (components[i] == current)
|
||||
componentIndex = i;
|
||||
}
|
||||
|
||||
// Search backward for the next acceptable component.
|
||||
for (int i = componentIndex - 1; i >= 0; i--)
|
||||
{
|
||||
if (accept (components[i]))
|
||||
return components[i];
|
||||
|
||||
if (components[i] instanceof Container)
|
||||
{
|
||||
Component result = getLastComponent ((Container) components[i]);
|
||||
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// No focusable components before current in its Container. So go
|
||||
// to the previous Component before current's Container (parent).
|
||||
Component result = getComponentBefore (root, parent);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first Component of root that should receive the focus.
|
||||
*
|
||||
* @param root a focus cycle root
|
||||
*
|
||||
* @return the first Component in the focus traversal order for
|
||||
* root, or null if no acceptable Component exists.
|
||||
*
|
||||
* @exception IllegalArgumentException If root is null.
|
||||
*/
|
||||
public Component getFirstComponent(Container root)
|
||||
{
|
||||
if (root == null)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
if (!root.isVisible ()
|
||||
|| !root.isDisplayable ())
|
||||
return null;
|
||||
|
||||
if (accept (root))
|
||||
return root;
|
||||
|
||||
Component[] componentArray = root.getComponents ();
|
||||
|
||||
for (int i = 0; i < componentArray.length; i++)
|
||||
{
|
||||
Component component = componentArray [i];
|
||||
|
||||
if (accept (component))
|
||||
return component;
|
||||
|
||||
if (component instanceof Container)
|
||||
{
|
||||
Component result = getFirstComponent ((Container) component);
|
||||
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last Component of root that should receive the focus.
|
||||
*
|
||||
* @param root a focus cycle root
|
||||
*
|
||||
* @return the last Component in the focus traversal order for
|
||||
* root, or null if no acceptable Component exists.
|
||||
*
|
||||
* @exception IllegalArgumentException If root is null.
|
||||
*/
|
||||
public Component getLastComponent (Container root)
|
||||
{
|
||||
if (root == null)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
if (!root.isVisible ()
|
||||
|| !root.isDisplayable ())
|
||||
return null;
|
||||
|
||||
if (accept (root))
|
||||
return root;
|
||||
|
||||
Component[] componentArray = root.getComponents ();
|
||||
|
||||
for (int i = componentArray.length - 1; i >= 0; i--)
|
||||
{
|
||||
Component component = componentArray [i];
|
||||
|
||||
if (accept (component))
|
||||
return component;
|
||||
|
||||
if (component instanceof Container)
|
||||
{
|
||||
Component result = getLastComponent ((Container) component);
|
||||
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default Component of root that should receive the focus.
|
||||
*
|
||||
* @param root a focus cycle root
|
||||
*
|
||||
* @return the default Component in the focus traversal order for
|
||||
* root, or null if no acceptable Component exists.
|
||||
*
|
||||
* @exception IllegalArgumentException If root is null.
|
||||
*/
|
||||
public Component getDefaultComponent (Container root)
|
||||
{
|
||||
return getFirstComponent (root);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not implicit down cycling is enabled. If it is,
|
||||
* then initiating a forward focus traversal operation onto a focus
|
||||
* cycle root, the focus will be implicitly transferred into the
|
||||
* root container's focus cycle.
|
||||
*
|
||||
* @param value the setting for implicit down cycling
|
||||
*/
|
||||
public void setImplicitDownCycleTraversal (boolean value)
|
||||
{
|
||||
implicitDownCycleTraversal = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether or not implicit down cycling is enabled. If it is,
|
||||
* then initiating a forward focus traversal operation onto a focus
|
||||
* cycle root, the focus will be implicitly transferred into the
|
||||
* root container's focus cycle.
|
||||
*
|
||||
* @return true if the focus will be transferred down-cycle
|
||||
* implicitly
|
||||
*/
|
||||
public boolean getImplicitDownCycleTraversal ()
|
||||
{
|
||||
return implicitDownCycleTraversal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the given Component is an acceptable target for the
|
||||
* keyboard input focus.
|
||||
*
|
||||
* @param current the Component to check
|
||||
*
|
||||
* @return true if current is acceptable, false otherwise
|
||||
*/
|
||||
protected boolean accept (Component current)
|
||||
{
|
||||
return (current.visible
|
||||
&& current.isDisplayable ()
|
||||
&& current.enabled
|
||||
&& current.focusable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This class represents various predefined cursor types.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class Cursor implements java.io.Serializable
|
||||
{
|
||||
static final long serialVersionUID = 8028237497568985504L;
|
||||
|
||||
/**
|
||||
* Constant for the system default cursor type
|
||||
*/
|
||||
public static final int DEFAULT_CURSOR = 0;
|
||||
|
||||
/**
|
||||
* Constant for a cross-hair cursor.
|
||||
*/
|
||||
public static final int CROSSHAIR_CURSOR = 1;
|
||||
|
||||
/**
|
||||
* Constant for a cursor over a text field.
|
||||
*/
|
||||
public static final int TEXT_CURSOR = 2;
|
||||
|
||||
/**
|
||||
* Constant for a cursor to display while waiting for an action to complete.
|
||||
*/
|
||||
public static final int WAIT_CURSOR = 3;
|
||||
|
||||
/**
|
||||
* Cursor used over SW corner of window decorations.
|
||||
*/
|
||||
public static final int SW_RESIZE_CURSOR = 4;
|
||||
|
||||
/**
|
||||
* Cursor used over SE corner of window decorations.
|
||||
*/
|
||||
public static final int SE_RESIZE_CURSOR = 5;
|
||||
|
||||
/**
|
||||
* Cursor used over NW corner of window decorations.
|
||||
*/
|
||||
public static final int NW_RESIZE_CURSOR = 6;
|
||||
|
||||
/**
|
||||
* Cursor used over NE corner of window decorations.
|
||||
*/
|
||||
public static final int NE_RESIZE_CURSOR = 7;
|
||||
|
||||
/**
|
||||
* Cursor used over N edge of window decorations.
|
||||
*/
|
||||
public static final int N_RESIZE_CURSOR = 8;
|
||||
|
||||
/**
|
||||
* Cursor used over S edge of window decorations.
|
||||
*/
|
||||
public static final int S_RESIZE_CURSOR = 9;
|
||||
|
||||
/**
|
||||
* Cursor used over W edge of window decorations.
|
||||
*/
|
||||
public static final int W_RESIZE_CURSOR = 10;
|
||||
|
||||
/**
|
||||
* Cursor used over E edge of window decorations.
|
||||
*/
|
||||
public static final int E_RESIZE_CURSOR = 11;
|
||||
|
||||
/**
|
||||
* Constant for a hand cursor.
|
||||
*/
|
||||
public static final int HAND_CURSOR = 12;
|
||||
|
||||
/**
|
||||
* Constant for a cursor used during window move operations.
|
||||
*/
|
||||
public static final int MOVE_CURSOR = 13;
|
||||
|
||||
public static final int CUSTOM_CURSOR = 0xFFFFFFFF;
|
||||
|
||||
private static final int PREDEFINED_COUNT = 14;
|
||||
|
||||
protected static Cursor[] predefined = new Cursor[PREDEFINED_COUNT];
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* @serial The numeric id of this cursor.
|
||||
*/
|
||||
int type;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Cursor</code> with the specified
|
||||
* type.
|
||||
*
|
||||
* @param type The cursor type.
|
||||
*
|
||||
* @exception IllegalArgumentException If the specified cursor type is invalid
|
||||
*/
|
||||
public Cursor(int type)
|
||||
{
|
||||
if (type < 0 || type >= PREDEFINED_COUNT)
|
||||
throw new IllegalArgumentException ("invalid cursor " + type);
|
||||
|
||||
this.type = type;
|
||||
// FIXME: lookup and set name?
|
||||
}
|
||||
|
||||
/** This constructor is used internally only.
|
||||
* Application code should call Toolkit.createCustomCursor().
|
||||
*/
|
||||
protected Cursor(String name)
|
||||
{
|
||||
this.name = name;
|
||||
this.type = CUSTOM_CURSOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of <code>Cursor</code> for one of the specified
|
||||
* predetermined types.
|
||||
*
|
||||
* @param type The type contant from this class.
|
||||
*
|
||||
* @return The requested predefined cursor.
|
||||
*
|
||||
* @exception IllegalArgumentException If the constant is not one of the
|
||||
* predefined cursor type constants from this class.
|
||||
*/
|
||||
public static Cursor getPredefinedCursor(int type)
|
||||
{
|
||||
if (type < 0 || type >= PREDEFINED_COUNT)
|
||||
throw new IllegalArgumentException ("invalid cursor " + type);
|
||||
if (predefined[type] == null)
|
||||
predefined[type] = new Cursor(type);
|
||||
return predefined[type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the system specific custom Cursor named Cursor names are,
|
||||
* for example: "Invalid.16x16".
|
||||
*
|
||||
* @exception AWTException
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
||||
* returns true.
|
||||
*/
|
||||
public static Cursor getSystemCustomCursor(String name)
|
||||
throws AWTException
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException ();
|
||||
|
||||
// FIXME
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instance of the system default cursor type.
|
||||
*
|
||||
* @return The system default cursor.
|
||||
*/
|
||||
public static Cursor getDefaultCursor()
|
||||
{
|
||||
return getPredefinedCursor(DEFAULT_CURSOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the numeric type identifier for this cursor.
|
||||
*
|
||||
* @return The cursor id.
|
||||
*/
|
||||
public int getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return (this.getClass() + "[" + getName() + "]");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/* DefaultFocusTraversalPolicy.java --
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* DefaultFocusTraversalPolicy is the default focus traversal policy
|
||||
* used by Containers.
|
||||
*
|
||||
* This policy sharpens ContainerOrderFocusTraversalPolicy's
|
||||
* acceptance criteria, to reject those Components that have
|
||||
* unfocusable peers. Despite this extra strictness, this policy will
|
||||
* always accept a Component that has explicitly been set focusable by
|
||||
* any means.
|
||||
*
|
||||
* This AWT implementation assumes that the peers of the following
|
||||
* Components are not focusable: Canvas, Panel, Label, ScrollPane,
|
||||
* Scrollbar, Window, and any lightweight Component.
|
||||
*
|
||||
* A Component's focusability is independent of the focusability of
|
||||
* its peer.
|
||||
*
|
||||
* @author Thomas Fitzsimmons (fitzsim@redhat.com)
|
||||
* @since 1.4
|
||||
*/
|
||||
public class DefaultFocusTraversalPolicy
|
||||
extends ContainerOrderFocusTraversalPolicy
|
||||
{
|
||||
/**
|
||||
* Construct a default focus traversal policy.
|
||||
*/
|
||||
public DefaultFocusTraversalPolicy ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a given Component would be acceptable as a focus
|
||||
* owner. The Component must be displayable, visible and enabled to
|
||||
* be acceptable. If the Component's focus traversability has been
|
||||
* overridden, by overriding Component.isFocusTraversable or
|
||||
* Component.isFocusable, or by calling Component.setFocusable, then
|
||||
* the Component will be accepted if it is focusable. If the
|
||||
* Component uses the default focus traversable behaviour, then
|
||||
* <code>comp</code> will always be rejected if it is a Canvas,
|
||||
* Panel, Label, ScrollPane, Scrollbar, Window or lightweight
|
||||
* Component.
|
||||
*
|
||||
* @param comp the Component to check
|
||||
*
|
||||
* @return true if the Component is an acceptable target for
|
||||
* keyboard input focus, false otherwise
|
||||
*/
|
||||
protected boolean accept (Component comp)
|
||||
{
|
||||
if (comp.visible
|
||||
&& comp.isDisplayable ()
|
||||
&& comp.enabled)
|
||||
{
|
||||
if (comp.isFocusTraversableOverridden != 0
|
||||
&& (comp.isFocusTraversable () || comp.isFocusable()))
|
||||
return true;
|
||||
|
||||
if (!(comp instanceof Canvas
|
||||
|| comp instanceof Panel
|
||||
|| comp instanceof Label
|
||||
|| comp instanceof ScrollPane
|
||||
|| comp instanceof Scrollbar
|
||||
|| comp instanceof Window
|
||||
|| comp.isLightweight ()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,536 @@
|
||||
/* DefaultKeyboardFocusManager.java --
|
||||
Copyright (C) 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
// FIXME: finish documentation
|
||||
public class DefaultKeyboardFocusManager extends KeyboardFocusManager
|
||||
{
|
||||
/**
|
||||
* This class models a request to delay the dispatch of events that
|
||||
* arrive after a certain time, until a certain component becomes
|
||||
* the focus owner.
|
||||
*/
|
||||
private class EventDelayRequest implements Comparable
|
||||
{
|
||||
/** A {@link java.util.List} of {@link java.awt.event.KeyEvent}s
|
||||
that are being delayed, pending this request's {@link
|
||||
Component} receiving the keyboard focus. */
|
||||
private LinkedList enqueuedKeyEvents = new LinkedList ();
|
||||
|
||||
/** An event timestamp. All events that arrive after this time
|
||||
should be queued in the {@link #enqueuedKeyEvents} {@link
|
||||
java.util.List}. */
|
||||
public long timestamp;
|
||||
/** When this {@link Component} becomes focused, all events
|
||||
between this EventDelayRequest and the next one in will be
|
||||
dispatched from {@link #enqueuedKeyEvents}. */
|
||||
public Component focusedComp;
|
||||
|
||||
/**
|
||||
* Construct a new EventDelayRequest.
|
||||
*
|
||||
* @param timestamp events that arrive after this time will be
|
||||
* delayed
|
||||
* @param focusedComp the Component that needs to receive focus
|
||||
* before events are dispatched
|
||||
*/
|
||||
public EventDelayRequest (long timestamp, Component focusedComp)
|
||||
{
|
||||
this.timestamp = timestamp;
|
||||
this.focusedComp = focusedComp;
|
||||
}
|
||||
|
||||
public int compareTo (Object o)
|
||||
{
|
||||
if (!(o instanceof EventDelayRequest))
|
||||
throw new ClassCastException ();
|
||||
|
||||
EventDelayRequest request = (EventDelayRequest) o;
|
||||
|
||||
if (request.timestamp < timestamp)
|
||||
return -1;
|
||||
else if (request.timestamp == timestamp)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
public boolean equals (Object o)
|
||||
{
|
||||
if (!(o instanceof EventDelayRequest) || o == null)
|
||||
return false;
|
||||
|
||||
EventDelayRequest request = (EventDelayRequest) o;
|
||||
|
||||
return (request.timestamp == timestamp
|
||||
&& request.focusedComp == focusedComp);
|
||||
}
|
||||
|
||||
public void enqueueEvent (KeyEvent e)
|
||||
{
|
||||
KeyEvent last = (KeyEvent) enqueuedKeyEvents.getLast ();
|
||||
if (last != null && e.getWhen () < last.getWhen ())
|
||||
throw new RuntimeException ("KeyEvents enqueued out-of-order");
|
||||
|
||||
if (e.getWhen () <= timestamp)
|
||||
throw new RuntimeException ("KeyEvents enqueued before starting timestamp");
|
||||
|
||||
enqueuedKeyEvents.add (e);
|
||||
}
|
||||
|
||||
public void dispatchEvents ()
|
||||
{
|
||||
int size = enqueuedKeyEvents.size ();
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
KeyEvent e = (KeyEvent) enqueuedKeyEvents.remove (0);
|
||||
dispatchKeyEvent (e);
|
||||
}
|
||||
}
|
||||
|
||||
public void discardEvents ()
|
||||
{
|
||||
enqueuedKeyEvents.clear ();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This flag indicates for which focus traversal key release event we
|
||||
* possibly wait, before letting any more KEY_TYPED events through.
|
||||
*/
|
||||
private AWTKeyStroke waitForKeyStroke = null;
|
||||
|
||||
/** The {@link java.util.SortedSet} of current {@link
|
||||
#EventDelayRequest}s. */
|
||||
private SortedSet delayRequests = new TreeSet ();
|
||||
|
||||
public DefaultKeyboardFocusManager ()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean dispatchEvent (AWTEvent e)
|
||||
{
|
||||
if (e instanceof WindowEvent)
|
||||
{
|
||||
Window target = (Window) e.getSource ();
|
||||
|
||||
if (e.id == WindowEvent.WINDOW_ACTIVATED)
|
||||
setGlobalActiveWindow (target);
|
||||
else if (e.id == WindowEvent.WINDOW_GAINED_FOCUS)
|
||||
setGlobalFocusedWindow (target);
|
||||
else if (e.id != WindowEvent.WINDOW_LOST_FOCUS
|
||||
&& e.id != WindowEvent.WINDOW_DEACTIVATED)
|
||||
return false;
|
||||
|
||||
redispatchEvent(target, e);
|
||||
return true;
|
||||
}
|
||||
else if (e instanceof FocusEvent)
|
||||
{
|
||||
Component target = (Component) e.getSource ();
|
||||
|
||||
if (e.id == FocusEvent.FOCUS_GAINED)
|
||||
{
|
||||
if (! (target instanceof Window))
|
||||
{
|
||||
if (((FocusEvent) e).isTemporary ())
|
||||
setGlobalFocusOwner (target);
|
||||
else
|
||||
setGlobalPermanentFocusOwner (target);
|
||||
}
|
||||
|
||||
// Keep track of this window's focus owner.
|
||||
|
||||
// Find the target Component's top-level ancestor. target
|
||||
// may be a window.
|
||||
Container parent = target.getParent ();
|
||||
|
||||
while (parent != null
|
||||
&& !(parent instanceof Window))
|
||||
parent = parent.getParent ();
|
||||
|
||||
// If the parent is null and target is not a window, then target is an
|
||||
// unanchored component and so we don't want to set the focus owner.
|
||||
if (! (parent == null && ! (target instanceof Window)))
|
||||
{
|
||||
Window toplevel = parent == null ?
|
||||
(Window) target : (Window) parent;
|
||||
|
||||
Component focusOwner = getFocusOwner ();
|
||||
if (focusOwner != null
|
||||
&& ! (focusOwner instanceof Window))
|
||||
toplevel.setFocusOwner (focusOwner);
|
||||
}
|
||||
}
|
||||
else if (e.id == FocusEvent.FOCUS_LOST)
|
||||
{
|
||||
if (((FocusEvent) e).isTemporary ())
|
||||
setGlobalFocusOwner (null);
|
||||
else
|
||||
setGlobalPermanentFocusOwner (null);
|
||||
}
|
||||
|
||||
redispatchEvent(target, e);
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (e instanceof KeyEvent)
|
||||
{
|
||||
// Loop through all registered KeyEventDispatchers, giving
|
||||
// each a chance to handle this event.
|
||||
Iterator i = getKeyEventDispatchers().iterator();
|
||||
|
||||
while (i.hasNext ())
|
||||
{
|
||||
KeyEventDispatcher dispatcher = (KeyEventDispatcher) i.next ();
|
||||
if (dispatcher.dispatchKeyEvent ((KeyEvent) e))
|
||||
return true;
|
||||
}
|
||||
|
||||
// processKeyEvent checks if this event represents a focus
|
||||
// traversal key stroke.
|
||||
Component focusOwner = getGlobalPermanentFocusOwner ();
|
||||
|
||||
if (focusOwner != null)
|
||||
processKeyEvent (focusOwner, (KeyEvent) e);
|
||||
|
||||
if (e.isConsumed ())
|
||||
return true;
|
||||
|
||||
if (enqueueKeyEvent ((KeyEvent) e))
|
||||
// This event was enqueued for dispatch at a later time.
|
||||
return true;
|
||||
else
|
||||
// This event wasn't handled by any of the registered
|
||||
// KeyEventDispatchers, and wasn't enqueued for dispatch
|
||||
// later, so send it to the default dispatcher.
|
||||
return dispatchKeyEvent ((KeyEvent) e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean enqueueKeyEvent (KeyEvent e)
|
||||
{
|
||||
Iterator i = delayRequests.iterator ();
|
||||
boolean oneEnqueued = false;
|
||||
while (i.hasNext ())
|
||||
{
|
||||
EventDelayRequest request = (EventDelayRequest) i.next ();
|
||||
if (e.getWhen () > request.timestamp)
|
||||
{
|
||||
request.enqueueEvent (e);
|
||||
oneEnqueued = true;
|
||||
}
|
||||
}
|
||||
return oneEnqueued;
|
||||
}
|
||||
|
||||
public boolean dispatchKeyEvent (KeyEvent e)
|
||||
{
|
||||
Component focusOwner = getGlobalPermanentFocusOwner ();
|
||||
|
||||
if (focusOwner != null)
|
||||
redispatchEvent(focusOwner, e);
|
||||
|
||||
// Loop through all registered KeyEventPostProcessors, giving
|
||||
// each a chance to process this event.
|
||||
Iterator i = getKeyEventPostProcessors().iterator();
|
||||
|
||||
while (i.hasNext ())
|
||||
{
|
||||
KeyEventPostProcessor processor = (KeyEventPostProcessor) i.next ();
|
||||
if (processor.postProcessKeyEvent ((KeyEvent) e))
|
||||
return true;
|
||||
}
|
||||
|
||||
// The event hasn't been consumed yet. Check if it is an
|
||||
// MenuShortcut.
|
||||
if (postProcessKeyEvent (e))
|
||||
return true;
|
||||
|
||||
// Always return true.
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean postProcessKeyEvent (KeyEvent e)
|
||||
{
|
||||
// Check if this event represents a menu shortcut.
|
||||
|
||||
// MenuShortcuts are activated by Ctrl- KeyEvents, only on KEY_PRESSED.
|
||||
int modifiers = e.getModifiersEx ();
|
||||
if (e.getID() == KeyEvent.KEY_PRESSED
|
||||
&& (modifiers & KeyEvent.CTRL_DOWN_MASK) != 0)
|
||||
{
|
||||
Window focusedWindow = getGlobalFocusedWindow ();
|
||||
if (focusedWindow instanceof Frame)
|
||||
{
|
||||
MenuBar menubar = ((Frame) focusedWindow).getMenuBar ();
|
||||
|
||||
if (menubar != null)
|
||||
{
|
||||
// If there's a menubar, loop through all menu items,
|
||||
// checking whether each one has a shortcut, and if
|
||||
// so, whether this key event should activate it.
|
||||
int numMenus = menubar.getMenuCount ();
|
||||
|
||||
for (int i = 0; i < numMenus; i++)
|
||||
{
|
||||
Menu menu = menubar.getMenu (i);
|
||||
int numItems = menu.getItemCount ();
|
||||
|
||||
for (int j = 0; j < numItems; j++)
|
||||
{
|
||||
MenuItem item = menu.getItem (j);
|
||||
MenuShortcut shortcut = item.getShortcut ();
|
||||
|
||||
if (item.isEnabled() && shortcut != null)
|
||||
{
|
||||
// Dispatch a new ActionEvent if:
|
||||
//
|
||||
// a) this is a Shift- KeyEvent, and the
|
||||
// shortcut requires the Shift modifier
|
||||
//
|
||||
// or, b) this is not a Shift- KeyEvent, and the
|
||||
// shortcut does not require the Shift
|
||||
// modifier.
|
||||
if (shortcut.getKey () == e.getKeyCode ()
|
||||
&& ((shortcut.usesShiftModifier ()
|
||||
&& (modifiers & KeyEvent.SHIFT_DOWN_MASK) != 0)
|
||||
|| (! shortcut.usesShiftModifier ()
|
||||
&& (modifiers & KeyEvent.SHIFT_DOWN_MASK) == 0)))
|
||||
{
|
||||
item.dispatchEvent (new ActionEvent (item,
|
||||
ActionEvent.ACTION_PERFORMED,
|
||||
item.getActionCommand (),
|
||||
modifiers));
|
||||
// The event was dispatched.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void processKeyEvent (Component comp, KeyEvent e)
|
||||
{
|
||||
AWTKeyStroke eventKeystroke = AWTKeyStroke.getAWTKeyStrokeForEvent (e);
|
||||
// For every focus traversal keystroke, we need to also consume
|
||||
// the other two key event types for the same key (e.g. if
|
||||
// KEY_PRESSED TAB is a focus traversal keystroke, we also need to
|
||||
// consume KEY_RELEASED and KEY_TYPED TAB key events).
|
||||
// consuming KEY_RELEASED is easy, because their keyCodes matches
|
||||
// the KEY_PRESSED event. Consuming the intermediate KEY_TYPED is
|
||||
// very difficult because their is no clean way that we can know
|
||||
// which KEY_TYPED belongs to a focusTraversalKey and which not.
|
||||
// To address this problem we swallow every KEY_TYPE between the
|
||||
// KEY_PRESSED event that matches a focusTraversalKey and the
|
||||
// corresponding KEY_RELEASED.
|
||||
AWTKeyStroke oppositeKeystroke = AWTKeyStroke.getAWTKeyStroke (e.getKeyCode (),
|
||||
e.getModifiersEx (),
|
||||
!(e.id == KeyEvent.KEY_RELEASED));
|
||||
|
||||
// Here we check if we are currently waiting for a KEY_RELEASED and
|
||||
// swallow all KeyEvents that are to be delivered in between. This
|
||||
// should only be the KEY_TYPED events that correspond to the
|
||||
// focusTraversalKey's KEY_PRESSED event
|
||||
if (waitForKeyStroke != null)
|
||||
{
|
||||
if (eventKeystroke.equals(waitForKeyStroke))
|
||||
// release this lock
|
||||
waitForKeyStroke = null;
|
||||
|
||||
// as long as we are waiting for the KEY_RELEASED, we swallow every
|
||||
// KeyEvent, including the KEY_RELEASED
|
||||
e.consume();
|
||||
return;
|
||||
}
|
||||
|
||||
Set forwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
|
||||
Set backwardKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
|
||||
Set upKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
|
||||
Set downKeystrokes = null;
|
||||
if (comp instanceof Container)
|
||||
downKeystrokes = comp.getFocusTraversalKeys (KeyboardFocusManager.DOWN_CYCLE_TRAVERSAL_KEYS);
|
||||
|
||||
if (forwardKeystrokes.contains (eventKeystroke))
|
||||
{
|
||||
waitForKeyStroke = oppositeKeystroke;
|
||||
focusNextComponent (comp);
|
||||
e.consume ();
|
||||
}
|
||||
else if (backwardKeystrokes.contains (eventKeystroke))
|
||||
{
|
||||
waitForKeyStroke = oppositeKeystroke;
|
||||
focusPreviousComponent (comp);
|
||||
e.consume ();
|
||||
}
|
||||
else if (upKeystrokes.contains (eventKeystroke))
|
||||
{
|
||||
waitForKeyStroke = oppositeKeystroke;
|
||||
upFocusCycle (comp);
|
||||
e.consume ();
|
||||
}
|
||||
else if (comp instanceof Container
|
||||
&& downKeystrokes.contains (eventKeystroke))
|
||||
{
|
||||
waitForKeyStroke = oppositeKeystroke;
|
||||
downFocusCycle ((Container) comp);
|
||||
e.consume ();
|
||||
}
|
||||
}
|
||||
|
||||
protected void enqueueKeyEvents (long after, Component untilFocused)
|
||||
{
|
||||
delayRequests.add (new EventDelayRequest (after, untilFocused));
|
||||
}
|
||||
|
||||
protected void dequeueKeyEvents (long after, Component untilFocused)
|
||||
{
|
||||
// FIXME: need synchronization on delayRequests and enqueuedKeyEvents.
|
||||
|
||||
// Remove the KeyEvent with the oldest timestamp, which should be
|
||||
// the first element in the SortedSet.
|
||||
if (after < 0)
|
||||
{
|
||||
int size = delayRequests.size ();
|
||||
if (size > 0)
|
||||
delayRequests.remove (delayRequests.first ());
|
||||
}
|
||||
else
|
||||
{
|
||||
EventDelayRequest template = new EventDelayRequest (after, untilFocused);
|
||||
if (delayRequests.contains (template))
|
||||
{
|
||||
EventDelayRequest actual = (EventDelayRequest) delayRequests.tailSet (template).first ();
|
||||
delayRequests.remove (actual);
|
||||
actual.dispatchEvents ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void discardKeyEvents (Component comp)
|
||||
{
|
||||
// FIXME: need synchronization on delayRequests and enqueuedKeyEvents.
|
||||
|
||||
Iterator i = delayRequests.iterator ();
|
||||
|
||||
while (i.hasNext ())
|
||||
{
|
||||
EventDelayRequest request = (EventDelayRequest) i.next ();
|
||||
|
||||
if (request.focusedComp == comp
|
||||
|| (comp instanceof Container
|
||||
&& ((Container) comp).isAncestorOf (request.focusedComp)))
|
||||
request.discardEvents ();
|
||||
}
|
||||
}
|
||||
|
||||
public void focusPreviousComponent (Component comp)
|
||||
{
|
||||
Component focusComp = (comp == null) ? getGlobalFocusOwner () : comp;
|
||||
Container focusCycleRoot = focusComp.getFocusCycleRootAncestor ();
|
||||
FocusTraversalPolicy policy = focusCycleRoot.getFocusTraversalPolicy ();
|
||||
|
||||
Component previous = policy.getComponentBefore (focusCycleRoot, focusComp);
|
||||
if (previous != null)
|
||||
previous.requestFocusInWindow ();
|
||||
}
|
||||
|
||||
public void focusNextComponent (Component comp)
|
||||
{
|
||||
Component focusComp = (comp == null) ? getGlobalFocusOwner () : comp;
|
||||
Container focusCycleRoot = focusComp.getFocusCycleRootAncestor ();
|
||||
FocusTraversalPolicy policy = focusCycleRoot.getFocusTraversalPolicy ();
|
||||
|
||||
Component next = policy.getComponentAfter (focusCycleRoot, focusComp);
|
||||
if (next != null)
|
||||
next.requestFocusInWindow ();
|
||||
}
|
||||
|
||||
public void upFocusCycle (Component comp)
|
||||
{
|
||||
Component focusComp = (comp == null) ? getGlobalFocusOwner () : comp;
|
||||
Container focusCycleRoot = focusComp.getFocusCycleRootAncestor ();
|
||||
|
||||
if (focusCycleRoot instanceof Window)
|
||||
{
|
||||
FocusTraversalPolicy policy = focusCycleRoot.getFocusTraversalPolicy ();
|
||||
Component defaultComponent = policy.getDefaultComponent (focusCycleRoot);
|
||||
if (defaultComponent != null)
|
||||
defaultComponent.requestFocusInWindow ();
|
||||
}
|
||||
else
|
||||
{
|
||||
Container parentFocusCycleRoot = focusCycleRoot.getFocusCycleRootAncestor ();
|
||||
|
||||
focusCycleRoot.requestFocusInWindow ();
|
||||
setGlobalCurrentFocusCycleRoot (parentFocusCycleRoot);
|
||||
}
|
||||
}
|
||||
|
||||
public void downFocusCycle (Container cont)
|
||||
{
|
||||
if (cont == null)
|
||||
return;
|
||||
|
||||
if (cont.isFocusCycleRoot (cont))
|
||||
{
|
||||
FocusTraversalPolicy policy = cont.getFocusTraversalPolicy ();
|
||||
Component defaultComponent = policy.getDefaultComponent (cont);
|
||||
if (defaultComponent != null)
|
||||
defaultComponent.requestFocusInWindow ();
|
||||
setGlobalCurrentFocusCycleRoot (cont);
|
||||
}
|
||||
}
|
||||
} // class DefaultKeyboardFocusManager
|
||||
@@ -0,0 +1,553 @@
|
||||
/* Dialog.java -- An AWT dialog box
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.peer.DialogPeer;
|
||||
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
import javax.accessibility.AccessibleState;
|
||||
import javax.accessibility.AccessibleStateSet;
|
||||
|
||||
/**
|
||||
* A dialog box widget class.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
*/
|
||||
public class Dialog extends Window
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization constant
|
||||
private static final long serialVersionUID = 5920926903803293709L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial Indicates whether or not this dialog box is modal.
|
||||
*/
|
||||
private boolean modal;
|
||||
|
||||
/**
|
||||
* @serial Indicates whether or not this dialog box is resizable.
|
||||
*/
|
||||
private boolean resizable = true;
|
||||
|
||||
/**
|
||||
* @serial The title string for this dialog box, which can be
|
||||
* <code>null</code>.
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* This field indicates whether the dialog is undecorated or not.
|
||||
*/
|
||||
private boolean undecorated = false;
|
||||
|
||||
/**
|
||||
* Indicates that we are blocked for modality in show
|
||||
*/
|
||||
private boolean blocked = false;
|
||||
|
||||
/**
|
||||
* Secondary EventQueue to handle AWT events while
|
||||
* we are blocked for modality in show
|
||||
*/
|
||||
private EventQueue eq2 = null;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Dialog</code> with the specified
|
||||
* parent, that is resizable and not modal, and which has no title.
|
||||
*
|
||||
* @param parent The parent frame of this dialog box.
|
||||
*
|
||||
* @exception IllegalArgumentException If the owner's GraphicsConfiguration
|
||||
* is not from a screen device, or if owner is null. This exception is always
|
||||
* thrown when GraphicsEnvironment.isHeadless() returns true.
|
||||
*/
|
||||
public
|
||||
Dialog(Frame parent)
|
||||
{
|
||||
this(parent, "", false);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Dialog</code> with the specified
|
||||
* parent and modality, that is resizable and which has no title.
|
||||
*
|
||||
* @param parent The parent frame of this dialog box.
|
||||
* @param modal <code>true</code> if this dialog box is modal,
|
||||
* <code>false</code> otherwise.
|
||||
*
|
||||
* @exception IllegalArgumentException If the owner's GraphicsConfiguration
|
||||
* is not from a screen device, or if owner is null. This exception is always
|
||||
* thrown when GraphicsEnvironment.isHeadless() returns true.
|
||||
*/
|
||||
public
|
||||
Dialog(Frame parent, boolean modal)
|
||||
{
|
||||
this(parent, "", modal);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Dialog</code> with the specified
|
||||
* parent, that is resizable and not modal, and which has the specified
|
||||
* title.
|
||||
*
|
||||
* @param parent The parent frame of this dialog box.
|
||||
* @param title The title string for this dialog box.
|
||||
*
|
||||
* @exception IllegalArgumentException If the owner's GraphicsConfiguration
|
||||
* is not from a screen device, or if owner is null. This exception is always
|
||||
* thrown when GraphicsEnvironment.isHeadless() returns true.
|
||||
*/
|
||||
public
|
||||
Dialog(Frame parent, String title)
|
||||
{
|
||||
this(parent, title, false);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Dialog</code> with the specified,
|
||||
* parent, title, and modality, that is resizable.
|
||||
*
|
||||
* @param parent The parent frame of this dialog box.
|
||||
* @param title The title string for this dialog box.
|
||||
* @param modal <code>true</code> if this dialog box is modal,
|
||||
* <code>false</code> otherwise.
|
||||
*
|
||||
* @exception IllegalArgumentException If owner is null or
|
||||
* GraphicsEnvironment.isHeadless() returns true.
|
||||
*/
|
||||
public
|
||||
Dialog(Frame parent, String title, boolean modal)
|
||||
{
|
||||
this (parent, title, modal, parent.getGraphicsConfiguration ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Dialog</code> with the specified,
|
||||
* parent, title, modality and <code>GraphicsConfiguration</code>,
|
||||
* that is resizable.
|
||||
*
|
||||
* @param parent The parent frame of this dialog box.
|
||||
* @param title The title string for this dialog box.
|
||||
* @param modal <code>true</code> if this dialog box is modal,
|
||||
* <code>false</code> otherwise.
|
||||
* @param gc The <code>GraphicsConfiguration</code> object to use.
|
||||
*
|
||||
* @exception IllegalArgumentException If owner is null, the
|
||||
* GraphicsConfiguration is not a screen device or
|
||||
* GraphicsEnvironment.isHeadless() returns true.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public
|
||||
Dialog (Frame parent, String title, boolean modal, GraphicsConfiguration gc)
|
||||
{
|
||||
super (parent, gc);
|
||||
|
||||
// A null title is equivalent to an empty title
|
||||
this.title = (title != null) ? title : "";
|
||||
this.modal = modal;
|
||||
visible = false;
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Dialog</code> with the specified,
|
||||
* parent, that is resizable.
|
||||
*
|
||||
* @exception IllegalArgumentException If parent is null. This exception is
|
||||
* always thrown when GraphicsEnvironment.isHeadless() returns true.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public
|
||||
Dialog (Dialog owner)
|
||||
{
|
||||
this (owner, "", false, owner.getGraphicsConfiguration ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Dialog</code> with the specified,
|
||||
* parent and title, that is resizable.
|
||||
*
|
||||
* @exception IllegalArgumentException If parent is null. This exception is
|
||||
* always thrown when GraphicsEnvironment.isHeadless() returns true.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public
|
||||
Dialog (Dialog owner, String title)
|
||||
{
|
||||
this (owner, title, false, owner.getGraphicsConfiguration ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Dialog</code> with the specified,
|
||||
* parent, title and modality, that is resizable.
|
||||
*
|
||||
* @exception IllegalArgumentException If parent is null. This exception is
|
||||
* always thrown when GraphicsEnvironment.isHeadless() returns true.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public
|
||||
Dialog (Dialog owner, String title, boolean modal)
|
||||
{
|
||||
this (owner, title, modal, owner.getGraphicsConfiguration ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Dialog</code> with the specified,
|
||||
* parent, title, modality and <code>GraphicsConfiguration</code>,
|
||||
* that is resizable.
|
||||
*
|
||||
* @exception IllegalArgumentException If parent is null, the
|
||||
* GraphicsConfiguration is not a screen device or
|
||||
* GraphicsEnvironment.isHeadless() returns true.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public
|
||||
Dialog (Dialog parent, String title, boolean modal, GraphicsConfiguration gc)
|
||||
{
|
||||
super (parent, parent.getGraphicsConfiguration ());
|
||||
|
||||
// A null title is equivalent to an empty title
|
||||
this.title = (title != null) ? title : "";
|
||||
this.modal = modal;
|
||||
visible = false;
|
||||
|
||||
setLayout (new BorderLayout ());
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the title of this dialog box.
|
||||
*
|
||||
* @return The title of this dialog box.
|
||||
*/
|
||||
public String
|
||||
getTitle()
|
||||
{
|
||||
return(title);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the title of this dialog box to the specified string.
|
||||
*
|
||||
* @param title The new title.
|
||||
*/
|
||||
public synchronized void
|
||||
setTitle(String title)
|
||||
{
|
||||
// A null title is equivalent to an empty title
|
||||
this.title = (title != null) ? title : "";
|
||||
|
||||
if (peer != null)
|
||||
{
|
||||
DialogPeer d = (DialogPeer) peer;
|
||||
d.setTitle (title);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Tests whether or not this dialog box is modal.
|
||||
*
|
||||
* @return <code>true</code> if this dialog box is modal,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public boolean
|
||||
isModal()
|
||||
{
|
||||
return(modal);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Changes the modality of this dialog box. This can only be done before
|
||||
* the peer is created.
|
||||
*
|
||||
* @param modal <code>true</code> to make this dialog box modal,
|
||||
* <code>false</code> to make it non-modal.
|
||||
*/
|
||||
public void
|
||||
setModal(boolean modal)
|
||||
{
|
||||
this.modal = modal;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Tests whether or not this dialog box is resizable.
|
||||
*
|
||||
* @return <code>true</code> if this dialog is resizable, <code>false</code>,
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean
|
||||
isResizable()
|
||||
{
|
||||
return(resizable);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Changes the resizability of this dialog box.
|
||||
*
|
||||
* @param resizable <code>true</code> to make this dialog resizable,
|
||||
* <code>false</code> to make it non-resizable.
|
||||
*/
|
||||
public synchronized void
|
||||
setResizable(boolean resizable)
|
||||
{
|
||||
this.resizable = resizable;
|
||||
if (peer != null)
|
||||
{
|
||||
DialogPeer d = (DialogPeer) peer;
|
||||
d.setResizable (resizable);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Creates this object's native peer.
|
||||
*/
|
||||
public synchronized void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit ().createDialog (this);
|
||||
super.addNotify ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Makes this dialog visible and brings it to the front.
|
||||
* If the dialog is modal and is not already visible, this call will not
|
||||
* return until the dialog is hidden by someone calling hide or dispose.
|
||||
* If this is the event dispatching thread we must ensure that another event
|
||||
* thread runs while the one which invoked this method is blocked.
|
||||
*/
|
||||
public synchronized void
|
||||
show()
|
||||
{
|
||||
super.show();
|
||||
|
||||
if (isModal())
|
||||
{
|
||||
// If already shown (and blocked) just return
|
||||
if (blocked)
|
||||
return;
|
||||
|
||||
/* If show is called in the dispatch thread for a modal dialog it will
|
||||
block so we must run another thread so the events keep being
|
||||
dispatched.*/
|
||||
if (EventQueue.isDispatchThread ())
|
||||
{
|
||||
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
||||
eq2 = new EventQueue ();
|
||||
eq.push (eq2);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
blocked = true;
|
||||
wait ();
|
||||
blocked = false;
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
blocked = false;
|
||||
}
|
||||
|
||||
if (eq2 != null)
|
||||
{
|
||||
eq2.pop ();
|
||||
eq2 = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Hides the Dialog and then
|
||||
* causes show() to return if it is currently blocked.
|
||||
*/
|
||||
|
||||
public synchronized void
|
||||
hide ()
|
||||
{
|
||||
if (blocked)
|
||||
{
|
||||
notifyAll ();
|
||||
}
|
||||
|
||||
super.hide();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Disposes the Dialog and then causes show() to return
|
||||
* if it is currently blocked.
|
||||
*/
|
||||
|
||||
public synchronized void
|
||||
dispose ()
|
||||
{
|
||||
if (blocked)
|
||||
{
|
||||
notifyAll ();
|
||||
}
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this component.
|
||||
*
|
||||
* @return A debugging string for this component.
|
||||
*/
|
||||
protected String
|
||||
paramString()
|
||||
{
|
||||
return ("title+" + title + ",modal=" + modal +
|
||||
",resizable=" + resizable + "," + super.paramString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this frame is undecorated or not.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean isUndecorated ()
|
||||
{
|
||||
return undecorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables or enables decorations for this frame. This method can only be
|
||||
* called while the frame is not displayable.
|
||||
*
|
||||
* @exception IllegalComponentStateException If this frame is displayable.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void setUndecorated (boolean undecorated)
|
||||
{
|
||||
if (isDisplayable ())
|
||||
throw new IllegalComponentStateException ();
|
||||
|
||||
this.undecorated = undecorated;
|
||||
}
|
||||
|
||||
protected class AccessibleAWTDialog extends AccessibleAWTWindow
|
||||
{
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.DIALOG;
|
||||
}
|
||||
|
||||
public AccessibleStateSet getAccessibleState()
|
||||
{
|
||||
AccessibleStateSet states = super.getAccessibleStateSet();
|
||||
if (isResizable())
|
||||
states.add(AccessibleState.RESIZABLE);
|
||||
if (isModal())
|
||||
states.add(AccessibleState.MODAL);
|
||||
return states;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>Dialog</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTDialog();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
} // class Dialog
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
/* Dimension.java -- represents a 2-dimensional span
|
||||
Copyright (C) 1999, 2000, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.Dimension2D;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class holds a width and height value pair. This is used in plenty
|
||||
* of windowing classes, but also has geometric meaning.
|
||||
*
|
||||
* <p>It is valid for a dimension to have negative width or height; but it
|
||||
* is considered to have no area. Therefore, the behavior in various methods
|
||||
* is undefined in such a case.
|
||||
*
|
||||
* <p>There are some public fields; if you mess with them in an inconsistent
|
||||
* manner, it is your own fault when you get invalid results. Also, this
|
||||
* class is not threadsafe.
|
||||
*
|
||||
* @author Per Bothner (bothner@cygnus.com)
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Component
|
||||
* @see LayoutManager
|
||||
* @since 1.0
|
||||
* @status updated to 1.14
|
||||
*/
|
||||
public class Dimension extends Dimension2D implements Serializable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = 4723952579491349524L;
|
||||
|
||||
/**
|
||||
* The width of this object.
|
||||
*
|
||||
* @see #getSize()
|
||||
* @see #setSize(double, double)
|
||||
* @serial the width
|
||||
*/
|
||||
public int width;
|
||||
|
||||
/**
|
||||
* The height of this object.
|
||||
*
|
||||
* @see #getSize()
|
||||
* @see #setSize(double, double)
|
||||
* @serial the height
|
||||
*/
|
||||
public int height;
|
||||
|
||||
/**
|
||||
* Create a new Dimension with a width and height of zero.
|
||||
*/
|
||||
public Dimension()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Dimension with width and height identical to that of the
|
||||
* specified dimension.
|
||||
*
|
||||
* @param d the Dimension to copy
|
||||
* @throws NullPointerException if d is null
|
||||
*/
|
||||
public Dimension(Dimension d)
|
||||
{
|
||||
width = d.width;
|
||||
height = d.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new Dimension with the specified width and height.
|
||||
*
|
||||
* @param w the width of this object
|
||||
* @param h the height of this object
|
||||
*/
|
||||
public Dimension(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width of this dimension.
|
||||
*
|
||||
* @return the width, as a double
|
||||
*/
|
||||
public double getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the height of this dimension.
|
||||
*
|
||||
* @return the height, as a double
|
||||
*/
|
||||
public double getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of this dimension. The values are rounded to int.
|
||||
*
|
||||
* @param w the new width
|
||||
* @param h the new height
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setSize(double w, double h)
|
||||
{
|
||||
width = (int) w;
|
||||
height = (int) h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of this dimension. A pretty useless method, as this is
|
||||
* already a dimension.
|
||||
*
|
||||
* @return a copy of this dimension
|
||||
* @see #setSize(Dimension)
|
||||
* @since 1.1
|
||||
*/
|
||||
public Dimension getSize()
|
||||
{
|
||||
return new Dimension(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width and height of this object to match that of the
|
||||
* specified object.
|
||||
*
|
||||
* @param d the Dimension to get the new width and height from
|
||||
* @throws NullPointerException if d is null
|
||||
* @see #getSize()
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setSize(Dimension d)
|
||||
{
|
||||
width = d.width;
|
||||
height = d.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width and height of this object to the specified values.
|
||||
*
|
||||
* @param w the new width value
|
||||
* @param h the new height value
|
||||
*/
|
||||
public void setSize(int w, int h)
|
||||
{
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests this object for equality against the specified object. This will
|
||||
* be true if and only if the specified object is an instance of
|
||||
* Dimension2D, and has the same width and height.
|
||||
*
|
||||
* @param obj the object to test against
|
||||
* @return true if the object is equal to this
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (! (obj instanceof Dimension))
|
||||
return false;
|
||||
Dimension dim = (Dimension) obj;
|
||||
return height == dim.height && width == dim.width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the hashcode for this object. It is not documented, but appears
|
||||
* to be <code>((width + height) * (width + height + 1) / 2) + width</code>.
|
||||
*
|
||||
* @return the hashcode
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
// Reverse engineering this was fun!
|
||||
return (width + height) * (width + height + 1) / 2 + width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object. The format is:
|
||||
* <code>getClass().getName() + "[width=" + width + ",height=" + height
|
||||
* + ']'</code>.
|
||||
*
|
||||
* @return a string representation of this object
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getName()
|
||||
+ "[width=" + width + ",height=" + height + ']';
|
||||
}
|
||||
} // class Dimension
|
||||
@@ -0,0 +1,164 @@
|
||||
/* DisplayMode.java -- a description of display mode configurations
|
||||
Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This encapsulates information about the display mode for a graphics
|
||||
* device configuration. They are device dependent, and may not always be
|
||||
* available.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see GraphicsDevice
|
||||
* @since 1.4
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class DisplayMode
|
||||
{
|
||||
/**
|
||||
* Value of the bit depth if multiple depths are supported.
|
||||
*
|
||||
* @see #getBitDepth()
|
||||
*/
|
||||
public static final int BIT_DEPTH_MULTI = -1;
|
||||
|
||||
/**
|
||||
* Value of an unknown refresh rate.
|
||||
*
|
||||
* @see #getRefreshRate()
|
||||
*/
|
||||
public static final int REFRESH_RATE_UNKNOWN = 0;
|
||||
|
||||
/** The width. */
|
||||
private final int width;
|
||||
|
||||
/** The height. */
|
||||
private final int height;
|
||||
|
||||
/** The bit depth. */
|
||||
private final int bitDepth;
|
||||
|
||||
/** The refresh rate. */
|
||||
private final int refreshRate;
|
||||
|
||||
/**
|
||||
* Create a mode with the given parameters.
|
||||
*
|
||||
* @param width the width
|
||||
* @param height the height
|
||||
* @param bitDepth the bitDepth
|
||||
* @param refreshRate the refreshRate
|
||||
* @see #BIT_DEPTH_MULTI
|
||||
* @see #REFRESH_RATE_UNKNOWN
|
||||
*/
|
||||
public DisplayMode(int width, int height, int bitDepth, int refreshRate)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.bitDepth = bitDepth;
|
||||
this.refreshRate = refreshRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height, in pixels.
|
||||
*
|
||||
* @return the height
|
||||
*/
|
||||
public int getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width, in pixels.
|
||||
*
|
||||
* @return the width
|
||||
*/
|
||||
public int getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bit depth, in bits per pixel. This may be BIT_DEPTH_MULTI.
|
||||
*
|
||||
* @return the bit depth
|
||||
* @see #BIT_DEPTH_MULTI
|
||||
*/
|
||||
public int getBitDepth()
|
||||
{
|
||||
return bitDepth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the refresh rate, in hertz. This may be REFRESH_RATE_UNKNOWN.
|
||||
*
|
||||
* @return the refresh rate
|
||||
* @see #REFRESH_RATE_UNKNOWN
|
||||
*/
|
||||
public int getRefreshRate()
|
||||
{
|
||||
return refreshRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for equality. This returns true for two modes with identical
|
||||
* parameters.
|
||||
*
|
||||
* @param dm The display mode to compare to
|
||||
*
|
||||
* @return true if it is equal
|
||||
*/
|
||||
public boolean equals (DisplayMode dm)
|
||||
{
|
||||
return (width == dm.width
|
||||
&& height == dm.height
|
||||
&& bitDepth == dm.bitDepth
|
||||
&& refreshRate == dm.refreshRate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code for the display mode.
|
||||
*
|
||||
* @return the hash code
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return width + height + bitDepth + refreshRate;
|
||||
}
|
||||
} // class DisplayMode
|
||||
@@ -0,0 +1,185 @@
|
||||
/* Copyright (C) 1999, 2000, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* Written using on-line Java Platform 1.2 API Specification, as well
|
||||
* as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998).
|
||||
* Status: Believed complete and correct.
|
||||
*/
|
||||
|
||||
public class Event implements java.io.Serializable
|
||||
{
|
||||
static final long serialVersionUID = 5488922509400504703L;
|
||||
|
||||
public static final int SHIFT_MASK = 1;
|
||||
public static final int CTRL_MASK = 2;
|
||||
public static final int META_MASK = 4;
|
||||
public static final int ALT_MASK = 8;
|
||||
|
||||
public static final int ACTION_EVENT = 1001;
|
||||
public static final int BACK_SPACE = 8;
|
||||
public static final int CAPS_LOCK = 1022;
|
||||
public static final int DELETE = 127;
|
||||
public static final int DOWN = 1005;
|
||||
public static final int END = 1001;
|
||||
public static final int ENTER = 10;
|
||||
public static final int ESCAPE = 27;
|
||||
public static final int F1 = 1008;
|
||||
public static final int F10 = 1017;
|
||||
public static final int F11 = 1018;
|
||||
public static final int F12 = 1019;
|
||||
public static final int F2 = 1009;
|
||||
public static final int F3 = 1010;
|
||||
public static final int F4 = 1011;
|
||||
public static final int F5 = 1012;
|
||||
public static final int F6 = 1013;
|
||||
public static final int F7 = 1014;
|
||||
public static final int F8 = 1015;
|
||||
public static final int F9 = 1016;
|
||||
public static final int GOT_FOCUS = 1004;
|
||||
public static final int HOME = 1000;
|
||||
public static final int INSERT = 1025;
|
||||
public static final int KEY_ACTION = 403;
|
||||
public static final int KEY_ACTION_RELEASE = 404;
|
||||
public static final int KEY_PRESS = 401;
|
||||
public static final int KEY_RELEASE = 402;
|
||||
public static final int LEFT = 1006;
|
||||
public static final int LIST_DESELECT = 702;
|
||||
public static final int LIST_SELECT = 701;
|
||||
public static final int LOAD_FILE = 1002;
|
||||
public static final int LOST_FOCUS = 1005;
|
||||
public static final int MOUSE_DOWN = 501;
|
||||
public static final int MOUSE_DRAG = 506;
|
||||
public static final int MOUSE_ENTER = 504;
|
||||
public static final int MOUSE_EXIT = 505;
|
||||
public static final int MOUSE_MOVE = 503;
|
||||
public static final int MOUSE_UP = 502;
|
||||
public static final int NUM_LOCK = 1023;
|
||||
public static final int PAUSE = 1024;
|
||||
public static final int PGDN = 1003;
|
||||
public static final int PGUP = 1002;
|
||||
public static final int PRINT_SCREEN = 1020;
|
||||
public static final int RIGHT = 1007;
|
||||
public static final int SAVE_FILE = 1003;
|
||||
public static final int SCROLL_ABSOLUTE = 605;
|
||||
public static final int SCROLL_BEGIN = 606;
|
||||
public static final int SCROLL_END = 607;
|
||||
public static final int SCROLL_LINE_DOWN = 602;
|
||||
public static final int SCROLL_LINE_UP = 601;
|
||||
public static final int SCROLL_LOCK = 1021;
|
||||
public static final int SCROLL_PAGE_DOWN = 604;
|
||||
public static final int SCROLL_PAGE_UP = 603;
|
||||
public static final int TAB = 9;
|
||||
public static final int UP = 1004;
|
||||
public static final int WINDOW_DEICONIFY = 204;
|
||||
public static final int WINDOW_DESTROY = 201;
|
||||
public static final int WINDOW_EXPOSE = 202;
|
||||
public static final int WINDOW_ICONIFY = 203;
|
||||
public static final int WINDOW_MOVED = 205;
|
||||
|
||||
public Object arg;
|
||||
public int clickCount;
|
||||
boolean consumed; // Required by serialization spec.
|
||||
public Event evt;
|
||||
public int id;
|
||||
public int key;
|
||||
public int modifiers;
|
||||
public Object target;
|
||||
public long when;
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
public Event (Object target, int id, Object arg)
|
||||
{
|
||||
this.id = id;
|
||||
this.target = target;
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
public Event (Object target, long when, int id, int x, int y, int key,
|
||||
int modifiers)
|
||||
{
|
||||
this.target = target;
|
||||
this.when = when;
|
||||
this.id = id;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.key = key;
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
public Event (Object target, long when, int id, int x, int y, int key,
|
||||
int modifiers, Object arg)
|
||||
{
|
||||
this (target, when, id, x, y, key, modifiers);
|
||||
this.arg = arg;
|
||||
}
|
||||
|
||||
public boolean controlDown ()
|
||||
{
|
||||
return ((modifiers & CTRL_MASK) == 0 ? false : true);
|
||||
}
|
||||
|
||||
public boolean metaDown ()
|
||||
{
|
||||
return ((modifiers & META_MASK) == 0 ? false : true);
|
||||
}
|
||||
|
||||
protected String paramString ()
|
||||
{
|
||||
return "id=" + id + ",x=" + x + ",y=" + y
|
||||
+ ",target=" + target + ",arg=" + arg;
|
||||
}
|
||||
|
||||
public boolean shiftDown()
|
||||
{
|
||||
return ((modifiers & SHIFT_MASK) == 0 ? false : true);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getName() + "[" + paramString() + "]";
|
||||
}
|
||||
|
||||
public void translate (int x, int y)
|
||||
{
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/* EventDispatchThread.java -
|
||||
Copyright (C) 2000, 2002, 2004 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* @author Bryce McKinlay
|
||||
* @status believed complete, but untested.
|
||||
*/
|
||||
class EventDispatchThread extends Thread
|
||||
{
|
||||
private static int dispatchThreadNum;
|
||||
|
||||
private EventQueue queue;
|
||||
|
||||
EventDispatchThread(EventQueue queue)
|
||||
{
|
||||
super();
|
||||
setName("AWT-EventQueue-" + ++dispatchThreadNum);
|
||||
this.queue = queue;
|
||||
setPriority(NORM_PRIORITY + 1);
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
AWTEvent evt = queue.getNextEvent();
|
||||
|
||||
KeyboardFocusManager manager;
|
||||
manager = KeyboardFocusManager.getCurrentKeyboardFocusManager ();
|
||||
|
||||
// Try to dispatch this event to the current keyboard focus
|
||||
// manager. It will dispatch all FocusEvents, all
|
||||
// WindowEvents related to focus, and all KeyEvents,
|
||||
// returning true. Otherwise, it returns false and we
|
||||
// dispatch the event normally.
|
||||
if (!manager.dispatchEvent (evt))
|
||||
queue.dispatchEvent(evt);
|
||||
}
|
||||
catch (ThreadDeath death)
|
||||
{
|
||||
// If someone wants to kill us, let them.
|
||||
return;
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
// We are interrupted when we should finish executing
|
||||
return;
|
||||
}
|
||||
catch (Throwable x)
|
||||
{
|
||||
System.err.println("Exception during event dispatch:");
|
||||
x.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,552 @@
|
||||
/* EventQueue.java --
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import gnu.java.awt.ClasspathToolkit;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.InputMethodEvent;
|
||||
import java.awt.event.InvocationEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.EmptyStackException;
|
||||
|
||||
/* Written using on-line Java 2 Platform Standard Edition v1.3 API
|
||||
* Specification, as well as "The Java Class Libraries", 2nd edition
|
||||
* (Addison-Wesley, 1998).
|
||||
* Status: Believed complete, but untested.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class manages a queue of <code>AWTEvent</code> objects that
|
||||
* are posted to it. The AWT system uses only one event queue for all
|
||||
* events.
|
||||
*
|
||||
* @author Bryce McKinlay
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class EventQueue
|
||||
{
|
||||
private static final int INITIAL_QUEUE_DEPTH = 8;
|
||||
private AWTEvent[] queue = new AWTEvent[INITIAL_QUEUE_DEPTH];
|
||||
|
||||
private int next_in = 0; // Index where next event will be added to queue
|
||||
private int next_out = 0; // Index of next event to be removed from queue
|
||||
|
||||
private EventQueue next;
|
||||
private EventQueue prev;
|
||||
private AWTEvent currentEvent;
|
||||
private long lastWhen = System.currentTimeMillis();
|
||||
|
||||
private EventDispatchThread dispatchThread = new EventDispatchThread(this);
|
||||
private boolean shutdown = false;
|
||||
|
||||
private long lastNativeQueueAccess = 0;
|
||||
private long humanLatencyThreshold = 100;
|
||||
|
||||
synchronized void setShutdown (boolean b)
|
||||
{
|
||||
shutdown = b;
|
||||
}
|
||||
|
||||
synchronized boolean isShutdown ()
|
||||
{
|
||||
if (shutdown)
|
||||
return true;
|
||||
|
||||
// This is the exact self-shutdown condition specified in J2SE:
|
||||
// http://java.sun.com/j2se/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html
|
||||
|
||||
if (peekEvent() == null
|
||||
&& ((ClasspathToolkit) Toolkit.getDefaultToolkit()).nativeQueueEmpty())
|
||||
{
|
||||
Frame[] frames = Frame.getFrames();
|
||||
for (int i = 0; i < frames.length; ++i)
|
||||
if (frames[i].isDisplayable())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>EventQueue</code>.
|
||||
*/
|
||||
public EventQueue()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next event in the queue. This method will block until
|
||||
* an event is available or until the thread is interrupted.
|
||||
*
|
||||
* @return The next event in the queue.
|
||||
*
|
||||
* @exception InterruptedException If this thread is interrupted while
|
||||
* waiting for an event to be posted to the queue.
|
||||
*/
|
||||
public synchronized AWTEvent getNextEvent()
|
||||
throws InterruptedException
|
||||
{
|
||||
if (next != null)
|
||||
return next.getNextEvent();
|
||||
|
||||
ClasspathToolkit tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit());
|
||||
long curr = System.currentTimeMillis();
|
||||
|
||||
if (! tk.nativeQueueEmpty() &&
|
||||
(curr - lastNativeQueueAccess > humanLatencyThreshold))
|
||||
{
|
||||
tk.iterateNativeQueue(this, false);
|
||||
lastNativeQueueAccess = curr;
|
||||
}
|
||||
|
||||
while (next_in == next_out)
|
||||
{
|
||||
// Only the EventDispatchThread associated with the top of the stack is
|
||||
// allowed to get events from the native source; everyone else just
|
||||
// waits on the head of the queue.
|
||||
|
||||
if (isDispatchThread())
|
||||
{
|
||||
// We are not allowed to return null from this method, yet it
|
||||
// is possible that we actually have run out of native events
|
||||
// in the enclosing while() loop, and none of the native events
|
||||
// happened to cause AWT events. We therefore ought to check
|
||||
// the isShutdown() condition here, before risking a "native
|
||||
// wait". If we check it before entering this function we may
|
||||
// wait forever for events after the shutdown condition has
|
||||
// arisen.
|
||||
|
||||
if (isShutdown())
|
||||
throw new InterruptedException();
|
||||
|
||||
tk.iterateNativeQueue(this, true);
|
||||
lastNativeQueueAccess = System.currentTimeMillis();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
wait();
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AWTEvent res = queue[next_out];
|
||||
|
||||
if (++next_out == queue.length)
|
||||
next_out = 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next event in the queue without removing it from the queue.
|
||||
* This method will block until an event is available or until the thread
|
||||
* is interrupted.
|
||||
*
|
||||
* @return The next event in the queue.
|
||||
* @specnote Does not block. Returns null if there are no events on the
|
||||
* queue.
|
||||
*/
|
||||
public synchronized AWTEvent peekEvent()
|
||||
{
|
||||
if (next != null)
|
||||
return next.peekEvent();
|
||||
|
||||
if (next_in != next_out)
|
||||
return queue[next_out];
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next event in the queue that has the specified id
|
||||
* without removing it from the queue.
|
||||
* This method will block until an event is available or until the thread
|
||||
* is interrupted.
|
||||
*
|
||||
* @param id The event id to return.
|
||||
*
|
||||
* @return The next event in the queue.
|
||||
*
|
||||
* @specnote Does not block. Returns null if there are no matching events
|
||||
* on the queue.
|
||||
*/
|
||||
public synchronized AWTEvent peekEvent(int id)
|
||||
{
|
||||
if (next != null)
|
||||
return next.peekEvent(id);
|
||||
|
||||
int i = next_out;
|
||||
while (i != next_in)
|
||||
{
|
||||
AWTEvent qevt = queue[i];
|
||||
if (qevt.id == id)
|
||||
return qevt;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts a new event to the queue.
|
||||
*
|
||||
* @param evt The event to post to the queue.
|
||||
*
|
||||
* @exception NullPointerException If event is null.
|
||||
*/
|
||||
public synchronized void postEvent(AWTEvent evt)
|
||||
{
|
||||
if (evt == null)
|
||||
throw new NullPointerException();
|
||||
|
||||
if (next != null)
|
||||
{
|
||||
next.postEvent(evt);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check for any events already on the queue with the same source
|
||||
and ID. */
|
||||
int i = next_out;
|
||||
while (i != next_in)
|
||||
{
|
||||
AWTEvent qevt = queue[i];
|
||||
Object src;
|
||||
if (qevt.id == evt.id
|
||||
&& (src = qevt.getSource()) == evt.getSource()
|
||||
&& src instanceof Component)
|
||||
{
|
||||
/* If there are, call coalesceEvents on the source component
|
||||
to see if they can be combined. */
|
||||
Component srccmp = (Component) src;
|
||||
AWTEvent coalesced_evt = srccmp.coalesceEvents(qevt, evt);
|
||||
if (coalesced_evt != null)
|
||||
{
|
||||
/* Yes. Replace the existing event with the combined event. */
|
||||
queue[i] = coalesced_evt;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (++i == queue.length)
|
||||
i = 0;
|
||||
}
|
||||
|
||||
queue[next_in] = evt;
|
||||
if (++next_in == queue.length)
|
||||
next_in = 0;
|
||||
|
||||
if (next_in == next_out)
|
||||
{
|
||||
/* Queue is full. Extend it. */
|
||||
AWTEvent[] oldQueue = queue;
|
||||
queue = new AWTEvent[queue.length * 2];
|
||||
|
||||
int len = oldQueue.length - next_out;
|
||||
System.arraycopy(oldQueue, next_out, queue, 0, len);
|
||||
if (next_out != 0)
|
||||
System.arraycopy(oldQueue, 0, queue, len, next_out);
|
||||
|
||||
next_out = 0;
|
||||
next_in = oldQueue.length;
|
||||
}
|
||||
|
||||
if (dispatchThread == null || !dispatchThread.isAlive())
|
||||
{
|
||||
dispatchThread = new EventDispatchThread(this);
|
||||
dispatchThread.start();
|
||||
}
|
||||
|
||||
// Window events might represent the closing of a window, which
|
||||
// might cause the end of the dispatch thread's life, so we'll wake
|
||||
// it up here to give it a chance to check for shutdown.
|
||||
|
||||
if (!isDispatchThread()
|
||||
|| (evt.getID() == WindowEvent.WINDOW_CLOSED)
|
||||
|| (evt.getID() == WindowEvent.WINDOW_CLOSING))
|
||||
((ClasspathToolkit) Toolkit.getDefaultToolkit()).wakeNativeQueue();
|
||||
|
||||
notify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes runnable to have its run method called in the dispatch thread of the
|
||||
* EventQueue. This will happen after all pending events are processed. The
|
||||
* call blocks until this has happened. This method will throw an Error if
|
||||
* called from the event dispatcher thread.
|
||||
*
|
||||
* @exception InterruptedException If another thread has interrupted
|
||||
* this thread.
|
||||
* @exception InvocationTargetException If an exception is thrown when running
|
||||
* runnable.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public static void invokeAndWait(Runnable runnable)
|
||||
throws InterruptedException, InvocationTargetException
|
||||
{
|
||||
if (isDispatchThread ())
|
||||
throw new Error("Can't call invokeAndWait from event dispatch thread");
|
||||
|
||||
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
||||
Thread current = Thread.currentThread();
|
||||
|
||||
InvocationEvent ie =
|
||||
new InvocationEvent(eq, runnable, current, true);
|
||||
|
||||
synchronized (current)
|
||||
{
|
||||
eq.postEvent(ie);
|
||||
current.wait();
|
||||
}
|
||||
|
||||
Exception exception;
|
||||
|
||||
if ((exception = ie.getException()) != null)
|
||||
throw new InvocationTargetException(exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* This arranges for runnable to have its run method called in the
|
||||
* dispatch thread of the EventQueue. This will happen after all
|
||||
* pending events are processed.
|
||||
*
|
||||
* @since 1.2
|
||||
*/
|
||||
public static void invokeLater(Runnable runnable)
|
||||
{
|
||||
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
||||
|
||||
InvocationEvent ie =
|
||||
new InvocationEvent(eq, runnable, null, false);
|
||||
|
||||
eq.postEvent(ie);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the current thread is the current AWT event dispatch
|
||||
* thread.
|
||||
*/
|
||||
public static boolean isDispatchThread()
|
||||
{
|
||||
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
||||
|
||||
/* Find last EventQueue in chain */
|
||||
while (eq.next != null)
|
||||
eq = eq.next;
|
||||
|
||||
return (Thread.currentThread() == eq.dispatchThread);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the event currently being dispatched by the event
|
||||
* dispatch thread. If the current thread is not the event
|
||||
* dispatch thread, this method returns null.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public static AWTEvent getCurrentEvent()
|
||||
{
|
||||
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
||||
Thread ct = Thread.currentThread();
|
||||
|
||||
/* Find out if this thread is the dispatch thread for any of the
|
||||
EventQueues in the chain */
|
||||
while (ct != eq.dispatchThread)
|
||||
{
|
||||
// Try next EventQueue, if any
|
||||
if (eq.next == null)
|
||||
return null; // Not an event dispatch thread
|
||||
eq = eq.next;
|
||||
}
|
||||
|
||||
return eq.currentEvent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows a custom EventQueue implementation to replace this one.
|
||||
* All pending events are transferred to the new queue. Calls to postEvent,
|
||||
* getNextEvent, and peekEvent and others are forwarded to the pushed queue
|
||||
* until it is removed with a pop().
|
||||
*
|
||||
* @exception NullPointerException if newEventQueue is null.
|
||||
*/
|
||||
public synchronized void push(EventQueue newEventQueue)
|
||||
{
|
||||
if (newEventQueue == null)
|
||||
throw new NullPointerException ();
|
||||
|
||||
/* Make sure we are at the top of the stack because callers can
|
||||
only get a reference to the one at the bottom using
|
||||
Toolkit.getDefaultToolkit().getSystemEventQueue() */
|
||||
if (next != null)
|
||||
{
|
||||
next.push (newEventQueue);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Make sure we have a live dispatch thread to drive the queue */
|
||||
if (dispatchThread == null)
|
||||
dispatchThread = new EventDispatchThread(this);
|
||||
|
||||
int i = next_out;
|
||||
while (i != next_in)
|
||||
{
|
||||
newEventQueue.postEvent(queue[i]);
|
||||
next_out = i;
|
||||
if (++i == queue.length)
|
||||
i = 0;
|
||||
}
|
||||
|
||||
next = newEventQueue;
|
||||
newEventQueue.prev = this;
|
||||
}
|
||||
|
||||
/** Transfer any pending events from this queue back to the parent queue that
|
||||
* was previously push()ed. Event dispatch from this queue is suspended.
|
||||
*
|
||||
* @exception EmptyStackException If no previous push was made on this
|
||||
* EventQueue.
|
||||
*/
|
||||
protected void pop() throws EmptyStackException
|
||||
{
|
||||
if (prev == null)
|
||||
throw new EmptyStackException();
|
||||
|
||||
/* The order is important here, we must get the prev lock first,
|
||||
or deadlock could occur as callers usually get here following
|
||||
prev's next pointer, and thus obtain prev's lock before trying
|
||||
to get this lock. */
|
||||
synchronized (prev)
|
||||
{
|
||||
prev.next = next;
|
||||
if (next != null)
|
||||
next.prev = prev;
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
int i = next_out;
|
||||
while (i != next_in)
|
||||
{
|
||||
prev.postEvent(queue[i]);
|
||||
next_out = i;
|
||||
if (++i == queue.length)
|
||||
i = 0;
|
||||
}
|
||||
// Empty the queue so it can be reused
|
||||
next_in = 0;
|
||||
next_out = 0;
|
||||
|
||||
((ClasspathToolkit) Toolkit.getDefaultToolkit()).wakeNativeQueue();
|
||||
setShutdown(true);
|
||||
dispatchThread = null;
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches an event. The manner in which the event is dispatched depends
|
||||
* upon the type of the event and the type of the event's source object.
|
||||
*
|
||||
* @exception NullPointerException If event is null.
|
||||
*/
|
||||
protected void dispatchEvent(AWTEvent evt)
|
||||
{
|
||||
currentEvent = evt;
|
||||
|
||||
if (evt instanceof InputEvent)
|
||||
lastWhen = ((InputEvent) evt).getWhen();
|
||||
else if (evt instanceof ActionEvent)
|
||||
lastWhen = ((ActionEvent) evt).getWhen();
|
||||
else if (evt instanceof InvocationEvent)
|
||||
lastWhen = ((InvocationEvent) evt).getWhen();
|
||||
|
||||
if (evt instanceof ActiveEvent)
|
||||
{
|
||||
ActiveEvent active_evt = (ActiveEvent) evt;
|
||||
active_evt.dispatch();
|
||||
}
|
||||
else
|
||||
{
|
||||
Object source = evt.getSource();
|
||||
|
||||
if (source instanceof Component)
|
||||
{
|
||||
Component srccmp = (Component) source;
|
||||
srccmp.dispatchEvent(evt);
|
||||
}
|
||||
else if (source instanceof MenuComponent)
|
||||
{
|
||||
MenuComponent srccmp = (MenuComponent) source;
|
||||
srccmp.dispatchEvent(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the timestamp of the most recent event that had a timestamp, or
|
||||
* the initialization time of the event queue if no events have been fired.
|
||||
* At present, only <code>InputEvent</code>s, <code>ActionEvent</code>s,
|
||||
* <code>InputMethodEvent</code>s, and <code>InvocationEvent</code>s have
|
||||
* timestamps, but this may be added to other events in future versions.
|
||||
* If this is called by the event dispatching thread, it can be any
|
||||
* (sequential) value, but to other threads, the safest bet is to return
|
||||
* System.currentTimeMillis().
|
||||
*
|
||||
* @return the most recent timestamp
|
||||
* @see InputEvent#getWhen()
|
||||
* @see ActionEvent#getWhen()
|
||||
* @see InvocationEvent#getWhen()
|
||||
* @see InputMethodEvent#getWhen()
|
||||
* @since 1.4
|
||||
*/
|
||||
public static long getMostRecentEventTime()
|
||||
{
|
||||
EventQueue eq = Toolkit.getDefaultToolkit().getSystemEventQueue();
|
||||
if (Thread.currentThread() != eq.dispatchThread)
|
||||
return System.currentTimeMillis();
|
||||
return eq.lastWhen;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,318 @@
|
||||
/* FileDialog.java -- A filename selection dialog box
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.peer.FileDialogPeer;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class implements a file selection dialog box widget.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
*/
|
||||
public class FileDialog extends Dialog implements Serializable
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Indicates that the purpose of the dialog is for opening a file.
|
||||
*/
|
||||
public static final int LOAD = 0;
|
||||
|
||||
/**
|
||||
* Indicates that the purpose of the dialog is for saving a file.
|
||||
*/
|
||||
public static final int SAVE = 1;
|
||||
|
||||
// Serialization constant
|
||||
private static final long serialVersionUID = 5035145889651310422L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The directory for this file dialog.
|
||||
*/
|
||||
private String dir;
|
||||
|
||||
/**
|
||||
* @serial The filename for this file dialog
|
||||
*/
|
||||
private String file;
|
||||
|
||||
/**
|
||||
* @serial The filter for selecting filenames to display
|
||||
*/
|
||||
private FilenameFilter filter;
|
||||
|
||||
/**
|
||||
* @serial The mode of this dialog, either <code>LOAD</code> or
|
||||
* <code>SAVE</code>.
|
||||
*/
|
||||
private int mode;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>FileDialog</code> with the
|
||||
* specified parent. This dialog will have no title and will be for
|
||||
* loading a file.
|
||||
*
|
||||
* @param parent The parent frame for this dialog.
|
||||
*/
|
||||
public
|
||||
FileDialog(Frame parent)
|
||||
{
|
||||
this(parent, "", LOAD);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initialized a new instance of <code>FileDialog</code> with the
|
||||
* specified parent and title. This dialog will be for opening a file.
|
||||
*
|
||||
* @param parent The parent frame for this dialog.
|
||||
* @param title The title for this dialog.
|
||||
*/
|
||||
public
|
||||
FileDialog(Frame parent, String title)
|
||||
{
|
||||
this(parent, title, LOAD);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initialized a new instance of <code>FileDialog</code> with the
|
||||
* specified parent, title, and mode.
|
||||
*
|
||||
* @param parent The parent frame for this dialog.
|
||||
* @param title The title for this dialog.
|
||||
* @param mode The mode of the dialog, either <code>LOAD</code> or
|
||||
* <code>SAVE</code>.
|
||||
*
|
||||
* @exception IllegalArgumentException If an illegal file dialog mode
|
||||
* is supplied.
|
||||
*/
|
||||
public
|
||||
FileDialog(Frame parent, String title, int mode)
|
||||
{
|
||||
super(parent, title, true);
|
||||
|
||||
if ((mode != LOAD) && (mode != SAVE))
|
||||
throw new IllegalArgumentException (
|
||||
"Mode argument must be either LOAD or SAVE");
|
||||
|
||||
setMode (mode);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the mode of this dialog, either <code>LOAD</code> or
|
||||
* <code>SAVE</code>.
|
||||
*
|
||||
* @return The mode of this dialog.
|
||||
*/
|
||||
public int
|
||||
getMode()
|
||||
{
|
||||
return(mode);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the mode of this dialog to either <code>LOAD</code> or
|
||||
* <code>SAVE</code>. This method is only effective before the native
|
||||
* peer is created.
|
||||
*
|
||||
* @param mode The new mode of this file dialog.
|
||||
*
|
||||
* @exception IllegalArgumentException If an illegal file dialog mode
|
||||
* is supplied.
|
||||
*/
|
||||
public void
|
||||
setMode(int mode)
|
||||
{
|
||||
if ((mode != LOAD) && (mode != SAVE))
|
||||
throw new IllegalArgumentException("Bad mode: " + mode);
|
||||
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the directory for this file dialog.
|
||||
*
|
||||
* @return The directory for this file dialog.
|
||||
*/
|
||||
public String
|
||||
getDirectory()
|
||||
{
|
||||
return(dir);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the directory for this file dialog.
|
||||
*
|
||||
* @param dir The new directory for this file dialog.
|
||||
*/
|
||||
public synchronized void
|
||||
setDirectory(String dir)
|
||||
{
|
||||
this.dir = dir;
|
||||
if (peer != null)
|
||||
{
|
||||
FileDialogPeer f = (FileDialogPeer) peer;
|
||||
f.setDirectory (dir);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the file that is selected in this dialog.
|
||||
*
|
||||
* @return The file that is selected in this dialog.
|
||||
*/
|
||||
public String
|
||||
getFile()
|
||||
{
|
||||
return(file);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the selected file for this dialog.
|
||||
*
|
||||
* @param file The selected file for this dialog.
|
||||
*/
|
||||
public synchronized void
|
||||
setFile(String file)
|
||||
{
|
||||
this.file = file;
|
||||
if (peer != null)
|
||||
{
|
||||
FileDialogPeer f = (FileDialogPeer) peer;
|
||||
f.setFile (file);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the filename filter being used by this dialog.
|
||||
*
|
||||
* @return The filename filter being used by this dialog.
|
||||
*/
|
||||
public FilenameFilter
|
||||
getFilenameFilter()
|
||||
{
|
||||
return(filter);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the filename filter used by this dialog.
|
||||
*
|
||||
* @param filter The new filename filter for this file dialog box.
|
||||
*/
|
||||
public synchronized void
|
||||
setFilenameFilter(FilenameFilter filter)
|
||||
{
|
||||
this.filter = filter;
|
||||
if (peer != null)
|
||||
{
|
||||
FileDialogPeer f = (FileDialogPeer) peer;
|
||||
f.setFilenameFilter (filter);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Creates the native peer for this file dialog box.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit ().createFileDialog (this);
|
||||
super.addNotify ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this object.
|
||||
*
|
||||
* @return A debugging string for this object.
|
||||
*/
|
||||
protected String
|
||||
paramString()
|
||||
{
|
||||
return ("dir=" + dir + ",file=" + file +
|
||||
",mode=" + mode + "," + super.paramString());
|
||||
}
|
||||
|
||||
} // class FileDialog
|
||||
|
||||
@@ -0,0 +1,364 @@
|
||||
/* FlowLayout.java -- Grid-based layout engine
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/** This class implements a flow-based layout. Components are laid
|
||||
* out in order from left to right. When a component cannot be placed
|
||||
* without horizontal clipping, a new row is started. This class
|
||||
* supports horizontal and vertical gaps. These are used for spacing
|
||||
* between components.
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class FlowLayout implements LayoutManager, Serializable
|
||||
{
|
||||
/** Constant that specifies left alignment. */
|
||||
public static final int LEFT = 0;
|
||||
/** Constant that specifies center alignment. */
|
||||
public static final int CENTER = 1;
|
||||
/** Constant that specifies right alignment. */
|
||||
public static final int RIGHT = 2;
|
||||
|
||||
/** Constant that specifies alignment to leading edge of container's
|
||||
* orientation. */
|
||||
public static final int LEADING = 3;
|
||||
/** Constant that specifies alignment to trailing edge of container's
|
||||
* orientation. */
|
||||
public static final int TRAILING = 4;
|
||||
|
||||
// Serialization constant
|
||||
private static final long serialVersionUID = -7262534875583282631L;
|
||||
|
||||
/**
|
||||
* Add a new component to the layout. This particular implementation
|
||||
* does nothing.
|
||||
*
|
||||
* @param name the name
|
||||
* @param comp the component
|
||||
*/
|
||||
public void addLayoutComponent (String name, Component comp)
|
||||
{
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current justification value for this object.
|
||||
*
|
||||
* @return The current justification value for this object.
|
||||
*/
|
||||
public int getAlignment ()
|
||||
{
|
||||
return align;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the horizontal gap between components.
|
||||
*
|
||||
* @return The horizontal gap between components.
|
||||
*/
|
||||
public int getHgap ()
|
||||
{
|
||||
return hgap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the vertical gap between lines of components.
|
||||
*
|
||||
* @return The vertical gap between lines of components.
|
||||
*/
|
||||
public int getVgap ()
|
||||
{
|
||||
return vgap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>FlowLayout</code> with a center
|
||||
* justification and a default horizontal and vertical gap of 5.
|
||||
*/
|
||||
public FlowLayout ()
|
||||
{
|
||||
this (CENTER, 5, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>FlowLayout</code> with the specified
|
||||
* justification and a default horizontal and vertical gap of 5.
|
||||
*
|
||||
* @param align The justification setting, which should be one of the
|
||||
* contants in this class.
|
||||
*/
|
||||
public FlowLayout (int align)
|
||||
{
|
||||
this (align, 5, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>FlowLayout</code> with the specified
|
||||
* justification and gap values
|
||||
* @param align Alignment
|
||||
* @param hgap The horizontal gap
|
||||
* @param vgap The vertical gap
|
||||
* @exception IllegalArgumentException If either gap is negative
|
||||
*/
|
||||
public FlowLayout (int align, int hgap, int vgap)
|
||||
{
|
||||
// Use methods to set fields so that we can have all the checking
|
||||
// in one place.
|
||||
setVgap (vgap);
|
||||
setHgap (hgap);
|
||||
setAlignment (align);
|
||||
}
|
||||
|
||||
/** Lay out the container's components based on current settings.
|
||||
* @param parent The parent container
|
||||
*/
|
||||
public void layoutContainer (Container parent)
|
||||
{
|
||||
synchronized (parent.getTreeLock ())
|
||||
{
|
||||
int num = parent.getComponentCount ();
|
||||
// This is more efficient than calling getComponents().
|
||||
Component[] comps = parent.component;
|
||||
|
||||
Dimension d = parent.getSize ();
|
||||
Insets ins = parent.getInsets ();
|
||||
|
||||
ComponentOrientation orient = parent.getComponentOrientation ();
|
||||
boolean left_to_right = orient.isLeftToRight ();
|
||||
|
||||
int y = ins.top + vgap;
|
||||
int i = 0;
|
||||
while (i < num)
|
||||
{
|
||||
// Find the components which go in the current row.
|
||||
int new_w = ins.left + hgap + ins.right;
|
||||
int new_h = 0;
|
||||
int j;
|
||||
boolean found_one = false;
|
||||
for (j = i; j < num; ++j)
|
||||
{
|
||||
// Skip invisible items.
|
||||
if (! comps[j].visible)
|
||||
continue;
|
||||
|
||||
Dimension c = comps[j].getPreferredSize ();
|
||||
|
||||
int next_w = new_w + hgap + c.width;
|
||||
if (next_w <= d.width || ! found_one)
|
||||
{
|
||||
new_w = next_w;
|
||||
new_h = Math.max (new_h, c.height);
|
||||
found_one = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Must start a new row, and we already found an item
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set the location of each component for this row.
|
||||
int x;
|
||||
|
||||
int myalign = align;
|
||||
if (align == LEADING)
|
||||
myalign = left_to_right ? LEFT : RIGHT;
|
||||
else if (align == TRAILING)
|
||||
myalign = left_to_right ? RIGHT : LEFT;
|
||||
|
||||
if (myalign == LEFT)
|
||||
x = ins.left + hgap;
|
||||
else if (myalign == CENTER)
|
||||
x = ins.left + (d.width - new_w) / 2 + hgap;
|
||||
else
|
||||
x = ins.left + (d.width - new_w) + hgap;
|
||||
|
||||
for (int k = i; k < j; ++k)
|
||||
{
|
||||
if (comps[k].visible)
|
||||
{
|
||||
Dimension c = comps[k].getPreferredSize ();
|
||||
comps[k].setBounds (x, y + (new_h - c.height) / 2,
|
||||
c.width, c.height);
|
||||
x += c.width + hgap;
|
||||
}
|
||||
}
|
||||
|
||||
// Advance to next row.
|
||||
i = j;
|
||||
y += new_h + vgap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum layout size for the specified container using
|
||||
* this layout.
|
||||
* @param cont The parent container
|
||||
* @return The minimum layout size.
|
||||
*/
|
||||
public Dimension minimumLayoutSize (Container cont)
|
||||
{
|
||||
return getSize (cont, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the preferred layout size for the specified container using
|
||||
* this layout.
|
||||
* @param cont The parent container
|
||||
* @return The preferred layout size.
|
||||
*/
|
||||
public Dimension preferredLayoutSize (Container cont)
|
||||
{
|
||||
return getSize (cont, false);
|
||||
}
|
||||
|
||||
/** Remove the indicated component from this layout manager.
|
||||
* This particular implementation does nothing.
|
||||
* @param comp The component to remove
|
||||
*/
|
||||
public void removeLayoutComponent (Component comp)
|
||||
{
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the justification value for this object to the specified value.
|
||||
*
|
||||
* @param align The new justification value for this object, which must
|
||||
* be one of the constants in this class.
|
||||
*/
|
||||
public void setAlignment (int align)
|
||||
{
|
||||
if (align != LEFT && align != RIGHT && align != CENTER
|
||||
&& align != LEADING && align != TRAILING)
|
||||
throw new IllegalArgumentException ("invalid alignment: " + align);
|
||||
this.align = align;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the horizontal gap between components to the specified value.
|
||||
*
|
||||
* @param hgap The new horizontal gap between components.
|
||||
*/
|
||||
public void setHgap (int hgap)
|
||||
{
|
||||
if (hgap < 0)
|
||||
throw new IllegalArgumentException ("horizontal gap must be nonnegative");
|
||||
this.hgap = hgap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the vertical gap between lines of components to the specified value.
|
||||
*
|
||||
* @param vgap The new vertical gap.
|
||||
*/
|
||||
public void setVgap (int vgap)
|
||||
{
|
||||
if (vgap < 0)
|
||||
throw new IllegalArgumentException ("vertical gap must be nonnegative");
|
||||
this.vgap = vgap;
|
||||
}
|
||||
|
||||
/** Return String description of this object.
|
||||
* @return A string representation of this object.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return ("[" + getClass ().getName () + ",hgap=" + hgap + ",vgap=" + vgap
|
||||
+ ",align=" + align + "]");
|
||||
}
|
||||
|
||||
// This method is used to compute the various sizes.
|
||||
private Dimension getSize (Container parent, boolean is_min)
|
||||
{
|
||||
synchronized (parent.getTreeLock ())
|
||||
{
|
||||
int w, h, num = parent.getComponentCount ();
|
||||
// This is more efficient than calling getComponents().
|
||||
Component[] comps = parent.component;
|
||||
|
||||
w = 0;
|
||||
h = 0;
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
if (! comps[i].visible)
|
||||
continue;
|
||||
|
||||
// FIXME: can we just directly read the fields in Component?
|
||||
// Or will that not work with subclassing?
|
||||
Dimension d;
|
||||
|
||||
if (is_min)
|
||||
d = comps[i].getMinimumSize ();
|
||||
else
|
||||
d = comps[i].getPreferredSize ();
|
||||
|
||||
w += d.width;
|
||||
h = Math.max (d.height, h);
|
||||
}
|
||||
|
||||
Insets ins = parent.getInsets ();
|
||||
|
||||
w += (num + 1) * hgap + ins.left + ins.right;
|
||||
h += 2 * vgap + ins.top + ins.bottom;
|
||||
|
||||
return new Dimension (w, h);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @serial The justification alignment of the lines of components, which
|
||||
* will be one of the constants defined in this class.
|
||||
*/
|
||||
private int align;
|
||||
|
||||
/**
|
||||
* @serial The horizontal gap between components.
|
||||
*/
|
||||
private int hgap;
|
||||
|
||||
/**
|
||||
* @serial The vertical gap between lines of components.
|
||||
*/
|
||||
private int vgap;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/* FocusTraversalPolicy.java --
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class FocusTraversalPolicy
|
||||
{
|
||||
/**
|
||||
* Creates a <code>FocusTraversalPolicy</code> object.
|
||||
*/
|
||||
public FocusTraversalPolicy()
|
||||
{
|
||||
// Do nothing in here.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Component that should receive the focus after a Component.
|
||||
*
|
||||
* @exception IllegalArgumentException If root or current is null,
|
||||
* or if root is not a focus cycle root of current.
|
||||
*/
|
||||
public abstract Component getComponentAfter(Container root,
|
||||
Component current);
|
||||
|
||||
/**
|
||||
* Returns the Component that should receive the focus before a Component.
|
||||
*
|
||||
* @exception IllegalArgumentException If root or current is null,
|
||||
* or if root is not a focus cycle root of current.
|
||||
*/
|
||||
public abstract Component getComponentBefore(Container root,
|
||||
Component current);
|
||||
|
||||
/**
|
||||
* Returns the first Component in the traversal cycle.
|
||||
*
|
||||
* @exception IllegalArgumentException If root is null.
|
||||
*/
|
||||
public abstract Component getFirstComponent(Container root);
|
||||
|
||||
/**
|
||||
* Returns the last Component in the traversal cycle.
|
||||
*
|
||||
* @exception IllegalArgumentException If root is null.
|
||||
*/
|
||||
public abstract Component getLastComponent(Container root);
|
||||
|
||||
/**
|
||||
* Returns the default Component to focus.
|
||||
*
|
||||
* @exception IllegalArgumentException If root is null.
|
||||
*/
|
||||
public abstract Component getDefaultComponent(Container root);
|
||||
|
||||
/**
|
||||
* Returns the Component that should receive the focus when a Window is made
|
||||
* visible for the first time.
|
||||
*
|
||||
* @exception IllegalArgumentException If window is null.
|
||||
*/
|
||||
public Component getInitialComponent(Window window)
|
||||
{
|
||||
return getDefaultComponent(window);
|
||||
}
|
||||
} // class FocusTraversalPolicy
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,65 @@
|
||||
/* FontFormatException.java -- the specified font is bad
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* Thrown when a specified font is bad.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Font
|
||||
* @since 1.3
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class FontFormatException extends Exception
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.4+.
|
||||
*/
|
||||
private static final long serialVersionUID = -4481290147811361272L;
|
||||
|
||||
/**
|
||||
* Create a new instance with the specified detailed error message.
|
||||
*
|
||||
* @param message the detailed error message
|
||||
*/
|
||||
public FontFormatException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
} // class FontFormatException
|
||||
@@ -0,0 +1,425 @@
|
||||
/* FontMetrics.java -- Information about about a fonts display characteristics
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.text.CharacterIterator;
|
||||
|
||||
// FIXME: I leave many methods basically unimplemented. This
|
||||
// should be reviewed.
|
||||
|
||||
/**
|
||||
* This class returns information about the display characteristics of
|
||||
* a font. It is abstract, and concrete subclasses should implement at
|
||||
* least the following methods:
|
||||
*
|
||||
* <ul>
|
||||
* <li>getAscent()</li>
|
||||
* <li>getDescent()</li>
|
||||
* <li>getLeading()</li>
|
||||
* <li>getMaxAdvance()</li>
|
||||
* <li>charWidth(char)</li>
|
||||
* <li>charsWidth(char[], int, int)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public abstract class FontMetrics implements java.io.Serializable
|
||||
{
|
||||
// Serialization constant.
|
||||
private static final long serialVersionUID = 1681126225205050147L;
|
||||
|
||||
/**
|
||||
* This is the font for which metrics will be returned.
|
||||
*/
|
||||
protected Font font;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>FontMetrics</code> for the
|
||||
* specified font.
|
||||
*
|
||||
* @param font The font to return metric information for.
|
||||
*/
|
||||
protected FontMetrics(Font font)
|
||||
{
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the font that this object is creating metric information fo.
|
||||
*
|
||||
* @return The font for this object.
|
||||
*/
|
||||
public Font getFont()
|
||||
{
|
||||
return font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the leading, or spacing between lines, for this font.
|
||||
*
|
||||
* @return The font leading.
|
||||
*/
|
||||
public int getLeading()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ascent of the font, which is the distance from the base
|
||||
* to the top of the majority of characters in the set. Some characters
|
||||
* can exceed this value however.
|
||||
*
|
||||
* @return The font ascent.
|
||||
*/
|
||||
public int getAscent()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the descent of the font, which is the distance from the base
|
||||
* to the bottom of the majority of characters in the set. Some characters
|
||||
* can exceed this value however.
|
||||
*
|
||||
* @return The font descent.
|
||||
*/
|
||||
public int getDescent()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the height of a line in this font. This will be the sum
|
||||
* of the leading, the ascent, and the descent.
|
||||
*
|
||||
* @return The height of the font.
|
||||
*/
|
||||
public int getHeight()
|
||||
{
|
||||
return getAscent() + getDescent() + getLeading();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum ascent value. This is the maximum distance any
|
||||
* character in the font rised above the baseline.
|
||||
*
|
||||
* @return The maximum ascent for this font.
|
||||
*/
|
||||
public int getMaxAscent()
|
||||
{
|
||||
return getAscent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum descent value. This is the maximum distance any
|
||||
* character in the font extends below the baseline.
|
||||
*
|
||||
* @return The maximum descent for this font.
|
||||
*/
|
||||
public int getMaxDescent()
|
||||
{
|
||||
return getMaxDecent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum descent value. This is the maximum distance any
|
||||
* character in the font extends below the baseline.
|
||||
*
|
||||
* @return The maximum descent for this font.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getMaxDescent()</code>.
|
||||
*/
|
||||
public int getMaxDecent()
|
||||
{
|
||||
return getDescent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the widest character in the font.
|
||||
*
|
||||
* @return The width of the widest character in the font.
|
||||
*/
|
||||
public int getMaxAdvance()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the specified character.
|
||||
*
|
||||
* @param ch The character to return the width of.
|
||||
*
|
||||
* @return The width of the specified character.
|
||||
*/
|
||||
public int charWidth(int ch)
|
||||
{
|
||||
return charWidth((char) ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the specified character.
|
||||
*
|
||||
* @param ch The character to return the width of.
|
||||
*
|
||||
* @return The width of the specified character.
|
||||
*/
|
||||
public int charWidth(char ch)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total width of the specified string
|
||||
*
|
||||
* @param str The string to return the width of.
|
||||
*
|
||||
* @return The width of the string.
|
||||
*/
|
||||
public int stringWidth(String str)
|
||||
{
|
||||
char[] buf = new char[str.length()];
|
||||
str.getChars(0, str.length(), buf, 0);
|
||||
|
||||
return charsWidth(buf, 0, buf.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total width of the specified character array.
|
||||
*
|
||||
* @param buf The character array containing the data.
|
||||
* @param offset The offset into the array to start calculating from.
|
||||
* @param len The total number of bytes to process.
|
||||
*
|
||||
* @return The width of the requested characters.
|
||||
*/
|
||||
public int charsWidth(char[] buf, int offset, int len)
|
||||
{
|
||||
int total_width = 0;
|
||||
for (int i = offset; i < len; i++)
|
||||
total_width += charWidth(buf[i]);
|
||||
return total_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total width of the specified byte array.
|
||||
*
|
||||
* @param buf The byte array containing the data.
|
||||
* @param offset The offset into the array to start calculating from.
|
||||
* @param len The total number of bytes to process.
|
||||
*
|
||||
* @return The width of the requested characters.
|
||||
*/
|
||||
public int bytesWidth(byte[] buf, int offset, int len)
|
||||
{
|
||||
int total_width = 0;
|
||||
for (int i = offset; i < len; i++)
|
||||
total_width = charWidth((char) buf[i]);
|
||||
|
||||
return total_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the widths of the first 256 characters in the font.
|
||||
*
|
||||
* @return The widths of the first 256 characters in the font.
|
||||
*/
|
||||
public int[] getWidths()
|
||||
{
|
||||
int[] result = new int[256];
|
||||
for (char i = 0; i < 256; i++)
|
||||
result[i] = charWidth(i);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*
|
||||
* @return A string representation of this object.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return (this.getClass() + "[font=" + font + ",ascent=" + getAscent()
|
||||
+ ",descent=" + getDescent() + ",height=" + getHeight() + "]");
|
||||
}
|
||||
|
||||
// Generic FontRenderContext used when getLineMetrics is called with a
|
||||
// plain Graphics object.
|
||||
private static final FontRenderContext gRC = new FontRenderContext(null,
|
||||
false,
|
||||
false);
|
||||
|
||||
/**
|
||||
* Returns a {@link LineMetrics} object constructed with the
|
||||
* specified text and the {@link FontRenderContext} of the Graphics
|
||||
* object when it is an instance of Graphics2D or a generic
|
||||
* FontRenderContext with a null transform, not anti-aliased and not
|
||||
* using fractional metrics.
|
||||
*
|
||||
* @param text The string to calculate metrics from.
|
||||
* @param g The Graphics object that will be used.
|
||||
*
|
||||
* @return A new {@link LineMetrics} object.
|
||||
*/
|
||||
public LineMetrics getLineMetrics(String text, Graphics g)
|
||||
{
|
||||
return getLineMetrics(text, 0, text.length(), g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link LineMetrics} object constructed with the
|
||||
* specified text and the {@link FontRenderContext} of the Graphics
|
||||
* object when it is an instance of Graphics2D or a generic
|
||||
* FontRenderContext with a null transform, not anti-aliased and not
|
||||
* using fractional metrics.
|
||||
*
|
||||
* @param text The string to calculate metrics from.
|
||||
* @param begin Index of first character in <code>text</code> to measure.
|
||||
* @param limit Index of last character in <code>text</code> to measure.
|
||||
* @param g The Graphics object that will be used.
|
||||
*
|
||||
* @return A new {@link LineMetrics} object.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException if the range [begin, limit] is
|
||||
* invalid in <code>text</code>.
|
||||
*/
|
||||
public LineMetrics getLineMetrics(String text, int begin, int limit,
|
||||
Graphics g)
|
||||
{
|
||||
FontRenderContext rc;
|
||||
if (g instanceof Graphics2D)
|
||||
rc = ((Graphics2D) g).getFontRenderContext();
|
||||
else
|
||||
rc = gRC;
|
||||
return font.getLineMetrics(text, begin, limit, rc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link LineMetrics} object constructed with the
|
||||
* specified text and the {@link FontRenderContext} of the Graphics
|
||||
* object when it is an instance of Graphics2D or a generic
|
||||
* FontRenderContext with a null transform, not anti-aliased and not
|
||||
* using fractional metrics.
|
||||
*
|
||||
* @param chars The string to calculate metrics from.
|
||||
* @param begin Index of first character in <code>text</code> to measure.
|
||||
* @param limit Index of last character in <code>text</code> to measure.
|
||||
* @param g The Graphics object that will be used.
|
||||
*
|
||||
* @return A new {@link LineMetrics} object.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException if the range [begin, limit] is
|
||||
* invalid in <code>text</code>.
|
||||
*/
|
||||
public LineMetrics getLineMetrics(char[] chars, int begin, int limit,
|
||||
Graphics g)
|
||||
{
|
||||
FontRenderContext rc;
|
||||
if (g instanceof Graphics2D)
|
||||
rc = ((Graphics2D) g).getFontRenderContext();
|
||||
else
|
||||
rc = gRC;
|
||||
return font.getLineMetrics(chars, begin, limit, rc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link LineMetrics} object constructed with the
|
||||
* specified text and the {@link FontRenderContext} of the Graphics
|
||||
* object when it is an instance of Graphics2D or a generic
|
||||
* FontRenderContext with a null transform, not anti-aliased and not
|
||||
* using fractional metrics.
|
||||
*
|
||||
* @param ci An iterator over the string to calculate metrics from.
|
||||
* @param begin Index of first character in <code>text</code> to measure.
|
||||
* @param limit Index of last character in <code>text</code> to measure.
|
||||
* @param g The Graphics object that will be used.
|
||||
*
|
||||
* @return A new {@link LineMetrics} object.
|
||||
*
|
||||
* @throws IndexOutOfBoundsException if the range [begin, limit] is
|
||||
* invalid in <code>text</code>.
|
||||
*/
|
||||
public LineMetrics getLineMetrics(CharacterIterator ci, int begin,
|
||||
int limit, Graphics g)
|
||||
{
|
||||
FontRenderContext rc;
|
||||
if (g instanceof Graphics2D)
|
||||
rc = ((Graphics2D) g).getFontRenderContext();
|
||||
else
|
||||
rc = gRC;
|
||||
return font.getLineMetrics(ci, begin, limit, rc);
|
||||
}
|
||||
|
||||
public Rectangle2D getStringBounds(String str, Graphics context)
|
||||
{
|
||||
return font.getStringBounds(str, getFontRenderContext(context));
|
||||
}
|
||||
|
||||
public Rectangle2D getStringBounds(String str, int beginIndex, int limit,
|
||||
Graphics context)
|
||||
{
|
||||
return font.getStringBounds(str, beginIndex, limit,
|
||||
getFontRenderContext(context));
|
||||
}
|
||||
|
||||
public Rectangle2D getStringBounds(char[] chars, int beginIndex, int limit,
|
||||
Graphics context)
|
||||
{
|
||||
return font.getStringBounds(chars, beginIndex, limit,
|
||||
getFontRenderContext(context));
|
||||
}
|
||||
|
||||
public Rectangle2D getStringBounds(CharacterIterator ci, int beginIndex,
|
||||
int limit, Graphics context)
|
||||
{
|
||||
return font.getStringBounds(ci, beginIndex, limit,
|
||||
getFontRenderContext(context));
|
||||
}
|
||||
|
||||
private FontRenderContext getFontRenderContext(Graphics context)
|
||||
{
|
||||
if (context instanceof Graphics2D)
|
||||
return ((Graphics2D) context).getFontRenderContext();
|
||||
|
||||
return gRC;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,649 @@
|
||||
/* Frame.java -- AWT toplevel window
|
||||
Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.peer.FramePeer;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
import javax.accessibility.AccessibleState;
|
||||
import javax.accessibility.AccessibleStateSet;
|
||||
|
||||
/**
|
||||
* This class is a top-level window with a title bar and window
|
||||
* decorations.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class Frame extends Window implements MenuContainer
|
||||
{
|
||||
/**
|
||||
* Constant for the default cursor.
|
||||
* @deprecated Replaced by <code>Cursor.DEFAULT_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int DEFAULT_CURSOR = Cursor.DEFAULT_CURSOR;
|
||||
|
||||
/**
|
||||
* Constant for a cross-hair cursor.
|
||||
* @deprecated Use <code>Cursor.CROSSHAIR_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int CROSSHAIR_CURSOR = Cursor.CROSSHAIR_CURSOR;
|
||||
|
||||
/**
|
||||
* Constant for a cursor over a text field.
|
||||
* @deprecated Use <code>Cursor.TEXT_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int TEXT_CURSOR = Cursor.TEXT_CURSOR;
|
||||
|
||||
/**
|
||||
* Constant for a cursor to display while waiting for an action to complete.
|
||||
* @deprecated Use <code>Cursor.WAIT_CURSOR</code>.
|
||||
*/
|
||||
public static final int WAIT_CURSOR = Cursor.WAIT_CURSOR;
|
||||
|
||||
/**
|
||||
* Cursor used over SW corner of window decorations.
|
||||
* @deprecated Use <code>Cursor.SW_RESIZE_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int SW_RESIZE_CURSOR = Cursor.SW_RESIZE_CURSOR;
|
||||
|
||||
/**
|
||||
* Cursor used over SE corner of window decorations.
|
||||
* @deprecated Use <code>Cursor.SE_RESIZE_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int SE_RESIZE_CURSOR = Cursor.SE_RESIZE_CURSOR;
|
||||
|
||||
/**
|
||||
* Cursor used over NW corner of window decorations.
|
||||
* @deprecated Use <code>Cursor.NW_RESIZE_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int NW_RESIZE_CURSOR = Cursor.NW_RESIZE_CURSOR;
|
||||
|
||||
/**
|
||||
* Cursor used over NE corner of window decorations.
|
||||
* @deprecated Use <code>Cursor.NE_RESIZE_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int NE_RESIZE_CURSOR = Cursor.NE_RESIZE_CURSOR;
|
||||
|
||||
/**
|
||||
* Cursor used over N edge of window decorations.
|
||||
* @deprecated Use <code>Cursor.N_RESIZE_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int N_RESIZE_CURSOR = Cursor.N_RESIZE_CURSOR;
|
||||
|
||||
/**
|
||||
* Cursor used over S edge of window decorations.
|
||||
* @deprecated Use <code>Cursor.S_RESIZE_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int S_RESIZE_CURSOR = Cursor.S_RESIZE_CURSOR;
|
||||
|
||||
/**
|
||||
* Cursor used over E edge of window decorations.
|
||||
* @deprecated Use <code>Cursor.E_RESIZE_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int E_RESIZE_CURSOR = Cursor.E_RESIZE_CURSOR;
|
||||
|
||||
/**
|
||||
* Cursor used over W edge of window decorations.
|
||||
* @deprecated Use <code>Cursor.W_RESIZE_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int W_RESIZE_CURSOR = Cursor.W_RESIZE_CURSOR;
|
||||
|
||||
/**
|
||||
* Constant for a hand cursor.
|
||||
* @deprecated Use <code>Cursor.HAND_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int HAND_CURSOR = Cursor.HAND_CURSOR;
|
||||
|
||||
/**
|
||||
* Constant for a cursor used during window move operations.
|
||||
* @deprecated Use <code>Cursor.MOVE_CURSOR</code> instead.
|
||||
*/
|
||||
public static final int MOVE_CURSOR = Cursor.MOVE_CURSOR;
|
||||
|
||||
public static final int ICONIFIED = 1;
|
||||
public static final int MAXIMIZED_BOTH = 6;
|
||||
public static final int MAXIMIZED_HORIZ = 2;
|
||||
public static final int MAXIMIZED_VERT = 4;
|
||||
public static final int NORMAL = 0;
|
||||
|
||||
// Serialization version constant
|
||||
private static final long serialVersionUID = 2673458971256075116L;
|
||||
|
||||
/**
|
||||
* @serial The version of the class data being serialized
|
||||
* // FIXME: what is this value?
|
||||
*/
|
||||
private int frameSerializedDataVersion;
|
||||
|
||||
/**
|
||||
* @serial Image used as the icon when this frame is minimized.
|
||||
*/
|
||||
private Image icon;
|
||||
|
||||
/**
|
||||
* @serial Constant used by the JDK Motif peer set. Not used in
|
||||
* this implementation.
|
||||
*/
|
||||
private boolean mbManagement;
|
||||
|
||||
/**
|
||||
* @serial The menu bar for this frame.
|
||||
*/
|
||||
//private MenuBar menuBar = new MenuBar();
|
||||
private MenuBar menuBar;
|
||||
|
||||
/**
|
||||
* @serial A list of other top-level windows owned by this window.
|
||||
*/
|
||||
Vector ownedWindows = new Vector();
|
||||
|
||||
/**
|
||||
* @serial Indicates whether or not this frame is resizable.
|
||||
*/
|
||||
private boolean resizable = true;
|
||||
|
||||
/**
|
||||
* @serial The state of this frame.
|
||||
* // FIXME: What are the values here?
|
||||
* This is package-private to avoid an accessor method.
|
||||
*/
|
||||
int state;
|
||||
|
||||
/**
|
||||
* @serial The title of the frame.
|
||||
*/
|
||||
private String title = "";
|
||||
|
||||
/**
|
||||
* Maximized bounds for this frame.
|
||||
*/
|
||||
private Rectangle maximizedBounds;
|
||||
|
||||
/**
|
||||
* This field indicates whether the frame is undecorated or not.
|
||||
*/
|
||||
private boolean undecorated = false;
|
||||
|
||||
/*
|
||||
* The number used to generate the name returned by getName.
|
||||
*/
|
||||
private static transient long next_frame_number;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Frame</code> that is not visible
|
||||
* and has no title.
|
||||
*/
|
||||
public
|
||||
Frame()
|
||||
{
|
||||
this("");
|
||||
noteFrame(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Frame</code> that is not visible
|
||||
* and has the specified title.
|
||||
*
|
||||
* @param title The title of this frame.
|
||||
*/
|
||||
public
|
||||
Frame(String title)
|
||||
{
|
||||
super();
|
||||
this.title = title;
|
||||
// Top-level frames are initially invisible.
|
||||
visible = false;
|
||||
noteFrame(this);
|
||||
}
|
||||
|
||||
public
|
||||
Frame(GraphicsConfiguration gc)
|
||||
{
|
||||
super(gc);
|
||||
visible = false;
|
||||
noteFrame(this);
|
||||
}
|
||||
|
||||
public
|
||||
Frame(String title, GraphicsConfiguration gc)
|
||||
{
|
||||
super(gc);
|
||||
setTitle(title);
|
||||
visible = false;
|
||||
noteFrame(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this frame's title string.
|
||||
*
|
||||
* @return This frame's title string.
|
||||
*/
|
||||
public String
|
||||
getTitle()
|
||||
{
|
||||
return(title);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets this frame's title to the specified value.
|
||||
*
|
||||
* @param title The new frame title.
|
||||
*/
|
||||
public synchronized void
|
||||
setTitle(String title)
|
||||
{
|
||||
this.title = title;
|
||||
if (peer != null)
|
||||
((FramePeer) peer).setTitle(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this frame's icon.
|
||||
*
|
||||
* @return This frame's icon, or <code>null</code> if this frame does not
|
||||
* have an icon.
|
||||
*/
|
||||
public Image
|
||||
getIconImage()
|
||||
{
|
||||
return(icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this frame's icon to the specified value.
|
||||
*
|
||||
* @icon The new icon for this frame.
|
||||
*/
|
||||
public synchronized void
|
||||
setIconImage(Image icon)
|
||||
{
|
||||
this.icon = icon;
|
||||
if (peer != null)
|
||||
((FramePeer) peer).setIconImage(icon);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this frame's menu bar.
|
||||
*
|
||||
* @return This frame's menu bar, or <code>null</code> if this frame
|
||||
* does not have a menu bar.
|
||||
*/
|
||||
public MenuBar
|
||||
getMenuBar()
|
||||
{
|
||||
return(menuBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this frame's menu bar.
|
||||
*
|
||||
* @param menuBar The new menu bar for this frame.
|
||||
*/
|
||||
public synchronized void
|
||||
setMenuBar(MenuBar menuBar)
|
||||
{
|
||||
if (peer != null)
|
||||
{
|
||||
if (this.menuBar != null)
|
||||
this.menuBar.removeNotify();
|
||||
if (menuBar != null)
|
||||
menuBar.addNotify();
|
||||
invalidateTree ();
|
||||
((FramePeer) peer).setMenuBar(menuBar);
|
||||
}
|
||||
this.menuBar = menuBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not this frame is resizable. This will be
|
||||
* <code>true</code> by default.
|
||||
*
|
||||
* @return <code>true</code> if this frame is resizable, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean
|
||||
isResizable()
|
||||
{
|
||||
return(resizable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the resizability of this frame to the specified value.
|
||||
*
|
||||
* @param resizable <code>true</code> to make the frame resizable,
|
||||
* <code>false</code> to make it non-resizable.
|
||||
*/
|
||||
public synchronized void
|
||||
setResizable(boolean resizable)
|
||||
{
|
||||
this.resizable = resizable;
|
||||
if (peer != null)
|
||||
((FramePeer) peer).setResizable(resizable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cursor type of the cursor for this window. This will
|
||||
* be one of the constants in this class.
|
||||
*
|
||||
* @return The cursor type for this frame.
|
||||
*
|
||||
* @deprecated Use <code>Component.getCursor()</code> instead.
|
||||
*/
|
||||
public int
|
||||
getCursorType()
|
||||
{
|
||||
return(getCursor().getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cursor for this window to the specified type. The specified
|
||||
* type should be one of the constants in this class.
|
||||
*
|
||||
* @param type The cursor type.
|
||||
*
|
||||
* @deprecated Use <code>Component.setCursor(Cursor)</code> instead.
|
||||
*/
|
||||
public void
|
||||
setCursor(int type)
|
||||
{
|
||||
setCursor(new Cursor(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified component from this frame's menu.
|
||||
*
|
||||
* @param menu The menu component to remove.
|
||||
*/
|
||||
public void
|
||||
remove(MenuComponent menu)
|
||||
{
|
||||
menuBar.remove(menu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies this frame that it should create its native peer.
|
||||
*/
|
||||
private static void fireDummyEvent()
|
||||
{
|
||||
EventQueue.invokeLater(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
// Do nothing here.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (menuBar != null)
|
||||
menuBar.addNotify();
|
||||
if (peer == null)
|
||||
peer = getToolkit ().createFrame (this);
|
||||
|
||||
// We now know there's a Frame (us) with a live peer, so we can start the
|
||||
// fundamental queue and dispatch thread, by inserting a dummy event.
|
||||
if (parent != null && parent.isDisplayable())
|
||||
fireDummyEvent();
|
||||
|
||||
super.addNotify();
|
||||
}
|
||||
|
||||
public void removeNotify()
|
||||
{
|
||||
if (menuBar != null)
|
||||
menuBar.removeNotify();
|
||||
super.removeNotify();
|
||||
|
||||
// By now we've been disconnected from the peer, and the peer set to
|
||||
// null. This is formally the same as saying "we just became
|
||||
// un-displayable", so we wake up the event queue with a dummy event to
|
||||
// see if it's time to shut down.
|
||||
fireDummyEvent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debugging string describing this window.
|
||||
*
|
||||
* @return A debugging string describing this window.
|
||||
*/
|
||||
protected String paramString ()
|
||||
{
|
||||
String title = getTitle ();
|
||||
|
||||
String resizable = "";
|
||||
if (isResizable ())
|
||||
resizable = ",resizable";
|
||||
|
||||
String state = "";
|
||||
switch (getState ())
|
||||
{
|
||||
case NORMAL:
|
||||
state = ",normal";
|
||||
break;
|
||||
case ICONIFIED:
|
||||
state = ",iconified";
|
||||
break;
|
||||
case MAXIMIZED_BOTH:
|
||||
state = ",maximized-both";
|
||||
break;
|
||||
case MAXIMIZED_HORIZ:
|
||||
state = ",maximized-horiz";
|
||||
break;
|
||||
case MAXIMIZED_VERT:
|
||||
state = ",maximized-vert";
|
||||
break;
|
||||
}
|
||||
|
||||
return super.paramString () + ",title=" + title + resizable + state;
|
||||
}
|
||||
|
||||
private static ArrayList weakFrames = new ArrayList();
|
||||
|
||||
private static void noteFrame(Frame f)
|
||||
{
|
||||
weakFrames.add(new WeakReference(f));
|
||||
}
|
||||
|
||||
public static Frame[] getFrames()
|
||||
{
|
||||
int n = 0;
|
||||
synchronized (weakFrames)
|
||||
{
|
||||
Iterator i = weakFrames.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
WeakReference wr = (WeakReference) i.next();
|
||||
if (wr.get() != null)
|
||||
++n;
|
||||
}
|
||||
if (n == 0)
|
||||
return new Frame[0];
|
||||
else
|
||||
{
|
||||
Frame[] frames = new Frame[n];
|
||||
n = 0;
|
||||
i = weakFrames.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
WeakReference wr = (WeakReference) i.next();
|
||||
if (wr.get() != null)
|
||||
frames[n++] = (Frame) wr.get();
|
||||
}
|
||||
return frames;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setState (int state)
|
||||
{
|
||||
int current_state = getExtendedState ();
|
||||
|
||||
if (state == NORMAL
|
||||
&& (current_state & ICONIFIED) != 0)
|
||||
setExtendedState (current_state | ICONIFIED);
|
||||
|
||||
if (state == ICONIFIED
|
||||
&& (current_state & ~ICONIFIED) == 0)
|
||||
setExtendedState (current_state & ~ICONIFIED);
|
||||
}
|
||||
|
||||
public int getState ()
|
||||
{
|
||||
/* FIXME: State might have changed in the peer... Must check. */
|
||||
|
||||
return (state & ICONIFIED) != 0 ? ICONIFIED : NORMAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public void setExtendedState (int state)
|
||||
{
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public int getExtendedState ()
|
||||
{
|
||||
return state;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public void setMaximizedBounds (Rectangle maximizedBounds)
|
||||
{
|
||||
this.maximizedBounds = maximizedBounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximized bounds of this frame.
|
||||
*
|
||||
* @return the maximized rectangle, may be null.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public Rectangle getMaximizedBounds ()
|
||||
{
|
||||
return maximizedBounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this frame is undecorated or not.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean isUndecorated ()
|
||||
{
|
||||
return undecorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables or enables decorations for this frame. This method can only be
|
||||
* called while the frame is not displayable.
|
||||
*
|
||||
* @exception IllegalComponentStateException If this frame is displayable.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void setUndecorated (boolean undecorated)
|
||||
{
|
||||
if (isDisplayable ())
|
||||
throw new IllegalComponentStateException ();
|
||||
|
||||
this.undecorated = undecorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique name for this frame.
|
||||
*
|
||||
* @return A unique name for this frame.
|
||||
*/
|
||||
String generateName ()
|
||||
{
|
||||
return "frame" + getUniqueLong ();
|
||||
}
|
||||
|
||||
private static synchronized long getUniqueLong ()
|
||||
{
|
||||
return next_frame_number++;
|
||||
}
|
||||
|
||||
protected class AccessibleAWTFrame extends AccessibleAWTWindow
|
||||
{
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.FRAME;
|
||||
}
|
||||
|
||||
public AccessibleStateSet getAccessibleState()
|
||||
{
|
||||
AccessibleStateSet states = super.getAccessibleStateSet();
|
||||
if (isResizable())
|
||||
states.add(AccessibleState.RESIZABLE);
|
||||
if ((state & ICONIFIED) != 0)
|
||||
states.add(AccessibleState.ICONIFIED);
|
||||
return states;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>Frame</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTFrame();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
/* GradientPaint.java --
|
||||
Copyright (C) 2002, 2005, Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ColorModel;
|
||||
import gnu.java.awt.GradientPaintContext;
|
||||
|
||||
/**
|
||||
* A paint object that can be used to color a region by blending two colors.
|
||||
* Instances of this class are immutable.
|
||||
*/
|
||||
public class GradientPaint implements Paint
|
||||
{
|
||||
private final float x1;
|
||||
private final float y1;
|
||||
private final Color c1;
|
||||
private final float x2;
|
||||
private final float y2;
|
||||
private final Color c2;
|
||||
private final boolean cyclic;
|
||||
|
||||
/**
|
||||
* Creates a new acyclic <code>GradientPaint</code>.
|
||||
*
|
||||
* @param x1 the x-coordinate of the anchor point for color 1.
|
||||
* @param y1 the y-coordinate of the anchor point for color 1.
|
||||
* @param c1 color 1 (<code>null</code> not permitted).
|
||||
* @param x2 the x-coordinate of the anchor point for color 2.
|
||||
* @param y2 the y-coordinate of the anchor point for color 2.
|
||||
* @param c2 the second color (<code>null</code> not permitted).
|
||||
*/
|
||||
public GradientPaint(float x1, float y1, Color c1,
|
||||
float x2, float y2, Color c2)
|
||||
{
|
||||
this(x1, y1, c1, x2, y2, c2, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new acyclic <code>GradientPaint</code>.
|
||||
*
|
||||
* @param p1 anchor point 1 (<code>null</code> not permitted).
|
||||
* @param c1 color 1 (<code>null</code> not permitted).
|
||||
* @param p2 anchor point 2 (<code>null</code> not permitted).
|
||||
* @param c2 color 2 (<code>null</code> not permitted).
|
||||
*/
|
||||
public GradientPaint(Point2D p1, Color c1, Point2D p2, Color c2)
|
||||
{
|
||||
this((float) p1.getX(), (float) p1.getY(), c1,
|
||||
(float) p2.getX(), (float) p2.getY(), c2, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new cyclic or acyclic <code>GradientPaint</code>.
|
||||
*
|
||||
* @param x1 the x-coordinate of the anchor point for color 1.
|
||||
* @param y1 the y-coordinate of the anchor point for color 1.
|
||||
* @param c1 color 1 (<code>null</code> not permitted).
|
||||
* @param x2 the x-coordinate of the anchor point for color 2.
|
||||
* @param y2 the y-coordinate of the anchor point for color 2.
|
||||
* @param c2 the second color (<code>null</code> not permitted).
|
||||
* @param cyclic a flag that controls whether the gradient is cyclic or
|
||||
* acyclic.
|
||||
*/
|
||||
public GradientPaint(float x1, float y1, Color c1,
|
||||
float x2, float y2, Color c2, boolean cyclic)
|
||||
{
|
||||
if (c1 == null || c2 == null)
|
||||
throw new NullPointerException();
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.c1 = c1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
this.c2 = c2;
|
||||
this.cyclic = cyclic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new cyclic or acyclic <code>GradientPaint</code>.
|
||||
*
|
||||
* @param p1 anchor point 1 (<code>null</code> not permitted).
|
||||
* @param c1 color 1 (<code>null</code> not permitted).
|
||||
* @param p2 anchor point 2 (<code>null</code> not permitted).
|
||||
* @param c2 color 2 (<code>null</code> not permitted).
|
||||
* @param cyclic a flag that controls whether the gradient is cyclic or
|
||||
* acyclic.
|
||||
*/
|
||||
public GradientPaint(Point2D p1, Color c1, Point2D p2, Color c2,
|
||||
boolean cyclic)
|
||||
{
|
||||
this((float) p1.getX(), (float) p1.getY(), c1,
|
||||
(float) p2.getX(), (float) p2.getY(), c2, cyclic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point with the same coordinates as the anchor point for color 1.
|
||||
* Note that if you modify this point, the <code>GradientPaint</code> remains
|
||||
* unchanged.
|
||||
*
|
||||
* @return A point with the same coordinates as the anchor point for color 1.
|
||||
*/
|
||||
public Point2D getPoint1()
|
||||
{
|
||||
return new Point2D.Float(x1, y1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first color.
|
||||
*
|
||||
* @return The color (never <code>null</code>).
|
||||
*/
|
||||
public Color getColor1()
|
||||
{
|
||||
return c1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a point with the same coordinates as the anchor point for color 2.
|
||||
* Note that if you modify this point, the <code>GradientPaint</code> remains
|
||||
* unchanged.
|
||||
*
|
||||
* @return A point with the same coordinates as the anchor point for color 2.
|
||||
*/
|
||||
public Point2D getPoint2()
|
||||
{
|
||||
return new Point2D.Float(x2, y2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the second color.
|
||||
*
|
||||
* @return The color (never <code>null</code>).
|
||||
*/
|
||||
public Color getColor2()
|
||||
{
|
||||
return c2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if this <code>GradientPaint</code> instance is
|
||||
* cyclic, and <code>false</code> otherwise.
|
||||
*
|
||||
* @return A boolean.
|
||||
*/
|
||||
public boolean isCyclic()
|
||||
{
|
||||
return cyclic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link PaintContext} used to generate the color pattern.
|
||||
*
|
||||
* @param cm the color model, used as a hint (ignored in this
|
||||
* implementation).
|
||||
* @param deviceBounds the device space bounding box of the painted area.
|
||||
* @param userBounds the user space bounding box of the painted area.
|
||||
* @param xform the transformation from user space to device space.
|
||||
* @param hints any hints for choosing between rendering alternatives.
|
||||
*
|
||||
* @return The context for performing the paint
|
||||
*/
|
||||
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
|
||||
Rectangle2D userBounds,
|
||||
AffineTransform xform,
|
||||
RenderingHints hints)
|
||||
{
|
||||
Point2D xp1 = xform.transform(getPoint1(), null);
|
||||
Point2D xp2 = xform.transform(getPoint2(), null);
|
||||
return new GradientPaintContext((float) xp1.getX(), (float) xp1.getY(), c1,
|
||||
(float) xp2.getX(), (float) xp2.getY(), c2, cyclic);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the transparency code for this <code>GradientPaint</code> instance.
|
||||
* This is derived from the two {@link Color} objects used in creating this
|
||||
* object: if both colors are opaque, this method returns
|
||||
* {@link Transparency#OPAQUE}, otherwise it returns
|
||||
* {@link Transparency#TRANSLUCENT}.
|
||||
*
|
||||
* @return {@link Transparency#OPAQUE} or {@link Transparency#TRANSLUCENT}.
|
||||
*/
|
||||
public int getTransparency()
|
||||
{
|
||||
if (c1.getAlpha() == 255 && c2.getAlpha() == 255)
|
||||
return Transparency.OPAQUE;
|
||||
else
|
||||
return Transparency.TRANSLUCENT;
|
||||
}
|
||||
|
||||
} // class GradientPaint
|
||||
@@ -0,0 +1,767 @@
|
||||
/* Graphics.java -- Abstract Java drawing class
|
||||
Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
|
||||
/**
|
||||
* This is the abstract superclass of classes for drawing to graphics
|
||||
* devices such as the screen or printers.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Warren Levy (warrenl@cygnus.com)
|
||||
*/
|
||||
public abstract class Graphics
|
||||
{
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default constructor for subclasses.
|
||||
*/
|
||||
protected
|
||||
Graphics()
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a copy of this <code>Graphics</code> object.
|
||||
*
|
||||
* @return A copy of this object.
|
||||
*/
|
||||
public abstract Graphics
|
||||
create();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a copy of this <code>Graphics</code> object. The origin point
|
||||
* will be translated to the point (x, y) and the cliping rectangle set
|
||||
* to the intersection of the clipping rectangle in this object and the
|
||||
* rectangle specified by the parameters to this method.
|
||||
*
|
||||
* @param x The new X coordinate of the clipping region rect.
|
||||
* @param y The new Y coordinate of the clipping region rect.
|
||||
* @param width The width of the clipping region intersect rectangle.
|
||||
* @param height The height of the clipping region intersect rectangle.
|
||||
*
|
||||
* @return A copy of this object, modified as specified.
|
||||
*/
|
||||
public Graphics
|
||||
create(int x, int y, int width, int height)
|
||||
{
|
||||
Graphics g = create();
|
||||
|
||||
g.translate(x, y);
|
||||
// FIXME: I'm not sure if this will work. Are the old clip rect bounds
|
||||
// translated above?
|
||||
g.clipRect(0, 0, width, height);
|
||||
|
||||
return(g);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Translates this context so that its new origin point is the point
|
||||
* (x, y).
|
||||
*
|
||||
* @param x The new X coordinate of the origin.
|
||||
* @param y The new Y coordinate of the origin.
|
||||
*/
|
||||
public abstract void
|
||||
translate(int x, int y);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the current color for this object.
|
||||
*
|
||||
* @return The color for this object.
|
||||
*/
|
||||
public abstract Color
|
||||
getColor();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the current color for this object.
|
||||
*
|
||||
* @param color The new color.
|
||||
*/
|
||||
public abstract void
|
||||
setColor(Color color);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets this context into "paint" mode, where the target pixels are
|
||||
* completely overwritten when drawn on.
|
||||
*/
|
||||
public abstract void
|
||||
setPaintMode();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets this context info "XOR" mode, where the targe pixles are
|
||||
* XOR-ed when drawn on.
|
||||
*
|
||||
* @param color The color to XOR against.
|
||||
*/
|
||||
public abstract void
|
||||
setXORMode(Color color);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the current font for this graphics context.
|
||||
*
|
||||
* @return The current font.
|
||||
*/
|
||||
public abstract Font
|
||||
getFont();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the font for this graphics context to the specified value.
|
||||
*
|
||||
* @param font The new font.
|
||||
*/
|
||||
public abstract void
|
||||
setFont(Font font);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the font metrics for the current font.
|
||||
*
|
||||
* @return The font metrics for the current font.
|
||||
*/
|
||||
public FontMetrics
|
||||
getFontMetrics()
|
||||
{
|
||||
return(getFontMetrics(getFont()));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the font metrics for the specified font.
|
||||
*
|
||||
* @param font The font to return metrics for.
|
||||
*
|
||||
* @return The requested font metrics.
|
||||
*/
|
||||
public abstract FontMetrics
|
||||
getFontMetrics(Font font);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the bounding rectangle of the clipping region for this
|
||||
* graphics context.
|
||||
*
|
||||
* @return The bounding rectangle for the clipping region.
|
||||
*/
|
||||
public abstract Rectangle
|
||||
getClipBounds();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the bounding rectangle of the clipping region for this
|
||||
* graphics context.
|
||||
*
|
||||
* @return The bounding rectangle for the clipping region.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getClipBounds()</code>.
|
||||
*/
|
||||
public Rectangle
|
||||
getClipRect()
|
||||
{
|
||||
return(getClipBounds());
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the clipping region to the intersection of the current clipping
|
||||
* region and the rectangle determined by the specified parameters.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the intersect rect.
|
||||
* @param y The Y coordinate of the upper left corner of the intersect rect.
|
||||
* @param width The width of the intersect rect.
|
||||
* @param height The height of the intersect rect.
|
||||
*/
|
||||
public abstract void
|
||||
clipRect(int x, int y, int width, int height);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the clipping region to the rectangle determined by the specified
|
||||
* parameters.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the rect.
|
||||
* @param y The Y coordinate of the upper left corner of the rect.
|
||||
* @param width The width of the rect.
|
||||
* @param height The height of the rect.
|
||||
*/
|
||||
public abstract void
|
||||
setClip(int x, int y, int width, int height);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the current clipping region as a <code>Shape</code> object.
|
||||
*
|
||||
* @return The clipping region as a <code>Shape</code>.
|
||||
*/
|
||||
public abstract Shape
|
||||
getClip();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the clipping region to the specified <code>Shape</code>.
|
||||
*
|
||||
* @param clip The new clipping region.
|
||||
*/
|
||||
public abstract void
|
||||
setClip(Shape clip);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Copies the specified rectangle to the specified offset location.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the copy rect.
|
||||
* @param y The Y coordinate of the upper left corner of the copy rect.
|
||||
* @param width The width of the copy rect.
|
||||
* @param height The height of the copy rect.
|
||||
* @param dx The offset from the X value to start drawing.
|
||||
* @param dy The offset from the Y value to start drawing.
|
||||
*/
|
||||
public abstract void
|
||||
copyArea(int x, int y, int width, int height, int dx, int dy);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws a line between the two specified points.
|
||||
*
|
||||
* @param x1 The X coordinate of the first point.
|
||||
* @param y1 The Y coordinate of the first point.
|
||||
* @param x2 The X coordinate of the second point.
|
||||
* @param y2 The Y coordinate of the second point.
|
||||
*/
|
||||
public abstract void
|
||||
drawLine(int x1, int y1, int x2, int y2);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Fills the area bounded by the specified rectangle.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the fill rect.
|
||||
* @param y The Y coordinate of the upper left corner of the fill rect.
|
||||
* @param width The width of the fill rect.
|
||||
* @param height The height of the fill rect.
|
||||
*/
|
||||
public abstract void
|
||||
fillRect(int x, int y, int width, int height);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws the outline of the specified rectangle.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the draw rect.
|
||||
* @param y The Y coordinate of the upper left corner of the draw rect.
|
||||
* @param width The width of the draw rect.
|
||||
* @param height The height of the draw rect.
|
||||
*/
|
||||
public void
|
||||
drawRect(int x, int y, int width, int height)
|
||||
{
|
||||
int x1 = x;
|
||||
int y1 = y;
|
||||
int x2 = x + width;
|
||||
int y2 = y + height;
|
||||
drawLine(x1, y1, x2, y1);
|
||||
drawLine(x2, y1, x2, y2);
|
||||
drawLine(x2, y2, x1, y2);
|
||||
drawLine(x1, y2, x1, y1);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Clears the specified rectangle.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the clear rect.
|
||||
* @param y The Y coordinate of the upper left corner of the clear rect.
|
||||
* @param width The width of the clear rect.
|
||||
* @param height The height of the clear rect.
|
||||
*/
|
||||
public abstract void
|
||||
clearRect(int x, int y, int width, int height);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws the outline of the specified rectangle with rounded cornders.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the draw rect.
|
||||
* @param y The Y coordinate of the upper left corner of the draw rect.
|
||||
* @param width The width of the draw rect.
|
||||
* @param height The height of the draw rect.
|
||||
* @param arcWidth The width of the corner arcs.
|
||||
* @param arcHeight The height of the corner arcs.
|
||||
*/
|
||||
public abstract void
|
||||
drawRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Fills the specified rectangle with rounded cornders.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the fill rect.
|
||||
* @param y The Y coordinate of the upper left corner of the fill rect.
|
||||
* @param width The width of the fill rect.
|
||||
* @param height The height of the fill rect.
|
||||
* @param arcWidth The width of the corner arcs.
|
||||
* @param arcHeight The height of the corner arcs.
|
||||
*/
|
||||
public abstract void
|
||||
fillRoundRect(int x, int y, int width, int height, int arcWidth, int arcHeight);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
public void
|
||||
draw3DRect(int x, int y, int width, int height, boolean raised)
|
||||
{
|
||||
Color color = getColor();
|
||||
Color tl = color.brighter();
|
||||
Color br = color.darker();
|
||||
|
||||
if (!raised)
|
||||
{
|
||||
Color tmp = tl;
|
||||
tl = br;
|
||||
br = tmp;
|
||||
}
|
||||
|
||||
int x1 = x;
|
||||
int y1 = y;
|
||||
int x2 = x + width;
|
||||
int y2 = y + height;
|
||||
|
||||
setColor(tl);
|
||||
drawLine(x1, y1, x2, y1);
|
||||
drawLine(x1, y2, x1, y1);
|
||||
setColor(br);
|
||||
drawLine(x2, y1, x2, y2);
|
||||
drawLine(x2, y2, x1, y2);
|
||||
setColor(color);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the specified rectangle with a 3D effect
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the fill rect.
|
||||
* @param y The Y coordinate of the upper left corner of the fill rect.
|
||||
* @param width The width of the fill rect.
|
||||
* @param height The height of the fill rect.
|
||||
* @param raised <code>true</code> if the rectangle appears raised,
|
||||
* <code>false</code> if it should appear etched.
|
||||
*/
|
||||
public void
|
||||
fill3DRect(int x, int y, int width, int height, boolean raised)
|
||||
{
|
||||
fillRect(x, y, width, height);
|
||||
draw3DRect(x, y, width-1, height-1, raised);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws an oval that just fits within the specified rectangle.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the rect.
|
||||
* @param y The Y coordinate of the upper left corner of the rect.
|
||||
* @param width The width of the rect.
|
||||
* @param height The height of the rect.
|
||||
*/
|
||||
public abstract void
|
||||
drawOval(int x, int y, int width, int height);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Fills an oval that just fits within the specified rectangle.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the rect.
|
||||
* @param y The Y coordinate of the upper left corner of the rect.
|
||||
* @param width The width of the rect.
|
||||
* @param height The height of the rect.
|
||||
*/
|
||||
public abstract void
|
||||
fillOval(int x, int y, int width, int height);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws an arc using the specified bounding rectangle and the specified
|
||||
* angle parameter. The arc is centered at the center of the rectangle.
|
||||
* The arc starts at the arcAngle position and extend for arcAngle
|
||||
* degrees. The degree origin is at the 3 o'clock position.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the rect.
|
||||
* @param y The Y coordinate of the upper left corner of the rect.
|
||||
* @param width The width of the rect.
|
||||
* @param height The height of the rect.
|
||||
* @param arcStart The beginning angle of the arc.
|
||||
* @param arcAngle The extent of the arc.
|
||||
*/
|
||||
public abstract void
|
||||
drawArc(int x, int y, int width, int height, int arcStart, int arcAngle);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Fills the arc define by the specified bounding rectangle and the specified
|
||||
* angle parameter. The arc is centered at the center of the rectangle.
|
||||
* The arc starts at the arcAngle position and extend for arcAngle
|
||||
* degrees. The degree origin is at the 3 o'clock position.
|
||||
*
|
||||
* @param x The X coordinate of the upper left corner of the rect.
|
||||
* @param y The Y coordinate of the upper left corner of the rect.
|
||||
* @param width The width of the rect.
|
||||
* @param height The height of the rect.
|
||||
* @param arcStart The beginning angle of the arc.
|
||||
* @param arcAngle The extent of the arc.
|
||||
*/
|
||||
public abstract void
|
||||
fillArc(int x, int y, int width, int height, int arcStart, int arcAngle);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws a series of interconnected lines determined by the arrays
|
||||
* of corresponding x and y coordinates.
|
||||
*
|
||||
* @param xPoints The X coordinate array.
|
||||
* @param yPoints The Y coordinate array.
|
||||
* @param npoints The number of points to draw.
|
||||
*/
|
||||
public abstract void
|
||||
drawPolyline(int xPoints[], int yPoints[], int npoints);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws a series of interconnected lines determined by the arrays
|
||||
* of corresponding x and y coordinates. The figure is closed if necessary
|
||||
* by connecting the first and last points.
|
||||
*
|
||||
* @param xPoints The X coordinate array.
|
||||
* @param yPoints The Y coordinate array.
|
||||
* @param npoints The number of points to draw.
|
||||
*/
|
||||
public abstract void
|
||||
drawPolygon(int xPoints[], int yPoints[], int npoints);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws the specified polygon.
|
||||
*
|
||||
* @param polygon The polygon to draw.
|
||||
*/
|
||||
public void
|
||||
drawPolygon(Polygon polygon)
|
||||
{
|
||||
drawPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Fills the polygon determined by the arrays
|
||||
* of corresponding x and y coordinates.
|
||||
*
|
||||
* @param xPoints The X coordinate array.
|
||||
* @param yPoints The Y coordinate array.
|
||||
* @param npoints The number of points to draw.
|
||||
*/
|
||||
public abstract void
|
||||
fillPolygon(int xPoints[], int yPoints[], int npoints);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Fills the specified polygon
|
||||
*
|
||||
* @param polygon The polygon to fill.
|
||||
*/
|
||||
public void
|
||||
fillPolygon(Polygon polygon)
|
||||
{
|
||||
fillPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws the specified string starting at the specified point.
|
||||
*
|
||||
* @param string The string to draw.
|
||||
* @param x The X coordinate of the point to draw at.
|
||||
* @param y The Y coordinate of the point to draw at.
|
||||
*/
|
||||
public abstract void
|
||||
drawString(String string, int x, int y);
|
||||
|
||||
public abstract void drawString (AttributedCharacterIterator ci, int x, int y);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws the specified characters starting at the specified point.
|
||||
*
|
||||
* @param data The array of characters to draw.
|
||||
* @param offset The offset into the array to start drawing characters from.
|
||||
* @param length The number of characters to draw.
|
||||
* @param x The X coordinate of the point to draw at.
|
||||
* @param y The Y coordinate of the point to draw at.
|
||||
*/
|
||||
public void
|
||||
drawChars(char data[], int offset, int length, int x, int y)
|
||||
{
|
||||
drawString(new String(data, offset, length), x, y);
|
||||
}
|
||||
|
||||
public void
|
||||
drawBytes(byte[] data, int offset, int length, int x, int y)
|
||||
{
|
||||
String str = new String(data, offset, length);
|
||||
drawString(str, x, y);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws all of the image that is available and returns. If the image
|
||||
* is not completely loaded, <code>false</code> is returned and
|
||||
* the specified iamge observer is notified as more data becomes
|
||||
* available.
|
||||
*
|
||||
* @param image The image to draw.
|
||||
* @param x The X coordinate of the point to draw at.
|
||||
* @param y The Y coordinate of the point to draw at.
|
||||
* @param observer The image observer to notify as data becomes available.
|
||||
*
|
||||
* @return <code>true</code> if all the image data is available,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public abstract boolean
|
||||
drawImage(Image image, int x, int y, ImageObserver observer);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws all of the image that is available and returns. The image
|
||||
* is scaled to fit in the specified rectangle. If the image
|
||||
* is not completely loaded, <code>false</code> is returned and
|
||||
* the specified iamge observer is notified as more data becomes
|
||||
* available.
|
||||
*
|
||||
* @param image The image to draw.
|
||||
* @param x The X coordinate of the point to draw at.
|
||||
* @param y The Y coordinate of the point to draw at.
|
||||
* @param width The width of the rectangle to draw in.
|
||||
* @param height The height of the rectangle to draw in.
|
||||
* @param observer The image observer to notify as data becomes available.
|
||||
*
|
||||
* @return <code>true</code> if all the image data is available,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public abstract boolean
|
||||
drawImage(Image image, int x, int y, int width, int height,
|
||||
ImageObserver observer);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws all of the image that is available and returns. If the image
|
||||
* is not completely loaded, <code>false</code> is returned and
|
||||
* the specified iamge observer is notified as more data becomes
|
||||
* available.
|
||||
*
|
||||
* @param image The image to draw.
|
||||
* @param x The X coordinate of the point to draw at.
|
||||
* @param y The Y coordinate of the point to draw at.
|
||||
* @param bgcolor The background color to use for the image.
|
||||
* @param observer The image observer to notify as data becomes available.
|
||||
*
|
||||
* @return <code>true</code> if all the image data is available,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public abstract boolean
|
||||
drawImage(Image image, int x, int y, Color bgcolor, ImageObserver observer);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Draws all of the image that is available and returns. The image
|
||||
* is scaled to fit in the specified rectangle. If the image
|
||||
* is not completely loaded, <code>false</code> is returned and
|
||||
* the specified iamge observer is notified as more data becomes
|
||||
* available.
|
||||
*
|
||||
* @param image The image to draw.
|
||||
* @param x The X coordinate of the point to draw at.
|
||||
* @param y The Y coordinate of the point to draw at.
|
||||
* @param width The width of the rectangle to draw in.
|
||||
* @param height The height of the rectangle to draw in.
|
||||
* @param bgcolor The background color to use for the image.
|
||||
* @param observer The image observer to notify as data becomes available.
|
||||
*
|
||||
* @return <code>true</code> if all the image data is available,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public abstract boolean
|
||||
drawImage(Image image, int x, int y, int width, int height, Color bgcolor,
|
||||
ImageObserver observer);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* FIXME: Write Javadocs for this when you understand it.
|
||||
*/
|
||||
public abstract boolean
|
||||
drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
|
||||
int sx2, int sy2, ImageObserver observer);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* FIXME: Write Javadocs for this when you understand it.
|
||||
*/
|
||||
public abstract boolean
|
||||
drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1,
|
||||
int sx2, int sy2, Color bgcolor, ImageObserver observer);
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Free any resources held by this graphics context immediately instead
|
||||
* of waiting for the object to be garbage collected and finalized.
|
||||
*/
|
||||
public abstract void
|
||||
dispose();
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Frees the resources held by this graphics context when it is
|
||||
* garbage collected.
|
||||
*/
|
||||
public void
|
||||
finalize()
|
||||
{
|
||||
dispose();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object.
|
||||
*
|
||||
* @return A string representation of this object.
|
||||
*/
|
||||
public String
|
||||
toString()
|
||||
{
|
||||
return getClass ().getName () + "[font=" + getFont () + ",color=" + getColor () + "]";
|
||||
}
|
||||
|
||||
public boolean
|
||||
hitClip(int x, int y, int width, int height)
|
||||
{
|
||||
throw new UnsupportedOperationException("not implemented yet");
|
||||
}
|
||||
|
||||
public Rectangle
|
||||
getClipBounds(Rectangle r)
|
||||
{
|
||||
Rectangle clipBounds = getClipBounds();
|
||||
|
||||
if (r == null)
|
||||
return clipBounds;
|
||||
|
||||
r.x = clipBounds.x;
|
||||
r.y = clipBounds.y;
|
||||
r.width = clipBounds.width;
|
||||
r.height = clipBounds.height;
|
||||
return r;
|
||||
}
|
||||
|
||||
} // class Graphics
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/* Copyright (C) 2000, 2002, 2004 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.BufferedImageOp;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.awt.image.renderable.RenderableImage;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
|
||||
*/
|
||||
public abstract class Graphics2D extends Graphics
|
||||
{
|
||||
|
||||
protected Graphics2D()
|
||||
{
|
||||
}
|
||||
|
||||
public void draw3DRect(int x, int y, int width, int height,
|
||||
boolean raised)
|
||||
{
|
||||
super.draw3DRect(x, y, width, height, raised);
|
||||
}
|
||||
|
||||
public void fill3DRect(int x, int y, int width, int height,
|
||||
boolean raised)
|
||||
{
|
||||
super.fill3DRect(x, y, width, height, raised);
|
||||
}
|
||||
|
||||
public abstract void draw(Shape shape);
|
||||
|
||||
public abstract boolean drawImage(Image image, AffineTransform xform,
|
||||
ImageObserver obs);
|
||||
|
||||
public abstract void drawImage(BufferedImage image,
|
||||
BufferedImageOp op,
|
||||
int x,
|
||||
int y);
|
||||
|
||||
public abstract void drawRenderedImage(RenderedImage image,
|
||||
AffineTransform xform);
|
||||
|
||||
public abstract void drawRenderableImage(RenderableImage image,
|
||||
AffineTransform xform);
|
||||
|
||||
public abstract void drawString(String text, int x, int y);
|
||||
|
||||
public abstract void drawString(String text, float x, float y);
|
||||
|
||||
public abstract void drawString(AttributedCharacterIterator iterator,
|
||||
int x, int y);
|
||||
|
||||
public abstract void drawString(AttributedCharacterIterator iterator,
|
||||
float x, float y);
|
||||
|
||||
// public abstract void drawGlyphVector(GlyphVector g, float x, float y);
|
||||
|
||||
public abstract void fill(Shape shape);
|
||||
|
||||
public abstract boolean hit(Rectangle rect, Shape text,
|
||||
boolean onStroke);
|
||||
|
||||
public abstract GraphicsConfiguration getDeviceConfiguration();
|
||||
|
||||
public abstract void setComposite(Composite comp);
|
||||
|
||||
public abstract void setPaint(Paint paint);
|
||||
|
||||
public abstract void setStroke(Stroke stroke);
|
||||
|
||||
public abstract void setRenderingHint(RenderingHints.Key hintKey,
|
||||
Object hintValue);
|
||||
|
||||
public abstract Object getRenderingHint(RenderingHints.Key hintKey);
|
||||
|
||||
public abstract void setRenderingHints(Map hints);
|
||||
|
||||
public abstract void addRenderingHints(Map hints);
|
||||
|
||||
public abstract RenderingHints getRenderingHints();
|
||||
|
||||
public abstract void translate(int x, int y);
|
||||
|
||||
public abstract void translate(double tx, double ty);
|
||||
|
||||
public abstract void rotate(double theta);
|
||||
|
||||
public abstract void rotate(double theta, double x, double y);
|
||||
|
||||
public abstract void scale(double scaleX, double scaleY);
|
||||
|
||||
public abstract void shear(double shearX, double shearY);
|
||||
|
||||
public abstract void transform(AffineTransform Tx);
|
||||
|
||||
public abstract void setTransform(AffineTransform Tx);
|
||||
|
||||
public abstract AffineTransform getTransform();
|
||||
|
||||
public abstract Paint getPaint();
|
||||
|
||||
public abstract Composite getComposite();
|
||||
|
||||
public abstract void setBackground(Color color);
|
||||
|
||||
public abstract Color getBackground();
|
||||
|
||||
public abstract Stroke getStroke();
|
||||
|
||||
public abstract void clip(Shape s);
|
||||
|
||||
public abstract FontRenderContext getFontRenderContext ();
|
||||
|
||||
public abstract void drawGlyphVector (GlyphVector g, float x, float y);
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/* GraphicsConfigTemplate.java -- a template for selecting configurations
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This allows filtering an array of GraphicsConfigurations for the best
|
||||
* one based on various requirements. The resulting configuration has had
|
||||
* all non-default attributes set as required to meet or exceed the request.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see GraphicsConfiguration
|
||||
* @see GraphicsDevice
|
||||
* @since 1.2
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public abstract class GraphicsConfigTemplate implements Serializable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.2+.
|
||||
*/
|
||||
private static final long serialVersionUID = -8061369279557787079L;
|
||||
|
||||
/** States that a feature is required to select a configuration. */
|
||||
public static final int REQUIRED = 1;
|
||||
|
||||
/**
|
||||
* States that a feature is preferred, but not required, to select a
|
||||
* configuration. In the case of multiple valid configurations, the tie
|
||||
* breaks in favor of the one with the feature.
|
||||
*/
|
||||
public static final int PREFERRED = 2;
|
||||
|
||||
/**
|
||||
* States that a feature is not necessary in the configuration. In the case
|
||||
* of multiple valid configurations, the tie breaks in favor of the one
|
||||
* without the feature, to reduce overhead.
|
||||
*/
|
||||
public static final int UNNECESSARY = 3;
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
public GraphicsConfigTemplate()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the "best" match among the array of possible configurations, given
|
||||
* the criteria of this template.
|
||||
*
|
||||
* @param array the array to choose from
|
||||
* @return the best match
|
||||
* @throws NullPointerException if array is null
|
||||
*/
|
||||
public abstract GraphicsConfiguration getBestConfiguration
|
||||
(GraphicsConfiguration[] array);
|
||||
|
||||
/**
|
||||
* Returns true if the given configuration supports all the features required
|
||||
* by this template.
|
||||
*
|
||||
* @param config the configuration to test
|
||||
* @return true if it is a match
|
||||
* @throws NullPointerException if config is null
|
||||
*/
|
||||
public abstract boolean isGraphicsConfigSupported
|
||||
(GraphicsConfiguration config);
|
||||
} // class GraphicsConfigTemplate
|
||||
@@ -0,0 +1,218 @@
|
||||
/* GraphicsConfiguration.java -- describes characteristics of graphics
|
||||
Copyright (C) 2000, 2001, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.VolatileImage;
|
||||
|
||||
/**
|
||||
* This class describes the configuration of various graphics devices, such
|
||||
* as a monitor or printer. Different configurations may exist for the same
|
||||
* device, according to the different native modes supported.
|
||||
*
|
||||
* <p>Virtual devices are supported (for example, in a multiple screen
|
||||
* environment, a virtual device covers all screens simultaneously); the
|
||||
* configuration will have a non-zero relative coordinate system in such
|
||||
* a case.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see Window
|
||||
* @see Frame
|
||||
* @see GraphicsEnvironment
|
||||
* @see GraphicsDevice
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public abstract class GraphicsConfiguration
|
||||
{
|
||||
/**
|
||||
* The default constructor.
|
||||
*
|
||||
* @see GraphicsDevice#getConfigurations()
|
||||
* @see GraphicsDevice#getDefaultConfiguration()
|
||||
* @see GraphicsDevice#getBestConfiguration(GraphicsConfigTemplate)
|
||||
* @see Graphics2D#getDeviceConfiguration()
|
||||
*/
|
||||
protected GraphicsConfiguration ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the associated device that this configuration describes.
|
||||
*
|
||||
* @return the device
|
||||
*/
|
||||
public abstract GraphicsDevice getDevice();
|
||||
|
||||
/**
|
||||
* Returns a buffered image optimized to this device, so that blitting can
|
||||
* be supported in the buffered image.
|
||||
*
|
||||
* @param w the width of the buffer
|
||||
* @param h the height of the buffer
|
||||
* @return the buffered image, or null if none is supported
|
||||
*/
|
||||
public abstract BufferedImage createCompatibleImage(int w, int h);
|
||||
|
||||
/**
|
||||
* Returns a buffered volatile image optimized to this device, so that
|
||||
* blitting can be supported in the buffered image. Because the buffer is
|
||||
* volatile, it can be optimized by native graphics accelerators.
|
||||
*
|
||||
* @param w the width of the buffer
|
||||
* @param h the height of the buffer
|
||||
* @return the buffered image, or null if none is supported
|
||||
* @see Component#createVolatileImage(int, int)
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract VolatileImage createCompatibleVolatileImage(int w, int h);
|
||||
|
||||
/**
|
||||
* Returns a buffered volatile image optimized to this device, and with the
|
||||
* given capabilities, so that blitting can be supported in the buffered
|
||||
* image. Because the buffer is volatile, it can be optimized by native
|
||||
* graphics accelerators.
|
||||
*
|
||||
* @param w the width of the buffer
|
||||
* @param h the height of the buffer
|
||||
* @param caps the desired capabilities of the image buffer
|
||||
* @return the buffered image, or null if none is supported
|
||||
* @throws AWTException if the capabilities cannot be met
|
||||
* @since 1.4
|
||||
*/
|
||||
public VolatileImage createCompatibleVolatileImage(int w, int h,
|
||||
ImageCapabilities caps)
|
||||
throws AWTException
|
||||
{
|
||||
throw new AWTException("not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a buffered image optimized to this device, and with the specified
|
||||
* transparency, so that blitting can be supported in the buffered image.
|
||||
*
|
||||
* @param w the width of the buffer
|
||||
* @param h the height of the buffer
|
||||
* @param transparency the transparency of the buffer
|
||||
* @return the buffered image, or null if none is supported
|
||||
* @see Transparency#OPAQUE
|
||||
* @see Transparency#BITMASK
|
||||
* @see Transparency#TRANSLUCENT
|
||||
*/
|
||||
public abstract BufferedImage createCompatibleImage(int w, int h,
|
||||
int transparency);
|
||||
|
||||
/**
|
||||
* Gets the color model of the corresponding device.
|
||||
*
|
||||
* @return the color model
|
||||
*/
|
||||
public abstract ColorModel getColorModel();
|
||||
|
||||
/**
|
||||
* Gets a color model for the corresponding device which supports the desired
|
||||
* transparency level.
|
||||
*
|
||||
* @param transparency the transparency of the model
|
||||
* @return the color model, with transparency
|
||||
* @see Transparency#OPAQUE
|
||||
* @see Transparency#BITMASK
|
||||
* @see Transparency#TRANSLUCENT
|
||||
*/
|
||||
public abstract ColorModel getColorModel(int transparency);
|
||||
|
||||
/**
|
||||
* Returns a transform that maps user coordinates to device coordinates. The
|
||||
* preferred mapping is about 72 user units to 1 inch (2.54 cm) of physical
|
||||
* space. This is often the identity transform. The device coordinates have
|
||||
* the origin at the upper left, with increasing x to the right, and
|
||||
* increasing y to the bottom.
|
||||
*
|
||||
* @return the transformation from user space to device space
|
||||
* @see #getNormalizingTransform()
|
||||
*/
|
||||
public abstract AffineTransform getDefaultTransform();
|
||||
|
||||
/**
|
||||
* Returns a transform that maps user coordinates to device coordinates. The
|
||||
* exact mapping is 72 user units to 1 inch (2.54 cm) of physical space.
|
||||
* This is often the identity transform. The device coordinates have the
|
||||
* origin at the upper left, with increasing x to the right, and increasing
|
||||
* y to the bottom. Note that this is more accurate (and thus, sometimes more
|
||||
* costly) than the default transform.
|
||||
*
|
||||
* @return the normalized transformation from user space to device space
|
||||
* @see #getDefaultTransform()
|
||||
*/
|
||||
public abstract AffineTransform getNormalizingTransform();
|
||||
|
||||
/**
|
||||
* Returns the bounds of the configuration, in device coordinates. If this
|
||||
* is a virtual device (for example, encompassing several screens), the
|
||||
* bounds may have a non-zero origin.
|
||||
*
|
||||
* @return the device bounds
|
||||
* @since 1.3
|
||||
*/
|
||||
public abstract Rectangle getBounds();
|
||||
|
||||
/**
|
||||
* Returns the buffering capabilities of this configuration.
|
||||
*
|
||||
* @return the buffer capabilities
|
||||
* @since 1.4
|
||||
*/
|
||||
public BufferCapabilities getBufferCapabilities()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the imaging capabilities of this configuration.
|
||||
*
|
||||
* @return the image capabilities
|
||||
* @since 1.4
|
||||
*/
|
||||
public ImageCapabilities getImageCapabilities()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
} // class GraphicsConfiguration
|
||||
@@ -0,0 +1,292 @@
|
||||
/* GraphicsDevice.java -- information about a graphics device
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.VolatileImage;
|
||||
|
||||
/**
|
||||
* This describes a graphics device available to the given environment. This
|
||||
* includes screen and printer devices, and the different configurations for
|
||||
* each device. Also, this allows you to create virtual devices which operate
|
||||
* over a multi-screen environment.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see GraphicsEnvironment
|
||||
* @see GraphicsConfiguration
|
||||
* @since 1.3
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public abstract class GraphicsDevice
|
||||
{
|
||||
/** Device is a raster screen. */
|
||||
public static final int TYPE_RASTER_SCREEN = 0;
|
||||
|
||||
/** Device is a printer. */
|
||||
public static final int TYPE_PRINTER = 1;
|
||||
|
||||
/** Device is an image buffer not visible to the user. */
|
||||
public static final int TYPE_IMAGE_BUFFER = 2;
|
||||
|
||||
/** The current full-screen window, or null if there is none. */
|
||||
private Window full_screen;
|
||||
|
||||
/**
|
||||
* The bounds of the fullscreen window before it has been switched to full
|
||||
* screen.
|
||||
*/
|
||||
private Rectangle fullScreenOldBounds;
|
||||
|
||||
/** The current display mode, or null if unknown. */
|
||||
private DisplayMode mode;
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
*
|
||||
* @see GraphicsEnvironment#getScreenDevices()
|
||||
* @see GraphicsEnvironment#getDefaultScreenDevice()
|
||||
* @see GraphicsConfiguration#getDevice()
|
||||
*/
|
||||
protected GraphicsDevice()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the device.
|
||||
*
|
||||
* @return the device type
|
||||
* @see #TYPE_RASTER_SCREEN
|
||||
* @see #TYPE_PRINTER
|
||||
* @see #TYPE_IMAGE_BUFFER
|
||||
*/
|
||||
public abstract int getType();
|
||||
|
||||
/**
|
||||
* Returns an identification string for the device. This can be
|
||||
* vendor-specific, and may be useful for debugging.
|
||||
*
|
||||
* @return the identification
|
||||
*/
|
||||
public abstract String getIDstring();
|
||||
|
||||
/**
|
||||
* Return all configurations valid for this device.
|
||||
*
|
||||
* @return an array of configurations
|
||||
*/
|
||||
public abstract GraphicsConfiguration[] getConfigurations();
|
||||
|
||||
/**
|
||||
* Return the default configuration for this device.
|
||||
*
|
||||
* @return the default configuration
|
||||
*/
|
||||
public abstract GraphicsConfiguration getDefaultConfiguration();
|
||||
|
||||
/**
|
||||
* Return the best configuration, according to the criteria in the given
|
||||
* template.
|
||||
*
|
||||
* @param template the template to adjust by
|
||||
* @return the best configuration
|
||||
* @throws NullPointerException if template is null
|
||||
*/
|
||||
public GraphicsConfiguration getBestConfiguration
|
||||
(GraphicsConfigTemplate template)
|
||||
{
|
||||
return template.getBestConfiguration(getConfigurations());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the device supports full-screen exclusive mode. The
|
||||
* default implementation returns true; subclass it if this is not the case.
|
||||
*
|
||||
* @return true if full screen support is available
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean isFullScreenSupported()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the given window between full screen and normal mode. The previous
|
||||
* full-screen window, if different, is restored; if the given window is
|
||||
* null, no window will be full screen. If
|
||||
* <code>isFullScreenSupported()</code> returns true, full screen mode is
|
||||
* considered to be exclusive, which implies:<ul>
|
||||
* <li>Windows cannot overlap the full-screen window. All other application
|
||||
* windows will always appear beneath the full-screen window in the
|
||||
* Z-order.</li>
|
||||
* <li>Input method windows are disabled. It is advisable to call
|
||||
* <code>Component.enableInputMethods(false)</code> to make a component
|
||||
* a non-client of the input method framework.</li>
|
||||
* </ul><br>
|
||||
* If <code>isFullScreenSupported()</code> returns false, full-screen
|
||||
* exclusive mode is simulated by resizing the window to the size of the
|
||||
* screen and positioning it at (0,0). This is also what this method does.
|
||||
* If a device supports real fullscreen mode then it should override this
|
||||
* method as well as #isFullScreenSupported and #getFullScreenWindow.
|
||||
*
|
||||
* @param w the window to toggle
|
||||
* @see #isFullScreenSupported()
|
||||
* @see #getFullScreenWindow()
|
||||
* @see #setDisplayMode(DisplayMode)
|
||||
* @see Component#enableInputMethods(boolean)
|
||||
* @since 1.4
|
||||
*/
|
||||
public synchronized void setFullScreenWindow(Window w)
|
||||
{
|
||||
// Restore the previous window to normal mode and release the reference.
|
||||
if (full_screen != null)
|
||||
{
|
||||
full_screen.setBounds(fullScreenOldBounds);
|
||||
}
|
||||
|
||||
full_screen = null;
|
||||
|
||||
// If w != null, make it full-screen.
|
||||
if (w != null)
|
||||
{
|
||||
fullScreenOldBounds = w.getBounds();
|
||||
full_screen = w;
|
||||
DisplayMode dMode = getDisplayMode();
|
||||
full_screen.setBounds(0, 0, dMode.getWidth(), dMode.getHeight());
|
||||
full_screen.requestFocus();
|
||||
full_screen.setLocationRelativeTo(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current full-screen window of the device, or null if no
|
||||
* window is full-screen.
|
||||
*
|
||||
* @return the full-screen window
|
||||
* @see #setFullScreenWindow(Window)
|
||||
* @since 1.4
|
||||
*/
|
||||
public Window getFullScreenWindow()
|
||||
{
|
||||
return full_screen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this device supports low-level display changes. This may
|
||||
* depend on whether full-screen exclusive mode is available.
|
||||
*
|
||||
* XXX The default implementation returns false for now.
|
||||
*
|
||||
* @return true if display changes are supported
|
||||
* @see #setDisplayMode(DisplayMode)
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean isDisplayChangeSupported()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display mode. This may be dependent on the availability of
|
||||
* full-screen exclusive mode.
|
||||
*
|
||||
* @param mode the new mode
|
||||
* @throws IllegalArgumentException if the new mode is not in getDisplayModes
|
||||
* @throws UnsupportedOperationException if ! isDisplayChangeSupported()
|
||||
* @see #getDisplayMode()
|
||||
* @see #getDisplayModes()
|
||||
* @see #isDisplayChangeSupported()
|
||||
* @since 1.4
|
||||
*/
|
||||
public void setDisplayMode(DisplayMode mode)
|
||||
{
|
||||
DisplayMode[] array = getDisplayModes();
|
||||
if (! isDisplayChangeSupported())
|
||||
throw new UnsupportedOperationException();
|
||||
int i = array == null ? 0 : array.length;
|
||||
while (--i >= 0)
|
||||
if (array[i].equals(mode))
|
||||
break;
|
||||
if (i < 0)
|
||||
throw new IllegalArgumentException();
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current display mode of this device, or null if unknown.
|
||||
*
|
||||
* @return the current display mode
|
||||
* @see #setDisplayMode(DisplayMode)
|
||||
* @see #getDisplayModes()
|
||||
* @since 1.4
|
||||
*/
|
||||
public DisplayMode getDisplayMode()
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of all available display modes. This implementation
|
||||
* returns a 0-length array, so subclasses must override this.
|
||||
*
|
||||
* @return the array of available modes
|
||||
* @since 1.4
|
||||
*/
|
||||
public DisplayMode[] getDisplayModes()
|
||||
{
|
||||
return new DisplayMode[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of bytes available in accelerated memory on this
|
||||
* device. The device may support creation or caching on a first-come,
|
||||
* first-served basis, depending on the operating system and driver.
|
||||
* Memory may be a finite resource, and because of multi-threading, you
|
||||
* are not guaranteed that the result of this method ensures your image
|
||||
* will successfully be put in accelerated memory. A negative result means
|
||||
* the memory is unlimited. The default implementation assumes no special
|
||||
* memory is available, and returns 0.
|
||||
*
|
||||
* @return the size of accelerated memory available
|
||||
* @see VolatileImage#flush()
|
||||
* @see ImageCapabilities#isAccelerated()
|
||||
*/
|
||||
public int getAvailableAcceleratedMemory()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} // class GraphicsDevice
|
||||
@@ -0,0 +1,244 @@
|
||||
/* GraphicsEnvironment.java -- information about the graphics environment
|
||||
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import gnu.java.awt.ClasspathToolkit;
|
||||
import gnu.classpath.SystemProperties;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* This descibes the collection of GraphicsDevice and Font objects available
|
||||
* on a given platform. The resources might be local or remote, and specify
|
||||
* the valid configurations for displaying graphics.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see GraphicsDevice
|
||||
* @see GraphicsConfiguration
|
||||
* @since 1.4
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public abstract class GraphicsEnvironment
|
||||
{
|
||||
private static GraphicsEnvironment localGraphicsEnvironment;
|
||||
|
||||
/**
|
||||
* The environment must be obtained from a factory or query method, hence
|
||||
* this constructor is protected.
|
||||
*/
|
||||
protected GraphicsEnvironment()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the local graphics environment. If the java.awt.graphicsenv
|
||||
* system property is set, it instantiates the specified class,
|
||||
* otherwise it assume that the awt toolkit is a ClasspathToolkit
|
||||
* and delegates to it to create the instance.
|
||||
*
|
||||
* @return the local environment
|
||||
*/
|
||||
public static GraphicsEnvironment getLocalGraphicsEnvironment()
|
||||
{
|
||||
if (localGraphicsEnvironment != null)
|
||||
return localGraphicsEnvironment;
|
||||
|
||||
String graphicsenv = SystemProperties.getProperty("java.awt.graphicsenv",
|
||||
null);
|
||||
if (graphicsenv != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// We intentionally use the bootstrap class loader.
|
||||
localGraphicsEnvironment = (GraphicsEnvironment)
|
||||
Class.forName(graphicsenv).newInstance();
|
||||
return localGraphicsEnvironment;
|
||||
}
|
||||
catch (Exception x)
|
||||
{
|
||||
throw (InternalError)
|
||||
new InternalError("Unable to instantiate java.awt.graphicsenv")
|
||||
.initCause(x);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ClasspathToolkit tk;
|
||||
tk = ((ClasspathToolkit) Toolkit.getDefaultToolkit());
|
||||
localGraphicsEnvironment = tk.getLocalGraphicsEnvironment();
|
||||
return localGraphicsEnvironment;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the local environment is headless, meaning that it does not
|
||||
* support a display, keyboard, or mouse. Many methods in the Abstract
|
||||
* Windows Toolkit (java.awt) throw a {@link HeadlessException} if this
|
||||
* returns true.
|
||||
*
|
||||
* This method returns true if the java.awt.headless property is set
|
||||
* to "true".
|
||||
*
|
||||
* @return true if the environment is headless, meaning that graphics are
|
||||
* unsupported
|
||||
* @since 1.4
|
||||
*/
|
||||
public static boolean isHeadless()
|
||||
{
|
||||
String headless = SystemProperties.getProperty("java.awt.headless", null);
|
||||
return "true".equalsIgnoreCase(headless);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given environment is headless, meaning that it does not
|
||||
* support a display, keyboard, or mouse. Many methods in the Abstract
|
||||
* Windows Toolkit (java.awt) throw a {@link HeadlessException} if this
|
||||
* returns true. This default implementation returns isHeadless(), so
|
||||
* subclasses need only override it if they differ.
|
||||
*
|
||||
* @return true if the environment is headless, meaning that graphics are
|
||||
* unsupported
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean isHeadlessInstance()
|
||||
{
|
||||
return isHeadless();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of all the GraphicsDevice objects.
|
||||
*
|
||||
* @return the available graphics devices, may be 0 length
|
||||
* @throws HeadlessException if the environment is headless
|
||||
*/
|
||||
public abstract GraphicsDevice[] getScreenDevices();
|
||||
|
||||
/**
|
||||
* Get the default screen GraphicsDevice object.
|
||||
*
|
||||
* @return the default screen device
|
||||
* @throws HeadlessException if the environment is headless
|
||||
*/
|
||||
public abstract GraphicsDevice getDefaultScreenDevice();
|
||||
|
||||
/**
|
||||
* Return a Graphics2D object which will render into the specified image.
|
||||
*
|
||||
* @param image the image to render into
|
||||
* @return the object that renders into the image
|
||||
*/
|
||||
public abstract Graphics2D createGraphics(BufferedImage image);
|
||||
|
||||
/**
|
||||
* Returns an array of the one-point size fonts available in this
|
||||
* environment. From there, the user can select the font and derive the
|
||||
* correct one of proper size and attributes, using <code>deriveFont</code>.
|
||||
* Only one master version of each font appears in this array; if a font
|
||||
* can be derived from another, it must be created in that way.
|
||||
*
|
||||
* @return the array of available fonts
|
||||
* @see #getAvailableFontFamilyNames()
|
||||
* @see Font#deriveFont(int, float)
|
||||
* @since 1.2
|
||||
*/
|
||||
public abstract Font[] getAllFonts();
|
||||
|
||||
/**
|
||||
* Returns an array of the font family names available in this environment.
|
||||
* This allows flexibility in choosing the style of font, while still letting
|
||||
* the Font class decide its best match.
|
||||
*
|
||||
* @return the array of available font families
|
||||
* @see #getAllFonts()
|
||||
* @see Font#getFamily()
|
||||
* @since 1.2
|
||||
*/
|
||||
public abstract String[] getAvailableFontFamilyNames();
|
||||
|
||||
/**
|
||||
* Returns an array of the font family names available in this environment,
|
||||
* localized to the current Locale if l is non-null. This allows
|
||||
* flexibility in choosing the style of font, while still letting the Font
|
||||
* class decide its best match.
|
||||
*
|
||||
* @param l the locale to use
|
||||
* @return the array of available font families, localized
|
||||
* @see #getAllFonts()
|
||||
* @see Font#getFamily()
|
||||
* @since 1.2
|
||||
*/
|
||||
public abstract String[] getAvailableFontFamilyNames(Locale l);
|
||||
|
||||
/**
|
||||
* Returns the point where a window should be centered. You should probably
|
||||
* also check that the window fits within the screen bounds. The default
|
||||
* simply returns the center of the maximum window bounds; subclasses should
|
||||
* override this if native objects (like scrollbars) make that off-centered.
|
||||
*
|
||||
* @return the centering point
|
||||
* @throws HeadlessException if the environment is headless
|
||||
* @see #getMaximumWindowBounds()
|
||||
* @since 1.4
|
||||
*/
|
||||
public Point getCenterPoint()
|
||||
{
|
||||
Rectangle r = getMaximumWindowBounds();
|
||||
return new Point(r.x + r.width / 2, r.y + r.height / 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum bounds for a centered window object. The default
|
||||
* implementation simply returns the bounds of the default configuration
|
||||
* of the default screen; subclasses should override this to if native
|
||||
* objects (like scrollbars) reduce what is truly available. Also,
|
||||
* subclasses should override this if the window should be centered across
|
||||
* a multi-screen display.
|
||||
*
|
||||
* @return the maximum window bounds
|
||||
* @throws HeadlessException if the environment is headless
|
||||
* @see #getCenterPoint()
|
||||
* @see GraphicsConfiguration#getBounds()
|
||||
* @see Toolkit#getScreenInsets(GraphicsConfiguration)
|
||||
* @since 1.4
|
||||
*/
|
||||
public Rectangle getMaximumWindowBounds()
|
||||
{
|
||||
return getDefaultScreenDevice().getDefaultConfiguration().getBounds();
|
||||
}
|
||||
} // class GraphicsEnvironment
|
||||
@@ -0,0 +1,195 @@
|
||||
/* GridBagConstraints.java -- Constraints for GridBag layout manager
|
||||
Copyright (C) 2000, 2001, 2002, 2004 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This specifies the constraints for a component managed by the
|
||||
* GridBagLayout layout manager.
|
||||
*/
|
||||
public class GridBagConstraints implements Cloneable, Serializable
|
||||
{
|
||||
static final long serialVersionUID = -1000070633030801713L;
|
||||
|
||||
/** Fill in both directions. */
|
||||
public static final int BOTH = 1;
|
||||
/** Don't fill. */
|
||||
public static final int NONE = 0;
|
||||
/** Fill horizontally. */
|
||||
public static final int HORIZONTAL = 2;
|
||||
/** Fill vertically. */
|
||||
public static final int VERTICAL = 3;
|
||||
|
||||
/** Position in the center. */
|
||||
public static final int CENTER = 10;
|
||||
/** Position to the east. */
|
||||
public static final int EAST = 13;
|
||||
/** Position to the north. */
|
||||
public static final int NORTH = 11;
|
||||
/** Position to the northeast. */
|
||||
public static final int NORTHEAST = 12;
|
||||
/** Position to the northwest. */
|
||||
public static final int NORTHWEST = 18;
|
||||
/** Position to the south. */
|
||||
public static final int SOUTH = 15;
|
||||
/** Position to the southeast. */
|
||||
public static final int SOUTHEAST = 14;
|
||||
/** Position to the southwest. */
|
||||
public static final int SOUTHWEST = 16;
|
||||
/** Position to the west. */
|
||||
public static final int WEST = 17;
|
||||
|
||||
/** Occupy all remaining cells except last cell. */
|
||||
public static final int RELATIVE = -1;
|
||||
/** Occupy all remaining cells. */
|
||||
public static final int REMAINDER = 0;
|
||||
|
||||
/**
|
||||
* Position to where the first text line would end. Equals to NORTHEAST for
|
||||
* horizontal left-to-right orientations.
|
||||
*/
|
||||
public static final int FIRST_LINE_END = 24;
|
||||
|
||||
/**
|
||||
* Position to where the first text line would start. Equals to NORTHWEST for
|
||||
* horizontal left-to-right orientations.
|
||||
*/
|
||||
public static final int FIRST_LINE_START = 23;
|
||||
|
||||
/**
|
||||
* Position to where the last text line would end. Equals to SOUTHEAST for
|
||||
* horizontal left-to-right orientations.
|
||||
*/
|
||||
public static final int LAST_LINE_END = 26;
|
||||
|
||||
/**
|
||||
* Position to where the last text line would start. Equals to SOUTHWEST for
|
||||
* horizontal left-to-right orientations.
|
||||
*/
|
||||
public static final int LAST_LINE_START = 25;
|
||||
|
||||
/**
|
||||
* Position to where a text line would end. Equals to EAST for
|
||||
* left-to-right orientations.
|
||||
*/
|
||||
public static final int LINE_END = 22;
|
||||
|
||||
/**
|
||||
* Position to where a text line would start. Equals to WEST for
|
||||
* left-to-right orientations.
|
||||
*/
|
||||
public static final int LINE_START = 21;
|
||||
|
||||
/**
|
||||
* Position to where a page ends. Equals SOUTH for horizontal orientations.
|
||||
*/
|
||||
public static final int PAGE_END = 20;
|
||||
|
||||
/**
|
||||
* Position to where a page starts. Equals NORTH for horizontal orientations.
|
||||
*/
|
||||
public static final int PAGE_START = 19;
|
||||
|
||||
public int anchor;
|
||||
public int fill;
|
||||
public int gridheight;
|
||||
public int gridwidth;
|
||||
public int gridx;
|
||||
public int gridy;
|
||||
public Insets insets;
|
||||
public int ipadx;
|
||||
public int ipady;
|
||||
public double weightx;
|
||||
public double weighty;
|
||||
|
||||
/** Create a copy of this object. */
|
||||
public Object clone ()
|
||||
{
|
||||
try
|
||||
{
|
||||
GridBagConstraints g = (GridBagConstraints) super.clone ();
|
||||
g.insets = (Insets) insets.clone ();
|
||||
return g;
|
||||
}
|
||||
catch (CloneNotSupportedException _)
|
||||
{
|
||||
// Can't happen.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** Create a new GridBagConstraints object with the default
|
||||
* parameters. */
|
||||
public GridBagConstraints ()
|
||||
{
|
||||
this.anchor = CENTER;
|
||||
this.fill = NONE;
|
||||
this.gridx = RELATIVE;
|
||||
this.gridy = RELATIVE;
|
||||
this.gridwidth = 1;
|
||||
this.gridheight = 1;
|
||||
this.ipadx = 0;
|
||||
this.ipady = 0;
|
||||
this.insets = new Insets (0, 0, 0, 0);
|
||||
this.weightx = 0;
|
||||
this.weighty = 0;
|
||||
}
|
||||
|
||||
/** Create a new GridBagConstraints object with the indicated
|
||||
* parameters. */
|
||||
public GridBagConstraints (int gridx, int gridy,
|
||||
int gridwidth, int gridheight,
|
||||
double weightx, double weighty,
|
||||
int anchor, int fill,
|
||||
Insets insets, int ipadx, int ipady)
|
||||
{
|
||||
this.anchor = anchor;
|
||||
this.fill = fill;
|
||||
this.gridx = gridx;
|
||||
this.gridy = gridy;
|
||||
this.gridwidth = gridwidth;
|
||||
this.gridheight = gridheight;
|
||||
this.ipadx = ipadx;
|
||||
this.ipady = ipady;
|
||||
this.insets = insets;
|
||||
this.weightx = weightx;
|
||||
this.weighty = weighty;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,70 @@
|
||||
/* GridBagLayoutInfo -
|
||||
Copyright (C) 2003, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
*/
|
||||
class GridBagLayoutInfo implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -4899416460737170217L;
|
||||
|
||||
int pos_x;
|
||||
int pos_y;
|
||||
int cols;
|
||||
int rows;
|
||||
int colWidths[];
|
||||
int rowHeights[];
|
||||
double colWeights[];
|
||||
double rowWeights[];
|
||||
|
||||
GridBagLayoutInfo (int cols, int rows)
|
||||
{
|
||||
this.pos_x = 0;
|
||||
this.pos_y = 0;
|
||||
this.cols = cols;
|
||||
this.rows = rows;
|
||||
this.colWidths = new int [cols];
|
||||
this.rowHeights = new int [rows];
|
||||
this.colWeights = new double [cols];
|
||||
this.rowWeights = new double [rows];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,360 @@
|
||||
/* GridLayout.java -- Grid-based layout engine
|
||||
Copyright (C) 1999, 2000, 2002, 2004 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/** This class implements a grid-based layout scheme. Components are
|
||||
* all given the same size and are laid out from left to right and top
|
||||
* to bottom. A GridLayout is configured with a number of rows and a
|
||||
* number of columns. If both are specified, then the number of
|
||||
* columns is ignored and is derived from the number of rows and the
|
||||
* total number of components. If either is zero then that dimension
|
||||
* is computed based on the actual size of the container. An
|
||||
* exception is thrown if an attempt is made to set both the number of
|
||||
* rows and the number of columns to 0. This class also supports
|
||||
* horizontal and vertical gaps; these are used as spacing between
|
||||
* cells.
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class GridLayout implements LayoutManager, Serializable
|
||||
{
|
||||
static final long serialVersionUID = -7411804673224730901L;
|
||||
|
||||
/** Add a new component to the layout. This particular implementation
|
||||
* does nothing.
|
||||
* @param name The name of the component to add.
|
||||
* @param comp The component to add.
|
||||
*/
|
||||
public void addLayoutComponent (String name, Component comp)
|
||||
{
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
/** Return the number of columns in this layout. */
|
||||
public int getColumns ()
|
||||
{
|
||||
return cols;
|
||||
}
|
||||
|
||||
/** Return the horizontal gap. */
|
||||
public int getHgap ()
|
||||
{
|
||||
return hgap;
|
||||
}
|
||||
|
||||
/** Return the number of rows in this layout. */
|
||||
public int getRows ()
|
||||
{
|
||||
return rows;
|
||||
}
|
||||
|
||||
/** Return the vertical gap. */
|
||||
public int getVgap ()
|
||||
{
|
||||
return vgap;
|
||||
}
|
||||
|
||||
/** Create a new <code>GridLayout</code> with one row and any number
|
||||
* of columns. Both gaps are set to 0.
|
||||
*/
|
||||
public GridLayout ()
|
||||
{
|
||||
this (1, 0, 0, 0);
|
||||
}
|
||||
|
||||
/** Create a new <code>GridLayout</code> with the specified number
|
||||
* of rows and columns. Both gaps are set to 0. Note that the row
|
||||
* and column settings cannot both be zero. If both the row and
|
||||
* column values are non-zero, the rows value takes precedence.
|
||||
* @param rows Number of rows
|
||||
* @param cols Number of columns
|
||||
* @exception IllegalArgumentException If rows and columns are both
|
||||
* 0, or if either are negative
|
||||
*/
|
||||
public GridLayout (int rows, int cols)
|
||||
{
|
||||
this (rows, cols, 0, 0);
|
||||
}
|
||||
|
||||
/** Create a new GridLayout with the specified number of rows and
|
||||
* columns and the specified gaps.
|
||||
* Note that the row and column settings cannot both be
|
||||
* zero. If both the row and column values are non-zero, the rows value
|
||||
* takes precedence.
|
||||
* @param rows Number of rows
|
||||
* @param cols Number of columns
|
||||
* @param hgap The horizontal gap
|
||||
* @param vgap The vertical gap
|
||||
* @exception IllegalArgumentException If rows and columns are both
|
||||
* 0, if either are negative, or if either gap is negative
|
||||
*/
|
||||
public GridLayout (int rows, int cols, int hgap, int vgap)
|
||||
{
|
||||
if (rows < 0)
|
||||
throw new IllegalArgumentException ("number of rows cannot be negative");
|
||||
if (cols < 0)
|
||||
throw new IllegalArgumentException ("number of columns cannot be negative");
|
||||
if (rows == 0 && cols == 0)
|
||||
throw new IllegalArgumentException ("both rows and columns cannot be 0");
|
||||
if (hgap < 0)
|
||||
throw new IllegalArgumentException ("horizontal gap must be nonnegative");
|
||||
if (vgap < 0)
|
||||
throw new IllegalArgumentException ("vertical gap must be nonnegative");
|
||||
this.rows = rows;
|
||||
this.cols = cols;
|
||||
this.hgap = hgap;
|
||||
this.vgap = vgap;
|
||||
}
|
||||
|
||||
/** Lay out the container's components based on current settings.
|
||||
* The free space in the container is divided evenly into the specified
|
||||
* number of rows and columns in this object.
|
||||
* @param parent The container to lay out
|
||||
*/
|
||||
public void layoutContainer (Container parent)
|
||||
{
|
||||
synchronized (parent.getTreeLock ())
|
||||
{
|
||||
int num = parent.ncomponents;
|
||||
|
||||
// There's no point, and handling this would mean adding special
|
||||
// cases.
|
||||
if (num == 0)
|
||||
return;
|
||||
|
||||
// This is more efficient than calling getComponents().
|
||||
Component[] comps = parent.component;
|
||||
|
||||
int real_rows = rows;
|
||||
int real_cols = cols;
|
||||
if (real_rows == 0)
|
||||
real_rows = (num + real_cols - 1) / real_cols;
|
||||
else
|
||||
real_cols = (num + real_rows - 1) / real_rows;
|
||||
|
||||
// We might have less than a single row. In this case we expand
|
||||
// to fill.
|
||||
if (num < real_cols)
|
||||
real_cols = num;
|
||||
|
||||
Dimension d = parent.getSize ();
|
||||
Insets ins = parent.getInsets ();
|
||||
|
||||
// Compute width and height of each cell in the grid.
|
||||
int tw = d.width - ins.left - ins.right;
|
||||
tw = (tw - (real_cols - 1) * hgap) / real_cols;
|
||||
int th = d.height - ins.top - ins.bottom;
|
||||
th = (th - (real_rows - 1) * vgap) / real_rows;
|
||||
|
||||
// If the cells are too small, still try to do something.
|
||||
if (tw < 0)
|
||||
tw = 1;
|
||||
if (th < 0)
|
||||
th = 1;
|
||||
|
||||
int x = ins.left;
|
||||
int y = ins.top;
|
||||
int i = 0;
|
||||
int recount = 0;
|
||||
|
||||
while (i < num)
|
||||
{
|
||||
comps[i].setBounds (x, y, tw, th);
|
||||
|
||||
++i;
|
||||
++recount;
|
||||
if (recount == real_cols)
|
||||
{
|
||||
recount = 0;
|
||||
y += vgap + th;
|
||||
x = ins.left;
|
||||
}
|
||||
else
|
||||
x += hgap + tw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Get the minimum layout size of the container.
|
||||
* @param cont The parent container
|
||||
*/
|
||||
public Dimension minimumLayoutSize (Container cont)
|
||||
{
|
||||
return getSize (cont, true);
|
||||
}
|
||||
|
||||
/** Get the preferred layout size of the container.
|
||||
* @param cont The parent container
|
||||
*/
|
||||
public Dimension preferredLayoutSize (Container cont)
|
||||
{
|
||||
return getSize (cont, false);
|
||||
}
|
||||
|
||||
/** Remove the indicated component from this layout manager.
|
||||
* This particular implementation does nothing.
|
||||
* @param comp The component to remove
|
||||
*/
|
||||
public void removeLayoutComponent (Component comp)
|
||||
{
|
||||
// Nothing.
|
||||
}
|
||||
|
||||
/** Set the number of columns.
|
||||
* @param newCols
|
||||
* @exception IllegalArgumentException If the number of columns is
|
||||
* negative, or if the number of columns is zero and the number
|
||||
* of rows is already 0.
|
||||
*/
|
||||
public void setColumns (int newCols)
|
||||
{
|
||||
if (newCols < 0)
|
||||
throw new IllegalArgumentException ("number of columns cannot be negative");
|
||||
if (newCols == 0 && rows == 0)
|
||||
throw new IllegalArgumentException ("number of rows is already 0");
|
||||
this.cols = newCols;
|
||||
}
|
||||
|
||||
/** Set the horizontal gap
|
||||
* @param hgap The horizontal gap
|
||||
* @exception IllegalArgumentException If the hgap value is less than zero.
|
||||
*/
|
||||
public void setHgap (int hgap)
|
||||
{
|
||||
if (hgap < 0)
|
||||
throw new IllegalArgumentException ("horizontal gap must be nonnegative");
|
||||
this.hgap = hgap;
|
||||
}
|
||||
|
||||
/** Set the number of rows
|
||||
* @param newRows
|
||||
* @exception IllegalArgumentException If the number of rows is
|
||||
* negative, or if the number of rows is zero and the number
|
||||
* of columns is already 0.
|
||||
*/
|
||||
public void setRows (int newRows)
|
||||
{
|
||||
if (newRows < 0)
|
||||
throw new IllegalArgumentException ("number of rows cannot be negative");
|
||||
if (newRows == 0 && cols == 0)
|
||||
throw new IllegalArgumentException ("number of columns is already 0");
|
||||
this.rows = newRows;
|
||||
}
|
||||
|
||||
/** Set the vertical gap.
|
||||
* @param vgap The vertical gap
|
||||
* @exception IllegalArgumentException If the vgap value is less than zero.
|
||||
*/
|
||||
public void setVgap (int vgap)
|
||||
{
|
||||
if (vgap < 0)
|
||||
throw new IllegalArgumentException ("vertical gap must be nonnegative");
|
||||
this.vgap = vgap;
|
||||
}
|
||||
|
||||
/** Return String description of this object. */
|
||||
public String toString ()
|
||||
{
|
||||
return ("[" + getClass ().getName ()
|
||||
+ ",hgap=" + hgap + ",vgap=" + vgap
|
||||
+ ",rows=" + rows + ",cols=" + cols
|
||||
+ "]");
|
||||
}
|
||||
|
||||
// This method is used to compute the various sizes.
|
||||
private Dimension getSize (Container parent, boolean is_min)
|
||||
{
|
||||
synchronized (parent.getTreeLock ())
|
||||
{
|
||||
int w = 0, h = 0, num = parent.ncomponents;
|
||||
// This is more efficient than calling getComponents().
|
||||
Component[] comps = parent.component;
|
||||
|
||||
for (int i = 0; i < num; ++i)
|
||||
{
|
||||
Dimension d;
|
||||
|
||||
if (is_min)
|
||||
d = comps[i].getMinimumSize ();
|
||||
else
|
||||
d = comps[i].getPreferredSize ();
|
||||
|
||||
w = Math.max (d.width, w);
|
||||
h = Math.max (d.height, h);
|
||||
}
|
||||
|
||||
int real_rows = rows;
|
||||
int real_cols = cols;
|
||||
if (real_rows == 0)
|
||||
real_rows = (num + real_cols - 1) / real_cols;
|
||||
else
|
||||
real_cols = (num + real_rows - 1) / real_rows;
|
||||
|
||||
Insets ins = parent.getInsets ();
|
||||
// We subtract out an extra gap here because the gaps are only
|
||||
// between cells.
|
||||
w = ins.left + ins.right + real_cols * (w + hgap) - hgap;
|
||||
h = ins.top + ins.bottom + real_rows * (h + vgap) - vgap;
|
||||
return new Dimension (w, h);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @serial The number of columns in the grid.
|
||||
*/
|
||||
private int cols;
|
||||
|
||||
/**
|
||||
* @serial The number of rows in the grid.
|
||||
*/
|
||||
private int rows;
|
||||
|
||||
/**
|
||||
* @serial The horizontal gap between columns
|
||||
*/
|
||||
private int hgap;
|
||||
|
||||
/**
|
||||
* @serial The vertical gap between rows
|
||||
*/
|
||||
private int vgap;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/* HeadlessException.java -- operation not possible in headless environment
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This exception is thrown when code dependent on a keyboard, mouse, or
|
||||
* display is executed in a headless environment.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.4
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class HeadlessException extends UnsupportedOperationException
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.4+.
|
||||
*/
|
||||
private static final long serialVersionUID = 167183644944358563L;
|
||||
|
||||
/**
|
||||
* Create a new instance with no detailed error message.
|
||||
*/
|
||||
public HeadlessException()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with the specified detailed error message.
|
||||
*
|
||||
* @param message the detailed error message
|
||||
*/
|
||||
public HeadlessException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
} // class HeadlessException
|
||||
@@ -0,0 +1,71 @@
|
||||
/* IllegalComponentStateException.java -- bad component state
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This exception is thrown when the requested operation failed because
|
||||
* a component was not in the proper state.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class IllegalComponentStateException extends IllegalStateException
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -1889339587208144238L;
|
||||
|
||||
/**
|
||||
* Create a new instance with no detailed error message.
|
||||
*/
|
||||
public IllegalComponentStateException()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with the specified detailed error message.
|
||||
*
|
||||
* @param message the detailed error message
|
||||
*/
|
||||
public IllegalComponentStateException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
} // class IllegalComponentStateException
|
||||
@@ -0,0 +1,203 @@
|
||||
/* Image.java -- superclass for images
|
||||
Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.FilteredImageSource;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.image.ReplicateScaleFilter;
|
||||
|
||||
/**
|
||||
* This is the abstract superclass of all image objects in Java.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public abstract class Image
|
||||
{
|
||||
/**
|
||||
* This variable is returned whenever a property that is not defined
|
||||
* is requested.
|
||||
*/
|
||||
// For debug purposes, this might as well be a unique string.
|
||||
public static final Object UndefinedProperty
|
||||
= new String("undefined property");
|
||||
|
||||
/**
|
||||
* Constant indicating that the default scaling algorithm should be used.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public static final int SCALE_DEFAULT = 1;
|
||||
|
||||
/**
|
||||
* Constant indicating that a fast scaling algorithm should be used.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public static final int SCALE_FAST = 2;
|
||||
|
||||
/**
|
||||
* Constant indicating that a smooth scaling algorithm should be used.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public static final int SCALE_SMOOTH = 4;
|
||||
|
||||
/**
|
||||
* Constant indicating that the <code>ReplicateScaleFilter</code> class
|
||||
* algorithm should be used for scaling.
|
||||
*
|
||||
* @see ReplicateScaleFilter
|
||||
* @since 1.1
|
||||
*/
|
||||
public static final int SCALE_REPLICATE = 8;
|
||||
|
||||
/**
|
||||
* Constant indicating that the area averaging scaling algorithm should be
|
||||
* used.
|
||||
*
|
||||
* @see java.awt.image.AreaAveragingScaleFilter
|
||||
* @since 1.1
|
||||
*/
|
||||
public static final int SCALE_AREA_AVERAGING = 16;
|
||||
|
||||
/**
|
||||
* A default constructor for subclasses.
|
||||
*/
|
||||
public Image()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the image, or -1 if it is unknown. If the
|
||||
* image width is unknown, the observer object will be notified when
|
||||
* the value is known.
|
||||
*
|
||||
* @param observer the image observer for this object
|
||||
* @return the width in pixels
|
||||
* @see #getHeight(ImageObserver)
|
||||
*/
|
||||
public abstract int getWidth(ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Returns the height of the image, or -1 if it is unknown. If the
|
||||
* image height is unknown, the observer object will be notified when
|
||||
* the value is known.
|
||||
*
|
||||
* @param observer the image observer for this object
|
||||
* @return the height in pixels
|
||||
* @see #getWidth(ImageObserver)
|
||||
*/
|
||||
public abstract int getHeight(ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Returns the image producer object for this object. The producer is the
|
||||
* object which generates pixels for this image.
|
||||
*
|
||||
* @return the image producer for this object
|
||||
*/
|
||||
public abstract ImageProducer getSource();
|
||||
|
||||
/**
|
||||
* Returns a graphics context object for drawing an off-screen object.
|
||||
* This method is only valid for off-screen objects.
|
||||
*
|
||||
* @return a graphics context object for an off-screen object
|
||||
* @see Graphics#getcreateImage(int, int)
|
||||
*/
|
||||
public abstract Graphics getGraphics();
|
||||
|
||||
/**
|
||||
* This method requests a named property for an object. The value of the
|
||||
* property is returned. The value <code>UndefinedProperty</code> is
|
||||
* returned if there is no property with the specified name. The value
|
||||
* <code>null</code> is returned if the properties for the object are
|
||||
* not yet known. In this case, the specified image observer is notified
|
||||
* when the properties are known.
|
||||
*
|
||||
* @param name the requested property name
|
||||
* @param observer the image observer for this object
|
||||
* @return the named property, if available
|
||||
* @see #UndefinedProperty
|
||||
*/
|
||||
public abstract Object getProperty(String name, ImageObserver observer);
|
||||
|
||||
/**
|
||||
* Scales the image to the requested dimension. A new Image with asynchronous
|
||||
* loading will be produced according to the hints of the algorithm
|
||||
* requested. If either the width or height is non-positive, it is adjusted
|
||||
* to preserve the original aspect ratio.
|
||||
*
|
||||
* @param width the width of the scaled image
|
||||
* @param height the height of the scaled image
|
||||
* @param flags a value indicating the algorithm to use
|
||||
* @return the scaled <code>Image</code> object
|
||||
* @see #SCALE_DEFAULT
|
||||
* @see #SCALE_FAST
|
||||
* @see #SCALE_SMOOTH
|
||||
* @see #SCALE_REPLICATE
|
||||
* @see #SCALE_AREA_AVERAGING
|
||||
* @since 1.1
|
||||
*/
|
||||
public Image getScaledInstance(int width, int height, int flags)
|
||||
{
|
||||
switch (flags)
|
||||
{
|
||||
case SCALE_DEFAULT:
|
||||
case SCALE_FAST:
|
||||
case SCALE_REPLICATE:
|
||||
ImageProducer producer =
|
||||
new FilteredImageSource(this.getSource(),
|
||||
new ReplicateScaleFilter(width, height));
|
||||
return Toolkit.getDefaultToolkit().createImage(producer);
|
||||
case SCALE_SMOOTH:
|
||||
case SCALE_AREA_AVERAGING:
|
||||
default:
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes (that is, destroys) any resources used for this image. This
|
||||
* includes the actual image data.
|
||||
*/
|
||||
public abstract void flush();
|
||||
} // class Image
|
||||
@@ -0,0 +1,107 @@
|
||||
/* ImageCapabilities.java -- the capabilities of an image buffer
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This class represents the capabilities of an image buffer. An
|
||||
* image buffer may be backed by accelerated graphics resources.
|
||||
* Those resources may or may not be volatile. This class is used to
|
||||
* describe these image buffer characteristics.
|
||||
*/
|
||||
public class ImageCapabilities implements Cloneable
|
||||
{
|
||||
/**
|
||||
* Whether or not this the image buffer uses accelerated graphics
|
||||
* resources.
|
||||
*/
|
||||
private final boolean accelerated;
|
||||
|
||||
/**
|
||||
* Create a new image capability descriptor.
|
||||
*
|
||||
* @param accelerated true if the image buffer uses accelerated
|
||||
* graphics resources
|
||||
*/
|
||||
public ImageCapabilities(boolean accelerated)
|
||||
{
|
||||
this.accelerated = accelerated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the image buffer uses accelerated graphics
|
||||
* resources.
|
||||
*
|
||||
* @return true if the image buffer uses accelerated graphics
|
||||
* resources; false otherwise
|
||||
*/
|
||||
public boolean isAccelerated()
|
||||
{
|
||||
return accelerated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the image buffer's resources are volatile,
|
||||
* meaning that they can be reclaimed by the graphics system at any
|
||||
* time.
|
||||
*
|
||||
* @return true if the image buffer's resources are volatile; false
|
||||
* otherwise
|
||||
*/
|
||||
public boolean isTrueVolatile()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone this image capability descriptor.
|
||||
*
|
||||
* @return a clone of this image capability descriptor
|
||||
*/
|
||||
public Object clone()
|
||||
{
|
||||
try
|
||||
{
|
||||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
throw (Error) new InternalError().initCause(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/* Insets.java -- information about a container border
|
||||
Copyright (C) 1999, 2000, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class represents the "margin" or space around a container.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @status
|
||||
*/
|
||||
public class Insets implements Cloneable, Serializable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -2272572637695466749L;
|
||||
|
||||
/**
|
||||
* The gap from the top.
|
||||
*
|
||||
* @serial the top inset
|
||||
*/
|
||||
public int top;
|
||||
|
||||
/**
|
||||
* The gap from the left.
|
||||
*
|
||||
* @serial the left inset
|
||||
*/
|
||||
public int left;
|
||||
|
||||
/**
|
||||
* The gap from the bottom.
|
||||
*
|
||||
* @serial the bottom inset
|
||||
*/
|
||||
public int bottom;
|
||||
|
||||
/**
|
||||
* The gap from the right.
|
||||
*
|
||||
* @serial the right inset
|
||||
*/
|
||||
public int right;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Inset</code> with the specified
|
||||
* inset values.
|
||||
*
|
||||
* @param top the top inset
|
||||
* @param left the left inset
|
||||
* @param bottom the bottom inset
|
||||
* @param right the right inset
|
||||
*/
|
||||
public Insets(int top, int left, int bottom, int right)
|
||||
{
|
||||
this.top = top;
|
||||
this.left = left;
|
||||
this.bottom = bottom;
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this object is equal to the specified object. The other
|
||||
* object must be an instance of Insets with identical field values.
|
||||
*
|
||||
* @param obj the object to test against
|
||||
* @return true if the specified object is equal to this one
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (! (obj instanceof Insets))
|
||||
return false;
|
||||
Insets i = (Insets) obj;
|
||||
return top == i.top && bottom == i.bottom
|
||||
&& left == i.left && right == i.right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hashcode for this instance. The formula is unspecified, but
|
||||
* appears to be <code>XXX what is it? </code>.
|
||||
*
|
||||
* @return the hashcode
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
// This can't be right...
|
||||
return top + bottom + left + right;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object, which will be non-null.
|
||||
* The format is unspecified, but appears to be <code>XXX what is it?</code>.
|
||||
*
|
||||
* @return a string representation of this object
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getName() + "(top=" + top + ",bottom=" + bottom +
|
||||
",left=" + left + ",right=" + right + ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of this object.
|
||||
*
|
||||
* @return a copy of this object
|
||||
*/
|
||||
public Object clone()
|
||||
{
|
||||
try
|
||||
{
|
||||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
throw (Error) new InternalError().initCause(e); // Impossible
|
||||
}
|
||||
}
|
||||
} // class Insets
|
||||
@@ -0,0 +1,75 @@
|
||||
/* ItemSelectable.java -- items that can be selected
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
/**
|
||||
* This interface is for objects that can have one or more items selected.
|
||||
* For example, radio buttons.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface ItemSelectable
|
||||
{
|
||||
/**
|
||||
* Returns the list of objects that are selected in this component.
|
||||
*
|
||||
* @return the list of selected objects, or null
|
||||
*/
|
||||
Object[] getSelectedObjects();
|
||||
|
||||
/**
|
||||
* Adds an item listener to this object. It will receive selection events
|
||||
* for this object by the user (but not programatically). If listener is
|
||||
* null, it is ignored.
|
||||
*
|
||||
* @param listener the item listener to add
|
||||
*/
|
||||
void addItemListener(ItemListener listener);
|
||||
|
||||
/**
|
||||
* Removes an item listener from this object.
|
||||
*
|
||||
* @param listener the item listener to remove
|
||||
*/
|
||||
void removeItemListener(ItemListener listener);
|
||||
} // interface ItemSelectable
|
||||
@@ -0,0 +1,500 @@
|
||||
/* JobAttributes.java --
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* Needs documentation...
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.3
|
||||
* @status updated to 1.4, lacks documentation
|
||||
*/
|
||||
public final class JobAttributes implements Cloneable
|
||||
{
|
||||
public static final class DefaultSelectionType extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES = { "all", "range", "selection" };
|
||||
public static final DefaultSelectionType ALL
|
||||
= new DefaultSelectionType(0);
|
||||
public static final DefaultSelectionType RANGE
|
||||
= new DefaultSelectionType(1);
|
||||
public static final DefaultSelectionType SELECTION
|
||||
= new DefaultSelectionType(2);
|
||||
private DefaultSelectionType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class DefaultSelectionType
|
||||
|
||||
public static final class DestinationType extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES = { "file", "printer" };
|
||||
public static final DestinationType FILE = new DestinationType(0);
|
||||
public static final DestinationType PRINTER = new DestinationType(1);
|
||||
private DestinationType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class DestinationType
|
||||
|
||||
public static final class DialogType extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES = { "common", "native", "none" };
|
||||
public static final DialogType COMMON = new DialogType(0);
|
||||
public static final DialogType NATIVE = new DialogType(1);
|
||||
public static final DialogType NONE = new DialogType(2);
|
||||
private DialogType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class DialogType
|
||||
|
||||
public static final class MultipleDocumentHandlingType
|
||||
extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES = {
|
||||
"separate-documents-collated-copies",
|
||||
"separate-documents-uncollated-copies"
|
||||
};
|
||||
public static final MultipleDocumentHandlingType
|
||||
SEPARATE_DOCUMENTS_COLLATED_COPIES
|
||||
= new MultipleDocumentHandlingType(0);
|
||||
public static final MultipleDocumentHandlingType
|
||||
SEPARATE_DOCUMENTS_UNCOLLATED_COPIES
|
||||
= new MultipleDocumentHandlingType(1);
|
||||
private MultipleDocumentHandlingType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class MultipleDocumentHandlingType
|
||||
|
||||
public static final class SidesType extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES
|
||||
= { "one-sided", "two-sided-long-edge", "two-sided-short-edge" };
|
||||
public static final SidesType ONE_SIDED = new SidesType(0);
|
||||
public static final SidesType TWO_SIDED_LONG_EDGE = new SidesType(1);
|
||||
public static final SidesType TWO_SIDED_SHORT_EDGE = new SidesType(2);
|
||||
private SidesType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class SidesType
|
||||
|
||||
private int copies;
|
||||
private DefaultSelectionType selection;
|
||||
private DestinationType destination;
|
||||
private DialogType dialog;
|
||||
private String filename;
|
||||
private int maxPage;
|
||||
private int minPage;
|
||||
private MultipleDocumentHandlingType multiple;
|
||||
private int[][] pageRanges; // null for default value
|
||||
private int fromPage; // 0 for default value
|
||||
private int toPage; // 0 for default value
|
||||
private String printer;
|
||||
private SidesType sides;
|
||||
|
||||
public JobAttributes()
|
||||
{
|
||||
copies = 1;
|
||||
selection = DefaultSelectionType.ALL;
|
||||
destination = DestinationType.PRINTER;
|
||||
dialog = DialogType.NATIVE;
|
||||
maxPage = Integer.MAX_VALUE;
|
||||
minPage = 1;
|
||||
multiple
|
||||
= MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES;
|
||||
sides = SidesType.ONE_SIDED;
|
||||
}
|
||||
|
||||
public JobAttributes(JobAttributes attr)
|
||||
{
|
||||
set(attr);
|
||||
}
|
||||
|
||||
public JobAttributes(int copies, DefaultSelectionType selection,
|
||||
DestinationType destination, DialogType dialog,
|
||||
String filename, int max, int min,
|
||||
MultipleDocumentHandlingType multiple,
|
||||
int[][] pageRanges, String printer, SidesType sides)
|
||||
{
|
||||
if (copies <= 0 || selection == null || destination == null
|
||||
|| dialog == null || max < min || min <= 0 || multiple == null
|
||||
|| sides == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.copies = copies;
|
||||
this.selection = selection;
|
||||
this.destination = destination;
|
||||
this.dialog = dialog;
|
||||
this.filename = filename;
|
||||
maxPage = max;
|
||||
minPage = min;
|
||||
this.multiple = multiple;
|
||||
setPageRanges(pageRanges);
|
||||
this.printer = printer;
|
||||
this.sides = sides;
|
||||
}
|
||||
|
||||
public Object clone()
|
||||
{
|
||||
return new JobAttributes(this);
|
||||
}
|
||||
|
||||
public void set(JobAttributes attr)
|
||||
{
|
||||
copies = attr.copies;
|
||||
selection = attr.selection;
|
||||
destination = attr.destination;
|
||||
dialog = attr.dialog;
|
||||
filename = attr.filename;
|
||||
maxPage = attr.maxPage;
|
||||
minPage = attr.minPage;
|
||||
multiple = attr.multiple;
|
||||
pageRanges = (int[][]) attr.pageRanges.clone();
|
||||
printer = attr.printer;
|
||||
sides = attr.sides;
|
||||
fromPage = attr.fromPage;
|
||||
toPage = attr.toPage;
|
||||
}
|
||||
|
||||
public int getCopies()
|
||||
{
|
||||
return copies;
|
||||
}
|
||||
|
||||
public void setCopies(int copies)
|
||||
{
|
||||
if (copies <= 0)
|
||||
throw new IllegalArgumentException();
|
||||
this.copies = copies;
|
||||
}
|
||||
|
||||
public void setCopiesToDefault()
|
||||
{
|
||||
copies = 1;
|
||||
}
|
||||
|
||||
public DefaultSelectionType getDefaultSelection()
|
||||
{
|
||||
return selection;
|
||||
}
|
||||
|
||||
public void setDefaultSelection(DefaultSelectionType selection)
|
||||
{
|
||||
if (selection == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.selection = selection;
|
||||
}
|
||||
|
||||
public DestinationType getDestination()
|
||||
{
|
||||
return destination;
|
||||
}
|
||||
|
||||
public void setDestination(DestinationType destination)
|
||||
{
|
||||
if (destination == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.destination = destination;
|
||||
}
|
||||
|
||||
public DialogType getDialog()
|
||||
{
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public void setDialog(DialogType dialog)
|
||||
{
|
||||
if (dialog == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
public String getFileName()
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void setFileName(String filename)
|
||||
{
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public int getFromPage()
|
||||
{
|
||||
return fromPage != 0 ? fromPage
|
||||
: pageRanges != null ? pageRanges[0][0]
|
||||
: toPage != 0 ? toPage : minPage;
|
||||
}
|
||||
|
||||
public void setFromPage(int fromPage)
|
||||
{
|
||||
if (fromPage < minPage || (fromPage > toPage && toPage != 0)
|
||||
|| fromPage > maxPage)
|
||||
throw new IllegalArgumentException();
|
||||
if (pageRanges == null)
|
||||
this.fromPage = fromPage;
|
||||
}
|
||||
|
||||
public int getMaxPage()
|
||||
{
|
||||
return maxPage;
|
||||
}
|
||||
|
||||
public void setMaxPage(int maxPage)
|
||||
{
|
||||
if (maxPage < minPage)
|
||||
throw new IllegalArgumentException();
|
||||
this.maxPage = maxPage;
|
||||
if (maxPage < fromPage)
|
||||
fromPage = maxPage;
|
||||
if (maxPage < toPage)
|
||||
toPage = maxPage;
|
||||
if (pageRanges != null)
|
||||
{
|
||||
int i = pageRanges.length - 1;
|
||||
while (i >= 0 && maxPage < pageRanges[i][1])
|
||||
i--;
|
||||
if (maxPage >= pageRanges[++i][0])
|
||||
pageRanges[i++][1] = maxPage;
|
||||
if (i == 0)
|
||||
pageRanges = null;
|
||||
else if (i < pageRanges.length)
|
||||
{
|
||||
int[][] tmp = new int[i][];
|
||||
System.arraycopy(pageRanges, 0, tmp, 0, i);
|
||||
pageRanges = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getMinPage()
|
||||
{
|
||||
return minPage;
|
||||
}
|
||||
|
||||
public void setMinPage(int minPage)
|
||||
{
|
||||
if (minPage <= 0 || minPage > maxPage)
|
||||
throw new IllegalArgumentException();
|
||||
this.minPage = minPage;
|
||||
if (minPage > toPage)
|
||||
toPage = minPage;
|
||||
if (minPage > fromPage)
|
||||
fromPage = minPage;
|
||||
if (pageRanges != null)
|
||||
{
|
||||
int size = pageRanges.length;
|
||||
int i = 0;
|
||||
while (i < size && minPage > pageRanges[i][0])
|
||||
i++;
|
||||
if (minPage <= pageRanges[i - 1][1])
|
||||
pageRanges[--i][0] = minPage;
|
||||
if (i == size)
|
||||
pageRanges = null;
|
||||
else if (i > 0)
|
||||
{
|
||||
int[][] tmp = new int[size - i][];
|
||||
System.arraycopy(pageRanges, i, tmp, 0, size - i);
|
||||
pageRanges = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MultipleDocumentHandlingType getMultipleDocumentHandling()
|
||||
{
|
||||
return multiple;
|
||||
}
|
||||
|
||||
public void setMultipleDocumentHandling
|
||||
(MultipleDocumentHandlingType multiple)
|
||||
{
|
||||
if (multiple == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.multiple = multiple;
|
||||
}
|
||||
|
||||
public void setMultipleDocumentHandlingToDefault()
|
||||
{
|
||||
multiple
|
||||
= MultipleDocumentHandlingType.SEPARATE_DOCUMENTS_UNCOLLATED_COPIES;
|
||||
}
|
||||
|
||||
public int[][] getPageRanges()
|
||||
{
|
||||
if (pageRanges == null)
|
||||
return new int[][] { { getFromPage(), getToPage() } };
|
||||
// Perform a deep clone, so user code cannot affect original arrays.
|
||||
int i = pageRanges.length;
|
||||
int[][] result = new int[i][];
|
||||
while (--i >= 0)
|
||||
result[i] = (int[]) pageRanges[i].clone();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setPageRanges(int[][] pageRanges)
|
||||
{
|
||||
int size = pageRanges == null ? 0 : pageRanges.length;
|
||||
if (size == 0)
|
||||
throw new IllegalArgumentException();
|
||||
while (--size >= 0)
|
||||
{
|
||||
int[] range = pageRanges[size];
|
||||
if (range == null || range.length != 2
|
||||
|| range[0] < minPage || range[1] < range[0] || range[1] > maxPage
|
||||
|| (size != 0 && range[0] <= pageRanges[size - 1][1]))
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
size = pageRanges.length;
|
||||
if (fromPage > 0 && pageRanges[0][0] > fromPage)
|
||||
fromPage = pageRanges[0][0];
|
||||
if (toPage > 0 && pageRanges[size - 1][1] < toPage)
|
||||
toPage = pageRanges[size - 1][1];
|
||||
this.pageRanges = new int[size][];
|
||||
while (--size >= 0)
|
||||
this.pageRanges[size] = (int[]) pageRanges[size].clone();
|
||||
}
|
||||
|
||||
public String getPrinter()
|
||||
{
|
||||
return printer;
|
||||
}
|
||||
|
||||
public void setPrinter(String printer)
|
||||
{
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
public SidesType getSides()
|
||||
{
|
||||
return sides;
|
||||
}
|
||||
|
||||
public void setSides(SidesType sides)
|
||||
{
|
||||
if (sides == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.sides = sides;
|
||||
}
|
||||
|
||||
public void setSidesToDefault()
|
||||
{
|
||||
sides = SidesType.ONE_SIDED;
|
||||
}
|
||||
|
||||
public int getToPage()
|
||||
{
|
||||
return toPage != 0 ? toPage
|
||||
: pageRanges != null ? pageRanges[pageRanges.length - 1][1]
|
||||
: fromPage != 0 ? fromPage : maxPage;
|
||||
}
|
||||
|
||||
public void setToPage(int toPage)
|
||||
{
|
||||
if (toPage < minPage || (fromPage > toPage && fromPage != 0)
|
||||
|| toPage > maxPage)
|
||||
throw new IllegalArgumentException();
|
||||
if (pageRanges == null)
|
||||
this.toPage = toPage;
|
||||
}
|
||||
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (! (o instanceof JobAttributes))
|
||||
return false;
|
||||
JobAttributes ja = (JobAttributes) o;
|
||||
if (copies != ja.copies || selection != ja.selection
|
||||
|| destination != ja.destination || dialog != ja.dialog
|
||||
|| ! filename.equals(ja.filename) || maxPage != ja.maxPage
|
||||
|| minPage != ja.minPage || multiple != ja.multiple
|
||||
|| fromPage != ja.fromPage || toPage != ja.toPage
|
||||
|| ! printer.equals(ja.printer) || sides != ja.sides
|
||||
|| (pageRanges == null) != (ja.pageRanges == null))
|
||||
return false;
|
||||
if (pageRanges != ja.pageRanges)
|
||||
for (int i = pageRanges.length; --i >= 0; )
|
||||
if (pageRanges[i][0] != ja.pageRanges[i][0]
|
||||
|| pageRanges[i][1] != ja.pageRanges[i][1])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
int hash = (selection.value << 6) ^ (destination.value << 5)
|
||||
^ (dialog.value << 3) ^ (multiple.value << 2) ^ sides.value
|
||||
^ (filename == null ? 0 : filename.hashCode())
|
||||
^ (printer == null ? 0 : printer.hashCode());
|
||||
// The effect of the above fields on the hashcode match the JDK. However,
|
||||
// I am unable to reverse engineer the effect of the fields listed below,
|
||||
// so I am using my own implementation. Note that this still satisfies
|
||||
// the general contract of hashcode, it just doesn't match the JDK.
|
||||
hash ^= (copies << 27) ^ (maxPage << 22) ^ (minPage << 17);
|
||||
if (pageRanges == null)
|
||||
hash ^= (getFromPage() << 13) ^ (getToPage() << 8);
|
||||
else
|
||||
for (int i = pageRanges.length; --i >= 0; )
|
||||
hash ^= (pageRanges[i][0] << 13) ^ (pageRanges[i][1] << 8);
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer s = new StringBuffer("copies=").append(copies)
|
||||
.append(",defaultSelection=").append(selection).append(",destination=")
|
||||
.append(destination).append(",dialog=").append(dialog)
|
||||
.append(",fileName=").append(filename).append(",fromPage=")
|
||||
.append(getFromPage()).append(",maxPage=").append(maxPage)
|
||||
.append(",minPage=").append(minPage)
|
||||
.append(",multiple-document-handling=").append(multiple)
|
||||
.append(",page-ranges=[");
|
||||
if (pageRanges == null)
|
||||
s.append(minPage).append(':').append(minPage).append(']');
|
||||
else
|
||||
for (int i = 0; i < pageRanges.length; i++)
|
||||
s.append(pageRanges[i][0]).append(':').append(pageRanges[i][1])
|
||||
.append(',');
|
||||
s.setLength(s.length() - 1);
|
||||
return s.append("],printer=").append(printer).append(",sides=")
|
||||
.append(sides).append(",toPage=").append(getToPage()).toString();
|
||||
}
|
||||
} // class JobAttributes
|
||||
@@ -0,0 +1,82 @@
|
||||
/* KeyEventDispatcher.java -- dispatches key events
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* An instance of this interface coordinates with a KeyboardFocusManager to
|
||||
* target and dispatch all key events. This allows retargeting, consuming,
|
||||
* changing, or otherwise manipulating the key event before sending it on to
|
||||
* a target.
|
||||
*
|
||||
* <p>By default, the KeyboardFocusManager is the sink for all key events not
|
||||
* dispatched by other dispatchers. Therefore, it is unnecessary for the user
|
||||
* to register the focus manager as a dispatcher.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see KeyboardFocusManager#addKeyEventDispatcher(KeyEventDispatcher)
|
||||
* @see KeyboardFocusManager#removeKeyEventDispatcher(KeyEventDispatcher)
|
||||
* @since 1.4
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface KeyEventDispatcher
|
||||
{
|
||||
/**
|
||||
* Called by the KeyboardFocusManager to request that a key event be
|
||||
* dispatched. The dispatcher is free to retarget the event, consume it,
|
||||
* dispatch it, or make other changes. This is usually done to allow
|
||||
* delivery of key events to objects other than the window in focus, such
|
||||
* as for navigating non-focusable components. If this dispatcher chooses
|
||||
* to dispatch the event itself, it should call <code>redispatchEvent</code>
|
||||
* to avoid infinite recursion.
|
||||
*
|
||||
* <p>If the return value is false, the KeyEvent is passed to the next
|
||||
* dispatcher in the chain, ending with the KeyboardFocusManager. If the
|
||||
* return value is true, the event has been consumed (although it might
|
||||
* have been ignored), and no further action will be taken on the event. Be
|
||||
* sure to check whether the event was consumed before dispatching it
|
||||
* further.
|
||||
*
|
||||
* @param e the key event
|
||||
* @return true if the event has been consumed
|
||||
* @see KeyboardFocusManager#redispatchEvent(Component, AWTEvent)
|
||||
*/
|
||||
boolean dispatchKeyEvent(KeyEvent e);
|
||||
} // interface KeyEventDispatcher
|
||||
@@ -0,0 +1,81 @@
|
||||
/* KeyEventPostProcessor.java -- performs actions after a key event dispatch
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
/**
|
||||
* An instance of this interface coordinates with a KeyboardFocusManager to
|
||||
* target and dispatch all key events that are otherwise unconsumed. This
|
||||
* allows events which take place when nothing has focus to still operate,
|
||||
* such as menu keyboard shortcuts.
|
||||
*
|
||||
* <p>By default, the KeyboardFocusManager is the sink for all key events not
|
||||
* post-processed elsewhere. Therefore, it is unnecessary for the user
|
||||
* to register the focus manager as a dispatcher.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see KeyboardFocusManager#addKeyEventPostProcessor(KeyEventPostProcessor)
|
||||
* @see KeyboardFocusManager#removeKeyEventPostProcessor(KeyEventPostProcessor)
|
||||
* @since 1.4
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface KeyEventPostProcessor
|
||||
{
|
||||
/**
|
||||
* Called by the KeyboardFocusManager to request that a key event be
|
||||
* post-processed. Typically, the event has already been dispatched and
|
||||
* handled, unless no object has focus. Thus, this allows global event
|
||||
* handling for things like menu shortcuts. If this post-processor chooses
|
||||
* to dispatch the event, it should call <code>redispatchEvent</code>
|
||||
* to avoid infinite recursion.
|
||||
*
|
||||
* <p>If the return value is false, the KeyEvent is passed to the next
|
||||
* dispatcher in the chain, ending with the KeyboardFocusManager. If the
|
||||
* return value is true, the event has been consumed (although it might
|
||||
* have been ignored), and no further action will be taken on the event. Be
|
||||
* sure to check whether the event was consumed before dispatching it
|
||||
* further.
|
||||
*
|
||||
* @param e the key event
|
||||
* @return true if the event has been consumed
|
||||
* @see KeyboardFocusManager#redispatchEvent(Component, AWTEvent)
|
||||
*/
|
||||
boolean postProcessKeyEvent(KeyEvent e);
|
||||
} // interface KeyEventPostProcessor
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,314 @@
|
||||
/* Label.java -- Java label widget
|
||||
Copyright (C) 1999, 2000, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.peer.LabelPeer;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
|
||||
/**
|
||||
* This component is used for displaying simple text strings that cannot
|
||||
* be edited by the user.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Tom Tromey (tromey@cygnus.com)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
*/
|
||||
public class Label extends Component implements Accessible
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Alignment constant aligning the text to the left of its window.
|
||||
*/
|
||||
public static final int LEFT = 0;
|
||||
|
||||
/**
|
||||
* Alignment constant aligning the text in the center of its window.
|
||||
*/
|
||||
public static final int CENTER = 1;
|
||||
|
||||
/**
|
||||
* Alignment constant aligning the text to the right of its window.
|
||||
*/
|
||||
public static final int RIGHT = 2;
|
||||
|
||||
// Serialization version constant:
|
||||
private static final long serialVersionUID = 3094126758329070636L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial Indicates the alignment of the text within this label's window.
|
||||
* This is one of the constants in this class. The default value is
|
||||
* <code>LEFT</code>.
|
||||
*/
|
||||
private int alignment;
|
||||
|
||||
/**
|
||||
* @serial The text displayed in the label
|
||||
*/
|
||||
private String text;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Label</code> with no text.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
||||
*/
|
||||
public
|
||||
Label()
|
||||
{
|
||||
this("", LEFT);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Label</code> with the specified
|
||||
* text that is aligned to the left.
|
||||
*
|
||||
* @param text The text of the label.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
||||
*/
|
||||
public
|
||||
Label(String text)
|
||||
{
|
||||
this(text, LEFT);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Label</code> with the specified
|
||||
* text and alignment.
|
||||
*
|
||||
* @param text The text of the label.
|
||||
* @param alignment The desired alignment for the text in this label,
|
||||
* which must be one of <code>LEFT</code>, <code>CENTER</code>, or
|
||||
* <code>RIGHT</code>.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
||||
*/
|
||||
public
|
||||
Label(String text, int alignment)
|
||||
{
|
||||
setAlignment (alignment);
|
||||
setText (text);
|
||||
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the constant indicating the alignment of the text in this
|
||||
* label. The value returned will be one of the alignment constants
|
||||
* from this class.
|
||||
*
|
||||
* @return The alignment of the text in the label.
|
||||
*/
|
||||
public int
|
||||
getAlignment()
|
||||
{
|
||||
return(alignment);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the text alignment of this label to the specified value.
|
||||
*
|
||||
* @param alignment The desired alignment for the text in this label,
|
||||
* which must be one of <code>LEFT</code>, <code>CENTER</code>, or
|
||||
* <code>RIGHT</code>.
|
||||
*/
|
||||
public synchronized void
|
||||
setAlignment(int alignment)
|
||||
{
|
||||
if (alignment != CENTER && alignment != LEFT && alignment != RIGHT)
|
||||
throw new IllegalArgumentException ("invalid alignment: " + alignment);
|
||||
this.alignment = alignment;
|
||||
if (peer != null)
|
||||
{
|
||||
LabelPeer lp = (LabelPeer) peer;
|
||||
lp.setAlignment (alignment);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the text displayed in this label.
|
||||
*
|
||||
* @return The text for this label.
|
||||
*/
|
||||
public String
|
||||
getText()
|
||||
{
|
||||
return(text);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the text in this label to the specified value.
|
||||
*
|
||||
* @param text The new text for this label.
|
||||
*/
|
||||
public synchronized void
|
||||
setText(String text)
|
||||
{
|
||||
this.text = text;
|
||||
|
||||
if (peer != null)
|
||||
{
|
||||
LabelPeer lp = (LabelPeer) peer;
|
||||
lp.setText (text);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Notifies this label that it has been added to a container, causing
|
||||
* the peer to be created. This method is called internally by the AWT
|
||||
* system.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit ().createLabel (this);
|
||||
super.addNotify ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a parameter string useful for debugging.
|
||||
*
|
||||
* @return A debugging string.
|
||||
*/
|
||||
protected String
|
||||
paramString()
|
||||
{
|
||||
return ("text=" + getText() + ",alignment=" +
|
||||
getAlignment() + "," + super.paramString());
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides accessibility support for the label.
|
||||
*/
|
||||
protected class AccessibleAWTLabel
|
||||
extends AccessibleAWTComponent
|
||||
{
|
||||
/**
|
||||
* For compatability with Sun's JDK 1.4.2 rev. 5
|
||||
*/
|
||||
private static final long serialVersionUID = -3568967560160480438L;
|
||||
|
||||
/**
|
||||
* Constructor for the accessible label.
|
||||
*/
|
||||
public AccessibleAWTLabel()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the accessible name for the label. This is
|
||||
* the text used in the label.
|
||||
*
|
||||
* @return a <code>String</code> containing the accessible
|
||||
* name for this label.
|
||||
*/
|
||||
public String getAccessibleName()
|
||||
{
|
||||
return getText();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the accessible role for the label.
|
||||
*
|
||||
* @return an instance of <code>AccessibleRole</code>, describing
|
||||
* the role of the label.
|
||||
*/
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.LABEL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>Label</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTLabel();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
} // class Label
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/* LayoutManager.java -- lay out elements in a Container
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This interface is for laying out containers in a particular sequence.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @see Container
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface LayoutManager
|
||||
{
|
||||
/**
|
||||
* Adds the specified component to the layout group.
|
||||
*
|
||||
* @param name the name of the component to add
|
||||
* @param component the component to add
|
||||
*/
|
||||
void addLayoutComponent(String name, Component component);
|
||||
|
||||
/**
|
||||
* Removes the specified component from the layout group.
|
||||
*
|
||||
* @param component the component to remove
|
||||
*/
|
||||
void removeLayoutComponent(Component component);
|
||||
|
||||
/**
|
||||
* Calculates the preferred size for this container, taking into account
|
||||
* the components it contains.
|
||||
*
|
||||
* @param parent the parent container to lay out
|
||||
* @return the preferred dimensions of this container
|
||||
* @see #minimumLayoutSize(Container)
|
||||
*/
|
||||
Dimension preferredLayoutSize(Container parent);
|
||||
|
||||
/**
|
||||
* Calculates the minimum size for this container, taking into account
|
||||
* the components it contains.
|
||||
*
|
||||
* @param parent the parent container to lay out
|
||||
* @return the minimum dimensions of this container
|
||||
* @see #preferredLayoutSize(Container)
|
||||
*/
|
||||
Dimension minimumLayoutSize(Container parent);
|
||||
|
||||
/**
|
||||
* Lays out the components in the given container.
|
||||
*
|
||||
* @param parent the container to lay out
|
||||
*/
|
||||
void layoutContainer(Container parent);
|
||||
} // interface LayoutManager
|
||||
@@ -0,0 +1,100 @@
|
||||
/* LayoutManager2.java -- enhanced layout manager
|
||||
Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* Layout manager for laying out containers based on contraints. The
|
||||
* constraints control how the layout will proceed.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @see LayoutManager
|
||||
* @see Container
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface LayoutManager2 extends LayoutManager
|
||||
{
|
||||
/**
|
||||
* Adds the specified component to the layout, with the specified
|
||||
* constraints object.
|
||||
*
|
||||
* @param component the component to add
|
||||
* @param constraints the constraints to satisfy
|
||||
*/
|
||||
void addLayoutComponent(Component component, Object constraints);
|
||||
|
||||
/**
|
||||
* Determines the maximum size of the specified target container.
|
||||
*
|
||||
* @param target the container to lay out
|
||||
* @return the maximum size of the container
|
||||
* @see Component#getMaximumSize()
|
||||
*/
|
||||
Dimension maximumLayoutSize(Container target);
|
||||
|
||||
/**
|
||||
* Returns the preferred X axis alignment for the specified target
|
||||
* container. This value will range from 0 to 1 where 0 is alignment
|
||||
* closest to the origin, 0.5 is centered, and 1 is aligned furthest
|
||||
* from the origin.
|
||||
*
|
||||
* @param target the target container
|
||||
* @return the x-axis alignment preference
|
||||
*/
|
||||
float getLayoutAlignmentX(Container target);
|
||||
|
||||
/**
|
||||
* Returns the preferred Y axis alignment for the specified target
|
||||
* container. This value will range from 0 to 1 where 0 is alignment
|
||||
* closest to the origin, 0.5 is centered, and 1 is aligned furthest
|
||||
* from the origin.
|
||||
*
|
||||
* @param target the target container
|
||||
* @return the y-axis alignment preference
|
||||
*/
|
||||
float getLayoutAlignmentY(Container target);
|
||||
|
||||
/**
|
||||
* Forces the layout manager to purge any cached information about the
|
||||
* layout of the target container. This will force it to be recalculated.
|
||||
*
|
||||
* @param target the target container
|
||||
*/
|
||||
void invalidateLayout(Container target);
|
||||
} // interface LayoutManager2
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,697 @@
|
||||
/* MediaTracker.java -- Class used for keeping track of images
|
||||
Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* This class is used for keeping track of the status of various media
|
||||
* objects.
|
||||
*
|
||||
* Media objects are tracked by assigning them an ID. It is possible
|
||||
* to assign the same ID to mutliple objects, effectivly grouping them
|
||||
* together. In this case the status flags ({@link #statusID}) and error flag
|
||||
* (@link #isErrorID} and {@link #getErrorsID}) are ORed together. This
|
||||
* means that you cannot say exactly which media object has which status,
|
||||
* at most you can say that there <em>are</em> certain media objects with
|
||||
* some certain status.
|
||||
*
|
||||
* At the moment only images are supported by this class.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Bryce McKinlay
|
||||
*/
|
||||
public class MediaTracker implements java.io.Serializable
|
||||
{
|
||||
/** Indicates that the media is still loading. */
|
||||
public static final int LOADING = 1 << 0;
|
||||
|
||||
/** Indicates that the loading operation has been aborted. */
|
||||
public static final int ABORTED = 1 << 1;
|
||||
|
||||
/** Indicates that an error has occured during loading of the media. */
|
||||
public static final int ERRORED = 1 << 2;
|
||||
|
||||
/** Indicates that the media has been successfully and completely loaded. */
|
||||
public static final int COMPLETE = 1 << 3;
|
||||
|
||||
/** The component on which the media is eventually been drawn. */
|
||||
Component target;
|
||||
|
||||
/** The head of the linked list of tracked media objects. */
|
||||
MediaEntry head;
|
||||
|
||||
/** Our serialVersionUID for serialization. */
|
||||
static final long serialVersionUID = -483174189758638095L;
|
||||
|
||||
/**
|
||||
* This represents a media object that is tracked by a MediaTracker.
|
||||
* It also implements a simple linked list.
|
||||
*/
|
||||
// FIXME: The serialized form documentation says MediaEntry is a
|
||||
// serializable field, but the serialized form of MediaEntry itself
|
||||
// doesn't appear to be documented.
|
||||
class MediaEntry implements ImageObserver
|
||||
{
|
||||
/** The ID of the media object. */
|
||||
int id;
|
||||
|
||||
/** The media object. (only images are supported ATM). */
|
||||
Image image;
|
||||
|
||||
/** The link to the next entry in the list. */
|
||||
MediaEntry next;
|
||||
|
||||
/** The tracking status. */
|
||||
int status;
|
||||
|
||||
/** The width of the image. */
|
||||
int width;
|
||||
|
||||
/** The height of the image. */
|
||||
int height;
|
||||
|
||||
/**
|
||||
* Receives notification from an {@link java.awt.image.ImageProducer}
|
||||
* that more data of the image is available.
|
||||
*
|
||||
* @param img the image that is updated
|
||||
* @param flags flags from the ImageProducer that indicate the status
|
||||
* of the loading process
|
||||
* @param x the X coordinate of the upper left corner of the image
|
||||
* @param y the Y coordinate of the upper left corner of the image
|
||||
* @param width the width of the image
|
||||
* @param height the height of the image
|
||||
*
|
||||
* @return <code>true</code> if more data is needed, <code>false</code>
|
||||
* otherwise
|
||||
*
|
||||
* @see java.awt.image.ImageObserver
|
||||
*/
|
||||
public boolean imageUpdate(Image img, int flags, int x, int y,
|
||||
int width, int height)
|
||||
{
|
||||
if ((flags & ABORT) != 0)
|
||||
status = ABORTED;
|
||||
else if ((flags & ERROR) != 0)
|
||||
status = ERRORED;
|
||||
else if ((flags & ALLBITS) != 0)
|
||||
status = COMPLETE;
|
||||
else
|
||||
status = 0;
|
||||
|
||||
synchronized (MediaTracker.this)
|
||||
{
|
||||
MediaTracker.this.notifyAll();
|
||||
}
|
||||
|
||||
// If status is not COMPLETE then we need more updates.
|
||||
return ((status & (COMPLETE | ERRORED | ABORTED)) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new MediaTracker for the component <code>c</code>. The
|
||||
* component should be the component that uses the media (i.e. draws it).
|
||||
*
|
||||
* @param c the Component that wants to use the media
|
||||
*/
|
||||
public MediaTracker(Component c)
|
||||
{
|
||||
target = c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image to the tracker with the specified <code>ID</code>.
|
||||
*
|
||||
* @param image the image to be added
|
||||
* @param id the ID of the tracker list to which the image is added
|
||||
*/
|
||||
public void addImage(Image image, int id)
|
||||
{
|
||||
MediaEntry e = new MediaEntry();
|
||||
e.id = id;
|
||||
e.image = image;
|
||||
synchronized(this)
|
||||
{
|
||||
e.next = head;
|
||||
head = e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an image to the tracker with the specified <code>ID</code>.
|
||||
* The image is expected to be rendered with the specified width and
|
||||
* height.
|
||||
*
|
||||
* @param image the image to be added
|
||||
* @param id the ID of the tracker list to which the image is added
|
||||
* @param width the width of the image
|
||||
* @param height the height of the image
|
||||
*/
|
||||
public void addImage(Image image, int id, int width, int height)
|
||||
{
|
||||
MediaEntry e = new MediaEntry();
|
||||
e.id = id;
|
||||
e.image = image;
|
||||
e.width = width;
|
||||
e.height = height;
|
||||
synchronized(this)
|
||||
{
|
||||
e.next = head;
|
||||
head = e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if all media objects have finished loading, i.e. are
|
||||
* {@link #COMPLETE}, {@link #ABORTED} or {@link #ERRORED}.
|
||||
*
|
||||
* If the media objects are not already loading, a call to this
|
||||
* method does <em>not</em> start loading. This is equivalent to
|
||||
* a call to <code>checkAll(false)</code>.
|
||||
*
|
||||
* @return if all media objects have finished loading either by beeing
|
||||
* complete, have been aborted or errored.
|
||||
*/
|
||||
public boolean checkAll()
|
||||
{
|
||||
return checkAll(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if all media objects have finished loading, i.e. are
|
||||
* {@link #COMPLETE}, {@link #ABORTED} or {@link #ERRORED}.
|
||||
*
|
||||
* If the media objects are not already loading, and <code>load</code>
|
||||
* is <code>true</code> then a call to this
|
||||
* method starts loading the media objects.
|
||||
*
|
||||
* @param load if <code>true</code> this method starts loading objects
|
||||
* that are not already loading
|
||||
*
|
||||
* @return if all media objects have finished loading either by beeing
|
||||
* complete, have been aborted or errored.
|
||||
*/
|
||||
public boolean checkAll(boolean load)
|
||||
{
|
||||
MediaEntry e = head;
|
||||
boolean result = true;
|
||||
|
||||
while (e != null)
|
||||
{
|
||||
if ((e.status & (COMPLETE | ERRORED | ABORTED)) == 0)
|
||||
{
|
||||
if (load && ((e.status & LOADING) == 0))
|
||||
{
|
||||
if (target.prepareImage(e.image, e))
|
||||
e.status = COMPLETE;
|
||||
else
|
||||
{
|
||||
e.status = LOADING;
|
||||
int flags = target.checkImage(e.image, e);
|
||||
if ((flags & ImageObserver.ABORT) != 0)
|
||||
e.status = ABORTED;
|
||||
else if ((flags & ImageObserver.ERROR) != 0)
|
||||
e.status = ERRORED;
|
||||
else if ((flags & ImageObserver.ALLBITS) != 0)
|
||||
e.status = COMPLETE;
|
||||
}
|
||||
boolean complete = (e.status
|
||||
& (COMPLETE | ABORTED | ERRORED)) != 0;
|
||||
if (!complete)
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
result = false;
|
||||
}
|
||||
e = e.next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if any of the registered media objects has encountered an error
|
||||
* during loading.
|
||||
*
|
||||
* @return <code>true</code> if at least one media object has encountered
|
||||
* an error during loading, <code>false</code> otherwise
|
||||
*
|
||||
*/
|
||||
public boolean isErrorAny()
|
||||
{
|
||||
MediaEntry e = head;
|
||||
while (e != null)
|
||||
{
|
||||
if ((e.status & ERRORED) != 0)
|
||||
return true;
|
||||
e = e.next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all media objects that have encountered errors during loading.
|
||||
*
|
||||
* @return an array of all media objects that have encountered errors
|
||||
* or <code>null</code> if there were no errors at all
|
||||
*/
|
||||
public Object[] getErrorsAny()
|
||||
{
|
||||
MediaEntry e = head;
|
||||
ArrayList result = null;
|
||||
while (e != null)
|
||||
{
|
||||
if ((e.status & ERRORED) != 0)
|
||||
{
|
||||
if (result == null)
|
||||
result = new ArrayList();
|
||||
result.add(e.image);
|
||||
}
|
||||
e = e.next;
|
||||
}
|
||||
if (result == null)
|
||||
return null;
|
||||
else
|
||||
return result.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for all media objects to finish loading, either by completing
|
||||
* successfully or by aborting or encountering an error.
|
||||
*
|
||||
* @throws InterruptedException if another thread interrupted the
|
||||
* current thread while waiting
|
||||
*/
|
||||
public void waitForAll() throws InterruptedException
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
while (checkAll(true) == false)
|
||||
wait();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for all media objects to finish loading, either by completing
|
||||
* successfully or by aborting or encountering an error.
|
||||
*
|
||||
* This method waits at most <code>ms</code> milliseconds. If the
|
||||
* media objects have not completed loading within this timeframe, this
|
||||
* method returns <code>false</code>, otherwise <code>true</code>.
|
||||
*
|
||||
* @param ms timeframe in milliseconds to wait for the media objects to
|
||||
* finish
|
||||
*
|
||||
* @return <code>true</code> if all media objects have successfully loaded
|
||||
* within the timeframe, <code>false</code> otherwise
|
||||
*
|
||||
* @throws InterruptedException if another thread interrupted the
|
||||
* current thread while waiting
|
||||
*/
|
||||
public boolean waitForAll(long ms) throws InterruptedException
|
||||
{
|
||||
long start = System.currentTimeMillis();
|
||||
boolean result = checkAll(true);
|
||||
synchronized (this)
|
||||
{
|
||||
while (result == false)
|
||||
{
|
||||
wait(ms);
|
||||
result = checkAll(true);
|
||||
if ((System.currentTimeMillis() - start) > ms)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status flags of all registered media objects ORed together.
|
||||
* If <code>load</code> is <code>true</code> then media objects that
|
||||
* are not already loading will be started to load.
|
||||
*
|
||||
* @param load if set to <code>true</code> then media objects that are
|
||||
* not already loading are started
|
||||
*
|
||||
* @return the status flags of all tracked media objects ORed together
|
||||
*/
|
||||
public int statusAll(boolean load)
|
||||
{
|
||||
int result = 0;
|
||||
MediaEntry e = head;
|
||||
while (e != null)
|
||||
{
|
||||
if (load && e.status == 0)
|
||||
{
|
||||
if (target.prepareImage(e.image, e))
|
||||
e.status = COMPLETE;
|
||||
else
|
||||
{
|
||||
e.status = LOADING;
|
||||
int flags = target.checkImage(e.image, e);
|
||||
if ((flags & ImageObserver.ABORT) != 0)
|
||||
e.status = ABORTED;
|
||||
else if ((flags & ImageObserver.ERROR) != 0)
|
||||
e.status = ERRORED;
|
||||
else if ((flags & ImageObserver.ALLBITS) != 0)
|
||||
e.status = COMPLETE;
|
||||
}
|
||||
}
|
||||
result |= e.status;
|
||||
e = e.next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the media objects with <code>ID</code> have completed loading.
|
||||
*
|
||||
* @param id the ID of the media objects to check
|
||||
*
|
||||
* @return <code>true</code> if all media objects with <code>ID</code>
|
||||
* have successfully finished
|
||||
*/
|
||||
public boolean checkID(int id)
|
||||
{
|
||||
return checkID(id, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the media objects with <code>ID</code> have completed loading.
|
||||
* If <code>load</code> is <code>true</code> then media objects that
|
||||
* are not already loading will be started to load.
|
||||
*
|
||||
* @param id the ID of the media objects to check
|
||||
* @param load if set to <code>true</code> then media objects that are
|
||||
* not already loading are started
|
||||
*
|
||||
* @return <code>true</code> if all media objects with <code>ID</code>
|
||||
* have successfully finished
|
||||
*/
|
||||
public boolean checkID(int id, boolean load)
|
||||
{
|
||||
MediaEntry e = head;
|
||||
boolean result = true;
|
||||
|
||||
while (e != null)
|
||||
{
|
||||
if (e.id == id && ((e.status & (COMPLETE | ABORTED | ERRORED)) == 0))
|
||||
{
|
||||
if (load && ((e.status & LOADING) == 0))
|
||||
{
|
||||
e.status = LOADING;
|
||||
if (target.prepareImage(e.image, e))
|
||||
e.status = COMPLETE;
|
||||
else
|
||||
{
|
||||
int flags = target.checkImage(e.image, e);
|
||||
if ((flags & ImageObserver.ABORT) != 0)
|
||||
e.status = ABORTED;
|
||||
else if ((flags & ImageObserver.ERROR) != 0)
|
||||
e.status = ERRORED;
|
||||
else if ((flags & ImageObserver.ALLBITS) != 0)
|
||||
e.status = COMPLETE;
|
||||
}
|
||||
boolean complete = (e.status
|
||||
& (COMPLETE | ABORTED | ERRORED)) != 0;
|
||||
if (!complete)
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
result = false;
|
||||
}
|
||||
e = e.next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if any of the media objects with <code>ID</code>
|
||||
* have encountered errors during loading, false otherwise.
|
||||
*
|
||||
* @param id the ID of the media objects to check
|
||||
*
|
||||
* @return <code>true</code> if any of the media objects with <code>ID</code>
|
||||
* have encountered errors during loading, false otherwise
|
||||
*/
|
||||
public boolean isErrorID(int id)
|
||||
{
|
||||
MediaEntry e = head;
|
||||
while (e != null)
|
||||
{
|
||||
if (e.id == id && ((e.status & ERRORED) != 0))
|
||||
return true;
|
||||
e = e.next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all media objects with the specified ID that have encountered
|
||||
* an error.
|
||||
*
|
||||
* @param id the ID of the media objects to check
|
||||
*
|
||||
* @return an array of all media objects with the specified ID that
|
||||
* have encountered an error
|
||||
*/
|
||||
public Object[] getErrorsID(int id)
|
||||
{
|
||||
MediaEntry e = head;
|
||||
ArrayList result = null;
|
||||
while (e != null)
|
||||
{
|
||||
if (e.id == id && ((e.status & ERRORED) != 0))
|
||||
{
|
||||
if (result == null)
|
||||
result = new ArrayList();
|
||||
result.add(e.image);
|
||||
}
|
||||
e = e.next;
|
||||
}
|
||||
if (result == null)
|
||||
return null;
|
||||
else
|
||||
return result.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for all media objects with the specified ID to finish loading,
|
||||
* either by completing successfully or by aborting or encountering an error.
|
||||
*
|
||||
* @param id the ID of the media objects to wait for
|
||||
*
|
||||
* @throws InterruptedException if another thread interrupted the
|
||||
* current thread while waiting
|
||||
*/
|
||||
public void waitForID(int id) throws InterruptedException
|
||||
{
|
||||
MediaEntry e = head;
|
||||
synchronized (this)
|
||||
{
|
||||
while (checkID (id, true) == false)
|
||||
wait();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for all media objects with the specified ID to finish loading,
|
||||
* either by completing successfully or by aborting or encountering an error.
|
||||
*
|
||||
* This method waits at most <code>ms</code> milliseconds. If the
|
||||
* media objects have not completed loading within this timeframe, this
|
||||
* method returns <code>false</code>, otherwise <code>true</code>.
|
||||
*
|
||||
* @param id the ID of the media objects to wait for
|
||||
* @param ms timeframe in milliseconds to wait for the media objects to
|
||||
* finish
|
||||
*
|
||||
* @return <code>true</code> if all media objects have successfully loaded
|
||||
* within the timeframe, <code>false</code> otherwise
|
||||
*
|
||||
* @throws InterruptedException if another thread interrupted the
|
||||
* current thread while waiting
|
||||
*/
|
||||
public boolean waitForID(int id, long ms) throws InterruptedException
|
||||
{
|
||||
MediaEntry e = head;
|
||||
long start = System.currentTimeMillis();
|
||||
boolean result = checkID(id, true);
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
while (result == false)
|
||||
{
|
||||
wait(ms);
|
||||
result = checkID(id, true);
|
||||
if ((System.currentTimeMillis() - start) > ms)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status flags of the media objects with the specified ID
|
||||
* ORed together.
|
||||
*
|
||||
* If <code>load</code> is <code>true</code> then media objects that
|
||||
* are not already loading will be started to load.
|
||||
*
|
||||
* @param load if set to <code>true</code> then media objects that are
|
||||
* not already loading are started
|
||||
*
|
||||
* @return the status flags of all tracked media objects ORed together
|
||||
*/
|
||||
public int statusID(int id, boolean load)
|
||||
{
|
||||
int result = 0;
|
||||
MediaEntry e = head;
|
||||
while (e != null)
|
||||
{
|
||||
if (e.id == id)
|
||||
{
|
||||
if (load && e.status == 0)
|
||||
{
|
||||
if (target.prepareImage(e.image, e))
|
||||
e.status = COMPLETE;
|
||||
else
|
||||
{
|
||||
e.status = LOADING;
|
||||
int flags = target.checkImage(e.image, e);
|
||||
if ((flags & ImageObserver.ABORT) != 0)
|
||||
e.status = ABORTED;
|
||||
else if ((flags & ImageObserver.ERROR) != 0)
|
||||
e.status = ERRORED;
|
||||
else if ((flags & ImageObserver.ALLBITS) != 0)
|
||||
e.status = COMPLETE;
|
||||
}
|
||||
}
|
||||
result |= e.status;
|
||||
}
|
||||
e = e.next;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an image from this MediaTracker.
|
||||
*
|
||||
* @param image the image to be removed
|
||||
*/
|
||||
public void removeImage(Image image)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
MediaEntry e = head;
|
||||
MediaEntry prev = null;
|
||||
while (e != null)
|
||||
{
|
||||
if (e.image == image)
|
||||
{
|
||||
if (prev == null)
|
||||
head = e.next;
|
||||
else
|
||||
prev.next = e.next;
|
||||
}
|
||||
prev = e;
|
||||
e = e.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an image with the specified ID from this MediaTracker.
|
||||
*
|
||||
* @param image the image to be removed
|
||||
*/
|
||||
public void removeImage(Image image, int id)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
MediaEntry e = head;
|
||||
MediaEntry prev = null;
|
||||
while (e != null)
|
||||
{
|
||||
if (e.id == id && e.image == image)
|
||||
{
|
||||
if (prev == null)
|
||||
head = e.next;
|
||||
else
|
||||
prev.next = e.next;
|
||||
}
|
||||
else
|
||||
prev = e;
|
||||
e = e.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an image with the specified ID and scale from this MediaTracker.
|
||||
*
|
||||
* @param image the image to be removed
|
||||
*/
|
||||
public void removeImage(Image image, int id, int width, int height)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
MediaEntry e = head;
|
||||
MediaEntry prev = null;
|
||||
while (e != null)
|
||||
{
|
||||
if (e.id == id && e.image == image
|
||||
&& e.width == width && e.height == height)
|
||||
{
|
||||
if (prev == null)
|
||||
head = e.next;
|
||||
else
|
||||
prev.next = e.next;
|
||||
}
|
||||
else
|
||||
prev = e;
|
||||
e = e.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,468 @@
|
||||
/* Menu.java -- A Java AWT Menu
|
||||
Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.peer.MenuPeer;
|
||||
import java.io.Serializable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
|
||||
/**
|
||||
* This class represents a pull down or tear off menu in Java's AWT.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class Menu extends MenuItem implements MenuContainer, Serializable
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization Constant
|
||||
private static final long serialVersionUID = -8809584163345499784L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The actual items in the menu
|
||||
*/
|
||||
private Vector items = new Vector();
|
||||
|
||||
/**
|
||||
* @serial Flag indicating whether or not this menu is a tear off
|
||||
*/
|
||||
private boolean tearOff;
|
||||
|
||||
/**
|
||||
* @serial Indicates whether or not this is a help menu.
|
||||
*/
|
||||
private boolean isHelpMenu;
|
||||
|
||||
/*
|
||||
* @serial Unused in this implementation, but present in Sun's
|
||||
* serialization spec. Value obtained via reflection.
|
||||
*/
|
||||
private int menuSerializedDataVersion = 1;
|
||||
|
||||
static final transient String separatorLabel = "-";
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Menu</code> with no label and that
|
||||
* is not a tearoff;
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
||||
*/
|
||||
public
|
||||
Menu()
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Menu</code> that is not a tearoff and
|
||||
* that has the specified label.
|
||||
*
|
||||
* @param label The menu label.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
||||
*/
|
||||
public
|
||||
Menu(String label)
|
||||
{
|
||||
this(label, false);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Menu</code> with the specified
|
||||
* label and tearoff status.
|
||||
*
|
||||
* @param label The label for this menu
|
||||
* @param isTearOff <code>true</code> if this menu is a tear off menu,
|
||||
* <code>false</code> otherwise.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
||||
*/
|
||||
public
|
||||
Menu(String label, boolean isTearOff)
|
||||
{
|
||||
super(label);
|
||||
|
||||
tearOff = isTearOff;
|
||||
|
||||
if (label.equals("Help"))
|
||||
isHelpMenu = true;
|
||||
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests whether or not this menu is a tearoff.
|
||||
*
|
||||
* @return <code>true</code> if this menu is a tearoff, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean
|
||||
isTearOff()
|
||||
{
|
||||
return(tearOff);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the number of items in this menu.
|
||||
*
|
||||
* @return The number of items in this menu.
|
||||
*/
|
||||
public int
|
||||
getItemCount()
|
||||
{
|
||||
return countItems ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of items in this menu.
|
||||
*
|
||||
* @return The number of items in this menu.
|
||||
*
|
||||
* @deprecated As of JDK 1.1, replaced by getItemCount().
|
||||
*/
|
||||
public int countItems ()
|
||||
{
|
||||
return items.size ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the item at the specified index.
|
||||
*
|
||||
* @return The item at the specified index.
|
||||
*
|
||||
* @exception ArrayIndexOutOfBoundsException If the index value is not valid.
|
||||
*/
|
||||
public MenuItem
|
||||
getItem(int index)
|
||||
{
|
||||
return((MenuItem)items.elementAt(index));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds the specified item to this menu. If it was previously part of
|
||||
* another menu, it is first removed from that menu.
|
||||
*
|
||||
* @param item The new item to add.
|
||||
*
|
||||
* @return The item that was added.
|
||||
*/
|
||||
public MenuItem
|
||||
add(MenuItem item)
|
||||
{
|
||||
items.addElement(item);
|
||||
if (item.parent != null)
|
||||
{
|
||||
item.parent.remove(item);
|
||||
}
|
||||
item.parent = this;
|
||||
|
||||
if (peer != null)
|
||||
{
|
||||
MenuPeer mp = (MenuPeer) peer;
|
||||
mp.addItem(item);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Add an item with the specified label to this menu.
|
||||
*
|
||||
* @param label The label of the menu item to add.
|
||||
*/
|
||||
public void
|
||||
add(String label)
|
||||
{
|
||||
add(new MenuItem(label));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Inserts the specified menu item into this menu at the specified index.
|
||||
*
|
||||
* @param item The menu item to add.
|
||||
* @param index The index of the menu item.
|
||||
*
|
||||
* @exception IllegalArgumentException If the index is less than zero.
|
||||
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
|
||||
*/
|
||||
public void
|
||||
insert(MenuItem item, int index)
|
||||
{
|
||||
if (index < 0)
|
||||
throw new IllegalArgumentException("Index is less than zero");
|
||||
|
||||
MenuPeer peer = (MenuPeer) getPeer();
|
||||
if (peer == null)
|
||||
return;
|
||||
|
||||
int count = getItemCount ();
|
||||
|
||||
if (index >= count)
|
||||
peer.addItem (item);
|
||||
else
|
||||
{
|
||||
for (int i = count - 1; i >= index; i--)
|
||||
peer.delItem (i);
|
||||
|
||||
peer.addItem (item);
|
||||
|
||||
for (int i = index; i < count; i++)
|
||||
peer.addItem ((MenuItem) items.elementAt (i));
|
||||
}
|
||||
|
||||
items.insertElementAt(item, index);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Inserts an item with the specified label into this menu at the specified index.
|
||||
*
|
||||
* @param label The label of the item to add.
|
||||
* @param index The index of the menu item.
|
||||
*
|
||||
* @exception IllegalArgumentException If the index is less than zero.
|
||||
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
|
||||
*/
|
||||
public void
|
||||
insert(String label, int index)
|
||||
{
|
||||
insert(new MenuItem(label), index);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds a separator bar at the current menu location.
|
||||
*/
|
||||
public void
|
||||
addSeparator()
|
||||
{
|
||||
add(new MenuItem(separatorLabel));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Inserts a separator bar at the specified index value.
|
||||
*
|
||||
* @param index The index at which to insert a separator bar.
|
||||
*
|
||||
* @exception IllegalArgumentException If the index is less than zero.
|
||||
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
|
||||
*/
|
||||
public void
|
||||
insertSeparator(int index)
|
||||
{
|
||||
insert(new MenuItem(separatorLabel), index);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Deletes the item at the specified index from this menu.
|
||||
*
|
||||
* @param index The index of the item to remove.
|
||||
*
|
||||
* @exception ArrayIndexOutOfBoundsException If the index is otherwise invalid.
|
||||
*/
|
||||
public synchronized void
|
||||
remove(int index)
|
||||
{
|
||||
items.removeElementAt(index);
|
||||
|
||||
MenuPeer mp = (MenuPeer)getPeer();
|
||||
if (mp != null)
|
||||
mp.delItem(index);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes the specifed item from the menu. If the specified component
|
||||
* does not exist, this method does nothing.
|
||||
*
|
||||
* @param item The component to remove.
|
||||
*/
|
||||
public void
|
||||
remove(MenuComponent item)
|
||||
{
|
||||
int index = items.indexOf(item);
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
remove(index);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes all the elements from this menu.
|
||||
*/
|
||||
public synchronized void
|
||||
removeAll()
|
||||
{
|
||||
int count = getItemCount();
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
// We must always remove item 0.
|
||||
remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Creates the native peer for this object.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit().createMenu(this);
|
||||
Enumeration e = items.elements();
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
MenuItem mi = (MenuItem)e.nextElement();
|
||||
mi.addNotify();
|
||||
}
|
||||
super.addNotify ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Destroys the native peer for this object.
|
||||
*/
|
||||
public void
|
||||
removeNotify()
|
||||
{
|
||||
Enumeration e = items.elements();
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
MenuItem mi = (MenuItem) e.nextElement();
|
||||
mi.removeNotify();
|
||||
}
|
||||
super.removeNotify();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this menu.
|
||||
*
|
||||
* @return A debugging string for this menu.
|
||||
*/
|
||||
public String
|
||||
paramString()
|
||||
{
|
||||
return (",tearOff=" + tearOff + ",isHelpMenu=" + isHelpMenu
|
||||
+ super.paramString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic Accessibility class for Menu. Details get provided in derived
|
||||
* classes.
|
||||
*/
|
||||
protected class AccessibleAWTMenu extends AccessibleAWTMenuItem
|
||||
{
|
||||
protected AccessibleAWTMenu()
|
||||
{
|
||||
}
|
||||
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.MENU;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>Menu</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTMenu();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
} // class Menu
|
||||
@@ -0,0 +1,423 @@
|
||||
/* MenuBar.java -- An AWT menu bar class
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.peer.MenuBarPeer;
|
||||
import java.awt.peer.MenuComponentPeer;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
|
||||
/**
|
||||
* This class implements a menu bar in the AWT system.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
*/
|
||||
public class MenuBar extends MenuComponent
|
||||
implements MenuContainer, Serializable, Accessible
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization Constant
|
||||
private static final long serialVersionUID = -4930327919388951260L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The menu used for providing help information
|
||||
*/
|
||||
private Menu helpMenu;
|
||||
|
||||
/**
|
||||
* @serial The menus contained in this menu bar.
|
||||
*/
|
||||
private Vector menus = new Vector();
|
||||
|
||||
/**
|
||||
* The accessible context for this component.
|
||||
*
|
||||
* @see #getAccessibleContext()
|
||||
* @serial ignored.
|
||||
*/
|
||||
private transient AccessibleContext accessibleContext;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>MenuBar</code>.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
||||
*/
|
||||
public
|
||||
MenuBar()
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the help menu for this menu bar. This may be <code>null</code>.
|
||||
*
|
||||
* @return The help menu for this menu bar.
|
||||
*/
|
||||
public Menu
|
||||
getHelpMenu()
|
||||
{
|
||||
return(helpMenu);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the help menu for this menu bar.
|
||||
*
|
||||
* @param menu The new help menu for this menu bar.
|
||||
*/
|
||||
public synchronized void
|
||||
setHelpMenu(Menu menu)
|
||||
{
|
||||
if (helpMenu != null)
|
||||
{
|
||||
helpMenu.removeNotify ();
|
||||
helpMenu.parent = null;
|
||||
}
|
||||
helpMenu = menu;
|
||||
|
||||
if (menu.parent != null)
|
||||
menu.parent.remove (menu);
|
||||
menu.parent = this;
|
||||
|
||||
MenuBarPeer peer = (MenuBarPeer) getPeer ();
|
||||
if (peer != null)
|
||||
{
|
||||
menu.addNotify();
|
||||
peer.addHelpMenu (menu);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/** Add a menu to this MenuBar. If the menu has already has a
|
||||
* parent, it is first removed from its old parent before being
|
||||
* added.
|
||||
*
|
||||
* @param menu The menu to add.
|
||||
*
|
||||
* @return The menu that was added.
|
||||
*/
|
||||
public synchronized Menu
|
||||
add(Menu menu)
|
||||
{
|
||||
if (menu.parent != null)
|
||||
menu.parent.remove (menu);
|
||||
|
||||
menu.parent = this;
|
||||
menus.addElement(menu);
|
||||
|
||||
if (peer != null)
|
||||
{
|
||||
menu.addNotify();
|
||||
}
|
||||
|
||||
return(menu);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes the menu at the specified index.
|
||||
*
|
||||
* @param index The index of the menu to remove from the menu bar.
|
||||
*/
|
||||
public synchronized void
|
||||
remove(int index)
|
||||
{
|
||||
Menu m = (Menu) menus.get (index);
|
||||
menus.remove (index);
|
||||
m.removeNotify ();
|
||||
m.parent = null;
|
||||
|
||||
if (peer != null)
|
||||
{
|
||||
MenuBarPeer mp = (MenuBarPeer) peer;
|
||||
mp.delMenu (index);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Removes the specified menu from the menu bar.
|
||||
*
|
||||
* @param menu The menu to remove from the menu bar.
|
||||
*/
|
||||
public void
|
||||
remove(MenuComponent menu)
|
||||
{
|
||||
int index = menus.indexOf(menu);
|
||||
if (index == -1)
|
||||
return;
|
||||
|
||||
remove(index);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this menu bar.
|
||||
*
|
||||
* @return The number of elements in the menu bar.
|
||||
*/
|
||||
public int
|
||||
getMenuCount()
|
||||
{
|
||||
return countMenus ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the number of elements in this menu bar.
|
||||
*
|
||||
* @return The number of elements in the menu bar.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of <code>getMenuCount()</code>.
|
||||
*/
|
||||
public int
|
||||
countMenus()
|
||||
{
|
||||
return menus.size () + (getHelpMenu () == null ? 0 : 1);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the menu at the specified index.
|
||||
*
|
||||
* @param index the index of the menu
|
||||
*
|
||||
* @return The requested menu.
|
||||
*
|
||||
* @exception ArrayIndexOutOfBoundsException If the index is not valid.
|
||||
*/
|
||||
public Menu
|
||||
getMenu(int index)
|
||||
{
|
||||
return((Menu)menus.elementAt(index));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Creates this object's native peer.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (getPeer() == null)
|
||||
setPeer((MenuComponentPeer)getToolkit().createMenuBar(this));
|
||||
Enumeration e = menus.elements();
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
Menu mi = (Menu)e.nextElement();
|
||||
mi.addNotify();
|
||||
}
|
||||
if (helpMenu != null)
|
||||
{
|
||||
helpMenu.addNotify();
|
||||
((MenuBarPeer) peer).addHelpMenu(helpMenu);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Destroys this object's native peer.
|
||||
*/
|
||||
public void
|
||||
removeNotify()
|
||||
{
|
||||
Enumeration e = menus.elements();
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
Menu mi = (Menu) e.nextElement();
|
||||
mi.removeNotify();
|
||||
}
|
||||
super.removeNotify();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a list of all shortcuts for the menus in this menu bar.
|
||||
*
|
||||
* @return A list of all shortcuts for the menus in this menu bar.
|
||||
*/
|
||||
public synchronized Enumeration
|
||||
shortcuts()
|
||||
{
|
||||
Vector shortcuts = new Vector();
|
||||
Enumeration e = menus.elements();
|
||||
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
Menu menu = (Menu)e.nextElement();
|
||||
if (menu.getShortcut() != null)
|
||||
shortcuts.addElement(menu.getShortcut());
|
||||
}
|
||||
|
||||
return(shortcuts.elements());
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the menu item for the specified shortcut, or <code>null</code>
|
||||
* if no such item exists.
|
||||
*
|
||||
* @param shortcut The shortcut to return the menu item for.
|
||||
*
|
||||
* @return The menu item for the specified shortcut.
|
||||
*/
|
||||
public MenuItem
|
||||
getShortcutMenuItem(MenuShortcut shortcut)
|
||||
{
|
||||
Enumeration e = menus.elements();
|
||||
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
Menu menu = (Menu)e.nextElement();
|
||||
MenuShortcut s = menu.getShortcut();
|
||||
if ((s != null) && (s.equals(shortcut)))
|
||||
return(menu);
|
||||
}
|
||||
|
||||
return(null);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Deletes the specified menu shortcut.
|
||||
*
|
||||
* @param shortcut The shortcut to delete.
|
||||
*/
|
||||
public void
|
||||
deleteShortcut(MenuShortcut shortcut)
|
||||
{
|
||||
MenuItem it;
|
||||
// This is a slow implementation, but it probably doesn't matter.
|
||||
while ((it = getShortcutMenuItem (shortcut)) != null)
|
||||
it.deleteShortcut ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>MenuBar</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTMenuBar();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides accessibility support for AWT menu bars.
|
||||
*
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
*/
|
||||
protected class AccessibleAWTMenuBar
|
||||
extends AccessibleAWTMenuComponent
|
||||
{
|
||||
|
||||
/**
|
||||
* Compatible with JDK 1.4.2 revision 5
|
||||
*/
|
||||
private static final long serialVersionUID = -8577604491830083815L;
|
||||
|
||||
/**
|
||||
* This is the default constructor, which simply calls the default
|
||||
* constructor of the superclass.
|
||||
*/
|
||||
protected AccessibleAWTMenuBar()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the accessible role relating to the menu bar.
|
||||
*
|
||||
* @return <code>AccessibleRole.MENU_BAR</code>.
|
||||
*/
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.MENU_BAR;
|
||||
}
|
||||
|
||||
} // class AccessibleAWTMenuBar
|
||||
|
||||
} // class MenuBar
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,71 @@
|
||||
/* MenuContainer.java -- container for menu items
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This interface is a container for menu components.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface MenuContainer
|
||||
{
|
||||
/**
|
||||
* Returns the font in use by this container.
|
||||
*
|
||||
* @return the menu font
|
||||
*/
|
||||
Font getFont();
|
||||
|
||||
/**
|
||||
* Removes the specified menu component from the menu.
|
||||
*
|
||||
* @param component the menu component to remove
|
||||
*/
|
||||
void remove(MenuComponent component);
|
||||
|
||||
/**
|
||||
* Posts an event to the listeners.
|
||||
*
|
||||
* @param event the event to dispatch
|
||||
* @deprecated use {@link MenuComponent#dispatchEvent(AWTEvent)} instead
|
||||
*/
|
||||
boolean postEvent(Event event);
|
||||
} // interface MenuContainer
|
||||
@@ -0,0 +1,603 @@
|
||||
/* MenuItem.java -- An item in a menu
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.peer.MenuItemPeer;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.EventListener;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleAction;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
import javax.accessibility.AccessibleValue;
|
||||
|
||||
/**
|
||||
* This class represents an item in a menu.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class MenuItem extends MenuComponent
|
||||
implements Serializable, Accessible
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization Constant
|
||||
private static final long serialVersionUID = -21757335363267194L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The name of the action command generated by this item.
|
||||
* This is package-private to avoid an accessor method.
|
||||
*/
|
||||
String actionCommand;
|
||||
|
||||
/**
|
||||
* @serial Indicates whether or not this menu item is enabled.
|
||||
* This is package-private to avoid an accessor method.
|
||||
*/
|
||||
boolean enabled = true;
|
||||
|
||||
/**
|
||||
* @serial The mask of events that are enabled for this menu item.
|
||||
*/
|
||||
long eventMask;
|
||||
|
||||
/**
|
||||
* @serial This menu item's label
|
||||
* This is package-private to avoid an accessor method.
|
||||
*/
|
||||
String label = "";
|
||||
|
||||
/**
|
||||
* @serial The shortcut for this menu item, if any
|
||||
*/
|
||||
private MenuShortcut shortcut;
|
||||
|
||||
// The list of action listeners for this menu item.
|
||||
private transient ActionListener action_listeners;
|
||||
|
||||
protected class AccessibleAWTMenuItem
|
||||
extends MenuComponent.AccessibleAWTMenuComponent
|
||||
implements AccessibleAction, AccessibleValue
|
||||
{
|
||||
/** Constructor */
|
||||
public AccessibleAWTMenuItem()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getAccessibleName()
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
public AccessibleAction getAccessibleAction()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.MENU_ITEM;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleAction#getAccessibleActionCount()
|
||||
*/
|
||||
public int getAccessibleActionCount()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleAction#getAccessibleActionDescription(int)
|
||||
*/
|
||||
public String getAccessibleActionDescription(int i)
|
||||
{
|
||||
if (i == 0)
|
||||
return label;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleAction#doAccessibleAction(int)
|
||||
*/
|
||||
public boolean doAccessibleAction(int i)
|
||||
{
|
||||
if (i != 0)
|
||||
return false;
|
||||
processActionEvent(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand));
|
||||
return true;
|
||||
}
|
||||
|
||||
public AccessibleValue getAccessibleValue()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue()
|
||||
*/
|
||||
public Number getCurrentAccessibleValue()
|
||||
{
|
||||
return (enabled) ? new Integer(1) : new Integer(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number)
|
||||
*/
|
||||
public boolean setCurrentAccessibleValue(Number number)
|
||||
{
|
||||
if (number.intValue() == 0)
|
||||
{
|
||||
setEnabled(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
setEnabled(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue()
|
||||
*/
|
||||
public Number getMinimumAccessibleValue()
|
||||
{
|
||||
return new Integer(0);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue()
|
||||
*/
|
||||
public Number getMaximumAccessibleValue()
|
||||
{
|
||||
return new Integer(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>MenuItem</code> with no label
|
||||
* and no shortcut.
|
||||
*/
|
||||
public
|
||||
MenuItem()
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>MenuItem</code> with the specified
|
||||
* label and no shortcut.
|
||||
*
|
||||
* @param label The label for this menu item.
|
||||
*/
|
||||
public
|
||||
MenuItem(String label)
|
||||
{
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>MenuItem</code> with the specified
|
||||
* label and shortcut.
|
||||
*
|
||||
* @param label The label for this menu item.
|
||||
* @param shortcut The shortcut for this menu item.
|
||||
*/
|
||||
public
|
||||
MenuItem(String label, MenuShortcut shortcut)
|
||||
{
|
||||
this.label = label;
|
||||
this.shortcut = shortcut;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the label for this menu item, which may be <code>null</code>.
|
||||
*
|
||||
* @return The label for this menu item.
|
||||
*/
|
||||
public String
|
||||
getLabel()
|
||||
{
|
||||
return(label);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method sets the label for this menu to the specified value.
|
||||
*
|
||||
* @param label The new label for this menu item.
|
||||
*/
|
||||
public synchronized void
|
||||
setLabel(String label)
|
||||
{
|
||||
this.label = label;
|
||||
if (peer != null)
|
||||
{
|
||||
MenuItemPeer mp = (MenuItemPeer) peer;
|
||||
mp.setLabel (label);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Tests whether or not this menu item is enabled.
|
||||
*
|
||||
* @return <code>true</code> if this menu item is enabled, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean
|
||||
isEnabled()
|
||||
{
|
||||
return(enabled);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the enabled status of this menu item.
|
||||
*
|
||||
* @param enabled <code>true</code> to enable this menu item,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public synchronized void
|
||||
setEnabled(boolean enabled)
|
||||
{
|
||||
enable (enabled);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the enabled status of this menu item.
|
||||
*
|
||||
* @param enabled <code>true</code> to enable this menu item,
|
||||
* <code>false</code> otherwise.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of <code>setEnabled()</code>.
|
||||
*/
|
||||
public void
|
||||
enable(boolean enabled)
|
||||
{
|
||||
if (enabled)
|
||||
enable ();
|
||||
else
|
||||
disable ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Enables this menu item.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of <code>setEnabled()</code>.
|
||||
*/
|
||||
public void
|
||||
enable()
|
||||
{
|
||||
if (enabled)
|
||||
return;
|
||||
|
||||
this.enabled = true;
|
||||
if (peer != null)
|
||||
((MenuItemPeer) peer).setEnabled (true);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Disables this menu item.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of <code>setEnabled()</code>.
|
||||
*/
|
||||
public void
|
||||
disable()
|
||||
{
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
this.enabled = false;
|
||||
if (peer != null)
|
||||
((MenuItemPeer) peer).setEnabled (false);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the shortcut for this menu item, which may be <code>null</code>.
|
||||
*
|
||||
* @return The shortcut for this menu item.
|
||||
*/
|
||||
public MenuShortcut
|
||||
getShortcut()
|
||||
{
|
||||
return(shortcut);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the shortcut for this menu item to the specified value. This
|
||||
* must be done before the native peer is created.
|
||||
*
|
||||
* @param shortcut The new shortcut for this menu item.
|
||||
*/
|
||||
public void
|
||||
setShortcut(MenuShortcut shortcut)
|
||||
{
|
||||
this.shortcut = shortcut;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Deletes the shortcut for this menu item if one exists. This must be
|
||||
* done before the native peer is created.
|
||||
*/
|
||||
public void
|
||||
deleteShortcut()
|
||||
{
|
||||
shortcut = null;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the name of the action command in the action events
|
||||
* generated by this menu item.
|
||||
*
|
||||
* @return The action command name
|
||||
*/
|
||||
public String
|
||||
getActionCommand()
|
||||
{
|
||||
if (actionCommand == null)
|
||||
return label;
|
||||
else
|
||||
return actionCommand;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the name of the action command in the action events generated by
|
||||
* this menu item.
|
||||
*
|
||||
* @param actionCommand The new action command name.
|
||||
*/
|
||||
public void
|
||||
setActionCommand(String actionCommand)
|
||||
{
|
||||
this.actionCommand = actionCommand;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Enables the specified events. This is done automatically when a
|
||||
* listener is added and does not normally need to be done by
|
||||
* application code.
|
||||
*
|
||||
* @param events The events to enable, which should be the bit masks
|
||||
* from <code>AWTEvent</code>.
|
||||
*/
|
||||
protected final void
|
||||
enableEvents(long events)
|
||||
{
|
||||
eventMask |= events;
|
||||
// TODO: see comment in Component.enableEvents().
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Disables the specified events.
|
||||
*
|
||||
* @param events The events to enable, which should be the bit masks
|
||||
* from <code>AWTEvent</code>.
|
||||
*/
|
||||
protected final void
|
||||
disableEvents(long events)
|
||||
{
|
||||
eventMask &= ~events;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Creates the native peer for this object.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit ().createMenuItem (this);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds the specified listener to the list of registered action listeners
|
||||
* for this component.
|
||||
*
|
||||
* @param listener The listener to add.
|
||||
*/
|
||||
public synchronized void
|
||||
addActionListener(ActionListener listener)
|
||||
{
|
||||
action_listeners = AWTEventMulticaster.add(action_listeners, listener);
|
||||
|
||||
enableEvents(AWTEvent.ACTION_EVENT_MASK);
|
||||
}
|
||||
|
||||
public synchronized void
|
||||
removeActionListener(ActionListener l)
|
||||
{
|
||||
action_listeners = AWTEventMulticaster.remove(action_listeners, l);
|
||||
}
|
||||
|
||||
public synchronized ActionListener[] getActionListeners()
|
||||
{
|
||||
return (ActionListener[])
|
||||
AWTEventMulticaster.getListeners(action_listeners,
|
||||
ActionListener.class);
|
||||
}
|
||||
|
||||
/** Returns all registered EventListers of the given listenerType.
|
||||
* listenerType must be a subclass of EventListener, or a
|
||||
* ClassClassException is thrown.
|
||||
* @since 1.3
|
||||
*/
|
||||
public EventListener[] getListeners(Class listenerType)
|
||||
{
|
||||
if (listenerType == ActionListener.class)
|
||||
return getActionListeners();
|
||||
return (EventListener[]) Array.newInstance(listenerType, 0);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
void
|
||||
dispatchEventImpl(AWTEvent e)
|
||||
{
|
||||
if (e.id <= ActionEvent.ACTION_LAST
|
||||
&& e.id >= ActionEvent.ACTION_FIRST
|
||||
&& (action_listeners != null
|
||||
|| (eventMask & AWTEvent.ACTION_EVENT_MASK) != 0))
|
||||
processEvent(e);
|
||||
|
||||
// Send the event to the parent menu if it has not yet been
|
||||
// consumed.
|
||||
if (!e.isConsumed ())
|
||||
((Menu) getParent ()).processEvent (e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the specified event by calling <code>processActionEvent()</code>
|
||||
* if it is an instance of <code>ActionEvent</code>.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void
|
||||
processEvent(AWTEvent event)
|
||||
{
|
||||
if (event instanceof ActionEvent)
|
||||
processActionEvent((ActionEvent)event);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Processes the specified event by dispatching it to any registered listeners.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void
|
||||
processActionEvent(ActionEvent event)
|
||||
{
|
||||
if (action_listeners != null)
|
||||
{
|
||||
event.setSource(this);
|
||||
action_listeners.actionPerformed(event);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this object.
|
||||
*
|
||||
* @return A debugging string for this object.
|
||||
*/
|
||||
public String
|
||||
paramString()
|
||||
{
|
||||
return ("label=" + label + ",enabled=" + enabled +
|
||||
",actionCommand=" + actionCommand + "," + super.paramString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>MenuItem</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTMenuItem();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
} // class MenuItem
|
||||
@@ -0,0 +1,207 @@
|
||||
/* MenuShortcut.java -- A class for menu accelerators
|
||||
Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This class implements a keyboard accelerator for a menu item.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class MenuShortcut implements java.io.Serializable
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization Constant
|
||||
private static final long serialVersionUID = 143448358473180225L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The virtual keycode for the shortcut.
|
||||
*/
|
||||
private int key;
|
||||
|
||||
/**
|
||||
* @serial <code>true</code> if the shift key was used with this shortcut,
|
||||
* or <code>false</code> otherwise.
|
||||
*/
|
||||
private boolean usesShift;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>MenuShortcut</code> with the
|
||||
* specified virtual key value.
|
||||
*
|
||||
* @param key The virtual keycode for the shortcut.
|
||||
*/
|
||||
public
|
||||
MenuShortcut(int key)
|
||||
{
|
||||
this(key, false);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>MenuShortcut</code> with the
|
||||
* specified virtual key value and shift setting.
|
||||
*
|
||||
* @param key The virtual keycode for the shortcut.
|
||||
* @param usesShift <code>true</code> if the shift key was pressed,
|
||||
* <code>false</code> otherwise.
|
||||
*/
|
||||
public
|
||||
MenuShortcut(int key, boolean usesShift)
|
||||
{
|
||||
this.key = key;
|
||||
this.usesShift = usesShift;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the virtual keycode for this shortcut.
|
||||
*
|
||||
* @return The virtual keycode for this shortcut.
|
||||
*/
|
||||
public int
|
||||
getKey()
|
||||
{
|
||||
return(key);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the shift setting for this shortcut.
|
||||
*
|
||||
* @return <code>true</code> if the shift key was pressed, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean
|
||||
usesShiftModifier()
|
||||
{
|
||||
return(usesShift);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Tests this object for equality against the specified object. The two
|
||||
* objects will be considered equal if and only if the specified object
|
||||
* is an instance of <code>MenuShortcut</code> and has the same key value
|
||||
* and shift setting as this object.
|
||||
*
|
||||
* @param obj The object to test for equality against.
|
||||
*
|
||||
* @return <code>true</code> if the two objects are equal, <code>false</code>
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean
|
||||
equals(MenuShortcut obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return(false);
|
||||
|
||||
if (obj.key != this.key)
|
||||
return(false);
|
||||
|
||||
if (obj.usesShift != this.usesShift)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
public boolean
|
||||
equals(Object obj)
|
||||
{
|
||||
if (obj instanceof MenuShortcut)
|
||||
{
|
||||
MenuShortcut ms = (MenuShortcut) obj;
|
||||
return (ms.key == key && ms.usesShift == usesShift);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a string representation of this shortcut.
|
||||
*
|
||||
* @return A string representation of this shortcut.
|
||||
*/
|
||||
public String
|
||||
toString()
|
||||
{
|
||||
return(getClass().getName() + "[" + paramString () + "]");
|
||||
}
|
||||
|
||||
public int
|
||||
hashCode()
|
||||
{
|
||||
// Arbitrary.
|
||||
return key + (usesShift ? 23 : 57);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this object.
|
||||
*
|
||||
* @return A debugging string for this object.
|
||||
*/
|
||||
protected String
|
||||
paramString()
|
||||
{
|
||||
return "key=" + key + ",usesShift=" + usesShift;
|
||||
}
|
||||
|
||||
} // class MenuShortcut
|
||||
@@ -0,0 +1,482 @@
|
||||
/* PageAttributes.java --
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Missing Documentation
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.3
|
||||
* @status updated to 1.4, but missing documentation
|
||||
*/
|
||||
public final class PageAttributes implements Cloneable
|
||||
{
|
||||
public static final class ColorType extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES = { "color", "monochrome" };
|
||||
public static final ColorType COLOR = new ColorType(0);
|
||||
public static final ColorType MONOCHROME = new ColorType(1);
|
||||
private ColorType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class ColorType
|
||||
public static final class MediaType extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES
|
||||
= { "iso-4a0", "iso-2a0", "iso-a0", "iso-a1", "iso-a2", "iso-a3",
|
||||
"iso-a4", "iso-a5", "iso-a6", "iso-a7", "iso-a8", "iso-a9",
|
||||
"iso-a10", "iso-b0", "iso-b1", "iso-b2", "iso-b3", "iso-b4",
|
||||
"iso-b5", "iso-b6", "iso-b7", "iso-b8", "iso-b9", "iso-b10",
|
||||
"jis-b0", "jis-b1", "jis-b2", "jis-b3", "jis-b4", "jis-b5",
|
||||
"jis-b6", "jis-b7", "jis-b8", "jis-b9", "jis-b10", "iso-c0",
|
||||
"iso-c1", "iso-c2", "iso-c3", "iso-c4", "iso-c5", "iso-c6",
|
||||
"iso-c7", "iso-c8", "iso-c9", "iso-c10", "iso-designated-long",
|
||||
"executive", "folio", "invoice", "ledger", "na-letter", "na-legal",
|
||||
"quarto", "a", "b", "c", "d", "e", "na-10x15-envelope",
|
||||
"na-10x14-envelope", "na-10x13-envelope", "na-9x12-envelope",
|
||||
"na-9x11-envelope", "na-7x9-envelope", "na-6x9-envelope",
|
||||
"na-number-9-envelope", "na-number-10-envelope",
|
||||
"na-number-11-envelope", "na-number-12-envelope",
|
||||
"na-number-14-envelope", "invite-envelope", "italy-envelope",
|
||||
"monarch-envelope", "personal-envelope" };
|
||||
public static final MediaType ISO_4A0 = new MediaType(0);
|
||||
public static final MediaType ISO_2A0 = new MediaType(1);
|
||||
public static final MediaType ISO_A0 = new MediaType(2);
|
||||
public static final MediaType ISO_A1 = new MediaType(3);
|
||||
public static final MediaType ISO_A2 = new MediaType(4);
|
||||
public static final MediaType ISO_A3 = new MediaType(5);
|
||||
public static final MediaType ISO_A4 = new MediaType(6);
|
||||
public static final MediaType ISO_A5 = new MediaType(7);
|
||||
public static final MediaType ISO_A6 = new MediaType(8);
|
||||
public static final MediaType ISO_A7 = new MediaType(9);
|
||||
public static final MediaType ISO_A8 = new MediaType(10);
|
||||
public static final MediaType ISO_A9 = new MediaType(11);
|
||||
public static final MediaType ISO_A10 = new MediaType(12);
|
||||
public static final MediaType ISO_B0 = new MediaType(13);
|
||||
public static final MediaType ISO_B1 = new MediaType(14);
|
||||
public static final MediaType ISO_B2 = new MediaType(15);
|
||||
public static final MediaType ISO_B3 = new MediaType(16);
|
||||
public static final MediaType ISO_B4 = new MediaType(17);
|
||||
public static final MediaType ISO_B5 = new MediaType(18);
|
||||
public static final MediaType ISO_B6 = new MediaType(19);
|
||||
public static final MediaType ISO_B7 = new MediaType(20);
|
||||
public static final MediaType ISO_B8 = new MediaType(21);
|
||||
public static final MediaType ISO_B9 = new MediaType(22);
|
||||
public static final MediaType ISO_B10 = new MediaType(23);
|
||||
public static final MediaType JIS_B0 = new MediaType(24);
|
||||
public static final MediaType JIS_B1 = new MediaType(25);
|
||||
public static final MediaType JIS_B2 = new MediaType(26);
|
||||
public static final MediaType JIS_B3 = new MediaType(27);
|
||||
public static final MediaType JIS_B4 = new MediaType(28);
|
||||
public static final MediaType JIS_B5 = new MediaType(29);
|
||||
public static final MediaType JIS_B6 = new MediaType(30);
|
||||
public static final MediaType JIS_B7 = new MediaType(31);
|
||||
public static final MediaType JIS_B8 = new MediaType(32);
|
||||
public static final MediaType JIS_B9 = new MediaType(33);
|
||||
public static final MediaType JIS_B10 = new MediaType(34);
|
||||
public static final MediaType ISO_C0 = new MediaType(35);
|
||||
public static final MediaType ISO_C1 = new MediaType(36);
|
||||
public static final MediaType ISO_C2 = new MediaType(37);
|
||||
public static final MediaType ISO_C3 = new MediaType(38);
|
||||
public static final MediaType ISO_C4 = new MediaType(39);
|
||||
public static final MediaType ISO_C5 = new MediaType(40);
|
||||
public static final MediaType ISO_C6 = new MediaType(41);
|
||||
public static final MediaType ISO_C7 = new MediaType(42);
|
||||
public static final MediaType ISO_C8 = new MediaType(43);
|
||||
public static final MediaType ISO_C9 = new MediaType(44);
|
||||
public static final MediaType ISO_C10 = new MediaType(45);
|
||||
public static final MediaType ISO_DESIGNATED_LONG = new MediaType(46);
|
||||
public static final MediaType EXECUTIVE = new MediaType(47);
|
||||
public static final MediaType FOLIO = new MediaType(48);
|
||||
public static final MediaType INVOICE = new MediaType(49);
|
||||
public static final MediaType LEDGER = new MediaType(50);
|
||||
public static final MediaType NA_LETTER = new MediaType(51);
|
||||
public static final MediaType NA_LEGAL = new MediaType(52);
|
||||
public static final MediaType QUARTO = new MediaType(53);
|
||||
public static final MediaType A = new MediaType(54);
|
||||
public static final MediaType B = new MediaType(55);
|
||||
public static final MediaType C = new MediaType(56);
|
||||
public static final MediaType D = new MediaType(57);
|
||||
public static final MediaType E = new MediaType(58);
|
||||
public static final MediaType NA_10X15_ENVELOPE = new MediaType(59);
|
||||
public static final MediaType NA_10X14_ENVELOPE = new MediaType(60);
|
||||
public static final MediaType NA_10X13_ENVELOPE = new MediaType(61);
|
||||
public static final MediaType NA_9X12_ENVELOPE = new MediaType(62);
|
||||
public static final MediaType NA_9X11_ENVELOPE = new MediaType(63);
|
||||
public static final MediaType NA_7X9_ENVELOPE = new MediaType(64);
|
||||
public static final MediaType NA_6X9_ENVELOPE = new MediaType(65);
|
||||
public static final MediaType NA_NUMBER_9_ENVELOPE = new MediaType(66);
|
||||
public static final MediaType NA_NUMBER_10_ENVELOPE = new MediaType(67);
|
||||
public static final MediaType NA_NUMBER_11_ENVELOPE = new MediaType(68);
|
||||
public static final MediaType NA_NUMBER_12_ENVELOPE = new MediaType(69);
|
||||
public static final MediaType NA_NUMBER_14_ENVELOPE = new MediaType(70);
|
||||
public static final MediaType INVITE_ENVELOPE = new MediaType(71);
|
||||
public static final MediaType ITALY_ENVELOPE = new MediaType(72);
|
||||
public static final MediaType MONARCH_ENVELOPE = new MediaType(73);
|
||||
public static final MediaType PERSONAL_ENVELOPE = new MediaType(74);
|
||||
public static final MediaType A0 = ISO_A0;
|
||||
public static final MediaType A1 = ISO_A1;
|
||||
public static final MediaType A2 = ISO_A2;
|
||||
public static final MediaType A3 = ISO_A3;
|
||||
public static final MediaType A4 = ISO_A4;
|
||||
public static final MediaType A5 = ISO_A5;
|
||||
public static final MediaType A6 = ISO_A6;
|
||||
public static final MediaType A7 = ISO_A7;
|
||||
public static final MediaType A8 = ISO_A8;
|
||||
public static final MediaType A9 = ISO_A9;
|
||||
public static final MediaType A10 = ISO_A10;
|
||||
public static final MediaType B0 = ISO_B0;
|
||||
public static final MediaType B1 = ISO_B1;
|
||||
public static final MediaType B2 = ISO_B2;
|
||||
public static final MediaType B3 = ISO_B3;
|
||||
public static final MediaType B4 = ISO_B4;
|
||||
public static final MediaType ISO_B4_ENVELOPE = ISO_B4;
|
||||
public static final MediaType B5 = ISO_B5;
|
||||
public static final MediaType ISO_B5_ENVELOPE = ISO_B4;
|
||||
public static final MediaType B6 = ISO_B6;
|
||||
public static final MediaType B7 = ISO_B7;
|
||||
public static final MediaType B8 = ISO_B8;
|
||||
public static final MediaType B9 = ISO_B9;
|
||||
public static final MediaType B10 = ISO_B10;
|
||||
public static final MediaType C0 = ISO_B0;
|
||||
public static final MediaType ISO_C0_ENVELOPE = ISO_C0;
|
||||
public static final MediaType C1 = ISO_C1;
|
||||
public static final MediaType ISO_C1_ENVELOPE = ISO_C1;
|
||||
public static final MediaType C2 = ISO_C2;
|
||||
public static final MediaType ISO_C2_ENVELOPE = ISO_C2;
|
||||
public static final MediaType C3 = ISO_C3;
|
||||
public static final MediaType ISO_C3_ENVELOPE = ISO_C3;
|
||||
public static final MediaType C4 = ISO_C4;
|
||||
public static final MediaType ISO_C4_ENVELOPE = ISO_C4;
|
||||
public static final MediaType C5 = ISO_C5;
|
||||
public static final MediaType ISO_C5_ENVELOPE = ISO_C5;
|
||||
public static final MediaType C6 = ISO_C6;
|
||||
public static final MediaType ISO_C6_ENVELOPE = ISO_C6;
|
||||
public static final MediaType C7 = ISO_C7;
|
||||
public static final MediaType ISO_C7_ENVELOPE = ISO_C7;
|
||||
public static final MediaType C8 = ISO_C8;
|
||||
public static final MediaType ISO_C8_ENVELOPE = ISO_C8;
|
||||
public static final MediaType C9 = ISO_C9;
|
||||
public static final MediaType ISO_C9_ENVELOPE = ISO_C9;
|
||||
public static final MediaType C10 = ISO_C10;
|
||||
public static final MediaType ISO_C10_ENVELOPE = ISO_C10;
|
||||
public static final MediaType ISO_DESIGNATED_LONG_ENVELOPE
|
||||
= ISO_DESIGNATED_LONG;
|
||||
public static final MediaType STATEMENT = INVOICE;
|
||||
public static final MediaType TABLOID = LEDGER;
|
||||
public static final MediaType LETTER = NA_LETTER;
|
||||
public static final MediaType NOTE = NA_LETTER;
|
||||
public static final MediaType LEGAL = NA_LEGAL;
|
||||
public static final MediaType ENV_10X15 = NA_10X15_ENVELOPE;
|
||||
public static final MediaType ENV_10X14 = NA_10X14_ENVELOPE;
|
||||
public static final MediaType ENV_10X13 = NA_10X13_ENVELOPE;
|
||||
public static final MediaType ENV_9X12 = NA_9X12_ENVELOPE;
|
||||
public static final MediaType ENV_9X11 = NA_9X11_ENVELOPE;
|
||||
public static final MediaType ENV_7X9 = NA_7X9_ENVELOPE;
|
||||
public static final MediaType ENV_6X9 = NA_6X9_ENVELOPE;
|
||||
public static final MediaType ENV_9 = NA_NUMBER_9_ENVELOPE;
|
||||
public static final MediaType ENV_10 = NA_NUMBER_10_ENVELOPE;
|
||||
public static final MediaType ENV_11 = NA_NUMBER_11_ENVELOPE;
|
||||
public static final MediaType ENV_12 = NA_NUMBER_12_ENVELOPE;
|
||||
public static final MediaType ENV_14 = NA_NUMBER_14_ENVELOPE;
|
||||
public static final MediaType ENV_INVITE = INVITE_ENVELOPE;
|
||||
public static final MediaType ENV_ITALY = ITALY_ENVELOPE;
|
||||
public static final MediaType ENV_MONARCH = MONARCH_ENVELOPE;
|
||||
public static final MediaType ENV_PERSONAL = PERSONAL_ENVELOPE;
|
||||
public static final MediaType INVITE = INVITE_ENVELOPE;
|
||||
public static final MediaType ITALY = ITALY_ENVELOPE;
|
||||
public static final MediaType MONARCH = MONARCH_ENVELOPE;
|
||||
public static final MediaType PERSONAL = PERSONAL_ENVELOPE;
|
||||
private MediaType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class MediaType
|
||||
public static final class OrientationRequestedType extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES = { "portrait", "landscape" };
|
||||
public static final OrientationRequestedType PORTRAIT
|
||||
= new OrientationRequestedType(0);
|
||||
public static final OrientationRequestedType LANDSCAPE
|
||||
= new OrientationRequestedType(1);
|
||||
private OrientationRequestedType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class OrientationRequestedType
|
||||
public static final class OriginType extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES = { "physical", "printable" };
|
||||
public static final OriginType PHYSICAL = new OriginType(0);
|
||||
public static final OriginType PRINTABLE = new OriginType(1);
|
||||
private OriginType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class OriginType
|
||||
public static final class PrintQualityType extends AttributeValue
|
||||
{
|
||||
private static final String[] NAMES = { "high", "normal", "draft" };
|
||||
public static final PrintQualityType HIGH = new PrintQualityType(0);
|
||||
public static final PrintQualityType NORMAL = new PrintQualityType(1);
|
||||
public static final PrintQualityType DRAFT = new PrintQualityType(2);
|
||||
private PrintQualityType(int value)
|
||||
{
|
||||
super(value, NAMES);
|
||||
}
|
||||
} // class PrintQualityType
|
||||
|
||||
|
||||
private ColorType color;
|
||||
private MediaType media;
|
||||
private OrientationRequestedType orientation;
|
||||
private OriginType origin;
|
||||
private PrintQualityType quality;
|
||||
private int resolutionX;
|
||||
private int resolutionY;
|
||||
private int resolutionScale;
|
||||
public PageAttributes()
|
||||
{
|
||||
color = ColorType.MONOCHROME;
|
||||
setMediaToDefault();
|
||||
orientation = OrientationRequestedType.PORTRAIT;
|
||||
origin = OriginType.PHYSICAL;
|
||||
quality = PrintQualityType.NORMAL;
|
||||
setPrinterResolutionToDefault();
|
||||
}
|
||||
|
||||
public PageAttributes(PageAttributes attr)
|
||||
{
|
||||
set(attr);
|
||||
}
|
||||
|
||||
public PageAttributes(ColorType color, MediaType media,
|
||||
OrientationRequestedType orientation,
|
||||
OriginType origin, PrintQualityType quality,
|
||||
int[] resolution)
|
||||
{
|
||||
if (color == null || media == null || orientation == null
|
||||
|| origin == null || quality == null)
|
||||
throw new IllegalArgumentException();
|
||||
setPrinterResolution(resolution);
|
||||
this.color = color;
|
||||
this.media = media;
|
||||
this.orientation = orientation;
|
||||
this.origin = origin;
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
public Object clone()
|
||||
{
|
||||
return new PageAttributes(this);
|
||||
}
|
||||
|
||||
public void set(PageAttributes attr)
|
||||
{
|
||||
color = attr.color;
|
||||
media = attr.media;
|
||||
orientation = attr.orientation;
|
||||
origin = attr.origin;
|
||||
quality = attr.quality;
|
||||
resolutionX = attr.resolutionX;
|
||||
resolutionY = attr.resolutionY;
|
||||
resolutionScale = attr.resolutionScale;
|
||||
}
|
||||
|
||||
public ColorType getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(ColorType color)
|
||||
{
|
||||
if (color == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public MediaType getMedia()
|
||||
{
|
||||
return media;
|
||||
}
|
||||
|
||||
public void setMedia(MediaType media)
|
||||
{
|
||||
if (media == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.media = media;
|
||||
}
|
||||
|
||||
public void setMediaToDefault()
|
||||
{
|
||||
String country = Locale.getDefault().getCountry();
|
||||
media = ("US".equals(country) || "CA".equals(country)) ? MediaType.LETTER
|
||||
: MediaType.A4;
|
||||
}
|
||||
|
||||
public OrientationRequestedType getOrientationRequested()
|
||||
{
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public void setOrientationRequested(OrientationRequestedType orientation)
|
||||
{
|
||||
if (orientation == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
public void setOrientationRequested(int orientation)
|
||||
{
|
||||
if (orientation == 3)
|
||||
this.orientation = OrientationRequestedType.PORTRAIT;
|
||||
else if (orientation == 4)
|
||||
this.orientation = OrientationRequestedType.LANDSCAPE;
|
||||
else
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public void setOrientationRequestedToDefault()
|
||||
{
|
||||
orientation = OrientationRequestedType.PORTRAIT;
|
||||
}
|
||||
|
||||
public OriginType getOrigin()
|
||||
{
|
||||
return origin;
|
||||
}
|
||||
|
||||
public void setOrigin(OriginType origin)
|
||||
{
|
||||
if (origin == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.origin = origin;
|
||||
}
|
||||
|
||||
public PrintQualityType getPrintQuality()
|
||||
{
|
||||
return quality;
|
||||
}
|
||||
|
||||
public void setPrintQuality(PrintQualityType quality)
|
||||
{
|
||||
if (quality == null)
|
||||
throw new IllegalArgumentException();
|
||||
this.quality = quality;
|
||||
}
|
||||
|
||||
public void setPrintQuality(int quality)
|
||||
{
|
||||
if (quality == 3)
|
||||
this.quality = PrintQualityType.DRAFT;
|
||||
else if (quality == 4)
|
||||
this.quality = PrintQualityType.NORMAL;
|
||||
else if (quality == 5)
|
||||
this.quality = PrintQualityType.HIGH;
|
||||
else
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
public void setPrintQualityToDefault()
|
||||
{
|
||||
quality = PrintQualityType.NORMAL;
|
||||
}
|
||||
|
||||
public int[] getPrinterResolution()
|
||||
{
|
||||
return new int[] { resolutionX, resolutionY, resolutionScale };
|
||||
}
|
||||
|
||||
public void setPrinterResolution(int[] resolution)
|
||||
{
|
||||
if (resolution == null || resolution.length != 3 || resolution[0] <= 0
|
||||
|| resolution[1] <= 0 || resolution[2] < 3 || resolution[2] > 4)
|
||||
throw new IllegalArgumentException();
|
||||
resolutionX = resolution[0];
|
||||
resolutionY = resolution[1];
|
||||
resolutionScale = resolution[2];
|
||||
}
|
||||
|
||||
public void setPrinterResolution(int resolution)
|
||||
{
|
||||
if (resolution <= 0)
|
||||
throw new IllegalArgumentException();
|
||||
resolutionX = resolution;
|
||||
resolutionY = resolution;
|
||||
resolutionScale = 3;
|
||||
}
|
||||
|
||||
public void setPrinterResolutionToDefault()
|
||||
{
|
||||
resolutionX = 72;
|
||||
resolutionY = 72;
|
||||
resolutionScale = 3;
|
||||
}
|
||||
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
return true;
|
||||
if (! (o instanceof PageAttributes))
|
||||
return false;
|
||||
PageAttributes pa = (PageAttributes) o;
|
||||
return color == pa.color && media == pa.media
|
||||
&& orientation == pa.orientation && origin == pa.origin
|
||||
&& quality == pa.quality && resolutionX == pa.resolutionX
|
||||
&& resolutionY == pa.resolutionY
|
||||
&& resolutionScale == pa.resolutionScale;
|
||||
}
|
||||
public int hashCode()
|
||||
{
|
||||
return (color.value << 31) ^ (media.value << 24)
|
||||
^ (orientation.value << 23) ^ (origin.value << 22)
|
||||
^ (quality.value << 20) ^ (resolutionScale << 19)
|
||||
^ (resolutionY << 10) ^ resolutionX;
|
||||
}
|
||||
public String toString()
|
||||
{
|
||||
return "color=" + color + ",media=" + media + ",orientation-requested="
|
||||
+ orientation + ",origin=" + origin + ",print-quality=" + quality
|
||||
+ ",printer-resolution=[" + resolutionX + ',' + resolutionY + ','
|
||||
+ resolutionScale + ']';
|
||||
}
|
||||
} // class PageAttributes
|
||||
@@ -0,0 +1,79 @@
|
||||
/* Paint.java -- generate colors for Graphics2D operations
|
||||
Copyright (C) 2000, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ColorModel;
|
||||
|
||||
/**
|
||||
* Defines how color patterns are generated for Graphics2D operations. This
|
||||
* is used to perform the <code>draw</code> and <code>fill</code> methods
|
||||
* of the graphics object. Instances must be immutable, because the graphics
|
||||
* object does not clone them.
|
||||
*
|
||||
* @author Warren Levy (warrenl@cygnus.com)
|
||||
* @see PaintContext
|
||||
* @see Color
|
||||
* @see GradientPaint
|
||||
* @see TexturePaint
|
||||
* @see Graphics2D#setPaint(Paint)
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface Paint extends Transparency
|
||||
{
|
||||
/**
|
||||
* Create the context necessary for performing the color pattern generation.
|
||||
* The color model is a hint, and may be null for Classpath implementations;
|
||||
* however some legacy code may throw a NullPointerException when passed a
|
||||
* null. Leaving the color model null provides the most efficiency and leeway
|
||||
* in the generation of the color pattern.
|
||||
*
|
||||
* @param cm the color model, used as a hint
|
||||
* @param deviceBounds the device space bounding box of the painted area
|
||||
* @param userBounds the user space bounding box of the painted area
|
||||
* @param xform the transformation from user space to device space
|
||||
* @param hints any hints for choosing between rendering alternatives
|
||||
* @return the context for performing the paint
|
||||
*/
|
||||
PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
|
||||
Rectangle2D userBounds, AffineTransform xform,
|
||||
RenderingHints hints);
|
||||
} // interface Paint
|
||||
@@ -0,0 +1,76 @@
|
||||
/* PaintContext.java -- the environment for performing a paint operation
|
||||
Copyright (C) 2000, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.Raster;
|
||||
|
||||
/**
|
||||
* @author Warren Levy (warrenl@cygnus.com)
|
||||
* @see Paint
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface PaintContext
|
||||
{
|
||||
/**
|
||||
* Release the resources allocated for the paint.
|
||||
*/
|
||||
void dispose();
|
||||
|
||||
/**
|
||||
* Return the color model of this context. It may be different from the
|
||||
* hint specified during createContext, as not all contexts can generate
|
||||
* color patterns in an arbitrary model.
|
||||
*
|
||||
* @return the context color model
|
||||
*/
|
||||
ColorModel getColorModel();
|
||||
|
||||
/**
|
||||
* Return a raster containing the colors for the graphics operation.
|
||||
*
|
||||
* @param x the x-coordinate, in device space
|
||||
* @param y the y-coordinate, in device space
|
||||
* @param w the width, in device space
|
||||
* @param h the height, in device space
|
||||
* @return a raster for the given area and color
|
||||
*/
|
||||
Raster getRaster(int x, int y, int w, int h);
|
||||
} // interface PaintContext
|
||||
@@ -0,0 +1,173 @@
|
||||
/* Panel.java -- Simple container object
|
||||
Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
|
||||
/**
|
||||
* A panel is a simple container class. It's default layout is the
|
||||
* <code>FlowLayout</code> manager.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see FlowLayout
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class Panel extends Container implements Accessible
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -2728009084054400034L;
|
||||
|
||||
/** The cached accessible context. */
|
||||
private transient AccessibleContext context;
|
||||
|
||||
/** Flag set when the first system-requested paint event is
|
||||
dispatched. */
|
||||
private transient boolean initialSystemUpdateDone;
|
||||
|
||||
/** Flag set when the first application-requested paint event is
|
||||
consumed. */
|
||||
private transient boolean initialUpdateConsumed;
|
||||
|
||||
/*
|
||||
* The number used to generate the name returned by getName.
|
||||
*/
|
||||
private static transient long next_panel_number;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Panel</code> that has a default
|
||||
* layout manager of <code>FlowLayout</code>.
|
||||
*/
|
||||
public Panel()
|
||||
{
|
||||
this(new FlowLayout());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Panel</code> with the specified
|
||||
* layout manager.
|
||||
*
|
||||
* @param layoutManager the layout manager for this object
|
||||
* @since 1.1
|
||||
*/
|
||||
public Panel(LayoutManager layoutManager)
|
||||
{
|
||||
setLayout(layoutManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies this object to create its native peer.
|
||||
*
|
||||
* @see #isDisplayable()
|
||||
* @see #removeNotify()
|
||||
*/
|
||||
public void addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit().createPanel(this);
|
||||
super.addNotify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this panel, creating one if
|
||||
* necessary. This always returns an instance of {@link AccessibleAWTPanel}.
|
||||
*
|
||||
* @return the accessibility context of this panel
|
||||
* @since 1.3
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
if (context == null)
|
||||
context = new AccessibleAWTPanel();
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides accessibility support for Panels, and is the
|
||||
* runtime type returned by {@link #getAccessibleContext()}.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.3
|
||||
*/
|
||||
protected class AccessibleAWTPanel extends AccessibleAWTContainer
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.4+.
|
||||
*/
|
||||
private static final long serialVersionUID = -6409552226660031050L;
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
protected AccessibleAWTPanel()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the role of this accessible object, a panel.
|
||||
*
|
||||
* @return the role of the object
|
||||
* @see AccessibleRole#PANEL
|
||||
*/
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.PANEL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique name for this panel.
|
||||
*
|
||||
* @return A unique name for this panel.
|
||||
*/
|
||||
String generateName ()
|
||||
{
|
||||
return "panel" + getUniqueLong ();
|
||||
}
|
||||
|
||||
private static synchronized long getUniqueLong ()
|
||||
{
|
||||
return next_panel_number++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
/* Point.java -- represents a point in 2-D space
|
||||
Copyright (C) 1999, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.Point2D;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class represents a point on the screen using cartesian coordinates.
|
||||
* Remember that in screen coordinates, increasing x values go from left to
|
||||
* right, and increasing y values go from top to bottom.
|
||||
*
|
||||
* <p>There are some public fields; if you mess with them in an inconsistent
|
||||
* manner, it is your own fault when you get invalid results. Also, this
|
||||
* class is not threadsafe.
|
||||
*
|
||||
* @author Per Bothner (bothner@cygnus.com)
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class Point extends Point2D implements Serializable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -5276940640259749850L;
|
||||
|
||||
/**
|
||||
* The x coordinate.
|
||||
*
|
||||
* @see #getLocation()
|
||||
* @see #move(int, int)
|
||||
* @serial the X coordinate of the point
|
||||
*/
|
||||
public int x;
|
||||
|
||||
/**
|
||||
* The y coordinate.
|
||||
*
|
||||
* @see #getLocation()
|
||||
* @see #move(int, int)
|
||||
* @serial The Y coordinate of the point
|
||||
*/
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Point</code> representing the
|
||||
* coordiates (0,0).
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
public Point()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Point</code> with coordinates
|
||||
* identical to the coordinates of the specified points.
|
||||
*
|
||||
* @param p the point to copy the coordinates from
|
||||
* @throws NullPointerException if p is null
|
||||
*/
|
||||
public Point(Point p)
|
||||
{
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Point</code> with the specified
|
||||
* coordinates.
|
||||
*
|
||||
* @param x the X coordinate
|
||||
* @param y the Y coordinate
|
||||
*/
|
||||
public Point(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the x coordinate.
|
||||
*
|
||||
* @return the value of x, as a double
|
||||
*/
|
||||
public double getX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the y coordinate.
|
||||
*
|
||||
* @return the value of y, as a double
|
||||
*/
|
||||
public double getY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the location of this point. A pretty useless method, as this
|
||||
* is already a point.
|
||||
*
|
||||
* @return a copy of this point
|
||||
* @see #setLocation(Point)
|
||||
* @since 1.1
|
||||
*/
|
||||
public Point getLocation()
|
||||
{
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this object's coordinates to match those of the specified point.
|
||||
*
|
||||
* @param p the point to copy the coordinates from
|
||||
* @throws NullPointerException if p is null
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setLocation(Point p)
|
||||
{
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this object's coordinates to the specified values. This method
|
||||
* is identical to the <code>move()</code> method.
|
||||
*
|
||||
* @param x the new X coordinate
|
||||
* @param y the new Y coordinate
|
||||
*/
|
||||
public void setLocation(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this object's coordinates to the specified values. This method
|
||||
* performs normal casting from double to int, so you may lose precision.
|
||||
*
|
||||
* @param x the new X coordinate
|
||||
* @param y the new Y coordinate
|
||||
*/
|
||||
public void setLocation(double x, double y)
|
||||
{
|
||||
this.x = (int) x;
|
||||
this.y = (int) y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this object's coordinates to the specified values. This method
|
||||
* is identical to the <code>setLocation(int, int)</code> method.
|
||||
*
|
||||
* @param x the new X coordinate
|
||||
* @param y the new Y coordinate
|
||||
*/
|
||||
public void move(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the coordinates of this point such that the specified
|
||||
* <code>dx</code> parameter is added to the existing X coordinate and
|
||||
* <code>dy</code> is added to the existing Y coordinate.
|
||||
*
|
||||
* @param dx the amount to add to the X coordinate
|
||||
* @param dy the amount to add to the Y coordinate
|
||||
*/
|
||||
public void translate(int dx, int dy)
|
||||
{
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not this object is equal to the specified object.
|
||||
* This will be true if and only if the specified object is an instance
|
||||
* of Point2D and has the same X and Y coordinates.
|
||||
*
|
||||
* @param obj the object to test against for equality
|
||||
* @return true if the specified object is equal
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (! (obj instanceof Point2D))
|
||||
return false;
|
||||
Point2D p = (Point2D) obj;
|
||||
return x == p.getX() && y == p.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object. The format is:
|
||||
* <code>getClass().getName() + "[x=" + x + ",y=" + y + ']'</code>.
|
||||
*
|
||||
* @return a string representation of this object
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getName() + "[x=" + x + ",y=" + y + ']';
|
||||
}
|
||||
} // class Point
|
||||
@@ -0,0 +1,613 @@
|
||||
/* Polygon.java -- class representing a polygon
|
||||
Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Line2D;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class represents a polygon, a closed, two-dimensional region in a
|
||||
* coordinate space. The region is bounded by an arbitrary number of line
|
||||
* segments, between (x,y) coordinate vertices. The polygon has even-odd
|
||||
* winding, meaning that a point is inside the shape if it crosses the
|
||||
* boundary an odd number of times on the way to infinity.
|
||||
*
|
||||
* <p>There are some public fields; if you mess with them in an inconsistent
|
||||
* manner, it is your own fault when you get NullPointerException,
|
||||
* ArrayIndexOutOfBoundsException, or invalid results. Also, this class is
|
||||
* not threadsafe.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class Polygon implements Shape, Serializable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -6460061437900069969L;
|
||||
|
||||
/**
|
||||
* This total number of endpoints.
|
||||
*
|
||||
* @serial the number of endpoints, possibly less than the array sizes
|
||||
*/
|
||||
public int npoints;
|
||||
|
||||
/**
|
||||
* The array of X coordinates of endpoints. This should not be null.
|
||||
*
|
||||
* @see #addPoint(int, int)
|
||||
* @serial the x coordinates
|
||||
*/
|
||||
public int[] xpoints;
|
||||
|
||||
/**
|
||||
* The array of Y coordinates of endpoints. This should not be null.
|
||||
*
|
||||
* @see #addPoint(int, int)
|
||||
* @serial the y coordinates
|
||||
*/
|
||||
public int[] ypoints;
|
||||
|
||||
/**
|
||||
* The bounding box of this polygon. This is lazily created and cached, so
|
||||
* it must be invalidated after changing points.
|
||||
*
|
||||
* @see #getBounds()
|
||||
* @serial the bounding box, or null
|
||||
*/
|
||||
protected Rectangle bounds;
|
||||
|
||||
/** A big number, but not so big it can't survive a few float operations */
|
||||
private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0;
|
||||
|
||||
/**
|
||||
* Initializes an empty polygon.
|
||||
*/
|
||||
public Polygon()
|
||||
{
|
||||
// Leave room for growth.
|
||||
xpoints = new int[4];
|
||||
ypoints = new int[4];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new polygon with the specified endpoints. The arrays are copied,
|
||||
* so that future modifications to the parameters do not affect the polygon.
|
||||
*
|
||||
* @param xpoints the array of X coordinates for this polygon
|
||||
* @param ypoints the array of Y coordinates for this polygon
|
||||
* @param npoints the total number of endpoints in this polygon
|
||||
* @throws NegativeArraySizeException if npoints is negative
|
||||
* @throws IndexOutOfBoundsException if npoints exceeds either array
|
||||
* @throws NullPointerException if xpoints or ypoints is null
|
||||
*/
|
||||
public Polygon(int[] xpoints, int[] ypoints, int 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);
|
||||
this.npoints = npoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the polygon to be empty. The arrays are left alone, to avoid object
|
||||
* allocation, but the number of points is set to 0, and all cached data
|
||||
* is discarded. If you are discarding a huge number of points, it may be
|
||||
* more efficient to just create a new Polygon.
|
||||
*
|
||||
* @see #invalidate()
|
||||
* @since 1.4
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
npoints = 0;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate or flush all cached data. After direct manipulation of the
|
||||
* public member fields, this is necessary to avoid inconsistent results
|
||||
* in methods like <code>contains</code>.
|
||||
*
|
||||
* @see #getBounds()
|
||||
* @since 1.4
|
||||
*/
|
||||
public void invalidate()
|
||||
{
|
||||
bounds = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the polygon by adding the specified values to all X and Y
|
||||
* coordinates. This updates the bounding box, if it has been calculated.
|
||||
*
|
||||
* @param dx the amount to add to all X coordinates
|
||||
* @param dy the amount to add to all Y coordinates
|
||||
* @since 1.1
|
||||
*/
|
||||
public void translate(int dx, int dy)
|
||||
{
|
||||
int i = npoints;
|
||||
while (--i >= 0)
|
||||
{
|
||||
xpoints[i] += dx;
|
||||
ypoints[i] += dy;
|
||||
}
|
||||
if (bounds != null)
|
||||
{
|
||||
bounds.x += dx;
|
||||
bounds.y += dy;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified endpoint to the polygon. This updates the bounding
|
||||
* box, if it has been created.
|
||||
*
|
||||
* @param x the X coordinate of the point to add
|
||||
* @param y the Y coordiante of the point to add
|
||||
*/
|
||||
public void addPoint(int x, int y)
|
||||
{
|
||||
if (npoints + 1 > xpoints.length)
|
||||
{
|
||||
int[] newx = new int[npoints + 1];
|
||||
System.arraycopy(xpoints, 0, newx, 0, npoints);
|
||||
xpoints = newx;
|
||||
}
|
||||
if (npoints + 1 > ypoints.length)
|
||||
{
|
||||
int[] newy = new int[npoints + 1];
|
||||
System.arraycopy(ypoints, 0, newy, 0, npoints);
|
||||
ypoints = newy;
|
||||
}
|
||||
xpoints[npoints] = x;
|
||||
ypoints[npoints] = y;
|
||||
npoints++;
|
||||
if (bounds != null)
|
||||
{
|
||||
if (npoints == 1)
|
||||
{
|
||||
bounds.x = x;
|
||||
bounds.y = y;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x < bounds.x)
|
||||
{
|
||||
bounds.width += bounds.x - x;
|
||||
bounds.x = x;
|
||||
}
|
||||
else if (x > bounds.x + bounds.width)
|
||||
bounds.width = x - bounds.x;
|
||||
if (y < bounds.y)
|
||||
{
|
||||
bounds.height += bounds.y - y;
|
||||
bounds.y = y;
|
||||
}
|
||||
else if (y > bounds.y + bounds.height)
|
||||
bounds.height = y - bounds.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bounding box of this polygon. This is the smallest
|
||||
* rectangle with sides parallel to the X axis that will contain this
|
||||
* polygon.
|
||||
*
|
||||
* @return the bounding box for this polygon
|
||||
* @see #getBounds2D()
|
||||
* @since 1.1
|
||||
*/
|
||||
public Rectangle getBounds()
|
||||
{
|
||||
return getBoundingBox();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bounding box of this polygon. This is the smallest
|
||||
* rectangle with sides parallel to the X axis that will contain this
|
||||
* polygon.
|
||||
*
|
||||
* @return the bounding box for this polygon
|
||||
* @see #getBounds2D()
|
||||
* @deprecated use {@link #getBounds()} instead
|
||||
*/
|
||||
public Rectangle getBoundingBox()
|
||||
{
|
||||
if (bounds == null)
|
||||
{
|
||||
if (npoints == 0)
|
||||
return bounds = new Rectangle();
|
||||
int i = npoints - 1;
|
||||
int minx = xpoints[i];
|
||||
int maxx = minx;
|
||||
int miny = ypoints[i];
|
||||
int maxy = miny;
|
||||
while (--i >= 0)
|
||||
{
|
||||
int x = xpoints[i];
|
||||
int y = ypoints[i];
|
||||
if (x < minx)
|
||||
minx = x;
|
||||
else if (x > maxx)
|
||||
maxx = x;
|
||||
if (y < miny)
|
||||
miny = y;
|
||||
else if (y > maxy)
|
||||
maxy = y;
|
||||
}
|
||||
bounds = new Rectangle(minx, miny, maxx - minx, maxy - miny);
|
||||
}
|
||||
return bounds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the specified point is inside this polygon.
|
||||
*
|
||||
* @param p the point to test
|
||||
* @return true if the point is inside this polygon
|
||||
* @throws NullPointerException if p is null
|
||||
* @see #contains(double, double)
|
||||
*/
|
||||
public boolean contains(Point p)
|
||||
{
|
||||
return contains(p.getX(), p.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the specified point is inside this polygon.
|
||||
*
|
||||
* @param x the X coordinate of the point to test
|
||||
* @param y the Y coordinate of the point to test
|
||||
* @return true if the point is inside this polygon
|
||||
* @see #contains(double, double)
|
||||
* @since 1.1
|
||||
*/
|
||||
public boolean contains(int x, int y)
|
||||
{
|
||||
return contains((double) x, (double) y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the specified point is inside this polygon.
|
||||
*
|
||||
* @param x the X coordinate of the point to test
|
||||
* @param y the Y coordinate of the point to test
|
||||
* @return true if the point is inside this polygon
|
||||
* @see #contains(double, double)
|
||||
* @deprecated use {@link #contains(int, int)} instead
|
||||
*/
|
||||
public boolean inside(int x, int y)
|
||||
{
|
||||
return contains((double) x, (double) y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a high-precision bounding box of this polygon. This is the
|
||||
* smallest rectangle with sides parallel to the X axis that will contain
|
||||
* this polygon.
|
||||
*
|
||||
* @return the bounding box for this polygon
|
||||
* @see #getBounds()
|
||||
* @since 1.2
|
||||
*/
|
||||
public Rectangle2D getBounds2D()
|
||||
{
|
||||
// For polygons, the integer version is exact!
|
||||
return getBounds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the specified point is inside this polygon.
|
||||
*
|
||||
* @param x the X coordinate of the point to test
|
||||
* @param y the Y coordinate of the point to test
|
||||
* @return true if the point is inside this polygon
|
||||
* @since 1.2
|
||||
*/
|
||||
public boolean contains(double x, double y)
|
||||
{
|
||||
return ((evaluateCrossings(x, y, false, BIG_VALUE) & 1) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the specified point is inside this polygon.
|
||||
*
|
||||
* @param p the point to test
|
||||
* @return true if the point is inside this polygon
|
||||
* @throws NullPointerException if p is null
|
||||
* @see #contains(double, double)
|
||||
* @since 1.2
|
||||
*/
|
||||
public boolean contains(Point2D p)
|
||||
{
|
||||
return contains(p.getX(), p.getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a high-precision rectangle intersects the shape. This is true
|
||||
* if any point in the rectangle is in the shape. This implementation is
|
||||
* precise.
|
||||
*
|
||||
* @param x the x coordinate of the rectangle
|
||||
* @param y the y coordinate of the rectangle
|
||||
* @param w the width of the rectangle, treated as point if negative
|
||||
* @param h the height of the rectangle, treated as point if negative
|
||||
* @return true if the rectangle intersects this shape
|
||||
* @since 1.2
|
||||
*/
|
||||
public boolean intersects(double x, double y, double w, double h)
|
||||
{
|
||||
/* Does any edge intersect? */
|
||||
if (evaluateCrossings(x, y, false, w) != 0 /* top */
|
||||
|| evaluateCrossings(x, y + h, false, w) != 0 /* bottom */
|
||||
|| evaluateCrossings(x + w, y, true, h) != 0 /* right */
|
||||
|| evaluateCrossings(x, y, true, h) != 0) /* left */
|
||||
return true;
|
||||
|
||||
/* No intersections, is any point inside? */
|
||||
if ((evaluateCrossings(x, y, false, BIG_VALUE) & 1) != 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a high-precision rectangle intersects the shape. This is true
|
||||
* if any point in the rectangle is in the shape. This implementation is
|
||||
* precise.
|
||||
*
|
||||
* @param r the rectangle
|
||||
* @return true if the rectangle intersects this shape
|
||||
* @throws NullPointerException if r is null
|
||||
* @see #intersects(double, double, double, double)
|
||||
* @since 1.2
|
||||
*/
|
||||
public boolean intersects(Rectangle2D r)
|
||||
{
|
||||
return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a high-precision rectangle lies completely in the shape. This is
|
||||
* true if all points in the rectangle are in the shape. This implementation
|
||||
* is precise.
|
||||
*
|
||||
* @param x the x coordinate of the rectangle
|
||||
* @param y the y coordinate of the rectangle
|
||||
* @param w the width of the rectangle, treated as point if negative
|
||||
* @param h the height of the rectangle, treated as point if negative
|
||||
* @return true if the rectangle is contained in this shape
|
||||
* @since 1.2
|
||||
*/
|
||||
public boolean contains(double x, double y, double w, double h)
|
||||
{
|
||||
if (! getBounds2D().intersects(x, y, w, h))
|
||||
return false;
|
||||
|
||||
/* Does any edge intersect? */
|
||||
if (evaluateCrossings(x, y, false, w) != 0 /* top */
|
||||
|| evaluateCrossings(x, y + h, false, w) != 0 /* bottom */
|
||||
|| evaluateCrossings(x + w, y, true, h) != 0 /* right */
|
||||
|| evaluateCrossings(x, y, true, h) != 0) /* left */
|
||||
return false;
|
||||
|
||||
/* No intersections, is any point inside? */
|
||||
if ((evaluateCrossings(x, y, false, BIG_VALUE) & 1) != 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a high-precision rectangle lies completely in the shape. This is
|
||||
* true if all points in the rectangle are in the shape. This implementation
|
||||
* is precise.
|
||||
*
|
||||
* @param r the rectangle
|
||||
* @return true if the rectangle is contained in this shape
|
||||
* @throws NullPointerException if r is null
|
||||
* @see #contains(double, double, double, double)
|
||||
* @since 1.2
|
||||
*/
|
||||
public boolean contains(Rectangle2D r)
|
||||
{
|
||||
return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an iterator along the shape boundary. If the optional transform
|
||||
* is provided, the iterator is transformed accordingly. Each call returns
|
||||
* a new object, independent from others in use. This class is not
|
||||
* threadsafe to begin with, so the path iterator is not either.
|
||||
*
|
||||
* @param transform an optional transform to apply to the iterator
|
||||
* @return a new iterator over the boundary
|
||||
* @since 1.2
|
||||
*/
|
||||
public PathIterator getPathIterator(final AffineTransform transform)
|
||||
{
|
||||
return new PathIterator()
|
||||
{
|
||||
/** The current vertex of iteration. */
|
||||
private int vertex;
|
||||
|
||||
public int getWindingRule()
|
||||
{
|
||||
return WIND_EVEN_ODD;
|
||||
}
|
||||
|
||||
public boolean isDone()
|
||||
{
|
||||
return vertex > npoints;
|
||||
}
|
||||
|
||||
public void next()
|
||||
{
|
||||
vertex++;
|
||||
}
|
||||
|
||||
public int currentSegment(float[] coords)
|
||||
{
|
||||
if (vertex >= npoints)
|
||||
return SEG_CLOSE;
|
||||
coords[0] = xpoints[vertex];
|
||||
coords[1] = ypoints[vertex];
|
||||
if (transform != null)
|
||||
transform.transform(coords, 0, coords, 0, 1);
|
||||
return vertex == 0 ? SEG_MOVETO : SEG_LINETO;
|
||||
}
|
||||
|
||||
public int currentSegment(double[] coords)
|
||||
{
|
||||
if (vertex >= npoints)
|
||||
return SEG_CLOSE;
|
||||
coords[0] = xpoints[vertex];
|
||||
coords[1] = ypoints[vertex];
|
||||
if (transform != null)
|
||||
transform.transform(coords, 0, coords, 0, 1);
|
||||
return vertex == 0 ? SEG_MOVETO : SEG_LINETO;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an iterator along the flattened version of the shape boundary.
|
||||
* Since polygons are already flat, the flatness parameter is ignored, and
|
||||
* the resulting iterator only has SEG_MOVETO, SEG_LINETO and SEG_CLOSE
|
||||
* points. If the optional transform is provided, the iterator is
|
||||
* transformed accordingly. Each call returns a new object, independent
|
||||
* from others in use. This class is not threadsafe to begin with, so the
|
||||
* path iterator is not either.
|
||||
*
|
||||
* @param transform an optional transform to apply to the iterator
|
||||
* @param flatness the maximum distance for deviation from the real boundary
|
||||
* @return a new iterator over the boundary
|
||||
* @since 1.2
|
||||
*/
|
||||
public PathIterator getPathIterator(AffineTransform transform,
|
||||
double flatness)
|
||||
{
|
||||
return getPathIterator(transform);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper for contains, intersects, calculates the number of intersections
|
||||
* between the polygon and a line extending from the point (x, y) along
|
||||
* the positive X, or Y axis, within a given interval.
|
||||
*
|
||||
* @return the winding number.
|
||||
* @see #condensed
|
||||
* @see #contains(double, double)
|
||||
*/
|
||||
private int evaluateCrossings(double x, double y, boolean useYaxis,
|
||||
double distance)
|
||||
{
|
||||
double x0;
|
||||
double x1;
|
||||
double y0;
|
||||
double y1;
|
||||
double epsilon = 0.0;
|
||||
int crossings = 0;
|
||||
int[] xp;
|
||||
int[] yp;
|
||||
|
||||
if (useYaxis)
|
||||
{
|
||||
xp = ypoints;
|
||||
yp = xpoints;
|
||||
double swap;
|
||||
swap = y;
|
||||
y = x;
|
||||
x = swap;
|
||||
}
|
||||
else
|
||||
{
|
||||
xp = xpoints;
|
||||
yp = ypoints;
|
||||
}
|
||||
|
||||
/* Get a value which is small but not insignificant relative the path. */
|
||||
epsilon = 1E-7;
|
||||
|
||||
x0 = xp[0] - x;
|
||||
y0 = yp[0] - y;
|
||||
for (int i = 1; i < npoints; i++)
|
||||
{
|
||||
x1 = xp[i] - x;
|
||||
y1 = yp[i] - y;
|
||||
|
||||
if (y0 == 0.0)
|
||||
y0 -= epsilon;
|
||||
if (y1 == 0.0)
|
||||
y1 -= epsilon;
|
||||
if (y0 * y1 < 0)
|
||||
if (Line2D.linesIntersect(x0, y0, x1, y1, epsilon, 0.0, distance, 0.0))
|
||||
++crossings;
|
||||
|
||||
x0 = xp[i] - x;
|
||||
y0 = yp[i] - y;
|
||||
}
|
||||
|
||||
// end segment
|
||||
x1 = xp[0] - x;
|
||||
y1 = yp[0] - y;
|
||||
if (y0 == 0.0)
|
||||
y0 -= epsilon;
|
||||
if (y1 == 0.0)
|
||||
y1 -= epsilon;
|
||||
if (y0 * y1 < 0)
|
||||
if (Line2D.linesIntersect(x0, y0, x1, y1, epsilon, 0.0, distance, 0.0))
|
||||
++crossings;
|
||||
|
||||
return crossings;
|
||||
}
|
||||
} // class Polygon
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
/* PopupMenu.java -- An AWT popup menu
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.peer.PopupMenuPeer;
|
||||
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
|
||||
/**
|
||||
* This class implement an AWT popup menu widget
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class PopupMenu extends Menu
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
// Serialization Constant
|
||||
private static final long serialVersionUID = -4620452533522760060L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>PopupMenu</code>.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
||||
* returns true.
|
||||
*/
|
||||
public
|
||||
PopupMenu()
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>PopupMenu</code> with the specified
|
||||
* label.
|
||||
*
|
||||
* @param label The label for this popup menu.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless()
|
||||
* returns true.
|
||||
*/
|
||||
public
|
||||
PopupMenu(String label)
|
||||
{
|
||||
super(label);
|
||||
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates this object's native peer.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit ().createPopupMenu (this);
|
||||
super.addNotify ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Displays this popup menu at the specified coordinates relative to
|
||||
* the specified component.
|
||||
*
|
||||
* @param component The component to which the display coordinates are relative.
|
||||
* @param x The X coordinate of the menu.
|
||||
* @param y The Y coordinate of the menu.
|
||||
*/
|
||||
public void
|
||||
show(Component component, int x, int y)
|
||||
{
|
||||
if (getPeer() == null)
|
||||
this.addNotify();
|
||||
PopupMenuPeer pmp = (PopupMenuPeer)getPeer();
|
||||
if (pmp != null)
|
||||
{
|
||||
/* XXX
|
||||
Event e = new Event (component, Event.ACTION_EVENT, component);
|
||||
e.x = x;
|
||||
e.y = y;*/
|
||||
pmp.show (component, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
protected class AccessibleAWTPopupMenu extends AccessibleAWTMenu
|
||||
{
|
||||
protected AccessibleAWTPopupMenu()
|
||||
{
|
||||
}
|
||||
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.POPUP_MENU;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>PopupMenu</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTPopupMenu();
|
||||
return accessibleContext;
|
||||
}
|
||||
|
||||
} // class PopupMenu
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/* PrintGraphics.java -- a print graphics context
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This interface allows the originating print job to be obtained.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface PrintGraphics
|
||||
{
|
||||
/**
|
||||
* Returns the <code>PrintJob</code> that this object is being
|
||||
* managed by.
|
||||
*
|
||||
* @return the print job for this object
|
||||
*/
|
||||
PrintJob getPrintJob();
|
||||
} // interface PrintGraphics
|
||||
@@ -0,0 +1,104 @@
|
||||
/* PrintJob.java -- A print job class
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* This abstract class represents a print job.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @see Toolkit#getPrintJob(Frame, String, Properties)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public abstract class PrintJob
|
||||
{
|
||||
/**
|
||||
* Create a new PrintJob.
|
||||
*/
|
||||
public PrintJob()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a graphics context suitable for rendering the next page. The
|
||||
* return must also implement {@link PrintGraphics}.
|
||||
*
|
||||
* @return a graphics context for printing the next page
|
||||
*/
|
||||
public abstract Graphics getGraphics();
|
||||
|
||||
/**
|
||||
* Returns the dimension of the page in pixels. The resolution will be
|
||||
* chosen to be similar to the on screen image.
|
||||
*
|
||||
* @return the page dimensions
|
||||
*/
|
||||
public abstract Dimension getPageDimension();
|
||||
|
||||
/**
|
||||
* Returns the resolution of the page in pixels per inch. Note that this is
|
||||
* not necessarily the printer's resolution.
|
||||
*
|
||||
* @return the resolution of the page in pixels per inch
|
||||
*/
|
||||
public abstract int getPageResolution();
|
||||
|
||||
/**
|
||||
* Tests whether or not the last page will be printed first.
|
||||
*
|
||||
* @return true if the last page prints first
|
||||
*/
|
||||
public abstract boolean lastPageFirst();
|
||||
|
||||
/**
|
||||
* Informs the print job that printing is complete or should be aborted.
|
||||
*/
|
||||
public abstract void end();
|
||||
|
||||
/**
|
||||
* This method explicitly ends the print job in the event the job
|
||||
* becomes un-referenced without the application having done so.
|
||||
*/
|
||||
public void finalize()
|
||||
{
|
||||
end();
|
||||
}
|
||||
} // class PrintJob
|
||||
@@ -0,0 +1,749 @@
|
||||
/* Rectangle.java -- represents a graphics rectangle
|
||||
Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class represents a rectangle and all the interesting things you
|
||||
* might want to do with it. Note that the coordinate system uses
|
||||
* the origin (0,0) as the top left of the screen, with the x and y
|
||||
* values increasing as they move to the right and down respectively.
|
||||
*
|
||||
* <p>It is valid for a rectangle to have negative width or height; but it
|
||||
* is considered to have no area or internal points. Therefore, the behavior
|
||||
* in methods like <code>contains</code> or <code>intersects</code> is
|
||||
* undefined unless the rectangle has positive width and height.
|
||||
*
|
||||
* <p>There are some public fields; if you mess with them in an inconsistent
|
||||
* manner, it is your own fault when you get NullPointerException,
|
||||
* ArrayIndexOutOfBoundsException, or invalid results. Also, this class is
|
||||
* not threadsafe.
|
||||
*
|
||||
* @author Warren Levy (warrenl@cygnus.com)
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public class Rectangle extends Rectangle2D implements Shape, Serializable
|
||||
{
|
||||
/**
|
||||
* Compatible with JDK 1.0+.
|
||||
*/
|
||||
private static final long serialVersionUID = -4345857070255674764L;
|
||||
|
||||
/**
|
||||
* The X coordinate of the top-left corner of the rectangle.
|
||||
*
|
||||
* @see #setLocation(int, int)
|
||||
* @see #getLocation()
|
||||
* @serial the x coordinate
|
||||
*/
|
||||
public int x;
|
||||
|
||||
/**
|
||||
* The Y coordinate of the top-left corner of the rectangle.
|
||||
*
|
||||
* @see #setLocation(int, int)
|
||||
* @see #getLocation()
|
||||
* @serial the y coordinate
|
||||
*/
|
||||
public int y;
|
||||
|
||||
/**
|
||||
* The width of the rectangle.
|
||||
*
|
||||
* @see #setSize(int, int)
|
||||
* @see #getSize()
|
||||
* @serial
|
||||
*/
|
||||
public int width;
|
||||
|
||||
/**
|
||||
* The height of the rectangle.
|
||||
*
|
||||
* @see #setSize(int, int)
|
||||
* @see #getSize()
|
||||
* @serial
|
||||
*/
|
||||
public int height;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Rectangle</code> with a top
|
||||
* left corner at (0,0) and a width and height of 0.
|
||||
*/
|
||||
public Rectangle()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Rectangle</code> from the
|
||||
* coordinates of the specified rectangle.
|
||||
*
|
||||
* @param r the rectangle to copy from
|
||||
* @throws NullPointerException if r is null
|
||||
* @since 1.1
|
||||
*/
|
||||
public Rectangle(Rectangle r)
|
||||
{
|
||||
x = r.x;
|
||||
y = r.y;
|
||||
width = r.width;
|
||||
height = r.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Rectangle</code> from the specified
|
||||
* inputs.
|
||||
*
|
||||
* @param x the X coordinate of the top left corner
|
||||
* @param y the Y coordinate of the top left corner
|
||||
* @param width the width of the rectangle
|
||||
* @param height the height of the rectangle
|
||||
*/
|
||||
public Rectangle(int x, int y, int width, int height)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Rectangle</code> with the specified
|
||||
* width and height. The upper left corner of the rectangle will be at
|
||||
* the origin (0,0).
|
||||
*
|
||||
* @param width the width of the rectangle
|
||||
* @param height the height of the rectange
|
||||
*/
|
||||
public Rectangle(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Rectangle</code> with a top-left
|
||||
* corner represented by the specified point and the width and height
|
||||
* represented by the specified dimension.
|
||||
*
|
||||
* @param p the upper left corner of the rectangle
|
||||
* @param d the width and height of the rectangle
|
||||
* @throws NullPointerException if p or d is null
|
||||
*/
|
||||
public Rectangle(Point p, Dimension d)
|
||||
{
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
width = d.width;
|
||||
height = d.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Rectangle</code> with a top left
|
||||
* corner at the specified point and a width and height of zero.
|
||||
*
|
||||
* @param p the upper left corner of the rectangle
|
||||
*/
|
||||
public Rectangle(Point p)
|
||||
{
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Rectangle</code> with an
|
||||
* upper left corner at the origin (0,0) and a width and height represented
|
||||
* by the specified dimension.
|
||||
*
|
||||
* @param d the width and height of the rectangle
|
||||
*/
|
||||
public Rectangle(Dimension d)
|
||||
{
|
||||
width = d.width;
|
||||
height = d.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the X coordinate of the upper-left corner.
|
||||
*
|
||||
* @return the value of x, as a double
|
||||
*/
|
||||
public double getX()
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Y coordinate of the upper-left corner.
|
||||
*
|
||||
* @return the value of y, as a double
|
||||
*/
|
||||
public double getY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the width of the rectangle.
|
||||
*
|
||||
* @return the value of width, as a double
|
||||
*/
|
||||
public double getWidth()
|
||||
{
|
||||
return width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of the rectangle.
|
||||
*
|
||||
* @return the value of height, as a double
|
||||
*/
|
||||
public double getHeight()
|
||||
{
|
||||
return height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the bounds of this rectangle. A pretty useless method, as this
|
||||
* is already a rectangle; it is included to mimic the
|
||||
* <code>getBounds</code> method in Component.
|
||||
*
|
||||
* @return a copy of this rectangle
|
||||
* @see #setBounds(Rectangle)
|
||||
* @since 1.1
|
||||
*/
|
||||
public Rectangle getBounds()
|
||||
{
|
||||
return new Rectangle(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the high-precision bounds of this rectangle. A pretty useless
|
||||
* method, as this is already a rectangle.
|
||||
*
|
||||
* @return a copy of this rectangle
|
||||
* @see #setBounds(Rectangle)
|
||||
* @since 1.2
|
||||
*/
|
||||
public Rectangle2D getBounds2D()
|
||||
{
|
||||
return new Rectangle(x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates this rectangle to match the dimensions of the specified
|
||||
* rectangle.
|
||||
*
|
||||
* @param r the rectangle to update from
|
||||
* @throws NullPointerException if r is null
|
||||
* @see #setBounds(int, int, int, int)
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setBounds(Rectangle r)
|
||||
{
|
||||
setBounds (r.x, r.y, r.width, r.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates this rectangle to have the specified dimensions.
|
||||
*
|
||||
* @param x the new X coordinate of the upper left hand corner
|
||||
* @param y the new Y coordinate of the upper left hand corner
|
||||
* @param width the new width of this rectangle
|
||||
* @param height the new height of this rectangle
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setBounds(int x, int y, int width, int height)
|
||||
{
|
||||
reshape (x, y, width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates this rectangle to have the specified dimensions, as rounded to
|
||||
* integers.
|
||||
*
|
||||
* @param x the new X coordinate of the upper left hand corner
|
||||
* @param y the new Y coordinate of the upper left hand corner
|
||||
* @param width the new width of this rectangle
|
||||
* @param height the new height of this rectangle
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setRect(double x, double y, double width, double height)
|
||||
{
|
||||
this.x = (int) x;
|
||||
this.y = (int) y;
|
||||
this.width = (int) width;
|
||||
this.height = (int) height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates this rectangle to have the specified dimensions.
|
||||
*
|
||||
* @param x the new X coordinate of the upper left hand corner
|
||||
* @param y the new Y coordinate of the upper left hand corner
|
||||
* @param width the new width of this rectangle
|
||||
* @param height the new height of this rectangle
|
||||
* @deprecated use {@link #setBounds(int, int, int, int)} instead
|
||||
*/
|
||||
public void reshape(int x, int y, int width, int height)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the location of this rectangle, which is the coordinates of
|
||||
* its upper left corner.
|
||||
*
|
||||
* @return the point where this rectangle is located
|
||||
* @see #setLocation(Point)
|
||||
* @since 1.1
|
||||
*/
|
||||
public Point getLocation()
|
||||
{
|
||||
return new Point(x,y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the location of this rectangle by setting its upper left
|
||||
* corner to the specified point.
|
||||
*
|
||||
* @param p the point to move the rectangle to
|
||||
* @throws NullPointerException if p is null
|
||||
* @see #getLocation()
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setLocation(Point p)
|
||||
{
|
||||
setLocation (p.x, p.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the location of this rectangle by setting its upper left
|
||||
* corner to the specified coordinates.
|
||||
*
|
||||
* @param x the new X coordinate for this rectangle
|
||||
* @param y the new Y coordinate for this rectangle
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setLocation(int x, int y)
|
||||
{
|
||||
move (x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the location of this rectangle by setting its upper left
|
||||
* corner to the specified coordinates.
|
||||
*
|
||||
* @param x the new X coordinate for this rectangle
|
||||
* @param y the new Y coordinate for this rectangle
|
||||
* @deprecated use {@link #setLocation(int, int)} instead
|
||||
*/
|
||||
public void move(int x, int y)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate the location of this rectangle by the given amounts.
|
||||
*
|
||||
* @param dx the x distance to move by
|
||||
* @param dy the y distance to move by
|
||||
* @see #setLocation(int, int)
|
||||
*/
|
||||
public void translate(int dx, int dy)
|
||||
{
|
||||
x += dx;
|
||||
y += dy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of this rectangle.
|
||||
*
|
||||
* @return the size of this rectangle
|
||||
* @see #setSize(Dimension)
|
||||
* @since 1.1
|
||||
*/
|
||||
public Dimension getSize()
|
||||
{
|
||||
return new Dimension(width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of this rectangle based on the specified dimensions.
|
||||
*
|
||||
* @param d the new dimensions of the rectangle
|
||||
* @throws NullPointerException if d is null
|
||||
* @see #getSize()
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setSize(Dimension d)
|
||||
{
|
||||
setSize (d.width, d.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of this rectangle based on the specified dimensions.
|
||||
*
|
||||
* @param width the new width of the rectangle
|
||||
* @param height the new height of the rectangle
|
||||
* @since 1.1
|
||||
*/
|
||||
public void setSize(int width, int height)
|
||||
{
|
||||
resize (width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the size of this rectangle based on the specified dimensions.
|
||||
*
|
||||
* @param width the new width of the rectangle
|
||||
* @param height the new height of the rectangle
|
||||
* @deprecated use {@link #setSize(int, int)} instead
|
||||
*/
|
||||
public void resize(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the specified point is inside this rectangle.
|
||||
* According to the contract of Shape, a point on the border is in only if
|
||||
* it has an adjacent point inside the rectangle in either the increasing
|
||||
* x or y direction.
|
||||
*
|
||||
* @param p the point to test
|
||||
* @return true if the point is inside the rectangle
|
||||
* @throws NullPointerException if p is null
|
||||
* @see #contains(int, int)
|
||||
* @since 1.1
|
||||
*/
|
||||
public boolean contains(Point p)
|
||||
{
|
||||
return contains (p.x, p.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the specified point is inside this rectangle.
|
||||
* According to the contract of Shape, a point on the border is in only if
|
||||
* it has an adjacent point inside the rectangle in either the increasing
|
||||
* x or y direction.
|
||||
*
|
||||
* @param x the X coordinate of the point to test
|
||||
* @param y the Y coordinate of the point to test
|
||||
* @return true if the point is inside the rectangle
|
||||
* @since 1.1
|
||||
*/
|
||||
public boolean contains(int x, int y)
|
||||
{
|
||||
return inside (x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether all points in the given rectangle are contained in this
|
||||
* rectangle.
|
||||
*
|
||||
* @param r the rectangle to check
|
||||
* @return true if r is contained in this rectangle
|
||||
* @throws NullPointerException if r is null
|
||||
* @see #contains(int, int, int, int)
|
||||
* @since 1.1
|
||||
*/
|
||||
public boolean contains(Rectangle r)
|
||||
{
|
||||
return contains (r.x, r.y, r.width, r.height);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether all points in the given rectangle are contained in this
|
||||
* rectangle.
|
||||
*
|
||||
* @param x the x coordinate of the rectangle to check
|
||||
* @param y the y coordinate of the rectangle to check
|
||||
* @param w the width of the rectangle to check
|
||||
* @param h the height of the rectangle to check
|
||||
* @return true if the parameters are contained in this rectangle
|
||||
* @since 1.1
|
||||
*/
|
||||
public boolean contains(int x, int y, int w, int h)
|
||||
{
|
||||
return width > 0 && height > 0 && w > 0 && h > 0
|
||||
&& x >= this.x && x + w <= this.x + this.width
|
||||
&& y >= this.y && y + h <= this.y + this.height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the specified point is inside this rectangle.
|
||||
*
|
||||
* @param x the X coordinate of the point to test
|
||||
* @param y the Y coordinate of the point to test
|
||||
* @return true if the point is inside the rectangle
|
||||
* @deprecated use {@link #contains(int, int)} instead
|
||||
*/
|
||||
public boolean inside(int x, int y)
|
||||
{
|
||||
return width > 0 && height > 0
|
||||
&& x >= this.x && x < this.x + width
|
||||
&& y >= this.y && y < this.y + height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not the specified rectangle intersects this rectangle.
|
||||
* This means the two rectangles share at least one internal point.
|
||||
*
|
||||
* @param r the rectangle to test against
|
||||
* @return true if the specified rectangle intersects this one
|
||||
* @throws NullPointerException if r is null
|
||||
* @since 1.2
|
||||
*/
|
||||
public boolean intersects(Rectangle r)
|
||||
{
|
||||
return r.width > 0 && r.height > 0 && width > 0 && height > 0
|
||||
&& r.x < x + width && r.x + r.width > x
|
||||
&& r.y < y + height && r.y + r.height > y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the rectangle which is formed by the intersection of this
|
||||
* rectangle with the specified rectangle. If the two do not intersect,
|
||||
* an empty rectangle will be returned (meaning the width and/or height
|
||||
* will be non-positive).
|
||||
*
|
||||
* @param r the rectange to calculate the intersection with
|
||||
* @return a new rectangle bounding the intersection
|
||||
* @throws NullPointerException if r is null
|
||||
*/
|
||||
public Rectangle intersection(Rectangle r)
|
||||
{
|
||||
Rectangle res = new Rectangle();
|
||||
intersect(this, r, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest rectangle that contains both this rectangle
|
||||
* and the specified rectangle.
|
||||
*
|
||||
* @param r the rectangle to compute the union with
|
||||
* @return the smallest rectangle containing both rectangles
|
||||
* @throws NullPointerException if r is null
|
||||
*/
|
||||
public Rectangle union(Rectangle r)
|
||||
{
|
||||
Rectangle res = new Rectangle();
|
||||
union(this, r, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies this rectangle so that it represents the smallest rectangle
|
||||
* that contains both the existing rectangle and the specified point.
|
||||
* However, if the point falls on one of the two borders which are not
|
||||
* inside the rectangle, a subsequent call to <code>contains</code> may
|
||||
* return false.
|
||||
*
|
||||
* @param x the X coordinate of the point to add to this rectangle
|
||||
* @param y the Y coordinate of the point to add to this rectangle
|
||||
*/
|
||||
public void add(int x, int y)
|
||||
{
|
||||
add((double) x, (double) y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies this rectangle so that it represents the smallest rectangle
|
||||
* that contains both the existing rectangle and the specified point.
|
||||
* However, if the point falls on one of the two borders which are not
|
||||
* inside the rectangle, a subsequent call to <code>contains</code> may
|
||||
* return false.
|
||||
*
|
||||
* @param p the point to add to this rectangle
|
||||
* @throws NullPointerException if p is null
|
||||
*/
|
||||
public void add(Point p)
|
||||
{
|
||||
add((double) p.x, (double) p.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies this rectangle so that it represents the smallest rectangle
|
||||
* that contains both the existing rectangle and the specified rectangle.
|
||||
*
|
||||
* @param r the rectangle to add to this rectangle
|
||||
* @throws NullPointerException if r is null
|
||||
* @see #union(Rectangle)
|
||||
*/
|
||||
public void add(Rectangle r)
|
||||
{
|
||||
union(this, r, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands the rectangle by the specified amount. The horizontal
|
||||
* and vertical expansion values are applied both to the X,Y coordinate
|
||||
* of this rectangle, and its width and height. Thus the width and
|
||||
* height will increase by 2h and 2v accordingly.
|
||||
*
|
||||
* @param h the horizontal expansion value
|
||||
* @param v the vertical expansion value
|
||||
*/
|
||||
public void grow(int h, int v)
|
||||
{
|
||||
x -= h;
|
||||
y -= v;
|
||||
width += h + h;
|
||||
height += v + v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether or not this rectangle is empty. An empty rectangle
|
||||
* has a non-positive width or height.
|
||||
*
|
||||
* @return true if the rectangle is empty
|
||||
*/
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return width <= 0 || height <= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine where the point lies with respect to this rectangle. The
|
||||
* result will be the binary OR of the appropriate bit masks.
|
||||
*
|
||||
* @param x the x coordinate to check
|
||||
* @param y the y coordinate to check
|
||||
* @return the binary OR of the result
|
||||
* @see #OUT_LEFT
|
||||
* @see #OUT_TOP
|
||||
* @see #OUT_RIGHT
|
||||
* @see #OUT_BOTTOM
|
||||
* @since 1.2
|
||||
*/
|
||||
public int outcode(double x, double y)
|
||||
{
|
||||
int result = 0;
|
||||
if (width <= 0)
|
||||
result |= OUT_LEFT | OUT_RIGHT;
|
||||
else if (x < this.x)
|
||||
result |= OUT_LEFT;
|
||||
else if (x > this.x + width)
|
||||
result |= OUT_RIGHT;
|
||||
if (height <= 0)
|
||||
result |= OUT_BOTTOM | OUT_TOP;
|
||||
else if (y < this.y) // Remember that +y heads top-to-bottom.
|
||||
result |= OUT_TOP;
|
||||
else if (y > this.y + height)
|
||||
result |= OUT_BOTTOM;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the rectangle which is formed by the intersection of this
|
||||
* rectangle with the specified rectangle. If the two do not intersect,
|
||||
* an empty rectangle will be returned (meaning the width and/or height
|
||||
* will be non-positive).
|
||||
*
|
||||
* @param r the rectange to calculate the intersection with
|
||||
* @return a new rectangle bounding the intersection
|
||||
* @throws NullPointerException if r is null
|
||||
* @since 1.2
|
||||
*/
|
||||
public Rectangle2D createIntersection(Rectangle2D r)
|
||||
{
|
||||
// Favor runtime type of other rectangle.
|
||||
Rectangle2D res = r.getBounds2D();
|
||||
intersect(this, r, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest rectangle that contains both this rectangle
|
||||
* and the specified rectangle.
|
||||
*
|
||||
* @param r the rectangle to compute the union with
|
||||
* @return the smallest rectangle containing both rectangles
|
||||
* @throws NullPointerException if r is null
|
||||
* @since 1.2
|
||||
*/
|
||||
public Rectangle2D createUnion(Rectangle2D r)
|
||||
{
|
||||
// Favor runtime type of other rectangle.
|
||||
Rectangle2D res = r.getBounds2D();
|
||||
union(this, r, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests this rectangle for equality against the specified object. This
|
||||
* will be true if an only if the specified object is an instance of
|
||||
* Rectangle2D with the same coordinates and dimensions.
|
||||
*
|
||||
* @param obj the object to test against for equality
|
||||
* @return true if the specified object is equal to this one
|
||||
*/
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (! (obj instanceof Rectangle2D))
|
||||
return false;
|
||||
Rectangle2D r = (Rectangle2D) obj;
|
||||
return r.getX() == x && r.getY() == y
|
||||
&& r.getWidth() == width && r.getHeight() == height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this rectangle. This is in the form
|
||||
* <code>getClass().getName() + "[x=" + x + ",y=" + y + ",width=" + width
|
||||
* + ",height=" + height + ']'</code>.
|
||||
*
|
||||
* @return a string representation of this rectangle
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return getClass().getName() + "[x=" + x + ",y=" + y + ",width=" + width
|
||||
+ ",height=" + height + ']';
|
||||
}
|
||||
} // class Rectangle
|
||||
@@ -0,0 +1,803 @@
|
||||
/* RenderingHints.java --
|
||||
Copyright (C) 2000, 2001, 2002, 2004, 2005 Free Software Foundation
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A collection of (key, value) items that provide 'hints' for the
|
||||
* {@link java.awt.Graphics2D} rendering pipeline. Because these
|
||||
* items are hints only, they may be ignored by a particular
|
||||
* {@link java.awt.Graphics2D} implementation.
|
||||
*
|
||||
* @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
*/
|
||||
public class RenderingHints implements Map, Cloneable
|
||||
{
|
||||
/**
|
||||
* The base class used to represent keys.
|
||||
*/
|
||||
public abstract static class Key
|
||||
{
|
||||
private final int key;
|
||||
|
||||
/**
|
||||
* Creates a new key.
|
||||
*
|
||||
* @param privateKey the private key.
|
||||
*/
|
||||
protected Key(int privateKey)
|
||||
{
|
||||
key = privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the specified value is compatible with
|
||||
* this key, and <code>false</code> otherwise.
|
||||
*
|
||||
* @param value the value (<code>null</code> permitted).
|
||||
*
|
||||
* @return A boolean.
|
||||
*/
|
||||
public abstract boolean isCompatibleValue(Object value);
|
||||
|
||||
/**
|
||||
* Returns the private key for this instance.
|
||||
*
|
||||
* @return The private key.
|
||||
*/
|
||||
protected final int intKey()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code for the key.
|
||||
*
|
||||
* @return A hash code.
|
||||
*/
|
||||
public final int hashCode()
|
||||
{
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks this key for equality with an arbitrary object.
|
||||
*
|
||||
* @param other the object (<code>null</code> permitted)
|
||||
*
|
||||
* @return A boolean.
|
||||
*/
|
||||
public final boolean equals(Object other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
} // class Key
|
||||
|
||||
private static final class KeyImpl extends Key
|
||||
{
|
||||
final String description;
|
||||
final Object v1;
|
||||
final Object v2;
|
||||
final Object v3;
|
||||
|
||||
KeyImpl(int privateKey, String description,
|
||||
Object v1, Object v2, Object v3)
|
||||
{
|
||||
super(privateKey);
|
||||
this.description = description;
|
||||
this.v1 = v1;
|
||||
this.v2 = v2;
|
||||
this.v3 = v3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the specified value is compatible with
|
||||
* this key, and <code>false</code> otherwise.
|
||||
*
|
||||
* @param value the value (<code>null</code> permitted).
|
||||
*
|
||||
* @return A boolean.
|
||||
*/
|
||||
public boolean isCompatibleValue(Object value)
|
||||
{
|
||||
return value == v1 || value == v2 || value == v3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of the key.
|
||||
*
|
||||
* @return A string.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
} // class KeyImpl
|
||||
|
||||
private HashMap hintMap = new HashMap();
|
||||
|
||||
/**
|
||||
* A key for the 'antialiasing' hint. Permitted values are:
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_ANTIALIAS_OFF}</td>
|
||||
* <td>Render without antialiasing (better speed).</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_ANTIALIAS_ON}</td>
|
||||
* <td>Render with antialiasing (better quality).</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_ANTIALIAS_DEFAULT}</td>
|
||||
* <td>Use the default value for antialiasing.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
public static final Key KEY_ANTIALIASING;
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_ANTIALIASING} key.
|
||||
*/
|
||||
public static final Object VALUE_ANTIALIAS_ON
|
||||
= "Antialiased rendering mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_ANTIALIASING} key.
|
||||
*/
|
||||
public static final Object VALUE_ANTIALIAS_OFF
|
||||
= "Nonantialiased rendering mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_ANTIALIASING} key.
|
||||
*/
|
||||
public static final Object VALUE_ANTIALIAS_DEFAULT
|
||||
= "Default antialiasing rendering mode";
|
||||
|
||||
/**
|
||||
* A key for the 'rendering' hint. Permitted values are:
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_RENDER_SPEED}</td>
|
||||
* <td>Prefer speed over quality when rendering.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_RENDER_QUALITY}</td>
|
||||
* <td>Prefer quality over speed when rendering.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_RENDER_DEFAULT}</td>
|
||||
* <td>Use the default value for quality vs. speed when rendering.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
public static final Key KEY_RENDERING;
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_RENDERING} key.
|
||||
*/
|
||||
public static final Object VALUE_RENDER_SPEED
|
||||
= "Fastest rendering methods";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_RENDERING} key.
|
||||
*/
|
||||
public static final Object VALUE_RENDER_QUALITY
|
||||
= "Highest quality rendering methods";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_RENDERING} key.
|
||||
*/
|
||||
public static final Object VALUE_RENDER_DEFAULT
|
||||
= "Default rendering methods";
|
||||
|
||||
/**
|
||||
* A key for the 'dithering' hint. Permitted values are:
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_DITHER_DISABLE}</td>
|
||||
* <td>Disable dithering.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_DITHER_ENABLE}</td>
|
||||
* <td>Enable dithering.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_DITHER_DEFAULT}</td>
|
||||
* <td>Use the default value for dithering.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
public static final Key KEY_DITHERING;
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_DITHERING} key.
|
||||
*/
|
||||
public static final Object VALUE_DITHER_DISABLE
|
||||
= "Nondithered rendering mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_DITHERING} key.
|
||||
*/
|
||||
public static final Object VALUE_DITHER_ENABLE
|
||||
= "Dithered rendering mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_DITHERING} key.
|
||||
*/
|
||||
public static final Object VALUE_DITHER_DEFAULT
|
||||
= "Default dithering mode";
|
||||
|
||||
/**
|
||||
* A key for the 'text antialiasing' hint. Permitted values are:
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_TEXT_ANTIALIAS_ON}</td>
|
||||
* <td>Render text with antialiasing (better quality usually).</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_TEXT_ANTIALIAS_OFF}</td>
|
||||
* <td>Render test without antialiasing (better speed).</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_TEXT_ANTIALIAS_DEFAULT}</td>
|
||||
* <td>Use the default value for text antialiasing.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
public static final Key KEY_TEXT_ANTIALIASING;
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_TEXT_ANTIALIASING} key.
|
||||
*/
|
||||
public static final Object VALUE_TEXT_ANTIALIAS_ON
|
||||
= "Antialiased text mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_TEXT_ANTIALIASING} key.
|
||||
*/
|
||||
public static final Object VALUE_TEXT_ANTIALIAS_OFF
|
||||
= "Nonantialiased text mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_TEXT_ANTIALIASING} key.
|
||||
*/
|
||||
public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT
|
||||
= "Default antialiasing text mode";
|
||||
|
||||
/**
|
||||
* A key for the 'fractional metrics' hint. Permitted values are:
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_FRACTIONALMETRICS_OFF}</td>
|
||||
* <td>Render text with fractional metrics off.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_FRACTIONALMETRICS_ON}</td>
|
||||
* <td>Render text with fractional metrics on.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_FRACTIONALMETRICS_DEFAULT}</td>
|
||||
* <td>Use the default value for fractional metrics.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
public static final Key KEY_FRACTIONALMETRICS;
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_FRACTIONALMETRICS} key.
|
||||
*/
|
||||
public static final Object VALUE_FRACTIONALMETRICS_OFF
|
||||
= "Integer text metrics mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_FRACTIONALMETRICS} key.
|
||||
*/
|
||||
public static final Object VALUE_FRACTIONALMETRICS_ON
|
||||
= "Fractional text metrics mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_FRACTIONALMETRICS} key.
|
||||
*/
|
||||
public static final Object VALUE_FRACTIONALMETRICS_DEFAULT
|
||||
= "Default fractional text metrics mode";
|
||||
|
||||
/**
|
||||
* A key for the 'interpolation' hint. Permitted values are:
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_INTERPOLATION_NEAREST_NEIGHBOR}</td>
|
||||
* <td>Use nearest neighbour interpolation.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_INTERPOLATION_BILINEAR}</td>
|
||||
* <td>Use bilinear interpolation.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_INTERPOLATION_BICUBIC}</td>
|
||||
* <td>Use bicubic interpolation.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
public static final Key KEY_INTERPOLATION;
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_INTERPOLATION} key.
|
||||
*/
|
||||
public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR
|
||||
= "Nearest Neighbor image interpolation mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_INTERPOLATION} key.
|
||||
*/
|
||||
public static final Object VALUE_INTERPOLATION_BILINEAR
|
||||
= "Bilinear image interpolation mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_INTERPOLATION} key.
|
||||
*/
|
||||
public static final Object VALUE_INTERPOLATION_BICUBIC
|
||||
= "Bicubic image interpolation mode";
|
||||
|
||||
/**
|
||||
* A key for the 'alpha interpolation' hint. Permitted values are:
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_ALPHA_INTERPOLATION_SPEED}</td>
|
||||
* <td>Prefer speed over quality.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_ALPHA_INTERPOLATION_QUALITY}</td>
|
||||
* <td>Prefer quality over speed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_ALPHA_INTERPOLATION_DEFAULT}</td>
|
||||
* <td>Use the default setting.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
public static final Key KEY_ALPHA_INTERPOLATION;
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_ALPHA_INTERPOLATION} key.
|
||||
*/
|
||||
public static final Object VALUE_ALPHA_INTERPOLATION_SPEED
|
||||
= "Fastest alpha blending methods";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_ALPHA_INTERPOLATION} key.
|
||||
*/
|
||||
public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY
|
||||
= "Highest quality alpha blending methods";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_ALPHA_INTERPOLATION} key.
|
||||
*/
|
||||
public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT
|
||||
= "Default alpha blending methods";
|
||||
|
||||
/**
|
||||
* A key for the 'color rendering' hint. Permitted values are:
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_COLOR_RENDER_SPEED}</td>
|
||||
* <td>Prefer speed over quality.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_COLOR_RENDER_QUALITY}</td>
|
||||
* <td>Prefer quality over speed.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_COLOR_RENDER_DEFAULT}</td>
|
||||
* <td>Use the default setting.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
public static final Key KEY_COLOR_RENDERING;
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_COLOR_RENDERING} key.
|
||||
*/
|
||||
public static final Object VALUE_COLOR_RENDER_SPEED
|
||||
= "Fastest color rendering mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_COLOR_RENDERING} key.
|
||||
*/
|
||||
public static final Object VALUE_COLOR_RENDER_QUALITY
|
||||
= "Highest quality color rendering mode";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_COLOR_RENDERING} key.
|
||||
*/
|
||||
public static final Object VALUE_COLOR_RENDER_DEFAULT
|
||||
= "Default color rendering mode";
|
||||
|
||||
/**
|
||||
* A key for the 'stroke control' hint. Permitted values are:
|
||||
* <p>
|
||||
* <table>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_STROKE_DEFAULT}</td>
|
||||
* <td>Use the default setting.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_STROKE_NORMALIZE}</td>
|
||||
* <td>XXX</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>{@link #VALUE_STROKE_PURE}</td>
|
||||
* <td>XXX</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
public static final Key KEY_STROKE_CONTROL;
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_STROKE_CONTROL} key.
|
||||
*/
|
||||
public static final Object VALUE_STROKE_DEFAULT
|
||||
= "Default stroke normalization";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_STROKE_CONTROL} key.
|
||||
*/
|
||||
public static final Object VALUE_STROKE_NORMALIZE
|
||||
= "Normalize strokes for consistent rendering";
|
||||
|
||||
/**
|
||||
* This value is for use with the {@link #KEY_STROKE_CONTROL} key.
|
||||
*/
|
||||
public static final Object VALUE_STROKE_PURE
|
||||
= "Pure stroke conversion for accurate paths";
|
||||
|
||||
static
|
||||
{
|
||||
KEY_ANTIALIASING = new KeyImpl(1, "Global antialiasing enable key",
|
||||
VALUE_ANTIALIAS_ON,
|
||||
VALUE_ANTIALIAS_OFF,
|
||||
VALUE_ANTIALIAS_DEFAULT);
|
||||
KEY_RENDERING = new KeyImpl(2, "Global rendering quality key",
|
||||
VALUE_RENDER_SPEED,
|
||||
VALUE_RENDER_QUALITY,
|
||||
VALUE_RENDER_DEFAULT);
|
||||
KEY_DITHERING = new KeyImpl(3, "Dithering quality key",
|
||||
VALUE_DITHER_DISABLE,
|
||||
VALUE_DITHER_ENABLE,
|
||||
VALUE_DITHER_DEFAULT);
|
||||
KEY_TEXT_ANTIALIASING
|
||||
= new KeyImpl(4, "Text-specific antialiasing enable key",
|
||||
VALUE_TEXT_ANTIALIAS_ON,
|
||||
VALUE_TEXT_ANTIALIAS_OFF,
|
||||
VALUE_TEXT_ANTIALIAS_DEFAULT);
|
||||
KEY_FRACTIONALMETRICS = new KeyImpl(5, "Fractional metrics enable key",
|
||||
VALUE_FRACTIONALMETRICS_OFF,
|
||||
VALUE_FRACTIONALMETRICS_ON,
|
||||
VALUE_FRACTIONALMETRICS_DEFAULT);
|
||||
KEY_INTERPOLATION = new KeyImpl(6, "Image interpolation method key",
|
||||
VALUE_INTERPOLATION_NEAREST_NEIGHBOR,
|
||||
VALUE_INTERPOLATION_BILINEAR,
|
||||
VALUE_INTERPOLATION_BICUBIC);
|
||||
KEY_ALPHA_INTERPOLATION
|
||||
= new KeyImpl(7, "Alpha blending interpolation method key",
|
||||
VALUE_ALPHA_INTERPOLATION_SPEED,
|
||||
VALUE_ALPHA_INTERPOLATION_QUALITY,
|
||||
VALUE_ALPHA_INTERPOLATION_DEFAULT);
|
||||
KEY_COLOR_RENDERING = new KeyImpl(8, "Color rendering quality key",
|
||||
VALUE_COLOR_RENDER_SPEED,
|
||||
VALUE_COLOR_RENDER_QUALITY,
|
||||
VALUE_COLOR_RENDER_DEFAULT);
|
||||
KEY_STROKE_CONTROL = new KeyImpl(9, "Stroke normalization control key",
|
||||
VALUE_STROKE_DEFAULT,
|
||||
VALUE_STROKE_NORMALIZE,
|
||||
VALUE_STROKE_PURE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new collection of hints containing all the (key, value) pairs
|
||||
* in the specified map.
|
||||
*
|
||||
* @param init a map containing a collection of hints (<code>null</code>
|
||||
* permitted).
|
||||
*/
|
||||
public RenderingHints(Map init)
|
||||
{
|
||||
if (init != null)
|
||||
putAll(init);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new collection containing a single (key, value) pair.
|
||||
*
|
||||
* @param key the key.
|
||||
* @param value the value.
|
||||
*/
|
||||
public RenderingHints(Key key, Object value)
|
||||
{
|
||||
put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of hints in the collection.
|
||||
*
|
||||
* @return The number of hints.
|
||||
*/
|
||||
public int size()
|
||||
{
|
||||
return hintMap.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if there are no hints in the collection,
|
||||
* and <code>false</code> otherwise.
|
||||
*
|
||||
* @return A boolean.
|
||||
*/
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return hintMap.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the collection of hints contains the
|
||||
* specified key, and <code>false</code> otherwise.
|
||||
*
|
||||
* @param key the key (<code>null</code> not permitted).
|
||||
*
|
||||
* @return A boolean.
|
||||
*
|
||||
* @throws NullPointerException if <code>key</code> is <code>null</code>.
|
||||
* @throws ClassCastException if <code>key</code> is not a {@link Key}.
|
||||
*/
|
||||
public boolean containsKey(Object key)
|
||||
{
|
||||
if (key == null)
|
||||
throw new NullPointerException();
|
||||
// don't remove the cast, it is necessary to throw the required exception
|
||||
return hintMap.containsKey((Key) key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the collection of hints contains the
|
||||
* specified value, and <code>false</code> otherwise.
|
||||
*
|
||||
* @param value the value.
|
||||
*
|
||||
* @return A boolean.
|
||||
*/
|
||||
public boolean containsValue(Object value)
|
||||
{
|
||||
return hintMap.containsValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value associated with the specified key, or <code>null</code>
|
||||
* if there is no value defined for the key.
|
||||
*
|
||||
* @param key the key (<code>null</code> permitted).
|
||||
*
|
||||
* @return The value (possibly <code>null</code>).
|
||||
*
|
||||
* @throws ClassCastException if <code>key</code> is not a {@link Key}.
|
||||
*
|
||||
* @see #containsKey(Object)
|
||||
*/
|
||||
public Object get(Object key)
|
||||
{
|
||||
// don't remove the cast, it is necessary to throw the required exception
|
||||
return hintMap.get((Key) key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a (key, value) pair to the collection of hints (if the
|
||||
* collection already contains the specified key, then the
|
||||
* value is updated).
|
||||
*
|
||||
* @param key the key.
|
||||
* @param value the value.
|
||||
*
|
||||
* @return the previous value of the key or <code>null</code> if the key
|
||||
* didn't have a value yet.
|
||||
*/
|
||||
public Object put(Object key, Object value)
|
||||
{
|
||||
if (key == null || value == null)
|
||||
throw new NullPointerException();
|
||||
if (! ((Key) key).isCompatibleValue(value))
|
||||
throw new IllegalArgumentException();
|
||||
return hintMap.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all the hints from a collection to this collection.
|
||||
*
|
||||
* @param hints the hint collection.
|
||||
*/
|
||||
public void add(RenderingHints hints)
|
||||
{
|
||||
hintMap.putAll(hints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all the hints from this collection.
|
||||
*/
|
||||
public void clear()
|
||||
{
|
||||
hintMap.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a hint from the collection.
|
||||
*
|
||||
* @param key the key.
|
||||
*
|
||||
* @return The value that was associated with the key, or <code>null</code> if
|
||||
* the key was not part of the collection
|
||||
*
|
||||
* @throws ClassCastException if the key is not a subclass of
|
||||
* {@link RenderingHints.Key}.
|
||||
*/
|
||||
public Object remove(Object key)
|
||||
{
|
||||
// don't remove the (Key) cast, it is necessary to throw the exception
|
||||
// required by the spec
|
||||
return hintMap.remove((Key) key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a collection of (key, value) pairs to the collection.
|
||||
*
|
||||
* @param m a map containing (key, value) items.
|
||||
*
|
||||
* @throws ClassCastException if the map contains a key that is not
|
||||
* a subclass of {@link RenderingHints.Key}.
|
||||
* @throws IllegalArgumentException if the map contains a value that is
|
||||
* not compatible with its key.
|
||||
*/
|
||||
public void putAll(Map m)
|
||||
{
|
||||
// preprocess map to generate appropriate exceptions
|
||||
Iterator iterator = m.keySet().iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Key key = (Key) iterator.next();
|
||||
if (!key.isCompatibleValue(m.get(key)))
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
// map is OK, update
|
||||
hintMap.putAll(m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set containing the keys from this collection.
|
||||
*
|
||||
* @return A set of keys.
|
||||
*/
|
||||
public Set keySet()
|
||||
{
|
||||
return hintMap.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a collection of the values from this hint collection. The
|
||||
* collection is backed by the <code>RenderingHints</code> instance,
|
||||
* so updates to one will affect the other.
|
||||
*
|
||||
* @return A collection of values.
|
||||
*/
|
||||
public Collection values()
|
||||
{
|
||||
return hintMap.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a set of entries from the collection.
|
||||
*
|
||||
* @return A set of entries.
|
||||
*/
|
||||
public Set entrySet()
|
||||
{
|
||||
return Collections.unmodifiableSet(hintMap.entrySet());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks this collection for equality with an arbitrary object.
|
||||
*
|
||||
* @param o the object (<code>null</code> permitted)
|
||||
*
|
||||
* @return A boolean.
|
||||
*/
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
return hintMap.equals(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code for the collection of hints.
|
||||
*
|
||||
* @return A hash code.
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
return hintMap.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a clone of this instance.
|
||||
*
|
||||
* @return A clone.
|
||||
*/
|
||||
public Object clone()
|
||||
{
|
||||
try
|
||||
{
|
||||
RenderingHints copy = (RenderingHints) super.clone();
|
||||
copy.hintMap = (HashMap) hintMap.clone();
|
||||
return copy;
|
||||
}
|
||||
catch (CloneNotSupportedException e)
|
||||
{
|
||||
throw (Error) new InternalError().initCause(e); // Impossible
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this instance.
|
||||
*
|
||||
* @return A string.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return hintMap.toString();
|
||||
}
|
||||
} // class RenderingHints
|
||||
@@ -0,0 +1,423 @@
|
||||
/* Robot.java -- a native input event generator
|
||||
Copyright (C) 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import gnu.java.awt.ClasspathToolkit;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.peer.RobotPeer;
|
||||
|
||||
/**
|
||||
* The Robot class is used to simulate user interaction with graphical
|
||||
* programs. It can generate native windowing system input events and
|
||||
* retrieve image data from the current screen. Robot is used to test
|
||||
* the AWT and Swing library implementations; it can also be used to
|
||||
* create self-running demo programs.
|
||||
*
|
||||
* Since Robot generates native windowing system events, rather than
|
||||
* simply inserting {@link AWTEvent}s on the AWT event queue, its use
|
||||
* is not restricted to Java programs. It can be used to
|
||||
* programatically drive any graphical application.
|
||||
*
|
||||
* This implementation requires an X server that supports the XTest
|
||||
* extension.
|
||||
*
|
||||
* @author Thomas Fitzsimmons (fitzsim@redhat.com)
|
||||
*
|
||||
* @since 1.3
|
||||
*/
|
||||
public class Robot
|
||||
{
|
||||
private boolean waitForIdle;
|
||||
private int autoDelay;
|
||||
private RobotPeer peer;
|
||||
|
||||
/**
|
||||
* Construct a Robot object that operates on the default screen.
|
||||
*
|
||||
* @exception AWTException if GraphicsEnvironment.isHeadless()
|
||||
* returns true or if the X server does not support the XTest
|
||||
* extension
|
||||
* @exception SecurityException if createRobot permission is not
|
||||
* granted
|
||||
*/
|
||||
public Robot () throws AWTException
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless ())
|
||||
throw new AWTException ("Robot: headless graphics environment");
|
||||
|
||||
SecurityManager sm = System.getSecurityManager ();
|
||||
if (sm != null)
|
||||
sm.checkPermission (new AWTPermission ("createRobot"));
|
||||
|
||||
ClasspathToolkit tk = (ClasspathToolkit) Toolkit.getDefaultToolkit ();
|
||||
|
||||
// createRobot will throw AWTException if XTest is not supported.
|
||||
peer = tk.createRobot (GraphicsEnvironment.getLocalGraphicsEnvironment ()
|
||||
.getDefaultScreenDevice ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a Robot object that operates on the specified screen.
|
||||
*
|
||||
* @exception AWTException if GraphicsEnvironment.isHeadless()
|
||||
* returns true or if the X server does not support the XTest
|
||||
* extension
|
||||
* @exception IllegalArgumentException if screen is not a screen
|
||||
* GraphicsDevice
|
||||
* @exception SecurityException if createRobot permission is not
|
||||
* granted
|
||||
*/
|
||||
public Robot (GraphicsDevice screen) throws AWTException
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless ())
|
||||
throw new AWTException ("Robot: headless graphics environment");
|
||||
|
||||
if (screen.getType () != GraphicsDevice.TYPE_RASTER_SCREEN)
|
||||
throw new IllegalArgumentException ("Robot: graphics"
|
||||
+ " device is not a screen");
|
||||
|
||||
SecurityManager sm = System.getSecurityManager ();
|
||||
if (sm != null)
|
||||
sm.checkPermission (new AWTPermission ("createRobot"));
|
||||
|
||||
ClasspathToolkit tk = (ClasspathToolkit) Toolkit.getDefaultToolkit ();
|
||||
|
||||
// createRobot will throw AWTException if XTest is not supported.
|
||||
peer = tk.createRobot (screen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the mouse pointer to absolute coordinates (x, y).
|
||||
*
|
||||
* @param x the destination x coordinate
|
||||
* @param y the destination y coordinate
|
||||
*/
|
||||
public void mouseMove(int x, int y)
|
||||
{
|
||||
peer.mouseMove (x, y);
|
||||
|
||||
if (waitForIdle)
|
||||
waitForIdle ();
|
||||
|
||||
if (autoDelay > 0)
|
||||
delay (autoDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Press one or more mouse buttons.
|
||||
*
|
||||
* @param buttons the buttons to press; a bitmask of one or more of
|
||||
* these {@link InputEvent} fields:
|
||||
*
|
||||
* <ul>
|
||||
* <li>BUTTON1_MASK</li>
|
||||
* <li>BUTTON2_MASK</li>
|
||||
* <li>BUTTON3_MASK</li>
|
||||
* </ul>
|
||||
*
|
||||
* @exception IllegalArgumentException if the button mask is invalid
|
||||
*/
|
||||
public void mousePress (int buttons)
|
||||
{
|
||||
if ((buttons & InputEvent.BUTTON1_MASK) == 0
|
||||
&& (buttons & InputEvent.BUTTON2_MASK) == 0
|
||||
&& (buttons & InputEvent.BUTTON3_MASK) == 0)
|
||||
throw new IllegalArgumentException ("Robot: mousePress:"
|
||||
+ " invalid button mask");
|
||||
|
||||
peer.mousePress (buttons);
|
||||
|
||||
if (waitForIdle)
|
||||
waitForIdle ();
|
||||
|
||||
if (autoDelay > 0)
|
||||
delay (autoDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release one or more mouse buttons.
|
||||
*
|
||||
* @param buttons the buttons to release; a bitmask of one or more
|
||||
* of these {@link InputEvent} fields:
|
||||
*
|
||||
* <ul>
|
||||
* <li>BUTTON1_MASK</li>
|
||||
* <li>BUTTON2_MASK</li>
|
||||
* <li>BUTTON3_MASK</li>
|
||||
* </ul>
|
||||
*
|
||||
* @exception IllegalArgumentException if the button mask is invalid
|
||||
*/
|
||||
public void mouseRelease(int buttons)
|
||||
{
|
||||
if ((buttons & InputEvent.BUTTON1_MASK) == 0
|
||||
&& (buttons & InputEvent.BUTTON2_MASK) == 0
|
||||
&& (buttons & InputEvent.BUTTON3_MASK) == 0)
|
||||
throw new IllegalArgumentException ("Robot: mouseRelease:"
|
||||
+ " invalid button mask");
|
||||
|
||||
peer.mouseRelease (buttons);
|
||||
|
||||
if (waitForIdle)
|
||||
waitForIdle ();
|
||||
|
||||
if (autoDelay > 0)
|
||||
delay (autoDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotate the mouse scroll wheel.
|
||||
*
|
||||
* @param wheelAmt number of steps to rotate mouse wheel. negative
|
||||
* to rotate wheel up (away from the user), positive to rotate wheel
|
||||
* down (toward the user).
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void mouseWheel (int wheelAmt)
|
||||
{
|
||||
peer.mouseWheel (wheelAmt);
|
||||
|
||||
if (waitForIdle)
|
||||
waitForIdle ();
|
||||
|
||||
if (autoDelay > 0)
|
||||
delay (autoDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Press a key.
|
||||
*
|
||||
* @param keycode key to press, a {@link java.awt.event.KeyEvent} VK_ constant
|
||||
*
|
||||
* @exception IllegalArgumentException if keycode is not a valid key
|
||||
*/
|
||||
public void keyPress (int keycode)
|
||||
{
|
||||
peer.keyPress (keycode);
|
||||
|
||||
if (waitForIdle)
|
||||
waitForIdle ();
|
||||
|
||||
if (autoDelay > 0)
|
||||
delay (autoDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release a key.
|
||||
*
|
||||
* @param keycode key to release, a {@link java.awt.event.KeyEvent} VK_
|
||||
* constant
|
||||
*
|
||||
* @exception IllegalArgumentException if keycode is not a valid key
|
||||
*/
|
||||
public void keyRelease (int keycode)
|
||||
{
|
||||
peer.keyRelease (keycode);
|
||||
|
||||
if (waitForIdle)
|
||||
waitForIdle ();
|
||||
|
||||
if (autoDelay > 0)
|
||||
delay (autoDelay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the color of the pixel at the given screen coordinates.
|
||||
*
|
||||
* @param x the x coordinate of the pixel
|
||||
* @param y the y coordinate of the pixel
|
||||
*
|
||||
* @return the Color of the pixel at screen coodinates <code>(x, y)</code>
|
||||
*/
|
||||
public Color getPixelColor (int x, int y)
|
||||
{
|
||||
return new Color (peer.getRGBPixel (x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an image containing pixels read from the screen. The
|
||||
* image does not include the mouse pointer.
|
||||
*
|
||||
* @param screenRect the rectangle of pixels to capture, in screen
|
||||
* coordinates
|
||||
*
|
||||
* @return a BufferedImage containing the requested pixels
|
||||
*
|
||||
* @exception IllegalArgumentException if requested width and height
|
||||
* are not both greater than zero
|
||||
* @exception SecurityException if readDisplayPixels permission is
|
||||
* not granted
|
||||
*/
|
||||
public BufferedImage createScreenCapture (Rectangle screenRect)
|
||||
{
|
||||
if (screenRect.width <= 0)
|
||||
throw new IllegalArgumentException ("Robot: capture width is <= 0");
|
||||
|
||||
if (screenRect.height <= 0)
|
||||
throw new IllegalArgumentException ("Robot: capture height is <= 0");
|
||||
|
||||
SecurityManager sm = System.getSecurityManager ();
|
||||
if (sm != null)
|
||||
sm.checkPermission (new AWTPermission ("readDisplayPixels"));
|
||||
|
||||
int[] pixels = peer.getRGBPixels (screenRect);
|
||||
|
||||
BufferedImage bufferedImage =
|
||||
new BufferedImage (screenRect.width, screenRect.height,
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
bufferedImage.setRGB (0, 0, screenRect.width, screenRect.height,
|
||||
pixels, 0, screenRect.width);
|
||||
|
||||
return bufferedImage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this Robot automatically calls {@link #waitForIdle()} after
|
||||
* generating an event.
|
||||
*
|
||||
* @return true if waitForIdle is automatically called
|
||||
*/
|
||||
public boolean isAutoWaitForIdle ()
|
||||
{
|
||||
return waitForIdle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether or not this Robot automatically calls {@link
|
||||
* #waitForIdle()} after generating an event.
|
||||
*
|
||||
* @param isOn true if waitForIdle should be called automatically
|
||||
*/
|
||||
public void setAutoWaitForIdle (boolean isOn)
|
||||
{
|
||||
waitForIdle = isOn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the length of time this Robot sleeps after generating an
|
||||
* event.
|
||||
*
|
||||
* @return the length of time in milliseconds
|
||||
*/
|
||||
public int getAutoDelay ()
|
||||
{
|
||||
return autoDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the length of time this Robot sleeps after generating an
|
||||
* event.
|
||||
*
|
||||
* @param ms the length of time in milliseconds
|
||||
*
|
||||
* @exception IllegalArgumentException if ms is not between 0 and
|
||||
* 60,000 milliseconds inclusive
|
||||
*/
|
||||
public void setAutoDelay (int ms)
|
||||
{
|
||||
if (ms <= 0 || ms >= 60000)
|
||||
throw new IllegalArgumentException ("Robot: delay length out-of-bounds");
|
||||
|
||||
autoDelay = ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sleep for a specified length of time.
|
||||
*
|
||||
* @param ms the length of time in milliseconds
|
||||
*
|
||||
* @exception IllegalArgumentException if ms is not between 0 and
|
||||
* 60,000 milliseconds inclusive
|
||||
*/
|
||||
public void delay (int ms)
|
||||
{
|
||||
if (ms < 0 || ms > 60000)
|
||||
throw new IllegalArgumentException ("Robot: delay length out-of-bounds");
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep (ms);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
System.err.println ("Robot: delay interrupted");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until all events currently on the event queue have been
|
||||
* dispatched.
|
||||
*/
|
||||
public void waitForIdle ()
|
||||
{
|
||||
if (EventQueue.isDispatchThread ())
|
||||
throw new IllegalThreadStateException ("Robot: waitForIdle called from "
|
||||
+ "the event dispatch thread");
|
||||
|
||||
try
|
||||
{
|
||||
EventQueue.invokeAndWait (new Runnable () { public void run () { } });
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
System.err.println ("Robot: waitForIdle interrupted");
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
System.err.println ("Robot: waitForIdle cannot invoke target");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this Robot.
|
||||
*
|
||||
* @return a string representation
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return getClass ().getName ()
|
||||
+ "[ autoDelay = " + autoDelay + ", autoWaitForIdle = "
|
||||
+ waitForIdle + " ]";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,615 @@
|
||||
/* ScrollPane.java -- Scrolling window
|
||||
Copyright (C) 1999, 2002, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.awt.peer.ScrollPanePeer;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
|
||||
/**
|
||||
* This widget provides a scrollable region that allows a single
|
||||
* subcomponent to be viewed through a smaller window.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class ScrollPane extends Container implements Accessible
|
||||
{
|
||||
|
||||
/*
|
||||
* Static Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constant indicating that scrollbars are created as needed in this
|
||||
* windows.
|
||||
*/
|
||||
public static final int SCROLLBARS_AS_NEEDED = 0;
|
||||
|
||||
/**
|
||||
* Constant indicating that scrollbars are always displayed in this
|
||||
* window.
|
||||
*/
|
||||
public static final int SCROLLBARS_ALWAYS = 1;
|
||||
|
||||
/**
|
||||
* Constant indicating that scrollbars are never displayed in this window.
|
||||
*/
|
||||
public static final int SCROLLBARS_NEVER = 2;
|
||||
|
||||
// Serialization constant
|
||||
private static final long serialVersionUID = 7956609840827222915L;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* @serial The horizontal scrollbar for this window. The methods
|
||||
* <code>setMinimum()</code>, <code>setMaximum</code>, and
|
||||
* <code>setVisibleAmount</code> must not be called on this scrollbar.
|
||||
*/
|
||||
private ScrollPaneAdjustable hAdjustable;
|
||||
|
||||
/**
|
||||
* @serial The vertical scrollbar for this window. The methods
|
||||
* <code>setMinimum()</code>, <code>setMaximum</code>, and
|
||||
* <code>setVisibleAmount</code> must not be called on this scrollbar.
|
||||
*/
|
||||
private ScrollPaneAdjustable vAdjustable;
|
||||
|
||||
/**
|
||||
* @serial Indicates when scrollbars are displayed in this window, will
|
||||
* be one of the constants from this class.
|
||||
*/
|
||||
private int scrollbarDisplayPolicy;
|
||||
|
||||
// Current scroll position
|
||||
private Point scrollPosition = new Point(0, 0);
|
||||
|
||||
private boolean wheelScrollingEnabled;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Constructors
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>ScrollPane</code> with a default
|
||||
* scrollbar policy of <code>SCROLLBARS_AS_NEEDED</code>.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
||||
*/
|
||||
public
|
||||
ScrollPane()
|
||||
{
|
||||
this(SCROLLBARS_AS_NEEDED);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>ScrollPane</code> with the
|
||||
* specified scrollbar policy.
|
||||
*
|
||||
* @param scrollbarDisplayPolicy When to display scrollbars, which must
|
||||
* be one of the constants defined in this class.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true.
|
||||
*/
|
||||
public
|
||||
ScrollPane(int scrollbarDisplayPolicy)
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless ())
|
||||
throw new HeadlessException ();
|
||||
|
||||
this.scrollbarDisplayPolicy = scrollbarDisplayPolicy;
|
||||
|
||||
if (scrollbarDisplayPolicy != SCROLLBARS_ALWAYS
|
||||
&& scrollbarDisplayPolicy != SCROLLBARS_AS_NEEDED
|
||||
&& scrollbarDisplayPolicy != SCROLLBARS_NEVER)
|
||||
throw new IllegalArgumentException("Bad scrollbarDisplayPolicy: " +
|
||||
scrollbarDisplayPolicy);
|
||||
|
||||
if (scrollbarDisplayPolicy != SCROLLBARS_NEVER)
|
||||
{
|
||||
hAdjustable = new ScrollPaneAdjustable (this, Scrollbar.HORIZONTAL);
|
||||
vAdjustable = new ScrollPaneAdjustable (this, Scrollbar.VERTICAL);
|
||||
}
|
||||
|
||||
wheelScrollingEnabled = true;
|
||||
|
||||
// Default size.
|
||||
setSize(100,100);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns the current scrollbar display policy.
|
||||
*
|
||||
* @return The current scrollbar display policy.
|
||||
*/
|
||||
public int
|
||||
getScrollbarDisplayPolicy()
|
||||
{
|
||||
return(scrollbarDisplayPolicy);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the horizontal scrollbar for this object. If the scrollbar
|
||||
* display policy is set to <code>SCROLLBARS_NEVER</code> then this
|
||||
* will be <code>null</code>.
|
||||
*
|
||||
* @return The horizontal scrollbar for this window.
|
||||
*/
|
||||
public Adjustable
|
||||
getHAdjustable()
|
||||
{
|
||||
return(hAdjustable);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the vertical scrollbar for this object. If the scrollbar
|
||||
* display policy is set to <code>SCROLLBARS_NEVER</code> then this
|
||||
* will be <code>null</code>.
|
||||
*
|
||||
* @return The horizontal scrollbar for this window.
|
||||
*/
|
||||
public Adjustable
|
||||
getVAdjustable()
|
||||
{
|
||||
return(vAdjustable);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the current viewport size. The viewport is the region of
|
||||
* this object's window where the child is actually displayed.
|
||||
*
|
||||
* @return The viewport size.
|
||||
*/
|
||||
public Dimension getViewportSize ()
|
||||
{
|
||||
Dimension viewsize = getSize ();
|
||||
Insets insets = getInsets ();
|
||||
|
||||
viewsize.width -= (insets.left + insets.right);
|
||||
viewsize.height -= (insets.top + insets.bottom);
|
||||
|
||||
Component[] list = getComponents();
|
||||
if ((list == null) || (list.length <= 0))
|
||||
return viewsize;
|
||||
|
||||
Dimension dim = list[0].getPreferredSize();
|
||||
|
||||
if (dim.width <= 0 && dim.height <= 0)
|
||||
return viewsize;
|
||||
|
||||
int vScrollbarWidth = getVScrollbarWidth ();
|
||||
int hScrollbarHeight = getHScrollbarHeight ();
|
||||
|
||||
if (scrollbarDisplayPolicy == SCROLLBARS_ALWAYS)
|
||||
{
|
||||
viewsize.width -= vScrollbarWidth;
|
||||
viewsize.height -= hScrollbarHeight;
|
||||
return viewsize;
|
||||
}
|
||||
|
||||
if (scrollbarDisplayPolicy == SCROLLBARS_NEVER)
|
||||
return viewsize;
|
||||
|
||||
// The scroll policy is SCROLLBARS_AS_NEEDED, so we need to see if
|
||||
// either scrollbar is needed.
|
||||
|
||||
// Assume we don't need either scrollbar.
|
||||
boolean mayNeedVertical = false;
|
||||
boolean mayNeedHorizontal = false;
|
||||
|
||||
boolean needVertical = false;
|
||||
boolean needHorizontal = false;
|
||||
|
||||
// Check if we need vertical scrollbars. If we do, then we need to
|
||||
// subtract the width of the vertical scrollbar from the viewport's
|
||||
// width.
|
||||
if (dim.height > viewsize.height)
|
||||
needVertical = true;
|
||||
else if (dim.height > (viewsize.height - hScrollbarHeight))
|
||||
// This is tricky. In this case the child is tall enough that its
|
||||
// bottom edge would be covered by a horizontal scrollbar, if one
|
||||
// were present. This means that if there's a horizontal
|
||||
// scrollbar then we need a vertical scrollbar.
|
||||
mayNeedVertical = true;
|
||||
|
||||
if (dim.width > viewsize.width)
|
||||
needHorizontal = true;
|
||||
else if (dim.width > (viewsize.width - vScrollbarWidth))
|
||||
mayNeedHorizontal = true;
|
||||
|
||||
if (needVertical && mayNeedHorizontal)
|
||||
needHorizontal = true;
|
||||
|
||||
if (needHorizontal && mayNeedVertical)
|
||||
needVertical = true;
|
||||
|
||||
if (needHorizontal)
|
||||
viewsize.height -= hScrollbarHeight;
|
||||
|
||||
if (needVertical)
|
||||
viewsize.width -= vScrollbarWidth;
|
||||
|
||||
return viewsize;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the height of a horizontal scrollbar.
|
||||
*
|
||||
* @return The height of a horizontal scrollbar.
|
||||
*/
|
||||
public int
|
||||
getHScrollbarHeight()
|
||||
{
|
||||
ScrollPanePeer spp = (ScrollPanePeer)getPeer();
|
||||
if (spp != null)
|
||||
return(spp.getHScrollbarHeight());
|
||||
else
|
||||
return(0); // FIXME: What to do here?
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the width of a vertical scrollbar.
|
||||
*
|
||||
* @return The width of a vertical scrollbar.
|
||||
*/
|
||||
public int
|
||||
getVScrollbarWidth()
|
||||
{
|
||||
ScrollPanePeer spp = (ScrollPanePeer)getPeer();
|
||||
if (spp != null)
|
||||
return(spp.getVScrollbarWidth());
|
||||
else
|
||||
return(0); // FIXME: What to do here?
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the current scroll position of the viewport.
|
||||
*
|
||||
* @return The current scroll position of the viewport.
|
||||
*/
|
||||
public Point
|
||||
getScrollPosition()
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
Adjustable v = getVAdjustable();
|
||||
Adjustable h = getHAdjustable();
|
||||
|
||||
if (v != null)
|
||||
y = v.getValue();
|
||||
if (h != null)
|
||||
x = h.getValue();
|
||||
|
||||
return(new Point(x, y));
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the scroll position to the specified value.
|
||||
*
|
||||
* @param scrollPosition The new scrollPosition.
|
||||
*
|
||||
* @exception IllegalArgumentException If the specified value is outside
|
||||
* the legal scrolling range.
|
||||
*/
|
||||
public void
|
||||
setScrollPosition(Point scrollPosition) throws IllegalArgumentException
|
||||
{
|
||||
setScrollPosition(scrollPosition.x, scrollPosition.y);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Sets the scroll position to the specified value.
|
||||
*
|
||||
* @param x The new X coordinate of the scroll position.
|
||||
* @param y The new Y coordinate of the scroll position.
|
||||
*
|
||||
* @exception IllegalArgumentException If the specified value is outside
|
||||
* the legal scrolling range.
|
||||
*/
|
||||
public void
|
||||
setScrollPosition(int x, int y)
|
||||
{
|
||||
Adjustable h = getHAdjustable();
|
||||
Adjustable v = getVAdjustable();
|
||||
|
||||
if (h != null)
|
||||
h.setValue(x);
|
||||
if (v != null)
|
||||
v.setValue(y);
|
||||
|
||||
ScrollPanePeer spp = (ScrollPanePeer)getPeer();
|
||||
if (spp != null)
|
||||
spp.setScrollPosition(x, y);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Notifies this object that it should create its native peer.
|
||||
*/
|
||||
public void
|
||||
addNotify()
|
||||
{
|
||||
if (!isDisplayable ())
|
||||
return;
|
||||
|
||||
setPeer((ComponentPeer)getToolkit().createScrollPane(this));
|
||||
super.addNotify();
|
||||
|
||||
Component[] list = getComponents();
|
||||
if (list != null && list.length > 0 && ! (list[0] instanceof Panel))
|
||||
{
|
||||
Panel panel = new Panel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.add(list[0], BorderLayout.CENTER);
|
||||
add(panel);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Notifies this object that it should destroy its native peers.
|
||||
*/
|
||||
public void
|
||||
removeNotify()
|
||||
{
|
||||
super.removeNotify();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Adds the specified child component to this container. A
|
||||
* <code>ScrollPane</code> can have at most one child, so if a second
|
||||
* one is added, then first one is removed.
|
||||
*
|
||||
* @param component The component to add to this container.
|
||||
* @param constraints A list of layout constraints for this object.
|
||||
* @param index The index at which to add the child, which is ignored
|
||||
* in this implementation.
|
||||
*/
|
||||
protected final void addImpl (Component component, Object constraints,
|
||||
int index)
|
||||
{
|
||||
Component[] list = getComponents();
|
||||
if ((list != null) && (list.length > 0))
|
||||
remove(list[0]);
|
||||
|
||||
super.addImpl(component, constraints, -1);
|
||||
|
||||
doLayout();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Lays out this component. This consists of resizing the sole child
|
||||
* component to its perferred size.
|
||||
*/
|
||||
public void
|
||||
doLayout()
|
||||
{
|
||||
layout ();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Lays out this component. This consists of resizing the sole child
|
||||
* component to its perferred size.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>doLayout()</code>.
|
||||
*/
|
||||
public void
|
||||
layout()
|
||||
{
|
||||
Component[] list = getComponents ();
|
||||
if ((list != null) && (list.length > 0))
|
||||
{
|
||||
Dimension dim = list[0].getPreferredSize ();
|
||||
Dimension vp = getViewportSize ();
|
||||
|
||||
if (dim.width < vp.width)
|
||||
dim.width = vp.width;
|
||||
|
||||
if (dim.height < vp.height)
|
||||
dim.height = vp.height;
|
||||
|
||||
ScrollPanePeer peer = (ScrollPanePeer) getPeer ();
|
||||
if (peer != null)
|
||||
peer.childResized (dim.width, dim.height);
|
||||
|
||||
list[0].setSize (dim);
|
||||
|
||||
Point p = getScrollPosition ();
|
||||
if (p.x > dim.width)
|
||||
p.x = dim.width;
|
||||
if (p.y > dim.height)
|
||||
p.y = dim.height;
|
||||
|
||||
setScrollPosition (p);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* This method overrides its superclass method to ensure no layout
|
||||
* manager is set for this container. <code>ScrollPane</code>'s do
|
||||
* not have layout managers.
|
||||
*
|
||||
* @param layoutManager Ignored
|
||||
*/
|
||||
public final void
|
||||
setLayout(LayoutManager layoutManager)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Prints all of the components in this container.
|
||||
*
|
||||
* @param graphics The desired graphics context for printing.
|
||||
*/
|
||||
public void
|
||||
printComponents(Graphics graphics)
|
||||
{
|
||||
super.printComponents(graphics);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns a debug string for this object.
|
||||
*
|
||||
* @return A debug string for this object.
|
||||
*/
|
||||
public String
|
||||
paramString()
|
||||
{
|
||||
Insets insets = getInsets();
|
||||
return getName() + ","
|
||||
+ getX() + ","
|
||||
+ getY() + ","
|
||||
+ getWidth() + "x" + getHeight() + ","
|
||||
+ "ScrollPosition=(" + scrollPosition.getX() + ","
|
||||
+ scrollPosition.getY() + "),"
|
||||
+ "Insets=(" + insets.top + ","
|
||||
+ insets.left + ","
|
||||
+ insets.bottom + ","
|
||||
+ insets.right + "),"
|
||||
+ "ScrollbarDisplayPolicy=" + getScrollbarDisplayPolicy() + ","
|
||||
+ "wheelScrollingEnabled=" + isWheelScrollingEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not an event is enabled.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
protected boolean eventTypeEnabled (int type)
|
||||
{
|
||||
if (type == MouseEvent.MOUSE_WHEEL)
|
||||
return wheelScrollingEnabled;
|
||||
|
||||
return super.eventTypeEnabled (type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not wheel scrolling is enabled.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean isWheelScrollingEnabled ()
|
||||
{
|
||||
return wheelScrollingEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables/disables wheel scrolling.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void setWheelScrollingEnabled (boolean enable)
|
||||
{
|
||||
wheelScrollingEnabled = enable;
|
||||
}
|
||||
|
||||
protected class AccessibleAWTScrollPane extends AccessibleAWTContainer
|
||||
{
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.SCROLL_PANE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>ScrollPane</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTScrollPane();
|
||||
return accessibleContext;
|
||||
}
|
||||
} // class ScrollPane
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
/* ScrollPaneAdjustable.java -- Scrollbars for a ScrollPane
|
||||
Copyright (C) 1999 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.AdjustmentListener;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Need this class since the serialization spec for ScrollPane
|
||||
* uses it.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @since 1.4
|
||||
*/
|
||||
public class ScrollPaneAdjustable
|
||||
implements Adjustable, Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -3359745691033257079L;
|
||||
|
||||
ScrollPane sp;
|
||||
int orientation;
|
||||
int value;
|
||||
int minimum;
|
||||
int maximum;
|
||||
int visibleAmount;
|
||||
int unitIncrement = 1;
|
||||
int blockIncrement = 1;
|
||||
AdjustmentListener adjustmentListener;
|
||||
|
||||
private transient boolean valueIsAdjusting = false;
|
||||
|
||||
ScrollPaneAdjustable (ScrollPane sp, int orientation)
|
||||
{
|
||||
this.sp = sp;
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
ScrollPaneAdjustable (ScrollPane sp, int orientation, int value, int minimum,
|
||||
int maximum, int visibleAmount, int unitIncrement,
|
||||
int blockIncrement)
|
||||
{
|
||||
this.sp = sp;
|
||||
this.orientation = orientation;
|
||||
this.value = value;
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
this.visibleAmount = visibleAmount;
|
||||
this.unitIncrement = unitIncrement;
|
||||
this.blockIncrement = blockIncrement;
|
||||
}
|
||||
|
||||
public void addAdjustmentListener (AdjustmentListener listener)
|
||||
{
|
||||
AWTEventMulticaster.add (adjustmentListener, listener);
|
||||
}
|
||||
|
||||
public void removeAdjustmentListener (AdjustmentListener listener)
|
||||
{
|
||||
AWTEventMulticaster.remove (adjustmentListener, listener);
|
||||
}
|
||||
|
||||
public AdjustmentListener[] getAdjustmentListeners ()
|
||||
{
|
||||
return (AdjustmentListener[]) AWTEventMulticaster.getListeners
|
||||
(adjustmentListener, AdjustmentListener.class);
|
||||
}
|
||||
|
||||
public int getBlockIncrement ()
|
||||
{
|
||||
return blockIncrement;
|
||||
}
|
||||
|
||||
public int getMaximum ()
|
||||
{
|
||||
return maximum;
|
||||
}
|
||||
|
||||
public int getMinimum ()
|
||||
{
|
||||
return minimum;
|
||||
}
|
||||
|
||||
public int getOrientation ()
|
||||
{
|
||||
return orientation;
|
||||
}
|
||||
|
||||
public int getUnitIncrement ()
|
||||
{
|
||||
return unitIncrement;
|
||||
}
|
||||
|
||||
public int getValue ()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getVisibleAmount ()
|
||||
{
|
||||
return visibleAmount;
|
||||
}
|
||||
|
||||
public void setBlockIncrement (int blockIncrement)
|
||||
{
|
||||
this.blockIncrement = blockIncrement;
|
||||
}
|
||||
|
||||
public void setMaximum (int maximum)
|
||||
{
|
||||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
public void setMinimum (int minimum)
|
||||
{
|
||||
this.minimum = minimum;
|
||||
}
|
||||
|
||||
public void setUnitIncrement (int unitIncrement)
|
||||
{
|
||||
this.unitIncrement = unitIncrement;
|
||||
}
|
||||
|
||||
public void setValue (int value)
|
||||
{
|
||||
this.value = value;
|
||||
|
||||
if (value < minimum)
|
||||
minimum = value;
|
||||
|
||||
if (value > maximum)
|
||||
maximum = value;
|
||||
}
|
||||
|
||||
public void setVisibleAmount (int visibleAmount)
|
||||
{
|
||||
this.visibleAmount = visibleAmount;
|
||||
}
|
||||
|
||||
public String paramString ()
|
||||
{
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the value is in the process of changing.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean getValueIsAdjusting ()
|
||||
{
|
||||
return valueIsAdjusting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of valueIsAdjusting.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void setValueIsAdjusting (boolean valueIsAdjusting)
|
||||
{
|
||||
this.valueIsAdjusting = valueIsAdjusting;
|
||||
}
|
||||
} // class ScrollPaneAdjustable
|
||||
|
||||
@@ -0,0 +1,825 @@
|
||||
/* Scrollbar.java -- AWT Scrollbar widget
|
||||
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005
|
||||
Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.AdjustmentEvent;
|
||||
import java.awt.event.AdjustmentListener;
|
||||
import java.awt.peer.ScrollbarPeer;
|
||||
import java.util.EventListener;
|
||||
|
||||
import javax.accessibility.Accessible;
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleRole;
|
||||
import javax.accessibility.AccessibleState;
|
||||
import javax.accessibility.AccessibleStateSet;
|
||||
import javax.accessibility.AccessibleValue;
|
||||
|
||||
/**
|
||||
* This class implements a scrollbar widget.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Tom Tromey (tromey@cygnus.com)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
*/
|
||||
public class Scrollbar extends Component implements Accessible, Adjustable
|
||||
{
|
||||
// FIXME: Serialization readObject/writeObject
|
||||
|
||||
/**
|
||||
* Constant indicating that a scrollbar is horizontal.
|
||||
*/
|
||||
public static final int HORIZONTAL = 0;
|
||||
|
||||
/**
|
||||
* Constant indicating that a scrollbar is vertical.
|
||||
*/
|
||||
public static final int VERTICAL = 1;
|
||||
|
||||
/**
|
||||
* Serialization Constant.
|
||||
*/
|
||||
private static final long serialVersionUID = 8451667562882310543L;
|
||||
|
||||
/**
|
||||
* @serial The amount by which the value of the scrollbar is changed
|
||||
* when incrementing in line mode.
|
||||
*/
|
||||
private int lineIncrement;
|
||||
|
||||
/**
|
||||
* @serial The amount by which the value of the scrollbar is changed
|
||||
* when incrementing in page mode.
|
||||
*/
|
||||
private int pageIncrement;
|
||||
|
||||
/**
|
||||
* @serial The maximum value for this scrollbar
|
||||
*/
|
||||
private int maximum;
|
||||
|
||||
/**
|
||||
* @serial The minimum value for this scrollbar
|
||||
*/
|
||||
private int minimum;
|
||||
|
||||
/**
|
||||
* @serial The orientation of this scrollbar, which will be either
|
||||
* the <code>HORIZONTAL</code> or <code>VERTICAL</code> constant
|
||||
* from this class.
|
||||
*/
|
||||
private int orientation;
|
||||
|
||||
/**
|
||||
* @serial The current value of this scrollbar.
|
||||
*/
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* @serial The width of the scrollbar's thumb, which is relative
|
||||
* to the minimum and maximum value of the scrollbar.
|
||||
*/
|
||||
private int visibleAmount;
|
||||
|
||||
/**
|
||||
* List of AdjustmentListener's.
|
||||
*/
|
||||
private AdjustmentListener adjustment_listeners;
|
||||
|
||||
/**
|
||||
* true if the scrollbar is adjusting, false otherwise.
|
||||
*/
|
||||
private transient boolean valueIsAdjusting = false;
|
||||
|
||||
/**
|
||||
* The number used to generate the name returned by getName.
|
||||
*/
|
||||
private static transient long next_scrollbar_number;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Scrollbar</code> with a
|
||||
* vertical orientation and default values for all other parameters.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true,
|
||||
*/
|
||||
public Scrollbar()
|
||||
{
|
||||
this(VERTICAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Scrollbar</code> with the
|
||||
* specified orientation and default values for all other parameters.
|
||||
* The orientation must be either the constant <code>HORIZONTAL</code> or
|
||||
* <code>VERTICAL</code> from this class. An incorrect value will throw
|
||||
* an exception.
|
||||
*
|
||||
* @param orientation The orientation of this scrollbar.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true,
|
||||
* @exception IllegalArgumentException If the orientation value is not valid.
|
||||
*/
|
||||
public Scrollbar(int orientation) throws IllegalArgumentException
|
||||
{
|
||||
this(orientation, 0, 10, 0, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of <code>Scrollbar</code> with the
|
||||
* specified parameters. The orientation must be either the constant
|
||||
* <code>HORIZONTAL</code> or <code>VERTICAL</code>. An incorrect value
|
||||
* will throw an exception. Inconsistent values for other parameters
|
||||
* are silently corrected to valid values.
|
||||
*
|
||||
* @param orientation The orientation of this scrollbar.
|
||||
* @param value The initial value of the scrollbar.
|
||||
* @param visibleAmount The width of the scrollbar thumb.
|
||||
* @param minimum The minimum value of the scrollbar.
|
||||
* @param maximum The maximum value of the scrollbar.
|
||||
*
|
||||
* @exception HeadlessException If GraphicsEnvironment.isHeadless() is true,
|
||||
* @exception IllegalArgumentException If the orientation value is not valid.
|
||||
*/
|
||||
public Scrollbar(int orientation, int value, int visibleAmount, int minimum,
|
||||
int maximum) throws IllegalArgumentException
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless())
|
||||
throw new HeadlessException();
|
||||
|
||||
if ((orientation != HORIZONTAL) && (orientation != VERTICAL))
|
||||
throw new IllegalArgumentException("Bad orientation value: "
|
||||
+ orientation);
|
||||
|
||||
this.orientation = orientation;
|
||||
|
||||
setValues(value, visibleAmount, minimum, maximum);
|
||||
|
||||
// Default is 1 according to online docs.
|
||||
lineIncrement = 1;
|
||||
|
||||
// Default is 10 according to javadocs.
|
||||
pageIncrement = 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the orientation constant for this object.
|
||||
*
|
||||
* @return The orientation constant for this object.
|
||||
*/
|
||||
public int getOrientation()
|
||||
{
|
||||
return orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the orientation of this scrollbar to the specified value. This
|
||||
* value must be either the constant <code>HORIZONTAL</code> or
|
||||
* <code>VERTICAL</code> from this class or an exception will be thrown.
|
||||
*
|
||||
* @param orientation The new orientation value.
|
||||
*
|
||||
* @exception IllegalArgumentException If the orientation value is not valid.
|
||||
*/
|
||||
public void setOrientation(int orientation)
|
||||
{
|
||||
if ((orientation != HORIZONTAL) && (orientation != VERTICAL))
|
||||
throw new IllegalArgumentException("Bad orientation value: "
|
||||
+ orientation);
|
||||
|
||||
// FIXME: Communicate to peer? Or must this be called before peer creation?
|
||||
this.orientation = orientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current value for this scrollbar.
|
||||
*
|
||||
* @return The current value for this scrollbar.
|
||||
*/
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current value for this scrollbar to the specified value.
|
||||
* If this is inconsistent with the minimum and maximum values for this
|
||||
* scrollbar, the value is silently adjusted.
|
||||
*
|
||||
* @param value The new value for this scrollbar.
|
||||
*/
|
||||
public void setValue(int value)
|
||||
{
|
||||
setValues(value, visibleAmount, minimum, maximum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum value for this scrollbar.
|
||||
*
|
||||
* @return The maximum value for this scrollbar.
|
||||
*/
|
||||
public int getMaximum()
|
||||
{
|
||||
return maximum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum value for this scrollbar to the specified value.
|
||||
* If the value is less than the current minimum value, it is silent
|
||||
* set to equal the minimum value.
|
||||
*
|
||||
* @param maximum The new maximum value for this scrollbar.
|
||||
*/
|
||||
public void setMaximum(int maximum)
|
||||
{
|
||||
setValues(value, visibleAmount, minimum, maximum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum value for this scrollbar.
|
||||
*
|
||||
* @return The minimum value for this scrollbar.
|
||||
*/
|
||||
public int getMinimum()
|
||||
{
|
||||
return minimum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum value for this scrollbar to the specified value. If
|
||||
* this is not consistent with the current value and maximum, it is
|
||||
* silently adjusted to be consistent.
|
||||
*
|
||||
* @param minimum The new minimum value for this scrollbar.
|
||||
*/
|
||||
public void setMinimum(int minimum)
|
||||
{
|
||||
setValues(value, visibleAmount, minimum, maximum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the scrollbar's thumb, in units relative to the
|
||||
* maximum and minimum value of the scrollbar.
|
||||
*
|
||||
* @return The width of the scrollbar's thumb.
|
||||
*/
|
||||
public int getVisibleAmount()
|
||||
{
|
||||
return getVisible();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width of the scrollbar's thumb, in units relative to the
|
||||
* maximum and minimum value of the scrollbar.
|
||||
*
|
||||
* @return The width of the scrollbar's thumb.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getVisibleAmount()</code>.
|
||||
*/
|
||||
public int getVisible()
|
||||
{
|
||||
return visibleAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the width of the scrollbar's thumb, in units relative to the
|
||||
* maximum and minimum value of the scrollbar.
|
||||
*
|
||||
* @param visibleAmount The new visible amount value of the scrollbar.
|
||||
*/
|
||||
public void setVisibleAmount(int visibleAmount)
|
||||
{
|
||||
setValues(value, visibleAmount, minimum, maximum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current value, visible amount, minimum, and maximum for this
|
||||
* scrollbar. These values are adjusted to be internally consistent
|
||||
* if necessary.
|
||||
*
|
||||
* @param value The new value for this scrollbar.
|
||||
* @param visibleAmount The new visible amount for this scrollbar.
|
||||
* @param minimum The new minimum value for this scrollbar.
|
||||
* @param maximum The new maximum value for this scrollbar.
|
||||
*/
|
||||
public synchronized void setValues(int value, int visibleAmount,
|
||||
int minimum, int maximum)
|
||||
{
|
||||
if (maximum < minimum)
|
||||
maximum = minimum;
|
||||
|
||||
if (value < minimum)
|
||||
value = minimum;
|
||||
|
||||
if (value > maximum)
|
||||
value = maximum;
|
||||
|
||||
if (visibleAmount > maximum - minimum)
|
||||
visibleAmount = maximum - minimum;
|
||||
|
||||
ScrollbarPeer peer = (ScrollbarPeer) getPeer();
|
||||
if (peer != null
|
||||
&& (this.value != value || this.visibleAmount != visibleAmount
|
||||
|| this.minimum != minimum || this.maximum != maximum))
|
||||
peer.setValues(value, visibleAmount, minimum, maximum);
|
||||
|
||||
this.value = value;
|
||||
this.visibleAmount = visibleAmount;
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
|
||||
int range = maximum - minimum;
|
||||
if (lineIncrement > range)
|
||||
{
|
||||
if (range == 0)
|
||||
lineIncrement = 1;
|
||||
else
|
||||
lineIncrement = range;
|
||||
|
||||
if (peer != null)
|
||||
peer.setLineIncrement(lineIncrement);
|
||||
}
|
||||
|
||||
if (pageIncrement > range)
|
||||
{
|
||||
if (range == 0)
|
||||
pageIncrement = 1;
|
||||
else
|
||||
pageIncrement = range;
|
||||
|
||||
if (peer != null)
|
||||
peer.setPageIncrement(pageIncrement);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value added or subtracted when the user activates the scrollbar
|
||||
* scroll by a "unit" amount.
|
||||
*
|
||||
* @return The unit increment value.
|
||||
*/
|
||||
public int getUnitIncrement()
|
||||
{
|
||||
return getLineIncrement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value added or subtracted when the user selects the scrollbar
|
||||
* scroll by a "unit" amount control.
|
||||
*
|
||||
* @return The unit increment value.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getUnitIncrement()</code>.
|
||||
*/
|
||||
public int getLineIncrement()
|
||||
{
|
||||
return lineIncrement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value added or subtracted to the scrollbar value when the
|
||||
* user selects the scroll by a "unit" amount control.
|
||||
*
|
||||
* @param unitIncrement The new unit increment amount.
|
||||
*/
|
||||
public synchronized void setUnitIncrement(int unitIncrement)
|
||||
{
|
||||
setLineIncrement(unitIncrement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value added or subtracted to the scrollbar value when the
|
||||
* user selects the scroll by a "unit" amount control.
|
||||
*
|
||||
* @param lineIncrement The new unit increment amount.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>setUnitIncrement()</code>.
|
||||
*/
|
||||
public void setLineIncrement(int lineIncrement)
|
||||
{
|
||||
if (lineIncrement < 0)
|
||||
throw new IllegalArgumentException("Unit increment less than zero.");
|
||||
|
||||
int range = maximum - minimum;
|
||||
if (lineIncrement > range)
|
||||
{
|
||||
if (range == 0)
|
||||
lineIncrement = 1;
|
||||
else
|
||||
lineIncrement = range;
|
||||
}
|
||||
|
||||
if (lineIncrement == this.lineIncrement)
|
||||
return;
|
||||
|
||||
this.lineIncrement = lineIncrement;
|
||||
|
||||
ScrollbarPeer peer = (ScrollbarPeer) getPeer();
|
||||
if (peer != null)
|
||||
peer.setLineIncrement(this.lineIncrement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value added or subtracted when the user activates the scrollbar
|
||||
* scroll by a "block" amount.
|
||||
*
|
||||
* @return The block increment value.
|
||||
*/
|
||||
public int getBlockIncrement()
|
||||
{
|
||||
return getPageIncrement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value added or subtracted when the user selects the scrollbar
|
||||
* scroll by a "block" amount control.
|
||||
*
|
||||
* @return The block increment value.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getBlockIncrement()</code>.
|
||||
*/
|
||||
public int getPageIncrement()
|
||||
{
|
||||
return pageIncrement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value added or subtracted to the scrollbar value when the
|
||||
* user selects the scroll by a "block" amount control.
|
||||
*
|
||||
* @param blockIncrement The new block increment amount.
|
||||
*/
|
||||
public synchronized void setBlockIncrement(int blockIncrement)
|
||||
{
|
||||
setPageIncrement(blockIncrement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value added or subtracted to the scrollbar value when the
|
||||
* user selects the scroll by a "block" amount control.
|
||||
*
|
||||
* @param pageIncrement The new block increment amount.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>setBlockIncrement()</code>.
|
||||
*/
|
||||
public void setPageIncrement(int pageIncrement)
|
||||
{
|
||||
if (pageIncrement < 0)
|
||||
throw new IllegalArgumentException("Block increment less than zero.");
|
||||
|
||||
int range = maximum - minimum;
|
||||
if (pageIncrement > range)
|
||||
{
|
||||
if (range == 0)
|
||||
pageIncrement = 1;
|
||||
else
|
||||
pageIncrement = range;
|
||||
}
|
||||
|
||||
if (pageIncrement == this.pageIncrement)
|
||||
return;
|
||||
|
||||
this.pageIncrement = pageIncrement;
|
||||
|
||||
ScrollbarPeer peer = (ScrollbarPeer) getPeer();
|
||||
if (peer != null)
|
||||
peer.setPageIncrement(this.pageIncrement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies this object to create its native peer.
|
||||
*/
|
||||
public synchronized void addNotify()
|
||||
{
|
||||
if (peer == null)
|
||||
peer = getToolkit().createScrollbar(this);
|
||||
super.addNotify();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new adjustment listener to the list of registered listeners
|
||||
* for this object.
|
||||
*
|
||||
* @param listener The listener to add.
|
||||
*/
|
||||
public synchronized void addAdjustmentListener(AdjustmentListener listener)
|
||||
{
|
||||
adjustment_listeners = AWTEventMulticaster.add(adjustment_listeners,
|
||||
listener);
|
||||
enableEvents(AWTEvent.ADJUSTMENT_EVENT_MASK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified listener from the list of registered listeners
|
||||
* for this object.
|
||||
*
|
||||
* @param listener The listener to remove.
|
||||
*/
|
||||
public synchronized void removeAdjustmentListener(AdjustmentListener listener)
|
||||
{
|
||||
adjustment_listeners = AWTEventMulticaster.remove(adjustment_listeners,
|
||||
listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes events for this scrollbar. It does this by calling
|
||||
* <code>processAdjustmentEvent()</code> if the event is an instance of
|
||||
* <code>AdjustmentEvent</code>, otherwise it calls the superclass to
|
||||
* process the event.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void processEvent(AWTEvent event)
|
||||
{
|
||||
if (event instanceof AdjustmentEvent)
|
||||
processAdjustmentEvent((AdjustmentEvent) event);
|
||||
else
|
||||
super.processEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes adjustment events for this object by dispatching them to
|
||||
* any registered listeners. Note that this method will only be called
|
||||
* if adjustment events are enabled. This will happen automatically if
|
||||
* any listeners are registered. Otherwise, it can be enabled by a
|
||||
* call to <code>enableEvents()</code>.
|
||||
*
|
||||
* @param event The event to process.
|
||||
*/
|
||||
protected void processAdjustmentEvent(AdjustmentEvent event)
|
||||
{
|
||||
value = event.getValue();
|
||||
if (adjustment_listeners != null)
|
||||
adjustment_listeners.adjustmentValueChanged(event);
|
||||
}
|
||||
|
||||
void dispatchEventImpl(AWTEvent e)
|
||||
{
|
||||
if (e.id <= AdjustmentEvent.ADJUSTMENT_LAST
|
||||
&& e.id >= AdjustmentEvent.ADJUSTMENT_FIRST
|
||||
&& (adjustment_listeners != null
|
||||
|| (eventMask & AWTEvent.ADJUSTMENT_EVENT_MASK) != 0))
|
||||
processEvent(e);
|
||||
else
|
||||
super.dispatchEventImpl(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debugging string for this object.
|
||||
*
|
||||
* @return A debugging string for this object.
|
||||
*/
|
||||
protected String paramString()
|
||||
{
|
||||
return ("value=" + getValue() + ",visibleAmount=" + getVisibleAmount()
|
||||
+ ",minimum=" + getMinimum() + ",maximum=" + getMaximum()
|
||||
+ ",pageIncrement=" + pageIncrement + ",lineIncrement="
|
||||
+ lineIncrement + ",orientation="
|
||||
+ (orientation == HORIZONTAL ? "HORIZONTAL" : "VERTICAL")
|
||||
+ super.paramString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the objects currently registered as FooListeners
|
||||
* upon this <code>Scrollbar</code>. FooListeners are registered using the
|
||||
* addFooListener method.
|
||||
*
|
||||
* @exception ClassCastException If listenerType doesn't specify a class or
|
||||
* interface that implements java.util.EventListener.
|
||||
*/
|
||||
public EventListener[] getListeners(Class listenerType)
|
||||
{
|
||||
if (listenerType == AdjustmentListener.class)
|
||||
return AWTEventMulticaster.getListeners(adjustment_listeners,
|
||||
listenerType);
|
||||
|
||||
return super.getListeners(listenerType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all registered adjustment listeners.
|
||||
*/
|
||||
public AdjustmentListener[] getAdjustmentListeners()
|
||||
{
|
||||
return (AdjustmentListener[]) getListeners(AdjustmentListener.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the value is in the process of changing.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean getValueIsAdjusting()
|
||||
{
|
||||
return valueIsAdjusting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of valueIsAdjusting.
|
||||
*
|
||||
* @since 1.4
|
||||
*/
|
||||
public void setValueIsAdjusting(boolean valueIsAdjusting)
|
||||
{
|
||||
this.valueIsAdjusting = valueIsAdjusting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique name for this scroll bar.
|
||||
*
|
||||
* @return A unique name for this scroll bar.
|
||||
*/
|
||||
String generateName()
|
||||
{
|
||||
return "scrollbar" + getUniqueLong();
|
||||
}
|
||||
|
||||
private static synchronized long getUniqueLong()
|
||||
{
|
||||
return next_scrollbar_number++;
|
||||
}
|
||||
|
||||
/**
|
||||
* This class provides accessibility support for the
|
||||
* scrollbar.
|
||||
*
|
||||
* @author Jerry Quinn (jlquinn@optonline.net)
|
||||
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
|
||||
*/
|
||||
protected class AccessibleAWTScrollBar extends AccessibleAWTComponent
|
||||
implements AccessibleValue
|
||||
{
|
||||
/**
|
||||
* Serialization constant to match JDK 1.5
|
||||
*/
|
||||
private static final long serialVersionUID = -344337268523697807L;
|
||||
|
||||
/**
|
||||
* Returns the role of this accessible object.
|
||||
*
|
||||
* @return the instance of <code>AccessibleRole</code>,
|
||||
* which describes this object.
|
||||
*
|
||||
* @see javax.accessibility.AccessibleRole
|
||||
*/
|
||||
public AccessibleRole getAccessibleRole()
|
||||
{
|
||||
return AccessibleRole.SCROLL_BAR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the state set of this accessible object.
|
||||
*
|
||||
* @return a set of <code>AccessibleState</code>s which
|
||||
* represent the current state of the accessible object.
|
||||
*
|
||||
* @see javax.accessibility.AccessibleState
|
||||
* @see javax.accessibility.AccessibleStateSet
|
||||
*/
|
||||
public AccessibleStateSet getAccessibleStateSet()
|
||||
{
|
||||
AccessibleStateSet states = super.getAccessibleStateSet();
|
||||
if (getOrientation() == HORIZONTAL)
|
||||
states.add(AccessibleState.HORIZONTAL);
|
||||
else
|
||||
states.add(AccessibleState.VERTICAL);
|
||||
if (getValueIsAdjusting())
|
||||
states.add(AccessibleState.BUSY);
|
||||
return states;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an implementation of the <code>AccessibleValue</code>
|
||||
* interface for this accessible object. In this case, the
|
||||
* current instance is simply returned (with a more appropriate
|
||||
* type), as it also implements the accessible value as well as
|
||||
* the context.
|
||||
*
|
||||
* @return the accessible value associated with this context.
|
||||
*
|
||||
* @see javax.accessibility.AccessibleValue
|
||||
*/
|
||||
public AccessibleValue getAccessibleValue()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current value of this accessible object.
|
||||
* In this case, this is the same as the value for
|
||||
* the scrollbar, wrapped in an <code>Integer</code>
|
||||
* object.
|
||||
*
|
||||
* @return the numeric value of this scrollbar.
|
||||
*
|
||||
* @see javax.accessibility.AccessibleValue#getCurrentAccessibleValue()
|
||||
*/
|
||||
public Number getCurrentAccessibleValue()
|
||||
{
|
||||
return new Integer(getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current value of this accessible object
|
||||
* to that supplied. In this case, the value of the
|
||||
* scrollbar is set, and this method always returns
|
||||
* true.
|
||||
*
|
||||
* @param number the new accessible value.
|
||||
*
|
||||
* @return true if the value was set.
|
||||
*
|
||||
* @see javax.accessibility.AccessibleValue#setCurrentAccessibleValue(java.lang.Number)
|
||||
*/
|
||||
public boolean setCurrentAccessibleValue(Number number)
|
||||
{
|
||||
setValue(number.intValue());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum acceptable accessible value used
|
||||
* by this object. In this case, this is the same as
|
||||
* the minimum value of the scrollbar, wrapped in an
|
||||
* object.
|
||||
*
|
||||
* @return the minimum value of this scrollbar.
|
||||
*
|
||||
* @see javax.accessibility.AccessibleValue#getMinimumAccessibleValue()
|
||||
*/
|
||||
public Number getMinimumAccessibleValue()
|
||||
{
|
||||
return new Integer(getMinimum());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum acceptable accessible value used
|
||||
* by this object. In this case, this is the same as
|
||||
* the maximum value of the scrollbar, wrapped in an
|
||||
* object.
|
||||
*
|
||||
* @return the maximum value of this scrollbar.
|
||||
*
|
||||
* @see javax.accessibility.AccessibleValue#getMaximumAccessibleValue()
|
||||
*/
|
||||
public Number getMaximumAccessibleValue()
|
||||
{
|
||||
return new Integer(getMaximum());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>Scrollbar</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTScrollBar();
|
||||
|
||||
return accessibleContext;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,203 @@
|
||||
/* Shape.java -- the classic Object-Oriented shape interface
|
||||
Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
/**
|
||||
* This interface represents an abstract shape. The shape is described by
|
||||
* a {@link PathIterator}, and has callbacks for determining bounding box,
|
||||
* where points and rectangles lie in relation to the shape, and tracing
|
||||
* the trajectory.
|
||||
*
|
||||
* <p>A point is inside if it is completely inside, or on the boundary and
|
||||
* adjacent points in the increasing x or y direction are completely inside.
|
||||
* Unclosed shapes are considered as implicitly closed when performing
|
||||
* <code>contains</code> or <code>intersects</code>.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @see PathIterator
|
||||
* @see AffineTransform
|
||||
* @see java.awt.geom.FlatteningPathIterator
|
||||
* @see java.awt.geom.GeneralPath
|
||||
* @since 1.0
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface Shape
|
||||
{
|
||||
/**
|
||||
* Returns a <code>Rectange</code> that bounds the shape. There is no
|
||||
* guarantee that this is the minimum bounding box, particularly if
|
||||
* the shape overflows the finite integer range of a bound. Generally,
|
||||
* <code>getBounds2D</code> returns a tighter bound.
|
||||
*
|
||||
* @return the shape's bounding box
|
||||
* @see #getBounds2D()
|
||||
*/
|
||||
Rectangle getBounds();
|
||||
|
||||
/**
|
||||
* Returns a high precision bounding box of the shape. There is no guarantee
|
||||
* that this is the minimum bounding box, but at least it never overflows.
|
||||
*
|
||||
* @return the shape's bounding box
|
||||
* @see #getBounds()
|
||||
* @since 1.2
|
||||
*/
|
||||
Rectangle2D getBounds2D();
|
||||
|
||||
/**
|
||||
* Test if the coordinates lie in the shape.
|
||||
*
|
||||
* @param x the x coordinate
|
||||
* @param y the y coordinate
|
||||
* @return true if (x,y) lies inside the shape
|
||||
* @since 1.2
|
||||
*/
|
||||
boolean contains(double x, double y);
|
||||
|
||||
/**
|
||||
* Test if the point lie in the shape.
|
||||
*
|
||||
* @param p the high-precision point
|
||||
* @return true if p lies inside the shape
|
||||
* @throws NullPointerException if p is null
|
||||
* @since 1.2
|
||||
*/
|
||||
boolean contains(Point2D p);
|
||||
|
||||
/**
|
||||
* Test if a high-precision rectangle intersects the shape. This is true
|
||||
* if any point in the rectangle is in the shape, with the caveat that the
|
||||
* operation may include high probability estimates when the actual
|
||||
* calculation is prohibitively expensive. The {@link java.awt.geom.Area}
|
||||
* class can be used for more precise answers.
|
||||
*
|
||||
* @param x the x coordinate of the rectangle
|
||||
* @param y the y coordinate of the rectangle
|
||||
* @param w the width of the rectangle, undefined results if negative
|
||||
* @param h the height of the rectangle, undefined results if negative
|
||||
* @return true if the rectangle intersects this shape
|
||||
* @see java.awt.geom.Area
|
||||
* @since 1.2
|
||||
*/
|
||||
boolean intersects(double x, double y, double w, double h);
|
||||
|
||||
/**
|
||||
* Test if a high-precision rectangle intersects the shape. This is true
|
||||
* if any point in the rectangle is in the shape, with the caveat that the
|
||||
* operation may include high probability estimates when the actual
|
||||
* calculation is prohibitively expensive. The {@link java.awt.geom.Area}
|
||||
* class can be used for more precise answers.
|
||||
*
|
||||
* @param r the rectangle
|
||||
* @return true if the rectangle intersects this shape
|
||||
* @throws NullPointerException if r is null
|
||||
* @see #intersects(double, double, double, double)
|
||||
* @since 1.2
|
||||
*/
|
||||
boolean intersects(Rectangle2D r);
|
||||
|
||||
/**
|
||||
* Test if a high-precision rectangle lies completely in the shape. This is
|
||||
* true if all points in the rectangle are in the shape, with the caveat
|
||||
* that the operation may include high probability estimates when the actual
|
||||
* calculation is prohibitively expensive. The {@link java.awt.geom.Area}
|
||||
* class can be used for more precise answers.
|
||||
*
|
||||
* @param x the x coordinate of the rectangle
|
||||
* @param y the y coordinate of the rectangle
|
||||
* @param w the width of the rectangle, undefined results if negative
|
||||
* @param h the height of the rectangle, undefined results if negative
|
||||
* @return true if the rectangle is contained in this shape
|
||||
* @see java.awt.geom.Area
|
||||
* @since 1.2
|
||||
*/
|
||||
boolean contains(double x, double y, double w, double h);
|
||||
|
||||
/**
|
||||
* Test if a high-precision rectangle lies completely in the shape. This is
|
||||
* true if all points in the rectangle are in the shape, with the caveat
|
||||
* that the operation may include high probability estimates when the actual
|
||||
* calculation is prohibitively expensive. The {@link java.awt.geom.Area}
|
||||
* class can be used for more precise answers.
|
||||
*
|
||||
* @param r the rectangle
|
||||
* @return true if the rectangle is contained in this shape
|
||||
* @throws NullPointerException if r is null
|
||||
* @see #contains(double, double, double, double)
|
||||
* @since 1.2
|
||||
*/
|
||||
boolean contains(Rectangle2D r);
|
||||
|
||||
/**
|
||||
* Return an iterator along the shape boundary. If the optional transform
|
||||
* is provided, the iterator is transformed accordingly. Each call returns
|
||||
* a new object, independent from others in use. It is recommended, but
|
||||
* not required, that the Shape isolate iterations from future changes to
|
||||
* the boundary, and document this fact.
|
||||
*
|
||||
* @param transform an optional transform to apply to the iterator
|
||||
* @return a new iterator over the boundary
|
||||
* @since 1.2
|
||||
*/
|
||||
PathIterator getPathIterator(AffineTransform transform);
|
||||
|
||||
/**
|
||||
* Return an iterator along the flattened version of the shape boundary.
|
||||
* Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE points are returned in the
|
||||
* iterator. The flatness paramter controls how far points are allowed to
|
||||
* differ from the real curve; although a limit on accuracy may cause this
|
||||
* parameter to be enlarged if needed.
|
||||
*
|
||||
* <p>If the optional transform is provided, the iterator is transformed
|
||||
* accordingly. Each call returns a new object, independent from others in
|
||||
* use. It is recommended, but not required, that the Shape isolate
|
||||
* iterations from future changes to the boundary, and document this fact.
|
||||
*
|
||||
* @param transform an optional transform to apply to the iterator
|
||||
* @param flatness the maximum distance for deviation from the real boundary
|
||||
* @return a new iterator over the boundary
|
||||
* @since 1.2
|
||||
*/
|
||||
PathIterator getPathIterator(AffineTransform transform, double flatness);
|
||||
} // interface Shape
|
||||
@@ -0,0 +1,65 @@
|
||||
/* Stroke.java -- a stroked outline of a shape
|
||||
Copyright (C) 2002, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
/**
|
||||
* This interface allows a Graphics2D to grab the outline of a shape, as if
|
||||
* stroked by a marking pen of appropriate size and shape. The area inked
|
||||
* by the pen is the area of this stroke. Anything in the graphic which
|
||||
* traces an outline will use this stroke, such as <code>drawLine</code>.
|
||||
* Strokes must be immutable, because the graphics object does not clone
|
||||
* them.
|
||||
*
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @see BasicStroke
|
||||
* @see Graphics2D#setStroke(Stroke)
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public interface Stroke
|
||||
{
|
||||
/**
|
||||
* Returns a shape which outlines the boundary of the given shape, in
|
||||
* effect converting the infinitely thin line into a new shape.
|
||||
*
|
||||
* @param s the shape to stroke
|
||||
* @return the stroked outline shape
|
||||
*/
|
||||
Shape createStrokedShape(Shape s);
|
||||
} // interface Stroke
|
||||
@@ -0,0 +1,462 @@
|
||||
/* SystemColor.java -- access dynamic system color values
|
||||
Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class contains the various "system colors" in use by the native
|
||||
* windowing system. The <code>getRGB()</code> method is dynamic on systems
|
||||
* which support dynamic system color changes, and most methods in the
|
||||
* superclass are written to use this dynamic value when reporting colors.
|
||||
* However, the <code>equals()</code> method is not dynamic, and does not
|
||||
* track the actual color of instances in this class. This means that equals
|
||||
* may give surprising results; you are better off relying on getRGB.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
* @author Eric Blake (ebb9@email.byu.edu)
|
||||
* @since 1.1
|
||||
* @status updated to 1.4
|
||||
*/
|
||||
public final class SystemColor extends Color implements Serializable
|
||||
{
|
||||
// Implementation note: To be serial compatible with JDK, this class must
|
||||
// violate the semantic meaning of super.value to be one of the
|
||||
// NUM_COLORS constants instead of the actual RGB value. Hence there are
|
||||
// a lot of ugly workarounds in Color and in this class. I would have
|
||||
// designed it MUCH differently, making a separate id field in this class.
|
||||
|
||||
/**
|
||||
* Compatible with JDK 1.1+.
|
||||
*/
|
||||
private static final long serialVersionUID = 4503142729533789064L;
|
||||
|
||||
/**
|
||||
* Array index of the desktop color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #desktop
|
||||
*/
|
||||
public static final int DESKTOP = 0;
|
||||
|
||||
/**
|
||||
* Array index of the active caption color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #activeCaption
|
||||
*/
|
||||
public static final int ACTIVE_CAPTION = 1;
|
||||
|
||||
/**
|
||||
* Array index of the active caption text color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #activeCaptionText
|
||||
*/
|
||||
public static final int ACTIVE_CAPTION_TEXT = 2;
|
||||
|
||||
/**
|
||||
* Array index of the active caption border color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #activeCaptionBorder
|
||||
*/
|
||||
public static final int ACTIVE_CAPTION_BORDER = 3;
|
||||
|
||||
/**
|
||||
* Array index of the inactive caption color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #inactiveCaption
|
||||
*/
|
||||
public static final int INACTIVE_CAPTION = 4;
|
||||
|
||||
/**
|
||||
* Array index of the inactive caption text color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #inactiveCaptionText
|
||||
*/
|
||||
public static final int INACTIVE_CAPTION_TEXT = 5;
|
||||
|
||||
/**
|
||||
* Array index of the inactive caption border color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #inactiveCaptionBorder
|
||||
*/
|
||||
public static final int INACTIVE_CAPTION_BORDER = 6;
|
||||
|
||||
/**
|
||||
* Array index of the window background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #window
|
||||
*/
|
||||
public static final int WINDOW = 7;
|
||||
|
||||
/**
|
||||
* Array index of the window border color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #windowBorder
|
||||
*/
|
||||
public static final int WINDOW_BORDER = 8;
|
||||
|
||||
/**
|
||||
* Array index of the window text color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #windowText
|
||||
*/
|
||||
public static final int WINDOW_TEXT = 9;
|
||||
|
||||
/**
|
||||
* Array index of the menu background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #menu
|
||||
*/
|
||||
public static final int MENU = 10;
|
||||
|
||||
/**
|
||||
* Array index of the menu text color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #menuText
|
||||
*/
|
||||
public static final int MENU_TEXT = 11;
|
||||
|
||||
/**
|
||||
* Array index of the text background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #text
|
||||
*/
|
||||
public static final int TEXT = 12;
|
||||
|
||||
/**
|
||||
* Array index of the text foreground color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #textText
|
||||
*/
|
||||
public static final int TEXT_TEXT = 13;
|
||||
|
||||
/**
|
||||
* Array index of the highlighted text background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #textHighlight
|
||||
*/
|
||||
public static final int TEXT_HIGHLIGHT = 14;
|
||||
|
||||
/**
|
||||
* Array index of the highlighted text foreground color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #textHighlightText
|
||||
*/
|
||||
public static final int TEXT_HIGHLIGHT_TEXT = 15;
|
||||
|
||||
/**
|
||||
* Array index of the inactive text foreground color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #textInactiveText
|
||||
*/
|
||||
public static final int TEXT_INACTIVE_TEXT = 16;
|
||||
|
||||
/**
|
||||
* Array index of the control background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #control
|
||||
*/
|
||||
public static final int CONTROL = 17;
|
||||
|
||||
/**
|
||||
* Array index of the control text color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #controlText
|
||||
*/
|
||||
public static final int CONTROL_TEXT = 18;
|
||||
|
||||
/**
|
||||
* Array index of the highlighted control background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #controlHighlight
|
||||
*/
|
||||
public static final int CONTROL_HIGHLIGHT = 19;
|
||||
|
||||
/**
|
||||
* Array index of the lightly highlighted control background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #controlLtHighlight
|
||||
*/
|
||||
public static final int CONTROL_LT_HIGHLIGHT = 20;
|
||||
|
||||
/**
|
||||
* Array index of the shadowed control background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #controlShadow
|
||||
*/
|
||||
public static final int CONTROL_SHADOW = 21;
|
||||
|
||||
/**
|
||||
* Array index of the darkly shadowed control background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #controlDkShadow
|
||||
*/
|
||||
public static final int CONTROL_DK_SHADOW = 22;
|
||||
|
||||
/**
|
||||
* Array index of the scrollbar background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #scrollbar
|
||||
*/
|
||||
public static final int SCROLLBAR = 23;
|
||||
|
||||
/**
|
||||
* Array index of the info background color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #info
|
||||
*/
|
||||
public static final int INFO = 24;
|
||||
|
||||
/**
|
||||
* Array index of the info text color. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*
|
||||
* @see #infoText
|
||||
*/
|
||||
public static final int INFO_TEXT = 25;
|
||||
|
||||
/**
|
||||
* The number of system colors. Used by
|
||||
* {@link Toolkit#loadSystemColors(int[])}.
|
||||
*/
|
||||
public static final int NUM_COLORS = 26;
|
||||
|
||||
/**
|
||||
* The internal array used to dynamically update <code>getRGB()</code>.
|
||||
*/
|
||||
private static final int[] colors = new int[NUM_COLORS];
|
||||
|
||||
/** The desktop color. */
|
||||
public static final SystemColor desktop
|
||||
= new SystemColor(DESKTOP);
|
||||
|
||||
/** The active caption background color. */
|
||||
public static final SystemColor activeCaption
|
||||
= new SystemColor(ACTIVE_CAPTION);
|
||||
|
||||
/** The active caption text color. */
|
||||
public static final SystemColor activeCaptionText
|
||||
= new SystemColor(ACTIVE_CAPTION_TEXT);
|
||||
|
||||
/** The active caption border color. */
|
||||
public static final SystemColor activeCaptionBorder
|
||||
= new SystemColor(ACTIVE_CAPTION_BORDER);
|
||||
|
||||
/** The inactive caption background color. */
|
||||
public static final SystemColor inactiveCaption
|
||||
= new SystemColor(INACTIVE_CAPTION);
|
||||
|
||||
/** The inactive caption text color. */
|
||||
public static final SystemColor inactiveCaptionText
|
||||
= new SystemColor(INACTIVE_CAPTION_TEXT);
|
||||
|
||||
/** The inactive caption border color. */
|
||||
public static final SystemColor inactiveCaptionBorder
|
||||
= new SystemColor(INACTIVE_CAPTION_BORDER);
|
||||
|
||||
/** The window background color. */
|
||||
public static final SystemColor window
|
||||
= new SystemColor(WINDOW);
|
||||
|
||||
/** The window border color. */
|
||||
public static final SystemColor windowBorder
|
||||
= new SystemColor(WINDOW_BORDER);
|
||||
|
||||
/** The window text color. */
|
||||
public static final SystemColor windowText
|
||||
= new SystemColor(WINDOW_TEXT);
|
||||
|
||||
/** The menu background color. */
|
||||
public static final SystemColor menu
|
||||
= new SystemColor(MENU);
|
||||
|
||||
/** The menu text color. */
|
||||
public static final SystemColor menuText
|
||||
= new SystemColor(MENU_TEXT);
|
||||
|
||||
/** The text background color. */
|
||||
public static final SystemColor text
|
||||
= new SystemColor(TEXT);
|
||||
|
||||
/** The text foreground color. */
|
||||
public static final SystemColor textText
|
||||
= new SystemColor(TEXT_TEXT);
|
||||
|
||||
/** The highlighted text background color. */
|
||||
public static final SystemColor textHighlight
|
||||
= new SystemColor(TEXT_HIGHLIGHT);
|
||||
|
||||
/** The highlighted text foreground color. */
|
||||
public static final SystemColor textHighlightText
|
||||
= new SystemColor(TEXT_HIGHLIGHT_TEXT);
|
||||
|
||||
/** The inactive text color. */
|
||||
public static final SystemColor textInactiveText
|
||||
= new SystemColor(TEXT_INACTIVE_TEXT);
|
||||
|
||||
/** The control background color. */
|
||||
public static final SystemColor control
|
||||
= new SystemColor(CONTROL);
|
||||
|
||||
/** The control text color. */
|
||||
public static final SystemColor controlText
|
||||
= new SystemColor(CONTROL_TEXT);
|
||||
|
||||
/** The control highlight color. */
|
||||
public static final SystemColor controlHighlight
|
||||
= new SystemColor(CONTROL_HIGHLIGHT);
|
||||
|
||||
/** The control light highlight color. */
|
||||
public static final SystemColor controlLtHighlight
|
||||
= new SystemColor(CONTROL_LT_HIGHLIGHT);
|
||||
|
||||
/** The control shadow color. */
|
||||
public static final SystemColor controlShadow
|
||||
= new SystemColor(CONTROL_SHADOW);
|
||||
|
||||
/** The control dark shadow color. */
|
||||
public static final SystemColor controlDkShadow
|
||||
= new SystemColor(CONTROL_DK_SHADOW);
|
||||
|
||||
/** The scrollbar color. */
|
||||
public static final SystemColor scrollbar
|
||||
= new SystemColor(SCROLLBAR);
|
||||
|
||||
/** The info text background color. */
|
||||
public static final SystemColor info
|
||||
= new SystemColor(INFO);
|
||||
|
||||
/** The info text foreground color. */
|
||||
public static final SystemColor infoText
|
||||
= new SystemColor(INFO_TEXT);
|
||||
|
||||
/**
|
||||
* Construct a system color which is dynamically updated.
|
||||
*
|
||||
* @param id the color id
|
||||
*/
|
||||
private SystemColor(int id)
|
||||
{
|
||||
// Note: See Color#Color(int, boolean) to explain why we use this
|
||||
// particular constructor.
|
||||
super(id, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RGB value for this color, in the sRGB color space. The blue
|
||||
* value will be in bits 0-7, green in 8-15, red in 6-23, and the alpha
|
||||
* value (bits 24-31) is 0xff. This is dynamically updated, so it may not
|
||||
* match the results of <code>getRed()</code>, <code>getGreen()</code>, or
|
||||
* <code>getBlue()</code>.
|
||||
*
|
||||
* @return the current RGB value
|
||||
*/
|
||||
public int getRGB()
|
||||
{
|
||||
Toolkit.getDefaultToolkit().loadSystemColors(colors);
|
||||
return colors[value] | ALPHA_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a paint context, used for filling areas of a raster scan with
|
||||
* the current value of this system color. Since the system colors may be
|
||||
* dynamically updated, the returned value may not always be the same; but
|
||||
* as the system color is solid, the context does not need any of the
|
||||
* passed parameters to do its job.
|
||||
*
|
||||
* @param cm the requested color model
|
||||
* @param deviceBounds the bounding box in device coordinates, ignored
|
||||
* @param userBounds the bounding box in user coordinates, ignored
|
||||
* @param xform the bounds transformation, ignored
|
||||
* @param hints any rendering hints, ignored
|
||||
* @return a context for painting this solid color
|
||||
*/
|
||||
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds,
|
||||
Rectangle2D userBounds,
|
||||
AffineTransform xform,
|
||||
RenderingHints hints)
|
||||
{
|
||||
Toolkit.getDefaultToolkit().loadSystemColors(colors);
|
||||
int color = colors[value] | ALPHA_MASK;
|
||||
if (context == null || color != context.color || !context.getColorModel().equals(cm))
|
||||
context = new ColorPaintContext(cm,color);
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string describing this color. This is in the format
|
||||
* "java.awt.SystemColor[i=" + index + ']', where index is one of the
|
||||
* integer constants of this class. Unfortunately, this description
|
||||
* does not describe the current value of the color; for that you should
|
||||
* use <code>new Color(syscolor.getRGB()).toString()</code>.
|
||||
*
|
||||
* @return a string describing this color
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
return "java.awt.SystemColor[i=" + value + ']';
|
||||
}
|
||||
} // class SystemColor
|
||||
@@ -0,0 +1,629 @@
|
||||
/* TextArea.java -- A multi-line text entry component
|
||||
Copyright (C) 1999, 2004 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
GNU Classpath is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
GNU Classpath is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GNU Classpath; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
02110-1301 USA.
|
||||
|
||||
Linking this library statically or dynamically with other modules is
|
||||
making a combined work based on this library. Thus, the terms and
|
||||
conditions of the GNU General Public License cover the whole
|
||||
combination.
|
||||
|
||||
As a special exception, the copyright holders of this library give you
|
||||
permission to link this library with independent modules to produce an
|
||||
executable, regardless of the license terms of these independent
|
||||
modules, and to copy and distribute the resulting executable under
|
||||
terms of your choice, provided that you also meet, for each linked
|
||||
independent module, the terms and conditions of the license of that
|
||||
module. An independent module is a module which is not derived from
|
||||
or based on this library. If you modify this library, you may extend
|
||||
this exception to your version of the library, but you are not
|
||||
obligated to do so. If you do not wish to do so, delete this
|
||||
exception statement from your version. */
|
||||
|
||||
|
||||
package java.awt;
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.awt.peer.TextAreaPeer;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.accessibility.AccessibleContext;
|
||||
import javax.accessibility.AccessibleStateSet;
|
||||
|
||||
|
||||
/**
|
||||
* A TextArea is a text component capable of displaying multiple lines
|
||||
* of user-editable text. A TextArea handles its own scrolling and
|
||||
* can display vertical and horizontal scrollbars as navigation aids.
|
||||
*
|
||||
* @author Aaron M. Renn (arenn@urbanophile.com)
|
||||
*/
|
||||
public class TextArea extends TextComponent implements java.io.Serializable
|
||||
{
|
||||
/**
|
||||
* Display both horiztonal and vertical scroll bars.
|
||||
*/
|
||||
public static final int SCROLLBARS_BOTH = 0;
|
||||
|
||||
/**
|
||||
* Display vertical scroll bar only.
|
||||
*/
|
||||
public static final int SCROLLBARS_VERTICAL_ONLY = 1;
|
||||
|
||||
/**
|
||||
* Display horizatonal scroll bar only.
|
||||
*/
|
||||
public static final int SCROLLBARS_HORIZONTAL_ONLY = 2;
|
||||
|
||||
/**
|
||||
* Do not display scrollbars.
|
||||
*/
|
||||
public static final int SCROLLBARS_NONE = 3;
|
||||
|
||||
/**
|
||||
* Serialization constant.
|
||||
*/
|
||||
private static final long serialVersionUID = 3692302836626095722L;
|
||||
|
||||
/**
|
||||
* @serial The number of columns used in this text area's preferred
|
||||
* and minimum size calculations.
|
||||
*/
|
||||
private int columns;
|
||||
|
||||
/**
|
||||
* @serial The number of rows used in this text area's preferred and
|
||||
* minimum size calculations.
|
||||
*/
|
||||
private int rows;
|
||||
|
||||
/**
|
||||
* @serial The scrollbar display policy. One of SCROLLBARS_BOTH,
|
||||
* SCROLLBARS_VERTICAL_ONLY, SCROLLBARS_HORIZONTAL_ONLY,
|
||||
* SCROLLBARS_NONE.
|
||||
*/
|
||||
private int scrollbarVisibility;
|
||||
|
||||
/*
|
||||
* The number used to generate the name returned by getName.
|
||||
*/
|
||||
private static transient long next_text_number;
|
||||
|
||||
/**
|
||||
* Initialize a new instance of <code>TextArea</code> that is empty.
|
||||
* Conceptually the <code>TextArea</code> has 0 rows and 0 columns
|
||||
* but its initial bounds are defined by its peer or by the
|
||||
* container in which it is packed. Both horizontal and vertical
|
||||
* scrollbars will be displayed.
|
||||
*
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
|
||||
*/
|
||||
public TextArea ()
|
||||
{
|
||||
this ("", 0, 0, SCROLLBARS_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a new instance of <code>TextArea</code> that contains
|
||||
* the specified text. Conceptually the <code>TextArea</code> has 0
|
||||
* rows and 0 columns but its initial bounds are defined by its peer
|
||||
* or by the container in which it is packed. Both horizontal and
|
||||
* veritcal scrollbars will be displayed.
|
||||
*
|
||||
* @param text The text to display in this text area.
|
||||
*
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
|
||||
*/
|
||||
public TextArea (String text)
|
||||
{
|
||||
this (text, 0, 0, SCROLLBARS_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a new instance of <code>TextArea</code> that is empty
|
||||
* and can display the specified number of rows and columns of text,
|
||||
* without the need to scroll. Both horizontal and vertical
|
||||
* scrollbars will be displayed.
|
||||
*
|
||||
* @param rows The number of rows in this text area.
|
||||
* @param columns The number of columns in this text area.
|
||||
*
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
|
||||
*/
|
||||
public TextArea (int rows, int columns)
|
||||
{
|
||||
this ("", rows, columns, SCROLLBARS_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a new instance of <code>TextArea</code> that can
|
||||
* display the specified number of rows and columns of text, without
|
||||
* the need to scroll. The TextArea initially contains the
|
||||
* specified text.
|
||||
*
|
||||
* @param text The text to display in this text area.
|
||||
* @param rows The number of rows in this text area.
|
||||
* @param columns The number of columns in this text area.
|
||||
*
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
|
||||
*/
|
||||
public TextArea (String text, int rows, int columns)
|
||||
{
|
||||
this (text, rows, columns, SCROLLBARS_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a new instance of <code>TextArea</code> that initially
|
||||
* contains the specified text. The TextArea can display the
|
||||
* specified number of rows and columns of text, without the need to
|
||||
* scroll. This constructor allows specification of the scroll bar
|
||||
* display policy.
|
||||
*
|
||||
* @param text The text to display in this text area.
|
||||
* @param rows The number of rows in this text area.
|
||||
* @param columns The number of columns in this text area.
|
||||
* @param scrollbarVisibility The scroll bar display policy. One of
|
||||
* SCROLLBARS_BOTH, SCROLLBARS_VERTICAL_ONLY,
|
||||
* SCROLLBARS_HORIZONTAL_ONLY, SCROLLBARS_NONE.
|
||||
*
|
||||
* @exception HeadlessException if GraphicsEnvironment.isHeadless () is true
|
||||
*/
|
||||
public TextArea (String text, int rows, int columns, int scrollbarVisibility)
|
||||
{
|
||||
super (text);
|
||||
|
||||
if (GraphicsEnvironment.isHeadless ())
|
||||
throw new HeadlessException ();
|
||||
|
||||
if (rows < 0 || columns < 0)
|
||||
throw new IllegalArgumentException ("Bad row or column value");
|
||||
|
||||
if (scrollbarVisibility != SCROLLBARS_BOTH
|
||||
&& scrollbarVisibility != SCROLLBARS_VERTICAL_ONLY
|
||||
&& scrollbarVisibility != SCROLLBARS_HORIZONTAL_ONLY
|
||||
&& scrollbarVisibility != SCROLLBARS_NONE)
|
||||
throw new IllegalArgumentException ("Bad scrollbar visibility value");
|
||||
|
||||
this.rows = rows;
|
||||
this.columns = columns;
|
||||
this.scrollbarVisibility = scrollbarVisibility;
|
||||
|
||||
// TextAreas need to receive tab key events so we override the
|
||||
// default forward and backward traversal key sets.
|
||||
Set s = new HashSet ();
|
||||
s.add (AWTKeyStroke.getAWTKeyStroke (KeyEvent.VK_TAB,
|
||||
KeyEvent.CTRL_DOWN_MASK));
|
||||
setFocusTraversalKeys (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, s);
|
||||
s = new HashSet ();
|
||||
s.add (AWTKeyStroke.getAWTKeyStroke (KeyEvent.VK_TAB,
|
||||
KeyEvent.SHIFT_DOWN_MASK
|
||||
| KeyEvent.CTRL_DOWN_MASK));
|
||||
setFocusTraversalKeys (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the number of columns that this text area would prefer
|
||||
* to display. This value may or may not correspond to the number
|
||||
* of columns that are actually displayed.
|
||||
*
|
||||
* @return The preferred number of columns.
|
||||
*/
|
||||
public int getColumns ()
|
||||
{
|
||||
return columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the preferred number of columns for this text area. This
|
||||
* method does not cause the number of columns displayed by the text
|
||||
* area to be updated, if the text area is currently visible.
|
||||
*
|
||||
* @param columns The preferred number of columns.
|
||||
*
|
||||
* @exception IllegalArgumentException If columns is less than zero.
|
||||
*/
|
||||
public synchronized void setColumns (int columns)
|
||||
{
|
||||
if (columns < 0)
|
||||
throw new IllegalArgumentException ("Value is less than zero: "
|
||||
+ columns);
|
||||
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the number of rows that this text area would prefer to
|
||||
* display. This value may or may not correspond to the number of
|
||||
* rows that are actually displayed.
|
||||
*
|
||||
* @return The preferred number of rows.
|
||||
*/
|
||||
public int getRows ()
|
||||
{
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the preferred number of rows for this text area. This method
|
||||
* does not cause the number of columns displayed by the text area
|
||||
* to be updated, if the text area is currently visible.
|
||||
*
|
||||
* @param rows The preferred number of rows.
|
||||
*
|
||||
* @exception IllegalArgumentException If rows is less than zero.
|
||||
*/
|
||||
public synchronized void setRows (int rows)
|
||||
{
|
||||
if (rows < 1)
|
||||
throw new IllegalArgumentException ("Value is less than one: " + rows);
|
||||
|
||||
this.rows = rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the minimum size for this text area, considering the
|
||||
* text area's current row and column values. A text area's minimum
|
||||
* size depends on the number of rows and columns of text it would
|
||||
* prefer to display, and on the size of the font in which the text
|
||||
* would be displayed.
|
||||
*
|
||||
* @return The minimum size for this text field.
|
||||
*/
|
||||
public Dimension getMinimumSize ()
|
||||
{
|
||||
return getMinimumSize (getRows (), getColumns ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the minimum size that this text area would have if its
|
||||
* row and column values were equal to those specified. A text
|
||||
* area's minimum size depends on the number of rows and columns of
|
||||
* text it would prefer to display, and on the size of the font in
|
||||
* which the text would be displayed.
|
||||
*
|
||||
* @param rows The number of rows to use in the minimum size
|
||||
* calculation.
|
||||
* @param columns The number of columns to use in the minimum size
|
||||
* calculation.
|
||||
*
|
||||
* @return The minimum size for this text area.
|
||||
*/
|
||||
public Dimension getMinimumSize (int rows, int columns)
|
||||
{
|
||||
return minimumSize (rows, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the minimum size for this text area, considering the
|
||||
* text area's current row and column values. A text area's minimum
|
||||
* size depends on the number of rows and columns of text it would
|
||||
* prefer to display, and on the size of the font in which the text
|
||||
* would be displayed.
|
||||
*
|
||||
* @return The minimum size for this text area.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getMinimumSize ()</code>.
|
||||
*/
|
||||
public Dimension minimumSize ()
|
||||
{
|
||||
return minimumSize (getRows (), getColumns ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the minimum size that this text area would have if its
|
||||
* row and column values were equal to those specified. A text
|
||||
* area's minimum size depends on the number of rows and columns of
|
||||
* text it would prefer to display, and on the size of the font in
|
||||
* which the text would be displayed.
|
||||
*
|
||||
* @param rows The number of rows to use in the minimum size
|
||||
* calculation.
|
||||
* @param columns The number of columns to use in the minimum size
|
||||
* calculation.
|
||||
*
|
||||
* @return The minimum size for this text area.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getMinimumSize (int, int)</code>.
|
||||
*/
|
||||
public Dimension minimumSize (int rows, int columns)
|
||||
{
|
||||
TextAreaPeer peer = (TextAreaPeer) getPeer ();
|
||||
|
||||
// Sun returns Dimension (0,0) in this case.
|
||||
if (peer == null)
|
||||
return new Dimension (0, 0);
|
||||
|
||||
return peer.getMinimumSize (rows, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the preferred size for this text area, considering the
|
||||
* text area's current row and column values. A text area's preferred
|
||||
* size depends on the number of rows and columns of text it would
|
||||
* prefer to display, and on the size of the font in which the text
|
||||
* would be displayed.
|
||||
*
|
||||
* @return The preferred size for this text field.
|
||||
*/
|
||||
public Dimension getPreferredSize ()
|
||||
{
|
||||
return getPreferredSize (getRows (), getColumns ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the preferred size that this text area would have if its
|
||||
* row and column values were equal to those specified. A text
|
||||
* area's preferred size depends on the number of rows and columns
|
||||
* of text it would prefer to display, and on the size of the font
|
||||
* in which the text would be displayed.
|
||||
*
|
||||
* @param rows The number of rows to use in the preferred size
|
||||
* calculation.
|
||||
* @param columns The number of columns to use in the preferred size
|
||||
* calculation.
|
||||
*
|
||||
* @return The preferred size for this text area.
|
||||
*/
|
||||
public Dimension getPreferredSize (int rows, int columns)
|
||||
{
|
||||
return preferredSize (rows, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the preferred size for this text area, considering the
|
||||
* text area's current row and column values. A text area's preferred
|
||||
* size depends on the number of rows and columns of text it would
|
||||
* prefer to display, and on the size of the font in which the text
|
||||
* would be displayed.
|
||||
*
|
||||
* @return The preferred size for this text field.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getPreferredSize ()</code>.
|
||||
*/
|
||||
public Dimension preferredSize ()
|
||||
{
|
||||
return preferredSize (getRows (), getColumns ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the preferred size that this text area would have if its
|
||||
* row and column values were equal to those specified. A text
|
||||
* area's preferred size depends on the number of rows and columns
|
||||
* of text it would prefer to display, and on the size of the font
|
||||
* in which the text would be displayed.
|
||||
*
|
||||
* @param rows The number of rows to use in the preferred size
|
||||
* calculation.
|
||||
* @param columns The number of columns to use in the preferred size
|
||||
* calculation.
|
||||
*
|
||||
* @return The preferred size for this text area.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>getPreferredSize (int, int)</code>.
|
||||
*/
|
||||
public Dimension preferredSize (int rows, int columns)
|
||||
{
|
||||
TextAreaPeer peer = (TextAreaPeer) getPeer ();
|
||||
|
||||
// Sun returns Dimension (0,0) in this case.
|
||||
if (peer == null)
|
||||
return new Dimension (0, 0);
|
||||
|
||||
return peer.getPreferredSize (rows, columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the scroll bar display policy -- one of SCROLLBARS_BOTH,
|
||||
* SCROLLBARS_VERTICAL_ONLY, SCROLLBARS_HORIZONTAL_ONLY,
|
||||
* SCROLLBARS_NONE.
|
||||
*
|
||||
* @return The current scroll bar display policy.
|
||||
*/
|
||||
public int getScrollbarVisibility ()
|
||||
{
|
||||
return scrollbarVisibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify this object that it should create its native peer.
|
||||
*/
|
||||
public void addNotify ()
|
||||
{
|
||||
if (getPeer () == null)
|
||||
setPeer ((ComponentPeer) getToolkit().createTextArea (this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the specified text to the end of the current text.
|
||||
*
|
||||
* @param str The text to append.
|
||||
*/
|
||||
public void append (String str)
|
||||
{
|
||||
appendText (str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the specified text to the end of the current text.
|
||||
*
|
||||
* @param str The text to append.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>append ()</code>.
|
||||
*/
|
||||
public void appendText (String str)
|
||||
{
|
||||
TextAreaPeer peer = (TextAreaPeer) getPeer ();
|
||||
|
||||
if (peer != null)
|
||||
peer.insert (str, peer.getText().length ());
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the specified text at the specified position. The first
|
||||
* character in the text area is at position zero.
|
||||
*
|
||||
* @param str The text to insert.
|
||||
* @param pos The position at which to insert text.
|
||||
*/
|
||||
public void insert (String str, int pos)
|
||||
{
|
||||
insertText (str, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the specified text at the specified position. The first
|
||||
* character in the text area is at position zero.
|
||||
*
|
||||
* @param str The text to insert.
|
||||
* @param pos The position at which to insert text.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>insert ()</code>.
|
||||
*/
|
||||
public void insertText (String str, int pos)
|
||||
{
|
||||
TextAreaPeer peer = (TextAreaPeer) getPeer ();
|
||||
|
||||
if (peer != null)
|
||||
peer.insert (str, pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a range of characters with the specified text. The
|
||||
* character at the start position will be replaced, unless start ==
|
||||
* end. The character at the end posistion will not be replaced.
|
||||
* The first character in the text area is at position zero. The
|
||||
* length of the replacement text may differ from the length of the
|
||||
* text that is replaced.
|
||||
*
|
||||
* @param str The new text for the range.
|
||||
* @param start The start position of the replacement range.
|
||||
* @param end The end position of the replacement range.
|
||||
*/
|
||||
public void replaceRange (String str, int start, int end)
|
||||
{
|
||||
replaceText (str, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace a range of characters with the specified text. The
|
||||
* character at the start position will be replaced, unless start ==
|
||||
* end. The character at the end posistion will not be replaced.
|
||||
* The first character in the text area is at position zero. The
|
||||
* length of the replacement text may differ from the length of the
|
||||
* text that is replaced.
|
||||
*
|
||||
* @param str The new text for the range.
|
||||
* @param start The start position of the replacement range.
|
||||
* @param end The end position of the replacement range.
|
||||
*
|
||||
* @deprecated This method is deprecated in favor of
|
||||
* <code>replaceRange ()</code>.
|
||||
*/
|
||||
public void replaceText (String str, int start, int end)
|
||||
{
|
||||
TextAreaPeer peer = (TextAreaPeer) getPeer ();
|
||||
|
||||
if (peer != null)
|
||||
peer.replaceRange (str, start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a debugging string for this text area.
|
||||
*
|
||||
* @return A debugging string for this text area.
|
||||
*/
|
||||
protected String paramString ()
|
||||
{
|
||||
String sbVisibility = "";
|
||||
|
||||
switch (scrollbarVisibility)
|
||||
{
|
||||
case SCROLLBARS_BOTH:
|
||||
sbVisibility = "both";
|
||||
break;
|
||||
case SCROLLBARS_VERTICAL_ONLY:
|
||||
sbVisibility = "vertical-only";
|
||||
break;
|
||||
case SCROLLBARS_HORIZONTAL_ONLY:
|
||||
sbVisibility = "horizontal-only";
|
||||
break;
|
||||
case SCROLLBARS_NONE:
|
||||
sbVisibility = "none";
|
||||
break;
|
||||
}
|
||||
|
||||
String editable = "";
|
||||
if (isEditable ())
|
||||
editable = "editable,";
|
||||
|
||||
return getName () + "," + getX () + "," + getY () + "," + getWidth ()
|
||||
+ "x" + getHeight () + "," + "text=" + getText () + "," + editable
|
||||
+ "selection=" + getSelectionStart () + "-" + getSelectionEnd ()
|
||||
+ ",rows=" + rows + ",columns=" + columns + ",scrollbarVisibility="
|
||||
+ sbVisibility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a unique name for this text area.
|
||||
*
|
||||
* @return A unique name for this text area.
|
||||
*/
|
||||
String generateName ()
|
||||
{
|
||||
return "text" + getUniqueLong ();
|
||||
}
|
||||
|
||||
private static synchronized long getUniqueLong ()
|
||||
{
|
||||
return next_text_number++;
|
||||
}
|
||||
|
||||
protected class AccessibleAWTTextArea extends AccessibleAWTTextComponent
|
||||
{
|
||||
protected AccessibleAWTTextArea()
|
||||
{
|
||||
}
|
||||
|
||||
public AccessibleStateSet getAccessibleStateSet()
|
||||
{
|
||||
return super.getAccessibleStateSet();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the AccessibleContext associated with this <code>TextArea</code>.
|
||||
* The context is created, if necessary.
|
||||
*
|
||||
* @return the associated context
|
||||
*/
|
||||
public AccessibleContext getAccessibleContext()
|
||||
{
|
||||
/* Create the context if this is the first request */
|
||||
if (accessibleContext == null)
|
||||
accessibleContext = new AccessibleAWTTextArea();
|
||||
return accessibleContext;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user