mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added enum editor
This commit is contained in:
+11
@@ -6,6 +6,7 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.geom.Rectangle2D;
|
import java.awt.geom.Rectangle2D;
|
||||||
|
|
||||||
|
import org.diylc.common.Orientation;
|
||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.Project;
|
import org.diylc.core.Project;
|
||||||
@@ -27,6 +28,7 @@ public class DIL_IC implements IDIYComponent<String> {
|
|||||||
private Point point2 = new Point((int) (Constants.GRID) * 4, (int) (Constants.GRID) * 5);
|
private Point point2 = new Point((int) (Constants.GRID) * 4, (int) (Constants.GRID) * 5);
|
||||||
private String name = "New Component";
|
private String name = "New Component";
|
||||||
private String value = "";
|
private String value = "";
|
||||||
|
private Orientation orientation = Orientation.DEFAULT;
|
||||||
|
|
||||||
@EditableProperty
|
@EditableProperty
|
||||||
public String getName() {
|
public String getName() {
|
||||||
@@ -46,6 +48,15 @@ public class DIL_IC implements IDIYComponent<String> {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Orientation getOrientation() {
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrientation(Orientation orientation) {
|
||||||
|
this.orientation = orientation;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getControlPointCount() {
|
public int getControlPointCount() {
|
||||||
return 2;
|
return 2;
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package org.diylc.common;
|
||||||
|
|
||||||
|
public enum Orientation {
|
||||||
|
|
||||||
|
DEFAULT, _90, _180, _270;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
if (this == DEFAULT) {
|
||||||
|
return "Default";
|
||||||
|
} else {
|
||||||
|
return name().replace("_", "") + " degrees clockwise";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+32
@@ -0,0 +1,32 @@
|
|||||||
|
package org.diylc.gui.editor;
|
||||||
|
|
||||||
|
import java.awt.event.ItemEvent;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
|
||||||
|
import javax.swing.DefaultComboBoxModel;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
|
||||||
|
import org.diylc.common.PropertyWrapper;
|
||||||
|
|
||||||
|
public class EnumEditor extends JComboBox {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private final PropertyWrapper property;
|
||||||
|
|
||||||
|
public EnumEditor(PropertyWrapper property) {
|
||||||
|
this.property = property;
|
||||||
|
Object[] values = property.getType().getEnumConstants();
|
||||||
|
setModel(new DefaultComboBoxModel(values));
|
||||||
|
setSelectedItem(property.getValue());
|
||||||
|
addItemListener(new ItemListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void itemStateChanged(ItemEvent e) {
|
||||||
|
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
|
EnumEditor.this.property.setValue(e.getItem());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-1
@@ -6,7 +6,6 @@ import java.awt.Component;
|
|||||||
import org.diylc.common.PropertyWrapper;
|
import org.diylc.common.PropertyWrapper;
|
||||||
import org.diylc.core.measures.AbstractMeasure;
|
import org.diylc.core.measures.AbstractMeasure;
|
||||||
|
|
||||||
|
|
||||||
public class FieldEditorFactory {
|
public class FieldEditorFactory {
|
||||||
|
|
||||||
public static Component createFieldEditor(PropertyWrapper property) {
|
public static Component createFieldEditor(PropertyWrapper property) {
|
||||||
@@ -22,6 +21,10 @@ public class FieldEditorFactory {
|
|||||||
MeasureEditor editor = new MeasureEditor(property);
|
MeasureEditor editor = new MeasureEditor(property);
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
if (property.getType().isEnum()) {
|
||||||
|
EnumEditor editor = new EnumEditor(property);
|
||||||
|
return editor;
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ public class PropertyEditorDialog extends ButtonDialog {
|
|||||||
private Set<PropertyWrapper> defaultedProperties;
|
private Set<PropertyWrapper> defaultedProperties;
|
||||||
|
|
||||||
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties) {
|
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties) {
|
||||||
super(owner, "Editor", new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
|
super(owner, "Component Editor", new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
|
||||||
|
|
||||||
LOG.debug("Creating property editor for: " + properties);
|
LOG.debug("Creating property editor for: " + properties);
|
||||||
|
|
||||||
|
|||||||
+1
@@ -10,6 +10,7 @@ import org.diylc.common.PropertyWrapper;
|
|||||||
public class StringEditor extends JTextField {
|
public class StringEditor extends JTextField {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private final PropertyWrapper property;
|
private final PropertyWrapper property;
|
||||||
|
|
||||||
public StringEditor(PropertyWrapper property) {
|
public StringEditor(PropertyWrapper property) {
|
||||||
|
|||||||
+2
-1
@@ -55,7 +55,8 @@ public class StatusBar extends JPanel implements IPlugIn {
|
|||||||
|
|
||||||
private JComboBox getZoomBox() {
|
private JComboBox getZoomBox() {
|
||||||
if (zoomBox == null) {
|
if (zoomBox == null) {
|
||||||
zoomBox = new JComboBox(new Double[] { 0.25d, 0.5d, 0.75d, 1d, 1.5d, 2d });
|
zoomBox = new JComboBox(new Double[] { 0.25d, 0.3333d, 0.5d, 0.6667d, 0.75d, 1d, 1.25d,
|
||||||
|
1.5d, 2d });
|
||||||
zoomBox.setSelectedItem(1d);
|
zoomBox.setSelectedItem(1d);
|
||||||
zoomBox.setFocusable(false);
|
zoomBox.setFocusable(false);
|
||||||
zoomBox.setRenderer(new PercentageListCellRenderer());
|
zoomBox.setRenderer(new PercentageListCellRenderer());
|
||||||
|
|||||||
Reference in New Issue
Block a user