
admin.astor.access.ChooseGroupDialog Maven / Gradle / Ivy
//+======================================================================
// $Source: $
//
// Project: Tango
//
// Description: Basic Dialog Class to display info
//
// $Author: pascal_verdier $
//
// Copyright (C) : 2004,2005,2006,2007,2008,2009,2009
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This file is part of Tango.
//
// Tango is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tango 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Tango. If not, see .
//
// $Revision: $
//
// $Log: $
//
//-======================================================================
package admin.astor.access;
import fr.esrf.tangoatk.widget.util.ATKGraphicsUtils;
import javax.swing.*;
import java.util.List;
//===============================================================
/**
* JDialog Class to display info
*
* @author Pascal Verdier
*/
//===============================================================
@SuppressWarnings("MagicConstant")
public class ChooseGroupDialog extends JDialog {
private int retVal = JOptionPane.OK_OPTION;
//===============================================================
/**
* Creates new form ChooseGroupDialog
*
* @param parent the JFrame parent instance
* @param title dialog title
* @param groups group list
*/
//===============================================================
public ChooseGroupDialog(JFrame parent, String title, List groups) {
super(parent, true);
initComponents();
for (UserGroup group : groups) {
groupComboBox.addItem(group);
}
groupComboBox.setEditable(true);
titleLabel.setText(title);
pack();
ATKGraphicsUtils.centerDialog(this);
}
//===============================================================
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
//===============================================================
// //GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
javax.swing.JPanel centerPanel = new javax.swing.JPanel();
groupComboBox = new javax.swing.JComboBox<>();
javax.swing.JPanel topPanel = new javax.swing.JPanel();
titleLabel = new javax.swing.JLabel();
javax.swing.JLabel dummyLbl = new javax.swing.JLabel();
javax.swing.JPanel bottomPanel = new javax.swing.JPanel();
javax.swing.JButton okBtn = new javax.swing.JButton();
javax.swing.JButton cancelBtn = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
centerPanel.setLayout(new java.awt.GridBagLayout());
groupComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
groupComboBoxActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
centerPanel.add(groupComboBox, gridBagConstraints);
titleLabel.setFont(new java.awt.Font("Dialog", 1, 18)); // NOI18N
titleLabel.setText("Dialog Title");
topPanel.add(titleLabel);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.insets = new java.awt.Insets(10, 10, 5, 0);
centerPanel.add(topPanel, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.insets = new java.awt.Insets(0, 0, 50, 0);
centerPanel.add(dummyLbl, gridBagConstraints);
getContentPane().add(centerPanel, java.awt.BorderLayout.CENTER);
okBtn.setText("OK");
okBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okBtnActionPerformed(evt);
}
});
bottomPanel.add(okBtn);
cancelBtn.setText("Cancel");
cancelBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelBtnActionPerformed(evt);
}
});
bottomPanel.add(cancelBtn);
getContentPane().add(bottomPanel, java.awt.BorderLayout.SOUTH);
pack();
}// //GEN-END:initComponents
//===============================================================
//===============================================================
@SuppressWarnings("UnusedParameters")
private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
retVal = JOptionPane.OK_OPTION;
doClose();
}//GEN-LAST:event_okBtnActionPerformed
//===============================================================
//===============================================================
@SuppressWarnings("UnusedParameters")
private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
retVal = JOptionPane.CANCEL_OPTION;
doClose();
}//GEN-LAST:event_cancelBtnActionPerformed
//===============================================================
//===============================================================
@SuppressWarnings("UnusedParameters")
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
retVal = JOptionPane.CANCEL_OPTION;
doClose();
}//GEN-LAST:event_closeDialog
//===============================================================
//===============================================================
@SuppressWarnings("UnusedParameters")
private void groupComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupComboBoxActionPerformed
retVal = JOptionPane.OK_OPTION;
doClose();
}//GEN-LAST:event_groupComboBoxActionPerformed
//===============================================================
/**
* Closes the dialog
*/
//===============================================================
private void doClose() {
setVisible(false);
dispose();
}
//===============================================================
//===============================================================
public int showDialog() {
setVisible(true);
return retVal;
}
//===============================================================
//===============================================================
public UserGroup getUserGroup() {
Object object = groupComboBox.getSelectedItem();
if (object instanceof UserGroup) {
return (UserGroup) object;
}
else {
String name = object.toString();
if (name.length()==0)
return null;
return new UserGroup(name);
}
}
//===============================================================
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox groupComboBox;
private javax.swing.JLabel titleLabel;
// End of variables declaration//GEN-END:variables
//===============================================================
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy