📄 darea.java
字号:
/*************************************************************************
This program is copyrighted. Please refer to COPYRIGHT.txt for the
copyright notice.
This file is part of JavaNNS.
JavaNNS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
JavaNNS is distributed in the hope that it will be useful,
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with JavaNNS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*************************************************************************/
/**
* Filename: $RCSfile: DArea.java,v $
* Purpose:
* Language: Java
* Compiler: JDK 1.3
* Authors: Fabian Hennecke
* Version: $Revision: 1.1.2.3 $
* $Date: 2005/02/03 17:49:56 $
* $Author: hoensela $
* Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
*/
package wsi.ra.chart2d;
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.swing.*;
import javax.swing.border.Border;
import java.util.Vector;
// zum Drucken:
import java.awt.print.*;
import wsi.ra.print.PagePrinter;
/*==========================================================================*
* CLASS DECLARATION
*==========================================================================*/
/**
* DArea is the crossing of the <code>JComponent</code>s and the
* <code>DComponent</code>s. It's the <code>DParent</code> which can be added to
* <code>JComponent</code>s
*/
public class DArea extends JComponent implements DParent, Printable
{
private static final boolean under_construction = false;
/**
* the default minimal rectangle which is shown
*/
public static final DRectangle DEFAULT_MIN_RECT = new DRectangle(-1, -1, 2, 2);
/**
* the container in which all DElements of the area are contained except
* the grid
*/
private DContainer container;
/**
* min_rectangle is set, when all elements are removed
* the intersection of visible_rect and max_rectangle is the currently visible
* rectangle
*/
protected DRectangle min_rect = DEFAULT_MIN_RECT,
visible_rect = DEFAULT_MIN_RECT;
protected Double min_x, min_y, max_x, max_y;
/**
* the grid of the area
*/
private DGrid grid;
private boolean auto_focus = false,
auto_grid = false,
grid_to_front = false;
/**
* maximal number of grid lines
*/
private int max_grid = 10;
/**
* the measures of the area
* it calculates the coordinates
*/
private DMeasures measures;
private DBorder dborder = new DBorder();
/**
* initializes the DArea with the initial capacity of 10 components
*/
public DArea(){
this( 10 );
}
/**
* initializes the DArea with the specialized initial capacity of components
* (@see java.util.Vector)
*
* @param the initial capacity
*/
public DArea( int initial_capacity ){
container = new DContainer();
container.setDParent( this );
grid = new DGrid( visible_rect, 1, 1 );
grid.setVisible( false );
grid.setDParent( this );
measures = new DMeasures( this );
}
/**
* returns the currently visible rectangle in DArea coordinates
*
* @return DRectangle the size and position of the visible area
*/
public DRectangle getDRectangle(){
DRectangle rect = (DRectangle)visible_rect.clone();
if( min_x != null ) rect.x = Math.max(rect.x, getMinX() );
if( min_y != null ) rect.y = Math.max(rect.y, getMinY() );
if( max_x != null ) rect.width = Math.min(rect.width, getMaxX() - getMinX());
if( max_y != null ) rect.height = Math.min(rect.height, getMaxY() - getMinY());
return rect;
}
/**
* switches the auto focus of this DArea on or off
*
* @param b on or off
*/
public void setAutoFocus( boolean b ){
boolean old = auto_focus;
auto_focus = b;
if( old != b ) repaint();
}
/**
* returns whether the DArea's auto focus is on or not
*
* @return <code>true</code> or <code>false</code>
*/
public boolean isOnAutoFocus(){ return auto_focus; }
/**
* sets the visible rectangle to this size
*
* @param x the x coordinate of the left border
* @param y the y coordinate of the bottom border
* @param width the width of the area
* @param height the height of the area
*/
public void setVisibleRectangle( double x, double y, double width, double height ){
//System.out.println("DArea.setVisibleRectangle(...)");
setVisibleRectangle( new DRectangle( x, y, width, height ) );
}
/**
* sets the visible rectangle
*
* @param rect the visible <code>DRectangle</code> in DArea coordinates
*/
public void setVisibleRectangle( DRectangle rect ){
if( under_construction )System.out.println("DArea.setVisibleRectangle(DRectangle)");
if( rect.isEmpty() ) throw
new IllegalArgumentException(
"You shopuld never try to set an empty rectangle\n"
+ "as the visible rectangle of an DArea" );
if( !rect.equals( visible_rect ) && rect.width > 0 && rect.height > 0 ){
auto_focus = false;
visible_rect = (DRectangle)rect.clone();
repaint();
}
}
/**
* sets the minimal rectangle
*
* @param x
* @param y
* @param width
* @param height
*/
public void setMinRectangle( double x, double y, double width, double height ){
setMinRectangle( new DRectangle( x, y, width, height ) );
}
/**
* sets the minimal rectangle
*
* @param rect the visible <code>DRectangle</code> in DArea coordinates
*/
public void setMinRectangle( DRectangle rect ){
if( rect.isEmpty() ) min_rect = DEFAULT_MIN_RECT;
else min_rect = (DRectangle)rect.clone();
}
/**
* method returns the minimal rectangle which is set as the visible when all
* elements are removed and the area is on auto focus
*
* @return the minmal rectangle
*/
public DRectangle getMinRectangle(){
return (DRectangle)min_rect.clone();
}
/**
* method sets the maximal rectangle whioch can be viewed with the
* DArea. This method can be used if the area is used with scale functions
* which are not invertible on all reals
*
* @param x the minmal x value
* @param y the minmal y value
* @param width of the maximal rectangle
* @param height of the maximal rectangle
*/
public void setMaxRectangle( double x, double y, double width, double height ){
setMaxRectangle( new DRectangle( x, y, width, height ) );
}
/**
* method sets the maximal rectangle whioch can be viewed with the
* DArea. This method can be used if the area is used with scale functions
* which are not invertible on all reals
*
* @param the rect maximal rectangle of the DArea
* @deprecated see setMinX, setMinY, setMaxX, setMaxY
*/
public void setMaxRectangle( DRectangle rect ){
if( !rect.contains( min_rect ) ) throw
new IllegalArgumentException("Maximal rectangle does not contain minmal rectangle");
setMinX( rect.x );
setMinY( rect.y );
setMaxX( rect.x + rect.width );
setMaxY( rect.y + rect.height );
}
/**
* method returns the maximal rectangle of the area
*
* @return the maximal rectangle
* @deprecated see getMaxX, getMaxY, getMinX, getMinY
*/
public DRectangle getMaxRectangle(){
return new DRectangle(min_x.doubleValue(),
min_y.doubleValue(),
max_x.doubleValue() - min_x.doubleValue(),
max_y.doubleValue() - min_y.doubleValue() );
}
/**
* method sets the minimal x-value which can be displayed by the DArea
* might be helpful, if scale functions are used which are not defined overall
*
* @param mix the minimal x-value
*/
public void setMinX( double mix ){
if( mix > min_rect.x ) throw
new IllegalArgumentException(
"Mimimal y-value axes intersects minmal rectangle.");
min_x = new Double( mix );
}
/**
* method resets the minimal x-value
*/
public void releaseMinX(){
min_x = null;
}
/**
* method returns the minmal x-value which can be displayed in the DArea
*
* @return the minmal x-value
*/
public double getMinX(){
if( min_x != null ) return min_x.doubleValue();
return 0;
}
/**
* method sets the minimal y-value which can be displayed by the DArea
* might be helpful, if scale functions are used which are not defined overall
*
* @param miy the minimal y-value
*/
public void setMinY( double miy ){
if( miy > min_rect.y ) throw
new IllegalArgumentException(
"Mimimal y-value axes intersects minmal rectangle.");
min_y = new Double( miy );
}
/**
* method resets the minimal y-value
*/
public void releaseMinY(){
min_y = null;
}
/**
* method returns the minmal y-value which can be displayed in the DArea
*
* @return the minmal y-value
*/
public double getMinY(){
if( min_y != null ) return min_y.doubleValue();
return 0;
}
/**
* method sets the maximal x-value which can be displayed by the DArea
* might be helpful, if scale functions are used which are not defined overall
*
* @param max the maximal x-value
*/
public void setMaxX( double max ){
if( max < min_rect.x + min_rect.width ) throw
new IllegalArgumentException(
"Maximal x-value axes intersects minmal rectangle.");
max_x = new Double( max );
}
/**
* method resets the maximal x-value
*/
public void releaseMaxX(){
max_x = null;
}
/**
* method returns the maxmal x-value which can be displayed in the DArea
*
* @return the maxmal x-value
*/
public double getMaxX(){
if( max_x != null ) return max_x.doubleValue();
return 0;
}
/**
* method sets the maximal y-values which can be displayed by the DArea
* might be helpful, if scale functions are used which are not defined overall
*
* @param may the maximal y-value
*/
public void setMaxY( double may ){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -