Changeset 5396 in josm


Ignore:
Timestamp:
2012-08-05T20:55:08+02:00 (12 years ago)
Author:
bastiK
Message:

respect attributes that are already present, when exporting gpx

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/GpxExporter.java

    r5361 r5396  
    6969        JPanel p = new JPanel(new GridBagLayout());
    7070
     71        GpxData gpxData;
     72        // At this moment, we only need to know the attributes of the GpxData,
     73        // conversion of OsmDataLayer (if needed) will be done after the dialog
     74        // is closed.
     75        if (layer instanceof GpxLayer) {
     76            gpxData = ((GpxLayer) layer).data;
     77        } else {
     78            gpxData = new GpxData();
     79        }
     80
    7181        p.add(new JLabel(tr("GPS track description")), GBC.eol());
    7282        JTextArea desc = new JTextArea(3, 40);
    7383        desc.setWrapStyleWord(true);
    7484        desc.setLineWrap(true);
     85        desc.setText((String) gpxData.attr.get(GpxData.META_DESC));
    7586        p.add(new JScrollPane(desc), GBC.eop().fill(GBC.BOTH));
    7687
    7788        JCheckBox author = new JCheckBox(tr("Add author information"), Main.pref.getBoolean("lastAddAuthor", true));
    78         author.setSelected(true);
    7989        p.add(author, GBC.eol());
    8090        JLabel nameLabel = new JLabel(tr("Real name"));
    8191        p.add(nameLabel, GBC.std().insets(10, 0, 5, 0));
    82         JTextField authorName = new JTextField(Main.pref.get("lastAuthorName"));
     92        JTextField authorName = new JTextField();
    8393        p.add(authorName, GBC.eol().fill(GBC.HORIZONTAL));
    8494        JLabel emailLabel = new JLabel(tr("E-Mail"));
    8595        p.add(emailLabel, GBC.std().insets(10, 0, 5, 0));
    86         String user = CredentialsManager.getInstance().getUsername();
    87         JTextField email = new JTextField(user == null ? "" : user);
     96        JTextField email = new JTextField();
    8897        p.add(email, GBC.eol().fill(GBC.HORIZONTAL));
    8998        JLabel copyrightLabel = new JLabel(tr("Copyright (URL)"));
     
    99108        JLabel warning = new JLabel("<html><font size='-2'>&nbsp;</html");
    100109        p.add(warning, GBC.eol().fill(GBC.HORIZONTAL).insets(15, 0, 0, 0));
    101         addDependencies(author, authorName, email, copyright, predefined, copyrightYear, nameLabel, emailLabel,
     110        addDependencies(gpxData, author, authorName, email, copyright, predefined, copyrightYear, nameLabel, emailLabel,
    102111                copyrightLabel, copyrightYearLabel, warning);
    103 
    104         // if the user name is not the email address, but the osm user name
    105         // move it from the email textfield to the author textfield
    106         if (!email.getText().contains("@")) {
    107             authorName.setText(email.getText());
    108             email.setText("");
    109         }
    110112
    111113        p.add(new JLabel(tr("Keywords")), GBC.eol());
    112114        JTextField keywords = new JTextField();
     115        keywords.setText((String) gpxData.attr.get(GpxData.META_KEYWORDS));
    113116        p.add(keywords, GBC.eop().fill(GBC.HORIZONTAL));
    114117
     
    131134        }
    132135
    133         GpxData gpxData;
    134136        if (layer instanceof OsmDataLayer) {
    135137            gpxData = ((OsmDataLayer) layer).toGpxData();
     
    180182    }
    181183
    182     private static void enableCopyright(final JTextField copyright, final JButton predefined,
     184    private static void enableCopyright(final GpxData data, final JTextField copyright, final JButton predefined,
    183185            final JTextField copyrightYear, final JLabel copyrightLabel, final JLabel copyrightYearLabel,
    184186            final JLabel warning, boolean enable) {
     
    190192        warning.setText(enable ? warningGpl : "<html><font size='-2'>&nbsp;</html");
    191193
    192         if (enable && copyrightYear.getText().length()==0) {
    193             copyrightYear.setText(enable ? Integer.toString(Calendar.getInstance().get(Calendar.YEAR)) : "");
    194         } else if (!enable) {
     194        if (enable) {
     195            if (copyrightYear.getText().length()==0) {
     196                String sCopyrightYear = (String) data.attr.get(GpxData.META_COPYRIGHT_YEAR);
     197                if (sCopyrightYear == null) {
     198                    sCopyrightYear = Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
     199                }
     200                copyrightYear.setText(sCopyrightYear);
     201            }
     202            if (copyright.getText().length()==0) {
     203                String sCopyright = (String) data.attr.get(GpxData.META_COPYRIGHT_LICENSE);
     204                if (sCopyright == null) {
     205                    sCopyright = Main.pref.get("lastCopyright", "http://creativecommons.org/licenses/by-sa/2.5");
     206                }
     207                copyright.setText(sCopyright);
     208                copyright.setCaretPosition(0);
     209            }
     210        } else {
    195211            copyrightYear.setText("");
    196         }
    197 
    198         if (enable && copyright.getText().length()==0) {
    199             copyright.setText(enable ? Main.pref.get("lastCopyright", "http://creativecommons.org/licenses/by-sa/2.5") : "");
    200             copyright.setCaretPosition(0);
    201         } else if (!enable) {
    202212            copyright.setText("");
    203213        }
     
    213223     */
    214224    private static void addDependencies(
     225            final GpxData data,
    215226            final JCheckBox author,
    216227            final JTextField authorName,
     
    232243                nameLabel.setEnabled(b);
    233244                emailLabel.setEnabled(b);
    234                 authorName.setText(b ? Main.pref.get("lastAuthorName") : "");
    235                 String user = CredentialsManager.getInstance().getUsername();
    236                 email.setText(b ? (user == null ? "" : user) : "");
    237 
    238                 boolean authorSet = authorName.getText().length() != 0;
    239                 GpxExporter.enableCopyright(copyright, predefined, copyrightYear, copyrightLabel, copyrightYearLabel, warning, b && authorSet);
     245                if (b) {
     246                    String sAuthorName = (String) data.attr.get(GpxData.META_AUTHOR_NAME);
     247                    if (sAuthorName == null) {
     248                        sAuthorName = Main.pref.get("lastAuthorName");
     249                    }
     250                    authorName.setText(sAuthorName);
     251                    String sEmail = (String) data.attr.get(GpxData.META_AUTHOR_EMAIL);
     252                    if (sEmail == null) {
     253                        sEmail = Main.pref.get("lastAuthorEmail");
     254                    }
     255                    email.setText(sEmail);
     256                } else {
     257                    authorName.setText("");
     258                    email.setText("");
     259                }
     260                boolean isAuthorSet = authorName.getText().length() != 0;
     261                GpxExporter.enableCopyright(data, copyright, predefined, copyrightYear, copyrightLabel, copyrightYearLabel, warning, b && isAuthorSet);
    240262            }
    241263        };
     
    245267            @Override public void keyReleased(KeyEvent e) {
    246268                boolean b = authorName.getText().length()!=0 && author.isSelected();
    247                 GpxExporter.enableCopyright(copyright, predefined, copyrightYear, copyrightLabel, copyrightYearLabel, warning, b);
     269                GpxExporter.enableCopyright(data, copyright, predefined, copyrightYear, copyrightLabel, copyrightYearLabel, warning, b);
    248270            }
    249271        };
Note: See TracChangeset for help on using the changeset viewer.