001    
002    package net.sourceforge.pavlov.controllers;
003    
004    import net.sourceforge.pavlov.library.*;
005    import net.sourceforge.sillyview.*;
006    import javax.swing.tree.DefaultMutableTreeNode;
007    import javax.swing.event.HyperlinkListener;
008    import javax.swing.event.HyperlinkEvent;
009    import java.net.URL;
010    import java.util.Collection;
011    import org.apache.log4j.*;
012    
013    /**
014     *@author     Haus
015     *@created    June 18, 2004
016     *@since      1.1
017     */
018    public class LibraryController extends Widget
019    {
020            private AbstractLibrary library;
021            /**
022             *  Description of the Field
023             */
024            public final static String BOOK = "<@BOOK>";
025            // FIXME: delete
026            /**
027             *  Description of the Field
028             */
029            public final static String CHAPTER = "<@CHAPTER>";
030            // FIXME: delete
031            /**
032             *  Description of the Field
033             */
034            public final static String START_QUIZ = "start_quiz";
035            /**
036             *  Description of the Field
037             */
038            public final static String START_QUIZ_COMMAND = "foobar.cgi";
039            // FIXME
040            /**
041             *  Description of the Field
042             */
043            public final static String BOOK_NAME = "book";
044            // FIXME: delete
045            /**
046             *  Description of the Field
047             */
048            public final static String CHAPTER_NAME = "chapter";
049            // FIXME: delete
050    
051            private VelocityModel model;
052    
053    
054            /**
055             *  Constructor for the LibraryController object
056             *
057             *@param  vu                       A WidgetView to display the library
058             *@param  lib                      A library to render
059             *@exception  java.io.IOException  Description of the Exception
060             *@exception  Exception            Description of the Exception
061             */
062            public LibraryController(WidgetView vu, AbstractLibrary lib)
063                    throws java.io.IOException, Exception
064            {
065                    super(vu);
066                    model = (VelocityModel)view.getModel();//new VelocityModel(template);
067                    Collection<AbstractBook> col = lib.getBooksReadOnly();
068                    model.setToken("books", col);
069                    model.setToken("start_quiz", START_QUIZ_COMMAND);
070                    // FIXED: view should be passed in as a parameter
071                    //view = new JPanelView(model, JPanelView.HTMLPANE);
072                    //FIXED: try to take this block out...
073                    //java.io.File f = new java.io.File("resources/views/");
074                    //view.setToken("BASE_URL", f.toURL());
075                    //FIXME: get from resourcebroker
076                    view.setToken(JPanelView.TITLE, "Pavlov Library");
077            }
078    
079    
080            /**
081             *  Sets the template attribute of the LibraryController object
082             *
083             *@param  tmp      The new template value
084             *@param  baseDir  The new template value
085             */
086            public void setTemplate(String tmp, java.io.File baseDir)
087            {
088                    model.setRawModel(tmp);
089                    try {
090                            view.setToken("BASE_URL", baseDir.toURL());
091                    }
092                    catch (java.net.MalformedURLException e) {
093                            System.out.println(e);
094                    }
095            }
096    
097            /**
098             *  Sets the template attribute of the LibraryController object
099             *
100             *@param  tmp      The new template value
101             *@param  baseDir  The new template value
102             */
103            public void setBaseDirectory(java.io.File baseDir)
104            {
105                    try {
106                            view.setToken("BASE_URL", baseDir.toURL());
107                    }
108                    catch (java.net.MalformedURLException e) {
109                            System.out.println(e);
110                    }
111            }
112    
113            
114            /**
115             *  Sets the hyperlinkListener attribute of the LibraryController object
116             *
117             *@param  h  The new hyperlinkListener value
118             */
119            public void setHyperlinkListener(HyperlinkListener h)
120            {
121                    view.setToken(JPanelView.HYPERLINK_LISTENER, h);
122            }
123    
124    }
125