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

📄 goto.java

📁 简单的java文本编辑器
💻 JAVA
字号:
/*************************************************************************************
* 类名: Goto                                                               
*                                                                    
* 功能: 此类为”goto对话框“的实现类
*                                                                
**************************************************************************************/
package edit.com;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

class Goto extends JPanel
{
    private JPanel centerPanel;
    private JLabel gotoLabel;
    private JTextField gotoText;
    private JButton okButton;
    private JButton cancelButton;
    private JDialog dialog;
    private GotoSet gotoSet ;
    private GotoTools tool = new GotoTool();

    public Goto( String s , int total )
    {
        gotoSet = new GotoSet( s , total );
        setLayout( new BorderLayout() );
        centerPanel = new JPanel();
        addToCenterPanel( centerPanel );
    }

    public Goto() {
        gotoSet = new GotoSet();
        setLayout( new BorderLayout() );
        centerPanel = new JPanel();
        addToCenterPanel( centerPanel );
    }

    public void setString( String s )
    {
    	gotoSet.setSourceString( s );
    }

    public void setTotalLine( int total ) {
        gotoSet.setTotalLine( total );
    }

    public int getFindPosition() {
        return gotoSet.getLineFind();
    }

    public GotoSet getSet() {
        return gotoSet;
    }


    public boolean showDialog( Component c , String s )
    {
    	gotoSet.setFlag( false );

    	Frame owner = null;

    	if( c instanceof Frame )
    	{
    		owner = ( Frame )c;
    	}
    	else
    	{
    		owner = ( Frame )SwingUtilities.getAncestorOfClass( Frame.class , c );
    	}

    	if( dialog == null || dialog.getOwner() != owner )
    	{
            owner = null;
            dialog = new JDialog( owner , true );
            dialog.getContentPane().add( this );
            dialog.setResizable( false );
            dialog.setSize( 300 , 150 );
    	}

    	dialog.setTitle( s );
        dialog.show();

        return gotoSet.getFlag();
    }

    private void addToCenterPanel( JPanel aPanel )
    {
    	aPanel.setLayout( new GridBagLayout() );

    	GridBagConstraints constraint = new GridBagConstraints();

    	gotoLabel = tool.createLael( "Goto : " ,
                                     new Font( null , Font.BOLD , 12 ),
                                     Color.blue );

    	gotoText = tool.createText( new Dimension( 100 , 25 ),
                                    new Dimension( 100 , 25 ) );

    	okButton = tool.createButton( "    O k    ",
                                      new Font( null , Font.BOLD , 12 ),
                                      Color.orange ,
                                      new OkListener() );

    	cancelButton = tool.createButton( "Cancel",
                                          new Font( null , Font.BOLD , 12 ),
                                          Color.orange,
                                          new CancelListener() );

    	Box temBox_2 = tool.createHorizontalBox( 20 );

    	Box buttonBox = Box.createVerticalBox();
    	buttonBox.add( okButton );
    	buttonBox.add( cancelButton );

    	tool.addToCenterWithConstraint( gotoLabel , constraint , aPanel, 0 , 0 , 1 , 1 , GridBagConstraints.NONE ,
    			GridBagConstraints.WEST );
    	tool.addToCenterWithConstraint( gotoText , constraint , aPanel, 1 , 0 , 1 , 1 , GridBagConstraints.HORIZONTAL ,
    			GridBagConstraints.CENTER );
        tool.addToCenterWithConstraint( temBox_2 , constraint , aPanel, 2 , 0 , 1 , 1 , GridBagConstraints.NONE ,
    			GridBagConstraints.WEST );
        tool.addToCenterWithConstraint( buttonBox , constraint , aPanel, 3 , 0 , 1 , 4 , GridBagConstraints.NONE ,
    			GridBagConstraints.WEST );

        add( aPanel , BorderLayout.CENTER );

   }

//private class defined
    private class OkListener implements ActionListener
    {
    	public void actionPerformed( ActionEvent a )
    	{
            gotoSet.setFlag( true );
            tool.findLine( Goto.this, gotoSet , gotoText.getText());
            dialog.setVisible( false );
    	}
    }

	private class CancelListener implements ActionListener
	{
		public void actionPerformed( ActionEvent a )
		{
		    dialog.setVisible( false );
		}
	}
}


⌨️ 快捷键说明

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