Faster component placement, auto-focus on "Value" box

This commit is contained in:
bancika
2012-08-17 12:56:35 +00:00
parent a25d43b710
commit 4522d9aeb5
5 changed files with 59 additions and 17 deletions
@@ -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,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();
@@ -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
@@ -658,6 +658,10 @@
<changeType>IMPROVEMENT</changeType>
<description>Control number of "Recently Used" items from config.properties</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Faster component placement, auto-focus on "Value" box</description>
</org.diylc.appframework.update.Change>
</changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
</org.diylc.appframework.update.Version>