/* * 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 javax.swing.JButton; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.plaf.nimbus.NimbusLookAndFeel; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; /** * * @author Yves */ public class XKCStep2C extends javax.swing.JPanel { DefaultTableModel tableModel = new DefaultTableModel(); /** * Creates new form XKCStep2C */ public XKCStep2C() { 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[]{"Layer", "Effects"}; tableModel = new DefaultTableModel(null,fxHead){ Class[] types = new Class [] { java.lang.Integer.class, java.lang.String.class}; boolean[] canEdit = new boolean [] { false, true}; @Override public Class getColumnClass(int columnIndex) {return types [columnIndex];} @Override public boolean isCellEditable(int rowIndex, int columnIndex) {return canEdit [columnIndex];} }; layersTable.setModel(tableModel); TableColumn column; for (int i = 0; i < 2; i++) { column = layersTable.getColumnModel().getColumn(i); switch(i){ case 0: column.setPreferredWidth(60); break; //Layer case 1: column.setPreferredWidth(600); break; //Commands } } } public JButton getNextButton(){ return btnNext; } public String getCommands(){ String commands = ""; for(int i=0;i<tableModel.getRowCount();i++){ if(i+1<tableModel.getRowCount()){ commands += (String)tableModel.getValueAt(i, 1) + "§"; }else{ commands += (String)tableModel.getValueAt(i, 1); } } if(commands.isEmpty()){ return commands; }else{ return "§"+commands; } } /** * 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() { jScrollPane1 = new javax.swing.JScrollPane(); layersTable = new javax.swing.JTable(); btnAdd = new javax.swing.JButton(); btnEdit = new javax.swing.JButton(); btnRemove = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); tfBase = new javax.swing.JTextField(); btnNext = new javax.swing.JButton(); layersTable.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" } )); jScrollPane1.setViewportView(layersTable); btnAdd.setText("Add layer"); btnAdd.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddActionPerformed(evt); } }); btnEdit.setText("Edit layer"); btnEdit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnEditActionPerformed(evt); } }); btnRemove.setText("Remove layer"); btnRemove.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnRemoveActionPerformed(evt); } }); jLabel2.setForeground(new java.awt.Color(255, 0, 0)); jLabel2.setText("<html><h3>Write overrides + effect :"); tfBase.setForeground(new java.awt.Color(255, 0, 0)); tfBase.setText("{\\pos($sx,$sy)\\t($sstart,$send,\\alpha&HFF&)}"); btnNext.setText("Next >>"); btnNext.setEnabled(false); 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(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(btnNext, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 574, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(btnAdd, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnEdit, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnRemove, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))) .addComponent(jLabel2) .addComponent(tfBase)) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(btnAdd) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnEdit) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnRemove)) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(tfBase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnNext) .addContainerGap()) ); }// </editor-fold>//GEN-END:initComponents private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed String s = tfBase.getText() + ";;;;"; tableModel.addRow(new Object[]{tableModel.getRowCount(),s}); btnNext.setEnabled(true); }//GEN-LAST:event_btnAddActionPerformed private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed String s = tfBase.getText() + ";;;;"; tableModel.setValueAt(s, layersTable.getSelectedRow(), 1); }//GEN-LAST:event_btnEditActionPerformed private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveActionPerformed try{ int tabtemp[] = layersTable.getSelectedRows(); for (int i=tabtemp.length-1;i>=0;i--){ tableModel.removeRow(tabtemp[i]); } }catch(Exception exc){ } if(tableModel.getRowCount()==0){ btnNext.setEnabled(false); } }//GEN-LAST:event_btnRemoveActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnAdd; private javax.swing.JButton btnEdit; private javax.swing.JButton btnNext; private javax.swing.JButton btnRemove; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable layersTable; private javax.swing.JTextField tfBase; // End of variables declaration//GEN-END:variables }