[brailleblaster] Re: Implementing StyledTextContent

  • From: "John J. Boyer" <john@xxxxxxxxxxxxxx>
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Tue, 18 Oct 2011 12:23:34 -0500

Chris,

I'm still climbing the learning curve of SWT and especially the custom 
package. There is a lot I don't understand. But I agree that any 
StyledTextContent implementation will have to be suppemented with 
StyleRamnge, etc. ShyledText does have facilities for inserting images. 
In fact, there is a snippet that showss how. I think the content model 
moight deal with images. If I remember right you can also add a 
PaintObject listener to Styled text. 

It'll take a lot more study before all this becomes clear no me. The 
implementation of rendering and editing for BrailleBlaster is going to 
be hard, and there's no getting around it.

Thanks,
John

On Tue, Oct 18, 2011 at 09:55:33AM -0700, Chris von See wrote:
> I haven't studied SWT or the StyledText related classes extensively, but it's 
> not clear to me how you'd be able to tell the StyledText widget to insert an 
> image unless you use StyleRange objects.  The API for StyledTextContent seems 
> to deal with everything as String objects, so you'd have to create any 
> StyleRange objects representing images or existing text styling (bold, 
> italic, etc.) directly on the StyledText widget.  Have you found an example 
> of a StyledTextContent class that serves images and styling info to 
> StyledText? and if so, can you send me a link?
> 
> Usually library designers make classes private because they don't want people 
> to use them ;)
> 
> Cheers
> Chris
> 
> 
> 
> On Oct 18, 2011, at 4:37 AM, John J. Boyer wrote:
> 
> > Mapping between the braille and Daisy views is handled by UTDML. It add 
> > this information to the xml document, so everything is in the xml parse 
> > tree. As I understand content models, one objective is to avoid data 
> > duplication. In the case of BrailleBlaster, another thing a content 
> > model would do is to take the text, math images, and UTDML information 
> > in the parse tree and send it to the StyledText widgets for the two 
> > views to be displayed. Another thing is to take the user's changes and 
> > modify the parse tree. I don't see how writing a custom content model 
> > can be avoided. Trying to find an easier way will probably just lead to 
> > dead ends. 
> > 
> > Why do you think the authors of SWT didn't make StyledTextEvent public? 
> > Was it a mistake or did they have a good reason? 
> > 
> > I've actually looked at TextEditor quite a lot, but I'm still not clear 
> > on which methods in StyledTextContent are to be called by the StyledText 
> > widget itself and which ones are to be called by the application.
> > 
> > Finding examples of SWT certainly is a pain. Fortunately, the snippets 
> > are easy.
> > 
> > Thanks,
> > John
> > 
> > On Mon, Oct 17, 2011 at 05:35:24PM -0700, Chris von See wrote:
> >> I'm glad you found my example helpful.
> >> 
> >> For some examples of how listeners and events can be used with StyledText, 
> >> you may want to look at the "texteditor" example from the SWT examples 
> >> JAR.  The code may not be relevant to BrailleBlaster, but at least it'll 
> >> give you an example implementation to look at.  I've attached the code to 
> >> save you the trouble of looking for it - it's a pain in the tail to find ;)
> >> 
> >> Another off-the-top-of-my-head option you might consider for synchronizing 
> >> the DAISY and braille views and for handling the presentation differences 
> >> between the two would be to use some sort mechanism that maps StyleRange 
> >> objects in the two views to each other.  The key to making such a map work 
> >> would be to ensure that all text in both views has a StyleRange created 
> >> when it is loaded into the StyledText control, but once that's done 
> >> handling changes between the two views would be very straightforward and 
> >> you wouldn't need custom StyleTextContent implementations any more.
> >> 
> >> 
> >> Cheers
> >> Chris
> >> 
> > 
> > 
> >> 
> >> 
> >> 
> >> On Oct 17, 2011, at 5:03 PM, John J. Boyer wrote:
> >> 
> >>> Chris,
> >>> 
> >>> Adding to my previous message.
> >>> 
> >>> It appears that the only method in DefaultContent that user 
> >>> StyledTextEvent and that I need be concerned about is replaceTextRange. 
> >>> Hopefully I will not have to override it. 
> >>> 
> >>> I'm considering adapting your code suggestion for the classes 
> >>> BrailleContent and DaisyContent, which will be used by the two views, 
> >>> respectively. Their requirelments are quite different. There will also 
> >>> be a ContentCommons class for shared code. This will be like the 
> >>> transcommon.ci module in liblouis, which is included by both 
> >>> lou_translateString.c and lou_backTranslateString.c
> >>> 
> >>> I must say that i'm not very satisfied with my understanding of envents 
> >>> and listeners in general and with how they are used in StyledText in 
> >>> particular. 
> >>> 
> >>> John
> >>> 
> >>> On Mon, Oct 17, 2011 at 12:02:46PM -0500, John J. Boyer wrote:
> >>>> Chris,
> >>>> 
> >>>> This is a good start. However, in some of the methods that override the 
> >>>> baseContent I will probably have to refer to StyledTextEvent and the 
> >>>> problem will reappear. I  don't really care what the compiler is 
> >>>> complaining about as long as we have somehting that works. 
> >>>> 
> >>>> John
> >>>> 
> >>>> On Mon, Oct 17, 2011 at 09:38:06AM -0700, Chris von See wrote:
> >>>>> If the default context can't be subclassed then can you do something 
> >>>>> like this:
> >>>>> 
> >>>>> public class BrailleBlasterContentModel implements StyledTextContent
> >>>>> {
> >>>>>         private StyledTextContent baseContent;
> >>>>>         private BrailleTranslator brailleTranslator;
> >>>>> 
> >>>>>         public BrailleBlasterContentModel(final StyledText styledText) {
> >>>>>                 baseContent = styledText.getContent();
> >>>>>                 styledText.setContent(this);
> >>>>> 
> >>>>>                 brailleTranslator = new 
> >>>>> LiblouisThingThatTranslatesToBraille();
> >>>>>         }
> >>>>> 
> >>>>>         public void addTextChangeListener(final TextChangeListener 
> >>>>> listener)  {
> >>>>>                 baseContent.addTextChangeListener(listener);
> >>>>>         }
> >>>>> 
> >>>>>         // continue to provide implementations from the 
> >>>>> StyledTextContent interface and delegate them to the stored
> >>>>>         // content model.  For methods that need new behavior, do 
> >>>>> whatever you need to do and call the stored
> >>>>>         // content model only if needed.
> >>>>> 
> >>>>>         public String getTextRange(final int start, final int length) {
> >>>>>                 // here let's pretend that you need additional 
> >>>>> functionality, so you take the content from the base model
> >>>>>                 // and do stuff to it
> >>>>>                 return 
> >>>>> brailleTranslator.toBraille(baseContent.getTextRange(start, length));
> >>>>>         }
> >>>>> }
> >>>>> 
> >>>>> 
> >>>>> I'm just trying to save you the pain of copying the Eclipse code and 
> >>>>> having to maintain it if/when it evolves.  I can't tell you what your 
> >>>>> compiler error is unless I look at your code.
> >>>>> 
> >>>>> Cheers
> >>>>> Chris
> >>>>> 
> >>>>> 
> >>>>> On Oct 17, 2011, at 8:47 AM, John J. Boyer wrote:
> >>>>> 
> >>>>>> DefaultContent.java says it is not intended to be subclassed. The 
> >>>>>> content model will have to conect what StyledText displays and the 
> >>>>>> user 
> >>>>>> changes with the underlying xml. Even if DefaultContent could be 
> >>>>>> subclassed StyledTextEvent is still needed. It performs important 
> >>>>>> functions in DefaultContent. The puzle is how the compiler can claim 
> >>>>>> that a class with a different name is a duplicate of one in  
> >>>>>> swt.custom 
> >>>>>> 
> >>>>>> John
> >>>>>> 
> >>>>>> On Mon, Oct 17, 2011 at 08:12:01AM -0700, Chris von See wrote:
> >>>>>>> Can you just extend the default StyledTextContent implementation and 
> >>>>>>> override the methods that you need to in order to implement the 
> >>>>>>> functionality you want?  What do you want to do that the default 
> >>>>>>> implementation doesn't do?
> >>>>>>> 
> >>>>>>> Cheers
> >>>>>>> Chris
> >>>>>>> 
> >>>>>>> 
> >>>>>>> On Oct 17, 2011, at 2:36 AM, John J. Boyer wrote:
> >>>>>>> 
> >>>>>>>> The Braille and Daisy views have quite different requirements, so it 
> >>>>>>>> is 
> >>>>>>>> best to implement a StyledTextContent model for each one. I thought 
> >>>>>>>> to 
> >>>>>>>> use the DefaultContent class as a starting point. The Eclipse 
> >>>>>>>> license 
> >>>>>>>> permits this. Si I copied it to org.brailleblaster.wordprocessor and 
> >>>>>>>> started modifying it. Various import statements had to be added. 
> >>>>>>>> When I 
> >>>>>>>> tried to import StyledTextEvent I was told that it was not public in 
> >>>>>>>> the 
> >>>>>>>> custom SWT package. So I copied that also. Then the compiler gave 
> >>>>>>>> the 
> >>>>>>>> message that it was a duplicate class, presumably because it had the 
> >>>>>>>> same name as a class in the classpath. So I changed the name 
> >>>>>>>> slightly. 
> >>>>>>>> The compiler still gives the same message, claiming that a class 
> >>>>>>>> with 
> >>>>>>>> the changed name exists in swt.custom, which it does not. It appears 
> >>>>>>>> to 
> >>>>>>>> be important for the content model to use the StyledTextEvent. What 
> >>>>>>>> is 
> >>>>>>>> the work-around for this problem?
> >>>>>>>> 
> >>>>>>>> Thanks,
> >>>>>>>> John
> >>>>>>>> 
> >>>>>>>> -- 
> >>>>>>>> John J. Boyer; President, Chief Software Developer
> >>>>>>>> Abilitiessoft, Inc.
> >>>>>>>> http://www.abilitiessoft.com
> >>>>>>>> Madison, Wisconsin USA
> >>>>>>>> Developing software for people with disabilities
> >>>>>>>> 
> >>>>>>>> 
> >>>>>>> 
> >>>>>> 
> >>>>>> -- 
> >>>>>> John J. Boyer; President, Chief Software Developer
> >>>>>> Abilitiessoft, Inc.
> >>>>>> http://www.abilitiessoft.com
> >>>>>> Madison, Wisconsin USA
> >>>>>> Developing software for people with disabilities
> >>>>>> 
> >>>>>> 
> >>>>> 
> >>>> 
> >>>> -- 
> >>>> John J. Boyer; President, Chief Software Developer
> >>>> Abilitiessoft, Inc.
> >>>> http://www.abilitiessoft.com
> >>>> Madison, Wisconsin USA
> >>>> Developing software for people with disabilities
> >>>> 
> >>> 
> >>> -- 
> >>> John J. Boyer; President, Chief Software Developer
> >>> Abilitiessoft, Inc.
> >>> http://www.abilitiessoft.com
> >>> Madison, Wisconsin USA
> >>> Developing software for people with disabilities
> >>> 
> >>> 
> >> 
> > 
> > 
> > -- 
> > John J. Boyer; President, Chief Software Developer
> > Abilitiessoft, Inc.
> > http://www.abilitiessoft.com
> > Madison, Wisconsin USA
> > Developing software for people with disabilities
> > 
> > 
> 

-- 
John J. Boyer, Executive Director
GodTouches Digital Ministry, Inc.
http://www.godtouches.org
Madison, Wisconsin, USA
Peace, Love, Service


Other related posts: