/*
*
* Panbox - encryption for cloud storage
* Copyright (C) 2014-2015 by Fraunhofer SIT and Sirrix AG
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additonally, third party code may be provided with notices and open source
* licenses from communities and third parties that govern the use of those
* portions, and any licenses granted hereunder do not alter any rights and
* obligations you may have under such open source licenses, however, the
* disclaimer of warranty and limitation of liability provisions of the GPLv3
* will apply to all the product.
*
*/
package org.panbox.desktop.common.gui;
import org.panbox.Settings;
import org.panbox.desktop.common.gui.addressbook.ContactListCellRenderer;
import org.panbox.desktop.common.gui.addressbook.ContactListModel;
import org.panbox.desktop.common.gui.addressbook.PanboxGUIContact;
import org.panbox.desktop.common.gui.addressbook.PanboxMyContact;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class AddContactToShareDialog extends javax.swing.JDialog {
/**
*
*/
private static final long serialVersionUID = 4892202577910829210L;
private final ContactListModel modelcopy = new ContactListModel();
private List<PanboxGUIContact> contacts = new ArrayList<PanboxGUIContact>();
private boolean aborted = false;
private static final ResourceBundle bundle = ResourceBundle.getBundle(
"org.panbox.desktop.common.gui.Messages", Settings.getInstance()
.getLocale());
public AddContactToShareDialog(java.awt.Frame parent, ContactListModel model, List<PanboxGUIContact> list) {
super(parent, true);
for (int i = 0, ctr = 0; i < model.getSize(); i++) {
if (!(model.get(i) instanceof PanboxMyContact) && !list.contains(model.get(i))) {
modelcopy.add(ctr++, model.get(i));
}
}
initComponents();
setLocationRelativeTo(parent);
if(modelcopy.getSize() == 0) {
addContacsButton.setEnabled(false);
}
}
/**
* 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
addContacsButton = new javax.swing.JButton();
abortButton = new javax.swing.JButton();
contactListScrollPane = new javax.swing.JScrollPane();
contactList = new javax.swing.JList<PanboxGUIContact>();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle(bundle.getString("AddContactToShareDialog.title")); // NOI18N
setResizable(false);
addContacsButton.setText(bundle.getString("AddContactToShareDialog.addContacsButton.text")); // NOI18N
addContacsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addContacsButtonActionPerformed(evt);
}
});
abortButton.setText(bundle.getString("AddContactToShareDialog.abortButton.text")); // NOI18N
abortButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
abortButtonActionPerformed(evt);
}
});
contactList.setModel(modelcopy);
contactList.setCellRenderer(new ContactListCellRenderer());
contactListScrollPane.setViewportView(contactList);
contactList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if(contactList.getSelectedValuesList().isEmpty()) {
addContacsButton.setEnabled(false);
} else {
addContacsButton.setEnabled(true);
}
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(contactListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(abortButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(addContacsButton)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(contactListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 397, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(addContacsButton)
.addComponent(abortButton))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void addContacsButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_addContacsButtonActionPerformed
contacts = contactList.getSelectedValuesList();
this.dispose();
}// GEN-LAST:event_addContacsButtonActionPerformed
private void abortButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_abortButtonActionPerformed
aborted = true;
this.dispose();
}// GEN-LAST:event_abortButtonActionPerformed
public List<PanboxGUIContact> getResult() throws OperationAbortedException {
if (aborted) {
throw new OperationAbortedException("Operation was aborted!");
} else if (contacts == null) {
throw new OperationAbortedException("No contacts selected!!");
} else {
return contacts;
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton abortButton;
private javax.swing.JButton addContacsButton;
private javax.swing.JList<PanboxGUIContact> contactList;
private javax.swing.JScrollPane contactListScrollPane;
// End of variables declaration//GEN-END:variables
}