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:
Bjorn Pijnacker 2021-02-23 18:19:01 +01:00
parent 16c5d7b2d0
commit 21ac830896
No known key found for this signature in database
GPG Key ID: 68CC60CD9AC50D72
4 changed files with 21 additions and 16 deletions

View File

@ -114,13 +114,13 @@ public class ExportToImageAction extends AbstractAction {
DiagramPanel.prepareGraphics(g2d);
// Render the model.
boolean lolcat = AttributeViewModel.getLolcatMode(); // save previous lolcat mode
AttributeViewModel.setLolcatMode(false);
boolean lolcat = LolcatAction.getInstance().isLolcatEnabled(); // save previous lolcat mode
LolcatAction.getInstance().setLolcatEnabled(false);
List<Relation> selectedRelations = this.model.getSelectedRelations();
this.model.getSelectedRelations().forEach(r -> r.setSelected(false));
new MappingModelViewModel(this.model).draw(g2d);
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.
g2d.setTransform(originalTransform);

View File

@ -1,6 +1,9 @@
package nl.andrewlalis.erme.control.actions;
import lombok.Getter;
import lombok.Setter;
import nl.andrewlalis.erme.EntityRelationMappingEditor;
import nl.andrewlalis.erme.view.DiagramPanel;
import nl.andrewlalis.erme.view.view_models.AttributeViewModel;
import javax.swing.*;
@ -8,6 +11,11 @@ import java.awt.event.ActionEvent;
public class LolcatAction extends AbstractAction {
private static LolcatAction instance;
@Getter
@Setter
private boolean lolcatEnabled = false;
public static LolcatAction getInstance() {
if (instance == null) {
instance = new LolcatAction();
@ -15,13 +23,16 @@ public class LolcatAction extends AbstractAction {
return instance;
}
@Setter
private DiagramPanel diagramPanel;
public LolcatAction() {
super("Toggle Lolcat Mode");
}
@Override
public void actionPerformed(ActionEvent actionEvent) {
AttributeViewModel.setLolcatMode(((AbstractButton)actionEvent.getSource()).getModel().isSelected());
EntityRelationMappingEditor.getFrame().getContentPane().repaint();
lolcatEnabled = ((AbstractButton)actionEvent.getSource()).getModel().isSelected();
diagramPanel.repaint();
}
}

View File

@ -128,6 +128,7 @@ public class DiagramPanel extends JPanel implements ModelChangeListener {
AddAttributeAction.getInstance().setModel(this.model);
RemoveAttributeAction.getInstance().setModel(this.model);
LoadSampleModelAction.getInstance().setDiagramPanel(this);
LolcatAction.getInstance().setDiagramPanel(this);
}
public static void prepareGraphics(Graphics2D g) {

View File

@ -1,6 +1,7 @@
package nl.andrewlalis.erme.view.view_models;
import nl.andrewlalis.erme.EntityRelationMappingEditor;
import nl.andrewlalis.erme.control.actions.LolcatAction;
import nl.andrewlalis.erme.model.Attribute;
import nl.andrewlalis.erme.model.AttributeType;
import nl.andrewlalis.erme.model.ForeignKeyAttribute;
@ -22,21 +23,12 @@ public class AttributeViewModel implements ViewModel {
public static final float FK_FONT_SIZE = 11.0f;
private static final float LOLCAT_SAT = 0.75f;
private static final float LOLCAT_BRIGHT = 1f;
private static boolean lolcatMode;
private final Attribute attribute;
public AttributeViewModel(Attribute attribute) {
this.attribute = attribute;
}
public static boolean getLolcatMode() {
return lolcatMode;
}
public static void setLolcatMode(boolean lolcatMode) {
AttributeViewModel.lolcatMode = lolcatMode;
}
@Override
public void draw(Graphics2D g) {
AttributedString as = this.getAttributedString(g);
@ -56,8 +48,8 @@ public class AttributeViewModel implements ViewModel {
}
private Color getBackgroundColor(int x, int y, Graphics2D g) {
if (!lolcatMode) return BACKGROUND_COLOR;
Dimension viewportSize = ((DiagramPanel)EntityRelationMappingEditor.getFrame().getContentPane()).getModel().getRelationBounds().getSize();
if (!LolcatAction.getInstance().isLolcatEnabled()) return BACKGROUND_COLOR;
Dimension viewportSize = g.getClipBounds().getSize();
double dx = viewportSize.width;
double dy = viewportSize.height;
@ -67,6 +59,7 @@ public class AttributeViewModel implements ViewModel {
double lambda = (dx * x + dy * y);
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);
}