package jas2.plugin;
import java.io.PrintWriter;
import javax.swing.JMenu;
import java.awt.Component;
/**
* A base class for both Plugin and ExtensionPlugin
*/
public abstract class BasicPlugin
{
/**
* output sent to this print stream will appear in the applcations output window
*/
public PrintWriter out;
/**
* This routine can be called by the plugin to create a new menu.
* The menu must be a swing styule menu (i.e.
* extend javax.swing.JMenu). Currently the menu will be added to the main menu bar, just to the left of the
* Help menu. The menu may of course contain any number of buttons and submenus, and the plugin can add listeners
* to these menu items so that it can respond to user requests.
*
* @param menu The menu to be added
*/
public void addMenu(JMenu menu)
{
basicContext.addMenu(menu);
}
/**
* Remove a menu previously added using addMenu
*
* @param menu The menu to be removed
* @see #addMenu(JMenu)
*/
public void removeMenu(JMenu menu)
{
basicContext.removeMenu(menu);
}
/**
* The plugin can call this method to cause the application to popup an error box
* displaying the specified message.
*/
public void error(String message)
{
basicContext.error(message);
}
/**
* The plugin can call this method to cause the application to popup an error box
* displaying the specified message and detail.
*/
public void error(String message, Throwable detail)
{
basicContext.error(message, detail);
}
/**
* The plugin can call this method to cause a single line message to be displayed
* in the applications status window, at the bottom of the main window.
*/
public void sendMessage(String message)
{
basicContext.sendMessage(message);
}
/**
* Plugins may use this method to create a new page.
* The exact appearance of the page depends on the
* WindowStyle the user has selected in the View menu, but this is hidden from the plugin by the PagebasicContext
* abstraction.
*
* @param name The name for the new Window
* @param page The component that will form the body of the new page. It is recommended that the page be a lightweight
* window, i.e. that it extends javax.swing.JComponent
*
* @return A PagebasicContext that can be used to manipulate the window, or to receive notifications of user actions.
*
*/
public PageContext installPage(String name, Component page)
{
return basicContext.installPage(name, page);
}
public PageContext installControl(String name, Component control)
{
return basicContext.installControl(name, control);
}
public PageContext installConsole(String name, Component console)
{
return basicContext.installConsole(name, console);
}
/**
* Called by the application when the plugin is installed
* Plugins should override this method to install new menus etc.
*/
public void init()
{
}
void setPluginContext(BasicPluginContext context)
{
basicContext = context;
this.out = context.getPrintStream();
init();
}
private BasicPluginContext basicContext;
}
Ads help maintain this website.