use of java.applet.Applet in project jdk8u_jdk by JetBrains.
the class Component method getNextFocusCandidate.
final Component getNextFocusCandidate() {
Container rootAncestor = getTraversalRoot();
Component comp = this;
while (rootAncestor != null && !(rootAncestor.isShowing() && rootAncestor.canBeFocusOwner())) {
comp = rootAncestor;
rootAncestor = comp.getFocusCycleRootAncestor();
}
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
focusLog.finer("comp = " + comp + ", root = " + rootAncestor);
}
Component candidate = null;
if (rootAncestor != null) {
FocusTraversalPolicy policy = rootAncestor.getFocusTraversalPolicy();
Component toFocus = policy.getComponentAfter(rootAncestor, comp);
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
focusLog.finer("component after is " + toFocus);
}
if (toFocus == null) {
toFocus = policy.getDefaultComponent(rootAncestor);
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
focusLog.finer("default component is " + toFocus);
}
}
if (toFocus == null) {
Applet applet = EmbeddedFrame.getAppletIfAncestorOf(this);
if (applet != null) {
toFocus = applet;
}
}
candidate = toFocus;
}
if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
focusLog.finer("Focus transfer candidate: " + candidate);
}
return candidate;
}
use of java.applet.Applet in project jdk8u_jdk by JetBrains.
the class BeansAppletStub method instantiate.
/**
* Instantiate a bean.
* <p>
* The bean is created based on a name relative to a class-loader.
* This name should be a dot-separated name such as "a.b.c".
* <p>
* In Beans 1.0 the given name can indicate either a serialized object
* or a class. Other mechanisms may be added in the future. In
* beans 1.0 we first try to treat the beanName as a serialized object
* name then as a class name.
* <p>
* When using the beanName as a serialized object name we convert the
* given beanName to a resource pathname and add a trailing ".ser" suffix.
* We then try to load a serialized object from that resource.
* <p>
* For example, given a beanName of "x.y", Beans.instantiate would first
* try to read a serialized object from the resource "x/y.ser" and if
* that failed it would try to load the class "x.y" and create an
* instance of that class.
* <p>
* If the bean is a subtype of java.applet.Applet, then it is given
* some special initialization. First, it is supplied with a default
* AppletStub and AppletContext. Second, if it was instantiated from
* a classname the applet's "init" method is called. (If the bean was
* deserialized this step is skipped.)
* <p>
* Note that for beans which are applets, it is the caller's responsiblity
* to call "start" on the applet. For correct behaviour, this should be done
* after the applet has been added into a visible AWT container.
* <p>
* Note that applets created via beans.instantiate run in a slightly
* different environment than applets running inside browsers. In
* particular, bean applets have no access to "parameters", so they may
* wish to provide property get/set methods to set parameter values. We
* advise bean-applet developers to test their bean-applets against both
* the JDK appletviewer (for a reference browser environment) and the
* BDK BeanBox (for a reference bean container).
*
* @return a JavaBean
* @param cls the class-loader from which we should create
* the bean. If this is null, then the system
* class-loader is used.
* @param beanName the name of the bean within the class-loader.
* For example "sun.beanbox.foobah"
* @param beanContext The BeanContext in which to nest the new bean
* @param initializer The AppletInitializer for the new bean
*
* @exception ClassNotFoundException if the class of a serialized
* object could not be found.
* @exception IOException if an I/O error occurs.
*/
public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext, AppletInitializer initializer) throws IOException, ClassNotFoundException {
InputStream ins;
ObjectInputStream oins = null;
Object result = null;
boolean serialized = false;
IOException serex = null;
// look in the bootstrap class loader first.
if (cls == null) {
try {
cls = ClassLoader.getSystemClassLoader();
} catch (SecurityException ex) {
// We're not allowed to access the system class loader.
// Drop through.
}
}
// Try to find a serialized object with this name
final String serName = beanName.replace('.', '/').concat(".ser");
if (cls == null)
ins = ClassLoader.getSystemResourceAsStream(serName);
else
ins = cls.getResourceAsStream(serName);
if (ins != null) {
try {
if (cls == null) {
oins = new ObjectInputStream(ins);
} else {
oins = new ObjectInputStreamWithLoader(ins, cls);
}
result = oins.readObject();
serialized = true;
oins.close();
} catch (IOException ex) {
ins.close();
// Drop through and try opening the class. But remember
// the exception in case we can't find the class either.
serex = ex;
} catch (ClassNotFoundException ex) {
ins.close();
throw ex;
}
}
if (result == null) {
// No serialized object, try just instantiating the class
Class<?> cl;
try {
cl = ClassFinder.findClass(beanName, cls);
} catch (ClassNotFoundException ex) {
// otherwise rethrow the ClassNotFoundException.
if (serex != null) {
throw serex;
}
throw ex;
}
if (!Modifier.isPublic(cl.getModifiers())) {
throw new ClassNotFoundException("" + cl + " : no public access");
}
try {
result = cl.newInstance();
} catch (Exception ex) {
// But we pass extra information in the detail message.
throw new ClassNotFoundException("" + cl + " : " + ex, ex);
}
}
if (result != null) {
// Ok, if the result is an applet initialize it.
AppletStub stub = null;
if (result instanceof Applet) {
Applet applet = (Applet) result;
boolean needDummies = initializer == null;
if (needDummies) {
// Figure our the codebase and docbase URLs. We do this
// by locating the URL for a known resource, and then
// massaging the URL.
// First find the "resource name" corresponding to the bean
// itself. So a serialzied bean "a.b.c" would imply a
// resource name of "a/b/c.ser" and a classname of "x.y"
// would imply a resource name of "x/y.class".
final String resourceName;
if (serialized) {
// Serialized bean
resourceName = beanName.replace('.', '/').concat(".ser");
} else {
// Regular class
resourceName = beanName.replace('.', '/').concat(".class");
}
URL objectUrl = null;
URL codeBase = null;
URL docBase = null;
// Now get the URL correponding to the resource name.
if (cls == null) {
objectUrl = ClassLoader.getSystemResource(resourceName);
} else
objectUrl = cls.getResource(resourceName);
if (objectUrl != null) {
String s = objectUrl.toExternalForm();
if (s.endsWith(resourceName)) {
int ix = s.length() - resourceName.length();
codeBase = new URL(s.substring(0, ix));
docBase = codeBase;
ix = s.lastIndexOf('/');
if (ix >= 0) {
docBase = new URL(s.substring(0, ix + 1));
}
}
}
// Setup a default context and stub.
BeansAppletContext context = new BeansAppletContext(applet);
stub = (AppletStub) new BeansAppletStub(applet, context, codeBase, docBase);
applet.setStub(stub);
} else {
initializer.initialize(applet, beanContext);
}
if (beanContext != null) {
unsafeBeanContextAdd(beanContext, result);
}
if (!serialized) {
// We need to set a reasonable initial size, as many
// applets are unhappy if they are started without
// having been explicitly sized.
applet.setSize(100, 100);
applet.init();
}
if (needDummies) {
((BeansAppletStub) stub).active = true;
} else
initializer.activate(applet);
} else if (beanContext != null)
unsafeBeanContextAdd(beanContext, result);
}
return result;
}
use of java.applet.Applet in project imagej1 by imagej.
the class JavaProperties method run.
public void run(String arg) {
show("java.version");
show("java.vendor");
if (IJ.isMacintosh())
show("mrj.version");
show("os.name");
show("os.version");
show("os.arch");
show("file.separator");
show("path.separator");
String s = System.getProperty("line.separator");
char ch1, ch2;
String str1, str2 = "";
ch1 = s.charAt(0);
if (ch1 == '\r')
str1 = "<cr>";
else
str1 = "<lf>";
if (s.length() == 2) {
ch2 = s.charAt(1);
if (ch2 == '\r')
str2 = "<cr>";
else
str2 = "<lf>";
}
list.add(" line.separator: " + str1 + str2);
Applet applet = IJ.getApplet();
if (applet != null) {
list.add("");
list.add(" code base: " + applet.getCodeBase());
list.add(" document base: " + applet.getDocumentBase());
list.add(" sample images dir: " + Prefs.getImagesURL());
TextWindow tw = new TextWindow("Properties", "", list, 400, 400);
return;
}
list.add("");
show("user.name");
show("user.home");
show("user.dir");
show("user.country");
show("file.encoding");
show("java.home");
show("java.compiler");
show("java.class.path");
show("java.ext.dirs");
show("java.io.tmpdir");
list.add("");
String userDir = System.getProperty("user.dir");
String userHome = System.getProperty("user.home");
String osName = System.getProperty("os.name");
list.add(" IJ.getVersion: " + IJ.getVersion());
list.add(" IJ.getFullVersion: " + IJ.getFullVersion());
list.add(" IJ.isJava16: " + IJ.isJava16());
list.add(" IJ.isJava17: " + IJ.isJava17());
list.add(" IJ.isJava18: " + IJ.isJava18());
list.add(" IJ.isJava19: " + IJ.isJava19());
list.add(" IJ.isLinux: " + IJ.isLinux());
list.add(" IJ.isMacintosh: " + IJ.isMacintosh());
list.add(" IJ.isMacOSX: " + IJ.isMacOSX());
list.add(" IJ.isWindows: " + IJ.isWindows());
list.add(" IJ.is64Bit: " + IJ.is64Bit());
list.add("");
list.add(" IJ.getDir(\"imagej\"): " + IJ.getDir("imagej"));
list.add(" IJ.getDir(\"home\"): " + IJ.getDir("home"));
list.add(" IJ.getDir(\"plugins\"): " + IJ.getDir("plugins"));
list.add(" IJ.getDir(\"macros\"): " + IJ.getDir("macros"));
list.add(" IJ.getDir(\"luts\"): " + IJ.getDir("luts"));
list.add(" IJ.getDir(\"current\"): " + IJ.getDir("current"));
list.add(" IJ.getDir(\"temp\"): " + IJ.getDir("temp"));
list.add(" IJ.getDir(\"default\"): " + IJ.getDir("default"));
list.add(" IJ.getDir(\"image\"): " + IJ.getDir("image"));
list.add("");
list.add(" Menus.getPlugInsPath: " + Menus.getPlugInsPath());
list.add(" Menus.getMacrosPath: " + Menus.getMacrosPath());
list.add(" Prefs.getImageJDir: " + Prefs.getImageJDir());
list.add(" Prefs.getThreads: " + Prefs.getThreads() + cores());
list.add(" Prefs.open100Percent: " + Prefs.open100Percent);
list.add(" Prefs.blackBackground: " + Prefs.blackBackground);
list.add(" Prefs.useJFileChooser: " + Prefs.useJFileChooser);
list.add(" Prefs.weightedColor: " + Prefs.weightedColor);
list.add(" Prefs.blackCanvas: " + Prefs.blackCanvas);
list.add(" Prefs.pointAutoMeasure: " + Prefs.pointAutoMeasure);
list.add(" Prefs.pointAutoNextSlice: " + Prefs.pointAutoNextSlice);
list.add(" Prefs.requireControlKey: " + Prefs.requireControlKey);
list.add(" Prefs.useInvertingLut: " + Prefs.useInvertingLut);
list.add(" Prefs.antialiasedTools: " + Prefs.antialiasedTools);
list.add(" Prefs.useInvertingLut: " + Prefs.useInvertingLut);
list.add(" Prefs.intelByteOrder: " + Prefs.intelByteOrder);
list.add(" Prefs.doubleBuffer: " + Prefs.doubleBuffer);
list.add(" Prefs.noPointLabels: " + Prefs.noPointLabels);
list.add(" Prefs.disableUndo: " + Prefs.disableUndo);
list.add(" Prefs dir: " + Prefs.getPrefsDir());
list.add(" Current dir: " + OpenDialog.getDefaultDirectory());
list.add(" Sample images dir: " + Prefs.getImagesURL());
list.add(" Memory in use: " + IJ.freeMemory());
Dimension d = IJ.getScreenSize();
list.add(" Screen size: " + d.width + "x" + d.height);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
String b1 = toString(GUI.getMaxWindowBounds());
String b2 = toString(ge.getMaximumWindowBounds());
if (!b2.equals(b1))
b1 += " (" + b2 + ")";
list.add(" Max window bounds: " + b1);
listMonitors(ge, list);
System.gc();
doFullDump();
if (IJ.getInstance() == null) {
for (int i = 0; i < list.size(); i++) IJ.log((String) list.get(i));
} else
new TextWindow("Properties", "", list, 400, 500);
}
use of java.applet.Applet in project runelite by runelite.
the class ClientLoader method loadRuneLite.
private Applet loadRuneLite() throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException {
ConfigLoader config = new ConfigLoader();
config.fetch();
String initialClass = config.getProperty(ConfigLoader.INITIAL_CLASS).replace(".class", "");
// the injected client is a runtime scoped dependency
Class<?> clientClass = this.getClass().getClassLoader().loadClass(initialClass);
Applet rs = (Applet) clientClass.newInstance();
rs.setStub(new RSStub(config));
return rs;
}
use of java.applet.Applet in project runelite by runelite.
the class ClientLoader method loadVanilla.
private Applet loadVanilla() throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
ConfigLoader config = new ConfigLoader();
config.fetch();
String codebase = config.getProperty(ConfigLoader.CODEBASE);
String initialJar = config.getProperty(ConfigLoader.INITIAL_JAR);
String initialClass = config.getProperty(ConfigLoader.INITIAL_CLASS).replace(".class", "");
URL url = new URL(codebase + initialJar);
// Must set parent classloader to null, or it will pull from
// this class's classloader first
URLClassLoader classloader = new URLClassLoader(new URL[] { url }, null);
Class<?> clientClass = classloader.loadClass(initialClass);
Applet rs = (Applet) clientClass.newInstance();
rs.setStub(new RSStub(config));
return rs;
}
Aggregations