Package gui

Source Code of gui.MainFrame

/*
* Hamsam - Instant Messaging API
* Copyright (C) 2003 Raghu K
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package gui;

import gui.tools.PropertiesManager;
import gui.tools.Traces;
import hamsam.api.Buddy;

import java.awt.BorderLayout;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

public class MainFrame extends JFrame
{
  private PropertiesManager langProp;
  private PropertiesManager genProp;
  private MenuBar menuBar;
  private TabbedPanel tabbedPanel;
  private StatusBar statusBar;
  private BorderLayout layout = new BorderLayout();
  private ImageIcon logo;

  //Singleton
  public static MainFrame myRef = null;

  public MainFrame()
  {
    if(myRef == null)
    {
      myRef = this;
      this.initMainFrame();
    }
  }

  /**
   * Init the main Frame
   */
  private void initMainFrame()
  {
    this.initPropertiesMgr();
   
    //Init graphic items
    menuBar = new MenuBar(this.langProp);
    tabbedPanel = new TabbedPanel(this.langProp);
    statusBar = new StatusBar(this.langProp);

    //Create the frame
    this.setTitle(this.langProp.getValue("frameTitle"));
    logo = new ImageIcon("images/hamsam.gif");
    this.setIconImage(logo.getImage());
    this.getContentPane().setLayout(layout);
    this.getContentPane().add(menuBar, BorderLayout.NORTH);
    this.getContentPane().add(tabbedPanel, BorderLayout.CENTER);
    this.getContentPane().add(statusBar, BorderLayout.SOUTH);

    //close operation
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Init frame size
    this.pack();
    this.setVisible(true);
  }

  /**
   * Init properties manager.
   */
  private void initPropertiesMgr()
  {
    try
    {
      genProp = new PropertiesManager("dico/language.properties");
      String ext = genProp.getValue("language");
      langProp = new PropertiesManager("dico/hamsam." + ext);
      Boolean b = new Boolean(genProp.getValue("debug"));
      Traces.setPrintingTraces(b.booleanValue());
    }
    catch(Exception e)
    {
      Traces.printTraces("Exception trying to get the properties file.");
      e.printStackTrace();
      System.exit(-1);
    }
  }

  public PropertiesManager getGeneralPropertiesManager()
  {
    return genProp;
  }

  /**
   * Update the buddy list.
   */
  public void updateBuddyListReceived(Buddy[] b)
  {
    tabbedPanel.updateBuddyList(b);
  }

  public void closeSession()
  {
    int count = tabbedPanel.getTabCount();
    this.enableContactPanel(false);

    //if there are chat panel opened
    for(int i = count - 1; i >= 2; i--)
      tabbedPanel.removeTabAt(i);

    //set connection panel selected
    tabbedPanel.setSelectedIndex(0);
  }
 
  /**
   * Add a chat panel to the main frame.
   */
  public void addChatPanel(Vector v)
  {
    this.tabbedPanel.addTab(this.langProp.getValue("chatPanel"),
        new ChatPanel(this.langProp, v));
    this.tabbedPanel.setSelectedIndex(this.tabbedPanel.getTabCount() - 1);
  }

  public void removeChatPanel()
  {
    this.tabbedPanel.removeTabAt(this.tabbedPanel.getSelectedIndex());
  }

  public void enableContactPanel(boolean b)
  {
    this.tabbedPanel.enableContactPanel(b);
  }

  public void setStatus(String status)
  {
    this.statusBar.setStatus(status);
  }

  public static void main(String[] args)
  {
      new MainFrame();
    }
}
TOP

Related Classes of gui.MainFrame

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.