<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package nl.fontys.sofa.limo.view.custom.panel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import nl.fontys.sofa.limo.view.util.IconUtil;
import nl.fontys.sofa.limo.view.util.LIMOResourceBundle;

/**
 * The AcceptanceTimesPropertyEditor class provides the acceptance times in a list. 
 * Beyound that, it provides the option to edit, delete and add acceptance times.
 * 
 * @author <NAME>
 */
public class AcceptanceTimePanel extends JPanel{
    
    private JPanel panelRight;
    private JButton btnEdit;
    private JTable table;
    private JButton btnDelete;
    protected DefaultTableModel model;
    private JButton btnAdd;
    
    public AcceptanceTimePanel(List<Long> acceptanceTime){
       this();
       for(Long time : acceptanceTime){
           model.addRow(new Long[]{time});
       }
                
    }

    public AcceptanceTimePanel(){
        initComponents();
    }


    @Override
    public String getName() {
        return  LIMOResourceBundle.getString("ACCEPTANCE_TIME");
    }
    
    
    
    private void initComponents() {
     
        btnAdd = new JButton(new ImageIcon(IconUtil.getIcon(IconUtil.UI_ICON.ADD)));
        btnEdit = new JButton(new ImageIcon(IconUtil.getIcon(IconUtil.UI_ICON.EDIT)));
        btnDelete = new JButton(new ImageIcon(IconUtil.getIcon(IconUtil.UI_ICON.TRASH)));
        table = new JTable();
        setLayout(new BorderLayout());
        model = new DefaultTableModel();
        model.addColumn(LIMOResourceBundle.getString("ACCEPTANCE_TIME"));
        Box bv = Box.createVerticalBox();
        table = new JTable(model);
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
        table.setRowSorter(sorter);
        JScrollPane sc = new JScrollPane(table);
        sc.setPreferredSize(new Dimension(160, 0));
        add(sc, BorderLayout.CENTER);
        setActionListener();
        bv.add(btnAdd);
        bv.add(btnEdit);
        bv.add(btnDelete);
        add(bv, BorderLayout.EAST);
    }
    
     public void setActionListener() {
       btnAdd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                long aTime = 0;

                String time = JOptionPane.showInputDialog(AcceptanceTimePanel.this,
                        LIMOResourceBundle.getString("ACCEPTANCE_TIME"), null);
                if (time != null) {
                    if (!time.isEmpty()) {
                        try {
                            aTime = Long.parseLong(time.replace(",", "."));
                             model.addRow(new Long[]{aTime});
                        } catch (NumberFormatException ex) {
                            JOptionPane.showMessageDialog(AcceptanceTimePanel.this,
                                    LIMOResourceBundle.getString("NOT_A_NUMBER"),
                                    LIMOResourceBundle.getString("NUMBER_ERROR"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                   
                   
                    
                }
            }
        });
        btnEdit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (table.getSelectedRow() >= 0) {
                    long aTime = 0;
                    String time = JOptionPane.showInputDialog(AcceptanceTimePanel.this,
                            LIMOResourceBundle.getString("ACCEPTANCE_TIME"), model.getValueAt(table.getSelectedRow(), 0));
                    if (time != null) {
                        if (!time.isEmpty()) {
                            try {
                                aTime = Long.parseLong(time.replace(",", "."));
                                model.setValueAt(aTime, table.getSelectedRow(), 0);
                            } catch (NumberFormatException ex) {
                                JOptionPane.showMessageDialog(AcceptanceTimePanel.this,
                                        LIMOResourceBundle.getString("NOT_A_NUMBER"),
                                        LIMOResourceBundle.getString("NUMBER_ERROR"),
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        }
                        
                        
                    }
                }
            }
        });
        btnDelete.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (table.getSelectedRow() >= 0) {
                    model.removeRow(table.getSelectedRow());
                }
            }
        });
     }
     
     protected JTable getTable(){
         return table;
     }
     
     /**
      * retunring all accaptance times which are shown in the panel
      * @return List<Long> of acceptance times
      */
     public List<Long> getAcceptanceTimes(){
         List<Long> times = new ArrayList<>();
          for (int i = 0; i < table.getRowCount(); i++) {
                times.add(Long.parseLong(table.getValueAt(i, 0).toString()));

            }
          return times;
     }
    
}<commit_msg>LIMO-157 surround Lis<Long> with {@code } in javadoc of method getAcceptanceTimes<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package nl.fontys.sofa.limo.view.custom.panel;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import nl.fontys.sofa.limo.view.util.IconUtil;
import nl.fontys.sofa.limo.view.util.LIMOResourceBundle;

