com.japisoft.resourcebrowser
Class ResourceBrowserPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--com.japisoft.resourcebrowser.ResourceBrowserPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, javax.swing.event.ListSelectionListener, java.awt.MenuContainer, java.awt.event.MouseListener, java.io.Serializable
Direct Known Subclasses:
FileBrowser, FTPBrowser, WEBDAVBrowser, ZIPBrowser

public class ResourceBrowserPanel
extends javax.swing.JPanel
implements java.awt.event.ActionListener, javax.swing.event.ListSelectionListener, java.awt.event.MouseListener

This is the main panel for selected or acting on a remote resource. This panel works with a ResourceManager which is the delegate for managing a set of resources. This delegate provides connection, listing and actions. For sample the user can have a delegate for FTP, WebDAV or ZIP/JAR resource.

Sample of usage :

 JFrame frame = new JFrame();
 frame.getContentPane().add( 
 	new ResourceBrowserPanel(new FTPBrowser()) );
 

For initializing/getting the user interface state, the State object is available through the setState and the getState methods. This state is "serializable" meaning, the user can store/read it with a java.io.ObjectOutputStream or a java.io.ObjectInputStream.

Sample of usage

	dialog = new JDialog();
	dialog.setTitle( "FTP Editor " );

	// We initialize a default FTP server and user account
	State state = new State();
	state.putValue( State.HOST_KEY, "MyHost" );
	state.putValue( State.USER_KEY, "MyUserName" );
	state.putValue( State.PASSWORD_KEY, "MyPassword" );
		
	dialog.getContentPane().add( browser = new FTPBrowser( state ) );
 

Version:
1.1
Author:
(c) 2004 JAPISoft / http://www.japisoft.com
See Also:
ResourceManager, State, Serialized Form

Field Summary
static int DIRECTORY_SELECTION_MODE
           
static int FILE_DIRECTORY_SELECTION_MODE
           
static int FILE_SELECTION_MODE
           
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
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
ResourceBrowserPanel(ResourceManager manager)
           
ResourceBrowserPanel(ResourceManager manager, State state)
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Inner usage.
 void addNotify()
           
 boolean connect()
          Connect to a server or a resource container.
 void deleteFile()
          Delete the selected file
 void disconnect()
          Close the current conection
 ActionModel getActionModel()
           
 ResourceManager getResourceManager()
           
 byte[] getSelectedContentFile(boolean autoDisconnect)
           
 java.lang.String getSelectedPathFile()
           
 ResourceItem getSelectedResource()
           
 int getSelectionMode()
           
 State getState()
           
 void lockUnlockFile()
          Lock or unlock the selected file
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void newFile()
          Create a new file
 void removeNotify()
           
 void renameFile()
          Rename the selected file
 void setFileResourceView(FileResourceView view)
          This is a UI delegate for displaying a file while browsing
 boolean setSelectedContentFile(byte[] content, boolean autoDisconnect)
          Reset the content of the selected file
 void setSelectionMode(int selectionMode)
          Reset the selection mode.
 void setState(State state)
          Reset the state for the UI part
 void valueChanged(javax.swing.event.ListSelectionEvent e)
          For inner usage.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FILE_SELECTION_MODE

public static final int FILE_SELECTION_MODE
See Also:
Constant Field Values

DIRECTORY_SELECTION_MODE

public static final int DIRECTORY_SELECTION_MODE
See Also:
Constant Field Values

FILE_DIRECTORY_SELECTION_MODE

public static final int FILE_DIRECTORY_SELECTION_MODE
See Also:
Constant Field Values
Constructor Detail

ResourceBrowserPanel

public ResourceBrowserPanel(ResourceManager manager)
Parameters:
manager - The manager of a dedicated resource container/protocol like FTP..

ResourceBrowserPanel

public ResourceBrowserPanel(ResourceManager manager,
                            State state)
Parameters:
manager - The manager of a dedicated resource container/protocol like FTP...
state - The state of the User interface like the host name...
Method Detail

setState

public void setState(State state)
Reset the state for the UI part


getState

public State getState()
Returns:
the state for the UI part like the host name

getActionModel

public ActionModel getActionModel()
Returns:
the user set of actions. Sample of action 'Delete' a file

setSelectionMode

public void setSelectionMode(int selectionMode)
Reset the selection mode. FILE_SELECTION_MODE, DIRECTORY_SELECTION_MODE or FILE_DIRECTORY_SELECTION_MODE

Parameters:
selectionMode -

getSelectionMode

public int getSelectionMode()
Returns:
the current selection mode

setFileResourceView

public void setFileResourceView(FileResourceView view)
This is a UI delegate for displaying a file while browsing


addNotify

public void addNotify()
Overrides:
addNotify in class javax.swing.JComponent

removeNotify

public void removeNotify()
Overrides:
removeNotify in class javax.swing.JComponent

getResourceManager

public ResourceManager getResourceManager()
Returns:
the current manager for browsing or acting. This manager is dedicated to a protocol like FTP or WabDAV...

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

getSelectedResource

public ResourceItem getSelectedResource()
Returns:
the selected file

getSelectedPathFile

public java.lang.String getSelectedPathFile()
Returns:
the selected file path

setSelectedContentFile

public boolean setSelectedContentFile(byte[] content,
                                      boolean autoDisconnect)
Reset the content of the selected file

Parameters:
content - A file content
autoDisconnect - if true, the connection will be closed at the end of the method
Returns:
false if the operation is not possible

getSelectedContentFile

public byte[] getSelectedContentFile(boolean autoDisconnect)
Parameters:
autoDisconnect - if true the connection will be closed at the end of the method
Returns:
the file content for this selection. null if the operation is not possible or if there's no selected file

newFile

public void newFile()
Create a new file


deleteFile

public void deleteFile()
Delete the selected file


renameFile

public void renameFile()
Rename the selected file


lockUnlockFile

public void lockUnlockFile()
Lock or unlock the selected file


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Inner usage. It mustn't be called by the developper

Specified by:
actionPerformed in interface java.awt.event.ActionListener

valueChanged

public void valueChanged(javax.swing.event.ListSelectionEvent e)
For inner usage. It mustn't be called by the developper

Specified by:
valueChanged in interface javax.swing.event.ListSelectionListener

connect

public boolean connect()
Connect to a server or a resource container. A dialog box will appear if an error has occured

Returns:
false if the connection cannot be established

disconnect

public void disconnect()
Close the current conection