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 JCheckBox agreeBox;
private JPanel thumbnailPanel; private JPanel thumbnailPanel;
private JTextField nameField; private JTextField nameField;
private JComboBox categoryBox; private JComboBox<String> categoryBox;
private JScrollPane descriptionPane; private JScrollPane descriptionPane;
private JTextArea descriptionArea; private JTextArea descriptionArea;
private JTextField keywordsField; private JTextField keywordsField;
@@ -227,9 +227,9 @@ public class UploadDialog extends ButtonDialog {
return nameField; return nameField;
} }
private JComboBox getCategoryBox() { private JComboBox<String> getCategoryBox() {
if (categoryBox == null) { if (categoryBox == null) {
categoryBox = new JComboBox(categories); categoryBox = new JComboBox<String>(categories);
} }
return categoryBox; return categoryBox;
} }
@@ -18,6 +18,7 @@
*/ */
package org.diylc.swing.plugins.file; package org.diylc.swing.plugins.file;
import java.awt.BorderLayout;
import java.awt.Component; import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.ArrayList; import java.util.ArrayList;
@@ -27,15 +28,18 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor; import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTable; import javax.swing.JTable;
import javax.swing.ListCellRenderer; import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.table.AbstractTableModel; import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer; import javax.swing.table.TableCellRenderer;
@@ -53,6 +57,10 @@ public class NetlistImportDialog extends ButtonDialog {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static String NETLIST_DEFAULT_TYPES = "netlistDefaultTypes"; 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<Class<?>> selectedTypes;
private List<Boolean> setDefault; private List<Boolean> setDefault;
@@ -63,13 +71,16 @@ public class NetlistImportDialog extends ButtonDialog {
private Map<String, List<Class<?>>> availableTypes; private Map<String, List<Class<?>>> availableTypes;
private JTable table; private JTable table;
private JLabel infoLabel;
private JPanel mainPanel;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public NetlistImportDialog(JFrame owner, IPlugInPort plugInPort, public NetlistImportDialog(JFrame owner, IPlugInPort plugInPort,
List<ParsedNetlistEntry> entries) { List<ParsedNetlistEntry> entries) {
super(owner, LangUtil.translate("Import Netlist"), super(owner, LangUtil.translate("Import Netlist"),
new String[] {ButtonDialog.OK, ButtonDialog.CANCEL}); 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<?>>>(); this.availableTypes = new HashMap<String, List<Class<?>>>();
for (ParsedNetlistEntry entry : entries) { for (ParsedNetlistEntry entry : entries) {
this.availableTypes.put(entry.getRawType(), entry.getTypeCandidates()); this.availableTypes.put(entry.getRawType(), entry.getTypeCandidates());
@@ -77,8 +88,8 @@ public class NetlistImportDialog extends ButtonDialog {
this.netlistDefaultTypes = (Map<String, String>) ConfigurationManager.getInstance() this.netlistDefaultTypes = (Map<String, String>) ConfigurationManager.getInstance()
.readObject(NETLIST_DEFAULT_TYPES, null); .readObject(NETLIST_DEFAULT_TYPES, null);
this.setDefault = rawTypes.stream().map( this.setDefault = rawTypes.stream()
type -> netlistDefaultTypes != null && netlistDefaultTypes.containsKey(type)) .map(type -> netlistDefaultTypes != null && netlistDefaultTypes.containsKey(type))
.collect(Collectors.toList()); .collect(Collectors.toList());
Map<String, List<ComponentType>> componentTypes = plugInPort.getComponentTypes(); Map<String, List<ComponentType>> componentTypes = plugInPort.getComponentTypes();
@@ -103,12 +114,10 @@ public class NetlistImportDialog extends ButtonDialog {
} }
private Class<?> getDefaultType(String rawType) { private Class<?> getDefaultType(String rawType) {
if (this.netlistDefaultTypes != null if (this.netlistDefaultTypes != null && this.netlistDefaultTypes.containsKey(rawType)) {
&& this.netlistDefaultTypes.containsKey(rawType)) {
Optional<Class<?>> first = this.allTypes.stream() Optional<Class<?>> first = this.allTypes.stream()
.filter( .filter(e -> e.getCanonicalName().equals(this.netlistDefaultTypes.get(rawType)))
e -> e.getCanonicalName().equals(this.netlistDefaultTypes.get(rawType)))
.findFirst(); .findFirst();
if (first.isPresent()) if (first.isPresent())
return first.get(); return first.get();
@@ -127,10 +136,29 @@ public class NetlistImportDialog extends ButtonDialog {
@Override @Override
protected JComponent getMainComponent() { protected JComponent getMainComponent() {
if (mainPanel == null) {
JScrollPane scrollPane = new JScrollPane(getTable()); JScrollPane scrollPane = new JScrollPane(getTable());
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
return scrollPane;
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") @SuppressWarnings("unchecked")
@@ -146,8 +174,7 @@ public class NetlistImportDialog extends ButtonDialog {
netlistDefaultTypes = new HashMap<String, String>(); netlistDefaultTypes = new HashMap<String, String>();
for (int i = 0; i < rawTypes.size(); i++) for (int i = 0; i < rawTypes.size(); i++)
if (setDefault.get(i)) if (setDefault.get(i))
netlistDefaultTypes.put(rawTypes.get(i), netlistDefaultTypes.put(rawTypes.get(i), selectedTypes.get(i).getCanonicalName());
selectedTypes.get(i).getCanonicalName());
else else
netlistDefaultTypes.remove(rawTypes.get(i)); netlistDefaultTypes.remove(rawTypes.get(i));