Package gui

Source Code of gui.ACPanel

package gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;

import javax.swing.DefaultComboBoxModel;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListModel;

import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import modelcrawler.AgentCrawlerModel;
import modelcrawler.AgentMetrics;
import modelcrawler.BigIndex;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ACPanel extends JFrame implements ActionListener, Observer {
  /**
   *
   */
  private static final long serialVersionUID = 2559048214107017374L;

  private AgentCrawlerModel _model = null;
  private JButton btnAddDomain;
  private JTable resultsTable;
  private JButton btnSearch;
  private JButton btnKillMonitor;
  private JList lstKeywords;
  private JLabel lblMasterMonitor;
  private JLabel lblKilledIndexers;
  private JLabel lblKilledCrawlers;
  private JLabel lblKilled;
  private JLabel lblInfo;
  private JLabel lblPages;
  private JLabel lblDomainsWaiting;
  private JLabel lblActiveIndexers;
  private JLabel lblActiveCrawlers;
  private JLabel lblIndexers;
  private JLabel lblCrawlers;
  private JLabel lblRunning;
  private JLabel lblAgentInfo;
  private JTextField txtKeywords;
  private JLabel lblSearch;
  private JLabel lblMaxSpawned;
  private JLabel lblMaxCrawlers;
  private JLabel lblLimits;
  private JLabel lblDomain;
  private JTextField txtDomain;

  /**
  * Auto-generated main method to display this JFrame
  */
 
  public ACPanel() {
    super();
    initGUI();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    this.setVisible(true);
    _model = AgentCrawlerModel.getModel();
    _model.addObserver(this);
    bindData();
  }
 
  private void initGUI() {
    try {
      setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      getContentPane().setLayout(null);
      this.setTitle("AgentCrawler");
      {
        btnAddDomain = new JButton();
        getContentPane().add(btnAddDomain);
        btnAddDomain.setText("Add Domain");
        btnAddDomain.setBounds(280, 34, 114, 23);
        btnAddDomain.setActionCommand("adddomain");
        btnAddDomain.addActionListener(this);
      }
      {
        txtDomain = new JTextField();
        getContentPane().add(txtDomain);
        txtDomain.setBounds(12, 35, 262, 20);
        txtDomain.setText("http://www.conservapedia.com/");
      }
      {
        lblDomain = new JLabel();
        getContentPane().add(lblDomain);
        lblDomain.setText("Domain to Add:");
        lblDomain.setBounds(10, 15, 244, 14);
      }
      {
//        TableModel resultsTableModel =
//          new DefaultTableModel(
//              new String[][] { { "One", "Two" }, { "Three", "Four" } },
//              new String[] { "Column 1", "Column 2" });
        TableModel resultsTableModel =
          new DefaultTableModel(
              new String[][] { { "None" } },
              new String[] { "URLS Found" });
        resultsTable = new JTable();
        getContentPane().add(resultsTable);
        resultsTable.setModel(resultsTableModel);
        resultsTable.setBounds(405, 184, 367, 194);
      }
      {
        lblLimits = new JLabel();
        getContentPane().add(lblLimits);
        lblLimits.setText("Max No.:");
        lblLimits.setBounds(12, 239, 79, 16);
        lblLimits.setToolTipText("Maximum Number of Agents Allowed -1 for unlimited");
      }
      {
        lblMaxCrawlers = new JLabel();
        getContentPane().add(lblMaxCrawlers);
        lblMaxCrawlers.setText("Max Crawlers:");
        lblMaxCrawlers.setBounds(103, 239, 88, 16);
      }
      {
        lblMaxSpawned = new JLabel();
        getContentPane().add(lblMaxSpawned);
        lblMaxSpawned.setText("Max. Spawned");
        lblMaxSpawned.setBounds(254, 239, 88, 16);
      }
      {
        lblSearch = new JLabel();
        getContentPane().add(lblSearch);
        lblSearch.setText("Search for Keywords:");
        lblSearch.setBounds(405, 13, 262, 16);
      }
      {
        txtKeywords = new JTextField();
        getContentPane().add(txtKeywords);
        txtKeywords.setBounds(405, 38, 262, 22);
      }
      {
        btnSearch = new JButton();
        getContentPane().add(btnSearch);
        btnSearch.setText("Search");
        btnSearch.setBounds(679, 39, 94, 22);
        btnSearch.setActionCommand("dosearch");
        btnSearch.addActionListener(this);
      }
      {
        lblAgentInfo = new JLabel();
        getContentPane().add(lblAgentInfo);
        lblAgentInfo.setText("Agent Info.");
        lblAgentInfo.setBounds(12, 140, 110, 16);
      }
      {
        lblRunning = new JLabel();
        getContentPane().add(lblRunning);
        lblRunning.setText("Running");
        lblRunning.setBounds(12, 184, 79, 16);
      }
      {
        lblCrawlers = new JLabel();
        getContentPane().add(lblCrawlers);
        lblCrawlers.setText("Crawlers");
        lblCrawlers.setBounds(103, 162, 52, 16);
      }
      {
        lblIndexers = new JLabel();
        getContentPane().add(lblIndexers);
        lblIndexers.setText("Indexers");
        lblIndexers.setBounds(254, 162, 56, 16);
      }
      {
        lblActiveCrawlers = new JLabel();
        getContentPane().add(lblActiveCrawlers);
        lblActiveCrawlers.setText("0");
        lblActiveCrawlers.setBounds(103, 184, 52, 16);
      }
      {
        lblActiveIndexers = new JLabel();
        getContentPane().add(lblActiveIndexers);
        lblActiveIndexers.setText("0");
        lblActiveIndexers.setBounds(254, 184, 56, 16);
      }
      {
        lblDomainsWaiting = new JLabel();
        getContentPane().add(lblDomainsWaiting);
        lblDomainsWaiting.setText("No. Of Domains to be Crawled: 0");
        lblDomainsWaiting.setBounds(12, 56, 375, 16);
      }
      {
        lblPages = new JLabel();
        getContentPane().add(lblPages);
        lblPages.setText("Pages Waiting vs Indexed: 0 : 0");
        lblPages.setBounds(12, 78, 382, 16);
      }
      {
        lblInfo = new JLabel();
        getContentPane().add(lblInfo);
        lblInfo.setText("Info");
        lblInfo.setBounds(12, 107, 375, 16);
      }
      {
        lblKilled = new JLabel();
        getContentPane().add(lblKilled);
        lblKilled.setText("Terminated:");
        lblKilled.setBounds(12, 211, 64, 16);
      }
      {
        lblKilledCrawlers = new JLabel();
        getContentPane().add(lblKilledCrawlers);
        lblKilledCrawlers.setText("0");
        lblKilledCrawlers.setBounds(103, 211, 59, 16);
      }
      {
        lblKilledIndexers = new JLabel();
        getContentPane().add(lblKilledIndexers);
        lblKilledIndexers.setText("0");
        lblKilledIndexers.setBounds(254, 211, 56, 16);
      }
      {
        btnKillMonitor = new JButton();
        getContentPane().add(btnKillMonitor);
        btnKillMonitor.setText("Kill Master Monitor");
        btnKillMonitor.setBounds(12, 315, 115, 22);
        btnKillMonitor.setActionCommand("killmastermonitor");
        btnKillMonitor.addActionListener(this);
      }
      {
        lblMasterMonitor = new JLabel();
        getContentPane().add(lblMasterMonitor);
        lblMasterMonitor.setText("Master Monitor Name");
        lblMasterMonitor.setBounds(148, 317, 239, 16);
      }
      {
        ListModel lstKeywordsModel =
          new DefaultComboBoxModel(
              new String[] { "Item One", "Item Two" });
        lstKeywords = new JList();
        getContentPane().add(lstKeywords);
        lstKeywords.setModel(lstKeywordsModel);
        lstKeywords.setBounds(405, 72, 367, 106);
      }
      pack();
      this.setSize(800, 450);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

 
  private void bindData() {
   
    AgentMetrics am = _model.getMetrics();
   
    lblMaxCrawlers.setText(Integer.toString( _model.getMaxCrawlers() ) );
    lblMaxSpawned.setText(Integer.toString( _model.getMaxIndexers() ) );
   
    lblActiveCrawlers.setText(Integer.toString(am.getActiveCrawlers()));
    lblActiveIndexers.setText(Integer.toString(am.getActiveIndexers()));
   
    lblKilledCrawlers.setText(Integer.toString(am.getTerminatedCrawlers()));
    lblKilledIndexers.setText(Integer.toString(am.getTerminatedIndexers()));
   
    lblDomainsWaiting.setText("Domains Waiting vs Crawled vs Failed: " +
        _model.getDomainCount() + " : " +
        _model.getDomainsCrawled() + " : " +
        _model.getDomainsFailed() );
    lblPages.setText("Pages Waiting vs Indexed vs Failed: " +
        Integer.toString(_model.getPageCount()) + " : " +
        _model.getPagesIndexed() + " : " +
        _model.getPagesFailed() );
   
    lblSearch.setText("Search for Keywords - " + Integer.toString(_model.getIndexCount()) + " keywords in index" );
    //TODO - Show keywords listed in index
    Set<String> keys = BigIndex.getIndex().getKeyWords();
    lstKeywords.setListData(keys.toArray());
       
    StringBuffer sb = new StringBuffer();
    if (!_model.hasDomainsWaiting()) {
      sb.append(" All Domains Crawled");
    }
    if (!_model.hasPagesWaiting()) {
      sb.append(" All Pages Indexed" );
    }
    lblInfo.setText( sb.toString() );
   
    lblMasterMonitor.setText( "Current Master: " + _model.getMasterMonitorName());
   
  }
 
  @Override
  public void actionPerformed(ActionEvent arg0) {
    if ( arg0.getActionCommand().equals("dosearch")) {
      List<String> results = _model.searchIndex(txtKeywords.getText());
      String[] cols = new String[] { "URL" };
      String[][] data = new String[results.size()][1];
      for(int i = 0; i<results.size(); i++) {
        data[i] = new String[] { results.get(i) };
      }
     
      TableModel resultsTableModel = new DefaultTableModel( data, cols );
      resultsTable.setModel(resultsTableModel);
    } else if ( arg0.getActionCommand().equals("adddomain")) {
      _model.addDomain(txtDomain.getText());
    } else if ( arg0.getActionCommand().equals("killmastermonitor")) {
      _model.killMasterMonitor();
      lblMasterMonitor.setText( "MASTER MONITOR KILLED" );

    }
  }

  public static void showFrame() {
    new ACPanel();   
  }

  @Override
  public void update(Observable arg0, Object arg1) {
    this.bindData();
  }

}
TOP

Related Classes of gui.ACPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.