/* * Copyright (C) 2013 JPEXS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.jpexs.decompiler.flash.gui; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.configuration.ConfigurationItem; import java.lang.reflect.Field; import java.util.Map; import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; /** * * @author JPEXS */ public class AdvancedSettingsDialog extends AppDialog { /** * Creates new form AdvancedSettingsDialog */ public AdvancedSettingsDialog() { initComponents(); View.centerScreen(this); View.setWindowIcon(this); pack(); configurationTable.setCellEditor(configurationTable.getDefaultEditor(null)); Map fields = Configuration.getConfigurationFields(); for (Entry entry : fields.entrySet()) { String name = entry.getKey(); Field field = entry.getValue(); DefaultTableModel model = (DefaultTableModel) configurationTable.getModel(); try { ConfigurationItem item = (ConfigurationItem) field.get(null); model.addRow(new Object[]{name, item.get()}); } catch (IllegalArgumentException | IllegalAccessException ex) { Logger.getLogger(AdvancedSettingsDialog.class.getName()).log(Level.SEVERE, null, ex); } } } /** * 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") // //GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); configurationTable = new com.jpexs.decompiler.flash.gui.EachRowRendererEditor(); btnOk = new javax.swing.JButton(); btnCancel = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setResizable(false); configurationTable.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { }, new String [] { "Name", "Value" } ) { Class[] types = new Class [] { java.lang.String.class, java.lang.Object.class }; boolean[] canEdit = new boolean [] { false, true }; public Class getColumnClass(int columnIndex) { return types [columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit [columnIndex]; } }); jScrollPane1.setViewportView(configurationTable); configurationTable.getColumnModel().getColumn(1).setCellEditor(configurationTable.getCellEditor()); btnOk.setText("OK"); btnOk.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnOkActionPerformed(evt); } }); btnCancel.setText("Cancel"); btnCancel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCancelActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent(btnCancel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnOk))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnOk) .addComponent(btnCancel)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents @SuppressWarnings("unchecked") private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed TableModel model = configurationTable.getModel(); int count = model.getRowCount(); for (int i = 0; i < count; i++) { String name = (String) model.getValueAt(i, 0); Object value = model.getValueAt(i, 1); Map fields = Configuration.getConfigurationFields(); Field field = fields.get(name); ConfigurationItem item = null; try { item = (ConfigurationItem) field.get(null); } catch (IllegalArgumentException | IllegalAccessException ex) { Logger.getLogger(AdvancedSettingsDialog.class.getName()).log(Level.SEVERE, null, ex); } if (item.get() != null && !item.get().equals(value)) { item.set(value); } } Configuration.saveConfig(); setVisible(false); }//GEN-LAST:event_btnOkActionPerformed private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed setVisible(false); }//GEN-LAST:event_btnCancelActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCancel; private javax.swing.JButton btnOk; private com.jpexs.decompiler.flash.gui.EachRowRendererEditor configurationTable; private javax.swing.JScrollPane jScrollPane1; // End of variables declaration//GEN-END:variables }