📄 userpanel.java
字号:
//You can redistribute this software and/or modify it under the terms of
//the Ozone Library License version 1 published by ozone-db.org.
//
//The original code and portions created by SMB are
//Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
//
package org.ozoneDB.adminGui.feature.account.users;
import java.awt.BorderLayout;
import java.awt.Point;
import java.awt.event.MouseEvent;
import javax.swing.*;
import org.ozoneDB.adminGui.feature.account.Account;
import org.ozoneDB.adminGui.widget.TableSorter;
import org.ozoneDB.adminGui.widget.TitledPanel;
//#############################################################################
/**
* This class is used to manage the account list panel.
*
* @author <p align=center>Ibsen Ramos-Bonilla
* <br>Copyright © 1997-@year@ by SMB GmbH. All Rights Reserved.</p>
*
* @version 1.0
*/
//#############################################################################
public class UserPanel extends TitledPanel {
/** Handle to the parent panel. */
private JComponent parent;
/** Handle to the Users information instance. */
private UserAccount userAccount;
/** The account list table. */
private JTable userTable = new JTable();
/** Table model for the account list table. */
private UserTableModel userTableModel = new UserTableModel();
/** The object that provides column sorting. */
private TableSorter tableSorter = new TableSorter();
/** Indicates the last account selected. */
private String lastUser = "";
/**
* The overloaded constructor.
*
* @param parent - the account panel parent instance.
*/
public UserPanel(JComponent parent) {
super("Users");
this.parent = parent;
init();
//load the table
this.userAccount.list();
}
/**
* This method initializes the account panel.
*/
private void init() {
//set the account account
this.userAccount = new UserAccount(this);
//initialize the table components
//TODO:this.tableSorter.setModel(this.userTableModel);
//TODO:this.userTable.setModel(this.tableSorter);
this.userTable.setModel(this.userTableModel);
//set the account table and sorter routine
//TODO:this.tableSorter.addMouseListenerToHeaderInTable(this.userTable);
// TODO:userTable.getTableHeader().addMouseListener(this);
//add the controls to the panel
JScrollPane scrollPane = new JScrollPane(this.userTable);
this.add(scrollPane, BorderLayout.CENTER);
}
/**
* Sets the column sizes to appropriate widths and adds a mouse listener to
* the table so we know what row the account has selected.
*/
/*private void initTable()
{
//add a listener for click events on the table.
userTable.addMouseListener(new MouseAdapter()
{
/*
detect mouse pressed instead of mouse clicked on this table
because if you use mouseClicked and the account moves the mouse even
a pixel between mouse pressed and mouse released, the mouse
click event never happens and the module buttons therefore don't
get updated properly.
*/
/*public void mousePressed(MouseEvent e)
{
userTable_mousePressed(e);
}
});*/
//set up the columns
/*setUpColumns();
userTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
ETClientMouseEventAdapter etMouseAdapter =
new ETClientMouseEventAdapter (this.module.getFrame(),
this.userTable);
userTable.addMouseListener(etMouseAdapter);
userTable.addMouseMotionListener(etMouseAdapter);
resizeTable();
}*/
/**
* This method returns the id of the selected account.
*
* @return String -- account id.
*/
public String getId() {
try {
return (String) (this.userTable.getModel().
getValueAt(this.userTable.getSelectedRow(),
Account.COLUMN_POS_USER_ID));
} catch (Exception e) {
return null;
}
}
/**
* This method returns the name of the selected account.
*
* @return String -- account name.
*/
public String getName() {
try {
return (String) (this.userTable.getModel().
getValueAt(this.userTable.getSelectedRow(),
Account.COLUMN_POS_USER_NAME));
} catch (Exception e) {
return null;
}
}
/**
* This method returns the password of the selected account.
*
* @return String -- account password.
*/
public String getPassword() {
try {
return (String) (this.userTable.getModel().
getValueAt(this.userTable.getSelectedRow(),
Account.COLUMN_POS_USER_PWD));
} catch (Exception e) {
return null;
}
}
/**
* This method returns the status of the selected account.
*
* @return String - account current status.
*/
public String getStatus() {
try {
return (String) (this.userTable.getModel().
getValueAt(this.userTable.getSelectedRow(),
Account.COLUMN_POS_USER_STATUS));
} catch (Exception e) {
return null;
}
}
/**
* This method returns a handle to the account panel table.
*
* @return UserTable - handle to the account table.
*/
public JTable getTable() {
return this.userTable;
}
/**
* This method returns a handle to the account panel table model.
*
* @return UserTableModel - handle to the account table model.
*/
public UserTableModel getModel() {
return this.userTableModel;
}
/**
* This method returns a handle to the account panel table sorter.
*
* @return UserTableModel - handle to the account table sorter.
*/
public TableSorter getSorter() {
return this.tableSorter;
}
/**
* This method returns a handle to the account panel group information.
*
* @return Groups - the groups information instance.
*/
public UserAccount getUsers() {
return this.userAccount;
}
/**
* Returns the first name and last name of the account with the given id
* @param - String userId
* @return - an array of length two: first name and last name
*/
/*public String[] getUserNames(String userId)
{
String[] names = {"", ""};
//get the number of rows in the table
int rowCount = userTable.getRowCount();
boolean found = false;
int index = 0;
//go through the rows until the correct userid is found. Add the first
//and last names to the array.
while(!found && index < rowCount)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -