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

📄 functionview.java

📁 FuncPlotter is a combined Java application and applet for displaying two-dimensional plots of explic
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    ////////////////////////////////////////////////////////////////////    //  Instance methods : overriding methods    ////////////////////////////////////////////////////////////////////        public Dimension getPreferredSize( )        {            return new Dimension( width, height );        }        //--------------------------------------------------------------        protected void paintComponent( Graphics gr )        {            // Draw background            Rectangle rect = gr.getClipBounds( );            gr.setColor( BACKGROUND_COLOUR );            gr.fillRect( rect.x, rect.y, rect.width, rect.height );            // Draw x/y background            boolean leftToRight = getComponentOrientation( ).isLeftToRight( );            int x = leftToRight ? 0 : getWidth( ) - LEADING_MARGIN - charWidth - GAP / 2;            gr.setColor( X_Y_BACKGROUND_COLOUR );            gr.fillRect( x, rect.y, LEADING_MARGIN + charWidth + GAP / 2, rect.height );            // Draw text            FontMetrics fontMetrics = gr.getFontMetrics( );            x += leftToRight ? LEADING_MARGIN : GAP / 2;            int y1 = TOP_MARGIN + fontMetrics.getAscent( );            int y2 = y1 + fontMetrics.getHeight( );            gr.setColor( FOREGROUND_COLOUR );            gr.drawString( "x", x, y1 );            gr.drawString( "y", x, y2 );            if ( text1 != null )            {                int x1 = leftToRight ? x + charWidth + GAP : x - GAP - fontMetrics.stringWidth( text1 );                gr.drawString( text1, x1, y1 );            }            if ( text2 != null )            {                int x1 = leftToRight ? x + charWidth + GAP : x - GAP - fontMetrics.stringWidth( text2 );                gr.drawString( text2, x1, y2 );            }            // Draw border            gr.setColor( BORDER_COLOUR );            gr.drawRect( 0, 0, getWidth( ) - 1, getHeight( ) - 1 );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods    ////////////////////////////////////////////////////////////////////        public void setText( String text1,                             String text2 )        {            this.text1 = text1;            this.text2 = text2;            repaint( );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        private int     width;        private int     height;        private int     charWidth;        private String  text1;        private String  text2;    }    //==================================================================    // INTERVAL ENDPOINT FIELD CLASS    private static class EndpointField        extends ConstrainedTextField    {    ////////////////////////////////////////////////////////////////////    //  Constants    ////////////////////////////////////////////////////////////////////        private static final    int NUM_COLUMNS = 12;        private static final    String  VALID_CHARS = "+-.0123456789E";    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private EndpointField( int maxLength )        {            super( maxLength, NUM_COLUMNS );            AppFont.TEXT_FIELD.setFont( this );            GuiUtilities.setHorizontalMargins( this, AppConstants.TEXT_FIELD_MARGIN );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods : overriding methods    ////////////////////////////////////////////////////////////////////        protected int getColumnWidth( )        {            return ( GuiUtilities.getCharWidth( '0', getFontMetrics( getFont( ) ) ) + 1 );        }        //--------------------------------------------------------------        protected String translateInsertString( String str,                                                int    offset )        {            return str.toUpperCase( );        }        //--------------------------------------------------------------        protected char validateCharacter( char ch,                                          int  index )        {            return ( (VALID_CHARS.indexOf( ch ) < 0) ? TextFieldConstants.INVALID_CHAR : ch );        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance methods    ////////////////////////////////////////////////////////////////////        public BigDecimal getValue( )            throws NumberFormatException        {            return new BigDecimal( getText( ) );        }        //--------------------------------------------------------------    }    //==================================================================    // DRAG START CLASS    private static class DragStart    {    ////////////////////////////////////////////////////////////////////    //  Constructors    ////////////////////////////////////////////////////////////////////        private DragStart( int          x,                           int          y,                           PlotInterval xInterval,                           PlotInterval yInterval )        {            this.x = x;            this.y = y;            this.xInterval = xInterval;            this.yInterval = yInterval;        }        //--------------------------------------------------------------    ////////////////////////////////////////////////////////////////////    //  Instance variables    ////////////////////////////////////////////////////////////////////        int             x;        int             y;        PlotInterval    xInterval;        PlotInterval    yInterval;    }    //==================================================================//////////////////////////////////////////////////////////////////////////  Constructors////////////////////////////////////////////////////////////////////////    public FunctionView( FunctionDocument document )    {        // Initialise instance variables        this.document = document;        // Initialise dimensions of plot and function list        AppConfig config = AppConfig.getInstance( );        if ( plotSize == null )            plotSize = new Dimension( config.getPlotSize( ) );        if ( functionListSize == null )            functionListSize = new Dimension( config.getFunctionListSize( ) );        // Get background colour        Color backgroundColour = config.getBackgroundColour( );;        //----  Plot panel        plotPanel = new PlotPanel( document, plotSize.width + 1, plotSize.height + 1 );        plotPanel.setBackground( backgroundColour );        plotPanel.addChangeListener( this );        plotPanel.addMouseListener( this );        plotPanel.addMouseMotionListener( this );        plotPanel.addMouseWheelListener( this );        KeyAction.create( plotPanel, JComponent.WHEN_FOCUSED, PLOT_PANEL_KEY_ACTIONS );        //----  Function list        // Function list        functionList = new FunctionList( document, functionListSize.width, functionListSize.height );        functionList.addActionListener( this );        functionList.addListSelectionListener( this );        functionList.addMouseListener( this );        KeyAction.create( functionList, JComponent.WHEN_FOCUSED,                          KeyStroke.getKeyStroke( KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK ),                          FunctionDocument.Command.COPY_FUNCTION );        // Scroll pane: function list        functionListScrollPane =                            new JScrollPane( functionList,                                             (functionListSize.height < FunctionDocument.MAX_NUM_FUNCTIONS)                                                                    ? JScrollPane.VERTICAL_SCROLLBAR_ALWAYS                                                                    : JScrollPane.VERTICAL_SCROLLBAR_NEVER,                                             JScrollPane.HORIZONTAL_SCROLLBAR_NEVER );        functionListScrollPane.setWheelScrollingEnabled( false );        functionListScrollPane.getVerticalScrollBar( ).setFocusable( false );        functionListScrollPane.getVerticalScrollBar( ).getModel( ).addChangeListener( this );        functionList.setViewport( functionListScrollPane.getViewport( ) );        //----  Function command button panel        GridBagLayout gridBag = new GridBagLayout( );        GridBagConstraints gbc = new GridBagConstraints( );        JPanel functionButtonPanel = new JPanel( gridBag );        functionButtonPanel.setBorder( BorderFactory.createEmptyBorder( 0, 4, 0, 4 ) );        functionButtonPanel.setBackground( backgroundColour );        int gridX = 0;        // Reset button width        FunctionButton.reset( );        // Button: add        addButton = new FunctionButton( FunctionDocument.Command.ADD_FUNCTION );        addButton.setMnemonic( KeyEvent.VK_A );        gbc.gridx = gridX++;        gbc.gridy = 0;        gbc.gridwidth = 1;        gbc.gridheight = 1;        gbc.weightx = 0.0;        gbc.weighty = 0.0;        gbc.anchor = GridBagConstraints.LINE_START;        gbc.fill = GridBagConstraints.NONE;        gbc.insets = AppConstants.COMPONENT_INSETS;        gridBag.setConstraints( addButton, gbc );        functionButtonPanel.add( addButton );        // Button: edit        JButton editButton = new FunctionButton( FunctionDocument.Command.EDIT_FUNCTION );        editButton.setMnemonic( KeyEvent.VK_T );        gbc.gridx = gridX++;        gbc.gridy = 0;        gbc.gridwidth = 1;        gbc.gridheight = 1;        gbc.weightx = 0.0;        gbc.weighty = 0.0;        gbc.anchor = GridBagConstraints.LINE_START;        gbc.fill = GridBagConstraints.NONE;        gbc.insets = AppConstants.COMPONENT_INSETS;        gridBag.setConstraints( editButton, gbc );        functionButtonPanel.add( editButton );        // Button: copy        JButton copyButton = new FunctionButton( FunctionDocument.Command.COPY_FUNCTION );        copyButton.setMnemonic( KeyEvent.VK_C );        gbc.gridx = gridX++;        gbc.gridy = 0;        gbc.gridwidth = 1;        gbc.gridheight = 1;        gbc.weightx = 0.0;        gbc.weighty = 0.0;        gbc.anchor = GridBagConstraints.LINE_START;        gbc.fill = GridBagConstraints.NONE;        gbc.insets = AppConstants.COMPONENT_INSETS;        gridBag.setConstraints( copyButton, gbc );        functionButtonPanel.add( copyButton );        // Button: undo        if ( App.getInstance( ).isApplet( ) )        {            JComponent filler = GuiUtilities.createFiller( 8, 1 );            gbc.gridx = gridX++;            gbc.gridy = 0;            gbc.gridwidth = 1;            gbc.gridheight = 1;            gbc.weightx = 0.0;            gbc.weighty = 0.0;            gbc.anchor = GridBagConstraints.LINE_START;            gbc.fill = GridBagConstraints.NONE;            gbc.insets = AppConstants.COMPONENT_INSETS;            gridBag.setConstraints( filler, gbc );            functionButtonPanel.add( filler );            JButton undoButton = new FunctionButton( FunctionDocument.Command.UNDO );            undoButton.setMnemonic( KeyEvent.VK_U );            gbc.gridx = gridX++;            gbc.gridy = 0;            gbc.gridwidth = 1;            gbc.gridheight = 1;            gbc.weightx = 0.0;            gbc.weighty = 0.0;            gbc.anchor = GridBagConstraints.LINE_START;            gbc.fill = GridBagConstraints.NONE;            gbc.insets = AppConstants.COMPONENT_INSETS;            gridBag.setConstraints( undoButton, gbc );            functionButtonPanel.add( undoButton );        }        gridX = 0;        // Button: hide/show        JButton hideShowButton = new FunctionButton( FunctionDocument.Command.HIDE_SHOW_FUNCTION );        hideShowButton.setMnemonic( KeyEvent.VK_H );        gbc.gridx = gridX++;        gbc.gridy = 1;        gbc.gridwidth = 1;        gbc.gridheight = 1;        gbc.weightx = 0.0;        gbc.weighty = 0.0;        gbc.anchor = GridBagConstraints.LINE_START;        gbc.fill = GridBagConstraints.NONE;        gbc.insets = AppConstants.COMPONENT_INSETS;        gridBag.setConstraints( hideShowButton, gbc );        functionButtonPanel.add( hideShowButton );        // Button: delete        deleteButton = new FunctionButton( FunctionDocument.Command.DELETE_FUNCTION );        deleteButton.setMnemonic( KeyEvent.VK_D );        gbc.gridx = gridX++;

⌨️ 快捷键说明

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