mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Added read-only "Length" property to curved components (i.e. "Hookup
Wire") that calculates total length of the curve
This commit is contained in:
@@ -38,7 +38,9 @@ public class BooleanEditor extends JCheckBox {
|
||||
|
||||
public BooleanEditor(final PropertyWrapper property) {
|
||||
super();
|
||||
setSelected((Boolean) property.getValue());
|
||||
setSelected((Boolean) property.getValue());
|
||||
if (property.isReadOnly())
|
||||
setEnabled(false);
|
||||
addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,7 +63,12 @@ public class ByteEditor extends JPanel {
|
||||
}
|
||||
|
||||
final JSlider slider = new JSlider();
|
||||
final DoubleTextField valueField = new DoubleTextField();
|
||||
final DoubleTextField valueField = new DoubleTextField();
|
||||
|
||||
if (property.isReadOnly()) {
|
||||
slider.setEnabled(false);
|
||||
valueField.setEnabled(false);
|
||||
}
|
||||
|
||||
final double percentFactor = (double) default100Percent / _100PercentValue;
|
||||
|
||||
|
||||
@@ -72,7 +72,12 @@ public class ColorEditor extends JPanel {
|
||||
|
||||
gbc.gridx++;
|
||||
gbc.insets = new Insets(0, 0, 0, 0);
|
||||
add(getColorField(), gbc);
|
||||
add(getColorField(), gbc);
|
||||
|
||||
if (property.isReadOnly()) {
|
||||
getColorField().setEnabled(false);
|
||||
getColorLabel().setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public JLabel getColorLabel() {
|
||||
|
||||
@@ -41,7 +41,9 @@ public class EnumEditor extends JComboBox {
|
||||
|
||||
public EnumEditor(final PropertyWrapper property) {
|
||||
this.property = property;
|
||||
Object[] values = property.getType().getEnumConstants();
|
||||
Object[] values = property.getType().getEnumConstants();
|
||||
if (property.isReadOnly())
|
||||
setEnabled(false);
|
||||
setModel(new DefaultComboBoxModel(values));
|
||||
setSelectedItem(property.getValue());
|
||||
addItemListener(new ItemListener() {
|
||||
|
||||
@@ -42,7 +42,9 @@ public class FontEditor extends FontChooserComboBox {
|
||||
private final PropertyWrapper property;
|
||||
|
||||
public FontEditor(final PropertyWrapper property) {
|
||||
this.property = property;
|
||||
this.property = property;
|
||||
if (property.isReadOnly())
|
||||
setEnabled(false);
|
||||
((JTextField) getEditor().getEditorComponent()).setBorder(BorderFactory.createCompoundBorder(
|
||||
((JTextField) getEditor().getEditorComponent()).getBorder(), BorderFactory.createEmptyBorder(0, 2, 0, 0)));
|
||||
setSelectedItem(((Font) property.getValue()).getName());
|
||||
|
||||
@@ -41,7 +41,9 @@ public class ImageEditor extends JButton {
|
||||
private static final String title = "Click to load image file";
|
||||
|
||||
public ImageEditor(final PropertyWrapper property) {
|
||||
super(property.isUnique() ? title : ("(multi value) " + title));
|
||||
super(property.isUnique() ? title : ("(multi value) " + title));
|
||||
if (property.isReadOnly())
|
||||
setEnabled(false);
|
||||
addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,7 +37,9 @@ public class IntEditor extends DoubleTextField {
|
||||
private Color oldBg = getBackground();
|
||||
|
||||
public IntEditor(final PropertyWrapper property) {
|
||||
setLayout(new BorderLayout());
|
||||
setLayout(new BorderLayout());
|
||||
if (property.isReadOnly())
|
||||
setEnabled(false);
|
||||
setValue((double) (Integer) property.getValue());
|
||||
addPropertyChangeListener(DoubleTextField.VALUE_PROPERTY, new PropertyChangeListener() {
|
||||
|
||||
|
||||
@@ -63,6 +63,8 @@ public class MeasureArrayEditor extends Container {
|
||||
values[i] = measure[i] == null ? null : measure[i].getValue();
|
||||
}
|
||||
valueField = new DoubleArrayTextField(measure == null ? null : values);
|
||||
if (property.isReadOnly())
|
||||
valueField.setEnabled(false);
|
||||
oldBg = valueField.getBackground();
|
||||
valueField.addPropertyChangeListener(
|
||||
DoubleArrayTextField.VALUE_PROPERTY,
|
||||
|
||||
@@ -56,7 +56,7 @@ public class MeasureEditor extends Container {
|
||||
@SuppressWarnings("unchecked")
|
||||
public MeasureEditor(final PropertyWrapper property) {
|
||||
setLayout(new BorderLayout());
|
||||
final AbstractMeasure<?> measure = ((AbstractMeasure<?>) property.getValue());
|
||||
final AbstractMeasure<?> measure = ((AbstractMeasure<?>) property.getValue());
|
||||
valueField = new DoubleTextField(measure == null ? null : measure.getValue());
|
||||
oldBg = valueField.getBackground();
|
||||
valueField.addPropertyChangeListener(DoubleTextField.VALUE_PROPERTY, new PropertyChangeListener() {
|
||||
@@ -87,9 +87,16 @@ public class MeasureEditor extends Container {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
try {
|
||||
Constructor<?> ctor = property.getType().getConstructors()[0];
|
||||
Constructor<?> ctor = property.getType().getConstructors()[0];
|
||||
Double newValue = valueField.getValue();
|
||||
if (newValue != null && property.isReadOnly() && measure.isConvertible()) {
|
||||
double oldFactor = ((Unit)((AbstractMeasure<?>)property.getValue()).getUnit()).getFactor();
|
||||
double newFactor = ((Unit)unitBox.getSelectedItem()).getFactor();
|
||||
newValue = newValue * oldFactor / newFactor;
|
||||
valueField.setValue(newValue);
|
||||
}
|
||||
AbstractMeasure<?> newMeasure =
|
||||
(AbstractMeasure<?>) ctor.newInstance(valueField.getValue(),
|
||||
(AbstractMeasure<?>) ctor.newInstance(newValue,
|
||||
(Enum<? extends Unit>) unitBox.getSelectedItem());
|
||||
property.setValue(newMeasure);
|
||||
property.setChanged(true);
|
||||
@@ -100,7 +107,12 @@ public class MeasureEditor extends Container {
|
||||
}
|
||||
}
|
||||
});
|
||||
add(unitBox, BorderLayout.EAST);
|
||||
add(unitBox, BorderLayout.EAST);
|
||||
|
||||
if (property.isReadOnly()) {
|
||||
valueField.setEnabled(false);
|
||||
unitBox.setEnabled(measure.isConvertible());
|
||||
}
|
||||
|
||||
if (!property.isUnique()) {
|
||||
valueField.setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
|
||||
@@ -50,7 +50,9 @@ public class MultiLineStringEditor extends JScrollPane {
|
||||
public MultiLineStringEditor(PropertyWrapper property) {
|
||||
super();
|
||||
this.property = property;
|
||||
setViewportView(getTextArea());
|
||||
setViewportView(getTextArea());
|
||||
if (property.isReadOnly())
|
||||
getTextArea().setEnabled(false);
|
||||
setPreferredSize(new Dimension(192, 64));
|
||||
setBorder(border);
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ public class PropertyEditorDialog extends ButtonDialog {
|
||||
gbc.fill = GridBagConstraints.NONE;
|
||||
gbc.weightx = 0;
|
||||
|
||||
if (saveDefaults) {
|
||||
if (saveDefaults && !property.isReadOnly()) {
|
||||
editorPanel.add(createDefaultCheckBox(property), gbc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,9 @@ public class StringEditor extends JTextField {
|
||||
|
||||
public StringEditor(PropertyWrapper property) {
|
||||
super(property.getValue() == null ? "" : (String) property.getValue());
|
||||
this.property = property;
|
||||
this.property = property;
|
||||
if (property.isReadOnly())
|
||||
setEnabled(false);
|
||||
this.setColumns(32);
|
||||
getDocument().addDocumentListener(new DocumentListener() {
|
||||
|
||||
|
||||
@@ -42,7 +42,9 @@ public class StringListEditor extends JComboBox {
|
||||
private final PropertyWrapper property;
|
||||
|
||||
public StringListEditor(final PropertyWrapper property) throws Exception {
|
||||
this.property = property;
|
||||
this.property = property;
|
||||
if (property.isReadOnly())
|
||||
setEnabled(false);
|
||||
String listFunctionName = property.getGetter().getAnnotation(DynamicList.class).availableValueFunction();
|
||||
Method function = property.getOwnerObject().getClass().getMethod(listFunctionName);
|
||||
Object[] values = (Object[]) function.invoke(property.getOwnerObject());
|
||||
|
||||
Reference in New Issue
Block a user