[Spedit-commits] CVS: prototype/Sources/net/sourceforge/spedit/app Pool.java,NONE,1.1 Application.ja
Status: Planning
Brought to you by:
krunte
|
From: S?bastien P. <kaz...@us...> - 2001-11-27 10:31:44
|
Update of /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/app In directory usw-pr-cvs1:/tmp/cvs-serv25172/sourceforge/spedit/app Modified Files: Application.java NavigationTree.java Added Files: Pool.java Log Message: Apart from the new SPML package many improvements have been done both to the StyleSheet and to the Views. There is now a basic layout management in the Views using the "stick" element of Padding style properties groups in XSS. One of the interesting aspect is the Pool class that gathers resources allowing the editor to dynamically manage resources. This is particulary useful for images/icons. --- NEW FILE: Pool.java --- // ---------------------------------------------------@RisingSun//Java//1.0//EN // Project : SPEdit-Prototypes // ClassName : Pool // Version : 0.50 // Type : Resource collector // ThreadSafe : Yep // Description : Gathers resources, providing a way to cache them. // URL : <http://spedit.sf.net> // ---------------------------------------------------------------------------- // Authors : Sbastien Pierre <sp...@is...> // ---------------------------------------------------------------------------- // Creation date : 23-Nov-2001 // Last mod. : 23-Nov-2001 // History : // 23-Nov-2001 First implementation.(sp) // // Bugs : // - // // To do : // package net.sourceforge.spedit.app; import java.util.*; //----------------------------------------------------------------------------- // // Pool // //----------------------------------------------------------------------------- /** * <p>The <code>Pool</code> class is a <em>resource collector</em>. This * basically means that the pool plays the role of a cache, which is especially * useful for images or icons. Basically when an extension needs an image or * another file it should use the pool, which will take care of loading it * properly and * cache it.</p> * <p>The nested abstract <code>Resource</code> class allows to put any kind * of resource into the pool. The resource charcteristics are that they are * identifiend by an URI which should be asbolute, that they can contain * any kind of object, that they are observable, can be refreshed and mutated. * Typical use case is run-time reloding of icons, or simply changing the * application localization on the fly.</p> */ public class Pool { //PROTECTED________________________________________________________________ protected Hashtable resourcePool; //------------------------------------------------------------------------- // // Constructors // //------------------------------------------------------------------------- /** * Creates a new resource pool. */ public Pool() { resourcePool = new Hashtable(); } //------------------------------------------------------------------------- // // Resource access & monitoring // //------------------------------------------------------------------------- /** * Puts a new resource into the pool. Take care of putting absolute uri, * otherwise there may be some conflicts with the resources. * @param resource the resource to be added. */ public void putResource(Resource resource) { resourcePool.put(resource.getURI(), resource); } /** * Access the given resource in the pool. * @param the URI identifying the resource. * @return the requested resource, or <code>null</code> if it has not * been found. */ public Resource getResource(String uri) { return (Resource)resourcePool.get(uri); } /** * Releases the given resource from the pool, this actually means * deleting it from the pool resource registry. * @param uri the uri identifying the resource * @return the released resource, or <code>null</code> if it has not * been found. */ public Resource releaseResource(String uri) { return (Resource)resourcePool.remove(uri); } /** * Releases the given resource from the pool, this actually means * deleting it from the pool resource registry. * @param resource the resource to be released from the pool. * @return the released resource, or <code>null</code> if it has not * been found. */ public Resource releaseResource(Resource resource) { return (Resource)resourcePool.remove(resource.getURI()); } //------------------------------------------------------------------------- // // Resource object // //------------------------------------------------------------------------- /** * <p>A resource is a mutable wrapper around an object, storing information * on the object source, allowing the resource to be observed in case it * changes, and allowing the resource to be refreshed.</p> */ public abstract class Resource extends Observable { protected String uri; protected Object resource; protected Exception e; /** * Creates a new resource with the given URI. The resource will * be loaded automatically. If an exception occurs, the resource * will be kept null and the exception can be reached using the * <code>getException</code> method. * @param uri URI of the resource to be loaded. */ public Resource(String uri) { this.uri = uri; this.resource = null; this.refresh(); } /** * Mutates the resource, changing its former value to the new value. * There is no checking on the resource consistency, this means that * you can mutate a List into an Image if you like, so use this method * with care. * @param resource is the new object that will be assigned to the * current resource. * @return the previous content of the resource. */ public synchronized Object mutate(Object resource) { Object oldres = this.resource; this.resource = resource; setChanged(); notifyObservers(resource); return oldres; } /** * Refreshes the resource content, trying to reload it. If an exception * happens during the refresh, the old resource value is kept and the * exception is made available using the <code>getException</code> method. * Note that this method should be implemented as <code>synchronized</code>. * @see #getException */ public abstract void refresh(); /** * Returns the resource content. This can be null in case an exception * has occured during the resource loading or refresh. In this case the * exception can be reached using the <code>getException</code> method. * @return The actual resource content, which may be <code>null</code> * in case an error has occured. * @see #getException */ public Object getContent() { return resource; } /** * This method can be called in case the resource <code>getContent</code> * method returns <code>null</code>. * @return Generally returns <code>null</code>, returns an exception when * an exception occured during resource loading or refresh. * @see #getContent */ public Exception getException() { return e; } /** * Returns the URI which describes the location of the resource. */ public String getURI() { return uri; } } //------------------------------------------------------------------------- // // Image resource // //------------------------------------------------------------------------- } // EOF-Unix/ISO-8859-1--------------------------------@RisingSun//Java//1.0//EN Index: Application.java =================================================================== RCS file: /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/app/Application.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Application.java 2001/11/21 11:02:02 1.4 --- Application.java 2001/11/27 10:31:41 1.5 *************** *** 2,6 **** // Project : SPEdit-Prototypes // ClassName : Application ! // Version : 0.10 // Type : Swing application // ThreadSafe : Yep --- 2,6 ---- // Project : SPEdit-Prototypes // ClassName : Application ! // Version : 0.20 // Type : Swing application // ThreadSafe : Yep *************** *** 12,17 **** // ---------------------------------------------------------------------------- // Creation date : 15-Sep-2001 ! // Last mod. : 24-Oct-2001 // History : // 24-Sep-2001 Moved inside the app package, better doc // and structure.(sp) --- 12,18 ---- // ---------------------------------------------------------------------------- // Creation date : 15-Sep-2001 ! // Last mod. : 22-Nov-2001 // History : + // 22-Nov-2001 Added code for Python modules path.(sp) // 24-Sep-2001 Moved inside the app package, better doc // and structure.(sp) *************** *** 69,72 **** --- 70,83 ---- public Application() { + //We initialize the PYTHONPATH equivalent that tells where modules can + //be found. + Properties props = new Properties(); + python.execfile("../Support/Application.py"); + File ext = new File("../Execution/Scripts"); + try { + python.exec("import sys ; sys.path.append('"+ext.getCanonicalPath()+"')"); + } + catch (IOException e) + { System.err.println("Scripts dir does not exist..."); } documentFrames = new Vector(); currentDocumentFrame = new DocumentFrame(); *************** *** 74,82 **** } - public void init() - { - currentDocumentFrame.init(); - } - //------------------------------------------------------------------------- // --- 85,88 ---- *************** *** 141,145 **** navigator = new NavigationTree(this); //editorKit = new XMLEditorKit("../Support/Configuration.xml"); ! editorKit = new XMLEditorKit("../Support/SP-Configuration.xml"); editorPane.setEditorKit(editorKit); factory = (XMLViewFactory)editorKit.getViewFactory(); --- 147,152 ---- navigator = new NavigationTree(this); //editorKit = new XMLEditorKit("../Support/Configuration.xml"); ! //editorKit = new XMLEditorKit("../Support/SP-Configuration.xml"); ! editorKit = new XMLEditorKit("../Support/ON-Configuration.xml"); editorPane.setEditorKit(editorKit); factory = (XMLViewFactory)editorKit.getViewFactory(); *************** *** 151,156 **** { //We load the custom file ! File ff = new File("../Support/SP-P11388.xml"); ! //File ff = new File("../Support/SP-Document.xml"); document = XMLDocument.loadFromFile(ff, factory); document.filter(factory); --- 158,163 ---- { //We load the custom file ! //File ff = new File("../Support/SP-P11388.xml"); ! File ff = new File("../Support/ON-Document.xml"); document = XMLDocument.loadFromFile(ff, factory); document.filter(factory); *************** *** 159,164 **** //We set layout for container getContentPane().setLayout(new XmFormLayout(constraints)); ! ! python.execfile("../Support/Application.py"); python.set("frame", this); python.exec("listener = MenuListener(frame)"); --- 166,170 ---- //We set layout for container getContentPane().setLayout(new XmFormLayout(constraints)); ! python.set("frame", this); python.exec("listener = MenuListener(frame)"); *************** *** 218,237 **** --- 224,248 ---- } } + evt.consume(); } public void mouseEntered(MouseEvent evt) { + evt.consume(); } public void mouseExited(MouseEvent evt) { + evt.consume(); } public void mousePressed(MouseEvent evt) { + evt.consume(); } public void mouseReleased(MouseEvent evt) { + evt.consume(); } *************** *** 365,368 **** --- 376,380 ---- view.replace(0,view.getViewCount(),new View[0]); //FIXME: Insertion should be made through the DOM... + newElement.getWrapper().getInformation().setNewlyCreated(true); wrapper.insert(newElement,pos,javax.swing.text.Position.Bias.Forward); //This makes the actual forced reaload after element insertion. Index: NavigationTree.java =================================================================== RCS file: /cvsroot/spedit/prototype/Sources/net/sourceforge/spedit/app/NavigationTree.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NavigationTree.java 2001/11/01 15:41:43 1.1 --- NavigationTree.java 2001/11/27 10:31:41 1.2 *************** *** 10,14 **** // URL : <http://spedit.sf.net> // ---------------------------------------------------------------------------- ! // Authors : Sébastien Pierre <sp...@is...> // ---------------------------------------------------------------------------- // Creation date : 19-Oct-2001 --- 10,14 ---- // URL : <http://spedit.sf.net> // ---------------------------------------------------------------------------- ! // Authors : Sbastien Pierre <sp...@is...> // ---------------------------------------------------------------------------- // Creation date : 19-Oct-2001 |