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 017public class OsmPrivilegesPanel extends VerticallyScrollablePanel { 018 019 private final JCheckBox cbWriteApi = new JCheckBox(); 020 private final JCheckBox cbWriteGpx = new JCheckBox(); 021 private final JCheckBox cbReadGpx = new JCheckBox(); 022 private final JCheckBox cbWritePrefs = new JCheckBox(); 023 private final JCheckBox cbReadPrefs = new JCheckBox(); 024 private final JCheckBox cbModifyNotes = new JCheckBox(); 025 026 /** 027 * Constructs a new {@code OsmPrivilegesPanel}. 028 */ 029 public OsmPrivilegesPanel() { 030 build(); 031 } 032 033 protected final void build() { 034 setLayout(new GridBagLayout()); 035 GridBagConstraints gc = new GridBagConstraints(); 036 setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); 037 038 // checkbox for "allow to upload map data" 039 // 040 gc.anchor = GridBagConstraints.NORTHWEST; 041 gc.fill = GridBagConstraints.HORIZONTAL; 042 gc.weightx = 1.0; 043 gc.insets = new Insets(0, 0, 3, 3); 044 add(cbWriteApi, gc); 045 cbWriteApi.setText(tr("Allow to upload map data")); 046 cbWriteApi.setToolTipText(tr("Select to grant JOSM the right to upload map data on your behalf")); 047 cbWriteApi.setSelected(true); 048 049 // checkbox for "allow to upload gps traces" 050 // 051 gc.gridy = 1; 052 add(cbWriteGpx, gc); 053 cbWriteGpx.setText(tr("Allow to upload GPS traces")); 054 cbWriteGpx.setToolTipText(tr("Select to grant JOSM the right to upload GPS traces on your behalf")); 055 cbWriteGpx.setSelected(true); 056 057 // checkbox for "allow to download private gps traces" 058 // 059 gc.gridy = 2; 060 add(cbReadGpx, gc); 061 cbReadGpx.setText(tr("Allow to download your private GPS traces")); 062 cbReadGpx.setToolTipText(tr("Select to grant JOSM the right to download your private GPS traces into JOSM layers")); 063 cbReadGpx.setSelected(true); 064 065 // checkbox for "allow to download private gps traces" 066 // 067 gc.gridy = 3; 068 add(cbReadPrefs, gc); 069 cbReadPrefs.setText(tr("Allow to read your preferences")); 070 cbReadPrefs.setToolTipText(tr("Select to grant JOSM the right to read your server preferences")); 071 cbReadPrefs.setSelected(true); 072 073 // checkbox for "allow to download private gps traces" 074 // 075 gc.gridy = 4; 076 add(cbWritePrefs, gc); 077 cbWritePrefs.setText(tr("Allow to write your preferences")); 078 cbWritePrefs.setToolTipText(tr("Select to grant JOSM the right to write your server preferences")); 079 cbWritePrefs.setSelected(true); 080 081 gc.gridy = 5; 082 add(cbModifyNotes, gc); 083 cbModifyNotes.setText(tr("Allow modifications of notes")); 084 cbModifyNotes.setToolTipText(tr("Select to grant JOSM the right to modify notes on your behalf")); 085 cbModifyNotes.setSelected(true); 086 087 // filler - grab remaining space 088 gc.gridy = 6; 089 gc.fill = GridBagConstraints.BOTH; 090 gc.weightx = 1.0; 091 gc.weighty = 1.0; 092 add(new JPanel(), gc); 093 } 094 095 /** 096 * Replies the currently entered privileges 097 * 098 * @return the privileges 099 */ 100 public OsmPrivileges getPrivileges() { 101 OsmPrivileges privileges = new OsmPrivileges(); 102 privileges.setAllowWriteApi(cbWriteApi.isSelected()); 103 privileges.setAllowWriteGpx(cbWriteGpx.isSelected()); 104 privileges.setAllowReadGpx(cbReadGpx.isSelected()); 105 privileges.setAllowWritePrefs(cbWritePrefs.isSelected()); 106 privileges.setAllowReadPrefs(cbReadPrefs.isSelected()); 107 privileges.setAllowModifyNotes(cbModifyNotes.isSelected()); 108 return privileges; 109 } 110}