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

📄 graph2d.java

📁 java 作图的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
       catch (Exception e) {          System.out.println("Failed to attach Axis");         e.printStackTrace();       }    }/** * Detach a previously attached Axis. *    @param the Axis to dettach.*/    public void detachAxis( Axis a ) {              if(a != null) {                   a.detachAll();                   a.g2d = null;                   axis.removeElement(a);       }    }/** * Detach All attached Axes.*/    public void detachAxes() {       int i;       if(axis == null | axis.isEmpty() ) return;       for (i=0; i<axis.size(); i++) {            ((Axis)axis.elementAt(i)).detachAll();            ((Axis)axis.elementAt(i)).g2d = null;       }       axis.removeAllElements();    }/** * Get the Maximum X value of all attached DataSets. *  @return  The maximum value*/     public double getXmax() {         DataSet d;         double max=0.0;         if(dataset == null | dataset.isEmpty() ) return max;         for (int i=0; i<dataset.size(); i++) {             d = ((DataSet)dataset.elementAt(i));             if(i==0) max = d.getXmax();             else     max = Math.max(max,d.getXmax());	 }         return max;     }/** * Get the Maximum Y value of all attached DataSets. *  @return  The maximum value*/     public double getYmax() {         DataSet d;         double max=0.0;         if(dataset == null | dataset.isEmpty() ) return max;         for (int i=0; i<dataset.size(); i++) {             d = ((DataSet)dataset.elementAt(i));             if(i==0) max = d.getYmax();             else     max = Math.max(max,d.getYmax());	 }         return max;     }/** * Get the Minimum X value of all attached DataSets. *  @return  The minimum value*/     public double getXmin() {         DataSet d;         double min = 0.0;         if(dataset == null | dataset.isEmpty() ) return min;         for (int i=0; i<dataset.size(); i++) {             d = ((DataSet)dataset.elementAt(i));             if(i==0) min = d.getXmin();             else     min = Math.min(min,d.getXmin());	 }         return min;     }/** * Get the Minimum Y value of all attached DataSets. *  @return  The minimum value*/     public double getYmin() {         DataSet d;         double min=0.0;         if(dataset == null | dataset.isEmpty() ) return min;         for (int i=0; i<dataset.size(); i++) {             d = ((DataSet)dataset.elementAt(i));             if(i==0) min = d.getYmin();             else     min = Math.min(min,d.getYmin());	 }         return min;     }/** *  Set the markers for the plot. *  @param m  Marker class containing the defined markers *  @see Markers */    public void setMarkers(Markers m) {        markers = m;    }/** *  Get the markers *  @return defined Marker class *  @see Markers */       public Markers getMarkers() {        return markers;    }/** * Set the background color for the entire canvas. * @params c The color to set the canvas */    public void setGraphBackground(Color c) {        if(c == null) return;        setBackground(c);    }/** * Set the background color for the data window. * @params c The color to set the data window.  */    public void setDataBackground(Color c) {        if(c == null) return;        DataBackground = c;    }/** *  This paints the entire plot. It calls the draw methods of all the *  attached axis and data sets. *  The order of drawing is - Axis first, data legends next, data last. *  @params g Graphics state. */    public void paint(Graphics g) {        int i;        Graphics lg  = g.create();        Rectangle r = bounds();        /* The r.x and r.y returned from bounds is relative to the	** parents space so set them equal to zero.        */        r.x = 0;        r.y = 0;        if(DefaultBackground == null) DefaultBackground=this.getBackground();        if(DataBackground == null)    DataBackground=this.getBackground();//        System.out.println("Graph2D paint method called!");        if( !paintAll ) return;        r.x      += borderLeft;        r.y      += borderTop;        r.width  -= borderLeft+borderRight;        r.height -= borderBottom+borderTop;        paintFirst(lg,r);        if( !axis.isEmpty() ) r = drawAxis(lg, r);        else  {               if(clearAll ) {                 Color c = g.getColor();	         g.setColor(DataBackground);                 g.fillRect(r.x,r.y,r.width,r.height);                 g.setColor(c);               }               drawFrame(lg,r.x,r.y,r.width,r.height);        }        paintBeforeData(lg,r);        if( !dataset.isEmpty() ) {           datarect.x      = r.x;           datarect.y      = r.y;           datarect.width  = r.width;           datarect.height = r.height;           for (i=0; i<dataset.size(); i++) {             ((DataSet)dataset.elementAt(i)).draw_data(lg,r);           }	}        paintLast(lg,r);        lg.dispose();    }/** *  A hook into the Graph2D.paint method. This is called before *  anything is plotted. The rectangle passed is the dimension of *  the canvas minus the border dimensions. *  @params g Graphics state *  @params r Rectangle containing the graph */    public void paintFirst( Graphics g, Rectangle r) {    }/** *  A hook into the Graph2D.paint method. This is called before *  the data is drawn but after the axis.  *  The rectangle passed is the dimension of *  the data window. *  @params g Graphics state *  @params r Rectangle containing the data */    public void paintBeforeData( Graphics g, Rectangle r) {    }/** *  A hook into the Graph2D.paint method. This is called after *  everything has been drawn.  *  The rectangle passed is the dimension of *  the data window. *  @params g Graphics state *  @params r Rectangle containing the data */    public void paintLast( Graphics g, Rectangle r) {      if( lastText != null ) {         lastText.draw(g,r.width/2, r.height/2, TextLine.CENTER);      }    }/** * This method is called via the Graph2D.repaint() method. * All it does is blank the canvas (with the background color) * before calling paint. */    public void update(Graphics g) {//          System.out.println("Graph2d update method called");        if( clearAll ) {            Color c = g.getColor();	    /* The r.x and r.y returned from bounds is relative to the	    ** parents space so set them equal to zero            */            Rectangle r = bounds();            r.x = 0;            r.y = 0;            g.setColor(getBackground());            g.fillRect(r.x,r.y,r.width,r.height);            g.setColor(c);          }          if( paintAll ) paint(g);    }/** * Handle  keyDown events. Only one event is handled the pressing * of the key 'r' - this will repaint the canvas. */   public boolean keyDown(Event e, int key) {        if( key == 'r' ) {                              repaint();                              return true;        }  else {                              return false;        }    }                                                          /** *  Calling this method pauses the plot and displays a flashing *  message on the screen. Mainly used when data is being loaded across the *  net. Everytime this routine is called a counter is incremented *  the method Graph2D.finishedloading() decrements the counter. When the *  counter is back to zero the plotting resumes. *  @see Graph2D#finishedloading() *  @see Graph2D#loadmessage() *  @see LoadMessage*/    public void startedloading() {           loadingData++;           if(loadingData != 1) return;           if(load_thread == null) load_thread = new LoadMessage(this);           load_thread.setFont(new Font("Helvetica", Font.PLAIN, 25));           load_thread.begin();    }/** * Decrement the loading Data counter by one. When it is zero resume * plotting. *  @see Graph2D#startedloading() *  @see Graph2D#loadmessage() *  @see LoadMessage*/    public void finishedloading() {           loadingData--;           if(loadingData > 0) return;           if(load_thread != null) load_thread.end();           load_thread = null;    }/** * Change the message to be flashed on the canvas * @param s String contining the new message. * @see Graph2D#startedloading() * @see Graph2D#finishedloading() * @see LoadMessage*/    public void loadmessage(String s) {           if(load_thread == null) load_thread = new LoadMessage(this);           load_thread.setMessage(s);    }                /************************ Protected Methods*********************//** *  Force the plot to have an aspect ratio of 1 by forcing the *  axes to have the same range. If the range of the axes *  are very different some extremely odd things can occur. All axes are *  forced to have the same range, so more than 2 axis is pointless. */        protected Rectangle ForceSquare(Graphics g, Rectangle r) {            Axis a;            Rectangle dr;            int x      = r.x;            int y      = r.y;            int width  = r.width;            int height = r.height;            double xmin;            double xmax;            double ymin;            double ymax;            double xrange = 0.0;            double yrange = 0.0;            double range;            double aspect;            if( dataset == null | dataset.isEmpty() ) return r;                 /***          Force all the axis to have the same range. This of course**          means that anything other than one xaxis and one yaxis**          is a bit pointless.*/            for (int i=0; i<axis.size(); i++) {               a = (Axis)axis.elementAt(i);               range = a.maximum - a.minimum;               if(a.isVertical()) {                                    yrange = Math.max(range, yrange);

⌨️ 快捷键说明

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