View Javadoc
1 /* 2 * PreferencesNodeTable 3 * 4 * $RCSfile: PreferencesNodeTable.java,v $ 5 * $Revision: 1.1 $ 6 * $Date: 2004/01/01 17:41:45 $ 7 * $Source: /cvsroot/jpui/jpui/src/PreferencesNodeTable.java,v $ 8 * 9 * JPUI - Java Preferences User Interface 10 * Copyright (C) 2003 11 * 12 * This program is free software; you can redistribute it and/or modify it 13 * under the terms of the GNU General Public License as published by the Free 14 * Software Foundation; either version 2 of the License, or (at your option) 15 * any later version. 16 * 17 * This program is distributed in the hope that it will be useful, but WITHOUT 18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 * more details. 21 * 22 * You should have received a copy of the GNU General Public License along with 23 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 24 * Place, Suite 330, Boston, MA 02111-1307 USA 25 * 26 * Author: macksold@users.sourceforge.net 27 */ 28 29 import java.util.prefs.Preferences; 30 31 import javax.swing.table.AbstractTableModel; 32 33 /*** 34 * Table of a preference nodes keys and values 35 */ 36 public class PreferencesNodeTable extends AbstractTableModel { 37 // reference to current preference node 38 private Preferences moPref; 39 40 // column headings for table 41 private static String[] msColumns = 42 { 43 Resources.getString("edit_node_key"), 44 Resources.getString("edit_node_value")}; 45 46 /*** 47 * default ctor that can not be called 48 */ 49 private PreferencesNodeTable() { 50 } 51 52 /*** 53 * ctor for creating a PreferencesNodeTable given 54 * a preferences node 55 * @param oPref 56 */ 57 public PreferencesNodeTable(Preferences oPref) { 58 moPref = oPref; 59 } 60 61 /*** 62 * @see javax.swing.table.TableModel#getRowCount() 63 */ 64 public int getRowCount() { 65 int nRows = 0; 66 try { 67 nRows = moPref.keys().length; 68 } 69 catch (Exception oEx) { 70 oEx.printStackTrace(); 71 } 72 return nRows; 73 } 74 75 /*** 76 * @see javax.swing.table.TableModel#getColumnCount() 77 */ 78 public int getColumnCount() { 79 return 2; 80 } 81 82 /*** 83 * @see javax.swing.table.TableModel#getValueAt(int, int) 84 */ 85 public Object getValueAt(int nRow, int nColumn) { 86 String sReturn = null; 87 try { 88 String[] sKeys = moPref.keys(); 89 // key 90 if (nColumn == 0) { 91 sReturn = sKeys[nRow]; 92 } 93 // value 94 else { 95 sReturn = moPref.get(sKeys[nRow], null); 96 } 97 } 98 catch (Exception oEx) { 99 oEx.printStackTrace(); 100 } 101 return sReturn; 102 } 103 104 /*** 105 * @see javax.swing.table.TableModel#getColumnName(int) 106 */ 107 public String getColumnName(int nCol) { 108 return msColumns[nCol]; 109 } 110 111 /*** 112 * @see javax.swing.table.TableModel#isCellEditable(int, int) 113 */ 114 public boolean isCellEditable(int nRow, int nColumn) { 115 return true; 116 } 117 118 /*** 119 * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int) 120 */ 121 public void setValueAt(Object oValue, int nRowIndex, int nColumnIndex) { 122 String sKey = (String) getValueAt(nRowIndex, 0); 123 if (nColumnIndex == 0) { 124 // rename the key 125 String sValue = (String) getValueAt(nRowIndex, 1); 126 String sNewKey = (String) oValue; 127 PreferencesModel.Instance().renameAttribute(sKey, sNewKey); 128 } 129 else if (nColumnIndex == 1) { 130 // set the value 131 PreferencesModel.Instance().setAttribute(sKey, oValue.toString()); 132 } 133 134 } 135 136 }

This page was automatically generated by Maven