Changeset 32533 in osm for applications/editors
- Timestamp:
- 2016-07-02T21:57:09+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/trustosm
- Files:
-
- 2 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/trustosm/.settings/org.eclipse.jdt.core.prefs
r30724 r32533 64 64 org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore 65 65 org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning 66 org.eclipse.jdt.core.compiler.problem.redundantSuperinterface= ignore66 org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning 67 67 org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore 68 68 org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore … … 86 86 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled 87 87 org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled 88 org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore 88 89 org.eclipse.jdt.core.compiler.problem.unusedImport=warning 89 90 org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/TrustOSMplugin.java
r32287 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm; 2 3 … … 66 67 Main.pref.put("trustosm.jarLibsExtracted", extractFiles("trustosm","resources")); 67 68 }*/ 68 extractFiles("trustosm", "lib");69 extractFiles("trustosm", "resources");69 extractFiles("trustosm", "lib"); 70 extractFiles("trustosm", "resources"); 70 71 71 72 refreshMenu(); … … 84 85 85 86 public static void checkForUnrestrictedPolicyFiles() { 86 byte[] data = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};87 byte[] data = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; 87 88 88 89 // create a cipher and attempt to encrypt the data block with our key 89 try {90 try { 90 91 Cipher c = Cipher.getInstance("AES"); 91 92 // create a 192 bit secret key from raw bytes 92 93 93 SecretKey key192 = new SecretKeySpec(new byte[] { 94 95 96 94 SecretKey key192 = new SecretKeySpec(new byte[] {0x00, 0x01, 0x02, 95 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 96 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 97 0x17 }, "AES"); 97 98 98 99 // now try encrypting with the larger key … … 103 104 Main.warn("It seems that the Unrestricted Policy Files are not available in this JVM. "+ 104 105 "So high level crypto is not allowed. Problems may occur."); 105 //extractFiles("trustosm","jce");106 106 installUnrestrictedPolicyFiles(); 107 107 } catch (BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException | NoSuchAlgorithmException e) { … … 260 260 gpgJMenu.add(new JMenuItem(new ExportSigsAction())); 261 261 } 262 263 262 } 264 263 265 264 public static void setSettings() { 266 Map<String, String> prefs = Main.pref.getAllPrefix("trustosm.");265 Map<String, String> prefs = Main.pref.getAllPrefix("trustosm."); 267 266 268 267 // if setting isn't present, we set a default … … 272 271 } 273 272 274 275 273 @Override 276 274 public PreferenceSetting getPreferenceSetting() { … … 280 278 @Override 281 279 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 282 if (oldFrame ==null && newFrame!=null) {280 if (oldFrame == null && newFrame != null) { 283 281 trustDialog = new TrustDialog(); 284 282 newFrame.addToggleDialog(trustDialog); -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/actions/ExportSigsAction.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.actions; 2 3 -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/actions/GetMissingDataAction.java
r32511 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.actions; 2 3 … … 22 23 23 24 public GetMissingDataAction() { 24 super(tr("Download OSM"), "getmissing",tr("Get all referenced but not actually present OSM objects from OSM server."),25 Shortcut.registerShortcut("gpg:download", tr("Download referenced osm objects..."), KeyEvent.VK_T, Shortcut.CTRL), true);25 super(tr("Download OSM"), "getmissing", tr("Get all referenced but not actually present OSM objects from OSM server."), 26 Shortcut.registerShortcut("gpg:download", tr("Download referenced osm objects..."), KeyEvent.VK_T, Shortcut.CTRL), true); 26 27 } 27 28 … … 35 36 public boolean downloadMissing() { 36 37 Collection<OsmPrimitive> missingData = new HashSet<>(); 37 Map<String, TrustOsmPrimitive> trustitems = TrustOSMplugin.signedItems;38 Map<String, TrustOsmPrimitive> trustitems = TrustOSMplugin.signedItems; 38 39 getMissing(trustitems, missingData); 39 40 … … 41 42 int itemCount = trustitems.size(); 42 43 if (missingCount == 0) { 43 JOptionPane.showMessageDialog(Main.parent, tr("{0} Signatures loaded. All referenced OSM objects found.", itemCount));44 JOptionPane.showMessageDialog(Main.parent, tr("{0} Signatures loaded. All referenced OSM objects found.", itemCount)); 44 45 } else { 45 int n = JOptionPane.showOptionDialog(Main.parent, tr("{0} of {1} OSM objects are referenced but not there.\nDo you want to load them from OSM-Server?",missingCount,itemCount), tr("Load objects from server"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 46 int n = JOptionPane.showOptionDialog(Main.parent, 47 tr("{0} of {1} OSM objects are referenced but not there.\nDo you want to load them from OSM-Server?", 48 missingCount, itemCount), 49 tr("Load objects from server"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 46 50 47 51 if (n == JOptionPane.YES_OPTION) { … … 54 58 } 55 59 56 public void getMissing(Map<String, TrustOsmPrimitive> trustitems, Collection<OsmPrimitive> missingData) {60 public void getMissing(Map<String, TrustOsmPrimitive> trustitems, Collection<OsmPrimitive> missingData) { 57 61 Collection<OsmPrimitive> presentData = Main.getLayerManager().getEditDataSet().allPrimitives(); 58 62 for (TrustOsmPrimitive t : trustitems.values()) { … … 62 66 } 63 67 } 64 65 66 68 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustNode.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.data; 2 3 … … 12 13 public class TrustNode extends TrustOsmPrimitive { 13 14 14 15 15 public static Node generateNodeFromSigtext(String sigtext) { 16 16 Pattern p = Pattern.compile("^(\\d*)\\((\\d*\\.?\\d*),(\\d*\\.?\\d*)\\)"); … … 18 18 if (m.matches()) { 19 19 Node node = new Node(Long.parseLong(m.group(1))); 20 node.setCoor(new LatLon(Double.parseDouble(m.group(2)), Double.parseDouble(m.group(3))));20 node.setCoor(new LatLon(Double.parseDouble(m.group(2)), Double.parseDouble(m.group(3)))); 21 21 return node; 22 22 } … … 40 40 @Override 41 41 public void setOsmPrimitive(OsmPrimitive osmItem) { 42 if (osmItem instanceof Node) {42 if (osmItem instanceof Node) { 43 43 osm = osmItem; 44 44 } else { … … 56 56 57 57 public void setNodeRatings(TrustSignatures ratings) { 58 this.ratings = ratings;58 this.ratings = ratings; 59 59 } 60 60 … … 62 62 return ratings; 63 63 } 64 65 64 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustOsmPrimitive.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.data; 2 3 … … 11 12 import org.openstreetmap.josm.data.osm.Way; 12 13 13 abstract publicclass TrustOsmPrimitive {14 public abstract class TrustOsmPrimitive { 14 15 15 16 public static String createUniqueObjectIdentifier(OsmPrimitive osm) { 16 17 String id = ""; 17 if (osm instanceof Node) {18 if (osm instanceof Node) { 18 19 id = "n"; 19 } else if (osm instanceof Way) {20 } else if (osm instanceof Way) { 20 21 id = "w"; 21 } else if (osm instanceof Relation) {22 } else if (osm instanceof Relation) { 22 23 id = "r"; 23 24 } … … 38 39 39 40 public static TrustOsmPrimitive createTrustOsmPrimitive(OsmPrimitive osm) { 40 if (osm instanceof Node) {41 if (osm instanceof Node) { 41 42 return new TrustNode((Node) osm); 42 } else if (osm instanceof Way) {43 } else if (osm instanceof Way) { 43 44 return new TrustWay(osm); 44 } else if (osm instanceof Relation) {45 } else if (osm instanceof Relation) { 45 46 return new TrustRelation(osm); 46 47 } … … 60 61 61 62 public abstract void setOsmPrimitive(OsmPrimitive osmItem); 62 63 63 64 64 public static String[] generateTagsFromSigtext(String sigtext) { -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustRelation.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.data; 2 3 … … 14 15 public class TrustRelation extends TrustOsmPrimitive { 15 16 16 17 17 public static RelationMember generateRelationMemberFromSigtext(String sigtext) { 18 18 Pattern p = Pattern.compile("^RelID=(\\w*)\n(\\d*),(.*)"); … … 20 20 if (m.matches()) { 21 21 OsmPrimitive osm = createOsmPrimitiveFromUniqueObjectIdentifier(m.group(2)); 22 return new RelationMember(m.group(3), osm);22 return new RelationMember(m.group(3), osm); 23 23 } 24 24 return null; … … 26 26 27 27 public static String generateRelationMemberSigtext(TrustRelation trust, String memID) { 28 Relation r = (Relation) trust.getOsmPrimitive();28 Relation r = (Relation) trust.getOsmPrimitive(); 29 29 List<RelationMember> members = r.getMembers(); 30 30 RelationMember member = null; … … 49 49 @Override 50 50 public void setOsmPrimitive(OsmPrimitive osmItem) { 51 if (osmItem instanceof Relation) {51 if (osmItem instanceof Relation) { 52 52 osm = osmItem; 53 53 } else { … … 55 55 } 56 56 } 57 58 57 59 58 public void storeMemberSig(String memID, PGPSignature sig) { … … 73 72 return memberSig; 74 73 } 75 76 74 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustSignatures.java
r30744 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.data; 2 3 … … 17 18 public class TrustSignatures { 18 19 19 public final staticbyte SIG_UNKNOWN = 0;20 public final staticbyte SIG_VALID = 1;21 public final staticbyte SIG_BROKEN = -1;22 public final staticbyte ITEM_REMOVED = -2;20 public static final byte SIG_UNKNOWN = 0; 21 public static final byte SIG_VALID = 1; 22 public static final byte SIG_BROKEN = -1; 23 public static final byte ITEM_REMOVED = -2; 23 24 24 25 //private final Vector<PGPSignature> signatures = new Vector<PGPSignature>(); … … 125 126 126 127 public String getArmoredFulltextSignatureAll(String plain) { 127 if (textsigs.containsKey(plain)) {128 if (textsigs.containsKey(plain)) { 128 129 List<PGPSignature> l = textsigs.get(plain); 129 130 PGPSignature first = l.get(0); -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustWay.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.data; 2 3 … … 27 28 String[] lines = sigtext.split("\n"); 28 29 List<Node> nodes = new ArrayList<>(); 29 for (int i =1; i<lines.length; i++){30 for (int i = 1; i < lines.length; i++) { 30 31 nodes.add(TrustNode.generateNodeFromSigtext(lines[i])); 31 32 } … … 50 51 @Override 51 52 public void setOsmPrimitive(OsmPrimitive osmItem) { 52 if (osmItem instanceof Way) {53 if (osmItem instanceof Way) { 53 54 osm = osmItem; 54 55 } else { … … 57 58 } 58 59 59 60 60 public void storeSegmentSig(List<Node> nodes, PGPSignature sig) { 61 61 if (segmentSig.containsKey(nodes)) { 62 segmentSig.get(nodes).addSignature(sig, TrustWay.generateSegmentSigtext(this, nodes));62 segmentSig.get(nodes).addSignature(sig, TrustWay.generateSegmentSigtext(this, nodes)); 63 63 } else { 64 segmentSig.put(nodes, new TrustSignatures(sig, TrustWay.generateSegmentSigtext(this, nodes), TrustSignatures.SIG_VALID));64 segmentSig.put(nodes, new TrustSignatures(sig, TrustWay.generateSegmentSigtext(this, nodes), TrustSignatures.SIG_VALID)); 65 65 } 66 66 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/DownloadSignedOsmDataTask.java
r31897 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.gui; 2 3 … … 23 24 import org.xml.sax.SAXException; 24 25 25 public class DownloadSignedOsmDataTask 26 public class DownloadSignedOsmDataTask extends PleaseWaitRunnable { 26 27 27 28 private boolean canceled; … … 41 42 } 42 43 43 44 44 @Override 45 45 protected void cancel() { 46 46 canceled = true; 47 synchronized (this) {47 synchronized (this) { 48 48 if (objectReader != null) { 49 49 objectReader.cancel(); … … 68 68 missing.size(), 69 69 "Wurst" 70 70 ); 71 71 } 72 72 … … 81 81 progressMonitor.indeterminateSubTask( 82 82 buildDownloadFeedbackMessage() 83 83 ); 84 84 final DataSet dataSet = objectReader.parseOsm(progressMonitor 85 85 .createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); … … 100 100 } 101 101 } 102 102 ); 103 103 104 104 } catch (Exception e) { -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/KeyGenerationTask.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.gui; 2 3 … … 22 23 protected void cancel() { 23 24 canceled = true; 24 synchronized (this) {25 synchronized (this) { 25 26 /* if (objectReader != null) { 26 27 objectReader.cancel(); … … 40 41 41 42 @Override 42 protected void realRun() throws SAXException, IOException, 43 OsmTransferException { 44 try { 45 /* synchronized (this) { 43 protected void realRun() throws SAXException, IOException, OsmTransferException { 44 /*try { 45 synchronized (this) { 46 46 if (canceled) return; 47 47 objectReader = new MultiFetchServerObjectReader(); … … 50 50 progressMonitor.indeterminateSubTask( 51 51 buildDownloadFeedbackMessage() 52 52 ); 53 53 final DataSet dataSet = objectReader.parseOsm(progressMonitor 54 54 .createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); … … 68 68 } 69 69 } 70 71 */ 70 ); 71 72 72 } catch (Exception e) { 73 73 if (canceled) { … … 77 77 } 78 78 lastException = e; 79 } 80 79 }*/ 81 80 } 82 81 -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/KeyTreeTableModel.java
r31945 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.gui; 2 3 … … 21 22 22 23 public static String convPGPSignatureToString(PGPSignature s) { 23 if (s ==null) return null;24 if (s == null) return null; 24 25 PGPSignatureSubpacketVector sv = s.getHashedSubPackets(); 25 26 if (sv != null && sv.hasSubpacket(SignatureSubpacketTags.SIGNER_USER_ID)) … … 27 28 28 29 PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(s.getKeyID()); 29 if (pub != null) {30 if (pub != null) { 30 31 Iterator<?> i = pub.getUserIDs(); 31 32 if (i.hasNext()) 32 return (String) i.next();33 return (String) i.next(); 33 34 34 35 } … … 37 38 38 39 private final SignatureTreeNode root; 39 private final String[] allTitle = {tr("UID"), tr("KeyID"),tr("OSM-Info"),tr("Signed")};40 private final String[] allTitle = {tr("UID"), tr("KeyID"), tr("OSM-Info"), tr("Signed")}; 40 41 private final List<String> columns = new ArrayList<>(Arrays.asList(allTitle)); 41 42 … … 47 48 PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(s.getKeyID()); 48 49 Iterator<?> iter = pub.getSignatures(); 49 while (iter.hasNext()) {50 PGPSignature ks = (PGPSignature) iter.next();50 while (iter.hasNext()) { 51 PGPSignature ks = (PGPSignature) iter.next(); 51 52 sn.getChildren().add(new SignatureTreeNode(ks)); 52 53 } … … 62 63 63 64 @Override 64 public String getColumnName( int column) {65 public String getColumnName(int column) { 65 66 String title = columns.get(column); 66 67 if (title != null) … … 69 70 } 70 71 71 72 72 @Override 73 73 public Object getValueAt(Object node, int column) { 74 SignatureTreeNode signode = ( SignatureTreeNode )node;74 SignatureTreeNode signode = (SignatureTreeNode) node; 75 75 String title = columns.get(column); 76 if (title != null) {76 if (title != null) { 77 77 if (title.equals(allTitle[0])) 78 78 return signode.getUID(); … … 90 90 @Override 91 91 public Object getChild(Object node, int index) { 92 SignatureTreeNode signode = ( SignatureTreeNode )node;93 return signode.getChildren().get( index);92 SignatureTreeNode signode = (SignatureTreeNode) node; 93 return signode.getChildren().get(index); 94 94 } 95 95 96 96 @Override 97 97 public int getChildCount(Object node) { 98 SignatureTreeNode signode = ( SignatureTreeNode )node;98 SignatureTreeNode signode = (SignatureTreeNode) node; 99 99 return signode.getChildren().size(); 100 100 } 101 101 102 102 @Override 103 public int getIndexOfChild( Object parent, Object child) {104 SignatureTreeNode signode = ( SignatureTreeNode )parent;105 for ( int i=0; i>signode.getChildren().size(); i++) {106 if ( signode.getChildren().get( i ) == child)103 public int getIndexOfChild(Object parent, Object child) { 104 SignatureTreeNode signode = (SignatureTreeNode) parent; 105 for (int i = 0; i > signode.getChildren().size(); i++) { 106 if (signode.getChildren().get(i) == child) 107 107 return i; 108 108 } … … 114 114 return root; 115 115 } 116 117 116 118 117 public class SignatureTreeNode { … … 127 126 } 128 127 129 public PGPSignature getSignature() {128 public PGPSignature getSignature() { 130 129 return s; 131 130 } 131 132 132 public String getUID() { 133 133 return convPGPSignatureToString(s); 134 134 } 135 135 136 public String getKeyID() { 136 137 return "0x"+Long.toHexString(s.getKeyID()).substring(8).toUpperCase(); 137 138 } 139 138 140 public String getOsmCertificate() { 139 141 String cert = ""; 140 for (NotationData nd : s.getHashedSubPackets().getNotationDataOccurrences()) {142 for (NotationData nd : s.getHashedSubPackets().getNotationDataOccurrences()) { 141 143 if (nd.getNotationName().equals("trustosm@openstreetmap.org")) { 142 144 cert += nd.getNotationValue(); … … 145 147 return cert; 146 148 } 149 147 150 public String getSignatureDate() { 148 151 return formatter.format(s.getCreationTime()); 149 152 } 153 150 154 public List<SignatureTreeNode> getChildren() { 151 155 return children; 152 156 } 153 154 157 } 155 158 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/dialogs/JCollapsiblePanel.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.gui.dialogs; 2 3 … … 21 22 JLabel title; 22 23 23 publicHeaderPanel(String text) {24 HeaderPanel(String text) { 24 25 25 26 setLayout(new GridBagLayout()); 26 title = new JLabel(text, ImageProvider.get("misc", "minimized"),SwingConstants.LEADING);27 add(title, GBC.eol());27 title = new JLabel(text, ImageProvider.get("misc", "minimized"), SwingConstants.LEADING); 28 add(title, GBC.eol()); 28 29 30 addMouseListener(new MouseAdapter() { 31 @Override 32 public void mouseClicked(MouseEvent e) { 33 expanded = !expanded; 29 34 30 addMouseListener( 31 new MouseAdapter() { 32 @Override 33 public void mouseClicked(MouseEvent e) { 34 expanded = !expanded; 35 if (contentPanel_.isShowing()) { 36 contentPanel_.setVisible(false); 37 title.setIcon(ImageProvider.get("misc", "minimized")); 38 } else { 39 contentPanel_.setVisible(true); 40 title.setIcon(ImageProvider.get("misc", "normal")); 41 } 42 validate(); 35 43 36 if (contentPanel_.isShowing()) { 37 contentPanel_.setVisible(false); 38 title.setIcon(ImageProvider.get("misc", "minimized")); 39 } 40 else { 41 contentPanel_.setVisible(true); 42 title.setIcon(ImageProvider.get("misc", "normal")); 43 } 44 validate(); 45 46 headerPanel_.repaint(); 47 } 48 } 49 ); 50 44 headerPanel_.repaint(); 45 } 46 }); 51 47 } 52 53 48 } 54 49 … … 62 57 contentPanel_.setVisible(false); 63 58 } 64 65 59 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/dialogs/KeySignaturesDialog.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.gui.dialogs; 2 3 … … 29 30 private JLabel lblMinimized; 30 31 31 32 32 public KeySignaturesDialog(PGPPublicKey key) { 33 33 super(new BorderLayout()); … … 36 36 Iterator<?> iter = key.getUserIDs(); 37 37 if (iter.hasNext()) { 38 userid = (String) iter.next();38 userid = (String) iter.next(); 39 39 } 40 40 … … 52 52 Iterator<?> iter = key.getSignatures(); 53 53 while (iter.hasNext()) { 54 PGPSignature sig = (PGPSignature) iter.next();54 PGPSignature sig = (PGPSignature) iter.next(); 55 55 String uid = "0x"+Long.toHexString(sig.getKeyID()).substring(8).toUpperCase(); 56 56 p.add(new JLabel(uid)); … … 67 67 //setContentVisible(false); 68 68 isCollapsed = true; 69 setPreferredSize(new Dimension(0, 20));70 setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));71 setMinimumSize(new Dimension(Integer.MAX_VALUE, 20));69 setPreferredSize(new Dimension(0, 20)); 70 setMaximumSize(new Dimension(Integer.MAX_VALUE, 20)); 71 setMinimumSize(new Dimension(Integer.MAX_VALUE, 20)); 72 72 lblMinimized.setIcon(ImageProvider.get("misc", "minimized")); 73 } 74 else throw new IllegalStateException(); 73 } else throw new IllegalStateException(); 75 74 } 76 75 … … 82 81 // setContentVisible(true); 83 82 isCollapsed = false; 84 setPreferredSize(new Dimension(0, 200));83 setPreferredSize(new Dimension(0, 200)); 85 84 setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); 86 85 lblMinimized.setIcon(ImageProvider.get("misc", "normal")); 87 } 88 else throw new IllegalStateException(); 86 } else throw new IllegalStateException(); 89 87 } 90 88 … … 95 93 */ 96 94 protected void setContentVisible(boolean visible) { 97 Component comps[]= getComponents();98 for (int i=0; i<comps.length; i++) {99 if (comps[i] != titleBar) {95 Component[] comps = getComponents(); 96 for (int i = 0; i < comps.length; i++) { 97 if (comps[i] != titleBar) { 100 98 comps[i].setVisible(visible); 101 99 } … … 105 103 /** 106 104 * The title bar displayed in docked mode 107 *108 105 */ 109 106 protected class TitleBar extends JPanel { 110 final privateJLabel lblTitle;107 private final JLabel lblTitle; 111 108 112 109 public TitleBar(String toggleDialogName) { … … 130 127 } 131 128 } 132 129 ); 133 130 134 131 setToolTipText(tr("Click to minimize/maximize the panel content")); -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/dialogs/TrustDialog.java
r30744 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.gui.dialogs; 2 3 … … 66 67 public class TrustDialog extends ToggleDialog implements SelectionChangedListener, MapViewPaintable { 67 68 68 public final static Color BGCOLOR_NO_SIG = new Color(234, 234, 234); 69 // public final static Color BGCOLOR_VALID_SIG = new Color(235,255,177); 70 public final static Color BGCOLOR_VALID_SIG = new Color(74,245,106); 71 public final static Color BGCOLOR_BROKEN_SIG = new Color(255, 197, 197); 72 public final static Color BGCOLOR_REMOVED_ITEM = new Color(255, 100, 100); 73 public final static Color BGCOLOR_UPDATED_ITEM = new Color(249,221,95); 74 75 /** Use a TrustGPGPreparer to sign or validate signatures */ 76 //private final TrustGPGPreparer gpg; 69 public static final Color BGCOLOR_NO_SIG = new Color(234, 234, 234); 70 // public static final Color BGCOLOR_VALID_SIG = new Color(235, 255,177); 71 public static final Color BGCOLOR_VALID_SIG = new Color(74, 245, 106); 72 public static final Color BGCOLOR_BROKEN_SIG = new Color(255, 197, 197); 73 public static final Color BGCOLOR_REMOVED_ITEM = new Color(255, 100, 100); 74 public static final Color BGCOLOR_UPDATED_ITEM = new Color(249, 221, 95); 77 75 78 76 /** The check signatures button */ … … 103 101 return false; 104 102 } 103 105 104 @Override public Class<?> getColumnClass(int columnIndex) { 106 105 return String.class; … … 115 114 if (!isRowSelected(row)) 116 115 switch (stat.byteValue()) { 117 case -2: c.setBackground( BGCOLOR_REMOVED_ITEM); break;118 case -1: c.setBackground( BGCOLOR_BROKEN_SIG); break;119 case 1: c.setBackground( BGCOLOR_VALID_SIG); break;120 default: c.setBackground( BGCOLOR_NO_SIG); break;116 case -2: c.setBackground(BGCOLOR_REMOVED_ITEM); break; 117 case -1: c.setBackground(BGCOLOR_BROKEN_SIG); break; 118 case 1: c.setBackground(BGCOLOR_VALID_SIG); break; 119 default: c.setBackground(BGCOLOR_NO_SIG); break; 121 120 } 122 121 return c; … … 142 141 if (!isRowSelected(row)) 143 142 switch (stat.byteValue()) { 144 case -2: c.setBackground( BGCOLOR_REMOVED_ITEM 145 case -1: c.setBackground( BGCOLOR_BROKEN_SIG 146 case 1: c.setBackground( BGCOLOR_VALID_SIG 147 default: c.setBackground( BGCOLOR_NO_SIG 143 case -2: c.setBackground( BGCOLOR_REMOVED_ITEM); break; 144 case -1: c.setBackground( BGCOLOR_BROKEN_SIG); break; 145 case 1: c.setBackground( BGCOLOR_VALID_SIG); break; 146 default: c.setBackground( BGCOLOR_NO_SIG); break; 148 147 } 149 148 return c; … … 162 161 163 162 // setting up the properties table 164 propertyData.setColumnIdentifiers(new String[]{tr("Key"), tr("Value")});163 propertyData.setColumnIdentifiers(new String[]{tr("Key"), tr("Value")}); 165 164 166 165 // copy and paste from org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog 167 166 168 propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {167 propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() { 169 168 /** 170 169 * … … 183 182 Map<?, ?> v = (Map<?, ?>) value; 184 183 if (v.size() != 1) { 185 str =tr("<different>");184 str = tr("<different>"); 186 185 c.setFont(c.getFont().deriveFont(Font.ITALIC)); 187 186 } else { … … 190 189 } 191 190 } 192 ((JLabel) c).setText(str);191 ((JLabel) c).setText(str); 193 192 } 194 193 return c; … … 196 195 }); 197 196 198 geomTree = new JTree( createTree());199 200 geomTree.setBackground( BGCOLOR_NO_SIG);197 geomTree = new JTree(createTree()); 198 199 geomTree.setBackground(BGCOLOR_NO_SIG); 201 200 geomTree.setRootVisible(false); 202 geomTree.setCellRenderer(new DefaultTreeCellRenderer(){ 203 201 geomTree.setCellRenderer(new DefaultTreeCellRenderer() { 204 202 @Override 205 203 public Component getTreeCellRendererComponent(JTree tree, Object value, 206 boolean selected, boolean expanded, boolean leaf, int row, 207 boolean hasFocus) 208 { 204 boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { 209 205 super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); 210 211 DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; 206 DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; 212 207 if (node.isRoot()) return this; 213 setBackgroundNonSelectionColor( BGCOLOR_NO_SIG);208 setBackgroundNonSelectionColor(BGCOLOR_NO_SIG); 214 209 Object o = node.getUserObject(); 215 if (o instanceof OsmPrimitive) {210 if (o instanceof OsmPrimitive) { 216 211 OsmPrimitive osm = (OsmPrimitive) o; 217 212 setIcon(ImageProvider.get(OsmPrimitiveType.from(osm))); 218 213 setText(osm.getDisplayName(DefaultNameFormatter.getInstance())); 219 220 214 if (osm instanceof Node) { 221 215 TrustSignatures sigs; 222 216 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 223 if (TrustOSMplugin.signedItems.containsKey(id) && (sigs = ((TrustNode)TrustOSMplugin.signedItems.get(id)).getNodeSigs()) != null) { 217 if (TrustOSMplugin.signedItems.containsKey(id) 218 && (sigs = ((TrustNode) TrustOSMplugin.signedItems.get(id)).getNodeSigs()) != null) { 224 219 byte stat = sigs.getStatus(); 225 220 switch (stat) { 226 case -2: setBackgroundNonSelectionColor( BGCOLOR_REMOVED_ITEM); break;227 case -1: setBackgroundNonSelectionColor( BGCOLOR_BROKEN_SIG); break;228 case 1: setBackgroundNonSelectionColor( BGCOLOR_VALID_SIG); break;229 default: setBackgroundNonSelectionColor( BGCOLOR_NO_SIG); break;221 case -2: setBackgroundNonSelectionColor(BGCOLOR_REMOVED_ITEM); break; 222 case -1: setBackgroundNonSelectionColor(BGCOLOR_BROKEN_SIG); break; 223 case 1: setBackgroundNonSelectionColor(BGCOLOR_VALID_SIG); break; 224 default: setBackgroundNonSelectionColor(BGCOLOR_NO_SIG); break; 230 225 } 231 226 } 232 } else if (osm instanceof Way) { 233 //setBackgroundNonSelectionColor( BGCOLOR_NO_SIG ); 234 } 235 236 } else if (o instanceof WaySegment){ 227 } 228 } else if (o instanceof WaySegment) { 237 229 WaySegment seg = (WaySegment) o; 238 230 setIcon(ImageProvider.get("mapmode/addsegment")); 239 setText(seg.getFirstNode().getDisplayName(DefaultNameFormatter.getInstance()) + " ----- " + seg.getSecondNode().getDisplayName(DefaultNameFormatter.getInstance())); 231 setText(seg.getFirstNode().getDisplayName(DefaultNameFormatter.getInstance()) 232 + " ----- " + 233 seg.getSecondNode().getDisplayName(DefaultNameFormatter.getInstance())); 240 234 TrustSignatures sigs; 241 235 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(seg.way); 242 if (TrustOSMplugin.signedItems.containsKey(id) && (sigs = ((TrustWay)TrustOSMplugin.signedItems.get(id)).getSigsOnSegment(seg)) != null) {243 byte stat = sigs.getStatus();244 switch (s tat) {245 case -2: setBackgroundNonSelectionColor( BGCOLOR_REMOVED_ITEM); break;246 case -1: setBackgroundNonSelectionColor( BGCOLOR_BROKEN_SIG); break;247 case 1: setBackgroundNonSelectionColor( BGCOLOR_VALID_SIG); break;248 default: setBackgroundNonSelectionColor( BGCOLOR_NO_SIG); break;236 if (TrustOSMplugin.signedItems.containsKey(id) 237 && (sigs = ((TrustWay) TrustOSMplugin.signedItems.get(id)).getSigsOnSegment(seg)) != null) { 238 switch (sigs.getStatus()) { 239 case -2: setBackgroundNonSelectionColor(BGCOLOR_REMOVED_ITEM); break; 240 case -1: setBackgroundNonSelectionColor(BGCOLOR_BROKEN_SIG); break; 241 case 1: setBackgroundNonSelectionColor(BGCOLOR_VALID_SIG); break; 242 default: setBackgroundNonSelectionColor(BGCOLOR_NO_SIG); break; 249 243 } 250 244 } … … 263 257 selectedPrimitives.clear(); 264 258 selectedSegments.clear(); 265 if (geomTree.getSelectionPaths() !=null)259 if (geomTree.getSelectionPaths() != null) 266 260 for (TreePath tp : geomTree.getSelectionPaths()) { 267 261 Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject(); … … 278 272 }); 279 273 280 propertyTable.addFocusListener(new FocusListener() {274 propertyTable.addFocusListener(new FocusListener() { 281 275 282 276 @Override 283 277 public void focusGained(FocusEvent fe) { 284 278 geomTree.clearSelection(); 285 286 279 } 287 280 … … 292 285 }); 293 286 294 geomTree.addFocusListener(new FocusListener() {287 geomTree.addFocusListener(new FocusListener() { 295 288 296 289 @Override … … 318 311 319 312 createLayout(dataPanel, true, Arrays.asList(new SideButton[] { 320 checkButton, signButton, showButton313 checkButton, signButton, showButton 321 314 })); 322 315 DataSet.addSelectionListener(this); … … 325 318 private class CheckAction extends JosmAction { 326 319 327 publicCheckAction() {320 CheckAction() { 328 321 super(tr("Check"), "checksignatures", tr("Check all available signatures for selected object."), null, false); 329 322 } … … 336 329 if (TrustOSMplugin.signedItems.containsKey(id)) 337 330 TrustAnalyzer.checkEverything(TrustOSMplugin.signedItems.get(id)); 338 //checkedItems.put(osm, TrustOSMplugin.gpg.check(checkedItems.containsKey(osm)? checkedItems.get(osm) : new TrustOSMItem(osm)));339 331 } 340 332 } … … 346 338 private class SignAction extends JosmAction { 347 339 348 publicSignAction() {340 SignAction() { 349 341 super(tr("Sign"), "sign", tr("Digital sign selected Tags, if you believe they are correct."), null, false); 350 342 } … … 354 346 if (osmData != null) { 355 347 for (int i : propertyTable.getSelectedRows()) { 356 String key = (String) propertyTable.getValueAt(i, 0);348 String key = (String) propertyTable.getValueAt(i, 0); 357 349 for (OsmPrimitive osm : osmData) { 358 350 if (osm.keySet().contains(key)) { 359 351 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 360 TrustOsmPrimitive trust = TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : TrustOsmPrimitive.createTrustOsmPrimitive(osm); 352 TrustOsmPrimitive trust = TrustOSMplugin.signedItems.containsKey(id) ? 353 TrustOSMplugin.signedItems.get(id) : TrustOsmPrimitive.createTrustOsmPrimitive(osm); 361 354 if (TrustOSMplugin.gpg.signTag(trust, key)) 362 355 TrustOSMplugin.signedItems.put(id, trust); … … 365 358 } 366 359 } 367 if (geomTree.getSelectionPaths() !=null)360 if (geomTree.getSelectionPaths() != null) 368 361 for (TreePath tp : geomTree.getSelectionPaths()) { 369 362 Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject(); … … 373 366 if (osm instanceof Node) { 374 367 Node osmNode = ((Node) osm); 375 TrustNode trust = TrustOSMplugin.signedItems.containsKey(id)? (TrustNode) TrustOSMplugin.signedItems.get(id) : new TrustNode(osmNode); 368 TrustNode trust = TrustOSMplugin.signedItems.containsKey(id) ? 369 (TrustNode) TrustOSMplugin.signedItems.get(id) : new TrustNode(osmNode); 376 370 trust.storeNodeSig(TrustOSMplugin.gpg.signNode(osmNode)); 377 371 TrustOSMplugin.signedItems.put(id, trust); 378 379 372 380 373 /* TreePath parentPath = tp.getParentPath(); … … 386 379 id = String.valueOf(osm.getUniqueId()); 387 380 } 388 TrustOsmPrimitive trust = TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : TrustOsmPrimitive.createTrustOsmPrimitive(osm); 381 TrustOsmPrimitive trust = TrustOSMplugin.signedItems.containsKey(id) ? 382 TrustOSMplugin.signedItems.get(id) : TrustOsmPrimitive.createTrustOsmPrimitive(osm); 389 383 trust.storeNodeSig(osmNode, TrustOSMplugin.gpg.signNode(osm,osmNode)); 390 384 TrustOSMplugin.signedItems.put(id, trust); 391 385 */ 392 386 } else if (osm instanceof Way) { 393 TrustOSMplugin.signedItems.put(id, TrustOSMplugin.gpg.signWay(TrustOSMplugin.signedItems.containsKey(id)? (TrustWay)TrustOSMplugin.signedItems.get(id) : new TrustWay(osm))); 387 TrustOSMplugin.signedItems.put(id, TrustOSMplugin.gpg.signWay(TrustOSMplugin.signedItems.containsKey(id) ? 388 (TrustWay) TrustOSMplugin.signedItems.get(id) : new TrustWay(osm))); 394 389 /*Way osmWay = ((Way) osm); 395 TrustWay trust = TrustOSMplugin.signedItems.containsKey(id)? (TrustWay) TrustOSMplugin.signedItems.get(id) : new TrustWay(osmWay); 390 TrustWay trust = TrustOSMplugin.signedItems.containsKey(id) ? 391 (TrustWay) TrustOSMplugin.signedItems.get(id) : new TrustWay(osmWay); 396 392 trust.storeSegmentSig(TrustOSMplugin.gpg.signWay(osmWay)); 397 393 TrustOSMplugin.signedItems.put(id, trust); … … 407 403 Way w = seg.way; 408 404 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(w); 409 TrustWay trust = TrustOSMplugin.signedItems.containsKey(id)? (TrustWay) TrustOSMplugin.signedItems.get(id) : new TrustWay(w); 410 trust.storeSegmentSig(nodes,TrustOSMplugin.gpg.signSegment(trust,nodes)); 405 TrustWay trust = TrustOSMplugin.signedItems.containsKey(id) ? 406 (TrustWay) TrustOSMplugin.signedItems.get(id) : new TrustWay(w); 407 trust.storeSegmentSig(nodes, TrustOSMplugin.gpg.signSegment(trust, nodes)); 411 408 TrustOSMplugin.signedItems.put(id, trust); 412 409 } … … 419 416 private class ShowAction extends JosmAction { 420 417 421 publicShowAction() {418 ShowAction() { 422 419 super(tr("Show"), "showsig", tr("Show all available signatures for selected attribute."), null, false); 423 420 } … … 427 424 if (osmData != null) { 428 425 for (int i : propertyTable.getSelectedRows()) { 429 String key = (String) propertyTable.getValueAt(i, 0);426 String key = (String) propertyTable.getValueAt(i, 0); 430 427 for (OsmPrimitive osm : osmData) { 431 428 String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); … … 436 433 } 437 434 } 438 if (geomTree.getSelectionPaths() !=null) {435 if (geomTree.getSelectionPaths() != null) { 439 436 for (TreePath tp : geomTree.getSelectionPaths()) { 440 437 Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject(); … … 446 443 TrustSignaturesDialog.showSignaturesDialog((TrustNode) TrustOSMplugin.signedItems.get(id)); 447 444 } 448 } else if (osm instanceof Way) { 449 //TrustOSMplugin.signedItems.put(id, TrustOSMplugin.gpg.signGeometry(TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : new TrustOSMItem(osm))); 450 } 445 } /*else if (osm instanceof Way) { 446 TrustOSMplugin.signedItems.put(id, TrustOSMplugin.gpg.signGeometry( 447 TrustOSMplugin.signedItems.containsKey(id)? TrustOSMplugin.signedItems.get(id) : new TrustOSMItem(osm))); 448 }*/ 451 449 } else if (o instanceof WaySegment) { 452 450 WaySegment seg = (WaySegment) o; … … 456 454 nodes.add(seg.getFirstNode()); 457 455 nodes.add(seg.getSecondNode()); 458 TrustSignaturesDialog.showSignaturesDialog((TrustWay) TrustOSMplugin.signedItems.get(id), nodes);456 TrustSignaturesDialog.showSignaturesDialog((TrustWay) TrustOSMplugin.signedItems.get(id), nodes); 459 457 } 460 458 } … … 468 466 TrustSignatures sigs; 469 467 if ((sigs = trust.getSigsOnKey(key)) == null) { 470 JOptionPane.showMessageDialog(null,tr("Sorry, there are no Signatures for the selected Attribute."), tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 468 JOptionPane.showMessageDialog(null, tr("Sorry, there are no Signatures for the selected Attribute."), 469 tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 471 470 } else { 472 471 JPanel p = new JPanel(); 473 472 p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); 474 Dimension d = new Dimension(0, 20);473 Dimension d = new Dimension(0, 20); 475 474 JLabel head = new JLabel(tr("Selected key value pair was:\n{0}={1}",key,trust.getOsmItem().get(key))); 476 475 head.setAlignmentX(LEFT_ALIGNMENT); … … 483 482 sigtext.setAlignmentX(LEFT_ALIGNMENT); 484 483 p.add(sigtext); 485 JLabel siginfo = new JLabel(tr("Signature created at {0} by User {1}",formatter.format(s.getCreationTime()),s.getHashedSubPackets().getSignerUserID())); 484 JLabel siginfo = new JLabel(tr("Signature created at {0} by User {1}", formatter.format(s.getCreationTime()), 485 s.getHashedSubPackets().getSignerUserID())); 486 486 siginfo.setAlignmentX(LEFT_ALIGNMENT); 487 487 p.add(siginfo); … … 491 491 JScrollPane scroller = new JScrollPane(p); 492 492 JPanel content = new JPanel(); 493 content.setMaximumSize(new Dimension(600, 500));493 content.setMaximumSize(new Dimension(600, 500)); 494 494 content.add(scroller); 495 495 JOptionPane.showMessageDialog(Main.parent,content, tr("Clearsigned Signature"), JOptionPane.PLAIN_MESSAGE); … … 500 500 List<WaySegment> segList = new ArrayList<>(); 501 501 for (int i = 0; i < w.getNodesCount()-1; i++) { 502 segList.add(new WaySegment(w, i));502 segList.add(new WaySegment(w, i)); 503 503 } 504 504 return segList; 505 505 } 506 506 507 private DefaultTreeModel createTree() {507 private DefaultTreeModel createTree() { 508 508 DefaultMutableTreeNode root = new DefaultMutableTreeNode(); 509 509 DefaultMutableTreeNode wayNode; 510 if (osmData !=null)510 if (osmData != null) 511 511 for (OsmPrimitive osm : osmData) { 512 512 //String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm); 513 if (osm instanceof Node) {513 if (osm instanceof Node) { 514 514 root.add(new DefaultMutableTreeNode(osm)); 515 } else if (osm instanceof Way) {515 } else if (osm instanceof Way) { 516 516 wayNode = new DefaultMutableTreeNode(osm); 517 List<WaySegment> presentSegments = TrustDialog.generateSegmentListFromWay(((Way) osm));518 for (WaySegment seg : presentSegments 517 List<WaySegment> presentSegments = TrustDialog.generateSegmentListFromWay(((Way) osm)); 518 for (WaySegment seg : presentSegments) { 519 519 wayNode.add(new DefaultMutableTreeNode(seg)); 520 520 } … … 542 542 */ 543 543 root.add(wayNode); 544 } else if (osm instanceof Relation) {544 } else if (osm instanceof Relation) { 545 545 546 546 } … … 575 575 for (String removedKey: removedKeys) { 576 576 TrustSignatures sigs = signedTags.get(removedKey); 577 sigs.setStatus( TrustSignatures.ITEM_REMOVED 577 sigs.setStatus( TrustSignatures.ITEM_REMOVED); 578 578 String[] kv = TrustOsmPrimitive.generateTagsFromSigtext(sigs.getOnePlainText()); 579 579 tags.put(kv[0],kv[1]); … … 585 585 } 586 586 587 // trust = TrustOSMplugin.signedItems.containsKey(osm) ? TrustOSMplugin.signedItems.get(osm) : new TrustOSMItem(osm);588 589 587 for (String key: osm.keySet()) { 590 588 String value = osm.get(key); 591 //keyCount.put(key, keyCount.containsKey(key) ? keyCount.get(key) + 1 : 1); 592 593 byte status = sigsAvailable && trust.getTagSigs().containsKey(key) ? trust.getTagSigs().get(key).getStatus() : TrustSignatures.SIG_UNKNOWN;594 Byte oldstatus = rowStatus.containsKey(key) ? rowStatus.get(key) : new Byte(TrustSignatures.SIG_VALID);589 590 byte status = sigsAvailable && trust.getTagSigs().containsKey(key) ? 591 trust.getTagSigs().get(key).getStatus() : TrustSignatures.SIG_UNKNOWN; 592 Byte oldstatus = rowStatus.containsKey(key) ? rowStatus.get(key) : new Byte(TrustSignatures.SIG_VALID); 595 593 Byte sigstatus = new Byte(status); 596 594 Byte newstatus; 597 595 if (sigstatus.equals(new Byte(TrustSignatures.SIG_BROKEN)) || oldstatus.equals(new Byte(TrustSignatures.SIG_BROKEN))) { 598 596 newstatus = new Byte(TrustSignatures.SIG_BROKEN); 599 } else if (sigstatus.equals(new Byte(TrustSignatures.SIG_UNKNOWN)) || oldstatus.equals(new Byte(TrustSignatures.SIG_UNKNOWN))) { 597 } else if (sigstatus.equals(new Byte(TrustSignatures.SIG_UNKNOWN)) 598 || oldstatus.equals(new Byte(TrustSignatures.SIG_UNKNOWN))) { 600 599 newstatus = new Byte(TrustSignatures.SIG_UNKNOWN); 601 600 } else newstatus = new Byte(TrustSignatures.SIG_VALID); 602 601 603 rowStatus.put(key, newstatus 602 rowStatus.put(key, newstatus); 604 603 if (valueCount.containsKey(key)) { 605 604 Map<String, Integer> v = valueCount.get(key); 606 v.put(value, v.containsKey(value) ? v.get(value) + 1 : 1);605 v.put(value, v.containsKey(value) ? v.get(value) + 1 : 1); 607 606 } else { 608 TreeMap<String, Integer> v = new TreeMap<>();607 TreeMap<String, Integer> v = new TreeMap<>(); 609 608 v.put(value, 1); 610 609 valueCount.put(key, v); … … 613 612 } 614 613 for (Entry<String, Map<String, Integer>> e : valueCount.entrySet()) { 615 int count =0;614 int count = 0; 616 615 for (Entry<String, Integer> e1: e.getValue().entrySet()) { 617 count +=e1.getValue();616 count += e1.getValue(); 618 617 } 619 618 if (count < osmData.size()) { … … 639 638 geomTree.setModel(createTree()); 640 639 updateTable(); 641 // signButton.setEnabled(newSelection.size() == 1);642 640 } 643 641 … … 657 655 for (WaySegment seg : selectedSegments) { 658 656 GeneralPath b = new GeneralPath(); 659 Point p1=mv.getPoint(seg.getFirstNode()); 660 Point p2=mv.getPoint(seg.getSecondNode()); 661 662 b.moveTo(p1.x,p1.y); b.lineTo(p2.x, p2.y); 657 Point p1 = mv.getPoint(seg.getFirstNode()); 658 Point p2 = mv.getPoint(seg.getSecondNode()); 659 660 b.moveTo(p1.x, p1.y); 661 b.lineTo(p2.x, p2.y); 663 662 664 663 g2.draw(b); -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/dialogs/TrustPreferenceEditor.java
r30742 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.gui.dialogs; 2 3 … … 23 24 public class TrustPreferenceEditor extends DefaultTabPreferenceSetting { 24 25 25 private final JCheckBox showSignedDeleted = new JCheckBox(tr("Show deleted tags and notes if they were signed before")); 26 private final JRadioButton defaultHomedir = new JRadioButton(tr("Use default (and maybe existing) GnuPG directory ({0}) to store new keys and configs.", "~/.gnupg")); 27 private final JRadioButton separateHomedir = new JRadioButton(tr("Use separate GnuPG directory ({0}) to store new keys and configs.", TrustOSMplugin.getGpgPath())); 26 private final JCheckBox showSignedDeleted = new JCheckBox( 27 tr("Show deleted tags and notes if they were signed before")); 28 private final JRadioButton defaultHomedir = new JRadioButton( 29 tr("Use default (and maybe existing) GnuPG directory ({0}) to store new keys and configs.", "~/.gnupg")); 30 private final JRadioButton separateHomedir = new JRadioButton( 31 tr("Use separate GnuPG directory ({0}) to store new keys and configs.", TrustOSMplugin.getGpgPath())); 28 32 29 33 public TrustPreferenceEditor() { … … 39 43 JPanel gpgsettings = new JPanel(new GridBagLayout()); 40 44 41 gpgsettings.setBorder(BorderFactory.createEmptyBorder(5, 5,5,5));45 gpgsettings.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 42 46 43 gpgsettings.add(new JLabel(tr("Use separate GnuPG configuration directory?")), GBC.eol().insets(20, 0,0,0));47 gpgsettings.add(new JLabel(tr("Use separate GnuPG configuration directory?")), GBC.eol().insets(20, 0, 0, 0)); 44 48 ButtonGroup gpgdirGroup = new ButtonGroup(); 45 49 gpgdirGroup.add(separateHomedir); … … 51 55 defaultHomedir.setSelected(true); 52 56 53 gpgsettings.add(separateHomedir, GBC.eol().insets(40, 0,0,0));54 gpgsettings.add(defaultHomedir, GBC.eol().insets(40, 0,0,0));57 gpgsettings.add(separateHomedir, GBC.eol().insets(40, 0, 0, 0)); 58 gpgsettings.add(defaultHomedir, GBC.eol().insets(40, 0, 0, 0)); 55 59 56 60 gpgsettings.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH)); 57 61 JScrollPane scrollpane = new JScrollPane(gpgsettings); 58 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0));62 scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0)); 59 63 tabs.add(tr("GnuPG"), scrollpane); 60 64 61 65 JPanel dialogsettings = new JPanel(new GridBagLayout()); 62 66 tabs.add(tr("Dialog"), dialogsettings); 63 dialogsettings.add(showSignedDeleted, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0,0,5));67 dialogsettings.add(showSignedDeleted, GBC.eol().fill(GBC.HORIZONTAL).insets(20, 0, 0, 5)); 64 68 } 65 69 -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/dialogs/TrustSignaturesDialog.java
r30744 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.gui.dialogs; 2 3 … … 35 36 import org.openstreetmap.josm.tools.ImageProvider; 36 37 37 38 39 public class TrustSignaturesDialog { 40 38 public final class TrustSignaturesDialog { 39 40 private TrustSignaturesDialog() { 41 // Hide default constructors for utilities classes 42 } 41 43 42 44 private static String createLabel(String plain, int type) { 43 45 if (type == 0) { 44 46 String[] kv = TrustOsmPrimitive.generateTagsFromSigtext(plain); 45 return tr("Signed key value pair was: {0}={1}", kv[0], kv[1]);47 return tr("Signed key value pair was: {0}={1}", kv[0], kv[1]); 46 48 } else if (type == 1) { 47 49 Node node = TrustNode.generateNodeFromSigtext(plain); 48 //return tr("Signed node was: {0}", node.getDisplayName(DefaultNameFormatter.getInstance()));49 50 return "ID:"+node.getUniqueId()+" ("+node.getCoor().toString() + ")"; 50 51 } else if (type == 2) { … … 57 58 private static void showDialog(TrustSignatures sigs, String label, int type) { 58 59 JPanel p = new JPanel(new GridBagLayout()); 59 p.add(new JLabel(label),GBC.eol()); 60 61 //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd:hh.mm.ss"); 60 p.add(new JLabel(label), GBC.eol()); 62 61 63 62 for (String plain : sigs.getAllPlainTexts()) { … … 67 66 textcontent.add(sigtext); 68 67 69 p.add(new JCollapsiblePanel(createLabel(plain, type), textcontent),GBC.eol());68 p.add(new JCollapsiblePanel(createLabel(plain, type), textcontent), GBC.eol()); 70 69 71 70 List<PGPSignature> siglist = sigs.getSignaturesByPlaintext(plain); 72 71 JPanel signerPanel = new JPanel(new GridBagLayout()); 73 //signerPanel.add(createSignerTree(siglist));74 72 KeyTreeTableModel km = new KeyTreeTableModel(siglist); 75 final JXTreeTable t = new JXTreeTable( km ); 76 //t.setHorizontalScrollEnabled(true); 77 //t.setRootVisible(false); 73 final JXTreeTable t = new JXTreeTable(km); 78 74 t.addMouseListener(new MouseAdapter() { 79 75 @Override … … 83 79 if (selPath == null) 84 80 return; 85 SignatureTreeNode sn = (SignatureTreeNode) selPath.getLastPathComponent();81 SignatureTreeNode sn = (SignatureTreeNode) selPath.getLastPathComponent(); 86 82 PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(sn.getSignature().getKeyID()); 87 83 TrustGPG.showKeyDetails(pub); … … 97 93 signerPanel.add(new JScrollPane(t)); 98 94 99 100 // JTreeTable tt = new JTreeTable(); 101 102 /* for (PGPSignature s : siglist) { 103 signerPanel.add(createKeyButton(tr("Signature created at {0} by User {1}",formatter.format(s.getCreationTime()),s.getHashedSubPackets().getSignerUserID()),s.getKeyID()),GBC.eol()); 104 //signerPanel.add(new JLabel(tr("Signature created at {0} by User {1}",formatter.format(s.getCreationTime()),s.getHashedSubPackets().getSignerUserID())),GBC.eol()); 105 }*/ 106 107 p.add(new JCollapsiblePanel(tr("{0} Signatures found.", siglist.size()),signerPanel),GBC.eol().insets(20,0,0,0)); 95 p.add(new JCollapsiblePanel(tr("{0} Signatures found.", siglist.size()), signerPanel), GBC.eol().insets(20, 0, 0, 0)); 108 96 } 109 97 p.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH)); 110 98 JScrollPane scroller = new JScrollPane(p); 111 //JPanel content = new JPanel(); 112 scroller.setPreferredSize(new Dimension(700,500)); 113 //content.add(scroller); 114 //JOptionPane.showMessageDialog(Main.parent,scroller, tr("Clearsigned Signature"), JOptionPane.PLAIN_MESSAGE); 99 scroller.setPreferredSize(new Dimension(700, 500)); 115 100 String[] buttons = {tr("Ok")}; 116 ExtendedDialog info = new ExtendedDialog(Main.parent, tr("Signature Info"), buttons,false);117 info.setContent(scroller, false);101 ExtendedDialog info = new ExtendedDialog(Main.parent, tr("Signature Info"), buttons, false); 102 info.setContent(scroller, false); 118 103 info.showDialog(); 119 104 } 120 121 105 122 106 public static void showSignaturesDialog(TrustNode trust) { 123 107 TrustSignatures sigs; 124 108 if ((sigs = trust.getNodeSigs()) == null) { 125 JOptionPane.showMessageDialog(null,tr("Sorry, there are no Signatures for the selected Node."), tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 109 JOptionPane.showMessageDialog(null, tr("Sorry, there are no Signatures for the selected Node."), 110 tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 126 111 } else { 127 String nodename = ((Node) trust.getOsmPrimitive()).getDisplayName(DefaultNameFormatter.getInstance());128 showDialog(sigs, tr("Selected node was:\n{0}", nodename),1);112 String nodename = ((Node) trust.getOsmPrimitive()).getDisplayName(DefaultNameFormatter.getInstance()); 113 showDialog(sigs, tr("Selected node was:\n{0}", nodename), 1); 129 114 } 130 115 } … … 133 118 TrustSignatures sigs; 134 119 if ((sigs = trust.getSigsOnKey(key)) == null) { 135 JOptionPane.showMessageDialog(null,tr("Sorry, there are no Signatures for the selected Attribute."), tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 120 JOptionPane.showMessageDialog(null, tr("Sorry, there are no Signatures for the selected Attribute."), 121 tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 136 122 } else { 137 showDialog(sigs, tr("Selected key value pair was:\n{0}={1}", key,trust.getOsmPrimitive().get(key)), 0);123 showDialog(sigs, tr("Selected key value pair was:\n{0}={1}", key, trust.getOsmPrimitive().get(key)), 0); 138 124 } 139 125 } … … 142 128 TrustSignatures sigs; 143 129 if ((sigs = trust.getSigsOnSegment(nodes)) == null) { 144 JOptionPane.showMessageDialog(null,tr("Sorry, there are no Signatures for the selected Segment."), tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 130 JOptionPane.showMessageDialog(null, tr("Sorry, there are no Signatures for the selected Segment."), 131 tr("No Signature found"), JOptionPane.WARNING_MESSAGE); 145 132 } else { 146 133 showDialog(sigs, tr("Selected WaySegment was:"), 2); … … 187 174 188 175 PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(s.getKeyID()); 189 if (pub != null) {176 if (pub != null) { 190 177 Iterator i = pub.getUserIDs(); 191 178 if (i.hasNext()) … … 197 184 public static JTree createSignerTree(Collection<PGPSignature> sigs) { 198 185 DefaultMutableTreeNode root = new DefaultMutableTreeNode(); 199 for (PGPSignature s : sigs) {186 for (PGPSignature s : sigs) { 200 187 DefaultMutableTreeNode sn = new DefaultMutableTreeNode(s); 201 188 PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(s.getKeyID()); 202 189 Iterator iter = pub.getSignatures(); 203 while (iter.hasNext()) {190 while (iter.hasNext()) { 204 191 PGPSignature ks = (PGPSignature)iter.next(); 205 192 sn.add(new DefaultMutableTreeNode(ks)); … … 212 199 t.setRootVisible(false); 213 200 t.setBackground(TrustDialog.BGCOLOR_NO_SIG); 214 t.setCellRenderer(new DefaultTreeCellRenderer() {201 t.setCellRenderer(new DefaultTreeCellRenderer() { 215 202 216 203 @Override … … 229 216 setBackgroundNonSelectionColor(TrustDialog.BGCOLOR_NO_SIG); 230 217 if (sv.hasSubpacket(SignatureSubpacketTags.NOTATION_DATA)) { 231 for (NotationData nd : sv.getNotationDataOccurences()) {218 for (NotationData nd : sv.getNotationDataOccurences()) { 232 219 System.out.println(nd.getNotationName()+"="+nd.getNotationValue()); 233 220 if (nd.getNotationName().equals("trustosm@openstreetmap.org")) { -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigExporter.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.io; 2 3 -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigImporter.java
r32511 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.io; 2 3 … … 49 50 } 50 51 // Set<OsmPrimitive> missingData = new HashSet<OsmPrimitive>(); 51 Map<String, TrustOsmPrimitive> trustitems = SigReader.parseSignatureXML(in, NullProgressMonitor.INSTANCE);52 Map<String, TrustOsmPrimitive> trustitems = SigReader.parseSignatureXML(in, NullProgressMonitor.INSTANCE); 52 53 System.out.println(trustitems.size()); 53 54 /* … … 57 58 JOptionPane.showMessageDialog(Main.parent, tr("{0} Signatures loaded. All referenced OSM objects found.",itemCount)); 58 59 } else { 59 int n = JOptionPane.showOptionDialog(Main.parent, tr("{0} of {1} OSM objects are referenced but not there.\nDo you want to load them from OSM-Server?",missingCount,itemCount), tr("Load objects from server"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 60 int n = JOptionPane.showOptionDialog(Main.parent, 61 tr("{0} of {1} OSM objects are referenced but not there.\nDo you want to load them from OSM-Server?",missingCount,itemCount), 62 tr("Load objects from server"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 60 63 61 64 if (n == JOptionPane.YES_OPTION) { … … 67 70 new GetMissingDataAction().downloadMissing(); 68 71 //TrustOSMplugin.signedItems.putAll(TrustStoreHandler.loadSigsFromFile(in)); 69 70 72 } 71 73 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigReader.java
r32511 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.io; 2 3 … … 47 48 public class SigReader { 48 49 49 private final Map<String, TrustOsmPrimitive> trustitems = new HashMap<>();50 private final Map<String, TrustOsmPrimitive> trustitems = new HashMap<>(); 50 51 private final Set<OsmPrimitive> missingData = new HashSet<>(); 51 52 52 public Map<String, TrustOsmPrimitive> getTrustItems() {53 public Map<String, TrustOsmPrimitive> getTrustItems() { 53 54 return trustitems; 54 55 } … … 75 76 private TrustOsmPrimitive trust; 76 77 77 78 78 /** 79 79 * The current Signatures. … … 81 81 private TrustSignatures tsigs; 82 82 83 84 83 private StringBuffer tmpbuf = new StringBuffer(); 85 86 84 87 85 @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { … … 94 92 95 93 String osmid = atts.getValue("osmid"); 96 if (osmid == null) {94 if (osmid == null) { 97 95 throwException(tr("Missing mandatory attribute ''{0}''.", "osmid")); 98 96 } else if (!osmid.matches("\\d+")) { … … 131 129 trustitems.put(TrustOsmPrimitive.createUniqueObjectIdentifier(trust.getOsmPrimitive()), trust); 132 130 } else if (qName.equals("openpgp")) { 133 // System.out.println(tmpbuf.toString());134 131 try { 135 132 parseOpenPGP(tmpbuf.toString()); 136 133 } catch (IOException e) { 137 throw new XmlParsingException(tr("Could not parse OpenPGP message."), e).rememberLocation(locator);134 throw new XmlParsingException(tr("Could not parse OpenPGP message."), e).rememberLocation(locator); 138 135 } 139 136 } else if (qName.equals("key")) { … … 141 138 trust.setTagRatings(kv[0], tsigs); 142 139 } else if (qName.equals("node")) { 143 ((TrustNode) trust).setNodeRatings(tsigs);140 ((TrustNode) trust).setNodeRatings(tsigs); 144 141 } else if (qName.equals("segment")) { 145 142 List<Node> nodes = TrustWay.generateSegmentFromSigtext(tsigs.getOnePlainText()); 146 ((TrustWay) trust).setSegmentRatings(nodes,tsigs);143 ((TrustWay) trust).setSegmentRatings(nodes, tsigs); 147 144 } else if (qName.equals("member")) { 148 145 RelationMember member = TrustRelation.generateRelationMemberFromSigtext(tsigs.getOnePlainText()); 149 ((TrustRelation) trust).setMemberRating(TrustOsmPrimitive.createUniqueObjectIdentifier(member.getMember()), tsigs);146 ((TrustRelation) trust).setMemberRating(TrustOsmPrimitive.createUniqueObjectIdentifier(member.getMember()), tsigs); 150 147 } 151 148 } … … 178 175 plain = plain.substring(0, plain.length()-1); 179 176 180 PGPSignatureList siglist = (PGPSignatureList) pgpFact.nextObject();181 for (int i =0; i<siglist.size();i++) {177 PGPSignatureList siglist = (PGPSignatureList) pgpFact.nextObject(); 178 for (int i = 0; i < siglist.size(); i++) { 182 179 tsigs.addSignature(siglist.get(i), plain); 183 180 } 184 185 186 } 187 188 181 } 189 182 } 190 183 … … 199 192 * @throws IllegalArgumentException thrown if source is null 200 193 */ 201 public static Map<String,TrustOsmPrimitive> parseSignatureXML(InputStream source, ProgressMonitor progressMonitor) throws IllegalDataException { 194 public static Map<String, TrustOsmPrimitive> parseSignatureXML(InputStream source, ProgressMonitor progressMonitor) 195 throws IllegalDataException { 202 196 if (progressMonitor == null) { 203 197 progressMonitor = NullProgressMonitor.INSTANCE; … … 216 210 217 211 return reader.getTrustItems(); 218 } catch (ParserConfigurationException e) {212 } catch (ParserConfigurationException e) { 219 213 throw new IllegalDataException(e.getMessage(), e); 220 214 } catch (SAXParseException e) { 221 215 throw new IllegalDataException(tr("Line {0} column {1}: ", e.getLineNumber(), e.getColumnNumber()) + e.getMessage(), e); 222 } catch (SAXException e) {216 } catch (SAXException e) { 223 217 throw new IllegalDataException(e.getMessage(), e); 224 } catch (Exception e) {218 } catch (Exception e) { 225 219 throw new IllegalDataException(e); 226 220 } finally { … … 228 222 } 229 223 } 230 231 232 224 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigWriter.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.io; 2 3 … … 75 76 private void writeSigs(TrustSignatures tsigs) { 76 77 for (String plain : tsigs.getAllPlainTexts()) { 77 simpleTag("openpgp",tsigs.getArmoredFulltextSignatureAll(plain)); 78 } 79 78 simpleTag("openpgp", tsigs.getArmoredFulltextSignatureAll(plain)); 79 } 80 80 } 81 81 … … 86 86 openln("tags"); 87 87 for (String key : signedKeys) { 88 openAtt("key","k=\""+key+"\""); 89 88 openAtt("key", "k=\""+key+"\""); 90 89 writeSigs(tagsigs.get(key)); 91 92 90 closeln("key"); 93 91 } … … 131 129 private void writeItems(Collection<TrustOsmPrimitive> items) { 132 130 133 for (TrustOsmPrimitive trust : items) {131 for (TrustOsmPrimitive trust : items) { 134 132 OsmPrimitive osm = trust.getOsmPrimitive(); 135 133 if (trust instanceof TrustNode) { -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/NameGenerator.java
r30742 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.util; 2 3 … … 53 54 ArrayList<String> sur = new ArrayList<>(); 54 55 55 final private static char[] vocals = {'a', 'e', 'i', 'o', 'u', 'ä', 'ö', 'õ', 'ü', 'y'}; 56 final private static char[] consonants = {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y'}; 56 private static final char[] vocals = 57 {'a', 'e', 'i', 'o', 'u', 'ä', 'ö', 'õ', 'ü', 'y'}; 58 private static final char[] consonants = 59 {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y'}; 57 60 58 61 private String fileName; … … 61 64 * Create new random name generator object. refresh() is automatically called. 62 65 * @param fileName insert file name, where syllables are located 63 * @throws IOException 64 */ 65 public NameGenerator(String fileName) throws IOException{ 66 */ 67 public NameGenerator(String fileName) throws IOException { 66 68 this.fileName = fileName; 67 69 refresh(); … … 71 73 * Change the file. refresh() is automatically called during the process. 72 74 * @param fileName insert the file name, where syllables are located. 73 * @throws IOException 74 */ 75 public void changeFile(String fileName) throws IOException{ 76 if(fileName == null) throw new IOException("File name cannot be null"); 75 */ 76 public void changeFile(String fileName) throws IOException { 77 if (fileName == null) throw new IOException("File name cannot be null"); 77 78 this.fileName = fileName; 78 79 refresh(); … … 82 83 * Refresh names from file. No need to call that method, if you are not changing the file during the operation of program, as this method 83 84 * is called every time file name is changed or new NameGenerator object created. 84 * @throws IOException 85 */ 86 public void refresh() throws IOException{ 87 try ( 88 FileReader input = new FileReader(fileName); 89 BufferedReader bufRead = new BufferedReader(input); 90 ) { 91 String line=""; 92 while (line != null){ 85 */ 86 public void refresh() throws IOException { 87 try (FileReader input = new FileReader(fileName); 88 BufferedReader bufRead = new BufferedReader(input); 89 ) { 90 String line = ""; 91 while (line != null) { 93 92 line = bufRead.readLine(); 94 93 if (line != null && !line.equals("")) { 95 if (line.charAt(0) == '-') {94 if (line.charAt(0) == '-') { 96 95 pre.add(line.substring(1).toLowerCase()); 97 96 } else if (line.charAt(0) == '+') { … … 106 105 107 106 private String upper(String s) { 108 return s.substring(0, 1).toUpperCase().concat(s.substring(1));107 return s.substring(0, 1).toUpperCase().concat(s.substring(1)); 109 108 } 110 109 111 110 private boolean containsConsFirst(ArrayList<String> array) { 112 for(String s: array){ 113 if(consonantFirst(s)) return true; 114 } 115 return false; 116 } 117 118 private boolean containsVocFirst(ArrayList<String> array){ 119 for(String s: array){ 120 if(vocalFirst(s)) return true; 121 } 122 return false; 123 } 124 125 private boolean allowCons(ArrayList<String> array){ 126 for(String s: array){ 127 if(hatesPreviousVocals(s) || hatesPreviousConsonants(s) == false) return true; 128 } 129 return false; 130 } 131 132 private boolean allowVocs(ArrayList<String> array){ 133 for(String s: array){ 134 if(hatesPreviousConsonants(s) || hatesPreviousVocals(s) == false) return true; 135 } 136 return false; 137 } 138 139 private boolean expectsVocal(String s){ 140 if(s.substring(1).contains("+v")) return true; 141 else return false; 142 } 143 private boolean expectsConsonant(String s){ 144 if(s.substring(1).contains("+c")) return true; 145 else return false; 146 } 147 private boolean hatesPreviousVocals(String s){ 148 if(s.substring(1).contains("-c")) return true; 149 else return false; 150 } 151 private boolean hatesPreviousConsonants(String s){ 152 if(s.substring(1).contains("-v")) return true; 153 else return false; 154 } 155 156 private String pureSyl(String s){ 111 for (String s: array) { 112 if (consonantFirst(s)) return true; 113 } 114 return false; 115 } 116 117 private boolean containsVocFirst(ArrayList<String> array) { 118 for (String s: array) { 119 if (vocalFirst(s)) return true; 120 } 121 return false; 122 } 123 124 private boolean allowCons(ArrayList<String> array) { 125 for (String s: array) { 126 if (hatesPreviousVocals(s) || hatesPreviousConsonants(s) == false) return true; 127 } 128 return false; 129 } 130 131 private boolean allowVocs(ArrayList<String> array) { 132 for (String s: array) { 133 if (hatesPreviousConsonants(s) || hatesPreviousVocals(s) == false) return true; 134 } 135 return false; 136 } 137 138 private boolean expectsVocal(String s) { 139 if (s.substring(1).contains("+v")) return true; 140 else return false; 141 } 142 143 private boolean expectsConsonant(String s) { 144 if (s.substring(1).contains("+c")) return true; 145 else return false; 146 } 147 148 private boolean hatesPreviousVocals(String s) { 149 if (s.substring(1).contains("-c")) return true; 150 else return false; 151 } 152 153 private boolean hatesPreviousConsonants(String s) { 154 if (s.substring(1).contains("-v")) return true; 155 else return false; 156 } 157 158 private String pureSyl(String s) { 157 159 s = s.trim(); 158 if (s.charAt(0) == '+' || s.charAt(0) == '-') s = s.substring(1);160 if (s.charAt(0) == '+' || s.charAt(0) == '-') s = s.substring(1); 159 161 return s.split(" ")[0]; 160 162 } 161 163 162 private boolean vocalFirst(String s) {164 private boolean vocalFirst(String s) { 163 165 return (String.copyValueOf(vocals).contains(String.valueOf(s.charAt(0)).toLowerCase())); 164 166 } 165 167 166 private boolean consonantFirst(String s) {168 private boolean consonantFirst(String s) { 167 169 return (String.copyValueOf(consonants).contains(String.valueOf(s.charAt(0)).toLowerCase())); 168 170 } 169 171 170 private boolean vocalLast(String s) {172 private boolean vocalLast(String s) { 171 173 return (String.copyValueOf(vocals).contains(String.valueOf(s.charAt(s.length()-1)).toLowerCase())); 172 174 } 173 175 174 private boolean consonantLast(String s) {176 private boolean consonantLast(String s) { 175 177 return (String.copyValueOf(consonants).contains(String.valueOf(s.charAt(s.length()-1)).toLowerCase())); 176 178 } 177 179 180 // CHECKSTYLE.OFF: LineLength 178 181 179 182 /** … … 183 186 * @throws RuntimeException when logical mistakes are detected inside chosen file, and program is unable to complete the name. 184 187 */ 185 public String compose(int syls){ 186 if(syls > 2 && mid.size() == 0) throw new RuntimeException("You are trying to create a name with more than 3 parts, which requires middle parts, " + 187 "which you have none in the file "+fileName+". You should add some. Every word, which doesn't have + or - for a prefix is counted as a middle part."); 188 if(pre.size() == 0) throw new RuntimeException("You have no prefixes to start creating a name. add some and use \"-\" prefix, to identify it as a prefix for a name. (example: -asd)"); 189 if(sur.size() == 0) throw new RuntimeException("You have no suffixes to end a name. add some and use \"+\" prefix, to identify it as a suffix for a name. (example: +asd)"); 190 if(syls < 1) throw new RuntimeException("compose(int syls) can't have less than 1 syllable"); 188 public String compose(int syls) { 189 if (syls > 2 && mid.size() == 0) 190 throw new RuntimeException("You are trying to create a name with more than 3 parts, which requires middle parts, " + 191 "which you have none in the file "+fileName+ 192 ". You should add some. Every word, which doesn't have + or - for a prefix is counted as a middle part."); 193 if (pre.size() == 0) 194 throw new RuntimeException( 195 "You have no prefixes to start creating a name. add some and use \"-\" prefix, to identify it as a prefix for a name. (example: -asd)"); 196 if (sur.size() == 0) 197 throw new RuntimeException( 198 "You have no suffixes to end a name. add some and use \"+\" prefix, to identify it as a suffix for a name. (example: +asd)"); 199 if (syls < 1) throw new RuntimeException("compose(int syls) can't have less than 1 syllable"); 191 200 int expecting = 0; // 1 for vocal, 2 for consonant 192 201 int last = 0; // 1 for vocal, 2 for consonant 193 202 String name; 194 int a = (int) (Math.random() * pre.size());195 196 if (vocalLast(pureSyl(pre.get(a)))) last = 1;203 int a = (int) (Math.random() * pre.size()); 204 205 if (vocalLast(pureSyl(pre.get(a)))) last = 1; 197 206 else last = 2; 198 207 199 if (syls > 2){200 if (expectsVocal(pre.get(a))){208 if (syls > 2) { 209 if (expectsVocal(pre.get(a))) { 201 210 expecting = 1; 202 if (containsVocFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with vocal, " +203 "but there is none. You should add one, or remove requirement for one.. ");204 } 205 if (expectsConsonant(pre.get(a))){211 if (containsVocFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with vocal, " + 212 "but there is none. You should add one, or remove requirement for one.. "); 213 } 214 if (expectsConsonant(pre.get(a))) { 206 215 expecting = 2; 207 if(containsConsFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with consonant, " + 208 "but there is none. You should add one, or remove requirement for one.. "); 209 } 210 } 211 else{ 212 if(expectsVocal(pre.get(a))){ 216 if (containsConsFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with consonant, " + 217 "but there is none. You should add one, or remove requirement for one.. "); 218 } 219 } else { 220 if (expectsVocal(pre.get(a))) { 213 221 expecting = 1; 214 if (containsVocFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with vocal, " +215 "but there is none. You should add one, or remove requirement for one.. ");216 } 217 if (expectsConsonant(pre.get(a))){222 if (containsVocFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with vocal, " + 223 "but there is none. You should add one, or remove requirement for one.. "); 224 } 225 if (expectsConsonant(pre.get(a))) { 218 226 expecting = 2; 219 if (containsConsFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with consonant, " +220 "but there is none. You should add one, or remove requirement for one.. ");221 } 222 } 223 if (vocalLast(pureSyl(pre.get(a))) && allowVocs(mid) == false) throw new RuntimeException("Expecting \"middle\" part that allows last character of prefix to be a vocal, " +227 if (containsConsFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with consonant, " + 228 "but there is none. You should add one, or remove requirement for one.. "); 229 } 230 } 231 if (vocalLast(pureSyl(pre.get(a))) && allowVocs(mid) == false) throw new RuntimeException("Expecting \"middle\" part that allows last character of prefix to be a vocal, " + 224 232 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the prefix used, was : \""+pre.get(a)+"\", which" + 225 "means there should be a part available, that has \"-v\" requirement or no requirements for previous syllables at all.");226 227 if (consonantLast(pureSyl(pre.get(a))) && allowCons(mid) == false) throw new RuntimeException("Expecting \"middle\" part that allows last character of prefix to be a consonant, " +233 "means there should be a part available, that has \"-v\" requirement or no requirements for previous syllables at all."); 234 235 if (consonantLast(pureSyl(pre.get(a))) && allowCons(mid) == false) throw new RuntimeException("Expecting \"middle\" part that allows last character of prefix to be a consonant, " + 228 236 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the prefix used, was : \""+pre.get(a)+"\", which" + 229 "means there should be a part available, that has \"-c\" requirement or no requirements for previous syllables at all."); 230 231 int b[] = new int[syls]; 232 for(int i = 0; i<b.length-2; i++){ 233 234 do{ 235 b[i] = (int)(Math.random() * mid.size()); 236 //System.out.println("exp " +expecting+" vocalF:"+vocalFirst(mid.get(b[i]))+" syl: "+mid.get(b[i])); 237 } 238 while(expecting == 1 && vocalFirst(pureSyl(mid.get(b[i]))) == false || expecting == 2 && consonantFirst(pureSyl(mid.get(b[i]))) == false 237 "means there should be a part available, that has \"-c\" requirement or no requirements for previous syllables at all."); 238 239 int[] b = new int[syls]; 240 for (int i = 0; i < b.length-2; i++) { 241 242 do { 243 b[i] = (int) (Math.random() * mid.size()); 244 } while (expecting == 1 && vocalFirst(pureSyl(mid.get(b[i]))) == false || expecting == 2 && consonantFirst(pureSyl(mid.get(b[i]))) == false 239 245 || last == 1 && hatesPreviousVocals(mid.get(b[i])) || last == 2 && hatesPreviousConsonants(mid.get(b[i]))); 240 246 241 247 expecting = 0; 242 if (expectsVocal(mid.get(b[i]))){248 if (expectsVocal(mid.get(b[i]))) { 243 249 expecting = 1; 244 if (i < b.length-3 && containsVocFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with vocal, " +245 "but there is none. You should add one, or remove requirement for one.. ");246 if (i == b.length-3 && containsVocFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with vocal, " +247 "but there is none. You should add one, or remove requirement for one.. ");248 } 249 if (expectsConsonant(mid.get(b[i]))){250 if (i < b.length-3 && containsVocFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with vocal, " + 251 "but there is none. You should add one, or remove requirement for one.. "); 252 if (i == b.length-3 && containsVocFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with vocal, " + 253 "but there is none. You should add one, or remove requirement for one.. "); 254 } 255 if (expectsConsonant(mid.get(b[i]))) { 250 256 expecting = 2; 251 if (i < b.length-3 && containsConsFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with consonant, " +252 "but there is none. You should add one, or remove requirement for one.. ");253 if (i == b.length-3 && containsConsFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with consonant, " +254 "but there is none. You should add one, or remove requirement for one.. ");255 } 256 if (vocalLast(pureSyl(mid.get(b[i]))) && allowVocs(mid) == false && syls > 3) throw new RuntimeException("Expecting \"middle\" part that allows last character of last syllable to be a vocal, " +257 if (i < b.length-3 && containsConsFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with consonant, " + 258 "but there is none. You should add one, or remove requirement for one.. "); 259 if (i == b.length-3 && containsConsFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with consonant, " + 260 "but there is none. You should add one, or remove requirement for one.. "); 261 } 262 if (vocalLast(pureSyl(mid.get(b[i]))) && allowVocs(mid) == false && syls > 3) throw new RuntimeException("Expecting \"middle\" part that allows last character of last syllable to be a vocal, " + 257 263 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the part used, was : \""+mid.get(b[i])+"\", which " + 258 "means there should be a part available, that has \"-v\" requirement or no requirements for previous syllables at all.");259 260 if (consonantLast(pureSyl(mid.get(b[i]))) && allowCons(mid) == false && syls > 3) throw new RuntimeException("Expecting \"middle\" part that allows last character of last syllable to be a consonant, " +264 "means there should be a part available, that has \"-v\" requirement or no requirements for previous syllables at all."); 265 266 if (consonantLast(pureSyl(mid.get(b[i]))) && allowCons(mid) == false && syls > 3) throw new RuntimeException("Expecting \"middle\" part that allows last character of last syllable to be a consonant, " + 261 267 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the part used, was : \""+mid.get(b[i])+"\", which " + 262 "means there should be a part available, that has \"-c\" requirement or no requirements for previous syllables at all.");263 if (i == b.length-3){264 if (vocalLast(pureSyl(mid.get(b[i]))) && allowVocs(sur) == false) throw new RuntimeException("Expecting \"suffix\" part that allows last character of last syllable to be a vocal, " +268 "means there should be a part available, that has \"-c\" requirement or no requirements for previous syllables at all."); 269 if (i == b.length-3) { 270 if (vocalLast(pureSyl(mid.get(b[i]))) && allowVocs(sur) == false) throw new RuntimeException("Expecting \"suffix\" part that allows last character of last syllable to be a vocal, " + 265 271 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the part used, was : \""+mid.get(b[i])+"\", which " + 266 "means there should be a suffix available, that has \"-v\" requirement or no requirements for previous syllables at all.");267 268 if (consonantLast(pureSyl(mid.get(b[i]))) && allowCons(sur) == false) throw new RuntimeException("Expecting \"suffix\" part that allows last character of last syllable to be a consonant, " +272 "means there should be a suffix available, that has \"-v\" requirement or no requirements for previous syllables at all."); 273 274 if (consonantLast(pureSyl(mid.get(b[i]))) && allowCons(sur) == false) throw new RuntimeException("Expecting \"suffix\" part that allows last character of last syllable to be a consonant, " + 269 275 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the part used, was : \""+mid.get(b[i])+"\", which " + 270 "means there should be a suffix available, that has \"-c\" requirement or no requirements for previous syllables at all.");271 } 272 if (vocalLast(pureSyl(mid.get(b[i])))) last = 1;276 "means there should be a suffix available, that has \"-c\" requirement or no requirements for previous syllables at all."); 277 } 278 if (vocalLast(pureSyl(mid.get(b[i])))) last = 1; 273 279 else last = 2; 274 280 } 275 281 276 282 int c; 277 do{ 278 c = (int)(Math.random() * sur.size()); 279 } 280 while(expecting == 1 && vocalFirst(pureSyl(sur.get(c))) == false || expecting == 2 && consonantFirst(pureSyl(sur.get(c))) == false 283 do { 284 c = (int) (Math.random() * sur.size()); 285 } while (expecting == 1 && vocalFirst(pureSyl(sur.get(c))) == false || expecting == 2 && consonantFirst(pureSyl(sur.get(c))) == false 281 286 || last == 1 && hatesPreviousVocals(sur.get(c)) || last == 2 && hatesPreviousConsonants(sur.get(c))); 282 287 283 288 name = upper(pureSyl(pre.get(a).toLowerCase())); 284 for (int i = 0; i<b.length-2; i++){289 for (int i = 0; i < b.length-2; i++) { 285 290 name = name.concat(pureSyl(mid.get(b[i]).toLowerCase())); 286 291 } 287 if (syls > 1)292 if (syls > 1) 288 293 name = name.concat(pureSyl(sur.get(c).toLowerCase())); 289 294 return name; 290 295 } 296 // CHECKSTYLE.ON: LineLength 291 297 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/SpringUtilities.java
r26055 r32533 28 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 30 */ 32 31 package org.openstreetmap.josm.plugins.trustosm.util; 33 32 34 import javax.swing.*; 33 import java.awt.Component; 34 import java.awt.Container; 35 36 import javax.swing.Spring; 35 37 import javax.swing.SpringLayout; 36 import java.awt.*;37 38 38 39 /** … … 42 43 * SpringBox and SpringCompactGrid. 43 44 */ 44 public class SpringUtilities { 45 public final class SpringUtilities { 46 47 private SpringUtilities() { 48 // Hide default constructors for utilities classes 49 } 50 45 51 /** 46 52 * A debugging utility that prints to stdout the component's … … 73 79 SpringLayout layout; 74 80 try { 75 layout = (SpringLayout) parent.getLayout();81 layout = (SpringLayout) parent.getLayout(); 76 82 } catch (ClassCastException exc) { 77 83 System.err.println("The first argument to makeGrid must use SpringLayout."); … … 176 182 SpringLayout layout; 177 183 try { 178 layout = (SpringLayout) parent.getLayout();184 layout = (SpringLayout) parent.getLayout(); 179 185 } catch (ClassCastException exc) { 180 186 System.err.println("The first argument to makeCompactGrid must use SpringLayout."); -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/TrustAnalyzer.java
r30724 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.util; 2 3 … … 20 21 import org.openstreetmap.josm.plugins.trustosm.data.TrustWay; 21 22 22 public class TrustAnalyzer { 23 24 public static void showManipulationWarning(){ 23 public final class TrustAnalyzer { 24 25 private TrustAnalyzer() { 26 // Hide default constructors for utilities classes 27 } 28 29 public static void showManipulationWarning() { 25 30 JOptionPane.showMessageDialog(Main.parent, tr("The Signature is broken!"), tr("Manipulation Warning"), JOptionPane.WARNING_MESSAGE); 26 31 } 27 28 32 29 33 public static double computeReputation(TrustOsmPrimitive trust, Map<String, List<PGPSignature>> textsigs) { … … 38 42 public static boolean isTagRatingValid(TrustOsmPrimitive trust, String key, String signedPlaintext) { 39 43 /** Rating is valid if signed plaintext matches the current plaintext */ 40 String currentSigtext = TrustOsmPrimitive.generateTagSigtext(trust.getOsmPrimitive(), key);44 String currentSigtext = TrustOsmPrimitive.generateTagSigtext(trust.getOsmPrimitive(), key); 41 45 return currentSigtext.equals(signedPlaintext); 42 46 } 43 44 47 45 48 public static void checkTag(TrustOsmPrimitive trust, String key) { … … 47 50 48 51 TrustSignatures sigs; 49 if ((sigs = trust.getSigsOnKey(key)) !=null) {52 if ((sigs = trust.getSigsOnKey(key)) != null) { 50 53 for (PGPSignature sig : sigs.getSignatures()) { 51 54 /** Here we have a full rating … … 58 61 * Second question: Is the rating valid? 59 62 */ 60 if (isTagRatingValid(trust, key,signedPlaintext)) {63 if (isTagRatingValid(trust, key, signedPlaintext)) { 61 64 /** if the rating is good, we can try to compute a reputation value at the end 62 65 * so we save the important rating stuff … … 71 74 72 75 //if (sigs.getStatus() == TrustSignatures.SIG_UNKNOWN) sigs.setStatus(TrustSignatures.SIG_VALID); 73 } else {74 //sigs.setStatus(TrustSignatures.SIG_BROKEN);75 } 76 } /*else { 77 sigs.setStatus(TrustSignatures.SIG_BROKEN); 78 }*/ 76 79 } else { 77 80 //sigs.setStatus(TrustSignatures.SIG_BROKEN); … … 88 91 } 89 92 90 91 93 public static boolean isNodeRatingValid(TrustNode trust, String signedPlaintext, PGPSignature sig) { 92 94 /** Rating is valid if Node from signed plaintext is inside Tolerance given in Signature */ 93 95 Node signedNode = TrustNode.generateNodeFromSigtext(signedPlaintext); 94 Node currentNode = (Node) trust.getOsmPrimitive();96 Node currentNode = (Node) trust.getOsmPrimitive(); 95 97 double dist = signedNode.getCoor().greatCircleDistance(currentNode.getCoor()); 96 98 97 99 /** is distance between signed Node and current Node inside tolerance? */ 98 return dist <=TrustGPG.searchTolerance(sig);100 return dist <= TrustGPG.searchTolerance(sig); 99 101 } 100 102 … … 106 108 public static void checkNode(TrustNode trust) { 107 109 Map<String, List<PGPSignature>> validRatings = new HashMap<>(); 108 //Node node = (Node)trust.getOsmPrimitive();109 110 TrustSignatures sigs; 110 if ((sigs = trust.getNodeSigs()) !=null) {111 if ((sigs = trust.getNodeSigs()) != null) { 111 112 for (String signedPlaintext : sigs.getAllPlainTexts()) { 112 113 for (PGPSignature sig : sigs.getSignaturesByPlaintext(signedPlaintext)) { 113 114 /** first thing: check signature */ 114 if (TrustOSMplugin.gpg.verify(signedPlaintext, sig)) {115 if (TrustOSMplugin.gpg.verify(signedPlaintext, sig)) { 115 116 /** if signature is valid check rating */ 116 if (isNodeRatingValid(trust, signedPlaintext,sig)) {117 if (isNodeRatingValid(trust, signedPlaintext, sig)) { 117 118 /** if the rating is good, we can try to compute a reputation value at the end 118 119 * so we save the important rating stuff … … 127 128 128 129 //if (sigs.getStatus() == TrustSignatures.SIG_UNKNOWN) sigs.setStatus(TrustSignatures.SIG_VALID); 129 } else { 130 //sigs.setStatus(TrustSignatures.SIG_BROKEN); 131 } 132 130 } /*else { 131 sigs.setStatus(TrustSignatures.SIG_BROKEN); 132 }*/ 133 133 } else { 134 134 //sigs.setStatus(TrustSignatures.SIG_BROKEN); … … 147 147 /** 148 148 * Check if the ratings made for a specific WaySegment are valid for the current form of that WaySegment 149 * @param trust150 * @param seg151 * @param signedPlaintext152 * @param sig153 * @return154 149 */ 155 150 public static boolean isSegmentRatingValid(TrustWay trust, List<Node> nodes, String signedPlaintext, PGPSignature sig) { … … 159 154 double tolerance = TrustGPG.searchTolerance(sig); 160 155 161 for (int i = 0; i <2; i++){156 for (int i = 0; i < 2; i++) { 162 157 Node signedNode = signedSegment.get(i); 163 158 Node currentNode = nodes.get(i); 164 159 double dist = signedNode.getCoor().greatCircleDistance(currentNode.getCoor()); 165 if (dist >tolerance) return false;160 if (dist > tolerance) return false; 166 161 } 167 162 return true; … … 178 173 179 174 TrustSignatures sigs; 180 if ((sigs = trust.getSigsOnSegment(nodes)) !=null) {175 if ((sigs = trust.getSigsOnSegment(nodes)) != null) { 181 176 for (String signedPlaintext : sigs.getAllPlainTexts()) { 182 177 for (PGPSignature sig : sigs.getSignaturesByPlaintext(signedPlaintext)) { 183 178 /** first thing: check signature */ 184 if (TrustOSMplugin.gpg.verify(signedPlaintext, sig)) {179 if (TrustOSMplugin.gpg.verify(signedPlaintext, sig)) { 185 180 /** if signature is valid check rating */ 186 if (isSegmentRatingValid(trust, nodes,signedPlaintext,sig)) {181 if (isSegmentRatingValid(trust, nodes, signedPlaintext, sig)) { 187 182 /** if the rating is good, we can try to compute a reputation value at the end 188 183 * so we save the important rating stuff … … 197 192 198 193 //if (sigs.getStatus() == TrustSignatures.SIG_UNKNOWN) sigs.setStatus(TrustSignatures.SIG_VALID); 199 } else { 200 //sigs.setStatus(TrustSignatures.SIG_BROKEN); 201 } 202 194 } /*else { 195 sigs.setStatus(TrustSignatures.SIG_BROKEN); 196 }*/ 203 197 } else { 204 198 //sigs.setStatus(TrustSignatures.SIG_BROKEN); … … 215 209 } 216 210 217 218 211 public static void checkEverything(TrustOsmPrimitive trust) { 219 212 /** check every single tag for reputation */ 220 for (String key : trust.getSignedKeys()) {213 for (String key : trust.getSignedKeys()) { 221 214 checkTag(trust, key); 222 215 } … … 224 217 /** check all reputation of this single Node */ 225 218 checkNode((TrustNode) trust); 226 } else if (trust instanceof TrustWay) {219 } else if (trust instanceof TrustWay) { 227 220 TrustWay tw = (TrustWay) trust; 228 221 /** check all reputation for every Segment of this Way */ 229 List<Node> wayNodes = ((Way) tw.getOsmPrimitive()).getNodes();230 for (int i =0; i<wayNodes.size()-1; i++) {222 List<Node> wayNodes = ((Way) tw.getOsmPrimitive()).getNodes(); 223 for (int i = 0; i < wayNodes.size()-1; i++) { 231 224 List<Node> nodes = new ArrayList<>(); 232 225 nodes.add(wayNodes.get(i)); 233 226 nodes.add(wayNodes.get(i+1)); 234 checkSegment(tw,nodes); 235 } 236 237 } /*else if (trust instanceof TrustRelation){ 227 checkSegment(tw, nodes); 228 } 229 } /*else if (trust instanceof TrustRelation) { 238 230 TrustRelation tr = (TrustRelation) trust; 239 231 }*/ 240 241 232 } 242 233 } -
applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/TrustGPG.java
r31945 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.trustosm.util; 2 3 … … 135 136 Iterator<?> iter = k.getUserIDs(); 136 137 if (iter.hasNext()) { 137 keyText += (String) iter.next();138 keyText += (String) iter.next(); 138 139 } 139 140 /* iter = sigKey.getUserIDs(); … … 172 173 while (rIt.hasNext()) { 173 174 174 PGPSecretKeyRing kRing = (PGPSecretKeyRing)rIt.next();175 Iterator<?> 175 PGPSecretKeyRing kRing = (PGPSecretKeyRing) rIt.next(); 176 Iterator<?> kIt = kRing.getSecretKeys(); 176 177 177 178 while (kIt.hasNext()) { 178 PGPSecretKey k = (PGPSecretKey)kIt.next();179 PGPSecretKey k = (PGPSecretKey) kIt.next(); 179 180 180 181 if (k.isSigningKey()) { … … 196 197 JPanel p = new JPanel(); 197 198 p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); 198 Dimension d = new Dimension(0, 20);199 Dimension d = new Dimension(0, 20); 199 200 200 201 JLabel head = new JLabel(tr("Select a signing key from your keyring-file:")); … … 212 213 JButton detailsButton = new JButton(tr("Details"), ImageProvider.get("keydetails")); 213 214 detailsButton.setAlignmentX(Component.LEFT_ALIGNMENT); 214 detailsButton.addActionListener(new ActionListener(){ 215 215 detailsButton.addActionListener(new ActionListener() { 216 216 @Override 217 217 public void actionPerformed(ActionEvent arg0) { 218 218 PGPSecretKey sk = sigKeys.get(keyBox.getSelectedIndex()); 219 219 showKeyDetails(getPublicKeyFromRing(sk.getKeyID())); 220 } });220 } }); 221 221 p.add(detailsButton); 222 222 … … 229 229 JButton createButton = new JButton(tr("Create new Key"), ImageProvider.get("key")); 230 230 createButton.setAlignmentX(Component.LEFT_ALIGNMENT); 231 createButton.addActionListener(new ActionListener() {231 createButton.addActionListener(new ActionListener() { 232 232 233 233 @Override … … 239 239 sigKeys.add(secKey); 240 240 } 241 } catch (NoSuchAlgorithmException e) { 242 // TODO Auto-generated catch block 243 e.printStackTrace(); 244 } catch (NoSuchProviderException e) { 245 // TODO Auto-generated catch block 246 e.printStackTrace(); 247 } catch (FileNotFoundException e) { 248 // TODO Auto-generated catch block 249 e.printStackTrace(); 250 } catch (PGPException e) { 251 // TODO Auto-generated catch block 252 e.printStackTrace(); 253 } catch (IOException e) { 254 // TODO Auto-generated catch block 255 e.printStackTrace(); 241 } catch (NoSuchAlgorithmException | NoSuchProviderException | PGPException | IOException e) { 242 Main.error(e); 256 243 } 257 258 }}); 244 } }); 259 245 p.add(createButton); 260 246 p.add(Box.createRigidArea(d)); 261 247 262 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Select a Key to sign"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, ImageProvider.get("keyring"), null, null); 248 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Select a Key to sign"), 249 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, ImageProvider.get("keyring"), null, null); 263 250 264 251 if (n == JOptionPane.OK_OPTION) { … … 273 260 pgpSecKey = null; 274 261 } 275 //String selection = (String) JOptionPane.showInputDialog(null, tr("Select a Key to sign"),tr("Secret Key Choice"), JOptionPane.OK_CANCEL_OPTION, null, keys, keys[0]);276 277 //System.out.println(selection);278 279 // return pgpSecKey;280 262 } 281 263 … … 301 283 String path = Main.pref.getPluginsDirectory().getPath(); 302 284 try (FileOutputStream pubOut = new FileOutputStream(path + "/trustosm/gnupg/pubring.gpg"); 303 FileOutputStream secOut = new FileOutputStream(path + "/trustosm/gnupg/secring.gpg")) {285 FileOutputStream secOut = new FileOutputStream(path + "/trustosm/gnupg/secring.gpg")) { 304 286 pgpSec.encode(secOut); 305 287 pgpPub.encode(pubOut); … … 314 296 JOptionPane jop = new JOptionPane(passwordField, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, ImageProvider.get("lock")); 315 297 JDialog dialog = jop.createDialog("Password:"); 316 dialog.addComponentListener(new ComponentAdapter() {298 dialog.addComponentListener(new ComponentAdapter() { 317 299 @Override 318 public void componentShown(ComponentEvent e) {300 public void componentShown(ComponentEvent e) { 319 301 passwordField.requestFocusInWindow(); 320 302 } 321 303 }); 322 304 dialog.setVisible(true); 323 int result = (Integer) jop.getValue();305 int result = (Integer) jop.getValue(); 324 306 dialog.dispose(); 325 if (result == JOptionPane.OK_OPTION){307 if (result == JOptionPane.OK_OPTION) { 326 308 password = passwordField.getPassword(); 327 309 } 328 329 310 330 311 /*final JPasswordField passwordField = new JPasswordField(10); … … 343 324 } 344 325 345 346 347 326 /* public void checkAll(TrustOsmPrimitive trust) { 348 327 OsmPrimitive osm = trust.getOsmPrimitive(); … … 351 330 } 352 331 353 if (osm instanceof Node) {332 if (osm instanceof Node) { 354 333 checkNode((TrustNode) trust); 355 } else if (osm instanceof Way) {334 } else if (osm instanceof Way) { 356 335 /* Iterator<Node> iter = ((Way)osm).getNodes().iterator(); 357 336 while (iter.hasNext()) { 358 337 checkNode(trust, iter.next()); 359 338 }/ 360 } else if (osm instanceof Relation) {339 } else if (osm instanceof Relation) { 361 340 362 341 } … … 365 344 366 345 public void invalidIDWarning(OsmPrimitive osm) { 367 JOptionPane.showMessageDialog(Main.parent, tr("The object with the ID \"{0}\" ({1}) is newly created.\nYou can not sign it, because the signature would lose the ID-Reference after uploading it to the OSM-server.",osm.getUniqueId(),osm.toString()), tr("Signing canceled!"), JOptionPane.ERROR_MESSAGE); 346 // CHECKSTYLE.OFF: LineLength 347 JOptionPane.showMessageDialog(Main.parent, 348 tr("The object with the ID \"{0}\" ({1}) is newly created.\nYou can not sign it, because the signature would lose the ID-Reference after uploading it to the OSM-server.", 349 osm.getUniqueId(), osm.toString()), 350 tr("Signing canceled!"), JOptionPane.ERROR_MESSAGE); 351 // CHECKSTYLE.ON: LineLength 368 352 } 369 353 /* … … 377 361 return trust; 378 362 } 379 if (osm instanceof Node) {363 if (osm instanceof Node) { 380 364 s = signNode(osm,(Node)osm, spGen); 381 365 if (s != null) ((TrustNode)trust).storeNodeSig(s); 382 } else if (osm instanceof Way) {366 } else if (osm instanceof Way) { 383 367 Iterator<Node> iter = ((Way)osm).getNodes().iterator(); 384 368 while (iter.hasNext()) { … … 387 371 if (s != null) ((TrustNode)trust).storeNodeSig(s); 388 372 } 389 } else if (osm instanceof Relation) {373 } else if (osm instanceof Relation) { 390 374 391 375 } … … 406 390 */ 407 391 List<Node> wayNodes = w.getNodes(); 408 for (int i =0; i<wayNodes.size()-1; i++) {392 for (int i = 0; i < wayNodes.size()-1; i++) { 409 393 List<Node> nodes = new ArrayList<>(); 410 394 nodes.add(wayNodes.get(i)); 411 395 nodes.add(wayNodes.get(i+1)); 412 s = signSegment(trust, nodes);413 if (s != null) trust.storeSegmentSig(nodes, s);396 s = signSegment(trust, nodes); 397 if (s != null) trust.storeSegmentSig(nodes, s); 414 398 } 415 399 … … 423 407 return null; 424 408 } 425 String tosign = TrustWay.generateSegmentSigtext(trust, nodes);409 String tosign = TrustWay.generateSegmentSigtext(trust, nodes); 426 410 PGPSignatureSubpacketGenerator spGen = chooseAccuracy(); 427 return sign(tosign, spGen);411 return sign(tosign, spGen); 428 412 } 429 413 430 414 public PGPSignature signNode(Node node) { 431 PGPSignatureSubpacketGenerator 432 return signNode(node, spGen);415 PGPSignatureSubpacketGenerator spGen = chooseAccuracy(); 416 return signNode(node, spGen); 433 417 } 434 418 … … 439 423 } 440 424 String tosign = TrustNode.generateNodeSigtext(node); 441 return sign(tosign, spGen);425 return sign(tosign, spGen); 442 426 } 443 427 … … 449 433 } 450 434 PGPSignature s; 451 String tosign = TrustOsmPrimitive.generateTagSigtext(osm,key); 452 //s = sign(tosign); 453 s = sign(tosign,chooseInformationSource()); 435 String tosign = TrustOsmPrimitive.generateTagSigtext(osm, key); 436 s = sign(tosign, chooseInformationSource()); 454 437 if (s != null) { 455 438 trust.storeTagSig(key, s); … … 461 444 /** 462 445 * Search in a given Signature for Tolerance information. 463 * @param sig464 446 * @return found tolerance as double or 0 if no Tolerance is given 465 447 */ 466 448 public static double searchTolerance(PGPSignature sig) { 467 449 /** Take the first NotationData packet that seems to have Tolerance information */ 468 for (NotationData nd : sig.getHashedSubPackets().getNotationDataOccurrences()) {450 for (NotationData nd : sig.getHashedSubPackets().getNotationDataOccurrences()) { 469 451 if (nd.getNotationName().equals(TrustGPG.NOTATION_DATA_KEY)) { 470 452 String notation = nd.getNotationValue(); … … 480 462 481 463 public PGPSignatureSubpacketGenerator chooseAccuracy() { 482 PGPSignatureSubpacketGenerator 464 PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); 483 465 JPanel p = new JPanel(new GridBagLayout()); 484 p.add(new JLabel(tr("Please give a tolerance in meters")), GBC.eol());466 p.add(new JLabel(tr("Please give a tolerance in meters")), GBC.eol()); 485 467 486 468 JFormattedTextField meters = new JFormattedTextField(NumberFormat.getNumberInstance()); … … 488 470 meters.setColumns(5); 489 471 490 p.add(meters,GBC.std()); 491 p.add(new JLabel(tr("meters")),GBC.eol()); 492 493 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Accuracy"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 472 p.add(meters, GBC.std()); 473 p.add(new JLabel(tr("meters")), GBC.eol()); 474 475 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Accuracy"), 476 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 494 477 495 478 if (n == JOptionPane.OK_OPTION) { … … 501 484 502 485 public PGPSignatureSubpacketGenerator chooseInformationSource() { 503 PGPSignatureSubpacketGenerator 486 PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); 504 487 JPanel p = new JPanel(new GridBagLayout()); 505 p.add(new JLabel(tr("Select as much as you like:")), GBC.eol());488 p.add(new JLabel(tr("Select as much as you like:")), GBC.eol()); 506 489 507 490 JCheckBox survey = new JCheckBox(tr("Survey")); 508 p.add(survey, GBC.eol());491 p.add(survey, GBC.eol()); 509 492 510 493 JCheckBox aerial = new JCheckBox(tr("Aerial Photography")); 511 p.add(aerial, GBC.eol());494 p.add(aerial, GBC.eol()); 512 495 513 496 JCheckBox web = new JCheckBox(tr("Web Recherche")); 514 p.add(web, GBC.eol());497 p.add(web, GBC.eol()); 515 498 516 499 JCheckBox trusted = new JCheckBox(tr("Trusted persons told me")); 517 p.add(trusted,GBC.eol()); 518 519 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Which source did you use?"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 500 p.add(trusted, GBC.eol()); 501 502 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Which source did you use?"), 503 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 520 504 521 505 if (n == JOptionPane.OK_OPTION) { … … 532 516 533 517 public PGPSignature sign(String tosign) { 534 PGPSignatureSubpacketGenerator 535 return sign(tosign, spGen);518 PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator(); 519 return sign(tosign, spGen); 536 520 } 537 521 … … 540 524 if (spGen == null) return null; 541 525 PGPSignature sig; 542 try{ 543 526 try { 544 527 readSecretKey(); 545 528 if (pgpSec == null) return null; … … 551 534 Provider provider = Security.getProvider("BC"); 552 535 PGPDigestCalculatorProvider digestCalculatorProvider = new JcaPGPDigestCalculatorProviderBuilder().setProvider(provider).build(); 553 PBESecretKeyDecryptor secretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder(digestCalculatorProvider).setProvider(provider).build(password); 536 PBESecretKeyDecryptor secretKeyDecryptor = new JcePBESecretKeyDecryptorBuilder(digestCalculatorProvider) 537 .setProvider(provider).build(password); 554 538 PGPPrivateKey pgpPrivKey = pgpSecKey.extractPrivateKey(secretKeyDecryptor); 555 539 int keyAlgorithm = pgpSecKey.getPublicKey().getAlgorithm(); 556 PGPContentSignerBuilder contentSignerBuilder = new JcaPGPContentSignerBuilder(keyAlgorithm, digest).setProvider(provider).setDigestProvider(provider); 540 PGPContentSignerBuilder contentSignerBuilder = new JcaPGPContentSignerBuilder(keyAlgorithm, digest) 541 .setProvider(provider).setDigestProvider(provider); 557 542 PGPSignatureGenerator sGen = new PGPSignatureGenerator(contentSignerBuilder); 558 543 sGen.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey); … … 560 545 Iterator<?> it = pgpSecKey.getPublicKey().getUserIDs(); 561 546 if (it.hasNext()) { 562 spGen.setSignerUserID(false, (String) it.next());547 spGen.setSignerUserID(false, (String) it.next()); 563 548 } 564 549 sGen.setHashedSubpackets(spGen.generate()); … … 569 554 //sig.encode(new BCPGOutputStream(new ArmoredOutputStream(new FileOutputStream("/tmp/sigtest.asc")))); 570 555 return sig; 571 } catch (Exception e){//Catch exception if any556 } catch (Exception e) { 572 557 System.err.println("PGP Signing Error: " + e.getMessage()); 573 558 } … … 600 585 sig.update(sigtext.getBytes(Charset.forName("UTF-8"))); 601 586 return sig.verify(); 602 } catch (Exception e){//Catch exception if any587 } catch (Exception e) { 603 588 System.err.println("PGP Verification Error: " + e.getMessage()); 604 589 } 605 590 return false; 606 591 } 607 608 592 609 593 // public static void writeSignatureToFile(PGPSignature sig, String clearText, FileOutputStream fout) throws Exception { … … 637 621 Iterator<?> iter = key.getUserIDs(); 638 622 if (iter.hasNext()) { 639 userid = (String) iter.next();623 userid = (String) iter.next(); 640 624 } 641 625 … … 682 666 } 683 667 684 685 String[] labels = {tr("Primary user-ID: "), tr("Key-ID: "), tr("Fingerprint: "), tr("Algorithm: "),tr("Strength in bit: "), tr("Creation date: "), tr("Expiration date: ")};668 String[] labels = {tr("Primary user-ID: "), tr("Key-ID: "), tr("Fingerprint: "), tr("Algorithm: "), 669 tr("Strength in bit: "), tr("Creation date: "), tr("Expiration date: ")}; 686 670 String[] values = {userid, keyid, fingerprint, algorithm, strength, creationTime, expirationTime}; 687 671 int numPairs = labels.length; … … 709 693 // metaPanel.add(p); 710 694 // JScrollPane sp = new JScrollPane(new KeySignaturesDialog(key)); 711 // sp.setPreferredSize(new Dimension(0, 200));695 // sp.setPreferredSize(new Dimension(0, 200)); 712 696 // metaPanel.add(sp); 713 697 … … 715 699 } 716 700 717 718 public PGPSecretKey generateKey()throws NoSuchAlgorithmException, NoSuchProviderException, PGPException, FileNotFoundException, IOException {701 public PGPSecretKey generateKey() 702 throws NoSuchAlgorithmException, NoSuchProviderException, PGPException, FileNotFoundException, IOException { 719 703 720 704 JTextField userId = new JTextField(); … … 727 711 strengthBox.setEnabled(false); 728 712 729 /* final String[] curves = {"prime192v1", "prime192v2", "prime192v3", "prime239v1", "prime239v2", "prime239v3", "prime256v1", "secp224r1", "secp256r1", "secp384r1", "secp521r1", "P-224", "P-256", "P-384", "P-521", "c2pnb163v1", "c2pnb163v2", "c2pnb163v3", "c2pnb176w1", "c2tnb191v2", "c2tnb191v1", "c2tnb191v3", "c2pnb208w1", "c2tnb239v1", "c2tnb239v2", "c2tnb239v3", "c2pnb272w1", "c2pnb304w1", "c2tnb359v1", "c2pnb368w1", "c2tnb431r1", "sect163r2", "sect233r1", "sect283r1", "sect409r1", "sect571r1", "B-163", "B-233", "B-283", "B-409", "B-571", "brainpoolp160r1", "brainpoolp160t1", "brainpoolp192r1", "brainpoolp192t1", "brainpoolp224r1", "brainpoolp224t1", "brainpoolp256r1", "brainpoolp256t1", "brainpoolp320r1", "brainpoolp320t1", "brainpoolp384r1", "brainpoolp384t1", "brainpoolp512r1", "brainpoolp512t1"}; 730 final String[] curvesizes = {"192", "192", "192", "239", "239", "239", "256", "224", "256", "384", "521", "224", "256", "384", "521", "163", "163", "163", "176", "191", "191", "191", "208", "239", "239", "239", "272", "304", "359", "368", "431", "163", "233", "283", "409", "571", "163", "233", "283", "409", "571", "160", "160", "192", "192", "224", "224", "256", "256", "320", "320", "384", "384", "512", "512"}; 713 /* final String[] curves = {"prime192v1", "prime192v2", "prime192v3", "prime239v1", "prime239v2", "prime239v3", "prime256v1", 714 "secp224r1", "secp256r1", "secp384r1", "secp521r1", "P-224", "P-256", "P-384", "P-521", "c2pnb163v1", "c2pnb163v2", "c2pnb163v3", 715 "c2pnb176w1", "c2tnb191v2", "c2tnb191v1", "c2tnb191v3", "c2pnb208w1", "c2tnb239v1", "c2tnb239v2", "c2tnb239v3", "c2pnb272w1", 716 "c2pnb304w1", "c2tnb359v1", "c2pnb368w1", "c2tnb431r1", "sect163r2", "sect233r1", "sect283r1", "sect409r1", "sect571r1", 717 "B-163", "B-233", "B-283", "B-409", "B-571", "brainpoolp160r1", "brainpoolp160t1", "brainpoolp192r1", "brainpoolp192t1", 718 "brainpoolp224r1", "brainpoolp224t1", "brainpoolp256r1", "brainpoolp256t1", "brainpoolp320r1", "brainpoolp320t1", "brainpoolp384r1", 719 "brainpoolp384t1", "brainpoolp512r1", "brainpoolp512t1"}; 720 final String[] curvesizes = {"192", "192", "192", "239", "239", "239", "256", "224", "256", "384", "521", "224", "256", "384", "521", 721 "163", "163", "163", "176", "191", "191", "191", "208", "239", "239", "239", "272", "304", "359", "368", "431", "163", "233", 722 "283", "409", "571", "163", "233", "283", "409", "571", "160", "160", "192", "192", "224", "224", "256", "256", "320", "320", 723 "384", "384", "512", "512"}; 731 724 final JComboBox curveBox = new JComboBox(curves); 732 curveBox.addActionListener(new ActionListener() {725 curveBox.addActionListener(new ActionListener() { 733 726 734 727 @Override … … 740 733 741 734 // final String[] algos = {"DSA","RSA","ECDSA"}; 742 final String[] algos = {"DSA", "RSA"};735 final String[] algos = {"DSA", "RSA"}; 743 736 final JComboBox<?> algoBox = new JComboBox<Object>(algos); 744 algoBox.addActionListener(new ActionListener() {737 algoBox.addActionListener(new ActionListener() { 745 738 746 739 @Override 747 740 public void actionPerformed(ActionEvent e) { 748 JComboBox<?> cb = (JComboBox<?>) e.getSource();749 String alg = (String) cb.getSelectedItem();741 JComboBox<?> cb = (JComboBox<?>) e.getSource(); 742 String alg = (String) cb.getSelectedItem(); 750 743 if (alg.equals("DSA")) { 751 744 strengthBox.setSelectedItem("1024"); … … 766 759 }); 767 760 768 769 770 771 772 final String[] protectAlgos = {"AES_256", "AES_192", "AES_128", "BLOWFISH", "CAST5", "DES", "IDEA", "SAFER", "TRIPLE_DES", "TWOFISH", "NULL"}; 773 int[] protAl = {PGPEncryptedData.AES_256, PGPEncryptedData.AES_192, PGPEncryptedData.AES_128, PGPEncryptedData.BLOWFISH, PGPEncryptedData.CAST5, PGPEncryptedData.DES, PGPEncryptedData.IDEA, PGPEncryptedData.SAFER, PGPEncryptedData.TRIPLE_DES, PGPEncryptedData.TWOFISH, PGPEncryptedData.NULL}; 761 final String[] protectAlgos = {"AES_256", "AES_192", "AES_128", "BLOWFISH", 762 "CAST5", "DES", "IDEA", "SAFER", "TRIPLE_DES", "TWOFISH", "NULL"}; 763 int[] protAl = {PGPEncryptedData.AES_256, PGPEncryptedData.AES_192, PGPEncryptedData.AES_128, PGPEncryptedData.BLOWFISH, 764 PGPEncryptedData.CAST5, PGPEncryptedData.DES, PGPEncryptedData.IDEA, PGPEncryptedData.SAFER, PGPEncryptedData.TRIPLE_DES, 765 PGPEncryptedData.TWOFISH, PGPEncryptedData.NULL}; 774 766 final JComboBox<?> protectBox = new JComboBox<Object>(protectAlgos); 775 767 776 768 final JDateChooser cal = new JDateChooser(null, null, null, new JSpinnerDateEditor()); 777 cal.setPreferredSize(new Dimension(130,cal.getPreferredSize().height)); 778 779 final String[] labels = {tr("User-ID:"), tr("Select algorithm:"), tr("Choose Bitlength (Strength):"), tr("Encryption algorithm to protect private key:"), tr("Choose an expiry date for the key:")}; 769 cal.setPreferredSize(new Dimension(130, cal.getPreferredSize().height)); 770 771 final String[] labels = {tr("User-ID:"), tr("Select algorithm:"), tr("Choose Bitlength (Strength):"), 772 tr("Encryption algorithm to protect private key:"), tr("Choose an expiry date for the key:")}; 780 773 final JComponent[] values = {userId, algoBox, strengthBox, protectBox, cal}; 781 774 … … 795 788 numPairs, 2, //rows, cols 796 789 6, 6, //initX, initY 797 16, 6); //xPad, yPad 798 799 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Create a new signing key"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 790 16, 6); //xPad, yPad 791 792 int n = JOptionPane.showOptionDialog(Main.parent, p, tr("Create a new signing key"), 793 JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); 800 794 801 795 if (n != JOptionPane.OK_OPTION) … … 803 797 804 798 805 String algo = (String) algoBox.getSelectedItem();799 String algo = (String) algoBox.getSelectedItem(); 806 800 807 801 KeyPairGenerator Kpg = KeyPairGenerator.getInstance(algo, "BC"); … … 820 814 } 821 815 else {*/ 822 Kpg.initialize(Integer.parseInt((String) strengthBox.getSelectedItem()));816 Kpg.initialize(Integer.parseInt((String) strengthBox.getSelectedItem())); 823 817 // 824 818 // this takes a while as the key generator has to generate some DSA params … … 853 847 PBESecretKeyEncryptor encryptor = new JcePBESecretKeyEncryptorBuilder(encAlgorithm).setProvider(provider). 854 848 setSecureRandom(new SecureRandom()).build(password); 855 849 856 850 PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, pgpKp, userId.getText(), 857 851 checksumCalculator, subPck, null, signerBuilder, encryptor); -
applications/editors/josm/plugins/trustosm/src/tools/NameGenerator.java
r30742 r32533 1 // License: GPL. For details, see LICENSE file. 1 2 package tools; 2 3 … … 53 54 ArrayList<String> sur = new ArrayList<>(); 54 55 55 final private static char[] vocals = {'a', 'e', 'i', 'o', 'u', 'ä', 'ö', 'õ', 'ü', 'y'}; 56 final private static char[] consonants = {'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y'}; 56 private static final char[] vocals = { 57 'a', 'e', 'i', 'o', 'u', 'ä', 'ö', 'õ', 'ü', 'y'}; 58 private static final char[] consonants = { 59 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y'}; 57 60 58 61 private String fileName; … … 61 64 * Create new random name generator object. refresh() is automatically called. 62 65 * @param fileName insert file name, where syllables are located 63 * @throws IOException 64 */ 65 public NameGenerator(String fileName) throws IOException{ 66 */ 67 public NameGenerator(String fileName) throws IOException { 66 68 this.fileName = fileName; 67 69 refresh(); … … 71 73 * Change the file. refresh() is automatically called during the process. 72 74 * @param fileName insert the file name, where syllables are located. 73 * @throws IOException 74 */ 75 public void changeFile(String fileName) throws IOException{ 76 if(fileName == null) throw new IOException("File name cannot be null"); 75 */ 76 public void changeFile(String fileName) throws IOException { 77 if (fileName == null) throw new IOException("File name cannot be null"); 77 78 this.fileName = fileName; 78 79 refresh(); … … 82 83 * Refresh names from file. No need to call that method, if you are not changing the file during the operation of program, as this method 83 84 * is called every time file name is changed or new NameGenerator object created. 84 * @throws IOException 85 */ 86 public void refresh() throws IOException{ 85 */ 86 public void refresh() throws IOException { 87 87 try ( 88 FileReader input = new FileReader(fileName);89 BufferedReader bufRead = new BufferedReader(input);90 ) {91 String line ="";88 FileReader input = new FileReader(fileName); 89 BufferedReader bufRead = new BufferedReader(input); 90 ) { 91 String line = ""; 92 92 93 93 while (line != null) { … … 98 98 } else if (line.charAt(0) == '+') { 99 99 sur.add(line.substring(1).toLowerCase()); 100 } else {100 } else { 101 101 mid.add(line.toLowerCase()); 102 102 } … … 107 107 108 108 private String upper(String s) { 109 return s.substring(0, 1).toUpperCase().concat(s.substring(1));109 return s.substring(0, 1).toUpperCase().concat(s.substring(1)); 110 110 } 111 111 … … 117 117 } 118 118 119 private boolean containsVocFirst(ArrayList<String> array){ 120 for(String s: array){ 121 if(vocalFirst(s)) return true; 122 } 123 return false; 124 } 125 126 private boolean allowCons(ArrayList<String> array){ 127 for(String s: array){ 128 if(hatesPreviousVocals(s) || hatesPreviousConsonants(s) == false) return true; 129 } 130 return false; 131 } 132 133 private boolean allowVocs(ArrayList<String> array){ 134 for(String s: array){ 135 if(hatesPreviousConsonants(s) || hatesPreviousVocals(s) == false) return true; 136 } 137 return false; 138 } 139 140 private boolean expectsVocal(String s){ 141 if(s.substring(1).contains("+v")) return true; 142 else return false; 143 } 144 private boolean expectsConsonant(String s){ 145 if(s.substring(1).contains("+c")) return true; 146 else return false; 147 } 148 private boolean hatesPreviousVocals(String s){ 149 if(s.substring(1).contains("-c")) return true; 150 else return false; 151 } 152 private boolean hatesPreviousConsonants(String s){ 153 if(s.substring(1).contains("-v")) return true; 154 else return false; 155 } 156 157 private String pureSyl(String s){ 119 private boolean containsVocFirst(ArrayList<String> array) { 120 for (String s: array) { 121 if (vocalFirst(s)) return true; 122 } 123 return false; 124 } 125 126 private boolean allowCons(ArrayList<String> array) { 127 for (String s: array) { 128 if (hatesPreviousVocals(s) || hatesPreviousConsonants(s) == false) return true; 129 } 130 return false; 131 } 132 133 private boolean allowVocs(ArrayList<String> array) { 134 for (String s: array) { 135 if (hatesPreviousConsonants(s) || hatesPreviousVocals(s) == false) return true; 136 } 137 return false; 138 } 139 140 private boolean expectsVocal(String s) { 141 if (s.substring(1).contains("+v")) return true; 142 else return false; 143 } 144 145 private boolean expectsConsonant(String s) { 146 if (s.substring(1).contains("+c")) return true; 147 else return false; 148 } 149 150 private boolean hatesPreviousVocals(String s) { 151 if (s.substring(1).contains("-c")) return true; 152 else return false; 153 } 154 155 private boolean hatesPreviousConsonants(String s) { 156 if (s.substring(1).contains("-v")) return true; 157 else return false; 158 } 159 160 private String pureSyl(String s) { 158 161 s = s.trim(); 159 if (s.charAt(0) == '+' || s.charAt(0) == '-') s = s.substring(1);162 if (s.charAt(0) == '+' || s.charAt(0) == '-') s = s.substring(1); 160 163 return s.split(" ")[0]; 161 164 } 162 165 163 private boolean vocalFirst(String s) {166 private boolean vocalFirst(String s) { 164 167 return (String.copyValueOf(vocals).contains(String.valueOf(s.charAt(0)).toLowerCase())); 165 168 } 166 169 167 private boolean consonantFirst(String s) {170 private boolean consonantFirst(String s) { 168 171 return (String.copyValueOf(consonants).contains(String.valueOf(s.charAt(0)).toLowerCase())); 169 172 } 170 173 171 private boolean vocalLast(String s) {174 private boolean vocalLast(String s) { 172 175 return (String.copyValueOf(vocals).contains(String.valueOf(s.charAt(s.length()-1)).toLowerCase())); 173 176 } 174 177 175 private boolean consonantLast(String s) {178 private boolean consonantLast(String s) { 176 179 return (String.copyValueOf(consonants).contains(String.valueOf(s.charAt(s.length()-1)).toLowerCase())); 177 180 } 178 181 182 // CHECKSTYLE.OFF: LineLength 179 183 180 184 /** … … 184 188 * @throws RuntimeException when logical mistakes are detected inside chosen file, and program is unable to complete the name. 185 189 */ 186 public String compose(int syls){ 187 if(syls > 2 && mid.size() == 0) throw new RuntimeException("You are trying to create a name with more than 3 parts, which requires middle parts, " + 188 "which you have none in the file "+fileName+". You should add some. Every word, which doesn't have + or - for a prefix is counted as a middle part."); 189 if(pre.size() == 0) throw new RuntimeException("You have no prefixes to start creating a name. add some and use \"-\" prefix, to identify it as a prefix for a name. (example: -asd)"); 190 if(sur.size() == 0) throw new RuntimeException("You have no suffixes to end a name. add some and use \"+\" prefix, to identify it as a suffix for a name. (example: +asd)"); 191 if(syls < 1) throw new RuntimeException("compose(int syls) can't have less than 1 syllable"); 190 public String compose(int syls) { 191 if (syls > 2 && mid.size() == 0) 192 throw new RuntimeException("You are trying to create a name with more than 3 parts, which requires middle parts, " + 193 "which you have none in the file "+fileName+". You should add some. Every word, which doesn't have + or - for a prefix is counted as a middle part."); 194 if (pre.size() == 0) 195 throw new RuntimeException("You have no prefixes to start creating a name. add some and use \"-\" prefix, to identify it as a prefix for a name. (example: -asd)"); 196 if (sur.size() == 0) 197 throw new RuntimeException("You have no suffixes to end a name. add some and use \"+\" prefix, to identify it as a suffix for a name. (example: +asd)"); 198 if (syls < 1) throw new RuntimeException("compose(int syls) can't have less than 1 syllable"); 192 199 int expecting = 0; // 1 for vocal, 2 for consonant 193 200 int last = 0; // 1 for vocal, 2 for consonant 194 201 String name; 195 int a = (int) (Math.random() * pre.size());196 197 if (vocalLast(pureSyl(pre.get(a)))) last = 1;202 int a = (int) (Math.random() * pre.size()); 203 204 if (vocalLast(pureSyl(pre.get(a)))) last = 1; 198 205 else last = 2; 199 206 200 if (syls > 2){201 if (expectsVocal(pre.get(a))){207 if (syls > 2) { 208 if (expectsVocal(pre.get(a))) { 202 209 expecting = 1; 203 if (containsVocFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with vocal, " +204 "but there is none. You should add one, or remove requirement for one.. ");205 } 206 if (expectsConsonant(pre.get(a))){210 if (containsVocFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with vocal, " + 211 "but there is none. You should add one, or remove requirement for one.. "); 212 } 213 if (expectsConsonant(pre.get(a))) { 207 214 expecting = 2; 208 if(containsConsFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with consonant, " + 209 "but there is none. You should add one, or remove requirement for one.. "); 210 } 211 } 212 else{ 213 if(expectsVocal(pre.get(a))){ 215 if (containsConsFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with consonant, " + 216 "but there is none. You should add one, or remove requirement for one.. "); 217 } 218 } else { 219 if (expectsVocal(pre.get(a))) { 214 220 expecting = 1; 215 if (containsVocFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with vocal, " +216 "but there is none. You should add one, or remove requirement for one.. ");217 } 218 if (expectsConsonant(pre.get(a))){221 if (containsVocFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with vocal, " + 222 "but there is none. You should add one, or remove requirement for one.. "); 223 } 224 if (expectsConsonant(pre.get(a))) { 219 225 expecting = 2; 220 if (containsConsFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with consonant, " +221 "but there is none. You should add one, or remove requirement for one.. ");222 } 223 } 224 if (vocalLast(pureSyl(pre.get(a))) && allowVocs(mid) == false) throw new RuntimeException("Expecting \"middle\" part that allows last character of prefix to be a vocal, " +226 if (containsConsFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with consonant, " + 227 "but there is none. You should add one, or remove requirement for one.. "); 228 } 229 } 230 if (vocalLast(pureSyl(pre.get(a))) && allowVocs(mid) == false) throw new RuntimeException("Expecting \"middle\" part that allows last character of prefix to be a vocal, " + 225 231 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the prefix used, was : \""+pre.get(a)+"\", which" + 226 "means there should be a part available, that has \"-v\" requirement or no requirements for previous syllables at all.");227 228 if (consonantLast(pureSyl(pre.get(a))) && allowCons(mid) == false) throw new RuntimeException("Expecting \"middle\" part that allows last character of prefix to be a consonant, " +232 "means there should be a part available, that has \"-v\" requirement or no requirements for previous syllables at all."); 233 234 if (consonantLast(pureSyl(pre.get(a))) && allowCons(mid) == false) throw new RuntimeException("Expecting \"middle\" part that allows last character of prefix to be a consonant, " + 229 235 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the prefix used, was : \""+pre.get(a)+"\", which" + 230 "means there should be a part available, that has \"-c\" requirement or no requirements for previous syllables at all.");231 232 int b[]= new int[syls];233 for (int i = 0; i<b.length-2; i++){234 235 do {236 b[i] = (int) (Math.random() * mid.size());236 "means there should be a part available, that has \"-c\" requirement or no requirements for previous syllables at all."); 237 238 int[] b = new int[syls]; 239 for (int i = 0; i < b.length-2; i++) { 240 241 do { 242 b[i] = (int) (Math.random() * mid.size()); 237 243 //System.out.println("exp " +expecting+" vocalF:"+vocalFirst(mid.get(b[i]))+" syl: "+mid.get(b[i])); 238 } 239 while(expecting == 1 && vocalFirst(pureSyl(mid.get(b[i]))) == false || expecting == 2 && consonantFirst(pureSyl(mid.get(b[i]))) == false 244 } while (expecting == 1 && vocalFirst(pureSyl(mid.get(b[i]))) == false || expecting == 2 && consonantFirst(pureSyl(mid.get(b[i]))) == false 240 245 || last == 1 && hatesPreviousVocals(mid.get(b[i])) || last == 2 && hatesPreviousConsonants(mid.get(b[i]))); 241 246 242 247 expecting = 0; 243 if (expectsVocal(mid.get(b[i]))){248 if (expectsVocal(mid.get(b[i]))) { 244 249 expecting = 1; 245 if (i < b.length-3 && containsVocFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with vocal, " +246 "but there is none. You should add one, or remove requirement for one.. ");247 if (i == b.length-3 && containsVocFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with vocal, " +248 "but there is none. You should add one, or remove requirement for one.. ");249 } 250 if (expectsConsonant(mid.get(b[i]))){250 if (i < b.length-3 && containsVocFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with vocal, " + 251 "but there is none. You should add one, or remove requirement for one.. "); 252 if (i == b.length-3 && containsVocFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with vocal, " + 253 "but there is none. You should add one, or remove requirement for one.. "); 254 } 255 if (expectsConsonant(mid.get(b[i]))) { 251 256 expecting = 2; 252 if (i < b.length-3 && containsConsFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with consonant, " +253 "but there is none. You should add one, or remove requirement for one.. ");254 if (i == b.length-3 && containsConsFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with consonant, " +255 "but there is none. You should add one, or remove requirement for one.. ");256 } 257 if (vocalLast(pureSyl(mid.get(b[i]))) && allowVocs(mid) == false && syls > 3) throw new RuntimeException("Expecting \"middle\" part that allows last character of last syllable to be a vocal, " +257 if (i < b.length-3 && containsConsFirst(mid) == false) throw new RuntimeException("Expecting \"middle\" part starting with consonant, " + 258 "but there is none. You should add one, or remove requirement for one.. "); 259 if (i == b.length-3 && containsConsFirst(sur) == false) throw new RuntimeException("Expecting \"suffix\" part starting with consonant, " + 260 "but there is none. You should add one, or remove requirement for one.. "); 261 } 262 if (vocalLast(pureSyl(mid.get(b[i]))) && allowVocs(mid) == false && syls > 3) throw new RuntimeException("Expecting \"middle\" part that allows last character of last syllable to be a vocal, " + 258 263 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the part used, was : \""+mid.get(b[i])+"\", which " + 259 "means there should be a part available, that has \"-v\" requirement or no requirements for previous syllables at all.");260 261 if (consonantLast(pureSyl(mid.get(b[i]))) && allowCons(mid) == false && syls > 3) throw new RuntimeException("Expecting \"middle\" part that allows last character of last syllable to be a consonant, " +264 "means there should be a part available, that has \"-v\" requirement or no requirements for previous syllables at all."); 265 266 if (consonantLast(pureSyl(mid.get(b[i]))) && allowCons(mid) == false && syls > 3) throw new RuntimeException("Expecting \"middle\" part that allows last character of last syllable to be a consonant, " + 262 267 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the part used, was : \""+mid.get(b[i])+"\", which " + 263 "means there should be a part available, that has \"-c\" requirement or no requirements for previous syllables at all.");264 if (i == b.length-3){265 if (vocalLast(pureSyl(mid.get(b[i]))) && allowVocs(sur) == false) throw new RuntimeException("Expecting \"suffix\" part that allows last character of last syllable to be a vocal, " +268 "means there should be a part available, that has \"-c\" requirement or no requirements for previous syllables at all."); 269 if (i == b.length-3) { 270 if (vocalLast(pureSyl(mid.get(b[i]))) && allowVocs(sur) == false) throw new RuntimeException("Expecting \"suffix\" part that allows last character of last syllable to be a vocal, " + 266 271 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the part used, was : \""+mid.get(b[i])+"\", which " + 267 "means there should be a suffix available, that has \"-v\" requirement or no requirements for previous syllables at all.");268 269 if (consonantLast(pureSyl(mid.get(b[i]))) && allowCons(sur) == false) throw new RuntimeException("Expecting \"suffix\" part that allows last character of last syllable to be a consonant, " +272 "means there should be a suffix available, that has \"-v\" requirement or no requirements for previous syllables at all."); 273 274 if (consonantLast(pureSyl(mid.get(b[i]))) && allowCons(sur) == false) throw new RuntimeException("Expecting \"suffix\" part that allows last character of last syllable to be a consonant, " + 270 275 "but there is none. You should add one, or remove requirements that cannot be fulfilled.. the part used, was : \""+mid.get(b[i])+"\", which " + 271 "means there should be a suffix available, that has \"-c\" requirement or no requirements for previous syllables at all.");272 } 273 if (vocalLast(pureSyl(mid.get(b[i])))) last = 1;276 "means there should be a suffix available, that has \"-c\" requirement or no requirements for previous syllables at all."); 277 } 278 if (vocalLast(pureSyl(mid.get(b[i])))) last = 1; 274 279 else last = 2; 275 280 } 276 281 277 282 int c; 278 do{ 279 c = (int)(Math.random() * sur.size()); 280 } 281 while(expecting == 1 && vocalFirst(pureSyl(sur.get(c))) == false || expecting == 2 && consonantFirst(pureSyl(sur.get(c))) == false 283 do { 284 c = (int) (Math.random() * sur.size()); 285 } while (expecting == 1 && vocalFirst(pureSyl(sur.get(c))) == false || expecting == 2 && consonantFirst(pureSyl(sur.get(c))) == false 282 286 || last == 1 && hatesPreviousVocals(sur.get(c)) || last == 2 && hatesPreviousConsonants(sur.get(c))); 283 287 284 288 name = upper(pureSyl(pre.get(a).toLowerCase())); 285 for (int i = 0; i<b.length-2; i++){289 for (int i = 0; i < b.length-2; i++) { 286 290 name = name.concat(pureSyl(mid.get(b[i]).toLowerCase())); 287 291 } 288 if (syls > 1)292 if (syls > 1) 289 293 name = name.concat(pureSyl(sur.get(c).toLowerCase())); 290 294 return name; 291 295 } 296 // CHECKSTYLE.ON: LineLength 292 297 } -
applications/editors/josm/plugins/trustosm/src/tools/SpringUtilities.java
r24389 r32533 28 28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 30 */ 31 31 32 32 package tools; 33 33 34 import javax.swing.*; 34 import java.awt.Component; 35 import java.awt.Container; 36 37 import javax.swing.Spring; 35 38 import javax.swing.SpringLayout; 36 import java.awt.*;37 39 38 40 /** … … 42 44 * SpringBox and SpringCompactGrid. 43 45 */ 44 public class SpringUtilities { 46 public final class SpringUtilities { 47 48 private SpringUtilities() { 49 // Hide default constructors for utilities classes 50 } 51 45 52 /** 46 53 * A debugging utility that prints to stdout the component's … … 73 80 SpringLayout layout; 74 81 try { 75 layout = (SpringLayout) parent.getLayout();82 layout = (SpringLayout) parent.getLayout(); 76 83 } catch (ClassCastException exc) { 77 84 System.err.println("The first argument to makeGrid must use SpringLayout."); … … 176 183 SpringLayout layout; 177 184 try { 178 layout = (SpringLayout) parent.getLayout();185 layout = (SpringLayout) parent.getLayout(); 179 186 } catch (ClassCastException exc) { 180 187 System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
Note:
See TracChangeset
for help on using the changeset viewer.