//----------------------------------------------------------------------------
// COMPONENT NAME: LPEX Editor
//
// © Copyright IBM Corporation 2005, 2006
// All Rights Reserved.
//
// DESCRIPTION:
// HairlineCommand - sample user-defined command (hairline)
//----------------------------------------------------------------------------
package com.ibm.lpex.samples;
import com.ibm.lpex.core.LpexCommand;
import com.ibm.lpex.core.LpexView;
/**
* Sample command <b>hairline</b> - control the display of a cursor or fixed
* vertical hairline.
*
* <p>Here is the HairlineCommand
* <a href="doc-files/HairlineCommand.java.html">source code</a>.</p>
*
* <p>To run this sample:
* <ul>
* <li>Define this user command via an editor preference page, where available,
* or from the editor command line:
* <pre>set commandClass.hairline com.ibm.lpex.samples.HairlineCommand</pre></li>
* <li>Run it from the editor command line:
* <pre>hairline [on | cursor | off]</pre></li>
* </ul></p>
*
* @see CursorHairline
* @see com.ibm.lpex.samples All the samples
*/
public class HairlineCommand implements LpexCommand
{
/**
* Runs this command.
* Sets the display and type of a vertical hairline.
*
* @param lpexView the document view in which the command was issued
* @param parameters optional parameter "on", "cursor" (to track cursor movements),
* or "off" (to remove the hairline)
*/
public boolean doCommand(LpexView lpexView, String parameters)
{
if (lpexView != null)
{
// defaults (for "on" / no parameters)
boolean displayHairline = true;
boolean trackCursor = false;
parameters = parameters.trim();
if (parameters.length() != 0)
{
if ("cursor".equals(parameters))
{
trackCursor = true;
}
else if ("off".equals(parameters))
{
displayHairline = false;
}
else if ("?".equals(parameters)) // command help
{
lpexView.doCommand("set messageText Syntax: hairline [on | cursor | off]");
return true;
}
else if (!"on".equals(parameters))
{
lpexView.doCommand("set messageText " + parameters +
" is not a valid parameter for the \"hairline\" command.");
return false;
}
}
if (displayHairline)
{
CursorHairline.install(lpexView, trackCursor);
}
else
{
CursorHairline.uninstall(lpexView);
}
}
return true;
}
}