mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
added text editor next to slider
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
package org.diylc.core.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface PercentEditor {
|
||||||
|
|
||||||
|
public byte _100PercentValue();
|
||||||
|
}
|
||||||
Binary file not shown.
@@ -19,6 +19,7 @@ import org.diylc.core.VisibilityPolicy;
|
|||||||
import org.diylc.core.annotations.BomPolicy;
|
import org.diylc.core.annotations.BomPolicy;
|
||||||
import org.diylc.core.annotations.ComponentDescriptor;
|
import org.diylc.core.annotations.ComponentDescriptor;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
|
import org.diylc.core.annotations.PercentEditor;
|
||||||
|
|
||||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@ public class Image extends AbstractTransparentComponent<Void> {
|
|||||||
private Point point = new Point(0, 0);
|
private Point point = new Point(0, 0);
|
||||||
@XStreamConverter(IconImageConverter.class)
|
@XStreamConverter(IconImageConverter.class)
|
||||||
private ImageIcon image = ICON;
|
private ImageIcon image = ICON;
|
||||||
private byte scale = 50;
|
private byte scale = DEFAULT_SCALE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
public void draw(Graphics2D g2d, ComponentState componentState, boolean outlineMode, Project project,
|
||||||
@@ -108,6 +109,7 @@ public class Image extends AbstractTransparentComponent<Void> {
|
|||||||
this.image = image;
|
this.image = image;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PercentEditor(_100PercentValue = 50)
|
||||||
@EditableProperty(defaultable = false)
|
@EditableProperty(defaultable = false)
|
||||||
public byte getScale() {
|
public byte getScale() {
|
||||||
return scale;
|
return scale;
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ import org.diylc.core.Project;
|
|||||||
import org.diylc.core.Theme;
|
import org.diylc.core.Theme;
|
||||||
import org.diylc.core.VisibilityPolicy;
|
import org.diylc.core.VisibilityPolicy;
|
||||||
import org.diylc.core.annotations.EditableProperty;
|
import org.diylc.core.annotations.EditableProperty;
|
||||||
|
import org.diylc.core.annotations.PositiveMeasureValidator;
|
||||||
|
import org.diylc.core.measures.Capacitance;
|
||||||
import org.diylc.core.measures.Size;
|
import org.diylc.core.measures.Size;
|
||||||
import org.diylc.core.measures.SizeUnit;
|
import org.diylc.core.measures.SizeUnit;
|
||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
@@ -165,26 +167,26 @@ public abstract class PassiveSMDComponent<T> extends AbstractTransparentComponen
|
|||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
width = smdWidth;
|
width = smdWidth;
|
||||||
height = smdLength;
|
height = smdLength;
|
||||||
x -= smdWidth / 2;
|
x = controlPoints[0].x - smdWidth / 2;
|
||||||
y -= pinSize / 2;
|
y = controlPoints[0].y - pinSize / 2;
|
||||||
break;
|
break;
|
||||||
case _90:
|
case _90:
|
||||||
width = smdLength;
|
width = smdLength;
|
||||||
height = smdWidth;
|
height = smdWidth;
|
||||||
x -= width - pinSize / 2;
|
x = controlPoints[1].x - pinSize / 2;
|
||||||
y -= smdWidth / 2;
|
y = controlPoints[1].y - smdWidth / 2;
|
||||||
break;
|
break;
|
||||||
case _180:
|
case _180:
|
||||||
width = smdWidth;
|
width = smdWidth;
|
||||||
height = smdLength;
|
height = smdLength;
|
||||||
x -= smdWidth / 2;
|
x = controlPoints[1].x - smdWidth / 2;
|
||||||
y -= height - pinSize / 2;
|
y = controlPoints[1].y - pinSize / 2;
|
||||||
break;
|
break;
|
||||||
case _270:
|
case _270:
|
||||||
width = smdLength;
|
width = smdLength;
|
||||||
height = smdWidth;
|
height = smdWidth;
|
||||||
x -= pinSize / 2;
|
x = controlPoints[0].x - pinSize / 2;
|
||||||
y -= smdWidth / 2;
|
y = controlPoints[0].y - smdWidth / 2;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unexpected orientation: " + orientation);
|
throw new RuntimeException("Unexpected orientation: " + orientation);
|
||||||
@@ -302,13 +304,11 @@ public abstract class PassiveSMDComponent<T> extends AbstractTransparentComponen
|
|||||||
int textWidth = (int) (rect.getWidth());
|
int textWidth = (int) (rect.getWidth());
|
||||||
|
|
||||||
do {
|
do {
|
||||||
System.out.println("trying font size: " + g2d.getFont().getSize2D());
|
|
||||||
g2d.setFont(g2d.getFont().deriveFont(g2d.getFont().getSize2D() - 1));
|
g2d.setFont(g2d.getFont().deriveFont(g2d.getFont().getSize2D() - 1));
|
||||||
fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
fontMetrics = g2d.getFontMetrics(g2d.getFont());
|
||||||
rect = fontMetrics.getStringBounds(label, g2d);
|
rect = fontMetrics.getStringBounds(label, g2d);
|
||||||
textHeight = (int) (rect.getHeight());
|
textHeight = (int) (rect.getHeight());
|
||||||
textWidth = (int) (rect.getWidth());
|
textWidth = (int) (rect.getWidth());
|
||||||
System.out.println("width: " + rect.getWidth());
|
|
||||||
} while (textWidth > length && g2d.getFont().getSize2D() > 2);
|
} while (textWidth > length && g2d.getFont().getSize2D() > 2);
|
||||||
|
|
||||||
double centerX = textTarget.getX() + textTarget.getWidth() / 2;
|
double centerX = textTarget.getX() + textTarget.getWidth() / 2;
|
||||||
@@ -391,7 +391,7 @@ public abstract class PassiveSMDComponent<T> extends AbstractTransparentComponen
|
|||||||
|
|
||||||
public static enum SMDSize {
|
public static enum SMDSize {
|
||||||
|
|
||||||
_0805(new Size(1.25d, SizeUnit.mm), new Size(2.0d, SizeUnit.mm)), _1206(new Size(1.6d, SizeUnit.mm), new Size(3.2d,
|
_0805(new Size(0.05d, SizeUnit.in), new Size(0.08d, SizeUnit.in)), _1206(new Size(1.6d, SizeUnit.mm), new Size(3.2d,
|
||||||
SizeUnit.mm)), _1210(new Size(2.5d, SizeUnit.mm), new Size(3.2d, SizeUnit.mm)), _1806(new Size(1.6d,
|
SizeUnit.mm)), _1210(new Size(2.5d, SizeUnit.mm), new Size(3.2d, SizeUnit.mm)), _1806(new Size(1.6d,
|
||||||
SizeUnit.mm), new Size(4.5d, SizeUnit.mm)), _1812(new Size(3.2d, SizeUnit.mm), new Size(4.5d, SizeUnit.mm));
|
SizeUnit.mm), new Size(4.5d, SizeUnit.mm)), _1812(new Size(3.2d, SizeUnit.mm), new Size(4.5d, SizeUnit.mm));
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -1,36 +1,91 @@
|
|||||||
package org.diylc.swing.gui.editor;
|
package org.diylc.swing.gui.editor;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JSlider;
|
import javax.swing.JSlider;
|
||||||
import javax.swing.event.ChangeEvent;
|
import javax.swing.event.ChangeEvent;
|
||||||
import javax.swing.event.ChangeListener;
|
import javax.swing.event.ChangeListener;
|
||||||
|
|
||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
|
import org.diylc.core.annotations.PercentEditor;
|
||||||
|
import org.diylc.swingframework.DoubleTextField;
|
||||||
import org.diylc.utils.Constants;
|
import org.diylc.utils.Constants;
|
||||||
|
|
||||||
public class ByteEditor extends JSlider {
|
public class ByteEditor extends JPanel {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Color oldBg = getBackground();
|
private Color oldBg = getBackground();
|
||||||
|
|
||||||
|
private static final byte default100Percent = 127;
|
||||||
|
|
||||||
|
private byte _100PercentValue;
|
||||||
|
|
||||||
public ByteEditor(final PropertyWrapper property) {
|
public ByteEditor(final PropertyWrapper property) {
|
||||||
super();
|
super();
|
||||||
setMinimum(0);
|
|
||||||
setMaximum(127);
|
setLayout(new FlowLayout());
|
||||||
setValue((Byte) property.getValue());
|
|
||||||
addChangeListener(new ChangeListener() {
|
try {
|
||||||
|
PercentEditor percentEditor = property.getGetter().getAnnotation(PercentEditor.class);
|
||||||
|
if (percentEditor == null)
|
||||||
|
_100PercentValue = default100Percent;
|
||||||
|
else
|
||||||
|
_100PercentValue = percentEditor._100PercentValue();
|
||||||
|
} catch (Exception e) {
|
||||||
|
_100PercentValue = default100Percent;
|
||||||
|
}
|
||||||
|
|
||||||
|
final JSlider slider = new JSlider();
|
||||||
|
final DoubleTextField valueField = new DoubleTextField();
|
||||||
|
|
||||||
|
final double percentFactor = (double) default100Percent / _100PercentValue;
|
||||||
|
|
||||||
|
slider.setMinimum(0);
|
||||||
|
slider.setMaximum(default100Percent * 100);
|
||||||
|
|
||||||
|
slider.addChangeListener(new ChangeListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stateChanged(ChangeEvent e) {
|
public void stateChanged(ChangeEvent e) {
|
||||||
property.setChanged(true);
|
property.setChanged(true);
|
||||||
setBackground(oldBg);
|
setBackground(oldBg);
|
||||||
property.setValue(new Integer(getValue()).byteValue());
|
slider.setBackground(oldBg);
|
||||||
|
property.setValue(new Integer(slider.getValue() / 100).byteValue());
|
||||||
|
valueField.setText(Integer.toString((int) Math.round(percentFactor * (double) slider.getValue()
|
||||||
|
/ default100Percent)));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
slider.setValue((Byte) property.getValue() * 100);
|
||||||
|
|
||||||
|
valueField
|
||||||
|
.setText(Integer.toString((int) Math.round(percentFactor * (double) slider.getValue() / default100Percent)));
|
||||||
|
valueField.setColumns(3);
|
||||||
|
valueField.addKeyListener(new KeyAdapter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {
|
||||||
|
try {
|
||||||
|
int newPosition = (int) (Double.parseDouble(valueField.getText()) * default100Percent / percentFactor);
|
||||||
|
System.out.println("keyReleased, pos: " + newPosition);
|
||||||
|
slider.setValue(newPosition);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (!property.isUnique()) {
|
if (!property.isUnique()) {
|
||||||
setBackground(Constants.MULTI_VALUE_COLOR);
|
setBackground(Constants.MULTI_VALUE_COLOR);
|
||||||
|
slider.setBackground(Constants.MULTI_VALUE_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
add(slider);
|
||||||
|
add(valueField);
|
||||||
|
add(new JLabel("%"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public class PropertyEditorDialog extends ButtonDialog {
|
|||||||
gbc.fill = GridBagConstraints.NONE;
|
gbc.fill = GridBagConstraints.NONE;
|
||||||
gbc.weightx = 0;
|
gbc.weightx = 0;
|
||||||
gbc.insets = new Insets(4, 2, 2, 2);
|
gbc.insets = new Insets(4, 2, 2, 2);
|
||||||
|
gbc.anchor = GridBagConstraints.WEST;
|
||||||
editorPanel.add(new JLabel(property.getName() + ": "), gbc);
|
editorPanel.add(new JLabel(property.getName() + ": "), gbc);
|
||||||
|
|
||||||
gbc.gridx = 1;
|
gbc.gridx = 1;
|
||||||
|
|||||||
@@ -1420,7 +1420,11 @@
|
|||||||
</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>
|
||||||
<description>Better line representation when zoomed in</description>
|
<description>Added percent text box next to the slider for editors like Alpha or Scale</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Better object line representation when zoomed in</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user