1 package SnowMailClient.gnupg.Views; 2 3 import snow.utils.storage.*; 4 import snow.sortabletable.*; 5 import SnowMailClient.Language.Language; 6 import SnowMailClient.gnupg.model.*; 7 import SnowMailClient.gnupg.GnuPGLink; 8 9 import java.util.*; 10 import java.text.*; 11 12 public final class KeysTableModel extends FineGrainTableModel 13 { 14 private final Vector<GnuPGKeyID> keys = new Vector<GnuPGKeyID>(); 15 private boolean advancedMode = true; 16 17 private static final String [] COLUMN_NAMES = new String []{ 18 Language.translate("Type"), 19 Language.translate("Trust"), 20 Language.translate("Name"), 21 Language.translate("Mail address"), 22 Language.translate("Capabilities"), 23 Language.translate("Created"), 24 Language.translate("Expires") }; 25 26 private static final int[] PREFERED_COLUMN_WIDTHS = new int[]{6,7,16,20, 6, 7,7}; 27 28 public static final SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH); 29 30 public KeysTableModel() 31 { 32 } 33 34 public void setKeys(TreeSet<GnuPGKeyID> k ) 35 { 36 this.fireTableModelWillChange(); 37 keys.clear(); 38 keys.addAll(k); 39 this.fireTableDataChanged(); 40 this.fireTableModelHasChanged(); 41 } 42 43 public void addKeys(TreeSet<GnuPGKeyID> k ) 44 { 45 this.fireTableModelWillChange(); 46 keys.addAll(k); 47 this.fireTableDataChanged(); 48 this.fireTableModelHasChanged(); 49 } 50 51 55 public void refreshModel(GnuPGLink link) 56 { 57 this.fireTableModelWillChange(); 58 59 try 61 { 62 link.setGPGPath(link.getPathToGPG()); 64 } 65 catch(Exception ignored) {} 66 67 try 68 { 69 link.setGPGPath(link.getPathToGPG()); 70 keys.clear(); 71 keys.addAll( link.getAllPublicKeyIDs()); 72 if(advancedMode) 73 { 74 keys.addAll( link.getAllSecretKeyIDs()); 75 } 76 } 77 catch(Exception e) { throw new RuntimeException (e); } 78 79 this.fireTableDataChanged(); 80 this.fireTableModelHasChanged(); 81 82 } 83 84 public GnuPGKeyID getKeyAt(int pos) 85 { 86 return keys.elementAt(pos); 87 } 88 89 90 public int getRowCount() 91 { 92 return keys.size(); 93 } 94 95 public int getColumnCount() 96 { 97 return COLUMN_NAMES.length; 98 } 99 100 public final Object getValueAt(int row, int column) 101 { 102 GnuPGKeyID k = keys.elementAt(row); 103 if(column==0) 104 { 105 if(k.isSecret()) return Language.translate("Secret"); 106 return Language.translate("Public"); 107 } 108 if(column==1) 109 { 110 if(k.isSecret()) return ""; if(k.hasExpired()) return Language.translate("Expired"); 112 return k.getCalculatedTrust(); 113 } 114 if(column==2) return k.getNames(); 115 if(column==3) return k.getMails(); 116 if(column==4) return k.getKeyCapabilities(); 117 if(column==5) 118 { 119 long ed = k.getCreationDate(); 120 if(ed==-1) return ""; 121 return dateFormat.format(ed); 122 } 123 if(column==6) 124 { 125 long ed = k.getExpirationDate(); 126 if(ed==-1) return ""; 127 return dateFormat.format(ed); 128 } 129 return "?"; 130 } 131 132 public String getColumnName(int col) 133 { 134 return COLUMN_NAMES[col]; 135 } 136 137 148 public void setAdvancedMode(boolean is, GnuPGLink link) 149 { 150 advancedMode = is; 151 this.refreshModel(link); 152 } 153 154 public int getPreferredColumnWidth(int column) 155 { 156 return PREFERED_COLUMN_WIDTHS[column]; 157 } 158 159 } | Popular Tags |