|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JScrollPane
com.wolfram.jlink.ui.MathSessionPane
public class MathSessionPane
MathSessionPane is a visual component that provides a scrolling In/Out session interface to the Mathematica kernel. Much more sophisticated than the kernel's own "terminal" interface, it provides features such as full text editing of input including copy/paste and unlimited undo/redo, support for graphics, control of fonts and styles, customizable syntax coloring, and bracket matching.
To use a MathSessionPane, either supply an existing KernelLink using the setLink() method, or provide a command line to create a link via the setLinkArguments() or setLinkArgumentsArray() methods. You must always arrange for the connect() method to be called, which will launch the kernel (if you supplied an appropriate command line) and cause the first In[] prompt to appear.
The following key commands are supported:
Ctrl-X Cut Ctrl-C Copy Ctrl-V Paste Ctrl-Z Undo Ctrl-Y Redo Ctrl-L Copy Input From Above Ctrl-B Balance Brackets Alt-. Abort Computation Alt-, Interrupt Computation (brings up dialog) (These all use the Command key on the Macintosh)Here is a simple program that uses MathSessionPane:
public static void main(String[] argv) {
final MathSessionPane msp = new MathSessionPane();
// Create the frame window to hold the pane.
Frame frm = new Frame();
frm.setSize(500, 500);
frm.add(msp);
frm.setVisible(true);
frm.doLayout();
frm.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
KernelLink ml = msp.getLink();
// If we're quitting while the kernel is busy, it might not die when the link
// is closed. So we force the issue by calling terminateKernel();
if (ml != null)
ml.terminateKernel();
System.exit(0);
}
});
// Modify this for your setup.
msp.setLinkArgumentsArray(new String[] {"-linkmode", "launch", "-linkname", "\"d:/math41/mathkernel\" -mathlink"});
try {
msp.connect();
} catch (MathLinkException e) {
e.printStackTrace();
}
}
To see a more complete application built around a MathSessionPane, look at the SimpleFrontEnd
example application in JLink/Examples/Part2/SimpleFrontEnd.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JScrollPane |
|---|
javax.swing.JScrollPane.AccessibleJScrollPane, javax.swing.JScrollPane.ScrollBar |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
java.awt.Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class javax.swing.JScrollPane |
|---|
columnHeader, horizontalScrollBar, horizontalScrollBarPolicy, lowerLeft, lowerRight, rowHeader, upperLeft, upperRight, verticalScrollBar, verticalScrollBarPolicy, viewport |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, 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 |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface javax.swing.ScrollPaneConstants |
|---|
COLUMN_HEADER, HORIZONTAL_SCROLLBAR, HORIZONTAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER, HORIZONTAL_SCROLLBAR_POLICY, LOWER_LEADING_CORNER, LOWER_LEFT_CORNER, LOWER_RIGHT_CORNER, LOWER_TRAILING_CORNER, ROW_HEADER, UPPER_LEADING_CORNER, UPPER_LEFT_CORNER, UPPER_RIGHT_CORNER, UPPER_TRAILING_CORNER, VERTICAL_SCROLLBAR, VERTICAL_SCROLLBAR_ALWAYS, VERTICAL_SCROLLBAR_AS_NEEDED, VERTICAL_SCROLLBAR_NEVER, VERTICAL_SCROLLBAR_POLICY, VIEWPORT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
MathSessionPane()
Creates a new MathSessionPane with vertical and horizontal scrollbars. |
|
MathSessionPane(int vsbPolicy,
int hsbPolicy)
Creates a new MathSessionPane with the specified policies for vertical and horizontal scrollbars. |
|
| Method Summary | |
|---|---|
void |
addColoredSymbols(java.lang.String[] syms,
java.awt.Color c)
Lets you customize syntax coloring by specifying an array of symbol names and the color you want them drawn in when they appear in input. |
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a PropertyChangeListener that will be notified of changes in the computationActive property. |
void |
balanceBrackets()
Grows the current selection to highlight the nearest matching set of delimiters. |
boolean |
canRedo()
Indicates whether a redo operation is currently possible. |
boolean |
canUndo()
Indicates whether an undo operation is currently possible. |
void |
clearColoredSymbols()
Wipes out all syntax coloring customizations specified by addColoredSymbols(). |
void |
closeLink()
Closes the link to Mathematica. |
void |
connect()
Connects the link to Mathematica and prepares the pane for use. |
void |
copyInputFromAbove()
Copies the previous input to the current cursor location. |
void |
evaluateInput()
Evaluates the current input. |
java.awt.Color |
getBackgroundColor()
Returns the background color of the text region. |
java.awt.Color |
getCommentColor()
Returns the color that will be used for comments in input if syntax coloring is on. |
int |
getConnectTimeout()
Returns the number of milliseconds that the connect() method will wait to connect the link to Mathematica. |
int |
getLeftIndent()
Returns the amount that input and output will be indented from the left edge. |
KernelLink |
getLink()
Returns the link currently being used to communicate with Mathematica. |
java.lang.String |
getLinkArguments()
Returns the string specified to create the link to Mathematica. |
java.lang.String[] |
getLinkArgumentsArray()
Returns the string array specified to create the link to Mathematica. |
java.awt.Color |
getMessageColor()
Returns the color used for Mathematica message output. |
java.awt.Color |
getPromptColor()
Returns the color used for In[] and Out[] prompts. |
java.awt.Color |
getStringColor()
Returns the color that will be used for literal strings in input if syntax coloring is on. |
java.awt.Color |
getSystemSymbolColor()
Returns the color that will be used in input for symbols in the Mathematica System` context if syntax coloring is on. |
java.lang.String |
getText()
Gives the current contents of the pane as a string. |
java.awt.Color |
getTextColor()
Gives the color for input and output text |
javax.swing.JTextPane |
getTextPane()
Gives the JTextPane component that is hosted within this MathSessionPane. |
int |
getTextSize()
Gives the font size currently in use. |
boolean |
isComputationActive()
Indicates whether a computation is currently in progress. |
boolean |
isFitGraphics()
Indicates whether graphics are set to be scaled to fit into the current visible width. |
boolean |
isFrontEndGraphics()
Indicates whether the Mathematica front end will be used to assist in rendering graphics. |
boolean |
isInputBoldface()
Indicates whether input is in a boldface font. |
boolean |
isShowTiming()
Indicates whether evaluation timings will be shown in a timing panel at the lower left corner of the pane. |
boolean |
isSyntaxColoring()
Indicates whether syntax coloring is currently enabled. |
void |
redo()
Redoes the last undone edit. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a PropertyChangeListener. |
void |
setBackgroundColor(java.awt.Color c)
Sets the background color of the text region. |
void |
setCommentColor(java.awt.Color c)
Sets the color that will be used for comments in input if syntax coloring is on. |
void |
setConnectTimeout(int timeoutMillis)
Sets the number of milliseconds that the connect() method will wait to connect the link to Mathematica. |
void |
setFitGraphics(boolean fit)
Sets whether to scale graphics so as to fit into the current visible width. |
void |
setFrontEndGraphics(boolean b)
Sets whether to use the Mathematica front end in the background to assist in rendering graphics. |
void |
setInputBoldface(boolean bold)
Sets whether to use boldface for Mathematica input. |
void |
setLeftIndent(int indent)
Sets the amount that input and output will be indented from the left edge. |
void |
setLink(KernelLink ml)
Sets the link to use for communicating with Mathematica. |
void |
setLinkArguments(java.lang.String linkArgs)
Sets the command line to use to open a link to Mathematica. |
void |
setLinkArgumentsArray(java.lang.String[] linkArgs)
Sets the arguments to use to open a link to Mathematica. |
void |
setMessageColor(java.awt.Color c)
Sets the color used for Mathematica message output. |
void |
setPromptColor(java.awt.Color c)
Sets the color used for In[] and Out[] prompts. |
void |
setShowTiming(boolean show)
Specifies whether to display the wall-clock timing for each input in a timing panel at the lower left corner of the pane. |
void |
setStringColor(java.awt.Color c)
Sets the color that will be used for literal strings in input if syntax coloring is on. |
void |
setSyntaxColoring(boolean b)
Enables or disables syntax coloring of input. |
void |
setSystemSymbolColor(java.awt.Color c)
Sets the color that will be used in input for symbols in the Mathematica System` context if syntax coloring is on. |
void |
setTextColor(java.awt.Color c)
Sets the color for input and output text. |
void |
setTextSize(int size)
Sets the font size for input and output text. |
void |
undo()
Undoes the last edit. |
| Methods inherited from class javax.swing.JScrollPane |
|---|
createHorizontalScrollBar, createVerticalScrollBar, createViewport, getAccessibleContext, getColumnHeader, getCorner, getHorizontalScrollBar, getHorizontalScrollBarPolicy, getRowHeader, getUI, getUIClassID, getVerticalScrollBar, getVerticalScrollBarPolicy, getViewport, getViewportBorder, getViewportBorderBounds, isValidateRoot, isWheelScrollingEnabled, paramString, setColumnHeader, setColumnHeaderView, setComponentOrientation, setCorner, setHorizontalScrollBar, setHorizontalScrollBarPolicy, setLayout, setRowHeader, setRowHeaderView, setUI, setVerticalScrollBar, setVerticalScrollBarPolicy, setViewport, setViewportBorder, setViewportView, setWheelScrollingEnabled, 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, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, 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, transferFocusBackward, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public MathSessionPane()
public MathSessionPane(int vsbPolicy,
int hsbPolicy)
vsbPolicy - vertical scrollbar policy (see the Swing JScrollPane class)hsbPolicy - horizontal scrollbar policy (see the Swing JScrollPane class)| Method Detail |
|---|
public void setLink(KernelLink ml)
ml - setLinkArguments(String),
setLinkArgumentsArray(String[]),
connect()public KernelLink getLink()
public void setLinkArguments(java.lang.String linkArgs)
"-linkmode launch -linkname \"c:/program files/wolfram research/mathematica/5.1/mathkernel.exe\"" (Windows)
"-linkmode launch -linkname 'math -mathlink'" (UNIX)
"-linkmode launch -linkname '\"/Applications/Mathematica 4.1.app/Contents/MacOS/MathKernel\" -mathlink'" (Mac OS X)
The actual creation of the link will happen when you call connect().
linkArgs - the command line to create the linksetLinkArgumentsArray(String[]),
setLink(KernelLink),
connect(),
closeLink()public void setLinkArgumentsArray(java.lang.String[] linkArgs)
String[] args = {"-linkmode", "launch", "-linkname", "c:\\program files\\wolfram research\\mathematica\\5.1\\mathkernel.exe"}; (Windows)
String[] args = {"-linkmode", "launch", "-linkname", "math -mathlink"}; (UNIX)
String[] args = {"-linkmode", "launch", "-linkname", \"/Applications/Mathematica 5.1.app/Contents/MacOS/MathKernel\" -mathlink"}; (Mac OS X)
The actual creation of the link will happen when you call connect().
linkArgs - the command line to create the linksetLinkArguments(String),
setLink(KernelLink),
connect(),
closeLink()public java.lang.String getLinkArguments()
setLinkArguments(String)public java.lang.String[] getLinkArgumentsArray()
setLinkArgumentsArray(String[])public void setConnectTimeout(int timeoutMillis)
getConnectTimeout()public int getConnectTimeout()
setConnectTimeout(int)public java.lang.String getText()
public javax.swing.JTextPane getTextPane()
public boolean isComputationActive()
public int getTextSize()
public void setTextSize(int size)
size - the font size, in pointspublic boolean isSyntaxColoring()
public void setSyntaxColoring(boolean b)
b - public java.awt.Color getTextColor()
public void setTextColor(java.awt.Color c)
c - public java.awt.Color getStringColor()
public void setStringColor(java.awt.Color c)
c - public java.awt.Color getCommentColor()
public void setCommentColor(java.awt.Color c)
c - public java.awt.Color getSystemSymbolColor()
public void setSystemSymbolColor(java.awt.Color c)
c - public java.awt.Color getBackgroundColor()
public void setBackgroundColor(java.awt.Color c)
c - public java.awt.Color getPromptColor()
public void setPromptColor(java.awt.Color c)
c - public java.awt.Color getMessageColor()
public void setMessageColor(java.awt.Color c)
c - public int getLeftIndent()
public void setLeftIndent(int indent)
indent - the indentation amount in pixelspublic boolean isInputBoldface()
public void setInputBoldface(boolean bold)
bold - public void setFitGraphics(boolean fit)
fit - public boolean isFitGraphics()
public void setFrontEndGraphics(boolean b)
b - public boolean isFrontEndGraphics()
public void addColoredSymbols(java.lang.String[] syms,
java.awt.Color c)
syms - The symbols to be specially colored, for example {"If", "For", "Do"}c - clearColoredSymbols()public void clearColoredSymbols()
addColoredSymbols(String[],Color)public void setShowTiming(boolean show)
show - public boolean isShowTiming()
public void evaluateInput()
public void undo()
public void redo()
public boolean canRedo()
public boolean canUndo()
public void copyInputFromAbove()
public void balanceBrackets()
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
addPropertyChangeListener in class java.awt.Containerlistener - public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
removePropertyChangeListener in class java.awt.Componentlistener -
public void connect()
throws MathLinkException
Do not call this until after the pane has been made visible.
MathLinkExceptionpublic void closeLink()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||