wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Uneditable ParagraphViews Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Uneditable ParagraphViews" Watch "Uneditable ParagraphViews" New topic
Author

Uneditable ParagraphViews

marcos robinson
Greenhorn

Joined: Nov 20, 2012
Posts: 5
I would like to have a document editor where certain document lines are uneditable, unclickable, etc.

I currently am using a JTextPane for my editor and extensions of DefaultStyledDocument and LeafElement, StyledEditorKit, and ParagraphView, to parse the document text into the appropriate elements and assign them to the appropriate extensions of ParagraphView. Everything is peachy up to this point.

So how to take the next step? How to designate and enforce certain extended ParagraphViews are "read-only"? My current approach is to override getNextVisualPositionFrom in the Leaf and Section ParagraphViews to prevent arrow keys from moving the cursor into a restricted ParagraphView, but preventing the mouse from clicking inside a restricted ParagraphView has to be handled separately.

Is there a simpler, more comprehensive approach to this? Thanks!
marcos robinson
Greenhorn

Joined: Nov 20, 2012
Posts: 5
After a bit more research, a different approach that seems to fit more elegantly is to use a ComponentView for the uneditable views, instead of ParagraphView.
I can then use something as simple as a JTextArea in the ComponentView in its createComponent() method and setEditable to false.

It automatically ignores mouse clicks in that view. I still have to include my code for nicely skipping the caret over the view when the user presses up, down, left, right. Otherwise, the caret will invisibly move through underlying model text. I will also have to prevent backspacing through the protected view. Even though the view is uneditable, the model data underneath can still be affected by the user.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Uneditable ParagraphViews