Skip to content

Commit 2762e26

Browse files
author
Michael Schroeder
committed
fix: focus and scroll behaviour (keybaord interaction)
1 parent ede3634 commit 2762e26

File tree

12 files changed

+66
-29
lines changed

12 files changed

+66
-29
lines changed

org.gitools.heatmap/src/main/java/org/gitools/heatmap/AbstractMatrixViewDimension.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ public MatrixDimensionKey getId() {
252252
}
253253

254254
@Override
255+
/**
256+
* Size of items (rows or columsn)
257+
*/
255258
public int size() {
256259
return visible.size();
257260
}

org.gitools.heatmap/src/main/java/org/gitools/heatmap/HeatmapDimension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public boolean showGrid() {
165165
return getCellSize() > 4;
166166
}
167167

168-
public int getFullSize() {
168+
public int getFullCellSize() {
169169
if (showGrid()) {
170170
return getCellSize() + getGridSize();
171171
}

org.gitools.ui.app/src/main/java/org/gitools/ui/app/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void windowClosed(final WindowEvent e) {
9797
progress.setVisible(true);
9898

9999

100-
setProgressText(progress, "Loading persistance manager");
100+
setProgressText(progress, "Loading Gitools interface");
101101
// Initialize Weld and ApplicationContext
102102
WeldContainer container = new StartMain(args).go();
103103
ApplicationContext.setPersistenceManager(container.instance().select(PersistenceManager.class).get());

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/drawer/AbstractHeatmapDrawer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ protected void drawSelectedHighlightedAndFocus(Graphics2D g, Rectangle box, Heat
216216
end = this.onScreenRect.colEnd;
217217
}
218218

219-
int cellSize = dimension.getFullSize();
219+
int cellSize = dimension.getFullCellSize();
220220
for (int i = start; i <= end; i++) {
221221
String id = dimension.getLabel(i);
222222
Color paint = null;

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/drawer/AbstractHeatmapHeaderDrawer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public Point getPoint(HeatmapPosition p) {
5555
protected int getHeaderPoint(int index) {
5656

5757
HeatmapDimension hdim = getHeatmapDimension();
58-
int cellSize = hdim.getFullSize();
58+
int cellSize = hdim.getFullCellSize();
5959
int totalSize = cellSize * hdim.size();
6060

6161
int point = index >= 0 ? index * cellSize : 0;
@@ -84,7 +84,7 @@ public HeatmapPosition getPosition(Point p) {
8484
protected int getHeaderPosition(int point) {
8585
HeatmapDimension hdim = getHeatmapDimension();
8686
int index = -1;
87-
int cellSize = hdim.getFullSize();
87+
int cellSize = hdim.getFullCellSize();
8888
int totalSize = cellSize * hdim.size();
8989
if (point >= 0 && point < totalSize) {
9090
index = point / cellSize;
@@ -95,7 +95,7 @@ protected int getHeaderPosition(int point) {
9595
@Override
9696
public Dimension getSize() {
9797
HeatmapDimension hdim = getHeatmapDimension();
98-
int total = (hdim.getFullSize()) * hdim.size();
98+
int total = (hdim.getFullCellSize()) * hdim.size();
9999
return (isHorizontal() ? new Dimension(total, getHeader().getSize()) : new Dimension(getHeader().getSize(), total));
100100
}
101101

@@ -112,7 +112,7 @@ public HeatmapDimension getHeatmapDimension() {
112112
}
113113

114114
protected int fullCellSize() {
115-
return heatmapDimension.getFullSize();
115+
return heatmapDimension.getFullCellSize();
116116
}
117117

118118
protected void prepareDraw(Graphics2D g, Rectangle box) {
@@ -128,7 +128,7 @@ protected void paintCell(Decoration decoration, int index, int offset, int width
128128
decoration,
129129
header.getBackgroundColor(),
130130
gridSize,
131-
offset, index * (heatmapDimension.getFullSize()),
131+
offset, index * (heatmapDimension.getFullCellSize()),
132132
width,
133133
heatmapDimension.getCellSize(),
134134
g,

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/drawer/HeatmapLayerBodyDrawer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,18 @@ protected void decorateCell(Decoration decoration, int row, int col) {
178178

179179
@Override
180180
public Dimension getSize() {
181-
return new Dimension(columns.getFullSize() * columns.size(), rows.getFullSize() * rows.size());
181+
return new Dimension(columns.getFullCellSize() * columns.size(), rows.getFullCellSize() * rows.size());
182182
}
183183

184184

185185
@Override
186186
public HeatmapPosition getPosition(Point p) {
187187

188-
int cellHeight = rows.getFullSize();
188+
int cellHeight = rows.getFullCellSize();
189189
int rowCount = rows.size();
190190
int totalHeight = cellHeight * rowCount;
191191

192-
int cellWidth = columns.getFullSize();
192+
int cellWidth = columns.getFullCellSize();
193193
int columnCount = columns.size();
194194
int totalWidth = cellWidth * columnCount;
195195

@@ -203,11 +203,11 @@ public HeatmapPosition getPosition(Point p) {
203203
@Override
204204
public Point getPoint(HeatmapPosition p) {
205205

206-
int cellHeight = rows.getFullSize();
206+
int cellHeight = rows.getFullCellSize();
207207
int rowCount = rows.size();
208208
int totalHeight = cellHeight * rowCount;
209209

210-
int cellWidth = columns.getFullSize();
210+
int cellWidth = columns.getFullCellSize();
211211
int columnCount = columns.size();
212212
int totalWidth = cellWidth * columnCount;
213213

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/drawer/header/HeatmapColoredLabelsDrawer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void draw(Graphics2D g, Rectangle box, Rectangle clip) {
7979
header.decorate(decoration, groupLabel, false);
8080
decoration.setRotate(true);
8181

82-
int fullSize = getHeatmapDimension().getFullSize();
82+
int fullSize = getHeatmapDimension().getFullCellSize();
8383
//gridSize = 0 (no grid) if same group
8484
int gridSize = ((getHeatmapDimension().getCellSize() > 2 && !highlighted && !isHighlightedIndex(endGroupIndex + 1)
8585
|| getHeatmapDimension().getCellSize() > 2 && !groupLabel.equals(header.getColoredLabel(endGroupIndex + 1)))

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/panel/HeatmapKeyboardController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private void moveLead(KeyEvent e) {
241241
case KeyEvent.VK_HOME:
242242
if (shiftDown) {
243243
col = 0;
244-
ip.setLead(++col, mv.getColumns());
244+
ip.setLead(col, mv.getColumns());
245245
if (selectingColumns) {
246246
ip.addToSelected(col, mv.getColumns());
247247
ip.setLastSelectedCol(col);

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/panel/HeatmapPanel.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,25 @@ public void makeRowFocusVisible() {
192192
checkFocusOutOfVisibleArea(heatmap.getRows(), rowSB, bodyVP.getSize().height);
193193
}
194194

195-
private void checkFocusOutOfVisibleArea(HeatmapDimension dimension, JScrollBar scrollBar, int visibleLength) {
195+
private void checkFocusOutOfVisibleArea(HeatmapDimension dimension, JScrollBar scrollBar, int visibleSize) {
196196

197-
int focusPoint = (dimension.indexOf(dimension.getFocus()) * dimension.getFullSize());
197+
int leadPoint = (dimension.indexOf(dimension.getFocus()) * dimension.getFullCellSize());
198198

199-
if (
200-
(focusPoint < scrollBar.getValue()) ||
201-
(scrollBar.getValue() + visibleLength < focusPoint)
202-
) {
203-
scrollBar.setValue(focusPoint);
199+
int min = 0;
200+
int max = dimension.getFullCellSize() * dimension.size();
201+
int margin = (dimension.getFullCellSize()*3 < 30) ? dimension.getFullCellSize()*3 : 30;
202+
int scrollPosition = scrollBar.getValue();
203+
204+
205+
if (leadPoint - margin < scrollPosition) {
206+
207+
int topFocus = leadPoint - margin;
208+
scrollBar.setValue(topFocus < min ? min : topFocus);
209+
210+
} else if (leadPoint + margin > scrollPosition + visibleSize) {
211+
int bottomFocus = leadPoint - visibleSize + margin;
212+
213+
scrollBar.setValue(bottomFocus < max ? bottomFocus : max - visibleSize);
204214
}
205215
}
206216

org.gitools.ui.app/src/main/java/org/gitools/ui/app/heatmap/panel/HeatmapPanelInputProcessor.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public class HeatmapPanelInputProcessor {
4242

4343
private IMatrixView mv;
4444
private Heatmap heatmap;
45-
private HeatmapPanel panel;
45+
private HeatmapPanel heatmapPanel;
4646

4747
public HeatmapPanelInputProcessor(HeatmapPanel heatmapPanel) {
4848

49-
this.panel = heatmapPanel;
49+
this.heatmapPanel = heatmapPanel;
5050
this.mv = heatmapPanel.getHeatmap();
5151
this.heatmap = heatmapPanel.getHeatmap();
5252

@@ -127,11 +127,11 @@ public void setLastSelectedRow(int lastSelectedRow) {
127127
public void scroll(int units, boolean horizontal) {
128128

129129
if (horizontal) {
130-
HeatmapPosition pos = panel.getScrollPosition();
131-
panel.setScrollColumnPosition(pos.column + units);
130+
HeatmapPosition pos = heatmapPanel.getScrollPosition();
131+
heatmapPanel.setScrollColumnPosition(pos.column + units);
132132
} else {
133-
HeatmapPosition pos = panel.getScrollPosition();
134-
panel.setScrollRowPosition(pos.row + units);
133+
HeatmapPosition pos = heatmapPanel.getScrollPosition();
134+
heatmapPanel.setScrollRowPosition(pos.row + units);
135135
}
136136
}
137137

@@ -196,6 +196,7 @@ public void removeFromSelected(Set<String> toRemove, IMatrixViewDimension dim) {
196196
}
197197

198198
public void setLead(int i, IMatrixViewDimension dim) {
199+
199200
int max = dim.size() - 1;
200201
if (i >= max) {
201202
dim.setFocus(dim.getLabel(max));
@@ -204,9 +205,18 @@ public void setLead(int i, IMatrixViewDimension dim) {
204205
} else {
205206
dim.setFocus(dim.getLabel(i));
206207
}
208+
209+
if (dim.getId().equals(MatrixDimensionKey.COLUMNS)) {
210+
heatmapPanel.makeColumnFocusVisible();
211+
} else {
212+
heatmapPanel.makeRowFocusVisible();
213+
}
214+
215+
207216
BoxManager.protect(MatrixDimensionKey.COLUMNS.name(), MatrixDimensionKey.ROWS.name());
208217
BoxManager.openOnly(LayerValuesBox.ID);
209218
BoxManager.reset();
219+
210220
}
211221

212222
public void setLead(int row, int col) {

0 commit comments

Comments
 (0)