Author: daceywang
Date: Tue Feb  3 11:52:23 2009
New Revision: 2937

Modified:
   trunk/src/ca/sqlpower/architect/swingui/BasicRelationshipUI.java
   trunk/src/ca/sqlpower/architect/swingui/Relationship.java
   trunk/src/ca/sqlpower/architect/swingui/RelationshipEditPanel.java
   trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java
   trunk/src/ca/sqlpower/architect/swingui/messages.properties

Log:
Improved the feature of changing relationshipLineColor. Moved the property just below the relationShipName, gave the ability to change the line color in the right-click menu, supported Undo, Redo and Save Load.

Modified: trunk/src/ca/sqlpower/architect/swingui/BasicRelationshipUI.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/BasicRelationshipUI.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/BasicRelationshipUI.java Tue Feb 3 11:52:23 2009
@@ -248,10 +248,18 @@
                 path = new GeneralPath(containmentPath);
                        }
                        
+            // if the relationship line is selected and the darker color
+            // is the same, then set it to default selected color
+            // (204,204,255)
+
                        if (!r.isSelected()) {
-                               g2.setColor(r.getColor());
+                               g2.setColor(r.getForegroundColor());
                        } else {
-                           g2.setColor(r.getColor().darker());
+                           
if(r.getForegroundColor().darker().equals(r.getForegroundColor())) {
+                               g2.setColor(new Color(204,204,255));
+                           } else {
+                               g2.setColor(r.getForegroundColor().darker());
+                           }
                        }

                        Stroke oldStroke = g2.getStroke();

Modified: trunk/src/ca/sqlpower/architect/swingui/Relationship.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/Relationship.java   (original)
+++ trunk/src/ca/sqlpower/architect/swingui/Relationship.java Tue Feb 3 11:52:23 2009
@@ -23,6 +23,7 @@
 import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
 import java.beans.PropertyChangeEvent;
@@ -30,6 +31,7 @@
 import java.util.Iterator;

 import javax.swing.AbstractAction;
+import javax.swing.Icon;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
@@ -51,14 +53,12 @@
 import ca.sqlpower.sqlobject.SQLObjectListener;
 import ca.sqlpower.sqlobject.SQLRelationship;
 import ca.sqlpower.sqlobject.SQLRelationship.ColumnMapping;
-import ca.sqlpower.util.WebColour;
+import ca.sqlpower.swingui.ColorIcon;
+import ca.sqlpower.swingui.ColourScheme;

public class Relationship extends PlayPenComponent implements SQLObjectListener, LayoutEdge {
        private static final Logger logger = 
Logger.getLogger(Relationship.class);

-       //Set the default color for Relationship lines
-       private Color color = new WebColour("#cc0000");
-
     private SQLRelationship model;
        private TablePane pkTable;
        private TablePane fkTable;
@@ -153,6 +153,24 @@
         setFocusToRelatedTables.add(mi);
         popup.add(setFocusToRelatedTables);

+ JMenu setRelationshipLineColor = new JMenu(Messages.getString("Relationship.relationshipLineColor")); //$NON-NLS-1$
+        for (final Color color : ColourScheme.RELATIONSHIP_LINE_COLOURS) {
+            Icon icon = new ColorIcon(60, 25, color);
+            mi = new JMenuItem(icon);
+            mi.addActionListener(new ActionListener() {
+                public void actionPerformed(ActionEvent e) {
+ getPlayPen().startCompoundEdit("Started setting the relationship line colour"); //$NON-NLS-1$ + for (Relationship r : getPlayPen().getSelectedRelationShips()) {
+                        logger.info("relationship line: ");
+                        r.setForegroundColor(color);
+                    }
+ getPlayPen().endCompoundEdit("Finished setting the relationship line colour"); //$NON-NLS-1$
+                }
+            });
+            setRelationshipLineColor.add(mi);
+        }
+        popup.add(setRelationshipLineColor);
+
         mi = new JMenuItem(af.getReverseRelationshipAction());
         popup.add(mi);

@@ -231,14 +249,6 @@
        }

        // -------------------- ACCESSORS AND MUTATORS ---------------------
-       
-       public Color getColor() {
-        return color;
-    }
-
-    public void setColor(Color color) {
-        this.color = color;
-    }

     public String getUIClassID() {
         return RelationshipUI.UI_CLASS_ID;

Modified: trunk/src/ca/sqlpower/architect/swingui/RelationshipEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/RelationshipEditPanel.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/RelationshipEditPanel.java Tue Feb 3 11:52:23 2009
@@ -124,7 +124,7 @@
             if(logger.isDebugEnabled()) {
                 logger.debug("This relationship is : " + r);
             }
-            this.color = r.getColor();
+            this.color = r.getForegroundColor();
         }

FormLayout layout = new FormLayout("pref, 4dlu, pref:grow, 4dlu, pref, 4dlu, pref:grow");
@@ -132,7 +132,13 @@
DefaultFormBuilder fb = new DefaultFormBuilder(layout, logger.isDebugEnabled() ? new FormDebugPanel() : new JPanel());

fb.append("Relationship Name", relationshipName = new JTextField(), 5);
-
+
+        fb.nextLine();
+ fb.append("Relationship Line Color", relationLineColor = new JComboBox(ColourScheme.RELATIONSHIP_LINE_COLOURS));
+        ColorCellRenderer renderer = new ColorCellRenderer(40, 20);
+        relationLineColor.setRenderer(renderer);
+
+        fb.nextLine();
                identifyingGroup = new ButtonGroup();
