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

📄 modeltime.java

📁 fortran并行计算包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  (C) 2001 by Argonne National Laboratory *      See COPYRIGHT in top-level directory. *//* *  @author  Anthony Chan */package viewer.zoomable;import java.util.Stack;import java.awt.Window;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import base.drawable.TimeBoundingBox;import viewer.common.Parameters;import viewer.common.Dialogs;/*   This is the Model( as in MVC architecture ) that determines the    transformation between user __time__ coordinates and the graphics    __pixel__ coordinates.  Since this classs is extended from the    DefaultBoundedRangeModel class which is then being used as    the model INSIDE the ScrollbarTime, JScrollBar, so the __pixel__    interface of this class is synchronized with that of ScrollbarTime    constantly during the program execution.  i.e.        ModelTime.getMinimum()  == ScrollbarTime.getMinimum()      ModelTime.getMaximum()  == ScrollbarTime.getMaximum()      ModelTime.getValue()    == ScrollbarTime.getValue()      ModelTime.getExtent()   == ScrollbarTime.getExtent()   All( or most ) accesses to this class should be through    the __time__ interface.  The only class that needs to access   the __pixel__ interface of this classs is the VIEW object   of the ViewportTime class.  i.e. method like      setViewPixelsPerUnitTime()      getViewPixelsPerUnitTime()      updatePixelCoords()   are accessed by RulerTime class.*/public class ModelTime extends DefaultBoundedRangeModel                       implements AdjustmentListener{    // private int    MAX_SCROLLBAR_PIXELS = Integer.MAX_VALUE;    /*        If DefaultBoundedRangeModel is used,        MAX_SCROLLBAR_PIXELS < Integer.MAX_VALUE / 2;        otherwise there will be overflow of DefaultBoundedRangeModel        when moving 1 block increment of scrollbar when zoom_level = 1    */    private int    MAX_SCROLLBAR_PIXELS = 1073741824;  // = 2^(30)    // user coordinates of the time axis of the viewport    private double tGlobal_min;    private double tGlobal_max;    private double tGlobal_extent;    private double tView_init;    private double tView_extent;    // previous value of tView_init;    private double old_tView_init;    // the zoom focus in user coodinates along the time axis of the viewport    private double tZoom_focus;    // the zoom focus in graphics pixel coodinates    private int    iZoom_focus;    // pixel coordinates of the time axis of the viewport    // are buried inside the superclass DefaultBoundedRangeModel    // screen properties    private int    iView_width = -1;    private double iViewPerTime;         // No. of View pixel per unit time    private double iScrollbarPerTime;    // No. of ScrollBar pixel per unit time    private double tZoomScale  = 1.0d;    private double tZoomFactor;    private double logZoomFactor;;    // special purpose ChangeListeners, TimeListeners, to avoid conflict with    // the EventListenerList, listenerList, in DefaultBoundedRangeModel    private ModelTimePanel     params_display;    private EventListenerList  time_listener_list;    // internal global variable for use in fireTimeChanged()    private TimeEvent          time_chg_evt;    private Window             root_window;    private JScrollBar         scrollbar;    private Stack              zoom_undo_stack;    private Stack              zoom_redo_stack;    public ModelTime( final Window  top_window,                            double  init_global_time,                            double  final_global_time )    {        params_display     = null;        time_chg_evt       = null;        time_listener_list = new EventListenerList();        zoom_undo_stack    = new Stack();        zoom_redo_stack    = new Stack();        root_window        = top_window;        setTimeGlobalMinimum( init_global_time );        setTimeGlobalMaximum( final_global_time );        setTimeZoomFocus();        tZoomFactor        = 2.0d;        logZoomFactor      = Math.log( tZoomFactor );    }    /*        None of the setTimeXXXXXX() functions updates the __Pixel__ coordinates    */    private void setTimeGlobalMinimum( double init_global_time )    {        tGlobal_min    = init_global_time;        old_tView_init = tGlobal_min;        tView_init     = tGlobal_min;    }    private void setTimeGlobalMaximum( double final_global_time )    {        tGlobal_max    = final_global_time;        tGlobal_extent = tGlobal_max - tGlobal_min;        tView_extent   = tGlobal_extent;        iScrollbarPerTime = (double) MAX_SCROLLBAR_PIXELS / tGlobal_extent;    }    // tGlobal_min & tGlobal_max cannot be changed by setTimeViewPosition()    private void setTimeViewPosition( double cur_view_init )    {        old_tView_init = tView_init;        if ( cur_view_init < tGlobal_min )            tView_init     = tGlobal_min;        else {            if ( cur_view_init > tGlobal_max - tView_extent )                tView_init     = tGlobal_max - tView_extent;            else                tView_init     = cur_view_init;        }    }    // tGlobal_min & tGlobal_max cannot be changed by setTimeViewExtent()    private void setTimeViewExtent( double cur_view_extent )    {        if ( cur_view_extent < tGlobal_extent ) {            tView_extent   = cur_view_extent;            if ( tView_init  > tGlobal_max - tView_extent ) {                old_tView_init  = tView_init;                tView_init      = tGlobal_max - tView_extent;            }        }        else {            tView_extent   = tGlobal_extent;            old_tView_init = tView_init;            tView_init     = tGlobal_min;        }    }    public double getTimeGlobalMinimum()    {        return tGlobal_min;    }    public double getTimeGlobalMaximum()    {        return tGlobal_max;    }    public double getTimeViewPosition()    {        return tView_init;    }    public double getTimeViewExtent()    {        return tView_extent;    }    /*       Set the Number of Pixels in the Viewport window.       if iView_width is NOT set, pixel coordinates cannot be updated.    */    public void setViewPixelsPerUnitTime( int width )    {        iView_width  = width;        iViewPerTime = iView_width / tView_extent;    }    public double getViewPixelsPerUnitTime()    {        return iViewPerTime;    }    public double computeTimeViewExtent( double time_per_pixel )    {        return iView_width * time_per_pixel;    }    /*       +1 : moving to the future, i.e. right       -1 : moving to the past  , i.e. left    */    public int getViewportMovingDir()    {        double tView_init_changed = tView_init - old_tView_init;        if ( tView_init_changed > 0.0 )            return 1;        else if ( tView_init_changed < 0.0 )            return -1;        else            return 0;    }    public void setScrollBar( JScrollBar sb )    {        scrollbar = sb;    }    public void removeScrollBar()    {        scrollbar = null;    }    public void setParamDisplay( ModelTimePanel tl )    {        params_display = tl;    }    public void removeParamDisplay( ModelTimePanel tl )    {        params_display = null;    }    private void updateParamDisplay()    {        if ( params_display != null ) {            if ( time_chg_evt == null )                time_chg_evt = new TimeEvent( this );            params_display.timeChanged( time_chg_evt );            params_display.zoomLevelChanged();        }    }    public void addTimeListener( TimeListener tl )    {        time_listener_list.add( TimeListener.class, tl );    }    public void removeTimeListener( TimeListener tl )    {        time_listener_list.remove( TimeListener.class, tl );    }    // Notify __ALL__ listeners that have registered interest for    // notification on this event type.  The event instance     // is lazily created using the parameters passed into     // the fire method.    protected void fireTimeChanged()    {        // Guaranteed to return a non-null array        Object[] listeners = time_listener_list.getListenerList();        // Process the listeners last to first, notifying        // those that are interested in this event        for ( int i = listeners.length-2; i>=0; i-=2 ) {            if ( listeners[i] == TimeListener.class ) {                // Lazily create the event:                if ( time_chg_evt == null )                    time_chg_evt = new TimeEvent( this );                ( (TimeListener) listeners[i+1] ).timeChanged( time_chg_evt );            }        }    }    /*       time2pixel() and pixel2time() are local to this object.       They have nothing to do the ones in ScrollableObject       (i.e. RulerTime/CanvasXXXXline).  In general, no one but       this object and possibly ScrollbarTime needs to access       the following time2pixel() and pixel2time() because the       ratio to flip between pixel and time is related to scrollbar.    */    private int time2pixel( double time_coord )    {        return (int) Math.round( ( time_coord - tGlobal_min )                               * iScrollbarPerTime );    }    private double pixel2time( int pixel_coord )    {        return (double) pixel_coord / iScrollbarPerTime                      + tGlobal_min;    }    private int timeRange2pixelRange( double time_range )    {        return (int) Math.round( time_range * iScrollbarPerTime );    }    private double pixelRange2timeRange( int pixel_range )    {        return (double) pixel_range / iScrollbarPerTime;    }    public void updatePixelCoords()    {        // super.setRangeProperties() calls super.fireStateChanged();        super.setRangeProperties( time2pixel( tView_init ),                                  timeRange2pixelRange( tView_extent ),                                  time2pixel( tGlobal_min ),                                  time2pixel( tGlobal_max ),                                  super.getValueIsAdjusting() );        // fireTimeChanged();    }    public void updateTimeCoords()    {        if ( iScrollbarPerTime > 0 ) {            tGlobal_min    = pixel2time( super.getMinimum() );            tGlobal_max    = pixel2time( super.getMaximum() );            tGlobal_extent = tGlobal_max - tGlobal_min;            old_tView_init = tView_init;            tView_init     = pixel2time( super.getValue() );            tView_extent   = pixelRange2timeRange( super.getExtent() );            updateParamDisplay();

⌨️ 快捷键说明

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