Example usage for javax.swing.table DefaultTableModel addRow

List of usage examples for javax.swing.table DefaultTableModel addRow

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel addRow.

Prototype

public void addRow(Object[] rowData) 

Source Link

Document

Adds a row to the end of the model.

Usage

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

/**
 * Create detail frames shown after calculation
 *//*from  w ww  . j a va 2 s.  c  o  m*/
private void buildDetailedStatistics(HashMap<Village, String> attackMappings,
        List<Village> pNotAssignedVillages) {
    // <editor-fold defaultstate="collapsed" desc="Build not assigned source table">
    Collections.sort(pNotAssignedVillages);
    DefaultTableModel sourcesModel = new javax.swing.table.DefaultTableModel(new Object[][] {},
            new String[] { "Spieler", "Dorf" }) {

        private Class[] cTypes = new Class[] { Tribe.class, Village.class };

        @Override
        public Class getColumnClass(int columnIndex) {
            return cTypes[columnIndex];
        }
    };
    for (Village notAssigned : pNotAssignedVillages) {
        Tribe t = notAssigned.getTribe();
        if (t == null) {
            sourcesModel.addRow(new Object[] { Barbarians.getSingleton(), notAssigned });
        } else {
            sourcesModel.addRow(new Object[] { t, notAssigned });
        }
    }
    jNotAssignedSourcesTable.setModel(sourcesModel);
    TableRowSorter<TableModel> sourcesSorter = new TableRowSorter<TableModel>(sourcesModel);
    jNotAssignedSourcesTable.setRowSorter(sourcesSorter);
    DefaultTableCellRenderer headerRenderer = new SortableTableHeaderRenderer();
    for (int i = 0; i < jNotAssignedSourcesTable.getColumnCount(); i++) {
        jNotAssignedSourcesTable.getColumn(jNotAssignedSourcesTable.getColumnName(i))
                .setHeaderRenderer(headerRenderer);
    }
    jNotAssignedSourcesTable.revalidate();
    //</editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Build attacks per target table">
    DefaultTableModel tableModel = new javax.swing.table.DefaultTableModel(new Object[][] {},
            new String[] { "Spieler", "Dorf", "Angriffe" }) {

        Class[] types = new Class[] { Tribe.class, Village.class, String.class };

        @Override
        public Class getColumnClass(int columnIndex) {
            return types[columnIndex];
        }
    };
    List<Village> notFullTargets = new LinkedList<Village>();
    Iterator<Village> keys = attackMappings.keySet().iterator();
    while (keys.hasNext()) {
        Village key = keys.next();
        Tribe t = key.getTribe();
        //int notAssignedAmount = attackMappings.get(key);
        String attackCount = attackMappings.get(key);
        String[] split = attackCount.split("/");
        int notAssignedAmount = Integer.parseInt(split[1]) - Integer.parseInt(split[0]);
        if (t != Barbarians.getSingleton()) {
            tableModel.addRow(new Object[] { t, key, attackCount });
        } else {
            tableModel.addRow(new Object[] { "Barbaren", key, attackCount });
        }
        if (notAssignedAmount > 0) {
            notFullTargets.add(key);
        }
    }
    jTargetDetailsTable.setModel(tableModel);
    TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(tableModel);
    jTargetDetailsTable.setRowSorter(sorter);
    DefaultTableCellRenderer coloredRenderer = new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Component c = new DefaultTableCellRenderer().getTableCellRendererComponent(table, value, isSelected,
                    hasFocus, row, row);
            String t = ((DefaultTableCellRenderer) c).getText();
            ((DefaultTableCellRenderer) c).setText(t);
            DefaultTableModel model = (DefaultTableModel) table.getModel();
            int r = table.convertRowIndexToModel(row);
            String sVal = (String) model.getValueAt(r, 2);
            String[] split = sVal.split("/");
            long max = Long.parseLong(split[1]);
            long v = Long.parseLong(split[0]);
            long diff = max - v;
            Color back = Color.RED;
            if (v == 0) {
                //color stays red
            } else if (v == max) {
                back = Color.GREEN;
            } else {
                float posv = 100.0f * (float) diff / (float) max;
                posv = ((int) posv / 10) * 10;
                posv /= 100;
                Color LAST_SEGMENT = new Color(255, 100, 0);
                int red = (int) Math.rint(
                        (float) LAST_SEGMENT.getRed() * (1.0f - posv) + (float) Color.YELLOW.getRed() * posv);
                int green = (int) Math.rint((float) LAST_SEGMENT.getGreen() * (1.0f - posv)
                        + (float) Color.YELLOW.getGreen() * posv);
                int blue = (int) Math.rint(
                        (float) LAST_SEGMENT.getBlue() * (1.0f - posv) + (float) Color.YELLOW.getBlue() * posv);
                if (red < 0) {
                    red = 0;
                }
                if (green < 0) {
                    green = 0;
                }
                if (blue < 0) {
                    blue = 0;
                }
                if (red > 254) {
                    red = 254;
                }
                if (green > 254) {
                    green = 254;
                }
                if (blue > 254) {
                    blue = 254;
                }
                back = new Color(red, green, blue);
            }
            DefaultTableCellRenderer renderer = ((DefaultTableCellRenderer) c);
            if (!isSelected) {
                renderer.setBackground(back);
            }
            return c;
        }
    };
    jTargetDetailsTable.setDefaultRenderer(Village.class, coloredRenderer);
    jTargetDetailsTable.setDefaultRenderer(Integer.class, coloredRenderer);
    jTargetDetailsTable.setDefaultRenderer(String.class, coloredRenderer);
    jTargetDetailsTable.setDefaultRenderer(Tribe.class, coloredRenderer);
    for (int i = 0; i < jTargetDetailsTable.getColumnCount(); i++) {
        jTargetDetailsTable.getColumn(jTargetDetailsTable.getColumnName(i)).setHeaderRenderer(headerRenderer);
    }
    jTargetDetailsTable.revalidate();
    //</editor-fold>
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void filterByUsage() {
    int idx = jideTabbedPane1.getSelectedIndex();
    if (idx == 0 || idx == 1) {
        DefaultTableModel model = new javax.swing.table.DefaultTableModel(new Object[][] {},
                new String[] { "Angriffsplan", "Abgleichen" }) {

            Class[] types = new Class[] { String.class, Boolean.class };

            @Override/*from   ww w. ja v  a2s  .  c om*/
            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            @Override
            public boolean isCellEditable(int row, int col) {
                if (col == 0) {
                    return false;
                }
                return true;
            }
        };
        String[] plans = AttackManager.getSingleton().getGroups();
        for (String plan : plans) {
            model.addRow(new Object[] { plan, false });
        }
        jAttackPlanTable.setModel(model);
        jAttackPlanTable.repaint();
        jAttackPlanTable.getTableHeader().setDefaultRenderer(new DefaultTableHeaderRenderer());
        // jAttackPlanSelectionDialog.setLocationRelativeTo(DSWorkbenchMainFrame.getSingleton().getAttackPlaner());
        jAttackPlanSelectionDialog.setVisible(true);
    } else {
        showInfo("Diese Funktion ist nur fr Herkunftsdrfer verfgbar");
    }
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

/**
 * Add target villages externally (see DSWorkbenchMainFrame)
 *
 * @param pVillages//from  w w  w .jav a 2 s.c  o m
 */
public void fireAddTargetsEvent(List<Village> pVillages) {
    DefaultTableModel victimModel = (DefaultTableModel) jVictimTable.getModel();
    for (Village v : pVillages) {
        if (v != null) {
            boolean contains = false;
            for (int row = 0; row < victimModel.getRowCount(); row++) {
                if (victimModel.getValueAt(row, 1).equals(v)) {
                    contains = true;
                    break;
                }
            }
            if (!contains) {
                int maxAttacks = 1;
                try {
                    maxAttacks = (Integer) jMaxAttacksPerVillage.getValue();
                } catch (Exception e) {
                    maxAttacks = 1;
                }
                if (v != null) {
                    victimModel.addRow(
                            new Object[] { v.getTribe(), v, jMarkTargetAsFake.isSelected(), maxAttacks, 0 });
                }
            }
        }
    }
    updateInfo();
    ((DefaultTableModel) jVictimTable.getModel()).fireTableDataChanged();
}

From source file:Clavis.Windows.WShedule.java

public synchronized void create() {
    initComponents();/*from   w  w  w .j ava 2 s  .  c  om*/
    this.setModal(true);
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            close();
        }
    });
    this.setTitle(lingua.translate("Registos de emprstimo para o recurso") + ": "
            + lingua.translate(mat.getTypeOfMaterialName()).toLowerCase() + " "
            + lingua.translate(mat.getDescription()));
    KeyQuest.addtoPropertyListener(jPanelInicial, true);
    String dat = new TimeDate.Date().toString();
    String[] auxiliar = prefs.get("datainicio", dat).split("/");
    if (auxiliar[0].length() > 1) {
        if (auxiliar[0].charAt(0) == '0') {
            auxiliar[0] = auxiliar[0].replaceFirst("0", "");
        }
    }
    if (auxiliar[1].length() > 1) {
        if (auxiliar[1].charAt(0) == '0') {
            auxiliar[1] = auxiliar[1].replaceFirst("0", "");
        }
    }
    if (auxiliar[2].length() > 1) {
        if (auxiliar[2].charAt(0) == '0') {
            auxiliar[2] = auxiliar[2].replaceFirst("0", "");
        }
    }
    inicio = new TimeDate.Date(Integer.valueOf(auxiliar[0]), Integer.valueOf(auxiliar[1]),
            Integer.valueOf(auxiliar[2]));
    auxiliar = prefs.get("datafim", dat).split("/");
    if (auxiliar[0].length() > 1) {
        if (auxiliar[0].charAt(0) == '0') {
            auxiliar[0] = auxiliar[0].replaceFirst("0", "");
        }
    }
    if (auxiliar[1].length() > 1) {
        if (auxiliar[1].charAt(0) == '0') {
            auxiliar[1] = auxiliar[1].replaceFirst("0", "");
        }
    }
    if (auxiliar[2].length() > 1) {
        if (auxiliar[2].charAt(0) == '0') {
            auxiliar[2] = auxiliar[2].replaceFirst("0", "");
        }
    }
    fim = new TimeDate.Date(Integer.valueOf(auxiliar[0]), Integer.valueOf(auxiliar[1]),
            Integer.valueOf(auxiliar[2]));

    SimpleDateFormat sdf = new SimpleDateFormat("dd/M/yyyy");
    Date date;
    try {
        date = sdf.parse(fim.toString());
    } catch (ParseException ex) {
        date = new Date();

    }
    jXDatePickerFim.setDate(date);
    try {
        date = sdf.parse(inicio.toString());
    } catch (ParseException ex) {
        date = new Date();
    }
    jXDatePickerInicio.setDate(date);
    andamento = 0;
    if (DataBase.DataBase.testConnection(url)) {
        DataBase.DataBase db = new DataBase.DataBase(url);
        java.util.List<Keys.Request> requisicoes = Clavis.RequestList
                .simplifyRequests(db.getRequestsByMaterialByDateInterval(mat, inicio, fim));
        db.close();
        estado = lingua.translate("Todos");
        DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
        if (requisicoes.size() > 0) {
            valores = new String[requisicoes.size()][4];
            lista = new java.util.ArrayList<>();
            requisicoes.stream().map((req) -> {
                if (mat.getMaterialTypeID() == 1) {
                    valores[andamento][0] = req.getPerson().getName();
                    valores[andamento][1] = req.getTimeBegin().toString(0) + " - "
                            + req.getTimeEnd().toString(0);
                    valores[andamento][2] = req.getBeginDate().toString();
                    String[] multipla = req.getActivity().split(":::");
                    if (multipla.length > 1) {
                        Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                        pop.create();
                        jTable1.addMouseListener(new MouseAdapter() {
                            int x = andamento;
                            int y = 3;

                            @Override
                            public void mousePressed(MouseEvent e) {
                                if (e.getButton() == MouseEvent.BUTTON1) {
                                    int row = jTable1.rowAtPoint(e.getPoint());
                                    int col = jTable1.columnAtPoint(e.getPoint());
                                    if ((row == x) && (col == y)) {
                                        pop.show(e.getComponent(), e.getX(), e.getY());
                                    }
                                }
                            }

                            @Override
                            public void mouseReleased(MouseEvent e) {
                                if (e.getButton() == MouseEvent.BUTTON1) {
                                    if (pop.isShowing()) {
                                        pop.setVisible(false);
                                    }
                                }
                            }
                        });
                        valores[andamento][3] = lingua.translate(multipla[0]) + "";
                    } else {
                        valores[andamento][3] = lingua.translate(req.getActivity());
                    }
                    if (valores[andamento][3].equals("")) {
                        valores[andamento][3] = lingua.translate("Sem descrio");
                    }
                    Object[] ob = { req.getPerson().getName(),
                            req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                            req.getBeginDate().toString(), valores[andamento][3], req.getSubject().getName() };
                    modelo.addRow(ob);
                } else {
                    valores[andamento][0] = req.getPerson().getName();
                    valores[andamento][1] = req.getBeginDate().toString();
                    valores[andamento][2] = req.getEndDate().toString();
                    String[] multipla = req.getActivity().split(":::");
                    if (multipla.length > 1) {
                        Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                        pop.create();
                        jTable1.addMouseListener(new MouseAdapter() {
                            int x = andamento;
                            int y = 3;

                            @Override
                            public void mousePressed(MouseEvent e) {
                                if (e.getButton() == MouseEvent.BUTTON1) {
                                    int row = jTable1.rowAtPoint(e.getPoint());
                                    int col = jTable1.columnAtPoint(e.getPoint());
                                    if ((row == x) && (col == y)) {
                                        pop.show(e.getComponent(), e.getX(), e.getY());
                                    }
                                }
                            }

                            @Override
                            public void mouseReleased(MouseEvent e) {
                                if (e.getButton() == MouseEvent.BUTTON1) {
                                    if (pop.isShowing()) {
                                        pop.setVisible(false);
                                    }
                                }
                            }
                        });
                        valores[andamento][3] = multipla[0];
                    } else {
                        valores[andamento][3] = lingua.translate(req.getActivity());
                    }
                    if (valores[andamento][3].equals("")) {
                        valores[andamento][3] = lingua.translate("Sem descrio");
                    }
                    Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                            req.getEndDate().toString(), valores[andamento][3] };
                    modelo.addRow(ob);
                }
                return req;
            }).map((req) -> {
                lista.add(req);
                return req;
            }).forEach((_item) -> {
                andamento++;
            });
        }
    }
    jComboBoxEstado.setSelectedIndex(prefs.getInt("comboboxvalue", 0));
    String[] opcoes = { lingua.translate("Ver detalhes da requisio"),
            lingua.translate("Ver requisices com a mesma data"),
            lingua.translate("Ver requisices com o mesmo estado") };
    ActionListener[] eventos = new ActionListener[opcoes.length];
    eventos[0] = (ActionEvent r) -> {
        Border border = BorderFactory.createCompoundBorder(
                BorderFactory.createCompoundBorder(new org.jdesktop.swingx.border.DropShadowBorder(Color.BLACK,
                        3, 0.5f, 6, false, false, true, true), BorderFactory.createLineBorder(Color.BLACK, 1)),
                BorderFactory.createEmptyBorder(0, 10, 0, 10));
        int val = jTable1.getSelectedRow();
        Keys.Request req = lista.get(val);
        javax.swing.JPanel pan = new javax.swing.JPanel(null);
        pan.setPreferredSize(new Dimension(500, 300));
        pan.setBounds(0, 20, 500, 400);
        pan.setBackground(Components.MessagePane.BACKGROUND_COLOR);
        javax.swing.JLabel lrecurso1 = new javax.swing.JLabel(lingua.translate("Recurso") + ": ");
        lrecurso1.setBounds(10, 20, 120, 26);
        lrecurso1.setFocusable(true);
        lrecurso1.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso1);
        javax.swing.JLabel lrecurso11 = new javax.swing.JLabel(
                lingua.translate(req.getMaterial().getTypeOfMaterialName()) + " "
                        + lingua.translate(req.getMaterial().getDescription()));
        lrecurso11.setBounds(140, 20, 330, 26);
        lrecurso11.setBorder(border);
        pan.add(lrecurso11);
        javax.swing.JLabel lrecurso2 = new javax.swing.JLabel(lingua.translate("Utilizador") + ": ");
        lrecurso2.setBounds(10, 50, 120, 26);
        lrecurso2.setFocusable(true);
        lrecurso2.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso2);
        javax.swing.JLabel lrecurso22 = new javax.swing.JLabel(req.getPerson().getName());
        lrecurso22.setBounds(140, 50, 330, 26);
        lrecurso22.setBorder(border);
        pan.add(lrecurso22);
        javax.swing.JLabel lrecurso3 = new javax.swing.JLabel(lingua.translate("Data inicial") + ": ");
        lrecurso3.setBounds(10, 80, 120, 26);
        lrecurso3.setFocusable(true);
        lrecurso3.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso3);
        javax.swing.JLabel lrecurso33 = new javax.swing.JLabel(
                req.getBeginDate().toStringWithMonthWord(lingua));
        lrecurso33.setBounds(140, 80, 330, 26);
        lrecurso33.setBorder(border);
        pan.add(lrecurso33);
        javax.swing.JLabel lrecurso4 = new javax.swing.JLabel(lingua.translate("Data final") + ": ");
        lrecurso4.setBounds(10, 110, 120, 26);
        lrecurso4.setFocusable(true);
        lrecurso4.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso4);
        javax.swing.JLabel lrecurso44 = new javax.swing.JLabel(req.getEndDate().toStringWithMonthWord(lingua));
        lrecurso44.setBounds(140, 110, 330, 26);
        lrecurso44.setBorder(border);
        pan.add(lrecurso44);

        javax.swing.JLabel lrecurso5 = new javax.swing.JLabel(lingua.translate("Atividade") + ": ");
        lrecurso5.setBounds(10, 140, 120, 26);
        lrecurso5.setFocusable(true);
        lrecurso5.setHorizontalAlignment(javax.swing.JLabel.LEFT);
        pan.add(lrecurso5);
        javax.swing.JLabel lrecurso55;
        if (req.getActivity().equals("")) {
            lrecurso55 = new javax.swing.JLabel(lingua.translate("Sem descrio"));
        } else {
            String[] saux = req.getActivity().split(":::");
            String atividade;
            boolean situacao = false;
            if (saux.length > 1) {
                situacao = true;
                atividade = saux[0];
            } else {
                atividade = req.getActivity();
            }
            if (req.getSubject().getId() > 0) {
                lrecurso55 = new javax.swing.JLabel(
                        lingua.translate(atividade) + ": " + req.getSubject().getName());
            } else {
                lrecurso55 = new javax.swing.JLabel(lingua.translate(atividade));
            }
            if (situacao) {
                Components.PopUpMenu pop = new Components.PopUpMenu(saux, lingua);
                pop.create();
                lrecurso55.addMouseListener(new MouseAdapter() {

                    @Override
                    public void mouseEntered(MouseEvent e) {
                        pop.show(e.getComponent(), e.getX(), e.getY());
                    }

                    @Override
                    public void mouseExited(MouseEvent e) {
                        pop.setVisible(false);
                    }

                });
            }
        }
        lrecurso55.setBounds(140, 140, 330, 26);
        lrecurso55.setBorder(border);
        pan.add(lrecurso55);
        int distancia = 170;
        if (req.getBeginDate().isBigger(req.getEndDate()) == 0) {
            javax.swing.JLabel lrecurso6 = new javax.swing.JLabel(lingua.translate("Horrio") + ": ");
            lrecurso6.setBounds(10, distancia, 120, 26);
            lrecurso6.setFocusable(true);
            lrecurso6.setHorizontalAlignment(javax.swing.JLabel.LEFT);
            pan.add(lrecurso6);
            javax.swing.JLabel lrecurso66 = new javax.swing.JLabel(
                    req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0));
            lrecurso66.setBounds(140, distancia, 330, 26);
            lrecurso66.setBorder(border);
            pan.add(lrecurso66);
            distancia = 200;
        }
        if (req.getBeginDate().isBigger(req.getEndDate()) == 0) {
            javax.swing.JLabel lrecurso7 = new javax.swing.JLabel(lingua.translate("Dia da semana") + ": ");
            lrecurso7.setBounds(10, distancia, 120, 26);
            lrecurso7.setFocusable(true);
            lrecurso7.setHorizontalAlignment(javax.swing.JLabel.LEFT);
            pan.add(lrecurso7);
            javax.swing.JLabel lrecurso77 = new javax.swing.JLabel(
                    lingua.translate(req.getWeekDay().perDayName()));
            lrecurso77.setBounds(140, distancia, 330, 26);
            lrecurso77.setBorder(border);
            pan.add(lrecurso77);
            if (distancia == 200) {
                distancia = 230;
            } else {
                distancia = 200;
            }
        }
        if (req.isTerminated() || req.isActive()) {
            javax.swing.JLabel lrecurso8 = new javax.swing.JLabel(lingua.translate("Levantamento") + ": ");
            lrecurso8.setBounds(10, distancia, 120, 26);
            lrecurso8.setFocusable(true);
            lrecurso8.setHorizontalAlignment(javax.swing.JLabel.LEFT);
            pan.add(lrecurso8);
            javax.swing.JLabel lrecurso88;
            if ((req.getLiftDate() != null) && (req.getLiftTime() != null)) {
                lrecurso88 = new javax.swing.JLabel(req.getLiftDate().toString() + " " + lingua.translate("s")
                        + " " + req.getLiftTime().toString(0));
            } else {
                lrecurso88 = new javax.swing.JLabel(lingua.translate("sem dados para apresentar"));
            }
            lrecurso88.setBounds(140, distancia, 330, 26);
            lrecurso88.setBorder(border);
            pan.add(lrecurso88);
            switch (distancia) {
            case 200:
                distancia = 230;
                break;
            case 230:
                distancia = 260;
                break;
            default:
                distancia = 200;
                break;
            }
        }
        if (req.isTerminated()) {
            javax.swing.JLabel lrecurso9 = new javax.swing.JLabel(lingua.translate("Entrega") + ": ");
            lrecurso9.setBounds(10, distancia, 120, 26);
            lrecurso9.setFocusable(true);
            lrecurso9.setHorizontalAlignment(javax.swing.JLabel.LEFT);
            pan.add(lrecurso9);
            javax.swing.JLabel lrecurso99;
            if ((req.getDeliveryDate() != null) && (req.getDeliveryTime() != null)) {
                lrecurso99 = new javax.swing.JLabel(req.getDeliveryDate().toString() + " "
                        + lingua.translate("s") + " " + req.getDeliveryTime().toString(0));
            } else {
                lrecurso99 = new javax.swing.JLabel(lingua.translate("sem dados para apresentar"));
            }
            lrecurso99.setBounds(140, distancia, 330, 26);
            lrecurso99.setBorder(border);
            pan.add(lrecurso99);
            switch (distancia) {
            case 200:
                distancia = 230;
                break;
            case 230:
                distancia = 260;
                break;
            case 260:
                distancia = 290;
                break;
            default:
                distancia = 200;
                break;
            }
        }
        Components.MessagePane mensagem = new Components.MessagePane(this, Components.MessagePane.INFORMACAO,
                Clavis.KeyQuest.getSystemColor(), lingua.translate(""), 500, 400, pan, "",
                new String[] { lingua.translate("Voltar") });
        mensagem.showMessage();
    };
    eventos[1] = (ActionEvent r) -> {
        String val = jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 2).toString();
        SimpleDateFormat sdf_auxiliar = new SimpleDateFormat("dd/MM/yyyy");
        Date data_auxiliar;
        try {
            data_auxiliar = sdf_auxiliar.parse(val);
            Calendar cal = Calendar.getInstance();
            cal.setTime(data_auxiliar);
            int dia = cal.get(Calendar.DAY_OF_MONTH);
            int mes = cal.get(Calendar.MONTH) + 1;
            int ano = cal.get(Calendar.YEAR);
            inicio = new TimeDate.Date(dia, mes, ano);
            fim = new TimeDate.Date(dia, mes, ano);
        } catch (ParseException ex) {
            data_auxiliar = new Date();
        }
        jXDatePickerFim.setDate(data_auxiliar);
        jXDatePickerInicio.setDate(data_auxiliar);
        refreshTable(jComboBoxEstado.getSelectedIndex());
    };
    eventos[2] = (ActionEvent r) -> {
        String val = jTable1.getModel().getValueAt(jTable1.getSelectedRow(), 3).toString();
        for (int i = 0; i < jComboBoxEstado.getItemCount(); i++) {
            if (jComboBoxEstado.getItemAt(i).equals(val)) {
                jComboBoxEstado.setSelectedIndex(i);
            }
        }
    };
    KeyStroke[] strokes = new KeyStroke[opcoes.length];
    strokes[0] = KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK);
    strokes[1] = KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK);
    strokes[2] = KeyStroke.getKeyStroke(KeyEvent.VK_E, Event.CTRL_MASK);
    Components.PopUpMenu pop = new Components.PopUpMenu(opcoes, eventos, strokes);
    pop.create();
    mouseaction = new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent e) {
            java.awt.Point ponto = new java.awt.Point(e.getX(), e.getY());
            if (jTable1.rowAtPoint(ponto) > -1) {
                jTable1.setRowSelectionInterval(jTable1.rowAtPoint(ponto),
                        jTable1.rowAtPoint(new java.awt.Point(e.getX(), e.getY())));
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                if (jTable1.getSelectedRow() >= 0) {
                    java.awt.Point ponto = new java.awt.Point(e.getX(), e.getY());
                    if (jTable1.rowAtPoint(ponto) > -1) {
                        pop.show(e.getComponent(), e.getX(), e.getY());
                    }
                }
            }
        }

    };
    jTable1.addMouseListener(mouseaction);
}

From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java

private void btnDropActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDropActionPerformed
    Boolean isSave = false;//from   w  ww  . j  a  v  a2 s .  c  om
    String staff = "";
    String pass = "NO";
    if (this.currentEntry != null) {
        if (this.cbDrop1.getSelectedIndex() != 0 && this.cbDrop2.getSelectedIndex() != 0
                && this.cbDrop3.getSelectedIndex() != 0 && this.cbDrop4.getSelectedIndex() != 0
                && this.cbDrop5.getSelectedIndex() != 0 && this.cbDrop6.getSelectedIndex() != 0
                && this.cbDrop7.getSelectedIndex() != 0 && this.cbDrop8.getSelectedIndex() != 0) {
            if (this.cbDrop1.getSelectedIndex() != 2 && this.cbDrop2.getSelectedIndex() != 2
                    && this.cbDrop3.getSelectedIndex() != 2 && this.cbDrop4.getSelectedIndex() != 2
                    && this.cbDrop5.getSelectedIndex() != 2 && this.cbDrop6.getSelectedIndex() != 2
                    && this.cbDrop7.getSelectedIndex() != 2 && this.cbDrop8.getSelectedIndex() != 2) {
                isSave = true;
                pass = "YES";
            } else {
                String checker = JOptionPane.showInputDialog(this,
                        "the value is not within the range, please entry technician name.", "Warning",
                        JOptionPane.OK_OPTION);
                pass = "NO(" + checker + ")";
                if (!checker.equals("")) {
                    isSave = true;
                }
            }
            staff = this.txtDropStaff.getText();
            this.txtDropStaff.setText("");
        } else {
            JOptionPane.showMessageDialog(this, "Please complete all the tests.", "Warning",
                    JOptionPane.OK_OPTION);
        }

        if (isSave) {
            DefaultTableModel model = (DefaultTableModel) this.tblDrop.getModel();
            Date now = new Date();
            String time = new SimpleDateFormat("HH:mm").format(now);
            model.addRow(
                    new Object[] { time, RecordKey.DROP_TEST_1, this.cbDrop1.getSelectedItem(), pass, staff });
            model.addRow(
                    new Object[] { time, RecordKey.DROP_TEST_2, this.cbDrop2.getSelectedItem(), pass, staff });
            model.addRow(
                    new Object[] { time, RecordKey.DROP_TEST_3, this.cbDrop3.getSelectedItem(), pass, staff });
            model.addRow(
                    new Object[] { time, RecordKey.DROP_TEST_4, this.cbDrop4.getSelectedItem(), pass, staff });
            model.addRow(
                    new Object[] { time, RecordKey.DROP_TEST_5, this.cbDrop5.getSelectedItem(), pass, staff });
            model.addRow(
                    new Object[] { time, RecordKey.DROP_TEST_6, this.cbDrop6.getSelectedItem(), pass, staff });
            model.addRow(
                    new Object[] { time, RecordKey.DROP_TEST_7, this.cbDrop7.getSelectedItem(), pass, staff });
            model.addRow(
                    new Object[] { time, RecordKey.DROP_TEST_8, this.cbDrop8.getSelectedItem(), pass, staff });

            ((AbstractTableModel) this.tblDrop.getModel()).fireTableDataChanged();

            //
            UpdateEntryData(now, (float) this.cbDrop1.getSelectedIndex(), RecordKey.DROP_TEST_1, pass, staff,
                    this.cbDrop1.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbDrop2.getSelectedIndex(), RecordKey.DROP_TEST_2, pass, staff,
                    this.cbDrop2.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbDrop3.getSelectedIndex(), RecordKey.DROP_TEST_3, pass, staff,
                    this.cbDrop3.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbDrop4.getSelectedIndex(), RecordKey.DROP_TEST_4, pass, staff,
                    this.cbDrop4.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbDrop5.getSelectedIndex(), RecordKey.DROP_TEST_5, pass, staff,
                    this.cbDrop5.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbDrop6.getSelectedIndex(), RecordKey.DROP_TEST_6, pass, staff,
                    this.cbDrop6.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbDrop7.getSelectedIndex(), RecordKey.DROP_TEST_7, pass, staff,
                    this.cbDrop7.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbDrop8.getSelectedIndex(), RecordKey.DROP_TEST_8, pass, staff,
                    this.cbDrop8.getSelectedItem().toString());
            this.cbDrop1.setSelectedIndex(0);
            this.cbDrop2.setSelectedIndex(0);
            this.cbDrop3.setSelectedIndex(0);
            this.cbDrop4.setSelectedIndex(0);
            this.cbDrop5.setSelectedIndex(0);
            this.cbDrop6.setSelectedIndex(0);
            this.cbDrop7.setSelectedIndex(0);
            this.cbDrop8.setSelectedIndex(0);
        }
    }
}

