Changeset 32533 in osm for applications/editors


Ignore:
Timestamp:
2016-07-02T21:57:09+02:00 (8 years ago)
Author:
donvip
Message:

checkstyle

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  
    6464org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
    6565org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
    66 org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
     66org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
    6767org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
    6868org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
     
    8686org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
    8787org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
     88org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
    8889org.eclipse.jdt.core.compiler.problem.unusedImport=warning
    8990org.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.
    12package org.openstreetmap.josm.plugins.trustosm;
    23
     
    6667            Main.pref.put("trustosm.jarLibsExtracted", extractFiles("trustosm","resources"));
    6768        }*/
    68         extractFiles("trustosm","lib");
    69         extractFiles("trustosm","resources");
     69        extractFiles("trustosm", "lib");
     70        extractFiles("trustosm", "resources");
    7071
    7172        refreshMenu();
     
    8485
    8586    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};
    8788
    8889        // create a cipher and attempt to encrypt the data block with our key
    89         try{
     90        try {
    9091            Cipher c = Cipher.getInstance("AES");
    9192            // create a 192 bit secret key from raw bytes
    9293
    93             SecretKey key192 = new SecretKeySpec(new byte[] { 0x00, 0x01, 0x02,
    94                     0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
    95                     0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
    96                     0x17 }, "AES");
     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");
    9798
    9899            // now try encrypting with the larger key
     
    103104            Main.warn("It seems that the Unrestricted Policy Files are not available in this JVM. "+
    104105                      "So high level crypto is not allowed. Problems may occur.");
    105             //extractFiles("trustosm","jce");
    106106            installUnrestrictedPolicyFiles();
    107107        } catch (BadPaddingException | IllegalBlockSizeException | NoSuchPaddingException | NoSuchAlgorithmException e) {
     
    260260            gpgJMenu.add(new JMenuItem(new ExportSigsAction()));
    261261        }
    262 
    263262    }
    264263
    265264    public static void setSettings() {
    266         Map<String,String> prefs = Main.pref.getAllPrefix("trustosm.");
     265        Map<String, String> prefs = Main.pref.getAllPrefix("trustosm.");
    267266
    268267        // if setting isn't present, we set a default
     
    272271    }
    273272
    274 
    275273    @Override
    276274    public PreferenceSetting getPreferenceSetting() {
     
    280278    @Override
    281279    public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) {
    282         if (oldFrame==null && newFrame!=null) {
     280        if (oldFrame == null && newFrame != null) {
    283281            trustDialog = new TrustDialog();
    284282            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.
    12package org.openstreetmap.josm.plugins.trustosm.actions;
    23
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/actions/GetMissingDataAction.java

    r32511 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.actions;
    23
     
    2223
    2324    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);
    2627    }
    2728
     
    3536    public boolean downloadMissing() {
    3637        Collection<OsmPrimitive> missingData = new HashSet<>();
    37         Map<String,TrustOsmPrimitive> trustitems = TrustOSMplugin.signedItems;
     38        Map<String, TrustOsmPrimitive> trustitems = TrustOSMplugin.signedItems;
    3839        getMissing(trustitems, missingData);
    3940
     
    4142        int itemCount = trustitems.size();
    4243        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));
    4445        } 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);
    4650
    4751            if (n == JOptionPane.YES_OPTION) {
     
    5458    }
    5559
    56     public void getMissing(Map<String,TrustOsmPrimitive> trustitems, Collection<OsmPrimitive> missingData) {
     60    public void getMissing(Map<String, TrustOsmPrimitive> trustitems, Collection<OsmPrimitive> missingData) {
    5761        Collection<OsmPrimitive> presentData = Main.getLayerManager().getEditDataSet().allPrimitives();
    5862        for (TrustOsmPrimitive t : trustitems.values()) {
     
    6266        }
    6367    }
    64 
    65 
    6668}
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustNode.java

    r30724 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.data;
    23
     
    1213public class TrustNode extends TrustOsmPrimitive {
    1314
    14 
    1515    public static Node generateNodeFromSigtext(String sigtext) {
    1616        Pattern p = Pattern.compile("^(\\d*)\\((\\d*\\.?\\d*),(\\d*\\.?\\d*)\\)");
     
    1818        if (m.matches()) {
    1919            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))));
    2121            return node;
    2222        }
     
    4040    @Override
    4141    public void setOsmPrimitive(OsmPrimitive osmItem) {
    42         if(osmItem instanceof Node) {
     42        if (osmItem instanceof Node) {
    4343            osm = osmItem;
    4444        } else {
     
    5656
    5757    public void setNodeRatings(TrustSignatures ratings) {
    58         this.ratings =ratings;
     58        this.ratings = ratings;
    5959    }
    6060
     
    6262        return ratings;
    6363    }
    64 
    6564}
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustOsmPrimitive.java

    r30724 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.data;
    23
     
    1112import org.openstreetmap.josm.data.osm.Way;
    1213
    13 abstract public class TrustOsmPrimitive {
     14public abstract class TrustOsmPrimitive {
    1415
    1516    public static String createUniqueObjectIdentifier(OsmPrimitive osm) {
    1617        String id = "";
    17         if(osm instanceof Node) {
     18        if (osm instanceof Node) {
    1819            id = "n";
    19         } else if(osm instanceof Way) {
     20        } else if (osm instanceof Way) {
    2021            id = "w";
    21         } else if(osm instanceof Relation) {
     22        } else if (osm instanceof Relation) {
    2223            id = "r";
    2324        }
     
    3839
    3940    public static TrustOsmPrimitive createTrustOsmPrimitive(OsmPrimitive osm) {
    40         if(osm instanceof Node) {
     41        if (osm instanceof Node) {
    4142            return new TrustNode((Node) osm);
    42         } else if(osm instanceof Way) {
     43        } else if (osm instanceof Way) {
    4344            return new TrustWay(osm);
    44         } else if(osm instanceof Relation) {
     45        } else if (osm instanceof Relation) {
    4546            return new TrustRelation(osm);
    4647        }
     
    6061
    6162    public abstract void setOsmPrimitive(OsmPrimitive osmItem);
    62 
    6363
    6464    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.
    12package org.openstreetmap.josm.plugins.trustosm.data;
    23
     
    1415public class TrustRelation extends TrustOsmPrimitive {
    1516
    16 
    1717    public static RelationMember generateRelationMemberFromSigtext(String sigtext) {
    1818        Pattern p = Pattern.compile("^RelID=(\\w*)\n(\\d*),(.*)");
     
    2020        if (m.matches()) {
    2121            OsmPrimitive osm = createOsmPrimitiveFromUniqueObjectIdentifier(m.group(2));
    22             return new RelationMember(m.group(3),osm);
     22            return new RelationMember(m.group(3), osm);
    2323        }
    2424        return null;
     
    2626
    2727    public static String generateRelationMemberSigtext(TrustRelation trust, String memID) {
    28         Relation r = (Relation)trust.getOsmPrimitive();
     28        Relation r = (Relation) trust.getOsmPrimitive();
    2929        List<RelationMember> members = r.getMembers();
    3030        RelationMember member = null;
     
    4949    @Override
    5050    public void setOsmPrimitive(OsmPrimitive osmItem) {
    51         if(osmItem instanceof Relation) {
     51        if (osmItem instanceof Relation) {
    5252            osm = osmItem;
    5353        } else {
     
    5555        }
    5656    }
    57 
    5857
    5958    public void storeMemberSig(String memID, PGPSignature sig) {
     
    7372        return memberSig;
    7473    }
    75 
    7674}
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/data/TrustSignatures.java

    r30744 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.data;
    23
     
    1718public class TrustSignatures {
    1819
    19     public final static byte SIG_UNKNOWN = 0;
    20     public final static byte SIG_VALID = 1;
    21     public final static byte SIG_BROKEN = -1;
    22     public final static byte 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;
    2324
    2425    //private final Vector<PGPSignature> signatures = new Vector<PGPSignature>();
     
    125126
    126127    public String getArmoredFulltextSignatureAll(String plain) {
    127         if (textsigs.containsKey(plain)){
     128        if (textsigs.containsKey(plain)) {
    128129            List<PGPSignature> l = textsigs.get(plain);
    129130            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.
    12package org.openstreetmap.josm.plugins.trustosm.data;
    23
     
    2728        String[] lines = sigtext.split("\n");
    2829        List<Node> nodes = new ArrayList<>();
    29         for (int i=1; i<lines.length; i++){
     30        for (int i = 1; i < lines.length; i++) {
    3031            nodes.add(TrustNode.generateNodeFromSigtext(lines[i]));
    3132        }
     
    5051    @Override
    5152    public void setOsmPrimitive(OsmPrimitive osmItem) {
    52         if(osmItem instanceof Way) {
     53        if (osmItem instanceof Way) {
    5354            osm = osmItem;
    5455        } else {
     
    5758    }
    5859
    59 
    6060    public void storeSegmentSig(List<Node> nodes, PGPSignature sig) {
    6161        if (segmentSig.containsKey(nodes)) {
    62             segmentSig.get(nodes).addSignature(sig, TrustWay.generateSegmentSigtext(this,nodes));
     62            segmentSig.get(nodes).addSignature(sig, TrustWay.generateSegmentSigtext(this, nodes));
    6363        } 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));
    6565        }
    6666    }
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/DownloadSignedOsmDataTask.java

    r31897 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.gui;
    23
     
    2324import org.xml.sax.SAXException;
    2425
    25 public class DownloadSignedOsmDataTask  extends PleaseWaitRunnable {
     26public class DownloadSignedOsmDataTask extends PleaseWaitRunnable {
    2627
    2728    private boolean canceled;
     
    4142    }
    4243
    43 
    4444    @Override
    4545    protected void cancel() {
    4646        canceled = true;
    47         synchronized(this) {
     47        synchronized (this) {
    4848            if (objectReader != null) {
    4949                objectReader.cancel();
     
    6868                missing.size(),
    6969                "Wurst"
    70         );
     70       );
    7171    }
    7272
     
    8181            progressMonitor.indeterminateSubTask(
    8282                    buildDownloadFeedbackMessage()
    83             );
     83           );
    8484            final DataSet dataSet = objectReader.parseOsm(progressMonitor
    8585                    .createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
     
    100100                        }
    101101                    }
    102             );
     102           );
    103103
    104104        } 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.
    12package org.openstreetmap.josm.plugins.trustosm.gui;
    23
     
    2223    protected void cancel() {
    2324        canceled = true;
    24         synchronized(this) {
     25        synchronized (this) {
    2526            /*        if (objectReader != null) {
    2627                objectReader.cancel();
     
    4041
    4142    @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) {
    4646                if (canceled) return;
    4747                objectReader = new MultiFetchServerObjectReader();
     
    5050            progressMonitor.indeterminateSubTask(
    5151                    buildDownloadFeedbackMessage()
    52             );
     52           );
    5353            final DataSet dataSet = objectReader.parseOsm(progressMonitor
    5454                    .createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false));
     
    6868                        }
    6969                    }
    70             );
    71              */
     70           );
     71
    7272        } catch (Exception e) {
    7373            if (canceled) {
     
    7777            }
    7878            lastException = e;
    79         }
    80 
     79        }*/
    8180    }
    8281
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/gui/KeyTreeTableModel.java

    r31945 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.gui;
    23
     
    2122
    2223    public static String convPGPSignatureToString(PGPSignature s) {
    23         if (s==null) return null;
     24        if (s == null) return null;
    2425        PGPSignatureSubpacketVector sv = s.getHashedSubPackets();
    2526        if (sv != null && sv.hasSubpacket(SignatureSubpacketTags.SIGNER_USER_ID))
     
    2728
    2829        PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(s.getKeyID());
    29         if (pub != null){
     30        if (pub != null) {
    3031            Iterator<?> i = pub.getUserIDs();
    3132            if (i.hasNext())
    32                 return (String)i.next();
     33                return (String) i.next();
    3334
    3435        }
     
    3738
    3839    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")};
    4041    private final List<String> columns = new ArrayList<>(Arrays.asList(allTitle));
    4142
     
    4748                PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(s.getKeyID());
    4849                Iterator<?> iter = pub.getSignatures();
    49                 while (iter.hasNext()){
    50                     PGPSignature ks = (PGPSignature)iter.next();
     50                while (iter.hasNext()) {
     51                    PGPSignature ks = (PGPSignature) iter.next();
    5152                    sn.getChildren().add(new SignatureTreeNode(ks));
    5253                }
     
    6263
    6364    @Override
    64     public String getColumnName( int column ) {
     65    public String getColumnName(int column) {
    6566        String title = columns.get(column);
    6667        if (title != null)
     
    6970    }
    7071
    71 
    7272    @Override
    7373    public Object getValueAt(Object node, int column) {
    74         SignatureTreeNode signode = ( SignatureTreeNode )node;
     74        SignatureTreeNode signode = (SignatureTreeNode) node;
    7575        String title = columns.get(column);
    76         if (title != null){
     76        if (title != null) {
    7777            if (title.equals(allTitle[0]))
    7878                return signode.getUID();
     
    9090    @Override
    9191    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);
    9494    }
    9595
    9696    @Override
    9797    public int getChildCount(Object node) {
    98         SignatureTreeNode signode = ( SignatureTreeNode )node;
     98        SignatureTreeNode signode = (SignatureTreeNode) node;
    9999        return signode.getChildren().size();
    100100    }
    101101
    102102    @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)
    107107                return i;
    108108        }
     
    114114        return root;
    115115    }
    116 
    117116
    118117    public class SignatureTreeNode {
     
    127126        }
    128127
    129         public PGPSignature getSignature(){
     128        public PGPSignature getSignature() {
    130129            return s;
    131130        }
     131
    132132        public String getUID() {
    133133            return convPGPSignatureToString(s);
    134134        }
     135
    135136        public String getKeyID() {
    136137            return "0x"+Long.toHexString(s.getKeyID()).substring(8).toUpperCase();
    137138        }
     139
    138140        public String getOsmCertificate() {
    139141            String cert = "";
    140             for (NotationData nd : s.getHashedSubPackets().getNotationDataOccurrences()){
     142            for (NotationData nd : s.getHashedSubPackets().getNotationDataOccurrences()) {
    141143                if (nd.getNotationName().equals("trustosm@openstreetmap.org")) {
    142144                    cert += nd.getNotationValue();
     
    145147            return cert;
    146148        }
     149
    147150        public String getSignatureDate() {
    148151            return formatter.format(s.getCreationTime());
    149152        }
     153
    150154        public List<SignatureTreeNode> getChildren() {
    151155            return children;
    152156        }
    153 
    154157    }
    155158}
  • 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.
    12package org.openstreetmap.josm.plugins.trustosm.gui.dialogs;
    23
     
    2122        JLabel title;
    2223
    23         public HeaderPanel(String text) {
     24        HeaderPanel(String text) {
    2425
    2526            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());
    2829
     30            addMouseListener(new MouseAdapter() {
     31                @Override
     32                public void mouseClicked(MouseEvent e) {
     33                    expanded = !expanded;
    2934
    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();
    3543
    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            });
    5147        }
    52 
    5348    }
    5449
     
    6257        contentPanel_.setVisible(false);
    6358    }
    64 
    6559}
  • 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.
    12package org.openstreetmap.josm.plugins.trustosm.gui.dialogs;
    23
     
    2930    private JLabel lblMinimized;
    3031
    31 
    3232    public KeySignaturesDialog(PGPPublicKey key) {
    3333        super(new BorderLayout());
     
    3636        Iterator<?> iter = key.getUserIDs();
    3737        if (iter.hasNext()) {
    38             userid = (String)iter.next();
     38            userid = (String) iter.next();
    3939        }
    4040
     
    5252        Iterator<?> iter = key.getSignatures();
    5353        while (iter.hasNext()) {
    54             PGPSignature sig = (PGPSignature)iter.next();
     54            PGPSignature sig = (PGPSignature) iter.next();
    5555            String uid = "0x"+Long.toHexString(sig.getKeyID()).substring(8).toUpperCase();
    5656            p.add(new JLabel(uid));
     
    6767            //setContentVisible(false);
    6868            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));
    7272            lblMinimized.setIcon(ImageProvider.get("misc", "minimized"));
    73         }
    74         else throw new IllegalStateException();
     73        } else throw new IllegalStateException();
    7574    }
    7675
     
    8281            //        setContentVisible(true);
    8382            isCollapsed = false;
    84             setPreferredSize(new Dimension(0,200));
     83            setPreferredSize(new Dimension(0, 200));
    8584            setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
    8685            lblMinimized.setIcon(ImageProvider.get("misc", "normal"));
    87         }
    88         else throw new IllegalStateException();
     86        } else throw new IllegalStateException();
    8987    }
    9088
     
    9593     */
    9694    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) {
    10098                comps[i].setVisible(visible);
    10199            }
     
    105103    /**
    106104     * The title bar displayed in docked mode
    107      *
    108105     */
    109106    protected class TitleBar extends JPanel {
    110         final private JLabel lblTitle;
     107        private final JLabel lblTitle;
    111108
    112109        public TitleBar(String toggleDialogName) {
     
    130127                        }
    131128                    }
    132             );
     129           );
    133130
    134131            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.
    12package org.openstreetmap.josm.plugins.trustosm.gui.dialogs;
    23
     
    6667public class TrustDialog extends ToggleDialog implements SelectionChangedListener, MapViewPaintable {
    6768
    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);
    7775
    7876    /** The check signatures button */
     
    103101            return false;
    104102        }
     103
    105104        @Override public Class<?> getColumnClass(int columnIndex) {
    106105            return String.class;
     
    115114            if (!isRowSelected(row))
    116115                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;
    121120                }
    122121            return c;
     
    142141            if (!isRowSelected(row))
    143142                switch (stat.byteValue()) {
    144                 case -2: c.setBackground( BGCOLOR_REMOVED_ITEM ); break;
    145                 case -1: c.setBackground( BGCOLOR_BROKEN_SIG ); break;
    146                 case 1: c.setBackground( BGCOLOR_VALID_SIG ); break;
    147                 default: c.setBackground( BGCOLOR_NO_SIG ); break;
     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;
    148147                }
    149148            return c;
     
    162161
    163162        // setting up the properties table
    164         propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")});
     163        propertyData.setColumnIdentifiers(new String[]{tr("Key"), tr("Value")});
    165164
    166165        // copy and paste from org.openstreetmap.josm.gui.dialogs.properties.PropertiesDialog
    167166
    168         propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer(){
     167        propertyTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {
    169168            /**
    170169             *
     
    183182                        Map<?, ?> v = (Map<?, ?>) value;
    184183                        if (v.size() != 1) {
    185                             str=tr("<different>");
     184                            str = tr("<different>");
    186185                            c.setFont(c.getFont().deriveFont(Font.ITALIC));
    187186                        } else {
     
    190189                        }
    191190                    }
    192                     ((JLabel)c).setText(str);
     191                    ((JLabel) c).setText(str);
    193192                }
    194193                return c;
     
    196195        });
    197196
    198         geomTree = new JTree( createTree() );
    199 
    200         geomTree.setBackground( BGCOLOR_NO_SIG );
     197        geomTree = new JTree(createTree());
     198
     199        geomTree.setBackground(BGCOLOR_NO_SIG);
    201200        geomTree.setRootVisible(false);
    202         geomTree.setCellRenderer(new DefaultTreeCellRenderer(){
    203 
     201        geomTree.setCellRenderer(new DefaultTreeCellRenderer() {
    204202            @Override
    205203            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) {
    209205                super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
    210 
    211                 DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
     206                DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    212207                if (node.isRoot()) return this;
    213                 setBackgroundNonSelectionColor( BGCOLOR_NO_SIG );
     208                setBackgroundNonSelectionColor(BGCOLOR_NO_SIG);
    214209                Object o = node.getUserObject();
    215                 if (o instanceof OsmPrimitive){
     210                if (o instanceof OsmPrimitive) {
    216211                    OsmPrimitive osm = (OsmPrimitive) o;
    217212                    setIcon(ImageProvider.get(OsmPrimitiveType.from(osm)));
    218213                    setText(osm.getDisplayName(DefaultNameFormatter.getInstance()));
    219 
    220214                    if (osm instanceof Node) {
    221215                        TrustSignatures sigs;
    222216                        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) {
    224219                            byte stat = sigs.getStatus();
    225220                            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;
    230225                            }
    231226                        }
    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) {
    237229                    WaySegment seg = (WaySegment) o;
    238230                    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()));
    240234                    TrustSignatures sigs;
    241235                    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 (stat) {
    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;
    249243                        }
    250244                    }
     
    263257                selectedPrimitives.clear();
    264258                selectedSegments.clear();
    265                 if (geomTree.getSelectionPaths()!=null)
     259                if (geomTree.getSelectionPaths() != null)
    266260                    for (TreePath tp : geomTree.getSelectionPaths()) {
    267261                        Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject();
     
    278272        });
    279273
    280         propertyTable.addFocusListener(new FocusListener(){
     274        propertyTable.addFocusListener(new FocusListener() {
    281275
    282276            @Override
    283277            public void focusGained(FocusEvent fe) {
    284278                geomTree.clearSelection();
    285 
    286279            }
    287280
     
    292285        });
    293286
    294         geomTree.addFocusListener(new FocusListener(){
     287        geomTree.addFocusListener(new FocusListener() {
    295288
    296289            @Override
     
    318311
    319312        createLayout(dataPanel, true, Arrays.asList(new SideButton[] {
    320             checkButton, signButton, showButton
     313                checkButton, signButton, showButton
    321314        }));
    322315        DataSet.addSelectionListener(this);
     
    325318    private class CheckAction extends JosmAction {
    326319
    327         public CheckAction() {
     320        CheckAction() {
    328321            super(tr("Check"), "checksignatures", tr("Check all available signatures for selected object."), null, false);
    329322        }
     
    336329                    if (TrustOSMplugin.signedItems.containsKey(id))
    337330                        TrustAnalyzer.checkEverything(TrustOSMplugin.signedItems.get(id));
    338                     //checkedItems.put(osm, TrustOSMplugin.gpg.check(checkedItems.containsKey(osm)? checkedItems.get(osm) : new TrustOSMItem(osm)));
    339331                }
    340332            }
     
    346338    private class SignAction extends JosmAction {
    347339
    348         public SignAction() {
     340        SignAction() {
    349341            super(tr("Sign"), "sign", tr("Digital sign selected Tags, if you believe they are correct."), null, false);
    350342        }
     
    354346            if (osmData != null) {
    355347                for (int i : propertyTable.getSelectedRows()) {
    356                     String key = (String)propertyTable.getValueAt(i, 0);
     348                    String key = (String) propertyTable.getValueAt(i, 0);
    357349                    for (OsmPrimitive osm : osmData) {
    358350                        if (osm.keySet().contains(key)) {
    359351                            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);
    361354                            if (TrustOSMplugin.gpg.signTag(trust, key))
    362355                                TrustOSMplugin.signedItems.put(id, trust);
     
    365358                }
    366359            }
    367             if (geomTree.getSelectionPaths()!=null)
     360            if (geomTree.getSelectionPaths() != null)
    368361                for (TreePath tp : geomTree.getSelectionPaths()) {
    369362                    Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject();
     
    373366                        if (osm instanceof Node) {
    374367                            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);
    376370                            trust.storeNodeSig(TrustOSMplugin.gpg.signNode(osmNode));
    377371                            TrustOSMplugin.signedItems.put(id, trust);
    378 
    379372
    380373                            /*                        TreePath parentPath = tp.getParentPath();
     
    386379                                id = String.valueOf(osm.getUniqueId());
    387380                            }
    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);
    389383                            trust.storeNodeSig(osmNode, TrustOSMplugin.gpg.signNode(osm,osmNode));
    390384                            TrustOSMplugin.signedItems.put(id, trust);
    391385                             */
    392386                        } 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)));
    394389                            /*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);
    396392                            trust.storeSegmentSig(TrustOSMplugin.gpg.signWay(osmWay));
    397393                            TrustOSMplugin.signedItems.put(id, trust);
     
    407403                        Way w = seg.way;
    408404                        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));
    411408                        TrustOSMplugin.signedItems.put(id, trust);
    412409                    }
     
    419416    private class ShowAction extends JosmAction {
    420417
    421         public ShowAction() {
     418        ShowAction() {
    422419            super(tr("Show"), "showsig", tr("Show all available signatures for selected attribute."), null, false);
    423420        }
     
    427424            if (osmData != null) {
    428425                for (int i : propertyTable.getSelectedRows()) {
    429                     String key = (String)propertyTable.getValueAt(i, 0);
     426                    String key = (String) propertyTable.getValueAt(i, 0);
    430427                    for (OsmPrimitive osm : osmData) {
    431428                        String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm);
     
    436433                }
    437434            }
    438             if (geomTree.getSelectionPaths()!=null) {
     435            if (geomTree.getSelectionPaths() != null) {
    439436                for (TreePath tp : geomTree.getSelectionPaths()) {
    440437                    Object o = ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject();
     
    446443                                TrustSignaturesDialog.showSignaturesDialog((TrustNode) TrustOSMplugin.signedItems.get(id));
    447444                            }
    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                        }*/
    451449                    } else if (o instanceof WaySegment) {
    452450                        WaySegment seg = (WaySegment) o;
     
    456454                            nodes.add(seg.getFirstNode());
    457455                            nodes.add(seg.getSecondNode());
    458                             TrustSignaturesDialog.showSignaturesDialog((TrustWay) TrustOSMplugin.signedItems.get(id),nodes);
     456                            TrustSignaturesDialog.showSignaturesDialog((TrustWay) TrustOSMplugin.signedItems.get(id), nodes);
    459457                        }
    460458                    }
     
    468466        TrustSignatures sigs;
    469467        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);
    471470        } else {
    472471            JPanel p = new JPanel();
    473472            p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
    474             Dimension d = new Dimension(0,20);
     473            Dimension d = new Dimension(0, 20);
    475474            JLabel head = new JLabel(tr("Selected key value pair was:\n{0}={1}",key,trust.getOsmItem().get(key)));
    476475            head.setAlignmentX(LEFT_ALIGNMENT);
     
    483482                sigtext.setAlignmentX(LEFT_ALIGNMENT);
    484483                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()));
    486486                siginfo.setAlignmentX(LEFT_ALIGNMENT);
    487487                p.add(siginfo);
     
    491491            JScrollPane scroller = new JScrollPane(p);
    492492            JPanel content = new JPanel();
    493             content.setMaximumSize(new Dimension(600,500));
     493            content.setMaximumSize(new Dimension(600, 500));
    494494            content.add(scroller);
    495495            JOptionPane.showMessageDialog(Main.parent,content, tr("Clearsigned Signature"), JOptionPane.PLAIN_MESSAGE);
     
    500500        List<WaySegment> segList = new ArrayList<>();
    501501        for (int i = 0; i < w.getNodesCount()-1; i++) {
    502             segList.add(new WaySegment(w,i));
     502            segList.add(new WaySegment(w, i));
    503503        }
    504504        return segList;
    505505    }
    506506
    507     private DefaultTreeModel createTree(){
     507    private DefaultTreeModel createTree() {
    508508        DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    509509        DefaultMutableTreeNode wayNode;
    510         if (osmData!=null)
     510        if (osmData != null)
    511511            for (OsmPrimitive osm : osmData) {
    512512                //String id = TrustOsmPrimitive.createUniqueObjectIdentifier(osm);
    513                 if(osm instanceof Node) {
     513                if (osm instanceof Node) {
    514514                    root.add(new DefaultMutableTreeNode(osm));
    515                 } else if(osm instanceof Way) {
     515                } else if (osm instanceof Way) {
    516516                    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) {
    519519                        wayNode.add(new DefaultMutableTreeNode(seg));
    520520                    }
     
    542542                     */
    543543                    root.add(wayNode);
    544                 } else if(osm instanceof Relation) {
     544                } else if (osm instanceof Relation) {
    545545
    546546                }
     
    575575                    for (String removedKey: removedKeys) {
    576576                        TrustSignatures sigs = signedTags.get(removedKey);
    577                         sigs.setStatus( TrustSignatures.ITEM_REMOVED );
     577                        sigs.setStatus( TrustSignatures.ITEM_REMOVED);
    578578                        String[] kv = TrustOsmPrimitive.generateTagsFromSigtext(sigs.getOnePlainText());
    579579                        tags.put(kv[0],kv[1]);
     
    585585                }
    586586
    587                 //        trust = TrustOSMplugin.signedItems.containsKey(osm) ? TrustOSMplugin.signedItems.get(osm) : new TrustOSMItem(osm);
    588 
    589587                for (String key: osm.keySet()) {
    590588                    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);
    595593                    Byte sigstatus = new Byte(status);
    596594                    Byte newstatus;
    597595                    if (sigstatus.equals(new Byte(TrustSignatures.SIG_BROKEN)) || oldstatus.equals(new Byte(TrustSignatures.SIG_BROKEN))) {
    598596                        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))) {
    600599                        newstatus = new Byte(TrustSignatures.SIG_UNKNOWN);
    601600                    } else newstatus = new Byte(TrustSignatures.SIG_VALID);
    602601
    603                     rowStatus.put(key, newstatus );
     602                    rowStatus.put(key, newstatus);
    604603                    if (valueCount.containsKey(key)) {
    605604                        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);
    607606                    } else {
    608                         TreeMap<String,Integer> v = new TreeMap<>();
     607                        TreeMap<String, Integer> v = new TreeMap<>();
    609608                        v.put(value, 1);
    610609                        valueCount.put(key, v);
     
    613612            }
    614613            for (Entry<String, Map<String, Integer>> e : valueCount.entrySet()) {
    615                 int count=0;
     614                int count = 0;
    616615                for (Entry<String, Integer> e1: e.getValue().entrySet()) {
    617                     count+=e1.getValue();
     616                    count += e1.getValue();
    618617                }
    619618                if (count < osmData.size()) {
     
    639638        geomTree.setModel(createTree());
    640639        updateTable();
    641         //        signButton.setEnabled(newSelection.size() == 1);
    642640    }
    643641
     
    657655        for (WaySegment seg : selectedSegments) {
    658656            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);
    663662
    664663            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.
    12package org.openstreetmap.josm.plugins.trustosm.gui.dialogs;
    23
     
    2324public class TrustPreferenceEditor extends DefaultTabPreferenceSetting {
    2425
    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()));
    2832
    2933    public TrustPreferenceEditor() {
     
    3943        JPanel gpgsettings = new JPanel(new GridBagLayout());
    4044
    41         gpgsettings.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     45        gpgsettings.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    4246
    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));
    4448        ButtonGroup gpgdirGroup = new ButtonGroup();
    4549        gpgdirGroup.add(separateHomedir);
     
    5155            defaultHomedir.setSelected(true);
    5256
    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));
    5559
    5660        gpgsettings.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
    5761        JScrollPane scrollpane = new JScrollPane(gpgsettings);
    58         scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 ));
     62        scrollpane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    5963        tabs.add(tr("GnuPG"), scrollpane);
    6064
    6165        JPanel dialogsettings = new JPanel(new GridBagLayout());
    6266        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));
    6468    }
    6569
  • 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.
    12package org.openstreetmap.josm.plugins.trustosm.gui.dialogs;
    23
     
    3536import org.openstreetmap.josm.tools.ImageProvider;
    3637
    37 
    38 
    39 public class TrustSignaturesDialog {
    40 
     38public final class TrustSignaturesDialog {
     39
     40    private TrustSignaturesDialog() {
     41        // Hide default constructors for utilities classes
     42    }
    4143
    4244    private static String createLabel(String plain, int type) {
    4345        if (type == 0) {
    4446            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]);
    4648        } else if (type == 1) {
    4749            Node node = TrustNode.generateNodeFromSigtext(plain);
    48             //return tr("Signed node was: {0}", node.getDisplayName(DefaultNameFormatter.getInstance()));
    4950            return "ID:"+node.getUniqueId()+" ("+node.getCoor().toString() + ")";
    5051        } else if (type == 2) {
     
    5758    private static void showDialog(TrustSignatures sigs, String label, int type) {
    5859        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());
    6261
    6362        for (String plain : sigs.getAllPlainTexts()) {
     
    6766            textcontent.add(sigtext);
    6867
    69             p.add(new JCollapsiblePanel(createLabel(plain, type),textcontent),GBC.eol());
     68            p.add(new JCollapsiblePanel(createLabel(plain, type), textcontent), GBC.eol());
    7069
    7170            List<PGPSignature> siglist = sigs.getSignaturesByPlaintext(plain);
    7271            JPanel signerPanel = new JPanel(new GridBagLayout());
    73             //signerPanel.add(createSignerTree(siglist));
    7472            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);
    7874            t.addMouseListener(new MouseAdapter() {
    7975                @Override
     
    8379                        if (selPath == null)
    8480                            return;
    85                         SignatureTreeNode sn = (SignatureTreeNode)selPath.getLastPathComponent();
     81                        SignatureTreeNode sn = (SignatureTreeNode) selPath.getLastPathComponent();
    8682                        PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(sn.getSignature().getKeyID());
    8783                        TrustGPG.showKeyDetails(pub);
     
    9793            signerPanel.add(new JScrollPane(t));
    9894
    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));
    10896        }
    10997        p.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH));
    11098        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));
    115100        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);
    118103        info.showDialog();
    119104    }
    120 
    121105
    122106    public static void showSignaturesDialog(TrustNode trust) {
    123107        TrustSignatures sigs;
    124108        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);
    126111        } 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);
    129114        }
    130115    }
     
    133118        TrustSignatures sigs;
    134119        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);
    136122        } 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);
    138124        }
    139125    }
     
    142128        TrustSignatures sigs;
    143129        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);
    145132        } else {
    146133            showDialog(sigs, tr("Selected WaySegment was:"), 2);
     
    187174
    188175        PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(s.getKeyID());
    189         if (pub != null){
     176        if (pub != null) {
    190177            Iterator i = pub.getUserIDs();
    191178            if (i.hasNext())
     
    197184    public static JTree createSignerTree(Collection<PGPSignature> sigs) {
    198185        DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    199         for (PGPSignature s : sigs){
     186        for (PGPSignature s : sigs) {
    200187            DefaultMutableTreeNode sn = new DefaultMutableTreeNode(s);
    201188            PGPPublicKey pub = TrustOSMplugin.gpg.getPublicKeyFromRing(s.getKeyID());
    202189            Iterator iter = pub.getSignatures();
    203             while (iter.hasNext()){
     190            while (iter.hasNext()) {
    204191                PGPSignature ks = (PGPSignature)iter.next();
    205192                sn.add(new DefaultMutableTreeNode(ks));
     
    212199        t.setRootVisible(false);
    213200        t.setBackground(TrustDialog.BGCOLOR_NO_SIG);
    214         t.setCellRenderer(new DefaultTreeCellRenderer(){
     201        t.setCellRenderer(new DefaultTreeCellRenderer() {
    215202
    216203            @Override
     
    229216                setBackgroundNonSelectionColor(TrustDialog.BGCOLOR_NO_SIG);
    230217                if (sv.hasSubpacket(SignatureSubpacketTags.NOTATION_DATA)) {
    231                     for (NotationData nd : sv.getNotationDataOccurences()){
     218                    for (NotationData nd : sv.getNotationDataOccurences()) {
    232219                        System.out.println(nd.getNotationName()+"="+nd.getNotationValue());
    233220                        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.
    12package org.openstreetmap.josm.plugins.trustosm.io;
    23
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigImporter.java

    r32511 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.io;
    23
     
    4950        }
    5051        //        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);
    5253        System.out.println(trustitems.size());
    5354        /*
     
    5758            JOptionPane.showMessageDialog(Main.parent, tr("{0} Signatures loaded. All referenced OSM objects found.",itemCount));
    5859        } 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);
    6063
    6164            if (n == JOptionPane.YES_OPTION) {
     
    6770        new GetMissingDataAction().downloadMissing();
    6871        //TrustOSMplugin.signedItems.putAll(TrustStoreHandler.loadSigsFromFile(in));
    69 
    7072    }
    7173}
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigReader.java

    r32511 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.io;
    23
     
    4748public class SigReader {
    4849
    49     private final Map<String,TrustOsmPrimitive> trustitems = new HashMap<>();
     50    private final Map<String, TrustOsmPrimitive> trustitems = new HashMap<>();
    5051    private final Set<OsmPrimitive> missingData = new HashSet<>();
    5152
    52     public Map<String,TrustOsmPrimitive> getTrustItems() {
     53    public Map<String, TrustOsmPrimitive> getTrustItems() {
    5354        return trustitems;
    5455    }
     
    7576        private TrustOsmPrimitive trust;
    7677
    77 
    7878        /**
    7979         * The current Signatures.
     
    8181        private TrustSignatures tsigs;
    8282
    83 
    8483        private StringBuffer tmpbuf = new StringBuffer();
    85 
    8684
    8785        @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
     
    9492
    9593                    String osmid = atts.getValue("osmid");
    96                     if (osmid == null){
     94                    if (osmid == null) {
    9795                        throwException(tr("Missing mandatory attribute ''{0}''.", "osmid"));
    9896                    } else if (!osmid.matches("\\d+")) {
     
    131129                trustitems.put(TrustOsmPrimitive.createUniqueObjectIdentifier(trust.getOsmPrimitive()), trust);
    132130            } else if (qName.equals("openpgp")) {
    133                 // System.out.println(tmpbuf.toString());
    134131                try {
    135132                    parseOpenPGP(tmpbuf.toString());
    136133                } 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);
    138135                }
    139136            } else if (qName.equals("key")) {
     
    141138                trust.setTagRatings(kv[0], tsigs);
    142139            } else if (qName.equals("node")) {
    143                 ((TrustNode)trust).setNodeRatings(tsigs);
     140                ((TrustNode) trust).setNodeRatings(tsigs);
    144141            } else if (qName.equals("segment")) {
    145142                List<Node> nodes = TrustWay.generateSegmentFromSigtext(tsigs.getOnePlainText());
    146                 ((TrustWay)trust).setSegmentRatings(nodes,tsigs);
     143                ((TrustWay) trust).setSegmentRatings(nodes, tsigs);
    147144            } else if (qName.equals("member")) {
    148145                RelationMember member = TrustRelation.generateRelationMemberFromSigtext(tsigs.getOnePlainText());
    149                 ((TrustRelation)trust).setMemberRating(TrustOsmPrimitive.createUniqueObjectIdentifier(member.getMember()), tsigs);
     146                ((TrustRelation) trust).setMemberRating(TrustOsmPrimitive.createUniqueObjectIdentifier(member.getMember()), tsigs);
    150147            }
    151148        }
     
    178175            plain = plain.substring(0, plain.length()-1);
    179176
    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++) {
    182179                tsigs.addSignature(siglist.get(i), plain);
    183180            }
    184 
    185 
    186         }
    187 
    188 
     181        }
    189182    }
    190183
     
    199192     * @throws IllegalArgumentException thrown if source is null
    200193     */
    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 {
    202196        if (progressMonitor == null) {
    203197            progressMonitor = NullProgressMonitor.INSTANCE;
     
    216210
    217211            return reader.getTrustItems();
    218         } catch(ParserConfigurationException e) {
     212        } catch (ParserConfigurationException e) {
    219213            throw new IllegalDataException(e.getMessage(), e);
    220214        } catch (SAXParseException e) {
    221215            throw new IllegalDataException(tr("Line {0} column {1}: ", e.getLineNumber(), e.getColumnNumber()) + e.getMessage(), e);
    222         } catch(SAXException e) {
     216        } catch (SAXException e) {
    223217            throw new IllegalDataException(e.getMessage(), e);
    224         } catch(Exception e) {
     218        } catch (Exception e) {
    225219            throw new IllegalDataException(e);
    226220        } finally {
     
    228222        }
    229223    }
    230 
    231 
    232224}
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/io/SigWriter.java

    r30724 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.io;
    23
     
    7576    private void writeSigs(TrustSignatures tsigs) {
    7677        for (String plain : tsigs.getAllPlainTexts()) {
    77             simpleTag("openpgp",tsigs.getArmoredFulltextSignatureAll(plain));
    78         }
    79 
     78            simpleTag("openpgp", tsigs.getArmoredFulltextSignatureAll(plain));
     79        }
    8080    }
    8181
     
    8686        openln("tags");
    8787        for (String key : signedKeys) {
    88             openAtt("key","k=\""+key+"\"");
    89 
     88            openAtt("key", "k=\""+key+"\"");
    9089            writeSigs(tagsigs.get(key));
    91 
    9290            closeln("key");
    9391        }
     
    131129    private void writeItems(Collection<TrustOsmPrimitive> items) {
    132130
    133         for (TrustOsmPrimitive trust : items){
     131        for (TrustOsmPrimitive trust : items) {
    134132            OsmPrimitive osm = trust.getOsmPrimitive();
    135133            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.
    12package org.openstreetmap.josm.plugins.trustosm.util;
    23
     
    5354    ArrayList<String> sur = new ArrayList<>();
    5455
    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'};
    5760
    5861    private String fileName;
     
    6164     * Create new random name generator object. refresh() is automatically called.
    6265     * @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 {
    6668        this.fileName = fileName;
    6769        refresh();
     
    7173     * Change the file. refresh() is automatically called during the process.
    7274     * @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");
    7778        this.fileName = fileName;
    7879        refresh();
     
    8283     * 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
    8384     * 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) {
    9392                line = bufRead.readLine();
    9493                if (line != null && !line.equals("")) {
    95                     if(line.charAt(0) == '-') {
     94                    if (line.charAt(0) == '-') {
    9695                        pre.add(line.substring(1).toLowerCase());
    9796                    } else if (line.charAt(0) == '+') {
     
    106105
    107106    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));
    109108    }
    110109
    111110    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) {
    157159        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);
    159161        return s.split(" ")[0];
    160162    }
    161163
    162     private boolean vocalFirst(String s){
     164    private boolean vocalFirst(String s) {
    163165        return (String.copyValueOf(vocals).contains(String.valueOf(s.charAt(0)).toLowerCase()));
    164166    }
    165167
    166     private boolean consonantFirst(String s){
     168    private boolean consonantFirst(String s) {
    167169        return (String.copyValueOf(consonants).contains(String.valueOf(s.charAt(0)).toLowerCase()));
    168170    }
    169171
    170     private boolean vocalLast(String s){
     172    private boolean vocalLast(String s) {
    171173        return (String.copyValueOf(vocals).contains(String.valueOf(s.charAt(s.length()-1)).toLowerCase()));
    172174    }
    173175
    174     private boolean consonantLast(String s){
     176    private boolean consonantLast(String s) {
    175177        return (String.copyValueOf(consonants).contains(String.valueOf(s.charAt(s.length()-1)).toLowerCase()));
    176178    }
    177179
     180    // CHECKSTYLE.OFF: LineLength
    178181
    179182    /**
     
    183186     * @throws RuntimeException when logical mistakes are detected inside chosen file, and program is unable to complete the name.
    184187     */
    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");
    191200        int expecting = 0; // 1 for vocal, 2 for consonant
    192201        int last = 0; // 1 for vocal, 2 for consonant
    193202        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;
    197206        else last = 2;
    198207
    199         if(syls > 2){
    200             if(expectsVocal(pre.get(a))){
     208        if (syls > 2) {
     209            if (expectsVocal(pre.get(a))) {
    201210                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))) {
    206215                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))) {
    213221                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))) {
    218226                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, " +
    224232                "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, " +
    228236                "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
    239245                    || last == 1 && hatesPreviousVocals(mid.get(b[i])) || last == 2 && hatesPreviousConsonants(mid.get(b[i])));
    240246
    241247            expecting = 0;
    242             if(expectsVocal(mid.get(b[i]))){
     248            if (expectsVocal(mid.get(b[i]))) {
    243249                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]))) {
    250256                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, " +
    257263                    "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, " +
    261267                    "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, " +
    265271                        "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, " +
    269275                        "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;
    273279            else last = 2;
    274280        }
    275281
    276282        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
    281286                || last == 1 && hatesPreviousVocals(sur.get(c)) || last == 2 && hatesPreviousConsonants(sur.get(c)));
    282287
    283288        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++) {
    285290            name = name.concat(pureSyl(mid.get(b[i]).toLowerCase()));
    286291        }
    287         if(syls > 1)
     292        if (syls > 1)
    288293            name = name.concat(pureSyl(sur.get(c).toLowerCase()));
    289294        return name;
    290295    }
     296    // CHECKSTYLE.ON: LineLength
    291297}
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/SpringUtilities.java

    r26055 r32533  
    2828 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    2929 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    30  */
    31 
     30 */
    3231package org.openstreetmap.josm.plugins.trustosm.util;
    3332
    34 import javax.swing.*;
     33import java.awt.Component;
     34import java.awt.Container;
     35
     36import javax.swing.Spring;
    3537import javax.swing.SpringLayout;
    36 import java.awt.*;
    3738
    3839/**
     
    4243 * SpringBox and SpringCompactGrid.
    4344 */
    44 public class SpringUtilities {
     45public final class SpringUtilities {
     46
     47    private SpringUtilities() {
     48        // Hide default constructors for utilities classes
     49    }
     50
    4551    /**
    4652     * A debugging utility that prints to stdout the component's
     
    7379        SpringLayout layout;
    7480        try {
    75             layout = (SpringLayout)parent.getLayout();
     81            layout = (SpringLayout) parent.getLayout();
    7682        } catch (ClassCastException exc) {
    7783            System.err.println("The first argument to makeGrid must use SpringLayout.");
     
    176182        SpringLayout layout;
    177183        try {
    178             layout = (SpringLayout)parent.getLayout();
     184            layout = (SpringLayout) parent.getLayout();
    179185        } catch (ClassCastException exc) {
    180186            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.
    12package org.openstreetmap.josm.plugins.trustosm.util;
    23
     
    2021import org.openstreetmap.josm.plugins.trustosm.data.TrustWay;
    2122
    22 public class TrustAnalyzer {
    23 
    24     public static void showManipulationWarning(){
     23public final class TrustAnalyzer {
     24
     25    private TrustAnalyzer() {
     26        // Hide default constructors for utilities classes
     27    }
     28
     29    public static void showManipulationWarning() {
    2530        JOptionPane.showMessageDialog(Main.parent, tr("The Signature is broken!"), tr("Manipulation Warning"), JOptionPane.WARNING_MESSAGE);
    2631    }
    27 
    2832
    2933    public static double computeReputation(TrustOsmPrimitive trust, Map<String, List<PGPSignature>> textsigs) {
     
    3842    public static boolean isTagRatingValid(TrustOsmPrimitive trust, String key, String signedPlaintext) {
    3943        /** 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);
    4145        return currentSigtext.equals(signedPlaintext);
    4246    }
    43 
    4447
    4548    public static void checkTag(TrustOsmPrimitive trust, String key) {
     
    4750
    4851        TrustSignatures sigs;
    49         if ((sigs = trust.getSigsOnKey(key))!=null) {
     52        if ((sigs = trust.getSigsOnKey(key)) != null) {
    5053            for (PGPSignature sig : sigs.getSignatures()) {
    5154                /** Here we have a full rating
     
    5861                     * Second question: Is the rating valid?
    5962                     */
    60                     if (isTagRatingValid(trust,key,signedPlaintext)) {
     63                    if (isTagRatingValid(trust, key, signedPlaintext)) {
    6164                        /** if the rating is good, we can try to compute a reputation value at the end
    6265                         *  so we save the important rating stuff
     
    7174
    7275                        //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                    }*/
    7679                } else {
    7780                    //sigs.setStatus(TrustSignatures.SIG_BROKEN);
     
    8891    }
    8992
    90 
    9193    public static boolean isNodeRatingValid(TrustNode trust, String signedPlaintext, PGPSignature sig) {
    9294        /** Rating is valid if Node from signed plaintext is inside Tolerance given in Signature */
    9395        Node signedNode = TrustNode.generateNodeFromSigtext(signedPlaintext);
    94         Node currentNode = (Node)trust.getOsmPrimitive();
     96        Node currentNode = (Node) trust.getOsmPrimitive();
    9597        double dist = signedNode.getCoor().greatCircleDistance(currentNode.getCoor());
    9698
    9799        /** is distance between signed Node and current Node inside tolerance? */
    98         return dist<=TrustGPG.searchTolerance(sig);
     100        return dist <= TrustGPG.searchTolerance(sig);
    99101    }
    100102
     
    106108    public static void checkNode(TrustNode trust) {
    107109        Map<String, List<PGPSignature>> validRatings = new HashMap<>();
    108         //Node node = (Node)trust.getOsmPrimitive();
    109110        TrustSignatures sigs;
    110         if ((sigs = trust.getNodeSigs())!=null) {
     111        if ((sigs = trust.getNodeSigs()) != null) {
    111112            for (String signedPlaintext : sigs.getAllPlainTexts()) {
    112113                for (PGPSignature sig : sigs.getSignaturesByPlaintext(signedPlaintext)) {
    113114                    /** first thing: check signature */
    114                     if (TrustOSMplugin.gpg.verify(signedPlaintext,sig)) {
     115                    if (TrustOSMplugin.gpg.verify(signedPlaintext, sig)) {
    115116                        /** if signature is valid check rating */
    116                         if (isNodeRatingValid(trust,signedPlaintext,sig)) {
     117                        if (isNodeRatingValid(trust, signedPlaintext, sig)) {
    117118                            /** if the rating is good, we can try to compute a reputation value at the end
    118119                             *  so we save the important rating stuff
     
    127128
    128129                            //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                        }*/
    133133                    } else {
    134134                        //sigs.setStatus(TrustSignatures.SIG_BROKEN);
     
    147147    /**
    148148     * Check if the ratings made for a specific WaySegment are valid for the current form of that WaySegment
    149      * @param trust
    150      * @param seg
    151      * @param signedPlaintext
    152      * @param sig
    153      * @return
    154149     */
    155150    public static boolean isSegmentRatingValid(TrustWay trust, List<Node> nodes, String signedPlaintext, PGPSignature sig) {
     
    159154        double tolerance = TrustGPG.searchTolerance(sig);
    160155
    161         for (int i = 0; i<2; i++){
     156        for (int i = 0; i < 2; i++) {
    162157            Node signedNode = signedSegment.get(i);
    163158            Node currentNode = nodes.get(i);
    164159            double dist = signedNode.getCoor().greatCircleDistance(currentNode.getCoor());
    165             if (dist>tolerance) return false;
     160            if (dist > tolerance) return false;
    166161        }
    167162        return true;
     
    178173
    179174        TrustSignatures sigs;
    180         if ((sigs = trust.getSigsOnSegment(nodes))!=null) {
     175        if ((sigs = trust.getSigsOnSegment(nodes)) != null) {
    181176            for (String signedPlaintext : sigs.getAllPlainTexts()) {
    182177                for (PGPSignature sig : sigs.getSignaturesByPlaintext(signedPlaintext)) {
    183178                    /** first thing: check signature */
    184                     if (TrustOSMplugin.gpg.verify(signedPlaintext,sig)) {
     179                    if (TrustOSMplugin.gpg.verify(signedPlaintext, sig)) {
    185180                        /** if signature is valid check rating */
    186                         if (isSegmentRatingValid(trust,nodes,signedPlaintext,sig)) {
     181                        if (isSegmentRatingValid(trust, nodes, signedPlaintext, sig)) {
    187182                            /** if the rating is good, we can try to compute a reputation value at the end
    188183                             *  so we save the important rating stuff
     
    197192
    198193                            //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                        }*/
    203197                    } else {
    204198                        //sigs.setStatus(TrustSignatures.SIG_BROKEN);
     
    215209    }
    216210
    217 
    218211    public static void checkEverything(TrustOsmPrimitive trust) {
    219212        /** check every single tag for reputation */
    220         for (String key : trust.getSignedKeys()){
     213        for (String key : trust.getSignedKeys()) {
    221214            checkTag(trust, key);
    222215        }
     
    224217            /** check all reputation of this single Node */
    225218            checkNode((TrustNode) trust);
    226         } else if (trust instanceof TrustWay){
     219        } else if (trust instanceof TrustWay) {
    227220            TrustWay tw = (TrustWay) trust;
    228221            /** 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++) {
    231224                List<Node> nodes = new ArrayList<>();
    232225                nodes.add(wayNodes.get(i));
    233226                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) {
    238230            TrustRelation tr = (TrustRelation) trust;
    239231        }*/
    240 
    241232    }
    242233}
  • applications/editors/josm/plugins/trustosm/src/org/openstreetmap/josm/plugins/trustosm/util/TrustGPG.java

    r31945 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.trustosm.util;
    23
     
    135136        Iterator<?> iter = k.getUserIDs();
    136137        if (iter.hasNext()) {
    137             keyText += (String)iter.next();
     138            keyText += (String) iter.next();
    138139        }
    139140        /*            iter = sigKey.getUserIDs();
     
    172173        while (rIt.hasNext()) {
    173174
    174             PGPSecretKeyRing    kRing = (PGPSecretKeyRing)rIt.next();
    175             Iterator<?>            kIt = kRing.getSecretKeys();
     175            PGPSecretKeyRing kRing = (PGPSecretKeyRing) rIt.next();
     176            Iterator<?> kIt = kRing.getSecretKeys();
    176177
    177178            while (kIt.hasNext()) {
    178                 PGPSecretKey    k = (PGPSecretKey)kIt.next();
     179                PGPSecretKey k = (PGPSecretKey) kIt.next();
    179180
    180181                if (k.isSigningKey()) {
     
    196197        JPanel p = new JPanel();
    197198        p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
    198         Dimension d = new Dimension(0,20);
     199        Dimension d = new Dimension(0, 20);
    199200
    200201        JLabel head = new JLabel(tr("Select a signing key from your keyring-file:"));
     
    212213        JButton detailsButton = new JButton(tr("Details"), ImageProvider.get("keydetails"));
    213214        detailsButton.setAlignmentX(Component.LEFT_ALIGNMENT);
    214         detailsButton.addActionListener(new ActionListener(){
    215 
     215        detailsButton.addActionListener(new ActionListener() {
    216216            @Override
    217217            public void actionPerformed(ActionEvent arg0) {
    218218                PGPSecretKey sk = sigKeys.get(keyBox.getSelectedIndex());
    219219                showKeyDetails(getPublicKeyFromRing(sk.getKeyID()));
    220             }});
     220            } });
    221221        p.add(detailsButton);
    222222
     
    229229        JButton createButton = new JButton(tr("Create new Key"), ImageProvider.get("key"));
    230230        createButton.setAlignmentX(Component.LEFT_ALIGNMENT);
    231         createButton.addActionListener(new ActionListener(){
     231        createButton.addActionListener(new ActionListener() {
    232232
    233233            @Override
     
    239239                        sigKeys.add(secKey);
    240240                    }
    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);
    256243                }
    257 
    258             }});
     244            } });
    259245        p.add(createButton);
    260246        p.add(Box.createRigidArea(d));
    261247
    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);
    263250
    264251        if (n == JOptionPane.OK_OPTION) {
     
    273260            pgpSecKey = null;
    274261        }
    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;
    280262    }
    281263
     
    301283        String path = Main.pref.getPluginsDirectory().getPath();
    302284        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")) {
    304286            pgpSec.encode(secOut);
    305287            pgpPub.encode(pubOut);
     
    314296        JOptionPane jop = new JOptionPane(passwordField, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, ImageProvider.get("lock"));
    315297        JDialog dialog = jop.createDialog("Password:");
    316         dialog.addComponentListener(new ComponentAdapter(){
     298        dialog.addComponentListener(new ComponentAdapter() {
    317299            @Override
    318             public void componentShown(ComponentEvent e){
     300            public void componentShown(ComponentEvent e) {
    319301                passwordField.requestFocusInWindow();
    320302            }
    321303        });
    322304        dialog.setVisible(true);
    323         int result = (Integer)jop.getValue();
     305        int result = (Integer) jop.getValue();
    324306        dialog.dispose();
    325         if(result == JOptionPane.OK_OPTION){
     307        if (result == JOptionPane.OK_OPTION) {
    326308            password = passwordField.getPassword();
    327309        }
    328 
    329310
    330311        /*final JPasswordField passwordField = new JPasswordField(10);
     
    343324    }
    344325
    345 
    346 
    347326    /*    public void checkAll(TrustOsmPrimitive trust) {
    348327        OsmPrimitive osm = trust.getOsmPrimitive();
     
    351330        }
    352331
    353         if(osm instanceof Node) {
     332        if (osm instanceof Node) {
    354333            checkNode((TrustNode) trust);
    355         } else if(osm instanceof Way) {
     334        } else if (osm instanceof Way) {
    356335            /*            Iterator<Node> iter = ((Way)osm).getNodes().iterator();
    357336            while (iter.hasNext()) {
    358337                checkNode(trust, iter.next());
    359338            }/
    360         } else if(osm instanceof Relation) {
     339        } else if (osm instanceof Relation) {
    361340
    362341        }
     
    365344
    366345    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
    368352    }
    369353    /*
     
    377361            return trust;
    378362        }
    379         if(osm instanceof Node) {
     363        if (osm instanceof Node) {
    380364            s = signNode(osm,(Node)osm, spGen);
    381365            if (s != null) ((TrustNode)trust).storeNodeSig(s);
    382         } else if(osm instanceof Way) {
     366        } else if (osm instanceof Way) {
    383367            Iterator<Node> iter = ((Way)osm).getNodes().iterator();
    384368            while (iter.hasNext()) {
     
    387371                if (s != null) ((TrustNode)trust).storeNodeSig(s);
    388372            }
    389         } else if(osm instanceof Relation) {
     373        } else if (osm instanceof Relation) {
    390374
    391375        }
     
    406390         */
    407391        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++) {
    409393            List<Node> nodes = new ArrayList<>();
    410394            nodes.add(wayNodes.get(i));
    411395            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);
    414398        }
    415399
     
    423407            return null;
    424408        }
    425         String tosign = TrustWay.generateSegmentSigtext(trust,nodes);
     409        String tosign = TrustWay.generateSegmentSigtext(trust, nodes);
    426410        PGPSignatureSubpacketGenerator spGen = chooseAccuracy();
    427         return sign(tosign,spGen);
     411        return sign(tosign, spGen);
    428412    }
    429413
    430414    public PGPSignature signNode(Node node) {
    431         PGPSignatureSubpacketGenerator  spGen = chooseAccuracy();
    432         return signNode(node,spGen);
     415        PGPSignatureSubpacketGenerator spGen = chooseAccuracy();
     416        return signNode(node, spGen);
    433417    }
    434418
     
    439423        }
    440424        String tosign = TrustNode.generateNodeSigtext(node);
    441         return sign(tosign,spGen);
     425        return sign(tosign, spGen);
    442426    }
    443427
     
    449433        }
    450434        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());
    454437        if (s != null) {
    455438            trust.storeTagSig(key, s);
     
    461444    /**
    462445     * Search in a given Signature for Tolerance information.
    463      * @param sig
    464446     * @return found tolerance as double or 0 if no Tolerance is given
    465447     */
    466448    public static double searchTolerance(PGPSignature sig) {
    467449        /** 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()) {
    469451            if (nd.getNotationName().equals(TrustGPG.NOTATION_DATA_KEY)) {
    470452                String notation = nd.getNotationValue();
     
    480462
    481463    public PGPSignatureSubpacketGenerator chooseAccuracy() {
    482         PGPSignatureSubpacketGenerator  spGen = new PGPSignatureSubpacketGenerator();
     464        PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
    483465        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());
    485467
    486468        JFormattedTextField meters = new JFormattedTextField(NumberFormat.getNumberInstance());
     
    488470        meters.setColumns(5);
    489471
    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);
    494477
    495478        if (n == JOptionPane.OK_OPTION) {
     
    501484
    502485    public PGPSignatureSubpacketGenerator chooseInformationSource() {
    503         PGPSignatureSubpacketGenerator  spGen = new PGPSignatureSubpacketGenerator();
     486        PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
    504487        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());
    506489
    507490        JCheckBox survey = new JCheckBox(tr("Survey"));
    508         p.add(survey,GBC.eol());
     491        p.add(survey, GBC.eol());
    509492
    510493        JCheckBox aerial = new JCheckBox(tr("Aerial Photography"));
    511         p.add(aerial,GBC.eol());
     494        p.add(aerial, GBC.eol());
    512495
    513496        JCheckBox web = new JCheckBox(tr("Web Recherche"));
    514         p.add(web,GBC.eol());
     497        p.add(web, GBC.eol());
    515498
    516499        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);
    520504
    521505        if (n == JOptionPane.OK_OPTION) {
     
    532516
    533517    public PGPSignature sign(String tosign) {
    534         PGPSignatureSubpacketGenerator  spGen = new PGPSignatureSubpacketGenerator();
    535         return sign(tosign,spGen);
     518        PGPSignatureSubpacketGenerator spGen = new PGPSignatureSubpacketGenerator();
     519        return sign(tosign, spGen);
    536520    }
    537521
     
    540524        if (spGen == null) return null;
    541525        PGPSignature sig;
    542         try{
    543 
     526        try {
    544527            readSecretKey();
    545528            if (pgpSec == null) return null;
     
    551534            Provider provider = Security.getProvider("BC");
    552535            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);
    554538            PGPPrivateKey pgpPrivKey = pgpSecKey.extractPrivateKey(secretKeyDecryptor);
    555539            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);
    557542            PGPSignatureGenerator sGen = new PGPSignatureGenerator(contentSignerBuilder);
    558543            sGen.init(PGPSignature.CANONICAL_TEXT_DOCUMENT, pgpPrivKey);
     
    560545            Iterator<?> it = pgpSecKey.getPublicKey().getUserIDs();
    561546            if (it.hasNext()) {
    562                 spGen.setSignerUserID(false, (String)it.next());
     547                spGen.setSignerUserID(false, (String) it.next());
    563548            }
    564549            sGen.setHashedSubpackets(spGen.generate());
     
    569554            //sig.encode(new BCPGOutputStream(new ArmoredOutputStream(new FileOutputStream("/tmp/sigtest.asc"))));
    570555            return sig;
    571         }catch (Exception e){//Catch exception if any
     556        } catch (Exception e) {
    572557            System.err.println("PGP Signing Error: " + e.getMessage());
    573558        }
     
    600585            sig.update(sigtext.getBytes(Charset.forName("UTF-8")));
    601586            return sig.verify();
    602         }catch (Exception e){//Catch exception if any
     587        } catch (Exception e) {
    603588            System.err.println("PGP Verification Error: " + e.getMessage());
    604589        }
    605590        return false;
    606591    }
    607 
    608592
    609593    //    public static void writeSignatureToFile(PGPSignature sig, String clearText, FileOutputStream fout) throws Exception {
     
    637621        Iterator<?> iter = key.getUserIDs();
    638622        if (iter.hasNext()) {
    639             userid = (String)iter.next();
     623            userid = (String) iter.next();
    640624        }
    641625
     
    682666        }
    683667
    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: ")};
    686670        String[] values = {userid, keyid, fingerprint, algorithm, strength, creationTime, expirationTime};
    687671        int numPairs = labels.length;
     
    709693        //        metaPanel.add(p);
    710694        //        JScrollPane sp = new JScrollPane(new KeySignaturesDialog(key));
    711         //        sp.setPreferredSize(new Dimension(0,200));
     695        //        sp.setPreferredSize(new Dimension(0, 200));
    712696        //        metaPanel.add(sp);
    713697
     
    715699    }
    716700
    717 
    718     public PGPSecretKey generateKey() throws NoSuchAlgorithmException, NoSuchProviderException, PGPException, FileNotFoundException, IOException {
     701    public PGPSecretKey generateKey()
     702            throws NoSuchAlgorithmException, NoSuchProviderException, PGPException, FileNotFoundException, IOException {
    719703
    720704        JTextField userId = new JTextField();
     
    727711        strengthBox.setEnabled(false);
    728712
    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"};
    731724        final JComboBox curveBox = new JComboBox(curves);
    732         curveBox.addActionListener(new ActionListener(){
     725        curveBox.addActionListener(new ActionListener() {
    733726
    734727            @Override
     
    740733
    741734        //        final String[] algos = {"DSA","RSA","ECDSA"};
    742         final String[] algos = {"DSA","RSA"};
     735        final String[] algos = {"DSA", "RSA"};
    743736        final JComboBox<?> algoBox = new JComboBox<Object>(algos);
    744         algoBox.addActionListener(new ActionListener(){
     737        algoBox.addActionListener(new ActionListener() {
    745738
    746739            @Override
    747740            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();
    750743                if (alg.equals("DSA")) {
    751744                    strengthBox.setSelectedItem("1024");
     
    766759        });
    767760
    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};
    774766        final JComboBox<?> protectBox = new JComboBox<Object>(protectAlgos);
    775767
    776768        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:")};
    780773        final JComponent[] values = {userId, algoBox, strengthBox, protectBox, cal};
    781774
     
    795788                numPairs, 2, //rows, cols
    796789                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);
    800794
    801795        if (n != JOptionPane.OK_OPTION)
     
    803797
    804798
    805         String algo = (String)algoBox.getSelectedItem();
     799        String algo = (String) algoBox.getSelectedItem();
    806800
    807801        KeyPairGenerator Kpg = KeyPairGenerator.getInstance(algo, "BC");
     
    820814        }
    821815        else {*/
    822         Kpg.initialize(Integer.parseInt((String)strengthBox.getSelectedItem()));
     816        Kpg.initialize(Integer.parseInt((String) strengthBox.getSelectedItem()));
    823817        //
    824818        // this takes a while as the key generator has to generate some DSA params
     
    853847        PBESecretKeyEncryptor encryptor = new JcePBESecretKeyEncryptorBuilder(encAlgorithm).setProvider(provider).
    854848                setSecureRandom(new SecureRandom()).build(password);
    855        
     849
    856850        PGPKeyRingGenerator keyRingGen = new PGPKeyRingGenerator(PGPSignature.POSITIVE_CERTIFICATION, pgpKp, userId.getText(),
    857851                checksumCalculator, subPck, null, signerBuilder, encryptor);
  • applications/editors/josm/plugins/trustosm/src/tools/NameGenerator.java

    r30742 r32533  
     1// License: GPL. For details, see LICENSE file.
    12package tools;
    23
     
    5354    ArrayList<String> sur = new ArrayList<>();
    5455
    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'};
    5760
    5861    private String fileName;
     
    6164     * Create new random name generator object. refresh() is automatically called.
    6265     * @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 {
    6668        this.fileName = fileName;
    6769        refresh();
     
    7173     * Change the file. refresh() is automatically called during the process.
    7274     * @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");
    7778        this.fileName = fileName;
    7879        refresh();
     
    8283     * 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
    8384     * 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 {
    8787        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 = "";
    9292
    9393            while (line != null) {
     
    9898                    } else if (line.charAt(0) == '+') {
    9999                        sur.add(line.substring(1).toLowerCase());
    100                     } else{
     100                    } else {
    101101                        mid.add(line.toLowerCase());
    102102                    }
     
    107107
    108108    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));
    110110    }
    111111
     
    117117    }
    118118
    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) {
    158161        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);
    160163        return s.split(" ")[0];
    161164    }
    162165
    163     private boolean vocalFirst(String s){
     166    private boolean vocalFirst(String s) {
    164167        return (String.copyValueOf(vocals).contains(String.valueOf(s.charAt(0)).toLowerCase()));
    165168    }
    166169
    167     private boolean consonantFirst(String s){
     170    private boolean consonantFirst(String s) {
    168171        return (String.copyValueOf(consonants).contains(String.valueOf(s.charAt(0)).toLowerCase()));
    169172    }
    170173
    171     private boolean vocalLast(String s){
     174    private boolean vocalLast(String s) {
    172175        return (String.copyValueOf(vocals).contains(String.valueOf(s.charAt(s.length()-1)).toLowerCase()));
    173176    }
    174177
    175     private boolean consonantLast(String s){
     178    private boolean consonantLast(String s) {
    176179        return (String.copyValueOf(consonants).contains(String.valueOf(s.charAt(s.length()-1)).toLowerCase()));
    177180    }
    178181
     182    // CHECKSTYLE.OFF: LineLength
    179183
    180184    /**
     
    184188     * @throws RuntimeException when logical mistakes are detected inside chosen file, and program is unable to complete the name.
    185189     */
    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");
    192199        int expecting = 0; // 1 for vocal, 2 for consonant
    193200        int last = 0; // 1 for vocal, 2 for consonant
    194201        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;
    198205        else last = 2;
    199206
    200         if(syls > 2){
    201             if(expectsVocal(pre.get(a))){
     207        if (syls > 2) {
     208            if (expectsVocal(pre.get(a))) {
    202209                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))) {
    207214                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))) {
    214220                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))) {
    219225                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, " +
    225231                "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, " +
    229235                "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());
    237243                //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
    240245                    || last == 1 && hatesPreviousVocals(mid.get(b[i])) || last == 2 && hatesPreviousConsonants(mid.get(b[i])));
    241246
    242247            expecting = 0;
    243             if(expectsVocal(mid.get(b[i]))){
     248            if (expectsVocal(mid.get(b[i]))) {
    244249                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]))) {
    251256                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, " +
    258263                    "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, " +
    262267                    "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, " +
    266271                        "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, " +
    270275                        "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;
    274279            else last = 2;
    275280        }
    276281
    277282        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
    282286                || last == 1 && hatesPreviousVocals(sur.get(c)) || last == 2 && hatesPreviousConsonants(sur.get(c)));
    283287
    284288        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++) {
    286290            name = name.concat(pureSyl(mid.get(b[i]).toLowerCase()));
    287291        }
    288         if(syls > 1)
     292        if (syls > 1)
    289293            name = name.concat(pureSyl(sur.get(c).toLowerCase()));
    290294        return name;
    291295    }
     296    // CHECKSTYLE.ON: LineLength
    292297}
  • applications/editors/josm/plugins/trustosm/src/tools/SpringUtilities.java

    r24389 r32533  
    2828 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    2929 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    30  */ 
     30 */
    3131
    3232package tools;
    3333
    34 import javax.swing.*;
     34import java.awt.Component;
     35import java.awt.Container;
     36
     37import javax.swing.Spring;
    3538import javax.swing.SpringLayout;
    36 import java.awt.*;
    3739
    3840/**
     
    4244 * SpringBox and SpringCompactGrid.
    4345 */
    44 public class SpringUtilities {
     46public final class SpringUtilities {
     47
     48    private SpringUtilities() {
     49        // Hide default constructors for utilities classes
     50    }
     51
    4552    /**
    4653     * A debugging utility that prints to stdout the component's
     
    7380        SpringLayout layout;
    7481        try {
    75             layout = (SpringLayout)parent.getLayout();
     82            layout = (SpringLayout) parent.getLayout();
    7683        } catch (ClassCastException exc) {
    7784            System.err.println("The first argument to makeGrid must use SpringLayout.");
     
    176183        SpringLayout layout;
    177184        try {
    178             layout = (SpringLayout)parent.getLayout();
     185            layout = (SpringLayout) parent.getLayout();
    179186        } catch (ClassCastException exc) {
    180187            System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
Note: See TracChangeset for help on using the changeset viewer.