cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r731576 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog: FindDialog.java FindDialogView.java
Date Mon, 05 Jan 2009 13:54:51 GMT
Author: aadamchik
Date: Mon Jan  5 05:54:50 2009
New Revision: 731576

URL: http://svn.apache.org/viewvc?rev=731576&view=rev
Log:
CAY-1156 Modeler search improvement

patch #3 from Olga. Fixed visual problems with the search dialog

Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java?rev=731576&r1=731575&r2=731576&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
Mon Jan  5 05:54:50 2009
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.dialog;
 
-import java.awt.Color;
 import java.awt.Component;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
@@ -67,12 +66,10 @@
     private static Font font;
     private static Font fontSelected;
 
-
     public static Font getFont() {
         return font;
     }
 
-    
     public static Font getFontSelected() {
         return fontSelected;
     }
@@ -89,21 +86,29 @@
             Object[] path = (Object[]) it.next();
 
             if (path[path.length - 1] instanceof ObjEntity) {
-                objEntityNames.put(new Integer(index++), ((ObjEntity) path[path.length -
1]).getName());
+                objEntityNames.put(
+                        new Integer(index++),
+                        ((ObjEntity) path[path.length - 1]).getName());
             }
 
             if (path[path.length - 1] instanceof DbEntity) {
-                dbEntityNames.put(new Integer(index++), ((DbEntity) path[path.length - 1]).getName());
+                dbEntityNames.put(
+                        new Integer(index++),
+                        ((DbEntity) path[path.length - 1]).getName());
             }
 
             if (path[path.length - 1] instanceof Attribute) {
-                Object parentObject = ((Attribute) path[path.length - 1]).getParent(); 
-                attrNames.put(new Integer(index++), getParentName(path, parentObject) +"."+
((Attribute) path[path.length - 1]).getName());
-             }
+                Object parentObject = ((Attribute) path[path.length - 1]).getParent();
+                attrNames.put(new Integer(index++), getParentName(path, parentObject)
+                        + "."
+                        + ((Attribute) path[path.length - 1]).getName());
+            }
 
             if (path[path.length - 1] instanceof Relationship) {
-                Object parentObject = ((Relationship) path[path.length - 1]).getParent();

-                relatNames.put(new Integer(index++), getParentName(path, parentObject) +"."+
((Relationship) path[path.length - 1]).getName());                
+                Object parentObject = ((Relationship) path[path.length - 1]).getParent();
+                relatNames.put(new Integer(index++), getParentName(path, parentObject)
+                        + "."
+                        + ((Relationship) path[path.length - 1]).getName());
             }
         }
 
@@ -135,19 +140,18 @@
         });
 
         font = view.getOkButton().getFont();
-        fontSelected = new Font(font.getFamily(), font.BOLD, font.getSize()+2 ); 
+        fontSelected = new Font(font.getFamily(), font.BOLD, font.getSize() + 2);
 
-        Color color = view.getOkButton().getBackground();        
-  
         JTable table = view.getTable();
-        
+        table.setRowHeight(fontSelected.getSize() + 6);
+        table.setRowMargin(0);
         table.addKeyListener(new JumpToResultsKeyListener());
-        table.addMouseListener(new JumpToResultActionListener());       
+        table.addMouseListener(new JumpToResultActionListener());
         table.getSelectionModel().setSelectionInterval(0, 0);
     }
 
     public static void jumpToResult(Object[] path, EditorView editor) {
-        
+
         if (path[path.length - 1] instanceof Entity) {
 
             /** Make selection in a project tree, open correspondent entity tab */
@@ -222,49 +226,53 @@
         }
     }
 
