You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pp...@apache.org on 2010/05/25 07:24:35 UTC

svn commit: r947918 - in /openjpa/trunk/openjpa-examples/openbooks/src/main: java/jpa/tools/swing/ java/openbook/client/ java/openbook/tools/converter/ java/openbook/util/ resources/

Author: ppoddar
Date: Tue May 25 05:24:34 2010
New Revision: 947918

URL: http://svn.apache.org/viewvc?rev=947918&view=rev
Log:
Improve upon Source Code browsing

Added:
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java   (with props)
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/SourceCodeBrowser.java   (with props)
    openjpa/trunk/openjpa-examples/openbooks/src/main/resources/java.css   (with props)
Modified:
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/BuyBookPage.java
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Images.java
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/tools/converter/ParseTokenListener.java
    openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/util/PropertyHelper.java

Added: openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java?rev=947918&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java (added)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java Tue May 25 05:24:34 2010
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+package jpa.tools.swing;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A map with indexed access.
+ * The keys are indexed in their order of insertion.
+ * The index of a given key is stable. It never changes unless the map is cleared.
+ * On <code>remove(k)</code>, the key is not removed, but its value is nullified.
+ * Then <code>indexOf(k)</code> will return <code>-1</code>.
+ * 
+ *  
+ * @author Pinaki Poddar
+ *
+ * @param <K>
+ * @param <V>
+ */
+public class IndexedMap<K,V> implements Map<K, V> {
+    private final List<K> _keys = new ArrayList<K>();
+    private final List<V> _values = new ArrayList<V>();
+    private final Set<K> _nulls = new HashSet<K>();
+    
+    public void clear() {
+        _keys.clear();
+        _values.clear();
+    }
+    
+    
+    public boolean containsKey(Object key) {
+        return _keys.contains(key) && !_nulls.contains(key);
+    }
+    
+    
+    public boolean containsValue(Object value) {
+        return _values.contains(value);
+    }
+    
+    /**
+     * Not supported.
+     */
+    public Set<java.util.Map.Entry<K, V>> entrySet() {
+        throw new UnsupportedOperationException();
+    }
+    
+    
+    public V get(Object key) {
+        int i = indexOf(key);
+        return i == -1 ? null : _values.get(i);
+    }
+    
+    public boolean isEmpty() {
+        return (_keys.size() - _nulls.size()) == 0;
+    }
+    
+    public Set<K> keySet() {
+        Set<K> result = new HashSet<K>(_keys);
+        result.removeAll(_nulls);
+        return result;
+    }
+    
+    public V put(K key, V value) {
+        int i = _keys.indexOf(key);
+        if (i == -1) {
+            _keys.add(key);
+            _values.add(value);
+            return null;
+        } else {
+            _nulls.remove(key);
+            return _values.set(i, value);
+        }
+    }
+    
+    public void putAll(Map<? extends K, ? extends V> m) {
+        for (K k : m.keySet()) {
+            this.put(k, m.get(k));
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    public V remove(Object key) {
+        V v = get(key);
+        _nulls.add((K)key);
+        return v;
+    }
+    
+    public int size() {
+        return _keys.size() - _nulls.size();
+    }
+    
+    public Collection<V> values() {
+        Collection<V> result = new ArrayList<V>();
+        for (int i = 0; i < _values.size(); i++) {
+            if (!_nulls.contains(_keys.get(i)))
+                result.add(_values.get(i));
+        }
+        return result;
+    }
+    
+    public int indexOf(Object key) {
+        return _keys.indexOf(key);
+    }
+}

Propchange: openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/IndexedMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java?rev=947918&r1=947917&r2=947918&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java (original)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/jpa/tools/swing/SourceCodeViewer.java Tue May 25 05:24:34 2010
@@ -15,23 +15,26 @@ package jpa.tools.swing;
 
 import java.awt.BorderLayout;
 import java.awt.FlowLayout;
-import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.util.Map;
+import java.net.URI;
+import java.net.URL;
+import java.util.LinkedList;
 
 import javax.swing.Box;
 import javax.swing.DefaultComboBoxModel;
+import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JEditorPane;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JScrollBar;
 import javax.swing.JScrollPane;
 
 
 /**
- * A viewer for source code.
- * The input to this viewer is a root URL and set of anchors.
+ * An internal viewer for HTML formatted source code.
+ * The input to this viewer is a root URL.
  * The viewer shows the anchors in a combo-box and displays the
  * corresponding HTML in the main editor. 
  * 
@@ -39,62 +42,87 @@ import javax.swing.JScrollPane;
  *
  */
 @SuppressWarnings("serial")
-public class SourceCodeViewer extends JPanel implements ActionListener {
+public class SourceCodeViewer extends JPanel {
     private final JEditorPane _editor;
     private final JComboBox   _bookmarks;
-    private Map<String, String> _anchors;
-    private String _root;
+    private IndexedMap<String, URI> _anchors = new IndexedMap<String, URI>();
+    private LinkedList<String> _visited = new LinkedList<String>();
     
     /**
-     * Create a Source Code Viewer for a set of anchors.
-     * @param root the root url 
-     * @param anchors the key is a visible text and value is the URL
-     * relative to the root.
+     * Create a Source Code Browser.
      */
-    public SourceCodeViewer(String root, Map<String,String> anchors) {
+    public SourceCodeViewer() {
         super(true);
         setLayout(new BorderLayout());
         
-        _anchors = anchors;
-        _root = root;
         _editor = new JEditorPane();
         _editor.setContentType("text/html");
-        _editor.setFont(new Font("Courier New", Font.PLAIN, 16));
         _editor.setEditable(false);
         
         DefaultComboBoxModel model = new DefaultComboBoxModel();
-        for (String key : anchors.keySet()) {
-            model.addElement(key);
-        }
         _bookmarks = new JComboBox(model);
-        _editor.setEditable(false);
         _bookmarks.setEditable(false);
         
-        _bookmarks.addActionListener(this);
+        _bookmarks.addActionListener(new ActionListener(){
+            public void actionPerformed(ActionEvent e) {
+                showAnchor((String)_bookmarks.getSelectedItem());
+            }
+        });
         
-        add(new JScrollPane(_editor), BorderLayout.CENTER);
         JPanel topPanel = new JPanel();
         ((FlowLayout)topPanel.getLayout()).setAlignment(FlowLayout.LEADING);
         topPanel.add(new JLabel("Go to "));
         topPanel.add(_bookmarks);
         topPanel.add(Box.createHorizontalGlue());
-        add(topPanel, BorderLayout.NORTH);
         
-        if (_anchors != null && !_anchors.isEmpty())
-           showPage(_anchors.keySet().iterator().next());
+        
+        add(new JScrollPane(_editor,
+                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, 
+                JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS), 
+                BorderLayout.CENTER);
+        add(topPanel, BorderLayout.NORTH);
     }
-   
-    public void actionPerformed(ActionEvent e) {
-        String anchor = (String)_bookmarks.getSelectedItem();
-        showPage(anchor);
+    
+    /**
+     * Add a page to this browser.
+     * 
+     * @param anchor a user visible description to identify the page
+     * @param uri the unique resource location
+     */
+    public void addPage(String anchor, URI url) {
+        _anchors.put(anchor, url);
+        ((DefaultComboBoxModel)_bookmarks.getModel()).addElement(anchor);
     }
     
-    private void showPage(String anchor) {
+    /**
+     * Shows the page identified by the given anchor.
+     * 
+     * @param anchor an anchor added a priori.
+     */
+    public void showAnchor(String anchor) {
+        int i = _anchors.indexOf(anchor);
+        if (i == -1)
+            return;
+        showPage(anchor, _anchors.get(anchor));
+    }
+   
+    /**
+     * Shows the given URI.
+     * @param anchor an anchor added a priori or a new one.
+     * @param uri the URI of the anchor
+     */
+    public void showPage(String anchor, URI uri) {
+        if (anchor == null || uri == null) 
+            return;
         try {
-            _editor.setPage(_root + _anchors.get(anchor));
+            URL url = uri.toURL();
+            _editor.setPage(url);
+            repaint();
+            _visited.add(anchor);
+            _anchors.put(anchor, uri);
         } catch (Exception ex) {
+            System.err.println("Anchor = " + anchor + " URI " + uri);
             ex.printStackTrace();
         }
-        
     }
 }

Modified: openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/BuyBookPage.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/BuyBookPage.java?rev=947918&r1=947917&r2=947918&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/BuyBookPage.java (original)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/BuyBookPage.java Tue May 25 05:24:34 2010
@@ -17,6 +17,7 @@ import java.awt.BorderLayout;
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.net.URI;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
@@ -41,9 +42,11 @@ import jpa.tools.swing.EntityDataModel;
 import jpa.tools.swing.EntityTable;
 import jpa.tools.swing.EntityTableView;
 import jpa.tools.swing.ErrorDialog;
+import openbook.client.Demo.ShowCodeAction;
 import openbook.domain.Author;
 import openbook.domain.Book;
 import openbook.domain.Customer;
+import openbook.domain.LineItem;
 import openbook.domain.PurchaseOrder;
 import openbook.domain.ShoppingCart;
 import openbook.server.OpenBookService;
@@ -134,9 +137,6 @@ public final class BuyBookPage extends J
             super(true);
             setBorder(BorderFactory.createTitledBorder(title));
 
-            JButton searchButton = new JButton("Search", Images.START);
-            searchButton.setHorizontalTextPosition(SwingConstants.LEADING);
-
             JLabel titleLabel  = new JLabel("Title :", SwingConstants.RIGHT);
             JLabel authorLabel = new JLabel("Author:", SwingConstants.RIGHT);
             JLabel priceLabel  = new JLabel("Price :", SwingConstants.RIGHT);
@@ -179,11 +179,18 @@ public final class BuyBookPage extends J
             layout.setHorizontalGroup(hGroup);
             layout.setVerticalGroup(vGroup);
 
+            JButton searchButton = new JButton("Search", Images.START);
+            searchButton.setHorizontalTextPosition(SwingConstants.LEADING);
+            ShowCodeAction showCode = Demo.getInstance().new ShowCodeAction();
+            showCode.setPage("Derived identity", "openbook/domain/LineItem.java.html#example.compound-derived-identity");
+            JButton viewCodeButton = new JButton(showCode);
+            
             JPanel buttonPanel = new JPanel();
             buttonPanel.add(Box.createHorizontalGlue());
             buttonPanel.add(searchButton);
             buttonPanel.add(Box.createHorizontalGlue());
-
+            buttonPanel.add(viewCodeButton);
+            
             BoxLayout box = new BoxLayout(this, BoxLayout.Y_AXIS);
             setLayout(box);
             add(panel);

Modified: openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java?rev=947918&r1=947917&r2=947918&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java (original)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Demo.java Tue May 25 05:24:34 2010
@@ -18,11 +18,16 @@ import java.awt.Color;
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.Cursor;
+import java.awt.Desktop;
 import java.awt.Dimension;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
+import java.beans.PropertyChangeListener;
+import java.io.File;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -87,7 +92,7 @@ import org.apache.openjpa.persistence.Op
  *
  */
 @SuppressWarnings("serial")
-public class Demo extends JFrame implements Thread.UncaughtExceptionHandler {
+public class Demo extends JFrame {
     private static Dimension TAB_VIEW = new Dimension(800,600);
     private static Dimension OUT_VIEW = new Dimension(800,200);
     private static Dimension NAV_VIEW = new Dimension(400,800);
@@ -116,8 +121,10 @@ public class Demo extends JFrame impleme
     private StatusBar   _statusBar;
     private ScrollingTextPane   _sqlLog;
     private SQLLogger _sqlListener;
+    private SourceCodeBrowser _sourceBrowser;
+    private static Demo _instance;
     public static final Icon    LOGO = Images.getIcon("images/OpenBooks.jpg");
-    
+    private static final String SRC_ROOT = "source/";
     private boolean _debug = Boolean.getBoolean("openbook.debug");
     
     /**
@@ -137,7 +144,7 @@ public class Demo extends JFrame impleme
         adjustWidgetSize();
         SwingUtilities.invokeLater(new Runnable() {
             public void run() {
-                Demo demo = new Demo();
+                Demo demo = Demo.getInstance();
                 demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
                 demo.pack();
@@ -147,6 +154,13 @@ public class Demo extends JFrame impleme
         });
     }
     
+    public synchronized static Demo getInstance() {
+        if (_instance == null) {
+            _instance = new Demo();
+        }
+        return _instance;
+    }
+    
     static void adjustWidgetSize() {
         Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
         int sw = (int)(95*screen.getWidth()/100);
@@ -158,7 +172,7 @@ public class Demo extends JFrame impleme
 
     
     private Demo() {
-        Thread.currentThread().setUncaughtExceptionHandler(this);
+        Thread.currentThread().setUncaughtExceptionHandler(new ErrorHandler());
         _config = PropertyHelper.load(System.getProperty("openbook.client.config", "demo.properties"));
         setIconImage(((ImageIcon)LOGO).getImage());
         setTitle("OpenBooks: A Sample JPA 2.0 Application");
@@ -208,8 +222,7 @@ public class Demo extends JFrame impleme
      */
     public OpenBookService getService() {
         if (_service == null) {
-            final String unitName = PropertyHelper.getString(_config, "openbook.unit", 
-                    OpenBookService.DEFAULT_UNIT_NAME);
+            final String unitName = getConfiguration("openbook.unit", OpenBookService.DEFAULT_UNIT_NAME);
             
             SwingWorker<OpenBookService, Void> getService = new SwingWorker<OpenBookService, Void> () {
                 @Override
@@ -254,16 +267,6 @@ public class Demo extends JFrame impleme
         return _customer;
     }
     
-    @Override
-    public void uncaughtException(Thread t, Throwable e) {
-        if (SwingUtilities.isEventDispatchThread()) {
-            new ErrorDialog(e);
-        } else {
-            e.printStackTrace();
-        }
-    }
-    
-    
     private JToolBar  createToolBar() {
         JToolBar toolBar = new JToolBar();
         toolBar.add(_buyBook);
@@ -289,7 +292,28 @@ public class Demo extends JFrame impleme
     private StatusBar createStatusBar() {
         return new StatusBar();
     }
-
+    
+    public String getConfiguration(String key, String def) {
+        return PropertyHelper.getString(_config, key, def);
+    }
+    
+    private SourceCodeBrowser getSourceCodeBrowser() {
+        if (_sourceBrowser == null) {
+            String root = getConfiguration("openbook.source.root",  SRC_ROOT);
+            boolean external = "true".equalsIgnoreCase(
+                    getConfiguration("openbook.source.browser.external", "false"))
+                    && Desktop.isDesktopSupported();
+            _sourceBrowser = new SourceCodeBrowser(root, false);
+            if (!external) {
+                Map<String,String> initialPages = PropertyHelper.getMap(_config, "openbook.source.list");
+                for (Map.Entry<String, String> entry : initialPages.entrySet()) {
+                    _sourceBrowser.addPage(entry.getKey(), entry.getValue());
+                }
+                showTab(_tabbedPane, "Source Code", _sourceBrowser.getViewer());
+            }
+        }
+        return _sourceBrowser;
+    }
 
     /**
      * Abstract root of all Action objects helps to locate/configure visual action parameters such as
@@ -299,23 +323,13 @@ public class Demo extends JFrame impleme
      *
      */
     public abstract class OpenBookAction extends AbstractAction {
-        public OpenBookAction(Map<String,Object> props, String key) {
-            this(PropertyHelper.getString(props, key + "name",    ""),
-                 PropertyHelper.getString(props, key + "icon",    null),
-                 PropertyHelper.getString(props, key + "tooltip", ""),
-                 PropertyHelper.getString(props, key + "help",    ""));
-        }
-        
         public OpenBookAction(String name, String iconLocation, String tooltip) {
-            this(name, iconLocation, tooltip, tooltip);
+            this(name, Images.getIcon(iconLocation, true), tooltip);
         }
         
-        public OpenBookAction(String name, String iconLocation, String tooltip, String helpText) {
+        public OpenBookAction(String name, Icon icon, String tooltip) {
             putValue(Action.NAME, name);
             putValue(Action.SHORT_DESCRIPTION, tooltip);
-            putValue(Action.LONG_DESCRIPTION,  helpText);
-            
-            Icon icon = Images.getIcon(iconLocation, true);
             putValue(Action.SMALL_ICON, icon);
         }
     }
@@ -424,44 +438,34 @@ public class Demo extends JFrame impleme
     }
     
     public class ViewSourceAction extends OpenBookAction {
-        private SourceCodeViewer _sourceViewer;
-        private static final String SRC_ROOT = "http://fisheye6.atlassian.com/browse/~raw,r=HEAD/openjpa/" +
-                                               "trunk/openjpa-examples/openbooks/src/main/java/";
-        
         public ViewSourceAction(String name, String iconLocation, String tooltip) {
             super(name, iconLocation, tooltip);
         }
         
         public void actionPerformed(ActionEvent e) {
-            if (_sourceViewer == null) {
-                String root = PropertyHelper.getString(_config, "openbook.source.url",  SRC_ROOT);
-                _sourceViewer = new SourceCodeViewer(root, getAnchors());
-            }
-            showTab(_tabbedPane, "Source Code", _sourceViewer);
+            getSourceCodeBrowser();
         }
-        
-        Map<String, String> getAnchors() {
-            Map<String,String> anchors = new TreeMap<String, String>();
-            anchors.put("domain.Book",      toJavaFilePath(Book.class));
-            anchors.put("domain.Author",    toJavaFilePath(Author.class));
-            anchors.put("domain.Customer",  toJavaFilePath(Customer.class));
-            anchors.put("domain.Inventory", toJavaFilePath(Inventory.class));
-            anchors.put("domain.PurchaseOrder", toJavaFilePath(PurchaseOrder.class));
-            anchors.put("domain.LineItem", toJavaFilePath(LineItem.class));
-            
-            anchors.put("OpenBooks Service", toJavaFilePath(OpenBookService.class));
-            anchors.put("Generic Persistence Service", "openbook/server/PersistenceService.java");
-            anchors.put("OpenBooks Service Implementation", "openbook/server/OpenBookServiceImpl.java");
-            
-            anchors.put("clinet.Buy Book", toJavaFilePath(BuyBookPage.class));
-            
-            return anchors;
+    }
+    
+    /**
+     * An action to show a piece of code in an internal or external browser.
+     *
+     */
+    public class ShowCodeAction extends AbstractAction {
+        private String _key;
+        private String _page;
+        public ShowCodeAction() {
+            super("Show Code", Images.JAVA);
         }
         
-        private String toJavaFilePath(Class<?> cls) {
-            return cls.getName().replace('.', '/') + ".java";
+        public void setPage(String key, String page) {
+            _key  = key;
+            _page = page;
         }
         
+        public void actionPerformed(ActionEvent e) {
+           getSourceCodeBrowser().showPage(_key, _page);
+        }
     }
     
     /**
@@ -481,7 +485,7 @@ public class Demo extends JFrame impleme
         
         public void actionPerformed(ActionEvent e) {
             if (_powerpoint == null && _showPresentation) {
-                String dir = PropertyHelper.getString(_config, "openbook.slides.dir", "slides/");
+                String dir = getConfiguration("openbook.slides.dir", "slides/");
                 String[] defaultSlides = { 
                                     "Slide1.JPG",
                                     "Slide2.JPG",
@@ -511,6 +515,7 @@ public class Demo extends JFrame impleme
         }
         
     }
+    
     public class AboutAction extends OpenBookAction {
         AboutDialog _dialog;
         
@@ -525,7 +530,6 @@ public class Demo extends JFrame impleme
             }
             _dialog.setVisible(true);
         }
-        
     }
     
     /**

Modified: openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Images.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Images.java?rev=947918&r1=947917&r2=947918&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Images.java (original)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/Images.java Tue May 25 05:24:34 2010
@@ -38,6 +38,7 @@ public class Images {
     public static Icon BROWSE  = getIcon("images/browse.png");
     public static Icon START   = getIcon("images/start_task.gif");
     public static Icon MONITOR = getIcon("images/console_view.gif");
+    public static Icon JAVA    = getIcon("images/SourceCode.jpg", true);
     
     public static Icon getIcon(String name) {
         Icon icon = images.get(name);

Added: openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/SourceCodeBrowser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/SourceCodeBrowser.java?rev=947918&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/SourceCodeBrowser.java (added)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/SourceCodeBrowser.java Tue May 25 05:24:34 2010
@@ -0,0 +1,111 @@
+package openbook.client;
+
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import jpa.tools.swing.SourceCodeViewer;
+
+/**
+ * Browses source code.
+ * The source code URI is resolved with respect to a root URI.
+ * The source code is expected to be in HTML format.
+ * The actual rendering of the source code can be either through an 
+ * {@linkplain SourceCodeViewer internal} or an external browser. 
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class SourceCodeBrowser {
+    private boolean _useExternal;
+    private SourceCodeViewer _internal = new SourceCodeViewer();
+    private URI _rootURI;
+    private File _rootDir;
+    
+    /**
+     * Construct a browser.
+     * 
+     * @param root a path to be resolved as an URI to root of source tree.
+     * @param useDesktop flags to use external or internal browser.
+     */
+    public SourceCodeBrowser(String root, boolean useDesktop) {
+        _rootURI = convertToURI(root);
+        _useExternal = useDesktop;
+    }
+    
+    public URI getRootURI() {
+        return _rootURI;
+    }
+    
+    /**
+     * Gets the root source directory if the sources are being serverd from a local
+     * file system directory.
+     */
+    public File getRootDirectory() {
+        return _rootDir;
+    }
+    /**
+     * Shows the given page.
+     * @param key key a user visible moniker for the page.
+     * @param page the path of the page content w.r.t the root URI of this browser.
+     */
+    public void showPage(String key, String page) {
+        showPage(key, URI.create(_rootURI.toString() + page));
+    }
+    
+    public void addPage(String key, String path) {
+        _internal.addPage(key, URI.create(_rootURI.toString() + path));
+    }
+    
+    public SourceCodeViewer getViewer() {
+        return _internal;
+    }
+    /**
+     * Shows the given page.
+     * 
+     * @param key a user visible moniker for the page.
+     * @param uri the URI of the page content.
+     */
+    public void showPage(String key, URI uri) {
+        System.err.println("Going to show [" + uri + "] for anchor " + key);
+        try {
+            if (_useExternal) {
+                Desktop.getDesktop().browse(uri);
+            } else {
+                _internal.showPage(key, uri);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+    
+    private URI convertToURI(String srcPath) {
+        try {
+            URI uri = URI.create(srcPath);
+            String scheme = uri.getScheme();
+            if (scheme != null && !"file".equals(scheme)) {
+                return uri;
+            }
+        } catch (IllegalArgumentException e) {
+            // we have a relative path. Resolve it against current directory
+        }
+        File srcDir = new File(new File("."), srcPath);
+        if (!srcDir.exists()) {
+            throw new RuntimeException(srcDir.getAbsolutePath() + " does not exist." +
+                    "The source root must be relative to current dir");
+        }
+        if (!srcDir.isDirectory()) {
+            throw new RuntimeException(srcDir.getAbsolutePath() + " is not a directory");
+        }
+        _rootDir = srcDir;
+        return convertForWindows(_rootDir.toURI());
+    }
+    
+    URI convertForWindows(URI uri) {
+        String os = System.getProperty("os.name");
+        boolean windows = os.toLowerCase().indexOf("windows") != -1;
+        return URI.create(uri.getScheme() + (windows ? "://" : "") + uri.getRawSchemeSpecificPart());
+    }
+}

Propchange: openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/client/SourceCodeBrowser.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/tools/converter/ParseTokenListener.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/tools/converter/ParseTokenListener.java?rev=947918&r1=947917&r2=947918&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/tools/converter/ParseTokenListener.java (original)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/tools/converter/ParseTokenListener.java Tue May 25 05:24:34 2010
@@ -134,9 +134,6 @@ public class ParseTokenListener extends 
             return;
         _stream.print(_renderer.endLine(currentLine));
         _stream.print(_renderer.newLine(newline));
-        if (newline != currentLine+1) {
-            System.err.println("Error is line number processing.  Line " + currentLine + " jumps to " + newline);
-        }
         currentLine = newline;
     }
 }

Modified: openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/util/PropertyHelper.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/util/PropertyHelper.java?rev=947918&r1=947917&r2=947918&view=diff
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/util/PropertyHelper.java (original)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/java/openbook/util/PropertyHelper.java Tue May 25 05:24:34 2010
@@ -21,6 +21,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -202,6 +203,26 @@ public class PropertyHelper {
         return def;
     }
     
+    public static Map<String,String> getMap(Map<String,Object> props, String key) {
+        return getMap(props, key, Collections.EMPTY_MAP);
+    }
+    
+    public static Map<String,String> getMap(Map<String,Object> props, String key, Map<String,String> def) {
+        List<String> pairs = getStringList(props, key);
+        if (pairs == null || pairs.isEmpty())
+            return def;
+        Map<String,String> result = new LinkedHashMap<String, String>();
+        for (String pair : pairs) {
+            int index = pair.indexOf("->");
+            if (index != -1) {
+                String name  = pair.substring(0, index).trim();
+                String value = pair.substring(index + 2).trim();
+                result.put(name, value);
+            }
+        }
+        return result;
+    }
+
     /**
      * Affirms if the given string using array [] symbol at the end.
      * 

Added: openjpa/trunk/openjpa-examples/openbooks/src/main/resources/java.css
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-examples/openbooks/src/main/resources/java.css?rev=947918&view=auto
==============================================================================
--- openjpa/trunk/openjpa-examples/openbooks/src/main/resources/java.css (added)
+++ openjpa/trunk/openjpa-examples/openbooks/src/main/resources/java.css Tue May 25 05:24:34 2010
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+/* -------------------------------------------------------------
+ *  The following styles control the syntax coloring of Java
+ *  source code.
+ *  The style names are used by HTMLTokenRenderer
+ * ----------------------------------------------------------- */
+body{
+   font-family:"Courier New";
+   font-size:120%;
+   white-space:pre-wrap;
+   
+}
+
+#keyword {
+  font-weight:bold;
+  color:rgb(127,0,85);
+}
+
+#comment {
+  color:rgb(63,127,95);
+  white-space:pre-wrap;
+}
+
+#lineno {
+  color:rgb(200,200,200);
+}
+
+#annotation {
+  color:rgb(200,200,200);
+}
+
+#literal {
+  color:blue;
+}
+
+#decimal {
+  color:blue;
+}
+
+#enum {
+  font-style:italic;
+  color:blue;
+}
\ No newline at end of file

Propchange: openjpa/trunk/openjpa-examples/openbooks/src/main/resources/java.css
------------------------------------------------------------------------------
    svn:eol-style = native