/* * ConfigAppPanel.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. * * All rights reserved. */ package com.digi.config.ui; import com.digi.config.core.*; import com.digi.config.util.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.plaf.*; import javax.swing.plaf.metal.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import java.net.*; import java.lang.Thread; import javax.xml.parsers.*; import org.w3c.dom.*; /** * This class represents the main configuration user interface. This class is * a JPanel that can be imbedded in other constructs such as a JFrame or an Applet. */ public class ConfigAppPanel extends CustomPanel implements StatusDisplay { /** Proxy to the device we are configuring */ Device device; /** TitleBar area of the config screen */ JPanel titleBar = null; /** MenuBar area of the config screen */ JMenuBar menuBar = null; /** Toolbar area of the config screen */ JToolBar toolBar = null; /** Holds the MenuBar & ToolBar components */ JPanel actionPanel = null; /** Navigation menu area of the config screen */ JPanel navigationPanel = null; /** View Details area of the config screen */ JPanel contentPanel = null; /** Status area of the config screen */ StatusPanel statusPanel = null; /** Display/Edit panel showing URL applet is connected to */ JPanel urlPanel = null; /** Message area of the config screen */ private MessageArea messageArea; /** Secure access tray icon */ SecureAccessIcon secureAccessIcon = null; boolean showMenuBar = false; // finish this... fetch these from config props boolean showToolBar = false; boolean showNavigationPanel = true; boolean artificialFrame = false; // The preferred size of the view area private static final int PREFERRED_WIDTH = 720; private static final int PREFERRED_HEIGHT = 640; // Available Actions Finish this... move these into a Dynamic list of Actions Action homeAction; Action configAllAction; Action networkAction; Action serialAction; Action gpioAction; Action securityAction; Action systemAction; Action alarmAction; Action rebootAction; Action backupAction; Action updateFirmwareAction; Action factoryAction; Action configHelpAction; Action viewHelpAction; // Available Configuration views Finish this... move these into a Dynamic list of Views ConfigView homeView; ConfigView configAllView; ConfigView networkView; ConfigView serialView; ConfigView gpioView; ConfigView securityView; ConfigView systemView; ConfigView alarmView; ConfigView backupView; ConfigView rebootView; ConfigView factoryView; /** The currently selected ConfigView */ ConfigView currentView; /** * ConfigAppPanel Constructor */ public ConfigAppPanel() throws Exception { this(true); } public ConfigAppPanel(boolean artificialFrame) throws Exception { super("App"); this.artificialFrame = artificialFrame; ConfigTheme configTheme = new ConfigTheme(); MetalLookAndFeel.setCurrentTheme(configTheme); UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); Color tabbedPaneColor = ConfigSettings.getColor("WindowSettings", "TabbedPaneBackgroundColor"); if (tabbedPaneColor!=null) { UIManager.put("TabbedPane.selected", tabbedPaneColor); } if ((this.backgroundImage==null) && ((this.backgroundColor==null) || (this.backgroundColor.getAlpha()==0))) { this.setBackground(ConfigSettings.getColor("WindowSettings", "BackgroundColor")); } // this.setBackground(Color.WHITE); this.setBorder(new EtchedBorder()); // Set up the Device proxy device = new Device(); SplashScreenPanel.currentScreen().updateProgress(); // Try initializing the cached kvpGroup try { device.refreshSettingTree(); SplashScreenPanel.currentScreen().updateProgress(); } catch (DeviceCommandException dce) { SystemLog.log("DeviceNotAvailable", new Serializable[]{device.getUrlName()}, dce); } // Setup the actions and associated views initializeActions(); //initializeViews(); // To defer the building of views until first touch comment this line // Define the content of the panel setLayout(new BorderLayout()); add(getActionPanel(), BorderLayout.NORTH); JPanel workPanel = new JPanel(); workPanel.setLayout(new BorderLayout()); workPanel.setOpaque(false); workPanel.add(getNavigationPanel(), BorderLayout.WEST); workPanel.add(getContentPanel(), BorderLayout.CENTER); JSplitPane mainSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, workPanel, getMessageAreaPanel()); mainSplit.setOpaque(false); mainSplit.setDividerLocation(-1); // Position relative to components size mainSplit.setResizeWeight(1); // Use any extra space on top mainSplit.setDividerSize(1); add(mainSplit, BorderLayout.CENTER); add(getStatusPanel(), BorderLayout.SOUTH); // If running standalone, or in developer mode, show the URL Panel too if (!ConfigSettings.getBoolean("General", "AppletMode") || ConfigSettings.getBoolean("DebugSettings", "GeneralDebug")) { // only show this view to developers statusPanel.addTrayComponent(getUrlPanel()); } // TODO: handle this somewhere else and implement some type of listener // so that we can detect when the URL/protocol changes. secureAccessIcon = new SecureAccessIcon(device.getUrlName()); statusPanel.addTrayComponent(secureAccessIcon); // Show/Hide menu components as specified boolean useMenus = ConfigSettings.getBoolean("PropertiesSettings", "UseMenus"); getMenuBar().setVisible(useMenus); getToolBar().setVisible(useMenus); getNavigationPanel().setVisible(!useMenus); Busy.registerGUIComponent(this); // initially position to the home view doHomeAction(); SplashScreenPanel.currentScreen().updateProgress(); } // /** // * Called to set the font in the components // * @param String - name of font // * @param int - size of font // */ // public void setUIFont (String name, int size){ // int style = 1; // java.util.Enumeration keys = UIManager.getDefaults().keys(); // while (keys.hasMoreElements()) { // Object key = keys.nextElement(); // Object value = UIManager.get (key); // if (value instanceof javax.swing.plaf.FontUIResource) { // style = ((FontUIResource)value).getStyle(); // UIManager.put (key,new FontUIResource(name, style, size)); // } // } // } // /** * Defines the main actions that can be invoked from the menus or * toolbar buttons. These actions will be used to construct the menus & * toolbar buttons. */ public void initializeActions() throws Exception { SplashScreenPanel.currentScreen().updateProgress(); // finish this... can we somehow assign the view to the action here??? homeAction = new ConfigAction("Home", this, "doHomeAction"); configAllAction = new ConfigAction("ConfigAll", this, "doConfigAllAction"); networkAction = new ConfigAction("Network", this, "doNetworkAction"); serialAction = new ConfigAction("Serial", this, "doSerialAction"); gpioAction = new ConfigAction("Gpio", this, "doGpioAction"); securityAction = new ConfigAction("Security", this, "doSecurityAction"); systemAction = new ConfigAction("System", this, "doSystemAction"); alarmAction = new ConfigAction("Alarm", this, "doAlarmAction"); backupAction = new ConfigAction("Backup", this, "doBackupAction"); rebootAction = new ConfigAction("Reboot", this, "doRebootAction"); updateFirmwareAction = new ConfigAction("UpdateFirmware", this, "doUpdateFirmwareAction"); factoryAction = new ConfigAction("RestoreFactoryDefaults", this, "doFactoryAction"); configHelpAction = new ConfigAction("ConfigHelp", this, "doConfigHelpAction"); viewHelpAction = new ConfigAction("ViewHelp", this, "doViewHelpAction"); SplashScreenPanel.currentScreen().updateProgress(); } /** * Creates and initializes the view's used in the configuration application. * * Note: this could be handled on first touch of each view as well. */ public void initializeViews() throws Exception { SplashScreenPanel.currentScreen().updateProgress(); homeView = new HomeView(); homeView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); configAllView = new GlobalSettingView(); configAllView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); networkView = new NetworkView(); networkView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); serialView = new SerialView(); serialView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); gpioView = new GpioView(); gpioView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); securityView = new SecurityView(); securityView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); systemView = new SystemView(); systemView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); alarmView = new AlarmGpioView(); alarmView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); backupView = new BackupView(); backupView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); rebootView = new RebootView(); rebootView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); factoryView = new RestoreFactoryDefaultsView(); factoryView.setDevice(device); SplashScreenPanel.currentScreen().updateProgress(); } /** * Gets the panel that holds the action controls (ie menu and toolbar) - creating * if necessary. */ public JPanel getActionPanel() { if (actionPanel==null) { actionPanel = new JPanel(); actionPanel.setLayout(new BoxLayout(actionPanel, BoxLayout.Y_AXIS)); if (artificialFrame) { actionPanel.add(getTitleBar()); } actionPanel.add(getMenuBar()); actionPanel.add(getToolBar()); SplashScreenPanel.currentScreen().updateProgress(); } return actionPanel; } /** * Gets the panel that holds the action controls (ie menu and toolbar) - creating * if necessary. */ public JPanel getNavigationPanel() { if (navigationPanel==null) { SplashScreenPanel.currentScreen().updateProgress(); navigationPanel = new CustomPanel("Navigation"); navigationPanel.setLayout(new BoxLayout(navigationPanel, BoxLayout.Y_AXIS)); navigationPanel.setBorder(new EtchedBorder()); JMenuBar menuBar = getMenuBar(); JButton button; Color menuColor = ConfigSettings.getColor("WindowSettings","MenuColor"); if (menuColor==null) { menuColor = Color.BLUE; } for (int i=0; i