openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ppod...@apache.org
Subject svn commit: r1004775 [1/3] - in /openjpa/tools/trunk/openjpa-tools/src/main: java/org/apache/openjpa/swing/ java/org/apache/openjpa/swing/graph/ java/org/apache/openjpa/swing/layout/ java/org/apache/openjpa/swing/print/ java/org/apache/openjpa/tools/ j...
Date Tue, 05 Oct 2010 19:22:19 GMT
Author: ppoddar
Date: Tue Oct  5 19:22:16 2010
New Revision: 1004775

URL: http://svn.apache.org/viewvc?rev=1004775&view=rev
Log:
Draft of MetaModel Browser

Added:
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ErrorDialog.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Geometry.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/GradientPanel.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Images.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SectionalView.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SwingHelper.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ToggleButton.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Connectable.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultConnectable.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdge.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRenderer.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRouter.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultGraphModel.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultNodeFactory.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Edge.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/EdgeFactory.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/EdgeRenderer.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/EdgeRouter.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/GraphModel.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/GraphPanel.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Mask.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/NodeViewFactory.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/RectilinearEdgeRouter.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/layout/
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/layout/FRLayoutManager.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/layout/Vector2D.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/layout/VerticalLayout.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/package.html   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/print/
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/print/PrintableDelegateComponent.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/print/Vista.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/AttributeLegendView.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/AttributeView.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/EntityTypeView.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/ErrorHandler.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/InMemoryBrokerFactory.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/MetamodelBrowser.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/MetamodelHelper.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/MetamodelUIManager.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/metamodel/MetamodelView.java   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/arrow_left.jpg   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/arrow_right.jpg   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/bullet_arrow_down.png   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/bullet_arrow_up.png   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/cancel.png   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/collapseall.gif   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/done.png   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/error.png   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/expandall.gif   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/help.png   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/icon_embeddable.gif   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/icon_entity.gif   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/icon_mappedsuper.gif   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/open.png   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/print.gif   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/refresh.png   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/save.png   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/search.jpg   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/images/start_task.gif   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/org/
    openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/
    openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/
    openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/swing/
    openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/swing/localizer.properties   (with props)
    openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/tools/
    openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/tools/metamodel/
    openjpa/tools/trunk/openjpa-tools/src/main/resources/org/apache/openjpa/tools/metamodel/localizer.properties   (with props)
Modified:
    openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/tools/MigrationTool.java

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ErrorDialog.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ErrorDialog.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ErrorDialog.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ErrorDialog.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,260 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.swing.BorderFactory;
+import javax.swing.Box;
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JEditorPane;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+/**
+ * A dialog to display runtime error.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+@SuppressWarnings("serial")
+public final class ErrorDialog extends JDialog {
+    private static List<String> filters = Arrays.asList(
+            "java.awt.", 
+            "javax.swing.", 
+            "sun.reflect.",
+            "java.util.concurrent.");
+    private static String NEWLINE = "<br>";
+    private static String INDENT  = "&nbsp;&nbsp;";
+    private final  JCheckBox filter;
+    private final  JLabel _header;
+    private JComponent   _main;
+    private JEditorPane  _stacktrace;
+    private JScrollPane  _stacktraceBar;
+    private final Throwable _error;
+    
+    /**
+     * Creates a modal dialog to display the given exception message.
+     * 
+     * @param t the exception to display
+     */
+    public ErrorDialog(Throwable t) {
+        this(null, null, t);
+    }
+
+    public ErrorDialog(JComponent owner, Throwable t) {
+        this(owner, null, t);
+    }
+    
+    /**
+     * Creates a modal dialog to display the given exception message.
+     * 
+     * @param owner if non-null, then the dialog is positioned (centered) w.r.t. this component
+     * @param t the exception to display
+     */
+    public ErrorDialog(JComponent owner, Icon icon, Throwable t) {
+        super();
+        setTitle(t.getClass().getName());
+        setModal(true);
+        if (icon != null && icon instanceof ImageIcon) 
+            setIconImage(((ImageIcon)icon).getImage());
+        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+        _error = t;
+        _main  = new JPanel(true);
+        _main.setLayout(new BorderLayout());
+        
+        _header = new JLabel();
+        _header.setText(formatMessage(_error, false, true));
+        _header.setIcon(Images.ERROR);
+
+        final JButton showDetails = new JButton("Show StackTrace >>");
+        final JButton copyToClipBoard = new JButton("Copy Stack Trace");
+        copyToClipBoard.setEnabled(false);
+        filter = new JCheckBox("Filter stack traces");
+        filter.setSelected(false);
+        String stacktrace = generateStackTrace(_error);
+        _stacktrace  = new JEditorPane();
+        _stacktrace.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
+        _stacktrace.setContentType("text/html");
+        _stacktrace.setText(stacktrace);
+        _stacktraceBar = new JScrollPane(_stacktrace, 
+                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, 
+                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+        _stacktraceBar.setVisible(false);
+        
+        JPanel buttonPanel = new JPanel();
+        buttonPanel.add(Box.createHorizontalStrut(20));
+        buttonPanel.add(showDetails);
+        buttonPanel.add(filter);
+        buttonPanel.add(copyToClipBoard);
+        buttonPanel.add(Box.createHorizontalGlue());
+        
+        JPanel messagePanel = new JPanel(true);
+        messagePanel.setLayout(new BorderLayout());
+        messagePanel.add(_header, BorderLayout.CENTER);
+        messagePanel.add(buttonPanel, BorderLayout.SOUTH);
+        
+        _main.add(messagePanel, BorderLayout.NORTH);
+        _main.add(_stacktraceBar, BorderLayout.CENTER);
+        _main.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
+        _header.setBackground(_main.getBackground());
+        _stacktrace.setBackground(_main.getBackground());
+        getContentPane().add(_main);
+
+        pack();
+        setLocationRelativeTo(owner);
+        
+        
+        showDetails.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                if (_stacktraceBar.isVisible()) {
+                    _stacktraceBar.setVisible(false);
+                    copyToClipBoard.setEnabled(false);
+                } else {
+                    _stacktraceBar.setVisible(true);
+                    copyToClipBoard.setEnabled(true);
+                }
+                showDetails.setText(_stacktraceBar.isVisible() ? "<< Hide StackTrace" : "Show StackTrace >>");
+                _main.revalidate();
+                _main.repaint();
+                pack();
+            }
+        });
+      
+        filter.addActionListener(new ActionListener(){
+            public void actionPerformed(ActionEvent e) {
+                String buffer = generateStackTrace(_error);
+                _stacktrace.setText(buffer);
+            }
+        });
+        
+        copyToClipBoard.addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                StringSelection data = new StringSelection(_stacktrace.getText());
+                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(data, data);
+            }
+        });
+        
+    }
+    
+    /**
+     * Creates a non-editable widget to display the detailed stack trace.
+     */
+    String generateStackTrace(Throwable t) {
+        StringBuilder buffer = generateStackTrace(t, null);
+        return buffer.toString();
+    }
+    
+    /**
+     * Recursively print the stack trace on the given buffer.
+     */    
+    private StringBuilder generateStackTrace(Throwable t, StringBuilder buffer) {
+        if (buffer == null) {
+            buffer = new StringBuilder();
+            buffer.append(t.getClass().getName() + NEWLINE);
+        } else {
+            buffer.append(formatMessage(t, true, false));
+        }
+        buffer.append(formatStackTraces(t.getStackTrace()));
+        Throwable cause = t.getCause();
+        if (cause != null && cause != t) {
+            generateStackTrace(cause, buffer);
+        }
+        return buffer;
+    }
+    
+    StringBuilder formatStackTraces(StackTraceElement[] traces) {
+        StringBuilder error = new StringBuilder();
+        for (StackTraceElement e : traces) {
+            if (!filter.isSelected() || !isSuppressed(e.getClassName())) {
+                String str = e.toString();
+                error.append(INDENT).append(str).append(NEWLINE);
+            }
+        }
+        return error;
+    }
+
+        
+    /**
+     * Create a HTML formatted string with the given exception type and the message broken
+     * at word boundaries at line of given width.
+     */ 
+    String formatMessage(Throwable t, boolean appendClass, boolean addHTML) {
+        List<String> lines = wrapText((appendClass ? t.getClass().getName()+": " : "") + t.getMessage(), 80);
+        StringBuilder buf = new StringBuilder(addHTML ? "<HTML>" : "");
+        for (String s : lines) {
+            buf.append(s + NEWLINE);
+        }
+        return buf.append(addHTML ? "</HTML>" : "").toString();
+    }
+    
+    public static List<String> wrapText(String s, int width) {
+        List<String> lines = new ArrayList<String>();
+        char[] chars = s.toCharArray();
+        StringBuilder line = new StringBuilder();
+        for (int i = 0; i < chars.length; i++) {
+            if (line.length() < width) {
+                line.append(chars[i]);
+            } else if (Character.isSpaceChar(chars[i])) {
+                lines.add(line.toString());
+                line = new StringBuilder();
+            } else {
+                line.append(chars[i]);
+            }
+        }
+        if (line.length() > 0)
+            lines.add(line.toString());
+        return lines;
+    }
+    
+    /**
+     * Affirms if the error messages from the given class name is to be suppressed.
+     */
+    private boolean isSuppressed(String className) {
+        for (String s : filters) {
+            if (className.startsWith(s))
+                return true;
+        }
+        return false;
+    }
+    
+    /**
+     * @param args
+     */
+    public static void main(String[] args) {
+        String m1 = "This is test error with very very very very very long line of error message that " 
+            + " should not be in a single line. Another message string that should be split across word." +
+            "The quick brown fox jumpled over the lazy dog";
+        String m2 = "This is another test error with very long line of error message that " 
+            + " should not be in a single line";
+        Throwable nested = new NumberFormatException(m2);
+        Throwable top = new IllegalArgumentException(m1, nested);
+        new ErrorDialog(top).setVisible(true);
+    }
+
+}

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ErrorDialog.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ErrorDialog.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Geometry.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Geometry.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Geometry.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Geometry.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,458 @@
+/*
+ * 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 org.apache.openjpa.swing;
+
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Line2D;
+import java.awt.geom.Path2D;
+import java.awt.geom.PathIterator;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.List;
+
+/**
+ * A set of utility to compute intersection of line segments, creating arrows etc.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class Geometry {
+    static final boolean _debug = Boolean.getBoolean("graph.debug");
+    /**
+     * Computes the intersection of the given line segment with the given rectangle.
+     * 
+     * @return null if the line segment does not intersect the rectangle.
+     */
+    public static Point2D intersection(Line2D seg, Rectangle2D r) {
+        return intersection(seg.getP1(), seg.getP2(), r);
+    }
+    
+    /**
+     * Computes the intersection of the line segment represented by the points with the given rectangle.
+     * 
+     * @return null if the line segment does not intersect the rectangle.
+     */
+    public static Point2D intersection(Point2D p1, Point2D p2, Rectangle2D r) {
+        return intersection(p1.getX(), p1.getY(), p2.getX(), p2.getY(), r);
+    }
+    
+    /**
+     * Computes the intersection of the line segment represented by the points with the given rectangle.
+     * 
+     * @return null if the line segment does not intersect the rectangle.
+     */
+    public static Point2D intersection(double x1, double y1, double x2, double y2, Rectangle2D r) {
+        Point2D p = null;
+        p = intersection(x1, y1, x2, y2, 
+                r.getX(), r.getY(), 
+                r.getX(), r.getY() + r.getHeight());
+        if (p != null) return p;
+        p = intersection(x1, y1, x2, y2, 
+                r.getX(), r.getY(), 
+                r.getX() + r.getWidth(), r.getY());
+        if (p != null) return p;
+        p = intersection(x1, y1, x2, y2, 
+                r.getX() + r.getWidth(), r.getY() + r.getHeight(), 
+                r.getX(), r.getY() + r.getHeight());
+        if (p != null) return p;
+        p = intersection(x1, y1, x2, y2, 
+                r.getX() + r.getWidth(), r.getY() + r.getHeight(), 
+                r.getX() + r.getWidth(), r.getY());
+        return p;
+    }
+    
+    /**
+     * Computes intersection between the given line segments.
+     * 
+     * @return null if the line segments do not intersects.
+     */
+    public static Point2D intersection(double x1, double y1, double x2, double y2, 
+            double x3, double y3, double x4, double y4) {
+        double denom = (y4-y3)*(x2-x1) - (x4-x3)*(y2-y1);
+        if (denom == 0) {
+            return null;
+        }
+        double ua = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3))/denom;
+        double ub = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3))/denom;
+        if (isBounded(ua, 0.0, 1.0) && isBounded(ub, 0.0, 1.0)) {
+            return new Point2D.Double(x1 + ua*(x2-x1), y1 + ua*(y2-y1));
+        }
+        return null;
+    }
+    
+    /**
+     * Affirms if the given value is strictly bounded by the given range.
+     */
+    public static boolean isBounded(double a, double min, double max) {
+        return a > min && a < max;
+    }
+    
+    /**
+     * Gets the first two points of the given path.
+     */
+    public static Line2D getStartpoints(Path2D path) {
+        double[] points = new double[6];
+        Point2D p1 = null;
+        Point2D p2 = null;
+        PathIterator iter = path.getPathIterator(null);
+        iter.currentSegment(points);
+        p1 = new Point2D.Double(points[0], points[1]);
+        iter.next();
+        iter.currentSegment(points);
+        p2 = new Point2D.Double(points[0], points[1]);
+        return new Line2D.Double(p1,p2);
+    }
+
+    /**
+     * Gets the last two points of the given path.
+     */
+    public static Line2D getEndpoints(Path2D path) {
+        AffineTransform at = new AffineTransform();
+        double[] points = new double[6];
+        Point2D p1 = null;
+        Point2D p2 = null;
+        PathIterator iter = path.getPathIterator(at);
+        while (!iter.isDone()) {
+            iter.currentSegment(points);
+            p1 = p2;
+            p2 = new Point2D.Double(points[0], points[1]);
+            iter.next();
+        }
+        return new Line2D.Double(p1,p2);
+    }
+    
+    /**
+     * Gets the point on the periphery of given rectangle to meet the given outside point. 
+     * 
+     * @return null if the point is inside the rectangle.
+     */
+    public static Point2D exitPoint(Rectangle2D r, double x, double y) {
+        if (r.contains(x,y))
+            return null;
+        int o = r.outcode(x, y);
+        double w = r.getWidth();
+        double h = r.getHeight();
+        double x0 = r.getCenterX();
+        double y0 = r.getCenterY();
+        
+        if ((o & Rectangle2D.OUT_LEFT) != 0)   x0 -= w/2;
+        if ((o & Rectangle2D.OUT_RIGHT) != 0)  x0 += w/2;
+        if ((o & Rectangle2D.OUT_TOP) != 0)    y0 -= h/2;
+        if ((o & Rectangle2D.OUT_BOTTOM) != 0) y0 += h/2;
+        
+        return new Point2D.Double(x0,y0);
+    }
+    
+    /**
+     * Get a path between the centers of two given rectangles.
+     * The path has two orthogonal line segments. The first segment is horizontal (vertical)
+     * if the horizontal displacement between the centers is longer (shorter) than the vertical.
+     */
+    public static Path2D getRectilinearPath(Rectangle2D r1, Rectangle2D r2) {
+        return getRectilinearPath(r1.getCenterX(), r1.getCenterY(), r2.getCenterX(), r2.getCenterY());
+    }
+    
+    public static Path2D getRectilinearPath(Point2D start, Point2D end) {
+        return getRectilinearPath(start.getX(), start.getY(), end.getX(), end.getY());
+    }
+    
+    public static Path2D getRectilinearPath(double x1, double y1, double x2, double y2) {
+        Path2D path = new Path2D.Double();
+        path.moveTo(x1, y1);
+        if (Math.abs(x1-x2) > Math.abs(y1 - y2)) {
+            path.lineTo(x2, y1);
+        } else {
+            path.lineTo(x1, y2);
+        }
+        path.lineTo(x2, y2);
+        return path;
+    }
+    
+    /**
+     * Given a pair of rectangles find the path that connects them without intersecting them.
+     */
+    public static Path2D getConnector(Rectangle2D r1, Rectangle2D r2) {
+        Path2D full = getRectilinearPath(r1, r2);
+        
+        Line2D exitPin  = getStartpoints(full);
+        Line2D entryPin = getEndpoints(full);
+        return getConnector(exitPin, entryPin);
+    }
+    
+    public static Path2D getConnector(Rectangle2D r1, Line2D entryPin) {
+        Point2D end = entryPin.getP1();
+        Path2D full = getRectilinearPath(r1.getCenterX(), r1.getCenterY(), end.getX(), end.getY());
+        
+        Line2D exitPin  = getStartpoints(full);
+        return getConnector(exitPin, entryPin);
+    }
+    
+    public static Path2D getConnector(Line2D exitPin, Rectangle2D r2) {
+        Path2D full = getRectilinearPath(exitPin.getP2().getX(), exitPin.getP2().getY(),
+                r2.getCenterX(), r2.getCenterY());
+        
+        Line2D entryPin = getEndpoints(full);
+        return getConnector(exitPin, entryPin);
+    }
+    
+    /**
+     * Connect a path between two given pins.
+     */
+    public static Path2D getConnector(Line2D exitPin, Line2D entryPin) {
+        Path2D path = new Path2D.Double();
+        Point2D start = exitPin.getP1();
+        path.moveTo(start.getX(), start.getY());
+        start = exitPin.getP2();
+        path.lineTo(start.getX(), start.getY());
+        log("Final Path : " + start);
+        int b = 6;
+        Point2D end = entryPin.getP1();
+        boolean xStraight = Math.abs(start.getX()-end.getX()) < b;
+        boolean yStraight = Math.abs(start.getY()-end.getY()) < b;
+        boolean straight = xStraight || yStraight; 
+        if (straight) {
+            if (xStraight) {
+                path.lineTo(end.getX(), start.getY());
+            } else if (yStraight) {
+                path.lineTo(start.getX(), end.getY());
+            }
+            path.lineTo(end.getX(), end.getY());
+            path.lineTo(entryPin.getP2().getX(), entryPin.getP2().getY());
+            return path;
+        }
+        double bx = Math.signum(start.getX()-end.getX())*b;
+        double by = Math.signum(start.getY()-end.getY())*b;
+        if (Math.abs(start.getX()-end.getX()) > Math.abs(start.getY()-end.getY())) {
+            path.lineTo(end.getX()+bx, start.getY());
+            path.quadTo(end.getX()+bx/3, start.getY()-by/3, end.getX(),start.getY()-by);
+            log("-> [" + end.getX() + "," + start.getY() + "]");
+        } else {
+            path.lineTo(start.getX(), end.getY() + by);
+            path.quadTo(start.getX()-bx/3, end.getY() + by/3, start.getX()-bx, end.getY());
+            log("-> [" + start.getY() + "," + end.getY() + "]");
+        }
+        path.lineTo(end.getX(), end.getY());
+        path.lineTo(entryPin.getP2().getX(), entryPin.getP2().getY());
+        return path;
+    }
+    
+    /**
+     * Get the slope of the given points in radian. 
+     */
+    public static double getAngle(Point2D p1, Point2D p2) {
+        return -Math.atan2(p1.getX() - p2.getX(), p1.getY() - p2.getY());
+    }
+    
+    /**
+     * Gets an arrow shape of given size at the end of the given path.
+     */
+    public static Shape addEndArrow(Path2D path, double arrowSize, double arrowAngleInDegree) {
+        Line2D end = Geometry.getEndpoints(path);
+        return addArrow(end.getP1(), end.getP2(), arrowSize, arrowAngleInDegree);
+    }
+    
+    /**
+     * Creates an arrow shape of given size at the beginning of the given path.
+     */
+    public static Shape addStartArrow(Path2D path, double arrowSize, double arrowAngleInDegree) {
+        Line2D start = Geometry.getStartpoints(path);
+        return addArrow(start.getP2(), start.getP1(), arrowSize, arrowAngleInDegree);
+    }
+    
+    /**
+     * Creates an arrow for the line segment p1,p2 whose tip is at p2.
+     * @param p1 the beginning of the line segment
+     * @param p2 the end of the line segment
+     * @param scale the projected length of the arrow along the line segment
+     * @return
+     */
+    public static Shape addArrow(Point2D p1, Point2D p2, double arrowSize, double arrowAngleInDegree) {
+        Path2D arrow = createArrow(arrowAngleInDegree);
+        AffineTransform at = AffineTransform.getTranslateInstance(p2.getX(), p2.getY());
+        double angle = getAngle(p1,p2);
+        at.rotate(angle);
+        at.scale(arrowSize, arrowSize);
+        Shape shape = at.createTransformedShape(arrow);
+        return shape;        
+    }
+    
+    
+    
+    /**
+     * Creates an arrow whose tip is at (0,0), unit height and angled theta.
+     * @return
+     */
+    public static Path2D.Double createArrow(double arrowAngleInDegree) {
+        double L = Math.tan(Math.toRadians(arrowAngleInDegree));
+        Path2D.Double path = new Path2D.Double();
+        path.moveTo(0, 0);
+        path.lineTo(-L, 1);
+        path.lineTo(L, 1);
+        path.lineTo(0, 0);
+        
+        return path;
+    }
+
+    public static Point asPoint(Point2D p) {
+        return new Point((int)p.getX(), (int)p.getY());
+    }
+    
+    public static Rectangle asRect(Rectangle2D r) {
+        return new Rectangle((int)r.getX(), (int)r.getY(), (int)r.getWidth(), (int)r.getHeight());
+    }
+    
+    public static void printPath(Path2D path) {
+        double[] points = new double[6];
+        PathIterator iter = path.getPathIterator(null);
+        while (!iter.isDone()) {
+            int type = iter.currentSegment(points);
+            switch (type) {
+            case PathIterator.SEG_MOVETO:
+                System.err.print("[" + points[0] + "," + points[1] + "]");
+                break;
+            case PathIterator.SEG_LINETO:
+                System.err.print("->[" + points[0] + "," + points[1] + "]");
+                break;
+            case PathIterator.SEG_QUADTO:
+                System.err.print("C[" + points[0] + "," + points[1] + ":" + points[2] + "," + points[3] + "]");
+                break;
+            default:
+            }
+            iter.next();
+        }
+        System.err.println();
+    }
+    
+    /**
+     * Modifies the given path such that it does not intersect the given rectangle. 
+     */
+    public static Path2D detour(Path2D path, Rectangle2D r) {
+        Rectangle2D i = path.getBounds2D().createIntersection(r);
+        if (i.getWidth() == 0 || i.getHeight() == 0)
+            return path;
+        BitSet bits = insider(i, r);
+        if (bits.isEmpty())
+            return path;
+        if (bits.cardinality() == 1) {
+            int n1 = bits.nextSetBit(0);
+            int n2 = (n1+2)%4;
+            Point2D p = mirror(n2, r, 20);
+            return modify(path, vertex(n1, i), p, n2);
+        }
+        return path;
+        
+    }
+    
+    /**
+     * Find which vertex(s) of i is inside r if any.
+     * Ignore if vertex is on edge of r
+     */
+    public static BitSet insider(Rectangle2D in, Rectangle2D r) {
+        BitSet bits  = new BitSet(4);
+        for (int i = 0; i < 4; i++) {
+            Point2D v = vertex(i,in);
+            bits.set(i, v.getX() > r.getX() && v.getX() < (r.getX()+r.getWidth()) 
+                     && v.getY() > r.getY() && v.getY() < (r.getY()+r.getHeight()));
+        }
+        return bits;
+    }
+    
+    public static Point2D mirror(int i, Rectangle2D r, int s) {
+        Point2D m = vertex(i,r);
+        AffineTransform tr = new AffineTransform();
+        tr.translate(i == 0 || i == 3 ? -s : s, i == 0 || i == 1 ? -s : s);
+        return tr.transform(m, m);
+    }
+    
+    /**
+     * Gets the i-th vertex of the given rectangle.
+     * 0-th vertex is top-left, and counted couter-clockwise i.e bottom-left is at index 3.
+     */
+    public static Point2D vertex(int i, Rectangle2D r) {
+        return new Point2D.Double(
+                r.getX() + (i == 1 || i == 2 ? r.getWidth() : 0),
+                r.getY() + (i == 2 || i == 3 ? r.getHeight() : 0));
+    }
+    
+    public static Path2D modify(Path2D original, Point2D breakPoint, Point2D newPoint, int vidx) {
+        List<Point2D> pts = getLineSegments(original);
+        int i = pts.indexOf(breakPoint);
+        Point2D p0 = pts.get(i-1);
+        Point2D p1 = pts.get(i);
+        Point2D p2 = pts.get(i+1);
+        
+        Point2D[] qs = new Point2D[5];
+        qs[0] = p0;
+        qs[1] = new Point2D.Double(vidx == 0 ? newPoint.getX() : p0.getX(), vidx == 0 ? p0.getY() : newPoint.getY());
+        qs[2] = newPoint;
+        qs[3] = new Point2D.Double(vidx == 0 ? p2.getX() : newPoint.getX(), vidx == 0 ? newPoint.getY() : p2.getY());
+        qs[4] = p2;
+        return createPath(qs);
+    }
+    
+    public static List<Point2D> getLineSegments(Path2D original) {
+        List<Point2D> pts = new ArrayList<Point2D>();
+        PathIterator iterator = original.getPathIterator(null);
+        double[] coords = new double[6];
+        while (!iterator.isDone()) {
+            int segtype = iterator.currentSegment(coords);
+            // assume all straight segments
+            pts.add(new Point2D.Double(coords[0], coords[1]));
+            iterator.next();
+        }
+        return pts;
+    }
+    
+    public static Path2D createPath(List<Point2D> pts) {
+        Path2D path = new Path2D.Double();
+        for (int i = 0; i < pts.size(); i++) {
+            Point2D p = pts.get(i);
+            if (i == 0) {
+                path.moveTo(p.getX(), p.getY());
+            } else {
+                path.lineTo(p.getX(), p.getY());
+            }
+        }
+        return path;
+    }
+    public static Path2D createPath(Point2D[] pts) {
+        Path2D path = new Path2D.Double();
+        for (int i = 0; i < pts.length; i++) {
+            Point2D p = pts[i];
+            if (i == 0) {
+                path.moveTo(p.getX(), p.getY());
+            } else {
+                path.lineTo(p.getX(), p.getY());
+            }
+        }
+        return path;
+    }
+    
+    
+    static void log(String s) {
+        if (_debug)
+            System.err.println(s);
+    }
+
+}

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Geometry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Geometry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/GradientPanel.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/GradientPanel.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/GradientPanel.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/GradientPanel.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,202 @@
+/*
+ * 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 org.apache.openjpa.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.GradientPaint;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.LayoutManager;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+import javax.swing.text.JTextComponent;
+
+/**
+ * A panel with gradient background.
+ * 
+ * @author Pinaki Poddar
+ * 
+ */
+@SuppressWarnings("serial")
+public class GradientPanel extends JPanel implements SwingConstants {
+    private Color lighter = new Color(250, 250, 250);
+    private Color darker = new Color(164, 164, 250);
+    private int direction = SOUTH_EAST;
+    private boolean _dirty = true;
+
+    public GradientPanel() {
+        super();
+    }
+
+    public GradientPanel(LayoutManager layout) {
+        super(layout);
+    }
+
+    public GradientPanel(boolean isDoubleBuffered) {
+        super(isDoubleBuffered);
+    }
+
+    public GradientPanel(LayoutManager layout, boolean isDoubleBuffered) {
+        super(layout, isDoubleBuffered);
+    }
+
+    protected void addImpl(Component comp, Object constratints, int index) {
+        super.addImpl(comp, constratints, index);
+        _dirty = true;
+    }
+
+    void setOpaqueRecursively(JComponent c) {
+        c.setOpaque(false);
+        int N = c.getComponentCount();
+        for (int i = 0; i < N; i++) {
+            Component cc = c.getComponent(i);
+            if (cc instanceof JComponent && !(cc instanceof JTextComponent))
+                setOpaqueRecursively((JComponent) cc);
+        }
+        _dirty = false;
+    }
+
+    @Override
+    public void paintComponent(Graphics g) {
+        setOpaqueRecursively(this);
+        Graphics2D g2d = (Graphics2D) g;
+        super.paintComponent(g2d);
+        int w = getWidth();
+        int h = getHeight();
+
+        int x1 = 0;
+        int y1 = 0;
+        int x2 = 0;
+        int y2 = 0;
+
+        switch (direction) {
+            case EAST:
+                x1 = w;
+                break;
+            case WEST:
+                x2 = w;
+                break;
+            case NORTH:
+                y2 = h;
+                break;
+            case SOUTH:
+                y1 = h;
+                break;
+            case NORTH_EAST:
+                x1 = w;
+                y2 = h;
+                break;
+            case NORTH_WEST:
+                x2 = w;
+                y2 = h;
+                break;
+            case SOUTH_WEST:
+                y1 = h;
+                x2 = w;
+                break;
+            default:
+            case SOUTH_EAST:
+                x2 = w;
+                y2 = h;
+                break;
+        }
+        GradientPaint gp = new GradientPaint(x1, y1, lighter, x2, y2, darker);
+        g2d.setPaint(gp);
+        g2d.fillRect(0, 0, w, h);
+    }
+
+    public GradientPanel setColorGradient(Color lighter, Color darker) {
+        this.lighter = lighter;
+        this.darker = darker;
+        return this;
+    }
+
+    public GradientPanel setDirection(int dir) {
+        this.direction = dir;
+        return this;
+    }
+
+    public static void main(String[] args) throws Exception {
+        JFrame frame = new JFrame("Gradient Panel");
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+        final GradientPanel panel = new GradientPanel();
+        panel.setPreferredSize(new Dimension(600, 600));
+
+        JPanel[] ctrl = new JPanel[3];
+        final JTextField[][] RGB = new JTextField[2][3];
+        for (int i = 0; i < 2; i++) {
+            ctrl[i] = new JPanel(true);
+            JLabel label = new JLabel("Color " + i + ":");
+            ctrl[i].add(label);
+            RGB[i] = new JTextField[3];
+            for (int j = 0; j < 3; j++) {
+                RGB[i][j] = new JTextField(3);
+                ctrl[i].add(RGB[i][j]);
+            }
+        }
+        ctrl[2] = new JPanel();
+
+        JButton update = new JButton("UPDATE");
+        update.addActionListener(new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                panel.setColorGradient(newColor(RGB[0]), newColor(RGB[1]));
+                panel.repaint();
+
+            }
+
+            Color newColor(JTextField[] f) {
+                return new Color(Integer.parseInt(f[0].getText()), Integer.parseInt(f[1].getText()), Integer
+                    .parseInt(f[2].getText()));
+            }
+        });
+
+        JPanel side = new JPanel(true);
+        side.setLayout(new BoxLayout(side, BoxLayout.Y_AXIS));
+        side.add(Box.createVerticalStrut(500));
+        side.add(ctrl[0]);
+        side.add(ctrl[1]);
+        side.add(update);
+
+        Container c = frame.getContentPane();
+        c.setLayout(new BorderLayout());
+        c.add(panel, BorderLayout.CENTER);
+        c.add(side, BorderLayout.EAST);
+
+        frame.pack();
+        frame.setVisible(true);
+    }
+
+}

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/GradientPanel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/GradientPanel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Images.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Images.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Images.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Images.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,94 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing;
+
+import java.awt.Image;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+
+import org.apache.openjpa.lib.util.Localizer;
+
+
+/**
+ * Utility to load and cache images.
+ * Maintains a cache of loaded images.
+ * 
+ * @author Pinaki Poddar
+ *
+ */
+public class Images {
+    private static Map<String, Icon> images = new HashMap<String, Icon>();
+    private static final Localizer _loc = Localizer.forPackage(Images.class);
+    
+    public static Icon ERROR   = getIcon("images/error.png");
+    
+    /**
+     * Gets the icon for the given key.
+     * The key is resolved against the localizer properties.
+     * 
+     * @see Localizer
+     * 
+     * @param key the moniker for the image. The location of the resource is specified against the
+     * given key in <code>localizer.properties</code> file.
+     * 
+     * @return the icon or a blank icon if the resource can not be found.
+     */
+    public static Icon getIcon(String key) {
+        Icon icon = images.get(key);
+        if (icon == null) {
+            icon = createImageIcon(key);
+            images.put(key, icon);
+        }
+        return icon;
+    }
+    
+    public static Icon getIcon(String name, boolean scale) {
+        return getIcon(name, 32, -1);
+    }
+    
+    public static Icon getIcon(String name, int width, int height) {
+        Icon icon = getIcon(name);
+        if (icon == null) {
+            return null;
+        }
+        icon = new ImageIcon(((ImageIcon)icon).getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));
+        return icon;
+    }
+    
+    /** 
+     * Returns an ImageIcon, or null if the path was invalid. 
+     * 
+     **/
+    protected static ImageIcon createImageIcon(String path) {
+        if (path == null)
+            return null;
+        URL imgURL = Thread.currentThread().getContextClassLoader().getResource(path);
+        if (imgURL != null) {
+            return new ImageIcon(imgURL);
+        } else {
+            imgURL = Images.class.getResource(path);
+            if (imgURL != null) {
+                return new ImageIcon(imgURL);
+            } else {
+                System.err.println(_loc.get("resource-not-found", path));
+                return new ImageIcon();
+            }
+        }
+    }
+
+}

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Images.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/Images.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SectionalView.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SectionalView.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SectionalView.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SectionalView.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,91 @@
+/*
+ * 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 org.apache.openjpa.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+
+import javax.swing.Box;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JTextField;
+
+import org.apache.openjpa.swing.layout.VerticalLayout;
+
+/**
+ * A composite widget that lays out multiple widgets (or section) that can be collapsed or expanded.
+ *    
+ * @author Pinaki Poddar
+ *
+ */
+@SuppressWarnings("serial")
+public class SectionalView extends GradientPanel {
+    public SectionalView() {
+        super(true);
+        setLayout(new VerticalLayout(this));
+    }
+    
+    
+    public void addSection(JComponent c, String toolTip) {
+        ToggleButton toggle = new ToggleButton(toolTip);
+        toggle.addToggleComponent(c);
+        toggle.setAlignmentX(LEFT_ALIGNMENT);
+        c.setAlignmentX(LEFT_ALIGNMENT);
+        add(toggle);
+        add(c);
+    }
+    
+    @Override
+    protected void addImpl(Component c, Object constraints, int index) {
+        if (c instanceof JComponent) {
+            ((JComponent)c).setAlignmentX(LEFT_ALIGNMENT);            
+        }
+        super.addImpl(c, constraints, index);
+    }
+    
+    /**
+     * Tester.
+     * 
+     */
+    public static void main(String[] args) throws Exception {
+        JFrame frame = new JFrame("Sectional View");
+        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+        final SectionalView panel = new SectionalView();
+        panel.add(new JTextField("Header"));
+        String[] texts = {"Section 1", "This is very, very wide Section 2", "Section 3"};
+        int[] widths = {10, 100, 10};
+        for (int i = 0; i < texts.length; i++) {
+            JTextField txt = new JTextField(texts[i], widths[i]);
+            System.err.println("TextField " + i + " Preferred size " + txt.getPreferredSize());
+            panel.addSection(txt, "Text " + i);
+        }
+
+        Container c = frame.getContentPane();
+        c.setLayout(new BorderLayout());
+        c.add(panel, BorderLayout.NORTH);
+        c.add(Box.createVerticalGlue(), BorderLayout.SOUTH);
+
+        frame.pack();
+        frame.setVisible(true);
+    }
+
+}

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SectionalView.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SectionalView.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SwingHelper.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SwingHelper.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SwingHelper.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SwingHelper.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,144 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing;
+
+import java.awt.AWTException;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.concurrent.TimeUnit;
+
+import javax.imageio.ImageIO;
+import javax.swing.AbstractButton;
+import javax.swing.ButtonGroup;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import javax.swing.plaf.FontUIResource;
+
+
+/**
+ * Assorted utility methods.
+ *  
+ * @author Pinaki Poddar
+ *
+ */
+public class SwingHelper {
+    /**
+     * Position the given component at the center of the given parent component or physical screen.
+     * 
+     * @param c the component to be positioned
+     * @param parent the component whose center will match the center of the given component.
+     * If null, the given component will match the screen center.
+     * 
+     */
+    public static void position(Component c, Component parent) {
+        Dimension d = c.getPreferredSize();
+        if (parent == null) {
+            Dimension s =  Toolkit.getDefaultToolkit().getScreenSize();
+            c.setLocation(s.width/2 - d.width/2,  s.height/2 - d.height/2);
+        } else {
+            Point p = parent.getLocationOnScreen();
+            int pw = parent.getWidth();
+            int ph = parent.getHeight();
+            c.setLocation(p.x + pw/2 - d.width/2, p.y + ph/2 - d.height/2);
+        }
+    }
+    
+    private static int[] factors = {1000, 1000, 1000, 1000, 60, 60, 24};
+    
+    public static String getTimeString(long value, TimeUnit unit) {
+        if (value <= 0)
+            return "";
+        int i = unit.ordinal();
+        TimeUnit[] units = TimeUnit.values();
+        TimeUnit next = null;
+        int factor = -1;
+        if (i < factors.length -1) {
+            next = units[i+1];
+            factor = factors[i+1];
+            long nextValue = value/factor;
+            if (nextValue > 0) 
+                return getTimeString(value/factor, next) + " " + getTimeString(value%factor, unit); 
+        } 
+        
+        return value + toString(unit);
+    }
+    
+    public static String toString(TimeUnit unit) {
+        switch (unit) {
+        case HOURS:
+        case DAYS:
+        case MINUTES:
+        case SECONDS:
+            return unit.toString().substring(0,1).toLowerCase();
+        case MILLISECONDS:
+            return "ms";
+        case MICROSECONDS:
+            return "micros";
+        case NANOSECONDS:
+            return "ns";
+        }
+        return "";
+    }
+    
+    public static void print(Component c, String format, File output) {
+        try {
+            Robot robot = new Robot();
+            Point root = c.getLocationOnScreen();
+            BufferedImage shot = robot.createScreenCapture(new Rectangle(root.x, root.y, c.getWidth(), c.getHeight()));
+            ImageIO.write(shot, format, output);
+        } catch (AWTException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+    
+    public static AbstractButton getSelectedButton(ButtonGroup group) {
+        Enumeration<AbstractButton> buttons = group.getElements();
+        while (buttons.hasMoreElements()) {
+            AbstractButton b = buttons.nextElement();
+            if (b.isSelected()) {
+                return b;
+            }
+        }
+        return null;
+    }
+    
+    public static void setLookAndFeel(int fontSize) throws Exception {
+        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+        UIDefaults defaults = UIManager.getDefaults();
+        Enumeration<Object> keys = defaults.keys();
+        while (keys.hasMoreElements()) {
+            Object key = keys.nextElement();
+
+            if ((key instanceof String) && (((String) key).endsWith(".font"))) {
+                FontUIResource font = (FontUIResource) UIManager.get(key);
+                defaults.put (key, new FontUIResource(font.getFontName(), font.getStyle(), fontSize));
+            }
+        }
+     }
+    
+
+
+}

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SwingHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/SwingHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ToggleButton.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ToggleButton.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ToggleButton.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ToggleButton.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,109 @@
+/*
+ * 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 org.apache.openjpa.swing;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.BorderFactory;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.SwingConstants;
+
+@SuppressWarnings("serial")
+public class ToggleButton extends JButton {
+    private static Icon HIDE_ICON = Images.getIcon("images/bullet_arrow_up.png");
+    private static Icon SHOW_ICON = Images.getIcon("images/bullet_arrow_down.png");
+    private List<Component> components;
+    private String hideText = "";
+    private String showText = "";
+    private boolean collapsed = false;
+    
+    public ToggleButton(String tooltip) {
+        this("", SHOW_ICON, "__________________", HIDE_ICON, tooltip);
+    }
+    
+    public ToggleButton(String showText, String hideText, String tooltip) {
+        this(showText, SHOW_ICON, hideText, HIDE_ICON, tooltip);
+    }
+    
+    public ToggleButton(String showText, final Icon showIcon, String hideText, final Icon hideIcon, String tooltip) {
+        super(hideText,hideIcon);
+        this.hideText = hideText;
+        this.showText = showText;
+        setHorizontalTextPosition(SwingConstants.RIGHT);
+        setBorderPainted(false);
+        setFocusPainted(false);
+        setContentAreaFilled(false);
+        setToolTipText(tooltip);
+        setBorder(BorderFactory.createEmptyBorder());
+        setPreferredSize(new Dimension(100,12));
+        components = new ArrayList<Component>();
+        
+        addActionListener(new ActionListener() {
+            public void actionPerformed(ActionEvent e) {
+                for (Component view : components) {
+                    if (view instanceof ToggleButton) {
+                        ((ToggleButton)view).toogle();
+                    } else {
+                        view.setVisible(!view.isVisible());
+                    } 
+                }
+                ToggleButton.this.toogle();
+            }
+        });
+    }
+    
+    
+    public void addToggleComponent(Component c) {
+        components.add(c);
+    }
+    
+    public void removeToggleComponent(Component c) {
+        components.remove(c);
+    }
+    
+    /**
+     * All the toggle components are set visible according to the flag.
+     * The appearance of this button changes but the button itself remains visible.
+     */
+    public void setVisible(boolean visible) {
+        for (Component c : components) {
+            c.setVisible(visible);
+        }
+        if (visible) {
+            setText(hideText);
+            setIcon(HIDE_ICON);
+        } else {
+            setText(showText);
+            setIcon(SHOW_ICON);
+        }
+    }
+        
+    void toogle() {
+        setVisible(collapsed);        
+        collapsed = !collapsed;
+        ((JComponent)getParent()).revalidate();
+    }
+}

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ToggleButton.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/ToggleButton.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Connectable.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Connectable.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Connectable.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Connectable.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,52 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing.graph;
+
+import java.awt.geom.Line2D;
+
+import javax.swing.JComponent;
+
+
+/**
+ * A interface to adapt a Swing widget to provide a set of exit/entry <em>pins</em> as line segment
+ * to connect edges.
+ * 
+ * @author Pinaki Poddar
+ *
+ * @param <V> the data type is connects.
+ */
+public interface Connectable<V> {
+    /**
+     * Get the exit pins relative to this receiver's parent where the edge should originate. 
+     * 
+     * @param e the edge
+     * @param target destination component whose entry pins will terminate the given edge.
+     * @return an array of pins (a line segment) containing at least one element.
+     */
+    Line2D[] getExitPins(Edge<V,V> e, Connectable<V> target);
+    
+    /**
+     * Get the location relative to this receiver's parent where the edge should terminate. 
+     * @param e the edge
+     * @param source the source component whose exit pins started this edge.
+     * @return an array of pins (a line segment) containing at least one element.
+     */
+    Line2D[] getEntryPins(Edge<V,V> e, Connectable<V> source);
+    
+    /**
+     * Gets the underlying Swing widget.
+     * 
+     */
+    JComponent asComponent();
+}

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Connectable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Connectable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultConnectable.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultConnectable.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultConnectable.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultConnectable.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,52 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing.graph;
+
+import java.awt.geom.Line2D;
+import java.awt.geom.Rectangle2D;
+
+import javax.swing.JComponent;
+
+/**
+ * A default implementation whose entry and exit pins 2px long and
+ * originates from top-left and bottom-right respectively.
+ * 
+ */
+public class DefaultConnectable<V> implements Connectable<V> {
+    private final JComponent _component;
+    
+    public DefaultConnectable(JComponent component) {
+        super();
+        this._component = component;
+    }
+
+    
+    public JComponent asComponent() {
+        return _component;
+    }
+
+    
+    public Line2D[] getEntryPins(Edge<V, V> e, Connectable<V> source) {
+        Rectangle2D r = _component.getBounds();
+        return new Line2D[]{new Line2D.Double(r.getX()-2,r.getY(), r.getX(),r.getY())};
+    }
+
+    
+    public Line2D[] getExitPins(Edge<V, V> e, Connectable<V> target) {
+        Rectangle2D r = _component.getBounds();
+        return new Line2D[]{new Line2D.Double(r.getX()+r.getWidth(),r.getY()+r.getHeight(), 
+                r.getX()+r.getWidth() + 2, r.getY())};
+    }
+    
+}
\ No newline at end of file

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultConnectable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultConnectable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdge.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdge.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdge.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdge.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,74 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing.graph;
+
+
+/**
+ * A default implementation of an Edge.
+ *
+ * @param <V1> type of the start node
+ * @param <V2> type of the terminal node
+ */
+public class DefaultEdge<V1,V2> implements Edge<V1, V2> {
+    private final V1 v1;
+    private final V2 v2;
+    
+    public DefaultEdge(V1 v1, V2 v2) {
+        super();
+        this.v1 = v1;
+        this.v2 = v2;
+    }
+
+    @Override
+    public V1 getSource() {
+        return v1;
+    }
+
+    @Override
+    public V2 getTarget() {
+        return v2;
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((v1 == null) ? 0 : v1.hashCode());
+        result = prime * result + ((v2 == null) ? 0 : v2.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        DefaultEdge<V1,V2> other = (DefaultEdge<V1,V2>) obj;
+        if (v1 == null) {
+            if (other.v1 != null)
+                return false;
+        } else if (!v1.equals(other.v1))
+            return false;
+        if (v2 == null) {
+            if (other.v2 != null)
+                return false;
+        } else if (!v2.equals(other.v2))
+            return false;
+        return true;
+    }
+    
+}
\ No newline at end of file

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdge.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdge.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRenderer.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRenderer.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRenderer.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRenderer.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,56 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing.graph;
+
+import java.awt.Graphics2D;
+import java.awt.Shape;
+import java.awt.geom.Path2D;
+
+import javax.swing.JLabel;
+
+import org.apache.openjpa.swing.Geometry;
+
+/**
+ * A default implementation.
+ * @author Pinaki Poddar
+ *
+ * @param <V>
+ */
+public class DefaultEdgeRenderer<V> implements EdgeRenderer<V> {
+    public static int ARROW_SIZE =  10;
+    public static int ARROW_ANGLE = 30;
+
+    boolean showArrowAtEnd    = true;
+    boolean showArrowAtStart  = false;
+    
+    @Override
+    public void render(Graphics2D g2, Path2D edgePath, Edge<V,V> edge) {
+        
+        g2.draw(edgePath);
+        Shape arrow1 = Geometry.addEndArrow(edgePath, ARROW_SIZE, ARROW_ANGLE);
+        g2.fill(arrow1);
+            
+        Shape arrow2 = Geometry.addStartArrow(edgePath, ARROW_SIZE, ARROW_ANGLE);
+        g2.fill(arrow2);
+    }
+    
+    @Override
+    public String getLabelText(Edge<V, V> edge) {
+        return edge.getSource().toString() + ":" + edge.getTarget().toString();
+    }
+    public JLabel getLabel(String text) {
+        return new JLabel(text);
+    }
+    
+}
\ No newline at end of file

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRenderer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRouter.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRouter.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRouter.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRouter.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,37 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing.graph;
+
+import java.awt.geom.Path2D;
+import java.awt.geom.Rectangle2D;
+
+/**
+ * A default implementation simply draws a path between the centers of the
+ * nodes.
+ * 
+ * 
+ * @param <V>
+ */
+public class DefaultEdgeRouter<V> implements EdgeRouter<V> {
+    public Path2D route(Edge<V, V> edge, Connectable<V> source, Connectable<V> target) {
+        Rectangle2D r1 = source.asComponent().getBounds();
+        Rectangle2D r2 = target.asComponent().getBounds();
+        if (r1 == null || r2 == null)
+            return null;
+        Path2D c2c = new Path2D.Double();
+        c2c.moveTo(r1.getCenterX(), r1.getCenterY());
+        c2c.lineTo(r2.getCenterX(), r2.getCenterY());
+        return c2c;
+    }
+}
\ No newline at end of file

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRouter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultEdgeRouter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultGraphModel.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultGraphModel.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultGraphModel.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultGraphModel.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,115 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing.graph;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A simple default implmentation.
+ * 
+ * @author Pinaki Poddar
+ *
+ * @param <V>
+ */
+public class DefaultGraphModel<V> implements GraphModel<V>, EdgeFactory<V,V> {
+    private Map<V,Set<Edge<V,V>>> _edges;
+    private EdgeFactory<V,V> _edgeFactory;
+    
+    public DefaultGraphModel() {
+        _edges =  new HashMap<V,Set<Edge<V,V>>>();
+        _edgeFactory = this;
+    }
+    @Override
+    public Set<V> getNodes() {
+        return _edges.keySet();
+    }
+
+    @Override
+    public boolean isLinked(V v1, V v2) {
+        Set<Edge<V,V>> edges = _edges.get(v1);
+        if (edges == null)
+            return false;
+        for (Edge<V,V> edge : edges) {
+            if (edge.getTarget() == v2)
+                return true;
+        }
+        return false;
+    }
+
+    @Override
+    public  <V1 extends V,V2 extends V> void link(Edge<V1,V2> edge) {
+        addVertex(edge.getSource());
+        addVertex(edge.getTarget());
+        Set<Edge<V,V>> edges = _edges.get(edge.getSource());
+        edges.add((Edge<V,V>)edge);
+    }
+    
+    public Edge<V,V> link(V v1, V v2) {
+        addVertex(v1);
+        addVertex(v2);
+        Set<Edge<V,V>> edges = _edges.get(v1);
+        Edge<V,V> edge = _edgeFactory.newEdge(v1, v2);
+        edges.add(edge);
+        return edge;
+    }
+    
+    public Edge<V,V> getEdge(V v1, V v2) {
+        Set<Edge<V,V>> edges = _edges.get(v1);
+        if (edges != null) {
+            for (Edge<V,V> edge : edges) {
+                if (edge.getSource() == v1 && edge.getTarget() == v2) {
+                    return edge;
+                }
+            }
+        }
+        return null;
+    }
+    
+    public Set<Edge<V,V>> getEdges() {
+        Set<Edge<V,V>> all = new HashSet<Edge<V,V>>();
+        for (Set<Edge<V,V>> e : _edges.values()) {
+            if (!e.isEmpty())
+                all.addAll(e);
+        }
+        return all;
+    }
+
+    @Override
+    public EdgeFactory<V,V> getEdgeFactory() {
+        return _edgeFactory;
+    }
+
+    @Override
+    public void setEdgeFactory(EdgeFactory<V,V> factory) {
+        _edgeFactory = factory;
+    }
+
+    
+    public Edge<V, V> newEdge(V v1, V v2) {
+        return new DefaultEdge<V, V>(v1,v2);
+    }
+    @Override
+    public void addVertex(V v) {
+        if (!_edges.containsKey(v)) {
+            _edges.put(v, new HashSet<Edge<V, V>>());
+        }
+    }
+    @Override
+    public Set<Edge<V, V>> getOutEdges(V v) {
+        return _edges.get(v);
+    }
+}
\ No newline at end of file

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultGraphModel.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultGraphModel.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultNodeFactory.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultNodeFactory.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultNodeFactory.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultNodeFactory.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,62 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing.graph;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.GradientPaint;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.util.Random;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.SwingConstants;
+
+
+/**
+ * Default implementation creates a JLabel for the given node.
+ *
+ * @param <V>
+ */
+public class DefaultNodeFactory<V> implements NodeViewFactory<V> {
+    Random rng = new Random(System.currentTimeMillis());
+    public Connectable<V> createComponent(V node, Graphics g) {
+        final JLabel label = new JLableWithGradientBackground(node.toString());
+        label.setPreferredSize(new Dimension(rng.nextInt(200)+50, rng.nextInt(100)+20));
+        return new DefaultConnectable<V>(label);
+    }
+    
+    @SuppressWarnings("serial")
+    public static class JLableWithGradientBackground extends JLabel {
+        Color c1 = new Color(180,180,180);
+        Color c2 = new Color(250,250,250);
+        
+        public JLableWithGradientBackground(String text) {
+            super(text);
+            setOpaque(false);
+            setHorizontalAlignment(SwingConstants.CENTER);
+            setBorder(BorderFactory.createEmptyBorder(5,10,5,10));
+            setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));
+        }
+        public void paintComponent(Graphics g) {
+            GradientPaint gp = new GradientPaint(0, 0, c1, getWidth(), getHeight(), c2);
+            Graphics2D g2 = (Graphics2D)g;
+            g2.setPaint(gp);
+            g2.fillRect( 0, 0, getWidth(), getHeight());
+            super.paintComponent(g);
+        }
+    }
+    
+}
\ No newline at end of file

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultNodeFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/DefaultNodeFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Edge.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Edge.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Edge.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Edge.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,35 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing.graph;
+
+/**
+ * An directed edge connects two vertex.
+ * 
+ * @author Pinaki Poddar
+ *
+ * @param <V1> type of source 
+ * @param <V2> type of target
+ */
+public interface Edge<V1,V2> {
+    /**
+     * Get the source vertex.
+     */
+    V1 getSource();
+    
+    /**
+     * Get the target vertex.
+     */
+    V2 getTarget();
+
+}

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Edge.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/Edge.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/EdgeFactory.java
URL: http://svn.apache.org/viewvc/openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/EdgeFactory.java?rev=1004775&view=auto
==============================================================================
--- openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/EdgeFactory.java (added)
+++ openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/EdgeFactory.java Tue Oct  5 19:22:16 2010
@@ -0,0 +1,24 @@
+/*
+ *  Licensed 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 org.apache.openjpa.swing.graph;
+
+/**
+ * A Factory to create an Edge.
+ *
+ * @param <V1>
+ * @param <V2>
+ */
+public interface EdgeFactory<V1,V2> {
+    public Edge<V1,V2> newEdge(V1 v1, V2 v2);
+}
\ No newline at end of file

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/EdgeFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: openjpa/tools/trunk/openjpa-tools/src/main/java/org/apache/openjpa/swing/graph/EdgeFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message