Skip to content

Commit

Permalink
- WIP on filters
Browse files Browse the repository at this point in the history
- change system tray icon
  • Loading branch information
jpage4500 committed Jul 18, 2024
1 parent 208cff4 commit 74b887f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private void setupSystemTray() {
// get the SystemTray instance
SystemTray tray = SystemTray.getSystemTray();

BufferedImage image = UiUtils.getImage("tray_icon.png", 100, 100);
BufferedImage image = UiUtils.getImage("system_tray.png", 100, 100);
PopupMenu popup = new PopupMenu();
MenuItem openItem = new MenuItem("Open");
openItem.addActionListener(e2 -> bringWindowToFront());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.jpage4500.devicemanager.table.LogsTableModel;
import com.jpage4500.devicemanager.ui.views.HintTextField;
import com.jpage4500.devicemanager.utils.ArrayUtils;
import com.jpage4500.devicemanager.utils.UiUtils;
import net.miginfocom.swing.MigLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -18,7 +19,7 @@ public class AddFilterDialog extends JPanel {

private LogFilter logFilter;
private HintTextField nameTextField;
private List<FilterPanel> filterList;
private List<FilterPanel> panelList;

public static LogFilter showAddFilterDialog(Component frame, LogFilter logFilter) {
String okButton = logFilter == null ? "Save" : "Update";
Expand All @@ -35,7 +36,7 @@ public static LogFilter showAddFilterDialog(Component frame, LogFilter logFilter
public AddFilterDialog(LogFilter logFilter) {
if (logFilter == null) logFilter = new LogFilter();
this.logFilter = logFilter;
filterList = new ArrayList<>();
panelList = new ArrayList<>();

initalizeUi();
}
Expand All @@ -44,34 +45,55 @@ protected void initalizeUi() {
setLayout(new MigLayout("fillx", "[][][][]"));

nameTextField = new HintTextField("Filter Name", null);
add(nameTextField, "span 4, grow, wrap 2");
add(nameTextField, "span 3, grow, wrap 2");

JScrollPane scrollPane = new JScrollPane(nameTextField);
addFilter();

// add/update filter
JButton addButton = new JButton("Add Filter");
JButton addButton = new JButton();
addButton.setIcon(UiUtils.getImageIcon("icon_add.png", 20));
addButton.addActionListener(e -> handleAddClicked());
add(addButton, "skip 2, wrap");
//add(addButton, "skip 3, wrap");
}

private void addFilter() {
FilterPanel filterPanel = new FilterPanel();

add(filterPanel.columnComboBox, "");
add(filterPanel.expressionComboBox, "");
add(filterPanel.valueField, "grow, wrap");
add(filterPanel.valueField, "grow, wmin 150");
add(filterPanel.deleteButton, "wrap");
revalidate();
repaint();

filterList.add(filterPanel);
filterPanel.deleteButton.addActionListener(actionEvent -> {
deletePanel(filterPanel);
});

panelList.add(filterPanel);
}

private void handleAddClicked() {
addFilter();
}

private void deletePanel(FilterPanel filterPanel) {
panelList.remove(filterPanel);
remove(filterPanel.columnComboBox);
remove(filterPanel.expressionComboBox);
remove(filterPanel.valueField);
remove(filterPanel.deleteButton);

revalidate();
repaint();
}

public static class FilterPanel {
private JComboBox<LogsTableModel.Columns> columnComboBox;
private JComboBox<LogFilter.Expression> expressionComboBox;
private JTextField valueField;
private HintTextField valueField;
private JButton deleteButton;

public FilterPanel() {
// column
Expand All @@ -85,7 +107,10 @@ public FilterPanel() {
int exprIndex = ArrayUtils.indexOf(expressions, LogFilter.Expression.STARTS_WITH);
expressionComboBox.setSelectedIndex(exprIndex);

valueField = new JTextField();
deleteButton = new JButton();
deleteButton.setIcon(UiUtils.getImageIcon("icon_delete.png", 20));

valueField = new HintTextField("Value", null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ public boolean restoreTable() {
TableColumnModel columnModel = getColumnModel();
// 1) backup columns to ColumnDetails
for (ColumnDetails details : detailsList) {
if (details.name == null) {
log.debug("restoreTable: invalid: {}", GsonHelper.toJson(details));
continue;
}
details.column = getColumnByName(details.name);
if (details.column != null) {
columnModel.removeColumn(details.column);
Expand Down Expand Up @@ -396,7 +400,7 @@ public TableColumn getColumnByName(String searchName) {
return column;
}
}
log.error("getColumnByName: NOT_FOUND:{}", searchName);
log.error("getColumnByName: NOT_FOUND:{}, {}", searchName, Utils.getStackTraceString());
return null;
}

Expand Down Expand Up @@ -426,7 +430,11 @@ public void saveTable() {
details.userPos = i;
details.modelPos = column.getModelIndex();
details.width = column.getWidth();
int maxWidth = column.getMaxWidth();
//int maxWidth = column.getMaxWidth();
if (details.name == null) {
log.debug("saveTable: invalid name:{} ({})", GsonHelper.toJson(details), prefKey);
continue;
}
detailList.add(details);
//log.trace("persist: {}, pos:{}, i:{}, w:{}, max:{}", details.header, i, details.modelPos, details.width, details.maxWidth);
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/jpage4500/devicemanager/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,23 @@ public static CompareResult compareVersion(String v1, String v2) {
return CompareResult.VERSION_EQUALS;
}

public static String getStackTraceString() {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < stackTrace.length; i++) {
// ignore THIS call
if (i < 2) continue;
StackTraceElement element = stackTrace[i];
//String className = element.getClassName();
String fileName = element.getFileName();
int lineNumber = element.getLineNumber();
// only show this app's classes
if (fileName == null || lineNumber == -1) continue;
if (!sb.isEmpty()) sb.append(", ");
sb.append("{" + fileName + ", " + element.getMethodName() + ", " + lineNumber + "}");
}

return sb.toString();
}

}
Binary file added src/main/resources/images/system_tray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 74b887f

Please sign in to comment.