// Keyboard action on the image viewer
// full / normal view
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "esc");
getActionMap().put("esc", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
Main.m_mainFrame.toggleView();
}
});
// Zoom in / out
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, InputEvent.CTRL_DOWN_MASK), "ctrl_+");
getActionMap().put("ctrl_+", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
setZoomUp();
}
});
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, InputEvent.CTRL_DOWN_MASK), "ctrl_-");
getActionMap().put("ctrl_-", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
setZoomDown();
}
});
// fit
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_DOWN_MASK), "ctrl_enter");
getActionMap().put("ctrl_enter", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
resetZoom();
}
});
// 100%
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_MULTIPLY, InputEvent.CTRL_DOWN_MASK), "ctrl_100%");
getActionMap().put("ctrl_100%", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
setZoom(1.0f);
}
});
// 50%
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DIVIDE, InputEvent.CTRL_DOWN_MASK), "ctrl_50%");
getActionMap().put("ctrl_50%", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
setZoom(.5f);
}
});
// Scrolling
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD2, 0), "ctrl_scrolldown");
getActionMap().put("ctrl_scrolldown", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
scrollImg(0, Main.m_settings.getImgScrollDelta());
}
});
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD8, 0), "ctrl_scrollup");
getActionMap().put("ctrl_scrollup", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
scrollImg(0, -Main.m_settings.getImgScrollDelta());
}
});
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD4, 0), "ctrl_scrollleft");
getActionMap().put("ctrl_scrollleft", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
scrollImg(-Main.m_settings.getImgScrollDelta(), 0);
}
});
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD6, 0), "ctrl_scrollright");
getActionMap().put("ctrl_scrollright", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
scrollImg(Main.m_settings.getImgScrollDelta(), 0);
}
});
// diagonal
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD7, 0), "ctrl_scrollupleft");
getActionMap().put("ctrl_scrollupleft", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
scrollImg(-Main.m_settings.getImgScrollDelta(), -Main.m_settings.getImgScrollDelta());
}
});
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD9, 0), "ctrl_scrollupright");
getActionMap().put("ctrl_scrollupright", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
scrollImg(Main.m_settings.getImgScrollDelta(), -Main.m_settings.getImgScrollDelta());
}
});
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD1, 0), "ctrl_scrolldownleft");
getActionMap().put("ctrl_scrolldownleft", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
scrollImg(-Main.m_settings.getImgScrollDelta(), Main.m_settings.getImgScrollDelta());
}
});
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD3, 0), "ctrl_scrolldownright");
getActionMap().put("ctrl_scrolldownright", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
scrollImg(Main.m_settings.getImgScrollDelta(), Main.m_settings.getImgScrollDelta());
}
});
// special
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD5, 0), "ctrl_scrollcenter");
getActionMap().put("ctrl_scrollcenter", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
{
Dimension size = getSize();
JViewport viewPort = (JViewport)getParent();
assert viewPort != null;
Dimension dimView = viewPort.getExtentSize();
setViewPosition(new Point((int)(size.width/2 - dimView.width/2), (int)(size.height/2 - dimView.height)));
}
}
});
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_NUMPAD0, 0), "ctrl_scrollhome");
getActionMap().put("ctrl_scrollhome", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
setViewPosition(new Point(0, 0));
}
});
getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DECIMAL, 0), "ctrl_scrollend");
getActionMap().put("ctrl_scrollend", new AbstractAction()
{
public void actionPerformed(ActionEvent event)
{
if (m_zoom != 0.0f)
{