You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2013/07/20 11:49:21 UTC

svn commit: r1505113 [2/2] - in /cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: ./ action/ dialog/ dialog/db/ dialog/objentity/ dialog/validator/ editor/ graph/ undo/ util/

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/BaseGraphBuilder.java Sat Jul 20 09:49:20 2013
@@ -49,9 +49,9 @@ import org.apache.cayenne.map.event.Enti
 import org.apache.cayenne.map.event.RelationshipEvent;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.action.ActionManager;
 import org.apache.cayenne.modeler.action.CreateAttributeAction;
 import org.apache.cayenne.modeler.action.CreateRelationshipAction;
-import org.apache.cayenne.modeler.action.ActionManager;
 import org.apache.cayenne.modeler.graph.action.EntityDisplayAction;
 import org.apache.cayenne.modeler.graph.action.RemoveEntityAction;
 import org.apache.cayenne.util.XMLEncoder;
@@ -85,13 +85,14 @@ abstract class BaseGraphBuilder implemen
     protected transient DataChannelDescriptor domain;
 
     /**
-     * Created entity cells. Maps to entity name, since GraphBuilder can be serialized
+     * Created entity cells. Maps to entity name, since GraphBuilder can be
+     * serialized
      */
     protected Map<String, DefaultGraphCell> entityCells;
 
     /**
-     * Created relationship cells Maps to relationship qualified name, since GraphBuilder
-     * can be serialized
+     * Created relationship cells Maps to relationship qualified name, since
+     * GraphBuilder can be serialized
      */
     protected Map<String, DefaultEdge> relCells;
 
@@ -111,10 +112,7 @@ abstract class BaseGraphBuilder implemen
 
     boolean undoEventsDisabled;
 
-    public synchronized void buildGraph(
-            ProjectController mediator,
-            DataChannelDescriptor domain,
-            boolean doLayout) {
+    public void buildGraph(ProjectController mediator, DataChannelDescriptor domain, boolean doLayout) {
         if (graph != null) {
             // graph already built, exiting silently
             return;
@@ -138,8 +136,7 @@ abstract class BaseGraphBuilder implemen
                     if (selected != null && selected instanceof DefaultGraphCell) {
                         Object userObject = ((DefaultGraphCell) selected).getUserObject();
                         if (userObject instanceof EntityCellMetadata) {
-                            showPopup(e.getPoint(), ((EntityCellMetadata) userObject)
-                                    .fetchEntity());
+                            showPopup(e.getPoint(), ((EntityCellMetadata) userObject).fetchEntity());
                         }
                     }
                 }
@@ -149,8 +146,7 @@ abstract class BaseGraphBuilder implemen
         graph.addMouseWheelListener(new MouseWheelListener() {
 
             public void mouseWheelMoved(MouseWheelEvent e) {
-                graph.setScale(graph.getScale()
-                        / Math.pow(ZOOM_FACTOR, e.getWheelRotation()));
+                graph.setScale(graph.getScale() / Math.pow(ZOOM_FACTOR, e.getWheelRotation()));
             }
         });
 
@@ -159,8 +155,8 @@ abstract class BaseGraphBuilder implemen
         relCells = new HashMap<String, DefaultEdge>();
 
         /**
-         * an array for entities that are not connected to anyone. We add them separately
-         * so that layout doesn't touch them
+         * an array for entities that are not connected to anyone. We add them
+         * separately so that layout doesn't touch them
          */
         List<DefaultGraphCell> isolatedObjects = new ArrayList<DefaultGraphCell>();
 
@@ -177,9 +173,7 @@ abstract class BaseGraphBuilder implemen
                 // mapCell.add(cell);
                 // cell.setParent(mapCell);
 
-                List<DefaultGraphCell> array = !isIsolated(domain, entity)
-                        ? createdObjects
-                        : isolatedObjects;
+                List<DefaultGraphCell> array = !isIsolated(domain, entity) ? createdObjects : isolatedObjects;
                 array.add(cell);
                 array.add((DefaultGraphCell) cell.getChildAt(0)); // port
             }
@@ -210,9 +204,12 @@ abstract class BaseGraphBuilder implemen
             // JGraphSimpleLayout layout = new
             // JGraphSimpleLayout(JGraphSimpleLayout.TYPE_TILT, 4000, 2000);
             layout.run(facade);
-            Map nested = facade.createNestedMap(true, true); // Obtain a map of the
-                                                             // resulting attribute
-                                                             // changes from the facade
+            Map nested = facade.createNestedMap(true, true); // Obtain a map of
+                                                             // the
+                                                             // resulting
+                                                             // attribute
+                                                             // changes from the
+                                                             // facade
 
             edit(nested); // Apply the results to the actual graph
         }
@@ -220,14 +217,15 @@ abstract class BaseGraphBuilder implemen
         /**
          * Adding isolated objects
          * 
-         * We're placing them so that they will take maximum space in left top corner. The
-         * sample order is below:
+         * We're placing them so that they will take maximum space in left top
+         * corner. The sample order is below:
          * 
          * 1 2 6 7... 3 5 8 ... 4 9... 10 ...
          */
         if (isolatedObjects.size() > 0) {
             int n = isolatedObjects.size() / 2; // number of isolated entities
-            int x = (int) Math.ceil((Math.sqrt(1 + 8 * n) - 1) / 2); // side of triangle
+            int x = (int) Math.ceil((Math.sqrt(1 + 8 * n) - 1) / 2); // side of
+                                                                     // triangle
 
             Dimension pref = graph.getPreferredSize();
             int dx = pref.width / 2 / x; // x-distance between entities
@@ -240,13 +238,8 @@ abstract class BaseGraphBuilder implemen
 
             for (int isolatedIndex = 0; isolatedIndex < isolatedObjects.size();) {
                 for (int i = 0; isolatedIndex < isolatedObjects.size() && i < x - row; i++) {
-                    GraphConstants.setBounds(isolatedObjects
-                            .get(isolatedIndex)
-                            .getAttributes(), new Rectangle2D.Double(
-                            pref.width - posX,
-                            pref.height - 3 * posY / 2,
-                            10,
-                            10));
+                    GraphConstants.setBounds(isolatedObjects.get(isolatedIndex).getAttributes(),
+                            new Rectangle2D.Double(pref.width - posX, pref.height - 3 * posY / 2, 10, 10));
                     isolatedIndex += 2; // because every 2nd object is port
                     posX += dx;
                 }
@@ -292,8 +285,8 @@ abstract class BaseGraphBuilder implemen
     }
 
     /**
-     * Returns whether an entity is not connected to any other TODO: not fine algorithm,
-     * it iterates through all entities and all rels
+     * Returns whether an entity is not connected to any other TODO: not fine
+     * algorithm, it iterates through all entities and all rels
      */
     protected boolean isIsolated(DataChannelDescriptor domain, Entity entity) {
         if (entity.getRelationships().size() == 0) {
@@ -314,8 +307,8 @@ abstract class BaseGraphBuilder implemen
     protected abstract Collection<? extends Entity> getEntities(DataMap map);
 
     /**
-     * Returns label for relationship on the graph, considering its "mandatory" and
-     * "to-many" properties
+     * Returns label for relationship on the graph, considering its "mandatory"
+     * and "to-many" properties
      */
     private static String getRelationshipLabel(Relationship rel) {
         if (rel == null) {
@@ -354,10 +347,8 @@ abstract class BaseGraphBuilder implemen
         JPopupMenu menu = new JPopupMenu();
         menu.add(new EntityDisplayAction(this).buildMenu());
         menu.addSeparator();
-        menu.add(new EntityDisplayAction(this, actionManager
-                .getAction(CreateAttributeAction.class)).buildMenu());
-        menu.add(new EntityDisplayAction(this, actionManager
-                .getAction(CreateRelationshipAction.class)).buildMenu());
+        menu.add(new EntityDisplayAction(this, actionManager.getAction(CreateAttributeAction.class)).buildMenu());
+        menu.add(new EntityDisplayAction(this, actionManager.getAction(CreateRelationshipAction.class)).buildMenu());
         menu.addSeparator();
         menu.add(new RemoveEntityAction(this));
 
@@ -389,8 +380,7 @@ abstract class BaseGraphBuilder implemen
                 Map nested = new HashMap();
                 nested.put(edge, edge.getAttributes());
                 edit(nested);
-            }
-            else {
+            } else {
                 insertRelationshipCell(rel);
             }
         }
@@ -402,9 +392,7 @@ abstract class BaseGraphBuilder implemen
             runWithUndoDisabled(new Runnable() {
 
                 public void run() {
-                    graph.getGraphLayoutCache().remove(new Object[] {
-                        cell
-                    }, true, true);
+                    graph.getGraphLayoutCache().remove(new Object[] { cell }, true, true);
                 }
             });
             entityCells.remove(e.getName());
@@ -417,9 +405,7 @@ abstract class BaseGraphBuilder implemen
             runWithUndoDisabled(new Runnable() {
 
                 public void run() {
-                    graph.getGraphLayoutCache().remove(new Object[] {
-                        edge
-                    });
+                    graph.getGraphLayoutCache().remove(new Object[] { edge });
                 }
             });
             relCells.remove(getQualifiedName(rel));
@@ -464,9 +450,8 @@ abstract class BaseGraphBuilder implemen
         DefaultGraphCell cell = createEntityCell(entity);
 
         // putting cell to a random posistion..
-        GraphConstants.setBounds(cell.getAttributes(), new Rectangle2D.Double(Math
-                .random()
-                * graph.getWidth(), Math.random() * graph.getHeight(), 10, 10));
+        GraphConstants.setBounds(cell.getAttributes(),
+                new Rectangle2D.Double(Math.random() * graph.getWidth(), Math.random() * graph.getHeight(), 10, 10));
 
         // setting graph type-specific attrs
         postProcessEntity(entity, cell);
@@ -477,35 +462,23 @@ abstract class BaseGraphBuilder implemen
     /**
      * Updates relationship labels for specified relationship edge.
      * 
-     * @param order order of relationship in entity's same target relationships - to
-     *            differ labels of relationships with same source and target
+     * @param order
+     *            order of relationship in entity's same target relationships -
+     *            to differ labels of relationships with same source and target
      */
-    protected void updateRelationshipLabels(
-            DefaultEdge edge,
-            Relationship rel,
-            Relationship reverse) {
+    protected void updateRelationshipLabels(DefaultEdge edge, Relationship rel, Relationship reverse) {
         DefaultGraphCell sourceCell = entityCells.get(rel.getSourceEntity().getName());
         DefaultGraphCell targetCell = entityCells.get(rel.getTargetEntity().getName());
 
         edge.setSource(sourceCell != null ? sourceCell.getChildAt(0) : null);
         edge.setTarget(targetCell != null ? targetCell.getChildAt(0) : null);
 
-        Object[] labels = {
-                rel.getName() + " " + getRelationshipLabel(rel),
-                reverse == null ? "" : reverse.getName()
-                        + " "
-                        + getRelationshipLabel(reverse)
-        };
+        Object[] labels = { rel.getName() + " " + getRelationshipLabel(rel),
+                reverse == null ? "" : reverse.getName() + " " + getRelationshipLabel(reverse) };
         GraphConstants.setExtraLabels(edge.getAttributes(), labels);
 
-        Point2D[] labelPositions = {
-                new Point2D.Double(
-                        GraphConstants.PERMILLE * (0.1 + 0.2 * Math.random()),
-                        10),
-                new Point2D.Double(
-                        GraphConstants.PERMILLE * (0.9 - 0.2 * Math.random()),
-                        -10)
-        };
+        Point2D[] labelPositions = { new Point2D.Double(GraphConstants.PERMILLE * (0.1 + 0.2 * Math.random()), 10),
+                new Point2D.Double(GraphConstants.PERMILLE * (0.9 - 0.2 * Math.random()), -10) };
         GraphConstants.setExtraLabelPositions(edge.getAttributes(), labelPositions);
     }
 
@@ -557,16 +530,14 @@ abstract class BaseGraphBuilder implemen
      */
     protected void remapRelationship(RelationshipEvent e) {
         if (e.isNameChange()) {
-            relCells.put(getQualifiedName(e.getRelationship()), relCells.remove(e
-                    .getEntity()
-                    .getName()
-                    + "."
-                    + e.getOldName()));
+            relCells.put(getQualifiedName(e.getRelationship()),
+                    relCells.remove(e.getEntity().getName() + "." + e.getOldName()));
         }
     }
 
     /**
-     * Returns qualified name (entity name + relationship name) for a relationship
+     * Returns qualified name (entity name + relationship name) for a
+     * relationship
      */
     static String getQualifiedName(Relationship rel) {
         return rel.getSourceEntity().getName() + "." + rel.getName();
@@ -603,7 +574,7 @@ abstract class BaseGraphBuilder implemen
         encoder.print(rect.getHeight() + "\" ");
     }
 
-    private synchronized void edit(final Map map) {
+    private void edit(final Map map) {
         runWithUndoDisabled(new Runnable() {
 
             public void run() {
@@ -612,7 +583,7 @@ abstract class BaseGraphBuilder implemen
         });
     }
 
-    private synchronized void insert(final Object cell) {
+    private void insert(final Object cell) {
         runWithUndoDisabled(new Runnable() {
 
             public void run() {
@@ -621,12 +592,11 @@ abstract class BaseGraphBuilder implemen
         });
     }
 
-    private synchronized void runWithUndoDisabled(Runnable r) {
+    private void runWithUndoDisabled(Runnable r) {
         undoEventsDisabled = true;
         try {
             r.run();
-        }
-        finally {
+        } finally {
             undoEventsDisabled = false;
         }
     }

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DataDomainGraphTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DataDomainGraphTab.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DataDomainGraphTab.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/graph/DataDomainGraphTab.java Sat Jul 20 09:49:20 2013
@@ -48,8 +48,7 @@ import org.jgraph.JGraph;
 /**
  * Tab for editing graphical representation of a dataDomain
  */
-public class DataDomainGraphTab extends JPanel implements DomainDisplayListener,
-        ItemListener {
+public class DataDomainGraphTab extends JPanel implements DomainDisplayListener, ItemListener {
 
     /**
      * mediator instance
@@ -106,9 +105,7 @@ public class DataDomainGraphTab extends 
         diagramCombo = Application.getWidgetFactory().createComboBox(names, false);
         diagramCombo.addItemListener(this);
 
-        toolbar
-                .add(new RebuildGraphAction(this, Application.getInstance())
-                        .buildButton());
+        toolbar.add(new RebuildGraphAction(this, Application.getInstance()).buildButton());
         toolbar.add(new SaveAsImageAction(this, Application.getInstance()).buildButton());
         toolbar.addSeparator();
         toolbar.add(new ZoomInAction(this, Application.getInstance()).buildButton());
@@ -132,8 +129,7 @@ public class DataDomainGraphTab extends 
             diagramCombo.setSelectedIndex(entity instanceof ObjEntity ? 1 : 0);
             refresh();
 
-            GraphBuilder builder = getGraphRegistry().getGraphMap(domain).get(
-                    getSelectedType());
+            GraphBuilder builder = getGraphRegistry().getGraphMap(domain).get(getSelectedType());
 
             Object cell = builder.getEntityCell(entity.getName());
 
@@ -141,8 +137,7 @@ public class DataDomainGraphTab extends 
                 graph.setSelectionCell(cell);
                 graph.scrollCellToVisible(cell);
             }
-        }
-        else if (domain != e.getDomain()) {
+        } else if (domain != e.getDomain()) {
             needRebuild = true;
             domain = e.getDomain();
 
@@ -153,9 +148,10 @@ public class DataDomainGraphTab extends 
     }
 
     /**
-     * Rebuilds graph from a domain, if it is not yet built Otherwise, takes it from cache
+     * Rebuilds graph from a domain, if it is not yet built Otherwise, takes it
+     * from cache
      */
-    public synchronized void refresh() {
+    public void refresh() {
         if (needRebuild && domain != null) {
             graph = getGraphRegistry().loadGraph(mediator, domain, getSelectedType());
             scrollPane.setViewportView(graph);
@@ -171,13 +167,10 @@ public class DataDomainGraphTab extends 
     /**
      * Rebuilds graph, deleting existing if needed
      */
-    public synchronized void rebuild() {
+    public void rebuild() {
         if (domain != null) {
-            JOptionPane pane = new JOptionPane(
-                    "Rebuilding graph from domain will cause all user"
-                            + " changes to be lost. Continue?",
-                    JOptionPane.QUESTION_MESSAGE,
-                    JOptionPane.YES_NO_OPTION);
+            JOptionPane pane = new JOptionPane("Rebuilding graph from domain will cause all user"
+                    + " changes to be lost. Continue?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
 
             JDialog dialog = pane.createDialog(Application.getFrame(), "Confirm Rebuild");
             dialog.setVisible(true);

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoManager.java Sat Jul 20 09:49:20 2013
@@ -37,20 +37,20 @@ public class CayenneUndoManager extends 
     }
 
     @Override
-    public synchronized void discardAllEdits() {
+    public void discardAllEdits() {
         super.discardAllEdits();
         updateUI();
     }
 
     @Override
-    public synchronized boolean addEdit(UndoableEdit anEdit) {
+    public boolean addEdit(UndoableEdit anEdit) {
         boolean result = super.addEdit(anEdit);
         updateUI();
         return result;
     }
 
     @Override
-    public synchronized void redo() throws CannotRedoException {
+    public void redo() throws CannotRedoException {
         UndoableEdit e = editToBeRedone();
 
         if (e instanceof TextCompoundEdit) {
@@ -61,8 +61,7 @@ public class CayenneUndoManager extends 
             super.redo();
 
             edit.stopWatchingCaretPosition();
-        }
-        else {
+        } else {
             super.redo();
         }
 
@@ -70,7 +69,7 @@ public class CayenneUndoManager extends 
     }
 
     @Override
-    public synchronized void undo() throws CannotUndoException {
+    public void undo() throws CannotUndoException {
         UndoableEdit e = editToBeUndone();
 
         if (e instanceof TextCompoundEdit) {
@@ -81,8 +80,7 @@ public class CayenneUndoManager extends 
             super.undo();
 
             edit.stopWatchingCaretPosition();
-        }
-        else {
+        } else {
             super.undo();
         }
 
@@ -90,11 +88,9 @@ public class CayenneUndoManager extends 
     }
 
     private void updateUI() {
-        CayenneAction undoAction = application.getActionManager().getAction(
-                UndoAction.class);
+        CayenneAction undoAction = application.getActionManager().getAction(UndoAction.class);
 
-        CayenneAction redoAction = application.getActionManager().getAction(
-                RedoAction.class);
+        CayenneAction redoAction = application.getActionManager().getAction(RedoAction.class);
 
         undoAction.setEnabled(canUndo());
         redoAction.setEnabled(canRedo());

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/TextCompoundEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/TextCompoundEdit.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/TextCompoundEdit.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/TextCompoundEdit.java Sat Jul 20 09:49:20 2013
@@ -71,15 +71,12 @@ public class TextCompoundEdit extends Co
         this.editor = editor;
         this.listener = listener;
 
-        EditorView editorView = ((CayenneModelerFrame) Application
-                .getInstance()
-                .getFrameController()
-                .getView()).getView();
+        EditorView editorView = ((CayenneModelerFrame) Application.getInstance().getFrameController().getView())
+                .getView();
 
         treePath = editorView.getProjectTreeView().getSelectionPath();
 
-        DefaultMutableTreeNode newPath = (DefaultMutableTreeNode) treePath
-                .getLastPathComponent();
+        DefaultMutableTreeNode newPath = (DefaultMutableTreeNode) treePath.getLastPathComponent();
 
         targetObject = newPath.getUserObject();
 
@@ -97,11 +94,9 @@ public class TextCompoundEdit extends Co
 
         if (targetObject instanceof SQLTemplate) {
             tabbedPane = editorView.getSqlTemplateView();
-            
+
             if (tabbedPane != null) {
-                selectedItem = ((SQLTemplateTabbedView) tabbedPane)
-                        .getScriptsTab()
-                        .getSelectedIndex();
+                selectedItem = ((SQLTemplateTabbedView) tabbedPane).getScriptsTab().getSelectedIndex();
             }
         }
 
@@ -128,20 +123,16 @@ public class TextCompoundEdit extends Co
 
     private void restoreSelections() {
 
-        EditorView editorView = ((CayenneModelerFrame) Application
-                .getInstance()
-                .getFrameController()
-                .getView()).getView();
+        EditorView editorView = ((CayenneModelerFrame) Application.getInstance().getFrameController().getView())
+                .getView();
 
         editorView.getProjectTreeView().getSelectionModel().setSelectionPath(treePath);
 
         if (tabbedPane != null) {
             tabbedPane.setSelectedIndex(selectedTabIndex);
-            
+
             if (tabbedPane instanceof SQLTemplateTabbedView) {
-                ((SQLTemplateTabbedView) tabbedPane)
-                        .getScriptsTab()
-                        .setSelectedIndex(selectedItem);
+                ((SQLTemplateTabbedView) tabbedPane).getScriptsTab().setSelectedIndex(selectedItem);
             }
         }
     }
@@ -174,8 +165,7 @@ public class TextCompoundEdit extends Co
 
         if (canRedo()) {
             super.redo();
-        }
-        else {
+        } else {
             die();
         }
 
@@ -189,8 +179,7 @@ public class TextCompoundEdit extends Co
 
         if (canUndo()) {
             super.undo();
-        }
-        else {
+        } else {
             die();
         }
 
@@ -203,12 +192,12 @@ public class TextCompoundEdit extends Co
     }
 
     @Override
-    public synchronized String getRedoPresentationName() {
+    public String getRedoPresentationName() {
         return "Redo Text Change";
     }
 
     @Override
-    public synchronized String getUndoPresentationName() {
+    public String getUndoPresentationName() {
         return "Undo Text Change";
     }
 

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CircularArray.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CircularArray.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CircularArray.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CircularArray.java Sat Jul 20 09:49:20 2013
@@ -17,13 +17,12 @@
  *  under the License.
  ****************************************************************/
 
-
 package org.apache.cayenne.modeler.util;
 
 /**
- * A circular array is an array of fixed size as objects are added it will push objects
- * off of the end to allow space for new objects to be added. This is useful for things
- * like a fixed history size for a navigation tool.
+ * A circular array is an array of fixed size as objects are added it will push
+ * objects off of the end to allow space for new objects to be added. This is
+ * useful for things like a fixed history size for a navigation tool.
  * 
  * @since 1.2
  */
@@ -38,7 +37,8 @@ public class CircularArray extends Objec
     /**
      * Creates an array of capacity size.
      * 
-     * @param capacity - size of the new array
+     * @param capacity
+     *            - size of the new array
      */
     public CircularArray(int capacity) {
         if (capacity <= 0) {
@@ -51,7 +51,7 @@ public class CircularArray extends Objec
     /**
      * Clears out the contents of the array.
      */
-    public synchronized void clear() {
+    public void clear() {
         array = new Object[capacity];
         head = 0;
         tail = 0;
@@ -66,12 +66,13 @@ public class CircularArray extends Objec
     }
 
     /**
-     * Adds a new object to the array. If the array is full it will push the oldest item
-     * out of the array.
+     * Adds a new object to the array. If the array is full it will push the
+     * oldest item out of the array.
      * 
-     * @param obj - the object to be added
+     * @param obj
+     *            - the object to be added
      */
-    public synchronized void add(Object obj) {
+    public void add(Object obj) {
         // we have wrapped and we have to move the head pointer
         if (count == capacity && tail == head) {
             head = (head + 1) % capacity;
@@ -112,7 +113,8 @@ public class CircularArray extends Objec
     /**
      * Returns true if the array contains the specified object.
      * 
-     * @param obj the object to be checked
+     * @param obj
+     *            the object to be checked
      */
     public boolean contains(Object obj) {
         return indexOf(obj) >= 0;
@@ -121,9 +123,10 @@ public class CircularArray extends Objec
     /**
      * Gets the object at the specified index.
      * 
-     * @param index the index of the object to be retrieved
+     * @param index
+     *            the index of the object to be retrieved
      */
-    public synchronized Object get(int index) {
+    public Object get(int index) {
         rangeCheck(index);
         if (count == 0) {
             return null;
@@ -134,9 +137,10 @@ public class CircularArray extends Objec
     /**
      * Returns the index of the specified object
      * 
-     * @param obj the object that is being searched for
+     * @param obj
+     *            the object that is being searched for
      */
-    public synchronized int indexOf(Object obj) {
+    public int indexOf(Object obj) {
         for (int i = 0; i < capacity; i++) {
             int index = convert(i);
             if (array[index] == obj) {
@@ -150,13 +154,14 @@ public class CircularArray extends Objec
     /**
      * Removes the specified object from the array
      * 
-     * @param i the index of the object to be removed
+     * @param i
+     *            the index of the object to be removed
      */
-    public synchronized void remove(Object obj) {
+    public void remove(Object obj) {
         if (count == 0) {
             return;
         }
-        
+
         int i = indexOf(obj);
 
         while (i >= 0) {
@@ -168,14 +173,12 @@ public class CircularArray extends Objec
                 head = (head + 1) % capacity;
                 array[pos] = null;
                 count--;
-            }
-            else if (pos == tail) {
+            } else if (pos == tail) {
                 // move the tail back one
                 tail = (tail - 1 + capacity) % capacity;
                 array[pos] = null;
                 count--;
-            }
-            else {
+            } else {
                 // create a brand new array and start it back out at zero
                 Object[] a = new Object[capacity];
                 int destPos = 0;
@@ -201,8 +204,7 @@ public class CircularArray extends Objec
                         if (len > 0) {
                             System.arraycopy(array, 0, a, destPos, len);
                         }
-                    }
-                    else if (head > pos) {
+                    } else if (head > pos) {
                         // copy from head to end of array
                         len = capacity - head;
                         if (len > 0) {
@@ -223,8 +225,7 @@ public class CircularArray extends Objec
                             System.arraycopy(array, pos + 1, a, destPos, len);
                         }
                     }
-                }
-                else if (head < tail) {
+                } else if (head < tail) {
                     // copy from head to position -1
                     len = pos - head;
                     if (len > 0) {
@@ -238,8 +239,7 @@ public class CircularArray extends Objec
                         System.arraycopy(array, pos + 1, a, destPos, len);
                         destPos += len;
                     }
-                }
-                else if (head > tail) {
+                } else if (head > tail) {
                     if (head < pos) {
                         // copy from head to position
                         len = pos - head;
@@ -258,8 +258,7 @@ public class CircularArray extends Objec
                         if (len > 0) {
                             System.arraycopy(array, 0, a, destPos, len);
                         }
-                    }
-                    else if (head > pos) {
+                    } else if (head > pos) {
                         // copy from head to end of array
                         len = capacity - head;
                         if (len > 0) {
@@ -291,13 +290,14 @@ public class CircularArray extends Objec
     }
 
     /**
-     * Resizes the array to the specified new size. If the new capacity is smaller than
-     * the current object count in the array, it will keep the newCapacity most recent
-     * objects.
+     * Resizes the array to the specified new size. If the new capacity is
+     * smaller than the current object count in the array, it will keep the
+     * newCapacity most recent objects.
      * 
-     * @param newCapacity the new capacity of the array
+     * @param newCapacity
+     *            the new capacity of the array
      */
-    public synchronized void resize(int newCapacity) {
+    public void resize(int newCapacity) {
         int i = 0;
         int offset = 0;
         if (newCapacity < count) {
@@ -330,7 +330,7 @@ public class CircularArray extends Objec
     /**
      * Converts the array to an Object array.
      */
-    public synchronized Object[] toArray() {
+    public Object[] toArray() {
         Object[] o = new Object[capacity];
         for (int i = 0; i < capacity; i++) {
             o[i] = array[convert(i)];
@@ -338,7 +338,7 @@ public class CircularArray extends Objec
         return o;
     }
 
-    public synchronized String internalRep() {
+    public String internalRep() {
         Object o = null;
 
         StringBuffer sb = new StringBuffer();
@@ -349,8 +349,7 @@ public class CircularArray extends Objec
             o = array[i];
             if (o == null) {
                 sb.append("null");
-            }
-            else {
+            } else {
                 sb.append(o.toString());
             }
             if (i == head || i == tail) {
@@ -391,8 +390,7 @@ public class CircularArray extends Objec
             }
             if (o == null) {
                 sb.append("null");
-            }
-            else {
+            } else {
                 sb.append(o.toString());
             }
         }

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/EntityTreeModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/EntityTreeModel.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/EntityTreeModel.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/EntityTreeModel.java Sat Jul 20 09:49:20 2013
@@ -21,9 +21,7 @@ package org.apache.cayenne.modeler.util;
 
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
@@ -49,10 +47,10 @@ public class EntityTreeModel implements 
      * Filter for checking attributes and relationships
      */
     protected EntityTreeFilter filter;
-    
+
     public EntityTreeModel(Entity root) {
         this.root = root;
-        sortedChildren = Collections.synchronizedMap(new HashMap<Object, Object[]>());
+        sortedChildren = new HashMap<Object, Object[]>();
     }
 
     public Object getRoot() {
@@ -82,10 +80,7 @@ public class EntityTreeModel implements 
 
         // wonder if linear search will be faster, considering that
         // this comparator uses reflection?
-        return Arrays.binarySearch(
-            sortedChildren(node),
-            child,
-            Comparators.getNamedObjectComparator());
+        return Arrays.binarySearch(sortedChildren(node), child, Comparators.getNamedObjectComparator());
     }
 
     public void addTreeModelListener(TreeModelListener listener) {
@@ -98,86 +93,79 @@ public class EntityTreeModel implements 
 
     private Object[] sortedChildren(Object node) {
         Entity entity = entityForNonLeafNode(node);
-        
+
         // may happen in incomplete relationships
-        if(entity == null) {
+        if (entity == null) {
             return new Object[0];
         }
 
-        synchronized (sortedChildren) {
-            Object key = node;
-            Object[] sortedForNode = sortedChildren.get(key);
-
-            if (sortedForNode == null) {
-                Collection<? extends Attribute> attributes = entity.getAttributes();
-                Collection<? extends Relationship> relationships = entity.getRelationships();
-
-                List<Object> nodes = new Vector<Object>();
-                                
-                // combine two collections in an array
-                for (Attribute attr : attributes) {
-                    if (filter == null || filter.attributeMatch(node, attr)) {
-                        nodes.add(attr);
-                    }
-                }
+        Object key = node;
+        Object[] sortedForNode = sortedChildren.get(key);
 
-                for (Relationship rel : relationships) {
-                    if (filter == null || filter.relationshipMatch(node, rel)) {
-                        nodes.add(rel);
-                    }
+        if (sortedForNode == null) {
+            Collection<? extends Attribute> attributes = entity.getAttributes();
+            Collection<? extends Relationship> relationships = entity.getRelationships();
+
+            List<Object> nodes = new Vector<Object>();
+
+            // combine two collections in an array
+            for (Attribute attr : attributes) {
+                if (filter == null || filter.attributeMatch(node, attr)) {
+                    nodes.add(attr);
                 }
+            }
 
-                sortedForNode = nodes.toArray();
-                
-                Arrays.sort(sortedForNode, Comparators.getEntityChildrenComparator());
-                sortedChildren.put(key, sortedForNode);
+            for (Relationship rel : relationships) {
+                if (filter == null || filter.relationshipMatch(node, rel)) {
+                    nodes.add(rel);
+                }
             }
 
-            return sortedForNode;
+            sortedForNode = nodes.toArray();
+
+            Arrays.sort(sortedForNode, Comparators.getEntityChildrenComparator());
+            sortedChildren.put(key, sortedForNode);
         }
+
+        return sortedForNode;
     }
-    
+
     /**
      * Removes children cache for specified entity.
      */
     public void invalidate() {
-        synchronized (sortedChildren) {
-            sortedChildren.clear();
-        }
+        sortedChildren.clear();
     }
-    
+
     /**
      * Removes children cache for specified entity.
      */
     public void invalidateChildren(Entity entity) {
-        synchronized (sortedChildren) {
-            sortedChildren.remove(entity);
-            
-            for (Relationship rel : entity.getRelationships()) {
-                sortedChildren.remove(rel);
-            }
+        sortedChildren.remove(entity);
+
+        for (Relationship rel : entity.getRelationships()) {
+            sortedChildren.remove(rel);
         }
     }
 
     private Entity entityForNonLeafNode(Object node) {
         if (node instanceof Entity) {
             return (Entity) node;
-        }
-        else if (node instanceof Relationship) {
+        } else if (node instanceof Relationship) {
             return ((Relationship) node).getTargetEntity();
         }
 
         String className = (node != null) ? node.getClass().getName() : "null";
         throw new IllegalArgumentException("Unexpected non-leaf node: " + className);
     }
-    
+
     /**
      * Sets filter for attrs and rels
      */
     public void setFilter(EntityTreeFilter filter) {
         this.filter = filter;
     }
-    
+
     /**
      * Returns filter for attrs and rels
      */

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/FileWatchdog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/FileWatchdog.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/FileWatchdog.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/FileWatchdog.java Sat Jul 20 09:49:20 2013
@@ -17,21 +17,21 @@
 package org.apache.cayenne.modeler.util;
 
 import java.io.File;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Vector;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- * FileWatchdog is a watcher for files' change. If one of the files has changed or been
- * removed, a {@link #doOnChange(org.apache.cayenne.modeler.util.FileWatchdog.FileInfo)}
- * or {@link #doOnRemove(org.apache.cayenne.modeler.util.FileWatchdog.FileInfo) method}
- * will be called
+ * FileWatchdog is a watcher for files' change. If one of the files has changed
+ * or been removed, a
+ * {@link #doOnChange(org.apache.cayenne.modeler.util.FileWatchdog.FileInfo)} or
+ * {@link #doOnRemove(org.apache.cayenne.modeler.util.FileWatchdog.FileInfo)
+ * method} will be called
  * 
  * Original code taken from Log4J project
  * 
@@ -49,7 +49,8 @@ public abstract class FileWatchdog exten
     protected Map<String, FileInfo> filesInfo;
 
     /**
-     * The delay to observe between every check. By default set {@link #DEFAULT_DELAY}.
+     * The delay to observe between every check. By default set
+     * {@link #DEFAULT_DELAY}.
      */
     protected long delay = DEFAULT_DELAY;
 
@@ -59,8 +60,8 @@ public abstract class FileWatchdog exten
     protected boolean paused;
 
     /**
-     * This flags shows whether only one or multiple notifications will be fired when
-     * several files change
+     * This flags shows whether only one or multiple notifications will be fired
+     * when several files change
      */
     protected boolean singleNotification;
 
@@ -72,21 +73,21 @@ public abstract class FileWatchdog exten
     private static Log log = LogFactory.getLog(FileWatchdog.class);
 
     protected FileWatchdog() {
-        filesInfo = Collections.synchronizedMap(new HashMap<String, FileInfo>());
+        filesInfo = new ConcurrentHashMap<String, FileInfo>();
         setDaemon(true);
     }
 
     /**
-     * Sets whether only one or multiple notifications will be fired when several files
-     * change
+     * Sets whether only one or multiple notifications will be fired when
+     * several files change
      */
     public void setSingleNotification(boolean b) {
         singleNotification = b;
     }
 
     /**
-     * Returns whether only one or multiple notifications will be fired when several files
-     * change
+     * Returns whether only one or multiple notifications will be fired when
+     * several files change
      */
     public boolean isSingleNotification() {
         return singleNotification;
@@ -95,37 +96,32 @@ public abstract class FileWatchdog exten
     /**
      * Adds a new file to watch
      * 
-     * @param location path of file
+     * @param location
+     *            path of file
      */
     public void addFile(String location) {
-        synchronized (sync) {
-            try {
-                filesInfo.put(location, new FileInfo(location));
-            }
-            catch (SecurityException e) {
-                log.error("SecurityException adding file " + location, e);
-            }
+        try {
+            filesInfo.put(location, new FileInfo(location));
+        } catch (SecurityException e) {
+            log.error("SecurityException adding file " + location, e);
         }
     }
 
     /**
      * Turns off watching for a specified file
      * 
-     * @param location path of file
+     * @param location
+     *            path of file
      */
     public void removeFile(String location) {
-        synchronized (sync) {
-            filesInfo.remove(location);
-        }
+        filesInfo.remove(location);
     }
 
     /**
      * Turns off watching for all files
      */
     public void removeAllFiles() {
-        synchronized (sync) {
-            filesInfo.clear();
-        }
+        filesInfo.clear();
     }
 
     /**
@@ -138,67 +134,66 @@ public abstract class FileWatchdog exten
     /**
      * Invoked when one of the watched files has changed
      * 
-     * @param fileInfo Changed file info
+     * @param fileInfo
+     *            Changed file info
      */
     protected abstract void doOnChange(FileInfo fileInfo);
 
     /**
      * Invoked when one of the watched files has been removed
      * 
-     * @param fileInfo Changed file info
+     * @param fileInfo
+     *            Changed file info
      */
     protected abstract void doOnRemove(FileInfo fileInfo);
 
     protected void check() {
-        synchronized (sync) {
-            if (paused)
-                return;
+        if (paused)
+            return;
 
-            List<FileInfo> changed = new Vector<FileInfo>();
-            List<FileInfo> deleted = new Vector<FileInfo>();
+        List<FileInfo> changed = new Vector<FileInfo>();
+        List<FileInfo> deleted = new Vector<FileInfo>();
 
-            for (Iterator<FileInfo> it = filesInfo.values().iterator(); it.hasNext();) {
-                FileInfo fi = it.next();
+        for (Iterator<FileInfo> it = filesInfo.values().iterator(); it.hasNext();) {
+            FileInfo fi = it.next();
 
-                boolean fileExists;
-                try {
-                    fileExists = fi.getFile().exists();
-                }
-                catch (SecurityException e) {
-                    log.error(
-                            "SecurityException checking file " + fi.getFile().getPath(),
-                            e);
-
-                    // we still process with other files
-                    continue;
-                }
-
-                if (fileExists) {
-                    long l = fi.getFile().lastModified(); // this can also throw a
-                                                            // SecurityException
-                    if (l > fi.getLastModified()) { // however, if we reached this point
-                                                    // this
-                        fi.setLastModified(l); // is very unlikely.
-                        changed.add(fi);
-                    }
-                }
-                else if (fi.getLastModified() != -1) // the file has been removed
-                {
-                    deleted.add(fi);
-                    it.remove(); // no point to watch the file now
+            boolean fileExists;
+            try {
+                fileExists = fi.getFile().exists();
+            } catch (SecurityException e) {
+                log.error("SecurityException checking file " + fi.getFile().getPath(), e);
+
+                // we still process with other files
+                continue;
+            }
+
+            if (fileExists) {
+                long l = fi.getFile().lastModified(); // this can also throw
+                                                      // a
+                                                      // SecurityException
+                if (l > fi.getLastModified()) { // however, if we reached
+                                                // this point
+                                                // this
+                    fi.setLastModified(l); // is very unlikely.
+                    changed.add(fi);
                 }
+            } else if (fi.getLastModified() != -1) // the file has been
+                                                   // removed
+            {
+                deleted.add(fi);
+                it.remove(); // no point to watch the file now
             }
+        }
 
-            for (FileInfo aDeleted : deleted) {
-                doOnRemove(aDeleted);
-                if (singleNotification)
-                    return;
-            }
-            for (FileInfo aChanged : changed) {
-                doOnChange(aChanged);
-                if (singleNotification)
-                    return;
-            }
+        for (FileInfo aDeleted : deleted) {
+            doOnRemove(aDeleted);
+            if (singleNotification)
+                return;
+        }
+        for (FileInfo aChanged : changed) {
+            doOnChange(aChanged);
+            if (singleNotification)
+                return;
         }
     }
 
@@ -207,8 +202,7 @@ public abstract class FileWatchdog exten
             try {
                 Thread.sleep(delay);
                 check();
-            }
-            catch (InterruptedException e) {
+            } catch (InterruptedException e) {
                 // someone asked to stop
                 return;
             }
@@ -216,12 +210,11 @@ public abstract class FileWatchdog exten
     }
 
     /**
-     * Tells watcher to pause watching for some time. Useful before changing files
+     * Tells watcher to pause watching for some time. Useful before changing
+     * files
      */
     public void pauseWatching() {
-        synchronized (sync) {
-            paused = true;
-        }
+        paused = true;
     }
 
     /**
@@ -232,7 +225,8 @@ public abstract class FileWatchdog exten
     }
 
     /**
-     * Class to store information about files (last modification time & File pointer)
+     * Class to store information about files (last modification time & File
+     * pointer)
      */
     protected class FileInfo {
 
@@ -249,7 +243,8 @@ public abstract class FileWatchdog exten
         /**
          * Creates new object
          * 
-         * @param location the file path
+         * @param location
+         *            the file path
          */
         public FileInfo(String location) {
             file = new File(location);

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JEditTextAreaUndoable.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JEditTextAreaUndoable.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JEditTextAreaUndoable.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/JEditTextAreaUndoable.java Sat Jul 20 09:49:20 2013
@@ -32,8 +32,7 @@ class JEditTextAreaUndoable extends JEdi
     private UndoableEditListener undoListener;
 
     JEditTextAreaUndoable() {
-        this.undoListener = new JTextFieldUndoListener(new JEditTextAreaUndoableAdapter(
-                this));
+        this.undoListener = new JTextFieldUndoListener(new JEditTextAreaUndoableAdapter(this));
 
         this.getDocument().addUndoableEditListener(this.undoListener);
     }
@@ -43,8 +42,7 @@ class JEditTextAreaUndoable extends JEdi
         this.getDocument().removeUndoableEditListener(this.undoListener);
         try {
             super.setText(t);
-        }
-        finally {
+        } finally {
             this.getDocument().addUndoableEditListener(this.undoListener);
         }
     }
@@ -52,7 +50,7 @@ class JEditTextAreaUndoable extends JEdi
     private static class JEditTextAreaUndoableAdapter extends JTextField {
 
         @Override
-        public synchronized void addFocusListener(FocusListener l) {
+        public void addFocusListener(FocusListener l) {
             if (textArea != null) {
                 textArea.addFocusListener(l);
             }

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/MultiColumnBrowser.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/MultiColumnBrowser.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/MultiColumnBrowser.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/MultiColumnBrowser.java Sat Jul 20 09:49:20 2013
@@ -26,7 +26,6 @@ import java.awt.GridLayout;
 import java.awt.Rectangle;
 import java.io.Serializable;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 import javax.swing.AbstractListModel;
@@ -47,19 +46,16 @@ import javax.swing.event.TreeSelectionLi
 import javax.swing.tree.TreeModel;
 import javax.swing.tree.TreePath;
 
-
 /**
- * A simple non-editable tree browser with multiple columns 
- * for display and navigation of a tree structure. This type of
- * browser is ideal for showing deeply (or infinitely) nested 
- * trees/graphs. The most famous example of its use is Mac OS X 
- * Finder column view. 
+ * A simple non-editable tree browser with multiple columns for display and
+ * navigation of a tree structure. This type of browser is ideal for showing
+ * deeply (or infinitely) nested trees/graphs. The most famous example of its
+ * use is Mac OS X Finder column view.
  * 
  * <p>
- * MultiColumnBrowser starts at the root of the tree
- * and automatically expands to the right as navigation goes deeper. 
- * MultiColumnBrowser uses the same TreeModel as a regular JTree 
- * for its navigation model.
+ * MultiColumnBrowser starts at the root of the tree and automatically expands
+ * to the right as navigation goes deeper. MultiColumnBrowser uses the same
+ * TreeModel as a regular JTree for its navigation model.
  * </p>
  * 
  * <p>
@@ -70,8 +66,7 @@ import javax.swing.tree.TreePath;
  */
 public class MultiColumnBrowser extends JPanel {
 
-    protected static final ImageIcon rightArrow =
-        ModelerUtil.buildIcon("scroll_right.gif");
+    protected static final ImageIcon rightArrow = ModelerUtil.buildIcon("scroll_right.gif");
 
     public static final int DEFAULT_MIN_COLUMNS_COUNT = 3;
 
@@ -84,7 +79,7 @@ public class MultiColumnBrowser extends 
     protected List<BrowserPanel> columns;
     protected ListSelectionListener browserSelector;
     protected List<TreeSelectionListener> treeSelectionListeners;
-    
+
     /**
      * Whether firing of TreeSelectionListeners is disabled now
      */
@@ -96,31 +91,24 @@ public class MultiColumnBrowser extends 
 
     public MultiColumnBrowser(int minColumns) {
         if (minColumns < DEFAULT_MIN_COLUMNS_COUNT) {
-            throw new IllegalArgumentException(
-                "Expected "
-                    + DEFAULT_MIN_COLUMNS_COUNT
-                    + " or more columns, got: "
+            throw new IllegalArgumentException("Expected " + DEFAULT_MIN_COLUMNS_COUNT + " or more columns, got: "
                     + minColumns);
         }
 
         this.minColumns = minColumns;
         this.browserSelector = new PanelController();
-        this.treeSelectionListeners = Collections.synchronizedList(new ArrayList<TreeSelectionListener>());
+        this.treeSelectionListeners = new ArrayList<TreeSelectionListener>();
         initView();
     }
 
     public void addTreeSelectionListener(TreeSelectionListener listener) {
-        synchronized (treeSelectionListeners) {
-            if (listener != null && !treeSelectionListeners.contains(listener)) {
-                treeSelectionListeners.add(listener);
-            }
+        if (listener != null && !treeSelectionListeners.contains(listener)) {
+            treeSelectionListeners.add(listener);
         }
     }
 
     public void removeTreeSelectionListener(TreeSelectionListener listener) {
-        synchronized (treeSelectionListeners) {
-            treeSelectionListeners.remove(listener);
-        }
+        treeSelectionListeners.remove(listener);
     }
 
     /**
@@ -130,12 +118,10 @@ public class MultiColumnBrowser extends 
         if (fireDisabled) {
             return;
         }
-        
-        TreeSelectionEvent e =
-            new TreeSelectionEvent(this, new TreePath(selectionPath), false, null, null);
-        synchronized (treeSelectionListeners) {
-            for (TreeSelectionListener listener : treeSelectionListeners)
-                listener.valueChanged(e);
+
+        TreeSelectionEvent e = new TreeSelectionEvent(this, new TreePath(selectionPath), false, null, null);
+        for (TreeSelectionListener listener : treeSelectionListeners) {
+            listener.valueChanged(e);
         }
     }
 
@@ -145,31 +131,29 @@ public class MultiColumnBrowser extends 
     public TreePath getSelectionPath() {
         return new TreePath(selectionPath);
     }
-    
+
     /**
      * Sets new selection path and fires an event
      */
     public void setSelectionPath(TreePath path) {
         try {
             fireDisabled = true;
-            
+
             for (int i = 0; i < path.getPathCount(); i++) {
                 selectRow(path.getPathComponent(i), i, path);
             }
-        }
-        finally {
+        } finally {
             fireDisabled = false;
         }
     }
-    
+
     /**
      * Selects one path component
      */
     protected void selectRow(Object row, int index, TreePath path) {
         if (index > 0 && columns.get(index - 1).getSelectedValue() != row) {
             columns.get(index - 1).setSelectedValue(row, true);
-        }
-        else { //update
+        } else { // update
             updateFromModel(row, index - 1);
         }
     }
@@ -201,9 +185,9 @@ public class MultiColumnBrowser extends 
     }
 
     /**
-     * Resets currently used renderer to default one that will
-     * use the "name" property of objects and display a small
-     * arrow to the right of all non-leaf nodes.
+     * Resets currently used renderer to default one that will use the "name"
+     * property of objects and display a small arrow to the right of all
+     * non-leaf nodes.
      */
     public void setDefaultRenderer() {
         if (!(renderer instanceof MultiColumnBrowserRenderer)) {
@@ -221,7 +205,7 @@ public class MultiColumnBrowser extends 
     /**
      * Initializes the renderer of column cells.
      */
-    public synchronized void setRenderer(ListCellRenderer renderer) {
+    public void setRenderer(ListCellRenderer renderer) {
         if (this.renderer != renderer) {
             this.renderer = renderer;
 
@@ -236,7 +220,7 @@ public class MultiColumnBrowser extends 
     /**
      * Initializes browser model.
      */
-    public synchronized void setModel(TreeModel model) {
+    public void setModel(TreeModel model) {
         if (model == null) {
             throw new NullPointerException("Null tree model.");
         }
@@ -268,13 +252,13 @@ public class MultiColumnBrowser extends 
     // ====================================================
 
     private void initView() {
-        columns = Collections.synchronizedList(new ArrayList<BrowserPanel>(minColumns));
+        columns = new ArrayList<BrowserPanel>(minColumns);
         adjustViewColumns(minColumns);
     }
 
     /**
-     * Expands or contracts the view by <code>delta</code> columns.
-     * Never contracts the view below <code>minColumns</code>.
+     * Expands or contracts the view by <code>delta</code> columns. Never
+     * contracts the view below <code>minColumns</code>.
      */
     private void adjustViewColumns(int delta) {
         if (delta == 0) {
@@ -286,8 +270,7 @@ public class MultiColumnBrowser extends 
             for (int i = 0; i < delta; i++) {
                 appendColumn();
             }
-        }
-        else {
+        } else {
             for (int i = -delta; i > 0 && columns.size() > minColumns; i--) {
                 removeLastColumn();
             }
@@ -302,10 +285,7 @@ public class MultiColumnBrowser extends 
         installColumn(panel);
 
         columns.add(panel);
-        JScrollPane scroller =
-            new JScrollPane(
-                panel,
-                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+        JScrollPane scroller = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
 
         // note - it is important to set prefrred size on scroller,
@@ -317,7 +297,7 @@ public class MultiColumnBrowser extends 
         add(scroller);
         return panel;
     }
-    
+
     /**
      * Installs all needed columns and renderers to a new column
      */
@@ -340,14 +320,14 @@ public class MultiColumnBrowser extends 
         remove(index);
         return panel;
     }
-    
+
     /**
      * Clears selection in browser and removes all unnessesary columns
      */
     public void clearSelection() {
         updateFromModel(model.getRoot(), -1);
     }
-    
+
     /**
      * Removes all local listeners from the column
      */
@@ -356,8 +336,8 @@ public class MultiColumnBrowser extends 
     }
 
     /**
-     * Refreshes preferred size of the browser to
-     * reflect current number of columns.
+     * Refreshes preferred size of the browser to reflect current number of
+     * columns.
      */
     private void refreshPreferredSize() {
         if (preferredColumnSize != null) {
@@ -393,30 +373,30 @@ public class MultiColumnBrowser extends 
             viewport.scrollRectToVisible(rectangle);
         }
     }
-    
+
     /**
      * Rebuilds view for the new object selection.
      */
-    protected synchronized void updateFromModel(Object selectedNode, int panelIndex) {
+    protected void updateFromModel(Object selectedNode, int panelIndex) {
         updateFromModel(selectedNode, panelIndex, true);
     }
 
     /**
      * Rebuilds view for the new object selection.
-     * @param load Whether children are loaded automatically
+     * 
+     * @param load
+     *            Whether children are loaded automatically
      */
-    protected synchronized void updateFromModel(Object selectedNode, int panelIndex, boolean load) {
-        if(selectionPath == null) {
+    protected void updateFromModel(Object selectedNode, int panelIndex, boolean load) {
+        if (selectionPath == null) {
             selectionPath = new Object[0];
         }
-        
+
         // clean up extra columns
         int lastIndex = selectionPath.length;
 
-        // check array range to handle race conditions 
-        for (int i = panelIndex + 1;
-            i <= lastIndex && i >= 0 && i < columns.size();
-            i++) {
+        // check array range to handle race conditions
+        for (int i = panelIndex + 1; i <= lastIndex && i >= 0 && i < columns.size(); i++) {
             BrowserPanel column = columns.get(i);
             column.getSelectionModel().clearSelection();
             column.setRootNode(null);
@@ -426,11 +406,11 @@ public class MultiColumnBrowser extends 
         this.selectionPath = rebuildPath(selectionPath, selectedNode, panelIndex);
 
         if (load) {
-            // a selectedNode is contained in "panelIndex" column, 
+            // a selectedNode is contained in "panelIndex" column,
             // but its children are in the next column.
             panelIndex++;
         }
-        
+
         // expand/contract columns as needed
         adjustViewColumns(panelIndex + 1 - columns.size());
 
@@ -446,10 +426,10 @@ public class MultiColumnBrowser extends 
         fireTreeSelectionEvent(selectionPath);
     }
 
-    /** 
-     * Builds a TreePath to the new node, that is known to be a peer or a child 
-     * of one of the path components. As the method walks the current path backwards,
-     * it cleans columns that are not common with the new path.
+    /**
+     * Builds a TreePath to the new node, that is known to be a peer or a child
+     * of one of the path components. As the method walks the current path
+     * backwards, it cleans columns that are not common with the new path.
      */
     private Object[] rebuildPath(Object[] path, Object node, int panelIndex) {
         Object[] newPath = new Object[panelIndex + 2];
@@ -477,10 +457,7 @@ public class MultiColumnBrowser extends 
             this.children = (treeNode != null) ? model.getChildCount(treeNode) : 0;
 
             // must fire an event to refresh the view
-            super.fireContentsChanged(
-                MultiColumnBrowser.this,
-                0,
-                Math.max(oldChildren, children));
+            super.fireContentsChanged(MultiColumnBrowser.this, 0, Math.max(oldChildren, children));
         }
 
         public Object getElementAt(int index) {
@@ -530,7 +507,7 @@ public class MultiColumnBrowser extends 
     }
 
     // ====================================================
-    // Default renderer that shows non-leaf nodes with a 
+    // Default renderer that shows non-leaf nodes with a
     // small right arrow. Unfortunately we can't subclass
     // DefaultListCellRenerer since it extends JLabel that
     // does not allow the layout that we need.
@@ -558,20 +535,11 @@ public class MultiColumnBrowser extends 
             nonLeafPanel.add((Component) nonLeafTextRenderer, BorderLayout.WEST);
         }
 
-        public Component getListCellRendererComponent(
-            JList list,
-            Object value,
-            int index,
-            boolean isSelected,
-            boolean cellHasFocus) {
+        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
+                boolean cellHasFocus) {
 
             if (getModel().isLeaf(value)) {
-                return leafRenderer.getListCellRendererComponent(
-                    list,
-                    value,
-                    index,
-                    isSelected,
-                    cellHasFocus);
+                return leafRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
             }
 
             Object renderedValue = ModelerUtil.getObjectName(value);
@@ -580,12 +548,7 @@ public class MultiColumnBrowser extends 
                 renderedValue = " ";
             }
 
-            Component text =
-                nonLeafTextRenderer.getListCellRendererComponent(
-                    list,
-                    renderedValue,
-                    index,
-                    isSelected,
+            Component text = nonLeafTextRenderer.getListCellRendererComponent(list, renderedValue, index, isSelected,
                     cellHasFocus);
 
             nonLeafPanel.setComponentOrientation(text.getComponentOrientation());

Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ValidatorTextAdapter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ValidatorTextAdapter.java?rev=1505113&r1=1505112&r2=1505113&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ValidatorTextAdapter.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ValidatorTextAdapter.java Sat Jul 20 09:49:20 2013
@@ -32,69 +32,70 @@ import javax.swing.text.JTextComponent;
 import org.apache.cayenne.validation.ValidationException;
 
 /**
- * Text adapter with live validation, which is fired in
- * VALIDATION_DELAY time.
+ * Text adapter with live validation, which is fired in VALIDATION_DELAY time.
  */
 public abstract class ValidatorTextAdapter extends TextAdapter {
     /**
      * Time between end of user input and validation firing
      */
     static final long VALIDATION_DELAY = 1500L;
-    
+
     /**
      * Is the live-checking enabled for the text component
      */
     boolean liveCheckEnabled;
-    
+
     public ValidatorTextAdapter(JTextField textField) {
         this(textField, true);
     }
-    
+
     public ValidatorTextAdapter(JTextField textField, boolean liveCheckEnabled) {
         super(textField, true, false, true);
         setLiveCheckEnabled(liveCheckEnabled);
         install(textField);
     }
-    
+
     public ValidatorTextAdapter(JTextArea textArea) {
         this(textArea, true);
     }
-    
+
     public ValidatorTextAdapter(JTextArea textArea, boolean liveCheckEnabled) {
         super(textArea, true, false);
         setLiveCheckEnabled(liveCheckEnabled);
         install(textArea);
     }
-    
+
     protected void install(JTextComponent textComponent) {
         TimerScheduler ts = new TimerScheduler();
-        
+
         textComponent.getDocument().addDocumentListener(ts);
         textComponent.addFocusListener(ts);
     }
-    
+
     /**
      * Live-checks if text is correct
-     * @throws ValidationException if the text is incorrect
+     * 
+     * @throws ValidationException
+     *             if the text is incorrect
      */
     protected abstract void validate(String text) throws ValidationException;
- 
+
     /**
      * @return Is the live-checking enabled for the text component
      */
     public boolean isLiveCheckEnabled() {
         return liveCheckEnabled;
     }
-    
+
     /**
      * Enables/disables live-checking
      */
     public void setLiveCheckEnabled(boolean b) {
         liveCheckEnabled = b;
     }
-    
+
     /**
-     * Task to be fired after some delay 
+     * Task to be fired after some delay
      */
     class ValidationTimerTask extends TimerTask {
         @Override
@@ -102,32 +103,33 @@ public abstract class ValidatorTextAdapt
             validate();
         }
     }
-    
+
     protected void validate() {
         try {
             validate(textComponent.getText());
             clear();
-        }
-        catch (ValidationException vex) {
+        } catch (ValidationException vex) {
             textComponent.setBackground(errorColor);
             textComponent.setToolTipText(wrapTooltip(vex.getUnlabeledMessage()));
         }
     }
-    
+
     /**
-     * Wraps the tooltip, making it multi-lined if needed.
-     * Current implementation uses HTML markup to break the lines
-     * @param tooltip single-line tooltip
+     * Wraps the tooltip, making it multi-lined if needed. Current
+     * implementation uses HTML markup to break the lines
+     * 
+     * @param tooltip
+     *            single-line tooltip
      * @return multi-line tooltip.
      */
     protected String wrapTooltip(String tooltip) {
         tooltip = encodeHTMLAttribute(tooltip);
         tooltip = tooltip.replaceAll(System.getProperty("line.separator"), "<br>");
-        
+
         return "<html>" + tooltip + "</html>";
     }
-    
-    /**
+
+/**
      * Encodes a string so that it can be used as an attribute value in an HMTL document.
      * Will do conversion of the greater/less signs and ampersands.
      * 
@@ -150,39 +152,29 @@ public abstract class ValidatorTextAdapt
             char c = str.charAt(i);
             if (c == '<') {
                 encoded.append("&lt;");
-            }
-            else if (c == '\"') {
+            } else if (c == '\"') {
                 encoded.append("&quot;");
-            }
-            else if (c == '>') {
+            } else if (c == '>') {
                 encoded.append("&gt;");
-            }
-            else if (c == '&') {
+            } else if (c == '&') {
                 encoded.append("&amp;");
-            }
-            else {
+            } else {
                 encoded.append(c);
             }
         }
 
         return encoded.toString();
     }
-    
+
     /**
-     * Listener to user input, which fires validation timer 
+     * Listener to user input, which fires validation timer
      */
     class TimerScheduler implements DocumentListener, FocusListener {
         /**
          * The timer, which fires validation after some delay
          */
         Timer validationTimer;
-        
-        Object sync; //to prevent concurrent collisions
-        
-        TimerScheduler() {
-            sync = new Object();
-        }
-        
+
         public void insertUpdate(DocumentEvent e) {
             schedule();
         }
@@ -196,17 +188,15 @@ public abstract class ValidatorTextAdapt
         }
 
         void schedule() {
-            if(isLiveCheckEnabled()) {
-                synchronized (sync) {
-                    if(validationTimer != null) {
-                        validationTimer.cancel();
-                    }
-                    
-                    clear();
-                    
-                    validationTimer = new Timer("cayenne-validation-timer");
-                    validationTimer.schedule(new ValidationTimerTask(), VALIDATION_DELAY);
+            if (isLiveCheckEnabled()) {
+                if (validationTimer != null) {
+                    validationTimer.cancel();
                 }
+
+                clear();
+
+                validationTimer = new Timer("cayenne-validation-timer");
+                validationTimer.schedule(new ValidationTimerTask(), VALIDATION_DELAY);
             }
         }
 
@@ -214,10 +204,8 @@ public abstract class ValidatorTextAdapt
         }
 
         public void focusLost(FocusEvent e) {
-            synchronized (sync) {
-                if(validationTimer != null) {
-                    validationTimer.cancel();
-                }
+            if (validationTimer != null) {
+                validationTimer.cancel();
             }
         };
     }