提交 998cfd0b 编写于 作者: L lana

Merge

...@@ -39,7 +39,8 @@ SUBDIRS = \ ...@@ -39,7 +39,8 @@ SUBDIRS = \
Notepad \ Notepad \
SampleTree \ SampleTree \
SwingApplet \ SwingApplet \
TableExample TableExample \
TransparentRuler
# Some demos aren't currently included in OpenJDK # Some demos aren't currently included in OpenJDK
ifndef OPENJDK ifndef OPENJDK
......
#
# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# This code 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
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
#
# Makefile to build the TransparentRuler demo.
#
BUILDDIR = ../../..
PRODUCT = demo/jfc
DEMONAME = TransparentRuler
include $(BUILDDIR)/common/Defs.gmk
DEMO_ROOT = $(SHARE_SRC)/demo/jfc/$(DEMONAME)
DEMO_TOPFILES = ./README.txt
DEMO_MAINCLASS = transparentruler.Ruler
DEMO_DESTDIR = $(DEMODIR)/jfc/$(DEMONAME)
#
# Demo jar building rules.
#
include $(BUILDDIR)/common/Demo.gmk
...@@ -21,4 +21,4 @@ ...@@ -21,4 +21,4 @@
# or visit www.oracle.com if you need additional information or have any # or visit www.oracle.com if you need additional information or have any
# questions. # questions.
# #
tzdata2011d tzdata2011e
...@@ -734,6 +734,48 @@ Zone Indian/Mayotte 3:00:56 - LMT 1911 Jul # Mamoutzou ...@@ -734,6 +734,48 @@ Zone Indian/Mayotte 3:00:56 - LMT 1911 Jul # Mamoutzou
# http://www.timeanddate.com/news/time/morocco-starts-dst-2010.html # http://www.timeanddate.com/news/time/morocco-starts-dst-2010.html
# </a> # </a>
# From Dan Abitol (2011-03-30):
# ...Rules for Africa/Casablanca are the following (24h format)
# The 3rd april 2011 at 00:00:00, [it] will be 3rd april 1:00:00
# The 31th july 2011 at 00:59:59, [it] will be 31th July 00:00:00
# ...Official links of change in morocco
# The change was broadcast on the FM Radio
# I ve called ANRT (telecom regulations in Morocco) at
# +212.537.71.84.00
# <a href="http://www.anrt.net.ma/fr/">
# http://www.anrt.net.ma/fr/
# </a>
# They said that
# <a href="http://www.map.ma/fr/sections/accueil/l_heure_legale_au_ma/view">
# http://www.map.ma/fr/sections/accueil/l_heure_legale_au_ma/view
# </a>
# is the official publication to look at.
# They said that the decision was already taken.
#
# More articles in the press
# <a href="http://www.yabiladi.com/articles/details/5058/secret-l-heure-d-ete-maroc-lev">
# http://www.yabiladi.com/articles/details/5058/secret-l-heure-d-ete-maroc-lev
# </a>
# e.html
# <a href="http://www.lematin.ma/Actualite/Express/Article.asp?id=148923">
# http://www.lematin.ma/Actualite/Express/Article.asp?id=148923
# </a>
# <a href="http://www.lavieeco.com/actualite/Le-Maroc-passe-sur-GMT%2B1-a-partir-de-dim">
# http://www.lavieeco.com/actualite/Le-Maroc-passe-sur-GMT%2B1-a-partir-de-dim
# anche-prochain-5538.html
# </a>
# From Petr Machata (2011-03-30):
# They have it written in English here:
# <a href="http://www.map.ma/eng/sections/home/morocco_to_spring_fo/view">
# http://www.map.ma/eng/sections/home/morocco_to_spring_fo/view
# </a>
#
# It says there that "Morocco will resume its standard time on July 31,
# 2011 at midnight." Now they don't say whether they mean midnight of
# wall clock time (i.e. 11pm UTC), but that's what I would assume. It has
# also been like that in the past.
# RULE NAME FROM TO TYPE IN ON AT SAVE LETTER/S # RULE NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule Morocco 1939 only - Sep 12 0:00 1:00 S Rule Morocco 1939 only - Sep 12 0:00 1:00 S
...@@ -757,6 +799,8 @@ Rule Morocco 2009 only - Jun 1 0:00 1:00 S ...@@ -757,6 +799,8 @@ Rule Morocco 2009 only - Jun 1 0:00 1:00 S
Rule Morocco 2009 only - Aug 21 0:00 0 - Rule Morocco 2009 only - Aug 21 0:00 0 -
Rule Morocco 2010 only - May 2 0:00 1:00 S Rule Morocco 2010 only - May 2 0:00 1:00 S
Rule Morocco 2010 only - Aug 8 0:00 0 - Rule Morocco 2010 only - Aug 8 0:00 0 -
Rule Morocco 2011 only - Apr 3 0:00 1:00 S
Rule Morocco 2011 only - Jul 31 0 0 -
# Zone NAME GMTOFF RULES FORMAT [UNTIL] # Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Africa/Casablanca -0:30:20 - LMT 1913 Oct 26 Zone Africa/Casablanca -0:30:20 - LMT 1913 Oct 26
0:00 Morocco WE%sT 1984 Mar 16 0:00 Morocco WE%sT 1984 Mar 16
......
...@@ -1193,6 +1193,19 @@ Zone America/Rio_Branco -4:31:12 - LMT 1914 ...@@ -1193,6 +1193,19 @@ Zone America/Rio_Branco -4:31:12 - LMT 1914
# From Arthur David Olson (2011-03-02): # From Arthur David Olson (2011-03-02):
# The emol.com article mentions a water shortage as the cause of the # The emol.com article mentions a water shortage as the cause of the
# postponement, which may mean that it's not a permanent change. # postponement, which may mean that it's not a permanent change.
# From Glenn Eychaner (2011-03-28):
# The article:
# <a href="http://diario.elmercurio.com/2011/03/28/_portada/_portada/noticias/7565897A-CA86-49E6-9E03-660B21A4883E.htm?id=3D{7565897A-CA86-49E6-9E03-660B21A4883E}">
# http://diario.elmercurio.com/2011/03/28/_portada/_portada/noticias/7565897A-CA86-49E6-9E03-660B21A4883E.htm?id=3D{7565897A-CA86-49E6-9E03-660B21A4883E}
# </a>
#
# In English:
# Chile's clocks will go back an hour this year on the 7th of May instead
# of this Saturday. They will go forward again the 3rd Saturday in
# August, not in October as they have since 1968. This is a pilot plan
# which will be reevaluated in 2012.
# Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S # Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
Rule Chile 1927 1932 - Sep 1 0:00 1:00 S Rule Chile 1927 1932 - Sep 1 0:00 1:00 S
Rule Chile 1928 1932 - Apr 1 0:00 0 - Rule Chile 1928 1932 - Apr 1 0:00 0 -
...@@ -1222,13 +1235,16 @@ Rule Chile 1997 only - Mar 30 3:00u 0 - ...@@ -1222,13 +1235,16 @@ Rule Chile 1997 only - Mar 30 3:00u 0 -
Rule Chile 1998 only - Mar Sun>=9 3:00u 0 - Rule Chile 1998 only - Mar Sun>=9 3:00u 0 -
Rule Chile 1998 only - Sep 27 4:00u 1:00 S Rule Chile 1998 only - Sep 27 4:00u 1:00 S
Rule Chile 1999 only - Apr 4 3:00u 0 - Rule Chile 1999 only - Apr 4 3:00u 0 -
Rule Chile 1999 max - Oct Sun>=9 4:00u 1:00 S Rule Chile 1999 2010 - Oct Sun>=9 4:00u 1:00 S
Rule Chile 2011 only - Aug Sun>=16 4:00u 1:00 S
Rule Chile 2012 max - Oct Sun>=9 4:00u 1:00 S
Rule Chile 2000 2007 - Mar Sun>=9 3:00u 0 - Rule Chile 2000 2007 - Mar Sun>=9 3:00u 0 -
# N.B.: the end of March 29 in Chile is March 30 in Universal time, # N.B.: the end of March 29 in Chile is March 30 in Universal time,
# which is used below in specifying the transition. # which is used below in specifying the transition.
Rule Chile 2008 only - Mar 30 3:00u 0 - Rule Chile 2008 only - Mar 30 3:00u 0 -
Rule Chile 2009 only - Mar Sun>=9 3:00u 0 - Rule Chile 2009 only - Mar Sun>=9 3:00u 0 -
Rule Chile 2010 2011 - Apr Sun>=1 3:00u 0 - Rule Chile 2010 only - Apr Sun>=1 3:00u 0 -
Rule Chile 2011 only - May Sun>=2 3:00u 0 -
Rule Chile 2012 max - Mar Sun>=9 3:00u 0 - Rule Chile 2012 max - Mar Sun>=9 3:00u 0 -
# IATA SSIM anomalies: (1992-02) says 1992-03-14; # IATA SSIM anomalies: (1992-02) says 1992-03-14;
# (1996-09) says 1998-03-08. Ignore these. # (1996-09) says 1998-03-08. Ignore these.
......
...@@ -5821,7 +5821,7 @@ public abstract class Component implements ImageObserver, MenuContainer, ...@@ -5821,7 +5821,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
* <code>InputMethodRequests</code> instance. * <code>InputMethodRequests</code> instance.
* If listener <code>l</code> is <code>null</code>, * If listener <code>l</code> is <code>null</code>,
* no exception is thrown and no action is performed. * no exception is thrown and no action is performed.
* <p>Refer to <a href="doc-files/AWTThreadIssues.html#ListenersThreads" * <p>Refer to <a href="{@docRoot}/java/awt/doc-files/AWTThreadIssues.html#ListenersThreads"
* >AWT Threading Issues</a> for details on AWT's threading model. * >AWT Threading Issues</a> for details on AWT's threading model.
* *
* @param l the input method listener * @param l the input method listener
......
...@@ -66,7 +66,7 @@ public interface CharSequence { ...@@ -66,7 +66,7 @@ public interface CharSequence {
* indexing. </p> * indexing. </p>
* *
* <p>If the <code>char</code> value specified by the index is a * <p>If the <code>char</code> value specified by the index is a
* <a href="Character.html#unicode">surrogate</a>, the surrogate * <a href="{@docRoot}/java/lang/Character.html#unicode">surrogate</a>, the surrogate
* value is returned. * value is returned.
* *
* @param index the index of the <code>char</code> value to be returned * @param index the index of the <code>char</code> value to be returned
......
...@@ -476,7 +476,7 @@ public final class JLayer<V extends Component> ...@@ -476,7 +476,7 @@ public final class JLayer<V extends Component>
* for this {@code JLayer} and the {@code JLayer} * for this {@code JLayer} and the {@code JLayer}
* is displayable. * is displayable.
* <p/> * <p/>
* The following example shows how to correclty use this method * The following example shows how to correctly use this method
* in the {@code LayerUI} implementations: * in the {@code LayerUI} implementations:
* <pre> * <pre>
* public void installUI(JComponent c) { * public void installUI(JComponent c) {
...@@ -834,7 +834,7 @@ public final class JLayer<V extends Component> ...@@ -834,7 +834,7 @@ public final class JLayer<V extends Component>
} }
/** /**
* First, implementatation of this method iterates through * First, implementation of this method iterates through
* glassPane's child components and returns {@code true} * glassPane's child components and returns {@code true}
* if any of them is visible and contains passed x,y point. * if any of them is visible and contains passed x,y point.
* After that it checks if no mouseListeners is attached to this component * After that it checks if no mouseListeners is attached to this component
......
...@@ -203,6 +203,12 @@ public class PopupFactory { ...@@ -203,6 +203,12 @@ public class PopupFactory {
popupType = HEAVY_WEIGHT_POPUP; popupType = HEAVY_WEIGHT_POPUP;
break; break;
} }
} else if (c instanceof Window) {
Window w = (Window) c;
if (!w.isOpaque() || w.getOpacity() < 1 || w.getShape() != null) {
popupType = HEAVY_WEIGHT_POPUP;
break;
}
} }
c = c.getParent(); c = c.getParent();
} }
......
...@@ -727,6 +727,9 @@ public class SpringLayout implements LayoutManager2 { ...@@ -727,6 +727,9 @@ public class SpringLayout implements LayoutManager2 {
* For any other <code>String</code> value passed as the edge, * For any other <code>String</code> value passed as the edge,
* no action is taken. For a <code>null</code> edge, a * no action is taken. For a <code>null</code> edge, a
* <code>NullPointerException</code> is thrown. * <code>NullPointerException</code> is thrown.
* <p/>
* <b>Note:</b> This method can affect {@code x} and {@code y} values
* previously set for this {@code Constraints}.
* *
* @param edgeName the edge to be set * @param edgeName the edge to be set
* @param s the spring controlling the specified edge * @param s the spring controlling the specified edge
......
...@@ -25,9 +25,7 @@ ...@@ -25,9 +25,7 @@
package javax.swing.plaf; package javax.swing.plaf;
import javax.accessibility.Accessible;
import javax.swing.*; import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
...@@ -38,7 +36,7 @@ import java.io.Serializable; ...@@ -38,7 +36,7 @@ import java.io.Serializable;
/** /**
* The base class for all {@link javax.swing.JLayer}'s UI delegates. * The base class for all {@link javax.swing.JLayer}'s UI delegates.
* <p/> * <p/>
* {@link #paint(java.awt.Graphics, javax.swing.JComponent)} method performes the * {@link #paint(java.awt.Graphics, javax.swing.JComponent)} method performs the
* painting of the {@code JLayer} * painting of the {@code JLayer}
* and {@link #eventDispatched(AWTEvent, JLayer)} method is notified * and {@link #eventDispatched(AWTEvent, JLayer)} method is notified
* about any {@code AWTEvent}s which have been generated by a {@code JLayer} * about any {@code AWTEvent}s which have been generated by a {@code JLayer}
...@@ -165,7 +163,7 @@ public class LayerUI<V extends Component> ...@@ -165,7 +163,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.COMPONENT_EVENT_MASK); * l.setLayerEventMask(AWTEvent.COMPONENT_EVENT_MASK);
* } * }
* *
* public void unistallUI(JComponent c) { * public void uninstallUI(JComponent c) {
* super.uninstallUI(c); * super.uninstallUI(c);
* JLayer l = (JLayer) c; * JLayer l = (JLayer) c;
* l.setLayerEventMask(0); * l.setLayerEventMask(0);
...@@ -197,7 +195,7 @@ public class LayerUI<V extends Component> ...@@ -197,7 +195,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.FOCUS_EVENT_MASK); * l.setLayerEventMask(AWTEvent.FOCUS_EVENT_MASK);
* } * }
* *
* public void unistallUI(JComponent c) { * public void uninstallUI(JComponent c) {
* super.uninstallUI(c); * super.uninstallUI(c);
* JLayer l = (JLayer) c; * JLayer l = (JLayer) c;
* l.setLayerEventMask(0); * l.setLayerEventMask(0);
...@@ -229,7 +227,7 @@ public class LayerUI<V extends Component> ...@@ -229,7 +227,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.KEY_EVENT_MASK); * l.setLayerEventMask(AWTEvent.KEY_EVENT_MASK);
* } * }
* *
* public void unistallUI(JComponent c) { * public void uninstallUI(JComponent c) {
* super.uninstallUI(c); * super.uninstallUI(c);
* JLayer l = (JLayer) c; * JLayer l = (JLayer) c;
* l.setLayerEventMask(0); * l.setLayerEventMask(0);
...@@ -261,7 +259,7 @@ public class LayerUI<V extends Component> ...@@ -261,7 +259,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK); * l.setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK);
* } * }
* *
* public void unistallUI(JComponent c) { * public void uninstallUI(JComponent c) {
* super.uninstallUI(c); * super.uninstallUI(c);
* JLayer l = (JLayer) c; * JLayer l = (JLayer) c;
* l.setLayerEventMask(0); * l.setLayerEventMask(0);
...@@ -293,7 +291,7 @@ public class LayerUI<V extends Component> ...@@ -293,7 +291,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK); * l.setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK);
* } * }
* *
* public void unistallUI(JComponent c) { * public void uninstallUI(JComponent c) {
* super.uninstallUI(c); * super.uninstallUI(c);
* JLayer l = (JLayer) c; * JLayer l = (JLayer) c;
* l.setLayerEventMask(0); * l.setLayerEventMask(0);
...@@ -325,7 +323,7 @@ public class LayerUI<V extends Component> ...@@ -325,7 +323,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.MOUSE_WHEEL_EVENT_MASK); * l.setLayerEventMask(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
* } * }
* *
* public void unistallUI(JComponent c) { * public void uninstallUI(JComponent c) {
* super.uninstallUI(c); * super.uninstallUI(c);
* JLayer l = (JLayer) c; * JLayer l = (JLayer) c;
* l.setLayerEventMask(0); * l.setLayerEventMask(0);
...@@ -357,7 +355,7 @@ public class LayerUI<V extends Component> ...@@ -357,7 +355,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.INPUT_METHOD_EVENT_MASK); * l.setLayerEventMask(AWTEvent.INPUT_METHOD_EVENT_MASK);
* } * }
* *
* public void unistallUI(JComponent c) { * public void uninstallUI(JComponent c) {
* super.uninstallUI(c); * super.uninstallUI(c);
* JLayer l = (JLayer) c; * JLayer l = (JLayer) c;
* l.setLayerEventMask(0); * l.setLayerEventMask(0);
...@@ -389,7 +387,7 @@ public class LayerUI<V extends Component> ...@@ -389,7 +387,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.HIERARCHY_EVENT_MASK); * l.setLayerEventMask(AWTEvent.HIERARCHY_EVENT_MASK);
* } * }
* *
* public void unistallUI(JComponent c) { * public void uninstallUI(JComponent c) {
* super.uninstallUI(c); * super.uninstallUI(c);
* JLayer l = (JLayer) c; * JLayer l = (JLayer) c;
* l.setLayerEventMask(0); * l.setLayerEventMask(0);
...@@ -421,7 +419,7 @@ public class LayerUI<V extends Component> ...@@ -421,7 +419,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK); * l.setLayerEventMask(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
* } * }
* *
* public void unistallUI(JComponent c) { * public void uninstallUI(JComponent c) {
* super.uninstallUI(c); * super.uninstallUI(c);
* JLayer l = (JLayer) c; * JLayer l = (JLayer) c;
* l.setLayerEventMask(0); * l.setLayerEventMask(0);
...@@ -691,7 +689,7 @@ public class LayerUI<V extends Component> ...@@ -691,7 +689,7 @@ public class LayerUI<V extends Component>
* Otherwise, the default implementation is used. * Otherwise, the default implementation is used.
* *
* @param c {@code JLayer} to return preferred size for * @param c {@code JLayer} to return preferred size for
* @return maximun size for the passed {@code JLayer} * @return maximum size for the passed {@code JLayer}
*/ */
public Dimension getMaximumSize(JComponent c) { public Dimension getMaximumSize(JComponent c) {
JLayer l = (JLayer) c; JLayer l = (JLayer) c;
......
/* /*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,13 +26,11 @@ package javax.swing.plaf.nimbus; ...@@ -26,13 +26,11 @@ package javax.swing.plaf.nimbus;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.plaf.UIResource;
import java.awt.Insets; import java.awt.Insets;
import java.awt.Component; import java.awt.Component;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.Color; import java.awt.Color;
import java.awt.Transparency;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
...@@ -58,7 +56,9 @@ class LoweredBorder extends AbstractRegionPainter implements Border { ...@@ -58,7 +56,9 @@ class LoweredBorder extends AbstractRegionPainter implements Border {
@Override @Override
protected Object[] getExtendedCacheKeys(JComponent c) { protected Object[] getExtendedCacheKeys(JComponent c) {
return new Object[] {c.getBackground()}; return (c != null)
? new Object[] { c.getBackground() }
: null;
} }
/** /**
...@@ -85,6 +85,7 @@ class LoweredBorder extends AbstractRegionPainter implements Border { ...@@ -85,6 +85,7 @@ class LoweredBorder extends AbstractRegionPainter implements Border {
*/ */
protected void doPaint(Graphics2D g, JComponent c, int width, int height, protected void doPaint(Graphics2D g, JComponent c, int width, int height,
Object[] extendedCacheKeys) { Object[] extendedCacheKeys) {
Color color = (c == null) ? Color.BLACK : c.getBackground();
BufferedImage img1 = new BufferedImage(IMG_SIZE,IMG_SIZE, BufferedImage img1 = new BufferedImage(IMG_SIZE,IMG_SIZE,
BufferedImage.TYPE_INT_ARGB); BufferedImage.TYPE_INT_ARGB);
BufferedImage img2 = new BufferedImage(IMG_SIZE,IMG_SIZE, BufferedImage img2 = new BufferedImage(IMG_SIZE,IMG_SIZE,
...@@ -93,14 +94,14 @@ class LoweredBorder extends AbstractRegionPainter implements Border { ...@@ -93,14 +94,14 @@ class LoweredBorder extends AbstractRegionPainter implements Border {
Graphics2D g2 = (Graphics2D)img1.getGraphics(); Graphics2D g2 = (Graphics2D)img1.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(c.getBackground()); g2.setColor(color);
g2.fillRoundRect(2,0,26,26,RADIUS,RADIUS); g2.fillRoundRect(2,0,26,26,RADIUS,RADIUS);
g2.dispose(); g2.dispose();
// draw shadow // draw shadow
InnerShadowEffect effect = new InnerShadowEffect(); InnerShadowEffect effect = new InnerShadowEffect();
effect.setDistance(1); effect.setDistance(1);
effect.setSize(3); effect.setSize(3);
effect.setColor(getLighter(c.getBackground(),2.1f)); effect.setColor(getLighter(color, 2.1f));
effect.setAngle(90); effect.setAngle(90);
effect.applyEffect(img1,img2,IMG_SIZE,IMG_SIZE); effect.applyEffect(img1,img2,IMG_SIZE,IMG_SIZE);
// draw outline to img2 // draw outline to img2
...@@ -108,7 +109,7 @@ class LoweredBorder extends AbstractRegionPainter implements Border { ...@@ -108,7 +109,7 @@ class LoweredBorder extends AbstractRegionPainter implements Border {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON); RenderingHints.VALUE_ANTIALIAS_ON);
g2.setClip(0,28,IMG_SIZE,1); g2.setClip(0,28,IMG_SIZE,1);
g2.setColor(getLighter(c.getBackground(),0.90f)); g2.setColor(getLighter(color, 0.90f));
g2.drawRoundRect(2,1,25,25,RADIUS,RADIUS); g2.drawRoundRect(2,1,25,25,RADIUS,RADIUS);
g2.dispose(); g2.dispose();
// draw final image // draw final image
...@@ -150,7 +151,7 @@ class LoweredBorder extends AbstractRegionPainter implements Border { ...@@ -150,7 +151,7 @@ class LoweredBorder extends AbstractRegionPainter implements Border {
* @param c the component for which this border insets value applies * @param c the component for which this border insets value applies
*/ */
public Insets getBorderInsets(Component c) { public Insets getBorderInsets(Component c) {
return INSETS; return (Insets) INSETS.clone();
} }
/** /**
......
...@@ -786,9 +786,9 @@ public class SynthTableUI extends BasicTableUI ...@@ -786,9 +786,9 @@ public class SynthTableUI extends BasicTableUI
hasFocus, row, column); hasFocus, row, column);
setIcon(null); setIcon(null);
Class columnClass = table.getColumnClass(column); if (table != null) {
configureValue(value, columnClass); configureValue(value, table.getColumnClass(column));
}
return this; return this;
} }
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,22 +29,24 @@ ...@@ -29,22 +29,24 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.applet.*; import java.applet.*;
/** /**
* An interactive test of the Graphics.drawArc and Graphics.fillArc * An interactive test of the Graphics.drawArc and Graphics.fillArc
* routines. Can be run either as a standalone application by * routines. Can be run either as a standalone application by
* typing "java ArcTest" or as an applet in the AppletViewer. * typing "java ArcTest" or as an applet in the AppletViewer.
*/ */
@SuppressWarnings("serial")
public class ArcTest extends Applet { public class ArcTest extends Applet {
ArcControls controls; // The controls for marking and filling arcs ArcControls controls; // The controls for marking and filling arcs
ArcCanvas canvas; // The drawing area to display arcs ArcCanvas canvas; // The drawing area to display arcs
@Override
public void init() { public void init() {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
canvas = new ArcCanvas(); canvas = new ArcCanvas();
...@@ -52,19 +54,23 @@ public class ArcTest extends Applet { ...@@ -52,19 +54,23 @@ public class ArcTest extends Applet {
add("South", controls = new ArcControls(canvas)); add("South", controls = new ArcControls(canvas));
} }
@Override
public void destroy() { public void destroy() {
remove(controls); remove(controls);
remove(canvas); remove(canvas);
} }
@Override
public void start() { public void start() {
controls.setEnabled(true); controls.setEnabled(true);
} }
@Override
public void stop() { public void stop() {
controls.setEnabled(false); controls.setEnabled(false);
} }
@Override
public void processEvent(AWTEvent e) { public void processEvent(AWTEvent e) {
if (e.getID() == Event.WINDOW_DESTROY) { if (e.getID() == Event.WINDOW_DESTROY) {
System.exit(0); System.exit(0);
...@@ -80,20 +86,28 @@ public class ArcTest extends Applet { ...@@ -80,20 +86,28 @@ public class ArcTest extends Applet {
f.add("Center", arcTest); f.add("Center", arcTest);
f.setSize(300, 300); f.setSize(300, 300);
f.show(); f.setVisible(true);
} }
@Override
public String getAppletInfo() { public String getAppletInfo() {
return "An interactive test of the Graphics.drawArc and \nGraphics.fillArc routines. Can be run \neither as a standalone application by typing 'java ArcTest' \nor as an applet in the AppletViewer."; return "An interactive test of the Graphics.drawArc and \nGraphics."
+ "fillArc routines. Can be run \neither as a standalone "
+ "application by typing 'java ArcTest' \nor as an applet in "
+ "the AppletViewer.";
} }
} }
@SuppressWarnings("serial")
class ArcCanvas extends Canvas { class ArcCanvas extends Canvas {
int startAngle = 0;
int extent = 45;
boolean filled = false;
Font font = new java.awt.Font("SansSerif", Font.PLAIN, 12);
int startAngle = 0;
int extent = 45;
boolean filled = false;
Font font = new java.awt.Font("SansSerif", Font.PLAIN, 12);
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
Rectangle r = getBounds(); Rectangle r = getBounds();
int hlines = r.height / 10; int hlines = r.height / 10;
...@@ -134,12 +148,16 @@ class ArcCanvas extends Canvas { ...@@ -134,12 +148,16 @@ class ArcCanvas extends Canvas {
} }
} }
@SuppressWarnings("serial")
class ArcControls extends Panel class ArcControls extends Panel
implements ActionListener { implements ActionListener {
TextField startTF; TextField startTF;
TextField extentTF; TextField extentTF;
ArcCanvas canvas; ArcCanvas canvas;
@SuppressWarnings("LeakingThisInConstructor")
public ArcControls(ArcCanvas canvas) { public ArcControls(ArcCanvas canvas) {
Button b = null; Button b = null;
...@@ -154,18 +172,19 @@ class ArcControls extends Panel ...@@ -154,18 +172,19 @@ class ArcControls extends Panel
add(b); add(b);
} }
@Override
public void actionPerformed(ActionEvent ev) { public void actionPerformed(ActionEvent ev) {
String label = ev.getActionCommand(); String label = ev.getActionCommand();
int start, extent; int start, extent;
try { try {
start = Integer.parseInt(startTF.getText().trim()); start = Integer.parseInt(startTF.getText().trim());
} catch (NumberFormatException nfe) { } catch (NumberFormatException ignored) {
start = 0; start = 0;
} }
try { try {
extent = Integer.parseInt(extentTF.getText().trim()); extent = Integer.parseInt(extentTF.getText().trim());
} catch (NumberFormatException nfe) { } catch (NumberFormatException ignored) {
extent = 0; extent = 0;
} }
...@@ -173,6 +192,8 @@ class ArcControls extends Panel ...@@ -173,6 +192,8 @@ class ArcControls extends Panel
} }
} }
@SuppressWarnings("serial")
class IntegerTextField extends TextField { class IntegerTextField extends TextField {
String oldText = null; String oldText = null;
...@@ -188,6 +209,7 @@ class IntegerTextField extends TextField { ...@@ -188,6 +209,7 @@ class IntegerTextField extends TextField {
// function, but this is neater, since ideally, it would prevent // function, but this is neater, since ideally, it would prevent
// the text from appearing at all. Sigh. See bugid 4100317/4114565. // the text from appearing at all. Sigh. See bugid 4100317/4114565.
// //
@Override
protected void processEvent(AWTEvent evt) { protected void processEvent(AWTEvent evt) {
int id = evt.getID(); int id = evt.getID();
if (id != KeyEvent.KEY_TYPED) { if (id != KeyEvent.KEY_TYPED) {
...@@ -200,8 +222,8 @@ class IntegerTextField extends TextField { ...@@ -200,8 +222,8 @@ class IntegerTextField extends TextField {
// Digits, backspace, and delete are okay // Digits, backspace, and delete are okay
// Note that the minus sign is allowed, but not the decimal // Note that the minus sign is allowed, but not the decimal
if (Character.isDigit(c) || (c == '\b') || (c == '\u007f') || if (Character.isDigit(c) || (c == '\b') || (c == '\u007f') || (c
(c == '\u002d')) { == '\u002d')) {
super.processEvent(evt); super.processEvent(evt);
return; return;
} }
...@@ -215,6 +237,7 @@ class IntegerTextField extends TextField { ...@@ -215,6 +237,7 @@ class IntegerTextField extends TextField {
// so we can revert to it on a TextEvent (paste, or // so we can revert to it on a TextEvent (paste, or
// legal key in the wrong location) with bad text // legal key in the wrong location) with bad text
// //
@Override
protected void processTextEvent(TextEvent te) { protected void processTextEvent(TextEvent te) {
// The empty string is okay, too // The empty string is okay, too
String newText = getText(); String newText = getText();
...@@ -233,12 +256,11 @@ class IntegerTextField extends TextField { ...@@ -233,12 +256,11 @@ class IntegerTextField extends TextField {
// Note that the empty string is not allowed. // Note that the empty string is not allowed.
// //
private boolean textIsInteger(String textToCheck) { private boolean textIsInteger(String textToCheck) {
int value = -1;
try { try {
value = Integer.parseInt(textToCheck, 10); Integer.parseInt(textToCheck, 10);
return true; return true;
} catch (NumberFormatException nfe) { } catch (NumberFormatException ignored) {
return false; return false;
} }
} }
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,28 +29,26 @@ ...@@ -29,28 +29,26 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.awt.*; import java.awt.*;
/** /**
* A simple bar chart demo * A simple bar chart demo
* @author Sami Shaio * @author Sami Shaio
* @modified 06/21/00 Daniel Peek : refactored, comments * @modified 06/21/00 Daniel Peek : refactored, comments
*/ */
@SuppressWarnings("serial")
public class BarChart extends java.applet.Applet { public class BarChart extends java.applet.Applet {
private static final int VERTICAL = 0; private static final int VERTICAL = 0;
private static final int HORIZONTAL = 1; private static final int HORIZONTAL = 1;
private static final int SOLID = 0; private static final int SOLID = 0;
private static final int STRIPED = 1; private static final int STRIPED = 1;
private int orientation; private int orientation;
private String title; private String title;
private Font font; private Font font;
private FontMetrics metrics; private FontMetrics metrics;
private int fontHeight = 15;
private int columns; private int columns;
private int values[]; private int values[];
private Color colors[]; private Color colors[];
...@@ -61,6 +59,7 @@ public class BarChart extends java.applet.Applet { ...@@ -61,6 +59,7 @@ public class BarChart extends java.applet.Applet {
private int barSpacing = 10; private int barSpacing = 10;
private int maxValue = 0; private int maxValue = 0;
@Override
public void init() { public void init() {
getSettings(); getSettings();
...@@ -70,7 +69,7 @@ public class BarChart extends java.applet.Applet { ...@@ -70,7 +69,7 @@ public class BarChart extends java.applet.Applet {
styles = new int[columns]; styles = new int[columns];
colors = new Color[columns]; colors = new Color[columns];
for (int i=0; i < columns; i++) { for (int i = 0; i < columns; i++) {
parseValue(i); parseValue(i);
parseLabel(i); parseLabel(i);
parseStyle(i); parseStyle(i);
...@@ -112,7 +111,7 @@ public class BarChart extends java.applet.Applet { ...@@ -112,7 +111,7 @@ public class BarChart extends java.applet.Applet {
} }
private void parseValue(int i) { private void parseValue(int i) {
String temp = getParameter("C" + (i+1)); String temp = getParameter("C" + (i + 1));
try { try {
values[i] = Integer.parseInt(temp); values[i] = Integer.parseInt(temp);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
...@@ -124,18 +123,17 @@ public class BarChart extends java.applet.Applet { ...@@ -124,18 +123,17 @@ public class BarChart extends java.applet.Applet {
} }
private void parseLabel(int i) { private void parseLabel(int i) {
String temp = getParameter("C" + (i+1) + "_label"); String temp = getParameter("C" + (i + 1) + "_label");
if (temp==null) { if (temp == null) {
labels[i] = ""; labels[i] = "";
} else { } else {
labels[i] = temp; labels[i] = temp;
} }
maxLabelWidth = Math.max(metrics.stringWidth maxLabelWidth = Math.max(metrics.stringWidth(labels[i]), maxLabelWidth);
((String) (labels[i])), maxLabelWidth);
} }
private void parseStyle(int i) { private void parseStyle(int i) {
String temp = getParameter("C" + (i+1) + "_style"); String temp = getParameter("C" + (i + 1) + "_style");
if (temp == null || temp.equalsIgnoreCase("solid")) { if (temp == null || temp.equalsIgnoreCase("solid")) {
styles[i] = SOLID; styles[i] = SOLID;
} else if (temp.equalsIgnoreCase("striped")) { } else if (temp.equalsIgnoreCase("striped")) {
...@@ -146,7 +144,7 @@ public class BarChart extends java.applet.Applet { ...@@ -146,7 +144,7 @@ public class BarChart extends java.applet.Applet {
} }
private void parseColor(int i) { private void parseColor(int i) {
String temp = getParameter("C" + (i+1) + "_color"); String temp = getParameter("C" + (i + 1) + "_color");
if (temp != null) { if (temp != null) {
temp = temp.toLowerCase(); temp = temp.toLowerCase();
if (temp.equals("red")) { if (temp.equals("red")) {
...@@ -179,6 +177,7 @@ public class BarChart extends java.applet.Applet { ...@@ -179,6 +177,7 @@ public class BarChart extends java.applet.Applet {
} }
} }
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
// draw the title centered at the bottom of the bar graph // draw the title centered at the bottom of the bar graph
g.setColor(Color.black); g.setColor(Color.black);
...@@ -192,7 +191,7 @@ public class BarChart extends java.applet.Applet { ...@@ -192,7 +191,7 @@ public class BarChart extends java.applet.Applet {
g.drawString(title, cx, cy); g.drawString(title, cx, cy);
// draw the bars and their titles // draw the bars and their titles
if(orientation == HORIZONTAL) { if (orientation == HORIZONTAL) {
paintHorizontal(g); paintHorizontal(g);
} else { // VERTICAL } else { // VERTICAL
paintVertical(g); paintVertical(g);
...@@ -208,12 +207,13 @@ public class BarChart extends java.applet.Applet { ...@@ -208,12 +207,13 @@ public class BarChart extends java.applet.Applet {
// set the X coordinate for this bar and label and center it // set the X coordinate for this bar and label and center it
int widthOfItems = maxLabelWidth + 3 + (maxValue * scale) + 5 int widthOfItems = maxLabelWidth + 3 + (maxValue * scale) + 5
+ metrics.stringWidth(Integer.toString(maxValue)); + metrics.stringWidth(Integer.toString(maxValue));
cx = Math.max((getSize().width - widthOfItems) / 2, 0); cx = Math.max((getSize().width - widthOfItems) / 2, 0);
// set the Y coordinate for this bar and label // set the Y coordinate for this bar and label
cy = getSize().height - metrics.getDescent() - metrics.getHeight() cy = getSize().height - metrics.getDescent() - metrics.getHeight()
- barSpacing - ((columns - i - 1) * (barSpacing + barHeight)); - barSpacing
- ((columns - i - 1) * (barSpacing + barHeight));
// draw the label // draw the label
g.setColor(Color.black); g.setColor(Color.black);
...@@ -223,7 +223,7 @@ public class BarChart extends java.applet.Applet { ...@@ -223,7 +223,7 @@ public class BarChart extends java.applet.Applet {
// draw the shadow // draw the shadow
g.fillRect(cx + 4, cy - barHeight + 4, g.fillRect(cx + 4, cy - barHeight + 4,
(values[i] * scale), barHeight); (values[i] * scale), barHeight);
// draw the bar // draw the bar
g.setColor(colors[i]); g.setColor(colors[i]);
...@@ -233,7 +233,7 @@ public class BarChart extends java.applet.Applet { ...@@ -233,7 +233,7 @@ public class BarChart extends java.applet.Applet {
} }
} else { // SOLID } else { // SOLID
g.fillRect(cx, cy - barHeight, g.fillRect(cx, cy - barHeight,
(values[i] * scale) + 1, barHeight + 1); (values[i] * scale) + 1, barHeight + 1);
} }
cx += (values[i] * scale) + 4; cx += (values[i] * scale) + 4;
...@@ -255,7 +255,7 @@ public class BarChart extends java.applet.Applet { ...@@ -255,7 +255,7 @@ public class BarChart extends java.applet.Applet {
// Y coordinate for this label and bar // Y coordinate for this label and bar
int cy = getSize().height - metrics.getHeight() int cy = getSize().height - metrics.getHeight()
- metrics.getDescent() - 4; - metrics.getDescent() - 4;
// draw the label // draw the label
g.setColor(Color.black); g.setColor(Color.black);
...@@ -264,18 +264,18 @@ public class BarChart extends java.applet.Applet { ...@@ -264,18 +264,18 @@ public class BarChart extends java.applet.Applet {
// draw the shadow // draw the shadow
g.fillRect(cx + 4, cy - (values[i] * scale) - 4, g.fillRect(cx + 4, cy - (values[i] * scale) - 4,
barWidth, (values[i] * scale)); barWidth, (values[i] * scale));
// draw the bar // draw the bar
g.setColor(colors[i]); g.setColor(colors[i]);
if (styles[i] == STRIPED) { if (styles[i] == STRIPED) {
for (int k=0; k <= values[i] * scale; k+=2) { for (int k = 0; k <= values[i] * scale; k += 2) {
g.drawLine(cx, cy - k, g.drawLine(cx, cy - k,
cx + barWidth, cy - k); cx + barWidth, cy - k);
} }
} else { } else {
g.fillRect(cx, cy - (values[i] * scale), g.fillRect(cx, cy - (values[i] * scale),
barWidth + 1, (values[i] * scale) + 1); barWidth + 1, (values[i] * scale) + 1);
} }
cy -= (values[i] * scale) + 5; cy -= (values[i] * scale) + 5;
...@@ -285,28 +285,30 @@ public class BarChart extends java.applet.Applet { ...@@ -285,28 +285,30 @@ public class BarChart extends java.applet.Applet {
} }
} }
@Override
public String getAppletInfo() { public String getAppletInfo() {
return "Title: Bar Chart \n" return "Title: Bar Chart \n"
+ "Author: Sami Shaio \n" + "Author: Sami Shaio \n"
+ "A simple bar chart demo."; + "A simple bar chart demo.";
} }
@Override
public String[][] getParameterInfo() { public String[][] getParameterInfo() {
String[][] info = { String[][] info = {
{"title", "string", "The title of bar graph. Default is 'Chart'"}, { "title", "string", "The title of bar graph. Default is 'Chart'" },
{"scale", "int", "The scale of the bar graph. Default is 10."}, { "scale", "int", "The scale of the bar graph. Default is 10." },
{"columns", "int", "The number of columns/rows. Default is 5."}, { "columns", "int", "The number of columns/rows. Default is 5." },
{"orientation", "{VERTICAL, HORIZONTAL}", { "orientation", "{VERTICAL, HORIZONTAL}",
"The orienation of the bar graph. Default is VERTICAL."}, "The orienation of the bar graph. Default is VERTICAL." },
{"c#", "int", "Subsitute a number for #. " { "c#", "int", "Subsitute a number for #. "
+ "The value/size of bar #. Default is 0."}, + "The value/size of bar #. Default is 0." },
{"c#_label", "string", "The label for bar #. " { "c#_label", "string", "The label for bar #. "
+ "Default is an empty label."}, + "Default is an empty label." },
{"c#_style", "{SOLID, STRIPED}", "The style of bar #. " { "c#_style", "{SOLID, STRIPED}", "The style of bar #. "
+ "Default is SOLID."}, + "Default is SOLID." },
{"c#_color", "{RED, GREEN, BLUE, PINK, ORANGE, MAGENTA, CYAN, " { "c#_color", "{RED, GREEN, BLUE, PINK, ORANGE, MAGENTA, CYAN, "
+ "WHITE, YELLOW, GRAY, DARKGRAY}", + "WHITE, YELLOW, GRAY, DARKGRAY}",
"The color of bar #. Default is GRAY."} "The color of bar #. Default is GRAY." }
}; };
return info; return info;
} }
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,92 +29,106 @@ ...@@ -29,92 +29,106 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
/** /**
* I love blinking things. * I love blinking things.
* *
* @author Arthur van Hoff * @author Arthur van Hoff
* @modified 04/24/96 Jim Hagen use getBackground * @author 04/24/96 Jim Hagen use getBackground
* @modified 02/05/98 Mike McCloskey removed use of deprecated methods * @author 02/05/98 Mike McCloskey removed use of deprecated methods
* @modified 04/23/99 Josh Bloch, use timer instead of explicit multithreading. * @author 04/23/99 Josh Bloch, use timer instead of explicit multithreading.
* @modified 07/10/00 Daniel Peek brought to code conventions, minor changes * @author 07/10/00 Daniel Peek brought to code conventions, minor changes
*/ */
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.util.StringTokenizer;
import java.util.Timer;
import java.util.TimerTask;
import java.awt.*;
import java.util.*;
public class Blink extends java.applet.Applet { public class Blink extends java.applet.Applet {
private static final long serialVersionUID = -775844794477507646L;
private Timer timer; // Schedules the blinking private Timer timer; // Schedules the blinking
private String labelString; // The label for the window private String labelString; // The label for the window
private int delay; // the delay time between blinks private int delay; // the delay time between blinks
@Override
public void init() { public void init() {
String blinkFrequency = getParameter("speed"); String blinkFrequency = getParameter("speed");
delay = (blinkFrequency == null) ? 400 : delay = (blinkFrequency == null) ? 400
(1000 / Integer.parseInt(blinkFrequency)); : (1000 / Integer.parseInt(blinkFrequency));
labelString = getParameter("lbl"); labelString = getParameter("lbl");
if (labelString == null) if (labelString == null) {
labelString = "Blink"; labelString = "Blink";
}
Font font = new java.awt.Font("Serif", Font.PLAIN, 24); Font font = new java.awt.Font("Serif", Font.PLAIN, 24);
setFont(font); setFont(font);
} }
@Override
public void start() { public void start() {
timer = new Timer(); //creates a new timer to schedule the blinking timer = new Timer(); //creates a new timer to schedule the blinking
timer.schedule(new TimerTask() { //creates a timertask to schedule timer.schedule(new TimerTask() { //creates a timertask to schedule
// overrides the run method to provide functionality // overrides the run method to provide functionality
@Override
public void run() { public void run() {
repaint(); repaint();
} }
} }, delay, delay);
, delay, delay);
} }
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
int fontSize = g.getFont().getSize(); int fontSize = g.getFont().getSize();
int x = 0, y = fontSize, space; int x = 0, y = fontSize, space;
int red = (int) ( 50 * Math.random()); int red = (int) (50 * Math.random());
int green = (int) ( 50 * Math.random()); int green = (int) (50 * Math.random());
int blue = (int) (256 * Math.random()); int blue = (int) (256 * Math.random());
Dimension d = getSize(); Dimension d = getSize();
g.setColor(Color.black); g.setColor(Color.black);
FontMetrics fm = g.getFontMetrics(); FontMetrics fm = g.getFontMetrics();
space = fm.stringWidth(" "); space = fm.stringWidth(" ");
for (StringTokenizer t = new StringTokenizer(labelString); for (StringTokenizer t = new StringTokenizer(labelString);
t.hasMoreTokens();) { t.hasMoreTokens();) {
String word = t.nextToken(); String word = t.nextToken();
int w = fm.stringWidth(word) + space; int w = fm.stringWidth(word) + space;
if (x + w > d.width) { if (x + w > d.width) {
x = 0; x = 0;
y += fontSize; //move word to next line if it doesn't fit y += fontSize; //move word to next line if it doesn't fit
} }
if (Math.random() < 0.5) if (Math.random() < 0.5) {
g.setColor(new java.awt.Color((red + y*30) % 256, g.setColor(new java.awt.Color((red + y * 30) % 256,
(green + x/3) % 256, blue)); (green + x / 3) % 256, blue));
else } else {
g.setColor(getBackground()); g.setColor(getBackground());
}
g.drawString(word, x, y); g.drawString(word, x, y);
x += w; //shift to the right to draw the next word x += w; //shift to the right to draw the next word
} }
} }
@Override
public void stop() { public void stop() {
timer.cancel(); //stops the timer timer.cancel(); //stops the timer
} }
@Override
public String getAppletInfo() { public String getAppletInfo() {
return "Title: Blinker\n" return "Title: Blinker\n"
+ "Author: Arthur van Hoff\n" + "Author: Arthur van Hoff\n"
+ "Displays multicolored blinking text."; + "Displays multicolored blinking text.";
} }
@Override
public String[][] getParameterInfo() { public String[][] getParameterInfo() {
String pinfo[][] = { String pinfo[][] = {
{"speed", "string", "The blink frequency"}, { "speed", "string", "The blink frequency" },
{"lbl", "string", "The text to blink."}, { "lbl", "string", "The text to blink." }, };
};
return pinfo; return pinfo;
} }
} }
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,14 +29,27 @@ ...@@ -29,14 +29,27 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet; import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.CardLayout;
import java.awt.Choice;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
@SuppressWarnings("serial")
final class CardPanel extends Panel {
class CardPanel extends Panel {
ActionListener listener; ActionListener listener;
Panel create(LayoutManager layout) { Panel create(LayoutManager layout) {
...@@ -83,16 +96,21 @@ class CardPanel extends Panel { ...@@ -83,16 +96,21 @@ class CardPanel extends Panel {
add("six", create(new GridLayout(2, 2, 10, 10))); add("six", create(new GridLayout(2, 2, 10, 10)));
} }
@Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
return new Dimension(200, 100); return new Dimension(200, 100);
} }
} }
@SuppressWarnings("serial")
public class CardTest extends Applet public class CardTest extends Applet
implements ActionListener, implements ActionListener,
ItemListener { ItemListener {
CardPanel cards; CardPanel cards;
@SuppressWarnings("LeakingThisInConstructor")
public CardTest() { public CardTest() {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
add("Center", cards = new CardPanel(this)); add("Center", cards = new CardPanel(this));
...@@ -127,24 +145,26 @@ public class CardTest extends Applet ...@@ -127,24 +145,26 @@ public class CardTest extends Applet
p.add(c); p.add(c);
} }
@Override
public void itemStateChanged(ItemEvent e) { public void itemStateChanged(ItemEvent e) {
((CardLayout)cards.getLayout()).show(cards, ((CardLayout) cards.getLayout()).show(cards,
(String)(e.getItem())); (String) (e.getItem()));
} }
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String arg = e.getActionCommand(); String arg = e.getActionCommand();
if ("first".equals(arg)) { if ("first".equals(arg)) {
((CardLayout)cards.getLayout()).first(cards); ((CardLayout) cards.getLayout()).first(cards);
} else if ("next".equals(arg)) { } else if ("next".equals(arg)) {
((CardLayout)cards.getLayout()).next(cards); ((CardLayout) cards.getLayout()).next(cards);
} else if ("previous".equals(arg)) { } else if ("previous".equals(arg)) {
((CardLayout)cards.getLayout()).previous(cards); ((CardLayout) cards.getLayout()).previous(cards);
} else if ("last".equals(arg)) { } else if ("last".equals(arg)) {
((CardLayout)cards.getLayout()).last(cards); ((CardLayout) cards.getLayout()).last(cards);
} else { } else {
((CardLayout)cards.getLayout()).show(cards,(String)arg); ((CardLayout) cards.getLayout()).show(cards, arg);
} }
} }
...@@ -156,9 +176,10 @@ public class CardTest extends Applet ...@@ -156,9 +176,10 @@ public class CardTest extends Applet
f.add("Center", cardTest); f.add("Center", cardTest);
f.setSize(300, 300); f.setSize(300, 300);
f.show(); f.setVisible(true);
} }
@Override
public String getAppletInfo() { public String getAppletInfo() {
return "Demonstrates the different types of layout managers."; return "Demonstrates the different types of layout managers.";
} }
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,24 +29,28 @@ ...@@ -29,24 +29,28 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.util.*; import java.applet.Applet;
import java.awt.*; import java.awt.Color;
import java.applet.*; import java.awt.Font;
import java.text.*; import java.awt.Graphics;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/** /**
* Time! * Time!
* *
* @author Rachel Gollub * @author Rachel Gollub
* @modified Daniel Peek replaced circle drawing calculation, few more changes * @author Daniel Peek replaced circle drawing calculation, few more changes
*/ */
@SuppressWarnings("serial")
public class Clock extends Applet implements Runnable { public class Clock extends Applet implements Runnable {
private volatile Thread timer; // The thread that displays clock private volatile Thread timer; // The thread that displays clock
private int lastxs, lastys, lastxm, private int lastxs, lastys, lastxm,
lastym, lastxh, lastyh; // Dimensions used to draw hands lastym, lastxh, lastyh; // Dimensions used to draw hands
private SimpleDateFormat formatter; // Formats the date displayed private SimpleDateFormat formatter; // Formats the date displayed
private String lastdate; // String to hold date displayed private String lastdate; // String to hold date displayed
private Font clockFaceFont; // Font for number display on clock private Font clockFaceFont; // Font for number display on clock
...@@ -55,11 +59,11 @@ public class Clock extends Applet implements Runnable { ...@@ -55,11 +59,11 @@ public class Clock extends Applet implements Runnable {
private Color numberColor; // Color of second hand and numbers private Color numberColor; // Color of second hand and numbers
private int xcenter = 80, ycenter = 55; // Center position private int xcenter = 80, ycenter = 55; // Center position
@Override
public void init() { public void init() {
int x,y;
lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0; lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy", formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy",
Locale.getDefault()); Locale.getDefault());
currentDate = new Date(); currentDate = new Date();
lastdate = formatter.format(currentDate); lastdate = formatter.format(currentDate);
clockFaceFont = new Font("Serif", Font.PLAIN, 14); clockFaceFont = new Font("Serif", Font.PLAIN, 14);
...@@ -68,26 +72,29 @@ public class Clock extends Applet implements Runnable { ...@@ -68,26 +72,29 @@ public class Clock extends Applet implements Runnable {
try { try {
setBackground(new Color(Integer.parseInt(getParameter("bgcolor"), setBackground(new Color(Integer.parseInt(getParameter("bgcolor"),
16))); 16)));
} catch (NullPointerException e) { } catch (NullPointerException e) {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
try { try {
handColor = new Color(Integer.parseInt(getParameter("fgcolor1"), handColor = new Color(Integer.parseInt(getParameter("fgcolor1"),
16)); 16));
} catch (NullPointerException e) { } catch (NullPointerException e) {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
try { try {
numberColor = new Color(Integer.parseInt(getParameter("fgcolor2"), numberColor = new Color(Integer.parseInt(getParameter("fgcolor2"),
16)); 16));
} catch (NullPointerException e) { } catch (NullPointerException e) {
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
} }
resize(300,300); // Set clock window size resize(300, 300); // Set clock window size
} }
// Paint is the main part of the program /**
* Paint is the main part of the program
*/
@Override
public void update(Graphics g) { public void update(Graphics g) {
int xh, yh, xm, ym, xs, ys; int xh, yh, xm, ym, xs, ys;
int s = 0, m = 10, h = 10; int s = 0, m = 10, h = 10;
...@@ -119,10 +126,12 @@ public class Clock extends Applet implements Runnable { ...@@ -119,10 +126,12 @@ public class Clock extends Applet implements Runnable {
ys = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 45 + ycenter); ys = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 45 + ycenter);
xm = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 40 + xcenter); xm = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 40 + xcenter);
ym = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 40 + ycenter); ym = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 40 + ycenter);
xh = (int) (Math.cos((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30 xh = (int) (Math.cos((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2)
+ xcenter); * 30
yh = (int) (Math.sin((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30 + xcenter);
+ ycenter); yh = (int) (Math.sin((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2)
* 30
+ ycenter);
// Get the date to print at the bottom // Get the date to print at the bottom
formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy"); formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy");
...@@ -136,12 +145,12 @@ public class Clock extends Applet implements Runnable { ...@@ -136,12 +145,12 @@ public class Clock extends Applet implements Runnable {
g.drawString(lastdate, 5, 125); g.drawString(lastdate, 5, 125);
} }
if (xm != lastxm || ym != lastym) { if (xm != lastxm || ym != lastym) {
g.drawLine(xcenter, ycenter-1, lastxm, lastym); g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
g.drawLine(xcenter-1, ycenter, lastxm, lastym); g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
} }
if (xh != lastxh || yh != lastyh) { if (xh != lastxh || yh != lastyh) {
g.drawLine(xcenter, ycenter-1, lastxh, lastyh); g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
g.drawLine(xcenter-1, ycenter, lastxh, lastyh); g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
} }
// Draw date and hands // Draw date and hands
...@@ -149,73 +158,83 @@ public class Clock extends Applet implements Runnable { ...@@ -149,73 +158,83 @@ public class Clock extends Applet implements Runnable {
g.drawString(today, 5, 125); g.drawString(today, 5, 125);
g.drawLine(xcenter, ycenter, xs, ys); g.drawLine(xcenter, ycenter, xs, ys);
g.setColor(handColor); g.setColor(handColor);
g.drawLine(xcenter, ycenter-1, xm, ym); g.drawLine(xcenter, ycenter - 1, xm, ym);
g.drawLine(xcenter-1, ycenter, xm, ym); g.drawLine(xcenter - 1, ycenter, xm, ym);
g.drawLine(xcenter, ycenter-1, xh, yh); g.drawLine(xcenter, ycenter - 1, xh, yh);
g.drawLine(xcenter-1, ycenter, xh, yh); g.drawLine(xcenter - 1, ycenter, xh, yh);
lastxs = xs; lastys = ys; lastxs = xs;
lastxm = xm; lastym = ym; lastys = ys;
lastxh = xh; lastyh = yh; lastxm = xm;
lastym = ym;
lastxh = xh;
lastyh = yh;
lastdate = today; lastdate = today;
currentDate = null; currentDate = null;
} }
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
g.setFont(clockFaceFont); g.setFont(clockFaceFont);
// Draw the circle and numbers // Draw the circle and numbers
g.setColor(handColor); g.setColor(handColor);
g.drawArc(xcenter-50, ycenter-50, 100, 100, 0, 360); g.drawArc(xcenter - 50, ycenter - 50, 100, 100, 0, 360);
g.setColor(numberColor); g.setColor(numberColor);
g.drawString("9", xcenter-45, ycenter+3); g.drawString("9", xcenter - 45, ycenter + 3);
g.drawString("3", xcenter+40, ycenter+3); g.drawString("3", xcenter + 40, ycenter + 3);
g.drawString("12", xcenter-5, ycenter-37); g.drawString("12", xcenter - 5, ycenter - 37);
g.drawString("6", xcenter-3, ycenter+45); g.drawString("6", xcenter - 3, ycenter + 45);
// Draw date and hands // Draw date and hands
g.setColor(numberColor); g.setColor(numberColor);
g.drawString(lastdate, 5, 125); g.drawString(lastdate, 5, 125);
g.drawLine(xcenter, ycenter, lastxs, lastys); g.drawLine(xcenter, ycenter, lastxs, lastys);
g.setColor(handColor); g.setColor(handColor);
g.drawLine(xcenter, ycenter-1, lastxm, lastym); g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
g.drawLine(xcenter-1, ycenter, lastxm, lastym); g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
g.drawLine(xcenter, ycenter-1, lastxh, lastyh); g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
g.drawLine(xcenter-1, ycenter, lastxh, lastyh); g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
} }
@Override
public void start() { public void start() {
timer = new Thread(this); timer = new Thread(this);
timer.start(); timer.start();
} }
@Override
public void stop() { public void stop() {
timer = null; timer = null;
} }
@Override
@SuppressWarnings("SleepWhileHoldingLock")
public void run() { public void run() {
Thread me = Thread.currentThread(); Thread me = Thread.currentThread();
while (timer == me) { while (timer == me) {
try { try {
Thread.currentThread().sleep(100); Thread.sleep(100);
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
repaint(); repaint();
} }
} }
@Override
public String getAppletInfo() { public String getAppletInfo() {
return "Title: A Clock \n" return "Title: A Clock \n"
+ "Author: Rachel Gollub, 1995 \n" + "Author: Rachel Gollub, 1995 \n"
+ "An analog clock."; + "An analog clock.";
} }
@Override
public String[][] getParameterInfo() { public String[][] getParameterInfo() {
String[][] info = { String[][] info = {
{"bgcolor", "hexadecimal RGB number", { "bgcolor", "hexadecimal RGB number",
"The background color. Default is the color of your browser."}, "The background color. Default is the color of your browser." },
{"fgcolor1", "hexadecimal RGB number", { "fgcolor1", "hexadecimal RGB number",
"The color of the hands and dial. Default is blue."}, "The color of the hands and dial. Default is blue." },
{"fgcolor2", "hexadecimal RGB number", { "fgcolor2", "hexadecimal RGB number",
"The color of the second hand and numbers. Default is dark gray."} "The color of the second hand and numbers. Default is dark gray." }
}; };
return info; return info;
} }
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,25 +29,43 @@ ...@@ -29,25 +29,43 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.applet.Applet; import java.applet.Applet;
import java.awt.event.*; import java.awt.AWTEvent;
import java.awt.*; import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Canvas;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.FontMetrics;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Label;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.TextEvent;
import java.awt.image.ColorModel; import java.awt.image.ColorModel;
import java.awt.image.MemoryImageSource; import java.awt.image.MemoryImageSource;
enum DitherMethod {
NOOP, RED, GREEN, BLUE, ALPHA, SATURATION
};
@SuppressWarnings("serial")
public class DitherTest extends Applet implements Runnable { public class DitherTest extends Applet implements Runnable {
final private static int NOOP = 0;
final private static int RED = 1;
final private static int GREEN = 2;
final private static int BLUE = 3;
final private static int ALPHA = 4;
final private static int SATURATION = 5;
private Thread runner; private Thread runner;
private DitherControls XControls; private DitherControls XControls;
private DitherControls YControls; private DitherControls YControls;
private DitherCanvas canvas; private DitherCanvas canvas;
...@@ -62,6 +80,7 @@ public class DitherTest extends Applet implements Runnable { ...@@ -62,6 +80,7 @@ public class DitherTest extends Applet implements Runnable {
ditherTest.start(); ditherTest.start();
} }
@Override
public void init() { public void init() {
String xspec = null, yspec = null; String xspec = null, yspec = null;
int xvals[] = new int[2]; int xvals[] = new int[2];
...@@ -70,7 +89,7 @@ public class DitherTest extends Applet implements Runnable { ...@@ -70,7 +89,7 @@ public class DitherTest extends Applet implements Runnable {
try { try {
xspec = getParameter("xaxis"); xspec = getParameter("xaxis");
yspec = getParameter("yaxis"); yspec = getParameter("yaxis");
} catch (NullPointerException npe) { } catch (NullPointerException ignored) {
//only occurs if run as application //only occurs if run as application
} }
...@@ -80,44 +99,34 @@ public class DitherTest extends Applet implements Runnable { ...@@ -80,44 +99,34 @@ public class DitherTest extends Applet implements Runnable {
if (yspec == null) { if (yspec == null) {
yspec = "blue"; yspec = "blue";
} }
int xmethod = colormethod(xspec, xvals); DitherMethod xmethod = colorMethod(xspec, xvals);
int ymethod = colormethod(yspec, yvals); DitherMethod ymethod = colorMethod(yspec, yvals);
setLayout(new BorderLayout()); setLayout(new BorderLayout());
XControls = new DitherControls(this, xvals[0], xvals[1], XControls = new DitherControls(this, xvals[0], xvals[1],
xmethod, false); xmethod, false);
YControls = new DitherControls(this, yvals[0], yvals[1], YControls = new DitherControls(this, yvals[0], yvals[1],
ymethod, true); ymethod, true);
YControls.addRenderButton(); YControls.addRenderButton();
add("North", XControls); add("North", XControls);
add("South", YControls); add("South", YControls);
add("Center", canvas = new DitherCanvas()); add("Center", canvas = new DitherCanvas());
} }
private int colormethod(String s, int vals[]) { private DitherMethod colorMethod(String s, int vals[]) {
int method = NOOP; DitherMethod method = DitherMethod.NOOP;
if (s == null) { if (s == null) {
s = ""; s = "";
} }
String lower = s.toLowerCase(); String lower = s.toLowerCase();
int len = 0;
if (lower.startsWith("red")) { for (DitherMethod m : DitherMethod.values()) {
method = RED; if (lower.startsWith(m.toString().toLowerCase())) {
lower = lower.substring(3); method = m;
} else if (lower.startsWith("green")) { lower = lower.substring(m.toString().length());
method = GREEN; }
lower = lower.substring(5);
} else if (lower.startsWith("blue")) {
method = BLUE;
lower = lower.substring(4);
} else if (lower.startsWith("alpha")) {
method = ALPHA;
lower = lower.substring(5);
} else if (lower.startsWith("saturation")) {
method = SATURATION;
lower = lower.substring(10);
} }
if (method == NOOP) { if (method == DitherMethod.NOOP) {
vals[0] = 0; vals[0] = 0;
vals[1] = 0; vals[1] = 0;
return method; return method;
...@@ -132,7 +141,7 @@ public class DitherTest extends Applet implements Runnable { ...@@ -132,7 +141,7 @@ public class DitherTest extends Applet implements Runnable {
begval = Integer.parseInt(lower.substring(0, dash)); begval = Integer.parseInt(lower.substring(0, dash));
endval = Integer.parseInt(lower.substring(dash + 1)); endval = Integer.parseInt(lower.substring(dash + 1));
} }
} catch (NumberFormatException nfe) { } catch (NumberFormatException ignored) {
} }
if (begval < 0) { if (begval < 0) {
...@@ -173,16 +182,14 @@ public class DitherTest extends Applet implements Runnable { ...@@ -173,16 +182,14 @@ public class DitherTest extends Applet implements Runnable {
c[0] = c[1] = c[2] = 0; c[0] = c[1] = c[2] = 0;
c[3] = 255; c[3] = 255;
if (xmethod < ymethod) { if (xmethod < ymethod) {
applymethod(c, xmethod, i, width, xvals); applyMethod(c, xmethod, i, width, xvals);
applymethod(c, ymethod, j, height, yvals); applyMethod(c, ymethod, j, height, yvals);
} else { } else {
applymethod(c, ymethod, j, height, yvals); applyMethod(c, ymethod, j, height, yvals);
applymethod(c, xmethod, i, width, xvals); applyMethod(c, xmethod, i, width, xvals);
} }
pixels[index++] = ((c[3] << 24) | pixels[index++] = ((c[3] << 24) | (c[0] << 16) | (c[1] << 8)
(c[0] << 16) | | c[2]);
(c[1] << 8) |
c[2]);
} }
// Poll once per row to see if we've been told to stop. // Poll once per row to see if we've been told to stop.
...@@ -191,51 +198,54 @@ public class DitherTest extends Applet implements Runnable { ...@@ -191,51 +198,54 @@ public class DitherTest extends Applet implements Runnable {
} }
} }
return createImage(new MemoryImageSource(width, height, return createImage(new MemoryImageSource(width, height,
ColorModel.getRGBdefault(), pixels, 0, width)); ColorModel.getRGBdefault(), pixels, 0, width));
} }
private void applymethod(int c[], int method, int step, private void applyMethod(int c[], int methodIndex, int step,
int total, int vals[]) { int total, int vals[]) {
if (method == NOOP) { DitherMethod method = DitherMethod.values()[methodIndex];
if (method == DitherMethod.NOOP) {
return; return;
} }
int val = ((total < 2) int val = ((total < 2)
? vals[0] ? vals[0]
: vals[0] + ((vals[1] - vals[0]) * step / (total - 1))); : vals[0] + ((vals[1] - vals[0]) * step / (total - 1)));
switch (method) { switch (method) {
case RED: case RED:
c[0] = val; c[0] = val;
break; break;
case GREEN: case GREEN:
c[1] = val; c[1] = val;
break; break;
case BLUE: case BLUE:
c[2] = val; c[2] = val;
break; break;
case ALPHA: case ALPHA:
c[3] = val; c[3] = val;
break; break;
case SATURATION: case SATURATION:
int max = Math.max(Math.max(c[0], c[1]), c[2]); int max = Math.max(Math.max(c[0], c[1]), c[2]);
int min = max * (255 - val) / 255; int min = max * (255 - val) / 255;
if (c[0] == 0) { if (c[0] == 0) {
c[0] = min; c[0] = min;
} }
if (c[1] == 0) { if (c[1] == 0) {
c[1] = min; c[1] = min;
} }
if (c[2] == 0) { if (c[2] == 0) {
c[2] = min; c[2] = min;
} }
break; break;
} }
} }
@Override
public void start() { public void start() {
runner = new Thread(this); runner = new Thread(this);
runner.start(); runner.start();
} }
@Override
public void run() { public void run() {
canvas.setImage(null); // Wipe previous image canvas.setImage(null); // Wipe previous image
Image img = calculateImage(); Image img = calculateImage();
...@@ -244,35 +254,43 @@ public class DitherTest extends Applet implements Runnable { ...@@ -244,35 +254,43 @@ public class DitherTest extends Applet implements Runnable {
} }
} }
@Override
public void stop() { public void stop() {
runner = null; runner = null;
} }
@Override
public void destroy() { public void destroy() {
remove(XControls); remove(XControls);
remove(YControls); remove(YControls);
remove(canvas); remove(canvas);
} }
@Override
public String getAppletInfo() { public String getAppletInfo() {
return "An interactive demonstration of dithering."; return "An interactive demonstration of dithering.";
} }
@Override
public String[][] getParameterInfo() { public String[][] getParameterInfo() {
String[][] info = { String[][] info = {
{"xaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}", { "xaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}",
"The color of the Y axis. Default is RED."}, "The color of the Y axis. Default is RED." },
{"yaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}", { "yaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}",
"The color of the X axis. Default is BLUE."} "The color of the X axis. Default is BLUE." }
}; };
return info; return info;
} }
} }
@SuppressWarnings("serial")
class DitherCanvas extends Canvas { class DitherCanvas extends Canvas {
private Image img; private Image img;
private static String calcString = "Calculating..."; private static String calcString = "Calculating...";
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
int w = getSize().width; int w = getSize().width;
int h = getSize().height; int h = getSize().height;
...@@ -288,14 +306,17 @@ class DitherCanvas extends Canvas { ...@@ -288,14 +306,17 @@ class DitherCanvas extends Canvas {
} }
} }
@Override
public void update(Graphics g) { public void update(Graphics g) {
paint(g); paint(g);
} }
@Override
public Dimension getMinimumSize() { public Dimension getMinimumSize() {
return new Dimension(20, 20); return new Dimension(20, 20);
} }
@Override
public Dimension getPreferredSize() { public Dimension getPreferredSize() {
return new Dimension(200, 200); return new Dimension(200, 200);
} }
...@@ -310,29 +331,29 @@ class DitherCanvas extends Canvas { ...@@ -310,29 +331,29 @@ class DitherCanvas extends Canvas {
} }
} }
@SuppressWarnings("serial")
class DitherControls extends Panel implements ActionListener { class DitherControls extends Panel implements ActionListener {
private CardinalTextField start; private CardinalTextField start;
private CardinalTextField end; private CardinalTextField end;
private Button button; private Button button;
private Choice choice; private Choice choice;
private DitherTest applet; private DitherTest applet;
private static LayoutManager dcLayout = new FlowLayout(FlowLayout.CENTER, private static LayoutManager dcLayout = new FlowLayout(FlowLayout.CENTER,
10, 5); 10, 5);
public DitherControls(DitherTest app, int s, int e, int type, public DitherControls(DitherTest app, int s, int e, DitherMethod type,
boolean vertical) { boolean vertical) {
applet = app; applet = app;
setLayout(dcLayout); setLayout(dcLayout);
add(new Label(vertical ? "Vertical" : "Horizontal")); add(new Label(vertical ? "Vertical" : "Horizontal"));
add(choice = new Choice()); add(choice = new Choice());
choice.addItem("Noop"); for (DitherMethod m : DitherMethod.values()) {
choice.addItem("Red"); choice.addItem(m.toString().substring(0, 1)
choice.addItem("Green"); + m.toString().substring(1).toLowerCase());
choice.addItem("Blue"); }
choice.addItem("Alpha"); choice.select(type.ordinal());
choice.addItem("Saturation");
choice.select(type);
add(start = new CardinalTextField(Integer.toString(s), 4)); add(start = new CardinalTextField(Integer.toString(s), 4));
add(end = new CardinalTextField(Integer.toString(e), 4)); add(end = new CardinalTextField(Integer.toString(e), 4));
} }
...@@ -369,6 +390,7 @@ class DitherControls extends Panel implements ActionListener { ...@@ -369,6 +390,7 @@ class DitherControls extends Panel implements ActionListener {
} }
/* called when user clicks the button */ /* called when user clicks the button */
@Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getSource() == button) { if (e.getSource() == button) {
applet.start(); applet.start();
...@@ -376,6 +398,8 @@ class DitherControls extends Panel implements ActionListener { ...@@ -376,6 +398,8 @@ class DitherControls extends Panel implements ActionListener {
} }
} }
@SuppressWarnings("serial")
class CardinalTextField extends TextField { class CardinalTextField extends TextField {
String oldText = null; String oldText = null;
...@@ -391,6 +415,7 @@ class CardinalTextField extends TextField { ...@@ -391,6 +415,7 @@ class CardinalTextField extends TextField {
// function, but this is neater, since ideally, it would prevent // function, but this is neater, since ideally, it would prevent
// the text from appearing at all. Sigh. See bugid 4100317/4114565. // the text from appearing at all. Sigh. See bugid 4100317/4114565.
// //
@Override
protected void processEvent(AWTEvent evt) { protected void processEvent(AWTEvent evt) {
int id = evt.getID(); int id = evt.getID();
if (id != KeyEvent.KEY_TYPED) { if (id != KeyEvent.KEY_TYPED) {
...@@ -420,6 +445,7 @@ class CardinalTextField extends TextField { ...@@ -420,6 +445,7 @@ class CardinalTextField extends TextField {
// Note: it would be easy to extend this to an eight-bit // Note: it would be easy to extend this to an eight-bit
// TextField (range 0-255), but I'll leave it as-is. // TextField (range 0-255), but I'll leave it as-is.
// //
@Override
protected void processTextEvent(TextEvent te) { protected void processTextEvent(TextEvent te) {
// The empty string is okay, too // The empty string is okay, too
String newText = getText(); String newText = getText();
...@@ -436,11 +462,8 @@ class CardinalTextField extends TextField { ...@@ -436,11 +462,8 @@ class CardinalTextField extends TextField {
// Returns true for Cardinal (non-negative) numbers // Returns true for Cardinal (non-negative) numbers
// Note that the empty string is not allowed // Note that the empty string is not allowed
private boolean textIsCardinal(String textToCheck) { private boolean textIsCardinal(String textToCheck) {
int value = -1;
try { try {
value = Integer.parseInt(textToCheck, 10); return Integer.parseInt(textToCheck, 10) >= 0;
return (value >= 0);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
return false; return false;
} }
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,27 +29,46 @@ ...@@ -29,27 +29,46 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.awt.event.*; import java.applet.Applet;
import java.awt.*; import java.awt.BorderLayout;
import java.applet.*; import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Panel;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
public class DrawTest extends Applet{ @SuppressWarnings("serial")
public class DrawTest extends Applet {
DrawPanel panel; DrawPanel panel;
DrawControls controls; DrawControls controls;
@Override
public void init() { public void init() {
setLayout(new BorderLayout()); setLayout(new BorderLayout());
panel = new DrawPanel(); panel = new DrawPanel();
controls = new DrawControls(panel); controls = new DrawControls(panel);
add("Center", panel); add("Center", panel);
add("South",controls); add("South", controls);
} }
@Override
public void destroy() { public void destroy() {
remove(panel); remove(panel);
remove(controls); remove(controls);
...@@ -63,22 +82,28 @@ public class DrawTest extends Applet{ ...@@ -63,22 +82,28 @@ public class DrawTest extends Applet{
f.add("Center", drawTest); f.add("Center", drawTest);
f.setSize(300, 300); f.setSize(300, 300);
f.show(); f.setVisible(true);
} }
@Override
public String getAppletInfo() { public String getAppletInfo() {
return "A simple drawing program."; return "A simple drawing program.";
} }
} }
@SuppressWarnings("serial")
class DrawPanel extends Panel implements MouseListener, MouseMotionListener { class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
public static final int LINES = 0; public static final int LINES = 0;
public static final int POINTS = 1; public static final int POINTS = 1;
int mode = LINES; int mode = LINES;
Vector lines = new Vector(); List<Rectangle> lines = new ArrayList<Rectangle>();
Vector colors = new Vector(); List<Color> colors = new ArrayList<Color>();
int x1,y1; int x1, y1;
int x2,y2; int x2, y2;
@SuppressWarnings("LeakingThisInConstructor")
public DrawPanel() { public DrawPanel() {
setBackground(Color.white); setBackground(Color.white);
addMouseMotionListener(this); addMouseMotionListener(this);
...@@ -87,16 +112,16 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener { ...@@ -87,16 +112,16 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
public void setDrawMode(int mode) { public void setDrawMode(int mode) {
switch (mode) { switch (mode) {
case LINES: case LINES:
case POINTS: case POINTS:
this.mode = mode; this.mode = mode;
break; break;
default: default:
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
} }
@Override
public void mouseDragged(MouseEvent e) { public void mouseDragged(MouseEvent e) {
e.consume(); e.consume();
switch (mode) { switch (mode) {
...@@ -106,8 +131,8 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener { ...@@ -106,8 +131,8 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
break; break;
case POINTS: case POINTS:
default: default:
colors.addElement(getForeground()); colors.add(getForeground());
lines.addElement(new Rectangle(x1, y1, e.getX(), e.getY())); lines.add(new Rectangle(x1, y1, e.getX(), e.getY()));
x1 = e.getX(); x1 = e.getX();
y1 = e.getY(); y1 = e.getY();
break; break;
...@@ -115,9 +140,11 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener { ...@@ -115,9 +140,11 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
repaint(); repaint();
} }
@Override
public void mouseMoved(MouseEvent e) { public void mouseMoved(MouseEvent e) {
} }
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
e.consume(); e.consume();
switch (mode) { switch (mode) {
...@@ -128,8 +155,8 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener { ...@@ -128,8 +155,8 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
break; break;
case POINTS: case POINTS:
default: default:
colors.addElement(getForeground()); colors.add(getForeground());
lines.addElement(new Rectangle(e.getX(), e.getY(), -1, -1)); lines.add(new Rectangle(e.getX(), e.getY(), -1, -1));
x1 = e.getX(); x1 = e.getX();
y1 = e.getY(); y1 = e.getY();
repaint(); repaint();
...@@ -137,12 +164,13 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener { ...@@ -137,12 +164,13 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
} }
} }
@Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
e.consume(); e.consume();
switch (mode) { switch (mode) {
case LINES: case LINES:
colors.addElement(getForeground()); colors.add(getForeground());
lines.addElement(new Rectangle(x1, y1, e.getX(), e.getY())); lines.add(new Rectangle(x1, y1, e.getX(), e.getY()));
x2 = -1; x2 = -1;
break; break;
case POINTS: case POINTS:
...@@ -152,23 +180,27 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener { ...@@ -152,23 +180,27 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
repaint(); repaint();
} }
@Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
} }
@Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
} }
@Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
} }
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
int np = lines.size(); int np = lines.size();
/* draw the current lines */ /* draw the current lines */
g.setColor(getForeground()); g.setColor(getForeground());
for (int i=0; i < np; i++) { for (int i = 0; i < np; i++) {
Rectangle p = (Rectangle)lines.elementAt(i); Rectangle p = lines.get(i);
g.setColor((Color)colors.elementAt(i)); g.setColor(colors.get(i));
if (p.width != -1) { if (p.width != -1) {
g.drawLine(p.x, p.y, p.width, p.height); g.drawLine(p.x, p.y, p.width, p.height);
} else { } else {
...@@ -185,9 +217,12 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener { ...@@ -185,9 +217,12 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
} }
@SuppressWarnings("serial")
class DrawControls extends Panel implements ItemListener { class DrawControls extends Panel implements ItemListener {
DrawPanel target; DrawPanel target;
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) { public DrawControls(DrawPanel target) {
this.target = target; this.target = target;
setLayout(new FlowLayout()); setLayout(new FlowLayout());
...@@ -222,33 +257,35 @@ class DrawControls extends Panel implements ItemListener { ...@@ -222,33 +257,35 @@ class DrawControls extends Panel implements ItemListener {
add(shapes); add(shapes);
} }
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
Rectangle r = getBounds(); Rectangle r = getBounds();
g.setColor(Color.lightGray); g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false); g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount(); int n = getComponentCount();
for(int i=0; i<n; i++) { for (int i = 0; i < n; i++) {
Component comp = getComponent(i); Component comp = getComponent(i);
if (comp instanceof Checkbox) { if (comp instanceof Checkbox) {
Point loc = comp.getLocation(); Point loc = comp.getLocation();
Dimension d = comp.getSize(); Dimension d = comp.getSize();
g.setColor(comp.getForeground()); g.setColor(comp.getForeground());
g.drawRect(loc.x-1, loc.y-1, d.width+1, d.height+1); g.drawRect(loc.x - 1, loc.y - 1, d.width + 1, d.height + 1);
} }
} }
} }
public void itemStateChanged(ItemEvent e) { @Override
if (e.getSource() instanceof Checkbox) { public void itemStateChanged(ItemEvent e) {
target.setForeground(((Component)e.getSource()).getForeground()); if (e.getSource() instanceof Checkbox) {
} else if (e.getSource() instanceof Choice) { target.setForeground(((Component) e.getSource()).getForeground());
String choice = (String) e.getItem(); } else if (e.getSource() instanceof Choice) {
if (choice.equals("Lines")) { String choice = (String) e.getItem();
target.setDrawMode(DrawPanel.LINES); if (choice.equals("Lines")) {
} else if (choice.equals("Points")) { target.setDrawMode(DrawPanel.LINES);
target.setDrawMode(DrawPanel.POINTS); } else if (choice.equals("Points")) {
} target.setDrawMode(DrawPanel.POINTS);
}
}
} }
}
} }
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,13 +29,13 @@ ...@@ -29,13 +29,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.awt.Graphics; import java.awt.Graphics;
import java.util.Stack; import java.util.Stack;
import java.util.Vector;
import java.awt.event.*; import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
/** /**
* A (not-yet) Context sensitive L-System Fractal applet class. * A (not-yet) Context sensitive L-System Fractal applet class.
...@@ -50,9 +50,11 @@ import java.awt.event.*; ...@@ -50,9 +50,11 @@ import java.awt.event.*;
* *
* @author Jim Graham * @author Jim Graham
*/ */
@SuppressWarnings("serial")
public class CLSFractal public class CLSFractal
extends java.applet.Applet extends java.applet.Applet
implements Runnable, MouseListener { implements Runnable, MouseListener {
Thread kicker; Thread kicker;
ContextLSystem cls; ContextLSystem cls;
int fractLevel = 1; int fractLevel = 1;
...@@ -67,31 +69,48 @@ public class CLSFractal ...@@ -67,31 +69,48 @@ public class CLSFractal
int border; int border;
boolean normalizescaling; boolean normalizescaling;
@Override
public void init() { public void init() {
String s; String s;
cls = new ContextLSystem(this); cls = new ContextLSystem(this);
s = getParameter("level"); s = getParameter("level");
if (s != null) fractLevel = Integer.parseInt(s); if (s != null) {
fractLevel = Integer.parseInt(s);
}
s = getParameter("incremental"); s = getParameter("incremental");
if (s != null) incrementalUpdates = s.equalsIgnoreCase("true"); if (s != null) {
incrementalUpdates = s.equalsIgnoreCase("true");
}
s = getParameter("delay"); s = getParameter("delay");
if (s != null) repaintDelay = Integer.parseInt(s); if (s != null) {
repaintDelay = Integer.parseInt(s);
}
s = getParameter("startAngle"); s = getParameter("startAngle");
if (s != null) startAngle = Float.valueOf(s).floatValue(); if (s != null) {
startAngle = Float.valueOf(s).floatValue();
}
s = getParameter("rotAngle"); s = getParameter("rotAngle");
if (s != null) rotAngle = Float.valueOf(s).floatValue(); if (s != null) {
rotAngle = Float.valueOf(s).floatValue();
}
rotAngle = rotAngle / 360 * 2 * 3.14159265358f; rotAngle = rotAngle / 360 * 2 * 3.14159265358f;
s = getParameter("border"); s = getParameter("border");
if (s != null) border = Integer.parseInt(s); if (s != null) {
border = Integer.parseInt(s);
}
s = getParameter("normalizescale"); s = getParameter("normalizescale");
if (s != null) normalizescaling = s.equalsIgnoreCase("true"); if (s != null) {
normalizescaling = s.equalsIgnoreCase("true");
}
addMouseListener(this); addMouseListener(this);
} }
@Override
public void destroy() { public void destroy() {
removeMouseListener(this); removeMouseListener(this);
} }
@Override
public void run() { public void run() {
Thread me = Thread.currentThread(); Thread me = Thread.currentThread();
boolean needsRepaint = false; boolean needsRepaint = false;
...@@ -99,7 +118,10 @@ public class CLSFractal ...@@ -99,7 +118,10 @@ public class CLSFractal
cls.generate(); cls.generate();
if (kicker == me && incrementalUpdates) { if (kicker == me && incrementalUpdates) {
repaint(); repaint();
try {Thread.sleep(repaintDelay);} catch (InterruptedException e){} try {
Thread.sleep(repaintDelay);
} catch (InterruptedException ignored) {
}
} else { } else {
needsRepaint = true; needsRepaint = true;
} }
...@@ -112,22 +134,27 @@ public class CLSFractal ...@@ -112,22 +134,27 @@ public class CLSFractal
} }
} }
@Override
public void start() { public void start() {
kicker = new Thread(this); kicker = new Thread(this);
kicker.start(); kicker.start();
} }
@Override
public void stop() { public void stop() {
kicker = null; kicker = null;
} }
/*1.1 event handling */ /*1.1 event handling */
@Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
} }
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
} }
@Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
cls = new ContextLSystem(this); cls = new ContextLSystem(this);
savedPath = null; savedPath = null;
...@@ -135,14 +162,16 @@ public class CLSFractal ...@@ -135,14 +162,16 @@ public class CLSFractal
e.consume(); e.consume();
} }
@Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
} }
@Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
} }
String savedPath; String savedPath;
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
String fractalPath = cls.getPath(); String fractalPath = cls.getPath();
if (fractalPath == null) { if (fractalPath == null) {
...@@ -155,13 +184,14 @@ public class CLSFractal ...@@ -155,13 +184,14 @@ public class CLSFractal
} }
for (int i = 0; i < border; i++) { for (int i = 0; i < border; i++) {
g.draw3DRect(i, i, getSize().width - i * 2, getSize().height - i * 2,false); g.draw3DRect(i, i, getSize().width - i * 2, getSize().height - i * 2,
false);
} }
render(g, fractalPath); render(g, fractalPath);
} }
void render(Graphics g, String path) { void render(Graphics g, String path) {
Stack turtleStack = new Stack(); Stack<CLSTurtle> turtleStack = new Stack<CLSTurtle>();
CLSTurtle turtle; CLSTurtle turtle;
if (g == null) { if (g == null) {
...@@ -172,11 +202,13 @@ public class CLSFractal ...@@ -172,11 +202,13 @@ public class CLSFractal
turtle = new CLSTurtle(startAngle, 0, 0, 0, 0, 1, 1); turtle = new CLSTurtle(startAngle, 0, 0, 0, 0, 1, 1);
} else { } else {
float frwidth = Xmax - Xmin; float frwidth = Xmax - Xmin;
if (frwidth == 0) if (frwidth == 0) {
frwidth = 1; frwidth = 1;
}
float frheight = Ymax - Ymin; float frheight = Ymax - Ymin;
if (frheight == 0) if (frheight == 0) {
frheight = 1; frheight = 1;
}
float xscale = (getSize().width - border * 2 - 1) / frwidth; float xscale = (getSize().width - border * 2 - 1) / frwidth;
float yscale = (getSize().height - border * 2 - 1) / frheight; float yscale = (getSize().height - border * 2 - 1) / frheight;
int xoff = border; int xoff = border;
...@@ -184,84 +216,102 @@ public class CLSFractal ...@@ -184,84 +216,102 @@ public class CLSFractal
if (normalizescaling) { if (normalizescaling) {
if (xscale < yscale) { if (xscale < yscale) {
yoff += ((getSize().height - border * 2) yoff += ((getSize().height - border * 2)
- ((Ymax - Ymin) * xscale)) / 2; - ((Ymax - Ymin) * xscale)) / 2;
yscale = xscale; yscale = xscale;
} else if (yscale < xscale) { } else if (yscale < xscale) {
xoff += ((getSize().width - border * 2) xoff += ((getSize().width - border * 2)
- ((Xmax - Xmin) * yscale)) / 2; - ((Xmax - Xmin) * yscale)) / 2;
xscale = yscale; xscale = yscale;
} }
} }
turtle = new CLSTurtle(startAngle, 0 - Xmin, 0 - Ymin, turtle = new CLSTurtle(startAngle, 0 - Xmin, 0 - Ymin,
xoff, yoff, xscale, yscale); xoff, yoff, xscale, yscale);
} }
for (int pos = 0; pos < path.length(); pos++) { for (int pos = 0; pos < path.length(); pos++) {
switch (path.charAt(pos)) { switch (path.charAt(pos)) {
case '+': case '+':
turtle.rotate(rotAngle); turtle.rotate(rotAngle);
break; break;
case '-': case '-':
turtle.rotate(-rotAngle); turtle.rotate(-rotAngle);
break; break;
case '[': case '[':
turtleStack.push(turtle); turtleStack.push(turtle);
turtle = new CLSTurtle(turtle); turtle = new CLSTurtle(turtle);
break; break;
case ']': case ']':
turtle = (CLSTurtle) turtleStack.pop(); turtle = turtleStack.pop();
break; break;
case 'f': case 'f':
turtle.jump();
break;
case 'F':
if (g == null) {
includePt(turtle.X, turtle.Y);
turtle.jump(); turtle.jump();
includePt(turtle.X, turtle.Y); break;
} else { case 'F':
turtle.draw(g); if (g == null) {
} includePt(turtle.X, turtle.Y);
break; turtle.jump();
default: includePt(turtle.X, turtle.Y);
break; } else {
turtle.draw(g);
}
break;
default:
break;
} }
} }
} }
void includePt(float x, float y) { void includePt(float x, float y) {
if (x < Xmin) if (x < Xmin) {
Xmin = x; Xmin = x;
if (x > Xmax) }
if (x > Xmax) {
Xmax = x; Xmax = x;
if (y < Ymin) }
if (y < Ymin) {
Ymin = y; Ymin = y;
if (y > Ymax) }
if (y > Ymax) {
Ymax = y; Ymax = y;
}
}
@Override
public String getAppletInfo() {
return "Title: CLSFractal 1.1f, 27 Mar 1995 \nAuthor: Jim Graham \nA "
+ "(not yet) Context Sensitive L-System production rule. \n"
+ "This class encapsulates a production rule for a Context "
+ "Sensitive\n L-System \n(pred, succ, lContext, rContext)."
+ " The matches() method, however, does not \n(yet) verify "
+ "the lContext and rContext parts of the rule.";
} }
public String getAppletInfo() { @Override
return "Title: CLSFractal 1.1f, 27 Mar 1995 \nAuthor: Jim Graham \nA (not yet) Context Sensitive L-System production rule. \nThis class encapsulates a production rule for a Context Sensitive\n L-System \n(pred, succ, lContext, rContext). The matches() method, however, does not \n(yet) verify the lContext and rContext parts of the rule."; public String[][] getParameterInfo() {
} String[][] info = {
{ "level", "int", "Maximum number of recursions. Default is 1." },
public String[][] getParameterInfo() { { "incremental", "boolean", "Whether or not to repaint between "
String[][] info = { + "recursions. Default is true." },
{"level", "int", "Maximum number of recursions. Default is 1."}, { "delay", "integer", "Sets delay between repaints. Default is 50." },
{"incremental","boolean","Whether or not to repaint between recursions. Default is true."}, { "startAngle", "float", "Sets the starting angle. Default is 0." },
{"delay","integer","Sets delay between repaints. Default is 50."}, { "rotAngle", "float", "Sets the rotation angle. Default is 45." },
{"startAngle","float","Sets the starting angle. Default is 0."}, { "border", "integer", "Width of border. Default is 2." },
{"rotAngle","float","Sets the rotation angle. Default is 45."}, { "normalizeScale", "boolean", "Whether or not to normalize "
{"border","integer","Width of border. Default is 2."}, + "the scaling. Default is true." },
{"normalizeScale","boolean","Whether or not to normalize the scaling. Default is true."}, { "pred", "String",
{"pred","String","Initializes the rules for Context Sensitive L-Systems."}, "Initializes the rules for Context Sensitive L-Systems." },
{"succ","String","Initializes the rules for Context Sensitive L-Systems."}, { "succ", "String",
{"lContext","String","Initializes the rules for Context Sensitive L-Systems."}, "Initializes the rules for Context Sensitive L-Systems." },
{"rContext","String","Initializes the rules for Context Sensitive L-Systems."} { "lContext", "String",
}; "Initializes the rules for Context Sensitive L-Systems." },
return info; { "rContext", "String",
} "Initializes the rules for Context Sensitive L-Systems." }
};
return info;
}
} }
/** /**
* A Logo turtle class designed to support Context sensitive L-Systems. * A Logo turtle class designed to support Context sensitive L-Systems.
* *
...@@ -271,6 +321,7 @@ public class CLSFractal ...@@ -271,6 +321,7 @@ public class CLSFractal
* @author Jim Graham * @author Jim Graham
*/ */
class CLSTurtle { class CLSTurtle {
float angle; float angle;
float X; float X;
float Y; float Y;
...@@ -280,7 +331,7 @@ class CLSTurtle { ...@@ -280,7 +331,7 @@ class CLSTurtle {
int yoff; int yoff;
public CLSTurtle(float ang, float x, float y, public CLSTurtle(float ang, float x, float y,
int xorg, int yorg, float sx, float sy) { int xorg, int yorg, float sx, float sy) {
angle = ang; angle = ang;
scaleX = sx; scaleX = sx;
scaleY = sy; scaleY = sy;
...@@ -313,12 +364,13 @@ class CLSTurtle { ...@@ -313,12 +364,13 @@ class CLSTurtle {
float x = X + (float) Math.cos(angle) * scaleX; float x = X + (float) Math.cos(angle) * scaleX;
float y = Y + (float) Math.sin(angle) * scaleY; float y = Y + (float) Math.sin(angle) * scaleY;
g.drawLine((int) X + xoff, (int) Y + yoff, g.drawLine((int) X + xoff, (int) Y + yoff,
(int) x + xoff, (int) y + yoff); (int) x + xoff, (int) y + yoff);
X = x; X = x;
Y = y; Y = y;
} }
} }
/** /**
* A (non-)Context sensitive L-System class. * A (non-)Context sensitive L-System class.
* *
...@@ -330,22 +382,23 @@ class CLSTurtle { ...@@ -330,22 +382,23 @@ class CLSTurtle {
* @author Jim Graham * @author Jim Graham
*/ */
class ContextLSystem { class ContextLSystem {
String axiom; String axiom;
Vector rules = new Vector(); List<CLSRule> rules = new ArrayList<CLSRule>();
int level; int level;
public ContextLSystem(java.applet.Applet app) { public ContextLSystem(java.applet.Applet app) {
axiom = app.getParameter("axiom"); axiom = app.getParameter("axiom");
int num = 1; int num = 1;
while (true) { while (true) {
String pred = app.getParameter("pred"+num); String pred = app.getParameter("pred" + num);
String succ = app.getParameter("succ"+num); String succ = app.getParameter("succ" + num);
if (pred == null || succ == null) { if (pred == null || succ == null) {
break; break;
} }
rules.addElement(new CLSRule(pred, succ, rules.add(new CLSRule(pred, succ,
app.getParameter("lContext"+num), app.getParameter("lContext" + num),
app.getParameter("rContext"+num))); app.getParameter("rContext" + num)));
num++; num++;
} }
currentPath = new StringBuffer(axiom); currentPath = new StringBuffer(axiom);
...@@ -355,7 +408,6 @@ class ContextLSystem { ...@@ -355,7 +408,6 @@ class ContextLSystem {
public int getLevel() { public int getLevel() {
return level; return level;
} }
StringBuffer currentPath; StringBuffer currentPath;
public synchronized String getPath() { public synchronized String getPath() {
...@@ -385,7 +437,7 @@ class ContextLSystem { ...@@ -385,7 +437,7 @@ class ContextLSystem {
public CLSRule findRule(int pos) { public CLSRule findRule(int pos) {
for (int i = 0; i < rules.size(); i++) { for (int i = 0; i < rules.size(); i++) {
CLSRule rule = (CLSRule) rules.elementAt(i); CLSRule rule = rules.get(i);
if (rule.matches(currentPath, pos)) { if (rule.matches(currentPath, pos)) {
return rule; return rule;
} }
...@@ -394,6 +446,7 @@ class ContextLSystem { ...@@ -394,6 +446,7 @@ class ContextLSystem {
} }
} }
/** /**
* A Context sensitive L-System production rule. * A Context sensitive L-System production rule.
* *
...@@ -405,6 +458,7 @@ class ContextLSystem { ...@@ -405,6 +458,7 @@ class ContextLSystem {
* @author Jim Graham * @author Jim Graham
*/ */
class CLSRule { class CLSRule {
String pred; String pred;
String succ; String succ;
String lContext; String lContext;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<body> <body>
<h1>Fractals 1.1</h1> <h1>Fractals 1.1</h1>
<hr> <hr>
<applet applet code="CLSFractal.class" width=500 height=120> <applet code="CLSFractal.class" width=500 height=120>
<param name=level value="5"> <param name=level value="5">
<param name=rotangle value="45"> <param name=rotangle value="45">
<param name=succ1 value="F-F++F-F"> <param name=succ1 value="F-F++F-F">
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.awt.Frame; import java.awt.Frame;
import java.awt.Event; import java.awt.Event;
...@@ -38,66 +36,67 @@ import java.awt.Dimension; ...@@ -38,66 +36,67 @@ import java.awt.Dimension;
import java.applet.Applet; import java.applet.Applet;
import java.awt.AWTEvent; import java.awt.AWTEvent;
// Applet to Application Frame window
class AppletFrame extends Frame /**
{ * Applet to Application Frame window
*/
@SuppressWarnings("serial")
class AppletFrame extends Frame {
public static void startApplet(String className, public static void startApplet(String className,
String title, String title,
String args[]) String args[]) {
{ // local variables
// local variables Applet a;
Applet a; Dimension appletSize;
Dimension appletSize;
try try {
{ // create an instance of your applet class
// create an instance of your applet class a = (Applet) Class.forName(className).newInstance();
a = (Applet) Class.forName(className).newInstance(); } catch (ClassNotFoundException e) {
} return;
catch (ClassNotFoundException e) { return; } } catch (InstantiationException e) {
catch (InstantiationException e) { return; } return;
catch (IllegalAccessException e) { return; } } catch (IllegalAccessException e) {
return;
}
// initialize the applet // initialize the applet
a.init(); a.init();
a.start(); a.start();
// create new application frame window // create new application frame window
AppletFrame f = new AppletFrame(title); AppletFrame f = new AppletFrame(title);
// add applet to frame window // add applet to frame window
f.add("Center", a); f.add("Center", a);
// resize frame window to fit applet // resize frame window to fit applet
// assumes that the applet sets its own size // assumes that the applet sets its own size
// otherwise, you should set a specific size here. // otherwise, you should set a specific size here.
appletSize = a.getSize(); appletSize = a.getSize();
f.pack(); f.pack();
f.setSize(appletSize); f.setSize(appletSize);
// show the window // show the window
f.show(); f.setVisible(true);
} // end startApplet() } // end startApplet()
// constructor needed to pass window title to class Frame // constructor needed to pass window title to class Frame
public AppletFrame(String name) public AppletFrame(String name) {
{ // call java.awt.Frame(String) constructor
// call java.awt.Frame(String) constructor super(name);
super(name);
} }
// needed to allow window close // needed to allow window close
public void processEvent(AWTEvent e) @Override
{ public void processEvent(AWTEvent e) {
// Window Destroy event // Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) if (e.getID() == Event.WINDOW_DESTROY) {
{ // exit the program
// exit the program System.exit(0);
System.exit(0); }
} } // end handleEvent()
} // end handleEvent()
} // end class AppletFrame } // end class AppletFrame
/* /*
* Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1995, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,22 +29,23 @@ ...@@ -29,22 +29,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
/** A fairly conventional 3D matrix object that can transform sets of /** A fairly conventional 3D matrix object that can transform sets of
3D points and perform a variety of manipulations on the transform */ 3D points and perform a variety of manipulations on the transform */
class Matrix3D { class Matrix3D {
float xx, xy, xz, xo; float xx, xy, xz, xo;
float yx, yy, yz, yo; float yx, yy, yz, yo;
float zx, zy, zz, zo; float zx, zy, zz, zo;
static final double pi = 3.14159265; static final double pi = 3.14159265;
/** Create a new unit matrix */ /** Create a new unit matrix */
Matrix3D () { Matrix3D() {
xx = 1.0f; xx = 1.0f;
yy = 1.0f; yy = 1.0f;
zz = 1.0f; zz = 1.0f;
} }
/** Scale by f in all dimensions */ /** Scale by f in all dimensions */
void scale(float f) { void scale(float f) {
xx *= f; xx *= f;
...@@ -60,6 +61,7 @@ class Matrix3D { ...@@ -60,6 +61,7 @@ class Matrix3D {
zz *= f; zz *= f;
zo *= f; zo *= f;
} }
/** Scale along each axis independently */ /** Scale along each axis independently */
void scale(float xf, float yf, float zf) { void scale(float xf, float yf, float zf) {
xx *= xf; xx *= xf;
...@@ -75,12 +77,14 @@ class Matrix3D { ...@@ -75,12 +77,14 @@ class Matrix3D {
zz *= zf; zz *= zf;
zo *= zf; zo *= zf;
} }
/** Translate the origin */ /** Translate the origin */
void translate(float x, float y, float z) { void translate(float x, float y, float z) {
xo += x; xo += x;
yo += y; yo += y;
zo += z; zo += z;
} }
/** rotate theta degrees about the y axis */ /** rotate theta degrees about the y axis */
void yrot(double theta) { void yrot(double theta) {
theta *= (pi / 180); theta *= (pi / 180);
...@@ -106,6 +110,7 @@ class Matrix3D { ...@@ -106,6 +110,7 @@ class Matrix3D {
zy = Nzy; zy = Nzy;
zz = Nzz; zz = Nzz;
} }
/** rotate theta degrees about the x axis */ /** rotate theta degrees about the x axis */
void xrot(double theta) { void xrot(double theta) {
theta *= (pi / 180); theta *= (pi / 180);
...@@ -131,6 +136,7 @@ class Matrix3D { ...@@ -131,6 +136,7 @@ class Matrix3D {
zy = Nzy; zy = Nzy;
zz = Nzz; zz = Nzz;
} }
/** rotate theta degrees about the z axis */ /** rotate theta degrees about the z axis */
void zrot(double theta) { void zrot(double theta) {
theta *= (pi / 180); theta *= (pi / 180);
...@@ -156,6 +162,7 @@ class Matrix3D { ...@@ -156,6 +162,7 @@ class Matrix3D {
xy = Nxy; xy = Nxy;
xz = Nxz; xz = Nxz;
} }
/** Multiply this matrix by a second: M = M*R */ /** Multiply this matrix by a second: M = M*R */
void mult(Matrix3D rhs) { void mult(Matrix3D rhs) {
float lxx = xx * rhs.xx + yx * rhs.xy + zx * rhs.xz; float lxx = xx * rhs.xx + yx * rhs.xy + zx * rhs.xz;
...@@ -204,10 +211,11 @@ class Matrix3D { ...@@ -204,10 +211,11 @@ class Matrix3D {
zy = 0; zy = 0;
zz = 1; zz = 1;
} }
/** Transform nvert points from v into tv. v contains the input /** Transform nvert points from v into tv. v contains the input
coordinates in floating point. Three successive entries in coordinates in floating point. Three successive entries in
the array constitute a point. tv ends up holding the transformed the array constitute a point. tv ends up holding the transformed
points as integers; three successive entries per point */ points as integers; three successive entries per point */
void transform(float v[], int tv[], int nvert) { void transform(float v[], int tv[], int nvert) {
float lxx = xx, lxy = xy, lxz = xz, lxo = xo; float lxx = xx, lxy = xy, lxz = xz, lxo = xo;
float lyx = yx, lyy = yy, lyz = yz, lyo = yo; float lyx = yx, lyy = yy, lyz = yz, lyo = yo;
...@@ -216,11 +224,13 @@ class Matrix3D { ...@@ -216,11 +224,13 @@ class Matrix3D {
float x = v[i]; float x = v[i];
float y = v[i + 1]; float y = v[i + 1];
float z = v[i + 2]; float z = v[i + 2];
tv[i ] = (int) (x * lxx + y * lxy + z * lxz + lxo); tv[i] = (int) (x * lxx + y * lxy + z * lxz + lxo);
tv[i + 1] = (int) (x * lyx + y * lyy + z * lyz + lyo); tv[i + 1] = (int) (x * lyx + y * lyy + z * lyz + lyo);
tv[i + 2] = (int) (x * lzx + y * lzy + z * lzz + lzo); tv[i + 2] = (int) (x * lzx + y * lzy + z * lzz + lzo);
} }
} }
@Override
public String toString() { public String toString() {
return ("[" + xo + "," + xx + "," + xy + "," + xz + ";" return ("[" + xo + "," + xx + "," + xy + "," + xz + ";"
+ yo + "," + yx + "," + yy + "," + yz + ";" + yo + "," + yx + "," + yy + "," + yz + ";"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<h1>MoleculeViewer (example 1)</h1> <h1>MoleculeViewer (example 1)</h1>
<hr> <hr>
<applet code=XYZApp.class width=300 height=300> <applet code=XYZApp.class width=300 height=300>
<param name=model value=models/HyaluronicAcid.xyz> <param name=model value="models/HyaluronicAcid.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason." alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag! Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet> </applet>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<h1>MoleculeViewer (example 2)</h1> <h1>MoleculeViewer (example 2)</h1>
<hr> <hr>
<applet code=XYZApp.class width=300 height=300> <applet code=XYZApp.class width=300 height=300>
<param name=model value=models/buckminsterfullerine.xyz> <param name=model value="models/buckminsterfullerine.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason." alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag! Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet> </applet>
......
...@@ -6,25 +6,25 @@ ...@@ -6,25 +6,25 @@
<h1>MoleculeViewer (example 3)</h1> <h1>MoleculeViewer (example 3)</h1>
<hr> <hr>
<applet code=XYZApp.class width=100 height=100> <applet code=XYZApp.class width=100 height=100>
<param name=model value=models/water.xyz> <param name=model value="models/water.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason." alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag! Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet> </applet>
<p> <p>
<applet code=XYZApp.class width=100 height=100> <applet code=XYZApp.class width=100 height=100>
<param name=model value=models/benzene.xyz> <param name=model value="models/benzene.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason." alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag! Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet> </applet>
<p> <p>
<applet code=XYZApp.class width=100 height=100> <applet code=XYZApp.class width=100 height=100>
<param name=model value=models/ethane.xyz> <param name=model value="models/ethane.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason." alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag! Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet> </applet>
<p> <p>
<applet code=XYZApp.class width=100 height=100> <applet code=XYZApp.class width=100 height=100>
<param name=model value=models/cyclohexane.xyz> <param name=model value="models/cyclohexane.xyz">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason." alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag! Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet> </applet>
......
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,37 +29,37 @@ ...@@ -29,37 +29,37 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.awt.event.*;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Font; import java.awt.Font;
import java.applet.Applet; import java.applet.Applet;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/** /**
* An applet that displays jittering text on the screen. * An applet that displays jittering text on the screen.
* *
* @author Daniel Wyszynski 04/12/95 * @author Daniel Wyszynski 04/12/95
* @modified 05/09/95 kwalrath Changed string; added thread suspension * @author 05/09/95 kwalrath Changed string; added thread suspension
* @modified 02/06/98 madbot removed use of suspend and resume and cleaned up * @author 02/06/98 madbot removed use of suspend and resume and cleaned up
*/ */
@SuppressWarnings("serial")
public class NervousText extends Applet implements Runnable, MouseListener { public class NervousText extends Applet implements Runnable, MouseListener {
String banner; // The text to be displayed String banner; // The text to be displayed
char bannerChars[]; // The same text as an array of characters char bannerChars[]; // The same text as an array of characters
char attributes[]; // Character attributes ('^' for superscript) char attributes[]; // Character attributes ('^' for superscript)
Thread runner = null; // The thread that is displaying the text Thread runner = null; // The thread that is displaying the text
boolean threadSuspended; // True when thread suspended (via mouse click) boolean threadSuspended; // True when thread suspended (via mouse click)
static final int REGULAR_WD = 15; static final int REGULAR_WD = 15;
static final int REGULAR_HT = 36; static final int REGULAR_HT = 36;
static final int SMALL_WD = 12; static final int SMALL_WD = 12;
static final int SMALL_HT = 24; static final int SMALL_HT = 24;
Font regularFont = new Font("Serif", Font.BOLD, REGULAR_HT); Font regularFont = new Font("Serif", Font.BOLD, REGULAR_HT);
Font smallFont = new Font("Serif", Font.BOLD, SMALL_HT); Font smallFont = new Font("Serif", Font.BOLD, SMALL_HT);
@Override
public void init() { public void init() {
banner = getParameter("text"); banner = getParameter("text");
if (banner == null) { if (banner == null) {
...@@ -67,8 +67,8 @@ public class NervousText extends Applet implements Runnable, MouseListener { ...@@ -67,8 +67,8 @@ public class NervousText extends Applet implements Runnable, MouseListener {
} }
int bannerLength = banner.length(); int bannerLength = banner.length();
StringBuffer bc = new StringBuffer(bannerLength); StringBuilder bc = new StringBuilder(bannerLength);
StringBuffer attrs = new StringBuffer(bannerLength); StringBuilder attrs = new StringBuilder(bannerLength);
int wd = 0; int wd = 0;
for (int i = 0; i < bannerLength; i++) { for (int i = 0; i < bannerLength; i++) {
char c = banner.charAt(i); char c = banner.charAt(i);
...@@ -89,7 +89,7 @@ public class NervousText extends Applet implements Runnable, MouseListener { ...@@ -89,7 +89,7 @@ public class NervousText extends Applet implements Runnable, MouseListener {
} }
bannerLength = bc.length(); bannerLength = bc.length();
bannerChars = new char[bannerLength]; bannerChars = new char[bannerLength];
attributes = new char[bannerLength]; attributes = new char[bannerLength];
bc.getChars(0, bannerLength, bannerChars, 0); bc.getChars(0, bannerLength, bannerChars, 0);
attrs.getChars(0, bannerLength, attributes, 0); attrs.getChars(0, bannerLength, attributes, 0);
...@@ -99,15 +99,18 @@ public class NervousText extends Applet implements Runnable, MouseListener { ...@@ -99,15 +99,18 @@ public class NervousText extends Applet implements Runnable, MouseListener {
addMouseListener(this); addMouseListener(this);
} }
@Override
public void destroy() { public void destroy() {
removeMouseListener(this); removeMouseListener(this);
} }
@Override
public void start() { public void start() {
runner = new Thread(this); runner = new Thread(this);
runner.start(); runner.start();
} }
@Override
public synchronized void stop() { public synchronized void stop() {
runner = null; runner = null;
if (threadSuspended) { if (threadSuspended) {
...@@ -116,22 +119,24 @@ public class NervousText extends Applet implements Runnable, MouseListener { ...@@ -116,22 +119,24 @@ public class NervousText extends Applet implements Runnable, MouseListener {
} }
} }
@Override
public void run() { public void run() {
Thread me = Thread.currentThread(); Thread me = Thread.currentThread();
while (runner == me) { while (runner == me) {
try { try {
Thread.sleep(100); Thread.sleep(100);
synchronized(this) { synchronized (this) {
while (threadSuspended) { while (threadSuspended) {
wait(); wait();
} }
} }
} catch (InterruptedException e){ } catch (InterruptedException e) {
} }
repaint(); repaint();
} }
} }
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
int length = bannerChars.length; int length = bannerChars.length;
for (int i = 0, x = 0; i < length; i++) { for (int i = 0, x = 0; i < length; i++) {
...@@ -152,33 +157,41 @@ public class NervousText extends Applet implements Runnable, MouseListener { ...@@ -152,33 +157,41 @@ public class NervousText extends Applet implements Runnable, MouseListener {
} }
} }
@Override
public synchronized void mousePressed(MouseEvent e) { public synchronized void mousePressed(MouseEvent e) {
e.consume(); e.consume();
threadSuspended = !threadSuspended; threadSuspended = !threadSuspended;
if (!threadSuspended) if (!threadSuspended) {
notify(); notify();
}
} }
@Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
} }
@Override
public void mouseEntered(MouseEvent e) { public void mouseEntered(MouseEvent e) {
} }
@Override
public void mouseExited(MouseEvent e) { public void mouseExited(MouseEvent e) {
} }
@Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
} }
@Override
public String getAppletInfo() { public String getAppletInfo() {
return "Title: NervousText\nAuthor: Daniel Wyszynski\nDisplays a text banner that jitters."; return "Title: NervousText\nAuthor: Daniel Wyszynski\n"
+ "Displays a text banner that jitters.";
} }
@Override
public String[][] getParameterInfo() { public String[][] getParameterInfo() {
String pinfo[][] = { String pinfo[][] = {
{"text", "string", "Text to display"}, { "text", "string", "Text to display" }, };
};
return pinfo; return pinfo;
} }
} }
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,22 +29,26 @@ ...@@ -29,22 +29,26 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
import java.awt.Graphics; import java.awt.Graphics;
@SuppressWarnings("serial")
public class GraphApplet extends java.applet.Applet { public class GraphApplet extends java.applet.Applet {
double f(double x) { double f(double x) {
return (Math.cos(x/5) + Math.sin(x/7) + 2) * getSize().height / 4; return (Math.cos(x / 5) + Math.sin(x / 7) + 2) * getSize().height / 4;
} }
@Override
public void paint(Graphics g) { public void paint(Graphics g) {
for (int x = 0 ; x < getSize().width ; x++) { for (int x = 0; x < getSize().width; x++) {
g.drawLine(x, (int)f(x), x + 1, (int)f(x + 1)); g.drawLine(x, (int) f(x), x + 1, (int) f(x + 1));
} }
} }
public String getAppletInfo() {
return "Draws a sin graph."; @Override
} public String getAppletInfo() {
return "Draws a sin graph.";
}
} }
/* /*
* Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
/*
*/
/** /**
* A bi-directional bubble sort demonstration algorithm * A bi-directional bubble sort demonstration algorithm
...@@ -39,6 +37,8 @@ ...@@ -39,6 +37,8 @@
* @author James Gosling * @author James Gosling
*/ */
class BidirBubbleSortAlgorithm extends SortAlgorithm { class BidirBubbleSortAlgorithm extends SortAlgorithm {
@Override
void sort(int a[]) throws Exception { void sort(int a[]) throws Exception {
int j; int j;
int limit = a.length; int limit = a.length;
...@@ -61,9 +61,9 @@ class BidirBubbleSortAlgorithm extends SortAlgorithm { ...@@ -61,9 +61,9 @@ class BidirBubbleSortAlgorithm extends SortAlgorithm {
} }
if (!swapped) { if (!swapped) {
return; return;
} } else {
else
swapped = false; swapped = false;
}
for (j = limit; --j >= st;) { for (j = limit; --j >= st;) {
if (stopRequested) { if (stopRequested) {
return; return;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<h1>The Sorting Algorithm Demo (1.1)</h1> <h1>The Sorting Algorithm Demo (1.1)</h1>
<hr> <hr>
<table cols=3 width="340"> <table width="340">
<tr> <tr>
<th><strong>Bubble Sort</strong></th> <th><strong>Bubble Sort</strong></th>
<th><strong>Bidirectional Bubble Sort</strong></th> <th><strong>Bidirectional Bubble Sort</strong></th>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<h1>3D Model: Cube</h1> <h1>3D Model: Cube</h1>
<hr> <hr>
<applet code=ThreeD.class width=100 height=100> <applet code=ThreeD.class width=100 height=100>
<param name=model value=models/cube.obj> <param name=model value="models/cube.obj">
alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason." alt="Your browser understands the &lt;APPLET&gt; tag but isn't running the applet, for some reason."
Your browser is completely ignoring the &lt;APPLET&gt; tag! Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet> </applet>
......
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册