|
26 | 26 | import java.awt.Color; |
27 | 27 | import java.awt.Desktop; |
28 | 28 | import java.awt.Dimension; |
| 29 | +import java.awt.event.ActionEvent; |
29 | 30 | import java.awt.event.ComponentAdapter; |
30 | 31 | import java.awt.event.ComponentEvent; |
31 | 32 | import java.awt.image.BufferedImage; |
|
38 | 39 | import java.util.Properties; |
39 | 40 |
|
40 | 41 | import javax.imageio.ImageIO; |
| 42 | +import javax.swing.AbstractAction; |
41 | 43 | import javax.swing.ButtonGroup; |
42 | 44 | import javax.swing.ImageIcon; |
43 | 45 | import javax.swing.JButton; |
44 | 46 | import javax.swing.JCheckBoxMenuItem; |
45 | 47 | import javax.swing.JColorChooser; |
46 | 48 | import javax.swing.JComboBox; |
| 49 | +import javax.swing.JComponent; |
47 | 50 | import javax.swing.JDesktopPane; |
48 | 51 | import javax.swing.JFileChooser; |
49 | 52 | import javax.swing.JFrame; |
@@ -343,6 +346,25 @@ public void componentResized(ComponentEvent ce) { |
343 | 346 | } |
344 | 347 | }); |
345 | 348 |
|
| 349 | + // Setting Keybinding for movement |
| 350 | + // Keybindings for movement and actions |
| 351 | + bindAction(ifrmPlot, "left", "LEFT", pv::moveLeft); |
| 352 | + bindAction(ifrmPlot, "right", "RIGHT", pv::moveRight); |
| 353 | + bindAction(ifrmPlot, "up", "UP", pv::moveUp); |
| 354 | + bindAction(ifrmPlot, "down", "DOWN", pv::moveDown); |
| 355 | + |
| 356 | + bindAction(ifrmPlot, "plus", "J", pv::zoomIn); |
| 357 | + bindAction(ifrmPlot, "minus", "F", pv::zoomOut); |
| 358 | + bindAction(ifrmPlot, "splus", "H", pv::smallZoomIn); |
| 359 | + bindAction(ifrmPlot, "sminus", "G", pv::smallZoomOut); |
| 360 | + |
| 361 | + bindAction(ifrmPlot, "rotAp", "Q", pv::rotateXPlus); |
| 362 | + bindAction(ifrmPlot, "rotAm", "A", pv::rotateXMinus); |
| 363 | + bindAction(ifrmPlot, "rotBp", "W", pv::rotateYPlus); |
| 364 | + bindAction(ifrmPlot, "rotBm", "S", pv::rotateYMinus); |
| 365 | + bindAction(ifrmPlot, "rotCp", "E", pv::rotateZPlus); |
| 366 | + bindAction(ifrmPlot, "rotCm", "D", pv::rotateZMinus); |
| 367 | + |
346 | 368 | JToolBar toolbar = new JToolBar(); |
347 | 369 |
|
348 | 370 | // --- Zoom Section --- |
@@ -488,6 +510,17 @@ public void componentResized(ComponentEvent ce) { |
488 | 510 | setExtendedState(JFrame.MAXIMIZED_BOTH); |
489 | 511 | } |
490 | 512 |
|
| 513 | + /* Actions */ |
| 514 | + private void bindAction(JComponent control, String actionName, String hotkey, Runnable action) { |
| 515 | + control.getInputMap().put(KeyStroke.getKeyStroke(hotkey), actionName); |
| 516 | + control.getActionMap().put(actionName, new AbstractAction() { |
| 517 | + @Override |
| 518 | + public void actionPerformed(ActionEvent arg0) { |
| 519 | + action.run(); |
| 520 | + } |
| 521 | + }); |
| 522 | + } |
| 523 | + |
491 | 524 | /* Menu Actions */ |
492 | 525 | public void saveImage() { |
493 | 526 | var files = new JFileChooser(); |
|
0 commit comments