Skip to content

Commit

Permalink
Double-click to open subtable
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaRGB committed Aug 16, 2022
1 parent aa2f324 commit 3fcbfba
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
public class GlyphList<G extends FontGlyph> extends JComponent implements Scrollable {
private static final long serialVersionUID = 1L;
private static final int LABEL_HEIGHT = 18;
private static final Color SUBTABLE_BG = new Color(0xFFAA00);
private static final Color SUBTABLE_SELBG = new Color(0xCC7700);

private final FontMapController fontMap;
private final Font<G> font;
Expand Down Expand Up @@ -177,6 +179,10 @@ public void selectAll() {
repaint();
}

public SortedSet<Integer> getSelectedIndices() {
return selection.toSet();
}

public void setSelectedIndices(Collection<Integer> indices, boolean shouldScroll) {
selection.clear();
int n = model.getCellCount();
Expand Down Expand Up @@ -299,22 +305,25 @@ protected void paintComponent(Graphics g) {
} else {
Integer marker = model.getCodePoint(i);
if (marker != null) {
Color bg, fg;
Color selbg, bg, fg;
String ms;
switch (marker.intValue()) {
case GlyphListModelList.SEQUENCE_MARKER:
selbg = Color.gray;
bg = Color.lightGray;
fg = Color.black;
label = "Sequence";
ms = Integer.toHexString(0xFF00 | i).substring(2).toUpperCase();
break;
case GlyphListModelList.SUBTABLE_MARKER:
bg = Color.orange;
selbg = SUBTABLE_SELBG;
bg = SUBTABLE_BG;
fg = Color.black;
label = "Subtable";
ms = Integer.toHexString(0xFF00 | i).substring(2).toUpperCase();
break;
case GlyphListModelList.UNDEFINED_MARKER:
selbg = Color.black;
bg = Color.darkGray;
fg = Color.white;
label = "Undefined";
Expand All @@ -326,6 +335,7 @@ protected void paintComponent(Graphics g) {
if (ch0 < 0x20 || ch0 > 0xFFFD || ch1 < 0x20 || ch1 > 0xFFFD) continue;
String cs0 = Integer.toHexString(0xFF0000 | ch0).substring(2).toUpperCase();
String cs1 = Integer.toHexString(0xFF0000 | ch1).substring(2).toUpperCase();
selbg = Color.gray;
bg = Color.lightGray;
fg = Color.black;
label = cs0 + "." + cs1;
Expand All @@ -336,7 +346,7 @@ protected void paintComponent(Graphics g) {
labelAntiAlias = (Resources.PSNAME_FONT != null) ? false : antiAlias;
paintCellBackground(g, bg, x1, x2, y);
paintCellLabel(g, bg, fg, label, labelFont, labelAntiAlias, x1, x2, y, lbuf);
paintCellMarker(g, bg, fg, ms, markerFont, antiAlias, x1, x2, y, gbuf);
paintCellMarker(g, (sel.contains(i) ? selbg : bg), fg, ms, markerFont, antiAlias, x1, x2, y, gbuf);
}
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.util.List;
import java.util.SortedSet;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JViewport;
import javax.swing.KeyStroke;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
import com.kreative.bitsnpicas.Font;
import com.kreative.bitsnpicas.FontGlyph;
import com.kreative.bitsnpicas.edit.GlyphListModelList.GlyphListModelTreeNode;

public class GlyphListPanel<G extends FontGlyph> extends JPanel {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -52,8 +59,41 @@ public void valueChanged(TreeSelectionEvent e) {
glyphList.addGlyphListListener(new GlyphListListener<G>() {
public void selectionChanged(GlyphList<G> gl, Font<G> font) {}
public void selectionOpened(GlyphList<G> gl, Font<G> font) {
for (GlyphLocator<G> loc : gl.getSelection()) {
Main.openGlyph(font, loc, gl, sm);
List<GlyphLocator<G>> selectedGlyphs = gl.getSelection();
if (
(selectedGlyphs.size() < 5) ||
(JOptionPane.showConfirmDialog(
GlyphListPanel.this,
"Are you sure you want to edit " + selectedGlyphs.size() + " glyphs?",
"Edit Glyphs",
JOptionPane.OK_CANCEL_OPTION
) == JOptionPane.OK_OPTION)
) {
for (GlyphLocator<G> loc : selectedGlyphs) {
Main.openGlyph(font, loc, gl, sm);
}
}
SortedSet<Integer> selectedIndices = gl.getSelectedIndices();
if (selectedIndices.size() == 1) {
int i = selectedIndices.first();
Integer cp = gl.getModel().getCodePoint(i);
if (cp != null && cp.intValue() == GlyphListModelList.SUBTABLE_MARKER) {
String name = "Subtable " + Integer.toHexString(0xFF00 | i).substring(2).toUpperCase();
TreePath path = modelList.getSelectionPath();
GlyphListModelTreeNode node = (GlyphListModelTreeNode)path.getLastPathComponent();
for (GlyphListModelTreeNode child : node.getChildren()) {
if (name.equals(child.toString())) {
path = path.pathByAddingChild(child);
modelList.setSelectionPath(path);
modelList.scrollPathToVisible(path);
JViewport vp = modelPane.getViewport();
Point p = vp.getViewPosition();
p.x = 0;
vp.setViewPosition(p);
return;
}
}
}
}
}
public void metricsChanged(GlyphList<G> gl, Font<G> font) {
Expand Down

0 comments on commit 3fcbfba

Please sign in to comment.