Пример #1
0
  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);
  }
Пример #2
0
 public boolean loadConfiguration(URL configURL) {
   try {
     InputStream input = new BufferedInputStream(configURL.openStream());
     try {
       loadConfiguration(input);
     } finally {
       input.close();
     }
     return true;
   } catch (FileNotFoundException e) {
     return false;
   } catch (IOException e) {
     throw (IllegalArgumentException)
         new IllegalArgumentException("could not read config file '" + configURL + '\'')
             .initCause(e);
   }
 }