Package guicomponents

Source Code of guicomponents.TableOptionsPanel

package guicomponents;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.LayoutManager;

import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;


import javax.swing.BorderFactory;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerListModel;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;

public class TableOptionsPanel extends JPanel {

 
    /**
   *
   */
  private static final long serialVersionUID = 1L;
   
    protected JCheckBox chkTable;
 
    protected JCheckBox chkCaption;
    protected JTextField txfCaption;
    protected JLabel lblLabel;
    protected JTextField txfLabel;
    protected JCheckBox chkDigits;
    protected JSpinner sprDigits;
   
    protected GridBagLayout gbl;
    protected JSeparator sep0;

    private TitledBorder title;
    private Border line;


  public TableOptionsPanel(String strLabel) {
      this(strLabel, true);
  }
   

  public TableOptionsPanel(String strLabel, boolean showPerformTableCheckBox) {
   
    chkTable = new JCheckBox("Perform Table");
    chkTable.setSelected(true);
    chkTable.setEnabled(true);
    chkTable.setVisible(showPerformTableCheckBox);
   
        chkCaption = new JCheckBox("Set Caption:");
        chkCaption.setEnabled(false);
        txfCaption = new JTextField("Fill in the caption here", 15); // wie gross solls werden?
        txfCaption.setEnabled(false);
        lblLabel = new JLabel("Set Label:");
        lblLabel.setEnabled(true);
        txfLabel = new JTextField(strLabel, 15); // wie gross solls werden?
        txfLabel.setEnabled(true);
        // align = new JCheckBox("align");
        // align.setEnabled(false);
        chkDigits = new JCheckBox("Set Digits:");
        chkDigits.setEnabled(false);

        Integer[] digitInts = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        SpinnerListModel digitsModel = new SpinnerListModel(digitInts);

        sprDigits = new JSpinner(digitsModel);
        sprDigits.setValue(3);
        sprDigits.setEnabled(false);       

       
       
       
        sep0 = new JSeparator();
 
       

        line = BorderFactory.createLineBorder(Color.LIGHT_GRAY);
        title = BorderFactory.createTitledBorder(line, "Table Options");
        title.setTitleJustification(TitledBorder.LEFT);
        this.setBorder(title);

       
        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  a                w  w 
                          // r  r  r  r  i                  p  p  n                e  e
                          // i  i  i  i  l                  a  a  c                i  i
                          // d  d  d  d  l                  d  d  h                g  g
                          // x  y  w  h                       x  y  o                h  h
                          //       i  e                                 r                t  t
                          //       d  i                                            x  y
                          //       t  g
                          //       h  h
                          //          t                     
       
        addComponent(this, gbl, chkTable,      0, 0, 2, 1, GridBagConstraints.HORIZONTAL,      0, 0, GridBagConstraints.LINE_START,  0, 0);       
        addComponent(this, gbl, lblLabel,      0, 1, 1, 1, GridBagConstraints.HORIZONTAL,      0, 0, GridBagConstraints.LINE_START,  0, 0);
        addComponent(this, gbl, txfLabel,      1, 1, 1, 1, GridBagConstraints.HORIZONTAL,      0, 0, GridBagConstraints.LINE_START,  0, 0);
        addComponent(this, gbl, chkCaption,    0, 2, 1, 1, GridBagConstraints.HORIZONTAL,     0, 0, GridBagConstraints.LINE_START,  0, 0);
        addComponent(this, gbl, txfCaption,    1, 2, 1, 1, GridBagConstraints.HORIZONTAL,      0, 0, GridBagConstraints.LINE_START,  0, 0);
        addComponent(this, gbl, chkDigits,     0, 3, 1, 1, GridBagConstraints.HORIZONTAL,      0, 0, GridBagConstraints.LINE_START,  0, 0);
        addComponent(this, gbl, sprDigits,     1, 3, 1, 1, GridBagConstraints.HORIZONTAL,     0, 0, GridBagConstraints.LINE_START,  0, 0)

        chkCaption.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                  txfCaption.setEnabled(true);
                }
                if (e.getStateChange() == ItemEvent.DESELECTED) {
                  txfCaption.setText("");
                  txfCaption.setText("Fill in the caption here");
                  txfCaption.setEnabled(false);
                }
            }
        });

        chkDigits.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                  sprDigits.setValue(3);
                  sprDigits.setEnabled(true);
                }
                if (e.getStateChange() == ItemEvent.DESELECTED) {
                  sprDigits.setValue(3);
                  sprDigits.setEnabled(false);
                }
            }
        });

    // TODO Auto-generated constructor stub
  }



 
  public TableOptionsPanel(LayoutManager arg0) {
    super(arg0);
    // TODO Auto-generated constructor stub
  }

  public TableOptionsPanel(boolean arg0) {
    super(arg0);
    // TODO Auto-generated constructor stub
  }

  public TableOptionsPanel(LayoutManager arg0, boolean arg1) {
    super(arg0, arg1);
    // TODO Auto-generated constructor stub
  }

    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);
    }

  public boolean isSelected() {
    // TODO Auto-generated method stub
    return this.chkTable.isSelected();
  }

  public String getLabel() {
    // TODO Auto-generated method stub
    return this.txfLabel.getText();
  }  

  public String getCaption() {
    // TODO Auto-generated method stub
    return (this.chkCaption.isSelected()?this.txfCaption.getText():null);
  }
 
  public int getDigits(){
    if (chkDigits.isSelected() == false)
      return 3;
   
    int tmp = (Integer) sprDigits.getValue();
    return tmp;
  }
//  public boolean isSelected() {
//    // TODO Auto-generated method stub
//    return isSelected();
//  }  
}


TOP

Related Classes of guicomponents.TableOptionsPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.