From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java

private void btnLeakFillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLeakFillActionPerformed
    Boolean isSave = false;/* w w  w .  j a  v a2 s  .  c om*/
    if (this.currentEntry != null) {
        if (!this.txtLeakFill.getText().equals("")) {
            isSave = true;
        } else {
            JOptionPane.showMessageDialog(this, "Please entry the data.", "Warning", JOptionPane.OK_OPTION);
        }

        if (isSave) {
            DefaultTableModel model = (DefaultTableModel) this.tblLeak.getModel();
            Date now = new Date();
            String time = new SimpleDateFormat("HH:mm").format(now);
            String stringValue = this.txtLeakFill.getText();
            model.addRow(new Object[] { time, RecordKey.LEAK_FILL, stringValue });
            ((AbstractTableModel) this.tblLeak.getModel()).fireTableDataChanged();
            this.txtLeakFill.setText("");
            UpdateEntryData(now, 0f, RecordKey.LEAK_FILL, "", "", stringValue);
            this.labLeakTime.setText(time);
        }
    }
}

From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java

private void btnCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCheckActionPerformed
    Boolean isSave = false;/*  w  w w . ja v  a 2s  .  c om*/
    String staff = "";
    String pass = "NO";
    if (this.currentEntry != null) {
        if (this.cbNeckRound.getSelectedIndex() != 0 && this.cbNeckComplete.getSelectedIndex() != 0
                && this.cbUnderTheHandle.getSelectedIndex() != 0 && this.cbBungIfDrilled.getSelectedIndex() != 0
                && this.cbBase.getSelectedIndex() != 0 && this.cbStrengthOfDrum.getSelectedIndex() != 0
                && this.cbWeightWithinRange.getSelectedIndex() != 0
                && this.cbColourTexture.getSelectedIndex() != 0
                && this.cbBungProvision.getSelectedIndex() != 0) {
            if (this.cbNeckRound.getSelectedIndex() != 2 && this.cbNeckComplete.getSelectedIndex() != 2
                    && this.cbUnderTheHandle.getSelectedIndex() != 2
                    && this.cbBungIfDrilled.getSelectedIndex() != 2 && this.cbBase.getSelectedIndex() != 2
                    && this.cbStrengthOfDrum.getSelectedIndex() != 2
                    && this.cbWeightWithinRange.getSelectedIndex() != 2
                    && this.cbColourTexture.getSelectedIndex() != 2
                    && this.cbBungProvision.getSelectedIndex() != 2) {
                isSave = true;
                pass = "YES";
            } else {
                String checker = JOptionPane.showInputDialog(this,
                        "the value is not within the range, please entry technician name.", "Warning",
                        JOptionPane.OK_OPTION);
                pass = "NO(" + checker + ")";
                if (!checker.equals("")) {
                    isSave = true;
                }
            }
            staff = this.txtCheckStaff.getText();
            this.txtCheckStaff.setText("");
        } else {
            JOptionPane.showMessageDialog(this, "Please complete all the checks.", "Warning",
                    JOptionPane.OK_OPTION);
        }

        if (isSave) {
            DefaultTableModel model = (DefaultTableModel) this.tblCheck.getModel();
            Date now = new Date();
            String time = new SimpleDateFormat("HH:mm").format(now);
            model.addRow(new Object[] { time, RecordKey.CHECK_NECK_ROUND, this.cbNeckRound.getSelectedItem(),
                    pass, staff });
            model.addRow(new Object[] { time, RecordKey.CHECK_NECK_COMPLETE,
                    this.cbNeckComplete.getSelectedItem(), pass, staff });
            model.addRow(new Object[] { time, RecordKey.CHECK_UNDER_THE_HANDLE,
                    this.cbUnderTheHandle.getSelectedItem(), pass, staff });
            model.addRow(new Object[] { time, RecordKey.CHECK_BUNG_IF_DRILLED,
                    this.cbBungIfDrilled.getSelectedItem(), pass, staff });
            model.addRow(
                    new Object[] { time, RecordKey.CHECK_BASE, this.cbBase.getSelectedItem(), pass, staff });
            model.addRow(new Object[] { time, RecordKey.CHECK_STRENGTH_OF_DRUM,
                    this.cbStrengthOfDrum.getSelectedItem(), pass, staff });
            model.addRow(new Object[] { time, RecordKey.CHECK_WEIGHT_WITHIN_RANGE,
                    this.cbWeightWithinRange.getSelectedItem(), pass, staff });
            model.addRow(new Object[] { time, RecordKey.CHECK_COLOUR_TEXTURE,
                    this.cbColourTexture.getSelectedItem(), pass, staff });
            model.addRow(new Object[] { time, RecordKey.CHECK_BUNG_PROVISION,
                    this.cbBungProvision.getSelectedItem(), pass, staff });

            ((AbstractTableModel) this.tblCheck.getModel()).fireTableDataChanged();

            //
            UpdateEntryData(now, (float) this.cbNeckRound.getSelectedIndex(), RecordKey.CHECK_NECK_ROUND, staff,
                    pass, this.cbNeckRound.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbNeckComplete.getSelectedIndex(), RecordKey.CHECK_NECK_COMPLETE,
                    staff, pass, this.cbNeckComplete.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbUnderTheHandle.getSelectedIndex(),
                    RecordKey.CHECK_UNDER_THE_HANDLE, staff, pass,
                    this.cbUnderTheHandle.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbBungIfDrilled.getSelectedIndex(),
                    RecordKey.CHECK_BUNG_IF_DRILLED, staff, pass,
                    this.cbBungIfDrilled.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbBase.getSelectedIndex(), RecordKey.CHECK_BASE, staff, pass,
                    this.cbBase.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbStrengthOfDrum.getSelectedIndex(),
                    RecordKey.CHECK_STRENGTH_OF_DRUM, staff, pass,
                    this.cbStrengthOfDrum.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbWeightWithinRange.getSelectedIndex(),
                    RecordKey.CHECK_WEIGHT_WITHIN_RANGE, staff, pass,
                    this.cbWeightWithinRange.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbColourTexture.getSelectedIndex(),
                    RecordKey.CHECK_COLOUR_TEXTURE, staff, pass,
                    this.cbColourTexture.getSelectedItem().toString());
            UpdateEntryData(now, (float) this.cbBungProvision.getSelectedIndex(),
                    RecordKey.CHECK_BUNG_PROVISION, staff, pass,
                    this.cbBungProvision.getSelectedItem().toString());

            this.cbNeckRound.setSelectedIndex(0);
            this.cbNeckComplete.setSelectedIndex(0);
            this.cbUnderTheHandle.setSelectedIndex(0);
            this.cbBungIfDrilled.setSelectedIndex(0);
            this.cbBase.setSelectedIndex(0);
            this.cbStrengthOfDrum.setSelectedIndex(0);
            this.cbWeightWithinRange.setSelectedIndex(0);
            this.cbColourTexture.setSelectedIndex(0);
            this.cbBungProvision.setSelectedIndex(0);
        }
    }
}

From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java

private void btnLeakCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLeakCheckActionPerformed
    Boolean isSave = false;//from   w  w  w.j  av  a2  s  . co m
    if (this.currentEntry != null) {
        if (!this.txtLeakCheck.getText().equals("")) {
            isSave = true;
        } else {
            JOptionPane.showMessageDialog(this, "Please entry the data.", "Warning", JOptionPane.OK_OPTION);
        }

        if (isSave) {
            DefaultTableModel model = (DefaultTableModel) this.tblLeak.getModel();
            Date now = new Date();
            String time = new SimpleDateFormat("HH:mm").format(now);
            String stringValue = this.txtLeakCheck.getText();
            model.addRow(new Object[] { time, RecordKey.LEAK_CHECK, stringValue });
            this.txtLeakCheck.setText("");
            UpdateEntryData(now, 0f, RecordKey.LEAK_CHECK, "", "", stringValue);
            //
            stringValue = this.cbLeak.getSelectedItem().toString();
            model.addRow(new Object[] { time, RecordKey.ANY_LEAK, stringValue });
            this.cbLeak.setSelectedIndex(0);
            UpdateEntryData(now, 0f, RecordKey.ANY_LEAK, "", "", stringValue);
            //
            if (!this.txtLeakNotes.getText().equals("")) {
                stringValue = this.txtLeakNotes.getText();
                model.addRow(new Object[] { time, RecordKey.LEAK_NOTES, stringValue });
                this.txtLeakNotes.setText("");
                UpdateEntryData(now, 0f, RecordKey.LEAK_NOTES, "", "", stringValue);
            }
            //
            ((AbstractTableModel) this.tblLeak.getModel()).fireTableDataChanged();
        }
    }
}

