
org.tango.pogo.pogo_gui.tools.PogoConfiguration Maven / Gradle / Ivy
//+======================================================================
//
// Project: Tango
//
// Description: Basic Dialog Class to manage Pogo configuration.
//
// $Author: verdier $
//
// Copyright (C) : 2004,2005,2006,2007,2008,2009,2009,2010,2011,2012,2013,2014
// 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: $
// $Date: $
//
// $HeadURL: $
//
//-======================================================================
package org.tango.pogo.pogo_gui.tools;
import fr.esrf.tangoatk.widget.util.ATKGraphicsUtils;
import javax.swing.*;
import java.awt.*;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
//===============================================================
/**
* JDialog Class to display and modify Pogo configuration
*
* @author Pascal Verdier
*/
//===============================================================
@SuppressWarnings("MagicConstant")
public class PogoConfiguration extends JDialog {
private Component parent;
private List families;
private int retVal = JOptionPane.CANCEL_OPTION;
//===============================================================
/**
* Creates new form PogoConfiguration
*
* @param parent The JFrame parent instance
*/
//===============================================================
public PogoConfiguration(JFrame parent) {
super(parent, true);
this.parent = parent;
initComponents();
titleLabel.setToolTipText(Utils.buildToolTip("Class Families",
"If you use your own repository with specific class families\n" +
"Add your institute name on right fields\n" +
" and the specific family names below.\n" +
"It will ne used for Class Identification Window."));
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
@SuppressWarnings("Convert2Diamond")
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
javax.swing.JPanel bottomPanel = new javax.swing.JPanel();
javax.swing.JButton okBtn = new javax.swing.JButton();
javax.swing.JButton cancelBtn = new javax.swing.JButton();
javax.swing.JPanel rightPanel = new javax.swing.JPanel();
javax.swing.JButton addBtn = new javax.swing.JButton();
javax.swing.JButton removeBtn = new javax.swing.JButton();
javax.swing.JScrollPane familyScrollPane = new javax.swing.JScrollPane();
familyList = new javax.swing.JList();
javax.swing.JPanel topTopPanel = new javax.swing.JPanel();
javax.swing.JLabel copyrightLabel = new javax.swing.JLabel();
javax.swing.JScrollPane copyrightScrollPane = new javax.swing.JScrollPane();
copyrightText = new javax.swing.JTextArea();
javax.swing.JPanel topPanel = new javax.swing.JPanel();
titleLabel = new javax.swing.JLabel();
siteLabel = new javax.swing.JTextField();
javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
javax.swing.JButton helpBtn = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
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);
rightPanel.setLayout(new java.awt.GridBagLayout());
addBtn.setText("Add");
addBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addBtnActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(60, 0, 5, 0);
rightPanel.add(addBtn, gridBagConstraints);
removeBtn.setText("Remove");
removeBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeBtnActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
rightPanel.add(removeBtn, gridBagConstraints);
getContentPane().add(rightPanel, java.awt.BorderLayout.LINE_END);
familyScrollPane.setPreferredSize(new java.awt.Dimension(300, 360));
familyScrollPane.setViewportView(familyList);
getContentPane().add(familyScrollPane, java.awt.BorderLayout.CENTER);
topTopPanel.setLayout(new java.awt.BorderLayout());
copyrightLabel.setText("Copyright:");
topTopPanel.add(copyrightLabel, java.awt.BorderLayout.NORTH);
copyrightScrollPane.setPreferredSize(new java.awt.Dimension(400, 100));
copyrightText.setColumns(40);
copyrightText.setFont(new java.awt.Font("Monospaced", 1, 12)); // NOI18N
copyrightText.setRows(5);
copyrightScrollPane.setViewportView(copyrightText);
topTopPanel.add(copyrightScrollPane, java.awt.BorderLayout.CENTER);
titleLabel.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
titleLabel.setText("Specific Class Family Names for ");
topPanel.add(titleLabel);
siteLabel.setColumns(10);
siteLabel.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
topPanel.add(siteLabel);
jLabel1.setText(" ");
topPanel.add(jLabel1);
helpBtn.setText("?");
helpBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
helpBtnActionPerformed(evt);
}
});
topPanel.add(helpBtn);
topTopPanel.add(topPanel, java.awt.BorderLayout.SOUTH);
getContentPane().add(topTopPanel, java.awt.BorderLayout.NORTH);
pack();
}// //GEN-END:initComponents
//===============================================================
//===============================================================
@SuppressWarnings({"UnusedDeclaration"})
private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
// Write families in file
try {
PogoProperty.siteName = siteLabel.getText();
PogoProperty.copyright = copyrightText.getText();
if (PogoProperty.getInstance().updateSitePropertyFile(this)) {
retVal = JOptionPane.OK_OPTION;
doClose();
}
} catch (Exception e) {
PogoException.popup(this, e);
}
}//GEN-LAST:event_okBtnActionPerformed
//===============================================================
//===============================================================
@SuppressWarnings({"UnusedDeclaration"})
private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
doClose();
}//GEN-LAST:event_cancelBtnActionPerformed
//===============================================================
//===============================================================
@SuppressWarnings({"UnusedDeclaration"})
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
doClose();
}//GEN-LAST:event_closeDialog
//===============================================================
//===============================================================
@SuppressWarnings({"unchecked", "UnusedDeclaration"})
private void addBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addBtnActionPerformed
String new_family = "";
boolean ok = false;
while (!ok) {
new_family = (String) JOptionPane.showInputDialog(this,
"Family Name ",
"Input Dialog",
JOptionPane.INFORMATION_MESSAGE,
null, null, new_family);
if (new_family == null || new_family.length() == 0)
return;
// Check if already exists
boolean found = false;
for (String family : families)
if (family.equalsIgnoreCase(new_family))
found = true;
if (found) {
Utils.popupError(this, new_family + " family already exists");
} else {
ok = true;
}
}
families.add(new_family);
MyCompare compare = new MyCompare();
Collections.sort(families, compare);
setFamilyList();
}//GEN-LAST:event_addBtnActionPerformed
//===============================================================
//===============================================================
private void setFamilyList() {
familyList.setListData(families.toArray(new String[families.size()]));
}
//===============================================================
//===============================================================
@SuppressWarnings({"UnusedDeclaration"})
private void removeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeBtnActionPerformed
List selections = familyList.getSelectedValuesList();
if (selections.isEmpty()) {
JOptionPane.showMessageDialog(this,
"Nothing selected to be removed !", "Error Window",
JOptionPane.ERROR_MESSAGE);
}
else {
for (Object selection : selections) {
String name = (String) selection;
for (String family : families) {
if (family.equals(name)) {
families.remove(family);
break;
}
}
}
setFamilyList();
}
}//GEN-LAST:event_removeBtnActionPerformed
//===============================================================
//===============================================================
@SuppressWarnings({"UnusedDeclaration"})
private void helpBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpBtnActionPerformed
JOptionPane.showMessageDialog(this,
"If you use your own repository with specific class families,\n" +
"enter your site name and use the list to add or remove your \n" +
"specific families.",
"Help Window",
JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_helpBtnActionPerformed
//===============================================================
/**
* Closes the dialog
*/
//===============================================================
private void doClose() {
if (parent==null)
System.exit(0);
else {
setVisible(false);
dispose();
}
}
//===============================================================
//===============================================================
private void displayProperties() throws PogoException {
siteLabel.setText(PogoProperty.siteName);
copyrightText.setText(PogoProperty.copyright);
families = PogoProperty.siteClassFamilies;
setFamilyList();
pack();
}
//===============================================================
//===============================================================
public int showDialog() {
try {
displayProperties();
setVisible(true);
} catch (Exception e) {
PogoException.popup(new JFrame(), e);
}
return retVal;
}
//===============================================================
//===============================================================
//===============================================================
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea copyrightText;
private javax.swing.JList familyList;
private javax.swing.JTextField siteLabel;
private javax.swing.JLabel titleLabel;
// End of variables declaration//GEN-END:variables
//===============================================================
//===============================================================
/**
* @param args the command line arguments
*/
//===============================================================
public static void main(String args[]) {
try {
PogoProperty.init();
new PogoConfiguration(null).showDialog();
} catch (Exception e) {
PogoException.popup(new JFrame(), e);
System.exit(0);
}
}
//======================================================
/**
* MyCompare class to sort collection
*/
//======================================================
class MyCompare implements Comparator {
public int compare(Object o1, Object o2) {
if (o1 instanceof String &&
o2 instanceof String) {
String s1 = o1.toString().toLowerCase();
String s2 = o2.toString().toLowerCase();
if (s1.equals("miscellaneous"))
return 0;
else if (s2.equals("miscellaneous"))
return 1;
else
return s1.compareTo(s2);
} else
return o1.toString().compareTo(o2.toString());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy