diff --git a/src/Localizable_de.properties b/src/Localizable_de.properties index 37321e0..8c2a77f 100644 --- a/src/Localizable_de.properties +++ b/src/Localizable_de.properties @@ -97,6 +97,7 @@ relationship_role=Rolle: relationship_first_entity=Erste Entit\u00e4t relationship_second_entity=Zweite Entit\u00e4t relationship_cardinality=Kardinalit\u00e4t +relationship_totality=Totalit\u00e4t relationship_weak=Schwache Relationship description_box_title=Titel diff --git a/src/Localizable_en.properties b/src/Localizable_en.properties index 4f88113..cf95f55 100644 --- a/src/Localizable_en.properties +++ b/src/Localizable_en.properties @@ -97,6 +97,7 @@ relationship_role=Role: relationship_first_entity=First Entity relationship_second_entity=Second Entity relationship_cardinality=Cardinality +relationship_totality=totality relationship_weak=Weak Relationship description_box_title=Title diff --git a/src/Relationship.java b/src/Relationship.java index 52f3989..3d7f07b 100644 --- a/src/Relationship.java +++ b/src/Relationship.java @@ -24,6 +24,7 @@ * THE SOFTWARE. */ +import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; @@ -41,6 +42,8 @@ public class Relationship extends ERObject private Entity e2; private boolean e1toMany; private boolean e2toMany; + private boolean e1total; + private boolean e2total; public Relationship() { @@ -60,6 +63,11 @@ public boolean getFirstEntityToMany() { return e1toMany; } + + public boolean getFirstEntityTotal() + { + return e1total; + } public Entity getSecondEntity() { @@ -70,6 +78,11 @@ public boolean getSecondEntityToMany() { return e2toMany; } + + public boolean getSecondEntityTotal() + { + return e2total; + } @Override public void paint(Graphics2D g) @@ -235,21 +248,31 @@ else if (e1.bounds.getCenterX() < bounds.x + bounds.width + 50) } } + String cardinality1; + String cardinality2; + cardinality1 = (e1toMany) ? "n" : "1"; + if (e1toMany) cardinality2 = (e2toMany) ? "m" : "1"; + else cardinality2 = (e2toMany) ? "n" : "1"; + int cardinality1Offset = g.getFontMetrics().stringWidth(cardinality1) / 2; + int cardinality2Offset = g.getFontMetrics().stringWidth(cardinality2) / 2; if (e1.bounds.getCenterX() < e2.bounds.getCenterX()) { - g.drawString((e1toMany) ? "n" : "1", bounds.x - 5, bounds.y + 30); - if (e1toMany) - g.drawString((e2toMany) ? "m" : "1", bounds.x + bounds.width + 5, bounds.y + 30); - else - g.drawString((e2toMany) ? "n" : "1", bounds.x + bounds.width + 5, bounds.y + 30); + g.drawString(cardinality1, bounds.x - 4 - cardinality1Offset, bounds.y + 30); + g.drawString(cardinality2, bounds.x + bounds.width + 4 - cardinality2Offset, bounds.y + 30); } else { - g.drawString((e1toMany) ? "n" : "1", bounds.x + bounds.width + 5, bounds.y + 30); - if (e1toMany) - g.drawString((e2toMany) ? "m" : "1", bounds.x - 5, bounds.y + 30); - else - g.drawString((e2toMany) ? "n" : "1", bounds.x - 5, bounds.y + 30); + g.drawString(cardinality1, bounds.x + bounds.width + 4 - cardinality1Offset, bounds.y + 30); + g.drawString(cardinality2, bounds.x - 4 - cardinality2Offset, bounds.y + 30); + } + + if (e1total) + { + g.fillOval(bounds.x - 9, bounds.y + bounds.height/2 - 5, 10, 10); + } + if (e2total) + { + g.fillOval(bounds.x + bounds.width - 1, bounds.y + bounds.height/2 - 5, 10, 10); } Polygon p = new Polygon(); @@ -296,7 +319,15 @@ public void setFirstEntityToMany(boolean toMany) { e1toMany = toMany; } - + + public void setFirstEntityTotal(boolean e1total) { + this.e1total = e1total; + } + + public void setSecondEntityTotal(boolean e2total) { + this.e2total = e2total; + } + public void setSecondEntity(Entity e2) { this.e2 = e2; diff --git a/src/RelationshipEditorPanel.java b/src/RelationshipEditorPanel.java index 3849e49..5771793 100644 --- a/src/RelationshipEditorPanel.java +++ b/src/RelationshipEditorPanel.java @@ -56,6 +56,8 @@ public class RelationshipEditorPanel extends JPanel implements ActionListener, K private final JRadioButton rbnCardinality2toOne; private final JRadioButton rbnCardinality2toMany; private final ButtonGroup bgpCardinality2; + private final JCheckBox cbxTotality1; + private final JCheckBox cbxTotality2; private final JCheckBox cbxIsWeakRelationship; private ERModelQuery query; private RepaintRequest request; @@ -66,12 +68,12 @@ public RelationshipEditorPanel() setLayout(null); lblRelationshipName = new JLabel(); - lblRelationshipName.setBounds(5, 74, 100, 27); + lblRelationshipName.setBounds(5, 111, 100, 27); lblRelationshipName.setText(ER_Editor.LOCALIZATION.getString("relationship_role")); add(lblRelationshipName); txtRelationshipName = new JTextField(); - txtRelationshipName.setBounds(110, 74, 180, 27); + txtRelationshipName.setBounds(110, 111, 180, 27); txtRelationshipName.addKeyListener(this); add(txtRelationshipName); @@ -101,34 +103,40 @@ public RelationshipEditorPanel() rbnCardinality1toMany.setText("N"); rbnCardinality1toMany.addActionListener(this); add(rbnCardinality1toMany); + + cbxTotality1 = new JCheckBox(); + cbxTotality1.setBounds(5, 74, 280, 27); + cbxTotality1.setText(ER_Editor.LOCALIZATION.getString("relationship_totality")); + cbxTotality1.addActionListener(this); + add(cbxTotality1); bgpCardinality1 = new ButtonGroup(); bgpCardinality1.add(rbnCardinality1toMany); bgpCardinality1.add(rbnCardinality1toOne); lblRelationshipEntity2 = new JLabel(); - lblRelationshipEntity2.setBounds(5, 111, 100, 27); + lblRelationshipEntity2.setBounds(5, 148, 100, 27); lblRelationshipEntity2.setText(ER_Editor.LOCALIZATION.getString("relationship_second_entity")); add(lblRelationshipEntity2); cbxRelationshipEntity2 = new JComboBox(); - cbxRelationshipEntity2.setBounds(110, 111, 180, 27); + cbxRelationshipEntity2.setBounds(110, 148, 180, 27); cbxRelationshipEntity2.addActionListener(this); add(cbxRelationshipEntity2); lblCardinality2 = new JLabel(); - lblCardinality2.setBounds(5, 148, 100, 27); + lblCardinality2.setBounds(5, 185, 100, 27); lblCardinality2.setText(ER_Editor.LOCALIZATION.getString("relationship_cardinality")); add(lblCardinality2); rbnCardinality2toOne = new JRadioButton(); - rbnCardinality2toOne.setBounds(110, 148, 80, 27); + rbnCardinality2toOne.setBounds(110, 185, 80, 27); rbnCardinality2toOne.setText("1"); rbnCardinality2toOne.addActionListener(this); add(rbnCardinality2toOne); rbnCardinality2toMany = new JRadioButton(); - rbnCardinality2toMany.setBounds(200, 148, 80, 27); + rbnCardinality2toMany.setBounds(200, 185, 80, 27); rbnCardinality2toMany.setText("N"); rbnCardinality2toMany.addActionListener(this); add(rbnCardinality2toMany); @@ -136,9 +144,15 @@ public RelationshipEditorPanel() bgpCardinality2 = new ButtonGroup(); bgpCardinality2.add(rbnCardinality2toMany); bgpCardinality2.add(rbnCardinality2toOne); + + cbxTotality2 = new JCheckBox(); + cbxTotality2.setBounds(5, 217, 280, 27); + cbxTotality2.setText(ER_Editor.LOCALIZATION.getString("relationship_totality")); + cbxTotality2.addActionListener(this); + add(cbxTotality2); cbxIsWeakRelationship = new JCheckBox(); - cbxIsWeakRelationship.setBounds(5, 185, 280, 27); + cbxIsWeakRelationship.setBounds(5, 254, 280, 27); cbxIsWeakRelationship.setText(ER_Editor.LOCALIZATION.getString("relationship_weak")); cbxIsWeakRelationship.addActionListener(this); add(cbxIsWeakRelationship); @@ -186,6 +200,20 @@ else if (e.getSource() == rbnCardinality2toOne || e.getSource() == rbnCardinalit history.pushEvent(changeEvent); relationship.setSecondEntityToMany(rbnCardinality2toMany.isSelected()); } + else if (e.getSource() == cbxTotality1) + { + RelationshipChangeEvent changeEvent = new RelationshipChangeEvent(relationship, RelationshipChangeEvent.CHANGE_WEAK, + !cbxTotality1.isSelected(), cbxTotality1.isSelected()); + history.pushEvent(changeEvent); + relationship.setFirstEntityTotal(cbxTotality1.isSelected()); + } + else if (e.getSource() == cbxTotality2) + { + RelationshipChangeEvent changeEvent = new RelationshipChangeEvent(relationship, RelationshipChangeEvent.CHANGE_WEAK, + !cbxTotality2.isSelected(), cbxTotality2.isSelected()); + history.pushEvent(changeEvent); + relationship.setSecondEntityTotal(cbxTotality2.isSelected()); + } else if (e.getSource() == cbxIsWeakRelationship) { RelationshipChangeEvent changeEvent = new RelationshipChangeEvent(relationship, RelationshipChangeEvent.CHANGE_WEAK,