From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java

private void btnRejectsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRejectsActionPerformed
    Boolean isSave = false;//from   w  w  w . j  a va  2 s  .c  o  m
    String staff = "";
    String pass = "NO";
    if (this.currentEntry != null) {
        if (!this.txtRejects.getText().equals("")) {
            isSave = true;
            pass = "YES";
        } else {
            JOptionPane.showMessageDialog(this, "Please entry the mount of the rejects.", "Warning",
                    JOptionPane.OK_OPTION);
        }

        if (isSave) {
            DefaultTableModel model = (DefaultTableModel) this.tblRejects.getModel();
            Date now = new Date();
            String time = new SimpleDateFormat("HH:mm").format(now);
            Float value = Float.parseFloat(this.txtRejects.getText());
            model.addRow(new Object[] { time, value });
            ((AbstractTableModel) this.tblRejects.getModel()).fireTableDataChanged();
            this.txtRejects.setText("");
            UpdateEntryData(now, value, RecordKey.BUNG, staff, pass, "");
        }
    }
}

From source file:com.cch.aj.entryrecorder.frame.MainJFrame.java

private void btnSecondsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSecondsActionPerformed
    Boolean isSave = false;//from  w w w .  ja v  a2s  .  co m
    String staff = "";
    String pass = "NO";
    if (this.currentEntry != null) {
        if (!this.txtSeconds.getText().equals("")) {
            isSave = true;
            pass = "YES";
        } else {
            JOptionPane.showMessageDialog(this, "Please entry the mount of the seconds.", "Warning",
                    JOptionPane.OK_OPTION);
        }

        if (isSave) {
            DefaultTableModel model = (DefaultTableModel) this.tblSeconds.getModel();
            Date now = new Date();
            String time = new SimpleDateFormat("HH:mm").format(now);
            Float value = Float.parseFloat(this.txtSeconds.getText());
            model.addRow(new Object[] { time, value });
            ((AbstractTableModel) this.tblSeconds.getModel()).fireTableDataChanged();
            this.txtSeconds.setText("");
            UpdateEntryData(now, value, RecordKey.BUNG, staff, pass, "");
        }
    }
}