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