/*
* Copyright (c) 2010-2012 Thiago T. Sá
*
* This file is part of CloudReports.
*
* CloudReports 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.
*
* CloudReports 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.
*
* For more information about your rights as a user of CloudReports,
* refer to the LICENSE file or see <http://www.gnu.org/licenses/>.
*/
package cloudreports.gui;
import java.io.File;
/**
* The ManageEnvironments form.
* Most of its code is generated automatically by the NetBeans IDE.
*
* @author Thiago T. Sá
* @since 1.0
*/
public class ManageEnvironments extends javax.swing.JDialog {
/** Creates a new ManageEnvironments form. */
public ManageEnvironments() {
setModal(true);
initComponents();
}
/** 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
environmentsList = new javax.swing.JList();
addButton = new javax.swing.JButton();
removeButton = new javax.swing.JButton();
closeButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Simulation Environments");
setResizable(false);
environmentsList.setModel(new javax.swing.AbstractListModel() {
String[] strings = MainView.getEnvironmentsNames();
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
environmentsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
jScrollPane1.setViewportView(environmentsList);
addButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cloudreports/gui/resources/add.png"))); // NOI18N
addButton.setText("Add");
addButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
addButtonActionPerformed(evt);
}
});
removeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cloudreports/gui/resources/remove.png"))); // NOI18N
removeButton.setText("Remove");
removeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
removeButtonActionPerformed(evt);
}
});
closeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cloudreports/gui/resources/close.png"))); // NOI18N
closeButton.setText("Close");
closeButton.setMaximumSize(new java.awt.Dimension(109, 36));
closeButton.setMinimumSize(new java.awt.Dimension(109, 36));
closeButton.setPreferredSize(new java.awt.Dimension(109, 36));
closeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeButtonActionPerformed(evt);
}
});
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()
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(addButton)
.addComponent(removeButton))
.addComponent(closeButton, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {addButton, closeButton, removeButton});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 214, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(addButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(removeButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(closeButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {closeButton, removeButton});
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* Adds a new simulation environment when the Add button is clicked.
*
* @param evt an action event.
* @since 1.0
*/
private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
NewEnvironment ne = new NewEnvironment();
ne.setLocationRelativeTo(this);
ne.setVisible(true);
}//GEN-LAST:event_addButtonActionPerformed
/**
* Removes a simulation environment when the Remove button is clicked.
*
* @param evt an action event.
* @since 1.0
*/
private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
if(MainView.getEnvironmentsNames().length < 2) {
Dialog.showWarning(this, "There must be at least one active environment.");
return;
}
int answer = Dialog.showQuestionDialog(this, "Environment Removal", "Do you really want to remove this environment?");
if(answer == 1) {
String environmentName = environmentsList.getSelectedValue().toString();
File dbFile = new File("db/" + environmentName + ".cre");
dbFile.delete();
updateList();
MainView.updateEnvironmentsBox();
}
}//GEN-LAST:event_removeButtonActionPerformed
/**
* Disposes the form when the Close button is clicked.
*
* @param evt an action event.
* @since 1.0
*/
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeButtonActionPerformed
dispose();
}//GEN-LAST:event_closeButtonActionPerformed
/**
* Updates the environments list.
*
* @since 1.0
*/
public static void updateList() {
environmentsList.setModel(new javax.swing.AbstractListModel() {
String[] strings = MainView.getEnvironmentsNames();
@Override
public int getSize() { return strings.length; }
@Override
public Object getElementAt(int i) { return strings[i]; }
});
environmentsList.updateUI();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addButton;
private javax.swing.JButton closeButton;
private static javax.swing.JList environmentsList;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton removeButton;
// End of variables declaration//GEN-END:variables
}