1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
| public class SlowControl extends JPanel {
// Declare GridBagLayout constraints
GridBagConstraints gbc = new GridBagConstraints();
private Data data;
// Add SlowControl
private JTextField txtNameAdd = new JTextField();
private JTextField txtPathAdd = new JTextField();
private JFormattedTextField txtDateAcqAdd = new JFormattedTextField(" YYYY-MM-DD HH:MM:SS ");
private JLabel lblAdd = new JLabel("Add SlowControl :");
private JLabel lblInfoAdd = new JLabel("Informations :");
private JLabel lblPathAdd = new JLabel("Path :");
private JLabel lblRunNameAdd = new JLabel("Run name :");
private JLabel lblDateAcqAdd = new JLabel("Date acq :");
private JLabel lblNameAdd = new JLabel("Name :");
private JComboBox cmbRunNameAdd;
private JComboBox cmbRunNameSearch;
private JComboBox cmbNameSearch;
private JButton butAdd = new JButton("Add");
private JButton butSearch = new JButton("Search");
private JButton butInfo = new JButton("Read Informations");
private JButton butModify = new JButton("Modify");
private JButton butDelete = new JButton("Delete");
private JSeparator sepAdd = new JSeparator(SwingConstants.VERTICAL);
private JSeparator sepBoth = new JSeparator(SwingConstants.HORIZONTAL);
/**
* Create a JPanel which contains all SlowControl tab's components.
*/
public SlowControl() {
super();
this.setBackground(Color.WHITE);
this.setLayout(new GridBagLayout());
// add a line border to the JPanel
this.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
initAdd();
this.txtPathAdd.setText("Gros test !");
}
/**
* Creates the slowControl's add unit.
*/
private void initAdd() {
// filling up comboBox with data from database
this.data = new Data("run_name", "RUN");
ArrayList result = this.data.selectFieldData();
this.cmbRunNameAdd = new JComboBox(this.data.arrayListToString(result));
// set preffered size and minimum size for all txt and but component
this.cmbRunNameAdd.setPreferredSize(cmbRunNameAdd.getPreferredSize());
this.cmbRunNameAdd.setMinimumSize(new Dimension(100, 20));
this.txtDateAcqAdd.setPreferredSize(this.cmbRunNameAdd.getPreferredSize());
this.txtDateAcqAdd.setMinimumSize(this.cmbRunNameAdd.getMinimumSize());
this.txtNameAdd.setPreferredSize(this.cmbRunNameAdd.getPreferredSize());
this.txtNameAdd.setMinimumSize(this.cmbRunNameAdd.getMinimumSize());
this.txtPathAdd.setPreferredSize(this.cmbRunNameAdd.getPreferredSize());
this.txtPathAdd.setMinimumSize(this.cmbRunNameAdd.getMinimumSize());
this.butAdd.setPreferredSize(this.butInfo.getPreferredSize());
this.butAdd.setMinimumSize(new Dimension (80, 30));
// set constraints for lblAdd
constraints(this.lblAdd, 0, 0, GridBagConstraints.REMAINDER, 1, GridBagConstraints.NONE,
new Insets(10,15,0,0), GridBagConstraints.LINE_START, 0, 0);
// set constraints for lblInfoAdd
constraints(this.lblInfoAdd, 1, 1, GridBagConstraints.REMAINDER, 1, GridBagConstraints.NONE,
new Insets(10,15,0,0), GridBagConstraints.LINE_START, 0, 0);
// set constraints for lblNameAdd
constraints(this.lblNameAdd, 2, 2, 1, 1, GridBagConstraints.NONE, new Insets(10,15,0,0),
GridBagConstraints.LINE_START, 0, 0);
// set constraints for txtNameAdd
// we use the GridBagContraints.RELATIVE property to set gridx. It means that gridx take
// care about the previous gridx element position. It will be incremented.
constraints(this.txtNameAdd, GridBagConstraints.RELATIVE, 2, 1, 1,
GridBagConstraints.HORIZONTAL, new Insets(10,5,0,0), GridBagConstraints.BASELINE,
0, 0);
// set constraints for lblPathAdd
// we have to disable the fill option
constraints(this.lblPathAdd, GridBagConstraints.RELATIVE, 2, 1, 1,
GridBagConstraints.NONE, new Insets(10,10,0,0), GridBagConstraints.BASELINE_LEADING,
0, 0);
// set constraints for txtPathAdd
constraints(this.txtPathAdd, GridBagConstraints.RELATIVE, 2, 1, 1,
GridBagConstraints.HORIZONTAL, new Insets(10,5,0,0), GridBagConstraints.BASELINE,
0, 0);
// set constraints for lblRunNameAdd
constraints(this.lblRunNameAdd, 2, 3, 1, 1,
GridBagConstraints.NONE, new Insets(10,15,0,0), GridBagConstraints.BASELINE_LEADING,
0, 0);
// set constraints for cmbRunNameAdd
constraints(this.cmbRunNameAdd, GridBagConstraints.RELATIVE, 3, 1, 1,
GridBagConstraints.HORIZONTAL, new Insets(10,5,0,0), GridBagConstraints.BASELINE,
0, 0);
// set constraints for lblDateAcqAdd
constraints(this.lblDateAcqAdd, GridBagConstraints.RELATIVE, 3, 1, 1,
GridBagConstraints.NONE, new Insets(10,10,0,0), GridBagConstraints.BASELINE_LEADING,
0, 0);
// set constraints for txtDateAcqAdd
constraints(this.txtDateAcqAdd, GridBagConstraints.RELATIVE, 3, 1, 1,
GridBagConstraints.HORIZONTAL, new Insets(10,5,0,0), GridBagConstraints.BASELINE,
0, 0);
}
/**
* Add a component to the GridBagLayout with all constraints given into parameters
* @param object
* @param gridx
* @param gridy
* @param gridwidth
* @param gridheight
* @param fill
* @param insets
* @param anchor
* @param weightx
* @param weighty
*/
private void constraints(Component object, int gridx, int gridy,
int gridwidth, int gridheight, int fill, Insets insets, int anchor, double weightx,
double weighty) {
gbc.gridx = gridx;
gbc.gridy = gridy;
gbc.gridwidth = gridwidth;
gbc.gridheight = gridheight;
gbc.fill = fill;
gbc.insets = insets;
gbc.anchor = anchor;
gbc.weightx = weightx;
gbc.weighty = weighty;
this.add(object, gbc);
}
} |
Partager