KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SnowMailClient > keyboard > UnicodeSearchDialog


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 /** dialog to search a key in the unicode chars
18 */

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      // south
33
closeControlPanel = new CloseControlPanel(this, true, true, Language.translate("Use selected characters"));
34      getContentPane().add(closeControlPanel, BorderLayout.SOUTH);
35
36      // center
37
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      // north
54
AdvancedSearchPanel searchPanel = new AdvancedSearchPanel("Search: ", null, stm, true);
55      //searchPanel.setAdvancedMode(true);
56
getContentPane().add(searchPanel, BorderLayout.NORTH);
57
58      setSize(500, 500);
59      setLocationRelativeTo(owner);
60      setVisible(true);
61
62   } // Constructor
63

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 JavaDoc[] COLUMN_NAMES = new String JavaDoc[]{
78                  //"representable",
79
"intcode",
80                  "char",
81                  //"name",
82
"unicode block"
83                  //"type"
84
// "lowercase", "uppercase", "titlecase"
85
};
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 JavaDoc 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        //System.out.println("set limit to "+lim);
110
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 JavaDoc 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 JavaDoc ub = Character.UnicodeBlock.of(c); // in 1.5, can be applied to INT
140
if(ub==null) return "" ;
141          return ""+ub ;
142        }
143        return "?";
144      }
145   }
146
147
148
149   public static void main(String JavaDoc[] a)
150   {
151      KeyboardDialog.main(null);
152   }
153
154 } // UnicodeSearchDialog
Popular Tags