Skip to content

Commit

Permalink
'#1864 better position and render of time event group selection combo
Browse files Browse the repository at this point in the history
box.
  • Loading branch information
patrickdalla committed Feb 22, 2024
1 parent 1a4c745 commit 4926400
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
13 changes: 10 additions & 3 deletions iped-app/src/main/java/iped/app/timelinegraph/IpedChartsPanel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package iped.app.timelinegraph;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
Expand Down Expand Up @@ -154,6 +155,7 @@ public class IpedChartsPanel extends JPanel implements ResultSetViewer, TableMod
IpedChartPanel chartPanel = null;
JList legendList = new JList();
JScrollPane listScroller = new JScrollPane(legendList);
JPanel legendPane = new JPanel();
JComboBox<TimeEventGroup> tegCombo = new JComboBox<>();

IpedStackedXYBarRenderer renderer = null;
Expand Down Expand Up @@ -309,8 +311,8 @@ public boolean test(TimeEventGroup t) {
}
});
tegCombo.setRenderer(cblcRenderer);
chartPanel.add(tegCombo);
tegCombo.addActionListener(this);
tegCombo.setMaximumSize(new Dimension(100, 0));

legendListModel = new DefaultListModel<LegendItemBlockContainer>();
legendList.setModel(legendListModel);
Expand Down Expand Up @@ -362,7 +364,12 @@ public void check(MouseEvent e) {
ttm.setEnabled(true);

splitPane.setTopComponent(chartPanel);
splitPane.setBottomComponent(listScroller);

legendPane.setPreferredSize(new Dimension(Integer.MAX_VALUE, 80));
legendPane.setLayout(new BorderLayout());
legendPane.add(tegCombo, BorderLayout.NORTH);
legendPane.add(listScroller, BorderLayout.CENTER);
splitPane.setBottomComponent(legendPane);
splitPane.setVisible(false);

chartPanel.setPopupMenu(null);
Expand Down Expand Up @@ -544,7 +551,7 @@ public void run() {
self.remove(splitPane);
self.add(splitPane);
splitPane.setTopComponent(chartPanel);
splitPane.setBottomComponent(listScroller);
splitPane.setBottomComponent(legendPane);
splitPane.setVisible(true);

// hide hidden events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import java.util.function.Predicate;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

public class CheckboxListCellRenderer<E> extends JPanel implements ListCellRenderer<E> {
JCheckBox enabledCheckBox = new JCheckBox();
JLabel selectedValues = new JLabel();
Predicate isEnabled;
int maxStringWidth = 0;
boolean indexedPredicate = false;
Expand All @@ -32,6 +34,30 @@ public CheckboxListCellRenderer(Predicate isEnabled, boolean indexedPredicate) {
@Override
public Component getListCellRendererComponent(JList<? extends E> list, E value, int index, boolean isSelected,
boolean cellHasFocus) {
if (index == -1) {

StringBuffer sb = new StringBuffer();
sb.append(" ");
for (int i = 0; i < list.getModel().getSize(); i++) {
Object lvalue = list.getModel().getElementAt(i);
boolean include = false;
if (indexedPredicate) {
if (isEnabled.test(i)) {
include = true;
}
} else {
if (isEnabled.test(lvalue)) {
include = true;
}
}
if (include) {
sb.append(lvalue);
sb.append(",");
}
}
selectedValues.setText(sb.toString());
return selectedValues;
}
if (indexedPredicate) {
enabledCheckBox.setSelected(isEnabled.test(index));
} else {
Expand Down

0 comments on commit 4926400

Please sign in to comment.