/* * 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 feuille.xtrn; import java.io.File; import java.util.ArrayList; import java.util.List; import javax.swing.JButton; import javax.swing.JOptionPane; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.plaf.nimbus.NimbusLookAndFeel; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; /** * * @author Yves */ public class ChooseFX extends javax.swing.JPanel { private DefaultTableModel tableModel; private boolean hasDeletedEffects = false; /** * Creates new form ChooseFX */ public ChooseFX() { initComponents(); init(); } private void init(){ try { javax.swing.UIManager.setLookAndFeel(new NimbusLookAndFeel()); javax.swing.SwingUtilities.updateComponentTreeUI(this); } catch (UnsupportedLookAndFeelException exc) { System.out.println("Nimbus LookAndFeel not loaded : "+exc); } String[] fxHead = new String[]{"Name", "Author(s)", "Description", "Effects"}; tableModel = new DefaultTableModel(null,fxHead){ Class[] types = new Class [] { String.class, String.class, String.class , String.class}; boolean[] canEdit = new boolean [] { false, false, false, false}; @Override public Class getColumnClass(int columnIndex) {return types [columnIndex];} @Override public boolean isCellEditable(int rowIndex, int columnIndex) {return canEdit [columnIndex];} }; jTable1.setModel(tableModel); TableColumn column; for (int i = 0; i < 4; i++) { column = jTable1.getColumnModel().getColumn(i); switch(i){ case 0: column.setPreferredWidth(150); break; //Name case 1: column.setPreferredWidth(150); break; //Author(s) case 2: column.setPreferredWidth(400); break; //Description case 3: column.setPreferredWidth(600); break; //Effects } } } public JButton getNextButton(){ return btnNext; } public String getCommmands(){ if(jTable1.getSelectedRow() != -1){ return (String)jTable1.getValueAt(jTable1.getSelectedRow(), 3); } return null; } public void setData(List<AegiObject> aegilist){ for(AegiObject ao : aegilist){ Object[] table = new Object[]{ao, ao.getAuthors(), ao.getDescription(), ao.getCommands()}; tableModel.addRow(table); } } public void rewriteXmlDataBase(String mainfolder){ if(hasDeletedEffects == true){ List<AegiObject> aegilist = new ArrayList<>(); for(int i=0; i<jTable1.getRowCount(); i++){ aegilist.add((AegiObject)jTable1.getValueAt(i, 0)); } XmlAegiWriter wr = new XmlAegiWriter(); wr.setAegiObjectList(aegilist); wr.createAegiBase(mainfolder+File.separator+"saveDataBase.xml"); } } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPopupMenu1 = new javax.swing.JPopupMenu(); popmDeleteEffect = new javax.swing.JMenuItem(); btnNext = new javax.swing.JButton(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); popmDeleteEffect.setText("Delete effects"); popmDeleteEffect.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { popmDeleteEffectActionPerformed(evt); } }); jPopupMenu1.add(popmDeleteEffect); btnNext.setText("Next >>"); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Title 1", "Title 2", "Title 3", "Title 4" } )); jTable1.setComponentPopupMenu(jPopupMenu1); jScrollPane1.setViewportView(jTable1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(btnNext, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 880, Short.MAX_VALUE)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnNext) .addContainerGap()) ); }// </editor-fold>//GEN-END:initComponents private void popmDeleteEffectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_popmDeleteEffectActionPerformed try{ int tabtemp[] = jTable1.getSelectedRows(); for (int i=tabtemp.length-1;i>=0;i--){ tableModel.removeRow(tabtemp[i]); hasDeletedEffects = true; } }catch(Exception exc){ } }//GEN-LAST:event_popmDeleteEffectActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnNext; private javax.swing.JPopupMenu jPopupMenu1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1; private javax.swing.JMenuItem popmDeleteEffect; // End of variables declaration//GEN-END:variables }