Skip to content

Commit aa36a80

Browse files
authored
Merge pull request #165 from SeeSharpSoft/fb_table_scrolling
[INTERNAL] table editor scrolling
2 parents b729920 + 563b079 commit aa36a80

File tree

9 files changed

+55
-20
lines changed

9 files changed

+55
-20
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ jdk:
55
env:
66
- IDEA_VERSION=IC-2017.3.1 GRAMMAR_KIT_VERSION=2017.1.2
77
- IDEA_VERSION=IC-2018.3.2 GRAMMAR_KIT_VERSION=2017.1.7
8-
- IDEA_VERSION=IC-2019.1.3 GRAMMAR_KIT_VERSION=2017.1.7
9-
# - IDEA_VERSION=PC-LATEST-EAP-SNAPSHOT GRAMMAR_KIT_VERSION=07f30a1e7666f36ae780f614b6bbc89690ba36c3
8+
- IDEA_VERSION=PC-LATEST-EAP-SNAPSHOT GRAMMAR_KIT_VERSION=2019.3
109

1110
script: xvfb-run gradle check
1211

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.8.1
2+
Nov 22, 2019
3+
4+
FIX: scrolling within table editor #164
5+
16
2.8.0
27
Oct 12, 2019
38

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jacocoTestReport {
2424
}
2525

2626
group 'net.seesharpsoft.intellij.plugins'
27-
version '2.8.0'
27+
version '2.8.1'
2828

2929
apply plugin: 'java'
3030
sourceCompatibility = javaVersion
@@ -71,7 +71,7 @@ idea {
7171
apply plugin: 'org.jetbrains.intellij'
7272
intellij {
7373
// IDE version - https://www.jetbrains.com/intellij-repository/releases
74-
version = System.getenv().getOrDefault('IDEA_VERSION', 'IC-191.5701.16')
74+
version = System.getenv().getOrDefault('IDEA_VERSION', 'IC-2019.1.3')
7575
pluginName = 'CSV Plugin'
7676
instrumentCode = true
7777
updateSinceUntilBuild = false
@@ -98,7 +98,7 @@ grammarKit {
9898
jflexRelease = '1.7.0-1'
9999

100100
// tag or short commit hash of Grammar-Kit to use - https://github.com/JetBrains/Grammar-Kit
101-
grammarKitRelease = System.getenv().getOrDefault('GRAMMAR_KIT_VERSION', '2017.1.7')
101+
grammarKitRelease = System.getenv().getOrDefault('GRAMMAR_KIT_VERSION', '2019.1.1')
102102
}
103103

104104
import org.jetbrains.grammarkit.tasks.GenerateLexer
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;
22

3+
import javax.swing.*;
34
import java.awt.event.MouseWheelEvent;
45
import java.awt.event.MouseWheelListener;
56

67
public class CsvTableEditorMouseWheelListener extends CsvTableEditorUtilBase implements MouseWheelListener {
78

8-
public static final int SCROLL_FACTOR = 3;
9+
public static final int ZOOM_FACTOR = 3;
10+
11+
protected static final int SCROLL_FACTOR = 100;
912

1013
public CsvTableEditorMouseWheelListener(CsvTableEditorSwing csvTableEditorArg) {
1114
super(csvTableEditorArg);
1215
}
1316

1417
@Override
1518
public void mouseWheelMoved(MouseWheelEvent mouseWheelEvent) {
16-
1719
if (mouseWheelEvent.isControlDown()) {
1820
int scrolled = mouseWheelEvent.getUnitsToScroll();
19-
int amount = -(scrolled / SCROLL_FACTOR);
21+
int amount = -(scrolled / ZOOM_FACTOR);
2022
if (amount == 0) {
2123
return;
2224
}
2325
csvTableEditor.changeFontSize(amount);
26+
} else {
27+
JScrollPane scrollPane = csvTableEditor.getTableScrollPane();
28+
JScrollBar vScrollbar = scrollPane.getVerticalScrollBar();
29+
vScrollbar.setValue(vScrollbar.getValue() + (int)(SCROLL_FACTOR * mouseWheelEvent.getPreciseWheelRotation()));
2430
}
2531
}
2632
}

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
</grid>
219219
</children>
220220
</scrollpane>
221-
<scrollpane id="6b9c5">
221+
<scrollpane id="6b9c5" binding="tableScrollPane">
222222
<constraints>
223223
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
224224
</constraints>

src/main/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwing.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public class CsvTableEditorSwing extends CsvTableEditor implements TableDataChan
5858
private JCheckBox cbFixedHeaders;
5959
private JCheckBox cbAutoColumnWidthOnOpen;
6060
protected LinkLabel lnkAdjustColumnWidth;
61+
private JScrollPane tableScrollPane;
6162

6263
private JTable rowHeadersTable;
6364

@@ -340,6 +341,10 @@ protected JBTable getTable() {
340341
return this.tblEditor;
341342
}
342343

344+
protected JScrollPane getTableScrollPane() {
345+
return this.tableScrollPane;
346+
}
347+
343348
protected DefaultTableModel getTableModel() {
344349
return (DefaultTableModel) tblEditor.getModel();
345350
}

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444

4545
<change-notes><![CDATA[
4646
<pre style="font-family: sans-serif">
47-
NEW: improved font handling in table editor #122
48-
FIX: proper font handling in balloon tooltips
47+
FIX: scrolling within table editor #164
4948
5049
NOTE: IDE versions prior to 2017.3.* are no longer supported!
5150
</pre>
Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
11
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;
22

3-
import net.seesharpsoft.intellij.plugins.csv.editor.table.CsvTableEditor;
43
import org.mockito.Mockito;
54

65
import javax.swing.*;
7-
import java.awt.event.InputEvent;
8-
import java.awt.event.MouseEvent;
96
import java.awt.event.MouseWheelEvent;
107

118
public class CsvTableEditorMouseWheelListenerTest extends CsvTableEditorSwingTestBase {
129

13-
public void testWheeledOnCsvTable() {
10+
@Override
11+
protected String getTestFile() { return "AnyFile.csv"; }
12+
13+
public void testZoomOnCsvTable() {
1414
CsvTableEditorSwing fileEditor = Mockito.spy(this.fileEditor);
15-
15+
1616
MouseWheelEvent wheelEvent = new MouseWheelEvent(fileEditor.getTable(),
1717
MouseWheelEvent.MOUSE_WHEEL,JComponent.WHEN_FOCUSED,
1818
MouseWheelEvent.CTRL_MASK,0,0,0,false,MouseWheelEvent.WHEEL_UNIT_SCROLL,
1919
3,-1);
2020

2121
CsvTableEditorMouseWheelListener spiedMouseWheelListener = fileEditor.tableEditorMouseWheelListener;
2222

23-
int size=fileEditor.getTable().getFont().getSize();
23+
int size = fileEditor.getTable().getFont().getSize();
24+
spiedMouseWheelListener.mouseWheelMoved(wheelEvent);
25+
int new_size = fileEditor.getTable().getFont().getSize();
26+
27+
assertEquals(size + 1, new_size);
28+
}
29+
30+
public void testScrollOnCsvTable() {
31+
CsvTableEditorSwing fileEditor = Mockito.spy(this.fileEditor);
32+
33+
MouseWheelEvent wheelEvent = new MouseWheelEvent(fileEditor.getTable(),
34+
MouseWheelEvent.MOUSE_WHEEL,JComponent.WHEN_FOCUSED,
35+
0,0,0,0,false, MouseWheelEvent.WHEEL_UNIT_SCROLL,
36+
1,1);
37+
38+
CsvTableEditorMouseWheelListener spiedMouseWheelListener = fileEditor.tableEditorMouseWheelListener;
39+
40+
int scrollValue = fileEditor.getTableScrollPane().getVerticalScrollBar().getValue();
41+
assertEquals(0, scrollValue);
2442
spiedMouseWheelListener.mouseWheelMoved(wheelEvent);
25-
int new_size=fileEditor.getTable().getFont().getSize();
43+
scrollValue = fileEditor.getTableScrollPane().getVerticalScrollBar().getValue();
2644

27-
assertTrue(new_size == size + 1);
45+
// 90 is max in this case
46+
assertEquals(90, scrollValue);
2847
}
2948
}

src/test/java/net/seesharpsoft/intellij/plugins/csv/editor/table/swing/CsvTableEditorSwingTestBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ protected String getTestDataPath() {
1919
return "./src/test/resources/editor";
2020
}
2121

22+
protected String getTestFile() { return "TableEditorFile.csv"; }
23+
2224
@Override
2325
protected void setUp() throws Exception {
2426
super.setUp();
2527
initializeEditorSettings(CsvEditorSettingsExternalizable.getInstance());
26-
myFixture.configureByFiles("TableEditorFile.csv");
28+
myFixture.configureByFiles(getTestFile());
2729

2830
fileEditor = new CsvTableEditorSwing(this.getProject(), myFixture.getFile().getVirtualFile());
2931
fileEditor.selectNotify();

0 commit comments

Comments
 (0)