Further refinements to motor filter. Moved diameter configuration into
popup. Added impulse class filters. Improved interface to CheckList and removed the double-click functionality from CheckListEditor.
This commit is contained in:
parent
246b9a6823
commit
bae9d38a51
@ -0,0 +1,45 @@
|
|||||||
|
package net.sf.openrocket.gui.dialogs.motor.thrustcurve;
|
||||||
|
|
||||||
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
|
import net.sf.openrocket.database.motor.ThrustCurveMotorSet;
|
||||||
|
|
||||||
|
public enum ImpulseClass {
|
||||||
|
|
||||||
|
A("A",0.0, 2.5 ),
|
||||||
|
B("B",2.5, 5.0 ),
|
||||||
|
C("C",5.0, 10.0),
|
||||||
|
D("D",10.0, 20.0),
|
||||||
|
E("E",20.0, 40.0),
|
||||||
|
F("F", 40.0, 80.0),
|
||||||
|
G("G", 80.0, 160.0),
|
||||||
|
H("H", 160.0, 320.0),
|
||||||
|
I("I", 320.0, 640.0),
|
||||||
|
J("J", 640.0, 1280.0),
|
||||||
|
K("K", 1280.0, 2560.0),
|
||||||
|
L("L", 2560.0, 5120.0),
|
||||||
|
M("M", 5120.0, 10240.0),
|
||||||
|
N("N", 10240.0, 20480.0),
|
||||||
|
O("O", 20480.0, Double.MAX_VALUE);
|
||||||
|
|
||||||
|
private ImpulseClass( String name, double low, double high ) {
|
||||||
|
this.name = name;
|
||||||
|
this.low = low;
|
||||||
|
this.high = high;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIn( ThrustCurveMotorSet m ) {
|
||||||
|
long motorImpulse = m.getTotalImpuse();
|
||||||
|
return motorImpulse >= low && motorImpulse <= high;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double low;
|
||||||
|
private double high;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
}
|
@ -1,96 +0,0 @@
|
|||||||
package net.sf.openrocket.gui.dialogs.motor.thrustcurve;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
|
||||||
import javax.swing.Box;
|
|
||||||
import javax.swing.BoxLayout;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JPopupMenu;
|
|
||||||
import javax.swing.JScrollPane;
|
|
||||||
import javax.swing.UIManager;
|
|
||||||
|
|
||||||
import net.sf.openrocket.gui.util.CheckList;
|
|
||||||
import net.sf.openrocket.motor.Manufacturer;
|
|
||||||
|
|
||||||
public abstract class ManufacturerPopupSelector extends JPopupMenu implements ActionListener {
|
|
||||||
|
|
||||||
Map<String, Manufacturer> componentMap = new HashMap<String, Manufacturer>();
|
|
||||||
CheckList list;
|
|
||||||
|
|
||||||
public ManufacturerPopupSelector(Collection<Manufacturer> allManufacturers, Collection<Manufacturer> unselectedManufacturers) {
|
|
||||||
|
|
||||||
JPanel root = new JPanel(new BorderLayout(3, 3));
|
|
||||||
root.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
|
|
||||||
root.setPreferredSize(new Dimension(250, 150)); // default popup size
|
|
||||||
|
|
||||||
Box commands = new Box(BoxLayout.LINE_AXIS);
|
|
||||||
|
|
||||||
commands.add(Box.createHorizontalStrut(5));
|
|
||||||
commands.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0));
|
|
||||||
commands.setBackground(UIManager.getColor("Panel.background"));
|
|
||||||
commands.setOpaque(true);
|
|
||||||
|
|
||||||
JButton closeButton = new JButton("close");
|
|
||||||
closeButton.addActionListener(this);
|
|
||||||
commands.add(closeButton);
|
|
||||||
|
|
||||||
List<String> manufacturers = new ArrayList<String>();
|
|
||||||
for (Manufacturer m : allManufacturers) {
|
|
||||||
manufacturers.add(m.getSimpleName());
|
|
||||||
componentMap.put(m.getSimpleName(), m);
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(manufacturers);
|
|
||||||
|
|
||||||
list = new CheckList.Builder().build();
|
|
||||||
list.setData(manufacturers);
|
|
||||||
|
|
||||||
if (unselectedManufacturers != null)
|
|
||||||
{
|
|
||||||
for (Manufacturer m : unselectedManufacturers) {
|
|
||||||
manufacturers.remove(m.getSimpleName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
list.setCheckedItems(manufacturers);
|
|
||||||
|
|
||||||
root.add(new JScrollPane(list.getList()), BorderLayout.CENTER);
|
|
||||||
root.add(commands, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
this.add(root);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
|
|
||||||
List<Manufacturer> selectedManufacturers = new ArrayList<Manufacturer>();
|
|
||||||
List<Manufacturer> unselectedManufacturers = new ArrayList<Manufacturer>();
|
|
||||||
|
|
||||||
Collection<String> selected = list.getCheckedItems();
|
|
||||||
for (String s : selected) {
|
|
||||||
selectedManufacturers.add(componentMap.get(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection<String> unselected = list.getUncheckedItems();
|
|
||||||
for (String s : unselected) {
|
|
||||||
unselectedManufacturers.add(componentMap.get(s));
|
|
||||||
}
|
|
||||||
|
|
||||||
onDismissed(selectedManufacturers, unselectedManufacturers);
|
|
||||||
setVisible(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void onDismissed(List<Manufacturer> selectedManufacturers, List<Manufacturer> unselectedManufacturers);
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,251 @@
|
|||||||
|
package net.sf.openrocket.gui.dialogs.motor.thrustcurve;
|
||||||
|
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.ButtonGroup;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.JRadioButton;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.swing.border.TitledBorder;
|
||||||
|
import javax.swing.event.ListDataEvent;
|
||||||
|
import javax.swing.event.ListDataListener;
|
||||||
|
|
||||||
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import net.sf.openrocket.gui.util.CheckList;
|
||||||
|
import net.sf.openrocket.gui.util.GUIUtil;
|
||||||
|
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||||
|
import net.sf.openrocket.l10n.Translator;
|
||||||
|
import net.sf.openrocket.motor.Manufacturer;
|
||||||
|
import net.sf.openrocket.startup.Application;
|
||||||
|
|
||||||
|
import com.itextpdf.text.Font;
|
||||||
|
|
||||||
|
public abstract class MotorFilterPopupMenu extends JPopupMenu {
|
||||||
|
|
||||||
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
|
private final CheckList<Manufacturer> manufacturerCheckList;
|
||||||
|
|
||||||
|
private final CheckList<ImpulseClass> impulseCheckList;
|
||||||
|
|
||||||
|
private final MotorRowFilter filter;
|
||||||
|
|
||||||
|
private int showMode = SHOW_ALL;
|
||||||
|
|
||||||
|
private static final int SHOW_ALL = 0;
|
||||||
|
private static final int SHOW_SMALLER = 1;
|
||||||
|
private static final int SHOW_EXACT = 2;
|
||||||
|
private static final int SHOW_MAX = 2;
|
||||||
|
|
||||||
|
|
||||||
|
public MotorFilterPopupMenu(Collection<Manufacturer> allManufacturers, MotorRowFilter filter ) {
|
||||||
|
|
||||||
|
this.filter = filter;
|
||||||
|
|
||||||
|
showMode = Application.getPreferences().getChoice(net.sf.openrocket.startup.Preferences.MOTOR_DIAMETER_FILTER, MotorFilterPopupMenu.SHOW_MAX, MotorFilterPopupMenu.SHOW_EXACT);
|
||||||
|
List<Manufacturer> unselectedManusFromPreferences = ((SwingPreferences) Application.getPreferences()).getExcludedMotorManufacturers();
|
||||||
|
|
||||||
|
// Manufacturer selection
|
||||||
|
JPanel sub = new JPanel(new MigLayout("fill"));
|
||||||
|
TitledBorder border = BorderFactory.createTitledBorder("Manufacturer");
|
||||||
|
GUIUtil.changeFontStyle(border, Font.BOLD);
|
||||||
|
sub.setBorder(border);
|
||||||
|
|
||||||
|
JPanel root = new JPanel(new MigLayout("fill", "[grow]"));
|
||||||
|
root.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
|
||||||
|
|
||||||
|
List<Manufacturer> manufacturers = new ArrayList<Manufacturer>();
|
||||||
|
for (Manufacturer m : allManufacturers) {
|
||||||
|
manufacturers.add(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(manufacturers, new Comparator<Manufacturer>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Manufacturer o1, Manufacturer o2) {
|
||||||
|
return o1.getSimpleName().compareTo( o2.getSimpleName());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
manufacturerCheckList = new CheckList.Builder().<Manufacturer>build();
|
||||||
|
manufacturerCheckList.setData(manufacturers);
|
||||||
|
|
||||||
|
manufacturerCheckList.setUncheckedItems(unselectedManusFromPreferences);
|
||||||
|
filter.setExcludedManufacturers(unselectedManusFromPreferences);
|
||||||
|
manufacturerCheckList.getModel().addListDataListener( new ListDataListener() {
|
||||||
|
@Override
|
||||||
|
public void intervalAdded(ListDataEvent e) {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void intervalRemoved(ListDataEvent e) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contentsChanged(ListDataEvent e) {
|
||||||
|
MotorFilterPopupMenu.this.filter.setExcludedManufacturers( manufacturerCheckList.getUncheckedItems() );
|
||||||
|
onSelectionChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sub.add(new JScrollPane(manufacturerCheckList.getList()), "grow,wrap");
|
||||||
|
|
||||||
|
JButton clearMotors = new JButton("clear");
|
||||||
|
clearMotors.addActionListener( new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
MotorFilterPopupMenu.this.manufacturerCheckList.clearAll();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sub.add(clearMotors,"split 2");
|
||||||
|
|
||||||
|
JButton selectMotors = new JButton("all");
|
||||||
|
selectMotors.addActionListener( new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
MotorFilterPopupMenu.this.manufacturerCheckList.checkAll();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sub.add(selectMotors,"wrap");
|
||||||
|
|
||||||
|
root.add(sub,"grow, wrap");
|
||||||
|
|
||||||
|
// Impulse selection
|
||||||
|
sub = new JPanel(new MigLayout("fill"));
|
||||||
|
border = BorderFactory.createTitledBorder("Impulse");
|
||||||
|
GUIUtil.changeFontStyle(border, Font.BOLD);
|
||||||
|
sub.setBorder(border);
|
||||||
|
|
||||||
|
impulseCheckList = new CheckList.Builder().<ImpulseClass>build();
|
||||||
|
impulseCheckList.setData(Arrays.asList(ImpulseClass.values()));
|
||||||
|
impulseCheckList.checkAll();
|
||||||
|
impulseCheckList.getModel().addListDataListener( new ListDataListener() {
|
||||||
|
@Override
|
||||||
|
public void intervalAdded(ListDataEvent e) {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void intervalRemoved(ListDataEvent e) {
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void contentsChanged(ListDataEvent e) {
|
||||||
|
MotorFilterPopupMenu.this.filter.setExcludedImpulseClasses( impulseCheckList.getUncheckedItems() );
|
||||||
|
onSelectionChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
sub.add(new JScrollPane(impulseCheckList.getList()), "grow,wrap");
|
||||||
|
|
||||||
|
JButton clearImpulse = new JButton("clear");
|
||||||
|
clearImpulse.addActionListener( new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
MotorFilterPopupMenu.this.impulseCheckList.clearAll();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
sub.add(clearImpulse,"split 2");
|
||||||
|
|
||||||
|
JButton selectImpulse = new JButton("all");
|
||||||
|
selectImpulse.addActionListener( new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
MotorFilterPopupMenu.this.impulseCheckList.checkAll();
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
sub.add(selectImpulse,"wrap");
|
||||||
|
|
||||||
|
root.add(sub,"grow, wrap");
|
||||||
|
|
||||||
|
// Diameter selection
|
||||||
|
|
||||||
|
sub = new JPanel(new MigLayout("fill"));
|
||||||
|
border = BorderFactory.createTitledBorder("Diameter");
|
||||||
|
GUIUtil.changeFontStyle(border, Font.BOLD);
|
||||||
|
sub.setBorder(border);
|
||||||
|
|
||||||
|
JRadioButton showAllDiametersButton = new JRadioButton( trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc1") );
|
||||||
|
showAllDiametersButton.addActionListener( new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
showMode = SHOW_ALL;
|
||||||
|
MotorFilterPopupMenu.this.filter.setDiameterControl(MotorRowFilter.DiameterFilterControl.ALL);
|
||||||
|
onSelectionChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
showAllDiametersButton.setSelected( showMode == SHOW_ALL);
|
||||||
|
sub.add(showAllDiametersButton, "growx,wrap");
|
||||||
|
|
||||||
|
JRadioButton showSmallerDiametersButton = new JRadioButton( trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc2") );
|
||||||
|
showSmallerDiametersButton.addActionListener( new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
showMode = SHOW_SMALLER;
|
||||||
|
MotorFilterPopupMenu.this.filter.setDiameterControl(MotorRowFilter.DiameterFilterControl.SMALLER);
|
||||||
|
onSelectionChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
showSmallerDiametersButton.setSelected( showMode == SHOW_SMALLER);
|
||||||
|
sub.add(showSmallerDiametersButton, "growx,wrap");
|
||||||
|
|
||||||
|
JRadioButton showExactDiametersButton = new JRadioButton( trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc3") );
|
||||||
|
showExactDiametersButton.addActionListener( new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
showMode = SHOW_EXACT;
|
||||||
|
MotorFilterPopupMenu.this.filter.setDiameterControl(MotorRowFilter.DiameterFilterControl.EXACT);
|
||||||
|
onSelectionChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
showExactDiametersButton.setSelected( showMode == SHOW_EXACT );
|
||||||
|
sub.add(showExactDiametersButton, "growx,wrap");
|
||||||
|
|
||||||
|
root.add(sub, "grow,wrap");
|
||||||
|
ButtonGroup comboGroup = new ButtonGroup();
|
||||||
|
comboGroup.add( showAllDiametersButton );
|
||||||
|
comboGroup.add( showSmallerDiametersButton );
|
||||||
|
comboGroup.add( showExactDiametersButton );
|
||||||
|
|
||||||
|
|
||||||
|
// Close button
|
||||||
|
JButton closeButton = new JButton("close");
|
||||||
|
closeButton.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
MotorFilterPopupMenu.this.onClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
root.add(closeButton, "split 2");
|
||||||
|
|
||||||
|
this.add(root);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onClose() {
|
||||||
|
|
||||||
|
((SwingPreferences) Application.getPreferences()).setExcludedMotorManufacturers(filter.getExcludedManufacturers());
|
||||||
|
|
||||||
|
Application.getPreferences().putChoice("MotorDiameterMatch", showMode );
|
||||||
|
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void onSelectionChanged();
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package net.sf.openrocket.gui.dialogs.motor.thrustcurve;
|
package net.sf.openrocket.gui.dialogs.motor.thrustcurve;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -33,11 +34,22 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
private List<ThrustCurveMotor> usedMotors = new ArrayList<ThrustCurveMotor>();
|
private List<ThrustCurveMotor> usedMotors = new ArrayList<ThrustCurveMotor>();
|
||||||
|
|
||||||
// things which can be changed to modify filter behavior
|
// things which can be changed to modify filter behavior
|
||||||
|
|
||||||
|
// Collection of strings which match text in the moto
|
||||||
private List<String> searchTerms = Collections.<String> emptyList();
|
private List<String> searchTerms = Collections.<String> emptyList();
|
||||||
|
|
||||||
|
// Limit motors based on diameter of the motor mount
|
||||||
private DiameterFilterControl diameterControl = DiameterFilterControl.ALL;
|
private DiameterFilterControl diameterControl = DiameterFilterControl.ALL;
|
||||||
|
|
||||||
|
// Boolean which hides motors in the usedMotors list
|
||||||
private boolean hideUsedMotors = false;
|
private boolean hideUsedMotors = false;
|
||||||
|
|
||||||
|
// List of manufacturers to exclude.
|
||||||
private List<Manufacturer> excludedManufacturers = new ArrayList<Manufacturer>();
|
private List<Manufacturer> excludedManufacturers = new ArrayList<Manufacturer>();
|
||||||
|
|
||||||
|
// List of ImpulseClasses to exclude.
|
||||||
|
private List<ImpulseClass> excludedImpulseClass = new ArrayList<ImpulseClass>();
|
||||||
|
|
||||||
public MotorRowFilter(MotorMount mount, ThrustCurveMotorDatabaseModel model) {
|
public MotorRowFilter(MotorMount mount, ThrustCurveMotorDatabaseModel model) {
|
||||||
super();
|
super();
|
||||||
this.model = model;
|
this.model = model;
|
||||||
@ -61,6 +73,10 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DiameterFilterControl getDiameterControl() {
|
||||||
|
return diameterControl;
|
||||||
|
}
|
||||||
|
|
||||||
void setDiameterControl(DiameterFilterControl diameterControl) {
|
void setDiameterControl(DiameterFilterControl diameterControl) {
|
||||||
this.diameterControl = diameterControl;
|
this.diameterControl = diameterControl;
|
||||||
}
|
}
|
||||||
@ -69,16 +85,25 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
this.hideUsedMotors = hideUsedMotors;
|
this.hideUsedMotors = hideUsedMotors;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setExcludedManufacturers(List<Manufacturer> excludedManufacturers) {
|
List<Manufacturer> getExcludedManufacturers() {
|
||||||
|
return excludedManufacturers;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setExcludedManufacturers(Collection<Manufacturer> excludedManufacturers) {
|
||||||
this.excludedManufacturers.clear();
|
this.excludedManufacturers.clear();
|
||||||
this.excludedManufacturers.addAll(excludedManufacturers);
|
this.excludedManufacturers.addAll(excludedManufacturers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setExcludedImpulseClasses(Collection<ImpulseClass> excludedImpulseClasses ) {
|
||||||
|
this.excludedImpulseClass.clear();
|
||||||
|
this.excludedImpulseClass.addAll(excludedImpulseClasses);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean include(RowFilter.Entry<? extends TableModel, ? extends Integer> entry) {
|
public boolean include(RowFilter.Entry<? extends TableModel, ? extends Integer> entry) {
|
||||||
int index = entry.getIdentifier();
|
int index = entry.getIdentifier();
|
||||||
ThrustCurveMotorSet m = model.getMotorSet(index);
|
ThrustCurveMotorSet m = model.getMotorSet(index);
|
||||||
return filterManufacturers(m) && filterUsed(m) && filterByDiameter(m) && filterByString(m);
|
return filterManufacturers(m) && filterUsed(m) && filterByDiameter(m) && filterByString(m) && filterByImpulseClass(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean filterManufacturers(ThrustCurveMotorSet m) {
|
private boolean filterManufacturers(ThrustCurveMotorSet m) {
|
||||||
@ -128,4 +153,14 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean filterByImpulseClass(ThrustCurveMotorSet m) {
|
||||||
|
for( ImpulseClass c : excludedImpulseClass ) {
|
||||||
|
if (c.isIn(m) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -83,23 +83,11 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelector {
|
public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelector {
|
||||||
private static final Logger log = LoggerFactory.getLogger(ThrustCurveMotorSelectionPanel.class);
|
private static final Logger log = LoggerFactory.getLogger(ThrustCurveMotorSelectionPanel.class);
|
||||||
|
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
private static final double MOTOR_SIMILARITY_THRESHOLD = 0.95;
|
private static final double MOTOR_SIMILARITY_THRESHOLD = 0.95;
|
||||||
|
|
||||||
private static final int SHOW_ALL = 0;
|
|
||||||
private static final int SHOW_SMALLER = 1;
|
|
||||||
private static final int SHOW_EXACT = 2;
|
|
||||||
private static final String[] SHOW_DESCRIPTIONS = {
|
|
||||||
//// Show all motors
|
|
||||||
trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc1"),
|
|
||||||
//// Show motors with diameter less than that of the motor mount
|
|
||||||
trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc2"),
|
|
||||||
//// Show motors with diameter equal to that of the motor mount
|
|
||||||
trans.get("TCMotorSelPan.SHOW_DESCRIPTIONS.desc3")
|
|
||||||
};
|
|
||||||
private static final int SHOW_MAX = 2;
|
|
||||||
|
|
||||||
private static final int ZOOM_ICON_POSITION_NEGATIVE_X = 50;
|
private static final int ZOOM_ICON_POSITION_NEGATIVE_X = 50;
|
||||||
private static final int ZOOM_ICON_POSITION_POSITIVE_Y = 12;
|
private static final int ZOOM_ICON_POSITION_POSITIVE_Y = 12;
|
||||||
|
|
||||||
@ -194,11 +182,8 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
}
|
}
|
||||||
database = db;
|
database = db;
|
||||||
|
|
||||||
List<Manufacturer> unselectedManusFromPreferences = ((SwingPreferences) Application.getPreferences()).getExcludedMotorManufacturers();
|
|
||||||
|
|
||||||
model = new ThrustCurveMotorDatabaseModel(database);
|
model = new ThrustCurveMotorDatabaseModel(database);
|
||||||
final MotorRowFilter rowFilter = new MotorRowFilter(mount, model);
|
final MotorRowFilter rowFilter = new MotorRowFilter(mount, model);
|
||||||
rowFilter.setExcludedManufacturers(unselectedManusFromPreferences);
|
|
||||||
|
|
||||||
//// GUI
|
//// GUI
|
||||||
|
|
||||||
@ -215,86 +200,57 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
label = new StyledLabel(trans.get("TCMotorSelPan.lbl.Selrocketmotor"), Style.BOLD);
|
label = new StyledLabel(trans.get("TCMotorSelPan.lbl.Selrocketmotor"), Style.BOLD);
|
||||||
panel.add(label, "spanx, wrap para");
|
panel.add(label, "spanx, wrap para");
|
||||||
|
|
||||||
// Diameter selection
|
// Search field
|
||||||
JComboBox filterComboBox = new JComboBox(SHOW_DESCRIPTIONS);
|
//// Search:
|
||||||
filterComboBox.addActionListener(new ActionListener() {
|
label = new StyledLabel(trans.get("TCMotorSelPan.lbl.Search"));
|
||||||
|
panel.add(label, "");
|
||||||
|
|
||||||
|
searchField = new JTextField();
|
||||||
|
searchField.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void changedUpdate(DocumentEvent e) {
|
||||||
JComboBox cb = (JComboBox) e.getSource();
|
update();
|
||||||
int sel = cb.getSelectedIndex();
|
}
|
||||||
if ((sel < 0) || (sel > SHOW_MAX))
|
|
||||||
sel = SHOW_ALL;
|
|
||||||
switch (sel) {
|
|
||||||
case SHOW_ALL:
|
|
||||||
rowFilter.setDiameterControl(MotorRowFilter.DiameterFilterControl.ALL);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SHOW_SMALLER:
|
@Override
|
||||||
rowFilter.setDiameterControl(MotorRowFilter.DiameterFilterControl.SMALLER);
|
public void insertUpdate(DocumentEvent e) {
|
||||||
break;
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
case SHOW_EXACT:
|
@Override
|
||||||
rowFilter.setDiameterControl(MotorRowFilter.DiameterFilterControl.EXACT);
|
public void removeUpdate(DocumentEvent e) {
|
||||||
break;
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
private void update() {
|
||||||
throw new BugException("Invalid selection mode sel=" + sel);
|
String text = searchField.getText().trim();
|
||||||
}
|
String[] split = text.split("\\s+");
|
||||||
|
rowFilter.setSearchTerms(Arrays.asList(split));
|
||||||
sorter.sort();
|
sorter.sort();
|
||||||
Application.getPreferences().putChoice("MotorDiameterMatch", sel);
|
|
||||||
scrollSelectionVisible();
|
scrollSelectionVisible();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(filterComboBox, "spanx, growx, wrap rel");
|
panel.add(searchField, "growx");
|
||||||
|
|
||||||
//// Hide very similar thrust curves
|
|
||||||
hideSimilarBox = new JCheckBox(trans.get("TCMotorSelPan.checkbox.hideSimilar"));
|
|
||||||
GUIUtil.changeFontSize(hideSimilarBox, -1);
|
|
||||||
hideSimilarBox.setSelected(Application.getPreferences().getBoolean(net.sf.openrocket.startup.Preferences.MOTOR_HIDE_SIMILAR, true));
|
|
||||||
hideSimilarBox.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Application.getPreferences().putBoolean(net.sf.openrocket.startup.Preferences.MOTOR_HIDE_SIMILAR, hideSimilarBox.isSelected());
|
|
||||||
updateData();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
panel.add(hideSimilarBox, "gapleft para, spanx, growx, wrap para");
|
|
||||||
|
|
||||||
{
|
|
||||||
final JCheckBox hideUsedBox = new JCheckBox("Hide motors already used in the mount");
|
|
||||||
GUIUtil.changeFontSize(hideUsedBox, -1);
|
|
||||||
hideUsedBox.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
rowFilter.setHideUsedMotors(hideUsedBox.isSelected());
|
|
||||||
sorter.sort();
|
|
||||||
scrollSelectionVisible();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
panel.add(hideUsedBox, "gapleft para, spanx, growx, wrap para");
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
// Find all the manufacturers:
|
// Find all the manufacturers:
|
||||||
Set<Manufacturer> manus = new HashSet<Manufacturer>();
|
Set<Manufacturer> allManufacturers = new HashSet<Manufacturer>();
|
||||||
for (ThrustCurveMotorSet s : database) {
|
for (ThrustCurveMotorSet s : database) {
|
||||||
manus.add(s.getManufacturer());
|
allManufacturers.add(s.getManufacturer());
|
||||||
}
|
}
|
||||||
final ManufacturerPopupSelector popup = new ManufacturerPopupSelector(manus, unselectedManusFromPreferences) {
|
|
||||||
|
final MotorFilterPopupMenu popup = new MotorFilterPopupMenu(allManufacturers, rowFilter) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDismissed(List<Manufacturer> selectedManufacturers, List<Manufacturer> unselectedManufacturers) {
|
public void onSelectionChanged() {
|
||||||
((SwingPreferences) Application.getPreferences()).setExcludedMotorManufacturers(unselectedManufacturers);
|
|
||||||
rowFilter.setExcludedManufacturers(unselectedManufacturers);
|
|
||||||
sorter.sort();
|
sorter.sort();
|
||||||
scrollSelectionVisible();
|
scrollSelectionVisible();
|
||||||
System.out.println("Here I am");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
JButton manuFilter = new JButton("Manufacturer Filter");
|
JButton manuFilter = new JButton("Motor Filter");
|
||||||
manuFilter.addMouseListener(new MouseListener() {
|
manuFilter.addMouseListener(new MouseListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -319,7 +275,7 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
panel.add(manuFilter, "gapleft para, spanx, growx, wrap para");
|
panel.add(manuFilter, "gapleft para, wrap para");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -382,8 +338,32 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
scrollpane.setViewportView(table);
|
scrollpane.setViewportView(table);
|
||||||
panel.add(scrollpane, "grow, width :500:, height :300:, spanx, wrap para");
|
panel.add(scrollpane, "grow, width :500:, height :300:, spanx, wrap para");
|
||||||
|
|
||||||
|
{
|
||||||
|
final JCheckBox hideUsedBox = new JCheckBox("Hide motors already used in the mount");
|
||||||
|
GUIUtil.changeFontSize(hideUsedBox, -1);
|
||||||
|
hideUsedBox.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
rowFilter.setHideUsedMotors(hideUsedBox.isSelected());
|
||||||
|
sorter.sort();
|
||||||
|
scrollSelectionVisible();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.add(hideUsedBox, "gapleft para, spanx, growx, wrap para");
|
||||||
|
}
|
||||||
|
|
||||||
|
//// Hide very similar thrust curves
|
||||||
|
hideSimilarBox = new JCheckBox(trans.get("TCMotorSelPan.checkbox.hideSimilar"));
|
||||||
|
GUIUtil.changeFontSize(hideSimilarBox, -1);
|
||||||
|
hideSimilarBox.setSelected(Application.getPreferences().getBoolean(net.sf.openrocket.startup.Preferences.MOTOR_HIDE_SIMILAR, true));
|
||||||
|
hideSimilarBox.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Application.getPreferences().putBoolean(net.sf.openrocket.startup.Preferences.MOTOR_HIDE_SIMILAR, hideSimilarBox.isSelected());
|
||||||
|
updateData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
panel.add(hideSimilarBox, "gapleft para, spanx, growx, wrap para");
|
||||||
|
|
||||||
// Motor mount diameter label
|
// Motor mount diameter label
|
||||||
//// Motor mount diameter:
|
//// Motor mount diameter:
|
||||||
@ -391,42 +371,6 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(diameter));
|
UnitGroup.UNITS_MOTOR_DIMENSIONS.getDefaultUnit().toStringUnit(diameter));
|
||||||
panel.add(label, "gapright 30lp, spanx, split");
|
panel.add(label, "gapright 30lp, spanx, split");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Search field
|
|
||||||
//// Search:
|
|
||||||
label = new StyledLabel(trans.get("TCMotorSelPan.lbl.Search"));
|
|
||||||
panel.add(label, "");
|
|
||||||
|
|
||||||
searchField = new JTextField();
|
|
||||||
searchField.getDocument().addDocumentListener(new DocumentListener() {
|
|
||||||
@Override
|
|
||||||
public void changedUpdate(DocumentEvent e) {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void insertUpdate(DocumentEvent e) {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void removeUpdate(DocumentEvent e) {
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void update() {
|
|
||||||
String text = searchField.getText().trim();
|
|
||||||
String[] split = text.split("\\s+");
|
|
||||||
rowFilter.setSearchTerms(Arrays.asList(split));
|
|
||||||
sorter.sort();
|
|
||||||
scrollSelectionVisible();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
panel.add(searchField, "growx, wrap");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Vertical split
|
// Vertical split
|
||||||
this.add(panel, "grow");
|
this.add(panel, "grow");
|
||||||
this.add(new JSeparator(JSeparator.VERTICAL), "growy, gap para para");
|
this.add(new JSeparator(JSeparator.VERTICAL), "growy, gap para para");
|
||||||
@ -615,17 +559,8 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
|
|||||||
|
|
||||||
panel.add(layer, "width 300:300:, height 180:180:, grow, spanx");
|
panel.add(layer, "width 300:300:, height 180:180:, grow, spanx");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.add(panel, "grow");
|
this.add(panel, "grow");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Sets the filter:
|
|
||||||
int showMode = Application.getPreferences().getChoice(net.sf.openrocket.startup.Preferences.MOTOR_DIAMETER_FILTER, SHOW_MAX, SHOW_EXACT);
|
|
||||||
filterComboBox.setSelectedIndex(showMode);
|
|
||||||
|
|
||||||
|
|
||||||
// Update the panel data
|
// Update the panel data
|
||||||
updateData();
|
updateData();
|
||||||
setDelays(false);
|
setDelays(false);
|
||||||
|
@ -159,6 +159,14 @@ public class CheckList<T> {
|
|||||||
return unchecked;
|
return unchecked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkAll() {
|
||||||
|
getModel().checkAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearAll() {
|
||||||
|
getModel().clearAll();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets checked elements
|
* Resets checked elements
|
||||||
* @param elements
|
* @param elements
|
||||||
@ -167,6 +175,10 @@ public class CheckList<T> {
|
|||||||
getModel().setCheckedItems(elements);
|
getModel().setCheckedItems(elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUncheckedItems( Collection<T> elements ) {
|
||||||
|
getModel().setUncheckedItems(elements);
|
||||||
|
}
|
||||||
|
|
||||||
public void toggleIndex(int index) {
|
public void toggleIndex(int index) {
|
||||||
if (index >= 0 && index < list.getModel().getSize()) {
|
if (index >= 0 && index < list.getModel().getSize()) {
|
||||||
DefaultCheckListModel<T> model = getModel();
|
DefaultCheckListModel<T> model = getModel();
|
||||||
|
@ -73,7 +73,8 @@ final class CheckListEditor extends MouseAdapter {
|
|||||||
|
|
||||||
if (e.getClickCount() > 1) {
|
if (e.getClickCount() > 1) {
|
||||||
// clear all and check selected for more then 1 clicks
|
// clear all and check selected for more then 1 clicks
|
||||||
model.setCheckedItems(Arrays.asList(model.getElementAt(index)));
|
// Original implementation had this implementation. I didn't like that behavior.
|
||||||
|
// model.setCheckedItems(Arrays.asList(model.getElementAt(index)));
|
||||||
} else {
|
} else {
|
||||||
// simple toggle for 1 click
|
// simple toggle for 1 click
|
||||||
model.setCheckedIndex(index, !model.isCheckedIndex(index));
|
model.setCheckedIndex(index, !model.isCheckedIndex(index));
|
||||||
|
@ -107,6 +107,16 @@ public class DefaultCheckListModel<T> extends AbstractListModel {
|
|||||||
return Collections.unmodifiableList(items);
|
return Collections.unmodifiableList(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearAll() {
|
||||||
|
checks.clear();
|
||||||
|
fireContentsChanged(this, 0, checks.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkAll() {
|
||||||
|
checks.addAll(data);
|
||||||
|
fireContentsChanged(this, 0, checks.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
public void setCheckedItems(Collection<T> items) {
|
public void setCheckedItems(Collection<T> items) {
|
||||||
|
|
||||||
// if ( CollectionUtils.isEmpty(items)) return;
|
// if ( CollectionUtils.isEmpty(items)) return;
|
||||||
@ -121,4 +131,14 @@ public class DefaultCheckListModel<T> extends AbstractListModel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUncheckedItems( Collection<T> items ) {
|
||||||
|
|
||||||
|
List<T> correctedItems = new ArrayList<T>(data);
|
||||||
|
correctedItems.removeAll(items);
|
||||||
|
|
||||||
|
checks.clear();
|
||||||
|
checks.addAll(correctedItems);
|
||||||
|
fireContentsChanged(this, 0, checks.size() - 1);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user