Author: daceywang
Date: Tue Apr 21 15:59:46 2009
New Revision: 2985
Modified:
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
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:
Fixed some mistakes of relationshipLabel and now support user defined
relationship label. So far labels can only be edited through
relationshipEditPanel and cannot be dragged. But it's easier now to
implement those two more features.
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 21 15:59:46 2009
@@ -140,7 +140,7 @@
private ProjectModificationWatcher projectModificationWatcher;
- private boolean displayRelationshipLabel;
+ private boolean displayRelationshipLabel = true;
private boolean relationshipLinesDirect;
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
Apr 21 15:59:46 2009
@@ -32,10 +32,13 @@
import java.awt.geom.Line2D;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.List;
+import javax.swing.JLabel;
+
import org.apache.log4j.Logger;
import ca.sqlpower.swingui.ColourScheme;
@@ -89,6 +92,16 @@
*/
protected int radius = 4;
+ private FontMetrics fm;
+
+ private JLabel parentToChild = new JLabel();
+ private JLabel childToParent = new JLabel();
+ private Rectangle2D parentToChildRec = new Rectangle();
+ private Rectangle2D childToParentRec = new Rectangle();
+ {
+
+ }
+
// ------------------------ ComponentUI methods ------------------------
public static PlayPenComponentUI createUI(PlayPenComponent c) {
@@ -99,6 +112,7 @@
public void installUI(PlayPenComponent c) {
logger.debug("Installing BasicRelationshipUI on "+c);
relationship = (Relationship) c;
+ fm = relationship.getFontMetrics(relationship.getFont());
relationship.addPropertyChangeListener(this);
}
@@ -124,7 +138,6 @@
logger.debug("BasicRelationshipUI is painting");
Relationship r = (Relationship) c;
Graphics2D g2 = (Graphics2D) g;
- FontMetrics fm = r.getFontMetrics(r.getFont());
logger.debug("orientation is: " + orientation);
if (g2 == null)
{
@@ -194,9 +207,9 @@
rightmost = lineEnd.x;
}
parentToChildLabelStart =
calculateRelationshipLabelStart(leftmost, rightmost,
-
fm.stringWidth(Relationship.PAREENT_TO_CHILD));
+
fm.stringWidth(r.getTextForParentLabel()));
childToParentLabelStart =
calculateRelationshipLabelStart(leftmost, rightmost,
-
fm.stringWidth(Relationship.CHILD_TO_PARENT));
+
fm.stringWidth(r.getTextForChildLabel()));
}
if (relationship.getPkTable() == relationship.getFkTable()) {
@@ -212,13 +225,32 @@
path = new GeneralPath(containmentPath);
// draw relationship labels
if (r.displayRelationshipLabel()) {
- parentToChildLabelStart =
calculateRelationshipLabelStart(lineEnd.x - getTerminationLength(),
-
lineStart.x, fm.stringWidth(Relationship.PAREENT_TO_CHILD));
- childToParentLabelStart =
calculateRelationshipLabelStart(lineEnd.x - getTerminationLength(),
-
lineStart.x, fm.stringWidth(Relationship.CHILD_TO_PARENT));
+ leftmost = lineEnd.x - getTerminationLength();
+ rightmost = lineStart.x;
+ parentToChildLabelStart =
calculateRelationshipLabelStart(leftmost, rightmost,
+
fm.stringWidth(r.getTextForParentLabel()));
+ childToParentLabelStart =
calculateRelationshipLabelStart(leftmost, rightmost,
+
fm.stringWidth(r.getTextForChildLabel()));
logger.debug("relationship label starts at: " +
parentToChildLabelStart);
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineStart.y + fm.getHeight());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineStart.y + 2*fm.getHeight());
+ g2.translate(parentToChildLabelStart,lineStart.y +
getTerminationLength() - fm.getHeight());
+ parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart, -(lineStart.y +
getTerminationLength()) + fm.getHeight());
+ parentToChildRec.setRect(parentToChildLabelStart,
+ lineStart.y + getTerminationLength() -
fm.getHeight(),
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+ g2.translate(childToParentLabelStart,lineStart.y +
getTerminationLength());
+ childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart, -(lineStart.y +
getTerminationLength()));
+ childToParentRec.setRect(childToParentLabelStart,
+ lineStart.y + getTerminationLength(),
+ fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
}
containmentPath.lineTo(lineEnd.x -
getTerminationLength(), lineEnd.y);
@@ -245,24 +277,102 @@
// draw relationship labels
if (r.displayRelationshipLabel()) {
if ((orientation & PARENT_FACES_LEFT) != 0) {
+ logger.debug("The startpoint is : " + lineStart + "; The
endpoint is: " + lineEnd);
if (lineStart.y < lineEnd.y) {
logger.debug("pk table is at right and
higher");
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y + fm.getAscent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineStart.y - fm.getDescent());
+
+
g2.translate(parentToChildLabelStart,lineEnd.y);
+ parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart,
-lineEnd.y);
+ parentToChildRec.setRect(parentToChildLabelStart,
+ lineEnd.y,
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+ g2.translate(childToParentLabelStart,lineStart.y
- fm.getHeight());
+ childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart,
-(lineStart.y - fm.getHeight()));
+ childToParentRec.setRect(childToParentLabelStart,
+ lineStart.y -fm.getHeight(),
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y + fm.getAscent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineStart.y - fm.getDescent());
} else {
logger.debug("pk table is at right and
lower");
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineStart.y + fm.getAscent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y - fm.getDescent());
+
g2.translate(parentToChildLabelStart,lineStart.y);
+
parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost
- leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart,
-lineStart.y);
+
parentToChildRec.setRect(parentToChildLabelStart,
+ lineStart.y,
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+ g2.translate(childToParentLabelStart,lineEnd.y
- fm.getHeight());
+
childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost
- leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart,
-(lineEnd.y - fm.getHeight()));
+
childToParentRec.setRect(childToParentLabelStart,
+ lineEnd.y - fm.getHeight(),
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineStart.y + fm.getAscent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y - fm.getDescent());
}
} else {
if (lineStart.y < lineEnd.y) {
logger.debug("pk table is at left and
higher");
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineStart.y - fm.getDescent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y + fm.getAscent());
+ g2.translate(parentToChildLabelStart,lineStart.y -
fm.getHeight());
+
parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost
- leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart,
-(lineStart.y - fm.getHeight()));
+
parentToChildRec.setRect(parentToChildLabelStart,
+ lineStart.y - fm.getHeight(),
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+
g2.translate(childToParentLabelStart,lineEnd.y);
+
childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost
- leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart,
-lineEnd.y);
+
childToParentRec.setRect(childToParentLabelStart,
+ lineEnd.y,
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineStart.y - fm.getDescent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y + fm.getAscent());
} else {
logger.debug("pk table is at left and lower");
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y - fm.getDescent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineStart.y + fm.getAscent());
+ g2.translate(parentToChildLabelStart,lineEnd.y
- fm.getHeight());
+
parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost
- leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart,
-(lineEnd.y - fm.getHeight()));
+
parentToChildRec.setRect(parentToChildLabelStart,
+ lineEnd.y - fm.getHeight(),
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+
g2.translate(childToParentLabelStart,lineStart.y);
+
childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost
- leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart,
-lineStart.y);
+
childToParentRec.setRect(childToParentLabelStart,
+ lineStart.y,
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y - fm.getDescent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineStart.y + fm.getAscent());
}
}
}
@@ -282,24 +392,52 @@
path = new GeneralPath(containmentPath);
// draw relationship labels
if (r.displayRelationshipLabel()) {
- if ((orientation & PARENT_FACES_TOP) != 0) {
- logger.debug("pk table is at bottom");
- if (lineStart.x > lineEnd.x) {
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, midy + fm.getAscent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, midy - fm.getDescent());
- } else {
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, midy - fm.getDescent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, midy + fm.getAscent());
- }
+ if (lineStart.x > lineEnd.x) {
+ logger.debug("TOP-BOTTOM : pk table is at right");
+ g2.translate(parentToChildLabelStart,midy);
+ parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart, -midy);
+ parentToChildRec.setRect(parentToChildLabelStart,
+ midy,
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+ g2.translate(childToParentLabelStart, midy -
fm.getHeight());
+ childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart, -(midy -
fm.getHeight()));
+ childToParentRec.setRect(childToParentLabelStart,
+ midy - fm.getHeight(),
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, midy + fm.getAscent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, midy - fm.getDescent());
} else {
- logger.debug("pk table is at top");
- if (lineStart.x > lineEnd.x) {
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, midy + fm.getAscent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, midy - fm.getDescent());
- } else {
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, midy - fm.getDescent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, midy + fm.getAscent());
- }
+ logger.debug("TOP-BOTTOM : pk table is at left");
+ g2.translate(parentToChildLabelStart,midy -
fm.getHeight());
+ parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart, -(midy -
fm.getHeight()));
+ parentToChildRec.setRect(parentToChildLabelStart,
+ midy - fm.getHeight(),
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+ g2.translate(childToParentLabelStart, midy);
+ childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart, -midy);
+ childToParentRec.setRect(childToParentLabelStart,
+ midy,
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, midy - fm.getDescent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, midy + fm.getAscent());
}
}
@@ -318,12 +456,50 @@
if (r.displayRelationshipLabel()) {
if ((orientation & PARENT_FACES_LEFT) != 0) {
logger.debug("pk table is at right");
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineStart.y + fm.getAscent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineStart.y - fm.getDescent());
+ g2.translate(parentToChildLabelStart,lineStart.y);
+ parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart,
-lineStart.y);
+ parentToChildRec.setRect(parentToChildLabelStart,
+ lineStart.y,
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+ g2.translate(childToParentLabelStart,lineStart.y -
fm.getHeight());
+ childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart,
-(lineStart.y - fm.getHeight()));
+ childToParentRec.setRect(childToParentLabelStart,
+ lineStart.y - fm.getHeight(),
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineStart.y + fm.getAscent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineStart.y - fm.getDescent());
} else {
logger.debug("pk table is at left");
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineStart.y - fm.getDescent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineStart.y + fm.getAscent());
+ g2.translate(parentToChildLabelStart,lineStart.y -
fm.getHeight());
+ parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart,
-(lineStart.y - fm.getHeight()));
+ parentToChildRec.setRect(parentToChildLabelStart,
+ lineStart.y - fm.getHeight(),
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+ g2.translate(childToParentLabelStart,lineStart.y);
+ childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart,
-lineStart.y);
+ childToParentRec.setRect(childToParentLabelStart,
+ lineStart.y,
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineStart.y - fm.getDescent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineStart.y + fm.getAscent());
}
}
@@ -339,24 +515,52 @@
path = new GeneralPath(containmentPath);
// draw relationship labels
if (r.displayRelationshipLabel()) {
- if ((orientation & PARENT_FACES_TOP) != 0) {
- logger.debug("pk table is at bottom");
- if (lineStart.x > lineEnd.x) {
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y + fm.getAscent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y - fm.getDescent());
- } else {
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y - fm.getDescent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y + fm.getAscent());
- }
+ if (lineStart.x > lineEnd.x) {
+ logger.debug("TOP_BOTTOM--LEFT_RIGHT pk table is
at right");
+ g2.translate(parentToChildLabelStart,lineEnd.y);
+ parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart, -lineEnd.y);
+ parentToChildRec.setRect(parentToChildLabelStart,
+ lineEnd.y,
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+ g2.translate(childToParentLabelStart,lineEnd.y -
fm.getHeight());
+ childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart, -(lineEnd.y
- fm.getHeight()));
+ childToParentRec.setRect(childToParentLabelStart,
+ lineEnd.y - fm.getHeight(),
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y + fm.getAscent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y - fm.getDescent());
} else {
- logger.debug("pk table is at top");
- if (lineStart.x > lineEnd.x) {
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y + fm.getAscent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y - fm.getDescent());
- } else {
- g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y - fm.getDescent());
- g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y + fm.getAscent());
- }
+ logger.debug("TOP_BOTTOM--LEFT_RIGHT pk table is
at left");
+ g2.translate(parentToChildLabelStart,lineEnd.y -
fm.getHeight());
+ parentToChild.setText(r.getTextForParentLabel());
+ parentToChild.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ parentToChild.paint(g2);
+ g2.translate(-parentToChildLabelStart, -(lineEnd.y
- fm.getHeight()));
+ parentToChildRec.setRect(parentToChildLabelStart,
+ lineEnd.y - fm.getHeight(),
+
fm.stringWidth(r.getTextForParentLabel()),
+ fm.getHeight());
+
+ g2.translate(childToParentLabelStart,lineEnd.y);
+ childToParent.setText(r.getTextForChildLabel());
+ childToParent.setBounds(0, 0, (int) (rightmost -
leftmost), fm.getHeight());
+ childToParent.paint(g2);
+ g2.translate(-childToParentLabelStart, -lineEnd.y);
+ childToParentRec.setRect(childToParentLabelStart,
+ lineEnd.y,
+
fm.stringWidth(r.getTextForChildLabel()),
+ fm.getHeight());
+// g2.drawString(Relationship.PAREENT_TO_CHILD,
parentToChildLabelStart, lineEnd.y - fm.getDescent());
+// g2.drawString(Relationship.CHILD_TO_PARENT,
childToParentLabelStart, lineEnd.y + fm.getAscent());
}
}
@@ -1015,7 +1219,7 @@
Point bottomRight = new Point(pkConnectionPoint.x +
getTerminationWidth(),
pkConnectionPoint.y + radius + getTerminationLength() * 2);
computedBounds = new Rectangle(topLeft.x + pkTable.getX(), topLeft.y +
pkTable.getY(),
-
bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
+ bottomRight.x - topLeft.x, bottomRight.y - topLeft.y +
fm.getHeight());
} else {
Point pkLimits = new Point(pkConnectionPoint);
@@ -1067,8 +1271,8 @@
fkLimits.x),
Math.max(pkLimits.y,
fkLimits.y));
- computedBounds = new Rectangle(topLeft.x, topLeft.y,
- bottomRight.x - topLeft.x,
bottomRight.y - topLeft.y);
+ computedBounds = new Rectangle(topLeft.x, topLeft.y -
fm.getAscent(),
+ bottomRight.x - topLeft.x, bottomRight.y - topLeft.y + fm.getHeight()
+ fm.getDescent());
if (logger.isDebugEnabled()) {
logger.debug("Updating bounds to
"+computedBounds
+" (topleft="+topLeft+";
bottomRight="+bottomRight+")");
@@ -1293,7 +1497,11 @@
*/
private float calculateRelationshipLabelStart(float leftmost, float
rightmost, float StringWidth) {
float x;
- x = leftmost + (rightmost - leftmost - StringWidth)/2;
+ if (rightmost - leftmost - StringWidth >= 0) {
+ x = leftmost + (rightmost - leftmost - StringWidth)/2;
+ } else {
+ x = leftmost;
+ }
return x;
}
}
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 21
15:59:46 2009
@@ -615,4 +615,20 @@
setSelected(intersects(pp.rubberBand),SelectionEvent.SINGLE_SELECT);
}
}
+
+ public void setTextForParentLabel(String textForParentLabel) {
+ model.setTextForParentLabel(textForParentLabel);
+ }
+
+ public String getTextForParentLabel() {
+ return model.getTextForParentLabel();
+ }
+
+ public void setTextForChildLabel(String textForChildLabel) {
+ model.setTextForChildLabel(textForChildLabel);
+ }
+
+ public String getTextForChildLabel() {
+ return model.getTextForChildLabel();
+ }
}
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 21 15:59:46 2009
@@ -68,6 +68,8 @@
private JDialog editDialog;
private JTextField relationshipName;
+ private JTextField pkLabelTextField;
+ private JTextField fkLabelTextField;
private ButtonGroup identifyingGroup;
private JRadioButton identifyingButton;
@@ -118,7 +120,7 @@
relationshipLines =
session.getPlayPen().getSelectedRelationShips();
//Since now can only select one relationship to edit at the same
time,
- //so the length of relationships is only 1.
+ //so the number of selected relationships is only 1.
for(Relationship r: relationshipLines) {
if(logger.isDebugEnabled()) {
logger.debug("This relationship is : " + r); //$NON-NLS-1$
@@ -138,6 +140,9 @@
relationLineColor.setRenderer(renderer);
fb.nextLine();
+ fb.append(Messages.getString("RelationshipEditPanel.pkLabel"),
pkLabelTextField = new JTextField());
+ fb.append(Messages.getString("RelationshipEditPanel.fkLabel"),
fkLabelTextField = new JTextField());
+
identifyingGroup = new ButtonGroup();
fb.append(Messages.getString("RelationshipEditPanel.type"),
identifyingButton = new
JRadioButton(Messages.getString("RelationshipEditPanel.identifying")), 5);
//$NON-NLS-1$ //$NON-NLS-2$
identifyingGroup.add(identifyingButton);
@@ -213,7 +218,7 @@
fb.append("", deleteSetDefault = new
JRadioButton(Messages.getString("RelationshipEditPanel.setDefault")));
//$NON-NLS-1$ //$NON-NLS-2$
deleteRuleGroup.add(deleteSetDefault);
- //TO-FIX,doesn't work!
+ //TODO Doesn't work!
relationshipName.selectAll();
fb.setDefaultDialogBorder();
@@ -224,6 +229,8 @@
public void setRelationship(SQLRelationship r) {
this.relationship = r;
relationshipName.setText(r.getName());
+ pkLabelTextField.setText(r.getTextForParentLabel());
+ fkLabelTextField.setText(r.getTextForChildLabel());
relationLineColor.setSelectedItem(color);
pkTableName.setText(Messages.getString("RelationshipEditPanel.pkTable",
relationship.getPkTable().getName())); //$NON-NLS-1$
fkTableName.setText(Messages.getString("RelationshipEditPanel.fkTable",
relationship.getFkTable().getName())); //$NON-NLS-1$
@@ -304,6 +311,10 @@
relationship.startCompoundEdit(Messages.getString("RelationshipEditPanel.modifyRelationshipProperties"));
//$NON-NLS-1$
try {
relationship.setName(relationshipName.getText());
+ // set the parent label text of relationship lines
+
relationship.setTextForParentLabel(pkLabelTextField.getText());
+ // set the child label text of relationship lines
+
relationship.setTextForChildLabel(fkLabelTextField.getText());
try {
relationship.setIdentifying(identifyingButton.isSelected());
} catch (SQLObjectException ex) {
@@ -311,6 +322,7 @@
}
for(Relationship r: relationshipLines) {
+ // set the color of relationship lines
r.setForegroundColor((Color)relationLineColor.getSelectedItem());
}
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 Apr 21
15:59:46 2009
@@ -332,10 +332,10 @@
getSession().setUsingLogicalNames(true);
}
- String displayRelationshipLabel =
attributes.getValue("relationshipLabelVisibility"); //$NON-NLS-1$
- if (displayRelationshipLabel == null) {
- getSession().setDisplayRelationshipLabel(false);
- } else if (!Boolean.valueOf(displayRelationshipLabel)) {
+ String relationshipLabelVisibility =
attributes.getValue("relationshipLabelVisibility"); //$NON-NLS-1$
+ if (relationshipLabelVisibility == null) {
+ getSession().setDisplayRelationshipLabel(true);
+ } else if (!Boolean.valueOf(relationshipLabelVisibility)) {
getSession().setDisplayRelationshipLabel(false);
} else {
getSession().setDisplayRelationshipLabel(true);
@@ -526,11 +526,19 @@
r.setPkConnectionPoint(new Point(pkx, pky));
r.setFkConnectionPoint(new Point(fkx, fky));
- String rLineColor =
attributes.getValue("relationshipLineColor"); //$NON-NLS-1$
+ String rLineColor = attributes.getValue("rLineColor");
//$NON-NLS-1$
if (rLineColor != null) {
Color relationshipLineColor = Color.decode(rLineColor);
r.setForegroundColor(relationshipLineColor);
}
+ String pkLabelText = attributes.getValue("pkLabelText");
+ if (pkLabelText != null) {
+ r.setTextForParentLabel(pkLabelText);
+ }
+ String fkLabelText = attributes.getValue("fkLabelText");
+ if (fkLabelText != null) {
+ r.setTextForChildLabel(fkLabelText);
+ }
} catch (SQLObjectException e) {
logger.error("Couldn't create relationship component", e);
//$NON-NLS-1$
@@ -1073,7 +1081,9 @@
+" 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$
+ +" rLineColor="+quote(rColorString) //$NON-NLS-1$
+ +" pkLabelText="+quote(r.getTextForParentLabel())
//$NON-NLS-1$
+ +" fkLabelText="+quote(r.getTextForChildLabel())
//$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 Apr 21
15:59:46 2009
@@ -291,9 +291,10 @@
ProjectSettingsPanel.showPK=Show PK Columns only
ProjectSettingsPanel.showPKFKUnique=Show PK + FK + Unique Columns
ProjectSettingsPanel.snapshotSourceDbOption=Snapshot Entire Source
Database in Project File?
-ProjectSettingsPanel.visibilityOfRelationshipLabel=Display or Hide
Relationship Label:
+ProjectSettingsPanel.visibilityOfRelationshipLabel=Display or Hide
Relationship Labels:
Relationship.setFocusMenu=Set Focus to...
Relationship.relationshipLineColor=Relationship Line Color
+RelationshipEditPanel.fkLabel= FK Table Label
RelationshipEditPanel.cardinality=Cardinality
RelationshipEditPanel.cascade=Cascade
RelationshipEditPanel.deferrability=Deferrability
@@ -315,6 +316,7 @@
RelationshipEditPanel.restrict=Restrict
RelationshipEditPanel.setDefault=Set Default
RelationshipEditPanel.setNull=Set Null
+RelationshipEditPanel.pkLabel=PK Table Label
RelationshipEditPanel.updateRule=Update Rule
RelationshipEditPanel.zeroOrMore=Zero or More
RelationshipEditPanel.zeroOrOne=Zero or One