Skip to content

Commit

Permalink
Fix NPE when configuring the layout on Ubuntu X11/Wayland
Browse files Browse the repository at this point in the history
fix issue #59
fix issue roan/KeysPerSecond#227
  • Loading branch information
RoanH committed Oct 8, 2022
1 parent 42d1ec6 commit fb3e5e2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
32 changes: 32 additions & 0 deletions KeysPerSecond/src/dev/roanh/kps/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,38 @@ protected Configuration(Path data){
this.data = data;
}

public final int getGraphX(){
return graph_x;
}

public final int getGraphY(){
return graph_y;
}

public final int getGraphWidth(){
return graph_w;
}

public final int getGraphHeight(){
return graph_h;
}

public final void setGraphX(int x){
graph_x = x;
}

public final void setGraphY(int y){
graph_y = y;
}

public final void setGraphWidth(int width){
graph_w = width;
}

public final void setGraphHeight(int height){
graph_h = height;
}

/**
* Gets the location on disk for this configuration file.
* @return The on disk location of the configuration file.
Expand Down
32 changes: 8 additions & 24 deletions KeysPerSecond/src/dev/roanh/kps/ui/dialog/LayoutDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,46 +140,30 @@ public static final void configureLayout(boolean live){
graphLayout.add(graphMode);

LayoutValidator validator = new LayoutValidator();
validator.getXField().setModel(new EndNumberModel(Main.config.graph_x, validator.getXField(), update(Main.config::setGraphX, live)));
validator.getYField().setModel(new EndNumberModel(Main.config.graph_y, validator.getYField(), update(Main.config::setGraphY, live)));
validator.getWidthField().setModel(new MaxNumberModel(Main.config.graph_w, validator.getWidthField(), update(Main.config::setGraphWidth, live)));
validator.getHeightField().setModel(new MaxNumberModel(Main.config.graph_h, validator.getHeightField(), update(Main.config::setGraphHeight, live)));

graphLayout.add(new JLabel("Graph x position: "));
JSpinner x = new JSpinner(new EndNumberModel(Main.config.graph_x, validator.getXField(), (val)->{
Main.config.graph_x = val;
if(live){
Main.reconfigure();
}
}));
JSpinner x = new JSpinner(validator.getXField().getModel());
x.setEditor(new SpecialNumberModelEditor(x));
x.setEnabled(Main.config.graphMode == GraphMode.INLINE);
graphLayout.add(x);

graphLayout.add(new JLabel("Graph y position: "));
JSpinner y = new JSpinner(new EndNumberModel(Main.config.graph_y, validator.getYField(), (val)->{
Main.config.graph_y = val;
if(live){
Main.reconfigure();
}
}));
JSpinner y = new JSpinner(validator.getYField().getModel());
y.setEditor(new SpecialNumberModelEditor(y));
y.setEnabled(Main.config.graphMode == GraphMode.INLINE);
graphLayout.add(y);

graphLayout.add(new JLabel("Graph width: "));
JSpinner w = new JSpinner(new MaxNumberModel(Main.config.graph_w, validator.getWidthField(), (val)->{
Main.config.graph_w = val;
if(live){
Main.reconfigure();
}
}));
JSpinner w = new JSpinner(validator.getWidthField().getModel());
w.setEditor(new SpecialNumberModelEditor(w));
graphLayout.add(w);

graphLayout.add(new JLabel("Graph height: "));
JSpinner h = new JSpinner(new MaxNumberModel(Main.config.graph_h, validator.getHeightField(), (val)->{
Main.config.graph_h = val;
if(live){
Main.reconfigure();
}
}));
JSpinner h = new JSpinner(validator.getHeightField().getModel());
h.setEditor(new SpecialNumberModelEditor(h));
graphLayout.add(h);

Expand Down

0 comments on commit fb3e5e2

Please sign in to comment.