Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a couple of things going on here.</p> <p>The Java framework is offering you a nice way updated your UI but constrains you to using a specific structure, Document.</p> <p>On the other hand you have a adequate model that represents your data. By using Document directly in your model you also take the risks of tying your model to a specific framework. Which isn't a good idea.</p> <p>The Java Document framework offers the ability to listen to changes you can leverage this into creating an <a href="http://en.wikipedia.org/wiki/Adapter_pattern" rel="nofollow noreferrer">Adapter class</a> between your model and Document. Basically when you setup the form you will make an instance of the adapter class. You will initialize with your model. The adapter will have a property returning a document. IN addition the Adapter will register itself as the listener for that document model. The adapter will be smart enough to know how to translate the chances to the document model to your model. </p> <p>Goes something like this</p> <ol> <li>UI is Created along with the JTextDocument.</li> <li>In the creation process it requests your model from the View.</li> <li>It create an instance of the Adapter initializing it with your model.</li> <li>The adapter also sets itself up as the listener of the Document.</li> <li>Assign the document to the JTextDocument object.</li> <li>Any interaction with the Document is reported back to Adapter</li> <li>The Adapter notifies the View passing the translated data back.</li> <li>The View changes the Model.</li> <li>The View nofitifies the Adapter that the model has change.</li> <li>The Adapter translates the changes into changes to the document.</li> </ol> <p>Because the adapter is tied to the Java Framework is should be pushed as close to the UI as it can get. Likely the Adapter will implement a interface exposed by the View so that the View doesn't have to reference anything specific to the framework you are using. When you change framework all you have to do is make a new object that implements that interface and the View is none the wiser.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload