/* * SecureAccessIcon.java * * Copyright (c) 2003-2004 Digi International * This program and the information contained in it is confidential and * proprietary to Digi International and may not be used, copied, or re- * produced without the prior written permission of Digi International. * */ package com.digi.config.ui; import com.digi.config.util.*; import javax.swing.*; import java.net.*; /** * This class is an icon that indicates whether network communications is secure * or not (i.e. HTTPS vs. HTTP). */ public class SecureAccessIcon extends JLabel { private static final String HTTP_PROTOCOL = "http"; private static final String HTTPS_PROTOCOL = "https"; private boolean secure = false; private ImageIcon secureIcon = null; private ImageIcon unsecureIcon = null; String secureToolTip = null; String unsecureToolTip = null; /** * Default constructor. Default state is unsecure. */ public SecureAccessIcon() { initialize(); setSecure(false); } /** * Constructor that sets initial state. * @param secure if true display secure access icon, otherwise unsecure icon. */ public SecureAccessIcon(boolean secure) { initialize(); setSecure(secure); } /** * Constructor that sets initial state based on protocol in a URL string. * @param urlStr URL string used to determine protocol. * @throws MalformedURLException */ public SecureAccessIcon(String urlStr) { initialize(); setSecure(urlStr); } public void setSecure(boolean secure) { this.secure = secure; setIcon(this.secure ? secureIcon : unsecureIcon); setToolTipText(this.secure ? secureToolTip : unsecureToolTip); paintImmediately(getVisibleRect()); } public void setSecure(String urlStr) { URL url = null; try { url = new URL(urlStr); } catch (MalformedURLException mue) { SystemLog.debug(urlStr+" is a bad URL. Showing unsecure icon.", mue); } if (url != null && url.getProtocol().equalsIgnoreCase(HTTPS_PROTOCOL)) { setSecure(true); } else { setSecure(false); } } public boolean isSecure() { return this.secure; } private void initialize() { secureIcon = ConfigResource.getImageRbIcon("SecureAccessImage"); unsecureIcon = ConfigResource.getImageRbIcon("UnsecureAccessImage"); secureToolTip = ConfigResource.getUiRbString("SecureAccessToolTip"); unsecureToolTip = ConfigResource.getUiRbString("UnsecureAccessToolTip"); } }