Re: [picocontainer-dev] Swing MVC example app

Paul Hammant <[email protected]>
Newsgroups gmane.comp.java.picocontainer.devel
Message-ID <[email protected]>
>
>
> The app needs a little work.  There as some mutually referent  
> components that I'm sure needn't be so directly entangled.


I'll elaborate :-)

I looked at quite a few publicly available Swing examples and most  
were way to messy for me to take on and complete in a bout of  
insomnia.  This one was bite sized though.

The original Main class was more direct DI.  The unsavory bit is the  
sour lines where controller is being told of two models and two  
views.  Its a sort of circular reference, and typical of MVC swing  
apps.  I solved it my making the constructors for the four components  
do more work - they now immediately add themselves as views/models to  
single controller class.

I'm sure there's way where there could be a sink and a broadcaster  
that do not act together until some method in the start() phase links  
them.

The original main class is below.  The new one :- http://svn.codehaus.org/picocontainer/java/sandbox/swing_mvc_example/src/java/com/sun/example/mvc/Main.java

> public class Main {
>
>     /** Creates a new instance of Main */
>     public Main() {
>
>         TextElementModel textElementModel = new TextElementModel();
>         DocumentModel documentModel = new DocumentModel();
>
>         DefaultController controller = new DefaultController();
>
>         DisplayViewPanel displayViewPanel = new  
> DisplayViewPanel(controller);
>         PropertiesViewPanel propertiesViewPanel = new  
> PropertiesViewPanel(controller);
>
>         controller.addView(displayViewPanel);
>         controller.addView(propertiesViewPanel);
>         controller.addModel(textElementModel);
>         controller.addModel(documentModel);
>
>         textElementModel.initDefault();
>         documentModel.initDefault();
>
>
>         JFrame displayFrame = new JFrame("Display (View 1)");
>         displayFrame.getContentPane().add(displayViewPanel,  
> BorderLayout.CENTER);
>          
> displayFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
>         displayFrame.pack();
>
>         JDialog propertiesDialog = new JDialog(displayFrame,  
> "Properties (View 2)");
>         propertiesDialog.setModal(false);
>         propertiesDialog.getContentPane().add(propertiesViewPanel,  
> BorderLayout.CENTER);
>         propertiesDialog.pack();
>
>         displayFrame.setVisible(true);
>         propertiesDialog.setVisible(true);
>
>
>
>     }
>
>     /**
>      * @param args the command line arguments
>      */
>     public static void main(String[] args) {
>         Main main = new Main();
>     }


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.