fb.append("Relationship Type", identifyingButton = new JRadioButton("Identifying"), 5);
                identifyingGroup.add(identifyingButton);
@@ -208,12 +214,6 @@
         fb.append("", deleteSetDefault = new JRadioButton("Set Default"));
         deleteRuleGroup.add(deleteSetDefault);

-        fb.nextLine();
-
- fb.append("Relationship Line Color", relationLineColor = new JComboBox(ColourScheme.FOREGROUND_COLOURS));
-        ColorCellRenderer renderer = new ColorCellRenderer(40, 20);
-        relationLineColor.setRenderer(renderer);
-
         //TO-FIX,doesn't work!
         relationshipName.selectAll();

@@ -225,6 +225,7 @@
        public void setRelationship(SQLRelationship r) {
                this.relationship = r;
                relationshipName.setText(r.getName());
+        relationLineColor.setSelectedItem(color);
                pkTableName.setText("PK Table: " + 
relationship.getPkTable().getName());
                fkTableName.setText("FK Table: " + 
relationship.getFkTable().getName());
                if ( r.isIdentifying()){
@@ -282,8 +283,6 @@
         } else if (r.getDeleteRule() == UpdateDeleteRule.SET_NULL) {
             deleteSetNull.setSelected(true);
         }
-
-        relationLineColor.setSelectedItem(color);

                relationshipName.selectAll();
                
@@ -312,6 +311,10 @@
logger.warn("Call to setIdentifying failed. Continuing with other properties.", ex);
                        }
                        
+                       for(Relationship r: relationshipLines) {
+ r.setForegroundColor((Color)relationLineColor.getSelectedItem());
+            }
+                       
                        if (pkTypeZeroOne.isSelected()) {
relationship.setPkCardinality(SQLRelationship.ZERO | SQLRelationship.ONE);
                        } else if (pkTypeZeroToMany.isSelected()) {
@@ -362,11 +365,6 @@
                 relationship.setDeleteRule(UpdateDeleteRule.SET_NULL);
             }

-            for(Relationship r: relationshipLines) {
-                r.setColor((Color)relationLineColor.getSelectedItem());
-            }
-
-
                } finally {
                        relationship.endCompoundEdit("Modify Relationship 
Properties");
                }

Modified: trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/SwingUIProject.java Tue Feb 3 11:52:23 2009
@@ -507,6 +507,13 @@
                 ((RelationshipUI) r.getUI()).setOrientation(orientation);
                 r.setPkConnectionPoint(new Point(pkx, pky));
                 r.setFkConnectionPoint(new Point(fkx, fky));
+
+ String rLineColor = attributes.getValue("relationshipLineColor"); //$NON-NLS-1$
+                if (rLineColor != null) {
+                    Color relationshipLineColor = Color.decode(rLineColor);
+                    r.setForegroundColor(relationshipLineColor);
+                }
+
             } catch (SQLObjectException e) {
logger.error("Couldn't create relationship component", e); //$NON-NLS-1$
             } catch (NumberFormatException e) {
@@ -1037,11 +1044,16 @@
         for (PlayPenComponent ppc : ppcs) {
             if (ppc instanceof Relationship) {
                 Relationship r = (Relationship) ppc;
+
+                Color relationshipLineColor = r.getForegroundColor();
+ String rColorString = String.format("0x%02x%02x%02x", relationshipLineColor.getRed(), relationshipLineColor.getGreen(), relationshipLineColor.getBlue()); //$NON-NLS-1$
+
ioo.println(out, "<table-link relationship-ref="+quote(sqlObjectSaveIdMap.get(r.getModel())) //$NON-NLS-1$ +" pk-x=\""+r.getPkConnectionPoint().x+"\"" //$NON-NLS-1$ //$NON-NLS-2$ +" pk-y=\""+r.getPkConnectionPoint().y+"\"" //$NON-NLS-1$ //$NON-NLS-2$ +" fk-x=\""+r.getFkConnectionPoint().x+"\"" //$NON-NLS-1$ //$NON-NLS-2$ +" fk-y=\""+r.getFkConnectionPoint().y+"\"" //$NON-NLS-1$ //$NON-NLS-2$ + +" relationshipLineColor="+quote(rColorString) //$NON-NLS-1$ +" orientation=\"" + ((RelationshipUI)r.getUI()).getOrientation() + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
             } else if (ppc instanceof UsageComponent) {
                 UsageComponent usageComp = (UsageComponent) ppc;

Modified: trunk/src/ca/sqlpower/architect/swingui/messages.properties
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/messages.properties (original)
+++ trunk/src/ca/sqlpower/architect/swingui/messages.properties Tue Feb 3 11:52:23 2009
@@ -273,6 +273,7 @@
 RecentMenu.couldNotOpenFile=Couldn't open file.
 RecentMenu.recentItems=Recent Items
 Relationship.setFocusMenu=Set Focus to...
+Relationship.relationshipLineColor=Relationship Line Color
 SearchReplace.anythingSearchOption=Anything
 SearchReplace.columnOfTable=Column of {0}
 SearchReplace.columnsSearchOption=Columns

Reply via email to