Improved editing experience of integer properties (e.g. number of terminals on a tag strip) by using the spinner text field

This commit is contained in:
Bane Stojkovic
2026-04-04 23:14:59 +02:00
parent 5ce17b4ca2
commit 124d1ab577
2 changed files with 24 additions and 14 deletions
@@ -317,6 +317,10 @@
<changeType>NEW_FEATURE</changeType>
<description>Added more ceramic resistor variants to 'Resistor' component</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Improved editing experience of integer properties (e.g. number of terminals on a tag strip) by using the spinner text field</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Improved logic when moving component(s) that have other components stuck with them; in case there are non-sticky control points within the included components, they will be moved along retaining component shape (e.g. wires or curved traces)</description>
@@ -21,39 +21,45 @@
*/
package org.diylc.swing.gui.editor;
import java.awt.BorderLayout;
import java.awt.Color;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.diylc.swingframework.DoubleTextField;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.diylc.common.PropertyWrapper;
import org.diylc.utils.Constants;
public class IntEditor extends DoubleTextField {
public class IntEditor extends JSpinner {
private static final long serialVersionUID = 1L;
private Color oldBg = getBackground();
private Color oldBg;
public IntEditor(final PropertyWrapper property) {
setLayout(new BorderLayout());
super(new SpinnerNumberModel());
JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) getEditor();
oldBg = editor.getTextField().getBackground();
if (property.isReadOnly())
setEnabled(false);
if (property.getValue() != null)
setValue((double) (Integer) property.getValue());
addPropertyChangeListener(DoubleTextField.VALUE_PROPERTY, new PropertyChangeListener() {
setValue((Integer) property.getValue());
addChangeListener(new ChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
public void stateChanged(ChangeEvent e) {
property.setChanged(true);
setBackground(oldBg);
property.setValue(evt.getNewValue() == null ? null : ((Double) evt.getNewValue()).intValue());
editor.getTextField().setBackground(oldBg);
property.setValue((Integer) getValue());
}
});
if (!property.isUnique()) {
setBackground(Constants.MULTI_VALUE_COLOR);
editor.getTextField().setBackground(Constants.MULTI_VALUE_COLOR);
}
}
}