diff --git a/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar b/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar index e0cb0fba..7397db7d 100644 Binary files a/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar and b/ diy-layout-creator --username bancika@gmail.com/DIYLC/library/main.jar differ diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/BOM.java b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/BOM.java index 69e3eede..4cf54e17 100644 --- a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/BOM.java +++ b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/BOM.java @@ -22,7 +22,7 @@ import org.diylc.plugins.file.BomMaker; import org.diylc.utils.Constants; @ComponentDescriptor(name = "Bill of Materials", author = "Branislav Stojkovic", category = "Misc", description = "", instanceNamePrefix = "BOM", zOrder = IDIYComponent.ABOVE_COMPONENT, stretchable = false) -public class BOM extends AbstractComponent { +public class BOM extends AbstractComponent { public static Size DEFAULT_SIZE = new Size(10d, SizeUnit.cm); public static Size SPACING = Constants.GRID_SIZE; @@ -113,13 +113,16 @@ public class BOM extends AbstractComponent { g2d.drawString("BOM", x, y); g2d.setFont(g2d.getFont().deriveFont(1f * 5 * width / 32)); - + fontMetrics = g2d.getFontMetrics(); rect = fontMetrics.getStringBounds("resistors", g2d); x = (width - textWidth) / 2 + 1; - g2d.drawString("resistors", x, 4 * height / 7); - g2d.drawString("tubes", x, 5 * height / 7); - g2d.drawString("diodes", x, 6 * height / 7); + y = height / 2 + 2; + g2d.drawString("resistors", x, y); + y += rect.getHeight() - 1; + g2d.drawString("tubes", x, y); + y += rect.getHeight() - 1; + g2d.drawString("diodes", x, y); } @Override @@ -138,13 +141,21 @@ public class BOM extends AbstractComponent { } @EditableProperty(name = "Width") - @Override - public Size getValue() { + public Size getSize() { return size; } + public void setSize(Size size) { + this.size = size; + } + + @Deprecated @Override - public void setValue(Size value) { - this.size = value; + public Void getValue() { + return null; + } + + @Override + public void setValue(Void value) { } } diff --git a/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/ProjectInformation.java b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/ProjectInformation.java new file mode 100644 index 00000000..a2dd961b --- /dev/null +++ b/ diy-layout-creator --username bancika@gmail.com/Library/src/org/diylc/components/misc/ProjectInformation.java @@ -0,0 +1,97 @@ +package org.diylc.components.misc; + +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.geom.Rectangle2D; + +import org.diylc.components.AbstractComponent; +import org.diylc.core.ComponentState; +import org.diylc.core.IDIYComponent; +import org.diylc.core.Project; +import org.diylc.core.annotations.ComponentDescriptor; +import org.diylc.core.measures.Size; +import org.diylc.core.measures.SizeUnit; +import org.diylc.utils.Constants; + +@ComponentDescriptor(name = "Project Information", author = "Branislav Stojkovic", category = "Misc", description = "Draws a box with general project information", instanceNamePrefix = "BOM", zOrder = IDIYComponent.ABOVE_COMPONENT, stretchable = false) +public class ProjectInformation extends AbstractComponent { + + public static Size DEFAULT_SIZE = new Size(10d, SizeUnit.cm); + public static Size SPACING = Constants.GRID_SIZE; + public static Color COLOR = Color.black; + public static String DEFAULT_TEXT = "No components to show in the Bill of Materials"; + + private static final long serialVersionUID = 1L; + + private Point point = new Point(0, 0); + + @Override + public void draw(Graphics2D g2d, ComponentState componentState, Project project) { + g2d.setFont(Constants.LABEL_FONT); + g2d.setColor(componentState == ComponentState.DRAGGING + || componentState == ComponentState.SELECTED ? SELECTION_COLOR : COLOR); + // FontMetrics fontMetrics = g2d.getFontMetrics(); + g2d.drawString(project.getTitle(), point.x, point.y); + } + + @Override + public void drawIcon(Graphics2D g2d, int width, int height) { + g2d.setColor(Color.white); + g2d.fillRect(width / 8, 0, 6 * width / 8, height - 1); + g2d.setColor(Color.black); + g2d.drawRect(width / 8, 0, 6 * width / 8, height - 1); + g2d.setFont(Constants.LABEL_FONT.deriveFont(1f * 9 * width / 32).deriveFont(Font.PLAIN)); + + FontMetrics fontMetrics = g2d.getFontMetrics(); + Rectangle2D rect = fontMetrics.getStringBounds("BOM", g2d); + + int textHeight = (int) (rect.getHeight()); + int textWidth = (int) (rect.getWidth()); + + // Center text horizontally and vertically. + int x = (width - textWidth) / 2 + 1; + int y = textHeight + 2; + + g2d.drawString("BOM", x, y); + + g2d.setFont(g2d.getFont().deriveFont(1f * 5 * width / 32)); + + fontMetrics = g2d.getFontMetrics(); + rect = fontMetrics.getStringBounds("resistors", g2d); + x = (width - textWidth) / 2 + 1; + y = height / 2 + 2; + g2d.drawString("resistors", x, y); + y += rect.getHeight() - 1; + g2d.drawString("tubes", x, y); + y += rect.getHeight() - 1; + g2d.drawString("diodes", x, y); + } + + @Override + public int getControlPointCount() { + return 1; + } + + @Override + public Point getControlPoint(int index) { + return point; + } + + @Override + public void setControlPoint(Point point, int index) { + this.point.setLocation(point); + } + + @Deprecated + @Override + public Void getValue() { + return null; + } + + @Override + public void setValue(Void value) { + } +}