net.sf.ovanttasks.ovnative.win32
Class LnkFile

java.lang.Object
  extended by net.sf.ovanttasks.ovnative.win32.LnkFile

public class LnkFile
extends Object

LnkFile reads and writes Windows Shortcut files in the .lnk format. It can be used to create or read .lnk files which are used by Microsoft for Shortcuts (the IShellLink Interface). The destination (path) can be executable (cmd.exe) or normal files (text files and more). They will be opend / executed by the shell.

The HOTKEYF_XXX constants are taken from (MinGW) commctrl.h.

The SW_SHOWXX constants are taken from (MinGW) winuser.h.

Author:
lars.gersmann@roxes.com, arnep@users.sf.net

Nested Class Summary
static class LnkFile.ShowCmd
          The inital state of the window.
 
Constructor Summary
LnkFile(File lnkFile, boolean load)
          Create a new LnkFile instance for a specified location.
LnkFile(String directory, String name, boolean load)
          Create a new LnkFile instance for a specified location.
 
Method Summary
 String getArguments()
          Returns the arguments of the shortcut.
 String getHotkey()
          Returns the hotkey.
 int getIconIndex()
          Returns the icon index for this shortcut.
 String getIconLocation()
          Returns the icon location for this shortcut.
 LnkFile.ShowCmd getShowState()
          Returns the initil state in wich the window will be appear on screen.
 File getSrcFile()
          Returns the source of the Link.
 String getTargetFile()
          Returns the taget for this shortcut.
 String getToolTipText()
          Returns the toolTipText for this shortcut.
 String getWorkingDirectory()
          Returns the working directory for this shortcut.
 void load()
          Loads the link data from the filesystem.
 void resolve()
          Resolve the link with UI interaction
 void save()
          Save the link
 void save(String directory, String name)
          Save the link
 void setArguments(String arguments)
          Set the Arguments
 void setHotkey(String hotkey)
          Sets the hotkey.
 void setIcon(String iconLocation, int iconIndex)
          Set the icon location for this shortcut.
 void setShowState(LnkFile.ShowCmd swShow)
          Sets the initial state in wich the window will be appear on screen.
 void setTargetFile(String targetFile)
          Set the target for this shortcut.
 void setToolTipText(String toolTipText)
          Set the toolTipText for this shortcut.
 void setWorkingDirectory(String workingDirectory)
          Set the working directory for this shortcut.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LnkFile

public LnkFile(String directory,
               String name,
               boolean load)
Create a new LnkFile instance for a specified location.

File.File(java.lang.String, java.lang.String) If load is true the instance of LnkFile is initialized with the values from the file.

The native library is also loaded.

Parameters:
directory - The parent pathname string
name - The child pathname
load - wether or not load the data from existing file.

LnkFile

public LnkFile(File lnkFile,
               boolean load)
Create a new LnkFile instance for a specified location.

If load is true the instance of LnkFile is initialized with the values from the lnkFile.

The native library is also loaded.

Parameters:
lnkFile - The lnkFile to use
load - wether or not load the data from existing file.
Method Detail

getShowState

public LnkFile.ShowCmd getShowState()
Returns the initil state in wich the window will be appear on screen. This can be normal, minimalized or maxiamlized.

Returns:
The sow state

setShowState

public void setShowState(LnkFile.ShowCmd swShow)
Sets the initial state in wich the window will be appear on screen. This can be normal, minimalized or maxiamlized.

Parameters:
swShow - The state to set.

getArguments

public String getArguments()
Returns the arguments of the shortcut. The path points to an executable (path), the arguments specified here will be passed to the executable.

Returns:
The arguments of the shortcut

getToolTipText

public String getToolTipText()
Returns the toolTipText for this shortcut. The toolTipText is visibe to the user if the mouse hoovers longer over the file.

Returns:
the description of this shortcut

getSrcFile

public File getSrcFile()
Returns the source of the Link. This is the file with the .lnk extentiuon.

Returns:

getIconIndex

public int getIconIndex()
Returns the icon index for this shortcut. This is the index within the .ico file or the index in the icon resources of a .dll or .exe

Returns:
the index of the icon within the specified location.

getIconLocation

public String getIconLocation()
Returns the icon location for this shortcut. This can be a .ico, .dll or .exe file. The iconIndex indicates the index of the icon within the file.

Returns:
the location of the icon for the shortcut.

getTargetFile

public String getTargetFile()
Returns the taget for this shortcut. The target is an executabel file , or can be an ordinary file for example a .txt file.

Returns:
The taget of this shortcut as absolute path.

getWorkingDirectory

public String getWorkingDirectory()
Returns the working directory for this shortcut.

Returns:
The working directory for the shortcut.

load

public void load()
          throws Win32Exception
Loads the link data from the filesystem.

Throws:
Win32Exception

resolve

public void resolve()
             throws Win32Exception
Resolve the link with UI interaction

Throws:
Win32Exception

save

public void save(String directory,
                 String name)
          throws Win32Exception
Save the link

Parameters:
directory -
name -
Throws:
Win32Exception

save

public void save()
          throws Win32Exception
Save the link

Throws:
Win32Exception

setArguments

public void setArguments(String arguments)
Set the Arguments

Parameters:
arguments - the arguments to set.

setToolTipText

public void setToolTipText(String toolTipText)
Set the toolTipText for this shortcut. The toolTipText is visible toi the user, if the mouse hoovers over the file.

Parameters:
toolTipText - The tooltiptext to display

setIcon

public void setIcon(String iconLocation,
                    int iconIndex)
Set the icon location for this shortcut. The icon will be displayed on the screen. The file can be an ico,dll or exe the iconindex is the index in the file. Both the file and the index into the file must be specified.

Parameters:
iconLocation - The path to the file.
iconIndex - The index of the icon within the file.

setTargetFile

public void setTargetFile(String targetFile)
Set the target for this shortcut. The target ist the path to the file of this link. If this is an executable, additional arguments and a workingDirectory can be provided.

Parameters:
targetFile - The target of this link

setWorkingDirectory

public void setWorkingDirectory(String workingDirectory)
Set the working directory for this shortcut. The workingDirectory is the directory in which the executable given by path will be executed.

Parameters:
workingDirectory - The working directory

setHotkey

public void setHotkey(String hotkey)
Sets the hotkey. The hotkey is used to execute the link given by path>/code> with keystoken. The following modifiers will be supported:
  • Alt the Alt key. Ctrl the Ctrl key, Shift the Shift key
  • Each separated by " + ". Example: Ctrl + Shift + Alt + A.

    Parameters:
    hotkey - The hotkey as String.

    getHotkey

    public String getHotkey()
    Returns the hotkey. The Hotkey will be returned as String setHotKey.

    Returns:
    the hotkey as String


    Copyright © 2008 Orangevolt. All Rights Reserved.