mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added text editor next to slider
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,36 +1,91 @@
|
||||
package org.diylc.swing.gui.editor;
|
||||
|
||||
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.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.annotations.PercentEditor;
|
||||
import org.diylc.swingframework.DoubleTextField;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public class ByteEditor extends JSlider {
|
||||
public class ByteEditor extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Color oldBg = getBackground();
|
||||
|
||||
private static final byte default100Percent = 127;
|
||||
|
||||
private byte _100PercentValue;
|
||||
|
||||
public ByteEditor(final PropertyWrapper property) {
|
||||
super();
|
||||
setMinimum(0);
|
||||
setMaximum(127);
|
||||
setValue((Byte) property.getValue());
|
||||
addChangeListener(new ChangeListener() {
|
||||
|
||||
setLayout(new FlowLayout());
|
||||
|
||||
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
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
property.setChanged(true);
|
||||
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()) {
|
||||
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.weightx = 0;
|
||||
gbc.insets = new Insets(4, 2, 2, 2);
|
||||
gbc.anchor = GridBagConstraints.WEST;
|
||||
editorPanel.add(new JLabel(property.getName() + ": "), gbc);
|
||||
|
||||
gbc.gridx = 1;
|
||||
|
||||
@@ -1420,7 +1420,11 @@
|
||||
</org.diylc.appframework.update.Change>
|
||||
<org.diylc.appframework.update.Change>
|
||||
<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>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
|
||||
Reference in New Issue
Block a user