Dresden OCL Toolkit

tudresden.ocl.gui
Class OCLEditor

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bytudresden.ocl.gui.OCLEditor
All Implemented Interfaces:
Accessible, ConstraintChangeListener, EditingUtilities, EventListener, ImageObserver, ListSelectionListener, MenuContainer, Serializable

public class OCLEditor
extends JPanel
implements ListSelectionListener, ConstraintChangeListener, EditingUtilities

An editor for a list of OCL Constraints. The editor allows editing of a list of constraint representations as specified by its model.

Author:
sz9
See Also:
Serialized Form

Nested Class Summary
protected static class OCLEditor.ConstraintTableModel
          Table model for the table of constraints.
protected static class OCLEditor.OCLEditorDocument
          A specialized styled document that will prevent editing of portions of text which have been specially marked "allowEdit"==FALSE.
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  ConstraintRepresentation m_crCurrent
          The currently selected constraint, if any.
private  OCLEditor.ConstraintTableModel m_ctmTableModel
          The table model used by the list of constraints table.
private  boolean m_fConstraintChanged
          Set to false when beginning edit mode, evaluated at the end of editing a newly created constraint to determine whether to remove it again.
private  boolean m_fCreatedFreshConstraint
          Indicates the constraint currently being edited is a newly created one.
private  boolean m_fDoAutoSplit
          Should multi-constraint inputs be automatically split into individual constraints?
private  boolean m_fDoTypeCheck
          Does parseAndCheckConstraint(java.lang.String, tudresden.ocl.check.types.ModelFacade) perform type checking?
private  boolean m_fHandleCaretUpdates
           
private  boolean m_fInEditMode
          If true, we're in edit mode.
private  boolean m_fNoContextEdit
          Should the constraints context (everything up to the first 'inv', 'pre', or 'post') be un-editable?
private  JButton m_jbEdit
           
private  JButton m_jbNew
           
private  JButton m_jbPreferences
           
private  JButton m_jbRemove
           
private  JButton m_jbSaveEditResult
           
private  JCheckBox m_jcbQuickBar
           
private  JPanel m_jpConstraintListPane
           
private  JPanel m_jpEditorPanel
           
private  JPanel m_jpPreviewGroup
           
private  JPanel m_jpPreviewPane
           
private  JPanel m_jpToolbarWrapper
           
private  JScrollPane m_jspConstraintEditorScroller
           
private  JScrollPane m_jspConstraintListScroller
           
private  JScrollPane m_jspConstraintPreviewScroller
           
private  JSplitPane m_jspMainPane
           
private  JToolBar m_jtbTools
           
private  JTable m_jtConstraintList
           
private  JTextPane m_jtpConstraintEditor
           
private  JTextPane m_jtpConstraintPreview
           
private  int m_nOldDot
           
private  int m_nOldMark
           
private  int m_nOptionMask
          The options supported by this instance of the editor.
private  OCLEditorModel m_oclemModel
          The underlying model.
private  OCLToolbar m_ocltbQuickBar
           
static int OPTIONMASK_AUTOSPLIT
           
static int OPTIONMASK_TYPECHECK
           
private  JPanel pad1
           
private  JPanel pad2
           
private static SimpleAttributeSet s_sasField
          Attributes used to denote fields that need to be replaced.
private static SimpleAttributeSet s_sasNoEditText
          Attributes used to denote uneditable text.
private static SimpleAttributeSet s_sasNormalText
          Attributes used to denote normal OCL constraint text.
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
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
OCLEditor()
          Creates new form OCLEditor
 
Method Summary
(package private)  void addConstraintText(String[] saBefore, String sText, String[] saAfter)
          Add the given text to the edit pane, if a constraint is currently being edited.
 void constraintAdded(ConstraintChangeEvent cce)
          Select the newly added constraint.
 void constraintDataChanged(ConstraintChangeEvent cce)
          Update the editor if the currently selected constraint changed.
 void constraintNameChanged(ConstraintChangeEvent cce)
          Ignored.
 void constraintRemoved(ConstraintChangeEvent cce)
          If the current constraint was deleted, clear the selection.
protected  OCLEditor.ConstraintTableModel createConstraintTableModel()
          Create and return an instance of ConstraintTableModel that will be used to represent the list of constraints currently being edited.
protected  int getCaretPositionFromLineAndColumn(int nLine, int nCol)
          Compute caret position for the given line and column in the editor pane's text.
 boolean getDoAutoSplit()
          Return whether auto split mode is on.
 boolean getDoTypeCheck()
          Return whether type checking mode is on.
 OCLEditorModel getModel()
          Retrieve the underlying model.
 boolean getNoContextEdit()
          Return whether context editing is currently prohibited.
 int getOptionMask()
           
private  void initComponents()
          This method is called from within the constructor to initialize the form.
 boolean isInEditMode()
          Return true if the OCL editor is currently in edit mode.
 boolean isValidConstraintName(String sName)
          Checks the specified name and returns true if it is a valid OCL name.
private  void onCaretUpdate(CaretEvent evt)
           
private  void onEditButton(ActionEvent evt)
           
private  void onNewConstraintButton(ActionEvent evt)
           
private  void onPreferencesButton(ActionEvent evt)
           
private  void onQuickBarButton(ActionEvent evt)
           
private  void onRemoveConstraintButton(ActionEvent evt)
          React to the remove button.
private  void onSubmitConstraintButton(ActionEvent evt)
          React to the submit button.
 OclTree parseAndCheckConstraint(String sConstraint, ModelFacade mfFacade)
          Check the specified constraint using the specified model facade for model information.
 void setDoAutoSplit(boolean fDoAutoSplit)
          Set the auto split mode.
 void setDoTypeCheck(boolean fDoTypeCheck)
          Set the type checking mode.
 void setEditMode(boolean fEditMode)
          Set the edit mode of the OCL editor.
protected  void setEditorText(ConstraintRepresentation cr)
          Replace the contents of the edior by the data of the specified constraint.
 void setModel(OCLEditorModel oclemModel)
          Set the underlying model and update the display.
 void setNoContextEdit(boolean fNoContextEdit)
          Specify whether or not to allow editing the context of a constraint.
 void setOptionMask(int nOptionMask)
          Specify which user option check boxes should be displayed.
 List splitConstraint(OclTree ocltConstraint)
          Split the specified constraint into its constituting constraints.
 void valueChanged(ListSelectionEvent p1)
          The selection in the table changed.
protected  String wrapMessage(String sMessage, int nMaxLineLen)
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, 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, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, 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, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, 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, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, 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, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

s_sasField

private static SimpleAttributeSet s_sasField
Attributes used to denote fields that need to be replaced.


s_sasNormalText

private static SimpleAttributeSet s_sasNormalText
Attributes used to denote normal OCL constraint text.


s_sasNoEditText

private static SimpleAttributeSet s_sasNoEditText
Attributes used to denote uneditable text.


m_oclemModel

private OCLEditorModel m_oclemModel
The underlying model.


m_crCurrent

private ConstraintRepresentation m_crCurrent
The currently selected constraint, if any.


m_ctmTableModel

private OCLEditor.ConstraintTableModel m_ctmTableModel
The table model used by the list of constraints table.


m_fDoTypeCheck

private boolean m_fDoTypeCheck
Does parseAndCheckConstraint(java.lang.String, tudresden.ocl.check.types.ModelFacade) perform type checking?


m_fDoAutoSplit

private boolean m_fDoAutoSplit
Should multi-constraint inputs be automatically split into individual constraints?


m_fNoContextEdit

private boolean m_fNoContextEdit
Should the constraints context (everything up to the first 'inv', 'pre', or 'post') be un-editable?


OPTIONMASK_TYPECHECK

public static final int OPTIONMASK_TYPECHECK
See Also:
Constant Field Values

OPTIONMASK_AUTOSPLIT

public static final int OPTIONMASK_AUTOSPLIT
See Also:
Constant Field Values

m_nOptionMask

