Changeset 1353 in josm


Ignore:
Timestamp:
31.01.2009 19:09:46 (3 years ago)
Author:
stoecker
Message:

apply patch by xeen - #2114

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r1268 r1353  
    5959import org.openstreetmap.josm.gui.MapFrame; 
    6060import org.openstreetmap.josm.gui.SideButton; 
    61 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 
    62 import org.openstreetmap.josm.gui.tagging.ForwardActionListener; 
    63 import org.openstreetmap.josm.gui.tagging.TaggingCellRenderer; 
    64 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 
    6561import org.openstreetmap.josm.tools.AutoCompleteComboBox; 
    6662import org.openstreetmap.josm.tools.GBC; 
     
    128124     */ 
    129125    void propertyEdit(int row) { 
     126        Collection<OsmPrimitive> sel = Main.ds.getSelected(); 
     127        if (sel.isEmpty()) return; 
     128 
    130129        String key = propertyData.getValueAt(row, 0).toString(); 
    131130        objKey=key; 
    132         Collection<OsmPrimitive> sel = Main.ds.getSelected(); 
    133         if (sel.isEmpty()) { 
    134             JOptionPane.showMessageDialog(Main.parent, tr("Please select the objects you want to change properties for.")); 
    135             return; 
    136         } 
     131 
    137132        String msg = "<html>"+trn("This will change up to {0} object.", "This will change up to {0} objects.", sel.size(), sel.size())+"<br><br>("+tr("An empty value deletes the key.", key)+")</html>"; 
    138133 
     
    304299    void add() { 
    305300        Collection<OsmPrimitive> sel = Main.ds.getSelected(); 
    306         if (sel.isEmpty()) { 
    307             JOptionPane.showMessageDialog(Main.parent, tr("Please select objects for which you want to change properties.")); 
    308             return; 
    309         } 
     301        if (sel.isEmpty()) return; 
    310302 
    311303        JPanel p = new JPanel(new BorderLayout()); 
     
    402394        Main.ds.fireSelectionChanged(sel); 
    403395        selectionChanged(sel); // update table 
    404            
     396 
    405397        int rowCount = propertyTable.getRowCount(); 
    406398        propertyTable.changeSelection((row < rowCount ? row : (rowCount-1)), 0, false, false); 
     
    439431    public JComboBox taggingPresets = new JComboBox(); 
    440432 
     433    /** 
     434     * The Add/Edit/Delete buttons (needed to be able to disable them) 
     435     */ 
     436    private final SideButton btnAdd; 
     437    private final SideButton btnEdit; 
     438    private final SideButton btnDel; 
     439 
     440    private final JLabel selectSth = new JLabel(tr("Please select the objects you want to change properties for.")); 
    441441 
    442442    /** 
     
    448448        Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 150); 
    449449 
    450         // --------------------------------------- 
    451         // This drop-down is really deprecated but we offer people a chance to 
    452         // activate it if they really want. Presets should be used from the 
    453         // menu. 
    454         if (TaggingPresetPreference.taggingPresets.size() > 0 && 
    455                 Main.pref.getBoolean("taggingpreset.in-properties-dialog", false)) { 
    456             Vector<ActionListener> allPresets = new Vector<ActionListener>(); 
    457             for (final TaggingPreset p : TaggingPresetPreference.taggingPresets) 
    458                 allPresets.add(new ForwardActionListener(this, p)); 
    459  
    460             TaggingPreset empty = new TaggingPreset(); 
    461             // empty.setName("this drop-down will be removed soon"); 
    462             allPresets.add(0, new ForwardActionListener(this, empty)); 
    463             taggingPresets.setModel(new DefaultComboBoxModel(allPresets)); 
    464             JPanel north = new JPanel(new GridBagLayout()); 
    465             north.add(getComponent(0),GBC.eol().fill(GBC.HORIZONTAL)); 
    466             north.add(taggingPresets,GBC.eol().fill(GBC.HORIZONTAL)); 
    467             add(north, BorderLayout.NORTH); 
    468         } 
    469         taggingPresets.addActionListener(new ActionListener(){ 
    470             public void actionPerformed(ActionEvent e) { 
    471                 TaggingPreset preset = ((ForwardActionListener)taggingPresets.getSelectedItem()).preset; 
    472                 preset.actionPerformed(e); 
    473                 taggingPresets.setSelectedItem(null); 
    474             } 
    475         }); 
    476         taggingPresets.setRenderer(new TaggingCellRenderer()); 
    477  
    478450        // setting up the properties table 
    479  
    480451        propertyData.setColumnIdentifiers(new String[]{tr("Key"),tr("Value")}); 
    481452        propertyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
     
    548519        JPanel bothTables = new JPanel(); 
    549520        bothTables.setLayout(new GridBagLayout()); 
     521        bothTables.add(selectSth, GBC.eol().fill().insets(10, 10, 10, 10)); 
    550522        bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); 
    551523        bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH)); 
     
    601573                { 
    602574                    int sel = propertyTable.getSelectedRow(); 
    603                     if (e.getActionCommand().equals("Edit")) { 
    604                         if(propertyTable.getRowCount() == 1) 
    605                             sel = 0; 
    606                         if (sel == -1) 
    607                             JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit.")); 
    608                         else 
    609                             propertyEdit(sel); 
    610                     } else if (e.getActionCommand().equals("Delete")) { 
    611                         if (sel == -1) 
    612                             JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete.")); 
    613                         else 
    614                             delete(sel); 
    615                     } 
     575                    // Although we might edit/delete the wrong tag here, chances are still better 
     576                    // than just displaying an error message (which always "fails"). 
     577                    if (e.getActionCommand().equals("Edit")) 
     578                        propertyEdit(sel >= 0 ? sel : 0); 
     579                    else if (e.getActionCommand().equals("Delete")) 
     580                        delete(sel >= 0 ? sel : 0); 
    616581                } 
    617582            } 
     
    620585        Shortcut s = Shortcut.registerShortcut("properties:add", tr("Add Properties"), KeyEvent.VK_B, 
    621586        Shortcut.GROUP_MNEMONIC); 
    622         buttonPanel.add(new SideButton(marktr("Add"),"add","Properties", 
    623                 tr("Add a new key/value pair to all objects"), s, buttonAction)); 
     587        this.btnAdd = new SideButton(marktr("Add"),"add","Properties", 
     588                tr("Add a new key/value pair to all objects"), s, buttonAction); 
     589        buttonPanel.add(this.btnAdd); 
    624590 
    625591        s = Shortcut.registerShortcut("properties:edit", tr("Edit Properties"), KeyEvent.VK_I, 
    626592        Shortcut.GROUP_MNEMONIC); 
    627         buttonPanel.add(new SideButton(marktr("Edit"),"edit","Properties", 
    628                 tr("Edit the value of the selected key for all objects"), s, buttonAction)); 
     593        this.btnEdit = new SideButton(marktr("Edit"),"edit","Properties", 
     594                tr("Edit the value of the selected key for all objects"), s, buttonAction); 
     595        buttonPanel.add(this.btnEdit); 
    629596 
    630597        s = Shortcut.registerShortcut("properties:delete", tr("Delete Properties"), KeyEvent.VK_Q, 
    631598        Shortcut.GROUP_MNEMONIC); 
    632         buttonPanel.add(new SideButton(marktr("Delete"),"delete","Properties", 
    633                 tr("Delete the selected key in all objects"), s, buttonAction)); 
     599        this.btnDel = new SideButton(marktr("Delete"),"delete","Properties", 
     600                tr("Delete the selected key in all objects"), s, buttonAction); 
     601        buttonPanel.add(this.btnDel); 
    634602        add(buttonPanel, BorderLayout.SOUTH); 
    635603 
     
    652620 
    653621        // re-load property data 
    654  
    655622        propertyData.setRowCount(0); 
    656623 
     
    681648        } 
    682649 
     650        boolean hasTags = !newSelection.isEmpty() && propertyData.getRowCount() > 0; 
     651        boolean hasSelection = !newSelection.isEmpty(); 
     652        btnAdd.setEnabled(hasSelection); 
     653        btnEdit.setEnabled(hasTags); 
     654        btnDel.setEnabled(hasTags); 
     655        propertyTable.setVisible(hasSelection); 
     656        propertyTable.getTableHeader().setVisible(hasSelection); 
     657        selectSth.setVisible(!hasSelection); 
     658        if(hasTags) propertyTable.changeSelection(0, 0, false, false); 
     659 
    683660        // re-load membership data 
    684661        // this is rather expensive since we have to walk through all members of all existing relationships. 
     
    708685 
    709686        membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0); 
     687        membershipTable.setVisible(membershipData.getRowCount() > 0); 
    710688 
    711689        if(propertyData.getRowCount() != 0 || membershipData.getRowCount() != 0) { 
    712             setTitle(tr("Properties: {0} / Memberships: {1}",  
     690            setTitle(tr("Properties: {0} / Memberships: {1}", 
    713691                propertyData.getRowCount(), membershipData.getRowCount()), true); 
    714692        } else { 
    715693            setTitle(tr("Properties / Memberships"), false); 
    716694        } 
    717  
    718695    } 
    719696} 
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r1281 r1353  
    222222    @Override public void mergeFrom(final Layer from) { 
    223223        final MergeVisitor visitor = new MergeVisitor(data,((OsmDataLayer)from).data); 
    224         int i=0; 
     224//        int i=0; 
    225225        int max = ((OsmDataLayer)from).data.allPrimitives().size(); 
    226226 
    227         System.out.format("Add/Merge data:"); 
    228          
     227//        System.out.format("Add/Merge data:"); 
     228 
    229229        for (final OsmPrimitive osm : ((OsmDataLayer)from).data.allPrimitives()) { 
    230             i++; 
    231             if(i%100 == 0) { 
    232                 double perc = (((double)i) / ((double)max) * 100.0); 
    233                 System.out.format(" " + (int)perc + "%%"); 
    234             } 
     230//            i++; 
     231//            if(i%100 == 0) { 
     232//                double perc = (((double)i) / ((double)max) * 100.0); 
     233//                System.out.format(" " + (int)perc + "%%"); 
     234//            } 
    235235            osm.visit(visitor); 
    236236        } 
    237237        visitor.fixReferences(); 
    238         System.out.println(""); 
     238//        System.out.println(""); 
    239239 
    240240        // copy the merged layer's data source info 
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r1284 r1353  
    5252public class OsmReader { 
    5353 
    54      static long tagsN = 0; 
    55      static long nodesN = 0; 
    56      static long waysN = 0; 
    57      static long relationsN = 0; 
    58      static long membersN = 0; 
     54//     static long tagsN = 0; 
     55//     static long nodesN = 0; 
     56//     static long waysN = 0; 
     57//     static long relationsN = 0; 
     58//     static long membersN = 0; 
    5959 
    6060     static InputStream currSource; 
     
    143143          private OsmPrimitive current; 
    144144          private String generator; 
    145           int n = 0; 
    146            
     145//          int n = 0; 
     146 
    147147          @Override public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 
    148148               try { 
    149                     if(n%100000 == 0) { 
    150                         try { 
    151                             FileInputStream fis = (FileInputStream)currSource; 
    152                             FileChannel channel = fis.getChannel(); 
    153                             double perc = (((double)channel.position()) / ((double)channel.size()) * 100.0); 
    154                             System.out.format(" " + (int)perc + "%%"); 
    155                         } 
    156                         catch(java.lang.ClassCastException cce) { 
    157                         } 
    158                         catch(IOException e) { 
    159                             System.out.format("Error reading file position " + e); 
    160                         } 
    161                     } 
    162                     n++;                     
     149//                    if(n%100000 == 0) { 
     150//                        try { 
     151//                            FileInputStream fis = (FileInputStream)currSource; 
     152//                            FileChannel channel = fis.getChannel(); 
     153//                            double perc = (((double)channel.position()) / ((double)channel.size()) * 100.0); 
     154//                            System.out.format(" " + (int)perc + "%%"); 
     155//                        } 
     156//                        catch(java.lang.ClassCastException cce) { 
     157//                        } 
     158//                        catch(IOException e) { 
     159//                            System.out.format("Error reading file position " + e); 
     160//                        } 
     161//                    } 
     162//                    n++; 
    163163 
    164164                    if (qName.equals("osm")) { 
     
    213213 
    214214                    } else if (qName.equals("node")) { 
    215                          nodesN++; 
     215//                         nodesN++; 
    216216                         current = new Node(new LatLon(getDouble(atts, "lat"), getDouble(atts, "lon"))); 
    217217                         readCommon(atts, current); 
    218218                         nodes.put(current.id, (Node)current); 
    219219                    } else if (qName.equals("way")) { 
    220                          waysN++; 
     220//                         waysN++; 
    221221                         current = new OsmPrimitiveData(); 
    222222                         readCommon(atts, current); 
     
    234234 
    235235                    } else if (qName.equals("relation")) { 
    236                          relationsN++; 
     236//                         relationsN++; 
    237237                         current = new OsmPrimitiveData(); 
    238238                         readCommon(atts, current); 
    239239                         relations.put((OsmPrimitiveData)current, new LinkedList<RelationMemberData>()); 
    240240                    } else if (qName.equals("member")) { 
    241                          membersN++; 
     241//                         membersN++; 
    242242                         Collection<RelationMemberData> list = relations.get(current); 
    243243                         if (list == null) 
     
    257257 
    258258                    } else if (qName.equals("tag")) { 
    259                          tagsN++; 
     259//                         tagsN++; 
    260260                         current.put(atts.getValue("k"), atts.getValue("v")); 
    261261                    } 
     
    439439          for (Way wy : ds.ways) 
    440440            hm.put(wy.id, wy); 
    441            
     441 
    442442          // pass 2 - sort out members 
    443443          for (Entry<OsmPrimitiveData, Collection<RelationMemberData>> e : relations.entrySet()) { 
     
    490490          osm.references = ref == null ? new DataSet() : ref; 
    491491 
    492            
     492 
    493493          currSource = source; 
    494            
     494 
    495495          // phase 1: Parse nodes and read in raw ways 
    496496          InputSource inputSource = new InputSource(new InputStreamReader(source, "UTF-8")); 
    497497          try { 
    498498             SAXParserFactory.newInstance().newSAXParser().parse(inputSource, osm.new Parser()); 
    499         } catch (ParserConfigurationException e1) { 
     499          } catch (ParserConfigurationException e1) { 
    500500             e1.printStackTrace(); // broken SAXException chaining 
    501501             throw new SAXException(e1); 
    502         } 
    503              
     502          } 
     503 
    504504          Main.pleaseWaitDlg.currentAction.setText(tr("Prepare OSM data...")); 
    505505          Main.pleaseWaitDlg.setIndeterminate(true);  
    506506 
    507           System.out.println(""); 
    508           System.out.println("Parser finished: Tags " + tagsN + " Nodes " + nodesN + " Ways " + waysN +  
    509             " Relations " + relationsN + " Members " + membersN); 
     507//          System.out.println("Parser finished: Tags " + tagsN + " Nodes " + nodesN + " Ways " + waysN + 
     508//            " Relations " + relationsN + " Members " + membersN); 
    510509 
    511510          for (Node n : osm.nodes.values()) 
     
    525524                    o.id = 0; 
    526525 
    527           System.out.println("Data loaded!"); 
     526//          System.out.println("Data loaded!"); 
    528527          Main.pleaseWaitDlg.setIndeterminate(false);  
    529528          Main.pleaseWaitDlg.progress.setValue(0);  
    530            
     529 
    531530          return osm; 
    532531     } 
  • trunk/src/org/openstreetmap/josm/io/OsmServerReader.java

    r1238 r1353  
    4242    protected InputStream getInputStreamRaw(String urlStr, PleaseWaitDialog pleaseWaitDlg) throws IOException { 
    4343 
    44         System.out.println("download: "+urlStr); 
     44//        System.out.println("download: "+urlStr); 
    4545        initAuthentication(); 
    4646        URL url = new URL(urlStr); 
     
    5555 
    5656        activeConnection.setConnectTimeout(15000); 
    57          
     57 
    5858        try { 
    5959            activeConnection.connect(); 
     
    6262            throw new IOException(tr("Couldn't connect to the osm server. Please check your internet connection.")); 
    6363        } 
    64          
     64 
    6565        if (isAuthCancelled() && activeConnection.getResponseCode() == 401) 
    6666            return null; 
Note: See TracChangeset for help on using the changeset viewer.