Skip to content

Commit

Permalink
Added mouse position caching as a partial workaround for #723
Browse files Browse the repository at this point in the history
This workaround enabled faster browsing through entities, but there is a noticeable delay in showing hyperlinks when mousing over expressions.
  • Loading branch information
matthewhorridge committed Jan 17, 2019
1 parent 30ac94f commit 7551bd7
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import org.protege.editor.core.ui.util.UIUtil;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
import java.util.List;

/**
Expand Down Expand Up @@ -79,7 +79,10 @@ public String getName() {

public int lastMousePositionCellIndex = -1;


private Point cachedMousePosition = null;

private boolean cachedMousePositionStale = true;

public MList() {
ListCellRenderer renderer = this.getCellRenderer();
this.ren = new MListCellRenderer();
Expand Down Expand Up @@ -148,13 +151,14 @@ protected void clearCellHeightCache() {


private void handleMouseMoved() {
cachedMousePositionStale = true;
if (MList.this.getModel().getSize() > 0) {
// only repaint all the cells the mouse has moved over
Rectangle dirty = getCellBounds(lastMousePositionCellIndex, lastMousePositionCellIndex);
if (dirty != null) {
repaint(dirty);
}
Point pt = MList.this.getMousePosition();
Point pt = getCachedMousePosition();
if (pt != null) {
lastMousePositionCellIndex = MList.this.locationToIndex(pt);
}
Expand Down Expand Up @@ -387,7 +391,7 @@ else if (obj instanceof MListItem) {

@Override
public String getToolTipText(MouseEvent event) {
Point mousePos = this.getMousePosition();
Point mousePos = getCachedMousePosition();
if (mousePos == null) {
return null;
}
Expand Down Expand Up @@ -491,7 +495,7 @@ private int paintButton(Graphics2D g2, Rectangle clipBound, int endOfButtonRun,
}

private Color getButtonColor(MListButton button) {
Point pt = this.getMousePosition();
Point pt = getCachedMousePosition();
if (pt == null) {
return button.getBackground();
}
Expand All @@ -506,4 +510,13 @@ private Color getButtonColor(MListButton button) {
return button.getBackground();
}

@Nullable
private Point getCachedMousePosition() {
if(cachedMousePositionStale) {
cachedMousePosition = getMousePosition();
cachedMousePositionStale = false;
}
return cachedMousePosition;
}

}

0 comments on commit 7551bd7

Please sign in to comment.