changed spaces to tabs

I have honestly no idea why it wasn't autodetecting the use of tabs
This commit is contained in:
Bjorn Pijnacker 2021-02-23 16:19:05 +01:00
parent c8b114195d
commit 16c5d7b2d0
No known key found for this signature in database
GPG Key ID: 68CC60CD9AC50D72
3 changed files with 121 additions and 121 deletions

View File

@ -7,30 +7,30 @@ import nl.andrewlalis.erme.view.EditorFrame;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
public class EntityRelationMappingEditor { public class EntityRelationMappingEditor {
public static final String VERSION = "1.3.1"; public static final String VERSION = "1.3.1";
private static EditorFrame frame; private static EditorFrame frame;
public static EditorFrame getFrame() { public static EditorFrame getFrame() {
return frame; return frame;
} }
public static void main(String[] args) { public static void main(String[] args) {
if (!FlatLightLaf.install()) { if (!FlatLightLaf.install()) {
System.err.println("Could not install FlatLight Look and Feel."); System.err.println("Could not install FlatLight Look and Feel.");
} }
final boolean includeAdminActions = shouldIncludeAdminActions(args); final boolean includeAdminActions = shouldIncludeAdminActions(args);
if (includeAdminActions) { if (includeAdminActions) {
System.out.println("Admin actions have been enabled."); System.out.println("Admin actions have been enabled.");
} }
frame = new EditorFrame(includeAdminActions); frame = new EditorFrame(includeAdminActions);
frame.setVisible(true); frame.setVisible(true);
} }
private static boolean shouldIncludeAdminActions(String[] args) { private static boolean shouldIncludeAdminActions(String[] args) {
if (args.length < 1) { if (args.length < 1) {
return false; return false;
} }
byte[] pw = args[0].getBytes(StandardCharsets.UTF_8); byte[] pw = args[0].getBytes(StandardCharsets.UTF_8);
return Hash.matches(pw, "admin_hash.txt"); return Hash.matches(pw, "admin_hash.txt");
} }
} }

View File

@ -7,21 +7,21 @@ import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
public class LolcatAction extends AbstractAction { public class LolcatAction extends AbstractAction {
private static LolcatAction instance; private static LolcatAction instance;
public static LolcatAction getInstance() { public static LolcatAction getInstance() {
if (instance == null) { if (instance == null) {
instance = new LolcatAction(); instance = new LolcatAction();
} }
return instance; return instance;
} }
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()); AttributeViewModel.setLolcatMode(((AbstractButton)actionEvent.getSource()).getModel().isSelected());
EntityRelationMappingEditor.getFrame().getContentPane().repaint(); EntityRelationMappingEditor.getFrame().getContentPane().repaint();
} }
} }

View File