-    
-private class JumpToResultActionListener implements MouseListener {
-       private EditorView editor = ((CayenneModelerFrame) application.getFrameController().getView()).getView();
-       
-                public void mouseClicked(MouseEvent e) {
-                    JTable table = (JTable) e.getSource();  
-                    Integer selectedLine = table.getSelectionModel().getLeadSelectionIndex();
-                    JLabel label = (JLabel) table.getModel().getValueAt(selectedLine, 0);
                  
-                    Integer index = (Integer) FindDialogView.getLabelAndObjectIndex().get(label);
-                     
-                    Object[] path = (Object[]) paths.get(index);
-                    jumpToResult(path, editor);
-                }
-
-                public void mouseEntered(MouseEvent e) {
-                }
-
-                public void mouseExited(MouseEvent e) {
-                }
+    private class JumpToResultActionListener implements MouseListener {
+
+        private EditorView editor = ((CayenneModelerFrame) application
+                .getFrameController()
+                .getView()).getView();
+
+        public void mouseClicked(MouseEvent e) {
+            JTable table = (JTable) e.getSource();
+            Integer selectedLine = table.getSelectionModel().getLeadSelectionIndex();
+            JLabel label = (JLabel) table.getModel().getValueAt(selectedLine, 0);
+            Integer index = (Integer) FindDialogView.getLabelAndObjectIndex().get(label);
+
+            Object[] path = (Object[]) paths.get(index);
+            jumpToResult(path, editor);
+        }
+
+        public void mouseEntered(MouseEvent e) {
+        }
+
+        public void mouseExited(MouseEvent e) {
+        }
 
-                public void mousePressed(MouseEvent e) {
-                }
+        public void mousePressed(MouseEvent e) {
+        }
 
-                public void mouseReleased(MouseEvent e) {
-                }
+        public void mouseReleased(MouseEvent e) {
+        }
     }
 
-private class JumpToResultsKeyListener implements KeyListener {
+    private class JumpToResultsKeyListener implements KeyListener {
 
         private EditorView editor = ((CayenneModelerFrame) application
-                .getFrameController().getView()).getView();
-     
-        public void keyPressed(KeyEvent e) { 
-           
+                .getFrameController()
+                .getView()).getView();
+
+        public void keyPressed(KeyEvent e) {
+
             if (e.getKeyCode() == KeyEvent.VK_ENTER) {
-                
-                JTable table = (JTable) e.getSource();  
+
+                JTable table = (JTable) e.getSource();
                 Integer selectedLine = table.getSelectionModel().getLeadSelectionIndex();
-                JLabel label = (JLabel) table.getModel().getValueAt(selectedLine, 0);   
               
-                Integer index = (Integer) FindDialogView.getLabelAndObjectIndex().get(label);
-                 
+                JLabel label = (JLabel) table.getModel().getValueAt(selectedLine, 0);
+                Integer index = (Integer) FindDialogView.getLabelAndObjectIndex().get(
+                        label);
+
                 Object[] path = (Object[]) paths.get(index);
-                jumpToResult(path, editor);          
+                jumpToResult(path, editor);
             }
         }
 
@@ -274,7 +282,7 @@
         public void keyTyped(KeyEvent e) {
         }
     }
-    
+
     /**
      * Builds a tree path for a given path. Urgent for later selection.
      * 
@@ -283,9 +291,8 @@
      */
     private static TreePath buildTreePath(Object[] path, EditorView editor) {
         Object[] mutableTreeNodes = new Object[path.length];
-        mutableTreeNodes[0] = ((ProjectTreeModel) editor
-                .getProjectTreeView()
-                .getModel()).getRootNode();
+        mutableTreeNodes[0] = ((ProjectTreeModel) editor.getProjectTreeView().getModel())
+                .getRootNode();
 
         Object[] helper;
         for (int i = 1; i < path.length; i++) {
@@ -298,21 +305,20 @@
                     .getModel()).getNodeForObjectPath(helper);
         }
         return new TreePath(mutableTreeNodes);
-    }   
-  
-    
-    private String getParentName(Object[] path, Object  parentObject) {
+    }
+
+    private String getParentName(Object[] path, Object parentObject) {
         String nameParent = null;
-        
-        if(parentObject  instanceof ObjEntity){
-            ObjEntity objEntity = (ObjEntity)parentObject;
+
+        if (parentObject instanceof ObjEntity) {
+            ObjEntity objEntity = (ObjEntity) parentObject;
             nameParent = objEntity.getName();
         }
-        if(parentObject  instanceof DbEntity){
-            DbEntity dbEntity = (DbEntity)parentObject;
-            nameParent = dbEntity.getName();                    
+        if (parentObject instanceof DbEntity) {
+            DbEntity dbEntity = (DbEntity) parentObject;
+            nameParent = dbEntity.getName();
         }
         return nameParent;
-    }  
-   
+    }
+
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java?rev=731576&r1=731575&r2=731576&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java
Mon Jan  5 05:54:50 2009
@@ -63,8 +63,7 @@
     private static JScrollPane scrollPane;
     private JTable table;
     private static Map LabelAndObjectIndex;
-    
-    
+
     public static Map getLabelAndObjectIndex() {
         return LabelAndObjectIndex;
     }
@@ -78,115 +77,130 @@
 
         JPanel panel = new JPanel();
         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
-        
+
         if (objEntityNames.isEmpty()
                 && dbEntityNames.isEmpty()
                 && attrNames.isEmpty()
                 && relatNames.isEmpty()) {
             panel.add(new JLabel("Nothing found!"));
-        } else {
-            
+        }
+        else {
+
             int curentLineInTable = 0;
-            int sizeDataVector = objEntityNames.size() + dbEntityNames.size() + attrNames.size()
+ relatNames.size();
-            
+            int sizeDataVector = objEntityNames.size()
+                    + dbEntityNames.size()
+                    + attrNames.size()
+                    + relatNames.size();
+
             Object[][] dataVector = new Object[sizeDataVector][];
-                      
-           TableModel tableModel = new TableModel();
-        
-           LabelAndObjectIndex = new HashMap<JLabel, Integer>();
-           
-           dataVector =  createResultTable(objEntityNames, CellRenderers
+
+            TableModel tableModel = new TableModel();
+
+            LabelAndObjectIndex = new HashMap<JLabel, Integer>();
+
+            dataVector = createResultTable(objEntityNames, CellRenderers
                     .iconForObject(new ObjEntity()), dataVector, curentLineInTable);
-           curentLineInTable = objEntityNames.size();
-           dataVector =  createResultTable(dbEntityNames, CellRenderers
-                 .iconForObject(new DbEntity()), dataVector, curentLineInTable);
-          
-           curentLineInTable = curentLineInTable + dbEntityNames.size();
-           dataVector =  createResultTable(attrNames, CellRenderers
-                 .iconForObject(new ObjAttribute()), dataVector, curentLineInTable);
-           
-           curentLineInTable = curentLineInTable + attrNames.size();
-           dataVector =  createResultTable(relatNames, CellRenderers
-                 .iconForObject(new ObjRelationship()), dataVector, curentLineInTable);
+            curentLineInTable = objEntityNames.size();
+            dataVector = createResultTable(dbEntityNames, CellRenderers
+                    .iconForObject(new DbEntity()), dataVector, curentLineInTable);
+
+            curentLineInTable = curentLineInTable + dbEntityNames.size();
+            dataVector = createResultTable(attrNames, CellRenderers
+                    .iconForObject(new ObjAttribute()), dataVector, curentLineInTable);
+
+            curentLineInTable = curentLineInTable + attrNames.size();
+            dataVector = createResultTable(relatNames, CellRenderers
+                    .iconForObject(new ObjRelationship()), dataVector, curentLineInTable);
+
+            tableModel.setDataVector(dataVector, new Object[] {
+                ""
+            });
 
-           tableModel.setDataVector(dataVector, new Object[]{""});
-            
             table = new JTable(tableModel);
-             
+
             table.getColumnModel().getColumn(0).setCellRenderer(new ImageRenderer());
             table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-            
-            InputMap im       = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
-            InputMap imParent = im.getParent(); 
-            imParent.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0));
+
+            InputMap im = table
+                    .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
+            InputMap imParent = im.getParent();
+            imParent.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
             im.setParent(imParent);
-            im.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0));
-            table.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,im);
-       }
-
-            JPanel okPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-            okButton = new JButton("OK");
-            okPanel.add(okButton);  
-            
-            JComponent contentPane = (JComponent) getContentPane();
-            
-            contentPane.setLayout(new BorderLayout());
-            
-            scrollPane = new JScrollPane( //panel
-                    table,
-                    JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
-                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
-            
-            contentPane.add(scrollPane);
-            contentPane.add(okPanel, BorderLayout.SOUTH);
-            
-            contentPane.setPreferredSize(new Dimension(400, 325));            
-            setTitle("Search results"); 
+            im.remove(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
+            table.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, im);
+        }
+
+        JPanel okPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
+        okButton = new JButton("OK");
+        okPanel.add(okButton);
+
+        JComponent contentPane = (JComponent) getContentPane();
+
+        contentPane.setLayout(new BorderLayout());
+
+        scrollPane = new JScrollPane( // panel
+                table,
+                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+
+        contentPane.add(scrollPane);
+        contentPane.add(okPanel, BorderLayout.SOUTH);
+
+        contentPane.setPreferredSize(new Dimension(400, 325));
+        setTitle("Search results");
     }
 
-    private Object[][] createResultTable(Map names, Icon icon, Object[][] dataVector, int
curentLineInTable){
-        
+    private Object[][] createResultTable(
+            Map names,
+            Icon icon,
+            Object[][] dataVector,
+            int curentLineInTable) {
+
         Comparator<String> comparer = new Comparator<String>() {
+
             public int compare(String o1, String o2) {
-                    return o1.compareTo(o2);
-            }};
+                return o1.compareTo(o2);
+            }
+        };
 
         Map sortedByNameMap = sortMapByValue(names, comparer);
-        
+
         Iterator it = sortedByNameMap.keySet().iterator();
-        Object[] objectHelper = new Object[]{};
-         
-        while (it.hasNext()) {           
-            Integer index = (Integer) it.next(); 
-            JLabel labelIcon = new JLabel(); 
-            labelIcon.setIcon(icon);  
+        Object[] objectHelper = new Object[] {};
+
+        while (it.hasNext()) {
+            Integer index = (Integer) it.next();
+            JLabel labelIcon = new JLabel();
+            labelIcon.setIcon(icon);
             labelIcon.setVisible(true);
             labelIcon.setText((String) sortedByNameMap.get(index));
-            objectHelper = new Object[]{labelIcon};  
-            dataVector[curentLineInTable] = objectHelper;            
+            objectHelper = new Object[] {
+                labelIcon
+            };
+            dataVector[curentLineInTable] = objectHelper;
             LabelAndObjectIndex.put(labelIcon, index);
-            curentLineInTable++;            
+            curentLineInTable++;
         }
-         
+
         return dataVector;
     }
 
     public JButton getOkButton() {
         return okButton;
     }
