?? abstracttitle.java
字號:
}
/**
* Sets the vertical alignment for the title, and notifies any registered
* listeners of the change.
* The constants TOP, MIDDLE and BOTTOM (defined in this class) can be used
* to specify the alignment.
*
* @param alignment the new vertical alignment (TOP, MIDDLE or BOTTOM).
*/
public void setVerticalAlignment(int alignment) {
if (this.verticalAlignment != alignment) {
this.verticalAlignment = alignment;
notifyListeners(new TitleChangeEvent(this));
}
}
/**
* Returns the spacer (determines the blank space around the edges) for
* this title.
*
* @return the spacer for this title.
*/
public Spacer getSpacer() {
return this.spacer;
}
/**
* Sets the spacer for the title, and notifies registered listeners of the
* change.
*
* @param spacer the new spacer.
*/
public void setSpacer(Spacer spacer) {
if (!this.spacer.equals(spacer)) {
this.spacer = spacer;
notifyListeners(new TitleChangeEvent(this));
}
}
/**
* Returns the flag that indicates whether or not the notification mechanism is enabled.
*
* @return the flag.
*/
public boolean getNotify() {
return this.notify;
}
/**
* Sets the flag that indicates whether or not the notification mechanism
* is enabled. There are certain situations (such as cloning) where you
* want to turn notification off temporarily.
*
* @param flag the new value of the flag.
*/
public void setNotify(boolean flag) {
this.notify = flag;
}
/**
* Returns true if the title can assume the specified location, and false otherwise.
*
* @param position the position.
*
* @return <code>true</code> if the title can assume the specified position.
*/
public abstract boolean isValidPosition(int position);
/**
* Returns the preferred width of the title. When a title is displayed at
* the left or right of a chart, the chart will attempt to give the title
* enough space for it's preferred width.
*
* @param g2 the graphics device.
*
* @return the preferred width of the title.
*/
public abstract double getPreferredWidth(Graphics2D g2);
/**
* Returns the preferred height of the title. When a title is displayed at
* the top or bottom of a chart, the chart will attempt to give the title
* enough space for it's preferred height.
*
* @param g2 the graphics device.
*
* @return the preferred height of the title.
*/
public abstract double getPreferredHeight(Graphics2D g2);
/**
* Draws the title on a Java 2D graphics device (such as the screen or a printer).
*
* @param g2 the graphics device.
* @param titleArea the area for drawing the title.
*/
public abstract void draw(Graphics2D g2, Rectangle2D titleArea);
/**
* Returns a clone of the title.
* <P>
* One situation when this is useful is when editing the title properties -
* you can edit a clone, and then it is easier to cancel the changes if
* necessary.
*
* @return a clone of the title.
*
*/
public Object clone() {
AbstractTitle duplicate = null;
try {
duplicate = (AbstractTitle) super.clone();
}
catch (CloneNotSupportedException e) {
// this should never happen because Cloneable is implemented
throw new RuntimeException("AbstractTitle.clone()");
}
return duplicate;
}
/**
* Registers an object for notification of changes to the title.
*
* @param listener the object that is being registered.
*/
public void addChangeListener(TitleChangeListener listener) {
this.listenerList.add(TitleChangeListener.class, listener);
}
/**
* Unregisters an object for notification of changes to the chart title.
*
* @param listener the object that is being unregistered.
*/
public void removeChangeListener(TitleChangeListener listener) {
this.listenerList.remove(TitleChangeListener.class, listener);
}
/**
* Notifies all registered listeners that the chart title has changed in some way.
*
* @param event an object that contains information about the change to the title.
*/
protected void notifyListeners(TitleChangeEvent event) {
if (this.notify) {
Object[] listeners = this.listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == TitleChangeListener.class) {
((TitleChangeListener) listeners[i + 1]).titleChanged(event);
}
}
}
}
/**
* Utility method for checking a horizontal alignment code.
*
* @param code the alignment code.
*
* @return <code>true</code> if alignment is <code>LEFT|MIDDLE|RIGHT</code>.
*/
protected static boolean isValidHorizontalAlignment(int code) {
switch(code) {
case AbstractTitle.LEFT: return true;
case AbstractTitle.MIDDLE: return true;
case AbstractTitle.RIGHT: return true;
default: return false;
}
}
/**
* Utility method for checking a vertical alignment code.
*
* @param code the alignment code.
*
* @return <code>true</code>, if alignment is <code>TOP|MIDDLE|BOTTOM</code>.
*/
protected static boolean isValidVerticalAlignment(int code) {
switch(code) {
case AbstractTitle.TOP: return true;
case AbstractTitle.MIDDLE: return true;
case AbstractTitle.BOTTOM: return true;
default: return false;
}
}
/**
* Tests an object for equality with this title.
*
* @param obj the object.
*
* @return <code>true</code> or <code>false</code>.
*/
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj instanceof AbstractTitle) {
AbstractTitle t = (AbstractTitle) obj;
// if (super.equals(obj)) {
boolean b0 = (this.position == t.position);
boolean b1 = (this.horizontalAlignment == t.horizontalAlignment);
boolean b2 = (this.verticalAlignment == t.verticalAlignment);
boolean b3 = ObjectUtils.equal(this.spacer, t.spacer);
boolean b4 = (this.notify == t.notify);
return b0 && b1 && b2 && b3 && b4;
// }
}
return false;
}
/**
* Provides serialization support.
*
* @param stream the output stream.
*
* @throws IOException if there is an I/O error.
*/
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
}
/**
* Provides serialization support.
*
* @param stream the input stream.
*
* @throws IOException if there is an I/O error.
* @throws ClassNotFoundException if there is a classpath problem.
*/
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
this.listenerList = new EventListenerList();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -