1 | /* |
---|
2 | * Jeti, a Java Jabber client, Copyright (C) 2001 E.S. de Boer |
---|
3 | * |
---|
4 | * This program is free software; you can redistribute it and/or modify |
---|
5 | * it under the terms of the GNU General Public License as published by |
---|
6 | * the Free Software Foundation; either version 2 of the License, or |
---|
7 | * (at your option) any later version. |
---|
8 | * |
---|
9 | * This program is distributed in the hope that it will be useful, |
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | * GNU General Public License for more details. |
---|
13 | * |
---|
14 | * You should have received a copy of the GNU General Public License |
---|
15 | * along with this program; if not, write to the Free Software |
---|
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | * |
---|
18 | * For questions, comments etc, |
---|
19 | * use the website at http://jeti.jabberstudio.org |
---|
20 | * or mail/IM me at jeti@jabber.org |
---|
21 | * |
---|
22 | * Created on 17-jun-2005 |
---|
23 | */ |
---|
24 | |
---|
25 | package nu.fw.jeti.util; |
---|
26 | |
---|
27 | import java.awt.event.ActionEvent; |
---|
28 | import java.awt.event.KeyEvent; |
---|
29 | |
---|
30 | import javax.swing.*; |
---|
31 | |
---|
32 | /** |
---|
33 | * @author E.S. de Boer |
---|
34 | * |
---|
35 | */ |
---|
36 | public class Utils |
---|
37 | { |
---|
38 | public static String toString(byte[] bytes) |
---|
39 | { |
---|
40 | StringBuffer buf = new StringBuffer(bytes.length * 2); |
---|
41 | for(int i = 0; i < bytes.length; i++) |
---|
42 | { |
---|
43 | int hex = bytes[i]; |
---|
44 | if (hex < 0) hex = 256 + hex; |
---|
45 | if (hex >=16) buf.append(Integer.toHexString(hex)); |
---|
46 | else |
---|
47 | { |
---|
48 | buf.append('0'); |
---|
49 | buf.append(Integer.toHexString(hex)); |
---|
50 | } |
---|
51 | } |
---|
52 | return buf.toString().toLowerCase(); |
---|
53 | } |
---|
54 | |
---|
55 | public static void addCancelButton(RootPaneContainer rpc,JButton button,Action cancelAction) |
---|
56 | { |
---|
57 | button.setAction(cancelAction); |
---|
58 | KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); |
---|
59 | JLayeredPane layeredPane = rpc.getLayeredPane(); |
---|
60 | layeredPane.getActionMap().put("cancel", cancelAction); |
---|
61 | layeredPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "cancel"); |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * Is the JRE Jeti runs on at least version version |
---|
66 | * @param version the minimum version needed |
---|
67 | * version can be 5 or 6 |
---|
68 | */ |
---|
69 | public static boolean isAtleastJava(int version) |
---|
70 | { |
---|
71 | String versionString = System.getProperty("java.version"); |
---|
72 | if (versionString.startsWith("1.4")) |
---|
73 | { |
---|
74 | return false; |
---|
75 | } |
---|
76 | if (versionString.startsWith("1.5")) |
---|
77 | { |
---|
78 | if(version==5) return true; |
---|
79 | else return false; |
---|
80 | } |
---|
81 | return true; |
---|
82 | } |
---|
83 | } |
---|