Skip to content

Commit

Permalink
add preferences and set display time for tooltips to preferences value
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi Delbruck authored and Tobi Delbruck committed Jun 18, 2024
1 parent 29896b1 commit 9d3cb1c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/net/sf/jaer/graphics/DisplayMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.prefs.Preferences;
import net.sf.jaer.util.DrawGL;
import org.apache.commons.text.WordUtils;
import static org.apache.tools.ant.util.ScriptManager.javax;

/**
* A abstract class that displays AE data in a ChipCanvas using OpenGL.
Expand All @@ -37,6 +39,7 @@
*/
public abstract class DisplayMethod implements PropertyChangeListener {

protected Preferences prefs=Preferences.userNodeForPackage(DisplayMethod.class);
private ChipCanvas chipCanvas;
protected GLUT glut; // GL extensions
protected GLU glu; // GL utilities
Expand All @@ -47,7 +50,7 @@ public abstract class DisplayMethod implements PropertyChangeListener {
private ArrayList<FrameAnnotater> annotators = new ArrayList<>();
private String statusChangeString = null;
private long statusChangeStartTimeMillis = 0;
private final long statusChangeDisplayTimeMillis = 1000;
private int statusChangeDisplayTimeMillis = prefs.getInt("statusChangeDisplayTimeMillis", 1000);
/**
* Provides PropertyChangeSupport for all DisplayMethods
*/
Expand Down Expand Up @@ -190,12 +193,12 @@ protected void onDeregistration() {
* @param drawable the OpenGL context
*/
protected void displayStatusChangeText(GLAutoDrawable drawable) {
if (statusChangeString == null) {
if (statusChangeString == null || statusChangeDisplayTimeMillis<=0) {
return;
}
long now = System.currentTimeMillis();
final int WRAP_LEN = 24;
if ((now - statusChangeStartTimeMillis) > statusChangeDisplayTimeMillis * (1 + (statusChangeString.length() / WRAP_LEN))) {
if ((now - statusChangeStartTimeMillis) > getStatusChangeDisplayTimeMillis() * (1 + (statusChangeString.length() / WRAP_LEN))) {
statusChangeString = null;
return;
}
Expand All @@ -214,7 +217,7 @@ protected void displayStatusChangeText(GLAutoDrawable drawable) {
}
}

int fontsize = Math.round(16*(chip.getSizeX()/346f)); // heuristic to scale font based on empirical estimate for DAVIS346
int fontsize = Math.round(8*(chip.getSizeX()/346f)); // heuristic to scale font based on empirical estimate for DAVIS346
// if font is too small, then make a larger one and scale all the drawing
float scale=1;
if(fontsize<10){
Expand Down Expand Up @@ -273,4 +276,19 @@ public PropertyChangeSupport getSupport() {
public void propertyChange(PropertyChangeEvent evt) {
// does nothing by default
}

/**
* @return the statusChangeDisplayTimeMillis
*/
public int getStatusChangeDisplayTimeMillis() {
return statusChangeDisplayTimeMillis;
}

/**
* @param statusChangeDisplayTimeMillis the statusChangeDisplayTimeMillis to set
*/
public void setStatusChangeDisplayTimeMillis(int statusChangeDisplayTimeMillis) {
this.statusChangeDisplayTimeMillis = statusChangeDisplayTimeMillis;
prefs.putInt("statusChangeDisplayTimeMillis", statusChangeDisplayTimeMillis);
}
}

0 comments on commit 9d3cb1c

Please sign in to comment.