/src/mpv5/ui/dialogs/subcomponents/ControlPanel_AdvancedLocalProperties.java
Java | 208 lines | 148 code | 26 blank | 34 comment | 10 complexity | 399135183084abec86aadfe1ee27a34e MD5 | raw file
1/* 2 * This file is part of YaBS. 3 * 4 * YaBS is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * YaBS is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with YaBS. If not, see <http://www.gnu.org/licenses/>. 16 */ 17/* 18 * GeneralListPanel.java 19 * 20 * Created on 03.04.2009, 15:26:37 21 */ 22package mpv5.ui.dialogs.subcomponents; 23 24import java.awt.Component; 25import java.util.ArrayList; 26import java.util.List; 27import javax.swing.JPanel; 28import mpv5.data.PropertyStore; 29import mpv5.globals.LocalSettings; 30import mpv5.globals.Messages; 31import mpv5.ui.dialogs.ControlApplet; 32import mpv5.ui.dialogs.Popup; 33import mpv5.usermanagement.MPSecurityManager; 34import mpv5.utils.models.MPTableModel; 35import mpv5.utils.tables.TableFormat; 36 37/** 38 * 39 * 40 */ 41public class ControlPanel_AdvancedLocalProperties extends javax.swing.JPanel implements ControlApplet { 42 43 private static final long serialVersionUID = 1L; 44 private static ControlPanel_AdvancedLocalProperties ident; 45 private PropertyStore oldvals; 46 47 /** Creates new form GeneralListPanel */ 48 public ControlPanel_AdvancedLocalProperties() { 49 if (MPSecurityManager.checkAdminAccess()) { 50 initComponents(); 51 setData(LocalSettings.getPropertyStore()); 52 } 53 } 54 55 public void setData(PropertyStore vals) { 56 oldvals = vals; 57 List<String[]> data = vals.getList(); 58 Object[][] list = new Object[data.size()][2]; 59 for (int i = 0; i < data.size(); i++) { 60 String[] strings = data.get(i); 61 list[i][0] = strings[0].toUpperCase(); 62 list[i][1] = strings[1]; 63 } 64 MPTableModel mod = new MPTableModel(list, new String[]{Messages.PROPERTY.getValue(), Messages.VALUE.getValue()}); 65 mod.setCanEdits(new boolean[]{false, true, false}); 66 jTable1.setModel(mod); 67 68 } 69 70 /** This method is called from within the constructor to 71 * initialize the form. 72 * WARNING: Do NOT modify this code. The content of this method is 73 * always regenerated by the Form Editor. 74 */ 75 @SuppressWarnings("unchecked") 76 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 77 private void initComponents() { 78 79 jScrollPane1 = new javax.swing.JScrollPane(); 80 jTable1 = new javax.swing.JTable(); 81 jPanel1 = new javax.swing.JPanel(); 82 jButton1 = new javax.swing.JButton(); 83 jButton2 = new javax.swing.JButton(); 84 jButton3 = new javax.swing.JButton(); 85 86 java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N 87 setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_AdvancedLocalProperties.border.title"))); // NOI18N 88 setName("Form"); // NOI18N 89 setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS)); 90 91 jScrollPane1.setName("jScrollPane1"); // NOI18N 92 93 jTable1.setAutoCreateRowSorter(true); 94 jTable1.setModel(new javax.swing.table.DefaultTableModel( 95 new Object [][] { 96 {}, 97 {}, 98 {}, 99 {} 100 }, 101 new String [] { 102 103 } 104 )); 105 jTable1.setName("jTable1"); // NOI18N 106 jScrollPane1.setViewportView(jTable1); 107 108 add(jScrollPane1); 109 110 jPanel1.setBackground(new java.awt.Color(255, 255, 255)); 111 jPanel1.setName("jPanel1"); // NOI18N 112 jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); 113 114 jButton1.setText(bundle.getString("ControlPanel_AdvancedLocalProperties.jButton1.text")); // NOI18N 115 jButton1.setName("jButton1"); // NOI18N 116 jButton1.addActionListener(new java.awt.event.ActionListener() { 117 public void actionPerformed(java.awt.event.ActionEvent evt) { 118 jButton1ActionPerformed(evt); 119 } 120 }); 121 jPanel1.add(jButton1); 122 123 jButton2.setText(bundle.getString("ControlPanel_AdvancedLocalProperties.jButton2.text")); // NOI18N 124 jButton2.setName("jButton2"); // NOI18N 125 jButton2.addActionListener(new java.awt.event.ActionListener() { 126 public void actionPerformed(java.awt.event.ActionEvent evt) { 127 jButton2ActionPerformed(evt); 128 } 129 }); 130 jPanel1.add(jButton2); 131 132 jButton3.setText(bundle.getString("ControlPanel_AdvancedLocalProperties.jButton3.text")); // NOI18N 133 jButton3.setName("jButton3"); // NOI18N 134 jButton3.addActionListener(new java.awt.event.ActionListener() { 135 public void actionPerformed(java.awt.event.ActionEvent evt) { 136 jButton3ActionPerformed(evt); 137 } 138 }); 139 jPanel1.add(jButton3); 140 141 add(jPanel1); 142 }// </editor-fold>//GEN-END:initComponents 143 144 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed 145 if (Popup.Y_N_dialog(Messages.ADVANCED_SETTINGS_SAVE, Messages.WARNING)) { 146 setSettings(); 147 LocalSettings.apply(); 148 LocalSettings.save(); 149 } 150}//GEN-LAST:event_jButton1ActionPerformed 151 152 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed 153 setSettings(); 154 LocalSettings.apply(); 155}//GEN-LAST:event_jButton2ActionPerformed 156 157 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed 158 reset(); 159}//GEN-LAST:event_jButton3ActionPerformed 160 // Variables declaration - do not modify//GEN-BEGIN:variables 161 private javax.swing.JButton jButton1; 162 private javax.swing.JButton jButton2; 163 private javax.swing.JButton jButton3; 164 private javax.swing.JPanel jPanel1; 165 private javax.swing.JScrollPane jScrollPane1; 166 private javax.swing.JTable jTable1; 167 // End of variables declaration//GEN-END:variables 168 169 @Override 170 public Component getAndRemoveActionPanel() { 171 remove(jPanel1); 172 validate(); 173 return jPanel1; 174 } 175 176 @Override 177 public void setValues(PropertyStore values) { 178 setData(values); 179 } 180 181 @Override 182 public String getUname() { 183 return "advancedlocalsettings"; 184 } 185 186 @Override 187 public void reset() { 188 if (oldvals != null) { 189 setValues(oldvals); 190 } 191 } 192 193 private void setSettings() { 194 if (jTable1.getCellEditor() != null) { 195 try { 196 jTable1.getCellEditor().stopCellEditing(); 197 } catch (Exception e) { 198 } 199 } 200 MPTableModel data = (MPTableModel) jTable1.getModel(); 201 int i = data.getRowCount(); 202 for (int j = 0; j < i; j++) { 203 String value = String.valueOf(data.getValueAt(j, 1)); 204 String key = String.valueOf(data.getValueAt(j, 0)).toLowerCase(); 205 if (!key.equals("null") && key.length() > 0)LocalSettings.setProperty(key, value); 206 } 207 } 208}