/**
 * The AcceptanceTimesPropertyEditor class provides the acceptance times in a list. 
 * Beyound that, it provides the option to edit, delete and add acceptance times.
 * 
 * @author <NAME>
 */
public class AcceptanceTimePanel extends JPanel{
    
    private JPanel panelRight;
    private JButton btnEdit;
    private JTable table;
    private JButton btnDelete;
    protected DefaultTableModel model;
    private JButton btnAdd;
    
    public AcceptanceTimePanel(List<Long> acceptanceTime){
       this();
       for(Long time : acceptanceTime){
           model.addRow(new Long[]{time});
       }
                
    }

    public AcceptanceTimePanel(){
        initComponents();
    }


    @Override
    public String getName() {
        return  LIMOResourceBundle.getString("ACCEPTANCE_TIME");
    }
    
    
    
    private void initComponents() {
     
        btnAdd = new JButton(new ImageIcon(IconUtil.getIcon(IconUtil.UI_ICON.ADD)));
        btnEdit = new JButton(new ImageIcon(IconUtil.getIcon(IconUtil.UI_ICON.EDIT)));
        btnDelete = new JButton(new ImageIcon(IconUtil.getIcon(IconUtil.UI_ICON.TRASH)));
        table = new JTable();
        setLayout(new BorderLayout());
        model = new DefaultTableModel();
        model.addColumn(LIMOResourceBundle.getString("ACCEPTANCE_TIME"));
        Box bv = Box.createVerticalBox();
        table = new JTable(model);
        RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
        table.setRowSorter(sorter);
        JScrollPane sc = new JScrollPane(table);
        sc.setPreferredSize(new Dimension(160, 0));
        add(sc, BorderLayout.CENTER);
        setActionListener();
        bv.add(btnAdd);
        bv.add(btnEdit);
        bv.add(btnDelete);
        add(bv, BorderLayout.EAST);
    }
    
     public void setActionListener() {
       btnAdd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                long aTime = 0;

                String time = JOptionPane.showInputDialog(AcceptanceTimePanel.this,
                        LIMOResourceBundle.getString("ACCEPTANCE_TIME"), null);
                if (time != null) {
                    if (!time.isEmpty()) {
                        try {
                            aTime = Long.parseLong(time.replace(",", "."));
                             model.addRow(new Long[]{aTime});
                        } catch (NumberFormatException ex) {
                            JOptionPane.showMessageDialog(AcceptanceTimePanel.this,
                                    LIMOResourceBundle.getString("NOT_A_NUMBER"),
                                    LIMOResourceBundle.getString("NUMBER_ERROR"),
                                    JOptionPane.ERROR_MESSAGE);
                        }
                    }
                   
                   
                    
                }
            }
        });
        btnEdit.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (table.getSelectedRow() >= 0) {
                    long aTime = 0;
                    String time = JOptionPane.showInputDialog(AcceptanceTimePanel.this,
                            LIMOResourceBundle.getString("ACCEPTANCE_TIME"), model.getValueAt(table.getSelectedRow(), 0));
                    if (time != null) {
                        if (!time.isEmpty()) {
                            try {
                                aTime = Long.parseLong(time.replace(",", "."));
                                model.setValueAt(aTime, table.getSelectedRow(), 0);
                            } catch (NumberFormatException ex) {
                                JOptionPane.showMessageDialog(AcceptanceTimePanel.this,
                                        LIMOResourceBundle.getString("NOT_A_NUMBER"),
                                        LIMOResourceBundle.getString("NUMBER_ERROR"),
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        }
                        
                        
                    }
                }
            }
        });
        btnDelete.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (table.getSelectedRow() >= 0) {
                    model.removeRow(table.getSelectedRow());
                }
            }
        });
     }
     
     protected JTable getTable(){
         return table;
     }
     
     /**
      * retunring all accaptance times which are shown in the panel
      * @return {@code List<Long>} wiht longs which represents acceptance times
      */
     public List<Long> getAcceptanceTimes(){
         List<Long> times = new ArrayList<>();
          for (int i = 0; i < table.getRowCount(); i++) {
                times.add(Long.parseLong(table.getValueAt(i, 0).toString()));

            }
          return times;
     }
    
}
{'fraction_non_alphanumeric': 0.09445981057748722, 'fraction_numerical': 0.002263012320844858, 'mean_word_length': 1.7179954441913439, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5650210', 'n_tokens_mistral': 3138, 'n_tokens_neox': 3012, 'n_words': 621}