⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 singlegroupviewpanel.java

📁 create the email in the server
💻 JAVA
字号:
package za.co.halo.SecureCommunications.gui.server;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.AbstractAction;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.WindowConstants;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import za.co.halo.SecureCommunications.ServerAccount;
import za.co.halo.SecureCommunications.ServerGroup;
import za.co.halo.SecureCommunications.ServerManager;
import za.co.halo.SecureCommunications.gui.server.GroupsPanel.RemoveAction;
/**
 * @author
 * SingleGroupViewPanel Class
 * This panel performs the functionality of viewing group detail
 * and also presents the user with the option to update group detial
 */

/**
* This code was generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* *************************************
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED
* for this machine, so Jigloo or this code cannot be used legally
* for any corporate or commercial purpose.
* *************************************
*/
public class SingleGroupViewPanel extends javax.swing.JPanel implements ActionListener{
	private JLabel groupnameLabel;
	private JTextField groupname;
	private ServerGroup group;
	private JButton saveAndClose, cancelButton, removeButton;
	private int index;
	private JButton addAccountButton;
	private JComboBox accountsList;
	private JSplitPane splitpane;
	private SingleGroupViewPanel thispanel;
	private Vector<ServerGroup> groups;
	private JLabel accountsLabel, addAccountsLabel;
	private JList accountList;
	private JScrollPane scrollPane;
	private ServerManager accounts;
	private ServerAccount ac;
	private Vector<String> accountNames;

	
   /**
	* main method
	* Use to:
	* display this JPanel inside a new JFrame
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
	//	frame.getContentPane().add(new SingelPOP3ViewPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
   /**
	* SingleGroupViewPanel constructor
	* Use to:
	* initialize member variables
	* initialize the build of graphical components.
	* @param JSplitPane(splitpane), Vector<ServerAccount>(accounts), JList(list) values: to initialize the member functions
	* @return void 
	*/
	public SingleGroupViewPanel(ServerGroup group_, int index, Vector<ServerGroup> groups , JSplitPane splitpane, ServerManager accounts) {
		super();
		thispanel = this;
		group = group_;
		this.groups = groups;
		this.index = index;
		this.splitpane = splitpane;
		this.accounts = accounts;
		System.out.println(accounts);
		initGUI();
	}
	
   /**
	* initGUI method
	* Use to:
	* build the graphics
	* @param void
	* @return void 
	*/
	private void initGUI() {
		try {
			this.setLayout(null);
			this.setPreferredSize(new java.awt.Dimension(298, 330));
			{
				groupnameLabel = new JLabel();
				this.add(groupnameLabel);
				groupnameLabel.setText("Group name");
				groupnameLabel.setBounds(5, 5, 79, 30);
			}
			{
				groupname = new JTextField();
				this.add(groupname);
				groupname.setText(group.getGroupName());
				groupname.setBounds(80, 5, 180, 30);
			}
			/*{
				accountsLabel = new JLabel();
				this.add(accountsLabel);
				accountsLabel.setText("Accounts");
				accountsLabel.setBounds(7, 50, 165, 30);
			}*/
			{
				accountList = new JList(group.getAccounts());
				scrollPane = new JScrollPane(accountList);
				scrollPane.setBounds(10, 48, 250, 145);
				this.add(scrollPane);
			}
			{
				addAccountsLabel = new JLabel();
				{
					//ComboBoxModel accountsListModel = new DefaultComboBoxModel(
						//new String[] { "Item One", "Item Two" });
					/*String[] accountNames = new String[accounts.getNumberofAccounts()];
					for (int i = 0; i < accounts.getNumberofAccounts(); i++)
					{
						if (!test()
						accountNames[i] = accounts.getClientAccount(i).getUserName();
					}*/
					/*accountsList = new JComboBox(createComboList());
					this.add(accountsList);*/
					ComboBoxModel mod = new DefaultComboBoxModel(createModel());
					accountsList = new JComboBox();
					accountsList.setModel(mod);
					accountsList.setBounds(13, 202, 177, 30);
					accountsList.addActionListener(this);
					this.add(accountsList);
				}
				/*this.add(addAccountsLabel);
				accountsLabel.setText("Account");
				accountsLabel.setBounds(10, 202, 53, 30);*/
			}
			{
				removeButton = new JButton(new RemoveAction());
				this.add(removeButton );
				removeButton.setText("Remove Account");
				//removeButton.setEnabled(false);
				removeButton.setPreferredSize(new java.awt.Dimension(96, 26));
				removeButton.setBounds(10, 277, 135, 26);
			}
			{
				saveAndClose = new JButton(new SaveAction());
				this.add(saveAndClose);
				saveAndClose.setText("Save & Close");
				saveAndClose.setBounds(10, 244, 109, 26);
			}
			{
				cancelButton = new JButton(new CancelAction());
				this.add(cancelButton);
				cancelButton.setText("Cancel");
				cancelButton.setBounds(126, 244, 73, 26);
				{
					addAccountButton = new JButton(new AddAction());
					this.add(addAccountButton);
					addAccountButton.setText("Add");
					addAccountButton.setBounds(197, 202, 58, 30);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
   /**
	* createModel method
	* Use to:
	* create a vector of account names
	* @param void
	* @return Vector<String>: vector that will be used by the ComboBoxModel 
	*/
	public Vector<String> createModel()
	{
		Vector<String> vec = new Vector();
		for (int i = 0; i < accounts.getNumberofAccounts(); i++)
		{
			if (createEL(i) != null)
				vec.addElement(createEL(i));
		}
		return vec;
	}
	
   /**
	* cretateEL method
	* Use to:
	* create the elements in the vector of the createModel method
	* @param int(i): number of the account to add to the vector
	* @return String: accountName to add to the vector 
	*/
	public String createEL(int i)
	{
		if (!testIfGroupExist(accounts.getClientAccount(i).getUserName()))
		{
			return accounts.getClientAccount(i).getUserName();
		}
		return null;
	}
	
   /**
	* testIfGroupExist method
	* Use to:
	* test if an account is already included in the accounts of the group
	* @param String(accountName): the account name to test
	* @return boolean: indication of false if account name is not already included 
	*/
	public boolean testIfGroupExist(String accountName)
	{
		boolean flag = false;
		for (int i = 0; i < group.getNumberOfAccounts(); i++)
		{
			if(group.getAccount(i).getUserName().equals(accountName))
				flag = true;
		}
		return flag;
	}
	
   /**
	* actionPeformed method
	* Use to:
	* Handle JComboBox(accountsList) actions
	* @param ActionEvent: the type of action
	* @return void 
	*/
	public void actionPerformed(ActionEvent e)
	{
		JComboBox cb = (JComboBox)e.getSource();
		int num = cb.getSelectedIndex();
        String accountName = (String)cb.getSelectedItem();
        System.out.println("====="+accountName+"=====");
        
         ac = accounts.getAccount(accountName);
       
	}
	
   /**
	* SaveAction class
	* Provides the functionality of handling save actions.
	*/
	class SaveAction extends AbstractAction {
		SaveAction() {
			super("Saved record");
		}

	   /**
		* actionPeformed method
		* Use to:
		* Handle save actions
		* @param ActionEvent: the type of action
		* @return void 
		*/
		public void actionPerformed(ActionEvent arg0) 
		{
			String groupname_ = groupname.getText();
			ServerGroup group = new ServerGroup(groupname_);
			groups.setElementAt(group , index);
			CleanPanel cleanpanel = new CleanPanel();
			splitpane.setRightComponent(cleanpanel);
		}

	}
	
   /**
	* CancelAction class
	* Provides the functionality of handling cancel actions.
	*/
	class CancelAction extends AbstractAction {
		CancelAction() {
			super("cancel creation of RMI account");
		}

	   /**
		* actionPeformed method
		* Use to:
		* Handle cancel actions
		* @param ActionEvent: the type of action
		* @return void 
		*/
		public void actionPerformed(ActionEvent arg0) 
		{
			CleanPanel cleanpanel = new CleanPanel();
			splitpane.setRightComponent(cleanpanel);
		}
		
		
	}
	
   /**
	* RemoveAction class
	* Provides the functionality of handling remove actions.
	*/
	class RemoveAction extends AbstractAction {
		RemoveAction() {
			super("Cancel creation of RMI account");
		}

	   /**
		* actionPeformed method
		* Use to:
		* Handle remove actions
		* @param ActionEvent: the type of action
		* @return void 
		*/
		public void actionPerformed(ActionEvent arg0) 
		{
			int indexToRemove = accountList.getSelectedIndex();
			group.removeAccount(indexToRemove);
			accountList.repaint();

			ComboBoxModel mod2 = new DefaultComboBoxModel(createModel());
			accountsList.setModel(mod2);
		}
	}
	
   /**
	* AddAction class
	* Provides the functionality of handling add actions.
	*/
	class AddAction extends AbstractAction {
		AddAction() {
			super("Add record");
		}

	   /**
		* actionPeformed method
		* Use to:
		* Handle add actions
		* @param ActionEvent: the type of action
		* @return void 
		*/
		public void actionPerformed(ActionEvent arg0) 
		{
			 group.addAccount(ac);
			 accountList.setListData(group.getAccounts());
			 //accountsList./
			 ComboBoxModel mod3 = new DefaultComboBoxModel(createModel());
			 accountsList.setModel(mod3);
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -