Ignore:
Timestamp:
2012-03-19T00:45:17+01:00 (12 years ago)
Author:
donvip
Message:

opendata: View embedded licenses

Location:
applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/gui/AskLicenseAgreementDialog.java

    r28113 r28114  
    33import static org.openstreetmap.josm.tools.I18n.tr;
    44
    5 import java.awt.Dimension;
    6 import java.awt.event.ActionEvent;
    75import java.io.IOException;
    86
    9 import javax.swing.Icon;
    10 import javax.swing.JEditorPane;
    11 import javax.swing.JOptionPane;
    12 import javax.swing.JScrollPane;
     7import org.openstreetmap.josm.Main;
     8import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    139
    14 import org.openstreetmap.josm.Main;
    15 import org.openstreetmap.josm.gui.ExtendedDialog;
    16 import org.openstreetmap.josm.plugins.opendata.core.licenses.License;
    17 import org.openstreetmap.josm.tools.ImageProvider;
    18 
    19 public class AskLicenseAgreementDialog extends ExtendedDialog {
    20 
    21         private final License license;
    22         private final JEditorPane htmlPane;
    23         private boolean summary;
     10public class AskLicenseAgreementDialog extends ViewLicenseDialog {
    2411       
    2512        public AskLicenseAgreementDialog(License license) throws IOException {
    26                 super(Main.parent, tr("License Agreement"), new String[] {tr("Accept"), "", tr("Refuse")});
     13                super(license, Main.parent, tr("License Agreement"), new String[] {tr("Accept"), "", tr("Refuse")});
    2714               
    28                 this.license = license;
    29                 this.htmlPane = new JEditorPane();
    30                 //htmlPane.setEditorKitForContentType(pdfEditorKit.getContentType(), pdfEditorKit);
    31                 htmlPane.setEditable(false);
    32                 if (license.getSummaryURL() != null) {
    33                         htmlPane.setPage(license.getSummaryURL());
    34                         summary = true;
    35                 } else {
    36                         htmlPane.setPage(license.getURL());
    37                         summary = false;
    38                 }
    39                 JScrollPane scrollPane = new JScrollPane(htmlPane);
    40                 scrollPane.setPreferredSize(new Dimension(800, 600));
    41        
    42         setButtonIcons(new Icon[] {
    43                 ImageProvider.get("ok"),
    44                 ImageProvider.get("agreement24"),
    45                 ImageProvider.get("cancel"),
    46                 });
    4715        setToolTipTexts(new String[] {
    4816                tr("I understand and accept these terms and conditions"),
    4917                tr("View the full text of this license"),
    5018                tr("I refuse these terms and conditions. Cancel download.")});
    51         if (license.getIcon() != null) {
    52                 setIcon(license.getIcon());
    53         } else {
    54                 setIcon(JOptionPane.INFORMATION_MESSAGE);
    55         }
    56         setCancelButton(3);
    57         setMinimumSize(new Dimension(300, 200));
    58         setContent(scrollPane, false);
    59         }
    60 
    61         @Override
    62         protected void buttonAction(int buttonIndex, ActionEvent evt) {
    63                 if (buttonIndex == 1) {
    64                         try {
    65                                 if (summary) {
    66                                         buttons.get(1).setText(tr("View summary"));
    67                                         htmlPane.setPage(license.getURL());
    68                                 } else {
    69                                         buttons.get(1).setText(tr("View full text"));
    70                                         htmlPane.setPage(license.getSummaryURL());
    71                                 }
    72                         } catch (IOException e) {
    73                                 e.printStackTrace();
    74                         }
    75                         summary = !summary;
    76                 } else {
    77                         super.buttonAction(buttonIndex, evt);
    78                 }
    79         }
    80 
    81         @Override
    82         public void setupDialog() {
    83                 super.setupDialog();
    84                 buttons.get(1).setEnabled(license.getSummaryURL() != null && license.getURL() != null);
    85                 if (summary) {
    86                         buttons.get(1).setText(tr("View full text"));
    87                 } else {
    88                         buttons.get(1).setText(tr("View summary"));
    89                 }
    9019        }
    9120}
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/layers/OdDataLayer.java

    r28113 r28114  
    3636import org.openstreetmap.josm.plugins.opendata.core.OdConstants;
    3737import org.openstreetmap.josm.plugins.opendata.core.actions.OpenLinkAction;
     38import org.openstreetmap.josm.plugins.opendata.core.actions.ViewLicenseAction;
    3839import org.openstreetmap.josm.plugins.opendata.core.datasets.AbstractDataSetHandler;
    3940import org.openstreetmap.josm.plugins.opendata.core.io.OsmDownloader;
     
    161162                                result.add(new OpenLinkAction(lic.getURL(), ICON_AGREEMENT_24,
    162163                                                tr("View License"), tr("Launch browser to the license page of the selected data set")));
    163                         } else {
    164                                 // TODO: view embedded licenses
    165164                        }
    166165                        if (lic.getSummaryURL() != null && lic.getSummaryURL().getProtocol().startsWith("http")) {
    167166                                result.add(new OpenLinkAction(lic.getSummaryURL(), ICON_AGREEMENT_24,
    168167                                                tr("View License (summary)"), tr("Launch browser to the summary license page of the selected data set")));
    169                         } else {
    170                                 // TODO: view embedded licenses
     168                        }
     169                        if ((lic.getURL() != null && !lic.getURL().getProtocol().startsWith("http")) || (lic.getSummaryURL() != null && !lic.getSummaryURL().getProtocol().startsWith("http"))) {
     170                                result.add(new ViewLicenseAction(lic, tr("View License"), tr("View the license of the selected data set")));
    171171                        }
    172172                }
Note: See TracChangeset for help on using the changeset viewer.