Author: daceywang
Date: Tue Apr 28 09:03:06 2009
New Revision: 3022

Modified:
   trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java
trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
   trunk/src/ca/sqlpower/architect/ArchitectSession.java
   trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java
   trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
   trunk/src/ca/sqlpower/architect/swingui/Relationship.java
   trunk/src/ca/sqlpower/architect/swingui/RelationshipEditPanel.java

Log:
Add a color chooser for relationship line color and the combo box should start with the current line color even if the color is not in our color set.

Modified: trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java
==============================================================================
--- trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java (original) +++ trunk/regress/ca/sqlpower/architect/TestingArchitectSession.java Tue Apr 28 09:03:06 2009
@@ -32,6 +32,7 @@

 package ca.sqlpower.architect;

+import java.awt.Color;
 import java.util.List;

 import ca.sqlpower.architect.ddl.DDLGenerator;
@@ -130,6 +131,11 @@
     }

     public SQLDatabase getDatabase(SPDataSource ds) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    public Color getCustomColour(Color foregroundColor) {
         // TODO Auto-generated method stub
         return null;
     }

Modified: trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
==============================================================================
--- trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java (original) +++ trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java Tue Apr 28 09:03:06 2009
@@ -18,6 +18,7 @@
  */
 package ca.sqlpower.architect.swingui;

+import java.awt.Color;
 import java.awt.Window;
 import java.io.IOException;
 import java.sql.SQLException;
@@ -366,5 +367,10 @@

public void setDisplayRelationshipLabel(boolean displayRelationshipLabel) {
         this.displayRelationshipLabel = displayRelationshipLabel;
+    }
+
+    public Color getCustomColour(Color foregroundColor) {
+        // TODO Auto-generated method stub
+        return null;
     }
 }

Modified: trunk/src/ca/sqlpower/architect/ArchitectSession.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/ArchitectSession.java       (original)
+++ trunk/src/ca/sqlpower/architect/ArchitectSession.java Tue Apr 28 09:03:06 2009
@@ -18,6 +18,7 @@
  */
 package ca.sqlpower.architect;

+import java.awt.Color;
 import java.util.List;

 import ca.sqlpower.architect.ddl.DDLGenerator;
@@ -99,5 +100,11 @@
      * Sets the new DDL Generator currently in use for this session.
      */
     public void setDDLGenerator(DDLGenerator generator);
+
+    /**
+     * Opens a dialog for the user to choose a custom colour.
+     * Returns the choosen colour.
+     */
+    public Color getCustomColour(Color foregroundColor);

 }

Modified: trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java   (original)
+++ trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java Tue Apr 28 09:03:06 2009
@@ -19,6 +19,7 @@
 package ca.sqlpower.architect;


+import java.awt.Color;
 import java.sql.SQLException;
 import java.util.List;

@@ -188,6 +189,11 @@
         } catch (SQLObjectException e) {
             throw new RuntimeException(e);
         }
+    }
+
+    public Color getCustomColour(Color foregroundColor) {
+        // TODO Auto-generated method stub
+        return null;
     }

 }

Modified: trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java (original) +++ trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Tue Apr 28 09:03:06 2009
@@ -18,12 +18,16 @@
  */
 package ca.sqlpower.architect.swingui;

+import java.awt.Color;
 import java.awt.Rectangle;
 import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.io.IOException;
+import java.io.Serializable;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -31,6 +35,7 @@
 import java.util.Set;

 import javax.swing.Action;
+import javax.swing.JColorChooser;
 import javax.swing.JDialog;
 import javax.swing.JFileChooser;
 import javax.swing.JMenu;
@@ -177,6 +182,13 @@
      * for Architect.
      */
     private final SwingUIUserPrompterFactory swinguiUserPrompterFactory;
+
+    /**
+ * A colour chooser used by the MungeProcessEditor to set custom colours. + * It has been created within a swing session to share recent colours amongst
+     * different match rule sets.
+     */
+    private final JColorChooser colourChooser = new JColorChooser();

     /**
* Creates a new swing session, including a new visible architect frame, with
@@ -947,5 +959,38 @@

public void setDisplayRelationshipLabel(boolean displayRelationshipLabel) {
         this.displayRelationshipLabel = displayRelationshipLabel;
+    }
+
+    public Color getCustomColour(Color initial) {
+        if (initial == null) {
+            initial = Color.BLACK;
+        }
+        colourChooser.setColor(initial);
+        ColorTracker ok = new ColorTracker(colourChooser);
+ JDialog dialog = JColorChooser.createDialog(frame, "Choose a custom colour", true, colourChooser, ok, null);
+
+        dialog.setVisible(true);
+
+        return ok.getColor();
+    }
+
+    /**
+     * Action Listener used by the custom colour dialog.
+     */
+    class ColorTracker implements ActionListener, Serializable {
+        JColorChooser chooser;
+        Color color;
+
+        public ColorTracker(JColorChooser c) {
+            chooser = c;
+        }
+
+        public void actionPerformed(ActionEvent e) {
+            color = chooser.getColor();
+        }
+
+        public Color getColor() {
+            return color;
+        }
     }
 }

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 Apr 28 09:03:06 2009
@@ -143,21 +143,8 @@
                setBackgroundColor(Color.green);
                model.addSQLObjectListener(this);
                setToolTipText(model.getName());
-               
-               // Check whether the foreground color of this machine is in the
-        // set of our color set. Add the color if it is not included,
-        // do nothing otherwise.
-        boolean containForegroundColor = false;
-        for (final Color color : SUGGESTED_COLOURS) {
-            if (color.equals(this.getForegroundColor())) {
-                containForegroundColor = true;
-        }
-        }
-        if (!containForegroundColor) {
-            SUGGESTED_COLOURS.add(this.getForegroundColor());
-        }
-
-        // requires pkTable and fkTable to be initialized
+
+               // requires pkTable and fkTable to be initialized
         //ui.bestConnectionPoints(); // breaks when loading a new project?
        }


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 Apr 28 09:03:06 2009
@@ -19,9 +19,14 @@
 package ca.sqlpower.architect.swingui;

 import java.awt.Color;
+import java.awt.event.ActionEvent;
 import java.util.List;
+import java.util.Vector;

+import javax.swing.AbstractAction;
+import javax.swing.Action;
 import javax.swing.ButtonGroup;
+import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JDialog;
 import javax.swing.JLabel;
@@ -133,6 +138,11 @@
fb.append(Messages.getString("RelationshipEditPanel.lineColour"), relationLineColor = new JComboBox(Relationship.SUGGESTED_COLOURS)); //$NON-NLS-1$
         ColorCellRenderer renderer = new ColorCellRenderer(40, 20);
         relationLineColor.setRenderer(renderer);
+        if (!containsColor(Relationship.SUGGESTED_COLOURS, color)) {
+            relationLineColor.addItem(color);
+            relationLineColor.setSelectedItem(color);
+        }
+        fb.append(new JButton(customColour));

         fb.nextLine();
fb.append(Messages.getString("RelationshipEditPanel.pkLabel"), pkLabelTextField = new JTextField());
@@ -427,5 +437,24 @@
     public void setEditDialog(JDialog editDialog) {
         this.editDialog = editDialog;
     }
-       
+
+    Action customColour = new AbstractAction("Custom Colour...") {
+        public void actionPerformed(ActionEvent arg0) {
+ Color colour = session.getCustomColour(relationshipLines.get(0).getForegroundColor()); + if (colour != null && !containsColor(Relationship.SUGGESTED_COLOURS, colour)) {
+                relationLineColor.addItem(colour);
+                relationLineColor.setSelectedItem(colour);
+            }
+        }
+    };
+
+       private boolean containsColor(Vector<Color> colorSet, Color color) {
+           boolean contains = false;
+           for (Color eachColor : colorSet) {
+               if (eachColor.equals(color)) {
+                   contains = true;
+               }
+           }
+           return contains;
+       }
 }

Reply via email to