1 package SnowMailClient.keyboard; 2 3 import snow.sortabletable.*; 4 import snow.utils.gui.*; 5 import snow.Language.Language; 6 7 import java.awt.*; 8 import java.awt.event.*; 9 import javax.swing.*; 10 import javax.swing.event.*; 11 import javax.swing.table.*; 12 import java.nio.charset.*; 13 import java.nio.*; 14 import java.util.*; 15 import java.io.*; 16 17 19 public class UnicodeSearchDialog extends JDialog 20 { 21 int charDisplayLimit = 8192; 22 final private UnicodeTableModel basicTableModel = new UnicodeTableModel(); 23 final private SortableTableModel stm = new SortableTableModel(basicTableModel, 1, true); 24 final private JTable table = new JTable(stm); 25 final private CloseControlPanel closeControlPanel; 26 27 28 public UnicodeSearchDialog(JDialog owner, int[] selCodes) 29 { 30 super(owner, "Unicode search", true); 31 32 closeControlPanel = new CloseControlPanel(this, true, true, Language.translate("Use selected characters")); 34 getContentPane().add(closeControlPanel, BorderLayout.SOUTH); 35 36 getContentPane().add( new JScrollPane(table), BorderLayout.CENTER ); 38 stm.installGUI(table); 39 basicTableModel.clearRowSelection(); 40 for(int i=0; i<selCodes.length; i++) 41 { 42 basicTableModel.setRowSelection(selCodes[i], true); 43 } 44 stm.restoreTableSelections(); 45 46 if(selCodes.length>0) 47 { 48 table.scrollRectToVisible( table.getCellRect(selCodes[0], 0, true) ); 49 } 50 51 52 53 AdvancedSearchPanel searchPanel = new AdvancedSearchPanel("Search: ", null, stm, true); 55 getContentPane().add(searchPanel, BorderLayout.NORTH); 57 58 setSize(500, 500); 59 setLocationRelativeTo(owner); 60 setVisible(true); 61 62 } 64 65 public boolean wasCancelled() { return closeControlPanel.getWasCancelled(); } 66 public int[] getSelectedCodes() 67 { 68 stm.storeTableSelection(); 69 return basicTableModel.getSelectedRows(); 70 } 71 72 73 class UnicodeTableModel extends FineGrainTableModel 74 { 75 private char[] representableCharsetChars = null; 76 77 String [] COLUMN_NAMES = new String []{ 78 "intcode", 80 "char", 81 "unicode block" 83 }; 86 87 int[] COLUMN_PREFERED_SIZES = new int[]{ 8,8, 16}; 88 public int getPreferredColumnWidth(int column) 89 { 90 if(column>=0 && column<COLUMN_PREFERED_SIZES.length) return COLUMN_PREFERED_SIZES[column]; 91 return -1; 92 } 93 94 public String getColumnName(int col) { return COLUMN_NAMES[col]; } 95 96 public int getColumnAlignment(int column) 97 { 98 if( column==2) return JLabel.LEFT; 99 return JLabel.CENTER; 100 } 101 102 103 104 public int getColumnCount() { return COLUMN_NAMES.length; } 105 public int getRowCount() { return charDisplayLimit; } 106 107 public void setDisplayLimit(int lim) 108 { 109 fireTableModelWillChange(); 111 charDisplayLimit = lim; 112 fireTableDataChanged(); 113 fireTableModelHasChanged(); 114 } 115 116 public void setCharset(Charset cs) 117 { 118 fireTableModelWillChange(); 119 byte[] bb = new byte[256]; 120 for(int i=0; i<256; i++) 121 { 122 bb[i] = (byte) i; 123 } 124 125 representableCharsetChars = cs.decode(ByteBuffer.wrap(bb)).toString().toCharArray(); 126 Arrays.sort(representableCharsetChars); 127 fireTableDataChanged(); 128 fireTableModelHasChanged(); 129 } 130 131 132 public Object getValueAt(int row, int col) 133 { 134 char c = (char) row; 135 if(col==0) return row; 136 if(col==1) return ""+c ; 137 if(col==2) 138 { 139 Character.UnicodeBlock ub = Character.UnicodeBlock.of(c); if(ub==null) return "" ; 141 return ""+ub ; 142 } 143 return "?"; 144 } 145 } 146 147 148 149 public static void main(String [] a) 150 { 151 KeyboardDialog.main(null); 152 } 153 154 } | Popular Tags |