Package GUI

Source Code of GUI.SettingsWindow$JTrennungsLabel

package GUI;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import Communication.ChatProvider;
import Communication.Interfaces.Connection;
import Communication.Mocks.ICQSimulation;
import Communication.Mocks.MSNSimulation;
import Control.Settings;
import Control.Interfaces.EventHandler;
import GUI.SettingWindows.ChatConnectionEditor;

/**
* Enables the user to change the {@link Settings} of the client, saving changed information
* to the defined output location.
*
* @author Sebastian
*/
public class SettingsWindow extends SatedaWindow{

  /**
   * Reads and changes the settings here
   */
  private Settings settings;

  /**
   * Enables the user to choose the part of the {@link Settings} he is interested in changing
   */
  private JComboBox menueChooser;


  private JLabel proxyText;
  private JList proxyList;
  private JButton addButton;
  private JButton deleteButton;
  private JButton editButton;

  /**
   * Is used by the user to dispose this window
   */
  private JButton exit;
  private DefaultListModel proxyModel = new DefaultListModel();

  private JLabel connectionText;
  private JList connectionList;
 
  /**
   * Indicates that the {@link ChatConnectionEditor} has been opened to edit an existing {@link Connection}
   */
  private boolean connectionBeingEdited;
 
  /**
   * Indicates that the {@link ChatConnectionEditor} has been opened to add a new {@link Connection}
   */
  private boolean connectionBeingAdded;
 
  private DefaultListModel connectionModel = new DefaultListModel();

  /**
   * Enables the user to add or edit a chat {@link Connection}
   */
  private ChatConnectionEditor chatConnectionEditor;

  private JTrennungsLabel hyphen;
  private JCheckBox automaticProxySelection = new JCheckBox("Automatisch Proxy-Konfigurationen testen");

  private EventHandler eventHandler;

  public SettingsWindow(Rectangle rectangle, final Settings settings, EventHandler eventHandler) {
    super(rectangle, false, -1);
    setVisible(true);

    this.eventHandler = eventHandler;
    this.settings = settings;
    isResizeable = false;

    add(automaticProxySelection);

    hyphen = new JTrennungsLabel();
    hyphen.setBounds(180,12,2, rectangle.height - 24);
    hyphen.repaint();

    proxyText = new JLabel("Verwaltung der Proxy-Konfigurationen");
    proxyText.setFont(new Font("Arial", Font.BOLD, 11));

    exit = new JButton("Beenden");
    exit.addActionListener(new ActionListener(){

      public void actionPerformed(ActionEvent e) {
        setVisible(false);
      }});

    connectionText = new JLabel("Verwaltung der Chatverbindungen");
    connectionText.setFont(new Font("Arial", Font.BOLD, 11));
    add(connectionText);

    connectionList = new JList(connectionModel);
    add(connectionList);
    connectionList.setBorder(BorderFactory.createRaisedBevelBorder());


    addButton = new JButton("Hinzuf�gen");
    deleteButton = new JButton("L�schen");
    editButton = new JButton("Bearbeiten");

    menueChooser = new JComboBox();
    menueChooser.setBounds(20,20,150,20);

    proxyList = new JList(proxyModel);
    proxyList.setBorder(BorderFactory.createRaisedBevelBorder());

    menueChooser.addItemListener(new ItemListener(){

      public void itemStateChanged(ItemEvent arg0) {

        hideAllComponents();

        if(arg0.getItem().equals("Internetverbindung")){
          loadConnectionSettings();
        }else if(arg0.getItem().equals("Chatverbindungen")){
          loadChatConnectionSettings();
        }
      }});

    menueChooser.addItem("Allgemeines");
    menueChooser.addItem("Chatverbindungen");
    menueChooser.addItem("Internetverbindung");
    menueChooser.addItem("Design");
    menueChooser.addItem("Kontakte");

    editButton.setEnabled(false);
    deleteButton.setEnabled(false);

    add(hyphen);
    add(exit);
    add(proxyText);
    add(editButton);
    add(deleteButton);
    add(addButton);
    add(proxyList);
    add(menueChooser);

    final SettingsWindow thisWindow = this;

    addButton.addActionListener(new ActionListener(){

      public void actionPerformed(ActionEvent arg0) {

        if(menueChooser.getModel().getSelectedItem().equals("Internetverbindung")){

        }else if(menueChooser.getModel().getSelectedItem().equals("Chatverbindungen")){

          if(chatConnectionEditor == null){
            connectionBeingAdded = true;
            connectionBeingEdited = false;
            chatConnectionEditor = new ChatConnectionEditor(new Rectangle(getX(),
                getY(), 230, 130), thisWindow);
            chatConnectionEditor.requestFocus();
          }
        }
      }});

    this.setTitle("Einstellungen");

    try {
      this.setIconImage(ImageIO.read(new File("Ressources/settings.png")));
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    editButton.addActionListener(new ActionListener(){


      public void actionPerformed(ActionEvent e) {
      }});

    deleteButton.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e) {

      }});

    exit.setBounds(menueChooser.getX(), getHeight() - 40,
        menueChooser.getWidth(), 20);
    setVisible(true);
  }

  public void requestChatConnectionSettings(){
    menueChooser.getModel().setSelectedItem("Chatverbindungen");
  }

  private void loadChatConnectionSettings(){

    connectionModel.removeAllElements();

    for(String name : settings.connectionName){
      connectionModel.addElement(name);
    }

    connectionList.addListSelectionListener(new ListSelectionListener(){


      public void valueChanged(ListSelectionEvent e) {
        editButton.setEnabled(true);
        deleteButton.setEnabled(true);
      }});

    connectionText.setBounds(192,20,240,20);
    connectionList.setBounds(190,48,240,182);

    addButton.setBounds(190,260,100,20);
    addButton.setVisible(true);

    editButton.setBounds(190,235,100,20);
    deleteButton.setBounds(310,235,90,20);
    editButton.setVisible(true);
    deleteButton.setVisible(true);

    connectionList.setVisible(true);
    connectionText.setVisible(true);
  }

  public class JTrennungsLabel extends JLabel{

    public void paint(Graphics g){
      g.setColor(Color.white);
      g.fillRect(0, 0, 2, getHeight());

      g.setColor(new Color(149,148,234));

      boolean zeichnen = false;

      for(int i = 0; i < getHeight(); i+=5){
        if(zeichnen){
          g.fillRect(0, i, 2, 5);
          zeichnen = false;
        }else{
          zeichnen = true;
        }
      }
    }
  }

  public void addProxy(String bez, String pfad, int port, String user, String passw){

    //    settings.addProxyName(bez);
    //    settings.addProxyPath(pfad);
    //    settings.addProxyPort(port);
    //    settings.addProxyUsername(user);
    //    settings.addProxyUserPassword(passw);
    //    settings.erneuereInformationen();

    loadConnectionSettings();
  }

  private void loadConnectionSettings(){

    automaticProxySelection.setBounds(188,5,250,50);
    proxyText.setBounds(192, 55, 230, 20);

    if(settings.testProxysOnLoginException){
      automaticProxySelection.setSelected(true);
    }

    proxyList.setBounds(190,80,240,140);

    automaticProxySelection.addItemListener(new ItemListener(){

      public void itemStateChanged(ItemEvent arg0) {

        settings.testProxysOnLoginException = automaticProxySelection.isSelected();
        settings.save();
      }});

    proxyModel.removeAllElements();

    if(settings.proxyName.size() == 0){
      proxyModel.addElement("Keine Proxy-Konfigurationen vorhanden");
    }else{

      for(String s : settings.proxyName){
        proxyModel.addElement(s);
      }
      proxyList.addListSelectionListener(new ListSelectionListener(){

        public void valueChanged(ListSelectionEvent e) {
          if(proxyList.getSelectedIndex() > -1){
            editButton.setEnabled(true);
            deleteButton.setEnabled(true);
          }
        }});
    }

    automaticProxySelection.setVisible(true);
    proxyText.setVisible(true);
    proxyList.setVisible(true);
    addButton.setVisible(true);
    deleteButton.setVisible(true);
    editButton.setVisible(true);

    editButton.setBounds(proxyList.getX(), proxyList.getY() + proxyList.getHeight() + 15, 100, 20);
    deleteButton.setBounds(proxyList.getX() + 120, proxyList.getY() + proxyList.getHeight() + 15, 90, 20);
    addButton.setBounds(proxyList.getX(), proxyList.getY() + proxyList.getHeight() + 40, 100, 20);

  }

  private void hideAllComponents(){

    editButton.setEnabled(false);
    deleteButton.setEnabled(false);

    connectionList.setVisible(false);
    connectionText.setVisible(false);

    proxyList.setVisible(false);
    proxyText.setVisible(false);
    addButton.setVisible(false);
    deleteButton.setVisible(false);
    editButton.setVisible(false);
    automaticProxySelection.setVisible(false);
  }

  /**
   * Indicates that the user edited an existing {@link Connection} or added a new one.
   *
   * @param name
   * @param loginName
   * @param password
   * @param type
   */
  public void chatConnectionEdited(String name, String loginName, String password,
      ChatProvider type){

    if(connectionBeingAdded){

      if(connectionModel.contains(name)){
        JOptionPane.showMessageDialog(this, "Eine Verbindung mit" +
            " der Bezeichnung exisitiert bereits", "Verbindung existiert bereits",
            JOptionPane.ERROR_MESSAGE);
      }else{
        settings.connectionName.add(name);
        settings.loginName.add(loginName);
        settings.loginPassword.add(password);
        settings.connectionType.add(type);

        connectionModel.addElement(name);

        Connection connection = null;
        if(type.equals(ChatProvider.ICQ)){
          connection = new ICQSimulation(loginName, password, eventHandler, ChatProvider.ICQ);
        }else if(type.equals(ChatProvider.MSN)){
          connection = new MSNSimulation(loginName, password, eventHandler, ChatProvider.MSN);     
        }
        eventHandler.addConnection(connection);
        eventHandler.chatConnectionsUpdated();
      }
    }else if(connectionBeingEdited){


    }

    settings.save();


   
    connectionBeingAdded = false;
    connectionBeingEdited = false;
  }


  public void componentHidden(ComponentEvent e) {
    // TODO Auto-generated method stub

  }


  public void componentMoved(ComponentEvent e) {
    // TODO Auto-generated method stub

  }


  public void componentShown(ComponentEvent e) {
    // TODO Auto-generated method stub

  }


  public void mouseEntered(MouseEvent arg0) {
    // TODO Auto-generated method stub

  }


  public void mouseExited(MouseEvent arg0) {
    // TODO Auto-generated method stub

  }


  public void windowActivated(WindowEvent arg0) {
    // TODO Auto-generated method stub

  }


  public void windowClosed(WindowEvent arg0) {
    // TODO Auto-generated method stub

  }


  public void windowClosing(WindowEvent arg0) {
    // TODO Auto-generated method stub

  }


  public void windowDeactivated(WindowEvent arg0) {

    if(chatConnectionEditor != null){
      chatConnectionEditor.dispose();
      chatConnectionEditor = null;
    }
  }

  public void windowDeiconified(WindowEvent arg0) {
  }

  public void windowIconified(WindowEvent arg0) {

    if(chatConnectionEditor != null){
      chatConnectionEditor.dispose();
      chatConnectionEditor = null;
    }
  }


  public void windowOpened(WindowEvent arg0) {
    // TODO Auto-generated method stub

  }
}
TOP

Related Classes of GUI.SettingsWindow$JTrennungsLabel

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.