/*
PseudoCode Interpreted Language (PCIL): Part of the algoviz@vt collection of algorithm visualizations.
Copyright (C) 2008 Brandon Malone, Frank Hadlock
This file is part of the PseudoCode Interpreted Language.
PseudoCode Interpreted Language 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.
PseudoCode Interpreted Language 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
PseudoCode Interpreted Language. If not, see
.
*/
/*
* CheckBoxView.java
*
* Created on August 15, 2008, 10:56 PM
*/
package dynamicmvc;
import java.awt.Component;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.JCheckBox;
/**
*
* @author Brandon
*/
public class CheckBoxView extends javax.swing.JFrame {
public final static Object buttonPressed = new Object();
ICheckBoxViewCaller caller;
Object callerFlag;
/** Creates new form CheckBoxView */
public CheckBoxView(String title, String text, Collection options, ArrayList uncheckedOptions, ICheckBoxViewCaller caller, Object callerFlag) {
initComponents();
this.setTitle(title);
this.callerFlag = callerFlag;
this.lblText.setText(text);
for(String option : options) {
JCheckBox cb = new JCheckBox(option);
cb.setActionCommand(option);
if (!uncheckedOptions.contains(option)) {
cb.setSelected(true);
}
this.pnlList.add(cb);
}
btnOK.setSelected(true);
this.caller = caller;
this.setSize(this.getPreferredSize());
}
protected ArrayList getCheckedOptions() {
ArrayList checkedOptions = new ArrayList();
for(Component c : pnlList.getComponents()) {
if(c instanceof JCheckBox) {
JCheckBox cb = (JCheckBox)c;
if(cb.isSelected()) {
checkedOptions.add(cb.getActionCommand());
}
}
}
return checkedOptions;
}
protected ArrayList getUncheckedOptions() {
ArrayList uncheckedOptions = new ArrayList();
for(Component c : pnlList.getComponents()) {
if(c instanceof JCheckBox) {
JCheckBox cb = (JCheckBox)c;
if(!cb.isSelected()) {
uncheckedOptions.add(cb.getActionCommand());
}
}
}
return uncheckedOptions;
}
/** 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() {
btnOK = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
pnlList = new javax.swing.JPanel();
lblText = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
btnOK.setText("OK");
btnOK.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnOKMouseClicked(evt);
}
});
btnCancel.setText("Cancel");
btnCancel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnCancelMouseClicked(evt);
}
});
pnlList.setBorder(javax.swing.BorderFactory.createTitledBorder("List"));
lblText.setText("text");
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(pnlList, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
.addComponent(lblText)
.addGroup(layout.createSequentialGroup()
.addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCancel)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblText)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlList, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnOK)
.addComponent(btnCancel))
.addContainerGap())
);
pack();
}// //GEN-END:initComponents
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
if (callerFlag != buttonPressed) {
caller.cancelClicked(this, callerFlag);
callerFlag = buttonPressed;
}
}//GEN-LAST:event_formWindowClosing
private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
// TODO add your handling code here:
if (callerFlag != buttonPressed) {
caller.cancelClicked(this, callerFlag);
callerFlag = buttonPressed;
}
}//GEN-LAST:event_formWindowClosed
private void btnCancelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelMouseClicked
// TODO add your handling code here:
caller.cancelClicked(this, callerFlag);
callerFlag = buttonPressed;
}//GEN-LAST:event_btnCancelMouseClicked
private void btnOKMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnOKMouseClicked
// TODO add your handling code here:
caller.okClicked(this, callerFlag);
callerFlag = buttonPressed;
}//GEN-LAST:event_btnOKMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnOK;
private javax.swing.JLabel lblText;
private javax.swing.JPanel pnlList;
// End of variables declaration//GEN-END:variables
}