forked from kreativekorp/bitsnpicas
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'kreativekorp:master' into master
- Loading branch information
Showing
30 changed files
with
1,736 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
main/java/BitsNPicas/src/com/kreative/bitsnpicas/edit/glmlicon/GLMLListCellRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
main/java/BitsNPicas/src/com/kreative/bitsnpicas/edit/glmlicon/GLMLResources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.