package gui;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import helper.Helper;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Component;
import java.util.Enumeration;
import guicomponents.ComputeReportAndReportOptionsPanel;
import guicomponents.OneSetSelectionPanel;
import guicomponents.ReturnValuesPanel;
import dao.RObject;
import dao.RObjectViewportTable;
import dao.TableSweaveTag;
import datastructures.ItemSet;
public class OneSetItemSelectionFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Class variables
*
*/
private JButton cancel;
private JButton ok;
private GridBagLayout gbl;
private OneSetSelectionPanel osSelPanel;
private ReturnValuesPanel rvPanel;
private ComputeReportAndReportOptionsPanel compRepAndRepOptPanel;
public OneSetItemSelectionFrame() {
super.setTitle("One-Set-MV-G Test");
this.setIconImage(
new ImageIcon("./images/i16x16/isop_favicon.png").getImage());
osSelPanel = new OneSetSelectionPanel();
rvPanel = new ReturnValuesPanel();
compRepAndRepOptPanel = new ComputeReportAndReportOptionsPanel("isop1set");
// leftList.setFixedCellHeight(10);
// leftList.setFixedCellWidth(10);
cancel = new JButton("Cancel");
ok = new JButton("OK");
/* set Tooltips for each component
leftLabel.setToolTipText("This is only a test.");
rightLabel.setToolTipText("This is only a test.");
fuellLabel1.setToolTipText("This is only a test.");
fuellLabel2.setToolTipText("This is only a test.");
fuellLabel3.setToolTipText("This is only a test.");
fuellLabel4.setToolTipText("This is only a test.");
toRight.setToolTipText("This is only a test.");
toLeft.setToolTipText("This is only a test.");
onlyCompute.setToolTipText("This is only a test.");
computeAndReport.setToolTipText("This is only a test.");
onlyReport.setToolTipText("This is only a test.");
cancel.setToolTipText("This is only a test.");
rightList.setToolTipText("This is only a test.");
leftList.setToolTipText("This is only a testtest.");
sep.setToolTipText("This is only a test.");
chkLatex.setToolTipText("This is only a test.");
chkVerbose.setToolTipText("Das ist Verbose");
chk_n.setToolTipText("This is only a test.");
chk_p.setToolTipText("This is only a test.");
chk_g.setToolTipText("This is only a test.");
chk_s.setToolTipText("This is only a test.");
chk_ubas.setToolTipText("This is only a test.");
chk_i.setToolTipText("This is only a test.");
chk_c.setToolTipText("This is only a test.");
chk_nsq.setToolTipText("This is only a test.");
chk_z.setToolTipText("This is only a test."); */
gbl = new GridBagLayout();
this.setLayout(gbl);
// Z Z Z Z F
// e e e e ü
// l l l l l
// l l l l l
// s z w h v
// p e e o e
// a i i e r
// l l t h h
// t e e e a
// e l
// t
// e
// n
// g g g g f i i i a w w
// r r r r i p p n n e e
// i i i i l a a s c i i
// d d d d l d d e h g g
// x y w h x y t o h h
// i e s r t t
// d i x y
// t g
// h h
// t
addComponent(this, gbl, osSelPanel, 0, 0, 4, 4, GridBagConstraints.HORIZONTAL, 0, 0, GridBagConstraints.CENTER, 0,0);
addComponent(this, gbl, rvPanel, 0, 4, 4, 3, GridBagConstraints.HORIZONTAL, 0, 0, GridBagConstraints.LINE_START, 0,0);
addComponent(this, gbl, compRepAndRepOptPanel, 0,10, 3, 6, GridBagConstraints.HORIZONTAL, 0, 0, GridBagConstraints.CENTER, 0,0);
addComponent(this, gbl, cancel, 3, 16,1, 1, GridBagConstraints.VERTICAL, 0, 0, GridBagConstraints.EAST, 0, 0);
addComponent(this, gbl, ok, 0, 16,1, 1, GridBagConstraints.VERTICAL, 0, 0, GridBagConstraints.CENTER, 0, 0);
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
btncancelClicked();
}
});
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
btnOkClicked();
}
});
}
/**
* @param computeEnabled
* @param reportEnabled
*/
private void btncancelClicked() {
this.setVisible(false);
}
private void btnOkClicked() {
if ( rvPanel.getReturnValuesAlaZdenko().equals("c( )") ){
Helper.ok("Error - No result value is selected.");
return;
}
if (osSelPanel.osiSelPanel.rightListModel.getSize()>0){
;
}else{
Helper.ok("Error - No Items are selected.");
return;
}
for (Enumeration<ItemSet> eis = osSelPanel.getItemSets(); eis.hasMoreElements(); ) {
ItemSet is = eis.nextElement();
String rVarName = dao.Controller.fitRVarName("isop1set");
String command = "isop.calc1set(" + is.getRString() + ")";
RObject isop1set = new RObject(rVarName, command+"[" + rvPanel.getReturnIndices() + "]");
if (compRepAndRepOptPanel.getTablePanel().isSelected()) {
RObjectViewportTable isop1settab = new RObjectViewportTable(compRepAndRepOptPanel.getTablePanel().getLabel(),
isop1set);
TableSweaveTag tabswvtag;
if (compRepAndRepOptPanel.isInReport()) {
tabswvtag = new TableSweaveTag(isop1settab);
tabswvtag.setLabel(compRepAndRepOptPanel.getTablePanel().getLabel());
tabswvtag.setCaption(compRepAndRepOptPanel.getTablePanel().getCaption());
tabswvtag.setDigits(compRepAndRepOptPanel.getTablePanel().getDigits());
} else tabswvtag = null;
dao.Controller.addTable(isop1settab, compRepAndRepOptPanel.isEvaled(), compRepAndRepOptPanel.isEvaled(),
tabswvtag);
}
}
this.setVisible(false);
}
private void addComponent(Container cont,
GridBagLayout gbl,
Component c,
int gridx, int gridy,
int gridwidth, int gridheight,
int fill,
int ipadx, int ipady,
/* Insets insets, */
int anchor,
double weightx, double weighty) {
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = gridx;
gbc.gridy = gridy; // Spalte/Reihe mit ganz links = 0 und ganz oben = 0
gbc.gridwidth = gridwidth;
gbc.gridheight = gridheight; // Anzahl Spalten/Reihen, die Komponente nutzt - DEFAULT = 1;
gbc.fill = fill; // entscheidet howto resize the component, wenn sie vergrößert wird = NONE , HORIZONTAL, VERTICAL, BOTH
gbc.ipadx = ipadx;
gbc.ipady = ipady; // interne Füllung (howmuch to add to the minimum weight/height of the component
// gbc.insets = insets; // externe Füllung (howmuch is the minimum space between component and the edges of its display area)
gbc.anchor = anchor; // used if component kleiner als seine display area (verschiedene Konstanten)
gbc.weightx = weightx;
gbc.weighty = weighty; // determines howto distribute space among columns and rows
gbl.setConstraints(c, gbc);
cont.add(c);
}
}