Major merge with Classpath.
Removed many duplicate files. * HACKING: Updated.x * classpath: Imported new directory. * standard.omit: New file. * Makefile.in, aclocal.m4, configure: Rebuilt. * sources.am: New file. * configure.ac: Run Classpath configure script. Moved code around to support. Disable xlib AWT peers (temporarily). * Makefile.am (SUBDIRS): Added 'classpath' (JAVAC): Removed. (AM_CPPFLAGS): Added more -I options. (BOOTCLASSPATH): Simplified. Completely redid how sources are built. Include sources.am. * include/Makefile.am (tool_include__HEADERS): Removed jni.h. * include/jni.h: Removed (in Classpath). * scripts/classes.pl: Updated to look at built classes. * scripts/makemake.tcl: New file. * testsuite/libjava.jni/jni.exp (gcj_jni_compile_c_to_so): Added -I options. (gcj_jni_invocation_compile_c_to_binary): Likewise. From-SVN: r102082
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
/* gnu.classpath.Configuration
|
||||
Copyright (C) 1998, 2001, 2003 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 gnu.classpath;
|
||||
|
||||
/**
|
||||
* This file defines compile-time constants that can be accessed by
|
||||
* java code. It is pre-processed by configure.
|
||||
*/
|
||||
public interface Configuration
|
||||
{
|
||||
// The value of DEBUG is substituted according to whether the
|
||||
// "--enable-libgcj-debug" argument was passed to configure. Code
|
||||
// which is made conditional based on the value of this flag will
|
||||
// be removed by the optimizer in a non-debug build.
|
||||
boolean DEBUG = @LIBGCJDEBUG@;
|
||||
|
||||
// For libgcj we never load the JNI libraries.
|
||||
boolean INIT_LOAD_LIBRARY = false;
|
||||
|
||||
// For libgcj we have native methods for dynamic proxy support....
|
||||
boolean HAVE_NATIVE_GET_PROXY_DATA = false;
|
||||
boolean HAVE_NATIVE_GET_PROXY_CLASS = false;
|
||||
boolean HAVE_NATIVE_GENERATE_PROXY_CLASS = false;
|
||||
|
||||
// Name of default AWT peer library.
|
||||
String default_awt_peer_toolkit = "@TOOLKIT@";
|
||||
}
|
||||
@@ -1,573 +0,0 @@
|
||||
/* ServiceFactory.java -- Factory for plug-in services.
|
||||
Copyright (C) 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 gnu.classpath;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedActionException;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* A factory for plug-ins that conform to a service provider
|
||||
* interface. This is a general mechanism that gets used by a number
|
||||
* of packages in the Java API. For instance, {@link
|
||||
* java.nio.charset.spi.CharsetProvider} allows to write custom
|
||||
* encoders and decoders for character sets, {@link
|
||||
* javax.imageio.spi.ImageReaderSpi} allows to support custom image
|
||||
* formats, and {@link javax.print.PrintService} makes it possible to
|
||||
* write custom printer drivers.
|
||||
*
|
||||
* <p>The plug-ins are concrete implementations of the service
|
||||
* provider interface, which is defined as an interface or an abstract
|
||||
* class. The implementation classes must be public and have a public
|
||||
* constructor that takes no arguments.
|
||||
*
|
||||
* <p>Plug-ins are usually deployed in JAR files. A JAR that provides
|
||||
* an implementation of a service must declare this in a resource file
|
||||
* whose name is the fully qualified service name and whose location
|
||||
* is the directory <code>META-INF/services</code>. This UTF-8 encoded
|
||||
* text file lists, on separate lines, the fully qualified names of
|
||||
* the concrete implementations. Thus, one JAR file can provide an
|
||||
* arbitrary number of implementations for an arbitrary count of
|
||||
* service provider interfaces.
|
||||
*
|
||||
* <p><b>Example</b>
|
||||
*
|
||||
* <p>For example, a JAR might provide two implementations of the
|
||||
* service provider interface <code>org.foo.ThinkService</code>,
|
||||
* namely <code>com.acme.QuickThinker</code> and
|
||||
* <code>com.acme.DeepThinker</code>. The code for <code>QuickThinker</code>
|
||||
* woud look as follows:
|
||||
*
|
||||
* <pre>
|
||||
* package com.acme;
|
||||
*
|
||||
* /**
|
||||
* * Provices a super-quick, but not very deep implementation of ThinkService.
|
||||
* */
|
||||
* public class QuickThinker
|
||||
* implements org.foo.ThinkService
|
||||
* {
|
||||
* /**
|
||||
* * Constructs a new QuickThinker. The service factory (which is
|
||||
* * part of the Java environment) calls this no-argument constructor
|
||||
* * when it looks up the available implementations of ThinkService.
|
||||
* *
|
||||
* * <p>Note that an application might query all available
|
||||
* * ThinkService providers, but use just one of them. Therefore,
|
||||
* * constructing an instance should be very inexpensive. For example,
|
||||
* * large data structures should only be allocated when the service
|
||||
* * actually gets used.
|
||||
* */
|
||||
* public QuickThinker()
|
||||
* {
|
||||
* }
|
||||
*
|
||||
* /**
|
||||
* * Returns the speed of this ThinkService in thoughts per second.
|
||||
* * Applications can choose among the available service providers
|
||||
* * based on this value.
|
||||
* */
|
||||
* public double getSpeed()
|
||||
* {
|
||||
* return 314159.2654;
|
||||
* }
|
||||
*
|
||||
* /**
|
||||
* * Produces a thought. While the returned thoughts are not very
|
||||
* * deep, they are generated in very short time.
|
||||
* */
|
||||
* public Thought think()
|
||||
* {
|
||||
* return null;
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* <p>The code for <code>com.acme.DeepThinker</code> is left as an
|
||||
* exercise to the reader.
|
||||
*
|
||||
* <p>Acme’s <code>ThinkService</code> plug-in gets deployed as
|
||||
* a JAR file. Besides the bytecode and resources for
|
||||
* <code>QuickThinker</code> and <code>DeepThinker</code>, it also
|
||||
* contains the text file
|
||||
* <code>META-INF/services/org.foo.ThinkService</code>:
|
||||
*
|
||||
* <pre>
|
||||
* # Available implementations of org.foo.ThinkService
|
||||
* com.acme.QuickThinker
|
||||
* com.acme.DeepThinker
|
||||
* </pre>
|
||||
*
|
||||
* <p><b>Thread Safety</b>
|
||||
*
|
||||
* <p>It is safe to use <code>ServiceFactory</code> from multiple
|
||||
* concurrent threads without external synchronization.
|
||||
*
|
||||
* <p><b>Note for User Applications</b>
|
||||
*
|
||||
* <p>User applications that want to load plug-ins should not directly
|
||||
* use <code>gnu.classpath.ServiceFactory</code>, because this class
|
||||
* is only available in Java environments that are based on GNU
|
||||
* Classpath. Instead, it is recommended that user applications call
|
||||
* {@link
|
||||
* javax.imageio.spi.ServiceRegistry#lookupProviders(Class)}. This API
|
||||
* is actually independent of image I/O, and it is available on every
|
||||
* environment.
|
||||
*
|
||||
* @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
|
||||
*/
|
||||
public final class ServiceFactory
|
||||
{
|
||||
/**
|
||||
* A logger that gets informed when a service gets loaded, or
|
||||
* when there is a problem with loading a service.
|
||||
*
|
||||
* <p>Because {@link java.util.logging.Logger#getLogger(String)}
|
||||
* is thread-safe, we do not need to worry about synchronization
|
||||
* here.
|
||||
*/
|
||||
private static final Logger LOGGER = Logger.getLogger("gnu.classpath");
|
||||
|
||||
|
||||
/**
|
||||
* Declared private in order to prevent constructing instances of
|
||||
* this utility class.
|
||||
*/
|
||||
private ServiceFactory()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds service providers that are implementing the specified
|
||||
* Service Provider Interface.
|
||||
*
|
||||
* <p><b>On-demand loading:</b> Loading and initializing service
|
||||
* providers is delayed as much as possible. The rationale is that
|
||||
* typical clients will iterate through the set of installed service
|
||||
* providers until one is found that matches some criteria (like
|
||||
* supported formats, or quality of service). In such scenarios, it
|
||||
* might make sense to install only the frequently needed service
|
||||
* providers on the local machine. More exotic providers can be put
|
||||
* onto a server; the server will only be contacted when no suitable
|
||||
* service could be found locally.
|
||||
*
|
||||
* <p><b>Security considerations:</b> Any loaded service providers
|
||||
* are loaded through the specified ClassLoader, or the system
|
||||
* ClassLoader if <code>classLoader</code> is
|
||||
* <code>null</code>. When <code>lookupProviders</code> is called,
|
||||
* the current {@link AccessControlContext} gets recorded. This
|
||||
* captured security context will determine the permissions when
|
||||
* services get loaded via the <code>next()</code> method of the
|
||||
* returned <code>Iterator</code>.
|
||||
*
|
||||
* @param spi the service provider interface which must be
|
||||
* implemented by any loaded service providers.
|
||||
*
|
||||
* @param loader the class loader that will be used to load the
|
||||
* service providers, or <code>null</code> for the system class
|
||||
* loader. For using the context class loader, see {@link
|
||||
* #lookupProviders(Class)}.
|
||||
*
|
||||
* @return an iterator over instances of <code>spi</code>.
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>spi</code> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
public static Iterator lookupProviders(Class spi,
|
||||
ClassLoader loader)
|
||||
{
|
||||
String resourceName;
|
||||
Enumeration urls;
|
||||
|
||||
if (spi == null)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
if (loader == null)
|
||||
loader = ClassLoader.getSystemClassLoader();
|
||||
|
||||
resourceName = "META-INF/services/" + spi.getName();
|
||||
try
|
||||
{
|
||||
urls = loader.getResources(resourceName);
|
||||
}
|
||||
catch (IOException ioex)
|
||||
{
|
||||
/* If an I/O error occurs here, we cannot provide any service
|
||||
* providers. In this case, we simply return an iterator that
|
||||
* does not return anything (no providers installed).
|
||||
*/
|
||||
log(Level.WARNING, "cannot access {0}", resourceName, ioex);
|
||||
return Collections.EMPTY_LIST.iterator();
|
||||
}
|
||||
|
||||
return new ServiceIterator(spi, urls, loader,
|
||||
AccessController.getContext());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finds service providers that are implementing the specified
|
||||
* Service Provider Interface, using the context class loader
|
||||
* for loading providers.
|
||||
*
|
||||
* @param spi the service provider interface which must be
|
||||
* implemented by any loaded service providers.
|
||||
*
|
||||
* @return an iterator over instances of <code>spi</code>.
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>spi</code> is
|
||||
* <code>null</code>.
|
||||
*
|
||||
* @see #lookupProviders(Class, ClassLoader)
|
||||
*/
|
||||
public static Iterator lookupProviders(Class spi)
|
||||
{
|
||||
ClassLoader ctxLoader;
|
||||
|
||||
ctxLoader = Thread.currentThread().getContextClassLoader();
|
||||
return lookupProviders(spi, ctxLoader);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An iterator over service providers that are listed in service
|
||||
* provider configuration files, which get passed as an Enumeration
|
||||
* of URLs. This is a helper class for {@link
|
||||
* ServiceFactory#lookupProviders}.
|
||||
*
|
||||
* @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
|
||||
*/
|
||||
private static final class ServiceIterator
|
||||
implements Iterator
|
||||
{
|
||||
/**
|
||||
* The service provider interface (usually an interface, sometimes
|
||||
* an abstract class) which the services must implement.
|
||||
*/
|
||||
private final Class spi;
|
||||
|
||||
|
||||
/**
|
||||
* An Enumeration<URL> over the URLs that contain a resource
|
||||
* <code>META-INF/services/<org.foo.SomeService></code>,
|
||||
* as returned by {@link ClassLoader#getResources(String)}.
|
||||
*/
|
||||
private final Enumeration urls;
|
||||
|
||||
|
||||
/**
|
||||
* The class loader used for loading service providers.
|
||||
*/
|
||||
private final ClassLoader loader;
|
||||
|
||||
|
||||
/**
|
||||
* The security context used when loading and initializing service
|
||||
* providers. We want to load and initialize all plug-in service
|
||||
* providers under the same security context, namely the one that
|
||||
* was active when {@link #lookupProviders} has been called.
|
||||
*/
|
||||
private final AccessControlContext securityContext;
|
||||
|
||||
|
||||
/**
|
||||
* A reader for the current file listing class names of service
|
||||
* implementors, or <code>null</code> when the last reader has
|
||||
* been fetched.
|
||||
*/
|
||||
private BufferedReader reader;
|
||||
|
||||
|
||||
/**
|
||||
* The URL currently being processed. This is only used for
|
||||
* emitting error messages.
|
||||
*/
|
||||
private URL currentURL;
|
||||
|
||||
|
||||
/**
|
||||
* The service provider that will be returned by the next call to
|
||||
* {@link #next()}, or <code>null</code> if the iterator has
|
||||
* already returned all service providers.
|
||||
*/
|
||||
private Object nextProvider;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an Iterator that loads and initializes services on
|
||||
* demand.
|
||||
*
|
||||
* @param spi the service provider interface which the services
|
||||
* must implement. Usually, this is a Java interface type, but it
|
||||
* might also be an abstract class or even a concrete superclass.
|
||||
*
|
||||
* @param urls an Enumeration<URL> over the URLs that contain a
|
||||
* resource
|
||||
* <code>META-INF/services/<org.foo.SomeService></code>, as
|
||||
* determined by {@link ClassLoader#getResources(String)}.
|
||||
*
|
||||
* @param loader the ClassLoader that gets used for loading
|
||||
* service providers.
|
||||
*
|
||||
* @param securityContext the security context to use when loading
|
||||
* and initializing service providers.
|
||||
*/
|
||||
ServiceIterator(Class spi, Enumeration urls, ClassLoader loader,
|
||||
AccessControlContext securityContext)
|
||||
{
|
||||
this.spi = spi;
|
||||
this.urls = urls;
|
||||
this.loader = loader;
|
||||
this.securityContext = securityContext;
|
||||
this.nextProvider = loadNextServiceProvider();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws NoSuchElementException if {@link #hasNext} returns
|
||||
* <code>false</code>.
|
||||
*/
|
||||
public Object next()
|
||||
{
|
||||
Object result;
|
||||
|
||||
if (!hasNext())
|
||||
throw new NoSuchElementException();
|
||||
|
||||
result = nextProvider;
|
||||
nextProvider = loadNextServiceProvider();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public boolean hasNext()
|
||||
{
|
||||
return nextProvider != null;
|
||||
}
|
||||
|
||||
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
private Object loadNextServiceProvider()
|
||||
{
|
||||
String line;
|
||||
|
||||
if (reader == null)
|
||||
advanceReader();
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* If we have reached the last provider list, we cannot
|
||||
* retrieve any further lines.
|
||||
*/
|
||||
if (reader == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
line = reader.readLine();
|
||||
}
|
||||
catch (IOException readProblem)
|
||||
{
|
||||
log(Level.WARNING, "IOException upon reading {0}", currentURL,
|
||||
readProblem);
|
||||
line = null;
|
||||
}
|
||||
|
||||
/* When we are at the end of one list of services,
|
||||
* switch over to the next one.
|
||||
*/
|
||||
if (line == null)
|
||||
{
|
||||
advanceReader();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Skip whitespace at the beginning and end of each line.
|
||||
line = line.trim();
|
||||
|
||||
// Skip empty lines.
|
||||
if (line.length() == 0)
|
||||
continue;
|
||||
|
||||
// Skip comment lines.
|
||||
if (line.charAt(0) == '#')
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
log(Level.FINE,
|
||||
"Loading service provider \"{0}\", specified"
|
||||
+ " by \"META-INF/services/{1}\" in {2}.",
|
||||
new Object[] { line, spi.getName(), currentURL },
|
||||
null);
|
||||
|
||||
/* Load the class in the security context that was
|
||||
* active when calling lookupProviders.
|
||||
*/
|
||||
return AccessController.doPrivileged(
|
||||
new ServiceProviderLoadingAction(spi, line, loader),
|
||||
securityContext);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
String msg = "Cannot load service provider class \"{0}\","
|
||||
+ " specified by \"META-INF/services/{1}\" in {2}";
|
||||
if (ex instanceof PrivilegedActionException
|
||||
&& ex.getCause() instanceof ClassCastException)
|
||||
msg = "Service provider class \"{0}\" is not an instance"
|
||||
+ " of \"{1}\". Specified"
|
||||
+ " by \"META-INF/services/{1}\" in {2}.";
|
||||
|
||||
log(Level.WARNING, msg,
|
||||
new Object[] { line, spi.getName(), currentURL },
|
||||
ex);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void advanceReader()
|
||||
{
|
||||
do
|
||||
{
|
||||
if (reader != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
reader.close();
|
||||
log(Level.FINE, "closed {0}", currentURL, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log(Level.WARNING, "cannot close {0}", currentURL, ex);
|
||||
}
|
||||
reader = null;
|
||||
currentURL = null;
|
||||
}
|
||||
|
||||
if (!urls.hasMoreElements())
|
||||
return;
|
||||
|
||||
currentURL = (URL) urls.nextElement();
|
||||
try
|
||||
{
|
||||
reader = new BufferedReader(new InputStreamReader(
|
||||
currentURL.openStream(), "UTF-8"));
|
||||
log(Level.FINE, "opened {0}", currentURL, null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
log(Level.WARNING, "cannot open {0}", currentURL, ex);
|
||||
}
|
||||
}
|
||||
while (reader == null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Package-private to avoid a trampoline.
|
||||
/**
|
||||
* Passes a log message to the <code>java.util.logging</code>
|
||||
* framework. This call returns very quickly if no log message will
|
||||
* be produced, so there is not much overhead in the standard case.
|
||||
*
|
||||
* @param the severity of the message, for instance {@link
|
||||
* Level#WARNING}.
|
||||
*
|
||||
* @param msg the log message, for instance <code>“Could not
|
||||
* load {0}.”</code>
|
||||
*
|
||||
* @param param the parameter(s) for the log message, or
|
||||
* <code>null</code> if <code>msg</code> does not specify any
|
||||
* parameters. If <code>param</code> is not an array, an array with
|
||||
* <code>param</code> as its single element gets passed to the
|
||||
* logging framework.
|
||||
*
|
||||
* @param t a Throwable that is associated with the log record, or
|
||||
* <code>null</code> if the log message is not associated with a
|
||||
* Throwable.
|
||||
*/
|
||||
static void log(Level level, String msg, Object param, Throwable t)
|
||||
{
|
||||
LogRecord rec;
|
||||
|
||||
// Return quickly if no log message will be produced.
|
||||
if (!LOGGER.isLoggable(level))
|
||||
return;
|
||||
|
||||
rec = new LogRecord(level, msg);
|
||||
if (param != null && param.getClass().isArray())
|
||||
rec.setParameters((Object[]) param);
|
||||
else
|
||||
rec.setParameters(new Object[] { param });
|
||||
|
||||
rec.setThrown(t);
|
||||
|
||||
// While java.util.logging can sometimes infer the class and
|
||||
// method of the caller, this automatic inference is not reliable
|
||||
// on highly optimizing VMs. Also, log messages make more sense to
|
||||
// developers when they display a public method in a public class;
|
||||
// otherwise, they might feel tempted to figure out the internals
|
||||
// of ServiceFactory in order to understand the problem.
|
||||
rec.setSourceClassName(ServiceFactory.class.getName());
|
||||
rec.setSourceMethodName("lookupProviders");
|
||||
|
||||
LOGGER.log(rec);
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
/* ServiceProviderLoadingAction.java -- Action for loading plug-in services.
|
||||
Copyright (C) 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 gnu.classpath;
|
||||
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
||||
/**
|
||||
* A privileged action for creating a new instance of a service
|
||||
* provider.
|
||||
*
|
||||
* <p>Class loading and instantiation is encapsulated in a
|
||||
* <code>PriviledgedAction</code> in order to restrict the loaded
|
||||
* service providers to the {@link java.security.AccessControlContext}
|
||||
* that was active when {@link
|
||||
* gnu.classpath.ServiceFactory#lookupProviders} was called, even
|
||||
* though the actual loading is delayed to the time when the provider
|
||||
* is actually needed.
|
||||
*
|
||||
* @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
|
||||
*/
|
||||
final class ServiceProviderLoadingAction
|
||||
implements PrivilegedExceptionAction
|
||||
{
|
||||
/**
|
||||
* The interface to which the loaded service provider implementation
|
||||
* must conform. Usually, this is a Java interface type, but it
|
||||
* might also be an abstract class or even a concrete class.
|
||||
*/
|
||||
private final Class spi;
|
||||
|
||||
|
||||
/**
|
||||
* The fully qualified name of the class that gets loaded when
|
||||
* this action is executed.
|
||||
*/
|
||||
private final String providerName;
|
||||
|
||||
|
||||
/**
|
||||
* The ClassLoader that gets used for loading the service provider
|
||||
* class.
|
||||
*/
|
||||
private final ClassLoader loader;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a privileged action for loading a service provider.
|
||||
*
|
||||
* @param spi the interface to which the loaded service provider
|
||||
* implementation must conform. Usually, this is a Java interface
|
||||
* type, but it might also be an abstract class or even a concrete
|
||||
* superclass.
|
||||
*
|
||||
* @param providerName the fully qualified name of the class that
|
||||
* gets loaded when this action is executed.
|
||||
*
|
||||
* @param loader the ClassLoader that gets used for loading the
|
||||
* service provider class.
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>spi</code>,
|
||||
* <code>providerName</code> or <code>loader</code> is
|
||||
* <code>null</code>.
|
||||
*/
|
||||
ServiceProviderLoadingAction(Class spi, String providerName,
|
||||
ClassLoader loader)
|
||||
{
|
||||
if (spi == null || providerName == null || loader == null)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
this.spi = spi;
|
||||
this.providerName = providerName;
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads an implementation class for a service provider, and creates
|
||||
* a new instance of the loaded class by invoking its public
|
||||
* no-argument constructor.
|
||||
*
|
||||
* @return a new instance of the class whose name was passed as
|
||||
* <code>providerName</code> to the constructor.
|
||||
*
|
||||
* @throws ClassCastException if the service provider does not
|
||||
* implement the <code>spi</code> interface that was passed to the
|
||||
* constructor.
|
||||
*
|
||||
* @throws IllegalAccessException if the service provider class or
|
||||
* its no-argument constructor are not <code>public</code>.
|
||||
*
|
||||
* @throws InstantiationException if the service provider class is
|
||||
* <code>abstract</code>, an interface, a primitive type, an array
|
||||
* class, or void; or if service provider class does not have a
|
||||
* no-argument constructor; or if there some other problem with
|
||||
* creating a new instance of the service provider.
|
||||
*/
|
||||
public Object run()
|
||||
throws Exception
|
||||
{
|
||||
Class loadedClass;
|
||||
Object serviceProvider;
|
||||
|
||||
loadedClass = loader.loadClass(providerName);
|
||||
serviceProvider = loadedClass.newInstance();
|
||||
|
||||
// Ensure that the loaded provider is actually implementing
|
||||
// the service provider interface.
|
||||
if (!spi.isInstance(serviceProvider))
|
||||
throw new ClassCastException(spi.getName());
|
||||
|
||||
return serviceProvider;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/* InvalidClassException.java -- invalid/unknown class reference id exception
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown by the JDWP back-end when an invalid reference
|
||||
* type id is used by the debugger.
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class InvalidClassException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidClassException (long id)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_CLASS,
|
||||
"invalid class id (" + id + ")");
|
||||
}
|
||||
|
||||
public InvalidClassException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_CLASS, t);
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/* InvalidCountException -- an invalid count exception
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when a count filter is given an invalid count.
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class InvalidCountException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidCountException (int id)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_COUNT, "invalid count (" + id + ")");
|
||||
}
|
||||
|
||||
public InvalidCountException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_COUNT, t);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/* InvalidEventTypeException.java -- an invalid event kind exception
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when the debugger asks for an event request
|
||||
* for a non-existant event
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class InvalidEventTypeException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidEventTypeException (byte kind)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_EVENT_TYPE,
|
||||
"invalid event type (" + kind + ")");
|
||||
}
|
||||
|
||||
public InvalidEventTypeException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_EVENT_TYPE, t);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/* InvalidObjectException.java -- an invalid object id exception
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when an invalid object id is used by
|
||||
* the debugger
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class InvalidObjectException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidObjectException (long id)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_OBJECT,
|
||||
"invalid object id (" + id + ")");
|
||||
}
|
||||
|
||||
public InvalidObjectException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_OBJECT, t);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/* InvalidStringException.java -- an invalid string id exception
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when the debugger uses an invalid String
|
||||
* id
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class InvalidStringException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidStringException (String str)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_STRING,
|
||||
"invalid string (" + str + ")");
|
||||
}
|
||||
|
||||
public InvalidStringException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_STRING, t);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/* InvalidThreadException.java -- an invalid thread id exception
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when an invalid thread id is used
|
||||
* by the debugger
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class InvalidThreadException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidThreadException (long id)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_THREAD,
|
||||
"invalid thread id (" + id + ")");
|
||||
}
|
||||
|
||||
public InvalidThreadException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_THREAD, t);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/* InvalidThreadGroupException.java -- an invalid thread group id exception
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when an invalid thread group id is used
|
||||
* by the debugger
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class InvalidThreadGroupException
|
||||
extends JdwpException
|
||||
{
|
||||
public InvalidThreadGroupException (long id)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_THREAD_GROUP,
|
||||
"invalid thread id (" + id + ")");
|
||||
}
|
||||
|
||||
public InvalidThreadException (Throwable t)
|
||||
{
|
||||
super (JdwpConstants.Error.INVALID_THREAD_GROUP, t);
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/* JdwpException.java -- an exception base class for all JDWP exceptions
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
/**
|
||||
* A base class exception for all JDWP back-end exceptions
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class JdwpException
|
||||
extends Exception
|
||||
{
|
||||
// The integer error code defined by JDWP
|
||||
private short _errorCode;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>JdwpException</code> with the
|
||||
* given error code and given cause
|
||||
*
|
||||
* @param code the JDWP error code
|
||||
* @param t the cause of the exception
|
||||
*/
|
||||
public JdwpException (short code, Throwable t)
|
||||
{
|
||||
super (t);
|
||||
_errorCode = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>JdwpException</code> with the
|
||||
* given error code and string error message
|
||||
*
|
||||
* @param code the JDWP error code
|
||||
* @param str an error message
|
||||
*/
|
||||
public JdwpException (short code, String str)
|
||||
{
|
||||
super (str);
|
||||
_errorCode = code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the JDWP error code represented by this exception
|
||||
*/
|
||||
public short getErrorCode ()
|
||||
{
|
||||
return _errorCode;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/* JdwpInternalErrorException.java -- an internal error exception
|
||||
features or functions
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown by the JDWP back-end when an unusual runtime
|
||||
* error occurs internally
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class JdwpInternalErrorException
|
||||
extends JdwpException
|
||||
{
|
||||
public JdwpInternalErrorException (Throwable cause)
|
||||
{
|
||||
super (JdwpConstants.Error.INTERNAL, cause);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/* NotImplementedException.java -- an exception for unimplemented JDWP
|
||||
features or functions
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown by virtual machines when functionality
|
||||
* or features are not implemented
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class NotImplementedException
|
||||
extends JdwpException
|
||||
{
|
||||
public NotImplementedException (String feature)
|
||||
{
|
||||
super (JdwpConstants.Error.NOT_IMPLEMENTED,
|
||||
feature + " is not yet implemented");
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/* Jdwp.java -- Virtual machine to JDWP back-end programming interface
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.exception;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* An exception thrown when the virtual machine is dead
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class VmDeadException
|
||||
extends JdwpException
|
||||
{
|
||||
public VmDeadException ()
|
||||
{
|
||||
super (JdwpConstants.Error.VM_DEAD, "Virtual machine is dead");
|
||||
}
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
/* ArrayId.java -- array object IDs
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* A class which represents a JDWP array id
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class ArrayId
|
||||
extends ObjectId
|
||||
{
|
||||
// Arrays are handled a little differently than other IDs
|
||||
//public static final Class typeClass = UNDEFINED
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ArrayId</code>
|
||||
*/
|
||||
public ArrayId ()
|
||||
{
|
||||
super (JdwpConstants.Tag.ARRAY);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/* ArrayReferenceTypeId.java -- array reference type ids
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* A reference type ID representing java arrays
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class ArrayReferenceTypeId
|
||||
extends ReferenceTypeId
|
||||
{
|
||||
/**
|
||||
* Constructs a new <code>ArrayReferenceTypeId</code>
|
||||
*/
|
||||
public ArrayReferenceTypeId ()
|
||||
{
|
||||
super (JdwpConstants.TypeTag.ARRAY);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/* ClassLoaderId.java -- class loader IDs
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* A class which represents a JDWP thread id
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class ClassLoaderId
|
||||
extends ObjectId
|
||||
{
|
||||
/**
|
||||
* The object class that this id represents
|
||||
*/
|
||||
public static final Class typeClass = ClassLoader.class;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ClassLoaderId</code>
|
||||
*/
|
||||
public ClassLoaderId ()
|
||||
{
|
||||
super (JdwpConstants.Tag.CLASS_LOADER);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/* ClassObjectId.java -- class object IDs
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* A class which represents a JDWP class object id
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class ClassObjectId
|
||||
extends ObjectId
|
||||
{
|
||||
/**
|
||||
* The object class that this id represents
|
||||
*/
|
||||
public static final Class typeClass = Class.class;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ClassObjectId</code>
|
||||
*/
|
||||
public ClassObjectId ()
|
||||
{
|
||||
super (JdwpConstants.Tag.CLASS_OBJECT);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/* ClassReferenceTypeId.java -- class reference type ids
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* A reference type ID representing java classes
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class ClassReferenceTypeId
|
||||
extends ReferenceTypeId
|
||||
{
|
||||
/**
|
||||
* Constructs a new <code>ClassReferenceTypeId</code>
|
||||
*/
|
||||
public ClassReferenceTypeId ()
|
||||
{
|
||||
super (JdwpConstants.TypeTag.CLASS);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/* InterfaceReferenceTypeId.java -- interface reference type ids
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* A reference type ID representing java interfaces
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class InterfaceReferenceTypeId
|
||||
extends ReferenceTypeId
|
||||
{
|
||||
/**
|
||||
* Constructs a new <code>InterfaceReferenceTypeId</code>
|
||||
*/
|
||||
public InterfaceReferenceTypeId ()
|
||||
{
|
||||
super (JdwpConstants.TypeTag.INTERFACE);
|
||||
}
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
/* JdwpId.java -- base class for all object ID types
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A baseclass for all object types reported to the debugger
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public abstract class JdwpId
|
||||
{
|
||||
/**
|
||||
* ID assigned to this object
|
||||
*/
|
||||
protected long _id;
|
||||
|
||||
/**
|
||||
* Tag of ID's type (see {@link gnu.classpath.jdwp.JdwpConstants.Tag})
|
||||
* for object-like IDs or the type tag (see {@link
|
||||
* gnu.classpath.JdwpConstants.TypeTag}) for reference type IDs.
|
||||
*/
|
||||
private byte _tag;
|
||||
|
||||
/**
|
||||
* Constructs an empty <code>JdwpId</code>
|
||||
*/
|
||||
public JdwpId (byte tag)
|
||||
{
|
||||
_tag = tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the id for this object reference
|
||||
*/
|
||||
void setId (long id)
|
||||
{
|
||||
_id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id for this object reference
|
||||
*/
|
||||
public long getId ()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two object ids for equality. Two object ids
|
||||
* are equal if they point to the same type and contain to
|
||||
* the same id number. (NOTE: This is a much stricter check
|
||||
* than is necessary: all <code>JdwpId</code>s have unique
|
||||
* ids.)
|
||||
*/
|
||||
public boolean equals (JdwpId id)
|
||||
{
|
||||
return ((id.getClass () == getClass ()) && (id.getId () == getId ()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns size of this type (used by IDSizes)
|
||||
*/
|
||||
public abstract int size ();
|
||||
|
||||
/**
|
||||
* Writes the contents of this type to the <code>DataOutputStream</code>
|
||||
* @param outStream the <code>DataOutputStream</code> to use
|
||||
* @throws IOException when an error occurs on the <code>OutputStream</code>
|
||||
*/
|
||||
public abstract void write (DataOutputStream outStream)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Writes the contents of this type to the output stream, preceded
|
||||
* by a one-byte tag for tagged object IDs or type tag for
|
||||
* reference type IDs.
|
||||
*
|
||||
* @param outStream the <code>DataOutputStream</code> to use
|
||||
* @throws IOException when an error occurs on the <code>OutputStream</code>
|
||||
*/
|
||||
public void writeTagged (DataOutputStream outStream)
|
||||
throws IOException
|
||||
{
|
||||
outStream.writeByte (_tag);
|
||||
write (outStream);
|
||||
}
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
/* JdwpIdFactory.java -- factory for generating type and object IDs
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* This factory generates ids for objects and types that may
|
||||
* be sent to a debugger.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class JdwpIdFactory
|
||||
{
|
||||
// ID of last object / referencetype
|
||||
private static Object _idLock = new Object ();
|
||||
private static Object _ridLock = new Object ();
|
||||
private static long _lastId = 0;
|
||||
private static long _lastRid = 0;
|
||||
|
||||
// A list of all ID types
|
||||
private static HashMap _idList = new HashMap ();
|
||||
|
||||
// Initialize the id list with known types
|
||||
static
|
||||
{
|
||||
// ObjectId and ArrayId are special cases. See newId.
|
||||
_idList.put (ClassLoaderId.typeClass, ClassLoaderId.class);
|
||||
_idList.put (ClassObjectId.typeClass, ClassObjectId.class);
|
||||
//_idList.put (FieldId.typeClass, FieldId.class);
|
||||
//_idList.put (FrameId.typeClass, FrameId.class);
|
||||
//_idList.put (MethodId.typeClass, MethodId.class);
|
||||
_idList.put (StringId.typeClass, StringId.class);
|
||||
_idList.put (ThreadId.typeClass, ThreadId.class);
|
||||
_idList.put (ThreadGroupId.typeClass, ThreadGroupId.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new id for the given object
|
||||
*
|
||||
* @param object the object for which an id is desired
|
||||
* @returns a suitable object id
|
||||
*/
|
||||
public static JdwpId newId (Object object)
|
||||
{
|
||||
JdwpId id = null;
|
||||
|
||||
// Special case: arrays
|
||||
if (object.getClass ().isArray ())
|
||||
id = new ArrayId ();
|
||||
else
|
||||
{
|
||||
// Loop through all classes until we hit baseclass
|
||||
Class myClass;
|
||||
for (myClass = object.getClass (); myClass != null;
|
||||
myClass = myClass.getSuperclass ())
|
||||
{
|
||||
Class clz = (Class) _idList.get (myClass);
|
||||
if (clz != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
id = (JdwpId) clz.newInstance ();
|
||||
synchronized (_idLock)
|
||||
{
|
||||
id.setId (++_lastId);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
catch (InstantiationException ie)
|
||||
{
|
||||
// This really should not happen
|
||||
throw new RuntimeException ("cannot create new ID", ie);
|
||||
}
|
||||
catch (IllegalAccessException iae)
|
||||
{
|
||||
// This really should not happen
|
||||
throw new RuntimeException ("illegal access of ID", iae);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* getSuperclass returned null and no matching ID type found.
|
||||
So it must derive from Object. */
|
||||
id = new ObjectId ();
|
||||
}
|
||||
|
||||
synchronized (_idLock)
|
||||
{
|
||||
id.setId (++_lastId);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new reference type id for the given class
|
||||
*
|
||||
* @param clazz the <code>Class</code> for which an id is desired
|
||||
* @returns a suitable reference type id or <code>null</code>
|
||||
*/
|
||||
public static ReferenceTypeId newReferenceTypeId (Class clazz)
|
||||
{
|
||||
ReferenceTypeId id = null;
|
||||
try
|
||||
{
|
||||
if (clazz.isArray ())
|
||||
id = new ArrayReferenceTypeId ();
|
||||
else if (clazz.isInterface ())
|
||||
id = new InterfaceReferenceTypeId ();
|
||||
else
|
||||
id = new ClassReferenceTypeId ();
|
||||
synchronized (_ridLock)
|
||||
{
|
||||
id.setId (++_lastRid);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
catch (InstantiationException ie)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
catch (IllegalAccessException iae)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/* ObjectId.java -- object IDs
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A class which represents a JDWP object id for an object
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class ObjectId
|
||||
extends JdwpId
|
||||
{
|
||||
/**
|
||||
* The object class that this id represents
|
||||
*/
|
||||
public static final Class typeClass = Object.class;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ObjectId</code>
|
||||
*/
|
||||
public ObjectId ()
|
||||
{
|
||||
super (JdwpConstants.Tag.OBJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ObjectId</code> of the
|
||||
* given type.
|
||||
*
|
||||
* @param tag the tag of this type of object ID
|
||||
*/
|
||||
public ObjectId (byte tag)
|
||||
{
|
||||
super (tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of this id type
|
||||
*/
|
||||
public int size ()
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the id to the stream
|
||||
*
|
||||
* @param outStream the stream to which to write
|
||||
* @throws IOException when an error occurs on the <code>OutputStream</code>
|
||||
*/
|
||||
public void write (DataOutputStream outStream)
|
||||
throws IOException
|
||||
{
|
||||
// All we need to do is write out our id as an 8-byte integer
|
||||
outStream.writeLong (_id);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
/* ReferenceTypeId.java -- a base class for all reference type IDs
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Base class for reference type IDs. This class usurps
|
||||
* <code>JdwpId</code>'s tag member for its own use (type tag).
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class ReferenceTypeId
|
||||
extends JdwpId
|
||||
{
|
||||
/**
|
||||
* Constructor used by {Array,Interface,Class}ReferenceTypeId
|
||||
*/
|
||||
public ReferenceTypeId (byte tag)
|
||||
{
|
||||
super (tag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of this ID type
|
||||
*/
|
||||
public int size ()
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the reference type ID to the given output stream
|
||||
*
|
||||
* @param outStream the stream to which to write the data
|
||||
* @throws IOException for errors writing to the stream
|
||||
*/
|
||||
public void write (DataOutputStream outStream)
|
||||
throws IOException
|
||||
{
|
||||
outStream.writeLong (_id);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/* StringId.java -- string IDs
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* A class which represents a JDWP string id
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class StringId
|
||||
extends ObjectId
|
||||
{
|
||||
/**
|
||||
* The object class that this id represents
|
||||
*/
|
||||
public static final Class typeClass = String.class;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>StringId</code>
|
||||
*/
|
||||
public StringId ()
|
||||
{
|
||||
super (JdwpConstants.Tag.STRING);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/* ThreadGroupId.java -- thread group IDs
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* A class which represents a JDWP thread group id
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class ThreadGroupId
|
||||
extends ObjectId
|
||||
{
|
||||
/**
|
||||
* The object class that this id represents
|
||||
*/
|
||||
public static final Class typeClass = ThreadGroup.class;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ThreadGroupId</code>
|
||||
*/
|
||||
public ThreadGroupId ()
|
||||
{
|
||||
super (JdwpConstants.Tag.THREAD_GROUP);
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/* ThreadId.java -- thread IDs
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.id;
|
||||
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
|
||||
/**
|
||||
* A class which represents a JDWP thread id
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class ThreadId
|
||||
extends ObjectId
|
||||
{
|
||||
/**
|
||||
* The object class that this id represents
|
||||
*/
|
||||
public static final Class typeClass = Thread.class;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ThreadId</code>
|
||||
*/
|
||||
public ThreadId ()
|
||||
{
|
||||
super (JdwpConstants.Tag.THREAD);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
/* CommandSet.java -- An interface defining JDWP Command Sets
|
||||
Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 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
|
||||
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 gnu.classpath.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing a JDWP Command Set. This class serves as a generic
|
||||
* interface for all Command Sets types used by JDWP.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public interface CommandSet
|
||||
{
|
||||
/**
|
||||
* Runs the given command with the data in distr and writes the data for the
|
||||
* reply packet to ostr.
|
||||
*
|
||||
* @param bb holds the data portion of the Command Packet
|
||||
* @param os data portion of the Reply Packet will be written here
|
||||
* @param command the command field of the Command Packet
|
||||
* @return true if the JDWP layer should shut down in response to this packet
|
||||
* @throws JdwpException command wasn't carried out successfully
|
||||
*/
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os,
|
||||
byte command)
|
||||
throws JdwpException;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/* FieldCommandSet.java -- class to implement the Field Command Set
|
||||
Copyright (C) 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 gnu.classpath.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing the Field Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class FieldCommandSet implements CommandSet
|
||||
{
|
||||
/**
|
||||
* There are no commands for this CommandSet at this time so we just throw a
|
||||
* NotImplementedException whenever it's called.
|
||||
*
|
||||
* @throws JdwpException An exception will always be thrown
|
||||
*/
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
throw new NotImplementedException(
|
||||
"No commands for command set Field implemented.");
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/* InterfaceTypeCommandSet.java -- class to implement the InterfaceType
|
||||
Command Set
|
||||
Copyright (C) 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 gnu.classpath.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing the InterfaceType Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class InterfaceTypeCommandSet implements CommandSet
|
||||
{
|
||||
/**
|
||||
* There are no commands for this CommandSet at this time so we just throw a
|
||||
* NotImplementedException whenever it's called.
|
||||
*
|
||||
* @throws JdwpException An exception will always be thrown
|
||||
*/
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
throw new NotImplementedException(
|
||||
"No commands for command set InterfaceType implemented.");
|
||||
}
|
||||
}
|
||||
@@ -1,249 +0,0 @@
|
||||
/* ObjectReferenceCommandSet.java -- lass to implement the ObjectReference
|
||||
Command Set
|
||||
Copyright (C) 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 gnu.classpath.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.IVirtualMachine;
|
||||
import gnu.classpath.jdwp.Jdwp;
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.exception.InvalidFieldException;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
import gnu.classpath.jdwp.id.IdManager;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
import gnu.classpath.jdwp.util.Value;
|
||||
import gnu.classpath.jdwp.util.MethodInvoker;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing the ObjectReference Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class ObjectReferenceCommandSet implements CommandSet
|
||||
{
|
||||
// Our hook into the jvm
|
||||
private final IVirtualMachine vm = Jdwp.getIVirtualMachine();
|
||||
|
||||
// Manages all the different ids that are assigned by jdwp
|
||||
private final IdManager idMan = Jdwp.getIdManager();
|
||||
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case JdwpConstants.CommandSet.ObjectReference.REFERENCE_TYPE:
|
||||
executeReferenceType(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ObjectReference.GET_VALUES:
|
||||
executeGetValues(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ObjectReference.SET_VALUES:
|
||||
executeSetValues(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ObjectReference.MONITOR_INFO:
|
||||
executeMonitorInfo(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ObjectReference.INVOKE_METHOD:
|
||||
executeInvokeMethod(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ObjectReference.DISABLE_COLLECTION:
|
||||
executeDisableCollection(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ObjectReference.ENABLE_COLLECTION:
|
||||
executeEnableCollection(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ObjectReference.IS_COLLECTED:
|
||||
executeIsCollected(bb, os);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Command " + command +
|
||||
" not found in String Reference Command Set.");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// The DataOutputStream we're using isn't talking to a socket at all
|
||||
// So if we throw an IOException we're in serious trouble
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeReferenceType(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readId(bb);
|
||||
Object obj = oid.getObject();
|
||||
Class clazz = obj.getClass();
|
||||
ReferenceTypeId refId = idMan.getReferenceTypeId(clazz);
|
||||
refId.writeTagged(os);
|
||||
}
|
||||
|
||||
private void executeGetValues(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readId(bb);
|
||||
Object obj = oid.getObject();
|
||||
|
||||
int numFields = bb.getInt();
|
||||
|
||||
os.writeInt(numFields); // Looks pointless but this is the protocol
|
||||
|
||||
for (int i = 0; i < numFields; i++)
|
||||
{
|
||||
Field field = (Field) idMan.readId(bb).getObject();
|
||||
Value.writeValueFromField(os, field, obj);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeSetValues(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readId(bb);
|
||||
Object obj = oid.getObject();
|
||||
|
||||
int numFields = bb.getInt();
|
||||
|
||||
for (int i = 0; i < numFields; i++)
|
||||
{
|
||||
Field field = (Field) idMan.readId(bb).getObject();
|
||||
Object value = Value.getObj(bb, field);
|
||||
try
|
||||
{
|
||||
field.set(obj, value);
|
||||
}
|
||||
catch (IllegalArgumentException ex)
|
||||
{
|
||||
// I suppose this would best qualify as an invalid field then
|
||||
throw new InvalidFieldException(ex);
|
||||
}
|
||||
catch (IllegalAccessException ex)
|
||||
{
|
||||
// We should be able to access any field
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void executeMonitorInfo(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
// This command is optional, determined by VirtualMachines CapabilitiesNew
|
||||
// so we'll leave it till later to implement
|
||||
throw new NotImplementedException(
|
||||
"Command ExecuteMonitorInfo not implemented.");
|
||||
|
||||
}
|
||||
|
||||
private void executeInvokeMethod(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readId(bb);
|
||||
Object obj = oid.getObject();
|
||||
|
||||
ObjectId tid = idMan.readId(bb);
|
||||
Thread thread = (Thread) tid.getObject();
|
||||
|
||||
ReferenceTypeId rid = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = rid.getType();
|
||||
|
||||
ObjectId mid = idMan.readId(bb);
|
||||
Method method = (Method) mid.getObject();
|
||||
|
||||
int args = bb.getInt();
|
||||
Object[] values = new Object[args];
|
||||
|
||||
for (int i = 0; i < args; i++)
|
||||
{
|
||||
values[i] = Value.getObj(bb);
|
||||
}
|
||||
|
||||
int invokeOptions = bb.getInt();
|
||||
|
||||
if ((invokeOptions & JdwpConstants.InvokeOptions.INVOKE_SINGLE_THREADED) != 0)
|
||||
{ // We must suspend all other running threads first
|
||||
vm.suspendAllThreads();
|
||||
}
|
||||
boolean nonVirtual;
|
||||
if ((invokeOptions & JdwpConstants.InvokeOptions.INVOKE_NONVIRTUAL) != 0)
|
||||
nonVirtual = true;
|
||||
else
|
||||
nonVirtual = false;
|
||||
MethodInvoker vmi = new MethodInvoker(vm);
|
||||
|
||||
vmi.executeMethod(obj, thread, clazz, method, values, nonVirtual);
|
||||
Object value = vmi.getReturnedValue();
|
||||
ObjectId exceptionId = vmi.getExceptionId();
|
||||
|
||||
Value.writeValue(os, value);
|
||||
exceptionId.writeTagged(os);
|
||||
}
|
||||
|
||||
private void executeDisableCollection(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readId(bb);
|
||||
oid.disableCollection();
|
||||
}
|
||||
|
||||
private void executeEnableCollection(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readId(bb);
|
||||
oid.enableCollection();
|
||||
}
|
||||
|
||||
private void executeIsCollected(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = idMan.readId(bb);
|
||||
boolean collected = oid.isCollected();
|
||||
os.writeBoolean(collected);
|
||||
}
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
/* PacketProcessor.java -- a thread which processes command packets
|
||||
from the debugger
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.Jdwp;
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.transport.JdwpCommandPacket;
|
||||
import gnu.classpath.jdwp.transport.JdwpConnection;
|
||||
import gnu.classpath.jdwp.transport.JdwpPacket;
|
||||
import gnu.classpath.jdwp.transport.JdwpReplyPacket;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* This class is responsible for processing packets from the
|
||||
* debugger. It waits for an available packet from the connection
|
||||
* ({@link gnu.classpath.jdwp.transport.JdwpConnection}) and then
|
||||
* processes the packet and any reply.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class PacketProcessor
|
||||
extends Thread
|
||||
{
|
||||
// The connection to the debugger
|
||||
private JdwpConnection _connection;
|
||||
|
||||
// Shutdown this thread?
|
||||
private boolean _shutdown;
|
||||
|
||||
// A Mapping of the command set (Byte) to the specific CommandSet
|
||||
private CommandSet[] _sets;
|
||||
|
||||
// Contents of the ReplyPackets data field
|
||||
private ByteArrayOutputStream _outputBytes;
|
||||
|
||||
// Output stream around _outputBytes
|
||||
private DataOutputStream _os;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>PacketProcessor</code> object
|
||||
* Connection must be validated before getting here!
|
||||
*
|
||||
* @param con the connection
|
||||
*/
|
||||
public PacketProcessor (JdwpConnection con)
|
||||
{
|
||||
_connection = con;
|
||||
_shutdown = false;
|
||||
|
||||
// MAXIMUM is the value of the largest command set we may receive
|
||||
_sets = new CommandSet[JdwpConstants.CommandSet.MAXIMUM + 1];
|
||||
_outputBytes = new ByteArrayOutputStream();
|
||||
_os = new DataOutputStream (_outputBytes);
|
||||
|
||||
// Create all the Command Sets and add them to our array
|
||||
_sets[JdwpConstants.CommandSet.VirtualMachine.CS_VALUE] =
|
||||
new VirtualMachineCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.ReferenceType.CS_VALUE] =
|
||||
new ReferenceTypeCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.ClassType.CS_VALUE] =
|
||||
new ClassTypeCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.ArrayType.CS_VALUE] =
|
||||
new ArrayTypeCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.InterfaceType.CS_VALUE] =
|
||||
new InterfaceTypeCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.Method.CS_VALUE] =
|
||||
new MethodCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.Field.CS_VALUE] =
|
||||
new FieldCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.ObjectReference.CS_VALUE] =
|
||||
new ObjectReferenceCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.StringReference.CS_VALUE] =
|
||||
new StringReferenceCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.ThreadReference.CS_VALUE] =
|
||||
new ThreadReferenceCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.ThreadGroupReference.CS_VALUE] =
|
||||
new ThreadGroupReferenceCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.ArrayReference.CS_VALUE] =
|
||||
new ArrayReferenceCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.ClassLoaderReference.CS_VALUE] =
|
||||
new ClassLoaderReferenceCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.EventRequest.CS_VALUE] =
|
||||
new EventRequestCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.StackFrame.CS_VALUE] =
|
||||
new StackFrameCommandSet();
|
||||
_sets[JdwpConstants.CommandSet.ClassObjectReference.CS_VALUE] =
|
||||
new ClassObjectReferenceCommandSet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Main run routine for this thread. Will loop getting packets
|
||||
* from the connection and processing them.
|
||||
*/
|
||||
public void run ()
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!_shutdown)
|
||||
{
|
||||
_processOnePacket ();
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
// Time to shutdown, tell Jdwp to shutdown
|
||||
Jdwp.getDefault().shutdown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the packet processor
|
||||
*/
|
||||
public void shutdown ()
|
||||
{
|
||||
_shutdown = true;
|
||||
interrupt ();
|
||||
}
|
||||
|
||||
// Helper function which actually does all the work of waiting
|
||||
// for a packet and getting it processed.
|
||||
private void _processOnePacket ()
|
||||
throws IOException
|
||||
{
|
||||
JdwpPacket pkt = _connection.getPacket ();
|
||||
|
||||
if (!(pkt instanceof JdwpCommandPacket))
|
||||
{
|
||||
// We're not supposed to get these from the debugger!
|
||||
// Drop it on the floor
|
||||
return;
|
||||
}
|
||||
|
||||
if (pkt != null)
|
||||
{
|
||||
JdwpCommandPacket commandPkt = (JdwpCommandPacket) pkt;
|
||||
JdwpReplyPacket reply = new JdwpReplyPacket(commandPkt);
|
||||
|
||||
// Reset our output stream
|
||||
_outputBytes.reset();
|
||||
|
||||
// Create a ByteBuffer around the command packet
|
||||
ByteBuffer bb = ByteBuffer.wrap(commandPkt.getData());
|
||||
byte command = commandPkt.getCommand();
|
||||
byte commandSet = commandPkt.getCommandSet();
|
||||
|
||||
CommandSet set = null;
|
||||
try
|
||||
{
|
||||
// There is no command set with value 0
|
||||
if (commandSet > 0 && commandSet < _sets.length)
|
||||
{
|
||||
set = _sets[commandPkt.getCommandSet()];
|
||||
}
|
||||
if (set != null)
|
||||
{
|
||||
_shutdown = set.runCommand(bb, _os, command);
|
||||
reply.setData(_outputBytes.toByteArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
// This command set wasn't in our tree
|
||||
reply.setErrorCode(JdwpConstants.Error.NOT_IMPLEMENTED);
|
||||
}
|
||||
}
|
||||
catch (JdwpException ex)
|
||||
{
|
||||
reply.setErrorCode(ex.getErrorCode ());
|
||||
}
|
||||
_connection.sendPacket (reply);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,321 +0,0 @@
|
||||
/* ReferenceTypeCommandSet.java -- lass to implement the ReferenceType
|
||||
Command Set
|
||||
Copyright (C) 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 gnu.classpath.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.IVirtualMachine;
|
||||
import gnu.classpath.jdwp.Jdwp;
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.exception.InvalidFieldException;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
import gnu.classpath.jdwp.id.IdManager;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
import gnu.classpath.jdwp.util.JdwpString;
|
||||
import gnu.classpath.jdwp.util.Signature;
|
||||
import gnu.classpath.jdwp.util.Value;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing the ReferenceType Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class ReferenceTypeCommandSet implements CommandSet
|
||||
{
|
||||
// Our hook into the jvm
|
||||
private final IVirtualMachine vm = Jdwp.getIVirtualMachine();
|
||||
|
||||
// Manages all the different ids that are assigned by jdwp
|
||||
private final IdManager idMan = Jdwp.getIdManager();
|
||||
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case JdwpConstants.CommandSet.ReferenceType.SIGNATURE:
|
||||
executeSignature(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.CLASS_LOADER:
|
||||
executeClassLoader(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.MODIFIERS:
|
||||
executeModifiers(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.FIELDS:
|
||||
executeFields(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.METHODS:
|
||||
executeMethods(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.GET_VALUES:
|
||||
executeGetValues(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.SOURCE_FILE:
|
||||
executeSourceFile(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.NESTED_TYPES:
|
||||
executeNestedTypes(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.STATUS:
|
||||
executeStatus(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.INTERFACES:
|
||||
executeInterfaces(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.CLASS_OBJECT:
|
||||
executeClassObject(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.SOURCE_DEBUG_EXTENSION:
|
||||
executeSourceDebugExtension(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.SIGNATURE_WITH_GENERIC:
|
||||
executeSignatureWithGeneric(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.FIELDS_WITH_GENERIC:
|
||||
executeFieldWithGeneric(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.ReferenceType.METHODS_WITH_GENERIC:
|
||||
executeMethodsWithGeneric(bb, os);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Command " + command +
|
||||
" not found in String Reference Command Set.");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// The DataOutputStream we're using isn't talking to a socket at all
|
||||
// So if we throw an IOException we're in serious trouble
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeSignature(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
String sig = Signature.computeClassSignature(refId.getType());
|
||||
JdwpString.writeString(os, sig);
|
||||
}
|
||||
|
||||
private void executeClassLoader(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
|
||||
Class clazz = refId.getType();
|
||||
ClassLoader loader = clazz.getClassLoader();
|
||||
ObjectId oid = idMan.getId(loader);
|
||||
oid.write(os);
|
||||
}
|
||||
|
||||
private void executeModifiers(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
|
||||
Class clazz = refId.getType();
|
||||
os.writeInt(clazz.getModifiers());
|
||||
}
|
||||
|
||||
private void executeFields(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
|
||||
Field[] fields = clazz.getFields();
|
||||
os.writeInt(fields.length);
|
||||
for (int i = 0; i < fields.length; i++)
|
||||
{
|
||||
Field field = fields[i];
|
||||
idMan.getId(field).write(os);
|
||||
JdwpString.writeString(os, field.getName());
|
||||
JdwpString.writeString(os, Signature.computeFieldSignature(field));
|
||||
os.writeInt(field.getModifiers());
|
||||
}
|
||||
}
|
||||
|
||||
private void executeMethods(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
|
||||
Method[] methods = clazz.getMethods();
|
||||
os.writeInt(methods.length);
|
||||
for (int i = 0; i < methods.length; i++)
|
||||
{
|
||||
Method method = methods[i];
|
||||
idMan.getId(method).write(os);
|
||||
JdwpString.writeString(os, method.getName());
|
||||
JdwpString.writeString(os, Signature.computeMethodSignature(method));
|
||||
os.writeInt(method.getModifiers());
|
||||
}
|
||||
}
|
||||
|
||||
private void executeGetValues(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
|
||||
int numFields = bb.getInt();
|
||||
os.writeInt(numFields); // Looks pointless but this is the protocol
|
||||
for (int i = 0; i < numFields; i++)
|
||||
{
|
||||
ObjectId fieldId = idMan.readId(bb);
|
||||
Field field = (Field) (fieldId.getObject());
|
||||
Class fieldClazz = field.getDeclaringClass();
|
||||
|
||||
// We don't actually need the clazz to get the field but we might as
|
||||
// well check that the debugger got it right
|
||||
if (fieldClazz.isAssignableFrom(clazz))
|
||||
Value.writeStaticValueFromField(os, field);
|
||||
else
|
||||
throw new InvalidFieldException(fieldId.getId());
|
||||
}
|
||||
}
|
||||
|
||||
private void executeSourceFile(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
|
||||
// We'll need to go into the jvm for this unless there's an easier way
|
||||
String sourceFileName = vm.getSourceFile(clazz);
|
||||
JdwpString.writeString(os, sourceFileName);
|
||||
// clazz.getProtectionDomain().getCodeSource().getLocation();
|
||||
}
|
||||
|
||||
private void executeNestedTypes(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
Class[] declaredClazzes = clazz.getDeclaredClasses();
|
||||
os.writeInt(declaredClazzes.length);
|
||||
for (int i = 0; i < declaredClazzes.length; i++)
|
||||
{
|
||||
Class decClazz = declaredClazzes[i];
|
||||
ReferenceTypeId clazzId = idMan.getReferenceTypeId(decClazz);
|
||||
clazzId.writeTagged(os);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeStatus(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
|
||||
// I don't think there's any other way to get this
|
||||
int status = vm.getStatus(clazz);
|
||||
os.writeInt(status);
|
||||
}
|
||||
|
||||
private void executeInterfaces(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
Class[] interfaces = clazz.getInterfaces();
|
||||
os.writeInt(interfaces.length);
|
||||
for (int i = 0; i < interfaces.length; i++)
|
||||
{
|
||||
Class interfaceClass = interfaces[i];
|
||||
ReferenceTypeId intId = idMan.getReferenceTypeId(interfaceClass);
|
||||
intId.write(os);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeClassObject(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ReferenceTypeId refId = idMan.readReferenceTypeId(bb);
|
||||
Class clazz = refId.getType();
|
||||
ObjectId clazzObjectId = idMan.getId(clazz);
|
||||
clazzObjectId.write(os);
|
||||
}
|
||||
|
||||
private void executeSourceDebugExtension(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
// This command is optional, determined by VirtualMachines CapabilitiesNew
|
||||
// so we'll leave it till later to implement
|
||||
throw new NotImplementedException(
|
||||
"Command SourceDebugExtension not implemented.");
|
||||
}
|
||||
|
||||
private void executeSignatureWithGeneric(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
// We don't have generics yet
|
||||
throw new NotImplementedException(
|
||||
"Command SourceDebugExtension not implemented.");
|
||||
}
|
||||
|
||||
private void executeFieldWithGeneric(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
// We don't have generics yet
|
||||
throw new NotImplementedException(
|
||||
"Command SourceDebugExtension not implemented.");
|
||||
}
|
||||
|
||||
private void executeMethodsWithGeneric(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
// We don't have generics yet
|
||||
throw new NotImplementedException(
|
||||
"Command SourceDebugExtension not implemented.");
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/* StringReferenceCommandSet.java -- class to implement the StringReference
|
||||
Command Set
|
||||
Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 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
|
||||
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 gnu.classpath.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.Jdwp;
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
import gnu.classpath.jdwp.util.JdwpString;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class representing the StringReference Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class StringReferenceCommandSet implements CommandSet
|
||||
{
|
||||
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
// Although there's only a single command to choose from we still use
|
||||
// a switch to maintain consistency with the rest of the CommandSets
|
||||
switch (command)
|
||||
{
|
||||
case JdwpConstants.CommandSet.StringReference.VALUE:
|
||||
executeValue(bb, os);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException("Command " + command +
|
||||
" not found in String Reference Command Set.");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// The DataOutputStream we're using isn't talking to a socket at all
|
||||
// So if we throw an IOException we're in serious trouble
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeValue(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = Jdwp.getIdManager().readId(bb);
|
||||
|
||||
String str = (String) oid.getObject();
|
||||
JdwpString.writeString(os, str);
|
||||
}
|
||||
}
|
||||
@@ -1,474 +0,0 @@
|
||||
/* VirtualMachineCommandSet.java -- class to implement the VirtualMachine
|
||||
Command Set
|
||||
Copyright (C) 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 gnu.classpath.jdwp.processor;
|
||||
|
||||
import gnu.classpath.jdwp.IVirtualMachine;
|
||||
import gnu.classpath.jdwp.Jdwp;
|
||||
import gnu.classpath.jdwp.JdwpConstants;
|
||||
import gnu.classpath.jdwp.exception.JdwpException;
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
import gnu.classpath.jdwp.exception.NotImplementedException;
|
||||
import gnu.classpath.jdwp.id.IdManager;
|
||||
import gnu.classpath.jdwp.id.ObjectId;
|
||||
import gnu.classpath.jdwp.id.ReferenceTypeId;
|
||||
import gnu.classpath.jdwp.util.JdwpString;
|
||||
import gnu.classpath.jdwp.util.Signature;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* A class representing the VirtualMachine Command Set.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class VirtualMachineCommandSet implements CommandSet
|
||||
{
|
||||
// Our hook into the jvm
|
||||
private final IVirtualMachine vm = Jdwp.getIVirtualMachine();
|
||||
|
||||
// Manages all the different ids that are assigned by jdwp
|
||||
private final IdManager idMan = Jdwp.getIdManager();
|
||||
|
||||
// The Jdwp object
|
||||
private final Jdwp jdwp = Jdwp.getDefault();
|
||||
|
||||
public boolean runCommand(ByteBuffer bb, DataOutputStream os, byte command)
|
||||
throws JdwpException
|
||||
{
|
||||
boolean keepRunning = true;
|
||||
try
|
||||
{
|
||||
switch (command)
|
||||
{
|
||||
case JdwpConstants.CommandSet.VirtualMachine.VERSION:
|
||||
executeVersion(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.CLASSES_BY_SIGNATURE:
|
||||
executeClassesBySignature(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.ALL_CLASSES:
|
||||
executeAllClasses(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.ALL_THREADS:
|
||||
executeAllThreads(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.TOP_LEVEL_THREAD_GROUPS:
|
||||
executeTopLevelThreadGroups(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.IDSIZES:
|
||||
executeIDsizes(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.DISPOSE:
|
||||
keepRunning = false;
|
||||
executeDispose(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.SUSPEND:
|
||||
executeSuspend(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.RESUME:
|
||||
executeResume(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.EXIT:
|
||||
keepRunning = false;
|
||||
executeExit(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.CREATE_STRING:
|
||||
executeCreateString(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.CAPABILITIES:
|
||||
executeCapabilities(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.CLASS_PATHS:
|
||||
executeClassPaths(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.DISPOSE_OBJECTS:
|
||||
executeDisposeObjects(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.HOLD_EVENTS:
|
||||
executeHoldEvents(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.RELEASE_EVENTS:
|
||||
executeReleaseEvents(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.CAPABILITIES_NEW:
|
||||
executeCapabilitiesNew(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.REDEFINE_CLASSES:
|
||||
executeRedefineClasses(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.SET_DEFAULT_STRATUM:
|
||||
executeSetDefaultStratum(bb, os);
|
||||
break;
|
||||
case JdwpConstants.CommandSet.VirtualMachine.ALL_CLASSES_WITH_GENERIC:
|
||||
executeAllClassesWithGeneric(bb, os);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
// The DataOutputStream we're using isn't talking to a socket at all
|
||||
// So if we throw an IOException we're in serious trouble
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
return keepRunning;
|
||||
}
|
||||
|
||||
private void executeVersion(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
|
||||
Properties props = System.getProperties();
|
||||
|
||||
int jdwpMajor = JdwpConstants.Version.MAJOR;
|
||||
int jdwpMinor = JdwpConstants.Version.MINOR;
|
||||
// The description field is pretty loosely defined
|
||||
String description = "JDWP version " + jdwpMajor + "." + jdwpMinor
|
||||
+ ", JVM version " + props.getProperty("java.vm.name")
|
||||
+ " " + props.getProperty("java.vm.version") + " "
|
||||
+ props.getProperty("java.version");
|
||||
String vmVersion = props.getProperty("java.version");
|
||||
String vmName = props.getProperty("java.vm.name");
|
||||
JdwpString.writeString(os, description);
|
||||
os.write(jdwpMajor);
|
||||
os.write(jdwpMinor);
|
||||
JdwpString.writeString(os, vmName);
|
||||
JdwpString.writeString(os, vmVersion);
|
||||
}
|
||||
|
||||
private void executeClassesBySignature(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
String sig = JdwpString.readString(bb);
|
||||
ArrayList allMatchingClasses = new ArrayList();
|
||||
|
||||
// This will be an Iterator over all loaded Classes
|
||||
Iterator iter = vm.getAllLoadedClasses();
|
||||
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Class clazz = (Class) iter.next();
|
||||
String clazzSig = Signature.computeClassSignature(clazz);
|
||||
if (clazzSig.equals(sig))
|
||||
allMatchingClasses.add(clazz);
|
||||
}
|
||||
|
||||
os.writeInt(allMatchingClasses.size());
|
||||
for (int i = 0; i < allMatchingClasses.size(); i++)
|
||||
{
|
||||
Class clazz = (Class) allMatchingClasses.get(i);
|
||||
ReferenceTypeId id = idMan.getReferenceTypeId(clazz);
|
||||
id.writeTagged(os);
|
||||
int status = vm.getStatus(clazz);
|
||||
os.writeInt(status);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeAllClasses(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
// Disable garbage collection while we're collecting the info on loaded
|
||||
// classes so we some classes don't get collected between the time we get
|
||||
// the count and the time we get the list
|
||||
vm.disableGarbageCollection();
|
||||
|
||||
int classCount = vm.getAllLoadedClassesCount();
|
||||
os.writeInt(classCount);
|
||||
|
||||
// This will be an Iterator over all loaded Classes
|
||||
Iterator iter = vm.getAllLoadedClasses();
|
||||
vm.enableGarbageCollection();
|
||||
int count = 0;
|
||||
|
||||
// Note it's possible classes were created since out classCount so make
|
||||
// sure we don't write more classes than we told the debugger
|
||||
while (iter.hasNext() && count++ < classCount)
|
||||
{
|
||||
Class clazz = (Class) iter.next();
|
||||
ReferenceTypeId id = idMan.getReferenceTypeId(clazz);
|
||||
id.writeTagged(os);
|
||||
String sig = Signature.computeClassSignature(clazz);
|
||||
JdwpString.writeString(os, sig);
|
||||
int status = vm.getStatus(clazz);
|
||||
os.writeInt(status);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeAllThreads(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ThreadGroup jdwpGroup = Thread.currentThread().getThreadGroup();
|
||||
ThreadGroup root = getRootThreadGroup(jdwpGroup);
|
||||
|
||||
int numThreads = root.activeCount();
|
||||
Thread allThreads[] = new Thread[numThreads];
|
||||
root.enumerate(allThreads, true);
|
||||
|
||||
// We need to loop through for the true count since some threads may have
|
||||
// been destroyed since we got
|
||||
// activeCount so those spots in the array will be null. As well we must
|
||||
// ignore any threads that belong to jdwp
|
||||
numThreads = 0;
|
||||
for (int i = 0; i < allThreads.length; i++)
|
||||
{
|
||||
Thread thread = allThreads[i];
|
||||
if (thread == null)
|
||||
break; // No threads after this point
|
||||
if (!thread.getThreadGroup().equals(jdwpGroup))
|
||||
numThreads++;
|
||||
}
|
||||
|
||||
os.writeInt(numThreads);
|
||||
|
||||
for (int i = 0; i < allThreads.length; i++)
|
||||
{
|
||||
Thread thread = allThreads[i];
|
||||
if (thread == null)
|
||||
break; // No threads after this point
|
||||
if (!thread.getThreadGroup().equals(jdwpGroup))
|
||||
idMan.getId(thread).write(os);
|
||||
}
|
||||
}
|
||||
|
||||
private void executeTopLevelThreadGroups(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ThreadGroup jdwpGroup = jdwp.getJdwpThreadGroup();
|
||||
ThreadGroup root = getRootThreadGroup(jdwpGroup);
|
||||
|
||||
os.writeInt(1); // Just one top level group allowed?
|
||||
idMan.getId(root);
|
||||
}
|
||||
|
||||
private void executeDispose(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
// resumeAllThreads isn't sufficient as a thread may have been
|
||||
// suspended multiple times, we likely need a way to keep track of how many
|
||||
// times a thread has been suspended or else a stronger resume method for
|
||||
// this purpose
|
||||
// vm.resumeAllThreadsExcept(jdwp.getJdwpThreadGroup());
|
||||
|
||||
// Simply shutting down the jdwp layer will take care of the rest of the
|
||||
// shutdown other than disabling debugging in the VM
|
||||
// vm.disableDebugging();
|
||||
|
||||
// Don't implement this until we're sure how to remove all the debugging
|
||||
// effects from the VM.
|
||||
throw new NotImplementedException(
|
||||
"Command VirtualMachine.Dispose not implemented");
|
||||
|
||||
}
|
||||
|
||||
private void executeIDsizes(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
ObjectId oid = new ObjectId();
|
||||
os.writeInt(oid.size()); // fieldId
|
||||
os.writeInt(oid.size()); // methodId
|
||||
os.writeInt(oid.size()); // objectId
|
||||
os.writeInt(new ReferenceTypeId((byte) 0x00).size()); // referenceTypeId
|
||||
os.writeInt(oid.size()); // frameId
|
||||
}
|
||||
|
||||
private void executeSuspend(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
vm.suspendAllThreadsExcept(jdwp.getJdwpThreadGroup());
|
||||
}
|
||||
|
||||
private void executeResume(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
vm.resumeAllThreadsExcept(jdwp.getJdwpThreadGroup());
|
||||
}
|
||||
|
||||
private void executeExit(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
int exitCode = bb.getInt();
|
||||
jdwp.setExit(exitCode);
|
||||
}
|
||||
|
||||
private void executeCreateString(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
String string = JdwpString.readString(bb);
|
||||
ObjectId stringId = Jdwp.getIdManager().getId(string);
|
||||
|
||||
// Since this string isn't referenced anywhere we'll disable garbage
|
||||
// collection on it so it's still around when the debugger gets back to it.
|
||||
stringId.disableCollection();
|
||||
stringId.write(os);
|
||||
}
|
||||
|
||||
private void executeCapabilities(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
// Store these somewhere?
|
||||
os.writeBoolean(false); // canWatchFieldModification
|
||||
os.writeBoolean(false); // canWatchFieldAccess
|
||||
os.writeBoolean(false); // canGetBytecodes
|
||||
os.writeBoolean(false); // canGetSyntheticAttribute
|
||||
os.writeBoolean(false); // canGetOwnedMonitorInfo
|
||||
os.writeBoolean(false); // canGetCurrentContendedMonitor
|
||||
os.writeBoolean(false); // canGetMonitorInfo
|
||||
}
|
||||
|
||||
private void executeClassPaths(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
String baseDir = System.getProperty("user.dir");
|
||||
JdwpString.writeString(os, baseDir);
|
||||
|
||||
// Find and write the classpath
|
||||
String classPath = System.getProperty("java.class.path");
|
||||
String[] paths = classPath.split(":");
|
||||
|
||||
os.writeInt(paths.length);
|
||||
for (int i = 0; i < paths.length; i++)
|
||||
JdwpString.writeString(os, paths[i]);
|
||||
|
||||
// Now the bootpath
|
||||
String bootPath = System.getProperty("sun.boot.class.path");
|
||||
paths = bootPath.split(":");
|
||||
os.writeInt(paths.length);
|
||||
for (int i = 0; i < paths.length; i++)
|
||||
JdwpString.writeString(os, paths[i]);
|
||||
}
|
||||
|
||||
private void executeDisposeObjects(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
// Instead of going through the list of objects they give us it's probably
|
||||
// better just to find the garbage collected objects ourselves
|
||||
idMan.update();
|
||||
}
|
||||
|
||||
private void executeHoldEvents(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
// Going to have to implement a send queue somewhere and do this without
|
||||
// triggering events
|
||||
// Until then just don't implement
|
||||
throw new NotImplementedException(
|
||||
"Command VirtualMachine.HoldEvents not implemented");
|
||||
}
|
||||
|
||||
// Opposite of executeHoldEvents
|
||||
private void executeReleaseEvents(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
throw new NotImplementedException(
|
||||
"Command VirtualMachine.ReleaseEvents not implemented");
|
||||
}
|
||||
|
||||
private void executeCapabilitiesNew(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException, IOException
|
||||
{
|
||||
// Store these somewhere?
|
||||
final int CAPABILITIES_NEW_SIZE = 32;
|
||||
os.writeBoolean(false); // canWatchFieldModification
|
||||
os.writeBoolean(false); // canWatchFieldAccess
|
||||
os.writeBoolean(false); // canGetBytecodes
|
||||
os.writeBoolean(false); // canGetSyntheticAttribute
|
||||
os.writeBoolean(false); // canGetOwnedMonitorInfo
|
||||
os.writeBoolean(false); // canGetCurrentContendedMonitor
|
||||
os.writeBoolean(false); // canGetMonitorInfo
|
||||
os.writeBoolean(false); // canRedefineClasses
|
||||
os.writeBoolean(false); // canAddMethod
|
||||
os.writeBoolean(false); // canUnrestrictedlyRedefineClasses
|
||||
os.writeBoolean(false); // canPopFrames
|
||||
os.writeBoolean(false); // canUseInstanceFilters
|
||||
os.writeBoolean(false); // canGetSourceDebugExtension
|
||||
os.writeBoolean(false); // canRequestVMDeathEvent
|
||||
os.writeBoolean(false); // canSetDefaultStratum
|
||||
for (int i = 15; i < CAPABILITIES_NEW_SIZE; i++)
|
||||
// Future capabilities
|
||||
// currently unused
|
||||
os.writeBoolean(false); // Set to false
|
||||
}
|
||||
|
||||
private void executeRedefineClasses(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
// Optional command, don't implement
|
||||
throw new NotImplementedException(
|
||||
"Command VirtualMachine.RedefineClasses not implemented");
|
||||
}
|
||||
|
||||
private void executeSetDefaultStratum(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
// Optional command, don't implement
|
||||
throw new NotImplementedException(
|
||||
"Command VirtualMachine.SetDefaultStratum not implemented");
|
||||
}
|
||||
|
||||
private void executeAllClassesWithGeneric(ByteBuffer bb, DataOutputStream os)
|
||||
throws JdwpException
|
||||
{
|
||||
// We don't handle generics
|
||||
throw new NotImplementedException(
|
||||
"Command VirtualMachine.AllClassesWithGeneric not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the root ThreadGroup of this ThreadGroup
|
||||
*/
|
||||
private ThreadGroup getRootThreadGroup(ThreadGroup group)
|
||||
{
|
||||
ThreadGroup parent = group.getParent();
|
||||
|
||||
while (parent != null)
|
||||
{
|
||||
group = parent;
|
||||
parent = group.getParent();
|
||||
}
|
||||
return group; // This group was the root
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/* ITransport.java -- An interface defining JDWP transports
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.transport;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.IllegalArgumentException;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A class representing a transport layer. This class serves as a generic
|
||||
* interface for all transport types used in the JDWP back-end.
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public interface ITransport
|
||||
{
|
||||
/**
|
||||
* Configure the transport with the given properties
|
||||
*
|
||||
* @param properties properties of the transport configuration
|
||||
* @throws TransportException on configury error
|
||||
*/
|
||||
public void configure (HashMap properties)
|
||||
throws TransportException;
|
||||
|
||||
/**
|
||||
* Initialize the transport
|
||||
*
|
||||
* @throws TransportException on initialization error
|
||||
*/
|
||||
public void initialize ()
|
||||
throws TransportException;
|
||||
|
||||
/**
|
||||
* Get the input stream for the transport
|
||||
*/
|
||||
public InputStream getInputStream ()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Get the output stream for the transport
|
||||
*/
|
||||
public OutputStream getOutputStream ()
|
||||
throws IOException;
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
/* JdwpCommandPacket.java -- JDWP command packet
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.transport;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A class representing a JDWP command packet.
|
||||
* This class adds command set and command to the packet header
|
||||
* information in {@link gnu.classpath.jdwp.transport.JdwpPacket}
|
||||
* and adds additional command packet-specific processing.
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class JdwpCommandPacket extends JdwpPacket
|
||||
{
|
||||
/**
|
||||
* Command set
|
||||
*/
|
||||
protected byte _commandSet;
|
||||
|
||||
/**
|
||||
* Command
|
||||
*/
|
||||
protected byte _command;
|
||||
|
||||
// Minimum packet size [excluding super class]
|
||||
// ( commandSet (1) + command (1) )
|
||||
private static final int MINIMUM_LENGTH = 2;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>JdwpCommandPacket</code>
|
||||
*/
|
||||
public JdwpCommandPacket ()
|
||||
{
|
||||
// Don't assign an id. This constructor is called by
|
||||
// JdwpPacket.fromBytes, and that will assign a packet id.
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new <code>JdwpCommandPacket</code>
|
||||
* with the given command set and command
|
||||
*
|
||||
* @param set the command set
|
||||
* @param command the command
|
||||
*/
|
||||
public JdwpCommandPacket (byte set, byte command)
|
||||
{
|
||||
_id = ++_last_id;
|
||||
_commandSet = set;
|
||||
_command = command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retuns the length of this packet
|
||||
*/
|
||||
public int getLength ()
|
||||
{
|
||||
return MINIMUM_LENGTH + super.getLength ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command set
|
||||
*/
|
||||
public byte getCommandSet ()
|
||||
{
|
||||
return _commandSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command set
|
||||
*/
|
||||
public void setCommandSet (byte cs)
|
||||
{
|
||||
_commandSet = cs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the command
|
||||
*/
|
||||
public byte getCommand ()
|
||||
{
|
||||
return _command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command
|
||||
*/
|
||||
public void setCommand (byte cmd)
|
||||
{
|
||||
_command = cmd;
|
||||
}
|
||||
|
||||
// Reads command packet data from the given buffer, starting
|
||||
// at the given offset
|
||||
protected int myFromBytes (byte[] bytes, int index)
|
||||
{
|
||||
int i = 0;
|
||||
setCommandSet (bytes[index + i++]);
|
||||
setCommand (bytes[index + i++]);
|
||||
return i;
|
||||
}
|
||||
|
||||
// Writes the command packet data into the given buffer
|
||||
protected void myWrite (DataOutputStream dos)
|
||||
throws IOException
|
||||
{
|
||||
dos.writeByte (getCommandSet ());
|
||||
dos.writeByte (getCommand ());
|
||||
}
|
||||
}
|
||||
@@ -1,298 +0,0 @@
|
||||
/* JdwpConnection.java -- A JDWP-speaking connection
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.transport;
|
||||
|
||||
import gnu.classpath.jdwp.Jdwp;
|
||||
import gnu.classpath.jdwp.event.Event;
|
||||
import gnu.classpath.jdwp.event.EventRequest;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A connection via some transport to some JDWP-speaking entity.
|
||||
* This is also a thread which handles all communications to/from
|
||||
* the debugger. While access to the transport layer may be accessed by
|
||||
* several threads, start-up and initialization should not be allowed
|
||||
* to occur more than once.
|
||||
*
|
||||
* <p>This class is also a thread that is responsible for pulling
|
||||
* packets off the wire and sticking them in a queue for packet
|
||||
* processing threads.
|
||||
*
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class JdwpConnection
|
||||
extends Thread
|
||||
{
|
||||
// The JDWP handshake
|
||||
private static final byte[] _HANDSHAKE = {'J', 'D', 'W', 'P', '-', 'H', 'a',
|
||||
'n', 'd', 's', 'h', 'a', 'k', 'e'};
|
||||
|
||||
// Transport method
|
||||
private ITransport _transport;
|
||||
|
||||
// Command queue
|
||||
private ArrayList _commandQueue;
|
||||
|
||||
// Shutdown flag
|
||||
private boolean _shutdown;
|
||||
|
||||
// Input stream from transport
|
||||
private DataInputStream _inStream;
|
||||
|
||||
// Output stream from transprot
|
||||
private DataOutputStream _outStream;
|
||||
|
||||
// A buffer used to construct the packet data
|
||||
private ByteArrayOutputStream _bytes;
|
||||
|
||||
// A DataOutputStream for the byte buffer
|
||||
private DataOutputStream _doStream;
|
||||
|
||||
/**
|
||||
* Creates a new <code>JdwpConnection</code> instance
|
||||
*
|
||||
* @param transport the transport to use for communications
|
||||
*/
|
||||
public JdwpConnection (ITransport transport)
|
||||
{
|
||||
_transport = transport;
|
||||
_commandQueue = new ArrayList ();
|
||||
_shutdown = false;
|
||||
_bytes = new ByteArrayOutputStream ();
|
||||
_doStream = new DataOutputStream (_bytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the connection, including connecting
|
||||
* to socket or shared memory endpoint
|
||||
*
|
||||
* @throws TransportException if initialization fails
|
||||
*/
|
||||
public void initialize ()
|
||||
throws TransportException
|
||||
{
|
||||
// Initialize transport (connect socket, e.g.)
|
||||
_transport.initialize ();
|
||||
|
||||
// Do handshake
|
||||
try
|
||||
{
|
||||
_inStream = new DataInputStream (_transport.getInputStream ());
|
||||
_outStream = new DataOutputStream (_transport.getOutputStream ());
|
||||
_doHandshake ();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
throw new TransportException (ioe);
|
||||
}
|
||||
}
|
||||
|
||||
/* Does the JDWP handshake -- this should not need synchronization
|
||||
because this is called by VM startup code, i.e., no packet
|
||||
processing threads have started yet. */
|
||||
private void _doHandshake ()
|
||||
throws IOException
|
||||
{
|
||||
// According to the spec, the handshake is always initiated by
|
||||
// the debugger, regardless of whether the JVM is in client mode or
|
||||
// server mode.
|
||||
|
||||
// Wait for handshake from debugger
|
||||
byte[] hshake = new byte[_HANDSHAKE.length];
|
||||
_inStream.readFully (hshake, 0, _HANDSHAKE.length);
|
||||
|
||||
if (Arrays.equals (hshake, _HANDSHAKE))
|
||||
{
|
||||
// Send reply handshake
|
||||
_outStream.write (_HANDSHAKE, 0, _HANDSHAKE.length);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IOException ("invalid JDWP handshake (\"" + hshake + "\")");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main run method for the thread. This thread loops waiting for
|
||||
* packets to be read via the connection. When a packet is complete
|
||||
* and ready for processing, it places the packet in a queue that can
|
||||
* be accessed via <code>getPacket</code>
|
||||
*/
|
||||
public void run ()
|
||||
{
|
||||
while (!_shutdown)
|
||||
{
|
||||
try
|
||||
{
|
||||
_readOnePacket ();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
/* IOException can occur for two reasons:
|
||||
1. Lost connection with the other side
|
||||
2. Transport was shutdown
|
||||
In either case, we make sure that all of the
|
||||
back-end gets shutdown. */
|
||||
Jdwp.getInstance().shutdown ();
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
System.out.println ("JdwpConnection.run: caught an exception: "
|
||||
+ t);
|
||||
// Just keep going
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reads a single packet from the connection, adding it to the packet
|
||||
// queue when a complete packet is ready.
|
||||
private void _readOnePacket ()
|
||||
throws IOException
|
||||
{
|
||||
byte[] data = null;
|
||||
|
||||
// Read in the packet
|
||||
int length = _inStream.readInt ();
|
||||
if (length < 11)
|
||||
{
|
||||
throw new IOException ("JDWP packet length < 11 ("
|
||||
+ length + ")");
|
||||
}
|
||||
|
||||
data = new byte[length];
|
||||
data[0] = (byte) (length >>> 24);
|
||||
data[1] = (byte) (length >>> 16);
|
||||
data[2] = (byte) (length >>> 8);
|
||||
data[3] = (byte) length;
|
||||
_inStream.readFully (data, 4, length - 4);
|
||||
|
||||
JdwpPacket packet = JdwpPacket.fromBytes (data);
|
||||
if (packet != null)
|
||||
{
|
||||
synchronized (_commandQueue)
|
||||
{
|
||||
_commandQueue.add (packet);
|
||||
_commandQueue.notifyAll ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a packet from the queue of ready packets
|
||||
*
|
||||
* @returns a <code>JdwpPacket</code> ready for processing
|
||||
* <code>null</code> when shutting down
|
||||
*/
|
||||
public JdwpPacket getPacket ()
|
||||
{
|
||||
synchronized (_commandQueue)
|
||||
{
|
||||
while (_commandQueue.isEmpty ())
|
||||
{
|
||||
try
|
||||
{
|
||||
_commandQueue.wait ();
|
||||
}
|
||||
catch (InterruptedException ie)
|
||||
{
|
||||
/* PacketProcessor is interrupted
|
||||
when shutting down */
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return (JdwpPacket) _commandQueue.remove (0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to the debugger
|
||||
*
|
||||
* @param pkt a <code>JdwpPacket</code> to send
|
||||
* @throws IOException
|
||||
*/
|
||||
public void sendPacket (JdwpPacket pkt)
|
||||
throws IOException
|
||||
{
|
||||
pkt.write (_outStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an event notification to the debugger
|
||||
*
|
||||
* @param request the debugger request that wanted this event
|
||||
* @param event the event
|
||||
* @throws IOException
|
||||
*/
|
||||
public void sendEvent (EventRequest request, Event event)
|
||||
throws IOException
|
||||
{
|
||||
JdwpPacket pkt;
|
||||
|
||||
synchronized (_bytes)
|
||||
{
|
||||
_bytes.reset ();
|
||||
pkt = event.toPacket (_doStream, request);
|
||||
pkt.setData (_bytes.toByteArray ());
|
||||
}
|
||||
|
||||
sendPacket (pkt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shutdown the connection
|
||||
*/
|
||||
public void shutdown ()
|
||||
{
|
||||
if (!_shutdown)
|
||||
{
|
||||
_transport.shutdown ();
|
||||
_shutdown = true;
|
||||
interrupt ();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,278 +0,0 @@
|
||||
/* JdwpPacket.java -- Base class for JDWP command and reply packets
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.transport;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* All command and reply packets in JDWP share
|
||||
* common header type information:
|
||||
*
|
||||
* length (4 bytes) : size of entire packet, including length
|
||||
* id (4 bytes) : unique packet id
|
||||
* flags (1 byte) : flag byte
|
||||
* [command packet stuff | reply packet stuff]
|
||||
* data (variable) : unique command-/reply-specific data
|
||||
*
|
||||
* This class deal with everything except the command- and reply-specific
|
||||
* data, which get handled in {@link
|
||||
* gnu.classpath.jdwp.transport.JdwpCommandPacket} and {@link
|
||||
* gnu.classpath.jdwp.transprot.JdwpReplyPacket}.
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public abstract class JdwpPacket
|
||||
{
|
||||
// Last id of packet constructed
|
||||
protected static int _last_id = 0;
|
||||
|
||||
// JDWP reply packet flag
|
||||
protected static final int JDWP_FLAG_REPLY = 0x80;
|
||||
|
||||
/**
|
||||
* Minimum packet size excluding sub-class data
|
||||
* ( length (4) + id (4) + flags (1) )
|
||||
*/
|
||||
protected static final int MINIMUM_SIZE = 9;
|
||||
|
||||
/**
|
||||
* Id of command/reply
|
||||
*/
|
||||
protected int _id;
|
||||
|
||||
/**
|
||||
* Packet flags
|
||||
*/
|
||||
protected byte _flags;
|
||||
|
||||
/**
|
||||
* Packet-specific data
|
||||
*/
|
||||
protected byte[] _data;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public JdwpPacket ()
|
||||
{
|
||||
// By default, DON'T assign an id. This way when a packet
|
||||
// is constructed from fromBytes, _last_id won't increment (i.e.,
|
||||
// it won't leave holes in the outgoing packet ids).
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>JdwpPacket</code> with the id
|
||||
* from the given packet.
|
||||
*
|
||||
* @param pkt a packet whose id will be used in this new packet
|
||||
*/
|
||||
public JdwpPacket (JdwpPacket pkt)
|
||||
{
|
||||
_id = pkt.getId ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the packet id
|
||||
*/
|
||||
public int getId ()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the packet id
|
||||
*/
|
||||
public void setId (int id)
|
||||
{
|
||||
_id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the packet flags
|
||||
*/
|
||||
public byte getFlags ()
|
||||
{
|
||||
return _flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the packet flags
|
||||
*/
|
||||
public void setFlags (byte flags)
|
||||
{
|
||||
_flags = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command/reply-specific data in this packet
|
||||
*/
|
||||
public byte[] getData ()
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the command/reply-specific data in this packet
|
||||
*/
|
||||
public void setData (byte[] data)
|
||||
{
|
||||
_data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of this entire packet
|
||||
*/
|
||||
public int getLength ()
|
||||
{
|
||||
return MINIMUM_SIZE + (_data == null ? 0 : _data.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow subclasses to initialize from data
|
||||
*
|
||||
* @param bytes packet data from the wire
|
||||
* @param index index into <code>bytes</code> to start processing
|
||||
* @return number of bytes in <code>bytes</code> processed
|
||||
*/
|
||||
protected abstract int myFromBytes (byte[] bytes, int index);
|
||||
|
||||
/**
|
||||
* Convert the given bytes into a <code>JdwpPacket</code>. Uses the
|
||||
* abstract method <code>myFromBytes</code> to allow subclasses to
|
||||
* process data.
|
||||
*
|
||||
* If the given data does not represent a valid JDWP packet, it returns
|
||||
* <code>null</code>.
|
||||
*
|
||||
* @param bytes packet data from the wire
|
||||
* @param index index into <code>bytes</code> to start processing
|
||||
* @return number of bytes in <code>bytes</code> processed
|
||||
*/
|
||||
public static JdwpPacket fromBytes (byte[] bytes)
|
||||
{
|
||||
int i = 0;
|
||||
int length = ((bytes[i++] & 0xff) << 24 | (bytes[i++] & 0xff) << 16
|
||||
| (bytes[i++] & 0xff) << 8 | (bytes[i++] & 0xff));
|
||||
int id = 0;
|
||||
byte flags = 0;
|
||||
|
||||
if (bytes.length == length)
|
||||
{
|
||||
id = ((bytes[i++] & 0xff) << 24 | (bytes[i++] & 0xff) << 16
|
||||
| (bytes[i++] & 0xff) << 8 | (bytes[i++] & 0xff));
|
||||
flags = bytes[i++];
|
||||
|
||||
Class clazz = null;
|
||||
if (flags == 0)
|
||||
clazz = JdwpCommandPacket.class;
|
||||
else if ((flags & JDWP_FLAG_REPLY) != 0)
|
||||
clazz = JdwpReplyPacket.class;
|
||||
else
|
||||
{
|
||||
// Malformed packet. Discard it.
|
||||
return null;
|
||||
}
|
||||
|
||||
JdwpPacket pkt = null;
|
||||
try
|
||||
{
|
||||
pkt = (JdwpPacket) clazz.newInstance ();
|
||||
}
|
||||
catch (InstantiationException ie)
|
||||
{
|
||||
// Discard packet
|
||||
return null;
|
||||
}
|
||||
catch (IllegalAccessException iae)
|
||||
{
|
||||
// Discard packet
|
||||
return null;
|
||||
}
|
||||
|
||||
pkt.setId (id);
|
||||
pkt.setFlags (flags);
|
||||
|
||||
i += pkt.myFromBytes (bytes, i);
|
||||
byte[] data = new byte[length - i];
|
||||
System.arraycopy (bytes, i, data, 0, data.length);
|
||||
pkt.setData (data);
|
||||
|
||||
return pkt;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Put subclass information onto the stream
|
||||
*
|
||||
* @param dos the output stream to which to write
|
||||
*/
|
||||
protected abstract void myWrite (DataOutputStream dos)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Writes the packet to the output stream
|
||||
*
|
||||
* @param dos the output stream to which to write the packet
|
||||
*/
|
||||
public void write (DataOutputStream dos)
|
||||
throws IOException
|
||||
{
|
||||
// length
|
||||
int length = getLength ();
|
||||
dos.writeInt (length);
|
||||
|
||||
// ID
|
||||
dos.writeInt (getId ());
|
||||
|
||||
// flag
|
||||
dos.writeByte (getFlags ());
|
||||
|
||||
// packet-specific stuff
|
||||
myWrite (dos);
|
||||
|
||||
// data (if any)
|
||||
byte[] data = getData ();
|
||||
if (data != null && data.length > 0)
|
||||
dos.write (data, 0, data.length);
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/* JdwpReplyPacket.java -- JDWP reply packet
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.transport;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A class represents a JDWP reply packet.
|
||||
* This class adds an error code to the packet header information
|
||||
* in {@link gnu.classpath.transport.JdwpPacket} and adds additional
|
||||
* reply packet-specific processing.
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class JdwpReplyPacket extends JdwpPacket
|
||||
{
|
||||
/**
|
||||
* Error code
|
||||
*/
|
||||
protected short _errorCode;
|
||||
|
||||
// Minimum packet size [excluding super class] ( errorCode (2) )
|
||||
private static final int MINIMUM_LENGTH = 2;
|
||||
|
||||
/**
|
||||
* Constructs a <code>JdwpReplyPacket</code>.
|
||||
*/
|
||||
public JdwpReplyPacket ()
|
||||
{
|
||||
// Don't assign a packet id. This is called by JdwpPacket.fromBytes
|
||||
// which assigns a packet id. (Not that a VM would do that...)
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>JdwpReplyPacket</code> with the
|
||||
* id from the given packet and error code
|
||||
*
|
||||
* @param pkt the packet whose id this packet will use
|
||||
* @param errorCode the error code
|
||||
*/
|
||||
public JdwpReplyPacket (JdwpPacket pkt, short errorCode)
|
||||
{
|
||||
this(pkt);
|
||||
_errorCode = errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>JdwpReplyPacket</code> with the
|
||||
* id from the given packet and an empty error code
|
||||
*
|
||||
* @param pkt the packet whose id this packet will use
|
||||
*/
|
||||
public JdwpReplyPacket (JdwpPacket pkt)
|
||||
{
|
||||
super (pkt);
|
||||
_flags = (byte) JDWP_FLAG_REPLY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of this packet
|
||||
*/
|
||||
public int getLength ()
|
||||
{
|
||||
return MINIMUM_LENGTH + super.getLength ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the error code
|
||||
*/
|
||||
public short getErrorCode ()
|
||||
{
|
||||
return _errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the error code
|
||||
*/
|
||||
public void setErrorCode (short ec)
|
||||
{
|
||||
_errorCode = ec;
|
||||
}
|
||||
|
||||
// Reads command packet data from the given buffer, starting
|
||||
// at the given offset
|
||||
protected int myFromBytes (byte[] bytes, int index)
|
||||
{
|
||||
int i = 0;
|
||||
setErrorCode ((short) ((bytes[index + i++] & 0xff) << 8
|
||||
| (bytes[index + i++] & 0xff)));
|
||||
return i;
|
||||
}
|
||||
|
||||
// Writes the command packet data into the given buffer
|
||||
protected void myWrite (DataOutputStream dos)
|
||||
throws IOException
|
||||
{
|
||||
dos.writeShort (getErrorCode ());
|
||||
}
|
||||
}
|
||||
@@ -1,171 +0,0 @@
|
||||
/* SocketTransport.java -- a socket transport
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.transport;
|
||||
|
||||
import gnu.classpath.jdwp.transport.ITransport;
|
||||
import gnu.classpath.jdwp.transport.TransportException;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
/**
|
||||
* A socket-based transport. This transport uses
|
||||
* configury string that looks like "name=dt_socket,
|
||||
* address=localhost:1234,server=y".
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
class SocketTransport
|
||||
implements ITransport
|
||||
{
|
||||
/**
|
||||
* Name of this transport
|
||||
*/
|
||||
public static final String NAME = "dt_socket";
|
||||
|
||||
// Configure properties
|
||||
private static final String _PROPERTY_ADDRESS = "address";
|
||||
private static final String _PROPERTY_SERVER = "server";
|
||||
|
||||
// Port number
|
||||
private int _port;
|
||||
|
||||
// Host name
|
||||
private String _host;
|
||||
|
||||
// Are we acting as a server?
|
||||
private boolean _server = false;
|
||||
|
||||
// Socket
|
||||
private Socket _socket;
|
||||
|
||||
/**
|
||||
* Setup the connection configuration from the given properties
|
||||
*
|
||||
* @param properties the properties of the JDWP session
|
||||
* @throws TransportException for any configury errors
|
||||
*/
|
||||
public void configure (HashMap properties)
|
||||
throws TransportException
|
||||
{
|
||||
// Get address [form: "hostname:port"]
|
||||
String p = (String) properties.get (_PROPERTY_ADDRESS);
|
||||
if (p != null)
|
||||
{
|
||||
String[] s = p.split (":");
|
||||
if (s.length == 2)
|
||||
{
|
||||
_host = s[0];
|
||||
_port = Integer.parseInt (s[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Get server [form: "y" or "n"]
|
||||
p = (String) properties.get (_PROPERTY_SERVER);
|
||||
if (p != null)
|
||||
{
|
||||
if (p.toLowerCase().equals ("y"))
|
||||
_server = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize this socket connection. This includes
|
||||
* connecting to the host (or listening for it).
|
||||
*
|
||||
* @throws TransportException if a transport-related error occurs
|
||||
*/
|
||||
public void initialize ()
|
||||
throws TransportException
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_server)
|
||||
{
|
||||
// Get a server socket
|
||||
ServerSocketFactory ssf = ServerSocketFactory.getDefault ();
|
||||
ServerSocket ss = ssf.createServerSocket (_port, 1);
|
||||
_socket = ss.accept ();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get a client socket (the factory will connect it)
|
||||
SocketFactory sf = SocketFactory.getDefault ();
|
||||
_socket = sf.createSocket (_host, _port);
|
||||
}
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
// This will grab UnknownHostException, too.
|
||||
throw new TransportException (ioe);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an <code>InputStream</code> for the transport
|
||||
*
|
||||
* @throws IOException if an I/O error occurs creating the stream
|
||||
* or the socket is not connected
|
||||
*/
|
||||
public InputStream getInputStream ()
|
||||
throws IOException
|
||||
{
|
||||
return _socket.getInputStream ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an <code>OutputStream</code> for the transport
|
||||
*
|
||||
* @throws IOException if an I/O error occurs creating the stream
|
||||
* or the socket is not connected
|
||||
*/
|
||||
public OutputStream getOutputStream ()
|
||||
throws IOException
|
||||
{
|
||||
return _socket.getOutputStream ();
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/* TransportException.java -- Exception for transport configury errors
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.transport;
|
||||
|
||||
/**
|
||||
* A transport configury or initialization exception thrown by
|
||||
* JDWP transports. This class is a generic exception class
|
||||
* that the different transport layers use to report transport-specific
|
||||
* exceptions that may occur (which could be very different from
|
||||
* one transport to the next.).
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class TransportException
|
||||
extends Exception
|
||||
{
|
||||
/**
|
||||
* Constructs a <code>TransportException</code> with the
|
||||
* given message
|
||||
*
|
||||
* @param message a message describing the exception
|
||||
*/
|
||||
public TransportException (String message)
|
||||
{
|
||||
super (message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a <code>TransportException</code> with the
|
||||
* given <code>Throwable</code> root cause
|
||||
*
|
||||
* @param t the cause of the exception
|
||||
*/
|
||||
public TransportException (Throwable t)
|
||||
{
|
||||
super (t);
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/* TransportFactory.java -- Factory for transports
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.transport;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A factory class that constructs transports for use by
|
||||
* the JDWP back-end.
|
||||
*
|
||||
* @author Keith Seitz <keiths@redhat.com>
|
||||
*/
|
||||
public class TransportFactory
|
||||
{
|
||||
// Keyword in configspec that specifies transport method
|
||||
private static final String _TRANSPORT_PROPERTY = "transport";
|
||||
|
||||
// A single transport method mapping
|
||||
private static class TransportMethod
|
||||
{
|
||||
String name;
|
||||
Class clazz;
|
||||
public TransportMethod (String name, Class clazz)
|
||||
{
|
||||
this.name = name;
|
||||
this.clazz = clazz;
|
||||
}
|
||||
}
|
||||
|
||||
// List of all supported transport methods
|
||||
private static TransportMethod[] _transportMethods = new TransportMethod[]
|
||||
{
|
||||
new TransportMethod (SocketTransport.NAME, SocketTransport.class)
|
||||
//new TransportMethod (ShmemTransport.NAME, ShmemTransport.class)
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a transport configured as specified in the properties
|
||||
*
|
||||
* @param properties a <code>HashMap</code> specifying the JDWP
|
||||
* configuration properties
|
||||
* @returns the created and configured transport
|
||||
* @throws TransportException for invalid configurations
|
||||
*/
|
||||
public static ITransport newInstance (HashMap properties)
|
||||
throws TransportException
|
||||
{
|
||||
String name = null;
|
||||
if (properties != null)
|
||||
name = (String) properties.get (_TRANSPORT_PROPERTY);
|
||||
if (name == null)
|
||||
throw new TransportException ("no transport specified");
|
||||
|
||||
for (int i = 0; i < _transportMethods.length; ++i)
|
||||
{
|
||||
if (_transportMethods[i].name.equals (name))
|
||||
{
|
||||
try
|
||||
{
|
||||
ITransport t;
|
||||
t = (ITransport) _transportMethods[i].clazz.newInstance ();
|
||||
t.configure (properties);
|
||||
return t;
|
||||
}
|
||||
catch (TransportException te)
|
||||
{
|
||||
throw te;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new TransportException (e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new TransportException ("transport \"" + name + "\" not found");
|
||||
}
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/* JdwpString.java -- utility class to read and write jdwp strings
|
||||
Copyright (C) 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., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 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 gnu.classpath.jdwp.util;
|
||||
|
||||
import gnu.classpath.jdwp.exception.JdwpInternalErrorException;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* A class to compute the JDWP representation of Strings.
|
||||
*
|
||||
* @author Aaron Luchko <aluchko@redhat.com>
|
||||
*/
|
||||
public class JdwpString
|
||||
{
|
||||
|
||||
/**
|
||||
* Write this String to the outStream as a string understood by jdwp.
|
||||
*
|
||||
* @param os write the String here
|
||||
* @param string the String to write
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void writeString(DataOutputStream os, String string)
|
||||
throws IOException
|
||||
{
|
||||
// Get the bytes of the string as a string in UTF-8
|
||||
byte[] strBytes = string.getBytes("UTF-8");
|
||||
os.writeInt(strBytes.length);
|
||||
os.write(strBytes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a jdwp style string from the ByteBuffer.
|
||||
*
|
||||
* @param bb contains the string
|
||||
* @return the String that was read
|
||||
* @throws JdwpInternalErrorException bb didn't contain a value UTF-8 string
|
||||
*/
|
||||
public static String readString(ByteBuffer bb)
|
||||
throws JdwpInternalErrorException
|
||||
{
|
||||
int length = bb.getInt();
|
||||
byte[] strBytes = new byte[length];
|
||||
bb.get(strBytes);
|
||||
try
|
||||
{
|
||||
return new String(strBytes, "UTF-8");
|
||||
}
|
||||
catch (UnsupportedEncodingException ex)
|
||||
{
|
||||
// Any string from the VM should be in UTF-8 so an encoding error
|
||||
// shouldn't be possible
|
||||
throw new JdwpInternalErrorException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,149 +0,0 @@
|
||||
/* Signature.java -- utility class to compute class and method signatures
|
||||
Copyright (C) 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
|
||||
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 gnu.classpath.jdwp.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* A class to compute class and method signatures.
|
||||
*
|
||||
* @author Tom Tromey (tromey@redhat.com)
|
||||
* @author Keith Seitz (keiths@redhat.com)
|
||||
*/
|
||||
public class Signature
|
||||
{
|
||||
/**
|
||||
* Computes the class signature, i.e., java.lang.String.class
|
||||
* returns "Ljava/lang/String;".
|
||||
*
|
||||
* @param theClass the class for which to compute the signature
|
||||
* @return the class's type signature
|
||||
*/
|
||||
public static String computeClassSignature (Class theClass)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ();
|
||||
_addToSignature (sb, theClass);
|
||||
return sb.toString ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the field signature which is just the class signature of the
|
||||
* field's type, ie a Field of type java.lang.String this will return
|
||||
* "Ljava/lang/String;".
|
||||
*
|
||||
* @param field the field for which to compute the signature
|
||||
* @return the field's type signature
|
||||
*/
|
||||
public static String computeFieldSignature (Field field)
|
||||
{
|
||||
return computeClassSignature (field.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the method signature, i.e., java.lang.String.split (String, int)
|
||||
* returns "(Ljava/lang/String;I)[Ljava/lang/String;"
|
||||
*
|
||||
* @param method the method for which to compute the signature
|
||||
* @return the method's type signature
|
||||
*/
|
||||
public static String computeMethodSignature (Method method)
|
||||
{
|
||||
return _computeSignature (method.getReturnType (),
|
||||
method.getParameterTypes ());
|
||||
}
|
||||
|
||||
private static String _computeSignature (Class returnType,
|
||||
Class[] paramTypes)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer ("(");
|
||||
if (paramTypes != null)
|
||||
{
|
||||
for (int i = 0; i < paramTypes.length; ++i)
|
||||
_addToSignature (sb, paramTypes[i]);
|
||||
}
|
||||
sb.append (")");
|
||||
_addToSignature (sb, returnType);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static void _addToSignature (StringBuffer sb, Class k)
|
||||
{
|
||||
// For some reason there's no easy way to get the signature of a
|
||||
// class.
|
||||
if (k.isPrimitive ())
|
||||
{
|
||||
if (k == void.class)
|
||||
sb.append('V');
|
||||
else if (k == boolean.class)
|
||||
sb.append('Z');
|
||||
else if (k == byte.class)
|
||||
sb.append('B');
|
||||
else if (k == char.class)
|
||||
sb.append('C');
|
||||
else if (k == short.class)
|
||||
sb.append('S');
|
||||
else if (k == int.class)
|
||||
sb.append('I');
|
||||
else if (k == float.class)
|
||||
sb.append('F');
|
||||
else if (k == double.class)
|
||||
sb.append('D');
|
||||
else if (k == long.class)
|
||||
sb.append('J');
|
||||
return;
|
||||
}
|
||||
|
||||
String name = k.getName ();
|
||||
int len = name.length ();
|
||||
sb.ensureCapacity (len);
|
||||
if (! k.isArray ())
|
||||
sb.append('L');
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
char c = name.charAt (i);
|
||||
if (c == '.')
|
||||
c = '/';
|
||||
sb.append (c);
|
||||
}
|
||||
if (! k.isArray ())
|
||||
sb.append(';');
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/* 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 gnu.java.awt;
|
||||
|
||||
/**
|
||||
* Simple transparent utility class that can be used to perform bit
|
||||
* mask extent calculations.
|
||||
*/
|
||||
public final class BitMaskExtent
|
||||
{
|
||||
/** The number of the least significant bit of the bit mask extent. */
|
||||
public byte leastSignificantBit;
|
||||
|
||||
/** The number of bits in the bit mask extent. */
|
||||
public byte bitWidth;
|
||||
|
||||
/**
|
||||
* Set the bit mask. This will calculate and set the leastSignificantBit
|
||||
* and bitWidth fields.
|
||||
*
|
||||
* @see #leastSignificantBit
|
||||
* @see #bitWidth
|
||||
*/
|
||||
public void setMask(long mask)
|
||||
{
|
||||
leastSignificantBit = 0;
|
||||
bitWidth = 0;
|
||||
if (mask == 0) return;
|
||||
long shiftMask = mask;
|
||||
for (; (shiftMask&1) == 0; shiftMask >>>=1) leastSignificantBit++;
|
||||
for (; (shiftMask&1) != 0; shiftMask >>>=1) bitWidth++;
|
||||
|
||||
if (shiftMask != 0)
|
||||
throw new IllegalArgumentException("mask must be continuous");
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the bit mask based on the values of the
|
||||
* leastSignificantBit and bitWidth fields.
|
||||
*/
|
||||
public long toMask()
|
||||
{
|
||||
return ((1<<bitWidth)-1) << leastSignificantBit;
|
||||
}
|
||||
}
|
||||
@@ -1,295 +0,0 @@
|
||||
/* BitwiseXORComposite.java -- Composite for emulating old-style XOR.
|
||||
Copyright (C) 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 gnu.java.awt;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Composite;
|
||||
import java.awt.CompositeContext;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
|
||||
/**
|
||||
* A composite for emulating traditional bitwise XOR of pixel values.
|
||||
* Please note that this composite does <i>not</i> implement the Porter-Duff
|
||||
* XOR operator, but an exclusive or of overlapping subpixel regions.
|
||||
*
|
||||
* <p><img src="doc-files/BitwiseXORComposite-1.png" width="545"
|
||||
* height="138" alt="A screen shot of BitwiseXORComposite in action"
|
||||
* />
|
||||
*
|
||||
* <p>The above screen shot shows the result of applying six different
|
||||
* BitwiseXORComposites. They were constructed with the colors colors
|
||||
* white, blue, black, orange, green, and brown, respectively. Each
|
||||
* composite was used to paint a fully white rectangle on top of the
|
||||
* blue bar in the background.
|
||||
*
|
||||
* <p>The purpose of this composite is to support the {@link
|
||||
* Graphics#setXORMode(Color)} method in composite-aware graphics
|
||||
* implementations. Applications typically would use
|
||||
* <code>setXORMode</code> for drawing “highlights” such
|
||||
* as text selections or cursors by inverting colors temporarily and
|
||||
* then inverting them back.
|
||||
*
|
||||
* <p>A concrete <code>Graphics</code> implementation may contain
|
||||
* the following code:
|
||||
*
|
||||
* <p><pre> public void setXORMode(Color xorColor)
|
||||
* {
|
||||
* setComposite(new gnu.java.awt.BitwiseXORComposite(xorColor));
|
||||
* }
|
||||
*
|
||||
* public void setPaintMode()
|
||||
* {
|
||||
* setComposite(java.awt.AlphaComposite.SrcOver);
|
||||
* }</pre>
|
||||
*
|
||||
* @author Graydon Hoare (graydon@redhat.com)
|
||||
* @author Sascha Brawer (brawer@dandelis.ch)
|
||||
*/
|
||||
public class BitwiseXORComposite
|
||||
implements Composite
|
||||
{
|
||||
/**
|
||||
* The color whose RGB value is xor-ed with the values of each
|
||||
* pixel.
|
||||
*/
|
||||
protected Color xorColor;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new composite for xor-ing the pixel value.
|
||||
*
|
||||
* @param xorColor the color whose pixel value will be bitwise
|
||||
* xor-ed with the source and destination pixels.
|
||||
*/
|
||||
public BitwiseXORComposite(Color xorColor)
|
||||
{
|
||||
this.xorColor = xorColor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a context object for performing the compositing
|
||||
* operation. Several contexts may co-exist for one composite; each
|
||||
* context may simultaneously be called from concurrent threads.
|
||||
*
|
||||
* @param srcColorModel the color model of the source.
|
||||
* @param dstColorModel the color model of the destination.
|
||||
* @param hints hints for choosing between rendering alternatives.
|
||||
*/
|
||||
public CompositeContext createContext(ColorModel srcColorModel,
|
||||
ColorModel dstColorModel,
|
||||
RenderingHints hints)
|
||||
{
|
||||
if (IntContext.isSupported(srcColorModel, dstColorModel, hints))
|
||||
return new IntContext(srcColorModel, xorColor);
|
||||
|
||||
return new GeneralContext(srcColorModel, dstColorModel, xorColor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A fallback CompositeContext that performs bitwise XOR of pixel
|
||||
* values with the pixel value of the specified <code>xorColor</code>.
|
||||
*
|
||||
* <p>Applying this CompositeContext on a 1024x1024 BufferedImage of
|
||||
* <code>TYPE_INT_RGB</code> took 611 ms on a lightly loaded 2.4 GHz
|
||||
* Intel Pentium 4 CPU running Sun J2SE 1.4.1_01 on GNU/Linux
|
||||
* 2.4.20. The timing is the average of ten runs on the same
|
||||
* BufferedImage. Since the measurements were taken with {@link
|
||||
* System#currentTimeMillis()}, they are rather inaccurate.
|
||||
*
|
||||
* @author Graydon Hoare (graydon@redhat.com)
|
||||
*/
|
||||
private static class GeneralContext
|
||||
implements CompositeContext
|
||||
{
|
||||
ColorModel srcColorModel;
|
||||
ColorModel dstColorModel;
|
||||
Color xorColor;
|
||||
|
||||
public GeneralContext(ColorModel srcColorModel,
|
||||
ColorModel dstColorModel,
|
||||
Color xorColor)
|
||||
{
|
||||
this.srcColorModel = srcColorModel;
|
||||
this.dstColorModel = dstColorModel;
|
||||
this.xorColor = xorColor;
|
||||
}
|
||||
|
||||
|
||||
public void compose(Raster src, Raster dstIn, WritableRaster dstOut)
|
||||
{
|
||||
Rectangle srcRect = src.getBounds();
|
||||
Rectangle dstInRect = dstIn.getBounds();
|
||||
Rectangle dstOutRect = dstOut.getBounds();
|
||||
|
||||
int xp = xorColor.getRGB();
|
||||
int w = Math.min(Math.min(srcRect.width, dstOutRect.width),
|
||||
dstInRect.width);
|
||||
int h = Math.min(Math.min(srcRect.height, dstOutRect.height),
|
||||
dstInRect.height);
|
||||
|
||||
Object srcPix = null, dstPix = null, rpPix = null;
|
||||
|
||||
// Re-using the rpPix object saved 1-2% of execution time in
|
||||
// the 1024x1024 pixel benchmark.
|
||||
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
srcPix = src.getDataElements(x + srcRect.x, y + srcRect.y, srcPix);
|
||||
dstPix = dstIn.getDataElements(x + dstInRect.x, y + dstInRect.y,
|
||||
dstPix);
|
||||
int sp = srcColorModel.getRGB(srcPix);
|
||||
int dp = dstColorModel.getRGB(dstPix);
|
||||
int rp = sp ^ xp ^ dp;
|
||||
dstOut.setDataElements(x + dstOutRect.x, y + dstOutRect.y,
|
||||
dstColorModel.getDataElements(rp, rpPix));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Disposes any cached resources. The default implementation does
|
||||
* nothing because no resources are cached.
|
||||
*/
|
||||
public void dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* An optimized CompositeContext that performs bitwise XOR of
|
||||
* <code>int</code> pixel values with the pixel value of a specified
|
||||
* <code>xorColor</code>. This CompositeContext working only for
|
||||
* rasters whose transfer format is {@link DataBuffer#TYPE_INT}.
|
||||
*
|
||||
* <p>Applying this CompositeContext on a 1024x1024 BufferedImage of
|
||||
* <code>TYPE_INT_RGB</code> took 69 ms on a lightly loaded 2.4 GHz
|
||||
* Intel Pentium 4 CPU running Sun J2SE 1.4.1_01 on GNU/Linux
|
||||
* 2.4.20. The timing is the average of ten runs on the same
|
||||
* BufferedImage. Since the measurements were taken with {@link
|
||||
* System#currentTimeMillis()}, they are rather inaccurate.
|
||||
*
|
||||
* @author Sascha Brawer (brawer@dandelis.ch)
|
||||
*/
|
||||
private static class IntContext
|
||||
extends GeneralContext
|
||||
{
|
||||
public IntContext(ColorModel colorModel, Color xorColor)
|
||||
{
|
||||
super(colorModel, colorModel, xorColor);
|
||||
}
|
||||
|
||||
|
||||
public void compose(Raster src, Raster dstIn,
|
||||
WritableRaster dstOut)
|
||||
{
|
||||
int aX, bX, dstX, aY, bY, dstY, width, height;
|
||||
int xorPixel;
|
||||
int[] srcLine, dstLine;
|
||||
|
||||
aX = src.getMinX();
|
||||
aY = src.getMinY();
|
||||
bX = dstIn.getMinX();
|
||||
bY = dstIn.getMinY();
|
||||
dstX = dstOut.getMinX();
|
||||
dstY = dstOut.getMinY();
|
||||
width = Math.min(Math.min(src.getWidth(), dstIn.getWidth()),
|
||||
dstOut.getWidth());
|
||||
height = Math.min(Math.min(src.getHeight(), dstIn.getHeight()),
|
||||
dstOut.getHeight());
|
||||
if ((width < 1) || (height < 1))
|
||||
return;
|
||||
|
||||
srcLine = new int[width];
|
||||
dstLine = new int[width];
|
||||
|
||||
/* We need an int[] array with at least one element here;
|
||||
* srcLine is as good as any other.
|
||||
*/
|
||||
srcColorModel.getDataElements(this.xorColor.getRGB(), srcLine);
|
||||
xorPixel = srcLine[0];
|
||||
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
src.getDataElements(aX, y + aY, width, 1, srcLine);
|
||||
dstIn.getDataElements(bX, y + bY, width, 1, dstLine);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
dstLine[x] ^= srcLine[x] ^ xorPixel;
|
||||
|
||||
dstOut.setDataElements(dstX, y + dstY, width, 1, dstLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines whether an instance of this CompositeContext would
|
||||
* be able to process the specified color models.
|
||||
*/
|
||||
public static boolean isSupported(ColorModel srcColorModel,
|
||||
ColorModel dstColorModel,
|
||||
RenderingHints hints)
|
||||
{
|
||||
// FIXME: It would be good if someone could review these checks.
|
||||
// They probably need to be more restrictive.
|
||||
|
||||
int transferType;
|
||||
|
||||
transferType = srcColorModel.getTransferType();
|
||||
if (transferType != dstColorModel.getTransferType())
|
||||
return false;
|
||||
|
||||
if (transferType != DataBuffer.TYPE_INT)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,243 +0,0 @@
|
||||
/* Buffers.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 gnu.java.awt;
|
||||
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.DataBufferByte;
|
||||
import java.awt.image.DataBufferDouble;
|
||||
import java.awt.image.DataBufferFloat;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.DataBufferShort;
|
||||
import java.awt.image.DataBufferUShort;
|
||||
|
||||
/**
|
||||
* Utility class for creating and accessing data buffers of arbitrary
|
||||
* data types.
|
||||
*/
|
||||
public final class Buffers
|
||||
{
|
||||
/**
|
||||
* Create a data buffer of a particular type.
|
||||
*
|
||||
* @param dataType the desired data type of the buffer.
|
||||
* @param data an array containing data, or null
|
||||
* @param size the size of the data buffer bank
|
||||
*/
|
||||
public static DataBuffer createBuffer(int dataType, Object data,
|
||||
int size)
|
||||
{
|
||||
if (data == null) return createBuffer(dataType, size, 1);
|
||||
|
||||
return createBufferFromData(dataType, data, size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a data buffer of a particular type.
|
||||
*
|
||||
* @param dataType the desired data type of the buffer.
|
||||
* @param size the size of the data buffer bank
|
||||
*/
|
||||
public static DataBuffer createBuffer(int dataType, int size) {
|
||||
return createBuffer(dataType, size, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a data buffer of a particular type.
|
||||
*
|
||||
* @param dataType the desired data type of the buffer.
|
||||
* @param size the size of the data buffer bank
|
||||
* @param numBanks the number of banks the buffer should have
|
||||
*/
|
||||
public static DataBuffer createBuffer(int dataType, int size, int numBanks)
|
||||
{
|
||||
switch (dataType)
|
||||
{
|
||||
case DataBuffer.TYPE_BYTE:
|
||||
return new DataBufferByte(size, numBanks);
|
||||
case DataBuffer.TYPE_SHORT:
|
||||
return new DataBufferShort(size, numBanks);
|
||||
case DataBuffer.TYPE_USHORT:
|
||||
return new DataBufferUShort(size, numBanks);
|
||||
case DataBuffer.TYPE_INT:
|
||||
return new DataBufferInt(size, numBanks);
|
||||
case DataBuffer.TYPE_FLOAT:
|
||||
return new DataBufferFloat(size, numBanks);
|
||||
case DataBuffer.TYPE_DOUBLE:
|
||||
return new DataBufferDouble(size, numBanks);
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a data buffer of a particular type.
|
||||
*
|
||||
* @param dataType the desired data type of the buffer
|
||||
* @param data an array containing the data
|
||||
* @param size the size of the data buffer bank
|
||||
*/
|
||||
public static DataBuffer createBufferFromData(int dataType, Object data,
|
||||
int size)
|
||||
{
|
||||
switch (dataType)
|
||||
{
|
||||
case DataBuffer.TYPE_BYTE:
|
||||
return new DataBufferByte((byte[]) data, size);
|
||||
case DataBuffer.TYPE_SHORT:
|
||||
return new DataBufferShort((short[]) data, size);
|
||||
case DataBuffer.TYPE_USHORT:
|
||||
return new DataBufferUShort((short[]) data, size);
|
||||
case DataBuffer.TYPE_INT:
|
||||
return new DataBufferInt((int[]) data, size);
|
||||
case DataBuffer.TYPE_FLOAT:
|
||||
return new DataBufferFloat((float[]) data, size);
|
||||
case DataBuffer.TYPE_DOUBLE:
|
||||
return new DataBufferDouble((double[]) data, size);
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data array of a data buffer, regardless of the data
|
||||
* type.
|
||||
*
|
||||
* @return an array of primitive values. The actual array type
|
||||
* depends on the data type of the buffer.
|
||||
*/
|
||||
public static Object getData(DataBuffer buffer)
|
||||
{
|
||||
if (buffer instanceof DataBufferByte)
|
||||
return ((DataBufferByte) buffer).getData();
|
||||
|
||||
if (buffer instanceof DataBufferShort)
|
||||
return ((DataBufferShort) buffer).getData();
|
||||
|
||||
if (buffer instanceof DataBufferUShort)
|
||||
return ((DataBufferUShort) buffer).getData();
|
||||
|
||||
if (buffer instanceof DataBufferInt)
|
||||
return ((DataBufferInt) buffer).getData();
|
||||
|
||||
if (buffer instanceof DataBufferFloat)
|
||||
return ((DataBufferFloat) buffer).getData();
|
||||
|
||||
if (buffer instanceof DataBufferDouble)
|
||||
return ((DataBufferDouble) buffer).getData();
|
||||
|
||||
throw new ClassCastException("Unknown data buffer type");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy data from array contained in data buffer, much like
|
||||
* System.arraycopy. Create a suitable destination array if the
|
||||
* given destination array is null.
|
||||
*/
|
||||
public static Object getData(DataBuffer src, int srcOffset,
|
||||
Object dest, int destOffset,
|
||||
int length)
|
||||
{
|
||||
Object from;
|
||||
if (src instanceof DataBufferByte)
|
||||
{
|
||||
from = ((DataBufferByte) src).getData();
|
||||
if (dest == null) dest = new byte[length+destOffset];
|
||||
}
|
||||
else if (src instanceof DataBufferShort)
|
||||
{
|
||||
from = ((DataBufferShort) src).getData();
|
||||
if (dest == null) dest = new short[length+destOffset];
|
||||
}
|
||||
else if (src instanceof DataBufferUShort)
|
||||
{
|
||||
from = ((DataBufferUShort) src).getData();
|
||||
if (dest == null) dest = new short[length+destOffset];
|
||||
}
|
||||
else if (src instanceof DataBufferInt)
|
||||
{
|
||||
from = ((DataBufferInt) src).getData();
|
||||
if (dest == null) dest = new int[length+destOffset];
|
||||
}
|
||||
else if (src instanceof DataBufferFloat)
|
||||
{
|
||||
from = ((DataBufferFloat) src).getData();
|
||||
if (dest == null) dest = new float[length+destOffset];
|
||||
}
|
||||
else if (src instanceof DataBufferDouble)
|
||||
{
|
||||
from = ((DataBufferDouble) src).getData();
|
||||
if (dest == null) dest = new double[length+destOffset];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ClassCastException("Unknown data buffer type");
|
||||
}
|
||||
|
||||
System.arraycopy(from, srcOffset, dest, destOffset, length);
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bits the width of a data element measured in bits
|
||||
*
|
||||
* @return the smallest data type that can store data elements of
|
||||
* the given number of bits, without any truncation.
|
||||
*/
|
||||
public static int smallestAppropriateTransferType(int bits)
|
||||
{
|
||||
if (bits <= 8)
|
||||
{
|
||||
return DataBuffer.TYPE_BYTE;
|
||||
}
|
||||
else if (bits <= 16)
|
||||
{
|
||||
return DataBuffer.TYPE_USHORT;
|
||||
}
|
||||
else if (bits <= 32)
|
||||
{
|
||||
return DataBuffer.TYPE_INT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DataBuffer.TYPE_UNDEFINED;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,369 +0,0 @@
|
||||
/* ClasspathToolkit.java -- Abstract superclass for Classpath toolkits.
|
||||
Copyright (C) 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 gnu.java.awt;
|
||||
|
||||
import gnu.java.awt.peer.ClasspathFontPeer;
|
||||
import gnu.java.awt.peer.ClasspathTextLayoutPeer;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.peer.RobotPeer;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.text.AttributedString;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
|
||||
/**
|
||||
* An abstract superclass for Classpath toolkits.
|
||||
*
|
||||
* <p>There exist some parts of AWT and Java2D that are specific to
|
||||
* the underlying platform, but for which the {@link Toolkit} class
|
||||
* does not provide suitable abstractions. Examples include some
|
||||
* methods of {@link Font} or {@link GraphicsEnvironment}. Those
|
||||
* methods use ClasspathToolkit as a central place for obtaining
|
||||
* platform-specific functionality.
|
||||
*
|
||||
* <p>In addition, ClasspathToolkit implements some abstract methods
|
||||
* of {@link java.awt.Toolkit} that are not really platform-specific,
|
||||
* such as the maintenance of a cache of loaded images.
|
||||
*
|
||||
* <p><b>Thread Safety:</b> The methods of this class may safely be
|
||||
* called without external synchronization. This also hold for any
|
||||
* inherited {@link Toolkit} methods. Subclasses are responsible for
|
||||
* the necessary synchronization.
|
||||
*
|
||||
* @author Sascha Brawer (brawer@dandelis.ch)
|
||||
*/
|
||||
public abstract class ClasspathToolkit
|
||||
extends Toolkit
|
||||
{
|
||||
/**
|
||||
* A map from URLs to previously loaded images, used by {@link
|
||||
* #getImage(java.net.URL)}. For images that were loaded via a path
|
||||
* to an image file, the map contains a key with a file URL.
|
||||
*/
|
||||
private HashMap imageCache;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a shared instance of the local, platform-specific
|
||||
* graphics environment.
|
||||
*
|
||||
* <p>This method is specific to GNU Classpath. It gets called by
|
||||
* the Classpath implementation of {@link
|
||||
* GraphicsEnvironment.getLocalGraphcisEnvironment()}.
|
||||
*/
|
||||
public abstract GraphicsEnvironment getLocalGraphicsEnvironment();
|
||||
|
||||
|
||||
/**
|
||||
* Determines the current size of the default, primary screen.
|
||||
*
|
||||
* @throws HeadlessException if the local graphics environment is
|
||||
* headless, which means that no screen is attached and no user
|
||||
* interaction is allowed.
|
||||
*/
|
||||
public Dimension getScreenSize()
|
||||
{
|
||||
DisplayMode mode;
|
||||
|
||||
// getDefaultScreenDevice throws HeadlessException if the
|
||||
// local graphics environment is headless.
|
||||
mode = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDisplayMode();
|
||||
|
||||
return new Dimension(mode.getWidth(), mode.getHeight());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determines the current color model of the default, primary
|
||||
* screen.
|
||||
*
|
||||
* @see GraphicsEnvironment#getDefaultScreenDevice()
|
||||
* @see java.awt.GraphicsDevice#getDefaultConfiguration()
|
||||
* @see java.awt.GraphicsConfiguration#getColorModel()
|
||||
*
|
||||
* @throws HeadlessException if the local graphics environment is
|
||||
* headless, which means that no screen is attached and no user
|
||||
* interaction is allowed.
|
||||
*/
|
||||
public ColorModel getColorModel()
|
||||
{
|
||||
// getDefaultScreenDevice throws HeadlessException if the
|
||||
// local graphics environment is headless.
|
||||
return GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDefaultConfiguration()
|
||||
.getColorModel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the metrics for rendering a font on the screen.
|
||||
*
|
||||
* @param font the font whose metrics are requested.
|
||||
*/
|
||||
public FontMetrics getFontMetrics(Font font)
|
||||
{
|
||||
return ((ClasspathFontPeer) font.getPeer ()).getFontMetrics (font);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Acquires an appropriate {@link ClasspathFontPeer}, for use in
|
||||
* classpath's implementation of {@link java.awt.Font}.
|
||||
*
|
||||
* @param name The logical name of the font. This may be either a face
|
||||
* name or a logical font name, or may even be null. A default
|
||||
* implementation of name decoding is provided in
|
||||
* {@link ClasspathFontPeer}, but may be overridden in other toolkits.
|
||||
*
|
||||
* @param attrs Any extra {@link java.awt.font.TextAttribute} attributes
|
||||
* this font peer should have, such as size, weight, family name, or
|
||||
* transformation.
|
||||
*/
|
||||
public abstract ClasspathFontPeer getClasspathFontPeer (String name, Map attrs);
|
||||
|
||||
public abstract ClasspathTextLayoutPeer
|
||||
getClasspathTextLayoutPeer (AttributedString str, FontRenderContext frc);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a {@link Font}, in a platform-specific manner.
|
||||
*
|
||||
* The default implementation simply constructs a {@link Font}, but some
|
||||
* toolkits may wish to override this, to return {@link Font} subclasses which
|
||||
* implement {@link java.awt.font.OpenType} or
|
||||
* {@link java.awt.font.MultipleMaster}.
|
||||
*/
|
||||
public Font getFont (String name, Map attrs)
|
||||
{
|
||||
return new Font (name, attrs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a font, reading the glyph definitions from a stream.
|
||||
*
|
||||
* <p>This method provides the platform-specific implementation for
|
||||
* the static factory method {@link Font#createFont(int,
|
||||
* java.io.InputStream)}.
|
||||
*
|
||||
* @param format the format of the font data, such as {@link
|
||||
* Font#TRUETYPE_FONT}. An implementation may ignore this argument
|
||||
* if it is able to automatically recognize the font format from the
|
||||
* provided data.
|
||||
*
|
||||
* @param stream an input stream from where the font data is read
|
||||
* in. The stream will be advanced to the position after the font
|
||||
* data, but not closed.
|
||||
*
|
||||
* @throws IllegalArgumentException if <code>format</code> is
|
||||
* not supported.
|
||||
*
|
||||
* @throws FontFormatException if <code>stream</code> does not
|
||||
* contain data in the expected format, or if required tables are
|
||||
* missing from a font.
|
||||
*
|
||||
* @throws IOException if a problem occurs while reading in the
|
||||
* contents of <code>stream</code>.
|
||||
*/
|
||||
public abstract Font createFont(int format, InputStream stream);
|
||||
|
||||
|
||||
/**
|
||||
* Returns an image from the specified file, which must be in a
|
||||
* recognized format. The set of recognized image formats may vary
|
||||
* from toolkit to toolkit.
|
||||
*
|
||||
* <p>This method maintains a cache for images. If an image has been
|
||||
* loaded from the same path before, the cached copy will be
|
||||
* returned. The implementation may hold cached copies for an
|
||||
* indefinite time, which can consume substantial resources with
|
||||
* large images. Users are therefore advised to use {@link
|
||||
* #createImage(java.lang.String)} instead.
|
||||
*
|
||||
* <p>The default implementation creates a file URL for the
|
||||
* specified path and invokes {@link #getImage(URL)}.
|
||||
*
|
||||
* @param path A path to the image file.
|
||||
*
|
||||
* @return IllegalArgumentException if <code>path</code> does not
|
||||
* designate a valid path.
|
||||
*/
|
||||
public Image getImage(String path)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getImage(new File(path).toURL());
|
||||
}
|
||||
catch (MalformedURLException muex)
|
||||
{
|
||||
throw (IllegalArgumentException) new IllegalArgumentException(path)
|
||||
.initCause(muex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads an image from the specified URL. The image data must be in
|
||||
* a recognized format. The set of recognized image formats may vary
|
||||
* from toolkit to toolkit.
|
||||
*
|
||||
* <p>This method maintains a cache for images. If an image has been
|
||||
* loaded from the same URL before, the cached copy will be
|
||||
* returned. The implementation may hold cached copies for an
|
||||
* indefinite time, which can consume substantial resources with
|
||||
* large images. Users are therefore advised to use {@link
|
||||
* #createImage(java.net.URL)} instead.
|
||||
*
|
||||
* @param url the URL from where the image is read.
|
||||
*/
|
||||
public Image getImage(URL url)
|
||||
{
|
||||
Image result;
|
||||
|
||||
synchronized (this)
|
||||
{
|
||||
// Many applications never call getImage. Therefore, we lazily
|
||||
// create the image cache when it is actually needed.
|
||||
if (imageCache == null)
|
||||
imageCache = new HashMap();
|
||||
else
|
||||
{
|
||||
result = (Image) imageCache.get(url);
|
||||
if (result != null)
|
||||
return result;
|
||||
}
|
||||
|
||||
// The createImage(URL) method, which is specified by
|
||||
// java.awt.Toolkit, is not implemented by this abstract class
|
||||
// because it is platform-dependent. Once Classpath has support
|
||||
// for the javax.imageio package, it might be worth considering
|
||||
// that toolkits provide native stream readers. Then, the class
|
||||
// ClasspathToolkit could provide a general implementation that
|
||||
// delegates the image format parsing to javax.imageio.
|
||||
result = createImage(url);
|
||||
|
||||
// It is not clear whether it would be a good idea to use weak
|
||||
// references here. The advantage would be reduced memory
|
||||
// consumption, since loaded images would not be kept
|
||||
// forever. But on VMs that frequently perform garbage
|
||||
// collection (which includes VMs with a parallel or incremental
|
||||
// collector), the image might frequently need to be re-loaded,
|
||||
// possibly over a slow network connection.
|
||||
imageCache.put(url, result);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns an image from the specified file, which must be in a
|
||||
* recognized format. The set of recognized image formats may vary
|
||||
* from toolkit to toolkit.
|
||||
*
|
||||
* <p>A new image is created every time this method gets called,
|
||||
* even if the same path has been passed before.
|
||||
*
|
||||
* <p>The default implementation creates a file URL for the
|
||||
* specified path and invokes {@link #createImage(URL)}.
|
||||
*
|
||||
* @param path A path to the file to be read in.
|
||||
*/
|
||||
public Image createImage(String path)
|
||||
{
|
||||
try
|
||||
{
|
||||
// The abstract method createImage(URL) is defined by
|
||||
// java.awt.Toolkit, but intentionally not implemented by
|
||||
// ClasspathToolkit because it is platform specific.
|
||||
return createImage(new File(path).toURL());
|
||||
}
|
||||
catch (MalformedURLException muex)
|
||||
{
|
||||
throw (IllegalArgumentException) new IllegalArgumentException(path)
|
||||
.initCause(muex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an ImageProducer from the specified URL. The image is assumed
|
||||
* to be in a recognised format. If the toolkit does not implement the
|
||||
* image format or the image format is not recognised, null is returned.
|
||||
* This default implementation is overriden by the Toolkit implementations.
|
||||
*
|
||||
* @param url URL to read image data from.
|
||||
*/
|
||||
public ImageProducer createImageProducer(URL url)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract RobotPeer createRobot (GraphicsDevice screen)
|
||||
throws AWTException;
|
||||
|
||||
/**
|
||||
* Used to register ImageIO SPIs provided by the toolkit.
|
||||
*/
|
||||
|
||||
public void registerImageIOSpis(IIORegistry reg)
|
||||
{
|
||||
}
|
||||
|
||||
public abstract boolean nativeQueueEmpty();
|
||||
public abstract void wakeNativeQueue();
|
||||
public abstract void iterateNativeQueue(EventQueue locked, boolean block);
|
||||
}
|
||||
@@ -1,156 +0,0 @@
|
||||
/* 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 gnu.java.awt;
|
||||
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.ComponentSampleModel;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.RasterOp;
|
||||
import java.awt.image.WritableRaster;
|
||||
|
||||
/**
|
||||
* This raster copy operation assumes that both source and destination
|
||||
* sample models are tightly pixel packed and contain the same number
|
||||
* of bands.
|
||||
*
|
||||
* @throws java.lang.ClassCastException if the sample models of the
|
||||
* rasters are not of type ComponentSampleModel.
|
||||
*
|
||||
* @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
|
||||
*/
|
||||
public class ComponentDataBlitOp implements RasterOp
|
||||
{
|
||||
public static final ComponentDataBlitOp INSTANCE = new ComponentDataBlitOp();
|
||||
|
||||
public WritableRaster filter(Raster src, WritableRaster dest)
|
||||
{
|
||||
if (dest == null)
|
||||
dest = createCompatibleDestRaster(src);
|
||||
|
||||
DataBuffer srcDB = src.getDataBuffer();
|
||||
DataBuffer destDB = dest.getDataBuffer();
|
||||
|
||||
ComponentSampleModel srcSM = (ComponentSampleModel) src.getSampleModel();
|
||||
ComponentSampleModel destSM = (ComponentSampleModel) dest.getSampleModel();
|
||||
|
||||
|
||||
// Calculate offset to data in the underlying arrays:
|
||||
|
||||
int srcScanlineStride = srcSM.getScanlineStride();
|
||||
int destScanlineStride = destSM.getScanlineStride();
|
||||
int srcX = src.getMinX() - src.getSampleModelTranslateX();
|
||||
int srcY = src.getMinY() - src.getSampleModelTranslateY();
|
||||
int destX = dest.getMinX() - dest.getSampleModelTranslateX();
|
||||
int destY = dest.getMinY() - dest.getSampleModelTranslateY();
|
||||
|
||||
int numBands = srcSM.getNumBands();
|
||||
|
||||
/* We can't use getOffset(x, y) from the sample model since we
|
||||
don't want the band offset added in. */
|
||||
|
||||
int srcOffset =
|
||||
numBands*srcX + srcScanlineStride*srcY + // from sample model
|
||||
srcDB.getOffset(); // from data buffer
|
||||
|
||||
int destOffset =
|
||||
numBands*destX + destScanlineStride*destY + // from sample model
|
||||
destDB.getOffset(); // from data buffer
|
||||
|
||||
// Determine how much, and how many times to blit.
|
||||
|
||||
int rowSize = src.getWidth()*numBands;
|
||||
int h = src.getHeight();
|
||||
|
||||
if ((rowSize == srcScanlineStride) &&
|
||||
(rowSize == destScanlineStride))
|
||||
{
|
||||
// collapse scan line blits to one large blit.
|
||||
rowSize *= h;
|
||||
h = 1;
|
||||
}
|
||||
|
||||
|
||||
// Do blitting
|
||||
|
||||
Object srcArray = Buffers.getData(srcDB);
|
||||
Object destArray = Buffers.getData(destDB);
|
||||
|
||||
for (int yd = 0; yd<h; yd++)
|
||||
{
|
||||
System.arraycopy(srcArray, srcOffset,
|
||||
destArray, destOffset,
|
||||
rowSize);
|
||||
srcOffset += srcScanlineStride;
|
||||
destOffset += destScanlineStride;
|
||||
}
|
||||
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
public Rectangle2D getBounds2D(Raster src)
|
||||
{
|
||||
return src.getBounds();
|
||||
}
|
||||
|
||||
public WritableRaster createCompatibleDestRaster(Raster src) {
|
||||
|
||||
/* FIXME: Maybe we should explicitly create a raster with a
|
||||
tightly pixel packed sample model, rather than assuming
|
||||
that the createCompatibleWritableRaster() method in Raster
|
||||
will create one. */
|
||||
|
||||
return src.createCompatibleWritableRaster();
|
||||
}
|
||||
|
||||
public Point2D getPoint2D(Point2D srcPoint, Point2D destPoint)
|
||||
{
|
||||
if (destPoint == null)
|
||||
return (Point2D) srcPoint.clone();
|
||||
|
||||
destPoint.setLocation(srcPoint);
|
||||
return destPoint;
|
||||
}
|
||||
|
||||
public RenderingHints getRenderingHints()
|
||||
{
|
||||
throw new UnsupportedOperationException("not implemented");
|
||||
}
|
||||
}
|
||||
@@ -1,143 +0,0 @@
|
||||
/* EmbeddedWindow.java --
|
||||
Copyright (C) 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 gnu.java.awt;
|
||||
|
||||
import gnu.java.awt.peer.EmbeddedWindowPeer;
|
||||
import gnu.java.security.action.SetAccessibleAction;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Toolkit;
|
||||
import java.lang.reflect.Field;
|
||||
import java.security.AccessController;
|
||||
|
||||
/**
|
||||
* Represents an AWT window that can be embedded into another
|
||||
* application.
|
||||
*
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
*/
|
||||
public class EmbeddedWindow extends Frame
|
||||
{
|
||||
private long handle;
|
||||
|
||||
/**
|
||||
* Creates a window to be embedded into another application. The
|
||||
* window will only be embedded after its setHandle method has been
|
||||
* called.
|
||||
*/
|
||||
public EmbeddedWindow ()
|
||||
{
|
||||
super();
|
||||
this.handle = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a window to be embedded into another application.
|
||||
*
|
||||
* @param handle the native handle to the screen area where the AWT
|
||||
* window should be embedded
|
||||
*/
|
||||
public EmbeddedWindow (long handle)
|
||||
{
|
||||
super();
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the native peer for this embedded window.
|
||||
*/
|
||||
public void addNotify()
|
||||
{
|
||||
Toolkit tk = getToolkit();
|
||||
|
||||
if (! (tk instanceof EmbeddedWindowSupport))
|
||||
throw new UnsupportedOperationException
|
||||
("Embedded windows are not supported by the current peers: "
|
||||
+ tk.getClass());
|
||||
|
||||
// Circumvent the package-privateness of the AWT internal
|
||||
// java.awt.Component.peer member variable.
|
||||
try
|
||||
{
|
||||
Field peerField = Component.class.getDeclaredField("peer");
|
||||
AccessController.doPrivileged(new SetAccessibleAction(peerField));
|
||||
peerField.set(this, ((EmbeddedWindowSupport) tk).createEmbeddedWindow (this));
|
||||
}
|
||||
catch (IllegalAccessException e)
|
||||
{
|
||||
// This should never happen.
|
||||
}
|
||||
catch (NoSuchFieldException e)
|
||||
{
|
||||
// This should never happen.
|
||||
}
|
||||
|
||||
super.addNotify();
|
||||
}
|
||||
|
||||
/**
|
||||
* If the native peer for this embedded window has been created,
|
||||
* then setHandle will embed the window. If not, setHandle tells
|
||||
* us where to embed ourselves when our peer is created.
|
||||
*
|
||||
* @param handle the native handle to the screen area where the AWT
|
||||
* window should be embedded
|
||||
*/
|
||||
public void setHandle(long handle)
|
||||
{
|
||||
if (this.handle != 0)
|
||||
throw new RuntimeException ("EmbeddedWindow is already embedded");
|
||||
|
||||
this.handle = handle;
|
||||
if (getPeer() != null)
|
||||
((EmbeddedWindowPeer) getPeer()).embed (this.handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the native handle of the screen area where the window will
|
||||
* be embedded.
|
||||
*
|
||||
* @return The native handle that was passed to the constructor.
|
||||
*/
|
||||
public long getHandle()
|
||||
{
|
||||
return handle;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/* EmbeddedWindowSupport.java --
|
||||
Copyright (C) 2003 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 gnu.java.awt;
|
||||
|
||||
import gnu.java.awt.peer.EmbeddedWindowPeer;
|
||||
|
||||
/**
|
||||
* Declares a method for creating native embedded window peers.
|
||||
*
|
||||
* All classes inherited from java.awt.Toolkit that implement this
|
||||
* interface are assumed to support the creation of embedded window
|
||||
* peers. To create an embedded window, use
|
||||
* gnu.java.awt.EmbeddedWindow.
|
||||
*
|
||||
* @see gnu.java.awt.EmbeddedWindow
|
||||
* @see java.awt.Toolkit
|
||||
*
|
||||
* @author Michael Koch (konqueror@gmx.de)
|
||||
*/
|
||||
public interface EmbeddedWindowSupport
|
||||
{
|
||||
/**
|
||||
* Creates an embedded window peer, and associates it with an
|
||||
* EmbeddedWindow object.
|
||||
*
|
||||
* @param w The embedded window with which to associate a peer.
|
||||
*/
|
||||
EmbeddedWindowPeer createEmbeddedWindow (EmbeddedWindow w);
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/* EventModifier.java -- tool for converting modifier bits to 1.4 syle
|
||||
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 gnu.java.awt;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
|
||||
public class EventModifier
|
||||
{
|
||||
/** The mask for old events. */
|
||||
public static final int OLD_MASK = 0x3f;
|
||||
|
||||
/** The mask for new events. */
|
||||
public static final int NEW_MASK = 0x3fc0;
|
||||
|
||||
/**
|
||||
* Non-instantiable.
|
||||
*/
|
||||
private EventModifier()
|
||||
{
|
||||
throw new InternalError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the old style modifiers (0x3f) to the new style (0xffffffc0).
|
||||
*
|
||||
* @param mod the modifiers to convert
|
||||
* @return the adjusted modifiers
|
||||
*/
|
||||
public static int extend(int mod)
|
||||
{
|
||||
// Favor what we hope will be the common case.
|
||||
if ((mod & OLD_MASK) == 0)
|
||||
return mod;
|
||||
if ((mod & InputEvent.SHIFT_MASK) != 0)
|
||||
mod |= InputEvent.SHIFT_DOWN_MASK;
|
||||
if ((mod & InputEvent.CTRL_MASK) != 0)
|
||||
mod |= InputEvent.CTRL_DOWN_MASK;
|
||||
if ((mod & InputEvent.META_MASK) != 0)
|
||||
mod |= InputEvent.META_DOWN_MASK;
|
||||
if ((mod & InputEvent.ALT_MASK) != 0)
|
||||
mod |= InputEvent.ALT_DOWN_MASK;
|
||||
if ((mod & InputEvent.BUTTON1_MASK) != 0)
|
||||
mod |= InputEvent.BUTTON1_DOWN_MASK;
|
||||
if ((mod & InputEvent.ALT_GRAPH_MASK) != 0)
|
||||
mod |= InputEvent.ALT_GRAPH_DOWN_MASK;
|
||||
return mod & ~OLD_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the new style modifiers (0xffffffc0) to the old style (0x3f).
|
||||
*
|
||||
* @param mod the modifiers to convert
|
||||
* @return the adjusted modifiers
|
||||
*/
|
||||
public static int revert(int mod)
|
||||
{
|
||||
if ((mod & InputEvent.SHIFT_DOWN_MASK) != 0)
|
||||
mod |= InputEvent.SHIFT_MASK;
|
||||
if ((mod & InputEvent.CTRL_DOWN_MASK) != 0)
|
||||
mod |= InputEvent.CTRL_MASK;
|
||||
if ((mod & InputEvent.META_DOWN_MASK) != 0)
|
||||
mod |= InputEvent.META_MASK;
|
||||
if ((mod & InputEvent.ALT_DOWN_MASK) != 0)
|
||||
mod |= InputEvent.ALT_MASK;
|
||||
if ((mod & InputEvent.ALT_GRAPH_DOWN_MASK) != 0)
|
||||
mod |= InputEvent.ALT_GRAPH_MASK;
|
||||
if ((mod & InputEvent.BUTTON1_DOWN_MASK) != 0)
|
||||
mod |= InputEvent.BUTTON1_MASK;
|
||||
return mod & OLD_MASK;
|
||||
}
|
||||
} // class EventModifier
|
||||
@@ -1,73 +0,0 @@
|
||||
/* CieXyzConverter.java -- CieXyz conversion class
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
|
||||
/**
|
||||
* CieXyzConverter - converts to/from a D50-relative CIE XYZ color space.
|
||||
*
|
||||
* The sRGB<->CIE XYZ conversions in SrgbConverter are used.
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class CieXyzConverter implements ColorSpaceConverter
|
||||
{
|
||||
public float[] toCIEXYZ(float[] in)
|
||||
{
|
||||
float[] out = new float[3];
|
||||
System.arraycopy(in, 0, out, 0, 3);
|
||||
return out;
|
||||
}
|
||||
|
||||
public float[] fromCIEXYZ(float[] in)
|
||||
{
|
||||
float[] out = new float[3];
|
||||
System.arraycopy(in, 0, out, 0, 3);
|
||||
return out;
|
||||
}
|
||||
|
||||
public float[] toRGB(float[] in)
|
||||
{
|
||||
return SrgbConverter.XYZtoRGB(in);
|
||||
}
|
||||
|
||||
public float[] fromRGB(float[] in)
|
||||
{
|
||||
return SrgbConverter.RGBtoXYZ(in);
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/* ClutProfileConverter.java -- Conversion routines for CLUT-Based profiles
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
import java.awt.color.ICC_Profile;
|
||||
|
||||
|
||||
/**
|
||||
* ClutProfileConverter - conversions through a CLUT-based profile
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class ClutProfileConverter implements ColorSpaceConverter
|
||||
{
|
||||
private ColorLookUpTable toPCS;
|
||||
private ColorLookUpTable fromPCS;
|
||||
private int nChannels;
|
||||
|
||||
public ClutProfileConverter(ICC_Profile profile)
|
||||
{
|
||||
nChannels = profile.getNumComponents();
|
||||
|
||||
// Sun does not specifiy which rendering intent should be used,
|
||||
// neither does the ICC v2 spec really.
|
||||
// Try intent 0
|
||||
try
|
||||
{
|
||||
toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB0Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
toPCS = null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA0Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fromPCS = null;
|
||||
}
|
||||
|
||||
if (toPCS != null || fromPCS != null)
|
||||
return;
|
||||
|
||||
// If no intent 0 clut is available, look for a intent 1 clut.
|
||||
try
|
||||
{
|
||||
toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB1Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
toPCS = null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA1Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fromPCS = null;
|
||||
}
|
||||
|
||||
if (toPCS != null || fromPCS != null)
|
||||
return;
|
||||
|
||||
// Last shot.. intent 2 CLUT.
|
||||
try
|
||||
{
|
||||
toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB2Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
toPCS = null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA2Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fromPCS = null;
|
||||
}
|
||||
|
||||
if (toPCS == null && fromPCS == null)
|
||||
throw new IllegalArgumentException("No CLUTs in profile!");
|
||||
}
|
||||
|
||||
public float[] toCIEXYZ(float[] in)
|
||||
{
|
||||
if (toPCS != null)
|
||||
return toPCS.lookup(in);
|
||||
else
|
||||
return new float[3];
|
||||
}
|
||||
|
||||
public float[] toRGB(float[] in)
|
||||
{
|
||||
return SrgbConverter.XYZtoRGB(toCIEXYZ(in));
|
||||
}
|
||||
|
||||
public float[] fromCIEXYZ(float[] in)
|
||||
{
|
||||
if (fromPCS != null)
|
||||
return fromPCS.lookup(in);
|
||||
else
|
||||
return new float[nChannels];
|
||||
}
|
||||
|
||||
public float[] fromRGB(float[] in)
|
||||
{
|
||||
return fromCIEXYZ(SrgbConverter.RGBtoXYZ(in));
|
||||
}
|
||||
}
|
||||
@@ -1,429 +0,0 @@
|
||||
/* ColorLookUpTable.java -- ICC v2 CLUT
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_Profile;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
/**
|
||||
* ColorLookUpTable handles color lookups through a color lookup table,
|
||||
* as defined in the ICC specification.
|
||||
* Both 'mft2' and 'mft1' (8 and 16-bit) type CLUTs are handled.
|
||||
*
|
||||
* This will have to be updated later for ICC 4.0.0
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class ColorLookUpTable
|
||||
{
|
||||
/**
|
||||
* CIE 1931 D50 white point (in Lab coordinates)
|
||||
*/
|
||||
private static float[] D50 = { 0.96422f, 1.00f, 0.82521f };
|
||||
|
||||
/**
|
||||
* Number of input/output channels
|
||||
*/
|
||||
int nIn;
|
||||
|
||||
/**
|
||||
* Number of input/output channels
|
||||
*/
|
||||
int nOut;
|
||||
int nInTableEntries; // Number of input table entries
|
||||
int nOutTableEntries; // Number of output table entries
|
||||
int gridpoints; // Number of gridpoints
|
||||
int nClut; // This is nOut*(gridpoints**nIn)
|
||||
double[][] inTable; // 1D input table ([channel][table])
|
||||
short[][] outTable; // 1D input table ([channel][table])
|
||||
double[] clut; // The color lookup table
|
||||
float[][] inMatrix; // input matrix (XYZ only)
|
||||
boolean useMatrix; // Whether to use the matrix or not.
|
||||
int[] multiplier;
|
||||
int[] offsets; // Hypercube offsets
|
||||
boolean inputLab; // Set if the CLUT input CS is Lab
|
||||
boolean outputLab; // Set if the CLUT output CS is Lab
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Requires a profile file to get the CLUT from and the tag of the
|
||||
* CLUT to create. (icSigXToYZTag where X,Y = [A | B], Z = [0,1,2])
|
||||
*/
|
||||
public ColorLookUpTable(ICC_Profile profile, int tag)
|
||||
{
|
||||
useMatrix = false;
|
||||
|
||||
switch (tag)
|
||||
{
|
||||
case ICC_Profile.icSigAToB0Tag:
|
||||
case ICC_Profile.icSigAToB1Tag:
|
||||
case ICC_Profile.icSigAToB2Tag:
|
||||
if (profile.getColorSpaceType() == ColorSpace.TYPE_XYZ)
|
||||
useMatrix = true;
|
||||
inputLab = false;
|
||||
outputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab);
|
||||
break;
|
||||
case ICC_Profile.icSigBToA0Tag:
|
||||
case ICC_Profile.icSigBToA1Tag:
|
||||
case ICC_Profile.icSigBToA2Tag:
|
||||
if (profile.getPCSType() == ColorSpace.TYPE_XYZ)
|
||||
useMatrix = true;
|
||||
inputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab);
|
||||
outputLab = false;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Not a clut-type tag.");
|
||||
}
|
||||
|
||||
byte[] data = profile.getData(tag);
|
||||
if (data == null)
|
||||
throw new IllegalArgumentException("Unsuitable profile, does not contain a CLUT.");
|
||||
|
||||
// check 'mft'
|
||||
if (data[0] != 0x6d || data[1] != 0x66 || data[2] != 0x74)
|
||||
throw new IllegalArgumentException("Unsuitable profile, invalid CLUT data.");
|
||||
|
||||
if (data[3] == 0x32)
|
||||
readClut16(data);
|
||||
else if (data[3] == 0x31)
|
||||
readClut8(data);
|
||||
else
|
||||
throw new IllegalArgumentException("Unknown/invalid CLUT type.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a 16-bit CLUT into our data structures
|
||||
*/
|
||||
private void readClut16(byte[] data)
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.wrap(data);
|
||||
|
||||
nIn = data[8] & (0xFF);
|
||||
nOut = data[9] & (0xFF);
|
||||
nInTableEntries = buf.getShort(48);
|
||||
nOutTableEntries = buf.getShort(50);
|
||||
gridpoints = data[10] & (0xFF);
|
||||
|
||||
inMatrix = new float[3][3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f;
|
||||
|
||||
inTable = new double[nIn][nInTableEntries];
|
||||
for (int channel = 0; channel < nIn; channel++)
|
||||
for (int i = 0; i < nInTableEntries; i++)
|
||||
inTable[channel][i] = (double) ((int) buf.getShort(52
|
||||
+ (channel * nInTableEntries
|
||||
+ i) * 2)
|
||||
& (0xFFFF)) / 65536.0;
|
||||
|
||||
nClut = nOut;
|
||||
multiplier = new int[nIn];
|
||||
multiplier[nIn - 1] = nOut;
|
||||
for (int i = 0; i < nIn; i++)
|
||||
{
|
||||
nClut *= gridpoints;
|
||||
if (i > 0)
|
||||
multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints;
|
||||
}
|
||||
|
||||
int clutOffset = 52 + nIn * nInTableEntries * 2;
|
||||
clut = new double[nClut];
|
||||
for (int i = 0; i < nClut; i++)
|
||||
clut[i] = (double) ((int) buf.getShort(clutOffset + i * 2) & (0xFFFF)) / 65536.0;
|
||||
|
||||
outTable = new short[nOut][nOutTableEntries];
|
||||
for (int channel = 0; channel < nOut; channel++)
|
||||
for (int i = 0; i < nOutTableEntries; i++)
|
||||
outTable[channel][i] = buf.getShort(clutOffset
|
||||
+ (nClut
|
||||
+ channel * nOutTableEntries + i) * 2);
|
||||
|
||||
// calculate the hypercube corner offsets
|
||||
offsets = new int[(1 << nIn)];
|
||||
offsets[0] = 0;
|
||||
for (int j = 0; j < nIn; j++)
|
||||
{
|
||||
int factor = 1 << j;
|
||||
for (int i = 0; i < factor; i++)
|
||||
offsets[factor + i] = offsets[i] + multiplier[j];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a 8-bit CLUT into our data structures.
|
||||
*/
|
||||
private void readClut8(byte[] data)
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.wrap(data);
|
||||
|
||||
nIn = (data[8] & (0xFF));
|
||||
nOut = (data[9] & (0xFF));
|
||||
nInTableEntries = 256; // always 256
|
||||
nOutTableEntries = 256; // always 256
|
||||
gridpoints = (data[10] & (0xFF));
|
||||
|
||||
inMatrix = new float[3][3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f;
|
||||
|
||||
inTable = new double[nIn][nInTableEntries];
|
||||
for (int channel = 0; channel < nIn; channel++)
|
||||
for (int i = 0; i < nInTableEntries; i++)
|
||||
inTable[channel][i] = (double) ((int) buf.get(48
|
||||
+ (channel * nInTableEntries
|
||||
+ i)) & (0xFF)) / 255.0;
|
||||
|
||||
nClut = nOut;
|
||||
multiplier = new int[nIn];
|
||||
multiplier[nIn - 1] = nOut;
|
||||
for (int i = 0; i < nIn; i++)
|
||||
{
|
||||
nClut *= gridpoints;
|
||||
if (i > 0)
|
||||
multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints;
|
||||
}
|
||||
|
||||
int clutOffset = 48 + nIn * nInTableEntries;
|
||||
clut = new double[nClut];
|
||||
for (int i = 0; i < nClut; i++)
|
||||
clut[i] = (double) ((int) buf.get(clutOffset + i) & (0xFF)) / 255.0;
|
||||
|
||||
outTable = new short[nOut][nOutTableEntries];
|
||||
for (int channel = 0; channel < nOut; channel++)
|
||||
for (int i = 0; i < nOutTableEntries; i++)
|
||||
outTable[channel][i] = (short) (buf.get(clutOffset + nClut
|
||||
+ channel * nOutTableEntries
|
||||
+ i) * 257);
|
||||
|
||||
// calculate the hypercube corner offsets
|
||||
offsets = new int[(1 << nIn)];
|
||||
offsets[0] = 0;
|
||||
for (int j = 0; j < nIn; j++)
|
||||
{
|
||||
int factor = 1 << j;
|
||||
for (int i = 0; i < factor; i++)
|
||||
offsets[factor + i] = offsets[i] + multiplier[j];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a lookup through the Color LookUp Table.
|
||||
* If the CLUT tag type is AtoB the conversion will be from the device
|
||||
* color space to the PCS, BtoA type goes in the opposite direction.
|
||||
*
|
||||
* For convenience, the PCS values for input or output will always be
|
||||
* CIE XYZ (D50), if the actual PCS is Lab, the values will be converted.
|
||||
*
|
||||
* N-dimensional linear interpolation is used.
|
||||
*/
|
||||
float[] lookup(float[] in)
|
||||
{
|
||||
float[] in2 = new float[in.length];
|
||||
if (useMatrix)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
in2[i] = in[0] * inMatrix[i][0] + in[1] * inMatrix[i][1]
|
||||
+ in[2] * inMatrix[i][2];
|
||||
}
|
||||
else if (inputLab)
|
||||
in2 = XYZtoLab(in);
|
||||
else
|
||||
System.arraycopy(in, 0, in2, 0, in.length);
|
||||
|
||||
// input table
|
||||
for (int i = 0; i < nIn; i++)
|
||||
{
|
||||
int index = (int) Math.floor(in2[i] * (double) (nInTableEntries - 1)); // floor in
|
||||
|
||||
// clip values.
|
||||
if (index >= nInTableEntries - 1)
|
||||
in2[i] = (float) inTable[i][nInTableEntries - 1];
|
||||
else if (index < 0)
|
||||
in2[i] = (float) inTable[i][0];
|
||||
else
|
||||
{
|
||||
// linear interpolation
|
||||
double alpha = in2[i] * ((double) nInTableEntries - 1.0) - index;
|
||||
in2[i] = (float) (inTable[i][index] * (1 - alpha)
|
||||
+ inTable[i][index + 1] * alpha);
|
||||
}
|
||||
}
|
||||
|
||||
// CLUT lookup
|
||||
double[] output2 = new double[nOut];
|
||||
double[] weights = new double[(1 << nIn)];
|
||||
double[] clutalpha = new double[nIn]; // interpolation values
|
||||
int offset = 0; // = gp
|
||||
for (int i = 0; i < nIn; i++)
|
||||
{
|
||||
int index = (int) Math.floor(in2[i] * ((double) gridpoints - 1.0));
|
||||
double alpha = in2[i] * ((double) gridpoints - 1.0) - (double) index;
|
||||
|
||||
// clip values.
|
||||
if (index >= gridpoints - 1)
|
||||
{
|
||||
index = gridpoints - 1;
|
||||
alpha = 1.0;
|
||||
}
|
||||
else if (index < 0)
|
||||
index = 0;
|
||||
clutalpha[i] = alpha;
|
||||
offset += index * multiplier[i];
|
||||
}
|
||||
|
||||
// Calculate interpolation weights
|
||||
weights[0] = 1.0;
|
||||
for (int j = 0; j < nIn; j++)
|
||||
{
|
||||
int factor = 1 << j;
|
||||
for (int i = 0; i < factor; i++)
|
||||
{
|
||||
weights[factor + i] = weights[i] * clutalpha[j];
|
||||
weights[i] *= (1.0 - clutalpha[j]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < nOut; i++)
|
||||
output2[i] = weights[0] * clut[offset + i];
|
||||
|
||||
for (int i = 1; i < (1 << nIn); i++)
|
||||
{
|
||||
int offset2 = offset + offsets[i];
|
||||
for (int f = 0; f < nOut; f++)
|
||||
output2[f] += weights[i] * clut[offset2 + f];
|
||||
}
|
||||
|
||||
// output table
|
||||
float[] output = new float[nOut];
|
||||
for (int i = 0; i < nOut; i++)
|
||||
{
|
||||
int index = (int) Math.floor(output2[i] * ((double) nOutTableEntries
|
||||
- 1.0));
|
||||
|
||||
// clip values.
|
||||
if (index >= nOutTableEntries - 1)
|
||||
output[i] = outTable[i][nOutTableEntries - 1];
|
||||
else if (index < 0)
|
||||
output[i] = outTable[i][0];
|
||||
else
|
||||
{
|
||||
// linear interpolation
|
||||
double a = output2[i] * ((double) nOutTableEntries - 1.0)
|
||||
- (double) index;
|
||||
output[i] = (float) ((double) ((int) outTable[i][index] & (0xFFFF)) * (1
|
||||
- a)
|
||||
+ (double) ((int) outTable[i][index + 1] & (0xFFFF)) * a) / 65536f;
|
||||
}
|
||||
}
|
||||
|
||||
if (outputLab)
|
||||
return LabtoXYZ(output);
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts CIE Lab coordinates to (D50) XYZ ones.
|
||||
*/
|
||||
private float[] LabtoXYZ(float[] in)
|
||||
{
|
||||
// Convert from byte-packed format to a
|
||||
// more convenient one (actual Lab values)
|
||||
// (See ICC spec for details)
|
||||
// factor is 100 * 65536 / 65280
|
||||
in[0] = (float) (100.392156862745 * in[0]);
|
||||
in[1] = (in[1] * 256.0f) - 128.0f;
|
||||
in[2] = (in[2] * 256.0f) - 128.0f;
|
||||
|
||||
float[] out = new float[3];
|
||||
|
||||
out[1] = (in[0] + 16.0f) / 116.0f;
|
||||
out[0] = in[1] / 500.0f + out[1];
|
||||
out[2] = out[1] - in[2] / 200.0f;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
double exp = out[i] * out[i] * out[i];
|
||||
if (exp <= 0.008856)
|
||||
out[i] = (out[i] - 16.0f / 116.0f) / 7.787f;
|
||||
else
|
||||
out[i] = (float) exp;
|
||||
out[i] = D50[i] * out[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts CIE XYZ coordinates to Lab ones.
|
||||
*/
|
||||
private float[] XYZtoLab(float[] in)
|
||||
{
|
||||
float[] temp = new float[3];
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
temp[i] = in[i] / D50[i];
|
||||
|
||||
if (temp[i] <= 0.008856f)
|
||||
temp[i] = (7.7870689f * temp[i]) + (16f / 116.0f);
|
||||
else
|
||||
temp[i] = (float) Math.exp((1.0 / 3.0) * Math.log(temp[i]));
|
||||
}
|
||||
|
||||
float[] out = new float[3];
|
||||
out[0] = (116.0f * temp[1]) - 16f;
|
||||
out[1] = 500.0f * (temp[0] - temp[1]);
|
||||
out[2] = 200.0f * (temp[1] - temp[2]);
|
||||
|
||||
// Normalize to packed format
|
||||
out[0] = (float) (out[0] / 100.392156862745);
|
||||
out[1] = (out[1] + 128f) / 256f;
|
||||
out[2] = (out[2] + 128f) / 256f;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (out[i] < 0f)
|
||||
out[i] = 0f;
|
||||
if (out[i] > 1f)
|
||||
out[i] = 1f;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/* ColorSpaceConverter.java -- an interface for colorspace conversion
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
|
||||
/**
|
||||
* ColorSpaceConverter - used by java.awt.color.ICC_ColorSpace
|
||||
*
|
||||
* Color space conversion can occur in several ways:
|
||||
*
|
||||
* -Directly (for the built in spaces sRGB, linear RGB, gray, CIE XYZ and PYCC
|
||||
* -ICC_ProfileRGB works through TRC curves and a matrix
|
||||
* -ICC_ProfileGray works through a single TRC
|
||||
* -Everything else is done through Color lookup tables.
|
||||
*
|
||||
* The different conversion methods are implemented through
|
||||
* an interface. The built-in colorspaces are implemented directly
|
||||
* with the relevant conversion equations.
|
||||
*
|
||||
* In this way, we hopefully will always use the fastest and most
|
||||
* accurate method available.
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public interface ColorSpaceConverter
|
||||
{
|
||||
float[] toCIEXYZ(float[] in);
|
||||
|
||||
float[] fromCIEXYZ(float[] in);
|
||||
|
||||
float[] toRGB(float[] in);
|
||||
|
||||
float[] fromRGB(float[] in);
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/* GrayProfileConverter.java -- Gray profile conversion class
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
import java.awt.color.ICC_Profile;
|
||||
import java.awt.color.ICC_ProfileGray;
|
||||
import java.awt.color.ProfileDataException;
|
||||
|
||||
/**
|
||||
* GrayProfileConverter - converts Grayscale profiles (ICC_ProfileGray)
|
||||
*
|
||||
* This type of profile contains a single tone reproduction curve (TRC).
|
||||
* Conversion consists of simple TRC lookup.
|
||||
*
|
||||
* This implementation is very lazy and does everything applying the TRC and
|
||||
* utilizing the built-in linear grayscale color space.
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class GrayProfileConverter implements ColorSpaceConverter
|
||||
{
|
||||
private GrayScaleConverter gc;
|
||||
private ToneReproductionCurve trc;
|
||||
private ColorLookUpTable toPCS;
|
||||
private ColorLookUpTable fromPCS;
|
||||
|
||||
/**
|
||||
* Constructs the converter described by an ICC_ProfileGray object
|
||||
*/
|
||||
public GrayProfileConverter(ICC_ProfileGray profile)
|
||||
{
|
||||
try
|
||||
{
|
||||
trc = new ToneReproductionCurve(profile.getGamma());
|
||||
}
|
||||
catch (ProfileDataException e)
|
||||
{
|
||||
trc = new ToneReproductionCurve(profile.getTRC());
|
||||
}
|
||||
|
||||
// linear grayscale converter
|
||||
gc = new GrayScaleConverter();
|
||||
|
||||
// If a CLUT is available, it should be used, and the TRCs ignored.
|
||||
// Note: A valid profile may only have CLUTs in one direction, and
|
||||
// TRC:s without useful info, making reverse-transforms impossible.
|
||||
// In this case the TRC will be used for the reverse-transform with
|
||||
// unpredictable results. This is in line with the Java specification,
|
||||
try
|
||||
{
|
||||
toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB0Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
toPCS = null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA0Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fromPCS = null;
|
||||
}
|
||||
}
|
||||
|
||||
public float[] toCIEXYZ(float[] in)
|
||||
{
|
||||
if (toPCS != null)
|
||||
return toPCS.lookup(in);
|
||||
float[] gray = new float[1];
|
||||
gray[0] = trc.lookup(in[0]);
|
||||
return gc.toCIEXYZ(gray);
|
||||
}
|
||||
|
||||
public float[] toRGB(float[] in)
|
||||
{
|
||||
float[] gray = new float[1];
|
||||
gray[0] = trc.lookup(in[0]);
|
||||
return gc.toRGB(gray);
|
||||
}
|
||||
|
||||
public float[] fromRGB(float[] in)
|
||||
{
|
||||
// get linear grayscale value
|
||||
float[] gray = gc.fromRGB(in);
|
||||
gray[0] = trc.reverseLookup(gray[0]);
|
||||
return gray;
|
||||
}
|
||||
|
||||
public float[] fromCIEXYZ(float[] in)
|
||||
{
|
||||
if (fromPCS != null)
|
||||
return fromPCS.lookup(in);
|
||||
|
||||
float[] gray = gc.fromCIEXYZ(in);
|
||||
gray[0] = trc.reverseLookup(gray[0]);
|
||||
return gray;
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/* GrayScaleConverter.java -- Linear grayscale conversion class
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
|
||||
/**
|
||||
* Linear Grayscale converter
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class GrayScaleConverter implements ColorSpaceConverter
|
||||
{
|
||||
// intensity factors (ITU Rec. BT.709)
|
||||
double[] coeff = { 0.2125f, 0.7154f, 0.0721f };
|
||||
|
||||
/**
|
||||
* CIE 1931 D50 white point (in Lab coordinates)
|
||||
*/
|
||||
private static float[] D50 = { 0.96422f, 1.00f, 0.82521f };
|
||||
|
||||
public float[] toCIEXYZ(float[] in)
|
||||
{
|
||||
float g = in[0];
|
||||
if (g < 0)
|
||||
g = 1 + g;
|
||||
float[] out = { g * D50[0], g * D50[1], g * D50[2] }; // White spot
|
||||
return out;
|
||||
}
|
||||
|
||||
public float[] toRGB(float[] in)
|
||||
{
|
||||
float[] out = new float[3];
|
||||
if (in[0] <= 0.00304f)
|
||||
out[0] = in[0] * 12.92f;
|
||||
else
|
||||
out[0] = 1.055f * ((float) Math.exp((1 / 2.4) * Math.log(in[0])))
|
||||
- 0.055f;
|
||||
out[1] = out[2] = out[0];
|
||||
return out;
|
||||
}
|
||||
|
||||
public float[] fromCIEXYZ(float[] in)
|
||||
{
|
||||
float[] temp = new float[3];
|
||||
temp[0] = 3.1338f * in[0] - 1.6171f * in[1] - 0.4907f * in[2];
|
||||
temp[1] = -0.9785f * in[0] + 1.9160f * in[1] + 0.0334f * in[2];
|
||||
temp[2] = 0.0720f * in[0] - 0.2290f * in[1] + 1.4056f * in[2];
|
||||
float[] out = new float[1];
|
||||
for (int i = 0; i < 3; i++)
|
||||
out[0] = (float) (temp[i] * coeff[i]);
|
||||
return out;
|
||||
}
|
||||
|
||||
public float[] fromRGB(float[] in)
|
||||
{
|
||||
float[] out = new float[1];
|
||||
|
||||
// Convert non-linear RGB coordinates to linear ones,
|
||||
// numbers from the w3 spec.
|
||||
out[0] = 0;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
float n = in[i];
|
||||
if (n < 0)
|
||||
n = 0f;
|
||||
if (n > 1)
|
||||
n = 1f;
|
||||
if (n <= 0.03928f)
|
||||
out[0] += (float) (coeff[i] * n / 12.92);
|
||||
else
|
||||
out[0] += (float) (coeff[i] * Math.exp(2.4 * Math.log((n + 0.055) / 1.055)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/* LinearRGBConverter.java -- conversion to a linear RGB color space
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
|
||||
/**
|
||||
* LinearRGBConverter - conversion routines for a linear sRGB colorspace
|
||||
* sRGB is a standard for RGB colorspaces, adopted by the w3c.
|
||||
*
|
||||
* The specification is available at:
|
||||
* http://www.w3.org/Graphics/Color/sRGB.html
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class LinearRGBConverter implements ColorSpaceConverter
|
||||
{
|
||||
/**
|
||||
* linear RGB --> sRGB
|
||||
* Use the inverse gamma curve
|
||||
*/
|
||||
public float[] toRGB(float[] in)
|
||||
{
|
||||
float[] out = new float[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
float n = in[i];
|
||||
if (n < 0)
|
||||
n = 0f;
|
||||
if (n > 1)
|
||||
n = 1f;
|
||||
if (n <= 0.00304f)
|
||||
out[i] = in[0] * 12.92f;
|
||||
else
|
||||
out[i] = 1.055f * ((float) Math.exp((1 / 2.4) * Math.log(n)))
|
||||
- 0.055f;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* sRGB --> linear RGB
|
||||
* Use the gamma curve (gamma=2.4 in sRGB)
|
||||
*/
|
||||
public float[] fromRGB(float[] in)
|
||||
{
|
||||
float[] out = new float[3];
|
||||
|
||||
// Convert non-linear RGB coordinates to linear ones,
|
||||
// numbers from the w3 spec.
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
float n = in[i];
|
||||
if (n < 0)
|
||||
n = 0f;
|
||||
if (n > 1)
|
||||
n = 1f;
|
||||
if (n <= 0.03928f)
|
||||
out[i] = (float) (n / 12.92);
|
||||
else
|
||||
out[i] = (float) (Math.exp(2.4 * Math.log((n + 0.055) / 1.055)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Linear RGB --> CIE XYZ (D50 relative)
|
||||
* This is a simple matrix transform, the matrix (relative D65)
|
||||
* is given in the sRGB spec. This has been combined with a
|
||||
* linear Bradford transform for the D65-->D50 mapping, resulting
|
||||
* in a single matrix which does the whole thing.
|
||||
*
|
||||
*/
|
||||
public float[] fromCIEXYZ(float[] in)
|
||||
{
|
||||
/*
|
||||
* Note: The numbers which were used to calculate this only had four
|
||||
* digits of accuracy. So don't be fooled by the number of digits here.
|
||||
* If someone has more accurate source, feel free to update this.
|
||||
*/
|
||||
float[] out = new float[3];
|
||||
out[0] = (float) (3.13383065124221 * in[0] - 1.61711949411313 * in[1]
|
||||
- 0.49071914111101 * in[2]);
|
||||
out[1] = (float) (-0.97847026691142 * in[0] + 1.91597856031996 * in[1]
|
||||
+ 0.03340430640699 * in[2]);
|
||||
out[2] = (float) (0.07203679486279 * in[0] - 0.22903073553113 * in[1]
|
||||
+ 1.40557835776234 * in[2]);
|
||||
if (out[0] < 0)
|
||||
out[0] = 0f;
|
||||
if (out[1] < 0)
|
||||
out[1] = 0f;
|
||||
if (out[2] < 0)
|
||||
out[2] = 0f;
|
||||
if (out[0] > 1.0f)
|
||||
out[0] = 1.0f;
|
||||
if (out[1] > 1.0f)
|
||||
out[1] = 1.0f;
|
||||
if (out[2] > 1.0f)
|
||||
out[2] = 1.0f;
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Linear RGB --> CIE XYZ (D50 relative)
|
||||
* Uses the inverse of the above matrix.
|
||||
*/
|
||||
public float[] toCIEXYZ(float[] in)
|
||||
{
|
||||
float[] out = new float[3];
|
||||
out[0] = (float) (0.43606375022190 * in[0] + 0.38514960146481 * in[1]
|
||||
+ 0.14308641888799 * in[2]);
|
||||
out[1] = (float) (0.22245089403542 * in[0] + 0.71692584775182 * in[1]
|
||||
+ 0.06062451125578 * in[2]);
|
||||
out[2] = (float) (0.01389851860679 * in[0] + 0.09707969011198 * in[1]
|
||||
+ 0.71399604572506 * in[2]);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,398 +0,0 @@
|
||||
/* ProfileHeader.java -- Encapsules ICC Profile header data
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.color.ICC_Profile;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
||||
/**
|
||||
* Header, abstracts and validates the header data.
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class ProfileHeader
|
||||
{
|
||||
/**
|
||||
* Magic identifier (ASCII 'acsp')
|
||||
*/
|
||||
private static final int icMagicNumber = 0x61637370;
|
||||
|
||||
/**
|
||||
* Mapping from ICC Profile signatures to ColorSpace types
|
||||
*/
|
||||
private static final int[] csTypeMap =
|
||||
{
|
||||
ICC_Profile.icSigXYZData,
|
||||
ColorSpace.TYPE_XYZ,
|
||||
ICC_Profile.icSigLabData,
|
||||
ColorSpace.TYPE_Lab,
|
||||
ICC_Profile.icSigLuvData,
|
||||
ColorSpace.TYPE_Luv,
|
||||
ICC_Profile.icSigYCbCrData,
|
||||
ColorSpace.TYPE_YCbCr,
|
||||
ICC_Profile.icSigYxyData,
|
||||
ColorSpace.TYPE_Yxy,
|
||||
ICC_Profile.icSigRgbData,
|
||||
ColorSpace.TYPE_RGB,
|
||||
ICC_Profile.icSigGrayData,
|
||||
ColorSpace.TYPE_GRAY,
|
||||
ICC_Profile.icSigHsvData,
|
||||
ColorSpace.TYPE_HSV,
|
||||
ICC_Profile.icSigHlsData,
|
||||
ColorSpace.TYPE_HLS,
|
||||
ICC_Profile.icSigCmykData,
|
||||
ColorSpace.TYPE_CMYK,
|
||||
ICC_Profile.icSigCmyData,
|
||||
ColorSpace.TYPE_CMY,
|
||||
ICC_Profile.icSigSpace2CLR,
|
||||
ColorSpace.TYPE_2CLR,
|
||||
ICC_Profile.icSigSpace3CLR,
|
||||
ColorSpace.TYPE_3CLR,
|
||||
ICC_Profile.icSigSpace4CLR,
|
||||
ColorSpace.TYPE_4CLR,
|
||||
ICC_Profile.icSigSpace5CLR,
|
||||
ColorSpace.TYPE_5CLR,
|
||||
ICC_Profile.icSigSpace6CLR,
|
||||
ColorSpace.TYPE_6CLR,
|
||||
ICC_Profile.icSigSpace7CLR,
|
||||
ColorSpace.TYPE_7CLR,
|
||||
ICC_Profile.icSigSpace8CLR,
|
||||
ColorSpace.TYPE_8CLR,
|
||||
ICC_Profile.icSigSpace9CLR,
|
||||
ColorSpace.TYPE_9CLR,
|
||||
ICC_Profile.icSigSpaceACLR,
|
||||
ColorSpace.TYPE_ACLR,
|
||||
ICC_Profile.icSigSpaceBCLR,
|
||||
ColorSpace.TYPE_BCLR,
|
||||
ICC_Profile.icSigSpaceCCLR,
|
||||
ColorSpace.TYPE_CCLR,
|
||||
ICC_Profile.icSigSpaceDCLR,
|
||||
ColorSpace.TYPE_DCLR,
|
||||
ICC_Profile.icSigSpaceECLR,
|
||||
ColorSpace.TYPE_ECLR,
|
||||
ICC_Profile.icSigSpaceFCLR,
|
||||
ColorSpace.TYPE_FCLR
|
||||
};
|
||||
|
||||
/**
|
||||
* Size of an ICC header (128 bytes)
|
||||
*/
|
||||
public static final int HEADERSIZE = 128;
|
||||
|
||||
/**
|
||||
* Mapping of ICC class signatures to profile class constants
|
||||
*/
|
||||
private static final int[] classMap =
|
||||
{
|
||||
ICC_Profile.icSigInputClass,
|
||||
ICC_Profile.CLASS_INPUT,
|
||||
ICC_Profile.icSigDisplayClass,
|
||||
ICC_Profile.CLASS_DISPLAY,
|
||||
ICC_Profile.icSigOutputClass,
|
||||
ICC_Profile.CLASS_OUTPUT,
|
||||
ICC_Profile.icSigLinkClass,
|
||||
ICC_Profile.CLASS_DEVICELINK,
|
||||
ICC_Profile.icSigColorSpaceClass,
|
||||
ICC_Profile.CLASS_COLORSPACECONVERSION,
|
||||
ICC_Profile.icSigAbstractClass,
|
||||
ICC_Profile.CLASS_ABSTRACT,
|
||||
ICC_Profile.icSigNamedColorClass,
|
||||
ICC_Profile.CLASS_NAMEDCOLOR
|
||||
};
|
||||
private int size;
|
||||
private int cmmId;
|
||||
|
||||
// Major/Minor version, The ICC-1998 spec is major v2
|
||||
private int majorVersion;
|
||||
|
||||
// Major/Minor version, The ICC-1998 spec is major v2
|
||||
private int minorVersion;
|
||||
private int profileClass; // profile device class
|
||||
private int colorSpace; // data color space type
|
||||
private int profileColorSpace; // profile connection space (PCS) type
|
||||
private byte[] timestamp; // original creation timestamp
|
||||
private int platform; // platform signature
|
||||
private int flags; // flags
|
||||
private int magic; // magic number.
|
||||
private int manufacturerSig; // manufacturer sig
|
||||
private int modelSig; // model sig
|
||||
private byte[] attributes; // Attributes
|
||||
private int intent; // rendering intent
|
||||
private byte[] illuminant; // illuminant info (Coordinates of D50 in the PCS)
|
||||
private int creatorSig; // Creator sig (same type as manufacturer)
|
||||
|
||||
/**
|
||||
* Creates a 'default' header for use with our predefined profiles.
|
||||
* Note the device and profile color spaces are not set.
|
||||
*/
|
||||
public ProfileHeader()
|
||||
{
|
||||
creatorSig = 0;
|
||||
intent = 0;
|
||||
modelSig = manufacturerSig = (int) 0x6E6f6E65; // 'none'
|
||||
magic = icMagicNumber;
|
||||
cmmId = 0;
|
||||
platform = 0; // no preferred platform
|
||||
timestamp = new byte[8];
|
||||
majorVersion = 2;
|
||||
minorVersion = 0x10;
|
||||
flags = 0;
|
||||
|
||||
// D50 in XYZ format (encoded)
|
||||
illuminant = new byte[]
|
||||
{
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0xf6, (byte) 0xd6,
|
||||
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0xd3, (byte) 0x2d
|
||||
};
|
||||
attributes = new byte[8];
|
||||
profileClass = ICC_Profile.CLASS_DISPLAY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a header from profile data. Only the header portion (128 bytes)
|
||||
* is read, so the array passed need not be the full profile.
|
||||
*/
|
||||
public ProfileHeader(byte[] data)
|
||||
{
|
||||
ByteBuffer buf = ByteBuffer.wrap(data);
|
||||
|
||||
// Get size (the sign bit shouldn't matter.
|
||||
// A valid profile can never be +2Gb)
|
||||
size = buf.getInt(ICC_Profile.icHdrSize);
|
||||
|
||||
// CMM ID
|
||||
cmmId = buf.getInt(ICC_Profile.icHdrCmmId);
|
||||
|
||||
// Version number
|
||||
majorVersion = (int) (data[ICC_Profile.icHdrVersion]);
|
||||
minorVersion = (int) (data[ICC_Profile.icHdrVersion + 1]);
|
||||
|
||||
// Profile/Device class
|
||||
int classSig = buf.getInt(ICC_Profile.icHdrDeviceClass);
|
||||
profileClass = -1;
|
||||
for (int i = 0; i < classMap.length; i += 2)
|
||||
if (classMap[i] == classSig)
|
||||
{
|
||||
profileClass = classMap[i + 1];
|
||||
break;
|
||||
}
|
||||
|
||||
// get the data color space
|
||||
int csSig = buf.getInt(ICC_Profile.icHdrColorSpace);
|
||||
colorSpace = -1;
|
||||
for (int i = 0; i < csTypeMap.length; i += 2)
|
||||
if (csTypeMap[i] == csSig)
|
||||
{
|
||||
colorSpace = csTypeMap[i + 1];
|
||||
break;
|
||||
}
|
||||
|
||||
// get the profile color space (PCS), must be xyz or lab except
|
||||
// for device-link-class profiles
|
||||
int pcsSig = buf.getInt(ICC_Profile.icHdrPcs);
|
||||
profileColorSpace = -1;
|
||||
if (profileClass != ICC_Profile.CLASS_DEVICELINK)
|
||||
{
|
||||
if (pcsSig == ICC_Profile.icSigXYZData)
|
||||
profileColorSpace = ColorSpace.TYPE_XYZ;
|
||||
if (pcsSig == ICC_Profile.icSigLabData)
|
||||
profileColorSpace = ColorSpace.TYPE_Lab;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < csTypeMap.length; i += 2)
|
||||
if (csTypeMap[i] == pcsSig)
|
||||
{
|
||||
profileColorSpace = csTypeMap[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// creation timestamp
|
||||
timestamp = new byte[8];
|
||||
System.arraycopy(data, ICC_Profile.icHdrDate, timestamp, 0, 8);
|
||||
|
||||
// magic number
|
||||
magic = buf.getInt(ICC_Profile.icHdrMagic);
|
||||
|
||||
// platform info
|
||||
platform = buf.getInt(ICC_Profile.icHdrPlatform);
|
||||
// get flags
|
||||
flags = buf.getInt(ICC_Profile.icHdrFlags);
|
||||
// get manufacturer sign
|
||||
manufacturerSig = buf.getInt(ICC_Profile.icHdrManufacturer);
|
||||
// get header model
|
||||
modelSig = buf.getInt(ICC_Profile.icHdrModel);
|
||||
// attributes
|
||||
attributes = new byte[8];
|
||||
System.arraycopy(data, ICC_Profile.icHdrAttributes, attributes, 0, 8);
|
||||
// rendering intent
|
||||
intent = buf.getInt(ICC_Profile.icHdrRenderingIntent);
|
||||
// illuminant info
|
||||
illuminant = new byte[12];
|
||||
System.arraycopy(data, ICC_Profile.icHdrIlluminant, illuminant, 0, 12);
|
||||
// Creator signature
|
||||
creatorSig = buf.getInt(ICC_Profile.icHdrCreator);
|
||||
// The rest of the header (Total size: 128 bytes) is unused..
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that the header is valid
|
||||
* @param size equals the file size if it is to be verified, -1 otherwise
|
||||
* @throws IllegalArgumentException if the header is found to be invalid.
|
||||
*/
|
||||
public void verifyHeader(int size) throws IllegalArgumentException
|
||||
{
|
||||
// verify size
|
||||
if (size != -1 && this.size != size)
|
||||
throw new IllegalArgumentException("Invalid profile length:" + size);
|
||||
|
||||
// Check version number
|
||||
if (majorVersion != 2)
|
||||
throw new IllegalArgumentException("Wrong major version number:"
|
||||
+ majorVersion);
|
||||
|
||||
// Profile/Device class
|
||||
if (profileClass == -1)
|
||||
throw new IllegalArgumentException("Invalid profile/device class");
|
||||
|
||||
// get the data color space
|
||||
if (colorSpace == -1)
|
||||
throw new IllegalArgumentException("Invalid colorspace");
|
||||
|
||||
// profile color space
|
||||
if (profileColorSpace == -1)
|
||||
throw new IllegalArgumentException("Invalid PCS.");
|
||||
|
||||
// check magic number
|
||||
if (magic != icMagicNumber)
|
||||
throw new IllegalArgumentException("Invalid magic number!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a header, setting the header file size at the same time.
|
||||
* @param size the profile file size.
|
||||
*/
|
||||
public byte[] getData(int size)
|
||||
{
|
||||
byte[] data = new byte[HEADERSIZE];
|
||||
ByteBuffer buf = ByteBuffer.wrap(data);
|
||||
buf.putInt(ICC_Profile.icHdrSize, size);
|
||||
buf.putInt(ICC_Profile.icHdrCmmId, cmmId);
|
||||
buf.putShort(ICC_Profile.icHdrVersion,
|
||||
(short) (majorVersion << 8 | minorVersion));
|
||||
for (int i = 1; i < classMap.length; i += 2)
|
||||
if (profileClass == classMap[i])
|
||||
buf.putInt(ICC_Profile.icHdrDeviceClass, classMap[i - 1]);
|
||||
for (int i = 1; i < csTypeMap.length; i += 2)
|
||||
if (csTypeMap[i] == colorSpace)
|
||||
buf.putInt(ICC_Profile.icHdrColorSpace, csTypeMap[i - 1]);
|
||||
for (int i = 1; i < csTypeMap.length; i += 2)
|
||||
if (csTypeMap[i] == profileColorSpace)
|
||||
buf.putInt(ICC_Profile.icHdrPcs, csTypeMap[i - 1]);
|
||||
|
||||
System.arraycopy(timestamp, 0, data, ICC_Profile.icHdrDate,
|
||||
timestamp.length);
|
||||
buf.putInt(ICC_Profile.icHdrMagic, icMagicNumber);
|
||||
buf.putInt(ICC_Profile.icHdrPlatform, platform);
|
||||
buf.putInt(ICC_Profile.icHdrFlags, flags);
|
||||
buf.putInt(ICC_Profile.icHdrManufacturer, manufacturerSig);
|
||||
buf.putInt(ICC_Profile.icHdrModel, modelSig);
|
||||
System.arraycopy(attributes, 0, data, ICC_Profile.icHdrAttributes,
|
||||
attributes.length);
|
||||
buf.putInt(ICC_Profile.icHdrRenderingIntent, intent);
|
||||
System.arraycopy(illuminant, 0, data, ICC_Profile.icHdrIlluminant,
|
||||
illuminant.length);
|
||||
buf.putInt(ICC_Profile.icHdrCreator, creatorSig);
|
||||
return buf.array();
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(int s)
|
||||
{
|
||||
size = s;
|
||||
}
|
||||
|
||||
public int getMajorVersion()
|
||||
{
|
||||
return majorVersion;
|
||||
}
|
||||
|
||||
public int getMinorVersion()
|
||||
{
|
||||
return minorVersion;
|
||||
}
|
||||
|
||||
public int getProfileClass()
|
||||
{
|
||||
return profileClass;
|
||||
}
|
||||
|
||||
public void setProfileClass(int pc)
|
||||
{
|
||||
profileClass = pc;
|
||||
}
|
||||
|
||||
public int getColorSpace()
|
||||
{
|
||||
return colorSpace;
|
||||
}
|
||||
|
||||
public int getProfileColorSpace()
|
||||
{
|
||||
return profileColorSpace;
|
||||
}
|
||||
|
||||
public void setColorSpace(int cs)
|
||||
{
|
||||
colorSpace = cs;
|
||||
}
|
||||
|
||||
public void setProfileColorSpace(int pcs)
|
||||
{
|
||||
profileColorSpace = pcs;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/* PyccConverter.java -- PhotoYCC conversion class
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
|
||||
/**
|
||||
* PyccConverter - conversion routines for the PhotoYCC colorspace
|
||||
*
|
||||
* Also known as PhotoCD YCC, it is an expansion of the conventional
|
||||
* YCC color space to also include colors with over 100% white.
|
||||
*
|
||||
* XXX FIXME: Not yet implemented, implementation pending.
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class PyccConverter implements ColorSpaceConverter
|
||||
{
|
||||
public float[] toRGB(float[] in)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public float[] fromRGB(float[] in)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public float[] toCIEXYZ(float[] in)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public float[] fromCIEXYZ(float[] in)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
/* RgbProfileConverter.java -- RGB Profile conversion class
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
import java.awt.color.ICC_Profile;
|
||||
import java.awt.color.ICC_ProfileRGB;
|
||||
import java.awt.color.ProfileDataException;
|
||||
|
||||
/**
|
||||
* RgbProfileConverter - converts RGB profiles (ICC_ProfileRGB)
|
||||
*
|
||||
* This type of profile contains a matrix and three
|
||||
* tone reproduction curves (TRCs).
|
||||
*
|
||||
* Device RGB --> CIE XYZ is done through first multiplying with
|
||||
* a matrix, then each component is looked-up against it's TRC.
|
||||
*
|
||||
* The opposite transform is done using the inverse of the matrix,
|
||||
* and TRC:s.
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class RgbProfileConverter implements ColorSpaceConverter
|
||||
{
|
||||
private float[][] matrix;
|
||||
private float[][] inv_matrix;
|
||||
private ToneReproductionCurve rTRC;
|
||||
private ToneReproductionCurve gTRC;
|
||||
private ToneReproductionCurve bTRC;
|
||||
private ColorLookUpTable toPCS;
|
||||
private ColorLookUpTable fromPCS;
|
||||
|
||||
/**
|
||||
* CIE 1931 D50 white point (in Lab coordinates)
|
||||
*/
|
||||
private static float[] D50 = { 0.96422f, 1.00f, 0.82521f };
|
||||
|
||||
/**
|
||||
* Constructs an RgbProfileConverter from a given ICC_ProfileRGB
|
||||
*/
|
||||
public RgbProfileConverter(ICC_ProfileRGB profile)
|
||||
{
|
||||
toPCS = fromPCS = null;
|
||||
matrix = profile.getMatrix();
|
||||
|
||||
// get TRCs
|
||||
try
|
||||
{
|
||||
rTRC = new ToneReproductionCurve(profile.getGamma(ICC_ProfileRGB.REDCOMPONENT));
|
||||
}
|
||||
catch (ProfileDataException e)
|
||||
{
|
||||
rTRC = new ToneReproductionCurve(profile.getTRC(ICC_ProfileRGB.REDCOMPONENT));
|
||||
}
|
||||
try
|
||||
{
|
||||
gTRC = new ToneReproductionCurve(profile.getGamma(ICC_ProfileRGB.GREENCOMPONENT));
|
||||
}
|
||||
catch (ProfileDataException e)
|
||||
{
|
||||
gTRC = new ToneReproductionCurve(profile.getTRC(ICC_ProfileRGB.GREENCOMPONENT));
|
||||
}
|
||||
try
|
||||
{
|
||||
bTRC = new ToneReproductionCurve(profile.getGamma(ICC_ProfileRGB.BLUECOMPONENT));
|
||||
}
|
||||
catch (ProfileDataException e)
|
||||
{
|
||||
bTRC = new ToneReproductionCurve(profile.getTRC(ICC_ProfileRGB.BLUECOMPONENT));
|
||||
}
|
||||
|
||||
// If a CLUT is available, it should be used, and the TRCs ignored.
|
||||
// Note: A valid profile may only have CLUTs in one direction, and
|
||||
// TRC:s without useful info, making reverse-transforms impossible.
|
||||
// In this case the TRC will be used for the reverse-transform with
|
||||
// unpredictable results. This is in line with the Java specification,
|
||||
try
|
||||
{
|
||||
toPCS = new ColorLookUpTable(profile, ICC_Profile.icSigAToB0Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
toPCS = null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
fromPCS = new ColorLookUpTable(profile, ICC_Profile.icSigBToA0Tag);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
fromPCS = null;
|
||||
}
|
||||
|
||||
// Calculate the inverse matrix if no reverse CLUT is available
|
||||
if(fromPCS == null)
|
||||
inv_matrix = invertMatrix(matrix);
|
||||
else
|
||||
{
|
||||
// otherwise just set it to an identity matrix
|
||||
inv_matrix = new float[3][3];
|
||||
inv_matrix[0][0] = inv_matrix[1][1] = inv_matrix[2][2] = 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public float[] toCIEXYZ(float[] in)
|
||||
{
|
||||
// CLUT takes precedence
|
||||
if (toPCS != null)
|
||||
return toPCS.lookup(in);
|
||||
|
||||
float[] temp = new float[3];
|
||||
float[] out = new float[3];
|
||||
|
||||
// device space --> linear gamma
|
||||
temp[0] = rTRC.lookup(in[0]);
|
||||
temp[1] = gTRC.lookup(in[1]);
|
||||
temp[2] = bTRC.lookup(in[2]);
|
||||
|
||||
// matrix multiplication
|
||||
out[0] = matrix[0][0] * temp[0] + matrix[0][1] * temp[1]
|
||||
+ matrix[0][2] * temp[2];
|
||||
out[1] = matrix[1][0] * temp[0] + matrix[1][1] * temp[1]
|
||||
+ matrix[1][2] * temp[2];
|
||||
out[2] = matrix[2][0] * temp[0] + matrix[2][1] * temp[1]
|
||||
+ matrix[2][2] * temp[2];
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public float[] toRGB(float[] in)
|
||||
{
|
||||
return SrgbConverter.XYZtoRGB(toCIEXYZ(in));
|
||||
}
|
||||
|
||||
public float[] fromCIEXYZ(float[] in)
|
||||
{
|
||||
if (fromPCS != null)
|
||||
return fromPCS.lookup(in);
|
||||
|
||||
float[] temp = new float[3];
|
||||
float[] out = new float[3];
|
||||
|
||||
// matrix multiplication
|
||||
temp[0] = inv_matrix[0][0] * in[0] + inv_matrix[0][1] * in[1]
|
||||
+ inv_matrix[0][2] * in[2];
|
||||
temp[1] = inv_matrix[1][0] * in[0] + inv_matrix[1][1] * in[1]
|
||||
+ inv_matrix[1][2] * in[2];
|
||||
temp[2] = inv_matrix[2][0] * in[0] + inv_matrix[2][1] * in[1]
|
||||
+ inv_matrix[2][2] * in[2];
|
||||
|
||||
// device space --> linear gamma
|
||||
out[0] = rTRC.reverseLookup(temp[0]);
|
||||
out[1] = gTRC.reverseLookup(temp[1]);
|
||||
out[2] = bTRC.reverseLookup(temp[2]);
|
||||
|
||||
// FIXME: Sun appears to clip the return values to [0,1]
|
||||
// I don't believe that is a Good Thing,
|
||||
// (some colorspaces may allow values outside that range.)
|
||||
// So we return the actual values here.
|
||||
return out;
|
||||
}
|
||||
|
||||
public float[] fromRGB(float[] in)
|
||||
{
|
||||
return fromCIEXYZ(SrgbConverter.RGBtoXYZ(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inverts a 3x3 matrix, returns the inverse,
|
||||
* throws an IllegalArgumentException if the matrix is not
|
||||
* invertible (this shouldn't happen for a valid profile)
|
||||
*/
|
||||
private float[][] invertMatrix(float[][] matrix)
|
||||
{
|
||||
float[][] out = new float[3][3];
|
||||
double determinant = matrix[0][0] * (matrix[1][1] * matrix[2][2]
|
||||
- matrix[2][1] * matrix[1][2])
|
||||
- matrix[0][1] * (matrix[1][0] * matrix[2][2]
|
||||
- matrix[2][0] * matrix[1][2])
|
||||
+ matrix[0][2] * (matrix[1][0] * matrix[2][1]
|
||||
- matrix[2][0] * matrix[1][1]);
|
||||
|
||||
if (determinant == 0.0)
|
||||
throw new IllegalArgumentException("Can't invert conversion matrix.");
|
||||
float invdet = (float) (1.0 / determinant);
|
||||
|
||||
out[0][0] = invdet * (matrix[1][1] * matrix[2][2]
|
||||
- matrix[1][2] * matrix[2][1]);
|
||||
out[0][1] = invdet * (matrix[0][2] * matrix[2][1]
|
||||
- matrix[0][1] * matrix[2][2]);
|
||||
out[0][2] = invdet * (matrix[0][1] * matrix[1][2]
|
||||
- matrix[0][2] * matrix[1][1]);
|
||||
out[1][0] = invdet * (matrix[1][2] * matrix[2][0]
|
||||
- matrix[1][0] * matrix[2][2]);
|
||||
out[1][1] = invdet * (matrix[0][0] * matrix[2][2]
|
||||
- matrix[0][2] * matrix[2][0]);
|
||||
out[1][2] = invdet * (matrix[0][2] * matrix[1][0]
|
||||
- matrix[0][0] * matrix[1][2]);
|
||||
out[2][0] = invdet * (matrix[1][0] * matrix[2][1]
|
||||
- matrix[1][1] * matrix[2][0]);
|
||||
out[2][1] = invdet * (matrix[0][1] * matrix[2][0]
|
||||
- matrix[0][0] * matrix[2][1]);
|
||||
out[2][2] = invdet * (matrix[0][0] * matrix[1][1]
|
||||
- matrix[0][1] * matrix[1][0]);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,152 +0,0 @@
|
||||
/* SrgbConverter.java -- sRGB conversion class
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
|
||||
/**
|
||||
* SrgbConverter - conversion routines for the sRGB colorspace
|
||||
* sRGB is a standard for RGB colorspaces, adopted by the w3c.
|
||||
*
|
||||
* The specification is available at:
|
||||
* http://www.w3.org/Graphics/Color/sRGB.html
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* Note the matrix numbers used here are NOT identical to those in the
|
||||
* w3 spec, as those numbers are CIE XYZ relative a D65 white point.
|
||||
* The CIE XYZ we use is relative a D50 white point, so therefore a
|
||||
* linear Bradford transform matrix for D65->D50 mapping has been applied.
|
||||
* (The ICC documents describe this transform)
|
||||
*
|
||||
* Linearized Bradford transform:
|
||||
* 0.8951 0.2664 -0.1614
|
||||
* -0.7502 1.7135 0.0367
|
||||
* 0.0389 -0.0685 1.0296
|
||||
*
|
||||
* Inverse:
|
||||
* 0.9870 -0.1471 0.1600
|
||||
* 0.4323 0.5184 0.0493
|
||||
* -0.00853 0.0400 0.9685
|
||||
*/
|
||||
public class SrgbConverter implements ColorSpaceConverter
|
||||
{
|
||||
public float[] fromCIEXYZ(float[] in)
|
||||
{
|
||||
return XYZtoRGB(in);
|
||||
}
|
||||
|
||||
public float[] toCIEXYZ(float[] in)
|
||||
{
|
||||
return RGBtoXYZ(in);
|
||||
}
|
||||
|
||||
public float[] toRGB(float[] in)
|
||||
{
|
||||
float[] out = new float[3];
|
||||
System.arraycopy(in, 0, out, 0, 3);
|
||||
return out;
|
||||
}
|
||||
|
||||
public float[] fromRGB(float[] in)
|
||||
{
|
||||
float[] out = new float[3];
|
||||
System.arraycopy(in, 0, out, 0, 3);
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* CIE XYZ (D50 relative) --> sRGB
|
||||
*
|
||||
* Static as it's used by other ColorSpaceConverters to
|
||||
* convert to sRGB if the color space is defined in XYZ.
|
||||
*/
|
||||
public static float[] XYZtoRGB(float[] in)
|
||||
{
|
||||
float[] temp = new float[3];
|
||||
temp[0] = 3.1338f * in[0] - 1.6171f * in[1] - 0.4907f * in[2];
|
||||
temp[1] = -0.9785f * in[0] + 1.9160f * in[1] + 0.0334f * in[2];
|
||||
temp[2] = 0.0720f * in[0] - 0.2290f * in[1] + 1.4056f * in[2];
|
||||
|
||||
float[] out = new float[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (temp[i] < 0)
|
||||
temp[i] = 0.0f;
|
||||
if (temp[i] > 1)
|
||||
temp[i] = 1.0f;
|
||||
if (temp[i] <= 0.00304f)
|
||||
out[i] = temp[i] * 12.92f;
|
||||
else
|
||||
out[i] = 1.055f * ((float) Math.exp((1 / 2.4) * Math.log(temp[i])))
|
||||
- 0.055f;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* sRGB --> CIE XYZ (D50 relative)
|
||||
*
|
||||
* Static as it's used by other ColorSpaceConverters to
|
||||
* convert to XYZ if the color space is defined in RGB.
|
||||
*/
|
||||
public static float[] RGBtoXYZ(float[] in)
|
||||
{
|
||||
float[] temp = new float[3];
|
||||
float[] out = new float[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
if (in[i] <= 0.03928f)
|
||||
temp[i] = in[i] / 12.92f;
|
||||
else
|
||||
temp[i] = (float) Math.exp(2.4 * Math.log((in[i] + 0.055) / 1.055));
|
||||
|
||||
/*
|
||||
* Note: The numbers which were used to calculate this only had four
|
||||
* digits of accuracy. So don't be fooled by the number of digits here.
|
||||
* If someone has more accurate source, feel free to update this.
|
||||
*/
|
||||
out[0] = (float) (0.436063750222 * temp[0] + 0.385149601465 * temp[1]
|
||||
+ 0.143086418888 * temp[2]);
|
||||
out[1] = (float) (0.222450894035 * temp[0] + 0.71692584775 * temp[1]
|
||||
+ 0.060624511256 * temp[2]);
|
||||
out[2] = (float) (0.0138985186 * temp[0] + 0.097079690112 * temp[1]
|
||||
+ 0.713996045725 * temp[2]);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
/* TagEntry.java -- A utility class used for storing the tags in ICC_Profile
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
|
||||
/**
|
||||
* TagEntry - stores a profile tag.
|
||||
* These are conveniently stored in a hashtable with the tag signature
|
||||
* as a key. A legal profile can only have one tag with a given sig,
|
||||
* so we can conveniently ignore collisions.
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class TagEntry
|
||||
{
|
||||
// tag table entry size
|
||||
public static final int entrySize = 12;
|
||||
private int signature;
|
||||
private int size;
|
||||
private int offset;
|
||||
private byte[] data;
|
||||
|
||||
public TagEntry(int sig, int offset, int size, byte[] data)
|
||||
{
|
||||
this.signature = sig;
|
||||
this.offset = offset;
|
||||
this.size = size;
|
||||
this.data = new byte[size];
|
||||
System.arraycopy(data, offset, this.data, 0, size);
|
||||
}
|
||||
|
||||
public TagEntry(int sig, byte[] data)
|
||||
{
|
||||
this.signature = sig;
|
||||
this.size = data.length;
|
||||
this.data = new byte[size];
|
||||
System.arraycopy(data, offset, this.data, 0, size);
|
||||
}
|
||||
|
||||
public byte[] getData()
|
||||
{
|
||||
byte[] d = new byte[size];
|
||||
System.arraycopy(this.data, 0, d, 0, size);
|
||||
return d;
|
||||
}
|
||||
|
||||
public String hashKey()
|
||||
{
|
||||
return tagHashKey(signature);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String s = "";
|
||||
s = s + (char) ((byte) ((signature >> 24) & 0xFF));
|
||||
s = s + (char) ((byte) ((signature >> 16) & 0xFF));
|
||||
s = s + (char) ((byte) ((signature >> 8) & 0xFF));
|
||||
s = s + (char) ((byte) (signature & 0xFF));
|
||||
return s;
|
||||
}
|
||||
|
||||
public int getSignature()
|
||||
{
|
||||
return signature;
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
public int getOffset()
|
||||
{
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setOffset(int offset)
|
||||
{
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public static String tagHashKey(int sig)
|
||||
{
|
||||
return "" + sig;
|
||||
}
|
||||
}
|
||||
@@ -1,177 +0,0 @@
|
||||
/* ToneReproductionCurve.java -- Representation of an ICC 'curv' type TRC
|
||||
Copyright (C) 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 gnu.java.awt.color;
|
||||
|
||||
|
||||
/**
|
||||
* ToneReproductionCurve - TRCs are used to describe RGB
|
||||
* and Grayscale profiles. The TRC is essentially the gamma
|
||||
* function of the color space.
|
||||
*
|
||||
* For example, Apple RGB has a gamma of 1.8, most monitors are ~2.2,
|
||||
* sRGB is 2.4 with a small linear part near 0.
|
||||
* Linear spaces are of course 1.0.
|
||||
* (The exact function is implemented in SrgbConverter)
|
||||
*
|
||||
* The ICC specification allows the TRC to be described as a single
|
||||
* Gamma value, where the function is thus out = in**gamma.
|
||||
* Alternatively, the gamma function may be represented by a lookup table
|
||||
* of values, in which case linear interpolation is used.
|
||||
*
|
||||
* @author Sven de Marothy
|
||||
*/
|
||||
public class ToneReproductionCurve
|
||||
{
|
||||
private float[] trc;
|
||||
private float gamma;
|
||||
private float[] reverseTrc;
|
||||
|
||||
/**
|
||||
* Constructs a TRC from a gamma values
|
||||
*/
|
||||
public ToneReproductionCurve(float gamma)
|
||||
{
|
||||
trc = null;
|
||||
reverseTrc = null;
|
||||
this.gamma = gamma;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a TRC from a set of float values
|
||||
*/
|
||||
public ToneReproductionCurve(float[] trcValues)
|
||||
{
|
||||
trc = new float[trcValues.length];
|
||||
System.arraycopy(trcValues, 0, trc, 0, trcValues.length);
|
||||
setupReverseTrc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a TRC from a set of short values normalized to
|
||||
* the 0-65535 range (as in the ICC profile file).
|
||||
* (Note the values are treated as unsigned)
|
||||
*/
|
||||
public ToneReproductionCurve(short[] trcValues)
|
||||
{
|
||||
trc = new float[trcValues.length];
|
||||
for (int i = 0; i < trcValues.length; i++)
|
||||
trc[i] = (float) ((int) trcValues[i] & (0xFFFF)) / 65535.0f;
|
||||
setupReverseTrc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a TRC lookup
|
||||
*/
|
||||
public float lookup(float in)
|
||||
{
|
||||
float out;
|
||||
|
||||
if (trc == null)
|
||||
{
|
||||
if (in == 0f)
|
||||
return 0.0f;
|
||||
return (float) Math.exp(gamma * Math.log(in));
|
||||
}
|
||||
else
|
||||
{
|
||||
double alpha = in * (trc.length - 1);
|
||||
int index = (int) Math.floor(alpha);
|
||||
alpha = alpha - (double) index;
|
||||
if (index >= trc.length - 1)
|
||||
return trc[trc.length - 1];
|
||||
if (index <= 0)
|
||||
return trc[0];
|
||||
out = (float) (trc[index] * (1.0 - alpha) + trc[index + 1] * alpha);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs an reverse lookup
|
||||
*/
|
||||
public float reverseLookup(float in)
|
||||
{
|
||||
float out;
|
||||
|
||||
if (trc == null)
|
||||
{
|
||||
if (in == 0f)
|
||||
return 0.0f;
|
||||
return (float) Math.exp((1.0 / gamma) * Math.log(in));
|
||||
}
|
||||
else
|
||||
{
|
||||
double alpha = in * (reverseTrc.length - 1);
|
||||
int index = (int) Math.floor(alpha);
|
||||
alpha = alpha - (double) index;
|
||||
if (index >= reverseTrc.length - 1)
|
||||
return reverseTrc[reverseTrc.length - 1];
|
||||
if (index <= 0)
|
||||
return reverseTrc[0];
|
||||
out = (float) (reverseTrc[index] * (1.0 - alpha)
|
||||
+ reverseTrc[index + 1] * alpha);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates a reverse-lookup table.
|
||||
* We use a whopping 10,000 entries.. This is should be more than any
|
||||
* real-life TRC table (typically around 256-1024) so we won't be losing
|
||||
* any precision.
|
||||
*
|
||||
* This will of course generate completely invalid results if the curve
|
||||
* is not monotonic and invertable. But what's the alternative?
|
||||
*/
|
||||
public void setupReverseTrc()
|
||||
{
|
||||
reverseTrc = new float[10000];
|
||||
int j = 0;
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
float n = ((float) i) / 10000f;
|
||||
while (trc[j + 1] < n && j < trc.length - 2)
|
||||
j++;
|
||||
|
||||
if (j == trc.length - 2)
|
||||
reverseTrc[i] = trc[trc.length - 1];
|
||||
else
|
||||
reverseTrc[i] = (j + (n - trc[j]) / (trc[j + 1] - trc[j])) / ((float) trc.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 8.6 KiB |
@@ -1,156 +0,0 @@
|
||||
/* ImageDecoder.java --
|
||||
Copyright (C) 1999, 2000, 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 gnu.java.awt.image;
|
||||
|
||||
import java.awt.image.ImageConsumer;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Vector;
|
||||
|
||||
public abstract class ImageDecoder implements ImageProducer
|
||||
{
|
||||
Vector consumers = new Vector ();
|
||||
String filename;
|
||||
URL url;
|
||||
byte[] data;
|
||||
int offset;
|
||||
int length;
|
||||
InputStream input;
|
||||
|
||||
static
|
||||
{
|
||||
// FIXME: there was some broken code here that looked like
|
||||
// it wanted to rely on this property. I don't have any idea
|
||||
// what it was intended to do.
|
||||
// String endian = System.getProperties ().getProperty ("gnu.cpu.endian");
|
||||
}
|
||||
|
||||
public ImageDecoder (String filename)
|
||||
{
|
||||
this.filename = filename;
|
||||
}
|
||||
|
||||
public ImageDecoder (URL url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public ImageDecoder (InputStream is)
|
||||
{
|
||||
this.input = is;
|
||||
}
|
||||
|
||||
public ImageDecoder (byte[] imagedata, int imageoffset, int imagelength)
|
||||
{
|
||||
data = imagedata;
|
||||
offset = imageoffset;
|
||||
length = imagelength;
|
||||
}
|
||||
|
||||
public void addConsumer (ImageConsumer ic)
|
||||
{
|
||||
consumers.addElement (ic);
|
||||
}
|
||||
|
||||
public boolean isConsumer (ImageConsumer ic)
|
||||
{
|
||||
return consumers.contains (ic);
|
||||
}
|
||||
|
||||
public void removeConsumer (ImageConsumer ic)
|
||||
{
|
||||
consumers.removeElement (ic);
|
||||
}
|
||||
|
||||
public void startProduction (ImageConsumer ic)
|
||||
{
|
||||
if (!isConsumer(ic))
|
||||
addConsumer(ic);
|
||||
|
||||
Vector list = (Vector) consumers.clone ();
|
||||
try
|
||||
{
|
||||
// Create the input stream here rather than in the
|
||||
// ImageDecoder constructors so that exceptions cause
|
||||
// imageComplete to be called with an appropriate error
|
||||
// status.
|
||||
if (input == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (url != null)
|
||||
input = url.openStream();
|
||||
else
|
||||
{
|
||||
if (filename != null)
|
||||
input = new FileInputStream (filename);
|
||||
else
|
||||
input = new ByteArrayInputStream (data, offset, length);
|
||||
}
|
||||
produce (list, input);
|
||||
}
|
||||
finally
|
||||
{
|
||||
input = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
produce (list, input);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
for (int i = 0; i < list.size (); i++)
|
||||
{
|
||||
ImageConsumer ic2 = (ImageConsumer) list.elementAt (i);
|
||||
ic2.imageComplete (ImageConsumer.IMAGEERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void requestTopDownLeftRightResend (ImageConsumer ic)
|
||||
{
|
||||
}
|
||||
|
||||
public abstract void produce (Vector v, InputStream is) throws IOException;
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/* XBMDecoder.java -- Decodes X-bitmaps
|
||||
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 gnu.java.awt.image;
|
||||
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ImageConsumer;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.Vector;
|
||||
|
||||
public class XBMDecoder extends ImageDecoder
|
||||
{
|
||||
BufferedReader reader;
|
||||
static final ColorModel cm = ColorModel.getRGBdefault ();
|
||||
static final int black = 0xff000000;
|
||||
static final int transparent = 0x00000000;
|
||||
static final int masktable[] = { 0x01, 0x02, 0x04, 0x08,
|
||||
0x10, 0x20, 0x40, 0x80 };
|
||||
|
||||
public XBMDecoder (String filename)
|
||||
{
|
||||
super (filename);
|
||||
}
|
||||
|
||||
public XBMDecoder (URL url)
|
||||
{
|
||||
super (url);
|
||||
}
|
||||
|
||||
public void produce (Vector v, InputStream is) throws IOException
|
||||
{
|
||||
reader = new BufferedReader (new InputStreamReader (is));
|
||||
int width = -1, height = -1;
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
String line = reader.readLine ();
|
||||
StringTokenizer st = new StringTokenizer (line);
|
||||
|
||||
st.nextToken (); // #define
|
||||
st.nextToken (); // name_[width|height]
|
||||
if (i == 0)
|
||||
width = Integer.parseInt (st.nextToken (), 10);
|
||||
else
|
||||
height = Integer.parseInt (st.nextToken (), 10);
|
||||
}
|
||||
|
||||
for (int i = 0; i < v.size (); i++)
|
||||
{
|
||||
ImageConsumer ic = (ImageConsumer) v.elementAt (i);
|
||||
|
||||
ic.setDimensions (width, height);
|
||||
ic.setColorModel (cm);
|
||||
ic.setHints (ImageConsumer.COMPLETESCANLINES
|
||||
| ImageConsumer.SINGLEFRAME
|
||||
| ImageConsumer.SINGLEPASS
|
||||
| ImageConsumer.TOPDOWNLEFTRIGHT);
|
||||
}
|
||||
|
||||
/* skip to the byte array */
|
||||
while (reader.read () != '{') { }
|
||||
|
||||
/* loop through each scanline */
|
||||
for (int line = 0; line < height; line++)
|
||||
{
|
||||
int scanline[] = getScanline (reader, width);
|
||||
|
||||
for (int i = 0; i < v.size (); i++)
|
||||
{
|
||||
ImageConsumer ic = (ImageConsumer) v.elementAt (i);
|
||||
ic.setPixels (0, 0 + line, width, 1, cm, scanline, 0, width);
|
||||
}
|
||||
}
|
||||
|
||||
/* tell each ImageConsumer that we're finished */
|
||||
for (int i = 0; i < v.size (); i++)
|
||||
{
|
||||
ImageConsumer ic = (ImageConsumer) v.elementAt (i);
|
||||
ic.imageComplete (ImageConsumer.STATICIMAGEDONE);
|
||||
}
|
||||
}
|
||||
|
||||
public static int[] getScanline (Reader in, int len) throws IOException
|
||||
{
|
||||
char byteStr[] = new char[2];
|
||||
int scanline[] = new int[len];
|
||||
int x = 0;
|
||||
|
||||
while (x < len)
|
||||
{
|
||||
int ch = in.read ();
|
||||
if (ch == '0')
|
||||
{
|
||||
in.read (); // 'x'
|
||||
|
||||
byteStr[0] = (char) in.read ();
|
||||
byteStr[1] = (char) in.read ();
|
||||
|
||||
int byteVal = Integer.parseInt (new String (byteStr), 16);
|
||||
|
||||
for (int i = 0; i < 8; i++, x++)
|
||||
{
|
||||
if (x == len) // condition occurs if bitmap is padded
|
||||
return scanline;
|
||||
|
||||
scanline[x] = ((byteVal & masktable[i]) != 0) ?
|
||||
black : transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return scanline;
|
||||
}
|
||||
}
|
||||
@@ -1,846 +0,0 @@
|
||||
/* ClasspathFontPeer.java -- Font peer used by GNU Classpath.
|
||||
Copyright (C) 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 gnu.java.awt.peer;
|
||||
|
||||
import gnu.java.awt.ClasspathToolkit;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.font.TransformAttribute;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.peer.FontPeer;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.CharacterIterator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A peer for fonts that are used inside Classpath. The purpose of
|
||||
* this interface is to abstract from platform-specific font handling
|
||||
* in the Classpath implementation of java.awt.Font and related
|
||||
* classes.
|
||||
*
|
||||
* <p><b>State kept by the peer:</b> a peer is generated for each Font
|
||||
* object in the default implementation. If you wish to share peers between
|
||||
* fonts, you will need to subclass both ClasspathFontPeer and
|
||||
* {@link ClasspathToolKit}.</p>
|
||||
*
|
||||
* <p><b>Thread Safety:</b> Methods of this interface may be called
|
||||
* from arbitrary threads at any time. Implementations of the
|
||||
* <code>ClasspathFontPeer</code> interface are required to perform
|
||||
* the necessary synchronization.</p>
|
||||
*
|
||||
* @see java.awt.Font#getPeer
|
||||
* @see java.awt.Toolkit#getFontPeer
|
||||
*
|
||||
* @author Sascha Brawer (brawer@dandelis.ch)
|
||||
* @author Graydon Hoare (graydon@redhat.com)
|
||||
*/
|
||||
public abstract class ClasspathFontPeer
|
||||
implements FontPeer
|
||||
{
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/*
|
||||
* Instance Variables
|
||||
*/
|
||||
|
||||
/**
|
||||
* The 3 names of this font. all fonts have 3 names, some of which
|
||||
* may be equal:
|
||||
*
|
||||
* logical -- name the font was constructed from
|
||||
* family -- a designer or brand name (Helvetica)
|
||||
* face -- specific instance of a design (Helvetica Regular)
|
||||
*
|
||||
* @see isLogicalFontName
|
||||
*/
|
||||
|
||||
protected String logicalName;
|
||||
protected String familyName;
|
||||
protected String faceName;
|
||||
|
||||
/**
|
||||
* The font style, which is a combination (by OR-ing) of the font style
|
||||
* constants PLAIN, BOLD and ITALIC, in this class.
|
||||
*/
|
||||
protected int style;
|
||||
|
||||
/**
|
||||
* The font point size. A point is 1/72 of an inch.
|
||||
*/
|
||||
protected float size;
|
||||
|
||||
/**
|
||||
* The affine transformation the font is currently subject to.
|
||||
*/
|
||||
protected AffineTransform transform;
|
||||
|
||||
protected static ClasspathToolkit tk()
|
||||
{
|
||||
return (ClasspathToolkit)(Toolkit.getDefaultToolkit ());
|
||||
}
|
||||
|
||||
/*
|
||||
* Confusingly, a Logical Font is a concept unrelated to
|
||||
* a Font's Logical Name.
|
||||
*
|
||||
* A Logical Font is one of 6 built-in, abstract font types
|
||||
* which must be supported by any java environment: SansSerif,
|
||||
* Serif, Monospaced, Dialog, and DialogInput.
|
||||
*
|
||||
* A Font's Logical Name is the name the font was constructed
|
||||
* from. This might be the name of a Logical Font, or it might
|
||||
* be the name of a Font Face.
|
||||
*/
|
||||
|
||||
protected static boolean isLogicalFontName(String name)
|
||||
{
|
||||
String uname = name.toUpperCase ();
|
||||
return (uname.equals ("SANSSERIF") ||
|
||||
uname.equals ("SERIF") ||
|
||||
uname.equals ("MONOSPACED") ||
|
||||
uname.equals ("DIALOG") ||
|
||||
uname.equals ("DIALOGINPUT"));
|
||||
}
|
||||
|
||||
protected static String logicalFontNameToFaceName (String name)
|
||||
{
|
||||
String uname = name.toUpperCase ();
|
||||
if (uname.equals("SANSSERIF"))
|
||||
return "Helvetica";
|
||||
else if (uname.equals ("SERIF"))
|
||||
return "Times";
|
||||
else if (uname.equals ("MONOSPACED"))
|
||||
return "Courier";
|
||||
else if (uname.equals ("DIALOG"))
|
||||
return "Helvetica";
|
||||
else if (uname.equals ("DIALOGINPUT"))
|
||||
return "Helvetica";
|
||||
else
|
||||
return "Helvetica";
|
||||
}
|
||||
|
||||
protected static String faceNameToFamilyName (String name)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public static void copyStyleToAttrs (int style, Map attrs)
|
||||
{
|
||||
if ((style & Font.BOLD) == Font.BOLD)
|
||||
attrs.put (TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD);
|
||||
else
|
||||
attrs.put (TextAttribute.WEIGHT, TextAttribute.WEIGHT_REGULAR);
|
||||
|
||||
if ((style & Font.ITALIC) == Font.ITALIC)
|
||||
attrs.put (TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE);
|
||||
else
|
||||
attrs.put (TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR);
|
||||
}
|
||||
|
||||
protected static void copyFamilyToAttrs (String fam, Map attrs)
|
||||
{
|
||||
if (fam != null)
|
||||
attrs.put (TextAttribute.FAMILY, fam);
|
||||
}
|
||||
|
||||
public static void copySizeToAttrs (float size, Map attrs)
|
||||
{
|
||||
attrs.put (TextAttribute.SIZE, new Float (size));
|
||||
}
|
||||
|
||||
protected static void copyTransformToAttrs (AffineTransform trans, Map attrs)
|
||||
{
|
||||
if (trans != null)
|
||||
attrs.put(TextAttribute.TRANSFORM, new TransformAttribute (trans));
|
||||
}
|
||||
|
||||
|
||||
protected void setStandardAttributes (String name, String family, int style,
|
||||
float size, AffineTransform trans)
|
||||
{
|
||||
this.logicalName = name;
|
||||
|
||||
if (isLogicalFontName (name))
|
||||
this.faceName = logicalFontNameToFaceName (name);
|
||||
else
|
||||
this.faceName = name;
|
||||
|
||||
if (family != null)
|
||||
this.familyName = family;
|
||||
else
|
||||
this.familyName = faceNameToFamilyName (faceName);
|
||||
|
||||
this.style = style;
|
||||
this.size = size;
|
||||
this.transform = trans;
|
||||
}
|
||||
|
||||
|
||||
protected void setStandardAttributes (String name, Map attribs)
|
||||
{
|
||||
String family = this.familyName;
|
||||
AffineTransform trans = this.transform;
|
||||
float size = this.size;
|
||||
int style = this.style;
|
||||
|
||||
if (attribs.containsKey (TextAttribute.FAMILY))
|
||||
family = (String) attribs.get (TextAttribute.FAMILY);
|
||||
|
||||
if (name == null)
|
||||
name = "SansSerif";
|
||||
|
||||
if (attribs.containsKey (TextAttribute.WEIGHT))
|
||||
{
|
||||
Float weight = (Float) attribs.get (TextAttribute.WEIGHT);
|
||||
if (weight.floatValue () >= TextAttribute.WEIGHT_BOLD.floatValue ())
|
||||
style += Font.BOLD;
|
||||
}
|
||||
|
||||
if (attribs.containsKey (TextAttribute.POSTURE))
|
||||
{
|
||||
Float posture = (Float) attribs.get (TextAttribute.POSTURE);
|
||||
if (posture.floatValue () >= TextAttribute.POSTURE_OBLIQUE.floatValue ())
|
||||
style += Font.ITALIC;
|
||||
}
|
||||
|
||||
if (attribs.containsKey (TextAttribute.SIZE))
|
||||
{
|
||||
Float sz = (Float) attribs.get (TextAttribute.SIZE);
|
||||
size = sz.floatValue ();
|
||||
|
||||
// Pango doesn't accept 0 as a font size.
|
||||
if (size < 1)
|
||||
size = 1;
|
||||
}
|
||||
else
|
||||
size = 12;
|
||||
|
||||
if (attribs.containsKey (TextAttribute.TRANSFORM))
|
||||
{
|
||||
TransformAttribute ta = (TransformAttribute)
|
||||
attribs.get(TextAttribute.TRANSFORM);
|
||||
trans = ta.getTransform ();
|
||||
}
|
||||
|
||||
setStandardAttributes (name, family, style, size, trans);
|
||||
}
|
||||
|
||||
protected void getStandardAttributes (Map attrs)
|
||||
{
|
||||
copyFamilyToAttrs (this.familyName, attrs);
|
||||
copySizeToAttrs (this.size, attrs);
|
||||
copyStyleToAttrs (this.style, attrs);
|
||||
copyTransformToAttrs (this.transform, attrs);
|
||||
}
|
||||
|
||||
|
||||
/* Begin public API */
|
||||
|
||||
public ClasspathFontPeer (String name, Map attrs)
|
||||
{
|
||||
setStandardAttributes (name, attrs);
|
||||
}
|
||||
|
||||
public ClasspathFontPeer (String name, int style, int size)
|
||||
{
|
||||
setStandardAttributes (name, (String)null, style,
|
||||
(float)size, (AffineTransform)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getName}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public String getName (Font font)
|
||||
{
|
||||
return logicalName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getFamily()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public String getFamily (Font font)
|
||||
{
|
||||
return familyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getFamily(Locale)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public String getFamily (Font font, Locale lc)
|
||||
{
|
||||
return familyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getFontName()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public String getFontName (Font font)
|
||||
{
|
||||
return faceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getFontName(Locale)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public String getFontName (Font font, Locale lc)
|
||||
{
|
||||
return faceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getSize}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public float getSize (Font font)
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#isPlain}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public boolean isPlain (Font font)
|
||||
{
|
||||
return style == Font.PLAIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#isBold}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public boolean isBold (Font font)
|
||||
{
|
||||
return ((style & Font.BOLD) == Font.BOLD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#isItalic}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public boolean isItalic (Font font)
|
||||
{
|
||||
return ((style & Font.ITALIC) == Font.ITALIC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#deriveFont(int, float)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public Font deriveFont (Font font, int style, float size)
|
||||
{
|
||||
Map attrs = new HashMap ();
|
||||
getStandardAttributes (attrs);
|
||||
copyStyleToAttrs (style, attrs);
|
||||
copySizeToAttrs (size, attrs);
|
||||
return tk().getFont (logicalName, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#deriveFont(float)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public Font deriveFont (Font font, float size)
|
||||
{
|
||||
Map attrs = new HashMap ();
|
||||
getStandardAttributes (attrs);
|
||||
copySizeToAttrs (size, attrs);
|
||||
return tk().getFont (logicalName, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#deriveFont(int)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public Font deriveFont (Font font, int style)
|
||||
{
|
||||
Map attrs = new HashMap ();
|
||||
getStandardAttributes (attrs);
|
||||
copyStyleToAttrs (style, attrs);
|
||||
return tk().getFont (logicalName, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#deriveFont(int, AffineTransform)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public Font deriveFont (Font font, int style, AffineTransform t)
|
||||
{
|
||||
Map attrs = new HashMap ();
|
||||
getStandardAttributes (attrs);
|
||||
copyStyleToAttrs (style, attrs);
|
||||
copyTransformToAttrs (t, attrs);
|
||||
return tk().getFont (logicalName, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#deriveFont(AffineTransform)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public Font deriveFont (Font font, AffineTransform t)
|
||||
{
|
||||
Map attrs = new HashMap ();
|
||||
getStandardAttributes (attrs);
|
||||
copyTransformToAttrs (t, attrs);
|
||||
return tk().getFont (logicalName, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#deriveFont(Map)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public Font deriveFont (Font font, Map attrs)
|
||||
{
|
||||
return tk().getFont (logicalName, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getAttributes()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public Map getAttributes (Font font)
|
||||
{
|
||||
HashMap h = new HashMap ();
|
||||
getStandardAttributes (h);
|
||||
return h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getAvailableAttributes()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public AttributedCharacterIterator.Attribute[] getAvailableAttributes(Font font)
|
||||
{
|
||||
AttributedCharacterIterator.Attribute a[] =
|
||||
new AttributedCharacterIterator.Attribute[5];
|
||||
a[0] = TextAttribute.FAMILY;
|
||||
a[1] = TextAttribute.SIZE;
|
||||
a[2] = TextAttribute.POSTURE;
|
||||
a[3] = TextAttribute.WEIGHT;
|
||||
a[4] = TextAttribute.TRANSFORM;
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getTransform()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public AffineTransform getTransform (Font font)
|
||||
{
|
||||
if (transform == null)
|
||||
transform = new AffineTransform ();
|
||||
return transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#isTransformed()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public boolean isTransformed (Font font)
|
||||
{
|
||||
return ! transform.isIdentity ();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getItalicAngle()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public float getItalicAngle (Font font)
|
||||
{
|
||||
if ((style & Font.ITALIC) == Font.ITALIC)
|
||||
return TextAttribute.POSTURE_OBLIQUE.floatValue ();
|
||||
else
|
||||
return TextAttribute.POSTURE_REGULAR.floatValue ();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getStyle()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public int getStyle (Font font)
|
||||
{
|
||||
return style;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Remaining methods are abstract */
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#canDisplay(char)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract boolean canDisplay (Font font, char c);
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#canDisplay(String)},
|
||||
* {@link Font#canDisplay(char [], int, int)}, and
|
||||
* {@link Font#canDisplay(CharacterIterator, int, int)}.
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit);
|
||||
|
||||
|
||||
/**
|
||||
* Returns the name of this font face inside the family, for example
|
||||
* <i>“Light”</i>.
|
||||
*
|
||||
* <p>This method is currently not used by {@link Font}. However,
|
||||
* this name would be needed by any serious desktop publishing
|
||||
* application.
|
||||
*
|
||||
* @param font the font whose sub-family name is requested.
|
||||
*
|
||||
* @param locale the locale for which to localize the name. If
|
||||
* <code>locale</code> is <code>null</code>, the returned name is
|
||||
* localized to the user’s default locale.
|
||||
*
|
||||
* @return the name of the face inside its family, or
|
||||
* <code>null</code> if the font does not provide a sub-family name.
|
||||
*/
|
||||
|
||||
public abstract String getSubFamilyName (Font font, Locale locale);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getPSName()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract String getPostScriptName (Font font);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getNumGlyphs()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract int getNumGlyphs (Font font);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getMissingGlyphCode()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract int getMissingGlyphCode (Font font);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getBaselineFor(char)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract byte getBaselineFor (Font font, char c);
|
||||
|
||||
|
||||
/**
|
||||
* Returns a name for the specified glyph. This is useful for
|
||||
* generating PostScript or PDF files that embed some glyphs of a
|
||||
* font. If the implementation follows glyph naming conventions
|
||||
* specified by Adobe, search engines can extract the original text
|
||||
* from the generated PostScript and PDF files.
|
||||
*
|
||||
* <p>This method is currently not used by GNU Classpath. However,
|
||||
* it would be very useful for someone wishing to write a good
|
||||
* PostScript or PDF stream provider for the
|
||||
* <code>javax.print</code> package.
|
||||
*
|
||||
* <p><b>Names are not unique:</b> Under some rare circumstances,
|
||||
* the same name can be returned for different glyphs. It is
|
||||
* therefore recommended that printer drivers check whether the same
|
||||
* name has already been returned for antoher glyph, and make the
|
||||
* name unique by adding the string ".alt" followed by the glyph
|
||||
* index.</p>
|
||||
*
|
||||
* <p>This situation would occur for an OpenType or TrueType font
|
||||
* that has a <code>post</code> table of format 3 and provides a
|
||||
* mapping from glyph IDs to Unicode sequences through a
|
||||
* <code>Zapf</code> table. If the same sequence of Unicode
|
||||
* codepoints leads to different glyphs (depending on contextual
|
||||
* position, for example, or on typographic sophistication level),
|
||||
* the same name would get synthesized for those glyphs. To avoid
|
||||
* this, the font peer would have to go through the names of all
|
||||
* glyphs, which would make this operation very inefficient with
|
||||
* large fonts.
|
||||
*
|
||||
* @param font the font containing the glyph whose name is
|
||||
* requested.
|
||||
*
|
||||
* @param glyphIndex the glyph whose name the caller wants to
|
||||
* retrieve.
|
||||
*
|
||||
* @return the glyph name, or <code>null</code> if a font does not
|
||||
* provide glyph names.
|
||||
*/
|
||||
|
||||
public abstract String getGlyphName (Font font, int glyphIndex);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link
|
||||
* Font#createGlyphVector(FontRenderContext, String)}, {@link
|
||||
* Font#createGlyphVector(FontRenderContext, char[])}, and {@link
|
||||
* Font#createGlyphVector(FontRenderContext, CharacterIterator)}.
|
||||
*
|
||||
* @param font the font object that the created GlyphVector will return
|
||||
* when it gets asked for its font. This argument is needed because the
|
||||
* public API of {@link GlyphVector} works with {@link java.awt.Font},
|
||||
* not with font peers.
|
||||
*/
|
||||
|
||||
public abstract GlyphVector createGlyphVector (Font font,
|
||||
FontRenderContext frc,
|
||||
CharacterIterator ci);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#createGlyphVector(FontRenderContext,
|
||||
* int[])}.
|
||||
*
|
||||
* @param font the font object that the created GlyphVector will return
|
||||
* when it gets asked for its font. This argument is needed because the
|
||||
* public API of {@link GlyphVector} works with {@link java.awt.Font},
|
||||
* not with font peers.
|
||||
*/
|
||||
|
||||
public abstract GlyphVector createGlyphVector (Font font,
|
||||
FontRenderContext ctx,
|
||||
int[] glyphCodes);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#layoutGlyphVector(FontRenderContext,
|
||||
* char[], int, int, int)}.
|
||||
*
|
||||
* @param font the font object that the created GlyphVector will return
|
||||
* when it gets asked for its font. This argument is needed because the
|
||||
* public API of {@link GlyphVector} works with {@link java.awt.Font},
|
||||
* not with font peers.
|
||||
*/
|
||||
|
||||
public abstract GlyphVector layoutGlyphVector (Font font,
|
||||
FontRenderContext frc,
|
||||
char[] chars, int start,
|
||||
int limit, int flags);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getFontMetrics()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract FontMetrics getFontMetrics (Font font);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#hasUniformLineMetrics()}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract boolean hasUniformLineMetrics (Font font);
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getLineMetrics(CharacterIterator, int,
|
||||
* int, FontRenderContext)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract LineMetrics getLineMetrics (Font font,
|
||||
CharacterIterator ci,
|
||||
int begin, int limit,
|
||||
FontRenderContext rc);
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getMaxCharBounds(FontRenderContext)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract Rectangle2D getMaxCharBounds (Font font,
|
||||
FontRenderContext rc);
|
||||
|
||||
/**
|
||||
* Implementation of {@link Font#getStringBounds(CharacterIterator, int,
|
||||
* int, FontRenderContext)}
|
||||
*
|
||||
* @param font the font this peer is being called from. This may be
|
||||
* useful if you are sharing peers between Font objects. Otherwise it may
|
||||
* be ignored.
|
||||
*/
|
||||
|
||||
public abstract Rectangle2D getStringBounds (Font font,
|
||||
CharacterIterator ci,
|
||||
int begin, int limit,
|
||||
FontRenderContext frc);
|
||||
|
||||
}
|
||||
@@ -1,104 +0,0 @@
|
||||
/* ClasspathTextLayoutPeer.java
|
||||
Copyright (C) 2003 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 gnu.java.awt.peer;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.font.TextHitInfo;
|
||||
import java.awt.font.TextLayout;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
/**
|
||||
* @author Graydon Hoare
|
||||
*/
|
||||
|
||||
public interface ClasspathTextLayoutPeer
|
||||
{
|
||||
TextHitInfo getStrongCaret (TextHitInfo hit1,
|
||||
TextHitInfo hit2);
|
||||
|
||||
void draw (Graphics2D g2, float x, float y);
|
||||
|
||||
byte getBaseline ();
|
||||
|
||||
boolean isLeftToRight ();
|
||||
boolean isVertical ();
|
||||
|
||||
float getAdvance ();
|
||||
float getAscent ();
|
||||
float getDescent ();
|
||||
float getLeading ();
|
||||
|
||||
int getCharacterCount ();
|
||||
byte getCharacterLevel (int index);
|
||||
|
||||
float[] getBaselineOffsets ();
|
||||
Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint);
|
||||
Rectangle2D getBounds ();
|
||||
|
||||
float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds);
|
||||
Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds);
|
||||
Shape[] getCaretShapes (int offset, Rectangle2D bounds,
|
||||
TextLayout.CaretPolicy policy);
|
||||
|
||||
Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint,
|
||||
Rectangle2D bounds);
|
||||
int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint,
|
||||
TextHitInfo secondEndpoint);
|
||||
|
||||
TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy);
|
||||
TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy);
|
||||
TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds);
|
||||
TextHitInfo getVisualOtherHit (TextHitInfo hit);
|
||||
|
||||
float getVisibleAdvance ();
|
||||
Shape getOutline (AffineTransform tx);
|
||||
Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
|
||||
TextHitInfo secondEndpoint,
|
||||
Rectangle2D bounds);
|
||||
|
||||
TextLayout getJustifiedLayout (float justificationWidth);
|
||||
void handleJustify (float justificationWidth);
|
||||
|
||||
Object clone ();
|
||||
int hashCode ();
|
||||
boolean equals (ClasspathTextLayoutPeer tl);
|
||||
String toString ();
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/* EmbeddedWindowPeer.java -- Interface for window peers that may be
|
||||
embedded into other applications
|
||||
Copyright (C) 2003 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 gnu.java.awt.peer;
|
||||
|
||||
import java.awt.peer.FramePeer;
|
||||
|
||||
public interface EmbeddedWindowPeer extends FramePeer
|
||||
{
|
||||
void embed (long handle);
|
||||
}
|
||||
@@ -1,298 +0,0 @@
|
||||
/* GLightweightPeer.java --
|
||||
Copyright (C) 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 gnu.java.awt.peer;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.BufferCapabilities;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.awt.peer.ContainerPeer;
|
||||
import java.awt.peer.LightweightPeer;
|
||||
|
||||
/*
|
||||
* Another possible implementation strategy for lightweight peers is
|
||||
* to make GLightweightPeer a placeholder class that implements
|
||||
* LightweightPeer. Then the Component and Container classes could
|
||||
* identify a peer as lightweight and handle it specially. The
|
||||
* current approach is probably more clear but less efficient.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A stub class that implements the ComponentPeer and ContainerPeer
|
||||
* interfaces using callbacks into the Component and Container
|
||||
* classes. GLightweightPeer allows the Component and Container
|
||||
* classes to treat lightweight and heavyweight peers in the same way.
|
||||
*
|
||||
* Lightweight components are painted directly onto their parent
|
||||
* containers through an Image object provided by the toolkit.
|
||||
*/
|
||||
public class GLightweightPeer
|
||||
implements LightweightPeer, ContainerPeer
|
||||
{
|
||||
private Component comp;
|
||||
|
||||
private Insets containerInsets;
|
||||
|
||||
public GLightweightPeer(Component comp)
|
||||
{
|
||||
this.comp = comp;
|
||||
}
|
||||
|
||||
// -------- java.awt.peer.ContainerPeer implementation:
|
||||
|
||||
public Insets insets()
|
||||
{
|
||||
return getInsets ();
|
||||
}
|
||||
|
||||
public Insets getInsets()
|
||||
{
|
||||
if (containerInsets == null)
|
||||
containerInsets = new Insets (0,0,0,0);
|
||||
return containerInsets;
|
||||
}
|
||||
|
||||
public void beginValidate()
|
||||
{
|
||||
}
|
||||
|
||||
public void endValidate()
|
||||
{
|
||||
}
|
||||
|
||||
public void beginLayout()
|
||||
{
|
||||
}
|
||||
|
||||
public void endLayout()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isPaintPending()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// -------- java.awt.peer.ComponentPeer implementation:
|
||||
|
||||
public int checkImage(Image img, int width, int height, ImageObserver o)
|
||||
{
|
||||
return comp.getToolkit().checkImage(img, width, height, o);
|
||||
}
|
||||
|
||||
public Image createImage(ImageProducer prod)
|
||||
{
|
||||
return comp.getToolkit().createImage(prod);
|
||||
}
|
||||
|
||||
/* This method is not called. */
|
||||
public Image createImage(int width, int height)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void disable() {}
|
||||
|
||||
public void dispose() {}
|
||||
|
||||
public void enable() {}
|
||||
|
||||
public GraphicsConfiguration getGraphicsConfiguration()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public FontMetrics getFontMetrics(Font f)
|
||||
{
|
||||
return comp.getToolkit().getFontMetrics(f);
|
||||
}
|
||||
|
||||
/* Returning null here tells the Component object that called us to
|
||||
* use its parent's Graphics. */
|
||||
public Graphics getGraphics()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Point getLocationOnScreen()
|
||||
{
|
||||
Point parentLocation = comp.getParent().getLocationOnScreen();
|
||||
return new Point (parentLocation.x + comp.getX(),
|
||||
parentLocation.y + comp.getY());
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize()
|
||||
{
|
||||
return new Dimension(comp.getWidth(), comp.getHeight());
|
||||
}
|
||||
|
||||
/* A lightweight component's preferred size is equivalent to its
|
||||
* Component width and height values. */
|
||||
public Dimension getPreferredSize()
|
||||
{
|
||||
return new Dimension(comp.getWidth(), comp.getHeight());
|
||||
}
|
||||
|
||||
/* Returning null here tells the Component object that called us to
|
||||
* use its parent's Toolkit. */
|
||||
public Toolkit getToolkit()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handleEvent(AWTEvent e) {}
|
||||
|
||||
public void hide() {}
|
||||
|
||||
public boolean isFocusable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFocusTraversable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public Dimension minimumSize()
|
||||
{
|
||||
return getMinimumSize();
|
||||
}
|
||||
|
||||
public Dimension preferredSize()
|
||||
{
|
||||
return getPreferredSize();
|
||||
}
|
||||
|
||||
public void paint(Graphics graphics) {}
|
||||
|
||||
public boolean prepareImage(Image img, int width, int height,
|
||||
ImageObserver o)
|
||||
{
|
||||
return comp.getToolkit().prepareImage(img, width, height, o);
|
||||
}
|
||||
|
||||
public void print(Graphics graphics) {}
|
||||
|
||||
public void repaint(long tm, int x, int y, int width, int height) {}
|
||||
|
||||
public void requestFocus() {}
|
||||
|
||||
public boolean requestFocus(Component source, boolean bool1, boolean bool2, long x)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void reshape(int x, int y, int width, int height) {}
|
||||
|
||||
public void setBackground(Color color) {}
|
||||
|
||||
public void setBounds(int x, int y, int width, int height) {}
|
||||
|
||||
public void setCursor(Cursor cursor) {}
|
||||
|
||||
public void setEnabled(boolean enabled) {}
|
||||
|
||||
public void setEventMask(long eventMask) {}
|
||||
|
||||
public void setFont(Font font) {}
|
||||
|
||||
public void setForeground(Color color) {}
|
||||
|
||||
public void setVisible(boolean visible) {}
|
||||
|
||||
public void show() {}
|
||||
|
||||
public ColorModel getColorModel ()
|
||||
{
|
||||
return comp.getColorModel ();
|
||||
}
|
||||
|
||||
public boolean isObscured()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canDetermineObscurity()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void coalescePaintEvent(PaintEvent e) { }
|
||||
|
||||
public void updateCursorImmediately() { }
|
||||
|
||||
public VolatileImage createVolatileImage(int width, int height)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean handlesWheelScrolling()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void createBuffers(int x, BufferCapabilities capabilities)
|
||||
throws AWTException { }
|
||||
|
||||
public Image getBackBuffer()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void flip(BufferCapabilities.FlipContents contents) { }
|
||||
|
||||
public void destroyBuffers() { }
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/* GThreadMutex.java -- Implements a mutex object for glib's gthread
|
||||
abstraction, for use with GNU Classpath's --portable-native-sync option.
|
||||
This is used in gthread-jni.c
|
||||
|
||||
Copyright (C) 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
/** Implements a mutex object for glib's gthread
|
||||
abstraction, for use with GNU Classpath's --portable-native-sync option.
|
||||
This is used in gthread-jni.c.
|
||||
|
||||
We use this object to implement the POSIX semantics for Mutexes. They are
|
||||
needed are needed for the function vector that is passed to glib's
|
||||
g_thread subpackage's initialization function.
|
||||
|
||||
The GThreadMutex object itself serves as the Real Lock; if code has
|
||||
entered the monitor for this GThreadMutex object (in Java language, if
|
||||
it's synchronized on this object) then it holds the lock that this object
|
||||
represents.
|
||||
|
||||
@author Steven Augart
|
||||
May, 2004
|
||||
|
||||
|
||||
*/
|
||||
|
||||
class GThreadMutex
|
||||
{
|
||||
/** Might "lock" be locked? Is anyone waiting
|
||||
to get that lock? How long is the queue?
|
||||
|
||||
If zero, nobody holds a lock on this GThreadMutex object, and nobody is
|
||||
trying to get one. Before someone attempts to acquire a lock on this
|
||||
object, they must increment potentialLockers. After they release their
|
||||
lock on this object, they must decrement potentialLockers.
|
||||
|
||||
Access to this field is guarded by synchronizing on the object
|
||||
<code>lockForPotentialLockers</code>.
|
||||
|
||||
After construction, we only access this field via JNI.
|
||||
*/
|
||||
volatile int potentialLockers;
|
||||
|
||||
/** An object to synchronize to if you want to examine or modify the
|
||||
<code>potentialLockers</code> field. Only hold this lock for brief
|
||||
moments, just long enough to check or set the value of
|
||||
<code>lockForPotentialLockers</code>.
|
||||
|
||||
We use this representation so that g_thread_mutex_trylock() will work
|
||||
with the POSIX semantics. This is the only case in which you ever hold a
|
||||
lock on <code>lockForPotentialLockers</code> while trying to get another
|
||||
lock -- if you are the mutex_trylock() implementation, and you have just
|
||||
checked that <code>potentialLockers</code> has the value zero. In that
|
||||
case, mutex_trylock() holds the lock on lockForPotentialLockers so that
|
||||
another thread calling mutex_trylock() or mutex_lock() won't increment
|
||||
potentialLockers after we've checked it and before we've gained the lock
|
||||
on the POSIX mutex. Of course, in that case the operation of gaining
|
||||
the POSIX lock itself will succeed immediately, and once it has
|
||||
succeeded, trylock releases lockForPotentialLockers right away,
|
||||
incremented to 1 (one).
|
||||
|
||||
After construction, we only access this field via JNI.
|
||||
*/
|
||||
Object lockForPotentialLockers;
|
||||
|
||||
GThreadMutex()
|
||||
{
|
||||
potentialLockers = 0;
|
||||
lockForPotentialLockers = new Object();
|
||||
}
|
||||
}
|
||||
// Local Variables:
|
||||
// c-file-style: "gnu"
|
||||
// End:
|
||||
@@ -1,303 +0,0 @@
|
||||
/* GThreadNativeMethodRunner.java -- Implements pthread_create(), under
|
||||
glib's gthread abstraction, for use with GNU Classpath's
|
||||
--portable-native-sync option.
|
||||
This is used by gthread-jni.c
|
||||
|
||||
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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/** Implements pthread_create(), under glib's gthread abstraction, for use
|
||||
with GNU Classpath's --portable-native-sync option. This is used in
|
||||
gthread-jni.c
|
||||
|
||||
Also implements a registry for threads, mapping Thread objects to small
|
||||
integers. The registry uses weak references for threads that aren't
|
||||
joinable, so that they will be garbage collected.
|
||||
|
||||
There are a number of possible alternative implementations.
|
||||
|
||||
|
||||
The rest of this comment consists of an answer to a question that was
|
||||
raised on the commit-classpath mailing list:
|
||||
|
||||
Mark Wielaard wrote:
|
||||
|
||||
> Can't we assume that jobject and gpointer are both (void *) so we don't
|
||||
> need the int <-> Thread (global jobject ref) mapping?
|
||||
> Maybe there are platforms where jobject and gpointer aren't the same,
|
||||
> but I guess that is pretty unlikely.
|
||||
|
||||
|
||||
I agree with you on the pointer size issues. A gpointer is a void *, so
|
||||
it's certainly guaranteed to be at least as large as any other
|
||||
pointer. And a jobject is implicitly an opaque pointer (in Jikes RVM, we
|
||||
use small integers, but we coerce them into the representation of a
|
||||
pointer).
|
||||
|
||||
The int <==> Thread mapping addresses a different issue. I realize that I
|
||||
did not document this properly (two and a half lines in thread_create),
|
||||
and the point is subtle (at least to me; took me a while to figure out).
|
||||
|
||||
The int => Thread mapping always returns jobjects that are local
|
||||
references, not global ones. This is because Thread objects need to be
|
||||
able to go away and be garbage collected after the thread they refer to
|
||||
has died.
|
||||
|
||||
If we keep a global object reference to a thread, then when do we delete
|
||||
that global object reference? We have an answer in the case of GThread
|
||||
objects that were explicitly created with the joinable attribute. It is
|
||||
safe for us to maintain a global reference to any joinable thread, since
|
||||
the joinable thread must linger (even if only in a zombie state)
|
||||
until it's explicitly joined via a g_thread_join() call. The global ref
|
||||
could be cleaned up at that point too.
|
||||
|
||||
However, in the case of GThreads that were created non-joinable by
|
||||
g_thread_create(), and in the case of Java threads that were created
|
||||
within pure Java code (not via g_thread_create()), we don't want them to
|
||||
linger forever, and there is no way to tell when the last reference
|
||||
to such threads needs to expire. In the case of this application -- AWT
|
||||
with GTK peers -- it would probably be safe anyway, since there are not
|
||||
very many threads we create, but I was going for correctness even in the
|
||||
case of long-running programs that might set up and tear down AWT
|
||||
interfaces many times.
|
||||
|
||||
So, I duplicated the POSIX thread-ID semantics. The thread ID of a
|
||||
non-joinable thread remains valid as long as that thread is still alive.
|
||||
Once that thread dies, the old thread ID may be reused at any moment. And
|
||||
that's why the array indexed by thread ID numbers is an array of weak
|
||||
references.
|
||||
|
||||
That's also why the int => Thread jobject mapping function always returns
|
||||
local references, since global references would lock the Thread in memory
|
||||
forever.
|
||||
|
||||
I would dearly love there to be a cleaner solution. I dislike the
|
||||
repeated dips from C code into Java that are necessary to look up thread
|
||||
ID numbers. If anyone can think of one, I'm all ears.
|
||||
*/
|
||||
|
||||
class GThreadNativeMethodRunner
|
||||
extends Thread
|
||||
{
|
||||
/** The C function pointer that was passed to g_thread_create().
|
||||
Specifically, this the numeric address of an object of
|
||||
C type "void *(*funcPtr)(void *funcArg)".
|
||||
*/
|
||||
private final long funcPtr;
|
||||
|
||||
/** The argument for the function "funcPtr(funcArg)". */
|
||||
private final long funcArg;
|
||||
|
||||
GThreadNativeMethodRunner(long funcPtr, long funcArg, boolean joinable)
|
||||
{
|
||||
this.funcPtr = funcPtr;
|
||||
this.funcArg = funcArg;
|
||||
|
||||
if (joinable)
|
||||
registerSelfJoinable();
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
nativeRun(funcPtr, funcArg);
|
||||
}
|
||||
|
||||
private native void nativeRun(long funcPtr, long funcArg);
|
||||
|
||||
/** THREADS is an array of threads, indexed by thread ID codes. Not sure
|
||||
whether this is the "best" approach but it does make it O(1) to look up a
|
||||
thread by its ID.
|
||||
|
||||
Zero is a valid thread ID code. Any negative number is invalid.
|
||||
|
||||
Possible future fixes (TODO?)
|
||||
|
||||
- The THREADS array will only grow. probably not a problem.
|
||||
But we could keep count when nulling entries and shrink when we have
|
||||
lots of nulls at the end. Probably not worth it. --mjw
|
||||
|
||||
- Could make this a set of Object; see the comment on "joinable" below.
|
||||
|
||||
The initial size of 17 is just a starting point. Any number will do,
|
||||
including zero.
|
||||
*/
|
||||
private static WeakReference[] threads = new WeakReference[17];
|
||||
|
||||
/** Used by threadToThreadID, below. Returns the registration number of
|
||||
the newly-registered thread.
|
||||
*/
|
||||
private static synchronized int registerThread(Thread t)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < threads.length; ++i)
|
||||
{
|
||||
WeakReference ref = threads[i];
|
||||
if (ref == null)
|
||||
break; // found an empty spot.
|
||||
}
|
||||
|
||||
if (i == threads.length)
|
||||
{
|
||||
/* expand the array */
|
||||
WeakReference[] bigger = new WeakReference[threads.length * 2];
|
||||
System.arraycopy(threads, 0, bigger, 0, threads.length);
|
||||
threads = bigger;
|
||||
}
|
||||
|
||||
threads[i] = new WeakReference(t);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/** Look up the Thread ID # for a Thread. Assign a Thread ID # if none
|
||||
exists. This is a general routine for handling all threads, including
|
||||
the VM's main thread, if appropriate.
|
||||
|
||||
|
||||
Runs in O(n/2) time.
|
||||
|
||||
We can't just issue a threadID upon thread creation. If we were to do
|
||||
that, not all threads would have a threadID, because not all threads
|
||||
are launched by GThreadNativeMethodRunner.
|
||||
*/
|
||||
static synchronized int threadToThreadID(Thread t)
|
||||
{
|
||||
for (int i = 0; i < threads.length; ++i )
|
||||
{
|
||||
if (threads[i] == null)
|
||||
continue;
|
||||
Thread referent = (Thread) threads[i].get();
|
||||
if (referent == null)
|
||||
{
|
||||
threads[i] = null; // Purge the dead WeakReference.
|
||||
continue;
|
||||
}
|
||||
if (referent.equals(t))
|
||||
return i;
|
||||
} // for()
|
||||
|
||||
/* No match found. */
|
||||
return registerThread(t);
|
||||
}
|
||||
|
||||
/** @param threadID Must be a non-negative integer.
|
||||
|
||||
Used to return null if the thread number was out of range or if
|
||||
the thread was unregistered. Now we throw an exception.
|
||||
|
||||
Possible Alternative Interface: We could go back to returning null in
|
||||
some sort of check-free mode, so code that calls this function must
|
||||
be prepared to get null.
|
||||
*/
|
||||
static Thread threadIDToThread(int threadID)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (threadID < 0)
|
||||
throw new IllegalArgumentException("Received a negative threadID, "
|
||||
+ threadID);
|
||||
if (threadID >= threads.length)
|
||||
throw new IllegalArgumentException("Received a threadID (" + threadID
|
||||
+ ") higher than was"
|
||||
+ " ever issued");
|
||||
|
||||
/* Note: if the user is using a stale reference, things will just
|
||||
break. We might end up getting a different thread than the one
|
||||
expected.
|
||||
|
||||
TODO: Add an error-checking mode where the user's problems with threads
|
||||
are announced. For instance, if the user asks for the thread
|
||||
associated with a threadID that was never issued, we could print a
|
||||
warning or even abort.
|
||||
|
||||
TODO: Consider optionally disabling all of the error-checking we
|
||||
already have; it probably slows down the implementation. We could
|
||||
just return NULL. This is just the reverse of the above TODO item.
|
||||
*/
|
||||
|
||||
WeakReference threadRef = threads[threadID];
|
||||
|
||||
if (threadRef == null)
|
||||
throw new IllegalArgumentException("Asked to look up a stale or unissued"
|
||||
+ "threadID (" + threadID + ")" );
|
||||
|
||||
|
||||
Thread referent = (Thread) threadRef.get();
|
||||
if (referent == null)
|
||||
throw new IllegalArgumentException ("Asked to look up a stale threadID ("
|
||||
+ threadID + ")");
|
||||
return referent;
|
||||
}
|
||||
|
||||
/** Joinable threads need a hard reference, so that they won't go away when
|
||||
they die. That is because their thread IDs need to stay valid until the
|
||||
thread is joined via thread_join(threadID). Joinable threads have to be
|
||||
explicitly joined before they are allowed to go away completely.
|
||||
|
||||
Possible Alternative Implementation: Eliminate the Joinable set. When
|
||||
calling getThreadIDFromThread() you know whether or not the thread
|
||||
is joinable. So just store the Thread itself in the threads array?
|
||||
Make that array an Object array and check with instanceof. This
|
||||
looks cleaner and more robust to me and it saves a native -> Java
|
||||
call. But instanceof might be expensive. --mjw
|
||||
*/
|
||||
private static final Set joinable =
|
||||
Collections.synchronizedSet(new HashSet());
|
||||
|
||||
/** Only called from the constructor. */
|
||||
private void registerSelfJoinable()
|
||||
{
|
||||
joinable.add(this);
|
||||
}
|
||||
|
||||
/** This method is only called from JNI, and only after we have succeeded in
|
||||
a thread_join() operation. */
|
||||
static void deRegisterJoinable(Thread thread)
|
||||
{
|
||||
joinable.remove(thread);
|
||||
}
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// c-file-style: "gnu"
|
||||
// End:
|
||||
@@ -1,134 +0,0 @@
|
||||
/* GdkFontMetrics.java
|
||||
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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import gnu.java.awt.ClasspathToolkit;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
public class GdkFontMetrics extends FontMetrics
|
||||
{
|
||||
|
||||
private int[] font_metrics;
|
||||
GdkFontPeer peer;
|
||||
|
||||
static final int FONT_METRICS_ASCENT = 0;
|
||||
static final int FONT_METRICS_MAX_ASCENT = 1;
|
||||
static final int FONT_METRICS_DESCENT = 2;
|
||||
static final int FONT_METRICS_MAX_DESCENT = 3;
|
||||
static final int FONT_METRICS_MAX_ADVANCE = 4;
|
||||
|
||||
static final int TEXT_METRICS_X_BEARING = 0;
|
||||
static final int TEXT_METRICS_Y_BEARING = 1;
|
||||
static final int TEXT_METRICS_WIDTH = 2;
|
||||
static final int TEXT_METRICS_HEIGHT = 3;
|
||||
static final int TEXT_METRICS_X_ADVANCE = 4;
|
||||
static final int TEXT_METRICS_Y_ADVANCE = 5;
|
||||
|
||||
|
||||
public GdkFontMetrics (Font font)
|
||||
{
|
||||
super (font.getPeer() instanceof GdkFontPeer
|
||||
? font
|
||||
: ((ClasspathToolkit)(Toolkit.getDefaultToolkit ()))
|
||||
.getFont (font.getName(), font.getAttributes ()));
|
||||
|
||||
peer = (GdkFontPeer) this.font.getPeer();
|
||||
|
||||
font_metrics = new int[5];
|
||||
double [] hires = new double[5];
|
||||
peer.getFontMetrics (hires);
|
||||
for (int i = 0; i < 5; ++i)
|
||||
font_metrics[i] = (int) hires[i];
|
||||
}
|
||||
|
||||
public int stringWidth (String str)
|
||||
{
|
||||
double [] hires = new double[6];
|
||||
peer.getTextMetrics(str, hires);
|
||||
return (int) hires [TEXT_METRICS_WIDTH];
|
||||
}
|
||||
|
||||
public int charWidth (char ch)
|
||||
{
|
||||
return stringWidth (new String (new char[] { ch }));
|
||||
}
|
||||
|
||||
public int charsWidth (char data[], int off, int len)
|
||||
{
|
||||
return stringWidth (new String (data, off, len));
|
||||
}
|
||||
|
||||
/*
|
||||
Sun's Motif implementation always returns 0 or 1 here (???), but
|
||||
going by the X11 man pages, it seems as though we should return
|
||||
font.ascent + font.descent.
|
||||
*/
|
||||
public int getLeading ()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getAscent ()
|
||||
{
|
||||
return font_metrics[FONT_METRICS_ASCENT];
|
||||
}
|
||||
|
||||
public int getMaxAscent ()
|
||||
{
|
||||
return font_metrics[FONT_METRICS_MAX_ASCENT];
|
||||
}
|
||||
|
||||
public int getDescent ()
|
||||
{
|
||||
return font_metrics[FONT_METRICS_DESCENT];
|
||||
}
|
||||
|
||||
public int getMaxDescent ()
|
||||
{
|
||||
return font_metrics[FONT_METRICS_MAX_DESCENT];
|
||||
}
|
||||
|
||||
public int getMaxAdvance ()
|
||||
{
|
||||
return font_metrics[FONT_METRICS_MAX_ADVANCE];
|
||||
}
|
||||
}
|
||||
@@ -1,307 +0,0 @@
|
||||
/* GdkFontPeer.java -- Implements FontPeer with GTK+
|
||||
Copyright (C) 1999, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import gnu.classpath.Configuration;
|
||||
import gnu.java.awt.peer.ClasspathFontPeer;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.text.CharacterIterator;
|
||||
import java.text.StringCharacterIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class GdkFontPeer extends ClasspathFontPeer
|
||||
{
|
||||
static native void initStaticState();
|
||||
private final int native_state = GtkGenericPeer.getUniqueInteger ();
|
||||
private static ResourceBundle bundle;
|
||||
|
||||
static
|
||||
{
|
||||
if (Configuration.INIT_LOAD_LIBRARY)
|
||||
{
|
||||
System.loadLibrary("gtkpeer");
|
||||
}
|
||||
|
||||
initStaticState ();
|
||||
|
||||
try
|
||||
{
|
||||
bundle = ResourceBundle.getBundle ("gnu.java.awt.peer.gtk.font");
|
||||
}
|
||||
catch (Throwable ignored)
|
||||
{
|
||||
bundle = null;
|
||||
}
|
||||
}
|
||||
|
||||
private native void initState ();
|
||||
private native void dispose ();
|
||||
private native void setFont (String family, int style, int size, boolean useGraphics2D);
|
||||
|
||||
native void getFontMetrics(double [] metrics);
|
||||
native void getTextMetrics(String str, double [] metrics);
|
||||
|
||||
protected void finalize ()
|
||||
{
|
||||
if (GtkToolkit.useGraphics2D ())
|
||||
GdkGraphics2D.releasePeerGraphicsResource(this);
|
||||
dispose ();
|
||||
}
|
||||
|
||||
/*
|
||||
* Helpers for the 3-way overloading that this class seems to suffer
|
||||
* from. Remove them if you feel like they're a performance bottleneck,
|
||||
* for the time being I prefer my code not be written and debugged in
|
||||
* triplicate.
|
||||
*/
|
||||
|
||||
private String buildString(CharacterIterator iter)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next())
|
||||
sb.append(c);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String buildString(CharacterIterator iter, int begin, int limit)
|
||||
{
|
||||
StringBuffer sb = new StringBuffer();
|
||||
int i = 0;
|
||||
for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next(), i++)
|
||||
{
|
||||
if (begin <= i)
|
||||
sb.append(c);
|
||||
if (limit <= i)
|
||||
break;
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String buildString(char[] chars, int begin, int limit)
|
||||
{
|
||||
return new String(chars, begin, limit - begin);
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
|
||||
public GdkFontPeer (String name, int style)
|
||||
{
|
||||
// All fonts get a default size of 12 if size is not specified.
|
||||
this(name, style, 12);
|
||||
}
|
||||
|
||||
public GdkFontPeer (String name, int style, int size)
|
||||
{
|
||||
super(name, style, size);
|
||||
initState ();
|
||||
setFont (this.familyName, this.style, (int)this.size,
|
||||
GtkToolkit.useGraphics2D());
|
||||
}
|
||||
|
||||
public GdkFontPeer (String name, Map attributes)
|
||||
{
|
||||
super(name, attributes);
|
||||
initState ();
|
||||
setFont (this.familyName, this.style, (int)this.size,
|
||||
GtkToolkit.useGraphics2D());
|
||||
}
|
||||
|
||||
public String getSubFamilyName(Font font, Locale locale)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getPostScriptName(Font font)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canDisplay (Font font, char c)
|
||||
{
|
||||
// FIXME: inquire with pango
|
||||
return true;
|
||||
}
|
||||
|
||||
public int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit)
|
||||
{
|
||||
// FIXME: inquire with pango
|
||||
return -1;
|
||||
}
|
||||
|
||||
private native GdkGlyphVector getGlyphVector(String txt,
|
||||
Font f,
|
||||
FontRenderContext ctx);
|
||||
|
||||
public GlyphVector createGlyphVector (Font font,
|
||||
FontRenderContext ctx,
|
||||
CharacterIterator i)
|
||||
{
|
||||
return getGlyphVector(buildString (i), font, ctx);
|
||||
}
|
||||
|
||||
public GlyphVector createGlyphVector (Font font,
|
||||
FontRenderContext ctx,
|
||||
int[] glyphCodes)
|
||||
{
|
||||
return null;
|
||||
// return new GdkGlyphVector (font, this, ctx, glyphCodes);
|
||||
}
|
||||
|
||||
public byte getBaselineFor (Font font, char c)
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
protected class GdkFontLineMetrics extends LineMetrics
|
||||
{
|
||||
FontMetrics fm;
|
||||
int nchars;
|
||||
|
||||
public GdkFontLineMetrics (FontMetrics m, int n)
|
||||
{
|
||||
fm = m;
|
||||
nchars = n;
|
||||
}
|
||||
|
||||
public float getAscent()
|
||||
{
|
||||
return (float) fm.getAscent ();
|
||||
}
|
||||
|
||||
public int getBaselineIndex()
|
||||
{
|
||||
return Font.ROMAN_BASELINE;
|
||||
}
|
||||
|
||||
public float[] getBaselineOffsets()
|
||||
{
|
||||
return new float[3];
|
||||
}
|
||||
|
||||
public float getDescent()
|
||||
{
|
||||
return (float) fm.getDescent ();
|
||||
}
|
||||
|
||||
public float getHeight()
|
||||
{
|
||||
return (float) fm.getHeight ();
|
||||
}
|
||||
|
||||
public float getLeading() { return 0.f; }
|
||||
public int getNumChars() { return nchars; }
|
||||
public float getStrikethroughOffset() { return 0.f; }
|
||||
public float getStrikethroughThickness() { return 0.f; }
|
||||
public float getUnderlineOffset() { return 0.f; }
|
||||
public float getUnderlineThickness() { return 0.f; }
|
||||
|
||||
}
|
||||
|
||||
public LineMetrics getLineMetrics (Font font, CharacterIterator ci,
|
||||
int begin, int limit, FontRenderContext rc)
|
||||
{
|
||||
return new GdkFontLineMetrics (getFontMetrics (font), limit - begin);
|
||||
}
|
||||
|
||||
public Rectangle2D getMaxCharBounds (Font font, FontRenderContext rc)
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public int getMissingGlyphCode (Font font)
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public String getGlyphName (Font font, int glyphIndex)
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public int getNumGlyphs (Font font)
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public Rectangle2D getStringBounds (Font font, CharacterIterator ci,
|
||||
int begin, int limit, FontRenderContext frc)
|
||||
{
|
||||
GdkGlyphVector gv = getGlyphVector(buildString (ci, begin, limit), font, frc);
|
||||
return gv.getVisualBounds();
|
||||
}
|
||||
|
||||
public boolean hasUniformLineMetrics (Font font)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public GlyphVector layoutGlyphVector (Font font, FontRenderContext frc,
|
||||
char[] chars, int start, int limit,
|
||||
int flags)
|
||||
{
|
||||
int nchars = (limit - start) + 1;
|
||||
char[] nc = new char[nchars];
|
||||
|
||||
for (int i = 0; i < nchars; ++i)
|
||||
nc[i] = chars[start + i];
|
||||
|
||||
return createGlyphVector (font, frc,
|
||||
new StringCharacterIterator (new String (nc)));
|
||||
}
|
||||
|
||||
public LineMetrics getLineMetrics (Font font, String str,
|
||||
FontRenderContext frc)
|
||||
{
|
||||
return new GdkFontLineMetrics (getFontMetrics (font), str.length ());
|
||||
}
|
||||
|
||||
public FontMetrics getFontMetrics (Font font)
|
||||
{
|
||||
return new GdkFontMetrics (font);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,359 +0,0 @@
|
||||
/* GdkGlyphVector.java -- Glyph vector object
|
||||
Copyright (C) 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphJustificationInfo;
|
||||
import java.awt.font.GlyphMetrics;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
public class GdkGlyphVector extends GlyphVector
|
||||
{
|
||||
|
||||
/* We use a simple representation for glyph vectors here. Glyph i
|
||||
* consumes 8 doubles:
|
||||
*
|
||||
* logical x: extents[ 10*i ]
|
||||
* logical y: extents[ 10*i + 1 ]
|
||||
* logical width: extents[ 10*i + 2 ]
|
||||
* logical height: extents[ 10*i + 3 ]
|
||||
*
|
||||
* visual x: extents[ 10*i + 4 ]
|
||||
* visual y: extents[ 10*i + 5 ]
|
||||
* visual width: extents[ 10*i + 6 ]
|
||||
* visual height: extents[ 10*i + 7 ]
|
||||
*
|
||||
* origin pos x: extents[ 10*i + 8 ]
|
||||
* origin pos y: extents[ 10*i + 9 ]
|
||||
*
|
||||
* as well as one int, code[i], representing the glyph code in the font.
|
||||
*/
|
||||
|
||||
double [] extents;
|
||||
int [] codes;
|
||||
|
||||
Font font;
|
||||
FontRenderContext fontRenderContext;
|
||||
|
||||
Rectangle2D allLogical;
|
||||
Rectangle2D allVisual;
|
||||
|
||||
public GdkGlyphVector(double[] extents, int[] codes, Font font, FontRenderContext frc)
|
||||
{
|
||||
this.extents = extents;
|
||||
this.codes = codes;
|
||||
this.font = font;
|
||||
this.fontRenderContext = frc;
|
||||
|
||||
allLogical = new Rectangle2D.Double();
|
||||
allVisual = new Rectangle2D.Double();
|
||||
|
||||
for (int i = 0; i < codes.length; ++i)
|
||||
{
|
||||
allLogical.add (new Rectangle2D.Double(extents[10*i ] + extents[10*i + 8],
|
||||
extents[10*i + 1] + extents[10*i + 9],
|
||||
extents[10*i + 2],
|
||||
extents[10*i + 3]));
|
||||
|
||||
allVisual.add (new Rectangle2D.Double(extents[10*i + 4] + extents[10*i + 8],
|
||||
extents[10*i + 5] + extents[10*i + 9],
|
||||
extents[10*i + 6],
|
||||
extents[10*i + 7]));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
geometric notes:
|
||||
|
||||
the FRC contains a mapping from points -> pixels.
|
||||
|
||||
typographics points are typically 1/72 of an inch.
|
||||
|
||||
pixel displays are often around 72 dpi.
|
||||
|
||||
so the FRC can get away with using an identity transform on a screen,
|
||||
often. behavior is documented by sun to fall back to an identity
|
||||
transform if the internal transformation is null.
|
||||
|
||||
coordinates coming up from pango are expressed as floats -- in device
|
||||
space, so basically pixels-with-fractional-bits -- derived from their
|
||||
storage format in pango (1024ths of pixels).
|
||||
|
||||
it is not clear from the javadocs whether the results of methods like
|
||||
getGlyphPositions ought to return coordinates in device space, or
|
||||
"point" space, or what. for now I'm returning them in device space.
|
||||
|
||||
*/
|
||||
|
||||
public double[] getExtents()
|
||||
{
|
||||
return extents;
|
||||
}
|
||||
|
||||
public int[] getCodes()
|
||||
{
|
||||
return codes;
|
||||
}
|
||||
|
||||
public Font getFont ()
|
||||
{
|
||||
return font;
|
||||
}
|
||||
|
||||
public FontRenderContext getFontRenderContext ()
|
||||
{
|
||||
return fontRenderContext;
|
||||
}
|
||||
|
||||
public int getGlyphCharIndex (int glyphIndex)
|
||||
{
|
||||
// FIXME: currently pango does not provide glyph-by-glyph
|
||||
// reverse mapping information, so we assume a broken 1:1
|
||||
// glyph model here. This is plainly wrong.
|
||||
return glyphIndex;
|
||||
}
|
||||
|
||||
public int[] getGlyphCharIndices (int beginGlyphIndex,
|
||||
int numEntries,
|
||||
int[] codeReturn)
|
||||
{
|
||||
int ix[] = codeReturn;
|
||||
if (ix == null)
|
||||
ix = new int[numEntries];
|
||||
|
||||
for (int i = 0; i < numEntries; i++)
|
||||
ix[i] = getGlyphCharIndex (beginGlyphIndex + i);
|
||||
return ix;
|
||||
}
|
||||
|
||||
public int getGlyphCode (int glyphIndex)
|
||||
{
|
||||
return codes[glyphIndex];
|
||||
}
|
||||
|
||||
public int[] getGlyphCodes (int beginGlyphIndex, int numEntries,
|
||||
int[] codeReturn)
|
||||
{
|
||||
if (codeReturn == null)
|
||||
codeReturn = new int[numEntries];
|
||||
|
||||
System.arraycopy(codes, beginGlyphIndex, codeReturn, 0, numEntries);
|
||||
return codeReturn;
|
||||
}
|
||||
|
||||
public Shape getGlyphLogicalBounds (int i)
|
||||
{
|
||||
return new Rectangle2D.Double (extents[8*i], extents[8*i + 1],
|
||||
extents[8*i + 2], extents[8*i + 3]);
|
||||
}
|
||||
|
||||
public GlyphMetrics getGlyphMetrics (int i)
|
||||
{
|
||||
// FIXME: pango does not yield vertical layout information at the
|
||||
// moment.
|
||||
|
||||
boolean is_horizontal = true;
|
||||
double advanceX = extents[8*i + 2]; // "logical width" == advanceX
|
||||
double advanceY = 0;
|
||||
|
||||
return new GlyphMetrics (is_horizontal,
|
||||
(float) advanceX, (float) advanceY,
|
||||
(Rectangle2D) getGlyphVisualBounds(i),
|
||||
GlyphMetrics.STANDARD);
|
||||
}
|
||||
|
||||
public Shape getGlyphOutline (int glyphIndex)
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public Shape getGlyphOutline (int glyphIndex, float x, float y)
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public Rectangle getGlyphPixelBounds (int i,
|
||||
FontRenderContext renderFRC,
|
||||
float x, float y)
|
||||
{
|
||||
return new Rectangle((int) x, (int) y,
|
||||
(int) extents[8*i + 6], (int) extents[8*i + 7]);
|
||||
}
|
||||
|
||||
public Point2D getGlyphPosition (int i)
|
||||
{
|
||||
return new Point2D.Double (extents[10*i + 8],
|
||||
extents[10*i + 9]);
|
||||
}
|
||||
|
||||
public float[] getGlyphPositions (int beginGlyphIndex,
|
||||
int numEntries,
|
||||
float[] positionReturn)
|
||||
{
|
||||
float fx[] = positionReturn;
|
||||
if (fx == null)
|
||||
fx = new float[numEntries * 2];
|
||||
|
||||
for (int i = 0; i < numEntries; ++i)
|
||||
{
|
||||
fx[2*i ] = (float) extents[10*i + 8];
|
||||
fx[2*i + 1] = (float) extents[10*i + 9];
|
||||
}
|
||||
return fx;
|
||||
}
|
||||
|
||||
public AffineTransform getGlyphTransform (int glyphIndex)
|
||||
{
|
||||
// Glyphs don't have independent transforms in these simple glyph
|
||||
// vectors; docs specify null is an ok return here.
|
||||
return null;
|
||||
}
|
||||
|
||||
public Shape getGlyphVisualBounds (int i)
|
||||
{
|
||||
return new Rectangle2D.Double(extents[8*i + 4], extents[8*i + 5],
|
||||
extents[8*i + 6], extents[8*i + 7]);
|
||||
}
|
||||
|
||||
public int getLayoutFlags ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Rectangle2D getLogicalBounds ()
|
||||
{
|
||||
return allLogical;
|
||||
}
|
||||
|
||||
public int getNumGlyphs ()
|
||||
{
|
||||
return codes.length;
|
||||
}
|
||||
|
||||
public Shape getOutline ()
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public Rectangle getPixelBounds (FontRenderContext renderFRC,
|
||||
float x, float y)
|
||||
{
|
||||
return new Rectangle((int)x,
|
||||
(int)y,
|
||||
(int) allVisual.getWidth(),
|
||||
(int) allVisual.getHeight());
|
||||
}
|
||||
|
||||
public Rectangle2D getVisualBounds ()
|
||||
{
|
||||
return allVisual;
|
||||
}
|
||||
|
||||
public void performDefaultLayout ()
|
||||
{
|
||||
}
|
||||
|
||||
public void setGlyphPosition (int i, Point2D newPos)
|
||||
{
|
||||
extents[8*i ] = newPos.getX();
|
||||
extents[8*i + 1] = newPos.getY();
|
||||
|
||||
extents[8*i + 4] = newPos.getX();
|
||||
extents[8*i + 5] = newPos.getY();
|
||||
}
|
||||
|
||||
public void setGlyphTransform (int glyphIndex,
|
||||
AffineTransform newTX)
|
||||
{
|
||||
// not yet.. maybe not ever?
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public boolean equals(GlyphVector gv)
|
||||
{
|
||||
if (gv == null)
|
||||
return false;
|
||||
|
||||
if (! (gv instanceof GdkGlyphVector))
|
||||
return false;
|
||||
|
||||
GdkGlyphVector ggv = (GdkGlyphVector) gv;
|
||||
|
||||
if ((ggv.codes.length != this.codes.length)
|
||||
|| (ggv.extents.length != this.extents.length))
|
||||
return false;
|
||||
|
||||
if ((ggv.font == null && this.font != null)
|
||||
|| (ggv.font != null && this.font == null)
|
||||
|| (!ggv.font.equals(this.font)))
|
||||
return false;
|
||||
|
||||
if ((ggv.fontRenderContext == null && this.fontRenderContext != null)
|
||||
|| (ggv.fontRenderContext != null && this.fontRenderContext == null)
|
||||
|| (!ggv.fontRenderContext.equals(this.fontRenderContext)))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < ggv.codes.length; ++i)
|
||||
if (ggv.codes[i] != this.codes[i])
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < ggv.extents.length; ++i)
|
||||
if (ggv.extents[i] != this.extents[i])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public GlyphJustificationInfo getGlyphJustificationInfo(int idx)
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public Shape getOutline(float x, float y)
|
||||
{
|
||||
throw new UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,487 +0,0 @@
|
||||
/* GdkGraphics.java
|
||||
Copyright (C) 1998, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.SystemColor;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
|
||||
public class GdkGraphics extends Graphics
|
||||
{
|
||||
private final int native_state = GtkGenericPeer.getUniqueInteger();
|
||||
|
||||
Color color, xorColor;
|
||||
GtkComponentPeer component;
|
||||
Font font;
|
||||
Rectangle clip;
|
||||
|
||||
int xOffset = 0;
|
||||
int yOffset = 0;
|
||||
|
||||
static final int GDK_COPY = 0, GDK_XOR = 2;
|
||||
|
||||
native void initState (GtkComponentPeer component);
|
||||
native void initState (int width, int height);
|
||||
native void copyState (GdkGraphics g);
|
||||
|
||||
GdkGraphics (GdkGraphics g)
|
||||
{
|
||||
color = g.color;
|
||||
xorColor = g.xorColor;
|
||||
font = g.font;
|
||||
clip = new Rectangle (g.clip);
|
||||
component = g.component;
|
||||
|
||||
copyState (g);
|
||||
}
|
||||
|
||||
GdkGraphics (int width, int height)
|
||||
{
|
||||
initState (width, height);
|
||||
color = Color.black;
|
||||
clip = new Rectangle (0, 0, width, height);
|
||||
font = new Font ("Dialog", Font.PLAIN, 12);
|
||||
}
|
||||
|
||||
GdkGraphics (GtkComponentPeer component)
|
||||
{
|
||||
this.component = component;
|
||||
font = component.awtComponent.getFont ();
|
||||
|
||||
if (component.isRealized ())
|
||||
initComponentGraphics ();
|
||||
else
|
||||
connectSignals (component);
|
||||
}
|
||||
|
||||
void initComponentGraphics ()
|
||||
{
|
||||
initState (component);
|
||||
color = component.awtComponent.getForeground ();
|
||||
Dimension d = component.awtComponent.getSize ();
|
||||
clip = new Rectangle (0, 0, d.width, d.height);
|
||||
}
|
||||
|
||||
native void connectSignals (GtkComponentPeer component);
|
||||
|
||||
public native void clearRect(int x, int y, int width, int height);
|
||||
|
||||
public void clipRect (int x, int y, int width, int height)
|
||||
{
|
||||
if (component != null && ! component.isRealized ())
|
||||
return;
|
||||
|
||||
clip = clip.intersection (new Rectangle (x, y, width, height));
|
||||
setClipRectangle (clip.x, clip.y, clip.width, clip.height);
|
||||
}
|
||||
|
||||
public native void copyArea(int x, int y, int width, int height,
|
||||
int dx, int dy);
|
||||
|
||||
public Graphics create ()
|
||||
{
|
||||
return new GdkGraphics (this);
|
||||
}
|
||||
|
||||
public native void dispose();
|
||||
|
||||
native void copyPixmap (Graphics g, int x, int y, int width, int height);
|
||||
native void copyAndScalePixmap (Graphics g, boolean flip_x, boolean flip_y,
|
||||
int src_x, int src_y,
|
||||
int src_width, int src_height,
|
||||
int dest_x, int dest_y,
|
||||
int dest_width, int dest_height);
|
||||
public boolean drawImage (Image img, int x, int y,
|
||||
Color bgcolor, ImageObserver observer)
|
||||
{
|
||||
if (component != null && ! component.isRealized ())
|
||||
return false;
|
||||
|
||||
if (img instanceof GtkOffScreenImage)
|
||||
{
|
||||
int width = img.getWidth (null);
|
||||
int height = img.getHeight (null);
|
||||
copyPixmap (img.getGraphics (),
|
||||
x, y, width, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
GtkImage image = (GtkImage) img;
|
||||
new GtkImagePainter (image, this, x, y, -1, -1, bgcolor, observer);
|
||||
return image.isLoaded ();
|
||||
}
|
||||
|
||||
public boolean drawImage (Image img, int x, int y, ImageObserver observer)
|
||||
{
|
||||
if (component != null && ! component.isRealized ())
|
||||
return false;
|
||||
|
||||
if (img instanceof GtkOffScreenImage)
|
||||
{
|
||||
int width = img.getWidth (null);
|
||||
int height = img.getHeight (null);
|
||||
copyPixmap (img.getGraphics (),
|
||||
x, y, width, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (component != null)
|
||||
return drawImage (img, x, y, component.getBackground (), observer);
|
||||
else
|
||||
return drawImage (img, x, y, SystemColor.window, observer);
|
||||
}
|
||||
|
||||
public boolean drawImage (Image img, int x, int y, int width, int height,
|
||||
Color bgcolor, ImageObserver observer)
|
||||
{
|
||||
if (component != null && ! component.isRealized ())
|
||||
return false;
|
||||
|
||||
if (img instanceof GtkOffScreenImage)
|
||||
{
|
||||
copyAndScalePixmap (img.getGraphics (), false, false,
|
||||
0, 0, img.getWidth (null), img.getHeight (null),
|
||||
x, y, width, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
GtkImage image = (GtkImage) img;
|
||||
new GtkImagePainter (image, this, x, y, width, height, bgcolor, observer);
|
||||
return image.isLoaded ();
|
||||
}
|
||||
|
||||
public boolean drawImage (Image img, int x, int y, int width, int height,
|
||||
ImageObserver observer)
|
||||
{
|
||||
if (component != null && ! component.isRealized ())
|
||||
return false;
|
||||
|
||||
if (component != null)
|
||||
return drawImage (img, x, y, width, height, component.getBackground (),
|
||||
observer);
|
||||
else
|
||||
return drawImage (img, x, y, width, height, SystemColor.window,
|
||||
observer);
|
||||
}
|
||||
|
||||
public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
Color bgcolor, ImageObserver observer)
|
||||
{
|
||||
if (component != null && ! component.isRealized ())
|
||||
return false;
|
||||
|
||||
if (img instanceof GtkOffScreenImage)
|
||||
{
|
||||
int dx_start, dy_start, d_width, d_height;
|
||||
int sx_start, sy_start, s_width, s_height;
|
||||
boolean x_flip = false;
|
||||
boolean y_flip = false;
|
||||
|
||||
if (dx1 < dx2)
|
||||
{
|
||||
dx_start = dx1;
|
||||
d_width = dx2 - dx1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dx_start = dx2;
|
||||
d_width = dx1 - dx2;
|
||||
x_flip ^= true;
|
||||
}
|
||||
if (dy1 < dy2)
|
||||
{
|
||||
dy_start = dy1;
|
||||
d_height = dy2 - dy1;
|
||||
}
|
||||
else
|
||||
{
|
||||
dy_start = dy2;
|
||||
d_height = dy1 - dy2;
|
||||
y_flip ^= true;
|
||||
}
|
||||
if (sx1 < sx2)
|
||||
{
|
||||
sx_start = sx1;
|
||||
s_width = sx2 - sx1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sx_start = sx2;
|
||||
s_width = sx1 - sx2;
|
||||
x_flip ^= true;
|
||||
}
|
||||
if (sy1 < sy2)
|
||||
{
|
||||
sy_start = sy1;
|
||||
s_height = sy2 - sy1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sy_start = sy2;
|
||||
s_height = sy1 - sy2;
|
||||
y_flip ^= true;
|
||||
}
|
||||
|
||||
copyAndScalePixmap (img.getGraphics (), x_flip, y_flip,
|
||||
sx_start, sy_start, s_width, s_height,
|
||||
dx_start, dy_start, d_width, d_height);
|
||||
return true;
|
||||
}
|
||||
|
||||
GtkImage image = (GtkImage) img;
|
||||
new GtkImagePainter (image, this, dx1, dy1, dx2, dy2,
|
||||
sx1, sy1, sx2, sy2, bgcolor, observer);
|
||||
return image.isLoaded ();
|
||||
}
|
||||
|
||||
public boolean drawImage (Image img, int dx1, int dy1, int dx2, int dy2,
|
||||
int sx1, int sy1, int sx2, int sy2,
|
||||
ImageObserver observer)
|
||||
{
|
||||
if (component != null && ! component.isRealized ())
|
||||
return false;
|
||||
|
||||
if (component != null)
|
||||
return drawImage (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
|
||||
component.getBackground (), observer);
|
||||
else
|
||||
return drawImage (img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2,
|
||||
SystemColor.window, observer);
|
||||
}
|
||||
|
||||
public native void drawLine(int x1, int y1, int x2, int y2);
|
||||
|
||||
public native void drawArc(int x, int y, int width, int height,
|
||||
int startAngle, int arcAngle);
|
||||
public native void fillArc(int x, int y, int width, int height,
|
||||
int startAngle, int arcAngle);
|
||||
public native void drawOval(int x, int y, int width, int height);
|
||||
public native void fillOval(int x, int y, int width, int height);
|
||||
|
||||
public native void drawPolygon(int[] xPoints, int[] yPoints, int nPoints);
|
||||
public native void fillPolygon(int[] xPoints, int[] yPoints, int nPoints);
|
||||
|
||||
public native void drawPolyline(int[] xPoints, int[] yPoints, int nPoints);
|
||||
|
||||
public native void drawRect(int x, int y, int width, int height);
|
||||
public native void fillRect(int x, int y, int width, int height);
|
||||
|
||||
GdkFontPeer getFontPeer()
|
||||
{
|
||||
return (GdkFontPeer) getFont().getPeer();
|
||||
}
|
||||
|
||||
native void drawString (GdkFontPeer f, String str, int x, int y);
|
||||
public void drawString (String str, int x, int y)
|
||||
{
|
||||
drawString(getFontPeer(), str, x, y);
|
||||
}
|
||||
|
||||
|
||||
public void drawString (AttributedCharacterIterator ci, int x, int y)
|
||||
{
|
||||
throw new Error ("not implemented");
|
||||
}
|
||||
|
||||
public void drawRoundRect(int x, int y, int width, int height,
|
||||
int arcWidth, int arcHeight)
|
||||
{
|
||||
if (arcWidth > width)
|
||||
arcWidth = width;
|
||||
if (arcHeight > height)
|
||||
arcHeight = height;
|
||||
|
||||
int xx = x + width - arcWidth;
|
||||
int yy = y + height - arcHeight;
|
||||
|
||||
drawArc (x, y, arcWidth, arcHeight, 90, 90);
|
||||
drawArc (xx, y, arcWidth, arcHeight, 0, 90);
|
||||
drawArc (xx, yy, arcWidth, arcHeight, 270, 90);
|
||||
drawArc (x, yy, arcWidth, arcHeight, 180, 90);
|
||||
|
||||
int y1 = y + arcHeight / 2;
|
||||
int y2 = y + height - arcHeight / 2;
|
||||
drawLine (x, y1, x, y2);
|
||||
drawLine (x + width, y1, x + width, y2);
|
||||
|
||||
int x1 = x + arcWidth / 2;
|
||||
int x2 = x + width - arcWidth / 2;
|
||||
drawLine (x1, y, x2, y);
|
||||
drawLine (x1, y + height, x2, y + height);
|
||||
}
|
||||
|
||||
public void fillRoundRect (int x, int y, int width, int height,
|
||||
int arcWidth, int arcHeight)
|
||||
{
|
||||
if (arcWidth > width)
|
||||
arcWidth = width;
|
||||
if (arcHeight > height)
|
||||
arcHeight = height;
|
||||
|
||||
int xx = x + width - arcWidth;
|
||||
int yy = y + height - arcHeight;
|
||||
|
||||
fillArc (x, y, arcWidth, arcHeight, 90, 90);
|
||||
fillArc (xx, y, arcWidth, arcHeight, 0, 90);
|
||||
fillArc (xx, yy, arcWidth, arcHeight, 270, 90);
|
||||
fillArc (x, yy, arcWidth, arcHeight, 180, 90);
|
||||
|
||||
fillRect (x, y + arcHeight / 2, width, height - arcHeight + 1);
|
||||
fillRect (x + arcWidth / 2, y, width - arcWidth + 1, height);
|
||||
}
|
||||
|
||||
public Shape getClip ()
|
||||
{
|
||||
return getClipBounds ();
|
||||
}
|
||||
|
||||
public Rectangle getClipBounds ()
|
||||
{
|
||||
if (clip == null)
|
||||
return null;
|
||||
else
|
||||
return clip.getBounds();
|
||||
}
|
||||
|
||||
public Color getColor ()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public Font getFont ()
|
||||
{
|
||||
return font;
|
||||
}
|
||||
|
||||
public FontMetrics getFontMetrics (Font font)
|
||||
{
|
||||
return new GdkFontMetrics (font);
|
||||
}
|
||||
|
||||
native void setClipRectangle (int x, int y, int width, int height);
|
||||
|
||||
public void setClip (int x, int y, int width, int height)
|
||||
{
|
||||
if ((component != null && ! component.isRealized ())
|
||||
|| clip == null)
|
||||
return;
|
||||
|
||||
clip.x = x;
|
||||
clip.y = y;
|
||||
clip.width = width;
|
||||
clip.height = height;
|
||||
|
||||
setClipRectangle (x, y, width, height);
|
||||
}
|
||||
|
||||
public void setClip (Rectangle clip)
|
||||
{
|
||||
setClip (clip.x, clip.y, clip.width, clip.height);
|
||||
}
|
||||
|
||||
public void setClip (Shape clip)
|
||||
{
|
||||
if (clip != null)
|
||||
setClip(clip.getBounds());
|
||||
}
|
||||
|
||||
private native void setFGColor(int red, int green, int blue);
|
||||
|
||||
public void setColor (Color c)
|
||||
{
|
||||
if (c == null)
|
||||
color = Color.BLACK;
|
||||
else
|
||||
color = c;
|
||||
|
||||
if (xorColor == null) /* paint mode */
|
||||
setFGColor (color.getRed (), color.getGreen (), color.getBlue ());
|
||||
else /* xor mode */
|
||||
setFGColor (color.getRed () ^ xorColor.getRed (),
|
||||
color.getGreen () ^ xorColor.getGreen (),
|
||||
color.getBlue () ^ xorColor.getBlue ());
|
||||
}
|
||||
|
||||
public void setFont (Font font)
|
||||
{
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
native void setFunction (int gdk_func);
|
||||
|
||||
public void setPaintMode ()
|
||||
{
|
||||
xorColor = null;
|
||||
|
||||
setFunction (GDK_COPY);
|
||||
setFGColor (color.getRed (), color.getGreen (), color.getBlue ());
|
||||
}
|
||||
|
||||
public void setXORMode (Color c)
|
||||
{
|
||||
xorColor = c;
|
||||
|
||||
setFunction (GDK_XOR);
|
||||
setFGColor (color.getRed () ^ xorColor.getRed (),
|
||||
color.getGreen () ^ xorColor.getGreen (),
|
||||
color.getBlue () ^ xorColor.getBlue ());
|
||||
}
|
||||
|
||||
public native void translateNative(int x, int y);
|
||||
|
||||
public void translate (int x, int y)
|
||||
{
|
||||
if (component != null && ! component.isRealized ())
|
||||
return;
|
||||
|
||||
clip.x -= x;
|
||||
clip.y -= y;
|
||||
|
||||
translateNative (x, y);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,138 +0,0 @@
|
||||
/* GdkGraphicsConfiguration.java -- describes characteristics of graphics
|
||||
Copyright (C) 2000, 2001, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.BufferCapabilities;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.ImageCapabilities;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import java.awt.geom.AffineTransform;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.VolatileImage;
|
||||
|
||||
public class GdkGraphicsConfiguration
|
||||
extends GraphicsConfiguration
|
||||
{
|
||||
GdkScreenGraphicsDevice gdkScreenGraphicsDevice;
|
||||
ColorModel cm;
|
||||
Rectangle bounds;
|
||||
|
||||
public GtkToolkit getToolkit()
|
||||
{
|
||||
return gdkScreenGraphicsDevice.getToolkit();
|
||||
}
|
||||
|
||||
public GdkGraphicsConfiguration(GdkScreenGraphicsDevice dev)
|
||||
{
|
||||
this.gdkScreenGraphicsDevice = dev;
|
||||
cm = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).getColorModel();
|
||||
bounds = getToolkit().getBounds();
|
||||
}
|
||||
|
||||
public GraphicsDevice getDevice()
|
||||
{
|
||||
return gdkScreenGraphicsDevice;
|
||||
}
|
||||
|
||||
public BufferedImage createCompatibleImage(int w, int h)
|
||||
{
|
||||
return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
||||
}
|
||||
|
||||
public BufferedImage createCompatibleImage(int w, int h,
|
||||
int transparency)
|
||||
{
|
||||
return createCompatibleImage(w, h);
|
||||
}
|
||||
|
||||
public VolatileImage createCompatibleVolatileImage(int w, int h)
|
||||
{
|
||||
return new GtkVolatileImage(w, h);
|
||||
}
|
||||
|
||||
public VolatileImage createCompatibleVolatileImage(int w, int h,
|
||||
ImageCapabilities caps)
|
||||
throws java.awt.AWTException
|
||||
{
|
||||
return new GtkVolatileImage(w, h, caps);
|
||||
}
|
||||
|
||||
public ColorModel getColorModel()
|
||||
{
|
||||
return cm;
|
||||
}
|
||||
|
||||
public ColorModel getColorModel(int transparency)
|
||||
{
|
||||
return getColorModel();
|
||||
}
|
||||
|
||||
public AffineTransform getDefaultTransform()
|
||||
{
|
||||
// FIXME: extract the GDK DPI information here.
|
||||
return new AffineTransform();
|
||||
}
|
||||
|
||||
public AffineTransform getNormalizingTransform()
|
||||
{
|
||||
// FIXME: extract the GDK DPI information here.
|
||||
return new AffineTransform();
|
||||
}
|
||||
|
||||
public Rectangle getBounds()
|
||||
{
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public BufferCapabilities getBufferCapabilities()
|
||||
{
|
||||
return new BufferCapabilities(getImageCapabilities(),
|
||||
getImageCapabilities(),
|
||||
BufferCapabilities.FlipContents.UNDEFINED);
|
||||
}
|
||||
|
||||
public ImageCapabilities getImageCapabilities()
|
||||
{
|
||||
return new ImageCapabilities(false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/* GdkGraphicsEnvironment.java -- information about the graphics environment
|
||||
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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Locale;
|
||||
|
||||
public class GdkGraphicsEnvironment extends GraphicsEnvironment
|
||||
{
|
||||
GtkToolkit gtkToolkit;
|
||||
|
||||
public GtkToolkit getToolkit()
|
||||
{
|
||||
return gtkToolkit;
|
||||
}
|
||||
|
||||
public GdkGraphicsEnvironment (GtkToolkit tk)
|
||||
{
|
||||
super();
|
||||
gtkToolkit = tk;
|
||||
}
|
||||
|
||||
public GraphicsDevice[] getScreenDevices ()
|
||||
{
|
||||
// FIXME: Support multiple screens, since GDK can.
|
||||
return new GraphicsDevice[] { new GdkScreenGraphicsDevice (this) };
|
||||
}
|
||||
|
||||
public GraphicsDevice getDefaultScreenDevice ()
|
||||
{
|
||||
if (GraphicsEnvironment.isHeadless ())
|
||||
throw new HeadlessException ();
|
||||
|
||||
return new GdkScreenGraphicsDevice (this);
|
||||
}
|
||||
|
||||
public Graphics2D createGraphics (BufferedImage image)
|
||||
{
|
||||
return new GdkGraphics2D (image);
|
||||
}
|
||||
|
||||
private native int nativeGetNumFontFamilies();
|
||||
private native void nativeGetFontFamilies(String[] family_names);
|
||||
|
||||
public Font[] getAllFonts ()
|
||||
{
|
||||
throw new java.lang.UnsupportedOperationException ();
|
||||
}
|
||||
|
||||
public String[] getAvailableFontFamilyNames ()
|
||||
{
|
||||
String[] family_names;
|
||||
int array_size;
|
||||
|
||||
array_size = nativeGetNumFontFamilies();
|
||||
family_names = new String[array_size];
|
||||
|
||||
nativeGetFontFamilies(family_names);
|
||||
return family_names;
|
||||
}
|
||||
|
||||
public String[] getAvailableFontFamilyNames (Locale l)
|
||||
{
|
||||
throw new java.lang.UnsupportedOperationException ();
|
||||
}
|
||||
}
|
||||
@@ -1,675 +0,0 @@
|
||||
/* GdkPixbufDecoder.java -- Image data decoding object
|
||||
Copyright (C) 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import gnu.classpath.Configuration;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DirectColorModel;
|
||||
import java.awt.image.ImageConsumer;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.RenderedImage;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.imageio.IIOImage;
|
||||
import javax.imageio.ImageReadParam;
|
||||
import javax.imageio.ImageReader;
|
||||
import javax.imageio.ImageTypeSpecifier;
|
||||
import javax.imageio.ImageWriteParam;
|
||||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.metadata.IIOMetadata;
|
||||
import javax.imageio.spi.IIORegistry;
|
||||
import javax.imageio.spi.ImageReaderSpi;
|
||||
import javax.imageio.spi.ImageWriterSpi;
|
||||
import javax.imageio.stream.ImageInputStream;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
|
||||
public class GdkPixbufDecoder extends gnu.java.awt.image.ImageDecoder
|
||||
{
|
||||
static
|
||||
{
|
||||
if (Configuration.INIT_LOAD_LIBRARY)
|
||||
{
|
||||
System.loadLibrary("gtkpeer");
|
||||
}
|
||||
initStaticState ();
|
||||
}
|
||||
|
||||
static native void initStaticState();
|
||||
private final int native_state = GtkGenericPeer.getUniqueInteger ();
|
||||
private boolean initialized = false;
|
||||
|
||||
// the current set of ImageConsumers for this decoder
|
||||
Vector curr;
|
||||
|
||||
// interface to GdkPixbuf
|
||||
native void initState ();
|
||||
native void pumpBytes (byte[] bytes, int len);
|
||||
native void finish ();
|
||||
static native void streamImage(int[] bytes, String format, int width, int height, boolean hasAlpha, DataOutput sink);
|
||||
|
||||
// gdk-pixbuf provids data in RGBA format
|
||||
static final ColorModel cm = new DirectColorModel (32, 0xff000000,
|
||||
0x00ff0000,
|
||||
0x0000ff00,
|
||||
0x000000ff);
|
||||
public GdkPixbufDecoder (InputStream in)
|
||||
{
|
||||
super (in);
|
||||
}
|
||||
|
||||
public GdkPixbufDecoder (String filename)
|
||||
{
|
||||
super (filename);
|
||||
}
|
||||
|
||||
public GdkPixbufDecoder (URL url)
|
||||
{
|
||||
super (url);
|
||||
}
|
||||
|
||||
public GdkPixbufDecoder (byte[] imagedata, int imageoffset, int imagelength)
|
||||
{
|
||||
super (imagedata, imageoffset, imagelength);
|
||||
}
|
||||
|
||||
// called back by native side
|
||||
void areaPrepared (int width, int height)
|
||||
{
|
||||
|
||||
if (curr == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < curr.size (); i++)
|
||||
{
|
||||
ImageConsumer ic = (ImageConsumer) curr.elementAt (i);
|
||||
ic.setDimensions (width, height);
|
||||
ic.setColorModel (cm);
|
||||
ic.setHints (ImageConsumer.RANDOMPIXELORDER);
|
||||
}
|
||||
}
|
||||
|
||||
// called back by native side
|
||||
void areaUpdated (int x, int y, int width, int height,
|
||||
int pixels[], int scansize)
|
||||
{
|
||||
if (curr == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < curr.size (); i++)
|
||||
{
|
||||
ImageConsumer ic = (ImageConsumer) curr.elementAt (i);
|
||||
ic.setPixels (x, y, width, height, cm, pixels, 0, scansize);
|
||||
}
|
||||
}
|
||||
|
||||
// called from an async image loader of one sort or another, this method
|
||||
// repeatedly reads bytes from the input stream and passes them through a
|
||||
// GdkPixbufLoader using the native method pumpBytes. pumpBytes in turn
|
||||
// decodes the image data and calls back areaPrepared and areaUpdated on
|
||||
// this object, feeding back decoded pixel blocks, which we pass to each
|
||||
// of the ImageConsumers in the provided Vector.
|
||||
|
||||
public void produce (Vector v, InputStream is) throws IOException
|
||||
{
|
||||
curr = v;
|
||||
|
||||
byte bytes[] = new byte[4096];
|
||||
int len = 0;
|
||||
initState();
|
||||
while ((len = is.read (bytes)) != -1)
|
||||
pumpBytes (bytes, len);
|
||||
|
||||
for (int i = 0; i < curr.size (); i++)
|
||||
{
|
||||
ImageConsumer ic = (ImageConsumer) curr.elementAt (i);
|
||||
ic.imageComplete (ImageConsumer.STATICIMAGEDONE);
|
||||
}
|
||||
|
||||
curr = null;
|
||||
}
|
||||
|
||||
public void finalize()
|
||||
{
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
public static class ImageFormatSpec
|
||||
{
|
||||
public String name;
|
||||
public boolean writable = false;
|
||||
public ArrayList mimeTypes = new ArrayList();
|
||||
public ArrayList extensions = new ArrayList();
|
||||
|
||||
public ImageFormatSpec(String name, boolean writable)
|
||||
{
|
||||
this.name = name;
|
||||
this.writable = writable;
|
||||
}
|
||||
|
||||
public synchronized void addMimeType(String m)
|
||||
{
|
||||
mimeTypes.add(m);
|
||||
}
|
||||
|
||||
public synchronized void addExtension(String e)
|
||||
{
|
||||
extensions.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
static ArrayList imageFormatSpecs;
|
||||
|
||||
public static ImageFormatSpec registerFormat(String name, boolean writable)
|
||||
{
|
||||
ImageFormatSpec ifs = new ImageFormatSpec(name, writable);
|
||||
synchronized(GdkPixbufDecoder.class)
|
||||
{
|
||||
if (imageFormatSpecs == null)
|
||||
imageFormatSpecs = new ArrayList();
|
||||
imageFormatSpecs.add(ifs);
|
||||
}
|
||||
return ifs;
|
||||
}
|
||||
|
||||
static String[] getFormatNames(boolean writable)
|
||||
{
|
||||
ArrayList names = new ArrayList();
|
||||
synchronized (imageFormatSpecs)
|
||||
{
|
||||
Iterator i = imageFormatSpecs.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
ImageFormatSpec ifs = (ImageFormatSpec) i.next();
|
||||
if (writable && !ifs.writable)
|
||||
continue;
|
||||
names.add(ifs.name);
|
||||
|
||||
/*
|
||||
* In order to make the filtering code work, we need to register
|
||||
* this type under every "format name" likely to be used as a synonym.
|
||||
* This generally means "all the extensions people might use".
|
||||
*/
|
||||
|
||||
Iterator j = ifs.extensions.iterator();
|
||||
while (j.hasNext())
|
||||
names.add((String) j.next());
|
||||
}
|
||||
}
|
||||
Object[] objs = names.toArray();
|
||||
String[] strings = new String[objs.length];
|
||||
for (int i = 0; i < objs.length; ++i)
|
||||
strings[i] = (String) objs[i];
|
||||
return strings;
|
||||
}
|
||||
|
||||
static String[] getFormatExtensions(boolean writable)
|
||||
{
|
||||
ArrayList extensions = new ArrayList();
|
||||
synchronized (imageFormatSpecs)
|
||||
{
|
||||
Iterator i = imageFormatSpecs.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
ImageFormatSpec ifs = (ImageFormatSpec) i.next();
|
||||
if (writable && !ifs.writable)
|
||||
continue;
|
||||
Iterator j = ifs.extensions.iterator();
|
||||
while (j.hasNext())
|
||||
extensions.add((String) j.next());
|
||||
}
|
||||
}
|
||||
Object[] objs = extensions.toArray();
|
||||
String[] strings = new String[objs.length];
|
||||
for (int i = 0; i < objs.length; ++i)
|
||||
strings[i] = (String) objs[i];
|
||||
return strings;
|
||||
}
|
||||
|
||||
static String[] getFormatMimeTypes(boolean writable)
|
||||
{
|
||||
ArrayList mimeTypes = new ArrayList();
|
||||
synchronized (imageFormatSpecs)
|
||||
{
|
||||
Iterator i = imageFormatSpecs.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
ImageFormatSpec ifs = (ImageFormatSpec) i.next();
|
||||
if (writable && !ifs.writable)
|
||||
continue;
|
||||
Iterator j = ifs.mimeTypes.iterator();
|
||||
while (j.hasNext())
|
||||
mimeTypes.add((String) j.next());
|
||||
}
|
||||
}
|
||||
Object[] objs = mimeTypes.toArray();
|
||||
String[] strings = new String[objs.length];
|
||||
for (int i = 0; i < objs.length; ++i)
|
||||
strings[i] = (String) objs[i];
|
||||
return strings;
|
||||
}
|
||||
|
||||
|
||||
static String findFormatName(Object ext, boolean needWritable)
|
||||
{
|
||||
if (ext == null)
|
||||
throw new IllegalArgumentException("extension is null");
|
||||
|
||||
if (!(ext instanceof String))
|
||||
throw new IllegalArgumentException("extension is not a string");
|
||||
|
||||
String str = (String) ext;
|
||||
|
||||
Iterator i = imageFormatSpecs.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
ImageFormatSpec ifs = (ImageFormatSpec) i.next();
|
||||
|
||||
if (needWritable && !ifs.writable)
|
||||
continue;
|
||||
|
||||
if (ifs.name.equals(str))
|
||||
return str;
|
||||
|
||||
Iterator j = ifs.extensions.iterator();
|
||||
while (j.hasNext())
|
||||
{
|
||||
String extension = (String)j.next();
|
||||
if (extension.equals(str))
|
||||
return ifs.name;
|
||||
}
|
||||
|
||||
j = ifs.mimeTypes.iterator();
|
||||
while (j.hasNext())
|
||||
{
|
||||
String mimeType = (String)j.next();
|
||||
if (mimeType.equals(str))
|
||||
return ifs.name;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("unknown extension '" + str + "'");
|
||||
}
|
||||
|
||||
private static GdkPixbufReaderSpi readerSpi;
|
||||
private static GdkPixbufWriterSpi writerSpi;
|
||||
|
||||
public static synchronized GdkPixbufReaderSpi getReaderSpi()
|
||||
{
|
||||
if (readerSpi == null)
|
||||
readerSpi = new GdkPixbufReaderSpi();
|
||||
return readerSpi;
|
||||
}
|
||||
|
||||
public static synchronized GdkPixbufWriterSpi getWriterSpi()
|
||||
{
|
||||
if (writerSpi == null)
|
||||
writerSpi = new GdkPixbufWriterSpi();
|
||||
return writerSpi;
|
||||
}
|
||||
|
||||
public static void registerSpis(IIORegistry reg)
|
||||
{
|
||||
reg.registerServiceProvider(getReaderSpi(), ImageReaderSpi.class);
|
||||
reg.registerServiceProvider(getWriterSpi(), ImageWriterSpi.class);
|
||||
}
|
||||
|
||||
public static class GdkPixbufWriterSpi extends ImageWriterSpi
|
||||
{
|
||||
public GdkPixbufWriterSpi()
|
||||
{
|
||||
super("GdkPixbuf", "2.x",
|
||||
GdkPixbufDecoder.getFormatNames(true),
|
||||
GdkPixbufDecoder.getFormatExtensions(true),
|
||||
GdkPixbufDecoder.getFormatMimeTypes(true),
|
||||
"gnu.java.awt.peer.gtk.GdkPixbufDecoder$GdkPixbufWriter",
|
||||
new Class[] { ImageOutputStream.class },
|
||||
new String[] { "gnu.java.awt.peer.gtk.GdkPixbufDecoder$GdkPixbufReaderSpi" },
|
||||
false, null, null, null, null,
|
||||
false, null, null, null, null);
|
||||
}
|
||||
|
||||
public boolean canEncodeImage(ImageTypeSpecifier ts)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public ImageWriter createWriterInstance(Object ext)
|
||||
{
|
||||
return new GdkPixbufWriter(this, ext);
|
||||
}
|
||||
|
||||
public String getDescription(java.util.Locale loc)
|
||||
{
|
||||
return "GdkPixbuf Writer SPI";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class GdkPixbufReaderSpi extends ImageReaderSpi
|
||||
{
|
||||
public GdkPixbufReaderSpi()
|
||||
{
|
||||
super("GdkPixbuf", "2.x",
|
||||
GdkPixbufDecoder.getFormatNames(false),
|
||||
GdkPixbufDecoder.getFormatExtensions(false),
|
||||
GdkPixbufDecoder.getFormatMimeTypes(false),
|
||||
"gnu.java.awt.peer.gtk.GdkPixbufDecoder$GdkPixbufReader",
|
||||
new Class[] { ImageInputStream.class },
|
||||
new String[] { "gnu.java.awt.peer.gtk.GdkPixbufDecoder$GdkPixbufWriterSpi" },
|
||||
false, null, null, null, null,
|
||||
false, null, null, null, null);
|
||||
}
|
||||
|
||||
public boolean canDecodeInput(Object obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public ImageReader createReaderInstance(Object ext)
|
||||
{
|
||||
return new GdkPixbufReader(this, ext);
|
||||
}
|
||||
|
||||
public String getDescription(Locale loc)
|
||||
{
|
||||
return "GdkPixbuf Reader SPI";
|
||||
}
|
||||
}
|
||||
|
||||
private static class GdkPixbufWriter
|
||||
extends ImageWriter
|
||||
{
|
||||
String ext;
|
||||
public GdkPixbufWriter(GdkPixbufWriterSpi ownerSpi, Object ext)
|
||||
{
|
||||
super(ownerSpi);
|
||||
this.ext = findFormatName(ext, true);
|
||||
}
|
||||
|
||||
public IIOMetadata convertImageMetadata (IIOMetadata inData,
|
||||
ImageTypeSpecifier imageType,
|
||||
ImageWriteParam param)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IIOMetadata convertStreamMetadata (IIOMetadata inData,
|
||||
ImageWriteParam param)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IIOMetadata getDefaultImageMetadata (ImageTypeSpecifier imageType,
|
||||
ImageWriteParam param)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IIOMetadata getDefaultStreamMetadata (ImageWriteParam param)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public void write (IIOMetadata streamMetadata, IIOImage i, ImageWriteParam param)
|
||||
throws IOException
|
||||
{
|
||||
RenderedImage image = i.getRenderedImage();
|
||||
Raster ras = image.getData();
|
||||
int width = ras.getWidth();
|
||||
int height = ras.getHeight();
|
||||
ColorModel model = image.getColorModel();
|
||||
int[] pixels = GdkGraphics2D.findSimpleIntegerArray (image.getColorModel(), ras);
|
||||
|
||||
if (pixels == null)
|
||||
{
|
||||
BufferedImage img = new BufferedImage(width, height,
|
||||
(model != null && model.hasAlpha() ?
|
||||
BufferedImage.TYPE_INT_ARGB
|
||||
: BufferedImage.TYPE_INT_RGB));
|
||||
int[] pix = new int[4];
|
||||
for (int y = 0; y < height; ++y)
|
||||
for (int x = 0; x < width; ++x)
|
||||
img.setRGB(x, y, model.getRGB(ras.getPixel(x, y, pix)));
|
||||
pixels = GdkGraphics2D.findSimpleIntegerArray (img.getColorModel(),
|
||||
img.getRaster());
|
||||
model = img.getColorModel();
|
||||
}
|
||||
|
||||
processImageStarted(1);
|
||||
streamImage(pixels, this.ext, width, height, model.hasAlpha(),
|
||||
(DataOutput) this.getOutput());
|
||||
processImageComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private static class GdkPixbufReader
|
||||
extends ImageReader
|
||||
implements ImageConsumer
|
||||
{
|
||||
// ImageConsumer parts
|
||||
GdkPixbufDecoder dec;
|
||||
BufferedImage bufferedImage;
|
||||
ColorModel defaultModel;
|
||||
int width;
|
||||
int height;
|
||||
String ext;
|
||||
|
||||
public GdkPixbufReader(GdkPixbufReaderSpi ownerSpi, Object ext)
|
||||
{
|
||||
super(ownerSpi);
|
||||
this.ext = findFormatName(ext, false);
|
||||
}
|
||||
|
||||
public GdkPixbufReader(GdkPixbufReaderSpi ownerSpi, Object ext, GdkPixbufDecoder d)
|
||||
{
|
||||
this(ownerSpi, ext);
|
||||
dec = d;
|
||||
}
|
||||
|
||||
public void setDimensions(int w, int h)
|
||||
{
|
||||
processImageStarted(1);
|
||||
width = w;
|
||||
height = h;
|
||||
}
|
||||
|
||||
public void setProperties(Hashtable props) {}
|
||||
|
||||
public void setColorModel(ColorModel model)
|
||||
{
|
||||
defaultModel = model;
|
||||
}
|
||||
|
||||
public void setHints(int flags) {}
|
||||
|
||||
public void setPixels(int x, int y, int w, int h,
|
||||
ColorModel model, byte[] pixels,
|
||||
int offset, int scansize)
|
||||
{
|
||||
}
|
||||
|
||||
public void setPixels(int x, int y, int w, int h,
|
||||
ColorModel model, int[] pixels,
|
||||
int offset, int scansize)
|
||||
{
|
||||
if (model == null)
|
||||
model = defaultModel;
|
||||
|
||||
if (bufferedImage == null)
|
||||
{
|
||||
bufferedImage = new BufferedImage (width, height, (model != null && model.hasAlpha() ?
|
||||
BufferedImage.TYPE_INT_ARGB
|
||||
: BufferedImage.TYPE_INT_RGB));
|
||||
}
|
||||
|
||||
int pixels2[];
|
||||
if (model != null)
|
||||
{
|
||||
pixels2 = new int[pixels.length];
|
||||
for (int yy = 0; yy < h; yy++)
|
||||
for (int xx = 0; xx < w; xx++)
|
||||
{
|
||||
int i = yy * scansize + xx;
|
||||
pixels2[i] = model.getRGB (pixels[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
pixels2 = pixels;
|
||||
|
||||
bufferedImage.setRGB (x, y, w, h, pixels2, offset, scansize);
|
||||
processImageProgress(y / (height == 0 ? 1 : height));
|
||||
}
|
||||
|
||||
public void imageComplete(int status)
|
||||
{
|
||||
processImageComplete();
|
||||
}
|
||||
|
||||
public BufferedImage getBufferedImage()
|
||||
{
|
||||
if (bufferedImage == null && dec != null)
|
||||
dec.startProduction (this);
|
||||
return bufferedImage;
|
||||
}
|
||||
|
||||
// ImageReader parts
|
||||
|
||||
public int getNumImages(boolean allowSearch)
|
||||
throws IOException
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public IIOMetadata getImageMetadata(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public IIOMetadata getStreamMetadata()
|
||||
throws IOException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Iterator getImageTypes(int imageIndex)
|
||||
throws IOException
|
||||
{
|
||||
BufferedImage img = getBufferedImage();
|
||||
Vector vec = new Vector();
|
||||
vec.add(new ImageTypeSpecifier(img));
|
||||
return vec.iterator();
|
||||
}
|
||||
|
||||
public int getHeight(int imageIndex)
|
||||
throws IOException
|
||||
{
|
||||
return getBufferedImage().getHeight();
|
||||
}
|
||||
|
||||
public int getWidth(int imageIndex)
|
||||
throws IOException
|
||||
{
|
||||
return getBufferedImage().getWidth();
|
||||
}
|
||||
|
||||
public void setInput(Object input,
|
||||
boolean seekForwardOnly,
|
||||
boolean ignoreMetadata)
|
||||
{
|
||||
super.setInput(input, seekForwardOnly, ignoreMetadata);
|
||||
dec = new GdkPixbufDecoder((InputStream) getInput());
|
||||
}
|
||||
|
||||
public BufferedImage read(int imageIndex, ImageReadParam param)
|
||||
throws IOException
|
||||
{
|
||||
return getBufferedImage ();
|
||||
}
|
||||
}
|
||||
|
||||
// remaining helper class and static method is a convenience for the Gtk
|
||||
// peers, for loading a BufferedImage in off a disk file without going
|
||||
// through the whole imageio system.
|
||||
|
||||
public static BufferedImage createBufferedImage (String filename)
|
||||
{
|
||||
GdkPixbufReader r = new GdkPixbufReader (getReaderSpi(),
|
||||
"png", // reader auto-detects, doesn't matter
|
||||
new GdkPixbufDecoder (filename));
|
||||
return r.getBufferedImage ();
|
||||
}
|
||||
|
||||
public static BufferedImage createBufferedImage (URL u)
|
||||
{
|
||||
GdkPixbufReader r = new GdkPixbufReader (getReaderSpi(),
|
||||
"png", // reader auto-detects, doesn't matter
|
||||
new GdkPixbufDecoder (u));
|
||||
return r.getBufferedImage ();
|
||||
}
|
||||
|
||||
public static BufferedImage createBufferedImage (byte[] imagedata, int imageoffset,
|
||||
int imagelength)
|
||||
{
|
||||
GdkPixbufReader r = new GdkPixbufReader (getReaderSpi(),
|
||||
"png", // reader auto-detects, doesn't matter
|
||||
new GdkPixbufDecoder (imagedata,
|
||||
imageoffset,
|
||||
imagelength));
|
||||
return r.getBufferedImage ();
|
||||
}
|
||||
|
||||
public static BufferedImage createBufferedImage (ImageProducer producer)
|
||||
{
|
||||
GdkPixbufReader r = new GdkPixbufReader (getReaderSpi(), "png" /* ignored */, null);
|
||||
producer.startProduction(r);
|
||||
return r.getBufferedImage ();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/* GdkRobot.java -- an XTest implementation of RobotPeer
|
||||
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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.DirectColorModel;
|
||||
import java.awt.peer.RobotPeer;
|
||||
|
||||
/**
|
||||
* Implements the RobotPeer interface using the XTest extension.
|
||||
*
|
||||
* @author Thomas Fitzsimmons
|
||||
*/
|
||||
public class GdkRobotPeer implements RobotPeer
|
||||
{
|
||||
// gdk-pixbuf provides data in RGBA format
|
||||
static final ColorModel cm = new DirectColorModel (32, 0xff000000,
|
||||
0x00ff0000,
|
||||
0x0000ff00,
|
||||
0x000000ff);
|
||||
|
||||
public GdkRobotPeer (GraphicsDevice screen) throws AWTException
|
||||
{
|
||||
// FIXME: make use of screen parameter when GraphicsDevice is
|
||||
// implemented.
|
||||
if (!initXTest ())
|
||||
throw new AWTException ("XTest extension not supported");
|
||||
}
|
||||
|
||||
native boolean initXTest ();
|
||||
|
||||
// RobotPeer methods
|
||||
public native void mouseMove (int x, int y);
|
||||
public native void mousePress (int buttons);
|
||||
public native void mouseRelease (int buttons);
|
||||
public native void mouseWheel (int wheelAmt);
|
||||
public native void keyPress (int keycode);
|
||||
public native void keyRelease (int keycode);
|
||||
native int[] nativeGetRGBPixels (int x, int y, int width, int height);
|
||||
|
||||
public int getRGBPixel (int x, int y)
|
||||
{
|
||||
return cm.getRGB (nativeGetRGBPixels (x, y, 1, 1)[0]);
|
||||
}
|
||||
|
||||
public int[] getRGBPixels (Rectangle r)
|
||||
{
|
||||
int[] gdk_pixels = nativeGetRGBPixels (r.x, r.y, r.width, r.height);
|
||||
int[] pixels = new int[r.width * r.height];
|
||||
|
||||
for (int i = 0; i < r.width * r.height; i++)
|
||||
pixels[i] = cm.getRGB (gdk_pixels[i]);
|
||||
|
||||
return pixels;
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/* GdkScreenGraphicsDevice.java -- information about a screen device
|
||||
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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsDevice;
|
||||
|
||||
public class GdkScreenGraphicsDevice extends GraphicsDevice
|
||||
{
|
||||
GdkGraphicsEnvironment env;
|
||||
|
||||
public GtkToolkit getToolkit()
|
||||
{
|
||||
return env.getToolkit();
|
||||
}
|
||||
|
||||
public GdkScreenGraphicsDevice (GdkGraphicsEnvironment e)
|
||||
{
|
||||
super ();
|
||||
env = e;
|
||||
}
|
||||
|
||||
public int getType ()
|
||||
{
|
||||
return GraphicsDevice.TYPE_RASTER_SCREEN;
|
||||
}
|
||||
|
||||
public String getIDstring ()
|
||||
{
|
||||
// FIXME: query X for this string
|
||||
return "default GDK device ID string";
|
||||
}
|
||||
|
||||
public GraphicsConfiguration[] getConfigurations ()
|
||||
{
|
||||
// FIXME: query X for the list of possible configurations
|
||||
return new GraphicsConfiguration [] { new GdkGraphicsConfiguration(this) };
|
||||
}
|
||||
|
||||
public GraphicsConfiguration getDefaultConfiguration ()
|
||||
{
|
||||
|
||||
// FIXME: query X for default configuration
|
||||
return new GdkGraphicsConfiguration(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
// determine display mode
|
||||
Dimension dim = getToolkit().getScreenSize();
|
||||
DisplayMode mode = new DisplayMode(dim.width, dim.height, 0,
|
||||
DisplayMode.REFRESH_RATE_UNKNOWN);
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* This device does not yet support fullscreen exclusive mode, so this
|
||||
* returns <code>false</code>.
|
||||
*
|
||||
* @return <code>false</code>
|
||||
* @since 1.4
|
||||
*/
|
||||
public boolean isFullScreenSupported()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,434 +0,0 @@
|
||||
/* GdkTextLayout.java
|
||||
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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import gnu.classpath.Configuration;
|
||||
import gnu.java.awt.peer.ClasspathTextLayoutPeer;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Shape;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphMetrics;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.font.TextAttribute;
|
||||
import java.awt.font.TextHitInfo;
|
||||
import java.awt.font.TextLayout;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.text.AttributedString;
|
||||
import java.text.CharacterIterator;
|
||||
|
||||
/**
|
||||
* This is an implementation of the text layout peer interface which
|
||||
* delegates all the hard work to pango.
|
||||
*
|
||||
* @author Graydon Hoare
|
||||
*/
|
||||
|
||||
public class GdkTextLayout
|
||||
implements ClasspathTextLayoutPeer
|
||||
{
|
||||
// native side, plumbing, etc.
|
||||
static
|
||||
{
|
||||
if (Configuration.INIT_LOAD_LIBRARY)
|
||||
{
|
||||
System.loadLibrary("gtkpeer");
|
||||
}
|
||||
initStaticState ();
|
||||
}
|
||||
private native void setText(String str);
|
||||
private native void getExtents(double[] inkExtents,
|
||||
double[] logExtents);
|
||||
private native void indexToPos(int idx, double[] pos);
|
||||
private native void initState ();
|
||||
private native void dispose ();
|
||||
static native void initStaticState();
|
||||
private final int native_state = GtkGenericPeer.getUniqueInteger ();
|
||||
protected void finalize ()
|
||||
{
|
||||
dispose ();
|
||||
}
|
||||
|
||||
// we hold on to these to make sure we can render when presented
|
||||
// with non-GdkGraphics2D paint targets
|
||||
private AttributedString attributedString;
|
||||
private FontRenderContext fontRenderContext;
|
||||
|
||||
public GdkTextLayout(AttributedString str, FontRenderContext frc)
|
||||
{
|
||||
initState();
|
||||
attributedString = str;
|
||||
fontRenderContext = frc;
|
||||
}
|
||||
|
||||
protected class CharacterIteratorProxy
|
||||
implements CharacterIterator
|
||||
{
|
||||
public CharacterIterator target;
|
||||
public int begin;
|
||||
public int limit;
|
||||
public int index;
|
||||
|
||||
public CharacterIteratorProxy (CharacterIterator ci)
|
||||
{
|
||||
target = ci;
|
||||
}
|
||||
|
||||
public int getBeginIndex ()
|
||||
{
|
||||
return begin;
|
||||
}
|
||||
|
||||
public int getEndIndex ()
|
||||
{
|
||||
return limit;
|
||||
}
|
||||
|
||||
public int getIndex ()
|
||||
{
|
||||
return index;
|
||||
}
|
||||
|
||||
public char setIndex (int idx)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
if (idx < begin || idx >= limit)
|
||||
throw new IllegalArgumentException ();
|
||||
char ch = target.setIndex (idx);
|
||||
index = idx;
|
||||
return ch;
|
||||
}
|
||||
|
||||
public char first ()
|
||||
{
|
||||
int save = target.getIndex ();
|
||||
char ch = target.setIndex (begin);
|
||||
target.setIndex (save);
|
||||
return ch;
|
||||
}
|
||||
|
||||
public char last ()
|
||||
{
|
||||
if (begin == limit)
|
||||
return this.first ();
|
||||
|
||||
int save = target.getIndex ();
|
||||
char ch = target.setIndex (limit - 1);
|
||||
target.setIndex (save);
|
||||
return ch;
|
||||
}
|
||||
|
||||
public char current ()
|
||||
{
|
||||
return target.current();
|
||||
}
|
||||
|
||||
public char next ()
|
||||
{
|
||||
if (index >= limit - 1)
|
||||
return CharacterIterator.DONE;
|
||||
else
|
||||
{
|
||||
index++;
|
||||
return target.next();
|
||||
}
|
||||
}
|
||||
|
||||
public char previous ()
|
||||
{
|
||||
if (index <= begin)
|
||||
return CharacterIterator.DONE;
|
||||
else
|
||||
{
|
||||
index--;
|
||||
return target.previous ();
|
||||
}
|
||||
}
|
||||
|
||||
public Object clone ()
|
||||
{
|
||||
CharacterIteratorProxy cip = new CharacterIteratorProxy (this.target);
|
||||
cip.begin = this.begin;
|
||||
cip.limit = this.limit;
|
||||
cip.index = this.index;
|
||||
return cip;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// public side
|
||||
|
||||
public void draw (Graphics2D g2, float x, float y)
|
||||
{
|
||||
if (g2 instanceof GdkGraphics2D)
|
||||
{
|
||||
// we share pango structures directly with GdkGraphics2D
|
||||
// when legal
|
||||
GdkGraphics2D gg2 = (GdkGraphics2D) g2;
|
||||
gg2.drawGdkTextLayout(this, x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
// falling back to a rather tedious layout algorithm when
|
||||
// not legal
|
||||
AttributedCharacterIterator ci = attributedString.getIterator ();
|
||||
CharacterIteratorProxy proxy = new CharacterIteratorProxy (ci);
|
||||
Font defFont = g2.getFont ();
|
||||
|
||||
/* Note: this implementation currently only interprets FONT text
|
||||
* attributes. There is a reasonable argument to be made for some
|
||||
* attributes being interpreted out here, where we have control of the
|
||||
* Graphics2D and can construct or derive new fonts, and some
|
||||
* attributes being interpreted by the GlyphVector itself. So far, for
|
||||
* all attributes except FONT we do neither.
|
||||
*/
|
||||
|
||||
for (char c = ci.first ();
|
||||
c != CharacterIterator.DONE;
|
||||
c = ci.next ())
|
||||
{
|
||||
proxy.begin = ci.getIndex ();
|
||||
proxy.limit = ci.getRunLimit(TextAttribute.FONT);
|
||||
if (proxy.limit <= proxy.begin)
|
||||
continue;
|
||||
|
||||
proxy.index = proxy.begin;
|
||||
|
||||
Object fnt = ci.getAttribute(TextAttribute.FONT);
|
||||
GlyphVector gv;
|
||||
if (fnt instanceof Font)
|
||||
gv = ((Font)fnt).createGlyphVector (fontRenderContext, proxy);
|
||||
else
|
||||
gv = defFont.createGlyphVector (fontRenderContext, proxy);
|
||||
|
||||
g2.drawGlyphVector (gv, x, y);
|
||||
|
||||
int n = gv.getNumGlyphs ();
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
GlyphMetrics gm = gv.getGlyphMetrics (i);
|
||||
if (gm.getAdvanceX() == gm.getAdvance ())
|
||||
x += gm.getAdvanceX ();
|
||||
else
|
||||
y += gm.getAdvanceY ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TextHitInfo getStrongCaret (TextHitInfo hit1,
|
||||
TextHitInfo hit2)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public byte getBaseline ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public boolean isLeftToRight ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public boolean isVertical ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public float getAdvance ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public float getAscent ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public float getDescent ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public float getLeading ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public int getCharacterCount ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public byte getCharacterLevel (int index)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public float[] getBaselineOffsets ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public Shape getBlackBoxBounds (int firstEndpoint, int secondEndpoint)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public Rectangle2D getBounds ()
|
||||
{
|
||||
double[] inkExtents = new double[4];
|
||||
double[] logExtents = new double[4];
|
||||
getExtents(inkExtents, logExtents);
|
||||
return new Rectangle2D.Double(logExtents[0], logExtents[1],
|
||||
logExtents[2], logExtents[3]);
|
||||
}
|
||||
|
||||
public float[] getCaretInfo (TextHitInfo hit, Rectangle2D bounds)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public Shape getCaretShape (TextHitInfo hit, Rectangle2D bounds)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public Shape[] getCaretShapes (int offset, Rectangle2D bounds,
|
||||
TextLayout.CaretPolicy policy)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public Shape getLogicalHighlightShape (int firstEndpoint, int secondEndpoint,
|
||||
Rectangle2D bounds)
|
||||
{
|
||||
AffineTransform at = new AffineTransform();
|
||||
GeneralPath gp = new GeneralPath();
|
||||
double [] rect = new double[4];
|
||||
Rectangle2D tmp = new Rectangle2D.Double();
|
||||
for (int i = firstEndpoint; i <= secondEndpoint; ++i)
|
||||
{
|
||||
indexToPos(i, rect);
|
||||
tmp.setRect(rect[0], rect[1], rect[2], rect[3]);
|
||||
Rectangle2D.intersect(tmp, bounds, tmp);
|
||||
gp.append(tmp.getPathIterator(at), false);
|
||||
}
|
||||
return gp;
|
||||
}
|
||||
|
||||
public int[] getLogicalRangesForVisualSelection (TextHitInfo firstEndpoint,
|
||||
TextHitInfo secondEndpoint)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public TextHitInfo getNextLeftHit (int offset, TextLayout.CaretPolicy policy)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
public TextHitInfo getNextRightHit (int offset, TextLayout.CaretPolicy policy)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
public TextHitInfo hitTestChar (float x, float y, Rectangle2D bounds)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
public TextHitInfo getVisualOtherHit (TextHitInfo hit)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public float getVisibleAdvance ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public Shape getOutline (AffineTransform tx)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public Shape getVisualHighlightShape (TextHitInfo firstEndpoint,
|
||||
TextHitInfo secondEndpoint,
|
||||
Rectangle2D bounds)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
|
||||
public TextLayout getJustifiedLayout (float justificationWidth)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public void handleJustify (float justificationWidth)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public Object clone ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public int hashCode ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public boolean equals (ClasspathTextLayoutPeer tl)
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
public String toString ()
|
||||
{
|
||||
throw new Error("not implemented");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/* GtkButtonPeer.java -- Implements ButtonPeer with GTK
|
||||
Copyright (C) 1998, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Button;
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.peer.ButtonPeer;
|
||||
|
||||
public class GtkButtonPeer extends GtkComponentPeer
|
||||
implements ButtonPeer
|
||||
{
|
||||
native void create (String label);
|
||||
|
||||
public native void connectSignals ();
|
||||
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
native void gtkSetLabel (String label);
|
||||
native void gtkWidgetSetForeground (int red, int green, int blue);
|
||||
native void gtkWidgetSetBackground (int red, int green, int blue);
|
||||
native void gtkActivate ();
|
||||
native void gtkWidgetRequestFocus ();
|
||||
native void setNativeBounds (int x, int y, int width, int height);
|
||||
|
||||
public GtkButtonPeer (Button b)
|
||||
{
|
||||
super (b);
|
||||
}
|
||||
|
||||
void create ()
|
||||
{
|
||||
create (((Button) awtComponent).getLabel ());
|
||||
}
|
||||
|
||||
public void setLabel (String label)
|
||||
{
|
||||
gtkSetLabel(label);
|
||||
}
|
||||
|
||||
public void handleEvent (AWTEvent e)
|
||||
{
|
||||
if (e.getID () == MouseEvent.MOUSE_RELEASED && isEnabled ())
|
||||
{
|
||||
MouseEvent me = (MouseEvent) e;
|
||||
Point p = me.getPoint();
|
||||
p.translate(((Component) me.getSource()).getX(),
|
||||
((Component) me.getSource()).getY());
|
||||
if (!me.isConsumed ()
|
||||
&& (me.getModifiersEx () & MouseEvent.BUTTON1_DOWN_MASK) != 0
|
||||
&& awtComponent.getBounds().contains(p))
|
||||
postActionEvent (((Button) awtComponent).getActionCommand (),
|
||||
me.getModifiersEx ());
|
||||
}
|
||||
|
||||
if (e.getID () == KeyEvent.KEY_PRESSED)
|
||||
{
|
||||
KeyEvent ke = (KeyEvent) e;
|
||||
if (!ke.isConsumed () && ke.getKeyCode () == KeyEvent.VK_SPACE)
|
||||
{
|
||||
postActionEvent (((Button) awtComponent).getActionCommand (),
|
||||
ke.getModifiersEx ());
|
||||
gtkActivate ();
|
||||
}
|
||||
}
|
||||
|
||||
super.handleEvent (e);
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/* GtkCanvasPeer.java
|
||||
Copyright (C) 1998, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.Canvas;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.peer.CanvasPeer;
|
||||
|
||||
public class GtkCanvasPeer extends GtkComponentPeer implements CanvasPeer
|
||||
{
|
||||
native void create ();
|
||||
|
||||
public GtkCanvasPeer (Canvas c)
|
||||
{
|
||||
super (c);
|
||||
}
|
||||
|
||||
public Graphics getGraphics ()
|
||||
{
|
||||
if (GtkToolkit.useGraphics2D ())
|
||||
return new GdkGraphics2D (this);
|
||||
else
|
||||
return new GdkGraphics (this);
|
||||
}
|
||||
|
||||
public void handleEvent (AWTEvent event)
|
||||
{
|
||||
int id = event.getID();
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case PaintEvent.PAINT:
|
||||
case PaintEvent.UPDATE:
|
||||
{
|
||||
try
|
||||
{
|
||||
Graphics g = getGraphics ();
|
||||
g.setClip (((PaintEvent)event).getUpdateRect());
|
||||
|
||||
if (id == PaintEvent.PAINT)
|
||||
awtComponent.paint (g);
|
||||
else
|
||||
awtComponent.update (g);
|
||||
|
||||
g.dispose ();
|
||||
}
|
||||
catch (InternalError e)
|
||||
{
|
||||
System.err.println (e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Preferred size for a drawing widget is always what the user requested */
|
||||
public Dimension getPreferredSize ()
|
||||
{
|
||||
return awtComponent.getSize ();
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/* GtkCheckboxGroupPeer.java - Wrap a CheckboxGroup
|
||||
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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.CheckboxGroup;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
// Note that there is no peer interface for a CheckboxGroup. We
|
||||
// introduce our own in order to make it easier to keep a piece of
|
||||
// native state for each one.
|
||||
public class GtkCheckboxGroupPeer extends GtkGenericPeer
|
||||
{
|
||||
// This maps from a CheckboxGroup to the native peer.
|
||||
private static WeakHashMap map = new WeakHashMap ();
|
||||
|
||||
// Find the native peer corresponding to a CheckboxGroup.
|
||||
public static synchronized GtkCheckboxGroupPeer
|
||||
getCheckboxGroupPeer (CheckboxGroup group)
|
||||
{
|
||||
if (group == null)
|
||||
return null;
|
||||
GtkCheckboxGroupPeer nat = (GtkCheckboxGroupPeer) map.get (group);
|
||||
if (nat == null)
|
||||
{
|
||||
nat = new GtkCheckboxGroupPeer ();
|
||||
map.put (group, nat);
|
||||
}
|
||||
return nat;
|
||||
}
|
||||
|
||||
private GtkCheckboxGroupPeer ()
|
||||
{
|
||||
// We don't need any special state here. Note that we can't store
|
||||
// a reference to the java-side CheckboxGroup. That would mean
|
||||
// they could never be collected.
|
||||
super (null);
|
||||
}
|
||||
|
||||
// Dispose of our native resources.
|
||||
public native void dispose ();
|
||||
|
||||
// Remove a given checkbox from this group.
|
||||
public native void remove (GtkCheckboxPeer box);
|
||||
|
||||
// When collected, clean up the native state.
|
||||
protected void finalize ()
|
||||
{
|
||||
dispose ();
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/* GtkCheckboxMenuItemPeer.java -- Implements CheckboxMenuItemPeer with GTK+
|
||||
Copyright (C) 1999, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.CheckboxMenuItem;
|
||||
import java.awt.ItemSelectable;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.peer.CheckboxMenuItemPeer;
|
||||
|
||||
public class GtkCheckboxMenuItemPeer extends GtkMenuItemPeer
|
||||
implements CheckboxMenuItemPeer
|
||||
{
|
||||
native void create (String label);
|
||||
|
||||
public GtkCheckboxMenuItemPeer (CheckboxMenuItem menu)
|
||||
{
|
||||
super (menu);
|
||||
setState (menu.getState ());
|
||||
}
|
||||
|
||||
public native void setState(boolean t);
|
||||
|
||||
protected void postMenuActionEvent ()
|
||||
{
|
||||
CheckboxMenuItem item = (CheckboxMenuItem)awtWidget;
|
||||
q().postEvent (new ItemEvent ((ItemSelectable)awtWidget,
|
||||
ItemEvent.ITEM_STATE_CHANGED,
|
||||
item.getActionCommand(),
|
||||
item.getState() ? ItemEvent.DESELECTED : ItemEvent.SELECTED));
|
||||
|
||||
super.postMenuActionEvent();
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/* GtkCheckboxPeer.java -- Implements CheckboxPeer with GTK
|
||||
Copyright (C) 1998, 1999, 2002, 2003 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Checkbox;
|
||||
import java.awt.CheckboxGroup;
|
||||
import java.awt.peer.CheckboxPeer;
|
||||
|
||||
public class GtkCheckboxPeer extends GtkComponentPeer
|
||||
implements CheckboxPeer
|
||||
{
|
||||
// Group from last time it was set.
|
||||
public GtkCheckboxGroupPeer old_group;
|
||||
// The current state of the GTK checkbox.
|
||||
private boolean currentState;
|
||||
|
||||
public native void create (GtkCheckboxGroupPeer group);
|
||||
public native void nativeSetCheckboxGroup (GtkCheckboxGroupPeer group);
|
||||
public native void connectSignals ();
|
||||
native void gtkWidgetModifyFont (String name, int style, int size);
|
||||
native void gtkButtonSetLabel (String label);
|
||||
native void gtkToggleButtonSetActive (boolean is_active);
|
||||
|
||||
public GtkCheckboxPeer (Checkbox c)
|
||||
{
|
||||
super (c);
|
||||
}
|
||||
|
||||
// FIXME: we must be able to switch between a checkbutton and a
|
||||
// radiobutton dynamically.
|
||||
public void create ()
|
||||
{
|
||||
Checkbox checkbox = (Checkbox) awtComponent;
|
||||
CheckboxGroup g = checkbox.getCheckboxGroup ();
|
||||
old_group = GtkCheckboxGroupPeer.getCheckboxGroupPeer (g);
|
||||
create (old_group);
|
||||
gtkToggleButtonSetActive (checkbox.getState ());
|
||||
gtkButtonSetLabel (checkbox.getLabel ());
|
||||
}
|
||||
|
||||
public void setState (boolean state)
|
||||
{
|
||||
if (currentState != state)
|
||||
gtkToggleButtonSetActive (state);
|
||||
}
|
||||
|
||||
public void setLabel (String label)
|
||||
{
|
||||
gtkButtonSetLabel (label);
|
||||
}
|
||||
|
||||
public void setCheckboxGroup (CheckboxGroup group)
|
||||
{
|
||||
GtkCheckboxGroupPeer gp
|
||||
= GtkCheckboxGroupPeer.getCheckboxGroupPeer (group);
|
||||
if (gp != old_group)
|
||||
{
|
||||
if (old_group != null)
|
||||
old_group.remove (this);
|
||||
nativeSetCheckboxGroup (gp);
|
||||
old_group = gp;
|
||||
}
|
||||
}
|
||||
|
||||
// Override the superclass postItemEvent so that the peer doesn't
|
||||
// need information that we have.
|
||||
public void postItemEvent (Object item, int stateChange)
|
||||
{
|
||||
Checkbox currentCheckBox = ((Checkbox)awtComponent);
|
||||
// A firing of the event is only desired if the state has changed due to a
|
||||
// button press. The currentCheckBox's state must be different from the
|
||||
// one that the stateChange is changing to.
|
||||
// stateChange = 1 if it goes from false -> true
|
||||
// stateChange = 2 if it goes from true -> false
|
||||
if (( !currentCheckBox.getState() && stateChange == 1)
|
||||
|| (currentCheckBox.getState() && stateChange == 2))
|
||||
{
|
||||
super.postItemEvent (awtComponent, stateChange);
|
||||
currentState = !currentCheckBox.getState();
|
||||
currentCheckBox.setState(currentState);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose ()
|
||||
{
|
||||
// Notify the group so that the native state can be cleaned up
|
||||
// appropriately.
|
||||
if (old_group != null)
|
||||
old_group.remove (this);
|
||||
super.dispose ();
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
/* GtkChoicePeer.java -- Implements ChoicePeer with GTK
|
||||
Copyright (C) 1998, 1999, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Choice;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.peer.ChoicePeer;
|
||||
|
||||
public class GtkChoicePeer extends GtkComponentPeer
|
||||
implements ChoicePeer
|
||||
{
|
||||
public GtkChoicePeer (Choice c)
|
||||
{
|
||||
super (c);
|
||||
|
||||
int count = c.getItemCount ();
|
||||
if (count > 0)
|
||||
{
|
||||
String items[] = new String[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
items[i] = c.getItem (i);
|
||||
|
||||
append (items);
|
||||
}
|
||||
|
||||
int selected = c.getSelectedIndex();
|
||||
if (selected >= 0)
|
||||
select(selected);
|
||||
}
|
||||
|
||||
native void create ();
|
||||
|
||||
native void append (String items[]);
|
||||
native int nativeGetSelected ();
|
||||
native void nativeAdd (String item, int index);
|
||||
native void nativeRemove (int index);
|
||||
native void nativeRemoveAll ();
|
||||
|
||||
public native void select (int position);
|
||||
|
||||
public void add (String item, int index)
|
||||
{
|
||||
int before = nativeGetSelected();
|
||||
|
||||
nativeAdd (item, index);
|
||||
|
||||
/* Generate an ItemEvent if we added the first one or
|
||||
if we inserted at or before the currently selected item. */
|
||||
if ((before < 0) || (before >= index))
|
||||
{
|
||||
// Must set our state before notifying listeners
|
||||
((Choice) awtComponent).select (((Choice) awtComponent).getItem (0));
|
||||
postItemEvent (((Choice) awtComponent).getItem (0), ItemEvent.SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove (int index)
|
||||
{
|
||||
int before = nativeGetSelected();
|
||||
int after;
|
||||
|
||||
nativeRemove (index);
|
||||
after = nativeGetSelected();
|
||||
|
||||
/* Generate an ItemEvent if we are removing the currently selected item
|
||||
and there are at least one item left. */
|
||||
if ((before == index) && (after >= 0))
|
||||
{
|
||||
// Must set our state before notifying listeners
|
||||
((Choice) awtComponent).select (((Choice) awtComponent).getItem (0));
|
||||
postItemEvent (((Choice) awtComponent).getItem (0), ItemEvent.SELECTED);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAll ()
|
||||
{
|
||||
nativeRemoveAll();
|
||||
}
|
||||
|
||||
public void addItem (String item, int position)
|
||||
{
|
||||
add (item, position);
|
||||
}
|
||||
|
||||
protected void choicePostItemEvent (String label, int stateChange)
|
||||
{
|
||||
// Must set our state before notifying listeners
|
||||
if (stateChange == ItemEvent.SELECTED)
|
||||
((Choice) awtComponent).select (label);
|
||||
postItemEvent (label, stateChange);
|
||||
}
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
/* GtkClipboard.java
|
||||
Copyright (C) 1999, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.ClipboardOwner;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class GtkClipboard extends Clipboard
|
||||
{
|
||||
/* the number of milliseconds that we'll wait around for the
|
||||
owner of the GDK_SELECTION_PRIMARY selection to convert
|
||||
the requested data */
|
||||
static final int SELECTION_RECEIVED_TIMEOUT = 5000;
|
||||
|
||||
/* We currently only support transferring of text between applications */
|
||||
static String selection;
|
||||
static Object selectionLock = new Object ();
|
||||
|
||||
static boolean hasSelection = false;
|
||||
|
||||
protected GtkClipboard()
|
||||
{
|
||||
super("System Clipboard");
|
||||
initNativeState();
|
||||
}
|
||||
|
||||
public Transferable getContents(Object requestor)
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
if (hasSelection)
|
||||
return contents;
|
||||
}
|
||||
|
||||
/* Java doesn't own the selection, so we need to ask X11 */
|
||||
// XXX: Does this hold with Swing too ?
|
||||
synchronized (selectionLock)
|
||||
{
|
||||
requestStringConversion();
|
||||
|
||||
try
|
||||
{
|
||||
selectionLock.wait(SELECTION_RECEIVED_TIMEOUT);
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return selection == null ? null : new StringSelection(selection);
|
||||
}
|
||||
}
|
||||
|
||||
void stringSelectionReceived(String newSelection)
|
||||
{
|
||||
synchronized (selectionLock)
|
||||
{
|
||||
selection = newSelection;
|
||||
selectionLock.notify();
|
||||
}
|
||||
}
|
||||
|
||||
/* convert Java clipboard data into a String suitable for sending
|
||||
to another application */
|
||||
synchronized String stringSelectionHandler() throws IOException
|
||||
{
|
||||
String selection = null;
|
||||
|
||||
try
|
||||
{
|
||||
if (contents.isDataFlavorSupported(DataFlavor.stringFlavor))
|
||||
selection = (String)contents.getTransferData(DataFlavor.stringFlavor);
|
||||
else if (contents.isDataFlavorSupported(DataFlavor.plainTextFlavor))
|
||||
{
|
||||
StringBuffer sbuf = new StringBuffer();
|
||||
InputStreamReader reader;
|
||||
char readBuf[] = new char[512];
|
||||
int numChars;
|
||||
|
||||
reader = new InputStreamReader
|
||||
((InputStream)
|
||||
contents.getTransferData(DataFlavor.plainTextFlavor), "UNICODE");
|
||||
|
||||
while (true)
|
||||
{
|
||||
numChars = reader.read(readBuf);
|
||||
if (numChars == -1)
|
||||
break;
|
||||
sbuf.append(readBuf, 0, numChars);
|
||||
}
|
||||
|
||||
selection = new String(sbuf);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
}
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
public synchronized void setContents(Transferable contents,
|
||||
ClipboardOwner owner)
|
||||
{
|
||||
selectionGet();
|
||||
|
||||
this.contents = contents;
|
||||
this.owner = owner;
|
||||
|
||||
hasSelection = true;
|
||||
}
|
||||
|
||||
synchronized void selectionClear()
|
||||
{
|
||||
hasSelection = false;
|
||||
|
||||
if (owner != null)
|
||||
{
|
||||
owner.lostOwnership(this, contents);
|
||||
owner = null;
|
||||
contents = null;
|
||||
}
|
||||
}
|
||||
|
||||
native void initNativeState();
|
||||
static native void requestStringConversion();
|
||||
static native void selectionGet();
|
||||
}
|
||||
@@ -1,662 +0,0 @@
|
||||
/* GtkComponentPeer.java -- Implements ComponentPeer with GTK
|
||||
Copyright (C) 1998, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.BufferCapabilities;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
import java.awt.ItemSelectable;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.ImageProducer;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
|
||||
public class GtkComponentPeer extends GtkGenericPeer
|
||||
implements ComponentPeer
|
||||
{
|
||||
VolatileImage backBuffer;
|
||||
BufferCapabilities caps;
|
||||
|
||||
Component awtComponent;
|
||||
|
||||
Insets insets;
|
||||
|
||||
boolean isInRepaint;
|
||||
|
||||
/* this isEnabled differs from Component.isEnabled, in that it
|
||||
knows if a parent is disabled. In that case Component.isEnabled
|
||||
may return true, but our isEnabled will always return false */
|
||||
native boolean isEnabled ();
|
||||
static native boolean modalHasGrab();
|
||||
|
||||
native int[] gtkWidgetGetForeground ();
|
||||
native int[] gtkWidgetGetBackground ();
|
||||
native void gtkWidgetGetDimensions (int[] dim);
|
||||
native void gtkWidgetGetPreferredDimensions (int[] dim);
|
||||
native void gtkWidgetGetLocationOnScreen (int[] point);
|
||||
native void gtkWidgetSetCursor (int type);
|
||||
native void gtkWidgetSetBackground (int red, int green, int blue);
|
||||
native void gtkWidgetSetForeground (int red, int green, int blue);
|
||||
native void gtkWidgetSetSensitive (boolean sensitive);
|
||||
native void gtkWidgetSetParent (ComponentPeer parent);
|
||||
native void gtkWidgetRequestFocus ();
|
||||
native void gtkWidgetDispatchKeyEvent (int id, long when, int mods,
|
||||
int keyCode, int keyLocation);
|
||||
|
||||
native boolean isRealized ();
|
||||
|
||||
void create ()
|
||||
{
|
||||
throw new RuntimeException ();
|
||||
}
|
||||
|
||||
native void connectSignals ();
|
||||
|
||||
protected GtkComponentPeer (Component awtComponent)
|
||||
{
|
||||
super (awtComponent);
|
||||
this.awtComponent = awtComponent;
|
||||
insets = new Insets (0, 0, 0, 0);
|
||||
|
||||
create ();
|
||||
|
||||
connectSignals ();
|
||||
|
||||
if (awtComponent.getForeground () != null)
|
||||
setForeground (awtComponent.getForeground ());
|
||||
if (awtComponent.getBackground () != null)
|
||||
setBackground (awtComponent.getBackground ());
|
||||
if (awtComponent.getFont() != null)
|
||||
setFont(awtComponent.getFont());
|
||||
|
||||
Component parent = awtComponent.getParent ();
|
||||
|
||||
// Only set our parent on the GTK side if our parent on the AWT
|
||||
// side is not showing. Otherwise the gtk peer will be shown
|
||||
// before we've had a chance to position and size it properly.
|
||||
if (awtComponent instanceof Window
|
||||
|| (parent != null && ! parent.isShowing ()))
|
||||
setParentAndBounds ();
|
||||
}
|
||||
|
||||
void setParentAndBounds ()
|
||||
{
|
||||
setParent ();
|
||||
|
||||
setComponentBounds ();
|
||||
|
||||
setVisibleAndEnabled ();
|
||||
}
|
||||
|
||||
void setParent ()
|
||||
{
|
||||
ComponentPeer p;
|
||||
Component component = awtComponent;
|
||||
do
|
||||
{
|
||||
component = component.getParent ();
|
||||
p = component.getPeer ();
|
||||
}
|
||||
while (p instanceof java.awt.peer.LightweightPeer);
|
||||
|
||||
if (p != null)
|
||||
gtkWidgetSetParent (p);
|
||||
}
|
||||
|
||||
void beginNativeRepaint ()
|
||||
{
|
||||
isInRepaint = true;
|
||||
}
|
||||
|
||||
void endNativeRepaint ()
|
||||
{
|
||||
isInRepaint = false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the bounds of this peer's AWT Component based on dimensions
|
||||
* returned by the native windowing system. Most Components impose
|
||||
* their dimensions on the peers which is what the default
|
||||
* implementation does. However some peers, like GtkFileDialogPeer,
|
||||
* need to pass their size back to the AWT Component.
|
||||
*/
|
||||
void setComponentBounds ()
|
||||
{
|
||||
Rectangle bounds = awtComponent.getBounds ();
|
||||
|
||||
if (bounds.x == 0 && bounds.y == 0
|
||||
&& bounds.width == 0 && bounds.height == 0)
|
||||
return;
|
||||
|
||||
setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
|
||||
}
|
||||
|
||||
void setVisibleAndEnabled ()
|
||||
{
|
||||
setVisible (awtComponent.isVisible ());
|
||||
setEnabled (awtComponent.isEnabled ());
|
||||
}
|
||||
|
||||
public int checkImage (Image image, int width, int height,
|
||||
ImageObserver observer)
|
||||
{
|
||||
GtkImage i = (GtkImage) image;
|
||||
return i.checkImage ();
|
||||
}
|
||||
|
||||
public Image createImage (ImageProducer producer)
|
||||
{
|
||||
GtkImage image = new GtkImage (producer, null);
|
||||
producer.startProduction (image);
|
||||
return image;
|
||||
}
|
||||
|
||||
public Image createImage (int width, int height)
|
||||
{
|
||||
Graphics g;
|
||||
if (GtkToolkit.useGraphics2D ())
|
||||
{
|
||||
Graphics2D g2 = new GdkGraphics2D (width, height);
|
||||
g2.setBackground (getBackground ());
|
||||
g = g2;
|
||||
}
|
||||
else
|
||||
g = new GdkGraphics (width, height);
|
||||
|
||||
g.setColor(getBackground());
|
||||
g.fillRect(0, 0, width, height);
|
||||
|
||||
return new GtkOffScreenImage (null, g, width, height);
|
||||
}
|
||||
|
||||
public void disable ()
|
||||
{
|
||||
setEnabled (false);
|
||||
}
|
||||
|
||||
public void enable ()
|
||||
{
|
||||
setEnabled (true);
|
||||
}
|
||||
|
||||
public ColorModel getColorModel ()
|
||||
{
|
||||
return ColorModel.getRGBdefault ();
|
||||
}
|
||||
|
||||
public FontMetrics getFontMetrics (Font font)
|
||||
{
|
||||
return getToolkit().getFontMetrics(font);
|
||||
}
|
||||
|
||||
public Graphics getGraphics ()
|
||||
{
|
||||
if (GtkToolkit.useGraphics2D ())
|
||||
return new GdkGraphics2D (this);
|
||||
else
|
||||
return new GdkGraphics (this);
|
||||
}
|
||||
|
||||
public Point getLocationOnScreen ()
|
||||
{
|
||||
int point[] = new int[2];
|
||||
gtkWidgetGetLocationOnScreen (point);
|
||||
return new Point (point[0], point[1]);
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize ()
|
||||
{
|
||||
return minimumSize ();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize ()
|
||||
{
|
||||
return preferredSize ();
|
||||
}
|
||||
|
||||
public Toolkit getToolkit ()
|
||||
{
|
||||
return Toolkit.getDefaultToolkit();
|
||||
}
|
||||
|
||||
public void handleEvent (AWTEvent event)
|
||||
{
|
||||
int id = event.getID();
|
||||
KeyEvent ke = null;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case PaintEvent.PAINT:
|
||||
case PaintEvent.UPDATE:
|
||||
{
|
||||
try
|
||||
{
|
||||
Graphics g = getGraphics ();
|
||||
|
||||
// Some peers like GtkFileDialogPeer are repainted by Gtk itself
|
||||
if (g == null)
|
||||
break;
|
||||
|
||||
g.setClip (((PaintEvent) event).getUpdateRect());
|
||||
|
||||
if (id == PaintEvent.PAINT)
|
||||
awtComponent.paint (g);
|
||||
else
|
||||
awtComponent.update (g);
|
||||
|
||||
g.dispose ();
|
||||
}
|
||||
catch (InternalError e)
|
||||
{
|
||||
System.err.println (e);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KeyEvent.KEY_PRESSED:
|
||||
ke = (KeyEvent) event;
|
||||
gtkWidgetDispatchKeyEvent (ke.getID (), ke.getWhen (), ke.getModifiersEx (),
|
||||
ke.getKeyCode (), ke.getKeyLocation ());
|
||||
break;
|
||||
case KeyEvent.KEY_RELEASED:
|
||||
ke = (KeyEvent) event;
|
||||
gtkWidgetDispatchKeyEvent (ke.getID (), ke.getWhen (), ke.getModifiersEx (),
|
||||
ke.getKeyCode (), ke.getKeyLocation ());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFocusTraversable ()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public Dimension minimumSize ()
|
||||
{
|
||||
int dim[] = new int[2];
|
||||
|
||||
gtkWidgetGetPreferredDimensions (dim);
|
||||
|
||||
return new Dimension (dim[0], dim[1]);
|
||||
}
|
||||
|
||||
public void paint (Graphics g)
|
||||
{
|
||||
}
|
||||
|
||||
public Dimension preferredSize ()
|
||||
{
|
||||
int dim[] = new int[2];
|
||||
|
||||
gtkWidgetGetPreferredDimensions (dim);
|
||||
|
||||
return new Dimension (dim[0], dim[1]);
|
||||
}
|
||||
|
||||
public boolean prepareImage (Image image, int width, int height,
|
||||
ImageObserver observer)
|
||||
{
|
||||
GtkImage i = (GtkImage) image;
|
||||
|
||||
if (i.isLoaded ()) return true;
|
||||
|
||||
class PrepareImage extends Thread
|
||||
{
|
||||
GtkImage image;
|
||||
ImageObserver observer;
|
||||
|
||||
PrepareImage (GtkImage image, ImageObserver observer)
|
||||
{
|
||||
this.image = image;
|
||||
image.setObserver (observer);
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
image.source.startProduction (image);
|
||||
}
|
||||
}
|
||||
|
||||
new PrepareImage (i, observer).start ();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void print (Graphics g)
|
||||
{
|
||||
throw new RuntimeException ();
|
||||
}
|
||||
|
||||
public void repaint (long tm, int x, int y, int width, int height)
|
||||
{
|
||||
if (x == 0 && y == 0 && width == 0 && height == 0)
|
||||
return;
|
||||
|
||||
q().postEvent (new PaintEvent (awtComponent, PaintEvent.UPDATE,
|
||||
new Rectangle (x, y, width, height)));
|
||||
}
|
||||
|
||||
public void requestFocus ()
|
||||
{
|
||||
gtkWidgetRequestFocus();
|
||||
postFocusEvent(FocusEvent.FOCUS_GAINED, false);
|
||||
}
|
||||
|
||||
public void reshape (int x, int y, int width, int height)
|
||||
{
|
||||
setBounds (x, y, width, height);
|
||||
}
|
||||
|
||||
public void setBackground (Color c)
|
||||
{
|
||||
gtkWidgetSetBackground (c.getRed(), c.getGreen(), c.getBlue());
|
||||
}
|
||||
|
||||
native void setNativeBounds (int x, int y, int width, int height);
|
||||
|
||||
public void setBounds (int x, int y, int width, int height)
|
||||
{
|
||||
Component parent = awtComponent.getParent ();
|
||||
|
||||
// Heavyweight components that are children of one or more
|
||||
// lightweight containers have to be handled specially. Because
|
||||
// calls to GLightweightPeer.setBounds do nothing, GTK has no
|
||||
// knowledge of the lightweight containers' positions. So we have
|
||||
// to add the offsets manually when placing a heavyweight
|
||||
// component within a lightweight container. The lightweight
|
||||
// container may itself be in a lightweight container and so on,
|
||||
// so we need to continue adding offsets until we reach a
|
||||
// container whose position GTK knows -- that is, the first
|
||||
// non-lightweight.
|
||||
boolean lightweightChild = false;
|
||||
Insets i;
|
||||
while (parent.isLightweight ())
|
||||
{
|
||||
lightweightChild = true;
|
||||
|
||||
i = ((Container) parent).getInsets ();
|
||||
|
||||
x += parent.getX () + i.left;
|
||||
y += parent.getY () + i.top;
|
||||
|
||||
parent = parent.getParent ();
|
||||
}
|
||||
|
||||
// We only need to convert from Java to GTK coordinates if we're
|
||||
// placing a heavyweight component in a Window.
|
||||
if (parent instanceof Window && !lightweightChild)
|
||||
{
|
||||
Insets insets = ((Window) parent).getInsets ();
|
||||
GtkWindowPeer peer = (GtkWindowPeer) parent.getPeer ();
|
||||
int menuBarHeight = 0;
|
||||
if (peer instanceof GtkFramePeer)
|
||||
menuBarHeight = ((GtkFramePeer) peer).getMenuBarHeight ();
|
||||
|
||||
// Convert from Java coordinates to GTK coordinates.
|
||||
setNativeBounds (x - insets.left, y - insets.top + menuBarHeight,
|
||||
width, height);
|
||||
}
|
||||
else
|
||||
setNativeBounds (x, y, width, height);
|
||||
}
|
||||
|
||||
void setCursor ()
|
||||
{
|
||||
setCursor (awtComponent.getCursor ());
|
||||
}
|
||||
|
||||
public void setCursor (Cursor cursor)
|
||||
{
|
||||
gtkWidgetSetCursor (cursor.getType ());
|
||||
}
|
||||
|
||||
public void setEnabled (boolean b)
|
||||
{
|
||||
gtkWidgetSetSensitive (b);
|
||||
}
|
||||
|
||||
public void setFont (Font f)
|
||||
{
|
||||
// FIXME: This should really affect the widget tree below me.
|
||||
// Currently this is only handled if the call is made directly on
|
||||
// a text widget, which implements setFont() itself.
|
||||
gtkWidgetModifyFont(f.getName(), f.getStyle(), f.getSize());
|
||||
}
|
||||
|
||||
public void setForeground (Color c)
|
||||
{
|
||||
gtkWidgetSetForeground (c.getRed(), c.getGreen(), c.getBlue());
|
||||
}
|
||||
|
||||
public Color getForeground ()
|
||||
{
|
||||
int rgb[] = gtkWidgetGetForeground ();
|
||||
return new Color (rgb[0], rgb[1], rgb[2]);
|
||||
}
|
||||
|
||||
public Color getBackground ()
|
||||
{
|
||||
int rgb[] = gtkWidgetGetBackground ();
|
||||
return new Color (rgb[0], rgb[1], rgb[2]);
|
||||
}
|
||||
|
||||
public void setVisible (boolean b)
|
||||
{
|
||||
if (b)
|
||||
show ();
|
||||
else
|
||||
hide ();
|
||||
}
|
||||
|
||||
public native void hide ();
|
||||
public native void show ();
|
||||
|
||||
protected void postMouseEvent(int id, long when, int mods, int x, int y,
|
||||
int clickCount, boolean popupTrigger)
|
||||
{
|
||||
q().postEvent(new MouseEvent(awtComponent, id, when, mods, x, y,
|
||||
clickCount, popupTrigger));
|
||||
}
|
||||
|
||||
protected void postExposeEvent (int x, int y, int width, int height)
|
||||
{
|
||||
if (!isInRepaint)
|
||||
q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
|
||||
new Rectangle (x, y, width, height)));
|
||||
}
|
||||
|
||||
protected void postKeyEvent (int id, long when, int mods,
|
||||
int keyCode, char keyChar, int keyLocation)
|
||||
{
|
||||
KeyEvent keyEvent = new KeyEvent (awtComponent, id, when, mods,
|
||||
keyCode, keyChar, keyLocation);
|
||||
|
||||
// Also post a KEY_TYPED event if keyEvent is a key press that
|
||||
// doesn't represent an action or modifier key.
|
||||
if (keyEvent.getID () == KeyEvent.KEY_PRESSED
|
||||
&& (!keyEvent.isActionKey ()
|
||||
&& keyCode != KeyEvent.VK_SHIFT
|
||||
&& keyCode != KeyEvent.VK_CONTROL
|
||||
&& keyCode != KeyEvent.VK_ALT))
|
||||
{
|
||||
synchronized (q)
|
||||
{
|
||||
q().postEvent (keyEvent);
|
||||
q().postEvent (new KeyEvent (awtComponent, KeyEvent.KEY_TYPED, when, mods,
|
||||
KeyEvent.VK_UNDEFINED, keyChar, keyLocation));
|
||||
}
|
||||
}
|
||||
else
|
||||
q().postEvent (keyEvent);
|
||||
}
|
||||
|
||||
protected void postFocusEvent (int id, boolean temporary)
|
||||
{
|
||||
q().postEvent (new FocusEvent (awtComponent, id, temporary));
|
||||
}
|
||||
|
||||
protected void postItemEvent (Object item, int stateChange)
|
||||
{
|
||||
q().postEvent (new ItemEvent ((ItemSelectable)awtComponent,
|
||||
ItemEvent.ITEM_STATE_CHANGED,
|
||||
item, stateChange));
|
||||
}
|
||||
|
||||
public GraphicsConfiguration getGraphicsConfiguration ()
|
||||
{
|
||||
// FIXME: just a stub for now.
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setEventMask (long mask)
|
||||
{
|
||||
// FIXME: just a stub for now.
|
||||
}
|
||||
|
||||
public boolean isFocusable ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean requestFocus (Component source, boolean b1,
|
||||
boolean b2, long x)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isObscured ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canDetermineObscurity ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public void coalescePaintEvent (PaintEvent e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void updateCursorImmediately ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public boolean handlesWheelScrolling ()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convenience method to create a new volatile image on the screen
|
||||
// on which this component is displayed.
|
||||
public VolatileImage createVolatileImage (int width, int height)
|
||||
{
|
||||
return new GtkVolatileImage (width, height);
|
||||
}
|
||||
|
||||
// Creates buffers used in a buffering strategy.
|
||||
public void createBuffers (int numBuffers, BufferCapabilities caps)
|
||||
throws AWTException
|
||||
{
|
||||
// numBuffers == 2 implies double-buffering, meaning one back
|
||||
// buffer and one front buffer.
|
||||
if (numBuffers == 2)
|
||||
backBuffer = new GtkVolatileImage(awtComponent.getWidth(),
|
||||
awtComponent.getHeight(),
|
||||
caps.getBackBufferCapabilities());
|
||||
else
|
||||
throw new AWTException("GtkComponentPeer.createBuffers:"
|
||||
+ " multi-buffering not supported");
|
||||
this.caps = caps;
|
||||
}
|
||||
|
||||
// Return the back buffer.
|
||||
public Image getBackBuffer ()
|
||||
{
|
||||
return backBuffer;
|
||||
}
|
||||
|
||||
// FIXME: flip should be implemented as a fast native operation
|
||||
public void flip (BufferCapabilities.FlipContents contents)
|
||||
{
|
||||
getGraphics().drawImage(backBuffer,
|
||||
awtComponent.getWidth(),
|
||||
awtComponent.getHeight(),
|
||||
null);
|
||||
|
||||
// create new back buffer and clear it to the background color.
|
||||
if (contents == BufferCapabilities.FlipContents.BACKGROUND)
|
||||
{
|
||||
backBuffer = createVolatileImage(awtComponent.getWidth(),
|
||||
awtComponent.getHeight());
|
||||
backBuffer.getGraphics().clearRect(0, 0,
|
||||
awtComponent.getWidth(),
|
||||
awtComponent.getHeight());
|
||||
}
|
||||
// FIXME: support BufferCapabilities.FlipContents.PRIOR
|
||||
}
|
||||
|
||||
// Release the resources allocated to back buffers.
|
||||
public void destroyBuffers ()
|
||||
{
|
||||
backBuffer.flush();
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
/* GtkContainerPeer.java -- Implements ContainerPeer with GTK
|
||||
Copyright (C) 1998, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Window;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.awt.peer.ContainerPeer;
|
||||
|
||||
public class GtkContainerPeer extends GtkComponentPeer
|
||||
implements ContainerPeer
|
||||
{
|
||||
Container c;
|
||||
boolean isValidating;
|
||||
|
||||
public GtkContainerPeer(Container c)
|
||||
{
|
||||
super (c);
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
public void beginValidate ()
|
||||
{
|
||||
isValidating = true;
|
||||
}
|
||||
|
||||
public void endValidate ()
|
||||
{
|
||||
Component parent = awtComponent.getParent ();
|
||||
|
||||
// Only set our parent on the GTK side if our parent on the AWT
|
||||
// side is not showing. Otherwise the gtk peer will be shown
|
||||
// before we've had a chance to position and size it properly.
|
||||
if (parent != null && parent.isShowing ())
|
||||
{
|
||||
Component[] components = ((Container) awtComponent).getComponents ();
|
||||
int ncomponents = components.length;
|
||||
|
||||
for (int i = 0; i < ncomponents; i++)
|
||||
{
|
||||
ComponentPeer peer = components[i].getPeer ();
|
||||
|
||||
// Skip lightweight peers.
|
||||
if (peer instanceof GtkComponentPeer)
|
||||
((GtkComponentPeer) peer).setParentAndBounds ();
|
||||
}
|
||||
|
||||
// GTK windows don't have parents.
|
||||
if (!(awtComponent instanceof Window))
|
||||
setParentAndBounds ();
|
||||
}
|
||||
|
||||
isValidating = false;
|
||||
}
|
||||
|
||||
public Insets getInsets()
|
||||
{
|
||||
return insets;
|
||||
}
|
||||
|
||||
public Insets insets()
|
||||
{
|
||||
return getInsets ();
|
||||
}
|
||||
|
||||
public void setBounds (int x, int y, int width, int height)
|
||||
{
|
||||
super.setBounds (x, y, width, height);
|
||||
}
|
||||
|
||||
public void setFont(Font f)
|
||||
{
|
||||
super.setFont(f);
|
||||
Component[] components = ((Container) awtComponent).getComponents();
|
||||
for (int i = 0; i < components.length; i++)
|
||||
{
|
||||
GtkComponentPeer peer = (GtkComponentPeer) components[i].getPeer();
|
||||
if (peer != null && ! peer.awtComponent.isFontSet())
|
||||
peer.setFont(f);
|
||||
}
|
||||
}
|
||||
|
||||
public Graphics getGraphics ()
|
||||
{
|
||||
return super.getGraphics();
|
||||
}
|
||||
|
||||
public void beginLayout () { }
|
||||
public void endLayout () { }
|
||||
public boolean isPaintPending () { return false; }
|
||||
|
||||
public void setBackground (Color c)
|
||||
{
|
||||
super.setBackground(c);
|
||||
|
||||
Object components[] = ((Container) awtComponent).getComponents();
|
||||
for (int i = 0; i < components.length; i++)
|
||||
{
|
||||
Component comp = (Component) components[i];
|
||||
|
||||
// If the child's background has not been explicitly set yet,
|
||||
// it should inherit this container's background. This makes the
|
||||
// child component appear as if it has a transparent background.
|
||||
// Note that we do not alter the background property of the child,
|
||||
// but only repaint the child with the parent's background color.
|
||||
if (!comp.isBackgroundSet() && comp.getPeer() != null)
|
||||
comp.getPeer().setBackground(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/* GtkDialogPeer.java -- Implements DialogPeer with GTK
|
||||
Copyright (C) 1998, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.peer.DialogPeer;
|
||||
|
||||
public class GtkDialogPeer extends GtkWindowPeer
|
||||
implements DialogPeer
|
||||
{
|
||||
public GtkDialogPeer (Dialog dialog)
|
||||
{
|
||||
super (dialog);
|
||||
}
|
||||
|
||||
public Graphics getGraphics ()
|
||||
{
|
||||
Graphics g;
|
||||
if (GtkToolkit.useGraphics2D ())
|
||||
g = new GdkGraphics2D (this);
|
||||
else
|
||||
g = new GdkGraphics (this);
|
||||
g.translate (-insets.left, -insets.top);
|
||||
return g;
|
||||
}
|
||||
|
||||
protected void postMouseEvent(int id, long when, int mods, int x, int y,
|
||||
int clickCount, boolean popupTrigger)
|
||||
{
|
||||
super.postMouseEvent (id, when, mods,
|
||||
x + insets.left, y + insets.top,
|
||||
clickCount, popupTrigger);
|
||||
}
|
||||
|
||||
protected void postExposeEvent (int x, int y, int width, int height)
|
||||
{
|
||||
if (!isInRepaint)
|
||||
q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
|
||||
new Rectangle (x + insets.left,
|
||||
y + insets.top,
|
||||
width, height)));
|
||||
}
|
||||
|
||||
void create ()
|
||||
{
|
||||
// Create a decorated dialog window.
|
||||
create (GDK_WINDOW_TYPE_HINT_DIALOG, true);
|
||||
|
||||
Dialog dialog = (Dialog) awtComponent;
|
||||
|
||||
gtkWindowSetModal (dialog.isModal ());
|
||||
setTitle (dialog.getTitle ());
|
||||
setResizable (dialog.isResizable ());
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/* GtkEmbeddedWindowPeer.java -- Implements EmbeddedWindowPeer using a
|
||||
GtkPlug
|
||||
Copyright (C) 2003 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import gnu.java.awt.EmbeddedWindow;
|
||||
import gnu.java.awt.peer.EmbeddedWindowPeer;
|
||||
|
||||
public class GtkEmbeddedWindowPeer extends GtkFramePeer
|
||||
implements EmbeddedWindowPeer
|
||||
{
|
||||
native void create (long socket_id);
|
||||
|
||||
void create ()
|
||||
{
|
||||
create (((EmbeddedWindow) awtComponent).getHandle ());
|
||||
}
|
||||
|
||||
native void construct (long socket_id);
|
||||
|
||||
// FIXME: embed doesn't work right now, though I believe it should.
|
||||
// This means that you can't call setVisible (true) on an
|
||||
// EmbeddedWindow before calling setHandle with a valid handle. The
|
||||
// problem is that somewhere after the call to
|
||||
// GtkEmbeddedWindow.create and before the call to
|
||||
// GtkEmbeddedWindow.construct, the GtkPlug peer is being realized.
|
||||
// GtkSocket silently fails to embed an already-realized GtkPlug.
|
||||
public void embed (long handle)
|
||||
{
|
||||
construct (handle);
|
||||
}
|
||||
|
||||
public GtkEmbeddedWindowPeer (EmbeddedWindow w)
|
||||
{
|
||||
super (w);
|
||||
}
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
/* GtkFileDialogPeer.java -- Implements FileDialogPeer with GTK
|
||||
Copyright (C) 1998, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Window;
|
||||
import java.awt.peer.FileDialogPeer;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
|
||||
public class GtkFileDialogPeer extends GtkDialogPeer implements FileDialogPeer
|
||||
{
|
||||
static final String FS = System.getProperty("file.separator");
|
||||
|
||||
private String currentFile = null;
|
||||
private String currentDirectory = null;
|
||||
private FilenameFilter filter;
|
||||
|
||||
native void create (GtkContainerPeer parent);
|
||||
native void connectSignals ();
|
||||
native void nativeSetFile (String file);
|
||||
public native String nativeGetDirectory();
|
||||
public native void nativeSetDirectory(String directory);
|
||||
native void nativeSetFilenameFilter (FilenameFilter filter);
|
||||
|
||||
public void create()
|
||||
{
|
||||
create((GtkContainerPeer) awtComponent.getParent().getPeer());
|
||||
|
||||
FileDialog fd = (FileDialog) awtComponent;
|
||||
|
||||
setDirectory(fd.getDirectory());
|
||||
setFile(fd.getFile());
|
||||
|
||||
FilenameFilter filter = fd.getFilenameFilter();
|
||||
if (filter != null)
|
||||
setFilenameFilter(filter);
|
||||
}
|
||||
|
||||
public GtkFileDialogPeer (FileDialog fd)
|
||||
{
|
||||
super (fd);
|
||||
}
|
||||
|
||||
void setComponentBounds ()
|
||||
{
|
||||
if (awtComponent.getHeight () == 0
|
||||
&& awtComponent.getWidth () == 0)
|
||||
{
|
||||
int[] dims = new int[2];
|
||||
gtkWidgetGetPreferredDimensions (dims);
|
||||
((GtkFileDialogPeer) this).setBoundsCallback ((Window) awtComponent,
|
||||
awtComponent.getX (),
|
||||
awtComponent.getY (),
|
||||
dims[0], dims[1]);
|
||||
}
|
||||
super.setComponentBounds ();
|
||||
}
|
||||
|
||||
public void setFile (String fileName)
|
||||
{
|
||||
/* If nothing changed do nothing. This usually happens because
|
||||
the only way we have to set the file name in FileDialog is by
|
||||
calling its SetFile which will call us back. */
|
||||
if ((fileName == null && currentFile == null)
|
||||
|| (fileName != null && fileName.equals (currentFile)))
|
||||
return;
|
||||
|
||||
if (fileName == null || fileName.equals (""))
|
||||
{
|
||||
currentFile = "";
|
||||
nativeSetFile ("");
|
||||
return;
|
||||
}
|
||||
|
||||
// GtkFileChooser requires absolute filenames. If the given filename
|
||||
// is not absolute, let's construct it based on current directory.
|
||||
currentFile = fileName;
|
||||
if (fileName.indexOf(FS) == 0)
|
||||
{
|
||||
nativeSetFile (fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
nativeSetFile (nativeGetDirectory() + FS + fileName);
|
||||
}
|
||||
}
|
||||
|
||||
public void setDirectory (String directory)
|
||||
{
|
||||
/* If nothing changed so nothing. This usually happens because
|
||||
the only way we have to set the directory in FileDialog is by
|
||||
calling its setDirectory which will call us back. */
|
||||
if ((directory == null && currentDirectory == null)
|
||||
|| (directory != null && directory.equals (currentDirectory)))
|
||||
return;
|
||||
|
||||
if (directory == null || directory.equals (""))
|
||||
{
|
||||
currentDirectory = FS;
|
||||
nativeSetFile (FS);
|
||||
return;
|
||||
}
|
||||
|
||||
currentDirectory = directory;
|
||||
nativeSetDirectory (directory);
|
||||
}
|
||||
|
||||
public void setFilenameFilter (FilenameFilter filter)
|
||||
{
|
||||
this.filter = filter;
|
||||
nativeSetFilenameFilter(filter);
|
||||
}
|
||||
|
||||
/* This method interacts with the native callback function of the
|
||||
same name. The native function will extract the filename from the
|
||||
GtkFileFilterInfo object and send it to this method, which will
|
||||
in turn call the filter's accept() method and give back the return
|
||||
value. */
|
||||
boolean filenameFilterCallback (String fullname) {
|
||||
String filename = fullname.substring(fullname.lastIndexOf(FS) + 1);
|
||||
String dirname = fullname.substring(0, fullname.lastIndexOf(FS));
|
||||
File dir = new File(dirname);
|
||||
return filter.accept(dir, filename);
|
||||
}
|
||||
|
||||
public Graphics getGraphics ()
|
||||
{
|
||||
// GtkFileDialog will repaint by itself
|
||||
return null;
|
||||
}
|
||||
|
||||
void gtkHideFileDialog ()
|
||||
{
|
||||
((Dialog) awtComponent).hide();
|
||||
}
|
||||
|
||||
void gtkDisposeFileDialog ()
|
||||
{
|
||||
((Dialog) awtComponent).dispose();
|
||||
}
|
||||
|
||||
/* Callback to set the file and directory values when the user is finished
|
||||
* with the dialog.
|
||||
*/
|
||||
void gtkSetFilename (String fileName)
|
||||
{
|
||||
FileDialog fd = (FileDialog) awtWidget;
|
||||
if (fileName == null)
|
||||
{
|
||||
currentFile = null;
|
||||
fd.setFile(null);
|
||||
return;
|
||||
}
|
||||
|
||||
int sepIndex = fileName.lastIndexOf (FS);
|
||||
if (sepIndex < 0)
|
||||
{
|
||||
/* This should never happen on Unix (all paths start with '/') */
|
||||
currentFile = fileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fileName.length() > (sepIndex + 1))
|
||||
{
|
||||
String fn = fileName.substring (sepIndex + 1);
|
||||
currentFile = fn;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentFile = null;
|
||||
}
|
||||
|
||||
String dn = fileName.substring (0, sepIndex + 1);
|
||||
currentDirectory = dn;
|
||||
fd.setDirectory(dn);
|
||||
}
|
||||
|
||||
fd.setFile (currentFile);
|
||||
}
|
||||
}
|
||||
@@ -1,225 +0,0 @@
|
||||
/* GtkFontPeer.java -- Implements FontPeer with GTK+
|
||||
Copyright (C) 1999, 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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import gnu.java.awt.peer.ClasspathFontPeer;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.GlyphVector;
|
||||
import java.awt.font.LineMetrics;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.text.CharacterIterator;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class GtkFontPeer extends ClasspathFontPeer
|
||||
{
|
||||
private static ResourceBundle bundle;
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
bundle = ResourceBundle.getBundle ("gnu.java.awt.peer.gtk.font");
|
||||
}
|
||||
catch (Throwable ignored)
|
||||
{
|
||||
bundle = null;
|
||||
}
|
||||
}
|
||||
|
||||
private final String Xname;
|
||||
|
||||
public GtkFontPeer (String name, int style)
|
||||
{
|
||||
// All fonts get a default size of 12 if size is not specified.
|
||||
this(name, style, 12);
|
||||
}
|
||||
|
||||
public GtkFontPeer (String name, int style, int size)
|
||||
{
|
||||
super(name, style, size);
|
||||
|
||||
String Xname = null;
|
||||
if (bundle != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Xname = bundle.getString (name.toLowerCase () + "." + style);
|
||||
}
|
||||
catch (MissingResourceException mre)
|
||||
{
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
if (Xname == null)
|
||||
{
|
||||
String weight;
|
||||
String slant;
|
||||
String spacing;
|
||||
|
||||
if (style == Font.ITALIC || (style == (Font.BOLD+Font.ITALIC)))
|
||||
slant = "i";
|
||||
else
|
||||
slant = "r";
|
||||
if (style == Font.BOLD || (style == (Font.BOLD+Font.ITALIC)))
|
||||
weight = "bold";
|
||||
else
|
||||
weight = "medium";
|
||||
if (name.equals("Serif") || name.equals("SansSerif")
|
||||
|| name.equals("Helvetica") || name.equals("Times"))
|
||||
spacing = "p";
|
||||
else
|
||||
spacing = "c";
|
||||
|
||||
Xname = "-*-*-" + weight + "-" + slant + "-normal-*-*-" + size + "-*-*-" + spacing + "-*-*-*";
|
||||
}
|
||||
|
||||
this.Xname = Xname;
|
||||
}
|
||||
|
||||
public String getXLFD ()
|
||||
{
|
||||
return Xname;
|
||||
}
|
||||
|
||||
|
||||
/* remaining methods are for static compatibility with the newer
|
||||
ClasspathFontPeer superclass; none of these methods ever existed or
|
||||
worked on the older FontPeer interface, but we need to pretend to
|
||||
support them anyways. */
|
||||
|
||||
public boolean canDisplay (Font font, char c)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public int canDisplayUpTo (Font font, CharacterIterator i, int start, int limit)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getSubFamilyName (Font font, Locale locale)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getPostScriptName (Font font)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public int getNumGlyphs (Font font)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public int getMissingGlyphCode (Font font)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public byte getBaselineFor (Font font, char c)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getGlyphName (Font font, int glyphIndex)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public GlyphVector createGlyphVector (Font font,
|
||||
FontRenderContext frc,
|
||||
CharacterIterator ci)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public GlyphVector createGlyphVector (Font font,
|
||||
FontRenderContext ctx,
|
||||
int[] glyphCodes)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public GlyphVector layoutGlyphVector (Font font,
|
||||
FontRenderContext frc,
|
||||
char[] chars, int start,
|
||||
int limit, int flags)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public FontMetrics getFontMetrics (Font font)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean hasUniformLineMetrics (Font font)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public LineMetrics getLineMetrics (Font font,
|
||||
CharacterIterator ci,
|
||||
int begin, int limit,
|
||||
FontRenderContext rc)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Rectangle2D getMaxCharBounds (Font font,
|
||||
FontRenderContext rc)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Rectangle2D getStringBounds (Font font,
|
||||
CharacterIterator ci,
|
||||
int begin, int limit,
|
||||
FontRenderContext frc)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
/* GtkFramePeer.java -- Implements FramePeer with GTK
|
||||
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 gnu.java.awt.peer.gtk;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.PaintEvent;
|
||||
import java.awt.image.ColorModel;
|
||||
import java.awt.peer.FramePeer;
|
||||
import java.awt.peer.MenuBarPeer;
|
||||
|
||||
public class GtkFramePeer extends GtkWindowPeer
|
||||
implements FramePeer
|
||||
{
|
||||
private int menuBarHeight;
|
||||
private MenuBarPeer menuBar;
|
||||
native int getMenuBarHeight (MenuBarPeer bar);
|
||||
native void setMenuBarWidth (MenuBarPeer bar, int width);
|
||||
native void setMenuBarPeer (MenuBarPeer bar);
|
||||
native void removeMenuBarPeer ();
|
||||
native void gtkFixedSetVisible (boolean visible);
|
||||
|
||||
int getMenuBarHeight ()
|
||||
{
|
||||
return menuBar == null ? 0 : getMenuBarHeight (menuBar);
|
||||
}
|
||||
|
||||
public void setMenuBar (MenuBar bar)
|
||||
{
|
||||
if (bar == null && menuBar != null)
|
||||
{
|
||||
// We're removing the menubar.
|
||||
gtkFixedSetVisible (false);
|
||||
menuBar = null;
|
||||
removeMenuBarPeer ();
|
||||
insets.top -= menuBarHeight;
|
||||
menuBarHeight = 0;
|
||||
awtComponent.validate ();
|
||||
gtkFixedSetVisible (true);
|
||||
}
|
||||
else if (bar != null && menuBar == null)
|
||||
{
|
||||
// We're adding a menubar where there was no menubar before.
|
||||
gtkFixedSetVisible (false);
|
||||
menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer();
|
||||
setMenuBarPeer (menuBar);
|
||||
int menuBarWidth =
|
||||
awtComponent.getWidth () - insets.left - insets.right;
|
||||
if (menuBarWidth > 0)
|
||||
setMenuBarWidth (menuBar, menuBarWidth);
|
||||
menuBarHeight = getMenuBarHeight ();
|
||||
insets.top += menuBarHeight;
|
||||
awtComponent.validate ();
|
||||
gtkFixedSetVisible (true);
|
||||
}
|
||||
else if (bar != null && menuBar != null)
|
||||
{
|
||||
// We're swapping the menubar.
|
||||
gtkFixedSetVisible (false);
|
||||
removeMenuBarPeer();
|
||||
int oldHeight = menuBarHeight;
|
||||
int menuBarWidth =
|
||||
awtComponent.getWidth () - insets.left - insets.right;
|
||||
menuBar = (MenuBarPeer) ((MenuBar) bar).getPeer ();
|
||||
setMenuBarPeer (menuBar);
|
||||
if (menuBarWidth > 0)
|
||||
setMenuBarWidth (menuBar, menuBarWidth);
|
||||
menuBarHeight = getMenuBarHeight ();
|
||||
if (oldHeight != menuBarHeight)
|
||||
{
|
||||
insets.top += (menuBarHeight - oldHeight);
|
||||
awtComponent.validate ();
|
||||
}
|
||||
gtkFixedSetVisible (true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBounds (int x, int y, int width, int height)
|
||||
{
|
||||
int menuBarWidth = width - insets.left - insets.right;
|
||||
if (menuBar != null && menuBarWidth > 0)
|
||||
setMenuBarWidth (menuBar, menuBarWidth);
|
||||
|
||||
nativeSetBounds (x, y,
|
||||
width - insets.left - insets.right,
|
||||
height - insets.top - insets.bottom
|
||||
+ menuBarHeight);
|
||||
}
|
||||
|
||||
public void setResizable (boolean resizable)
|
||||
{
|
||||
// Call setSize; otherwise when resizable is changed from true to
|
||||
// false the frame will shrink to the dimensions it had before it
|
||||
// was resizable.
|
||||
setSize (awtComponent.getWidth() - insets.left - insets.right,
|
||||
awtComponent.getHeight() - insets.top - insets.bottom
|
||||
+ menuBarHeight);
|
||||
gtkWindowSetResizable (resizable);
|
||||
}
|
||||
|
||||
protected void postInsetsChangedEvent (int top, int left,
|
||||
int bottom, int right)
|
||||
{
|
||||
insets.top = top + menuBarHeight;
|
||||
insets.left = left;
|
||||
insets.bottom = bottom;
|
||||
insets.right = right;
|
||||
}
|
||||
|
||||
public GtkFramePeer (Frame frame)
|
||||
{
|
||||
super (frame);
|
||||
}
|
||||
|
||||
void create ()
|
||||
{
|
||||
// Create a normal decorated window.
|
||||
create (GDK_WINDOW_TYPE_HINT_NORMAL, true);
|
||||
|
||||
Frame frame = (Frame) awtComponent;
|
||||
|
||||
setMenuBar (frame.getMenuBar ());
|
||||
|
||||
setTitle (frame.getTitle ());
|
||||
gtkWindowSetResizable (frame.isResizable ());
|
||||
setIconImage(frame.getIconImage());
|
||||
}
|
||||
|
||||
native void nativeSetIconImageFromDecoder (GdkPixbufDecoder decoder);
|
||||
native void nativeSetIconImageFromData (int[] pixels, int width, int height);
|
||||
public void setIconImage (Image image)
|
||||
{
|
||||
if (image != null && image instanceof GtkImage)
|
||||
{
|
||||
GtkImage img = (GtkImage) image;
|
||||
// FIXME: Image should be loaded, but if not, do image loading here.
|
||||
if (img.isLoaded())
|
||||
{
|
||||
if (img.getSource() instanceof GdkPixbufDecoder)
|
||||
{
|
||||
nativeSetIconImageFromDecoder((GdkPixbufDecoder) img.getSource());
|
||||
}
|
||||
else
|
||||
{
|
||||
int[] pixels = img.getPixelCache();
|
||||
ColorModel model = img.getColorModel();
|
||||
int[] data = new int[pixels.length * 4];
|
||||
for (int i = 0; i < pixels.length; i++)
|
||||
{
|
||||
data[i * 4] = model.getRed(pixels[i]);
|
||||
data[i * 4 + 1] = model.getGreen(pixels[i]);
|
||||
data[i * 4 + 2] = model.getBlue(pixels[i]);
|
||||
data[i * 4 + 3] = model.getAlpha(pixels[i]);
|
||||
}
|
||||
nativeSetIconImageFromData(data, img.getWidth(null), img.getHeight(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Graphics getGraphics ()
|
||||
{
|
||||
Graphics g;
|
||||
if (GtkToolkit.useGraphics2D ())
|
||||
g = new GdkGraphics2D (this);
|
||||
else
|
||||
g = new GdkGraphics (this);
|
||||
g.translate (-insets.left, -insets.top);
|
||||
return g;
|
||||
}
|
||||
|
||||
protected void postConfigureEvent (int x, int y, int width, int height)
|
||||
{
|
||||
int frame_x = x - insets.left;
|
||||
// Since insets.top includes the MenuBar height, we need to add back
|
||||
// the MenuBar height to the frame's y position.
|
||||
// If no MenuBar exists in this frame, the MenuBar height will be 0.
|
||||
int frame_y = y - insets.top + menuBarHeight;
|
||||
int frame_width = width + insets.left + insets.right;
|
||||
// Ditto as above. Since insets.top already includes the MenuBar's height,
|
||||
// we need to subtract the MenuBar's height from the top inset.
|
||||
int frame_height = height + insets.top + insets.bottom - menuBarHeight;
|
||||
if (frame_x != awtComponent.getX()
|
||||
|| frame_y != awtComponent.getY()
|
||||
|| frame_width != awtComponent.getWidth()
|
||||
|| frame_height != awtComponent.getHeight())
|
||||
{
|
||||
if (frame_width != awtComponent.getWidth() && menuBar != null
|
||||
&& width > 0)
|
||||
setMenuBarWidth (menuBar, width);
|
||||
|
||||
setBoundsCallback ((Window) awtComponent,
|
||||
frame_x,
|
||||
frame_y,
|
||||
frame_width,
|
||||
frame_height);
|
||||
|
||||
awtComponent.validate();
|
||||
}
|
||||
}
|
||||
|
||||
protected void postMouseEvent(int id, long when, int mods, int x, int y,
|
||||
int clickCount, boolean popupTrigger)
|
||||
{
|
||||
super.postMouseEvent (id, when, mods,
|
||||
x + insets.left, y + insets.top,
|
||||
clickCount, popupTrigger);
|
||||
}
|
||||
|
||||
protected void postExposeEvent (int x, int y, int width, int height)
|
||||
{
|
||||
if (!isInRepaint)
|
||||
q().postEvent (new PaintEvent (awtComponent, PaintEvent.PAINT,
|
||||
new Rectangle (x + insets.left,
|
||||
y + insets.top,
|
||||
width, height)));
|
||||
}
|
||||
|
||||
public int getState ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void setState (int state)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void setMaximizedBounds (Rectangle r)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user