-    
-    public  <K, V> Map<K,V> sortMapByValue(Map<K, V> in, Comparator<?
super V> compare) {
+
+    public <K, V> Map<K, V> sortMapByValue(Map<K, V> in, Comparator<?
super V> compare) {
         Map<V, K> swapped = new TreeMap<V, K>(compare);
-        for(Entry<K,V> entry: in.entrySet()) {
-                if (entry.getValue() != null) {
-                        swapped.put(entry.getValue(), entry.getKey());
-                }
+        for (Entry<K, V> entry : in.entrySet()) {
+            if (entry.getValue() != null) {
+                swapped.put(entry.getValue(), entry.getKey());
+            }
         }
         LinkedHashMap<K, V> result = new LinkedHashMap<K, V>();
-        for(Entry<V,K> entry: swapped.entrySet()) {
-                if (entry.getValue() != null) {
-                        result.put(entry.getValue(), entry.getKey());
-                }
+        for (Entry<V, K> entry : swapped.entrySet()) {
+            if (entry.getValue() != null) {
+                result.put(entry.getValue(), entry.getKey());
+            }
         }
         return result;
     }
@@ -194,33 +208,37 @@
 }
 
 class ImageRenderer extends DefaultTableCellRenderer {
+
     JLabel lbl = new JLabel();
     ImageIcon icon = null;
-    
+
     ImageRenderer() {
         super();
     }
-    
-    public Component getTableCellRendererComponent(JTable table, Object value,
-                                                   boolean isSelected, boolean hasFocus,

-                                                   int row, int column) {   
+
+    public Component getTableCellRendererComponent(
+            JTable table,
+            Object value,
+            boolean isSelected,
+            boolean hasFocus,
+            int row,
+            int column) {
         lbl.setOpaque(true);
-        lbl.setText(((JLabel)value).getText().toString());
-        lbl.setIcon(((JLabel)value).getIcon());
-        int thickness;
-        lbl.setBorder( BorderFactory.createLineBorder(Color.LIGHT_GRAY,thickness =0));
-        
+        lbl.setText(((JLabel) value).getText().toString());
+        lbl.setIcon(((JLabel) value).getIcon());
+        lbl.setBorder(BorderFactory.createLineBorder(Color.WHITE, 0));
+        lbl.setBackground(Color.WHITE);
+
         lbl.setHorizontalAlignment(JLabel.LEFT);
-        {             
-            lbl.setFont(isSelected ? FindDialog.getFontSelected() :  FindDialog.getFont());
  
-        }
-         return lbl;
-    }        
-} 
+        lbl.setFont(isSelected ? FindDialog.getFontSelected() : FindDialog.getFont());
 
+        return lbl;
+    }
+}
 
 class TableModel extends javax.swing.table.DefaultTableModel {
+
     public boolean isCellEditable(int row, int col) {
         return false;
-    } 
+    }
 }



Mime
View raw message