private int m_nOptionMask
The options supported by this instance of the editor. I.e., the options which will show up in the options dialog.


m_fInEditMode

private boolean m_fInEditMode
If true, we're in edit mode.


m_fConstraintChanged

private boolean m_fConstraintChanged
Set to false when beginning edit mode, evaluated at the end of editing a newly created constraint to determine whether to remove it again. When a constraintDataChanged(tudresden.ocl.gui.events.ConstraintChangeEvent) event is received for the currently selected constraint, this is set to true.


m_fCreatedFreshConstraint

private boolean m_fCreatedFreshConstraint
Indicates the constraint currently being edited is a newly created one. This means, it will be removed if no changes where made to it.


m_fHandleCaretUpdates

private boolean m_fHandleCaretUpdates

m_nOldDot

private int m_nOldDot

m_nOldMark

private int m_nOldMark

m_jtbTools

private JToolBar m_jtbTools

m_jbNew

private JButton m_jbNew

m_jbRemove

private JButton m_jbRemove

m_jbEdit

private JButton m_jbEdit

m_jbSaveEditResult

private JButton m_jbSaveEditResult

pad1

private JPanel pad1

m_jbPreferences

private JButton m_jbPreferences

pad2

private JPanel pad2

m_jcbQuickBar

private JCheckBox m_jcbQuickBar

m_jpToolbarWrapper

private JPanel m_jpToolbarWrapper

m_ocltbQuickBar

private OCLToolbar m_ocltbQuickBar

m_jpEditorPanel

private JPanel m_jpEditorPanel

m_jspConstraintEditorScroller

private JScrollPane m_jspConstraintEditorScroller

m_jtpConstraintEditor

private JTextPane m_jtpConstraintEditor

m_jspMainPane

private JSplitPane m_jspMainPane

m_jpConstraintListPane

private JPanel m_jpConstraintListPane

m_jspConstraintListScroller

private JScrollPane m_jspConstraintListScroller

m_jtConstraintList

private JTable m_jtConstraintList

m_jpPreviewPane

private JPanel m_jpPreviewPane

m_jpPreviewGroup

private JPanel m_jpPreviewGroup

m_jspConstraintPreviewScroller

private JScrollPane m_jspConstraintPreviewScroller

m_jtpConstraintPreview

private JTextPane m_jtpConstraintPreview
Constructor Detail

OCLEditor

public OCLEditor()
Creates new form OCLEditor

Method Detail

createConstraintTableModel

protected OCLEditor.ConstraintTableModel createConstraintTableModel()
Create and return an instance of ConstraintTableModel that will be used to represent the list of constraints currently being edited.

Attention! This method is called from the constructor and should therefore be overridden with great care. When referencing this from within this method care must be taken to recognize that this will not have been fully initialized yet. In particular, any field introduced by subclasses of OCLEditor will not have been initialized, and any code specified in constructors of subclasses of OCLEditor will not have been executed.

Returns:
an instance of ConstraintTableModel to be used to display the list of constraints being edited

getModel

public OCLEditorModel getModel()
Retrieve the underlying model.


setModel

public void setModel(OCLEditorModel oclemModel)
Set the underlying model and update the display.


isInEditMode

public boolean isInEditMode()
Return true if the OCL editor is currently in edit mode.


setEditMode

public void setEditMode(boolean fEditMode)
Set the edit mode of the OCL editor. Setting the edit mode to false cancels any current edit.


isValidConstraintName

public boolean isValidConstraintName(String sName)
Checks the specified name and returns true if it is a valid OCL name.

Specified by:
isValidConstraintName in interface EditingUtilities

setOptionMask

public void setOptionMask(int nOptionMask)
Specify which user option check boxes should be displayed.


getOptionMask

public int getOptionMask()

setNoContextEdit

public void setNoContextEdit(boolean fNoContextEdit)
Specify whether or not to allow editing the context of a constraint.


getNoContextEdit

public boolean getNoContextEdit()
Return whether context editing is currently prohibited.


setDoTypeCheck

public void setDoTypeCheck(boolean fDoTypeCheck)
Set the type checking mode.


getDoTypeCheck

public boolean getDoTypeCheck()
Return whether type checking mode is on. If this returns true, parseAndCheckConstraint(java.lang.String, tudresden.ocl.check.types.ModelFacade) will also check type conformance of constraints.


parseAndCheckConstraint

public OclTree parseAndCheckConstraint(String sConstraint,
                                       ModelFacade mfFacade)
                                throws OclParserException,
                                       IOException,
                                       OclTypeException
Check the specified constraint using the specified model facade for model information. Return the parse tree for the constraint.

This is a short-cut helper function for editor models that want to parse constraints before adding them to the model base.

Specified by:
parseAndCheckConstraint in interface EditingUtilities
Throws:
OclParserException - if a syntax error occurred.
IOException - if an I/O operation failed.
OclTypeException - if a type checking error occurred.

setDoAutoSplit

public void setDoAutoSplit(boolean fDoAutoSplit)
Set the auto split mode.


getDoAutoSplit

public boolean getDoAutoSplit()
Return whether auto split mode is on. If this returns true, constraint representations should call splitConstraint(tudresden.ocl.OclTree) and create one constraint representation per actual constraint.

Specified by:
getDoAutoSplit in interface EditingUtilities

splitConstraint

public List splitConstraint(OclTree ocltConstraint)
Split the specified constraint into its constituting constraints. E.g.
 context Test
 inv: a > 0
 inv: a < 10
 inv: a * 100 = 900
 
would be split into three constraints:
 context Test
 inv: a > 0

 context Test
 inv: a < 10

 context Test
 inv: a * 100 = 900
 

Specified by:
splitConstraint in interface EditingUtilities
Returns:
a list of abstract syntax trees, one per sub-constraint.

addConstraintText

void addConstraintText(String[] saBefore,
                       String sText,
                       String[] saAfter)
Add the given text to the edit pane, if a constraint is currently being edited. The text will replace the current selection. If saBefore/saAfter are not null and contain elements, these will be added as items to be replaced. The first such item will be selected.


setEditorText

protected void setEditorText(ConstraintRepresentation cr)
Replace the contents of the edior by the data of the specified constraint.


initComponents

private void initComponents()
This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the FormEditor.


onEditButton

private void onEditButton(ActionEvent evt)

onNewConstraintButton

private void onNewConstraintButton(ActionEvent evt)

onPreferencesButton

private void onPreferencesButton(ActionEvent evt)

onCaretUpdate

private void onCaretUpdate(CaretEvent evt)

onQuickBarButton

private void onQuickBarButton(ActionEvent evt)

wrapMessage

protected String wrapMessage(String sMessage,
                             int nMaxLineLen)

onSubmitConstraintButton

private void onSubmitConstraintButton(ActionEvent evt)
React to the submit button.


getCaretPositionFromLineAndColumn

protected int getCaretPositionFromLineAndColumn(int nLine,
                                                int nCol)
Compute caret position for the given line and column in the editor pane's text.


onRemoveConstraintButton

private void onRemoveConstraintButton(ActionEvent evt)
React to the remove button.


valueChanged

public void valueChanged(ListSelectionEvent p1)
The selection in the table changed.

Specified by:
valueChanged in interface ListSelectionListener

constraintAdded

public void constraintAdded(ConstraintChangeEvent cce)
Select the newly added constraint.

Specified by:
constraintAdded in interface ConstraintChangeListener

constraintRemoved

public void constraintRemoved(ConstraintChangeEvent cce)
If the current constraint was deleted, clear the selection.

Specified by:
constraintRemoved in interface ConstraintChangeListener

constraintNameChanged

public void constraintNameChanged(ConstraintChangeEvent cce)
Ignored.

Specified by:
constraintNameChanged in interface ConstraintChangeListener

constraintDataChanged

public void constraintDataChanged(ConstraintChangeEvent cce)
Update the editor if the currently selected constraint changed.

Specified by:
constraintDataChanged in interface ConstraintChangeListener

Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.