changed the way the lolcat boolean is represented; changed the way LolcatAction accesses DiagramPanel; changed the way AttributeViewModel gets the window bounds
This commit is contained in:
parent
16c5d7b2d0
commit
21ac830896
|
@ -114,13 +114,13 @@ public class ExportToImageAction extends AbstractAction {
|
||||||
DiagramPanel.prepareGraphics(g2d);
|
DiagramPanel.prepareGraphics(g2d);
|
||||||
|
|
||||||
// Render the model.
|
// Render the model.
|
||||||
boolean lolcat = AttributeViewModel.getLolcatMode(); // save previous lolcat mode
|
boolean lolcat = LolcatAction.getInstance().isLolcatEnabled(); // save previous lolcat mode
|
||||||
AttributeViewModel.setLolcatMode(false);
|
LolcatAction.getInstance().setLolcatEnabled(false);
|
||||||
List<Relation> selectedRelations = this.model.getSelectedRelations();
|
List<Relation> selectedRelations = this.model.getSelectedRelations();
|
||||||
this.model.getSelectedRelations().forEach(r -> r.setSelected(false));
|
this.model.getSelectedRelations().forEach(r -> r.setSelected(false));
|
||||||
new MappingModelViewModel(this.model).draw(g2d);
|
new MappingModelViewModel(this.model).draw(g2d);
|
||||||
this.model.getRelations().forEach(r -> r.setSelected(selectedRelations.contains(r)));
|
this.model.getRelations().forEach(r -> r.setSelected(selectedRelations.contains(r)));
|
||||||
AttributeViewModel.setLolcatMode(lolcat); // revert previous lolcat mode
|
LolcatAction.getInstance().setLolcatEnabled(lolcat); // revert previous lolcat mode
|
||||||
|
|
||||||
// Revert back to the normal image space, and render a watermark.
|
// Revert back to the normal image space, and render a watermark.
|
||||||
g2d.setTransform(originalTransform);
|
g2d.setTransform(originalTransform);
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package nl.andrewlalis.erme.control.actions;
|
package nl.andrewlalis.erme.control.actions;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
import nl.andrewlalis.erme.EntityRelationMappingEditor;
|
import nl.andrewlalis.erme.EntityRelationMappingEditor;
|
||||||
|
import nl.andrewlalis.erme.view.DiagramPanel;
|
||||||
import nl.andrewlalis.erme.view.view_models.AttributeViewModel;
|
import nl.andrewlalis.erme.view.view_models.AttributeViewModel;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
@ -8,6 +11,11 @@ import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
public class LolcatAction extends AbstractAction {
|
public class LolcatAction extends AbstractAction {
|
||||||
private static LolcatAction instance;
|
private static LolcatAction instance;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private boolean lolcatEnabled = false;
|
||||||
|
|
||||||
public static LolcatAction getInstance() {
|
public static LolcatAction getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new LolcatAction();
|
instance = new LolcatAction();
|
||||||
|
@ -15,13 +23,16 @@ public class LolcatAction extends AbstractAction {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
private DiagramPanel diagramPanel;
|
||||||
|
|
||||||
public LolcatAction() {
|
public LolcatAction() {
|
||||||
super("Toggle Lolcat Mode");
|
super("Toggle Lolcat Mode");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent actionEvent) {
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
AttributeViewModel.setLolcatMode(((AbstractButton)actionEvent.getSource()).getModel().isSelected());
|
lolcatEnabled = ((AbstractButton)actionEvent.getSource()).getModel().isSelected();
|
||||||
EntityRelationMappingEditor.getFrame().getContentPane().repaint();
|
diagramPanel.repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,7 @@ public class DiagramPanel extends JPanel implements ModelChangeListener {
|
||||||
AddAttributeAction.getInstance().setModel(this.model);
|
AddAttributeAction.getInstance().setModel(this.model);
|
||||||
RemoveAttributeAction.getInstance().setModel(this.model);
|
RemoveAttributeAction.getInstance().setModel(this.model);
|
||||||
LoadSampleModelAction.getInstance().setDiagramPanel(this);
|
LoadSampleModelAction.getInstance().setDiagramPanel(this);
|
||||||
|
LolcatAction.getInstance().setDiagramPanel(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void prepareGraphics(Graphics2D g) {
|
public static void prepareGraphics(Graphics2D g) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package nl.andrewlalis.erme.view.view_models;
|
package nl.andrewlalis.erme.view.view_models;
|
||||||
|
|
||||||
import nl.andrewlalis.erme.EntityRelationMappingEditor;
|
import nl.andrewlalis.erme.EntityRelationMappingEditor;
|
||||||
|
import nl.andrewlalis.erme.control.actions.LolcatAction;
|
||||||
import nl.andrewlalis.erme.model.Attribute;
|
import nl.andrewlalis.erme.model.Attribute;
|
||||||
import nl.andrewlalis.erme.model.AttributeType;
|
import nl.andrewlalis.erme.model.AttributeType;
|
||||||
import nl.andrewlalis.erme.model.ForeignKeyAttribute;
|
import nl.andrewlalis.erme.model.ForeignKeyAttribute;
|
||||||
|
@ -22,21 +23,12 @@ public class AttributeViewModel implements ViewModel {
|
||||||
public static final float FK_FONT_SIZE = 11.0f;
|
public static final float FK_FONT_SIZE = 11.0f;
|
||||||
private static final float LOLCAT_SAT = 0.75f;
|
private static final float LOLCAT_SAT = 0.75f;
|
||||||
private static final float LOLCAT_BRIGHT = 1f;
|
private static final float LOLCAT_BRIGHT = 1f;
|
||||||
private static boolean lolcatMode;
|
|
||||||
private final Attribute attribute;
|
private final Attribute attribute;
|
||||||
|
|
||||||
public AttributeViewModel(Attribute attribute) {
|
public AttributeViewModel(Attribute attribute) {
|
||||||
this.attribute = attribute;
|
this.attribute = attribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getLolcatMode() {
|
|
||||||
return lolcatMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setLolcatMode(boolean lolcatMode) {
|
|
||||||
AttributeViewModel.lolcatMode = lolcatMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g) {
|
public void draw(Graphics2D g) {
|
||||||
AttributedString as = this.getAttributedString(g);
|
AttributedString as = this.getAttributedString(g);
|
||||||
|
@ -56,8 +48,8 @@ public class AttributeViewModel implements ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color getBackgroundColor(int x, int y, Graphics2D g) {
|
private Color getBackgroundColor(int x, int y, Graphics2D g) {
|
||||||
if (!lolcatMode) return BACKGROUND_COLOR;
|
if (!LolcatAction.getInstance().isLolcatEnabled()) return BACKGROUND_COLOR;
|
||||||
Dimension viewportSize = ((DiagramPanel)EntityRelationMappingEditor.getFrame().getContentPane()).getModel().getRelationBounds().getSize();
|
Dimension viewportSize = g.getClipBounds().getSize();
|
||||||
|
|
||||||
double dx = viewportSize.width;
|
double dx = viewportSize.width;
|
||||||
double dy = viewportSize.height;
|
double dy = viewportSize.height;
|
||||||
|
@ -67,6 +59,7 @@ public class AttributeViewModel implements ViewModel {
|
||||||
|
|
||||||
double lambda = (dx * x + dy * y);
|
double lambda = (dx * x + dy * y);
|
||||||
double diag_val = Math.sqrt(Math.pow(dx * lambda, 2) + Math.pow(dy * lambda, 2)) / mag;
|
double diag_val = Math.sqrt(Math.pow(dx * lambda, 2) + Math.pow(dy * lambda, 2)) / mag;
|
||||||
|
System.out.println(diag_val);
|
||||||
|
|
||||||
return Color.getHSBColor((float) diag_val, LOLCAT_SAT, LOLCAT_BRIGHT);
|
return Color.getHSBColor((float) diag_val, LOLCAT_SAT, LOLCAT_BRIGHT);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue