add info box in the import dialog

This commit is contained in:
bancika
2021-01-03 00:21:05 +01:00
parent 75758e0250
commit 1737df8047
3 changed files with 50 additions and 23 deletions
Binary file not shown.
@@ -68,7 +68,7 @@ public class UploadDialog extends ButtonDialog {
private JCheckBox agreeBox;
private JPanel thumbnailPanel;
private JTextField nameField;
private JComboBox categoryBox;
private JComboBox<String> categoryBox;
private JScrollPane descriptionPane;
private JTextArea descriptionArea;
private JTextField keywordsField;
@@ -227,9 +227,9 @@ public class UploadDialog extends ButtonDialog {
return nameField;
}
private JComboBox getCategoryBox() {
private JComboBox<String> getCategoryBox() {
if (categoryBox == null) {
categoryBox = new JComboBox(categories);
categoryBox = new JComboBox<String>(categories);
}
return categoryBox;
}
@@ -18,6 +18,7 @@
*/
package org.diylc.swing.plugins.file;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.util.ArrayList;
@@ -27,15 +28,18 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
@@ -53,6 +57,10 @@ public class NetlistImportDialog extends ButtonDialog {
private static final long serialVersionUID = 1L;
public static String NETLIST_DEFAULT_TYPES = "netlistDefaultTypes";
public static String INFO_HTML =
"<html>Detected component types are listed above, along with possible matches within the DIYLC inventory.<br>"
+ "Make adjustments where needed directly in the table by picking a different type from the drop down box.<br>"
+ "Use 'Default' boxes to save your selections as defaults for the next time.</html>";
private List<Class<?>> selectedTypes;
private List<Boolean> setDefault;
@@ -63,13 +71,16 @@ public class NetlistImportDialog extends ButtonDialog {
private Map<String, List<Class<?>>> availableTypes;
private JTable table;
private JLabel infoLabel;
private JPanel mainPanel;
@SuppressWarnings("unchecked")
public NetlistImportDialog(JFrame owner, IPlugInPort plugInPort,
List<ParsedNetlistEntry> entries) {
super(owner, LangUtil.translate("Import Netlist"),
new String[] {ButtonDialog.OK, ButtonDialog.CANCEL});
this.rawTypes = entries.stream().map(x -> x.getRawType()).distinct().sorted().collect(Collectors.toList());
this.rawTypes =
entries.stream().map(x -> x.getRawType()).distinct().sorted().collect(Collectors.toList());
this.availableTypes = new HashMap<String, List<Class<?>>>();
for (ParsedNetlistEntry entry : entries) {
this.availableTypes.put(entry.getRawType(), entry.getTypeCandidates());
@@ -77,8 +88,8 @@ public class NetlistImportDialog extends ButtonDialog {
this.netlistDefaultTypes = (Map<String, String>) ConfigurationManager.getInstance()
.readObject(NETLIST_DEFAULT_TYPES, null);
this.setDefault = rawTypes.stream().map(
type -> netlistDefaultTypes != null && netlistDefaultTypes.containsKey(type))
this.setDefault = rawTypes.stream()
.map(type -> netlistDefaultTypes != null && netlistDefaultTypes.containsKey(type))
.collect(Collectors.toList());
Map<String, List<ComponentType>> componentTypes = plugInPort.getComponentTypes();
@@ -103,12 +114,10 @@ public class NetlistImportDialog extends ButtonDialog {
}
private Class<?> getDefaultType(String rawType) {
if (this.netlistDefaultTypes != null
&& this.netlistDefaultTypes.containsKey(rawType)) {
if (this.netlistDefaultTypes != null && this.netlistDefaultTypes.containsKey(rawType)) {
Optional<Class<?>> first = this.allTypes.stream()
.filter(
e -> e.getCanonicalName().equals(this.netlistDefaultTypes.get(rawType)))
.filter(e -> e.getCanonicalName().equals(this.netlistDefaultTypes.get(rawType)))
.findFirst();
if (first.isPresent())
return first.get();
@@ -127,10 +136,29 @@ public class NetlistImportDialog extends ButtonDialog {
@Override
protected JComponent getMainComponent() {
JScrollPane scrollPane = new JScrollPane(getTable());
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
return scrollPane;
if (mainPanel == null) {
JScrollPane scrollPane = new JScrollPane(getTable());
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
this.mainPanel = new JPanel(new BorderLayout());
this.mainPanel.add(scrollPane, BorderLayout.CENTER);
this.mainPanel.add(getInfoLabel(), BorderLayout.SOUTH);
this.mainPanel.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
}
return this.mainPanel;
}
private JLabel getInfoLabel() {
if (infoLabel == null) {
infoLabel = new JLabel();
infoLabel.setOpaque(true);
infoLabel.setBackground(UIManager.getColor("ToolTip.background"));
infoLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(),
BorderFactory.createEmptyBorder(2, 2, 2, 2)));
infoLabel.setText(INFO_HTML);
}
return infoLabel;
}
@SuppressWarnings("unchecked")
@@ -146,8 +174,7 @@ public class NetlistImportDialog extends ButtonDialog {
netlistDefaultTypes = new HashMap<String, String>();
for (int i = 0; i < rawTypes.size(); i++)
if (setDefault.get(i))
netlistDefaultTypes.put(rawTypes.get(i),
selectedTypes.get(i).getCanonicalName());
netlistDefaultTypes.put(rawTypes.get(i), selectedTypes.get(i).getCanonicalName());
else
netlistDefaultTypes.remove(rawTypes.get(i));