Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add manufacturer name to device and dark mode #2650

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<jogl.version>2.5.0</jogl.version>
<miglayout.version>11.4.2</miglayout.version>
<guava.version>33.0.0-jre</guava.version>
<jserialcomm.version>2.10.4</jserialcomm.version>
<jserialcomm.version>2.11.0</jserialcomm.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<commons-io.version>2.14.0</commons-io.version>
<commons-csv.version>1.9.0</commons-csv.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ public class DefaultConnectionDevice extends AbstractConnectionDevice {
private final String address;
private final Integer port;
private final String description;
private final String manufacturer;

public DefaultConnectionDevice(String address) {
this(address, null, "");
this(address, null, "", "");
}

public DefaultConnectionDevice(String address, Integer port, String description) {
public DefaultConnectionDevice(String address, Integer port, String description, String manufacturer) {
this.address = address;
this.port = port;
this.description = description;
this.manufacturer = manufacturer;
}

@Override
Expand All @@ -60,6 +62,14 @@ public Optional<String> getDescription() {
return Optional.of(description);
}

@Override
public Optional<String> getManufacturer() {
if (StringUtils.isEmpty(manufacturer)) {
return Optional.empty();
}
return Optional.of(manufacturer);
}

@Override
public String toString() {
return super.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ public interface IConnectionDevice {
Optional<Integer> getPort();

/**
* Get the an optional description of the device
* Get the optional description of the device
*
* @return the description of the device
*/
Optional<String> getDescription();

/**
* Get the manufacturer of the device
*
* @return the manufacturer
*/
Optional<String> getManufacturer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,13 @@ public Optional<String> getDescription() {
public Optional<Integer> getPort() {
return Optional.empty();
}

@Override
public Optional<String> getManufacturer() {
String manufacturer = serialPort.getManufacturer();
if (StringUtils.isEmpty(manufacturer)) {
return Optional.empty();
}
return Optional.of(manufacturer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void run() {
@Override
public List<? extends IConnectionDevice> getDevices() {
return MdnsService.getInstance().getServices(MDNS_SERVICE).stream()
.map(service -> new DefaultConnectionDevice(service.getHost(), service.getPort(), service.getName()))
.map(service -> new DefaultConnectionDevice(service.getHost(), service.getPort(), service.getName(), "Port " + service.getPort()))
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Will Winder
Copyright 2023-2024 Will Winder

This file is part of Universal Gcode Sender (UGS).

Expand All @@ -19,13 +19,16 @@ This file is part of Universal Gcode Sender (UGS).
package com.willwinder.ugs.nbp.core.ui;

import com.willwinder.universalgcodesender.connection.IConnectionDevice;
import net.miginfocom.swing.MigLayout;
import org.openide.util.ImageUtilities;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;

/**
* Renders a connection device
Expand All @@ -36,41 +39,40 @@ public class PortCellItem extends JPanel {
private static final Border DEFAULT_BORDER = new EmptyBorder(5, 5, 5, 5);

PortCellItem(JList<? extends IConnectionDevice> list, IConnectionDevice device, boolean isSelected) {
super(new BorderLayout());
super(new MigLayout());
setOpaque(true);
setBorder(DEFAULT_BORDER);
populatePortInfo(device);
setComponentOrientation(list.getComponentOrientation());

if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
for(Component component : getComponents()) {
if (isSelected) {
setBackground(list.getSelectionBackground());
component.setBackground(list.getSelectionBackground());
component.setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
component.setBackground(list.getBackground());
component.setForeground(list.getForeground());
}
}

setEnabled(list.isEnabled());
setFont(list.getFont());
}

private void populatePortInfo(IConnectionDevice device) {
if (!device.getDescription().isPresent()) {
setTitle(device.getAddress());
} else {
setTitleAndDescription(device);
}
}
add(new JLabel(ImageUtilities.loadImageIcon("resources/icons/device24.svg", false)), "spany");

private void setTitle(String title) {
JLabel addressLabel = new JLabel(title);
add(addressLabel, BorderLayout.CENTER);
}
JLabel label = new JLabel(device.getAddress());
Font f = label.getFont();
label.setFont(f.deriveFont(Font.BOLD));
add(label, "wrap, growx, align left");

private void setTitleAndDescription(IConnectionDevice device) {
setTitle(device.getDescription().orElse(device.getAddress()));
JLabel addressLabel = new JLabel(device.getAddress());
addressLabel.setFont(addressLabel.getFont().deriveFont(8f));
add(addressLabel, BorderLayout.SOUTH);
if (device.getDescription().isPresent()) {
add(new JLabel(device.getDescription().orElse(device.getAddress())), "wrap, growx, align left");
}

if (device.getManufacturer().isPresent()) {
add(new JLabel(device.getManufacturer().get()) , "wrap, growx, align left");
}
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading