001package icy.swimmingPool;
002
003import icy.main.Icy;
004
005import java.awt.GridBagConstraints;
006import java.awt.GridBagLayout;
007import java.awt.Insets;
008import java.awt.event.ActionEvent;
009import java.awt.event.ActionListener;
010
011import javax.swing.JButton;
012import javax.swing.JLabel;
013import javax.swing.JPanel;
014import javax.swing.SwingConstants;
015import javax.swing.border.EtchedBorder;
016
017public class SwimmingPoolObjectPanel extends JPanel {
018
019        
020        private SwimmingObject result;
021        private JButton deleteButton;
022        
023        /**
024         * Create the panel.
025         * @param result 
026         */
027        public SwimmingPoolObjectPanel(SwimmingObject result) {
028                setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
029                
030                this.result = result;
031                GridBagLayout gridBagLayout = new GridBagLayout();
032                gridBagLayout.columnWidths = new int[]{200, 0, 100, 0};
033                gridBagLayout.rowHeights = new int[]{23, 0};
034                gridBagLayout.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
035                gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE};
036                setLayout(gridBagLayout);
037                
038                JLabel dateLabel = new JLabel("New label");
039                dateLabel.setHorizontalAlignment(SwingConstants.LEFT);
040                GridBagConstraints gbc_dateLabel = new GridBagConstraints();
041                gbc_dateLabel.fill = GridBagConstraints.BOTH;
042                gbc_dateLabel.insets = new Insets(0, 0, 0, 5);
043                gbc_dateLabel.gridx = 0;
044                gbc_dateLabel.gridy = 0;
045                add(dateLabel, gbc_dateLabel);
046                
047                JLabel nameLabel = new JLabel("New label");
048                nameLabel.setHorizontalAlignment(SwingConstants.LEFT);
049                GridBagConstraints gbc_descriptionLabel = new GridBagConstraints();
050                gbc_descriptionLabel.insets = new Insets(0, 0, 0, 5);
051                gbc_descriptionLabel.fill = GridBagConstraints.BOTH;
052                gbc_descriptionLabel.gridx = 1;
053                gbc_descriptionLabel.gridy = 0;
054                add(nameLabel, gbc_descriptionLabel);
055                
056                deleteButton = new JButton("Delete");
057                GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
058                gbc_btnNewButton.fill = GridBagConstraints.BOTH;
059                gbc_btnNewButton.gridx = 2;
060                gbc_btnNewButton.gridy = 0;
061                add(deleteButton, gbc_btnNewButton);
062                
063                dateLabel.setText( " " + result.getCreationDate().toString() );
064                nameLabel.setText( result.getName() );          
065                
066                deleteButton.addActionListener( new ActionListener() {
067                        
068                        @Override
069                        public void actionPerformed(ActionEvent arg0) {
070                                
071                                Icy.getMainInterface().getSwimmingPool().remove( SwimmingPoolObjectPanel.this.result );
072
073                        }
074                });
075
076        }
077
078}