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

📄 viewmanager.java

📁 用来为垂直搜索引擎抓取数据的采集系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    {
        itsWebBrowser = new WebBrowser();
        
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        
        
        JToolBar toolbar = new JToolBar();
        toolbar.setFloatable( false );
        
        JLabel label = new JLabel( "地址: " );
//        itsField = new JTextField( "http://218.22.25.140/" );
        itsField = new JTextField( "http://www.chinannn.com" );
        itsGo = new JButton( "Go" );
        itsHome = new JButton( "Home" );
        itsBack = new JButton( "<=" );
        itsForward = new JButton( "=>" );
        itsStop = new JButton( "stop" );
        itsSource = new JButton( "source" );
        
        WebBrowserButtonAction webAction = new WebBrowserButtonAction();
        
        itsField.addKeyListener( new AddressKeyAction()  );
        
        itsGo.addActionListener( webAction );
        itsHome.addActionListener( webAction );
        itsBack.addActionListener( webAction );
        itsForward.addActionListener( webAction );
        itsStop.addActionListener( webAction );
        itsSource.addActionListener( webAction );
        
        toolbar.add( label );
        toolbar.add( itsField );
        toolbar.add( itsGo );
        toolbar.add( itsHome );
        toolbar.add( itsBack );
        toolbar.add( itsForward );
        toolbar.add( itsStop );
        toolbar.add( itsSource );
        
        final WebBrowser webBrowser = new WebBrowser();

        //Use below code to check the status of the navigation process,
        //or register a listener for the notification events.
        webBrowser.addWebBrowserListener(new WebBrowserListener()
        {
            boolean isFirstPage = true;
            public void downloadStarted(WebBrowserEvent event)
            {
            }
            public void downloadCompleted(WebBrowserEvent event)
            {
            }
            public void downloadProgress(WebBrowserEvent event)
            {
            }
            public void downloadError(WebBrowserEvent event)
            {
            }
            public void documentCompleted(WebBrowserEvent event)
            {
            }
            public void titleChange(WebBrowserEvent event)
            {
                System.out.println( "titleChanged");
            }

            public void statusTextChange(WebBrowserEvent event)
            {
                System.out.println( "statusTextChange");
            }
        });

        try
        {
            itsWebBrowser.setURL(new URL("http://218.22.25.140/"));
            // Below Chinese website tests unicode support.
            //webBrowser.setURL(new URL("http://www.google.com/intl/zh-CN/"));

            // Print out debug messages in the command line.
            //webBrowser.setDebug(true);
        } catch (MalformedURLException e)
        {
            System.out.println(e.getMessage());
            return;
        }

        panel.setMinimumSize( new Dimension(1,1) );
        panel.setPreferredSize(new Dimension(600, 500));
        panel.add( toolbar, BorderLayout.NORTH );
        panel.add( itsWebBrowser, BorderLayout.CENTER);

        ViewManager.getInstance().getTabbedPane().add( tabName, panel );

    }
    public WebBrowser getWebBrowser()
    {
        return itsWebBrowser;
    }
    /**
     * 对整个主显示界面进行布置,然后把各个模块综合到一起进行显示。
     * @return
     */
    public JPanel getMainPanel()
    {
        if( itsMainPanel==null )
        {
            itsMainPanel = new JPanel();

            JPanel contentPanel = new JPanel();
            contentPanel.setLayout( new BorderLayout() );
            
            ViewManager viewManager=null;
            viewManager = ViewManager.getInstance();
            
            JSplitPane sp1 = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT );
            
            JPanel treePanel = ViewManager.getInstance().createTreePanel();
            sp1.setLeftComponent( new JScrollPane(treePanel) );
            
            JTabbedPane tabbedPane = null;
            tabbedPane = ViewManager.getInstance().getTabbedPane();
            JSplitPane sp2 = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
            sp2.setTopComponent( tabbedPane );
            
            JSplitPane sp3 = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT );
            JPanel progressPanel = ViewManager.getInstance().createProgressPanel();
            JPanel detailPanel = ViewManager.getInstance().createDetailPanel();
            sp3.setLeftComponent( progressPanel );
            sp3.setRightComponent( detailPanel );
            
            sp2.setBottomComponent( sp3 );
            
            sp1.setRightComponent( sp2 );
            
            sp1.setOneTouchExpandable( true );
            sp2.setOneTouchExpandable( true );

            
            contentPanel.add( sp1, BorderLayout.CENTER );
            
            JMenuBar menubar = ViewManager.getInstance().createMenuBar();
            JToolBar toolbar = ViewManager.getInstance().createToolBar();
            
            
            JLabel statusLabel = new JLabel( "<html><body><h5>status...</h5></body></html>" );
            
            itsMainPanel.setLayout( new BorderLayout() );
            itsMainPanel.add( toolbar, BorderLayout.NORTH );
            itsMainPanel.add( contentPanel, BorderLayout.CENTER );
            itsMainPanel.add( statusLabel, BorderLayout.SOUTH );

            createPopupMenu();
        }
        return itsMainPanel;
    }
    private JTextArea itsNoticeArea=null;
    /**
     * 把str指定的内容,送到通知面板显示。
     * @param str
     */
    public void setNotice( String str )
    {
        if( str==null )
            return ;
        int count=str.length();

        StringBuffer buf = new StringBuffer();
        for( int i=0; i<count; i++ )
        {
            if( i!=0 && i%60==0 )
            {
                buf.append( "\n" );
            }
            buf.append( str.charAt(i) );
        }
        itsNoticeArea.setText( buf.toString() );

    }
    /**
     * 创建放置左边结构树的面板,然后把生成的树添加到面板中。
     * @return
     */
    private JPanel createTreePanel()
    {
        JPanel part=null;
        part = new JPanel();
        part.setLayout( new BorderLayout() );
        
//        itsRoot = new DefaultMutableTreeNode("抓取规则集合");
        itsRoot = new DefaultMutableTreeNode("Agent集合");
        DefaultTreeModel treeModel = new DefaultTreeModel( itsRoot );

        itsTree = new JTree();
        itsTree.setModel( treeModel );
        itsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
        itsTree.setExpandsSelectedPaths( true );

        part.add( itsTree, BorderLayout.CENTER );
        return part;
    }
/**
 * 生成弹出菜单,并添加相应的监听器。
 *
 */
    public void createPopupMenu()
    {
        // for tree
        JPopupMenu popup = new JPopupMenu();
        itsOpenRuleMenuItem = new JMenuItem("Open The Rule File");
        TreePopupAction popAction = new TreePopupAction();
        itsOpenRuleMenuItem.addActionListener( popAction );
        popup.add(itsOpenRuleMenuItem);

        JMenuItem menuItem=null;
        menuItem = new JMenuItem("Cancel");
        popup.add(menuItem);
        
        MouseListener popupListener = new PopupListener(popup);
        getInstance().getTree().addMouseListener(popupListener);
        
        // for tabbedpane
        JPopupMenu popupTab = new JPopupMenu();
        itsCloseTabMenuItem = new JMenuItem( "Close" );
        TabPopupAction tabPop = new TabPopupAction();
        itsCloseTabMenuItem.addActionListener( tabPop );
        popupTab.add( itsCloseTabMenuItem );
        popupTab.add( new JMenuItem("Cancel") );
        
        MouseListener popupListenerTab = new PopupListener(popupTab);
        getInstance().getTabbedPane().addMouseListener( popupListenerTab );
        
    }
    private JMenuItem itsCloseTabMenuItem=null;
    private JMenuItem itsOpenRuleMenuItem=null;
    public JMenuItem getColoseTabMenuItem()
    {
        return itsCloseTabMenuItem;
    }
    public JMenuItem getOpenRuleMenuItem()
    {
        return itsOpenRuleMenuItem;
    }
    /**
     * 弹出菜单监听器,当弹出菜单有相应的行为时,调用相应的函数。
     * @author wbz
     *
     */
    class PopupListener extends MouseAdapter
    {
        JPopupMenu popup;
        PopupListener(JPopupMenu popupMenu)
        {
            popup = popupMenu;
        }

        public void mousePressed(MouseEvent e)
        {
//            maybeShowPopup(e);
        }

        public void mouseReleased(MouseEvent e)
        {
            maybeShowPopup(e);
        }

        private void maybeShowPopup(MouseEvent e)
        {
            if (e.isPopupTrigger())
            {
                popup.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    }
    /**
     * 创建左右栏的分隔标签,此标签在一个面板上显示。
     * @return
     */
    private JPanel createProgressPanel()
    {
        JPanel part=null;
        part = new JPanel();
        part.add( new JLabel( "<html><body><h2>IIM Lab</h2></body></html>") );
        
        return part;
    }
    /**
     * 创建详细信息显示面板。
     * @return
     */
    private JPanel createDetailPanel()
    {
        JPanel part = new JPanel();
        part.setLayout( new BorderLayout() );
        itsNoticeArea = new JTextArea( "Notice" );
        part.add( new JScrollPane(itsNoticeArea), BorderLayout.CENTER );
        
        return part;
    }
    /**
     * 创建工具栏
     * @return
     */
    private JToolBar createToolBar()
    {
        int count=3,i;
        String [] iconsFile={"start.jpeg", "stop.jpeg", "about3.jpg"};

        JToolBar toolBar = new JToolBar();
        toolBar.setFloatable( false );
        JButton[] buttons = new JButton[count];
        JButton flush=new JButton("刷新");
        for( i=0; i<count; i++ )
        {
            iconsFile[i] = "icons/" + iconsFile[i];
            buttons[i] = new JButton( new ImageIcon(iconsFile[i]) );
            toolBar.add( buttons[i] );
        }
        toolBar.add(flush);
        buttons[0].addActionListener( new RunAction() );
        flush.addActionListener(new FlushAction());
        return toolBar;
    }
/**
 * 创建菜单和菜单项。
 * @return
 */
    private JMenuBar createMenuBar()
    {
        JMenuBar menuBar = new JMenuBar( );
        JMenu menuFile = new JMenu( "File" );
        JMenuItem menuItem = null;
        menuItem = new JMenuItem( "Exit" );
        menuFile.add( menuItem );
        
        JMenu menuHelp = new JMenu( "Help" );
        menuItem = new JMenuItem( "About" );
        menuHelp.add( menuItem );
        
        menuBar.add( menuFile );
        menuBar.add( menuHelp );
        
        return menuBar;
    }
   
    
    
}

⌨️ 快捷键说明

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