⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scaledborder.java

📁 著名的神经网络工具箱
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************

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: ScaledBorder.java,v $
 *  Purpose:
 *  Language: Java
 *  Compiler: JDK 1.3
 *  Authors:  Fabian Hennecke
 *  Version:  $Revision: 1.1.2.3 $
 *            $Date: 2005/02/03 17:52:50 $
 *            $Author: hoensela $
 *  Copyright (c) Dept. Computer Architecture, University of Tuebingen, Germany
 */



package wsi.ra.chart2d;

/*==========================================================================*
 * IMPORTS
 *==========================================================================*/

import java.awt.* ;
import javax.swing.BorderFactory;
import javax.swing.border.* ;
import java.awt.geom.AffineTransform ;
import java.text.NumberFormat;
import java.text.DecimalFormat;

/*==========================================================================*
 * CLASS DECLARATION
 *==========================================================================*/

/**
 * ScaledBorder puts an border around Components
 * ( especially around DrawingAreas ) with scaled and labeled axes
 */
public class ScaledBorder implements Border
{
  private boolean under_construction = false;

  /**
   * length of the distance markers on the axes in pixels
   */
  int marker_length = 2;

  /**
   * length in pixels of the arrows at the ends of the axes
   */
  int arrow_length = 10;

  /**
   * a flag if the arrows should be visible
   */
  public boolean show_arrows = true;

  /**
   * distance between the x-values in digits
   */
  int x_value2value = 2;

  /**
   * distance between y-label and y-values in digit width
   */
  int y_label2values = 1;

  /**
   * distance between y-values and y-axis markers in parts of the digit width
   */
  int y_values2marker = 2;

  /**
   * distance between values and arrows in pixels
   */
  int x_values2arrow = 10,
      y_values2arrow = 10;

  /**
   * distance between arrows and outer border
   */
  int axis2border = 4;

  /**
   * distance between labels and the border in pixels
   */
  public int x_label2border = 6,
             y_label2border = 6;

  /**
   * the size of the source rectangle
   * that means before the values are mdified by scale functions
   */
  DRectangle src_rect;

  /**
   * the minimal increment of the scales
   */
  public double minimal_increment;

  /**
   * the  displayed labels
   */
  public String x_label, y_label;

  /**
   * foreground and background colors
   */
  public Color foreground, background;

  /**
   * the border which is shown around the scaled border
   */
  Border outer_border;

  /**
   * flag if the outer border should be displayed
   */
  boolean show_outer_border = true;

  /**
   * scale functions if, for example, an logarithmic function is needed instead
   * of a linear.
   */
  public DFunction x_scale, y_scale;

  /**
   * formatters of the x- and y-axis numbers
   * @see java.text.NumberFormat
   */
  public NumberFormat format_x = new DecimalFormat(),
                      format_y = new DecimalFormat();

  private double src_dX = -1, src_dY = -1;

  private boolean do_refresh,
                  auto_scale_x = true,
                  auto_scale_y = true;

  private Insets old_insets;

  private DMeasures m;

  /**
   * constructor creates a default ScaledBorder inside of a lowered BevelBorder
   */
  public ScaledBorder(){
    this(
      BorderFactory.createBevelBorder(
        BevelBorder.LOWERED,
        Color.white,
        Color.lightGray,
        Color.black,
        Color.lightGray
      )
    );
  }
  /**
   * constructor creates a new <code>ScaledBorder<code/>
   * surrounded by the specified <code>Border<code/>
   */
  public ScaledBorder( Border outer ){
    outer_border = outer;
    m = new DMeasures( this );
  }

  /**
   * method tells the border to calculate the differences between displayed
   * x-values by itself
   */
  public void setAutoScaleX(){ auto_scale_x = true; }

  /**
   * method tells the border to calculate the differences between displayed
   * y-values by itself
   */
  public void setAutoScaleY(){ auto_scale_y = true; }

  /**
   * method sets the differences between source x-values of the displayed values
   * @see setAutoScaleX().
   * If scale functions are used there might be a difference between the shown values
   * and the source values
   */
  public void setSrcdX(double dX){
    auto_scale_x = false;
    src_dX = dX;
  }

  /**
   * method sets the differences between source y-values of the displayed values
   * @see setAutoScaleY().
   * If scale functions are used there might be a difference between the shown values
   * and the source values
   */
  public void setSrcdY(double dY){
    auto_scale_y = false;
    src_dY = dY;
  }

  public void paintBorder(Component c, Graphics g, int x, int y, int width, int height){
    if( under_construction ) System.out.println("ScaledBorder.paintBorder()");
    if( foreground == null ) foreground = c.getForeground();
    if( background == null ) background = c.getBackground();
    Color old_color = g.getColor();
    g.setColor( background );
    g.fillRect( x, y, width, height );
    g.setColor( old_color );

    Insets outer_insets = new Insets( 0, 0, 0, 0);// insets of the outer border
    if( show_outer_border ) {
      outer_border.paintBorder( c, g, x, y, width, height );
      outer_insets = outer_border.getBorderInsets( c );
    }

    do_refresh = true;
    Insets inner_insets = getBorderInsets(c);

    Dimension d = c.getSize(),
              cd = new Dimension( d.width - inner_insets.left - inner_insets.right,
                                  d.height - inner_insets.top - inner_insets.bottom );
    FontMetrics fm = g.getFontMetrics();
    int fontAsc = fm.getAscent();
    do_refresh = false;

    m.update(c, inner_insets);

    // axes
    g.setColor( foreground );
    g.drawLine( inner_insets.left, inner_insets.top,
                inner_insets.left, inner_insets.top + cd.height );
    g.drawLine( inner_insets.left, inner_insets.top + cd.height,
                inner_insets.left + cd.width, inner_insets.top + cd.height );

    if( show_arrows ){
      g.drawLine( inner_insets.left, inner_insets.top,
                  inner_insets.left, inner_insets.top - y_values2arrow );
      g.drawLine( inner_insets.left - marker_length, inner_insets.top - y_values2arrow,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -