Class Thumbelina
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.htmlparser.lexerapplications.thumbelina.Thumbelina
- All Implemented Interfaces:
ItemListener
,ImageObserver
,MenuContainer
,Serializable
,Runnable
,EventListener
,Accessible
,ChangeListener
,ListSelectionListener
public class Thumbelina
extends JPanel
implements Runnable, ItemListener, ChangeListener, ListSelectionListener
View images behind thumbnails.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
Activity state.protected JCheckBox
Background thread checkbox in status bar.protected String
The URL being currently being examined.protected boolean
Iftrue
, does not follow links containing cgi calls.protected boolean
Iftrue
, does not follow links containing queries (?).protected JList
History list.protected JScrollPane
Scroller for the history list.protected JSplitPane
Main panel in central area.protected PicturePanel
The central area for pictures.protected JScrollPane
Scroller for the picture panel.protected JPanel
Status bar.protected PropertyChangeSupport
Bound property support.protected JProgressBar
Image request queue monitor in status bar.protected JLabel
URL queue size display in status bar.protected JProgressBar
Image ready queue monitor in status bar.protected HashMap
Images requested.protected JCheckBox
Sequencer thread toggle in status bar.protected Sequencer
The picture sequencer.protected JSlider
Sequencer speed slider in status bar.protected Thread
Background thread.protected HashMap
Images being tracked currently.protected JTextField
URL report in status bar.protected HashMap
URL's visited.protected JLabel
URL visited count display in status bar.protected static final URL[][]
Value returned when no links are discovered.static final String
Property name for current URL binding.static final String
Property name for queue size binding.static final String
Property name for visited URL size binding.Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of Thumbelina.Thumbelina
(String url) Creates a new instance of Thumbelina.Thumbelina
(URL url) Creates a new instance of Thumbelina. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addHistory
(String url) Adds the given url to the history list.void
Add a PropertyChangeListener to the listener list.void
Append the given URL to the queue.void
Append the given URLs to the queue.protected URL[][]
extractImageLinks
(Lexer lexer, URL docbase) Get the links of an element of a document.protected void
Fetch images.protected ArrayList
Filter URLs and add to queue.boolean
Gets the state of the background thread.Return the URL currently being examined.boolean
Gets the state of history list visibility.protected URL[][]
getImageLinks
(URL url) Get the image links from the current URL.Get the picture panel object encapsulated by this Thumbelina.getQueue()
Getter for property queue.int
Getter for property queue.boolean
Gets the state of the sequencer thread.int
getSpeed()
Get the sequencer delay time.boolean
Gets the state of status bar visibility.protected static void
help()
Provide command line help.boolean
Getter for property discardCGI.boolean
Getter for property discardQueries.protected boolean
Check if the url looks like an image.void
itemStateChanged
(ItemEvent event) Handle checkbox events from the status bar.static void
Mainline.protected void
memCheck()
Check for low memory situation.void
Open a URL.void
Remove a PropertyChangeListener from the listener list.void
reset()
Reset this Thumbelina.void
run()
The main processing loop.void
setBackgroundThreadActive
(boolean active) Sets the state of the background thread activity.protected void
setCurrentURL
(String url) Set the current URL being examined.void
setDiscardCGI
(boolean discard) Setter for property discardCGI.void
setDiscardQueries
(boolean discard) Setter for property discardQueries.void
setHistoryListVisible
(boolean visible) Sets the history list visibility.void
setSequencerActive
(boolean active) Sets the sequencer activity state.void
setSpeed
(int speed) Set the sequencer delay time.void
setStatusBarVisible
(boolean visible) Sets the status bar visibility.void
stateChanged
(ChangeEvent event) Handles the speed slider events.protected void
updateQueueSize
(int original, int current) Apply a change in 'to be examined' URL list size.protected void
updateVisitedSize
(int original, int current) Apply a change in 'visited' URL list size.void
valueChanged
(ListSelectionEvent event) Handles the history list events.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
PROP_CURRENT_URL_PROPERTY
Property name for current URL binding.- See Also:
-
PROP_URL_QUEUE_PROPERTY
Property name for queue size binding.- See Also:
-
PROP_URL_VISITED_PROPERTY
Property name for visited URL size binding.- See Also:
-
mVisited
URL's visited. -
mRequested
Images requested. -
mTracked
Images being tracked currently. -
mThread
Background thread. -
mActive
protected boolean mActiveActivity state.true
means processing URLS,false
not. -
mSequencer
The picture sequencer. -
mPicturePanel
The central area for pictures. -
NONE
Value returned when no links are discovered. -
mPropertySupport
Bound property support. -
mCurrentURL
The URL being currently being examined. -
mDiscardCGI
protected boolean mDiscardCGIIftrue
, does not follow links containing cgi calls. -
mDiscardQueries
protected boolean mDiscardQueriesIftrue
, does not follow links containing queries (?). -
mBackgroundToggle
Background thread checkbox in status bar. -
mHistory
History list. -
mPicturePanelScroller
Scroller for the picture panel. -
mHistoryScroller
Scroller for the history list. -
mMainArea
Main panel in central area. -
mPowerBar
Status bar. -
mQueueProgress
Image request queue monitor in status bar. -
mReadyProgress
Image ready queue monitor in status bar. -
mRunToggle
Sequencer thread toggle in status bar. -
mSpeedSlider
Sequencer speed slider in status bar. -
mUrlText
URL report in status bar. -
mQueueSize
URL queue size display in status bar. -
mVisitedSize
URL visited count display in status bar.
-
-
Constructor Details
-
Thumbelina
public Thumbelina()Creates a new instance of Thumbelina. -
Thumbelina
Creates a new instance of Thumbelina.- Parameters:
url
- Single URL to enter into the 'to follow' list.- Throws:
MalformedURLException
- If the url is malformed.
-
Thumbelina
Creates a new instance of Thumbelina.- Parameters:
url
- URL to enter into the 'to follow' list.
-
-
Method Details
-
memCheck
protected void memCheck()Check for low memory situation. Report to the user a bad situation. -
reset
public void reset()Reset this Thumbelina. Clears the sequencer of pending images, resets the picture panel, emptiies the 'to be examined' list of URLs. -
append
Append the given URL to the queue. Adds the url only if it isn't already in the queue, and notifys listeners about the addition.- Parameters:
url
- The url to add.
-
append
Append the given URLs to the queue.- Parameters:
list
- The list of URL objects to add.
-
filter
Filter URLs and add to queue. Removes already visited links and appends the rest (if any) to the visit pending list.- Parameters:
urls
- The list of URL's to add to the 'to visit' list.- Returns:
- Returns the filered list.
-
getStatusBarVisible
public boolean getStatusBarVisible()Gets the state of status bar visibility.- Returns:
true
if the status bar is visible.
-
setStatusBarVisible
public void setStatusBarVisible(boolean visible) Sets the status bar visibility.- Parameters:
visible
- The new visibility state. Iftrue
, the status bar will be unhidden.
-
getHistoryListVisible
public boolean getHistoryListVisible()Gets the state of history list visibility.- Returns:
true
if the history list is visible.
-
setHistoryListVisible
public void setHistoryListVisible(boolean visible) Sets the history list visibility.- Parameters:
visible
- The new visibility state. Iftrue
, the history list will be unhidden.
-
getSequencerActive
public boolean getSequencerActive()Gets the state of the sequencer thread.- Returns:
true
if the thread is pumping images.
-
setSequencerActive
public void setSequencerActive(boolean active) Sets the sequencer activity state. The sequencer is the thread that moves images from the pending list to the picture panel on a timed basis.- Parameters:
active
- The new activity state. Iftrue
, the sequencer will be turned on. This may alter the speed setting if it is set to zero.
-
getBackgroundThreadActive
public boolean getBackgroundThreadActive()Gets the state of the background thread.- Returns:
true
if the thread is examining web pages.
-
setBackgroundThreadActive
public void setBackgroundThreadActive(boolean active) Sets the state of the background thread activity. The background thread is responsible for examining URLs that are on the queue for thumbnails, and starting the image fetch operation.- Parameters:
active
- Iftrue
, the background thread will be turned on.
-
getSpeed
public int getSpeed()Get the sequencer delay time.- Returns:
- The number of milliseconds between image additions to the panel.
-
setSpeed
public void setSpeed(int speed) Set the sequencer delay time. The sequencer is the thread that moves images from the pending list to the picture panel on a timed basis. This value sets the number of milliseconds it waits between pictures. Setting it to zero toggles the running state off.- Parameters:
speed
- The sequencer delay in milliseconds.
-
isDiscardCGI
public boolean isDiscardCGI()Getter for property discardCGI.- Returns:
- Value of property discardCGI.
-
setDiscardCGI
public void setDiscardCGI(boolean discard) Setter for property discardCGI.- Parameters:
discard
- New value of property discardCGI.
-
isDiscardQueries
public boolean isDiscardQueries()Getter for property discardQueries.- Returns:
- Value of property discardQueries.
-
setDiscardQueries
public void setDiscardQueries(boolean discard) Setter for property discardQueries.- Parameters:
discard
- New value of property discardQueries.
-
isImage
Check if the url looks like an image.- Parameters:
url
- The usrl to check for image characteristics.- Returns:
true
if the url ends in a recognized image extension.
-
extractImageLinks
Get the links of an element of a document. Only gets the links on IMG elements that reference another image. The latter is based on suffix (.jpg, .gif and .png).- Parameters:
lexer
- The fully conditioned lexer, ready to rock.docbase
- The url to read.- Returns:
- The URLs, targets of the IMG links;
- Throws:
IOException
- If the underlying infrastructure throws it.ParserException
- If there is a problem parsing the url.
-
getImageLinks
Get the image links from the current URL.- Parameters:
url
- The URL to get the links from- Returns:
- An array of two URL arrays, index 0 is a list of images, index 1 is a list of links to possibly follow.
-
getPicturePanel
Get the picture panel object encapsulated by this Thumbelina.- Returns:
- The picture panel.
-
addPropertyChangeListener
Add a PropertyChangeListener to the listener list. The listener is registered for all properties.- Overrides:
addPropertyChangeListener
in classContainer
- Parameters:
listener
- The PropertyChangeListener to be added.
-
removePropertyChangeListener
Remove a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.- Overrides:
removePropertyChangeListener
in classComponent
- Parameters:
listener
- The PropertyChangeListener to be removed.
-
getCurrentURL
Return the URL currently being examined. This is a bound property. Notifications are available via the PROP_CURRENT_URL_PROPERTY property.- Returns:
- The size of the 'to be examined' list.
-
setCurrentURL
Set the current URL being examined.- Parameters:
url
- The url that is being examined.
-
updateQueueSize
protected void updateQueueSize(int original, int current) Apply a change in 'to be examined' URL list size. Sends notification via thePROP_URL_QUEUE_PROPERTY
property and updates the status bar.- Parameters:
original
- The original size of the list.current
- The new size of the list.
-
updateVisitedSize
protected void updateVisitedSize(int original, int current) Apply a change in 'visited' URL list size. Sends notification via thePROP_URL_VISITED_PROPERTY
property and updates the status bar.- Parameters:
original
- The original size of the list.current
- The new size of the list.
-
fetch
Fetch images. Ask the toolkit to make the image from a URL, and add a tracker to handle it when it's received. Add details to the rquested and tracked lists and update the status bar.- Parameters:
images
- The list of images to fetch.
-
run
public void run()The main processing loop. Pull suspect URLs off the queue one at a time, fetch and parse it, request images and enqueue further links. -
itemStateChanged
Handle checkbox events from the status bar. Based on the thread toggles, activates or deactivates the background thread processes.- Specified by:
itemStateChanged
in interfaceItemListener
- Parameters:
event
- The event describing the checkbox event.
-
stateChanged
Handles the speed slider events.- Specified by:
stateChanged
in interfaceChangeListener
- Parameters:
event
- The event describing the slider activity.
-
valueChanged
Handles the history list events.- Specified by:
valueChanged
in interfaceListSelectionListener
- Parameters:
event
- The event describing the list activity.
-
addHistory
Adds the given url to the history list. Also puts the URL in the url text of the status bar.- Parameters:
url
- The URL to add to the history list.
-
open
Open a URL. Resets the urls list and appends the given url as the only item.- Parameters:
ref
- The URL to add.
-
help
protected static void help()Provide command line help. -
main
Mainline.- Parameters:
args
- the command line arguments. Can be one or more forms of -help to get command line help, or a URL to prime the program with. Checks for JDK 1.4 and if not found runs in crippled mode (no ThumbelinaFrame).
-
getQueue
Getter for property queue.- Returns:
- List of URLs that are to be visited.
-
getQueueSize
public int getQueueSize()Getter for property queue. This is a bound property. Notifications are available via thePROP_URL_QUEUE_PROPERTY
property.- Returns:
- The size of the list of URLs that are to be visited.
-