mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Tilde to repeat last added component
This commit is contained in:
@@ -21,6 +21,7 @@ import java.awt.image.VolatileImage;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -101,7 +102,10 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
}
|
||||
|
||||
private void initializeActions() {
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_QUOTE, 0), "repeatLast");
|
||||
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "clearSlot");
|
||||
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
final int x = i;
|
||||
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F1 + i - 1, 0),
|
||||
@@ -126,6 +130,32 @@ public class CanvasPanel extends JComponent implements Autoscroll {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(null, null);
|
||||
}
|
||||
});
|
||||
|
||||
getActionMap().put("repeatLast", new AbstractAction() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<String> recent =
|
||||
(List<String>) ConfigurationManager.getInstance().readObject(IPlugInPort.RECENT_COMPONENTS_KEY, null);
|
||||
if (recent != null && !recent.isEmpty()) {
|
||||
String clazz = recent.get(0);
|
||||
Map<String, List<ComponentType>> componentTypes = CanvasPanel.this.plugInPort.getComponentTypes();
|
||||
for (Map.Entry<String, List<ComponentType>> entry : componentTypes.entrySet()) {
|
||||
for (ComponentType type : entry.getValue()) {
|
||||
if (type.getInstanceClass().getCanonicalName().equals(clazz)) {
|
||||
CanvasPanel.this.plugInPort.setNewComponentTypeSlot(type, null);
|
||||
// hack: fake mouse movement to repaint
|
||||
CanvasPanel.this.plugInPort.mouseMoved(getMousePosition(), false, false, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.Format;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
Reference in New Issue
Block a user