?? infiniteprogresspanel.java
字號:
/*
* Copyright (c) 2005, Romain Guy <romain.guy@jext.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Code from Romain Guy's webblog - http://www.jroller.com/page/gfx
* Subject to the BSD license.
*
* For questions, suggestions, bug-reports, enhancement-requests etc.
* visit http://www.quickserver.org
*/
package chatserver.client;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JComponent;
/**
*
* An infinite progress panel displays a rotating figure and
* a message to notice the user of a long, duration unknown
* task. The shape and the text are drawn upon a white veil
* which alpha level (or shield value) lets the underlying
* component shine through. This panel is meant to be used
* asa <i>glass pane</i> in the window performing the long
* operation.
* <br /><br />
* On the contrary to regular glass panes, you don't need to
* set it visible or not by yourself. Once you've started the
* animation all the mouse events are intercepted by this
* panel, preventing them from being forwared to the
* underlying components.
* <br /><br />
* The panel can be controlled by the <code>start()</code>,
* <code>stop()</code> and <code>interrupt()</code> methods.
* <br /><br />
* Example:
* <br /><br />
* <pre>InfiniteProgressPanel pane = new InfiniteProgressPanel();
* frame.setGlassPane(pane);
* pane.start()</pre>
* <br /><br />
* Several properties can be configured at creation time. The
* message and its font can be changed at runtime. Changing the
* font can be done using <code>setFont()</code> and
* <code>setForeground()</code>.
*
* Code from Romain Guy's webblog - http://www.jroller.com/page/gfx (BSD license.)
*
* @author Romain Guy
* @version 1.0
*/
public class InfiniteProgressPanel extends JComponent implements MouseListener {
/** Contains the bars composing the circular shape. */
protected Area[] ticker = null;
/** The animation thread is responsible for fade in/out and rotation. */
protected Thread animation = null;
/** Notifies whether the animation is running or not. */
protected boolean started = false;
/** Alpha level of the veil, used for fade in/out. */
protected int alphaLevel = 0;
/** Duration of the veil's fade in/out. */
protected int rampDelay = 300;
/** Alpha level of the veil. */
protected float shield = 0.70f;
/** Message displayed below the circular shape. */
protected String text = "";
/** Amount of bars composing the circular shape. */
protected int barsCount = 14;
/** Amount of frames per seconde. Lowers this to save CPU. */
protected float fps = 15.0f;
/** Rendering hints to set anti aliasing. */
protected RenderingHints hints = null;
/**
* Creates a new progress panel with default values:<br />
* <ul>
* <li>No message</li>
* <li>14 bars</li>
* <li>Veil's alpha level is 70%</li>
* <li>15 frames per second</li>
* <li>Fade in/out last 300 ms</li>
* </ul>
*/
public InfiniteProgressPanel() {
this("");
}
/**
* Creates a new progress panel with default values:<br />
* <ul>
* <li>14 bars</li>
* <li>Veil's alpha level is 70%</li>
* <li>15 frames per second</li>
* <li>Fade in/out last 300 ms</li>
* </ul>
* @param text The message to be displayed. Can be null or empty.
*/
public InfiniteProgressPanel(String text) {
this(text, 14);
}
/**
* Creates a new progress panel with default values:<br />
* <ul>
* <li>Veil's alpha level is 70%</li>
* <li>15 frames per second</li>
* <li>Fade in/out last 300 ms</li>
* </ul>
* @param text The message to be displayed. Can be null or empty.
* @param barsCount The amount of bars composing the circular shape
*/
public InfiniteProgressPanel(String text, int barsCount) {
this(text, barsCount, 0.70f);
}
/**
* Creates a new progress panel with default values:<br />
* <ul>
* <li>15 frames per second</li>
* <li>Fade in/out last 300 ms</li>
* </ul>
* @param text The message to be displayed. Can be null or empty.
* @param barsCount The amount of bars composing the circular shape.
* @param shield The alpha level between 0.0 and 1.0 of the colored
* shield (or veil).
*/
public InfiniteProgressPanel(String text, int barsCount, float shield) {
this(text, barsCount, shield, 15.0f);
}
/**
* Creates a new progress panel with default values:<br />
* <ul>
* <li>Fade in/out last 300 ms</li>
* </ul>
* @param text The message to be displayed. Can be null or empty.
* @param barsCount The amount of bars composing the circular shape.
* @param shield The alpha level between 0.0 and 1.0 of the colored
* shield (or veil).
* @param fps The number of frames per second. Lower this value to
* decrease CPU usage.
*/
public InfiniteProgressPanel(String text, int barsCount, float shield, float fps) {
this(text, barsCount, shield, fps, 300);
}
/**
* Creates a new progress panel.
* @param text The message to be displayed. Can be null or empty.
* @param barsCount The amount of bars composing the circular shape.
* @param shield The alpha level between 0.0 and 1.0 of the colored
* shield (or veil).
* @param fps The number of frames per second. Lower this value to
* decrease CPU usage.
* @param rampDelay The duration, in milli seconds, of the fade in and
* the fade out of the veil.
*/
public InfiniteProgressPanel(String text, int barsCount, float shield, float fps, int rampDelay) {
this.text = text;
this.rampDelay = rampDelay >= 0 ? rampDelay : 0;
this.shield = shield >= 0.0f ? shield : 0.0f;
this.fps = fps > 0.0f ? fps : 15.0f;
this.barsCount = barsCount > 0 ? barsCount : 14;
this.hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
this.hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
this.hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
}
/**
* Changes the displayed message at runtime.
*
* @param text The message to be displayed. Can be null or empty.
*/
public void setText(String text) {
this.text = text;
repaint();
}
/**
* Returns the current displayed message.
*/
public String getText() {
return text;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -