/* * Jeti, a Java Jabber client, Copyright (C) 2001 E.S. de Boer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * For questions, comments etc, * use the website at http://jeti.jabberstudio.org * or mail/IM me at jeti@jabber.org * * Created on 17-jun-2005 */ package nu.fw.jeti.util; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import javax.swing.*; /** * @author E.S. de Boer * */ public class Utils { public static String toString(byte[] bytes) { StringBuffer buf = new StringBuffer(bytes.length * 2); for(int i = 0; i < bytes.length; i++) { int hex = bytes[i]; if (hex < 0) hex = 256 + hex; if (hex >=16) buf.append(Integer.toHexString(hex)); else { buf.append('0'); buf.append(Integer.toHexString(hex)); } } return buf.toString().toLowerCase(); } public static void addCancelButton(RootPaneContainer rpc,JButton button,Action cancelAction) { button.setAction(cancelAction); KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); JLayeredPane layeredPane = rpc.getLayeredPane(); layeredPane.getActionMap().put("cancel", cancelAction); layeredPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "cancel"); } /** * Is the JRE Jeti runs on at least version version * @param version the minimum version needed * version can be 5 or 6 */ public static boolean isAtleastJava(int version) { String versionString = System.getProperty("java.version"); if (versionString.startsWith("1.4")) { return false; } if (versionString.startsWith("1.5")) { if(version==5) return true; else return false; } return true; } }