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

Merge

......@@ -39,7 +39,8 @@ SUBDIRS = \
Notepad \
SampleTree \
SwingApplet \
TableExample
TableExample \
TransparentRuler
# Some demos aren't currently included in 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 @@
# or visit www.oracle.com if you need additional information or have any
# questions.
#
tzdata2011d
tzdata2011e
......@@ -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
# </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 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
Rule Morocco 2009 only - Aug 21 0:00 0 -
Rule Morocco 2010 only - May 2 0:00 1:00 S
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 Africa/Casablanca -0:30:20 - LMT 1913 Oct 26
0:00 Morocco WE%sT 1984 Mar 16
......
......@@ -1193,6 +1193,19 @@ Zone America/Rio_Branco -4:31:12 - LMT 1914
# From Arthur David Olson (2011-03-02):
# The emol.com article mentions a water shortage as the cause of the
# 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 Chile 1927 1932 - Sep 1 0:00 1:00 S
Rule Chile 1928 1932 - Apr 1 0:00 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 - Sep 27 4:00u 1:00 S
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 -
# N.B.: the end of March 29 in Chile is March 30 in Universal time,
# which is used below in specifying the transition.
Rule Chile 2008 only - Mar 30 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 -
# IATA SSIM anomalies: (1992-02) says 1992-03-14;
# (1996-09) says 1998-03-08. Ignore these.
......
......@@ -5821,7 +5821,7 @@ public abstract class Component implements ImageObserver, MenuContainer,
* <code>InputMethodRequests</code> instance.
* If listener <code>l</code> is <code>null</code>,
* 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.
*
* @param l the input method listener
......
......@@ -66,7 +66,7 @@ public interface CharSequence {
* indexing. </p>
*
* <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.
*
* @param index the index of the <code>char</code> value to be returned
......
......@@ -476,7 +476,7 @@ public final class JLayer<V extends Component>
* for this {@code JLayer} and the {@code JLayer}
* is displayable.
* <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:
* <pre>
* public void installUI(JComponent c) {
......@@ -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}
* if any of them is visible and contains passed x,y point.
* After that it checks if no mouseListeners is attached to this component
......
......@@ -203,6 +203,12 @@ public class PopupFactory {
popupType = HEAVY_WEIGHT_POPUP;
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();
}
......
......@@ -727,6 +727,9 @@ public class SpringLayout implements LayoutManager2 {
* For any other <code>String</code> value passed as the edge,
* no action is taken. For a <code>null</code> edge, a
* <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 s the spring controlling the specified edge
......
......@@ -25,9 +25,7 @@
package javax.swing.plaf;
import javax.accessibility.Accessible;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
......@@ -38,7 +36,7 @@ import java.io.Serializable;
/**
* The base class for all {@link javax.swing.JLayer}'s UI delegates.
* <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}
* and {@link #eventDispatched(AWTEvent, JLayer)} method is notified
* about any {@code AWTEvent}s which have been generated by a {@code JLayer}
......@@ -165,7 +163,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.COMPONENT_EVENT_MASK);
* }
*
* public void unistallUI(JComponent c) {
* public void uninstallUI(JComponent c) {
* super.uninstallUI(c);
* JLayer l = (JLayer) c;
* l.setLayerEventMask(0);
......@@ -197,7 +195,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.FOCUS_EVENT_MASK);
* }
*
* public void unistallUI(JComponent c) {
* public void uninstallUI(JComponent c) {
* super.uninstallUI(c);
* JLayer l = (JLayer) c;
* l.setLayerEventMask(0);
......@@ -229,7 +227,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.KEY_EVENT_MASK);
* }
*
* public void unistallUI(JComponent c) {
* public void uninstallUI(JComponent c) {
* super.uninstallUI(c);
* JLayer l = (JLayer) c;
* l.setLayerEventMask(0);
......@@ -261,7 +259,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK);
* }
*
* public void unistallUI(JComponent c) {
* public void uninstallUI(JComponent c) {
* super.uninstallUI(c);
* JLayer l = (JLayer) c;
* l.setLayerEventMask(0);
......@@ -293,7 +291,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.MOUSE_MOTION_EVENT_MASK);
* }
*
* public void unistallUI(JComponent c) {
* public void uninstallUI(JComponent c) {
* super.uninstallUI(c);
* JLayer l = (JLayer) c;
* l.setLayerEventMask(0);
......@@ -325,7 +323,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
* }
*
* public void unistallUI(JComponent c) {
* public void uninstallUI(JComponent c) {
* super.uninstallUI(c);
* JLayer l = (JLayer) c;
* l.setLayerEventMask(0);
......@@ -357,7 +355,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.INPUT_METHOD_EVENT_MASK);
* }
*
* public void unistallUI(JComponent c) {
* public void uninstallUI(JComponent c) {
* super.uninstallUI(c);
* JLayer l = (JLayer) c;
* l.setLayerEventMask(0);
......@@ -389,7 +387,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.HIERARCHY_EVENT_MASK);
* }
*
* public void unistallUI(JComponent c) {
* public void uninstallUI(JComponent c) {
* super.uninstallUI(c);
* JLayer l = (JLayer) c;
* l.setLayerEventMask(0);
......@@ -421,7 +419,7 @@ public class LayerUI<V extends Component>
* l.setLayerEventMask(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
* }
*
* public void unistallUI(JComponent c) {
* public void uninstallUI(JComponent c) {
* super.uninstallUI(c);
* JLayer l = (JLayer) c;
* l.setLayerEventMask(0);
......@@ -691,7 +689,7 @@ public class LayerUI<V extends Component>
* Otherwise, the default implementation is used.
*
* @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) {
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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -26,13 +26,11 @@ package javax.swing.plaf.nimbus;
import javax.swing.border.Border;
import javax.swing.JComponent;
import javax.swing.plaf.UIResource;
import java.awt.Insets;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.Transparency;
import java.awt.RenderingHints;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
......@@ -58,7 +56,9 @@ class LoweredBorder extends AbstractRegionPainter implements Border {
@Override
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 {
*/
protected void doPaint(Graphics2D g, JComponent c, int width, int height,
Object[] extendedCacheKeys) {
Color color = (c == null) ? Color.BLACK : c.getBackground();
BufferedImage img1 = new BufferedImage(IMG_SIZE,IMG_SIZE,
BufferedImage.TYPE_INT_ARGB);
BufferedImage img2 = new BufferedImage(IMG_SIZE,IMG_SIZE,
......@@ -93,14 +94,14 @@ class LoweredBorder extends AbstractRegionPainter implements Border {
Graphics2D g2 = (Graphics2D)img1.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setColor(c.getBackground());
g2.setColor(color);
g2.fillRoundRect(2,0,26,26,RADIUS,RADIUS);
g2.dispose();
// draw shadow
InnerShadowEffect effect = new InnerShadowEffect();
effect.setDistance(1);
effect.setSize(3);
effect.setColor(getLighter(c.getBackground(),2.1f));
effect.setColor(getLighter(color, 2.1f));
effect.setAngle(90);
effect.applyEffect(img1,img2,IMG_SIZE,IMG_SIZE);
// draw outline to img2
......@@ -108,7 +109,7 @@ class LoweredBorder extends AbstractRegionPainter implements Border {
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
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.dispose();
// draw final image
......@@ -150,7 +151,7 @@ class LoweredBorder extends AbstractRegionPainter implements Border {
* @param c the component for which this border insets value applies
*/
public Insets getBorderInsets(Component c) {
return INSETS;
return (Insets) INSETS.clone();
}
/**
......
......@@ -786,9 +786,9 @@ public class SynthTableUI extends BasicTableUI
hasFocus, row, column);
setIcon(null);
Class columnClass = table.getColumnClass(column);
configureValue(value, columnClass);
if (table != null) {
configureValue(value, table.getColumnClass(column));
}
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
* modification, are permitted provided that the following conditions
......@@ -29,22 +29,24 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/**
* An interactive test of the Graphics.drawArc and Graphics.fillArc
* routines. Can be run either as a standalone application by
* typing "java ArcTest" or as an applet in the AppletViewer.
*/
@SuppressWarnings("serial")
public class ArcTest extends Applet {
ArcControls controls; // The controls for marking and filling arcs
ArcCanvas canvas; // The drawing area to display arcs
@Override
public void init() {
setLayout(new BorderLayout());
canvas = new ArcCanvas();
......@@ -52,19 +54,23 @@ public class ArcTest extends Applet {
add("South", controls = new ArcControls(canvas));
}
@Override
public void destroy() {
remove(controls);
remove(canvas);
}
@Override
public void start() {
controls.setEnabled(true);
}
@Override
public void stop() {
controls.setEnabled(false);
}
@Override
public void processEvent(AWTEvent e) {
if (e.getID() == Event.WINDOW_DESTROY) {
System.exit(0);
......@@ -80,20 +86,28 @@ public class ArcTest extends Applet {
f.add("Center", arcTest);
f.setSize(300, 300);
f.show();
f.setVisible(true);
}
@Override
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 {
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) {
Rectangle r = getBounds();
int hlines = r.height / 10;
......@@ -134,12 +148,16 @@ class ArcCanvas extends Canvas {
}
}
@SuppressWarnings("serial")
class ArcControls extends Panel
implements ActionListener {
implements ActionListener {
TextField startTF;
TextField extentTF;
ArcCanvas canvas;
@SuppressWarnings("LeakingThisInConstructor")
public ArcControls(ArcCanvas canvas) {
Button b = null;
......@@ -154,18 +172,19 @@ class ArcControls extends Panel
add(b);
}
@Override
public void actionPerformed(ActionEvent ev) {
String label = ev.getActionCommand();
int start, extent;
try {
start = Integer.parseInt(startTF.getText().trim());
} catch (NumberFormatException nfe) {
} catch (NumberFormatException ignored) {
start = 0;
}
try {
extent = Integer.parseInt(extentTF.getText().trim());
} catch (NumberFormatException nfe) {
} catch (NumberFormatException ignored) {
extent = 0;
}
......@@ -173,6 +192,8 @@ class ArcControls extends Panel
}
}
@SuppressWarnings("serial")
class IntegerTextField extends TextField {
String oldText = null;
......@@ -188,6 +209,7 @@ class IntegerTextField extends TextField {
// function, but this is neater, since ideally, it would prevent
// the text from appearing at all. Sigh. See bugid 4100317/4114565.
//
@Override
protected void processEvent(AWTEvent evt) {
int id = evt.getID();
if (id != KeyEvent.KEY_TYPED) {
......@@ -200,8 +222,8 @@ class IntegerTextField extends TextField {
// Digits, backspace, and delete are okay
// Note that the minus sign is allowed, but not the decimal
if (Character.isDigit(c) || (c == '\b') || (c == '\u007f') ||
(c == '\u002d')) {
if (Character.isDigit(c) || (c == '\b') || (c == '\u007f') || (c
== '\u002d')) {
super.processEvent(evt);
return;
}
......@@ -215,6 +237,7 @@ class IntegerTextField extends TextField {
// so we can revert to it on a TextEvent (paste, or
// legal key in the wrong location) with bad text
//
@Override
protected void processTextEvent(TextEvent te) {
// The empty string is okay, too
String newText = getText();
......@@ -233,12 +256,11 @@ class IntegerTextField extends TextField {
// Note that the empty string is not allowed.
//
private boolean textIsInteger(String textToCheck) {
int value = -1;
try {
value = Integer.parseInt(textToCheck, 10);
Integer.parseInt(textToCheck, 10);
return true;
} catch (NumberFormatException nfe) {
} catch (NumberFormatException ignored) {
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
* modification, are permitted provided that the following conditions
......@@ -29,28 +29,26 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.awt.*;
/**
* A simple bar chart demo
* @author Sami Shaio
* @modified 06/21/00 Daniel Peek : refactored, comments
*/
@SuppressWarnings("serial")
public class BarChart extends java.applet.Applet {
private static final int VERTICAL = 0;
private static final int HORIZONTAL = 1;
private static final int SOLID = 0;
private static final int STRIPED = 1;
private int orientation;
private String title;
private Font font;
private FontMetrics metrics;
private int fontHeight = 15;
private int columns;
private int values[];
private Color colors[];
......@@ -61,6 +59,7 @@ public class BarChart extends java.applet.Applet {
private int barSpacing = 10;
private int maxValue = 0;
@Override
public void init() {
getSettings();
......@@ -70,7 +69,7 @@ public class BarChart extends java.applet.Applet {
styles = new int[columns];
colors = new Color[columns];
for (int i=0; i < columns; i++) {
for (int i = 0; i < columns; i++) {
parseValue(i);
parseLabel(i);
parseStyle(i);
......@@ -112,7 +111,7 @@ public class BarChart extends java.applet.Applet {
}
private void parseValue(int i) {
String temp = getParameter("C" + (i+1));
String temp = getParameter("C" + (i + 1));
try {
values[i] = Integer.parseInt(temp);
} catch (NumberFormatException e) {
......@@ -124,18 +123,17 @@ public class BarChart extends java.applet.Applet {
}
private void parseLabel(int i) {
String temp = getParameter("C" + (i+1) + "_label");
if (temp==null) {
String temp = getParameter("C" + (i + 1) + "_label");
if (temp == null) {
labels[i] = "";
} else {
labels[i] = temp;
}
maxLabelWidth = Math.max(metrics.stringWidth
((String) (labels[i])), maxLabelWidth);
maxLabelWidth = Math.max(metrics.stringWidth(labels[i]), maxLabelWidth);
}
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")) {
styles[i] = SOLID;
} else if (temp.equalsIgnoreCase("striped")) {
......@@ -146,7 +144,7 @@ public class BarChart extends java.applet.Applet {
}
private void parseColor(int i) {
String temp = getParameter("C" + (i+1) + "_color");
String temp = getParameter("C" + (i + 1) + "_color");
if (temp != null) {
temp = temp.toLowerCase();
if (temp.equals("red")) {
......@@ -179,6 +177,7 @@ public class BarChart extends java.applet.Applet {
}
}
@Override
public void paint(Graphics g) {
// draw the title centered at the bottom of the bar graph
g.setColor(Color.black);
......@@ -192,7 +191,7 @@ public class BarChart extends java.applet.Applet {
g.drawString(title, cx, cy);
// draw the bars and their titles
if(orientation == HORIZONTAL) {
if (orientation == HORIZONTAL) {
paintHorizontal(g);
} else { // VERTICAL
paintVertical(g);
......@@ -208,12 +207,13 @@ public class BarChart extends java.applet.Applet {
// set the X coordinate for this bar and label and center it
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);
// set the Y coordinate for this bar and label
cy = getSize().height - metrics.getDescent() - metrics.getHeight()
- barSpacing - ((columns - i - 1) * (barSpacing + barHeight));
- barSpacing
- ((columns - i - 1) * (barSpacing + barHeight));
// draw the label
g.setColor(Color.black);
......@@ -223,7 +223,7 @@ public class BarChart extends java.applet.Applet {
// draw the shadow
g.fillRect(cx + 4, cy - barHeight + 4,
(values[i] * scale), barHeight);
(values[i] * scale), barHeight);
// draw the bar
g.setColor(colors[i]);
......@@ -233,7 +233,7 @@ public class BarChart extends java.applet.Applet {
}
} else { // SOLID
g.fillRect(cx, cy - barHeight,
(values[i] * scale) + 1, barHeight + 1);
(values[i] * scale) + 1, barHeight + 1);
}
cx += (values[i] * scale) + 4;
......@@ -255,7 +255,7 @@ public class BarChart extends java.applet.Applet {
// Y coordinate for this label and bar
int cy = getSize().height - metrics.getHeight()
- metrics.getDescent() - 4;
- metrics.getDescent() - 4;
// draw the label
g.setColor(Color.black);
......@@ -264,18 +264,18 @@ public class BarChart extends java.applet.Applet {
// draw the shadow
g.fillRect(cx + 4, cy - (values[i] * scale) - 4,
barWidth, (values[i] * scale));
barWidth, (values[i] * scale));
// draw the bar
g.setColor(colors[i]);
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,
cx + barWidth, cy - k);
cx + barWidth, cy - k);
}
} else {
g.fillRect(cx, cy - (values[i] * scale),
barWidth + 1, (values[i] * scale) + 1);
barWidth + 1, (values[i] * scale) + 1);
}
cy -= (values[i] * scale) + 5;
......@@ -285,28 +285,30 @@ public class BarChart extends java.applet.Applet {
}
}
@Override
public String getAppletInfo() {
return "Title: Bar Chart \n"
+ "Author: Sami Shaio \n"
+ "A simple bar chart demo.";
+ "Author: Sami Shaio \n"
+ "A simple bar chart demo.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{"title", "string", "The title of bar graph. Default is 'Chart'"},
{"scale", "int", "The scale of the bar graph. Default is 10."},
{"columns", "int", "The number of columns/rows. Default is 5."},
{"orientation", "{VERTICAL, HORIZONTAL}",
"The orienation of the bar graph. Default is VERTICAL."},
{"c#", "int", "Subsitute a number for #. "
+ "The value/size of bar #. Default is 0."},
{"c#_label", "string", "The label for bar #. "
+ "Default is an empty label."},
{"c#_style", "{SOLID, STRIPED}", "The style of bar #. "
+ "Default is SOLID."},
{"c#_color", "{RED, GREEN, BLUE, PINK, ORANGE, MAGENTA, CYAN, "
+ "WHITE, YELLOW, GRAY, DARKGRAY}",
"The color of bar #. Default is GRAY."}
{ "title", "string", "The title of bar graph. Default is 'Chart'" },
{ "scale", "int", "The scale of the bar graph. Default is 10." },
{ "columns", "int", "The number of columns/rows. Default is 5." },
{ "orientation", "{VERTICAL, HORIZONTAL}",
"The orienation of the bar graph. Default is VERTICAL." },
{ "c#", "int", "Subsitute a number for #. "
+ "The value/size of bar #. Default is 0." },
{ "c#_label", "string", "The label for bar #. "
+ "Default is an empty label." },
{ "c#_style", "{SOLID, STRIPED}", "The style of bar #. "
+ "Default is SOLID." },
{ "c#_color", "{RED, GREEN, BLUE, PINK, ORANGE, MAGENTA, CYAN, "
+ "WHITE, YELLOW, GRAY, DARKGRAY}",
"The color of bar #. Default is GRAY." }
};
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
* modification, are permitted provided that the following conditions
......@@ -29,92 +29,106 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
/**
* I love blinking things.
*
* @author Arthur van Hoff
* @modified 04/24/96 Jim Hagen use getBackground
* @modified 02/05/98 Mike McCloskey removed use of deprecated methods
* @modified 04/23/99 Josh Bloch, use timer instead of explicit multithreading.
* @modified 07/10/00 Daniel Peek brought to code conventions, minor changes
* @author 04/24/96 Jim Hagen use getBackground
* @author 02/05/98 Mike McCloskey removed use of deprecated methods
* @author 04/23/99 Josh Bloch, use timer instead of explicit multithreading.
* @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 {
private static final long serialVersionUID = -775844794477507646L;
private Timer timer; // Schedules the blinking
private String labelString; // The label for the window
private int delay; // the delay time between blinks
@Override
public void init() {
String blinkFrequency = getParameter("speed");
delay = (blinkFrequency == null) ? 400 :
(1000 / Integer.parseInt(blinkFrequency));
delay = (blinkFrequency == null) ? 400
: (1000 / Integer.parseInt(blinkFrequency));
labelString = getParameter("lbl");
if (labelString == null)
if (labelString == null) {
labelString = "Blink";
}
Font font = new java.awt.Font("Serif", Font.PLAIN, 24);
setFont(font);
}
@Override
public void start() {
timer = new Timer(); //creates a new timer to schedule the blinking
timer.schedule(new TimerTask() { //creates a timertask to schedule
// overrides the run method to provide functionality
@Override
public void run() {
repaint();
}
}
, delay, delay);
}, delay, delay);
}
@Override
public void paint(Graphics g) {
int fontSize = g.getFont().getSize();
int x = 0, y = fontSize, space;
int red = (int) ( 50 * Math.random());
int green = (int) ( 50 * Math.random());
int blue = (int) (256 * Math.random());
int red = (int) (50 * Math.random());
int green = (int) (50 * Math.random());
int blue = (int) (256 * Math.random());
Dimension d = getSize();
g.setColor(Color.black);
FontMetrics fm = g.getFontMetrics();
space = fm.stringWidth(" ");
for (StringTokenizer t = new StringTokenizer(labelString);
t.hasMoreTokens();) {
t.hasMoreTokens();) {
String word = t.nextToken();
int w = fm.stringWidth(word) + space;
if (x + w > d.width) {
x = 0;
y += fontSize; //move word to next line if it doesn't fit
}
if (Math.random() < 0.5)
g.setColor(new java.awt.Color((red + y*30) % 256,
(green + x/3) % 256, blue));
else
if (Math.random() < 0.5) {
g.setColor(new java.awt.Color((red + y * 30) % 256,
(green + x / 3) % 256, blue));
} else {
g.setColor(getBackground());
}
g.drawString(word, x, y);
x += w; //shift to the right to draw the next word
}
}
@Override
public void stop() {
timer.cancel(); //stops the timer
}
@Override
public String getAppletInfo() {
return "Title: Blinker\n"
+ "Author: Arthur van Hoff\n"
+ "Displays multicolored blinking text.";
+ "Author: Arthur van Hoff\n"
+ "Displays multicolored blinking text.";
}
@Override
public String[][] getParameterInfo() {
String pinfo[][] = {
{"speed", "string", "The blink frequency"},
{"lbl", "string", "The text to blink."},
};
{ "speed", "string", "The blink frequency" },
{ "lbl", "string", "The text to blink." }, };
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
* modification, are permitted provided that the following conditions
......@@ -29,14 +29,27 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.awt.*;
import java.awt.event.*;
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;
Panel create(LayoutManager layout) {
......@@ -83,16 +96,21 @@ class CardPanel extends Panel {
add("six", create(new GridLayout(2, 2, 10, 10)));
}
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 100);
}
}
@SuppressWarnings("serial")
public class CardTest extends Applet
implements ActionListener,
ItemListener {
implements ActionListener,
ItemListener {
CardPanel cards;
@SuppressWarnings("LeakingThisInConstructor")
public CardTest() {
setLayout(new BorderLayout());
add("Center", cards = new CardPanel(this));
......@@ -127,24 +145,26 @@ public class CardTest extends Applet
p.add(c);
}
@Override
public void itemStateChanged(ItemEvent e) {
((CardLayout)cards.getLayout()).show(cards,
(String)(e.getItem()));
((CardLayout) cards.getLayout()).show(cards,
(String) (e.getItem()));
}
@Override
public void actionPerformed(ActionEvent e) {
String arg = e.getActionCommand();
if ("first".equals(arg)) {
((CardLayout)cards.getLayout()).first(cards);
((CardLayout) cards.getLayout()).first(cards);
} else if ("next".equals(arg)) {
((CardLayout)cards.getLayout()).next(cards);
((CardLayout) cards.getLayout()).next(cards);
} else if ("previous".equals(arg)) {
((CardLayout)cards.getLayout()).previous(cards);
((CardLayout) cards.getLayout()).previous(cards);
} else if ("last".equals(arg)) {
((CardLayout)cards.getLayout()).last(cards);
((CardLayout) cards.getLayout()).last(cards);
} else {
((CardLayout)cards.getLayout()).show(cards,(String)arg);
((CardLayout) cards.getLayout()).show(cards, arg);
}
}
......@@ -156,9 +176,10 @@ public class CardTest extends Applet
f.add("Center", cardTest);
f.setSize(300, 300);
f.show();
f.setVisible(true);
}
@Override
public String getAppletInfo() {
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
* modification, are permitted provided that the following conditions
......@@ -29,24 +29,28 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.util.*;
import java.awt.*;
import java.applet.*;
import java.text.*;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
/**
* Time!
*
* @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 {
private volatile Thread timer; // The thread that displays clock
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 String lastdate; // String to hold date displayed
private Font clockFaceFont; // Font for number display on clock
......@@ -55,11 +59,11 @@ public class Clock extends Applet implements Runnable {
private Color numberColor; // Color of second hand and numbers
private int xcenter = 80, ycenter = 55; // Center position
@Override
public void init() {
int x,y;
lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;
formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy",
Locale.getDefault());
formatter = new SimpleDateFormat("EEE MMM dd hh:mm:ss yyyy",
Locale.getDefault());
currentDate = new Date();
lastdate = formatter.format(currentDate);
clockFaceFont = new Font("Serif", Font.PLAIN, 14);
......@@ -68,26 +72,29 @@ public class Clock extends Applet implements Runnable {
try {
setBackground(new Color(Integer.parseInt(getParameter("bgcolor"),
16)));
16)));
} catch (NullPointerException e) {
} catch (NumberFormatException e) {
}
try {
handColor = new Color(Integer.parseInt(getParameter("fgcolor1"),
16));
16));
} catch (NullPointerException e) {
} catch (NumberFormatException e) {
}
try {
numberColor = new Color(Integer.parseInt(getParameter("fgcolor2"),
16));
16));
} catch (NullPointerException 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) {
int xh, yh, xm, ym, xs, ys;
int s = 0, m = 10, h = 10;
......@@ -119,10 +126,12 @@ public class Clock extends Applet implements Runnable {
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);
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
+ xcenter);
yh = (int) (Math.sin((h*30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30
+ ycenter);
xh = (int) (Math.cos((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2)
* 30
+ xcenter);
yh = (int) (Math.sin((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2)
* 30
+ ycenter);
// Get the date to print at the bottom
formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy");
......@@ -136,12 +145,12 @@ public class Clock extends Applet implements Runnable {
g.drawString(lastdate, 5, 125);
}
if (xm != lastxm || ym != lastym) {
g.drawLine(xcenter, ycenter-1, lastxm, lastym);
g.drawLine(xcenter-1, ycenter, lastxm, lastym);
g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
}
if (xh != lastxh || yh != lastyh) {
g.drawLine(xcenter, ycenter-1, lastxh, lastyh);
g.drawLine(xcenter-1, ycenter, lastxh, lastyh);
g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
}
// Draw date and hands
......@@ -149,73 +158,83 @@ public class Clock extends Applet implements Runnable {
g.drawString(today, 5, 125);
g.drawLine(xcenter, ycenter, xs, ys);
g.setColor(handColor);
g.drawLine(xcenter, ycenter-1, xm, ym);
g.drawLine(xcenter-1, ycenter, xm, ym);
g.drawLine(xcenter, ycenter-1, xh, yh);
g.drawLine(xcenter-1, ycenter, xh, yh);
lastxs = xs; lastys = ys;
lastxm = xm; lastym = ym;
lastxh = xh; lastyh = yh;
g.drawLine(xcenter, ycenter - 1, xm, ym);
g.drawLine(xcenter - 1, ycenter, xm, ym);
g.drawLine(xcenter, ycenter - 1, xh, yh);
g.drawLine(xcenter - 1, ycenter, xh, yh);
lastxs = xs;
lastys = ys;
lastxm = xm;
lastym = ym;
lastxh = xh;
lastyh = yh;
lastdate = today;
currentDate = null;
}
@Override
public void paint(Graphics g) {
g.setFont(clockFaceFont);
// Draw the circle and numbers
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.drawString("9", xcenter-45, ycenter+3);
g.drawString("3", xcenter+40, ycenter+3);
g.drawString("12", xcenter-5, ycenter-37);
g.drawString("6", xcenter-3, ycenter+45);
g.drawString("9", xcenter - 45, ycenter + 3);
g.drawString("3", xcenter + 40, ycenter + 3);
g.drawString("12", xcenter - 5, ycenter - 37);
g.drawString("6", xcenter - 3, ycenter + 45);
// Draw date and hands
g.setColor(numberColor);
g.drawString(lastdate, 5, 125);
g.drawLine(xcenter, ycenter, lastxs, lastys);
g.setColor(handColor);
g.drawLine(xcenter, ycenter-1, lastxm, lastym);
g.drawLine(xcenter-1, ycenter, lastxm, lastym);
g.drawLine(xcenter, ycenter-1, lastxh, lastyh);
g.drawLine(xcenter-1, ycenter, lastxh, lastyh);
g.drawLine(xcenter, ycenter - 1, lastxm, lastym);
g.drawLine(xcenter - 1, ycenter, lastxm, lastym);
g.drawLine(xcenter, ycenter - 1, lastxh, lastyh);
g.drawLine(xcenter - 1, ycenter, lastxh, lastyh);
}
@Override
public void start() {
timer = new Thread(this);
timer.start();
}
@Override
public void stop() {
timer = null;
}
@Override
@SuppressWarnings("SleepWhileHoldingLock")
public void run() {
Thread me = Thread.currentThread();
while (timer == me) {
try {
Thread.currentThread().sleep(100);
Thread.sleep(100);
} catch (InterruptedException e) {
}
repaint();
}
}
@Override
public String getAppletInfo() {
return "Title: A Clock \n"
+ "Author: Rachel Gollub, 1995 \n"
+ "An analog clock.";
+ "Author: Rachel Gollub, 1995 \n"
+ "An analog clock.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{"bgcolor", "hexadecimal RGB number",
"The background color. Default is the color of your browser."},
{"fgcolor1", "hexadecimal RGB number",
"The color of the hands and dial. Default is blue."},
{"fgcolor2", "hexadecimal RGB number",
"The color of the second hand and numbers. Default is dark gray."}
{ "bgcolor", "hexadecimal RGB number",
"The background color. Default is the color of your browser." },
{ "fgcolor1", "hexadecimal RGB number",
"The color of the hands and dial. Default is blue." },
{ "fgcolor2", "hexadecimal RGB number",
"The color of the second hand and numbers. Default is dark gray." }
};
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
* modification, are permitted provided that the following conditions
......@@ -29,25 +29,43 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;
import java.awt.AWTEvent;
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.MemoryImageSource;
enum DitherMethod {
NOOP, RED, GREEN, BLUE, ALPHA, SATURATION
};
@SuppressWarnings("serial")
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 DitherControls XControls;
private DitherControls YControls;
private DitherCanvas canvas;
......@@ -62,6 +80,7 @@ public class DitherTest extends Applet implements Runnable {
ditherTest.start();
}
@Override
public void init() {
String xspec = null, yspec = null;
int xvals[] = new int[2];
......@@ -70,7 +89,7 @@ public class DitherTest extends Applet implements Runnable {
try {
xspec = getParameter("xaxis");
yspec = getParameter("yaxis");
} catch (NullPointerException npe) {
} catch (NullPointerException ignored) {
//only occurs if run as application
}
......@@ -80,44 +99,34 @@ public class DitherTest extends Applet implements Runnable {
if (yspec == null) {
yspec = "blue";
}
int xmethod = colormethod(xspec, xvals);
int ymethod = colormethod(yspec, yvals);
DitherMethod xmethod = colorMethod(xspec, xvals);
DitherMethod ymethod = colorMethod(yspec, yvals);
setLayout(new BorderLayout());
XControls = new DitherControls(this, xvals[0], xvals[1],
xmethod, false);
xmethod, false);
YControls = new DitherControls(this, yvals[0], yvals[1],
ymethod, true);
ymethod, true);
YControls.addRenderButton();
add("North", XControls);
add("South", YControls);
add("Center", canvas = new DitherCanvas());
}
private int colormethod(String s, int vals[]) {
int method = NOOP;
private DitherMethod colorMethod(String s, int vals[]) {
DitherMethod method = DitherMethod.NOOP;
if (s == null) {
s = "";
}
String lower = s.toLowerCase();
int len = 0;
if (lower.startsWith("red")) {
method = RED;
lower = lower.substring(3);
} else if (lower.startsWith("green")) {
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);
for (DitherMethod m : DitherMethod.values()) {
if (lower.startsWith(m.toString().toLowerCase())) {
method = m;
lower = lower.substring(m.toString().length());
}
}
if (method == NOOP) {
if (method == DitherMethod.NOOP) {
vals[0] = 0;
vals[1] = 0;
return method;
......@@ -132,7 +141,7 @@ public class DitherTest extends Applet implements Runnable {
begval = Integer.parseInt(lower.substring(0, dash));
endval = Integer.parseInt(lower.substring(dash + 1));
}
} catch (NumberFormatException nfe) {
} catch (NumberFormatException ignored) {
}
if (begval < 0) {
......@@ -173,16 +182,14 @@ public class DitherTest extends Applet implements Runnable {
c[0] = c[1] = c[2] = 0;
c[3] = 255;
if (xmethod < ymethod) {
applymethod(c, xmethod, i, width, xvals);
applymethod(c, ymethod, j, height, yvals);
applyMethod(c, xmethod, i, width, xvals);
applyMethod(c, ymethod, j, height, yvals);
} else {
applymethod(c, ymethod, j, height, yvals);
applymethod(c, xmethod, i, width, xvals);
applyMethod(c, ymethod, j, height, yvals);
applyMethod(c, xmethod, i, width, xvals);
}
pixels[index++] = ((c[3] << 24) |
(c[0] << 16) |
(c[1] << 8) |
c[2]);
pixels[index++] = ((c[3] << 24) | (c[0] << 16) | (c[1] << 8)
| c[2]);
}
// Poll once per row to see if we've been told to stop.
......@@ -191,51 +198,54 @@ public class DitherTest extends Applet implements Runnable {
}
}
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,
int total, int vals[]) {
if (method == NOOP) {
private void applyMethod(int c[], int methodIndex, int step,
int total, int vals[]) {
DitherMethod method = DitherMethod.values()[methodIndex];
if (method == DitherMethod.NOOP) {
return;
}
int val = ((total < 2)
? vals[0]
: vals[0] + ((vals[1] - vals[0]) * step / (total - 1)));
? vals[0]
: vals[0] + ((vals[1] - vals[0]) * step / (total - 1)));
switch (method) {
case RED:
c[0] = val;
break;
case GREEN:
c[1] = val;
break;
case BLUE:
c[2] = val;
break;
case ALPHA:
c[3] = val;
break;
case SATURATION:
int max = Math.max(Math.max(c[0], c[1]), c[2]);
int min = max * (255 - val) / 255;
if (c[0] == 0) {
c[0] = min;
}
if (c[1] == 0) {
c[1] = min;
}
if (c[2] == 0) {
c[2] = min;
}
break;
case RED:
c[0] = val;
break;
case GREEN:
c[1] = val;
break;
case BLUE:
c[2] = val;
break;
case ALPHA:
c[3] = val;
break;
case SATURATION:
int max = Math.max(Math.max(c[0], c[1]), c[2]);
int min = max * (255 - val) / 255;
if (c[0] == 0) {
c[0] = min;
}
if (c[1] == 0) {
c[1] = min;
}
if (c[2] == 0) {
c[2] = min;
}
break;
}
}
@Override
public void start() {
runner = new Thread(this);
runner.start();
}
@Override
public void run() {
canvas.setImage(null); // Wipe previous image
Image img = calculateImage();
......@@ -244,35 +254,43 @@ public class DitherTest extends Applet implements Runnable {
}
}
@Override
public void stop() {
runner = null;
}
@Override
public void destroy() {
remove(XControls);
remove(YControls);
remove(canvas);
}
@Override
public String getAppletInfo() {
return "An interactive demonstration of dithering.";
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{"xaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}",
"The color of the Y axis. Default is RED."},
{"yaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}",
"The color of the X axis. Default is BLUE."}
{ "xaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}",
"The color of the Y axis. Default is RED." },
{ "yaxis", "{RED, GREEN, BLUE, ALPHA, SATURATION}",
"The color of the X axis. Default is BLUE." }
};
return info;
}
}
@SuppressWarnings("serial")
class DitherCanvas extends Canvas {
private Image img;
private static String calcString = "Calculating...";
@Override
public void paint(Graphics g) {
int w = getSize().width;
int h = getSize().height;
......@@ -288,14 +306,17 @@ class DitherCanvas extends Canvas {
}
}
@Override
public void update(Graphics g) {
paint(g);
}
@Override
public Dimension getMinimumSize() {
return new Dimension(20, 20);
}
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 200);
}
......@@ -310,29 +331,29 @@ class DitherCanvas extends Canvas {
}
}
@SuppressWarnings("serial")
class DitherControls extends Panel implements ActionListener {
private CardinalTextField start;
private CardinalTextField end;
private Button button;
private Choice choice;
private DitherTest applet;
private static LayoutManager dcLayout = new FlowLayout(FlowLayout.CENTER,
10, 5);
10, 5);
public DitherControls(DitherTest app, int s, int e, int type,
boolean vertical) {
public DitherControls(DitherTest app, int s, int e, DitherMethod type,
boolean vertical) {
applet = app;
setLayout(dcLayout);
add(new Label(vertical ? "Vertical" : "Horizontal"));
add(choice = new Choice());
choice.addItem("Noop");
choice.addItem("Red");
choice.addItem("Green");
choice.addItem("Blue");
choice.addItem("Alpha");
choice.addItem("Saturation");
choice.select(type);
for (DitherMethod m : DitherMethod.values()) {
choice.addItem(m.toString().substring(0, 1)
+ m.toString().substring(1).toLowerCase());
}
choice.select(type.ordinal());
add(start = new CardinalTextField(Integer.toString(s), 4));
add(end = new CardinalTextField(Integer.toString(e), 4));
}
......@@ -369,6 +390,7 @@ class DitherControls extends Panel implements ActionListener {
}
/* called when user clicks the button */
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button) {
applet.start();
......@@ -376,6 +398,8 @@ class DitherControls extends Panel implements ActionListener {
}
}
@SuppressWarnings("serial")
class CardinalTextField extends TextField {
String oldText = null;
......@@ -391,6 +415,7 @@ class CardinalTextField extends TextField {
// function, but this is neater, since ideally, it would prevent
// the text from appearing at all. Sigh. See bugid 4100317/4114565.
//
@Override
protected void processEvent(AWTEvent evt) {
int id = evt.getID();
if (id != KeyEvent.KEY_TYPED) {
......@@ -420,6 +445,7 @@ class CardinalTextField extends TextField {
// Note: it would be easy to extend this to an eight-bit
// TextField (range 0-255), but I'll leave it as-is.
//
@Override
protected void processTextEvent(TextEvent te) {
// The empty string is okay, too
String newText = getText();
......@@ -436,11 +462,8 @@ class CardinalTextField extends TextField {
// Returns true for Cardinal (non-negative) numbers
// Note that the empty string is not allowed
private boolean textIsCardinal(String textToCheck) {
int value = -1;
try {
value = Integer.parseInt(textToCheck, 10);
return (value >= 0);
return Integer.parseInt(textToCheck, 10) >= 0;
} catch (NumberFormatException nfe) {
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
* modification, are permitted provided that the following conditions
......@@ -29,27 +29,46 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.applet.Applet;
import java.awt.BorderLayout;
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;
DrawControls controls;
@Override
public void init() {
setLayout(new BorderLayout());
panel = new DrawPanel();
controls = new DrawControls(panel);
add("Center", panel);
add("South",controls);
add("South", controls);
}
@Override
public void destroy() {
remove(panel);
remove(controls);
......@@ -63,22 +82,28 @@ public class DrawTest extends Applet{
f.add("Center", drawTest);
f.setSize(300, 300);
f.show();
f.setVisible(true);
}
@Override
public String getAppletInfo() {
return "A simple drawing program.";
}
}
@SuppressWarnings("serial")
class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
public static final int LINES = 0;
public static final int POINTS = 1;
int mode = LINES;
Vector lines = new Vector();
Vector colors = new Vector();
int x1,y1;
int x2,y2;
int mode = LINES;
List<Rectangle> lines = new ArrayList<Rectangle>();
List<Color> colors = new ArrayList<Color>();
int x1, y1;
int x2, y2;
@SuppressWarnings("LeakingThisInConstructor")
public DrawPanel() {
setBackground(Color.white);
addMouseMotionListener(this);
......@@ -87,16 +112,16 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
public void setDrawMode(int mode) {
switch (mode) {
case LINES:
case POINTS:
this.mode = mode;
break;
default:
throw new IllegalArgumentException();
case LINES:
case POINTS:
this.mode = mode;
break;
default:
throw new IllegalArgumentException();
}
}
@Override
public void mouseDragged(MouseEvent e) {
e.consume();
switch (mode) {
......@@ -106,8 +131,8 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
break;
case POINTS:
default:
colors.addElement(getForeground());
lines.addElement(new Rectangle(x1, y1, e.getX(), e.getY()));
colors.add(getForeground());
lines.add(new Rectangle(x1, y1, e.getX(), e.getY()));
x1 = e.getX();
y1 = e.getY();
break;
......@@ -115,9 +140,11 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
repaint();
}
@Override
public void mouseMoved(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
e.consume();
switch (mode) {
......@@ -128,8 +155,8 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
break;
case POINTS:
default:
colors.addElement(getForeground());
lines.addElement(new Rectangle(e.getX(), e.getY(), -1, -1));
colors.add(getForeground());
lines.add(new Rectangle(e.getX(), e.getY(), -1, -1));
x1 = e.getX();
y1 = e.getY();
repaint();
......@@ -137,12 +164,13 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
}
}
@Override
public void mouseReleased(MouseEvent e) {
e.consume();
switch (mode) {
case LINES:
colors.addElement(getForeground());
lines.addElement(new Rectangle(x1, y1, e.getX(), e.getY()));
colors.add(getForeground());
lines.add(new Rectangle(x1, y1, e.getX(), e.getY()));
x2 = -1;
break;
case POINTS:
......@@ -152,23 +180,27 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
repaint();
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void paint(Graphics g) {
int np = lines.size();
/* draw the current lines */
g.setColor(getForeground());
for (int i=0; i < np; i++) {
Rectangle p = (Rectangle)lines.elementAt(i);
g.setColor((Color)colors.elementAt(i));
for (int i = 0; i < np; i++) {
Rectangle p = lines.get(i);
g.setColor(colors.get(i));
if (p.width != -1) {
g.drawLine(p.x, p.y, p.width, p.height);
} else {
......@@ -185,9 +217,12 @@ class DrawPanel extends Panel implements MouseListener, MouseMotionListener {
}
@SuppressWarnings("serial")
class DrawControls extends Panel implements ItemListener {
DrawPanel target;
@SuppressWarnings("LeakingThisInConstructor")
public DrawControls(DrawPanel target) {
this.target = target;
setLayout(new FlowLayout());
......@@ -222,33 +257,35 @@ class DrawControls extends Panel implements ItemListener {
add(shapes);
}
@Override
public void paint(Graphics g) {
Rectangle r = getBounds();
g.setColor(Color.lightGray);
g.draw3DRect(0, 0, r.width, r.height, false);
int n = getComponentCount();
for(int i=0; i<n; i++) {
for (int i = 0; i < n; i++) {
Component comp = getComponent(i);
if (comp instanceof Checkbox) {
Point loc = comp.getLocation();
Dimension d = comp.getSize();
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) {
if (e.getSource() instanceof Checkbox) {
target.setForeground(((Component)e.getSource()).getForeground());
} else if (e.getSource() instanceof Choice) {
String choice = (String) e.getItem();
if (choice.equals("Lines")) {
target.setDrawMode(DrawPanel.LINES);
} else if (choice.equals("Points")) {
target.setDrawMode(DrawPanel.POINTS);
}
@Override
public void itemStateChanged(ItemEvent e) {
if (e.getSource() instanceof Checkbox) {
target.setForeground(((Component) e.getSource()).getForeground());
} else if (e.getSource() instanceof Choice) {
String choice = (String) e.getItem();
if (choice.equals("Lines")) {
target.setDrawMode(DrawPanel.LINES);
} 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
* modification, are permitted provided that the following conditions
......@@ -29,13 +29,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.awt.Graphics;
import java.util.Stack;
import java.util.Vector;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;
/**
* A (not-yet) Context sensitive L-System Fractal applet class.
......@@ -50,9 +50,11 @@ import java.awt.event.*;
*
* @author Jim Graham
*/
@SuppressWarnings("serial")
public class CLSFractal
extends java.applet.Applet
implements Runnable, MouseListener {
extends java.applet.Applet
implements Runnable, MouseListener {
Thread kicker;
ContextLSystem cls;
int fractLevel = 1;
......@@ -67,31 +69,48 @@ public class CLSFractal
int border;
boolean normalizescaling;
@Override
public void init() {
String s;
cls = new ContextLSystem(this);
s = getParameter("level");
if (s != null) fractLevel = Integer.parseInt(s);
if (s != null) {
fractLevel = Integer.parseInt(s);
}
s = getParameter("incremental");
if (s != null) incrementalUpdates = s.equalsIgnoreCase("true");
if (s != null) {
incrementalUpdates = s.equalsIgnoreCase("true");
}
s = getParameter("delay");
if (s != null) repaintDelay = Integer.parseInt(s);
if (s != null) {
repaintDelay = Integer.parseInt(s);
}
s = getParameter("startAngle");
if (s != null) startAngle = Float.valueOf(s).floatValue();
if (s != null) {
startAngle = Float.valueOf(s).floatValue();
}
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;
s = getParameter("border");
if (s != null) border = Integer.parseInt(s);
if (s != null) {
border = Integer.parseInt(s);
}
s = getParameter("normalizescale");
if (s != null) normalizescaling = s.equalsIgnoreCase("true");
if (s != null) {
normalizescaling = s.equalsIgnoreCase("true");
}
addMouseListener(this);
}
@Override
public void destroy() {
removeMouseListener(this);
}
@Override
public void run() {
Thread me = Thread.currentThread();
boolean needsRepaint = false;
......@@ -99,7 +118,10 @@ public class CLSFractal
cls.generate();
if (kicker == me && incrementalUpdates) {
repaint();
try {Thread.sleep(repaintDelay);} catch (InterruptedException e){}
try {
Thread.sleep(repaintDelay);
} catch (InterruptedException ignored) {
}
} else {
needsRepaint = true;
}
......@@ -112,22 +134,27 @@ public class CLSFractal
}
}
@Override
public void start() {
kicker = new Thread(this);
kicker.start();
}
@Override
public void stop() {
kicker = null;
}
/*1.1 event handling */
/*1.1 event handling */
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
cls = new ContextLSystem(this);
savedPath = null;
......@@ -135,14 +162,16 @@ public class CLSFractal
e.consume();
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
String savedPath;
@Override
public void paint(Graphics g) {
String fractalPath = cls.getPath();
if (fractalPath == null) {
......@@ -155,13 +184,14 @@ public class CLSFractal
}
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);
}
void render(Graphics g, String path) {
Stack turtleStack = new Stack();
Stack<CLSTurtle> turtleStack = new Stack<CLSTurtle>();
CLSTurtle turtle;
if (g == null) {
......@@ -172,11 +202,13 @@ public class CLSFractal
turtle = new CLSTurtle(startAngle, 0, 0, 0, 0, 1, 1);
} else {
float frwidth = Xmax - Xmin;
if (frwidth == 0)
if (frwidth == 0) {
frwidth = 1;
}
float frheight = Ymax - Ymin;
if (frheight == 0)
if (frheight == 0) {
frheight = 1;
}
float xscale = (getSize().width - border * 2 - 1) / frwidth;
float yscale = (getSize().height - border * 2 - 1) / frheight;
int xoff = border;
......@@ -184,84 +216,102 @@ public class CLSFractal
if (normalizescaling) {
if (xscale < yscale) {
yoff += ((getSize().height - border * 2)
- ((Ymax - Ymin) * xscale)) / 2;
- ((Ymax - Ymin) * xscale)) / 2;
yscale = xscale;
} else if (yscale < xscale) {
xoff += ((getSize().width - border * 2)
- ((Xmax - Xmin) * yscale)) / 2;
- ((Xmax - Xmin) * yscale)) / 2;
xscale = yscale;
}
}
turtle = new CLSTurtle(startAngle, 0 - Xmin, 0 - Ymin,
xoff, yoff, xscale, yscale);
xoff, yoff, xscale, yscale);
}
for (int pos = 0; pos < path.length(); pos++) {
switch (path.charAt(pos)) {
case '+':
turtle.rotate(rotAngle);
break;
case '-':
turtle.rotate(-rotAngle);
break;
case '[':
turtleStack.push(turtle);
turtle = new CLSTurtle(turtle);
break;
case ']':
turtle = (CLSTurtle) turtleStack.pop();
break;
case 'f':
turtle.jump();
break;
case 'F':
if (g == null) {
includePt(turtle.X, turtle.Y);
case '+':
turtle.rotate(rotAngle);
break;
case '-':
turtle.rotate(-rotAngle);
break;
case '[':
turtleStack.push(turtle);
turtle = new CLSTurtle(turtle);
break;
case ']':
turtle = turtleStack.pop();
break;
case 'f':
turtle.jump();
includePt(turtle.X, turtle.Y);
} else {
turtle.draw(g);
}
break;
default:
break;
break;
case 'F':
if (g == null) {
includePt(turtle.X, turtle.Y);
turtle.jump();
includePt(turtle.X, turtle.Y);
} else {
turtle.draw(g);
}
break;
default:
break;
}
}
}
void includePt(float x, float y) {
if (x < Xmin)
if (x < Xmin) {
Xmin = x;
if (x > Xmax)
}
if (x > Xmax) {
Xmax = x;
if (y < Ymin)
}
if (y < Ymin) {
Ymin = y;
if (y > Ymax)
}
if (y > Ymax) {
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() {
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."},
{"incremental","boolean","Whether or not to repaint between recursions. Default is true."},
{"delay","integer","Sets delay between repaints. Default is 50."},
{"startAngle","float","Sets the starting angle. Default is 0."},
{"rotAngle","float","Sets the rotation angle. Default is 45."},
{"border","integer","Width of border. Default is 2."},
{"normalizeScale","boolean","Whether or not to normalize the scaling. Default is true."},
{"pred","String","Initializes the rules for Context Sensitive L-Systems."},
{"succ","String","Initializes the rules for Context Sensitive L-Systems."},
{"lContext","String","Initializes the rules for Context Sensitive L-Systems."},
{"rContext","String","Initializes the rules for Context Sensitive L-Systems."}
};
return info;
}
@Override
public String[][] getParameterInfo() {
String[][] info = {
{ "level", "int", "Maximum number of recursions. Default is 1." },
{ "incremental", "boolean", "Whether or not to repaint between "
+ "recursions. Default is true." },
{ "delay", "integer", "Sets delay between repaints. Default is 50." },
{ "startAngle", "float", "Sets the starting angle. Default is 0." },
{ "rotAngle", "float", "Sets the rotation angle. Default is 45." },
{ "border", "integer", "Width of border. Default is 2." },
{ "normalizeScale", "boolean", "Whether or not to normalize "
+ "the scaling. Default is true." },
{ "pred", "String",
"Initializes the rules for Context Sensitive L-Systems." },
{ "succ", "String",
"Initializes the rules for Context Sensitive L-Systems." },
{ "lContext", "String",
"Initializes the rules for Context Sensitive L-Systems." },
{ "rContext", "String",
"Initializes the rules for Context Sensitive L-Systems." }
};
return info;
}
}
/**
* A Logo turtle class designed to support Context sensitive L-Systems.
*
......@@ -271,6 +321,7 @@ public class CLSFractal
* @author Jim Graham
*/
class CLSTurtle {
float angle;
float X;
float Y;
......@@ -280,7 +331,7 @@ class CLSTurtle {
int yoff;
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;
scaleX = sx;
scaleY = sy;
......@@ -313,12 +364,13 @@ class CLSTurtle {
float x = X + (float) Math.cos(angle) * scaleX;
float y = Y + (float) Math.sin(angle) * scaleY;
g.drawLine((int) X + xoff, (int) Y + yoff,
(int) x + xoff, (int) y + yoff);
(int) x + xoff, (int) y + yoff);
X = x;
Y = y;
}
}
/**
* A (non-)Context sensitive L-System class.
*
......@@ -330,22 +382,23 @@ class CLSTurtle {
* @author Jim Graham
*/
class ContextLSystem {
String axiom;
Vector rules = new Vector();
List<CLSRule> rules = new ArrayList<CLSRule>();
int level;
public ContextLSystem(java.applet.Applet app) {
axiom = app.getParameter("axiom");
int num = 1;
while (true) {
String pred = app.getParameter("pred"+num);
String succ = app.getParameter("succ"+num);
String pred = app.getParameter("pred" + num);
String succ = app.getParameter("succ" + num);
if (pred == null || succ == null) {
break;
}
rules.addElement(new CLSRule(pred, succ,
app.getParameter("lContext"+num),
app.getParameter("rContext"+num)));
rules.add(new CLSRule(pred, succ,
app.getParameter("lContext" + num),
app.getParameter("rContext" + num)));
num++;
}
currentPath = new StringBuffer(axiom);
......@@ -355,7 +408,6 @@ class ContextLSystem {
public int getLevel() {
return level;
}
StringBuffer currentPath;
public synchronized String getPath() {
......@@ -385,7 +437,7 @@ class ContextLSystem {
public CLSRule findRule(int pos) {
for (int i = 0; i < rules.size(); i++) {
CLSRule rule = (CLSRule) rules.elementAt(i);
CLSRule rule = rules.get(i);
if (rule.matches(currentPath, pos)) {
return rule;
}
......@@ -394,6 +446,7 @@ class ContextLSystem {
}
}
/**
* A Context sensitive L-System production rule.
*
......@@ -405,6 +458,7 @@ class ContextLSystem {
* @author Jim Graham
*/
class CLSRule {
String pred;
String succ;
String lContext;
......
......@@ -5,7 +5,7 @@
<body>
<h1>Fractals 1.1</h1>
<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=rotangle value="45">
<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
* modification, are permitted provided that the following conditions
......@@ -29,8 +29,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.awt.Frame;
import java.awt.Event;
......@@ -38,66 +36,67 @@ import java.awt.Dimension;
import java.applet.Applet;
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,
String title,
String args[])
{
// local variables
Applet a;
Dimension appletSize;
String title,
String args[]) {
// local variables
Applet a;
Dimension appletSize;
try
{
// create an instance of your applet class
a = (Applet) Class.forName(className).newInstance();
}
catch (ClassNotFoundException e) { return; }
catch (InstantiationException e) { return; }
catch (IllegalAccessException e) { return; }
try {
// create an instance of your applet class
a = (Applet) Class.forName(className).newInstance();
} catch (ClassNotFoundException e) {
return;
} catch (InstantiationException e) {
return;
} catch (IllegalAccessException e) {
return;
}
// initialize the applet
a.init();
a.start();
// initialize the applet
a.init();
a.start();
// create new application frame window
AppletFrame f = new AppletFrame(title);
// create new application frame window
AppletFrame f = new AppletFrame(title);
// add applet to frame window
f.add("Center", a);
// add applet to frame window
f.add("Center", a);
// resize frame window to fit applet
// assumes that the applet sets its own size
// otherwise, you should set a specific size here.
appletSize = a.getSize();
f.pack();
f.setSize(appletSize);
// resize frame window to fit applet
// assumes that the applet sets its own size
// otherwise, you should set a specific size here.
appletSize = a.getSize();
f.pack();
f.setSize(appletSize);
// show the window
f.show();
// show the window
f.setVisible(true);
} // end startApplet()
// constructor needed to pass window title to class Frame
public AppletFrame(String name)
{
// call java.awt.Frame(String) constructor
super(name);
public AppletFrame(String name) {
// call java.awt.Frame(String) constructor
super(name);
}
// needed to allow window close
public void processEvent(AWTEvent e)
{
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY)
{
// exit the program
System.exit(0);
}
} // end handleEvent()
@Override
public void processEvent(AWTEvent e) {
// Window Destroy event
if (e.getID() == Event.WINDOW_DESTROY) {
// exit the program
System.exit(0);
}
} // end handleEvent()
} // 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
* modification, are permitted provided that the following conditions
......@@ -29,22 +29,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
/** 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 {
float xx, xy, xz, xo;
float yx, yy, yz, yo;
float zx, zy, zz, zo;
static final double pi = 3.14159265;
/** Create a new unit matrix */
Matrix3D () {
Matrix3D() {
xx = 1.0f;
yy = 1.0f;
zz = 1.0f;
}
/** Scale by f in all dimensions */
void scale(float f) {
xx *= f;
......@@ -60,6 +61,7 @@ class Matrix3D {
zz *= f;
zo *= f;
}
/** Scale along each axis independently */
void scale(float xf, float yf, float zf) {
xx *= xf;
......@@ -75,12 +77,14 @@ class Matrix3D {
zz *= zf;
zo *= zf;
}
/** Translate the origin */
void translate(float x, float y, float z) {
xo += x;
yo += y;
zo += z;
}
/** rotate theta degrees about the y axis */
void yrot(double theta) {
theta *= (pi / 180);
......@@ -106,6 +110,7 @@ class Matrix3D {
zy = Nzy;
zz = Nzz;
}
/** rotate theta degrees about the x axis */
void xrot(double theta) {
theta *= (pi / 180);
......@@ -131,6 +136,7 @@ class Matrix3D {
zy = Nzy;
zz = Nzz;
}
/** rotate theta degrees about the z axis */
void zrot(double theta) {
theta *= (pi / 180);
......@@ -156,6 +162,7 @@ class Matrix3D {
xy = Nxy;
xz = Nxz;
}
/** Multiply this matrix by a second: M = M*R */
void mult(Matrix3D rhs) {
float lxx = xx * rhs.xx + yx * rhs.xy + zx * rhs.xz;
......@@ -204,10 +211,11 @@ class Matrix3D {
zy = 0;
zz = 1;
}
/** Transform nvert points from v into tv. v contains the input
coordinates in floating point. Three successive entries in
the array constitute a point. tv ends up holding the transformed
points as integers; three successive entries per point */
coordinates in floating point. Three successive entries in
the array constitute a point. tv ends up holding the transformed
points as integers; three successive entries per point */
void transform(float v[], int tv[], int nvert) {
float lxx = xx, lxy = xy, lxz = xz, lxo = xo;
float lyx = yx, lyy = yy, lyz = yz, lyo = yo;
......@@ -216,11 +224,13 @@ class Matrix3D {
float x = v[i];
float y = v[i + 1];
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 + 2] = (int) (x * lzx + y * lzy + z * lzz + lzo);
}
}
@Override
public String toString() {
return ("[" + xo + "," + xx + "," + xy + "," + xz + ";"
+ yo + "," + yx + "," + yy + "," + yz + ";"
......
......@@ -6,7 +6,7 @@
<h1>MoleculeViewer (example 1)</h1>
<hr>
<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."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
......
......@@ -6,7 +6,7 @@
<h1>MoleculeViewer (example 2)</h1>
<hr>
<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."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
......
......@@ -6,25 +6,25 @@
<h1>MoleculeViewer (example 3)</h1>
<hr>
<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."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<p>
<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."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<p>
<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."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
<p>
<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."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</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
* modification, are permitted provided that the following conditions
......@@ -29,37 +29,37 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Font;
import java.applet.Applet;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/**
* An applet that displays jittering text on the screen.
*
* @author Daniel Wyszynski 04/12/95
* @modified 05/09/95 kwalrath Changed string; added thread suspension
* @modified 02/06/98 madbot removed use of suspend and resume and cleaned up
* @author 05/09/95 kwalrath Changed string; added thread suspension
* @author 02/06/98 madbot removed use of suspend and resume and cleaned up
*/
@SuppressWarnings("serial")
public class NervousText extends Applet implements Runnable, MouseListener {
String banner; // The text to be displayed
char bannerChars[]; // The same text as an array of characters
char attributes[]; // Character attributes ('^' for superscript)
Thread runner = null; // The thread that is displaying the text
boolean threadSuspended; // True when thread suspended (via mouse click)
static final int REGULAR_WD = 15;
static final int REGULAR_HT = 36;
static final int SMALL_WD = 12;
static final int SMALL_HT = 24;
Font regularFont = new Font("Serif", Font.BOLD, REGULAR_HT);
Font smallFont = new Font("Serif", Font.BOLD, SMALL_HT);
@Override
public void init() {
banner = getParameter("text");
if (banner == null) {
......@@ -67,8 +67,8 @@ public class NervousText extends Applet implements Runnable, MouseListener {
}
int bannerLength = banner.length();
StringBuffer bc = new StringBuffer(bannerLength);
StringBuffer attrs = new StringBuffer(bannerLength);
StringBuilder bc = new StringBuilder(bannerLength);
StringBuilder attrs = new StringBuilder(bannerLength);
int wd = 0;
for (int i = 0; i < bannerLength; i++) {
char c = banner.charAt(i);
......@@ -89,7 +89,7 @@ public class NervousText extends Applet implements Runnable, MouseListener {
}
bannerLength = bc.length();
bannerChars = new char[bannerLength];
bannerChars = new char[bannerLength];
attributes = new char[bannerLength];
bc.getChars(0, bannerLength, bannerChars, 0);
attrs.getChars(0, bannerLength, attributes, 0);
......@@ -99,15 +99,18 @@ public class NervousText extends Applet implements Runnable, MouseListener {
addMouseListener(this);
}
@Override
public void destroy() {
removeMouseListener(this);
}
@Override
public void start() {
runner = new Thread(this);
runner.start();
}
@Override
public synchronized void stop() {
runner = null;
if (threadSuspended) {
......@@ -116,22 +119,24 @@ public class NervousText extends Applet implements Runnable, MouseListener {
}
}
@Override
public void run() {
Thread me = Thread.currentThread();
while (runner == me) {
try {
Thread.sleep(100);
synchronized(this) {
synchronized (this) {
while (threadSuspended) {
wait();
}
}
} catch (InterruptedException e){
} catch (InterruptedException e) {
}
repaint();
}
}
@Override
public void paint(Graphics g) {
int length = bannerChars.length;
for (int i = 0, x = 0; i < length; i++) {
......@@ -152,33 +157,41 @@ public class NervousText extends Applet implements Runnable, MouseListener {
}
}
@Override
public synchronized void mousePressed(MouseEvent e) {
e.consume();
threadSuspended = !threadSuspended;
if (!threadSuspended)
if (!threadSuspended) {
notify();
}
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
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() {
String pinfo[][] = {
{"text", "string", "Text to display"},
};
{ "text", "string", "Text to display" }, };
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
* modification, are permitted provided that the following conditions
......@@ -29,22 +29,26 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
import java.awt.Graphics;
@SuppressWarnings("serial")
public class GraphApplet extends java.applet.Applet {
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) {
for (int x = 0 ; x < getSize().width ; x++) {
g.drawLine(x, (int)f(x), x + 1, (int)f(x + 1));
for (int x = 0; x < getSize().width; x++) {
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
* modification, are permitted provided that the following conditions
......@@ -29,8 +29,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*/
/**
* A bi-directional bubble sort demonstration algorithm
......@@ -39,6 +37,8 @@
* @author James Gosling
*/
class BidirBubbleSortAlgorithm extends SortAlgorithm {
@Override
void sort(int a[]) throws Exception {
int j;
int limit = a.length;
......@@ -61,9 +61,9 @@ class BidirBubbleSortAlgorithm extends SortAlgorithm {
}
if (!swapped) {
return;
}
else
} else {
swapped = false;
}
for (j = limit; --j >= st;) {
if (stopRequested) {
return;
......
......@@ -6,7 +6,7 @@
<h1>The Sorting Algorithm Demo (1.1)</h1>
<hr>
<table cols=3 width="340">
<table width="340">
<tr>
<th><strong>Bubble Sort</strong></th>
<th><strong>Bidirectional Bubble Sort</strong></th>
......
......@@ -6,7 +6,7 @@
<h1>3D Model: Cube</h1>
<hr>
<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."
Your browser is completely ignoring the &lt;APPLET&gt; tag!
</applet>
......
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册