?? abstracttitle.java
字號:
/* ======================================
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ------------------
* AbstractTitle.java
* ------------------
* (C) Copyright 2000-2003, by David Berry and Contributors.
*
* Original Author: David Berry;
* Contributor(s): David Gilbert (for Object Refinery Limited);
*
* $Id: AbstractTitle.java,v 1.5 2003/08/20 11:31:13 mungady Exp $
*
* Changes (from 21-Aug-2001)
* --------------------------
* 21-Aug-2001 : Added standard header (DG);
* 18-Sep-2001 : Updated header (DG);
* 14-Nov-2001 : Package com.jrefinery.common.ui.* changed to com.jrefinery.ui.* (DG);
* 07-Feb-2002 : Changed blank space around title from Insets --> Spacer, to allow for relative
* or absolute spacing (DG);
* 25-Jun-2002 : Removed unnecessary imports (DG);
* 01-Oct-2002 : Fixed errors reported by Checkstyle (DG);
* 14-Oct-2002 : Changed the event listener storage structure (DG);
*
*/
package org.jfree.chart;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import javax.swing.event.EventListenerList;
import org.jfree.chart.event.TitleChangeEvent;
import org.jfree.chart.event.TitleChangeListener;
import org.jfree.util.ObjectUtils;
/**
* The base class for all chart titles.
* <P>
* A chart can have multiple titles, appearing at the top, bottom, left or
* right of the chart (defined by the constants TOP, BOTTOM, LEFT and RIGHT ---
* we also use the constants NORTH, SOUTH, EAST and WEST to remain consistent
* with java.awt.BorderLayout, as most developers will be familiar with that
* class).
* <P>
* Concrete implementations of this class will render text, images, and hence
* do the actual work of drawing titles.
*
* @author David Berry
*/
public abstract class AbstractTitle extends Object implements Cloneable, Serializable {
/** Useful constant for the title position (also used for vertical alignment). */
public static final int TOP = 0;
/** Useful constant for the title position (also used for vertical alignment). */
public static final int BOTTOM = 1;
/** Useful constant for the title position (also used for horizontal alignment). */
public static final int RIGHT = 2;
/** Useful constant for the title position (also used for horizontal alignment). */
public static final int LEFT = 3;
/** Useful constant for the title position. */
public static final int NORTH = 0;
/** Useful constant for the title position. */
public static final int SOUTH = 1;
/** Useful constant for the title position. */
public static final int EAST = 2;
/** Useful constant for the title position. */
public static final int WEST = 3;
/** Useful constant for the title alignment (horizontal or vertical). */
public static final int CENTER = 4;
/** Useful constant for the title alignment (horizontal or vertical). */
public static final int MIDDLE = 4;
/** The default title position. */
public static final int DEFAULT_POSITION = AbstractTitle.TOP;
/** The default horizontal alignment. */
public static final int DEFAULT_HORIZONTAL_ALIGNMENT = AbstractTitle.CENTER;
/** The default vertical alignment. */
public static final int DEFAULT_VERTICAL_ALIGNMENT = AbstractTitle.MIDDLE;
/** Default title spacer. */
public static final Spacer DEFAULT_SPACER = new Spacer(Spacer.RELATIVE, 0.01, 0.30, 0.01, 0.15);
/**
* The position of the title (use the constants NORTH, SOUTH, EAST and
* WEST, or if you prefer you can also use TOP, BOTTOM, LEFT and RIGHT).
*/
private int position;
/** The horizontal alignment of the title. */
private int horizontalAlignment;
/** The vertical alignment of the title. */
private int verticalAlignment;
/** The amount of blank space to leave around the title. */
private Spacer spacer;
/** Storage for registered change listeners. */
private transient EventListenerList listenerList;
/** A flag that can be used to temporarily disable the listener mechanism. */
private boolean notify;
/**
* Creates a new title, using default attributes where necessary.
*/
protected AbstractTitle() {
this(AbstractTitle.DEFAULT_POSITION,
AbstractTitle.DEFAULT_HORIZONTAL_ALIGNMENT,
AbstractTitle.DEFAULT_VERTICAL_ALIGNMENT,
AbstractTitle.DEFAULT_SPACER);
}
/**
* Creates a new title, using default attributes where necessary.
*
* @param position the relative position of the title (TOP, BOTTOM, RIGHT and LEFT).
* @param horizontalAlignment the horizontal alignment of the title (LEFT, CENTER or RIGHT).
* @param verticalAlignment the vertical alignment of the title (TOP, MIDDLE or BOTTOM).
*/
protected AbstractTitle(int position, int horizontalAlignment, int verticalAlignment) {
this(position,
horizontalAlignment, verticalAlignment,
AbstractTitle.DEFAULT_SPACER);
}
/**
* Constructs a new AbstractTitle.
* <P>
* This class defines constants for the valid position and alignment values
* --- an IllegalArgumentException will be thrown if invalid values are
* passed to this constructor.
*
* @param position the relative position of the title (TOP, BOTTOM, RIGHT and LEFT).
* @param horizontalAlignment the horizontal alignment of the title (LEFT, CENTER or RIGHT).
* @param verticalAlignment the vertical alignment of the title (TOP, MIDDLE or BOTTOM).
* @param spacer the amount of space to leave around the outside of the title.
*/
protected AbstractTitle(int position,
int horizontalAlignment, int verticalAlignment,
Spacer spacer) {
// check arguments...
if (!isValidPosition(position)) {
throw new IllegalArgumentException("AbstractTitle(): invalid position.");
}
if (!AbstractTitle.isValidHorizontalAlignment(horizontalAlignment)) {
throw new IllegalArgumentException("AbstractTitle(): invalid horizontal alignment.");
}
if (!AbstractTitle.isValidVerticalAlignment(verticalAlignment)) {
throw new IllegalArgumentException("AbstractTitle(): invalid vertical alignment.");
}
// initialise...
this.position = position;
this.horizontalAlignment = horizontalAlignment;
this.verticalAlignment = verticalAlignment;
this.spacer = spacer;
this.listenerList = new EventListenerList();
this.notify = true;
}
/**
* Returns the relative position of the title---represented by one of four
* integer constants defined in this class: TOP, BOTTOM, RIGHT or LEFT (or
* the equivalent NORTH, SOUTH, EAST and WEST).
*
* @return The title position.
*/
public int getPosition() {
return this.position;
}
/**
* Sets the position for the title.
*
* @param position the relative position of the title (use one of the constants TOP, BOTTOM,
* RIGHT and LEFT, or the equivalent NORTH, SOUTH, EAST and WEST).
*/
public void setPosition(int position) {
if (this.position != position) {
// check that the position is valid
this.position = position;
notifyListeners(new TitleChangeEvent(this));
}
}
/**
* Returns the horizontal alignment of the title. The constants LEFT,
* CENTER and RIGHT (defined in this class) are used.
*
* @return the horizontal alignment of the title (LEFT, CENTER or RIGHT).
*/
public int getHorizontalAlignment() {
return this.horizontalAlignment;
}
/**
* Sets the horizontal alignment for the title, and notifies any registered
* listeners of the change. The constants LEFT, CENTER and RIGHT (defined
* in this class) can be used to specify the alignment.
*
* @param alignment the new horizontal alignment (LEFT, CENTER or RIGHT).
*/
public void setHorizontalAlignment(int alignment) {
if (this.horizontalAlignment != alignment) {
this.horizontalAlignment = alignment;
notifyListeners(new TitleChangeEvent(this));
}
}
/**
* Returns the vertical alignment of the title. The constants TOP, MIDDLE
* and BOTTOM (defined in this class) are used.
*
* @return the vertical alignment of the title (TOP, MIDDLE or BOTTOM).
*/
public int getVerticalAlignment() {
return this.verticalAlignment;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -