001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.io.remotecontrol; 003 004import static org.openstreetmap.josm.tools.I18n.tr; 005 006import java.util.Arrays; 007import java.util.List; 008 009import org.openstreetmap.josm.Main; 010 011/** 012 * Contains a preference name to control permission for the operation 013 * implemented by the RequestHandler, and an error message to be displayed if 014 * not permitted. 015 * 016 * @author Bodo Meissner 017 */ 018public class PermissionPrefWithDefault { 019 020 public static final PermissionPrefWithDefault LOAD_DATA = 021 new PermissionPrefWithDefault("remotecontrol.permission.load-data", true, tr("Load data from API")); 022 public static final PermissionPrefWithDefault IMPORT_DATA = 023 new PermissionPrefWithDefault("remotecontrol.permission.import", true, tr("Import data from URL")); 024 public static final PermissionPrefWithDefault OPEN_FILES = 025 new PermissionPrefWithDefault("remotecontrol.permission.open-files", false, tr("Open local files")); 026 public static final PermissionPrefWithDefault LOAD_IMAGERY = 027 new PermissionPrefWithDefault("remotecontrol.permission.imagery", true, tr("Load imagery layers")); 028 public static final PermissionPrefWithDefault CHANGE_SELECTION = 029 new PermissionPrefWithDefault("remotecontrol.permission.change-selection", true, tr("Change the selection")); 030 public static final PermissionPrefWithDefault CHANGE_VIEWPORT = 031 new PermissionPrefWithDefault("remotecontrol.permission.change-viewport", true, tr("Change the viewport")); 032 public static final PermissionPrefWithDefault CREATE_OBJECTS = 033 new PermissionPrefWithDefault("remotecontrol.permission.create-objects", true, tr("Create new objects")); 034 public static final PermissionPrefWithDefault READ_PROTOCOL_VERSION = 035 new PermissionPrefWithDefault("remotecontrol.permission.read-protocolversion", true, tr("Read protocol version")); 036 /** 037 * name of the preference setting to permit the remote operation 038 */ 039 public final String pref; 040 /** 041 * default preference setting 042 */ 043 public final boolean defaultVal; 044 /** 045 * text for the preference dialog checkbox 046 */ 047 public final String preferenceText; 048 049 public PermissionPrefWithDefault(String pref, boolean defaultVal, String preferenceText) { 050 this.pref = pref; 051 this.defaultVal = defaultVal; 052 this.preferenceText = preferenceText; 053 } 054 055 public boolean isAllowed() { 056 return Main.pref.getBoolean(pref, defaultVal); 057 } 058 059 public static List<PermissionPrefWithDefault> getPermissionPrefs() { 060 return Arrays.asList( 061 LOAD_DATA, IMPORT_DATA, OPEN_FILES, LOAD_IMAGERY, 062 CHANGE_SELECTION, CHANGE_VIEWPORT, 063 CREATE_OBJECTS, READ_PROTOCOL_VERSION); 064 } 065}