3.29.0 release

[Bug Fix] Issue with losing saved user configuration
[Bug Fix] Issue with disabled "Save as Template" context menu item
problem, as well as issue with strange rotation and probably few more
[Bug Fix] Undo steps kept after opening a new file
[New Feature] Transistors can be rotated and flipped vertically
[New Feature] DIL ICs can show pin numbers
[New Feature] Display both component value and name or neither of them
[New Feature] Potentiometer schematic symbol added
This commit is contained in:
bancika
2016-04-20 11:46:00 +02:00
parent fbc3c4bfc4
commit 3e18c5e1db
29 changed files with 335 additions and 115 deletions
@@ -2,12 +2,12 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/log4j-1.2.15.jar"/>
<classpathentry kind="lib" path="lib/junit-4.7.jar"/>
<classpathentry kind="lib" path="library/main.jar"/>
<classpathentry kind="lib" path="lib/app-framework.jar"/>
<classpathentry kind="lib" path="lib/jettison-1.0.1.jar"/>
<classpathentry kind="lib" path="lib/xstream-1.3.1.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_40"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -2,7 +2,7 @@ package org.diylc.common;
public enum Display {
NAME, VALUE;
NAME, VALUE, NONE, BOTH;
@Override
public String toString() {
@@ -33,8 +33,7 @@ import org.diylc.utils.Constants;
*
* @author Branislav Stojkovic
*/
public abstract class AbstractLeadedComponent<T> extends
AbstractTransparentComponent<T> {
public abstract class AbstractLeadedComponent<T> extends AbstractTransparentComponent<T> {
private static final long serialVersionUID = 1L;
@@ -45,8 +44,7 @@ public abstract class AbstractLeadedComponent<T> extends
protected Size length;
protected Size width;
protected Point[] points = new Point[] {
new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0),
protected Point[] points = new Point[] { new Point((int) (-DEFAULT_SIZE.convertToPixels() / 2), 0),
new Point((int) (DEFAULT_SIZE.convertToPixels() / 2), 0) };
protected Color bodyColor = Color.white;
protected Color borderColor = Color.black;
@@ -68,44 +66,35 @@ public abstract class AbstractLeadedComponent<T> extends
}
@Override
public void draw(Graphics2D g2d, ComponentState componentState,
boolean outlineMode, Project project,
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
IDrawingObserver drawingObserver) {
double distance = points[0].distance(points[1]);
Shape shape = getBodyShape();
// If there's no body, just draw the line connecting the ending points.
if (shape == null) {
drawLead(g2d, componentState);
} else if (supportsStandingMode()
&& length.convertToPixels() > points[0].distance(points[1])) {
} else if (supportsStandingMode() && length.convertToPixels() > points[0].distance(points[1])) {
// When ending points are too close draw the component in standing
// mode.
int width = getClosestOdd(this.width.convertToPixels());
Shape body = new Ellipse2D.Double((getFlipStanding() ? points[1]
: points[0]).x
- width / 2, (getFlipStanding() ? points[1] : points[0]).y
- width / 2, width, width);
Shape body = new Ellipse2D.Double((getFlipStanding() ? points[1] : points[0]).x - width / 2,
(getFlipStanding() ? points[1] : points[0]).y - width / 2, width, width);
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR
: getStandingBodyColor());
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : getStandingBodyColor());
g2d.fill(body);
g2d.setComposite(oldComposite);
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance()
.readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor();
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
}
g2d.setColor(finalBorderColor);
@@ -116,8 +105,7 @@ public abstract class AbstractLeadedComponent<T> extends
} else {
// Normal mode with component body in the center and two lead parts.
Rectangle shapeRect = shape.getBounds();
Double theta = Math.atan2(points[1].y - points[0].y, points[1].x
- points[0].x);
Double theta = Math.atan2(points[1].y - points[0].y, points[1].x - points[0].x);
// Go back to the original transformation to draw leads.
if (!outlineMode) {
AffineTransform textTransform = g2d.getTransform();
@@ -127,36 +115,25 @@ public abstract class AbstractLeadedComponent<T> extends
// 0.5f));
// }
int leadThickness = getClosestOdd(getLeadThickness());
double leadLength = (distance - calculatePinSpacing(shapeRect))
/ 2 - leadThickness / 2;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness));
Color leadColor = shouldShadeLeads() ? getLeadColorForPainting(
componentState).darker()
double leadLength = (distance - calculatePinSpacing(shapeRect)) / 2 - leadThickness / 2;
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness));
Color leadColor = shouldShadeLeads() ? getLeadColorForPainting(componentState).darker()
: getLeadColorForPainting(componentState);
g2d.setColor(leadColor);
int endX = (int) (points[0].x + Math.cos(theta) * leadLength);
int endY = (int) Math.round(points[0].y + Math.sin(theta)
* leadLength);
int endY = (int) Math.round(points[0].y + Math.sin(theta) * leadLength);
g2d.drawLine(points[0].x, points[0].y, endX, endY);
endX = (int) (points[1].x + Math.cos(theta - Math.PI)
* leadLength);
endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI)
* leadLength);
endX = (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength);
endY = (int) Math.round(points[1].y + Math.sin(theta - Math.PI) * leadLength);
g2d.drawLine(points[1].x, points[1].y, endX, endY);
if (shouldShadeLeads()) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
leadThickness - 2));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(leadThickness - 2));
leadColor = getLeadColorForPainting(componentState);
g2d.setColor(leadColor);
g2d.drawLine(points[0].x, points[0].y,
(int) (points[0].x + Math.cos(theta) * leadLength),
g2d.drawLine(points[0].x, points[0].y, (int) (points[0].x + Math.cos(theta) * leadLength),
(int) (points[0].y + Math.sin(theta) * leadLength));
g2d.drawLine(points[1].x, points[1].y,
(int) (points[1].x + Math.cos(theta - Math.PI)
* leadLength), (int) (points[1].y + Math
.sin(theta - Math.PI)
* leadLength));
g2d.drawLine(points[1].x, points[1].y, (int) (points[1].x + Math.cos(theta - Math.PI) * leadLength),
(int) (points[1].y + Math.sin(theta - Math.PI) * leadLength));
}
g2d.setTransform(textTransform);
}
@@ -173,19 +150,16 @@ public abstract class AbstractLeadedComponent<T> extends
length = getLength().convertToPixels();
}
oldTransform = g2d.getTransform();
g2d.translate((points[0].x + points[1].x - length) / 2,
(points[0].y + points[1].y - width) / 2);
g2d.translate((points[0].x + points[1].x - length) / 2, (points[0].y + points[1].y - width) / 2);
g2d.rotate(theta, length / 2, width / 2);
// Draw body.
Composite oldComposite = g2d.getComposite();
if (alpha < MAX_ALPHA) {
g2d.setComposite(AlphaComposite.getInstance(
AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
}
if (bodyColor != null) {
if (bodyColor != null) {
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR
: bodyColor);
g2d.setColor(outlineMode ? Constants.TRANSPARENT_COLOR : bodyColor);
g2d.fill(shape);
}
}
@@ -194,16 +168,13 @@ public abstract class AbstractLeadedComponent<T> extends
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
Color finalBorderColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance()
.readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: theme.getOutlineColor();
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : theme.getOutlineColor();
} else {
finalBorderColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: borderColor;
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR : borderColor;
}
g2d.setColor(finalBorderColor);
g2d.draw(shape);
@@ -259,49 +230,46 @@ public abstract class AbstractLeadedComponent<T> extends
}
Color finalLabelColor;
if (outlineMode) {
Theme theme = (Theme) ConfigurationManager.getInstance()
.readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: theme.getOutlineColor();
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY,
Constants.DEFAULT_THEME);
finalLabelColor = componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? LABEL_COLOR_SELECTED : theme.getOutlineColor();
} else {
finalLabelColor = componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: labelColor;
finalLabelColor = componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING
? LABEL_COLOR_SELECTED : labelColor;
}
g2d.setColor(finalLabelColor);
FontMetrics fontMetrics = g2d.getFontMetrics();
String label = display == Display.NAME ? getName()
: (getValue() == null ? "" : getValue().toString());
String label = "";
label = display == Display.NAME ? getName() : (getValue() == null ? "" : getValue().toString());
if (display == Display.NONE) {
label = "";
}
if (display == Display.BOTH) {
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
}
Rectangle2D textRect = fontMetrics.getStringBounds(label, g2d);
// Don't offset in outline mode.
int offset = outlineMode ? 0 : getLabelOffset((int) length,
(int) width);
int offset = outlineMode ? 0 : getLabelOffset((int) length, (int) width);
// Adjust label angle if needed to make sure that it's readable.
if ((theta >= Math.PI / 2 && theta <= Math.PI)
|| (theta < -Math.PI / 2 && theta > -Math.PI)) {
if ((theta >= Math.PI / 2 && theta <= Math.PI) || (theta < -Math.PI / 2 && theta > -Math.PI)) {
g2d.rotate(Math.PI, length / 2, width / 2);
offset = -offset;
}
g2d.drawString(label, (int) (length - textRect.getWidth()) / 2
+ offset, calculateLabelYCoordinate(shapeRect, textRect,
fontMetrics));
g2d.drawString(label, (int) (length - textRect.getWidth()) / 2 + offset,
calculateLabelYCoordinate(shapeRect, textRect, fontMetrics));
g2d.setTransform(oldTransform);
}
}
private void drawLead(Graphics2D g2d, ComponentState componentState) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
getLeadThickness()));
Color leadColor = shouldShadeLeads() ? getLeadColorForPainting(
componentState).darker()
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness()));
Color leadColor = shouldShadeLeads() ? getLeadColorForPainting(componentState).darker()
: getLeadColorForPainting(componentState);
g2d.setColor(leadColor);
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
if (shouldShadeLeads()) {
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(
getLeadThickness() - 2));
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(getLeadThickness() - 2));
leadColor = getLeadColorForPainting(componentState);
g2d.setColor(leadColor);
g2d.drawLine(points[0].x, points[0].y, points[1].x, points[1].y);
@@ -312,10 +280,8 @@ public abstract class AbstractLeadedComponent<T> extends
// Do nothing.
}
protected int calculateLabelYCoordinate(Rectangle2D shapeRect,
Rectangle2D textRect, FontMetrics fontMetrics) {
return (int) (shapeRect.getHeight() - textRect.getHeight()) / 2
+ fontMetrics.getAscent();
protected int calculateLabelYCoordinate(Rectangle2D shapeRect, Rectangle2D textRect, FontMetrics fontMetrics) {
return (int) (shapeRect.getHeight() - textRect.getHeight()) / 2 + fontMetrics.getAscent();
}
protected boolean shouldShadeLeads() {
@@ -352,8 +318,7 @@ public abstract class AbstractLeadedComponent<T> extends
* Controls how component shape should be placed relative to start and end
* point.
*
* @return
* <code>true<code> if shape rect should be used to center the component or <code>false</code>
* @return <code>true<code> if shape rect should be used to center the component or <code>false</code>
* to place the component relative to <code>length</code> and
* <code>width</code> values.
*/
@@ -372,8 +337,7 @@ public abstract class AbstractLeadedComponent<T> extends
* @return default lead color. Override this method to change it.
*/
protected Color getLeadColorForPainting(ComponentState componentState) {
return componentState == ComponentState.SELECTED
|| componentState == ComponentState.DRAGGING ? SELECTION_COLOR
return componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
: getLeadColor();
}
@@ -591,7 +591,7 @@ public class Presenter implements IPlugInPort {
}
} else {
// Otherwise just select that one component.
if (button == BUTTON1
if (button == BUTTON1 || (button == BUTTON3 && newSelection.size() == 1)
|| !newSelection.contains(topComponent)) {
newSelection.clear();
}