Skip to content

Commit

Permalink
Merge branch 'kreativekorp:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cooljeanius authored Nov 7, 2023
2 parents 11f2d83 + 8c20bb4 commit fd2463d
Show file tree
Hide file tree
Showing 30 changed files with 1,736 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public BitmapListFrame(SaveRoutine routine, BitmapFont font) {
makeUI();
}

public GlyphListPanel<BitmapFontGlyph> getPanel() {
return panel;
}

private void makeUI() {
setJMenuBar(mb);
setContentPane(panel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public GlyphListFrame(SaveRoutine routine, Font<G> font) {
makeUI();
}

public void makeUI() {
public GlyphListPanel<G> getPanel() {
return panel;
}

private void makeUI() {
setJMenuBar(mb);
setContentPane(panel);
pack();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.kreative.bitsnpicas.edit;

import java.awt.Container;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import javax.swing.JTree;
import javax.swing.JViewport;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
Expand Down Expand Up @@ -43,14 +46,45 @@ public GlyphListModel getSelectedModel() {
return ((GlyphListModelTreeNode)o).getModel();
}

public String getSelectedModelName() {
TreePath path = getSelectionPath();
if (path == null) return null;
Object o = path.getLastPathComponent();
if (!(o instanceof GlyphListModelTreeNode)) return null;
return ((GlyphListModelTreeNode)o).getModel().toString();
}

public void setSelectedModel(GlyphListModel model, boolean shouldScroll) {
Object root = getModel().getRoot();
if (!(root instanceof GlyphListModelTreeNode)) return;
GlyphListModelTreeNode r = (GlyphListModelTreeNode)root;
TreePath path = findGlyphListModel(model, r, new TreePath(r));
if (path != null) {
setSelectionPath(path);
if (shouldScroll) scrollPathToVisible(path);
if (path != null) setSelectionPath(path, shouldScroll);
}

public void setSelectedModelName(String name, boolean shouldScroll) {
Object root = getModel().getRoot();
if (!(root instanceof GlyphListModelTreeNode)) return;
GlyphListModelTreeNode r = (GlyphListModelTreeNode)root;
TreePath path = findGlyphListModelName(name, r, new TreePath(r));
if (path != null) setSelectionPath(path, shouldScroll);
}

private void setSelectionPath(TreePath path, boolean shouldScroll) {
setSelectionPath(path);
if (shouldScroll) {
scrollPathToVisible(path);
Container c = getParent();
while (c != null) {
if (c instanceof JViewport) {
JViewport port = (JViewport)c;
Point pos = port.getViewPosition();
pos.x = 0;
port.setViewPosition(pos);
break;
}
c = c.getParent();
}
}
}

Expand All @@ -63,13 +97,29 @@ private TreePath findGlyphListModel(GlyphListModel model, GlyphListModelTreeNode
return null;
}

private TreePath findGlyphListModelName(String name, GlyphListModelTreeNode node, TreePath parent) {
if (hasModelName(name, node)) return parent;
for (GlyphListModelTreeNode child : node.getChildren()) {
TreePath path = findGlyphListModelName(name, child, parent.pathByAddingChild(child));
if (path != null) return path;
}
return null;
}

private static boolean hasModel(GlyphListModel model, GlyphListModelTreeNode node) {
GlyphListModel other = node.getModel();
if (model == null) return (other == null);
if (other == null) return (model == null);
return model.equals(other);
}

private static boolean hasModelName(String name, GlyphListModelTreeNode node) {
GlyphListModel other = node.getModel();
if (name == null) return (other == null);
if (other == null) return (name == null);
return name.equals(other.toString());
}

private static class GlyphListModelRootNode extends GlyphListModelTreeNode {
public GlyphListModelRootNode(Font<?> font) {
super(null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public void glyphsChanged(GlyphList<G> gl, Font<G> font) {
im.put(KeyStroke.getKeyStroke("RIGHT"), "none");
}

public GlyphListModelList getModelList() {
return modelList;
}

public GlyphList<G> getGlyphList() {
return glyphList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.kreative.bitsnpicas.edit.glmlicon.GLMLListCellRenderer;
import com.kreative.unicode.data.EncodingList;
import com.kreative.unicode.data.GlyphList;

Expand All @@ -16,6 +17,7 @@ public BitmapExportEncodingPanel() {
this.generalEncoding = new JComboBox(EncodingList.instance().glyphLists().toArray());

generalEncoding.setEditable(false);
new GLMLListCellRenderer("encoding").apply(generalEncoding);
JPanel encodingInnerPanel = new JPanel(new BorderLayout(8, 8));
encodingInnerPanel.add(new JLabel("Encoding"), BorderLayout.LINE_START);
encodingInnerPanel.add(generalEncoding, BorderLayout.CENTER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import com.kreative.bitsnpicas.edit.glmlicon.GLMLListCellRenderer;
import com.kreative.unicode.data.EncodingList;
import com.kreative.unicode.data.GlyphList;

Expand Down Expand Up @@ -37,6 +38,8 @@ public BitmapExportFONTXPanel() {

singleByteEncoding.setEditable(false);
doubleByteEncoding.setEditable(false);
new GLMLListCellRenderer("encoding").apply(singleByteEncoding);
new GLMLListCellRenderer("encoding").apply(doubleByteEncoding);
singleByteEncoding.setSelectedItem(EncodingList.instance().getGlyphList("CP437"));
doubleByteEncoding.setSelectedItem(Charset.forName("CP943").displayName());
JPanel ep = new JPanel(new GridLayout(0, 1, 4, 4));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.swing.SpinnerNumberModel;
import com.kreative.bitsnpicas.IDGenerator;
import com.kreative.bitsnpicas.PointSizeGenerator;
import com.kreative.bitsnpicas.edit.glmlicon.GLMLListCellRenderer;
import com.kreative.unicode.data.EncodingList;
import com.kreative.unicode.data.GlyphList;

Expand Down Expand Up @@ -39,6 +40,7 @@ public BitmapExportMacPanel() {
macFontIdAuto.setSelected(true);
macFontSizeAutoAny.setSelected(true);
macEncoding.setEditable(false);
new GLMLListCellRenderer("encoding").apply(macEncoding);
ButtonGroup macFontIdGroup = new ButtonGroup();
macFontIdGroup.add(macFontIdAuto);
macFontIdGroup.add(macFontIdManual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import com.kreative.bitsnpicas.edit.glmlicon.GLMLListCellRenderer;
import com.kreative.unicode.data.EncodingList;
import com.kreative.unicode.data.GlyphList;

Expand Down Expand Up @@ -47,12 +48,14 @@ public BitmapExportPSFPanel() {
lea.addAll(EncodingList.instance().glyphLists());
this.lowEncoding = new JComboBox(lea.toArray());
this.lowEncoding.setEditable(false);
new GLMLListCellRenderer("encoding").apply(lowEncoding);

ArrayList<Object> hea = new ArrayList<Object>();
hea.add("U+0100 - U+01FF");
hea.addAll(EncodingList.instance().glyphLists());
this.highEncoding = new JComboBox(hea.toArray());
this.highEncoding.setEditable(false);
new GLMLListCellRenderer("encoding").apply(highEncoding);

this.useLowEncoding = new JCheckBox("Include $000-$0FF");
this.useHighEncoding = new JCheckBox("Include $100-$1FF");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.kreative.bitsnpicas.edit.glmlicon.GLMLListCellRenderer;
import com.kreative.unicode.data.EncodingList;
import com.kreative.unicode.data.GlyphList;

Expand All @@ -25,6 +26,7 @@ public BitmapExportU8MPanel() {
this.u8mLoadAddress = new JTextField("$A000");

u8mEncoding.setEditable(false);
new GLMLListCellRenderer("encoding").apply(u8mEncoding);
u8mLoadAddress.setEnabled(false);
JPanel u8mLabelPanel = new JPanel(new GridLayout(0, 1, 4, 4));
u8mLabelPanel.add(u8mHasLoadAddress);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.kreative.bitsnpicas.edit.glmlicon;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Image;
import javax.swing.BorderFactory;
import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import com.kreative.unicode.data.Encoding;
import com.kreative.unicode.data.GlyphList;

public class GLMLListCellRenderer extends DefaultListCellRenderer {
private static final long serialVersionUID = 1L;

private final String group;

public GLMLListCellRenderer() {
this.group = null;
}

public GLMLListCellRenderer(String group) {
this.group = group;
}

public void apply(JComboBox c) {
Dimension d1 = c.getPreferredSize();
c.setRenderer(this);
Dimension d2 = c.getPreferredSize();
int width = Math.max(d1.width, d2.width);
int height = Math.max(d1.height, d2.height);
c.setPreferredSize(new Dimension(width, height));
}

public Component getListCellRendererComponent(
JList list, Object value, int index, boolean sel, boolean focus
) {
Component c = super.getListCellRendererComponent(list, value, index, sel, focus);
if (c instanceof JLabel) {
JLabel label = (JLabel)c;
label.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8));
label.setIcon(new ImageIcon(getImageForListCell(value)));
}
return c;
}

private Image getImageForListCell(Object value) {
if (value instanceof GlyphList) {
String group = (this.group != null) ? this.group : "glyphlist";
String name = ((GlyphList)value).getName();
return GLMLResources.getImage(group, name);
}
if (value instanceof Encoding) {
String group = (this.group != null) ? this.group : "encoding";
String name = ((Encoding)value).getName();
return GLMLResources.getImage(group, name);
}
return GLMLResources.getImage(this.group, value.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.kreative.bitsnpicas.edit.glmlicon;

import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import javax.imageio.ImageIO;

public class GLMLResources {
public static Image getImage(String group, String name) {
if (group != null && name != null) {
if (group.equals("subtable")) {
try {
int v = Integer.parseInt(name.substring(name.length() - 2), 16);
if (subtableImages[v] != null) return subtableImages[v];
} catch (NumberFormatException nfe) {}
}
Map<String,Image> submap = mappedImages.get(group);
if (submap != null) {
Image image = submap.get(name);
if (image != null) return image;
}
}
return getImage("unknown.png");
}

private static final Map<String,Image> imageResources = new HashMap<String,Image>();
private static Image getImage(String name) {
Image image = imageResources.get(name);
if (image != null) return image;
URL res = GLMLResources.class.getResource(name);
if (res == null) return null;
image = Toolkit.getDefaultToolkit().createImage(res);
if (image == null) return null;
imageResources.put(name, image);
return image;
}

private static final Map<String,Map<String,Image>> mappedImages = new HashMap<String,Map<String,Image>>();
static {
Scanner index = new Scanner(GLMLResources.class.getResourceAsStream("index.txt"));
while (index.hasNextLine()) {
String[] line = index.nextLine().trim().split("\\s+", 3);
if (line.length != 3) continue;
Image image = getImage(line[0]);
if (image == null) continue;
Map<String,Image> submap = mappedImages.get(line[1]);
if (submap == null) mappedImages.put(line[1], (submap = new HashMap<String,Image>()));
submap.put(line[2], image);
}
index.close();
}

private static final BufferedImage[] subtableImages = new BufferedImage[256];
static {
try {
BufferedImage ss = ImageIO.read(GLMLResources.class.getResource("subtable.png"));
int cw = ss.getWidth() / 32;
int ch = ss.getHeight();
int[] rgb = new int[cw * ch];
for (int v0 = 0; v0 < 16; v0++) {
for (int v1 = 0; v1 < 16; v1++) {
BufferedImage ci = new BufferedImage(cw*2, ch, BufferedImage.TYPE_INT_ARGB);
ss.getRGB((v0*2) * cw, 0, cw, ch, rgb, 0, cw);
ci.setRGB(0, 0, cw, ch, rgb, 0, cw);
ss.getRGB((v1*2+1) * cw, 0, cw, ch, rgb, 0, cw);
ci.setRGB(cw, 0, cw, ch, rgb, 0, cw);
subtableImages[(v0 << 4) | v1] = ci;
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit fd2463d

Please sign in to comment.