Show selection size in both inches and centimeters

This commit is contained in:
bancika
2017-04-20 16:19:22 +02:00
parent f1611bbf0f
commit 5dc090828c
4 changed files with 30 additions and 33 deletions
@@ -255,9 +255,9 @@ public interface IPlugInPort extends ISelectionProcessor, IMouseProcessor, IKeyP
void setLayerLocked(int layerZOrder, boolean locked);
/**
* @return selection size expressed in either inches or centimeters, based on the user preference.
* @return selection size expressed in both inches or centimeters, respectively
*/
Point2D calculateSelectionDimension();
Point2D[] calculateSelectionDimension();
// /**
// * @return the smallest rectangle that encloses the selection
@@ -1707,30 +1707,26 @@ public class Presenter implements IPlugInPort {
}
@Override
public Point2D calculateSelectionDimension() {
public Point2D[] calculateSelectionDimension() {
if (selectedComponents.isEmpty()) {
return null;
}
boolean metric = ConfigurationManager.getInstance().readBoolean(METRIC_KEY, true);
Area area = new Area();
for (IDIYComponent<?> component : selectedComponents) {
Area componentArea = drawingManager.getComponentArea(component);
if (componentArea != null) {
area.add(componentArea);
} else {
LOG.warn("No area found for: " + component.getName());
}
}
double width = area.getBounds2D().getWidth();
double height = area.getBounds2D().getHeight();
Rectangle2D rect = getSelectionBounds();
double width = rect.getWidth();
double height = rect.getHeight();
width /= Constants.PIXELS_PER_INCH;
height /= Constants.PIXELS_PER_INCH;
if (metric) {
width *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
height *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
}
Point2D dimension = new Point2D.Double(width, height);
return dimension;
Point2D inSize = new Point2D.Double(width, height);
width *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
height *= SizeUnit.in.getFactor() / SizeUnit.cm.getFactor();
Point2D cmSize = new Point2D.Double(width, height);
return new Point2D[] {inSize, cmSize};
}
// @Override
@@ -30,7 +30,6 @@ import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import org.diylc.announcements.AnnouncementProvider;
import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.appframework.miscutils.Utils;
import org.diylc.common.BadPositionException;
import org.diylc.common.ComponentType;
@@ -41,7 +40,6 @@ import org.diylc.common.ITask;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IView;
import org.diylc.images.IconLoader;
import org.diylc.presenter.Presenter;
import org.diylc.swing.ISwingUI;
import org.diylc.swingframework.MemoryBar;
import org.diylc.swingframework.miscutils.PercentageListCellRenderer;
@@ -134,7 +132,7 @@ public class StatusBar extends JPanel implements IPlugIn {
private UpdateLabel getUpdateLabel() {
if (updateLabel == null) {
updateLabel = new UpdateLabel(plugInPort.getCurrentVersionNumber(), UPDATE_URL) {
private static final long serialVersionUID = 1L;
@Override
@@ -153,7 +151,7 @@ public class StatusBar extends JPanel implements IPlugIn {
public JLabel getAnnouncementLabel() {
if (announcementLabel == null) {
announcementLabel = new JLabel(IconLoader.Megaphone.getIcon()) {
private static final long serialVersionUID = 1L;
@Override
@@ -200,7 +198,7 @@ public class StatusBar extends JPanel implements IPlugIn {
private MemoryBar getMemoryPanel() {
if (memoryPanel == null) {
memoryPanel = new MemoryBar(false) {
private static final long serialVersionUID = 1L;
@Override
@@ -223,7 +221,7 @@ public class StatusBar extends JPanel implements IPlugIn {
public JLabel getSizeLabel() {
if (sizeLabel == null) {
sizeLabel = new JLabel(IconLoader.Size.getIcon()) {
private static final long serialVersionUID = 1L;
@Override
@@ -237,17 +235,16 @@ public class StatusBar extends JPanel implements IPlugIn {
@Override
public void mouseClicked(MouseEvent e) {
Point2D size = plugInPort.calculateSelectionDimension();
boolean metric = ConfigurationManager.getInstance().readBoolean(Presenter.METRIC_KEY, true);
Point2D[] sizes = plugInPort.calculateSelectionDimension();
String text;
if (size == null) {
if (sizes == null) {
text = "Selection is empty.";
} else {
text =
"Selection size: " + sizeFormat.format(size.getX()) + " x " + sizeFormat.format(size.getY())
+ (metric ? " cm" : " in");
sizeFormat.format(sizes[0].getX()) + " x " + sizeFormat.format(sizes[0].getY()) + " in\n"
+ sizeFormat.format(sizes[1].getX()) + " x " + sizeFormat.format(sizes[1].getY()) + " cm";
}
JOptionPane.showMessageDialog(SwingUtilities.getRootPane(StatusBar.this), text, "Information",
JOptionPane.showMessageDialog(SwingUtilities.getRootPane(StatusBar.this), text, "Selection Size",
JOptionPane.INFORMATION_MESSAGE);
}
});
+4
View File
@@ -1709,6 +1709,10 @@
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Solder Pad size shouldn't be rounded up or down to the nearest integer to allow better precision</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Show selection size in both inches and centimeters</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>