mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-12 02:02:16 +10:00
Faster component placement, auto-focus on "Value" box
This commit is contained in:
+17
@@ -5,6 +5,7 @@ import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@@ -93,4 +94,20 @@ public class MeasureEditor extends Container {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestFocus() {
|
||||
this.valueField.requestFocus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requestFocusInWindow() {
|
||||
return this.valueField.requestFocusInWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void addKeyListener(KeyListener l) {
|
||||
this.valueField.addKeyListener(l);
|
||||
this.unitBox.addKeyListener(l);
|
||||
}
|
||||
}
|
||||
|
||||
+28
-7
@@ -28,7 +28,8 @@ import org.diylc.swingframework.ButtonDialog;
|
||||
|
||||
public class PropertyEditorDialog extends ButtonDialog {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(PropertyEditorDialog.class);
|
||||
private static final Logger LOG = Logger
|
||||
.getLogger(PropertyEditorDialog.class);
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -36,9 +37,12 @@ public class PropertyEditorDialog extends ButtonDialog {
|
||||
|
||||
private List<PropertyWrapper> properties;
|
||||
private Set<PropertyWrapper> defaultedProperties;
|
||||
private Component componentToFocus = null;
|
||||
|
||||
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title) {
|
||||
super(owner, title, new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
|
||||
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties,
|
||||
String title) {
|
||||
super(owner, title,
|
||||
new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
|
||||
|
||||
LOG.debug("Creating property editor for: " + properties);
|
||||
|
||||
@@ -73,8 +77,9 @@ public class PropertyEditorDialog extends ButtonDialog {
|
||||
try {
|
||||
property.getValidator().validate(property.getValue());
|
||||
} catch (ValidationException ve) {
|
||||
JOptionPane.showMessageDialog(PropertyEditorDialog.this, "Input error for \""
|
||||
+ property.getName() + "\": " + ve.getMessage(), "Error",
|
||||
JOptionPane.showMessageDialog(PropertyEditorDialog.this,
|
||||
"Input error for \"" + property.getName() + "\": "
|
||||
+ ve.getMessage(), "Error",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}
|
||||
@@ -126,6 +131,11 @@ public class PropertyEditorDialog extends ButtonDialog {
|
||||
editorPanel.add(createDefaultCheckBox(property), gbc);
|
||||
}
|
||||
|
||||
// Make value field focused
|
||||
if (property.getName().equalsIgnoreCase("value")) {
|
||||
componentToFocus = editor;
|
||||
}
|
||||
|
||||
gbc.gridy++;
|
||||
}
|
||||
|
||||
@@ -153,8 +163,10 @@ public class PropertyEditorDialog extends ButtonDialog {
|
||||
return defaultedProperties;
|
||||
}
|
||||
|
||||
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties, String title) {
|
||||
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title);
|
||||
public static boolean showFor(JFrame owner,
|
||||
List<PropertyWrapper> properties, String title) {
|
||||
PropertyEditorDialog editor = new PropertyEditorDialog(owner,
|
||||
properties, title);
|
||||
editor.setVisible(true);
|
||||
if (OK.equals(editor.getSelectedButtonCaption())) {
|
||||
return true;
|
||||
@@ -162,6 +174,15 @@ public class PropertyEditorDialog extends ButtonDialog {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean b) {
|
||||
if (b && componentToFocus != null) {
|
||||
componentToFocus.requestFocusInWindow();
|
||||
componentToFocus = null;
|
||||
}
|
||||
super.setVisible(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent getMainComponent() {
|
||||
return createEditorFields();
|
||||
|
||||
+10
-10
@@ -182,16 +182,16 @@ class CanvasPanel extends JComponent implements Autoscroll {
|
||||
.isAltDown());
|
||||
}
|
||||
});
|
||||
addMouseListener(new MouseAdapter() {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
plugInPort.mouseClicked(e.getPoint(), e.getButton(), e.isControlDown(), e.isShiftDown(), e
|
||||
.isAltDown(), e.getClickCount());
|
||||
}
|
||||
}
|
||||
});
|
||||
// addMouseListener(new MouseAdapter() {
|
||||
//
|
||||
// @Override
|
||||
// public void mouseClicked(MouseEvent e) {
|
||||
// if (e.getButton() == MouseEvent.BUTTON1) {
|
||||
// plugInPort.mouseClicked(e.getPoint(), e.getButton(), e.isControlDown(), e.isShiftDown(), e
|
||||
// .isAltDown(), e.getClickCount());
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
// Autoscroll
|
||||
|
||||
Reference in New Issue
Block a user