protected String getConfigProperty(String prop, String defaultValue) { ConfigManager config = parent.getConfig(); String value = config.getProperty(roleName + '.' + getName() + '.' + prop); if (value == null) { value = config.getProperty(roleName + '.' + prop); } return value == null ? defaultValue : value; }
public String getProperty(String name, String defaultValue) { String value = properties.getProperty(name); if (value == null || value.length() == 0) { value = parent != null ? parent.getProperty(name, defaultValue) : defaultValue; } return value; }
public ViewerPanel(String userName, String serverName) { this.serverName = serverName; this.userName = userName; // TODO: use the tasim_viewer.conf file // NOTE: this should actually be the tac09aa_viewer.conf file String configFile = "tasim_viewer.conf"; // String configFile = "tac13adx_viewer.conf"; URL configURL = ViewerPanel.class.getResource("/config/" + configFile); config = new ConfigManager(); try { if (configURL != null) { config.loadConfiguration(configURL); } else if (!config.loadConfiguration("config" + File.separatorChar + configFile)) { // Failed to load the configuration. log.severe("could not find config " + configFile); } } catch (Exception e) { log.severe("could not find config " + configFile); } // Should not be hardcoded but setup depending on simulation type. FIX // THIS!!! 0 \TODO viewer = null; try { String simulationViewerClass = config.getProperty("simulationViewer"); viewer = (SimulationViewer) Class.forName(simulationViewerClass).newInstance(); } catch (InstantiationException e) { log.severe("Could not instantiate the simulation viewer"); } catch (IllegalAccessException e) { log.severe("Could not instantiate the simulation viewer"); } catch (ClassNotFoundException e) { log.severe("Could not find the simulation viewer class"); } viewer.init(this); viewerPanel = viewer.getComponent(); mainPanel = new JPanel(new BorderLayout()); mainPanel.setForeground(foregroundColor); mainPanel.setBackground(backgroundColor); mainPanel.add(viewerPanel, BorderLayout.CENTER); statusLabel = new JLabel("Status:"); statusLabel.setOpaque(true); statusLabel.setForeground(foregroundColor); statusLabel.setBackground(backgroundColor); chatPanel = new ChatPanel(this); // Hack to avoid using another panel chatPanel.setStatusLabel(statusLabel); mainPanel.add(chatPanel, BorderLayout.SOUTH); statusPanel = new StatusPanel(this, foregroundColor, backgroundColor); mainPanel.add(statusPanel, BorderLayout.NORTH); }
private String getLogDirectory(String property, String name) throws IOException { String logDirectory = config.getProperty(property); if (logDirectory != null) { // Create directories for logs File fp = new File(logDirectory); if ((!fp.exists() && !fp.mkdirs()) || !fp.isDirectory()) { throw new IOException("could not create directory '" + logDirectory + '\''); } return fp.getAbsolutePath() + File.separatorChar + name; } else { return name; } }
public SimClient( ConfigManager config, String serverHost, int serverPort, String name, String password, String agentImpl) throws IOException { this.config = config; this.serverHost = serverHost; this.serverPort = serverPort; this.userName = name; this.userPassword = password; this.agentImpl = agentImpl; this.autoJoinCount = config.getPropertyAsInt("autojoin", 1); String logPrefix = config.getProperty("log.prefix", "aw"); this.logFilePrefix = getLogDirectory("log.directory", logPrefix); this.logSimPrefix = getLogDirectory("log.sim.directory", logPrefix); // Set shorter names for the log formatter = new LogFormatter(); formatter.setAliasLevel(2); LogFormatter.setFormatterForAllHandlers(formatter); setLogging(); // TODO: create current context // currentContext = something if (!createAgentInstance()) { showWarning("Agent Setup Failed", "could not setup the agent"); System.exit(1); } this.connection = new ServerConnection(this, 0L); this.connection.open(); // Start the message thread new Thread(this, "SimClient").start(); }