Two new trimmer potentiometer types

This commit is contained in:
Branislav Stojkovic
2018-12-15 19:19:05 +01:00
parent 3939d2c5a7
commit 1b7f24bae4
3 changed files with 515 additions and 467 deletions
@@ -1,474 +1,518 @@
/* /*
*
* DIY Layout Creator (DIYLC). Copyright (c) 2009-2018 held jointly by the individual authors.
*
* This file is part of DIYLC.
*
* DIYLC is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* DIYLC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with DIYLC. If not, see
* <http://www.gnu.org/licenses/>.
*/
package org.diylc.components.passive;
DIY Layout Creator (DIYLC). import java.awt.AlphaComposite;
Copyright (c) 2009-2018 held jointly by the individual authors. import java.awt.Color;
import java.awt.Composite;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.RoundRectangle2D;
This file is part of DIYLC. import org.diylc.appframework.miscutils.ConfigurationManager;
import org.diylc.common.Display;
import org.diylc.common.IPlugInPort;
import org.diylc.common.ObjectCache;
import org.diylc.common.Orientation;
import org.diylc.core.ComponentState;
import org.diylc.core.CreationMethod;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
import org.diylc.core.Project;
import org.diylc.core.Theme;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
import org.diylc.core.measures.SizeUnit;
import org.diylc.utils.Constants;
DIYLC is free software: you can redistribute it and/or modify @ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive",
it under the terms of the GNU General Public License as published by creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR",
the Free Software Foundation, either version 3 of the License, or description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT,
(at your option) any later version. stretchable = false)
public class TrimmerPotentiometer extends AbstractPotentiometer {
DIYLC is distributed in the hope that it will be useful, private static final long serialVersionUID = 1L;
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License protected static Size FLAT_BODY_SIZE = new Size(9.5d, SizeUnit.mm);
along with DIYLC. If not, see <http://www.gnu.org/licenses/>. protected static Size FLAT_LARGE_SIZE = new Size(13d, SizeUnit.mm);
protected static Size FLAT_SMALL_BODY_SIZE = new Size(5d, SizeUnit.mm);
protected static Size FLAT_SHAFT_SIZE = new Size(4.5d, SizeUnit.mm);
protected static Size VERTICAL_BODY_LENGTH = new Size(9.5d, SizeUnit.mm);
protected static Size VERTICAL_BODY_WIDTH = new Size(4.5d, SizeUnit.mm);
protected static Size ROUNDED_EDGE = new Size(1d, SizeUnit.mm);
protected static Size SPACING = new Size(0.1d, SizeUnit.in);
private static Color BODY_COLOR = Color.decode("#FFFFE0");
private static Color BORDER_COLOR = Color.decode("#8E8E38");
private static Color SHAFT_COLOR = Color.decode("#FFFFE0");
private static Color SHAFT_BORDER_COLOR = Color.decode("#8E8E38");
public static Color PIN_COLOR = Color.decode("#00B2EE");
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker();
public static Size PIN_SIZE = new Size(0.03d, SizeUnit.in);
protected static Display DISPLAY = Display.NAME;
*/ protected Color bodyColor = BODY_COLOR;
package org.diylc.components.passive; protected Color borderColor = BORDER_COLOR;
protected Display display = DISPLAY;
import java.awt.AlphaComposite; // Array of 7 elements: 3 lug connectors, 1 pot body and 3 lugs
import java.awt.Color; transient protected Shape[] body = null;
import java.awt.Composite;
import java.awt.FontMetrics; protected TrimmerType type = TrimmerType.FLAT_SMALL;
import java.awt.Graphics2D;
import java.awt.Point; public TrimmerPotentiometer() {
import java.awt.Shape; controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)};
import java.awt.geom.AffineTransform; updateControlPoints();
import java.awt.geom.Area; }
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D; protected void updateControlPoints() {
int spacing = (int) SPACING.convertToPixels();
import org.diylc.appframework.miscutils.ConfigurationManager; int dx1 = 0;
import org.diylc.common.Display; int dy1 = 0;
import org.diylc.common.IPlugInPort; int dx2 = 0;
import org.diylc.common.ObjectCache; int dy2 = 0;
import org.diylc.common.Orientation; switch (getOrientation()) {
import org.diylc.core.ComponentState; case DEFAULT:
import org.diylc.core.CreationMethod; switch (getType()) {
import org.diylc.core.IDIYComponent; case FLAT_SMALL:
import org.diylc.core.IDrawingObserver; case FLAT_XSMALL:
import org.diylc.core.Project; dx1 = 2 * spacing;
import org.diylc.core.Theme; dy1 = spacing;
import org.diylc.core.annotations.ComponentDescriptor; dx2 = 0;
import org.diylc.core.annotations.EditableProperty; dy2 = 2 * spacing;
import org.diylc.core.measures.Size; break;
import org.diylc.core.measures.SizeUnit; case FLAT_LARGE:
import org.diylc.utils.Constants; dx1 = 4 * spacing;
dy1 = spacing;
@ComponentDescriptor(name = "Trimmer Potentiometer", author = "Branislav Stojkovic", category = "Passive", dx2 = 0;
creationMethod = CreationMethod.SINGLE_CLICK, instanceNamePrefix = "VR", dy2 = 2 * spacing;
description = "Various types of board mounted trimmer potentiometers", zOrder = IDIYComponent.COMPONENT, break;
stretchable = false) case FLAT_XLARGE:
public class TrimmerPotentiometer extends AbstractPotentiometer { dx1 = 5 * spacing;
dy1 = 2 * spacing;
private static final long serialVersionUID = 1L; dx2 = 0;
dy2 = 4 * spacing;
protected static Size FLAT_BODY_SIZE = new Size(9.5d, SizeUnit.mm); break;
protected static Size FLAT_SHAFT_SIZE = new Size(4d, SizeUnit.mm); case VERTICAL_INLINE:
protected static Size VERTICAL_BODY_LENGTH = new Size(9.5d, SizeUnit.mm); dx1 = 0;
protected static Size VERTICAL_BODY_WIDTH = new Size(4.5d, SizeUnit.mm); dy1 = spacing;
protected static Size SPACING = new Size(0.1d, SizeUnit.in); dx2 = 0;
private static Color BODY_COLOR = Color.decode("#FFFFE0"); dy2 = 2 * spacing;
private static Color BORDER_COLOR = Color.decode("#8E8E38"); break;
private static Color SHAFT_COLOR = Color.decode("#FFFFE0"); case VERTICAL_OFFSET:
private static Color SHAFT_BORDER_COLOR = Color.decode("#8E8E38"); dx1 = spacing;
public static Color PIN_COLOR = Color.decode("#00B2EE"); dy1 = spacing;
public static Color PIN_BORDER_COLOR = PIN_COLOR.darker(); dx2 = 0;
public static Size PIN_SIZE = new Size(0.03d, SizeUnit.in); dy2 = 2 * spacing;
protected static Display DISPLAY = Display.NAME; break;
case VERTICAL_OFFSET_BIG_GAP:
protected Color bodyColor = BODY_COLOR; dx1 = 2 * spacing;
protected Color borderColor = BORDER_COLOR; dy1 = spacing;
protected Display display = DISPLAY; dx2 = 0;
// Array of 7 elements: 3 lug connectors, 1 pot body and 3 lugs dy2 = 2 * spacing;
transient protected Shape[] body = null; break;
}
protected TrimmerType type = TrimmerType.FLAT_SMALL; break;
case _90:
public TrimmerPotentiometer() { switch (getType()) {
controlPoints = new Point[] {new Point(0, 0), new Point(0, 0), new Point(0, 0)}; case FLAT_SMALL:
updateControlPoints(); case FLAT_XSMALL:
} dx1 = -spacing;
dy1 = 2 * spacing;
protected void updateControlPoints() { dx2 = -2 * spacing;
int spacing = (int) SPACING.convertToPixels(); dy2 = 0;
int dx1 = 0; break;
int dy1 = 0; case FLAT_LARGE:
int dx2 = 0; dx1 = -spacing;
int dy2 = 0; dy1 = 4 * spacing;
switch (orientation) { dx2 = -2 * spacing;
case DEFAULT: dy2 = 0;
switch (type) { break;
case FLAT_SMALL: case FLAT_XLARGE:
dx1 = 2 * spacing; dx1 = -2 * spacing;
dy1 = spacing; dy1 = 5 * spacing;
dx2 = 0; dx2 = -4 * spacing;
dy2 = 2 * spacing; dy2 = 0;
break; break;
case FLAT_LARGE: case VERTICAL_INLINE:
dx1 = 4 * spacing; dx1 = -spacing;
dy1 = spacing; dy1 = 0;
dx2 = 0; dx2 = -2 * spacing;
dy2 = 2 * spacing; dy2 = 0;
break; break;
case VERTICAL_INLINE: case VERTICAL_OFFSET:
dx1 = 0; dx1 = -spacing;
dy1 = spacing; dy1 = spacing;
dx2 = 0; dx2 = -2 * spacing;
dy2 = 2 * spacing; dy2 = 0;
break; break;
case VERTICAL_OFFSET: case VERTICAL_OFFSET_BIG_GAP:
dx1 = spacing; dx1 = -spacing;
dy1 = spacing; dy1 = 2 * spacing;
dx2 = 0; dx2 = -2 * spacing;
dy2 = 2 * spacing; dy2 = 0;
break; break;
case VERTICAL_OFFSET_BIG_GAP: }
dx1 = 2 * spacing; break;
dy1 = spacing; case _180:
dx2 = 0; switch (getType()) {
dy2 = 2 * spacing; case FLAT_SMALL:
break; case FLAT_XSMALL:
} dx1 = -2 * spacing;
break; dy1 = -spacing;
case _90: dx2 = 0;
switch (type) { dy2 = -2 * spacing;
case FLAT_SMALL: break;
dx1 = -spacing; case FLAT_LARGE:
dy1 = 2 * spacing; dx1 = -4 * spacing;
dx2 = -2 * spacing; dy1 = -spacing;
dy2 = 0; dx2 = 0;
break; dy2 = -2 * spacing;
case FLAT_LARGE: break;
dx1 = -spacing; case FLAT_XLARGE:
dy1 = 4 * spacing; dx1 = -5 * spacing;
dx2 = -2 * spacing; dy1 = -2 * spacing;
dy2 = 0; dx2 = 0;
break; dy2 = -4 * spacing;
case VERTICAL_INLINE: break;
dx1 = -spacing; case VERTICAL_INLINE:
dy1 = 0; dx1 = 0;
dx2 = -2 * spacing; dy1 = -spacing;
dy2 = 0; dx2 = 0;
break; dy2 = -2 * spacing;
case VERTICAL_OFFSET: break;
dx1 = -spacing; case VERTICAL_OFFSET:
dy1 = spacing; dx1 = -spacing;
dx2 = -2 * spacing; dy1 = -spacing;
dy2 = 0; dx2 = 0;
break; dy2 = -2 * spacing;
case VERTICAL_OFFSET_BIG_GAP: break;
dx1 = -spacing; case VERTICAL_OFFSET_BIG_GAP:
dy1 = 2 * spacing; dx1 = -2 * spacing;
dx2 = -2 * spacing; dy1 = -spacing;
dy2 = 0; dx2 = 0;
break; dy2 = -2 * spacing;
} break;
break; }
case _180: break;
switch (type) { case _270:
case FLAT_SMALL: switch (getType()) {
dx1 = -2 * spacing; case FLAT_SMALL:
dy1 = -spacing; case FLAT_XSMALL:
dx2 = 0; dx1 = spacing;
dy2 = -2 * spacing; dy1 = -2 * spacing;
break; dx2 = 2 * spacing;
case FLAT_LARGE: dy2 = 0;
dx1 = -4 * spacing; break;
dy1 = -spacing; case FLAT_LARGE:
dx2 = 0; dx1 = spacing;
dy2 = -2 * spacing; dy1 = -4 * spacing;
break; dx2 = 2 * spacing;
case VERTICAL_INLINE: dy2 = 0;
dx1 = 0; break;
dy1 = -spacing; case FLAT_XLARGE:
dx2 = 0; dx1 = 2 * spacing;
dy2 = -2 * spacing; dy1 = -5 * spacing;
break; dx2 = 4 * spacing;
case VERTICAL_OFFSET: dy2 = 0;
dx1 = -spacing; break;
dy1 = -spacing; case VERTICAL_INLINE:
dx2 = 0; dx1 = spacing;
dy2 = -2 * spacing; dy1 = 0;
break; dx2 = 2 * spacing;
case VERTICAL_OFFSET_BIG_GAP: dy2 = 0;
dx1 = -2 * spacing; break;
dy1 = -spacing; case VERTICAL_OFFSET:
dx2 = 0; dx1 = spacing;
dy2 = -2 * spacing; dy1 = -spacing;
break; dx2 = 2 * spacing;
} dy2 = 0;
break; break;
case _270: case VERTICAL_OFFSET_BIG_GAP:
switch (type) { dx1 = spacing;
case FLAT_SMALL: dy1 = -2 * spacing;
dx1 = spacing; dx2 = 2 * spacing;
dy1 = -2 * spacing; dy2 = 0;
dx2 = 2 * spacing; break;
dy2 = 0; }
break; break;
case FLAT_LARGE: default:
dx1 = spacing; break;
dy1 = -4 * spacing; }
dx2 = 2 * spacing; controlPoints[1].setLocation(controlPoints[0].x + dx1, controlPoints[0].y + dy1);
dy2 = 0; controlPoints[2].setLocation(controlPoints[0].x + dx2, controlPoints[0].y + dy2);
break; }
case VERTICAL_INLINE:
dx1 = spacing; public Shape[] getBody() {
dy1 = 0; if (body == null) {
dx2 = 2 * spacing; body = new Shape[2];
dy2 = 0;
break; // Calculate the center point as center of the minimum bounding
case VERTICAL_OFFSET: // rectangle.
dx1 = spacing; int centerX =
dy1 = -spacing; (Math.max(Math.max(controlPoints[0].x, controlPoints[1].x), controlPoints[2].x) + Math.min(
dx2 = 2 * spacing; Math.min(controlPoints[0].x, controlPoints[1].x), controlPoints[2].x)) / 2;
dy2 = 0; int centerY =
break; (Math.max(Math.max(controlPoints[0].y, controlPoints[1].y), controlPoints[2].y) + Math.min(
case VERTICAL_OFFSET_BIG_GAP: Math.min(controlPoints[0].y, controlPoints[1].y), controlPoints[2].y)) / 2;
dx1 = spacing;
dy1 = -2 * spacing; // Calculate body dimensions based on the selected type.
dx2 = 2 * spacing; int length = 0;
dy2 = 0; int width = 0;
break; switch (getType()) {
} case FLAT_LARGE:
break; case FLAT_SMALL:
default: case FLAT_XSMALL:
break; case FLAT_XLARGE:
} if (getType() == TrimmerType.FLAT_XSMALL)
controlPoints[1].setLocation(controlPoints[0].x + dx1, controlPoints[0].y + dy1); length = getClosestOdd(FLAT_SMALL_BODY_SIZE.convertToPixels());
controlPoints[2].setLocation(controlPoints[0].x + dx2, controlPoints[0].y + dy2); else if (getType() == TrimmerType.FLAT_XLARGE)
} length = getClosestOdd(FLAT_LARGE_SIZE.convertToPixels());
else
public Shape[] getBody() { length = getClosestOdd(FLAT_BODY_SIZE.convertToPixels());
if (body == null) { width = length;
body = new Shape[2]; int shaftSize = getClosestOdd(FLAT_SHAFT_SIZE.convertToPixels());
Area shaft =
// Calculate the center point as center of the minimum bounding new Area(new Ellipse2D.Double(centerX - shaftSize / 2, centerY - shaftSize / 2, shaftSize, shaftSize));
// rectangle. Area slot =
int centerX = new Area(new Rectangle2D.Double(centerX - shaftSize / 2, centerY - shaftSize / 8, shaftSize,
(Math.max(Math.max(controlPoints[0].x, controlPoints[1].x), controlPoints[2].x) + Math.min( shaftSize / 4));
Math.min(controlPoints[0].x, controlPoints[1].x), controlPoints[2].x)) / 2; slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, centerX, centerY));
int centerY = shaft.subtract(slot);
(Math.max(Math.max(controlPoints[0].y, controlPoints[1].y), controlPoints[2].y) + Math.min( body[1] = shaft;
Math.min(controlPoints[0].y, controlPoints[1].y), controlPoints[2].y)) / 2; break;
case VERTICAL_INLINE:
// Calculate body dimensions based on the selected type. case VERTICAL_OFFSET:
int length = 0; case VERTICAL_OFFSET_BIG_GAP:
int width = 0; length = getClosestOdd(VERTICAL_BODY_LENGTH.convertToPixels());
switch (type) { width = getClosestOdd(VERTICAL_BODY_WIDTH.convertToPixels());
case FLAT_LARGE: break;
case FLAT_SMALL: }
length = getClosestOdd(FLAT_BODY_SIZE.convertToPixels()); if (orientation == Orientation.DEFAULT || orientation == Orientation._180) {
width = length; int p = length;
int shaftSize = getClosestOdd(FLAT_SHAFT_SIZE.convertToPixels()); length = width;
Area shaft = width = p;
new Area(new Ellipse2D.Double(centerX - shaftSize / 2, centerY - shaftSize / 2, shaftSize, shaftSize)); }
Area slot = double edge = ROUNDED_EDGE.convertToPixels();
new Area(new Rectangle2D.Double(centerX - shaftSize / 2, centerY - shaftSize / 8, shaftSize, body[0] = new RoundRectangle2D.Double(centerX - length / 2, centerY - width / 2, length, width, edge, edge);
shaftSize / 4)); }
slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, centerX, centerY)); return body;
shaft.subtract(slot); }
body[1] = shaft;
break; @Override
case VERTICAL_INLINE: public void setControlPoint(Point point, int index) {
case VERTICAL_OFFSET: super.setControlPoint(point, index);
case VERTICAL_OFFSET_BIG_GAP: body = null;
length = getClosestOdd(VERTICAL_BODY_LENGTH.convertToPixels()); }
width = getClosestOdd(VERTICAL_BODY_WIDTH.convertToPixels());
break; @Override
} public void setOrientation(Orientation orientation) {
if (orientation == Orientation.DEFAULT || orientation == Orientation._180) { super.setOrientation(orientation);
int p = length; updateControlPoints();
length = width; body = null;
width = p; }
}
body[0] = new Rectangle2D.Double(centerX - length / 2, centerY - width / 2, length, width); @Override
} public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
return body; IDrawingObserver drawingObserver) {
} if (checkPointsClipped(g2d.getClip())) {
return;
@Override }
public void setControlPoint(Point point, int index) { g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
super.setControlPoint(point, index); Shape mainShape = getBody()[0];
body = null; Shape shaftShape = getBody()[1];
} Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME);
if (mainShape != null) {
@Override g2d.setColor(bodyColor);
public void setOrientation(Orientation orientation) { Composite oldComposite = g2d.getComposite();
super.setOrientation(orientation); if (alpha < MAX_ALPHA) {
updateControlPoints(); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA));
body = null; }
} if (!outlineMode) {
g2d.fill(mainShape);
@Override }
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project, if (!outlineMode && shaftShape != null) {
IDrawingObserver drawingObserver) { g2d.setColor(SHAFT_COLOR);
if (checkPointsClipped(g2d.getClip())) { g2d.fill(shaftShape);
return; g2d.setColor(SHAFT_BORDER_COLOR);
} g2d.draw(shaftShape);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); }
Shape mainShape = getBody()[0]; g2d.setComposite(oldComposite);
Shape shaftShape = getBody()[1]; Color finalBorderColor;
Theme theme = (Theme) ConfigurationManager.getInstance().readObject(IPlugInPort.THEME_KEY, Constants.DEFAULT_THEME); if (outlineMode) {
if (mainShape != null) { finalBorderColor =
g2d.setColor(bodyColor); componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
Composite oldComposite = g2d.getComposite(); : theme.getOutlineColor();
if (alpha < MAX_ALPHA) { } else {
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha / MAX_ALPHA)); finalBorderColor =
} componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR
if (!outlineMode) { : borderColor;
g2d.fill(mainShape); }
} g2d.setColor(finalBorderColor);
if (!outlineMode && shaftShape != null) { g2d.draw(mainShape);
g2d.setColor(SHAFT_COLOR); }
g2d.fill(shaftShape);
g2d.setColor(SHAFT_BORDER_COLOR); // Draw pins.
g2d.draw(shaftShape); int pinSize = getClosestOdd(PIN_SIZE.convertToPixels());
} for (Point point : controlPoints) {
g2d.setComposite(oldComposite); if (!outlineMode) {
Color finalBorderColor; g2d.setColor(PIN_COLOR);
if (outlineMode) { g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
finalBorderColor = }
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR);
: theme.getOutlineColor(); g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
} else { }
finalBorderColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? SELECTION_COLOR // Draw label.
: borderColor; g2d.setFont(project.getFont());
} Color finalLabelColor;
g2d.setColor(finalBorderColor); if (outlineMode) {
g2d.draw(mainShape); finalLabelColor =
} componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
: theme.getOutlineColor();
// Draw pins. } else {
int pinSize = getClosestOdd(PIN_SIZE.convertToPixels()); finalLabelColor =
for (Point point : controlPoints) { componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED
if (!outlineMode) { : LABEL_COLOR;
g2d.setColor(PIN_COLOR); }
g2d.fillOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize);
} String label = "";
g2d.setColor(outlineMode ? theme.getOutlineColor() : PIN_BORDER_COLOR); label = (getDisplay() == Display.NAME) ? getName() : (getValue() == null ? "" : getValue().toString());
g2d.drawOval(point.x - pinSize / 2, point.y - pinSize / 2, pinSize, pinSize); if (getDisplay() == Display.NONE) {
} label = "";
}
// Draw label. if (getDisplay() == Display.BOTH) {
g2d.setFont(project.getFont()); label = getName() + " " + (getValue() == null ? "" : getValue().toString());
Color finalLabelColor; }
if (outlineMode) {
finalLabelColor = g2d.setColor(finalLabelColor);
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED FontMetrics fontMetrics = g2d.getFontMetrics();
: theme.getOutlineColor(); Rectangle2D bodyRect = getBody()[0].getBounds2D();
} else { Rectangle2D rect = fontMetrics.getStringBounds(label, g2d);
finalLabelColor =
componentState == ComponentState.SELECTED || componentState == ComponentState.DRAGGING ? LABEL_COLOR_SELECTED int textHeight = (int) rect.getHeight();
: LABEL_COLOR; int textWidth = (int) rect.getWidth();
} int panelHeight = (int) bodyRect.getHeight();
int panelWidth = (int) bodyRect.getWidth();
String label = "";
label = (getDisplay() == Display.NAME) ? getName() : (getValue() == null ? "" : getValue().toString()); int x = (panelWidth - textWidth) / 2;
if (getDisplay() == Display.NONE) { int y = (panelHeight - textHeight) / 2 + fontMetrics.getAscent();
label = "";
} g2d.drawString(label, (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y));
if (getDisplay() == Display.BOTH) { }
label = getName() + " " + (getValue() == null ? "" : getValue().toString());
} @Override
public void drawIcon(Graphics2D g2d, int width, int height) {
g2d.setColor(finalLabelColor); int margin = 4;
FontMetrics fontMetrics = g2d.getFontMetrics(); g2d.setColor(BODY_COLOR);
Rectangle2D bodyRect = getBody()[0].getBounds2D(); g2d.fillRect(margin, margin, width - 2 * margin, width - 2 * margin);
Rectangle2D rect = fontMetrics.getStringBounds(label, g2d); g2d.setColor(BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1));
int textHeight = (int) rect.getHeight(); g2d.drawRect(margin, margin, width - 2 * margin, width - 2 * margin);
int textWidth = (int) rect.getWidth(); int shaftSize = 11;
int panelHeight = (int) bodyRect.getHeight(); int slotSize = 2;
int panelWidth = (int) bodyRect.getWidth(); Area area =
new Area(new Ellipse2D.Double(width / 2 - shaftSize / 2, width / 2 - shaftSize / 2, shaftSize, shaftSize));
int x = (panelWidth - textWidth) / 2; Area slot = new Area(new Rectangle2D.Double(0, width / 2 - slotSize / 2, width, slotSize));
int y = (panelHeight - textHeight) / 2 + fontMetrics.getAscent(); slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, width / 2, width / 2));
area.subtract(slot);
g2d.drawString(label, (int) (bodyRect.getX() + x), (int) (bodyRect.getY() + y)); g2d.setColor(SHAFT_COLOR);
} g2d.fill(area);
g2d.setColor(SHAFT_BORDER_COLOR);
@Override g2d.draw(area);
public void drawIcon(Graphics2D g2d, int width, int height) {
int margin = 4; int pinSize = 3;
g2d.setColor(BODY_COLOR); g2d.setColor(PIN_COLOR);
g2d.fillRect(margin, margin, width - 2 * margin, width - 2 * margin); g2d.fillOval(margin - pinSize / 2, 10 - pinSize / 2, pinSize, pinSize);
g2d.setColor(BORDER_COLOR); g2d.setColor(PIN_BORDER_COLOR);
g2d.setStroke(ObjectCache.getInstance().fetchBasicStroke(1)); g2d.drawOval(margin - pinSize / 2, 10 - pinSize / 2, pinSize, pinSize);
g2d.drawRect(margin, margin, width - 2 * margin, width - 2 * margin);
int shaftSize = 11; g2d.setColor(PIN_COLOR);
int slotSize = 2; g2d.fillOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize);
Area area = g2d.setColor(PIN_BORDER_COLOR);
new Area(new Ellipse2D.Double(width / 2 - shaftSize / 2, width / 2 - shaftSize / 2, shaftSize, shaftSize)); g2d.drawOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize);
Area slot = new Area(new Rectangle2D.Double(0, width / 2 - slotSize / 2, width, slotSize));
slot.transform(AffineTransform.getRotateInstance(Math.PI / 4, width / 2, width / 2)); g2d.setColor(PIN_COLOR);
area.subtract(slot); g2d.fillOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize);
g2d.setColor(SHAFT_COLOR); g2d.setColor(PIN_BORDER_COLOR);
g2d.fill(area); g2d.drawOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize);
g2d.setColor(SHAFT_BORDER_COLOR); }
g2d.draw(area);
@EditableProperty(name = "Body")
int pinSize = 3; public Color getBodyColor() {
g2d.setColor(PIN_COLOR); return bodyColor;
g2d.fillOval(margin - pinSize / 2, 10 - pinSize / 2, pinSize, pinSize); }
g2d.setColor(PIN_BORDER_COLOR);
g2d.drawOval(margin - pinSize / 2, 10 - pinSize / 2, pinSize, pinSize); public void setBodyColor(Color bodyColor) {
this.bodyColor = bodyColor;
g2d.setColor(PIN_COLOR); }
g2d.fillOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize);
g2d.setColor(PIN_BORDER_COLOR); @EditableProperty
g2d.drawOval(margin - pinSize / 2, 21 - pinSize / 2, pinSize, pinSize); public Display getDisplay() {
if (display == null) {
g2d.setColor(PIN_COLOR); display = DISPLAY;
g2d.fillOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize); }
g2d.setColor(PIN_BORDER_COLOR); return display;
g2d.drawOval(width - margin - pinSize / 2, width / 2 - pinSize / 2, pinSize, pinSize); }
}
public void setDisplay(Display display) {
@EditableProperty(name = "Body") this.display = display;
public Color getBodyColor() { }
return bodyColor;
} @EditableProperty(name = "Border")
public Color getBorderColor() {
public void setBodyColor(Color bodyColor) { return borderColor;
this.bodyColor = bodyColor; }
}
public void setBorderColor(Color borderColor) {
@EditableProperty this.borderColor = borderColor;
public Display getDisplay() { }
if (display == null) {
display = DISPLAY; @EditableProperty
} public TrimmerType getType() {
return display; return type;
} }
public void setDisplay(Display display) { public void setType(TrimmerType type) {
this.display = display; this.type = type;
} updateControlPoints();
body = null;
@EditableProperty(name = "Border") }
public Color getBorderColor() {
return borderColor; public static enum TrimmerType {
} FLAT_SMALL("Horizontal Small 1"), FLAT_XSMALL("Horizontal Small 2"), FLAT_LARGE("Horizontal Medium"), FLAT_XLARGE(
"Horizontal Large"), VERTICAL_INLINE("Vertical Inline"), VERTICAL_OFFSET("Vertical Offset 1"), VERTICAL_OFFSET_BIG_GAP(
public void setBorderColor(Color borderColor) { "Vertical Offset 2");
this.borderColor = borderColor;
} String label;
@EditableProperty private TrimmerType(String label) {
public TrimmerType getType() { this.label = label;
return type; }
}
@Override
public void setType(TrimmerType type) { public String toString() {
this.type = type; return label;// name().substring(0, 1) + name().substring(1).toLowerCase().replace("_", " ");
updateControlPoints(); }
body = null; }
} }
public static enum TrimmerType {
FLAT_LARGE, FLAT_SMALL, VERTICAL_INLINE, VERTICAL_OFFSET, VERTICAL_OFFSET_BIG_GAP;
@Override
public String toString() {
return name().substring(0, 1) + name().substring(1).toLowerCase().replace("_", " ");
}
}
}
Binary file not shown.
+4
View File
@@ -1877,6 +1877,10 @@
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>Holding "shift" key switches mouse wheel scrolling from vertical to horizontal</description> <description>Holding "shift" key switches mouse wheel scrolling from vertical to horizontal</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Two new trimmer potentiometer types</description>
</org.diylc.appframework.update.Change> </org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>