Skip to content

Commit

Permalink
Dynamically resize the calls token list component
Browse files Browse the repository at this point in the history
  • Loading branch information
IotaBread committed Jan 16, 2024
1 parent 44d86ea commit 9ba8155
Showing 1 changed file with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class CallsTreeDocker extends Docker {
private final JTree tree = new JTree();
private final JList<Token> tokens = new JList<>();

private final JSplitPane contentPane;

public CallsTreeDocker(Gui gui) {
super(gui);
this.tree.setModel(null);
Expand All @@ -46,16 +48,16 @@ public CallsTreeDocker(Gui gui) {
this.tokens.setPreferredSize(ScaleUtil.getDimension(0, 200));
this.tokens.setMinimumSize(ScaleUtil.getDimension(0, 200));

JSplitPane contentPane = new JSplitPane(
this.contentPane = new JSplitPane(
JSplitPane.VERTICAL_SPLIT,
true,
new JScrollPane(this.tree),
new JScrollPane(this.tokens)
);

contentPane.setResizeWeight(1); // let the top side take all the slack
contentPane.resetToPreferredSizes();
this.add(contentPane, BorderLayout.CENTER);
this.contentPane.setResizeWeight(1); // let the top side take all the slack
this.contentPane.resetToPreferredSizes();
this.add(this.contentPane, BorderLayout.CENTER);
}

public void showCalls(Entry<?> entry, boolean recurse) {
Expand All @@ -77,10 +79,23 @@ public void showCalls(Entry<?> entry, boolean recurse) {
public void showTokens(Collection<Token> tokens) {
this.tokens.setListData(new Vector<>(tokens));
this.tokens.setSelectedIndex(0);
this.updateContentSize();
}

public void clearTokens() {
this.tokens.setListData(new Vector<>());
this.updateContentSize();
}

public void updateContentSize() {
int tokenCount = this.tokens.getModel().getSize();
if (tokenCount == 0) {
this.contentPane.setResizeWeight(1);
this.contentPane.resetToPreferredSizes();
} else {
this.contentPane.setResizeWeight(0.75);
this.contentPane.resetToPreferredSizes();
}
}

@SuppressWarnings("unchecked")
Expand Down

0 comments on commit 9ba8155

Please sign in to comment.