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.Container;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.KeyListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@@ -93,4 +94,20 @@ public class MeasureEditor extends Container {
e.printStackTrace(); 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 { 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; private static final long serialVersionUID = 1L;
@@ -36,9 +37,12 @@ public class PropertyEditorDialog extends ButtonDialog {
private List<PropertyWrapper> properties; private List<PropertyWrapper> properties;
private Set<PropertyWrapper> defaultedProperties; private Set<PropertyWrapper> defaultedProperties;
private Component componentToFocus = null;
public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties, String title) { public PropertyEditorDialog(JFrame owner, List<PropertyWrapper> properties,
super(owner, title, new String[] { ButtonDialog.OK, ButtonDialog.CANCEL }); String title) {
super(owner, title,
new String[] { ButtonDialog.OK, ButtonDialog.CANCEL });
LOG.debug("Creating property editor for: " + properties); LOG.debug("Creating property editor for: " + properties);
@@ -73,8 +77,9 @@ public class PropertyEditorDialog extends ButtonDialog {
try { try {
property.getValidator().validate(property.getValue()); property.getValidator().validate(property.getValue());
} catch (ValidationException ve) { } catch (ValidationException ve) {
JOptionPane.showMessageDialog(PropertyEditorDialog.this, "Input error for \"" JOptionPane.showMessageDialog(PropertyEditorDialog.this,
+ property.getName() + "\": " + ve.getMessage(), "Error", "Input error for \"" + property.getName() + "\": "
+ ve.getMessage(), "Error",
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
return false; return false;
} }
@@ -126,6 +131,11 @@ public class PropertyEditorDialog extends ButtonDialog {
editorPanel.add(createDefaultCheckBox(property), gbc); editorPanel.add(createDefaultCheckBox(property), gbc);
} }
// Make value field focused
if (property.getName().equalsIgnoreCase("value")) {
componentToFocus = editor;
}
gbc.gridy++; gbc.gridy++;
} }
@@ -153,8 +163,10 @@ public class PropertyEditorDialog extends ButtonDialog {
return defaultedProperties; return defaultedProperties;
} }
public static boolean showFor(JFrame owner, List<PropertyWrapper> properties, String title) { public static boolean showFor(JFrame owner,
PropertyEditorDialog editor = new PropertyEditorDialog(owner, properties, title); List<PropertyWrapper> properties, String title) {
PropertyEditorDialog editor = new PropertyEditorDialog(owner,
properties, title);
editor.setVisible(true); editor.setVisible(true);
if (OK.equals(editor.getSelectedButtonCaption())) { if (OK.equals(editor.getSelectedButtonCaption())) {
return true; return true;
@@ -162,6 +174,15 @@ public class PropertyEditorDialog extends ButtonDialog {
return false; return false;
} }
@Override
public void setVisible(boolean b) {
if (b && componentToFocus != null) {
componentToFocus.requestFocusInWindow();
componentToFocus = null;
}
super.setVisible(b);
}
@Override @Override
protected JComponent getMainComponent() { protected JComponent getMainComponent() {
return createEditorFields(); return createEditorFields();
@@ -182,16 +182,16 @@ class CanvasPanel extends JComponent implements Autoscroll {
.isAltDown()); .isAltDown());
} }
}); });
addMouseListener(new MouseAdapter() { // addMouseListener(new MouseAdapter() {
//
@Override // @Override
public void mouseClicked(MouseEvent e) { // public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) { // if (e.getButton() == MouseEvent.BUTTON1) {
plugInPort.mouseClicked(e.getPoint(), e.getButton(), e.isControlDown(), e.isShiftDown(), e // plugInPort.mouseClicked(e.getPoint(), e.getButton(), e.isControlDown(), e.isShiftDown(), e
.isAltDown(), e.getClickCount()); // .isAltDown(), e.getClickCount());
} // }
} // }
}); // });
} }
// Autoscroll // Autoscroll
@@ -658,6 +658,10 @@
<changeType>IMPROVEMENT</changeType> <changeType>IMPROVEMENT</changeType>
<description>Control number of "Recently Used" items from config.properties</description> <description>Control number of "Recently Used" items from config.properties</description>
</org.diylc.appframework.update.Change> </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> </changes>
<url>http://code.google.com/p/diy-layout-creator/downloads/list</url> <url>http://code.google.com/p/diy-layout-creator/downloads/list</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>