@ -15,98 +15,98 @@ import java.text.AttributedString;
* View model for rendering a single attribute of a relation. * View model for rendering a single attribute of a relation.
*/ */
public class AttributeViewModel implements ViewModel { public class AttributeViewModel implements ViewModel {
public static final int PADDING_X = 5; public static final int PADDING_X = 5;
public static final int PADDING_Y = 5; public static final int PADDING_Y = 5;
public static final Color BACKGROUND_COLOR = Color.LIGHT_GRAY; public static final Color BACKGROUND_COLOR = Color.LIGHT_GRAY;
public static final Color FONT_COLOR = Color.BLACK; public static final Color FONT_COLOR = Color.BLACK;
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 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() { public static boolean getLolcatMode() {
return lolcatMode; return lolcatMode;
} }
public static void setLolcatMode(boolean lolcatMode) { public static void setLolcatMode(boolean lolcatMode) {
AttributeViewModel.lolcatMode = 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);
Rectangle r = this.getBounds(g, as); Rectangle r = this.getBounds(g, as);
g.setColor(this.getBackgroundColor(r.x + r.width / 2, r.y + r.height / 2, g)); g.setColor(this.getBackgroundColor(r.x + r.width / 2, r.y + r.height / 2, g));
g.fillRect(r.x, r.y, r.width, r.height); g.fillRect(r.x, r.y, r.width, r.height);
g.setColor(FONT_COLOR); g.setColor(FONT_COLOR);
g.drawRect(r.x, r.y, r.width, r.height); g.drawRect(r.x, r.y, r.width, r.height);
g.drawString(as.getIterator(), r.x + PADDING_X, r.y + (r.height - PADDING_Y)); g.drawString(as.getIterator(), r.x + PADDING_X, r.y + (r.height - PADDING_Y));
if (this.attribute instanceof ForeignKeyAttribute) { if (this.attribute instanceof ForeignKeyAttribute) {
ForeignKeyAttribute fkAttribute = (ForeignKeyAttribute) this.attribute; ForeignKeyAttribute fkAttribute = (ForeignKeyAttribute) this.attribute;
Font originalFont = g.getFont(); Font originalFont = g.getFont();
g.setFont(g.getFont().deriveFont(Font.ITALIC, FK_FONT_SIZE)); g.setFont(g.getFont().deriveFont(Font.ITALIC, FK_FONT_SIZE));
g.drawString(fkAttribute.getFullReferenceName(), r.x + PADDING_X, r.y - PADDING_Y); g.drawString(fkAttribute.getFullReferenceName(), r.x + PADDING_X, r.y - PADDING_Y);
g.setFont(originalFont); g.setFont(originalFont);
} }
} }
private Color getBackgroundColor(int x, int y, Graphics2D g) { private Color getBackgroundColor(int x, int y, Graphics2D g) {
if (!lolcatMode) return BACKGROUND_COLOR; if (!lolcatMode) return BACKGROUND_COLOR;
Dimension viewportSize = ((DiagramPanel)EntityRelationMappingEditor.getFrame().getContentPane()).getModel().getRelationBounds().getSize(); Dimension viewportSize = ((DiagramPanel)EntityRelationMappingEditor.getFrame().getContentPane()).getModel().getRelationBounds().getSize();
double dx = viewportSize.width; double dx = viewportSize.width;
double dy = viewportSize.height; double dy = viewportSize.height;
double mag = Math.sqrt(dx * dx + dy * dy); double mag = Math.sqrt(dx * dx + dy * dy);
dx /= mag; dx /= mag;
dy /= mag; dy /= mag;
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;
return Color.getHSBColor((float) diag_val, LOLCAT_SAT, LOLCAT_BRIGHT); return Color.getHSBColor((float) diag_val, LOLCAT_SAT, LOLCAT_BRIGHT);
} }
@Override @Override
public Rectangle getBounds(Graphics2D g) { public Rectangle getBounds(Graphics2D g) {
return this.getBounds(g, this.getAttributedString(g)); return this.getBounds(g, this.getAttributedString(g));
} }
private Rectangle getBounds(Graphics2D g, AttributedString as) { private Rectangle getBounds(Graphics2D g, AttributedString as) {
final RelationViewModel relationViewModel = (RelationViewModel) this.attribute.getRelation().getViewModel(); final RelationViewModel relationViewModel = (RelationViewModel) this.attribute.getRelation().getViewModel();
int x = this.attribute.getRelation().getPosition().x + RelationViewModel.PADDING_X; int x = this.attribute.getRelation().getPosition().x + RelationViewModel.PADDING_X;
int y = this.attribute.getRelation().getPosition().y + relationViewModel.getNameBounds(g).height + RelationViewModel.ATTRIBUTE_SEPARATION; int y = this.attribute.getRelation().getPosition().y + relationViewModel.getNameBounds(g).height + RelationViewModel.ATTRIBUTE_SEPARATION;
int i = 0; int i = 0;
while (!this.attribute.getRelation().getAttributes().get(i).equals(this.attribute)) { while (!this.attribute.getRelation().getAttributes().get(i).equals(this.attribute)) {
x += this.attribute.getRelation().getAttributes().get(i).getViewModel().getBounds(g).width; x += this.attribute.getRelation().getAttributes().get(i).getViewModel().getBounds(g).width;
i++; i++;
} }
Rectangle2D nameRect = g.getFontMetrics().getStringBounds(as.getIterator(), 0, this.attribute.getName().length(), g); Rectangle2D nameRect = g.getFontMetrics().getStringBounds(as.getIterator(), 0, this.attribute.getName().length(), g);
int width = (int) nameRect.getWidth() + (2 * PADDING_X); int width = (int) nameRect.getWidth() + (2 * PADDING_X);
int height = (int) nameRect.getHeight() + (2 * PADDING_Y); int height = (int) nameRect.getHeight() + (2 * PADDING_Y);
if (this.attribute instanceof ForeignKeyAttribute) { if (this.attribute instanceof ForeignKeyAttribute) {
ForeignKeyAttribute fkAttribute = (ForeignKeyAttribute) this.attribute; ForeignKeyAttribute fkAttribute = (ForeignKeyAttribute) this.attribute;
Font originalFont = g.getFont(); Font originalFont = g.getFont();
g.setFont(g.getFont().deriveFont(Font.ITALIC, FK_FONT_SIZE)); g.setFont(g.getFont().deriveFont(Font.ITALIC, FK_FONT_SIZE));
Rectangle referenceNameBounds = g.getFontMetrics().getStringBounds(fkAttribute.getFullReferenceName(), g).getBounds(); Rectangle referenceNameBounds = g.getFontMetrics().getStringBounds(fkAttribute.getFullReferenceName(), g).getBounds();
g.setFont(originalFont); g.setFont(originalFont);
width = Math.max(width, referenceNameBounds.width + (2 * PADDING_X)); width = Math.max(width, referenceNameBounds.width + (2 * PADDING_X));
} }
return new Rectangle(x, y, width, height); return new Rectangle(x, y, width, height);
} }
private AttributedString getAttributedString(Graphics2D g) { private AttributedString getAttributedString(Graphics2D g) {
AttributedString as = new AttributedString(this.attribute.getName()); AttributedString as = new AttributedString(this.attribute.getName());
as.addAttribute(TextAttribute.FONT, g.getFont()); as.addAttribute(TextAttribute.FONT, g.getFont());
if (this.attribute.getType().equals(AttributeType.ID_KEY)) { if (this.attribute.getType().equals(AttributeType.ID_KEY)) {
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
} else if (this.attribute.getType().equals(AttributeType.PARTIAL_ID_KEY)) { } else if (this.attribute.getType().equals(AttributeType.PARTIAL_ID_KEY)) {
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED); as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED);
} }
return as; return as;
} }
} }