📄 mainwindow.java
字号:
/* * Created on 28-nov-2005 * * * *//** * @author magowiz * */package gui;import java.util.StringTokenizer;import java.io.*;import java.net.*;import java.io.IOException;import java.io.InputStream;import java.net.URL;import java.net.MalformedURLException;import java.awt.Component;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.util.Calendar;import java.util.TimeZone;import catalog_search.CatalogSearchResponse;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTabbedPane;import javax.swing.JTable;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.JProgressBar;import javax.swing.table.DefaultTableModel;import p2p_system.AddBCEvt;import p2p_system.AddedBCEvt;import p2p_system.BCInterfListener;import p2p_system.BookmarkedCatalogItem;import p2p_system.BookmarkedCatalogs;import p2p_system.DelBCEvt;import p2p_system.DeletedBCEvt;import p2p_system.Peer;import javax.swing.event.TableModelEvent;import javax.swing.JCheckBox;import java.awt.Dimension;public class MainWindow implements BCInterfListener{ private BookmarkedCatalogs bcs; // @jve:decl-index=0: private Peer p; private String[] cname; private String [] clabel; private DefaultTableModel dtm=null; private DefaultTableModel dtm2=null; private JPanel jContentPane = null; private JFrame MainWindowFrame = null; // @jve:decl-index=0:visual-constraint="-22,47" private JTabbedPane jTabbedPane = null; private JPanel SearchPanel = null; private JButton SearchButton = null; private JLabel titleLabel = null; private JLabel DescriptionLabel = null; private JTextField TitleTextField = null; private JTextField DescriptionTextField = null; private JPanel CatalogListPanel = null; private JPanel ButtonPanel = null; private JPanel InputCatalogPanel = null; private JButton addButton = null; private JButton deleteButton = null; private JLabel Label = null; private JTextField LabelTextField = null; private JTextField UrlTextField = null; private JLabel UrlLabel = null; private JPanel LogPanel = null; private JButton ClearButton = null; private JScrollPane LogScrollPane = null; private JTextArea LogTextArea = null; private JScrollPane CatalogListScrollPane = null; private JTable CatalogListTable = null; private JPanel SearchResultPanel = null; private JTable CatalogSearchResultTable = null; private JScrollPane jScrollPane = null; private JPanel CatalogSelectPanel = null; private JLabel CatSearchLabel = null; private JCheckBox OtherWebCheckBox = null; private JCheckBox []cats=null; private JPanel jPanel = null; private JPanel LocalCatalogPanel = null; private JLabel LocalCatalogTitleLabel = null; private JTextField LocalCatalogTitleTextField = null; private JLabel LocalCatalogDescriptionLabel = null; private JTextField LocalCatalogDescriptionTextField = null; private JLabel LocalCatalogUrlLabel = null; private JTextField LocalCatalogUrlTextField = null; private JButton InsertButton = null; private JCheckBox LocalPeerCheckBox = null; private JCheckBox OtherPeerCheckBox = null; private JCheckBox DownloadFileCheckBox = null; private int nres=0; /** * This method initializes jContentPane * * @return javax.swing.JPanel */ private JPanel getJContentPane() { if (jContentPane == null) { jContentPane = new JPanel(); jContentPane.setLayout(new BoxLayout(jContentPane, BoxLayout.X_AXIS)); jContentPane.add(getJTabbedPane(), null); } return jContentPane; } /** * This method initializes jFrame * * @return javax.swing.JFrame */ private JFrame getJFrame() { if (MainWindowFrame == null) { MainWindowFrame = new JFrame(); //System.out.println(MainWindowFrame.toString()); MainWindowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MainWindowFrame.setContentPane(getJContentPane()); MainWindowFrame.setTitle("JxtASK - Knowledge Sharing W2P"); MainWindowFrame.setSize(615, 335); } return MainWindowFrame; } /** * This method initializes jTabbedPane * * @return javax.swing.JTabbedPane */ private JTabbedPane getJTabbedPane() { if (jTabbedPane == null) { jTabbedPane = new JTabbedPane(); jTabbedPane.addTab("Local Catalog", null, getLocalCatalogPanel(), null); jTabbedPane.addTab("Catalog List", null, getCatalogListPanel(), null); jTabbedPane.addTab("Search", null, getSearchPanel(), null); jTabbedPane.addTab("Catalog Select", null, getCatalogSelectPanel(), null); jTabbedPane.addTab("Search Results", null, getSearchResultPanel(), null); jTabbedPane.addTab("Log", null, getLogPanel(), null); } return jTabbedPane; } /** * This method initializes jPanel * * @return javax.swing.JPanel */ private JPanel getSearchPanel() { if (SearchPanel == null) { GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); gridBagConstraints1.gridx = -1; gridBagConstraints1.gridy = -1; GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); DescriptionLabel = new JLabel(); titleLabel = new JLabel(); GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); GridBagConstraints gridBagConstraints12 = new GridBagConstraints(); SearchPanel = new JPanel(); SearchPanel.setLayout(new GridBagLayout()); SearchPanel.setName("Search"); titleLabel.setText("Title"); gridBagConstraints6.gridx = 0; gridBagConstraints6.gridy = 1; gridBagConstraints6.gridheight = 1; gridBagConstraints6.gridwidth = 1; gridBagConstraints6.fill = java.awt.GridBagConstraints.NONE; gridBagConstraints6.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints7.gridx = 0; gridBagConstraints7.gridy = 2; gridBagConstraints7.anchor = java.awt.GridBagConstraints.NORTHWEST; SearchPanel.setMinimumSize(new java.awt.Dimension(200,200)); gridBagConstraints11.gridx = 1; gridBagConstraints11.gridy = 1; gridBagConstraints11.weightx = 1.0; gridBagConstraints11.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints12.gridx = 1; gridBagConstraints12.gridy = 2; gridBagConstraints12.weightx = 1.0; gridBagConstraints12.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints12.ipady = 40; gridBagConstraints4.gridx = 0; gridBagConstraints4.gridy = 3; gridBagConstraints4.gridwidth = 2; gridBagConstraints4.gridheight = 1; DescriptionLabel.setText("Description"); gridBagConstraints2.gridx = -1; gridBagConstraints2.gridy = -1; gridBagConstraints2.weightx = 1.0; gridBagConstraints2.weighty = 1.0; gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH; SearchPanel.add(titleLabel, gridBagConstraints6); SearchPanel.add(getTitleTextField(), gridBagConstraints11); SearchPanel.add(getDescriptionTextField(), gridBagConstraints12); SearchPanel.add(DescriptionLabel, gridBagConstraints7); SearchPanel.add(getSearchButton(), gridBagConstraints4); } return SearchPanel; } /** * This method initializes jButton * * @return javax.swing.JButton */ private JButton getSearchButton() { if (SearchButton == null) { SearchButton = new JButton(); SearchButton.setText("Search"); SearchButton.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR)); SearchButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { if((!TitleTextField.getText().equals(""))||(!DescriptionTextField.getText().equals(""))){ nres=0; boolean ow=OtherWebCheckBox.isSelected(); boolean op=OtherPeerCheckBox.isSelected(); boolean lc=LocalPeerCheckBox.isSelected(); String [] a = new String[2]; a[0]=TitleTextField.getText(); a[1]=DescriptionTextField.getText(); String[] c=null; int count=0; for(int i=0;i<cname.length;i++) { if(cats[i].isSelected()) count++; } c=new String[count]; int x=0; for(int i=0;i<cname.length;i++) { if(cats[i].isSelected()) { c[x]=cname[i]; x++; } } if((!op)&&(!ow)&&(!lc)&&(x==0)) { JOptionPane.showMessageDialog(null, "You must select at least one item in Catalog Select tab.", "Warning: No catalogs selected", JOptionPane.WARNING_MESSAGE); } else { p2p_system.SearchEvt se=new p2p_system.SearchEvt(this,a[0],a[1],c,ow,op,lc); p.search(se); } } else{JOptionPane.showMessageDialog(null, "You must insert at least one of Title and Description.", "Warning: Invalid Search terms", JOptionPane.WARNING_MESSAGE);} } }); } return SearchButton; } /** * This method initializes jTextField * * @return javax.swing.JTextField */ private JTextField getTitleTextField() { if (TitleTextField == null) { TitleTextField = new JTextField(); } return TitleTextField; } /** * This method initializes jTextField1 * * @return javax.swing.JTextField */ private JTextField getDescriptionTextField() { if (DescriptionTextField == null) { DescriptionTextField = new JTextField(); } return DescriptionTextField; } public void init(Peer q,BookmarkedCatalogs bc) { p=q; bcs=bc; JFrame mw=this.getJFrame(); Object [] cn={"Label","Name","URL","Status"}; Object [] csr={"Title","Description","Url","Catalog Name"}; dtm= new DefaultTableModel(cn,0); dtm2= new DefaultTableModel(csr,0); CatalogListTable.setModel(dtm); CatalogSearchResultTable.setModel(dtm2); if(bcs.getCatalogsNumber()!=0) fillCatListTable(); System.out.println(" "); mw.pack(); mw.show(); } private void fillCatListTable() { int cN=bcs.getCatalogsNumber(); BookmarkedCatalogItem bci=null; cname= new String[cN]; clabel=new String[cN]; cats=new JCheckBox[cN]; for(int i=0;i<cN;i++) { bci=bcs.getItem(i); Object [] r={bci.getCatalogLabel(),bci.getCatalogName(),bci.getCatalogUrl(),"Waiting"}; dtm.addRow(r); clabel[i]=new String(r[0].toString()); cname[i]=new String(r[1].toString()); cats[i]=new JCheckBox(clabel[i]); jPanel.add(cats[i]); } } /** * This method initializes jPanel * * @return javax.swing.JPanel */ private JPanel getCatalogListPanel() { if (CatalogListPanel == null) { GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); GridBagConstraints gridBagConstraints38 = new GridBagConstraints(); GridBagConstraints gridBagConstraints37 = new GridBagConstraints(); CatalogListPanel = new JPanel(); CatalogListPanel.setLayout(new GridBagLayout()); gridBagConstraints37.gridx = 1; gridBagConstraints37.gridy = 0; gridBagConstraints37.ipadx = 50; gridBagConstraints37.ipady = 275; gridBagConstraints38.gridx = 2; gridBagConstraints38.gridy = 0; gridBagConstraints38.ipadx = 5; gridBagConstraints3.weightx = 1.0; gridBagConstraints3.weighty = 1.0; gridBagConstraints3.fill = java.awt.GridBagConstraints.BOTH; CatalogListPanel.add(getCatalogListScrollPane(), gridBagConstraints3); CatalogListPanel.add(getButtonPanel(), gridBagConstraints37); CatalogListPanel.add(getInputCatalogPanel(), gridBagConstraints38); } return CatalogListPanel; } /** * This method initializes jPanel * * @return javax.swing.JPanel */ private JPanel getButtonPanel() { if (ButtonPanel == null) { GridBagConstraints gridBagConstraints31 = new GridBagConstraints(); ButtonPanel = new JPanel(); ButtonPanel.setLayout(new GridBagLayout()); gridBagConstraints31.gridx = 0; gridBagConstraints31.gridy = 1; ButtonPanel.setPreferredSize(new java.awt.Dimension(1,1)); ButtonPanel.add(getAddButton(), new GridBagConstraints()); ButtonPanel.add(getDeleteButton(), gridBagConstraints31);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -