📄 adduserdialog.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.//// $Id: AddUserDialog.java,v 1.1 2003/11/09 15:47:32 per_nyfelt Exp $package org.ozoneDB.adminGui.feature.account;import org.ozoneDB.adminGui.main.AdminGui;import org.ozoneDB.adminGui.res.Settings;import org.ozoneDB.adminGui.widget.QuickButton;import org.ozoneDB.adminGui.widget.QuickLabel;import org.ozoneDB.adminGui.widget.MessageBox;import org.ozoneDB.core.User;import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;/** * Prompts for username and id so that a a new account can be created */public class AddUserDialog extends JDialog { private static final Dimension DIALOG_SIZE = new Dimension(400, 200); private JTextField userNameField; private JTextField userIdField; private boolean inputOK = false; public AddUserDialog(Frame owner, String title) { super(owner, title, true); userNameField = new JTextField(10); userNameField.setBackground(Color.WHITE); userIdField = new JTextField(10); userIdField.setBackground(Color.WHITE); setDefaultCloseOperation(DISPOSE_ON_CLOSE); doGUILayout(); setVisible(true); } private void doGUILayout() { setSize(DIALOG_SIZE); setLocationRelativeTo(null); setResizable(false); getContentPane().add(createContentPanel(), BorderLayout.CENTER); getContentPane().add(createButtonPanel(), BorderLayout.SOUTH); } private JPanel createContentPanel() { JPanel panel = new JPanel(new GridBagLayout()); panel.setBorder(BorderFactory.createLoweredBevelBorder()); panel.setBackground(Color.WHITE); GridBagConstraints gbc = new GridBagConstraints(); gbc.weightx = 1.0d; gbc.weighty = 1.0d; gbc.insets = new Insets(0, 10, 0, 10); gbc.anchor = GridBagConstraints.EAST; gbc.gridy = 0; gbc.gridx = 0; panel.add(new QuickLabel("User name", Settings.COLOR_COBALT), gbc); gbc.anchor = GridBagConstraints.WEST; gbc.gridx++; panel.add(userNameField, gbc); gbc.anchor = GridBagConstraints.EAST; gbc.gridy++; gbc.gridx = 0; panel.add(new QuickLabel("User Id", Settings.COLOR_COBALT), gbc); gbc.anchor = GridBagConstraints.WEST; gbc.gridx++; panel.add(userIdField, gbc); return panel; } private JPanel createButtonPanel() { JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER)); QuickButton ok = new QuickButton("OK", new OKListener()); ok.setBackground(Color.WHITE); panel.add(ok); QuickButton close = new QuickButton("Close", new CloseListener()); close.setBackground(Color.WHITE); panel.add(close); return panel; } public boolean isInputOK() { return inputOK; } public String getUserName() { return userNameField.getText(); } public int getUserId() { return Integer.parseInt(userIdField.getText()); } class OKListener implements ActionListener { public void actionPerformed(ActionEvent ae) { try { User user = AdminGui.instance().getAdmin().userForName(getUserName()); if (user == null) { inputOK = true; AddUserDialog.this.hide(); } else { inputOK = false; MessageBox.showInfo("User exists", "User " + getUserName() + " already exist"); } } catch (Exception e) { inputOK = false; MessageBox.showError("Failed to check for existing account", e.toString()); } } } class CloseListener implements ActionListener { public void actionPerformed(ActionEvent ae) { inputOK = false; AddUserDialog.this.hide(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -