* for this {@code JLayer} and the {@code JLayer}
* is displayable.
*
- * 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:
*
* public void installUI(JComponent c) {
@@ -834,7 +834,7 @@ public final class JLayer
}
/**
- * 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
diff --git a/src/share/classes/javax/swing/PopupFactory.java b/src/share/classes/javax/swing/PopupFactory.java
index 13a1f9d1a687d2925a96f31a00684367f94f3158..713ada71558c6ce56ff298fd2fbcec2218354815 100644
--- a/src/share/classes/javax/swing/PopupFactory.java
+++ b/src/share/classes/javax/swing/PopupFactory.java
@@ -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();
}
diff --git a/src/share/classes/javax/swing/SpringLayout.java b/src/share/classes/javax/swing/SpringLayout.java
index 53a86c3d099f927a00d89fe60c9c8adc25b19fd7..7686fc5622857b3f377622f14cd15dbb95851015 100644
--- a/src/share/classes/javax/swing/SpringLayout.java
+++ b/src/share/classes/javax/swing/SpringLayout.java
@@ -727,6 +727,9 @@ public class SpringLayout implements LayoutManager2 {
* For any other String value passed as the edge,
* no action is taken. For a null edge, a
* NullPointerException is thrown.
+ *
+ * Note: 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
diff --git a/src/share/classes/javax/swing/plaf/LayerUI.java b/src/share/classes/javax/swing/plaf/LayerUI.java
index e118467aa99967717bea219277f1aea9935ae690..c7ff14eeb4bf845e6be1a854e58988d8a5f9ed6e 100644
--- a/src/share/classes/javax/swing/plaf/LayerUI.java
+++ b/src/share/classes/javax/swing/plaf/LayerUI.java
@@ -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.
*
- * {@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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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
* 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;
diff --git a/src/share/classes/javax/swing/plaf/nimbus/LoweredBorder.java b/src/share/classes/javax/swing/plaf/nimbus/LoweredBorder.java
index 46fc84adf67a2b9105010b6452b0e385aa42a7cd..768d77219745f7124319357cbf4b95988f388333 100644
--- a/src/share/classes/javax/swing/plaf/nimbus/LoweredBorder.java
+++ b/src/share/classes/javax/swing/plaf/nimbus/LoweredBorder.java
@@ -1,5 +1,5 @@
/*
- * 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();
}
/**
diff --git a/src/share/classes/javax/swing/plaf/synth/SynthTableUI.java b/src/share/classes/javax/swing/plaf/synth/SynthTableUI.java
index 621be2400f441d8f8b050a4ffd8e049a89d17cda..b1e6a09291057266fbfc84160a5a33ad18f4b96f 100644
--- a/src/share/classes/javax/swing/plaf/synth/SynthTableUI.java
+++ b/src/share/classes/javax/swing/plaf/synth/SynthTableUI.java
@@ -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;
}
diff --git a/src/share/demo/applets/ArcTest/ArcTest.java b/src/share/demo/applets/ArcTest/ArcTest.java
index d02fd0e377f8d9e6c882b25686f01fe7b7b9baf9..d58ef44b340cf07e38322e6a7b2ea51b6a81ff08 100644
--- a/src/share/demo/applets/ArcTest/ArcTest.java
+++ b/src/share/demo/applets/ArcTest/ArcTest.java
@@ -1,5 +1,5 @@
/*
- * 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;
}
}
diff --git a/src/share/demo/applets/BarChart/BarChart.java b/src/share/demo/applets/BarChart/BarChart.java
index dce59b51c57a5664149261c6e99b27cc02db8a13..81cab8fcf3b9905271e57888c0afec5d82357dc7 100644
--- a/src/share/demo/applets/BarChart/BarChart.java
+++ b/src/share/demo/applets/BarChart/BarChart.java
@@ -1,5 +1,5 @@
/*
- * 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;
}
diff --git a/src/share/demo/applets/Blink/Blink.java b/src/share/demo/applets/Blink/Blink.java
index 3495dc9ef0c1b843c951ff777b8d735ea864ab3b..ab6f9795cc6ad3d16df93e52e0a5fc7b99b306a3 100644
--- a/src/share/demo/applets/Blink/Blink.java
+++ b/src/share/demo/applets/Blink/Blink.java
@@ -1,5 +1,5 @@
/*
- * 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;
}
}
diff --git a/src/share/demo/applets/CardTest/CardTest.java b/src/share/demo/applets/CardTest/CardTest.java
index 93e42ff95f0c6c6c0feb44b2d3f6469bdfaa9d38..38110efaf5b6564b54510235983d3c969ba538be 100644
--- a/src/share/demo/applets/CardTest/CardTest.java
+++ b/src/share/demo/applets/CardTest/CardTest.java
@@ -1,5 +1,5 @@
/*
- * 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.";
}
diff --git a/src/share/demo/applets/Clock/Clock.java b/src/share/demo/applets/Clock/Clock.java
index 4c86ad3319dd3f392cde5208339040de01cf9a4a..ea698ff503e4509c8f92a0ddfc9d01dd26047eb3 100644
--- a/src/share/demo/applets/Clock/Clock.java
+++ b/src/share/demo/applets/Clock/Clock.java
@@ -1,5 +1,5 @@
/*
- * 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;
}
diff --git a/src/share/demo/applets/DitherTest/DitherTest.java b/src/share/demo/applets/DitherTest/DitherTest.java
index 25e743db9df706789c81e77c2798661ca7e24201..04165735702d624eaf285491c3431ed38ae44b8b 100644
--- a/src/share/demo/applets/DitherTest/DitherTest.java
+++ b/src/share/demo/applets/DitherTest/DitherTest.java
@@ -1,5 +1,5 @@
/*
- * 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;
}
diff --git a/src/share/demo/applets/DrawTest/DrawTest.java b/src/share/demo/applets/DrawTest/DrawTest.java
index 2a98482bf4e00069788bee1ba4fec83e831831dd..50af991079e65ae81ed4892ddb9229f065646969 100644
--- a/src/share/demo/applets/DrawTest/DrawTest.java
+++ b/src/share/demo/applets/DrawTest/DrawTest.java
@@ -1,5 +1,5 @@
/*
- * 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 lines = new ArrayList();
+ List colors = new ArrayList();
+ 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 turtleStack = new Stack();
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 rules = new ArrayList();
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;
diff --git a/src/share/demo/applets/Fractal/example1.html b/src/share/demo/applets/Fractal/example1.html
index ac6aab9ad646db03d44120aa6eafa1d978c308cc..12d49e03217d7479cdd6db3b05b5321f58e1cfb9 100644
--- a/src/share/demo/applets/Fractal/example1.html
+++ b/src/share/demo/applets/Fractal/example1.html
@@ -5,7 +5,7 @@
Fractals 1.1
-