mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 09:12:09 +10:00
enhance search
This commit is contained in:
@@ -1004,12 +1004,15 @@ public class Presenter implements IPlugInPort {
|
|||||||
drawingManager.clearContinuityArea();
|
drawingManager.clearContinuityArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public void selectMatching(String criteria) {
|
public void selectMatching(String criteria) {
|
||||||
Set<IDIYComponent<?>> matching = new HashSet<IDIYComponent<?>>();
|
Set<IDIYComponent<?>> matching = new HashSet<IDIYComponent<?>>();
|
||||||
for (IDIYComponent<?> c : currentProject.getComponents()) {
|
for (IDIYComponent<?> c : currentProject.getComponents()) {
|
||||||
|
ComponentType type = ComponentProcessor.getInstance().extractComponentTypeFrom((Class<? extends IDIYComponent<?>>) c.getClass());
|
||||||
if ((c.getName() != null && c.getName().toLowerCase().matches(criteria.toLowerCase())) ||
|
if ((c.getName() != null && c.getName().toLowerCase().matches(criteria.toLowerCase())) ||
|
||||||
(c.getValueForDisplay() != null && c.getValueForDisplay().toLowerCase().matches(criteria.toLowerCase())))
|
(c.getValueForDisplay() != null && c.getValueForDisplay().toLowerCase().matches(criteria.toLowerCase())) ||
|
||||||
|
type.getName().toLowerCase().matches(criteria.toLowerCase()))
|
||||||
matching.add(c);
|
matching.add(c);
|
||||||
}
|
}
|
||||||
updateSelection(matching);
|
updateSelection(matching);
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import javax.swing.JFrame;
|
|||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.UIManager;
|
||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
import javax.swing.event.DocumentListener;
|
import javax.swing.event.DocumentListener;
|
||||||
|
|
||||||
@@ -40,17 +41,35 @@ import org.diylc.swingframework.ButtonDialog;
|
|||||||
|
|
||||||
public class FindDialog extends ButtonDialog {
|
public class FindDialog extends ButtonDialog {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private static final String TOOLTIP_HTML = "<html>Use RegEx to search for component names, types and values.<br>"
|
||||||
|
+ "<br><b>Character classes:</b><br>"
|
||||||
|
+ ". - matches any character<br>"
|
||||||
|
+ "\\s - whitespace<br>"
|
||||||
|
+ "\\S - non-whitespace<br>"
|
||||||
|
+ "\\d - digit<br>"
|
||||||
|
+ "\\D - non-digit<br>"
|
||||||
|
+ "<br><b>Quantifiers:</b><br>"
|
||||||
|
+ "* - zero or more times<br>"
|
||||||
|
+ "? - zero or one time<br>"
|
||||||
|
+ "+ - one or more times<br>"
|
||||||
|
+ "<br><b>Examples:</b><br>"
|
||||||
|
+ "'R27' - matches a component named R27<br>"
|
||||||
|
+ "'Resistor' - matches all resistors<br>"
|
||||||
|
+ "'R\\d+' - matches components starting with R, followed by at least one digit"
|
||||||
|
+ "</html>";
|
||||||
|
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
|
|
||||||
private JTextField criteriaField;
|
private JTextField criteriaField;
|
||||||
|
private JLabel tooltipLabel;
|
||||||
|
|
||||||
private String criteria;
|
private String criteria;
|
||||||
|
|
||||||
public FindDialog(JFrame owner) {
|
public FindDialog(JFrame owner) {
|
||||||
super(owner, "Find", new String[] {OK, CANCEL});
|
super(owner, "Find", new String[] {OK, CANCEL});
|
||||||
setMinimumSize(new Dimension(240, 32));
|
setMinimumSize(new Dimension(400, 32));
|
||||||
layoutGui();
|
layoutGui();
|
||||||
refreshState();
|
refreshState();
|
||||||
}
|
}
|
||||||
@@ -80,9 +99,26 @@ public class FindDialog extends ButtonDialog {
|
|||||||
gbc.weightx = 1;
|
gbc.weightx = 1;
|
||||||
|
|
||||||
gbc.gridy = 0;
|
gbc.gridy = 0;
|
||||||
mainPanel.add(getCriteriaField(), gbc);
|
mainPanel.add(getCriteriaField(), gbc);
|
||||||
|
|
||||||
|
gbc.gridx = 0;
|
||||||
|
gbc.gridy = 1;
|
||||||
|
gbc.gridwidth = 2;
|
||||||
|
mainPanel.add(getTooltipLabel(), gbc);
|
||||||
}
|
}
|
||||||
return mainPanel;
|
return mainPanel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JLabel getTooltipLabel() {
|
||||||
|
if (tooltipLabel == null) {
|
||||||
|
tooltipLabel = new JLabel();
|
||||||
|
tooltipLabel.setOpaque(true);
|
||||||
|
tooltipLabel.setBackground(UIManager.getColor("ToolTip.background"));
|
||||||
|
tooltipLabel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(),
|
||||||
|
BorderFactory.createEmptyBorder(2, 2, 2, 2)));
|
||||||
|
tooltipLabel.setText(TOOLTIP_HTML);
|
||||||
|
}
|
||||||
|
return tooltipLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshState() {
|
private void refreshState() {
|
||||||
|
|||||||
Reference in New Issue
Block a user