All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class Webcrawler.Controller.Controller

java.lang.Object
   |
   +----Webcrawler.Controller.Controller

public abstract class Controller
extends Object
implements ControllerInterface, ActionListener, ChangeListener
This is the abstract superclass of all controllers for the Webcrawler. It provides the general settings such as the Start-URL, the maximum crawl-depth and more advanced settings like the max. number of Reader/Parser-Threads or the Start-Time. When creating a new Controller object a window is created that contains tabs for the different settings. A subclass of this class should add at least one tab for the specific settings of that particular Controller. The controller creates a new Crawler-object which is told to start when the user presses the Start-Button. This class implements the ControllerInterface, so that it can communicate with the Crawler. When deriving new Controllers from this one, don't forget to call the "super" methods in all methods and constructors. Currently available controllers: Grabber, StringFinder

See Also:
ControllerInterface, Grabber, StringFinder

Variable Index

 o crawler
This is the one and only Crawler of the Webcrawler-Application.
 o crawlerStarted
 o currTimeLabel
 o enableMaxTimeBox
 o enableStartTimeBox
 o frame
 o helpMenu
Subclasses should add a MenuItem for their specific help here.
 o info
 o maxDepthField
 o maxNodeNumField
 o maxThreadNumSlider
 o maxTimeField
 o maxTimeLabel
 o mb
 o nest
 o nodesInTree
 o nodesLoaded
 o onlySameHostBox
 o openIcon
 o pasteIcon
 o play1Icon
 o play2Icon
 o play3Icon
 o progressBar
 o rootURLField
 o saveIcon
 o secondsOver
 o startButton
 o startHost
 o startTimeField
 o startTimeLabel
 o stop1Icon
 o stop2Icon
 o stop3Icon
 o stopButton
 o tabbedPane
The tabbedPane that subclasses should ad their controller-specific tab to For example see one of the standard controllers like the "StringFinder"
 o userStarted

Constructor Index

 o Controller()
This constructor creates a new Crawler-object which is started by pressing the Start-Button in the "General" tab.

Method Index

 o actionPerformed(ActionEvent)
Catches the ActionEvents when one of the buttons in the "General"-tab was pressed always call super.actionEvent(e) in subclasses at the end of the subclass' method
 o addedANode(URLNode)
When a new node is added to the tree, the Crawler calls this method to let the Controller know.
 o crawlerDone()
Called by the Crawler when its work is done.
 o everySecond()
Called by the NotifyEverySecond-thread once a second.
 o getCrawler()
This mehod can be used by the surrounding application for attaching visualizers to the Crawler - since the crawler is being created by the controller.
 o loadCurrSettings()
Loads the settings for the current Controller window.
 o loadLink(LoadableNode)
Subclasses should implement this mehtod.
 o localFileName(LoadableNode)
Before the Crawler sends a node to the todo-pool for being downloaded, it asks the controller, through this method, under what filename the downloaded data should be stored locally.
 o nodeDone(URLNode)
Called by the Crawler when the node n is done (=loaded).
 o nodeLoaded(URLNode)
When the Crawler gets a node back from a Reader (= when the data has been downloaded) the Crawler notifies the Controller, via this method.
 o saveCurrSettings()
Saves the settings in the current Controller window.
 o startCrawler()
Tells the Crawler the maximum number of allowed Reader-threads and starts the Crawler.
 o stateChanged(ChangeEvent)
Catches the ChangeEvents when one of the Checkboxes int the "Advanced"-tab was clicked
 o stopCrawler()
Stops the Crawler
 o willSonsBeLoaded(HTMLNode)
Says if n's sons will be loaded in the future.

Variables

 o play1Icon
 static ImageIcon play1Icon
 o play2Icon
 static ImageIcon play2Icon
 o play3Icon
 static ImageIcon play3Icon
 o stop1Icon
 static ImageIcon stop1Icon
 o stop2Icon
 static ImageIcon stop2Icon
 o stop3Icon
 static ImageIcon stop3Icon
 o saveIcon
 static ImageIcon saveIcon
 o openIcon
 static ImageIcon openIcon
 o pasteIcon
 static ImageIcon pasteIcon
 o crawler
 protected Crawler crawler
This is the one and only Crawler of the Webcrawler-Application. It is created by this Controller.

 o nodesInTree
 protected int nodesInTree
 o nodesLoaded
 protected int nodesLoaded
 o frame
 protected JFrame frame
 o mb
 protected JMenuBar mb
 o helpMenu
 protected JMenu helpMenu
Subclasses should add a MenuItem for their specific help here.

 o tabbedPane
 protected JTabbedPane tabbedPane
The tabbedPane that subclasses should ad their controller-specific tab to For example see one of the standard controllers like the "StringFinder"

See Also:
StringFinder
 o rootURLField
 protected JTextField rootURLField
 o maxDepthField
 protected JTextField maxDepthField
 o maxNodeNumField
 protected JTextField maxNodeNumField
 o startButton
 protected JButton startButton
 o stopButton
 protected JButton stopButton
 o info
 protected JLabel info
 o progressBar
 protected JProgressBar progressBar
 o maxThreadNumSlider
 protected JSlider maxThreadNumSlider
 o onlySameHostBox
 protected JCheckBox onlySameHostBox
 o enableStartTimeBox
 protected JCheckBox enableStartTimeBox
 o startTimeLabel
 protected JLabel startTimeLabel
 o startTimeField
 protected JTextField startTimeField
 o enableMaxTimeBox
 protected JCheckBox enableMaxTimeBox
 o currTimeLabel
 protected JLabel currTimeLabel
 o maxTimeLabel
 protected JLabel maxTimeLabel
 o maxTimeField
 protected JTextField maxTimeField
 o nest
 private Controller. NotifyEverySecondThread nest
 o userStarted
 protected boolean userStarted
 o crawlerStarted
 protected boolean crawlerStarted
 o secondsOver
 protected int secondsOver
 o startHost
 protected String startHost

Constructors

 o Controller
 public Controller()
This constructor creates a new Crawler-object which is started by pressing the Start-Button in the "General" tab. It also creates a new window which contains that "General" tab as well as the "Advanced" tab. A new NotifyEverySecond-thread is created and started. It will call this class' everySecond() method once a second. When deriving a new controller-class from this one, always call super() in the new class' constructor

See Also:
NotifyEverySecond, everySecond

Methods

 o actionPerformed
 public void actionPerformed(ActionEvent e)
Catches the ActionEvents when one of the buttons in the "General"-tab was pressed always call super.actionEvent(e) in subclasses at the end of the subclass' method

 o stateChanged
 public void stateChanged(ChangeEvent e)
Catches the ChangeEvents when one of the Checkboxes int the "Advanced"-tab was clicked

 o saveCurrSettings
 protected void saveCurrSettings()
Saves the settings in the current Controller window. Here the entries in all the components of the general and advanced tab are stored to set\ctrl.dat saveCurrSettings() is called by the actionPerformed-method. Always call super.saveCurrSettings() in subclasses.

 o loadCurrSettings
 protected void loadCurrSettings()
Loads the settings for the current Controller window. Here the entries in all the components of the general and advanced tab are loaded and the fields on screen are set. loadCurrSettings() is called by the actionPerformed-method. Always call super.loadCurrSettings() in subclasses.

 o getCrawler
 public Crawler getCrawler()
This mehod can be used by the surrounding application for attaching visualizers to the Crawler - since the crawler is being created by the controller.

Returns:
The Crawler-object that was created when this controller was created
 o everySecond
 protected void everySecond()
Called by the NotifyEverySecond-thread once a second. Here it is used to check if the user had pressed the start-button. In this case, this method waits until startTime (if enableStartTime is selected) and then calls startCrawler(). If enablemaxTime is selected, this method calls stopCrawler() after the specified number of seconds.

 o startCrawler
 public void startCrawler()
Tells the Crawler the maximum number of allowed Reader-threads and starts the Crawler.

 o stopCrawler
 public void stopCrawler()
Stops the Crawler

 o willSonsBeLoaded
 public boolean willSonsBeLoaded(HTMLNode n)
Says if n's sons will be loaded in the future. If n is already at the max depth it's sons won't be loaded. This info is important for the Parsers, cuz' they don't need to do the +"/index.html"-check for every son if it won't be loaded. always call super.willSonsBeLoaded() in subclasses. Usually subclasses won't have to override this method.

 o loadLink
 public boolean loadLink(LoadableNode n)
Subclasses should implement this mehtod. The Crawler always asks the Controller if a link should be downloaded, using this method. Here it is made sure that the URLType of the node is "normal", that the depth is < maxDepth and that there are not more than maxNodeNum nodes read already. It is also checked that if the "Load Links from same host only" Checkbox is selected, only links that have the same host as the startURL will be loaded. always call super.loadLink(n) in subclasses!

 o localFileName
 public abstract String localFileName(LoadableNode n)
Before the Crawler sends a node to the todo-pool for being downloaded, it asks the controller, through this method, under what filename the downloaded data should be stored locally.

 o addedANode
 public void addedANode(URLNode n)
When a new node is added to the tree, the Crawler calls this method to let the Controller know. Here, this is used for counting the nodes in the tree, so that if there are more than maxNodeNum nodes, the loadLink() method can return false. always call super.addedANode(n) in subclasses!

 o nodeLoaded
 public void nodeLoaded(URLNode n)
When the Crawler gets a node back from a Reader (= when the data has been downloaded) the Crawler notifies the Controller, via this method. Subclasses should use this method if they need to do any operations on the local file (which has been downloaded by now). always call super.nodeLoaded(n) in subclasses!

 o nodeDone
 public abstract void nodeDone(URLNode n)
Called by the Crawler when the node n is done (=loaded). Here: abstract (=does nothing) Note: always call the superclass' nodeDone method in subclasses!

 o crawlerDone
 public void crawlerDone()
Called by the Crawler when its work is done. Subclasses should use this to clean up temporary files. always call super.crawlerDone() in subclasses!


All Packages  Class Hierarchy  This Package  Previous  Next  Index