package gui;
import java.awt.*;
import javax.swing.*;
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 java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Component;
import java.util.Enumeration;
import guicomponents.ComputeReportAndReportOptionsPanel;
import guicomponents.OneSetSelectionPanel;
import dao.RObject;
import dao.RObjectViewportTable;
import dao.TableSweaveTag;
import datastructures.ItemSet;
public class W2ItemSelectionFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Class variables
*
*/
private JButton cancel;
private JButton ok;
private GridBagLayout gbl;
private JCheckBox chk_showWi;
private OneSetSelectionPanel osSelPanel;
private ComputeReportAndReportOptionsPanel compRepAndRepOptPanel;
public W2ItemSelectionFrame() {
super.setTitle("W2 Test");
this.setIconImage(
new ImageIcon("./images/i16x16/isop_favicon.png").getImage());
osSelPanel = new OneSetSelectionPanel();
compRepAndRepOptPanel = new ComputeReportAndReportOptionsPanel("isop.W2");
// leftList.setFixedCellHeight(10);
// leftList.setFixedCellWidth(10);
cancel = new JButton("Cancel");
ok = new JButton("OK");
chk_showWi = new JCheckBox("showWi"/* show per item*/); // spaeter noch ausbessern
/* 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, chk_showWi, 0, 9, 1, 1, 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, 17,1, 1, GridBagConstraints.VERTICAL, 0, 0, GridBagConstraints.EAST, 0, 0);
addComponent(this, gbl, ok, 0, 17,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() {
for (Enumeration<ItemSet> eis = osSelPanel.getItemSets(); eis.hasMoreElements(); ) {
ItemSet is = eis.nextElement();
String rVarName = dao.Controller.fitRVarName("isopW2");
RObject isopW2 = new RObject(rVarName, "isop.W12(" + is.getRString() +" , type=2 , showWi="+ (chk_showWi.isSelected()?"TRUE":"FALSE") + ")");
if (compRepAndRepOptPanel.getTablePanel().isSelected()) {
RObjectViewportTable isopW2tab = new RObjectViewportTable(compRepAndRepOptPanel.getTablePanel().getLabel(),
isopW2);
TableSweaveTag tabswvtag;
if (compRepAndRepOptPanel.isInReport()) {
tabswvtag = new TableSweaveTag(isopW2tab);
tabswvtag.setLabel(compRepAndRepOptPanel.getTablePanel().getLabel());
tabswvtag.setCaption(compRepAndRepOptPanel.getTablePanel().getCaption());
tabswvtag.setDigits(compRepAndRepOptPanel.getTablePanel().getDigits());
} else tabswvtag = null;
dao.Controller.addTable(isopW2tab, 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);
}
}