Skip to content

Commit

Permalink
Add page up/page down as alternate shortcut for previous/next glyph; c…
Browse files Browse the repository at this point in the history
…lose #33
  • Loading branch information
RebeccaRGB committed Sep 26, 2023
1 parent a712b7c commit 13966bc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public BitmapEditFrame(BitmapFont font, GlyphLocator<BitmapFontGlyph> locator, G
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
GlyphEditFrame.addActions(this, panel, BitmapFontGlyph.class);
panel.getGlyphComponent().requestFocusInWindow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public BitmapToolHandler getToolHandler() {
return toolHandler;
}

public void setGlyph(GlyphLocator<BitmapFontGlyph> locator) {
super.setGlyph(locator);
public void setGlyph(GlyphLocator<BitmapFontGlyph> locator, Class<BitmapFontGlyph> glyphClass) {
super.setGlyph(locator, glyphClass);
this.toolHandler.clearHistory();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package com.kreative.bitsnpicas.edit;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.KeyStroke;
import com.kreative.bitsnpicas.Font;
import com.kreative.bitsnpicas.FontGlyph;

Expand All @@ -19,5 +26,45 @@ public GlyphEditFrame(Class<G> glyphClass, Font<G> font, GlyphLocator<G> locator
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
GlyphEditFrame.addActions(this, panel, glyphClass);
panel.getGlyphComponent().requestFocusInWindow();
}

public static <G extends FontGlyph> void addActions(final JFrame frame, final GlyphEditPanel<G> panel, final Class<G> glyphClass) {
InputMap im = frame.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "previousGlyph");
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "nextGlyph");
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, KeyEvent.SHIFT_MASK), "previousDefinedGlyph");
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, KeyEvent.SHIFT_MASK), "nextDefinedGlyph");

ActionMap am = frame.getRootPane().getActionMap();
am.put("previousGlyph", new AbstractAction() {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
panel.setGlyph(panel.getGlyphLocator().getPrevious(), glyphClass);
frame.setTitle(panel.getGlyphLocator().toString());
}
});
am.put("nextGlyph", new AbstractAction() {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
panel.setGlyph(panel.getGlyphLocator().getNext(), glyphClass);
frame.setTitle(panel.getGlyphLocator().toString());
}
});
am.put("previousDefinedGlyph", new AbstractAction() {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
panel.setGlyph(panel.getGlyphLocator().getPreviousDefined(), null);
frame.setTitle(panel.getGlyphLocator().toString());
}
});
am.put("nextDefinedGlyph", new AbstractAction() {
private static final long serialVersionUID = 1L;
public void actionPerformed(ActionEvent e) {
panel.setGlyph(panel.getGlyphLocator().getNextDefined(), null);
frame.setTitle(panel.getGlyphLocator().toString());
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,8 @@ public PreviousGlyphMenuItem(final Frame frame, final GlyphEditPanel<G> panel, f
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, CommonMenuItems.SHORTCUT_KEY));
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GlyphLocator<G> loc = panel.getGlyphLocator().getPrevious();
if (loc == null) return;
if (loc.getGlyph() == null) {
try {
G g = glyphClass.newInstance();
loc.setGlyph(g);
panel.getGlyphList().glyphRepertoireChanged();
} catch (Exception ex) {
return;
}
}
panel.setGlyph(loc);
frame.setTitle(loc.toString());
panel.setGlyph(panel.getGlyphLocator().getPrevious(), glyphClass);
frame.setTitle(panel.getGlyphLocator().toString());
}
});
}
Expand All @@ -159,19 +148,8 @@ public NextGlyphMenuItem(final Frame frame, final GlyphEditPanel<G> panel, final
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_CLOSE_BRACKET, CommonMenuItems.SHORTCUT_KEY));
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GlyphLocator<G> loc = panel.getGlyphLocator().getNext();
if (loc == null) return;
if (loc.getGlyph() == null) {
try {
G g = glyphClass.newInstance();
loc.setGlyph(g);
panel.getGlyphList().glyphRepertoireChanged();
} catch (Exception ex) {
return;
}
}
panel.setGlyph(loc);
frame.setTitle(loc.toString());
panel.setGlyph(panel.getGlyphLocator().getNext(), glyphClass);
frame.setTitle(panel.getGlyphLocator().toString());
}
});
}
Expand All @@ -184,10 +162,8 @@ public PreviousDefinedGlyphMenuItem(final Frame frame, final GlyphEditPanel<G> p
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_OPEN_BRACKET, CommonMenuItems.SHORTCUT_KEY | KeyEvent.SHIFT_MASK));
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GlyphLocator<G> loc = panel.getGlyphLocator().getPreviousDefined();
if (loc == null) return;
panel.setGlyph(loc);
frame.setTitle(loc.toString());
panel.setGlyph(panel.getGlyphLocator().getPreviousDefined(), null);
frame.setTitle(panel.getGlyphLocator().toString());
}
});
}
Expand All @@ -200,10 +176,8 @@ public NextDefinedGlyphMenuItem(final Frame frame, final GlyphEditPanel<G> panel
setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_CLOSE_BRACKET, CommonMenuItems.SHORTCUT_KEY | KeyEvent.SHIFT_MASK));
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
GlyphLocator<G> loc = panel.getGlyphLocator().getNextDefined();
if (loc == null) return;
panel.setGlyph(loc);
frame.setTitle(loc.toString());
panel.setGlyph(panel.getGlyphLocator().getNextDefined(), null);
frame.setTitle(panel.getGlyphLocator().toString());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,21 @@ public GlyphLocator<G> getGlyphLocator() {
return locator;
}

public void setGlyph(GlyphLocator<G> locator) {
this.glyphComponent.setGlyph(locator.getGlyphFont(), locator.getGlyph());
public void setGlyph(GlyphLocator<G> locator, Class<G> glyphClass) {
if (locator == null) return;
Font<G> font = locator.getGlyphFont();
G glyph = locator.getGlyph();
if (glyph == null) {
if (glyphClass == null) return;
try {
glyph = glyphClass.newInstance();
locator.setGlyph(glyph);
this.glyphList.glyphRepertoireChanged();
} catch (Exception ex) {
return;
}
}
this.glyphComponent.setGlyph(font, glyph);
this.locator = locator;
}
}

0 comments on commit 13966bc

Please sign in to comment.