示例#1
0
 /** Saves the layout on closing of the main window. */
 public void saveLayout() {
   try {
     LayoutSettings settings = LayoutSettingsManager.getLayoutSettings();
     settings.setMainWindowHeight(getHeight());
     settings.setMainWindowWidth(getWidth());
     settings.setMainWindowX(getX());
     settings.setMainWindowY(getY());
     LayoutSettingsManager.saveLayoutSettings();
   } catch (Exception e) {
     // Don't let this cause a real problem shutting down.
   }
 }
示例#2
0
  /**
   * Updates the displayed name for the contact. This method tries to use an alias first. If that's
   * not set, the nickname will be used instead. If that's not set either, the JID of the user will
   * be used.
   */
  protected void setDisplayName() {
    final String displayName = getDisplayName();

    int nickLength = displayName.length();

    LayoutSettings settings = LayoutSettingsManager.getLayoutSettings();
    int windowWidth = settings.getMainWindowWidth();

    if (nickLength > windowWidth) {
      displayNameLabel.setText(
          StringUtils.unescapeNode(displayName).substring(0, windowWidth) + "...");
    } else {
      displayNameLabel.setText(StringUtils.unescapeNode(displayName));
    }
  }
示例#3
0
  /**
   * Constructs the UI for the MainWindow. The MainWindow UI is the container for the entire Spark
   * application.
   *
   * @param title the title of the frame.
   * @param icon the icon used in the frame.
   */
  private MainWindow(String title, ImageIcon icon) {

    // Initialize and dock the menus
    buildMenu();

    // Add Workspace Container
    getContentPane().setLayout(new BorderLayout());

    LayoutSettings settings = LayoutSettingsManager.getLayoutSettings();
    if (settings.getMainWindowX() == 0 && settings.getMainWindowY() == 0) {
      // Use default settings.
      setSize(300, 500);
      GraphicUtils.centerWindowOnScreen(this);
    } else {
      setBounds(
          settings.getMainWindowX(),
          settings.getMainWindowY(),
          settings.getMainWindowWidth(),
          settings.getMainWindowHeight());
    }

    // Add menubar
    this.setJMenuBar(mainWindowBar);
    this.getContentPane().add(topToolbar, BorderLayout.NORTH);

    setTitle(title);
    setIconImage(icon.getImage());

    // Setup WindowListener to be the proxy to the actual window listener
    // which cannot normally be used outside of the Window component because
    // of protected access.
    addWindowListener(
        new WindowAdapter() {

          /**
           * This event fires when the window has become active.
           *
           * @param e WindowEvent is not used.
           */
          public void windowActivated(WindowEvent e) {
            fireWindowActivated();
          }

          /** Invoked when a window is de-activated. */
          public void windowDeactivated(WindowEvent e) {}

          /**
           * This event fires whenever a user minimizes the window from the toolbar.
           *
           * @param e WindowEvent is not used.
           */
          public void windowIconified(WindowEvent e) {}

          /**
           * This event fires when the application is closing. This allows Plugins to do any
           * persistence or other work before exiting.
           *
           * @param e WindowEvent is never used.
           */
          public void windowClosing(WindowEvent e) {
            saveLayout();
            setVisible(false);
          }
        });

    this.addWindowFocusListener(new MainWindowFocusListener());
  }