
admin.astor.tools.LastBranchesListDialog 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.tools;
import fr.esrf.Tango.DevFailed;
import fr.esrf.tangoatk.widget.util.ATKGraphicsUtils;
import fr.esrf.tangoatk.widget.util.ErrorPane;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
//===============================================================
/**
* JDialog Class to display info
*
* @author Pascal Verdier
*/
//===============================================================
@SuppressWarnings({"MagicConstant", "Convert2Diamond"})
public class LastBranchesListDialog extends JDialog {
private JFrame parent;
private List branches;
private int returnValue = JOptionPane.OK_OPTION;
//===============================================================
/**
* Creates new form LastBranchesListDialog
*/
//===============================================================
public LastBranchesListDialog(JFrame parent, List branches, String[] lastBranches) throws DevFailed {
super(parent, true);
this.parent = parent;
this.branches = branches;
initComponents();
branchList.removeAll();
if (lastBranches!=null && lastBranches.length>0)
branchList.setListData(lastBranches);
removeBtn.setEnabled(false);
upBtn.setEnabled(false);
downBtn.setEnabled(false);
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 topPanel = new javax.swing.JPanel();
javax.swing.JLabel titleLabel = 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();
javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
branchList = new javax.swing.JList();
javax.swing.JPanel eastPanel = new javax.swing.JPanel();
removeBtn = new javax.swing.JButton();
javax.swing.JButton addBtn = new javax.swing.JButton();
upBtn = new javax.swing.JButton();
downBtn = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
titleLabel.setFont(new java.awt.Font("Dialog", 1, 14)); // NOI18N
titleLabel.setText("Branch(es) to be displayed at bottom");
titleLabel.setToolTipText("");
topPanel.add(titleLabel);
getContentPane().add(topPanel, java.awt.BorderLayout.NORTH);
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);
branchList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
branchListValueChanged(evt);
}
});
jScrollPane1.setViewportView(branchList);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
eastPanel.setLayout(new java.awt.GridBagLayout());
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 = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
eastPanel.add(removeBtn, gridBagConstraints);
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 = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
eastPanel.add(addBtn, gridBagConstraints);
upBtn.setText("Up");
upBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
upBtnActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 5;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
eastPanel.add(upBtn, gridBagConstraints);
downBtn.setText("Down");
downBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
downBtnActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 6;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
eastPanel.add(downBtn, gridBagConstraints);
getContentPane().add(eastPanel, java.awt.BorderLayout.EAST);
pack();
}// //GEN-END:initComponents
//===============================================================
//===============================================================
@SuppressWarnings("UnusedParameters")
private void okBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okBtnActionPerformed
returnValue = JOptionPane.OK_OPTION;
doClose();
}//GEN-LAST:event_okBtnActionPerformed
//===============================================================
//===============================================================
@SuppressWarnings("UnusedParameters")
private void cancelBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelBtnActionPerformed
returnValue = JOptionPane.CANCEL_OPTION;
doClose();
}//GEN-LAST:event_cancelBtnActionPerformed
//===============================================================
//===============================================================
@SuppressWarnings("UnusedParameters")
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
returnValue = JOptionPane.CANCEL_OPTION;
doClose();
}//GEN-LAST:event_closeDialog
//===============================================================
//===============================================================
@SuppressWarnings("UnusedParameters")
private void removeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeBtnActionPerformed
String selection = branchList.getSelectedValue();
ListModel model = branchList.getModel();
List stringList = new ArrayList<>();
for (int i=0 ; i lastBranches = new ArrayList<>();
ListModel model = branchList.getModel();
for (int i=0 ; i availableBranches = new ArrayList<>();
for (String branch : branches) {
if (!branch.equals("Tango Database")) {
boolean found = false;
for (String lastBranch : lastBranches) {
if (branch.equals(lastBranch))
found = true;
}
if (!found)
availableBranches.add(branch);
}
}
if (availableBranches.size()==0) {
Utils.popupError(parent, "No branch available !");
return;
}
// And propose a selection list
String[] array = new String[availableBranches.size()];
for (int i=0 ; i lastBranches = new ArrayList<>();
ListModel model = branchList.getModel();
for (int i=0 ; i lastBranches = new ArrayList<>();
ListModel model = branchList.getModel();
for (int i=0 ; i=lastBranches.size()-1)
return;
lastBranches.remove(i);
lastBranches.add(i+1, selection);
i++;
}
}
branchList.setListData(lastBranches.toArray(new String[lastBranches.size()]));
branchList.setSelectedValue(selection,true);
}//GEN-LAST:event_downBtnActionPerformed
//===============================================================
/**
* Closes the dialog
*/
//===============================================================
private void doClose() {
if (parent==null)
System.exit(0);
else {
setVisible(false);
dispose();
}
}
//===============================================================
//===============================================================
public String[] getLastBranches() {
ListModel model = branchList.getModel();
String[] array = new String[model.getSize()];
for (int i=0 ; i branchList;
private javax.swing.JButton downBtn;
private javax.swing.JButton removeBtn;
private javax.swing.JButton upBtn;
// End of variables declaration//GEN-END:variables
//===============================================================
//===============================================================
/**
* @param args the command line arguments
*/
//===============================================================
public static void main(String args[]) {
try {
String[] last = { "Miscellaneous", "Insertion Devices" };
List branches = new ArrayList<>();
branches.add("AAAA");
branches.add("In Test");
branches.add("Miscellaneous");
branches.add("Insertion Devices");
branches.add("Development");
new LastBranchesListDialog(null, branches, last).setVisible(true);
}
catch(DevFailed e) {
ErrorPane.showErrorMessage(new Frame(), null, e);
System.exit(0);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy