⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewinputattributes.java

📁 world wind java sdk 源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    private static final boolean DEFAULT_ROTATE_SMOOTHING_ENABLED = true;
    private static final boolean DEFAULT_ZOOM_SMOOTHING_ENABLED = true;
    private static final double DEFAULT_FOCUS_SMOOTHING_VALUE = 0.0; // [0, 1] smoothing value
    private static final double DEFAULT_PAN_SMOOTHING_VALUE = 0.4; // [0, 1] smoothing value
    private static final double DEFAULT_ROTATE_SMOOTHING_VALUE = 0.7; // [0, 1] smoothing value
    private static final double DEFAULT_ZOOM_SMOOTHING_VALUE = 0.85; // [0, 1] smoothing value
    // Keyboard/Action calibration values.
    private static final double DEFAULT_KEY_PAN_MIN_VALUE = 0.000005; // Speed in degrees per frame
    private static final double DEFAULT_KEY_PAN_MAX_VALUE = 4.0; // Speed in degrees per frame
    private static final double DEFAULT_KEY_ROTATE_MIN_VALUE = 2.0; // Speed in degrees per frame
    private static final double DEFAULT_KEY_ROTATE_MAX_VALUE = 2.2; // Speed in degrees per frame
    private static final double DEFAULT_KEY_ZOOM_VALUE = 0.06; // Speed in log-meters per frame
    // Mouse/Action calibration values.
    private static final double DEFAULT_MOUSE_FOCUS_MIN_VALUE = 0.95; // [0, 1] smoothing value
    private static final double DEFAULT_MOUSE_FOCUS_MAX_VALUE = 0.90; // [0, 1] smoothing value
    private static final double DEFAULT_MOUSE_PAN_MIN_VALUE = 0.00001; // Speed in degrees per mouse movement
    private static final double DEFAULT_MOUSE_PAN_MAX_VALUE = 0.2; // Speed in degrees per mouse movement
    private static final double DEFAULT_MOUSE_ROTATE_MIN_VALUE = 0.14; // Speed in degrees per mouse movement
    private static final double DEFAULT_MOUSE_ROTATE_MAX_VALUE = 0.18; // Speed in degrees per mouse movement
    private static final double DEFAULT_MOUSE_ZOOM_VALUE = 0.003; // Speed in log-meters per mouse movement
    // MouseWheel/Action calibration values.
    private static final double DEFAULT_MOUSE_WHEEL_ZOOM_VALUE = 0.1; // Speed in log-meters per wheel movement
    private static final double DEFAULT_MOUSE_WHEEL_ZOOM_VALUE_OSX = 0.01; // Speed in log-meters per wheel movement

    // Device attributes.
    private Map<Object, DeviceAttributes> deviceMap = new HashMap<Object, DeviceAttributes>();
    // Device/action pairing attributes.
    private Map<Object, ActionAttributesMap> deviceActionMap = new HashMap<Object, ActionAttributesMap>();

    public ViewInputAttributes()
    {
        this.setDefaultDeviceAttributes();
        this.setDefaultActionAttributes();
    }

    public DeviceAttributes getDeviceAttributes(Object deviceKey)
    {
        if (deviceKey == null)
        {
            String message = Logging.getMessage("nullValue.DeviceKeyIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }

        return this.deviceMap.get(deviceKey);
    }

    public void setDeviceAttributes(Object deviceKey, DeviceAttributes attributes)
    {
        if (deviceKey == null)
        {
            String message = Logging.getMessage("nullValue.DeviceKeyIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }
        if (attributes == null)
        {
            String message = Logging.getMessage("nullValue.AttributesIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }

        this.deviceMap.put(deviceKey, attributes);
    }

    public ActionAttributesMap getActionMap(Object deviceKey)
    {
        if (deviceKey == null)
        {
            String message = Logging.getMessage("nullValue.DeviceKeyIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }

        return this.deviceActionMap.get(deviceKey);
    }

    public void setActionMap(Object deviceKey, ActionAttributesMap map)
    {
        if (deviceKey == null)
        {
            String message = Logging.getMessage("nullValue.DeviceKeyIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }
        if (map == null)
        {
            String message = Logging.getMessage("nullValue.MapIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }

        this.deviceActionMap.put(deviceKey, map);
    }

    public ActionAttributes getActionAttributes(Object deviceKey, Object actionKey)
    {
        if (deviceKey == null)
        {
            String message = Logging.getMessage("nullValue.DeviceKeyIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }
        if (actionKey == null)
        {
            String message = Logging.getMessage("nullValue.ActionKeyIsNull");
            Logging.logger().severe(message);
            throw new IllegalArgumentException(message);
        }

        ActionAttributesMap map = this.getActionMap(deviceKey);
        if (map == null)
            return null;

        return map.getActionAttributes(actionKey);
    }

    //**************************************************************//
    //********************  Default Attributes  ********************//
    //**************************************************************//

    protected void setDefaultDeviceAttributes()
    {
        this.setDeviceAttributes(DEVICE_KEYBOARD, new DeviceAttributes(DEFAULT_KEY_SENSITIVITY));
        this.setDeviceAttributes(DEVICE_MOUSE, new DeviceAttributes(DEFAULT_MOUSE_SENSITIVITY));
        this.setDeviceAttributes(DEVICE_MOUSE_WHEEL, new DeviceAttributes(DEFAULT_MOUSE_WHEEL_SENSITIVITY));
    }

    protected void setDefaultActionAttributes()
    {
        // Default keyboard/action calibration values.
        ActionAttributesMap map = new ActionAttributesMap();
        map.setActionAttributes(VIEW_PAN,
            new ActionAttributes(DEFAULT_KEY_PAN_MIN_VALUE, DEFAULT_KEY_PAN_MAX_VALUE, DEFAULT_PAN_SMOOTHING_ENABLED, DEFAULT_PAN_SMOOTHING_VALUE));
        map.setActionAttributes(VIEW_ROTATE,
            new ActionAttributes(DEFAULT_KEY_ROTATE_MIN_VALUE, DEFAULT_KEY_ROTATE_MAX_VALUE, DEFAULT_ROTATE_SMOOTHING_ENABLED, DEFAULT_ROTATE_SMOOTHING_VALUE));
        map.setActionAttributes(VIEW_ZOOM,
            new ActionAttributes(DEFAULT_KEY_ZOOM_VALUE, DEFAULT_KEY_ZOOM_VALUE, DEFAULT_ZOOM_SMOOTHING_ENABLED, DEFAULT_ZOOM_SMOOTHING_VALUE));
        this.setSlowActionAttributes(map, DEFAULT_SLOW_VALUE);
        this.setActionMap(DEVICE_KEYBOARD, map);

        // Default mouse/action calibration values.
        map = new ActionAttributesMap();
        map.setActionAttributes(VIEW_FOCUS,
            new ActionAttributes(DEFAULT_MOUSE_FOCUS_MIN_VALUE, DEFAULT_MOUSE_FOCUS_MAX_VALUE, DEFAULT_FOCUS_SMOOTHING_ENABLED, DEFAULT_FOCUS_SMOOTHING_VALUE));
        map.setActionAttributes(VIEW_PAN,
            new ActionAttributes(DEFAULT_MOUSE_PAN_MIN_VALUE, DEFAULT_MOUSE_PAN_MAX_VALUE, DEFAULT_PAN_SMOOTHING_ENABLED, DEFAULT_PAN_SMOOTHING_VALUE));
        map.setActionAttributes(VIEW_ROTATE,
            new ActionAttributes(DEFAULT_MOUSE_ROTATE_MIN_VALUE, DEFAULT_MOUSE_ROTATE_MAX_VALUE, DEFAULT_ROTATE_SMOOTHING_ENABLED, DEFAULT_ROTATE_SMOOTHING_VALUE));
        map.setActionAttributes(VIEW_ZOOM,
            new ActionAttributes(DEFAULT_MOUSE_ZOOM_VALUE, DEFAULT_MOUSE_ZOOM_VALUE, DEFAULT_ZOOM_SMOOTHING_ENABLED, DEFAULT_ZOOM_SMOOTHING_VALUE));
        this.setSlowActionAttributes(map, DEFAULT_SLOW_VALUE);
        this.setActionMap(DEVICE_MOUSE, map);

        // Default mousewheel/action calibration values.
        map = new ActionAttributesMap();
        if (Configuration.isMacOS())
        {
            map.setActionAttributes(VIEW_ZOOM,
                new ActionAttributes(DEFAULT_MOUSE_WHEEL_ZOOM_VALUE_OSX, DEFAULT_MOUSE_WHEEL_ZOOM_VALUE_OSX, DEFAULT_ZOOM_SMOOTHING_ENABLED, DEFAULT_ZOOM_SMOOTHING_VALUE));
            this.setSlowActionAttributes(map, DEFAULT_SLOW_VALUE);
        }
        else
        {
            map.setActionAttributes(VIEW_ZOOM,
                new ActionAttributes(DEFAULT_MOUSE_WHEEL_ZOOM_VALUE, DEFAULT_MOUSE_WHEEL_ZOOM_VALUE, DEFAULT_ZOOM_SMOOTHING_ENABLED, DEFAULT_ZOOM_SMOOTHING_VALUE));
            this.setSlowActionAttributes(map, DEFAULT_SLOW_VALUE);
        }
        this.setActionMap(DEVICE_MOUSE_WHEEL, map);
    }

    protected void setSlowActionAttributes(ActionAttributesMap map, double slowCoefficient)
    {
        ActionAttributes attributes = map.getActionAttributes(VIEW_FOCUS);
        if (attributes != null)
            map.setActionAttributes(VIEW_FOCUS_SLOW, this.makeSlowActionAttributes(attributes, slowCoefficient));

        attributes = map.getActionAttributes(VIEW_PAN);
        if (attributes != null)
            map.setActionAttributes(VIEW_PAN_SLOW, this.makeSlowActionAttributes(attributes, slowCoefficient));

        attributes = map.getActionAttributes(VIEW_ROTATE);
        if (attributes != null)
            map.setActionAttributes(VIEW_ROTATE_SLOW, this.makeSlowActionAttributes(attributes, slowCoefficient));

        attributes = map.getActionAttributes(VIEW_ZOOM);
        if (attributes != null)
            map.setActionAttributes(VIEW_ZOOM_SLOW, this.makeSlowActionAttributes(attributes, slowCoefficient));
    }

    protected ActionAttributes makeSlowActionAttributes(ActionAttributes attributes, double slowCoefficient)
    {
        ActionAttributes slowAttributes = new ActionAttributes(attributes);
        double[] values = attributes.getValues();
        slowAttributes.setValues(values[0] * slowCoefficient, values[1] * slowCoefficient);
        return slowAttributes;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -