Neujahrs-Geschenk
-
import java.awt.*; public class UnicodeBrowser { public static void main (String[] args) { new UnicodeBrowserFrame (true).show (); } } class MyMenu extends MenuItem { Menu menu; MyMenu (Menu amenu, String label) { super (label); menu = amenu; } } class UnicodeBrowserFrame extends Frame { static String hex = "0123456789abcdef"; Toolkit toolkit = Toolkit.getDefaultToolkit (); boolean canexit; Menu mfile; MyMenu mffirst; MyMenu mfnext; MyMenu mfprev; MyMenu mflast; MyMenu mfnonn; MyMenu mfquit; Menu mfont; Font labfont; FontMetrics labfm; Font medfont; FontMetrics medfm; String disname; Font disfont = null; int dissize; FontMetrics disfm; FontMetrics trivfm; int trivwid; UnicodeBrowserCanvas[] bcs = new UnicodeBrowserCanvas[256]; UnicodeBrowserTd td; UnicodeBrowserDisplay bd; int page; UnicodeBrowserFrame (boolean acanexit) { super ("Unicode Browser"); canexit = acanexit; resize (635,420); addNotify (); MenuBar mb = new MenuBar (); mfile = new Menu ("File"); mfile.add (mffirst = new MyMenu (mfile,"First Code Page")); mfile.add (mfnext = new MyMenu (mfile,"Next Code Page" )); mfile.add (mfprev = new MyMenu (mfile,"Previous Code Page")); mfile.add (mflast = new MyMenu (mfile,"Last Code Page")); mfile.addSeparator (); mfile.add (mfnonn = new MyMenu (mfile,"Next Non-Null Code Page")); mfile.addSeparator (); if (canexit) mfile.add (mfquit = new MyMenu (mfile,"Quit")); else mfile.add (mfquit = new MyMenu (mfile,"Close")); mb.add (mfile); mfont = new Menu ("Font"); String[] fonts = toolkit.getFontList (); for (int i=0; i<fonts.length; i++) mfont.add ( new MyMenu (mfont,fonts[i])); mb.add (mfont); setMenuBar (mb); medfont = getGraphics ().getFont (); medfm = toolkit.getFontMetrics (medfont); disname = medfont.getName (); labfont = new Font (disname,0,medfont.getSize ()-2); labfm = toolkit.getFontMetrics (labfont); Panel pan = new Panel (); pan.setLayout ( new GridLayout (16,16) ); for (int i=0; i<16; i++) for (int j=0; j<16; j++) { int code = 16*i + j; UnicodeBrowserCanvas newbc = new UnicodeBrowserCanvas (this,code); pan.add (newbc); bcs[code] = newbc; } setLayout ( new BorderLayout () ); add ("North",td = new UnicodeBrowserTd (this)); add ("South",bd = new UnicodeBrowserDisplay (this)); add ("Center",pan); page = 0; } public boolean handleEvent (Event evt) { if ( (Event.WINDOW_DESTROY==evt.id) && (this==evt.target) ) { quit (); } return(super.handleEvent (evt)); } public void redraw () { td.paint (td.getGraphics ()); bd.paint (bd.getGraphics ()); for (int i=0; i<256; i++) bcs[i].paint (bcs[i].getGraphics ()); } public boolean action (Event evt, Object obj) { MyMenu item = (MyMenu) evt.target; if ( mfile == item.menu ) { if ( mffirst == item ) { page = 0; redraw (); } else if ( mfnext == item ) { page++; redraw (); } else if ( mfprev == item ) { if (page > 0) page--; redraw (); } else if ( mflast == item ) { page = 255; redraw (); } else if ( mfnonn == item ) { } else if ( mfquit == item ) { quit (); } return true; } else if ( mfont == item.menu ) { disname = (String) obj; newfont (); redraw (); return true; } return false; } void quit () { if (canexit) System.exit (0); else dispose (); } void newfont () { // System.err.println( // "newfont: dissize = " + dissize + // " frame_height = " + size().height + // " frame_width = " + size().width); disfont = new Font (disname,0,dissize); disfm = toolkit.getFontMetrics (disfont); trivfm = toolkit.getFontMetrics (new Font (disname,0,50)); trivwid = trivfm.charWidth ('\uFEFF'); td.paint (td.getGraphics ()); } } class UnicodeBrowserCanvas extends Canvas { UnicodeBrowserFrame frame; int code; UnicodeBrowserCanvas (UnicodeBrowserFrame aUnicodeBrowserFrame, int acode) { frame = aUnicodeBrowserFrame; code = acode; } public void paint (Graphics g) { char codepoint = (char) ((frame.page<<8) | code); Dimension dim = size (); if ((dim.height-10) != frame.dissize) { frame.dissize = dim.height - 10; frame.newfont (); } g.clearRect (0,0,dim.width-1,dim.height-1); g.drawRect (0,0,dim.width-1,dim.height-1); if ( ('\uFEFF'==codepoint) || (frame.trivfm.charWidth (codepoint)!=frame.trivwid) ) { g.drawRect (2,2,dim.width-5,dim.height-5); } char[] data = new char[1]; data[0] = codepoint; int wid = frame.disfm.charsWidth (data,0,1); int masc = frame.disfm.getMaxAscent (); int mdes = frame.disfm.getMaxDescent (); int lwid = frame.labfm.getMaxAdvance (); int xpos = (dim.width+lwid-wid)/2; int ypos = (dim.height+masc-mdes)/2; g.setFont (frame.disfont); g.drawChars (data,0,1,xpos,ypos); g.setFont (frame.labfont); g.drawString (""+wid,4,dim.height-4); String point = "" + UnicodeBrowserFrame.hex.charAt ( (code>>4) & 0x0F ) + UnicodeBrowserFrame.hex.charAt ( code & 0x0F ); g.drawString (point,4,frame.labfm.getMaxAscent ()+4); } } class UnicodeBrowserTd extends Canvas { Dimension psize; UnicodeBrowserFrame frame; UnicodeBrowserTd (UnicodeBrowserFrame aUnicodeBrowserFrame) { frame = aUnicodeBrowserFrame; int hite = frame.medfm.getMaxAscent () + frame.medfm.getMaxDescent () + 5*frame.medfm.getLeading (); psize = new Dimension (600,hite); } public Dimension preferredSize () { // System.err.println("UnicodeBrowserTd.preferredSize returns "+psize.height); return psize; } public Dimension minimumSize () { // System.err.println("UnicodeBrowserTd.minimumSize returns "+psize.height); return psize; } public void paint (Graphics g) { Dimension dim = size (); g.clearRect (0,0,dim.width,dim.height); if ( null != frame.disfont ) { g.setColor (Color.black); g.setFont (frame.medfont); int ypos = frame.medfm.getLeading () + frame.medfm.getMaxAscent (); g.drawString (frame.disfont.toString (),10,ypos); } } } class UnicodeBrowserDisplay extends Canvas { Dimension psize; UnicodeBrowserFrame frame; UnicodeBrowserDisplay (UnicodeBrowserFrame aUnicodeBrowserFrame) { frame = aUnicodeBrowserFrame; int hite = frame.medfm.getMaxAscent () + frame.medfm.getMaxDescent () + 5*frame.medfm.getLeading (); psize = new Dimension (600,hite); } public Dimension preferredSize () { // System.err.println("UnicodeBrowserDisplay.preferredSize returns "+psize.height); return psize; } public Dimension minimumSize () { // System.err.println("UnicodeBrowserDisplay.minimumSize returns "+psize.height); return psize; } public void paint (Graphics g) { Dimension dim = size (); g.clearRect (0,0,dim.width,dim.height); g.setFont (frame.medfont); int ypos = frame.medfm.getLeading () + frame.medfm.getMaxAscent (); String data = "Code page " + UnicodeBrowserFrame.hex.charAt ( (frame.page>>4) & 0x0F ) + UnicodeBrowserFrame.hex.charAt ( frame.page & 0x0F ) + " " + upn (frame.page); g.drawString (data,10,ypos); } String upn (int page) { switch (page) { case 0x00: return "Basic Latin & Latin-1 Supplement"; case 0x01: return "Latin Extended A & Latin Extended B (cont)"; case 0x02: return "Latin Extended B (cont) & IPA & Spacing Mod"; case 0x03: return "Combining Diacriticals & Greek"; case 0x04: return "Cyrillic"; case 0x05: return "? & Armenian & Hebrew"; case 0x06: return "Arabic"; case 0x09: return "Devanagari & Bengali"; case 0x0A: return "Gurmukhi & Gujarati"; case 0x0B: return "Oriya & Tamil"; case 0x0C: return "Telugu & Kannada"; case 0x0D: return "Malayalam"; case 0x0E: return "Thai & Lao"; case 0x0F: return "Tibetan"; case 0x10: return "Georgian"; case 0x11: return "Hangul Jamo"; case 0x1E: return "Latin Extended Additional"; case 0x1F: return "Greek Extended"; case 0x20: return "Punct & Super & Sub & Currency & Combin"; case 0x21: return "Letterlikes & Number Forms & Arrows"; case 0x22: return "Mathematical Operators"; case 0x23: return "Miscellaneous Technical"; case 0x24: return "Control Picts & OCR & Enclosed Alpha"; case 0x25: return "Box Drawing & Block Elts & Geom Shapes"; case 0x26: return "Miscellaneous Symbols"; case 0x27: return "Dingbats"; case 0x30: return "CJK Symbols/Punct & Hiragana & Katakana"; case 0x31: return "Bopomofo & Hangul Compat & Kanbun"; case 0x32: return "Enclosed CJK Letters and Months"; case 0x33: return "CJK Compatability"; case 0x4E: case 0x4F: case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: case 0x58: case 0x59: case 0x5A: case 0x5B: case 0x5C: case 0x5D: case 0x5E: case 0x5F: case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: case 0x68: case 0x69: case 0x6A: case 0x6B: case 0x6C: case 0x6D: case 0x6E: case 0x6F: case 0x70: case 0x71: case 0x72: case 0x73: case 0x74: case 0x75: case 0x76: case 0x77: case 0x78: case 0x79: case 0x7A: case 0x7B: case 0x7C: case 0x7D: case 0x7E: case 0x7F: case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: case 0x88: case 0x89: case 0x8A: case 0x8B: case 0x8C: case 0x8D: case 0x8E: case 0x8F: case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: case 0x98: case 0x99: case 0x9A: case 0x9B: case 0x9C: case 0x9D: case 0x9E: case 0x9F: return "CJK Unified Ideographs"; case 0xAC: case 0xAD: case 0xAE: case 0xAF: case 0xB0: case 0xB1: case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: case 0xB7: case 0xB8: case 0xB9: case 0xBA: case 0xBB: case 0xBC: case 0xBD: case 0xBE: case 0xBF: case 0xC0: case 0xC1: case 0xC2: case 0xC3: case 0xC4: case 0xC5: case 0xC6: case 0xC7: case 0xC8: case 0xC9: case 0xCA: case 0xCB: case 0xCC: case 0xCD: case 0xCE: case 0xCF: case 0xD0: case 0xD1: case 0xD2: case 0xD3: case 0xD4: case 0xD5: case 0xD6: case 0xD7: return "Hangul Syllables"; case 0xD8: case 0xD9: case 0xDA: case 0xDB: return "High & Private Use High Surrogates"; case 0xDC: case 0xDD: case 0xDE: case 0xDF: return "Low Surrogates"; case 0xE0: case 0xE1: case 0xE2: case 0xE3: case 0xE4: case 0xE5: case 0xE6: case 0xE7: case 0xE8: case 0xE9: case 0xEA: case 0xEB: case 0xEC: case 0xED: case 0xEE: case 0xEF: case 0xF0: case 0xF1: case 0xF2: case 0xF3: case 0xF4: case 0xF5: case 0xF6: case 0xF7: case 0xF8: return "Private Use"; case 0xF9: case 0xFA: return "CJK Compatability Ideographs"; case 0xFB: return "Alphabetic Presentation & Arabic Pres."; case 0xFC: case 0xFD: return "Arabic Presentation Forms"; case 0xFE: return "Cmb Half & CJK Comp & Small Form & Arabic Pres"; case 0xFF: return "HalfWidth & FullWidth & Specials"; default: return "(Unknown Unicode Page " + page + ")"; } } }
-
a) Wo ist die Frage?
b) Warum Daumen-runter?
-
1.) Das war nur ein Geschenk von mir an euch zum Jahresanfang 2003. Daher gibt es keine Frage.
2.) Sollte eigentlich nen hoher Daumer sein. Hab mich verklickt.