Skip to content

Commit

Permalink
[Bar Chart] Customize direction when a bar chart is scrolled with the…
Browse files Browse the repository at this point in the history
… mouse wheel

#1096
  • Loading branch information
wolfgang-ch committed May 9, 2023
1 parent 631747c commit e18e488
Show file tree
Hide file tree
Showing 13 changed files with 322 additions and 107 deletions.
3 changes: 2 additions & 1 deletion bundles/net.tourbook.chart/META-INF/MANIFEST.MF
Expand Up @@ -11,7 +11,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.core.expressions,
net.tourbook.common
Bundle-ActivationPolicy: lazy
Export-Package: net.tourbook.chart
Export-Package: net.tourbook.chart,
net.tourbook.chart.preferences
Bundle-RequiredExecutionEnvironment: JavaSE-11
Import-Package: net.tourbook.common,
net.tourbook.common.form,
Expand Down
3 changes: 2 additions & 1 deletion bundles/net.tourbook.chart/build.properties
Expand Up @@ -3,6 +3,7 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
icons/,\
plugin.properties
plugin.properties,\
plugin.xml
additional.bundles = net.tourbook.common,\
net.tourbook.ext.jars
11 changes: 11 additions & 0 deletions bundles/net.tourbook.chart/plugin.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.core.runtime.preferences">
<initializer
class="net.tourbook.chart.preferences.ChartPreferenceInitializer">
</initializer>
</extension>

</plugin>
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (C) 2005, 2021 Wolfgang Schramm and Contributors
* Copyright (C) 2005, 2023 Wolfgang Schramm and Contributors
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
Expand All @@ -19,6 +19,7 @@

import net.tourbook.common.color.ThemeUtil;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ResourceLocator;
import org.eclipse.ui.plugin.AbstractUIPlugin;
Expand Down Expand Up @@ -65,6 +66,11 @@ public static ImageDescriptor getImageDescriptor(final String path) {
return imageDescriptor.isPresent() ? imageDescriptor.get() : null;
}

public static IPreferenceStore getPrefStore() {

return getDefault().getPreferenceStore();
}

/**
* @param imageName
* @return Returns the themed image descriptor from {@link ChartActivator} plugin images
Expand All @@ -74,19 +80,11 @@ public static ImageDescriptor getThemedImageDescriptor(final String imageName) {
return getImageDescriptor(ThemeUtil.getThemedImageName(imageName));
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
}

/*
* (non-Javadoc)
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
@Override
public void stop(final BundleContext context) throws Exception {
plugin = null;
Expand Down
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.HashMap;

import net.tourbook.chart.preferences.IChartPreferences;
import net.tourbook.common.DPITools;
import net.tourbook.common.PointLong;
import net.tourbook.common.RectangleLong;
Expand Down Expand Up @@ -8410,15 +8411,31 @@ void onMouseWheel(final Event event, final boolean isEventFromAxis, final boolea
// mouse mode: move slider

/**
* when a slider in a graph is moved with the mouse wheel the direction is the same as when
* When a slider in a graph is moved with the mouse wheel the direction is the same as when
* the mouse wheel is scrolling in the tour editor:
* <p>
* wheel up -> tour editor up
* Wheel up -> Tour editor up
*/
if (event.count < 0) {
event.keyCode |= SWT.ARROW_RIGHT;
final MouseWheel2KeyTranslation mouseKeyTranslation = (MouseWheel2KeyTranslation) net.tourbook.common.util.Util.getEnumValue(

ChartActivator.getPrefStore().getString(IChartPreferences.GRAPH_MOUSE_KEY_TRANSLATION),
MouseWheel2KeyTranslation.Up_Left);

if (mouseKeyTranslation.equals(MouseWheel2KeyTranslation.Up_Left)) {

if (event.count < 0) {
event.keyCode |= SWT.ARROW_RIGHT;
} else {
event.keyCode |= SWT.ARROW_LEFT;
}

} else {
event.keyCode |= SWT.ARROW_LEFT;

if (event.count < 0) {
event.keyCode |= SWT.ARROW_LEFT;
} else {
event.keyCode |= SWT.ARROW_RIGHT;
}
}

/*
Expand Down
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (C) 2023 Wolfgang Schramm and Contributors
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*******************************************************************************/
package net.tourbook.chart;

/**
* Translate mouse wheel direction into keyboard arrow direction
*/
public enum MouseWheel2KeyTranslation {

/**
* Scrolling the mouse up is moving the bar selection to the left
*/
Up_Left,

/**
* Scrolling the mouse up is moving the bar selection to the right
*/
Up_Right,

}
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (C) 2023 Wolfgang Schramm and Contributors
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*******************************************************************************/
package net.tourbook.chart.preferences;

import net.tourbook.chart.ChartActivator;
import net.tourbook.chart.MouseWheel2KeyTranslation;

import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;

public class ChartPreferenceInitializer extends AbstractPreferenceInitializer {

public ChartPreferenceInitializer() {}

@Override
public void initializeDefaultPreferences() {

final IPreferenceStore store = ChartActivator.getPrefStore();

// mouse wheel to key translation
store.setDefault(IChartPreferences.GRAPH_MOUSE_KEY_TRANSLATION, MouseWheel2KeyTranslation.Up_Left.name());
}

}
@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (C) 2023 Wolfgang Schramm and Contributors
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
*******************************************************************************/
package net.tourbook.chart.preferences;

public interface IChartPreferences {

public static final String GRAPH_MOUSE_KEY_TRANSLATION = "GRAPH_MOUSE_KEY_TRANSLATION"; //$NON-NLS-1$
}
1 change: 1 addition & 0 deletions bundles/net.tourbook/META-INF/MANIFEST.MF
Expand Up @@ -80,6 +80,7 @@ Import-Package: com.fasterxml.jackson.core.type,
com.javadocmd.simplelatlng,
cop.swt.widgets.viewers.table.celleditors,
net.tourbook.chart,
net.tourbook.chart.preferences,
net.tourbook.common,
net.tourbook.common.action,
net.tourbook.common.color,
Expand Down
5 changes: 5 additions & 0 deletions bundles/net.tourbook/src/net/tourbook/Messages.java
Expand Up @@ -1572,6 +1572,7 @@ public class Messages extends NLS {
public static String Pref_Graphs_Group_Graphs;
public static String Pref_Graphs_Group_Grid;
public static String Pref_Graphs_Group_mouse_mode;
public static String Pref_Graphs_Group_MouseKeyTranslation;
public static String Pref_Graphs_Group_units_for_xaxis;
public static String Pref_Graphs_Group_zoom_options;
public static String Pref_Graphs_Label_GraphTransparency;
Expand All @@ -1587,6 +1588,10 @@ public class Messages extends NLS {
public static String Pref_Graphs_move_sliders_when_zoomed;
public static String Pref_Graphs_Radio_mouse_mode_slider;
public static String Pref_Graphs_Radio_mouse_mode_zoom;
public static String Pref_Graphs_Radio_MouseKey_UpLeft;
public static String Pref_Graphs_Radio_MouseKey_UpLeft_Tooltip;
public static String Pref_Graphs_Radio_MouseKey_UpRight;
public static String Pref_Graphs_Radio_MouseKey_UpRight_Tooltip;
public static String Pref_Graphs_Radio_show_distance;
public static String Pref_Graphs_Radio_show_time;
public static String Pref_Graphs_Tab_graph_defaults;
Expand Down

0 comments on commit e18e488

Please sign in to comment.