📄 functionview.java
字号:
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( xZoomFactorComboBox, gbc ); xZoomPanel.add( xZoomFactorComboBox ); //---- Y zoom panel JPanel yZoomPanel = new JPanel( gridBag ); yZoomPanel.setBackground( backgroundColour ); gridX = 0; // Label: y zoom JLabel yZoomLabel = new FLabel( Y_ZOOM_STR ); gbc.gridx = gridX++; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.LINE_END; gbc.fill = GridBagConstraints.NONE; gbc.insets = AppConstants.COMPONENT_INSETS; gridBag.setConstraints( yZoomLabel, gbc ); yZoomPanel.add( yZoomLabel ); // Panel: y zoom buttons JPanel yZoomButtonPanel = new JPanel( new GridLayout( 1, 0, 4, 0 ) ); GuiUtilities.setPaddedLineBorder( yZoomButtonPanel, 4 ); yZoomButtonPanel.setBackground( scrollZoomBackgroundColour ); yZoomButtonPanel.add( new ZoomButton( FunctionDocument.Command.Y_ZOOM_IN ) ); yZoomButtonPanel.add( new ZoomButton( FunctionDocument.Command.Y_ZOOM_OUT ) ); 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( yZoomButtonPanel, gbc ); yZoomPanel.add( yZoomButtonPanel ); // Combo box: y zoom factor yZoomFactorComboBox = new FComboBox( ZOOM_FACTOR_STRS ); yZoomFactorComboBox.setSelectedItem( yZoomFactorStr ); yZoomFactorComboBox.setActionCommand( Command.SELECT_Y_ZOOM_FACTOR ); yZoomFactorComboBox.addActionListener( this ); 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( yZoomFactorComboBox, gbc ); yZoomPanel.add( yZoomFactorComboBox ); //---- Zoom panel JPanel zoomPanel = new JPanel( gridBag ); zoomPanel.setBorder( BorderFactory.createEmptyBorder( 2, 0, 2, 0 ) ); zoomPanel.setBackground( backgroundColour ); gridY = 0; gbc.gridx = 0; gbc.gridy = gridY++; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.5; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.LINE_END; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets( 0, 0, 0, 0 ); gridBag.setConstraints( xZoomPanel, gbc ); zoomPanel.add( xZoomPanel ); gbc.gridx = 0; gbc.gridy = gridY++; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.5; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.LINE_END; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets( 0, 0, 0, 0 ); gridBag.setConstraints( yZoomPanel, gbc ); zoomPanel.add( yZoomPanel ); //---- Scroll/zoom panel JPanel scrollZoomPanel = new JPanel( gridBag ); GuiUtilities.setPaddedLineBorder( scrollZoomPanel, 4, 6 ); scrollZoomPanel.setBackground( backgroundColour ); gridX = 0; gbc.gridx = gridX++; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.5; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets( 0, 0, 0, 0 ); gridBag.setConstraints( scrollPanel, gbc ); scrollZoomPanel.add( scrollPanel ); gbc.gridx = gridX++; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.5; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets( 0, 8, 0, 0 ); gridBag.setConstraints( zoomPanel, gbc ); scrollZoomPanel.add( zoomPanel ); //---- Control panel JPanel controlPanel = new JPanel( gridBag ); controlPanel.setBackground( backgroundColour ); gridY = 0; gbc.gridx = 0; gbc.gridy = gridY++; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.NORTH; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets( 0, 0, 0, 0 ); gridBag.setConstraints( functionPanel, gbc ); controlPanel.add( functionPanel ); gbc.gridx = 0; gbc.gridy = gridY++; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.NORTH; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets( 3, 0, 0, 0 ); gridBag.setConstraints( coordPanel, gbc ); controlPanel.add( coordPanel ); gbc.gridx = 0; gbc.gridy = gridY++; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.NORTH; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets( 3, 0, 0, 0 ); gridBag.setConstraints( intervalPanel, gbc ); controlPanel.add( intervalPanel ); gbc.gridx = 0; gbc.gridy = gridY++; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.NORTH; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets( 3, 0, 0, 0 ); gridBag.setConstraints( scrollZoomPanel, gbc ); controlPanel.add( scrollZoomPanel ); //---- Main panel setLayout( gridBag ); setBorder( BorderFactory.createEmptyBorder( 2, 2, 2, 2 ) ); setBackground( backgroundColour ); gbc.gridx = 0; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.NORTH; gbc.fill = GridBagConstraints.VERTICAL; gbc.insets = new Insets( 0, 0, 0, 0 ); gridBag.setConstraints( plotPanel, gbc ); add( plotPanel ); gbc.gridx = 1; gbc.gridy = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.anchor = GridBagConstraints.NORTH; gbc.fill = GridBagConstraints.NONE; gbc.insets = new Insets( 0, 3, 0, 0 ); gridBag.setConstraints( controlPanel,gbc ); add( controlPanel ); // Set orientation of components according to locale, except scroll buttons App.applyOrientationByLocale( this ); scrollPanel.applyComponentOrientation( ComponentOrientation.LEFT_TO_RIGHT ); // Add listener addMouseListener( this ); // Add key actions KeyAction.create( this, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, KeyStroke.getKeyStroke( KeyEvent.VK_CONTEXT_MENU, 0 ), Command.SHOW_POP_UP_MENU, this ); if ( App.getInstance( ).isApplet( ) ) KeyAction.create( this, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, APPLET_VIEW_KEY_ACTIONS ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Class methods//////////////////////////////////////////////////////////////////////// public static double getXZoomFactor( ) { return Double.parseDouble( xZoomFactorStr ); } //------------------------------------------------------------------ public static double getYZoomFactor( ) { return Double.parseDouble( yZoomFactorStr ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods : ActionListener interface//////////////////////////////////////////////////////////////////////// public void actionPerformed( ActionEvent event ) { try { String command = Util.mapString( COMMAND_MAP, event.getActionCommand( ) ); String methodName = AppConstants.COMMAND_METHOD_PREFIX + command.substring( 0, 1 ).toUpperCase( ) + command.substring( 1 ); Util.getDeclaredMethod( getClass( ), methodName, false ).invoke( this ); } catch ( InvocationTargetException e ) { if ( e.getCause( ) instanceof AppException ) App.getInstance( ).showErrorMessage( App.SHORT_NAME, e.getCause( ) ); else { System.err.println( e ); e.getCause( ).printStackTrace( ); } } catch ( Exception e ) { e.printStackTrace( ); } } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods : ChangeListener interface//////////////////////////////////////////////////////////////////////// public void stateChanged( ChangeEvent event ) { Object eventSource = event.getSource( ); if ( eventSource == plotPanel ) { updateIntervalFields( ); updateMouseCursorCoords( ); } else if ( eventSource == functionListScrollPane.getVerticalScrollBar( ).getModel( ) ) { if ( !functionListScrollPane.getVerticalScrollBar( ).getValueIsAdjusting( ) && !functionList.isDragging( ) ) functionList.snapViewPosition( ); } } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods : ListSelectionListener interface//////////////////////////////////////////////////////////////////////// public void valueChanged( ListSelectionEvent event ) { if ( !event.getValueIsAdjusting( ) ) updateButtons( ); } //------------------------------------------------------------------////////////////////////////////////////////////////////////////////////// Instance methods : MouseListener interface//////////////////////////////////////////////////////////////////////// public void mouseClicked( MouseEvent event ) { // do nothing } //------------------------------------------------------------------ public void mouseEntered( MouseEvent event ) { if ( event.getComponent( ) == plotPanel ) updateMouseCursorCoords( event ); } //------------------------------------------------------------------ public void mouseExited( MouseEvent event ) { if ( event.getComponent( ) == plotPanel ) updateMouseCursorCoords( (MouseEvent)null ); } //------------------------------------------------------------------ public void mousePressed( MouseEvent event ) { if ( SwingUtilities.isLeftMouseButton( event ) ) { if ( event.getComponent( ) == plotPanel ) { dragStart = new DragStart( event.getX( ), event.getY( ), document.getXInterval( ), document.getYInterval( ) ); plotPanel.setCursor( true ); } } showPopUpMenu( event ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -