001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.oauth; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.awt.GridBagConstraints; 007import java.awt.GridBagLayout; 008import java.awt.Insets; 009 010import javax.swing.BorderFactory; 011import javax.swing.JCheckBox; 012import javax.swing.JPanel; 013 014import org.openstreetmap.josm.data.oauth.OsmPrivileges; 015import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 016 017/** 018 * Panel letting the user choose from a detailed list of privileges that will be 019 * requested for the OAuth token. 020 */ 021public class OsmPrivilegesPanel extends VerticallyScrollablePanel { 022 023 private final JCheckBox cbWriteApi = new JCheckBox(); 024 private final JCheckBox cbWriteGpx = new JCheckBox(); 025 private final JCheckBox cbReadGpx = new JCheckBox(); 026 private final JCheckBox cbWritePrefs = new JCheckBox(); 027 private final JCheckBox cbReadPrefs = new JCheckBox(); 028 private final JCheckBox cbModifyNotes = new JCheckBox(); 029 030 /** 031 * Constructs a new {@code OsmPrivilegesPanel}. 032 */ 033 public OsmPrivilegesPanel() { 034 build(); 035 } 036 037 protected final void build() { 038 setLayout(new GridBagLayout()); 039 GridBagConstraints gc = new GridBagConstraints(); 040 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 041 042 // checkbox for "allow to upload map data" 043 // 044 gc.anchor = GridBagConstraints.NORTHWEST; 045 gc.fill = GridBagConstraints.HORIZONTAL; 046 gc.weightx = 1.0; 047 gc.insets = new Insets(0, 0, 3, 3); 048 add(cbWriteApi, gc); 049 cbWriteApi.setText(tr("Allow to upload map data")); 050 cbWriteApi.setToolTipText(tr("Select to grant JOSM the right to upload map data on your behalf")); 051 cbWriteApi.setSelected(true); 052 053 // checkbox for "allow to upload gps traces" 054 // 055 gc.gridy = 1; 056 add(cbWriteGpx, gc); 057 cbWriteGpx.setText(tr("Allow to upload GPS traces")); 058 cbWriteGpx.setToolTipText(tr("Select to grant JOSM the right to upload GPS traces on your behalf")); 059 cbWriteGpx.setSelected(true); 060 061 // checkbox for "allow to download private gps traces" 062 // 063 gc.gridy = 2; 064 add(cbReadGpx, gc); 065 cbReadGpx.setText(tr("Allow to download your private GPS traces")); 066 cbReadGpx.setToolTipText(tr("Select to grant JOSM the right to download your private GPS traces into JOSM layers")); 067 cbReadGpx.setSelected(true); 068 069 // checkbox for "allow to download private gps traces" 070 // 071 gc.gridy = 3; 072 add(cbReadPrefs, gc); 073 cbReadPrefs.setText(tr("Allow to read your preferences")); 074 cbReadPrefs.setToolTipText(tr("Select to grant JOSM the right to read your server preferences")); 075 cbReadPrefs.setSelected(true); 076 077 // checkbox for "allow to download private gps traces" 078 // 079 gc.gridy = 4; 080 add(cbWritePrefs, gc); 081 cbWritePrefs.setText(tr("Allow to write your preferences")); 082 cbWritePrefs.setToolTipText(tr("Select to grant JOSM the right to write your server preferences")); 083 cbWritePrefs.setSelected(true); 084 085 gc.gridy = 5; 086 add(cbModifyNotes, gc); 087 cbModifyNotes.setText(tr("Allow modifications of notes")); 088 cbModifyNotes.setToolTipText(tr("Select to grant JOSM the right to modify notes on your behalf")); 089 cbModifyNotes.setSelected(true); 090 091 // filler - grab remaining space 092 gc.gridy = 6; 093 gc.fill = GridBagConstraints.BOTH; 094 gc.weightx = 1.0; 095 gc.weighty = 1.0; 096 add(new JPanel(), gc); 097 } 098 099 /** 100 * Replies the currently entered privileges 101 * 102 * @return the privileges 103 */ 104 public OsmPrivileges getPrivileges() { 105 OsmPrivileges privileges = new OsmPrivileges(); 106 privileges.setAllowWriteApi(cbWriteApi.isSelected()); 107 privileges.setAllowWriteGpx(cbWriteGpx.isSelected()); 108 privileges.setAllowReadGpx(cbReadGpx.isSelected()); 109 privileges.setAllowWritePrefs(cbWritePrefs.isSelected()); 110 privileges.setAllowReadPrefs(cbReadPrefs.isSelected()); 111 privileges.setAllowModifyNotes(cbModifyNotes.isSelected()); 112 return privileges; 113 } 114}