mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Component edit dialog allows changing property values even when they are not the same
This commit is contained in:
+9
-6
@@ -20,6 +20,7 @@ public class PropertyWrapper implements Cloneable {
|
||||
private boolean defaultable;
|
||||
private IPropertyValidator validator;
|
||||
private boolean unique = true;
|
||||
private boolean changed = false;
|
||||
|
||||
public PropertyWrapper(String name, Class<?> type, String getter, String setter,
|
||||
boolean defaultable, IPropertyValidator validator) {
|
||||
@@ -82,6 +83,14 @@ public class PropertyWrapper implements Cloneable {
|
||||
public void setUnique(boolean unique) {
|
||||
this.unique = unique;
|
||||
}
|
||||
|
||||
public boolean isChanged() {
|
||||
return changed;
|
||||
}
|
||||
|
||||
public void setChanged(boolean changed) {
|
||||
this.changed = changed;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Object clone() throws CloneNotSupportedException {
|
||||
@@ -103,7 +112,6 @@ public class PropertyWrapper implements Cloneable {
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((setter == null) ? 0 : setter.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -138,11 +146,6 @@ public class PropertyWrapper implements Cloneable {
|
||||
return false;
|
||||
} else if (!type.equals(other.type))
|
||||
return false;
|
||||
if (value == null) {
|
||||
if (other.value != null)
|
||||
return false;
|
||||
} else if (!value.equals(other.value))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -182,6 +182,19 @@ public class ComponentProcessor {
|
||||
property.readFrom(component);
|
||||
}
|
||||
properties.retainAll(newProperties);
|
||||
// Try to find matching properties in old and new lists and see if
|
||||
// their values match.
|
||||
for (PropertyWrapper oldProperty : properties) {
|
||||
if (newProperties.contains(oldProperty)) {
|
||||
PropertyWrapper newProperty = newProperties.get(newProperties
|
||||
.indexOf(oldProperty));
|
||||
if ((newProperty.getValue() != null && newProperty.getValue() == null)
|
||||
|| !newProperty.getValue().equals(oldProperty.getValue())) {
|
||||
// Values don't match, so the property is not unique valued.
|
||||
oldProperty.setUnique(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// for (PropertyWrapper property : properties) {
|
||||
// try {
|
||||
// property.readUniqueFrom(component);
|
||||
|
||||
+3
-1
@@ -1213,7 +1213,9 @@ public class Presenter implements IPlugInPort {
|
||||
for (IDIYComponent<?> component : selectedComponents) {
|
||||
drawingManager.invalidateComponent(component);
|
||||
for (PropertyWrapper property : properties) {
|
||||
property.writeTo(component);
|
||||
if (property.isChanged()) {
|
||||
property.writeTo(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
+10
-2
@@ -1,17 +1,20 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JCheckBox;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public class BooleanEditor extends JCheckBox {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private Color oldBg = getBackground();
|
||||
|
||||
public BooleanEditor(final PropertyWrapper property) {
|
||||
super();
|
||||
setSelected((Boolean) property.getValue());
|
||||
@@ -19,8 +22,13 @@ public class BooleanEditor extends JCheckBox {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
property.setChanged(true);
|
||||
setBackground(oldBg);
|
||||
property.setValue(isSelected());
|
||||
}
|
||||
});
|
||||
if (!property.isUnique()) {
|
||||
setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -1,15 +1,20 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public class ByteEditor extends JSlider {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Color oldBg = getBackground();
|
||||
|
||||
public ByteEditor(final PropertyWrapper property) {
|
||||
super();
|
||||
setMinimum(0);
|
||||
@@ -19,8 +24,13 @@ public class ByteEditor extends JSlider {
|
||||
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
property.setChanged(true);
|
||||
setBackground(oldBg);
|
||||
property.setValue(new Integer(getValue()).byteValue());
|
||||
}
|
||||
});
|
||||
if (!property.isUnique()) {
|
||||
setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-4
@@ -12,13 +12,14 @@ import javax.swing.SwingConstants;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
|
||||
|
||||
public class ColorEditor extends JLabel {
|
||||
public class ColorEditor extends JLabel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String title = "Click to edit";
|
||||
|
||||
public ColorEditor(final PropertyWrapper property) {
|
||||
super("Click to edit");
|
||||
super(property.isUnique() ? title : ("(multi value) " + title));
|
||||
setOpaque(true);
|
||||
setHorizontalAlignment(SwingConstants.CENTER);
|
||||
setBorder(BorderFactory.createEtchedBorder());
|
||||
@@ -31,13 +32,14 @@ public class ColorEditor extends JLabel {
|
||||
Color newColor = JColorChooser.showDialog(ColorEditor.this, "Choose Color",
|
||||
getBackground());
|
||||
if (newColor != null) {
|
||||
property.setChanged(true);
|
||||
property.setValue(newColor);
|
||||
setBackground(newColor);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setBackground(Color bg) {
|
||||
if (bg.getRed() < 127 || bg.getBlue() < 127 || bg.getGreen() < 127) {
|
||||
|
||||
+10
-1
@@ -1,5 +1,6 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
@@ -7,14 +8,17 @@ import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JComboBox;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public class EnumEditor extends JComboBox {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Color oldBg = getBackground();
|
||||
|
||||
private final PropertyWrapper property;
|
||||
|
||||
public EnumEditor(PropertyWrapper property) {
|
||||
public EnumEditor(final PropertyWrapper property) {
|
||||
this.property = property;
|
||||
Object[] values = property.getType().getEnumConstants();
|
||||
setModel(new DefaultComboBoxModel(values));
|
||||
@@ -24,9 +28,14 @@ public class EnumEditor extends JComboBox {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
property.setChanged(true);
|
||||
setBackground(oldBg);
|
||||
EnumEditor.this.property.setValue(e.getItem());
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!property.isUnique()) {
|
||||
setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-1
@@ -1,10 +1,12 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
import com.diyfever.gui.FontChooserComboBox;
|
||||
|
||||
@@ -12,9 +14,11 @@ public class FontEditor extends FontChooserComboBox {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Color oldBg = getBackground();
|
||||
|
||||
private final PropertyWrapper property;
|
||||
|
||||
public FontEditor(PropertyWrapper property) {
|
||||
public FontEditor(final PropertyWrapper property) {
|
||||
this.property = property;
|
||||
setSelectedItem(((Font) property.getValue()).getName());
|
||||
addItemListener(new ItemListener() {
|
||||
@@ -22,6 +26,8 @@ public class FontEditor extends FontChooserComboBox {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
property.setChanged(true);
|
||||
setBackground(oldBg);
|
||||
Font oldFont = (Font) FontEditor.this.property.getValue();
|
||||
Font newFont = new Font(getSelectedItem().toString(), oldFont.getStyle(),
|
||||
oldFont.getSize());
|
||||
@@ -29,5 +35,8 @@ public class FontEditor extends FontChooserComboBox {
|
||||
}
|
||||
}
|
||||
});
|
||||
if (!property.isUnique()) {
|
||||
setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-11
@@ -1,6 +1,5 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
|
||||
@@ -15,8 +14,10 @@ public class ImageEditor extends JButton {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private static final String title = "Click to load image file";
|
||||
|
||||
public ImageEditor(final PropertyWrapper property) {
|
||||
super("Click to load file");
|
||||
super(property.isUnique() ? title : ("(multi value) " + title));
|
||||
addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
@@ -25,6 +26,7 @@ public class ImageEditor extends JButton {
|
||||
FileFilterEnum.IMAGES.getFilter(), null,
|
||||
FileFilterEnum.IMAGES.getExtensions()[0], null);
|
||||
if (file != null) {
|
||||
property.setChanged(true);
|
||||
ImageIcon image = new ImageIcon(file.getAbsolutePath());
|
||||
property.setValue(image);
|
||||
}
|
||||
@@ -32,13 +34,13 @@ public class ImageEditor extends JButton {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackground(Color bg) {
|
||||
if (bg.getRed() < 127 || bg.getBlue() < 127 || bg.getGreen() < 127) {
|
||||
setForeground(Color.white);
|
||||
} else {
|
||||
setForeground(Color.black);
|
||||
}
|
||||
super.setBackground(bg);
|
||||
}
|
||||
// @Override
|
||||
// public void setBackground(Color bg) {
|
||||
// if (bg.getRed() < 127 || bg.getBlue() < 127 || bg.getGreen() < 127) {
|
||||
// setForeground(Color.white);
|
||||
// } else {
|
||||
// setForeground(Color.black);
|
||||
// }
|
||||
// super.setBackground(bg);
|
||||
// }
|
||||
}
|
||||
|
||||
+9
@@ -1,10 +1,12 @@
|
||||
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.common.PropertyWrapper;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
import com.diyfever.gui.DoubleTextField;
|
||||
|
||||
@@ -12,6 +14,8 @@ public class IntEditor extends DoubleTextField {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Color oldBg = getBackground();
|
||||
|
||||
public IntEditor(final PropertyWrapper property) {
|
||||
setLayout(new BorderLayout());
|
||||
setValue((double) (Integer) property.getValue());
|
||||
@@ -19,8 +23,13 @@ public class IntEditor extends DoubleTextField {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
property.setChanged(true);
|
||||
setBackground(oldBg);
|
||||
property.setValue(((Double) evt.getNewValue()).intValue());
|
||||
}
|
||||
});
|
||||
if (!property.isUnique()) {
|
||||
setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+20
-2
@@ -1,6 +1,7 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@@ -14,6 +15,7 @@ import javax.swing.JComboBox;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.measures.AbstractMeasure;
|
||||
import org.diylc.core.measures.Unit;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
import com.diyfever.gui.DoubleTextField;
|
||||
|
||||
@@ -21,11 +23,16 @@ public class MeasureEditor extends Container {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Color oldBg;
|
||||
private DoubleTextField valueField;
|
||||
private JComboBox unitBox;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public MeasureEditor(final PropertyWrapper property) {
|
||||
setLayout(new BorderLayout());
|
||||
AbstractMeasure measure = ((AbstractMeasure) property.getValue());
|
||||
DoubleTextField valueField = new DoubleTextField(measure.getValue());
|
||||
valueField = new DoubleTextField(measure.getValue());
|
||||
oldBg = valueField.getBackground();
|
||||
valueField.addPropertyChangeListener(DoubleTextField.VALUE_PROPERTY,
|
||||
new PropertyChangeListener() {
|
||||
|
||||
@@ -36,6 +43,9 @@ public class MeasureEditor extends Container {
|
||||
.getValue()).clone();
|
||||
newMeasure.setValue((Double) evt.getNewValue());
|
||||
property.setValue(newMeasure);
|
||||
property.setChanged(true);
|
||||
valueField.setBackground(oldBg);
|
||||
unitBox.setBackground(oldBg);
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
}
|
||||
}
|
||||
@@ -43,7 +53,7 @@ public class MeasureEditor extends Container {
|
||||
add(valueField, BorderLayout.CENTER);
|
||||
try {
|
||||
Method method = measure.getUnit().getClass().getMethod("values");
|
||||
final JComboBox unitBox = new JComboBox((Object[]) method.invoke(measure.getUnit()));
|
||||
unitBox = new JComboBox((Object[]) method.invoke(measure.getUnit()));
|
||||
unitBox.setSelectedItem(measure.getUnit());
|
||||
unitBox.addActionListener(new ActionListener() {
|
||||
|
||||
@@ -54,11 +64,19 @@ public class MeasureEditor extends Container {
|
||||
.getValue()).clone();
|
||||
newMeasure.setUnit((Enum<? extends Unit>) unitBox.getSelectedItem());
|
||||
property.setValue(newMeasure);
|
||||
property.setChanged(true);
|
||||
valueField.setBackground(oldBg);
|
||||
unitBox.setBackground(oldBg);
|
||||
} catch (CloneNotSupportedException ex) {
|
||||
}
|
||||
}
|
||||
});
|
||||
add(unitBox, BorderLayout.EAST);
|
||||
|
||||
if (!property.isUnique()) {
|
||||
valueField.setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
unitBox.setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
+11
-3
@@ -1,16 +1,20 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public class StringEditor extends JTextField {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private Color oldBg = getBackground();
|
||||
|
||||
private final PropertyWrapper property;
|
||||
|
||||
public StringEditor(PropertyWrapper property) {
|
||||
@@ -33,10 +37,14 @@ public class StringEditor extends JTextField {
|
||||
textChanged();
|
||||
}
|
||||
});
|
||||
if (!property.isUnique()) {
|
||||
setBackground(Constants.MULTI_VALUE_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void textChanged() {
|
||||
property.setChanged(true);
|
||||
setBackground(oldBg);
|
||||
property.setValue(getText());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -22,4 +22,6 @@ public class Constants {
|
||||
240, 240, 240), Color.black);
|
||||
|
||||
public static final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0);
|
||||
|
||||
public static final Color MULTI_VALUE_COLOR = Color.yellow;
|
||||
}
|
||||
|
||||
@@ -322,6 +322,10 @@
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<description>Auto-created solder pads aren't assigned with default settings and name</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Component edit dialog allows changing property values even when they are not the same. Boxes are marked yellow to designate multi-valued state.</description>
|
||||
</com.diyfever.gui.update.Change>
|
||||
<com.diyfever.gui.update.Change>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<description>Component edit dialog should show mutual properties when components of different types are selected (e.g. curved trace and straight trace witdth)</description>
|
||||
|
||||
Reference in New Issue
Block a user