Added manufacturer selection boxes and exclude motors currently used

filters.
This commit is contained in:
kruland2607 2013-09-12 15:10:31 -05:00
parent 64015d72be
commit ea6aa3e414
10 changed files with 892 additions and 27 deletions

View File

@ -0,0 +1,96 @@
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);
}

View File

@ -9,6 +9,10 @@ import javax.swing.RowFilter;
import javax.swing.table.TableModel;
import net.sf.openrocket.database.motor.ThrustCurveMotorSet;
import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.MotorMount;
//////// Row filters
@ -23,16 +27,28 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
SMALLER
};
// configuration data used in the filter process
private final ThrustCurveMotorDatabaseModel model;
private final double diameter;
private final Double diameter;
private List<ThrustCurveMotor> usedMotors = new ArrayList<ThrustCurveMotor>();
// things which can be changed to modify filter behavior
private List<String> searchTerms = Collections.<String> emptyList();
private DiameterFilterControl diameterControl = DiameterFilterControl.ALL;
private boolean hideUsedMotors = false;
private List<Manufacturer> excludedManufacturers = new ArrayList<Manufacturer>();
public MotorRowFilter(ThrustCurveMotorDatabaseModel model, double diameter) {
public MotorRowFilter(MotorMount mount, ThrustCurveMotorDatabaseModel model) {
super();
this.model = model;
this.diameter = diameter;
if (mount != null) {
this.diameter = mount.getMotorMountDiameter();
for (MotorConfiguration m : mount.getMotorConfiguration()) {
this.usedMotors.add((ThrustCurveMotor) m.getMotor());
}
} else {
this.diameter = null;
}
}
public void setSearchTerms(final List<String> searchTerms) {
@ -49,14 +65,46 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
this.diameterControl = diameterControl;
}
void setHideUsedMotors(boolean hideUsedMotors) {
this.hideUsedMotors = hideUsedMotors;
}
void setExcludedManufacturers(List<Manufacturer> excludedManufacturers) {
this.excludedManufacturers.clear();
this.excludedManufacturers.addAll(excludedManufacturers);
}
@Override
public boolean include(RowFilter.Entry<? extends TableModel, ? extends Integer> entry) {
int index = entry.getIdentifier();
ThrustCurveMotorSet m = model.getMotorSet(index);
return filterByDiameter(m) && filterByString(m);
return filterManufacturers(m) && filterUsed(m) && filterByDiameter(m) && filterByString(m);
}
public boolean filterByDiameter(ThrustCurveMotorSet m) {
private boolean filterManufacturers(ThrustCurveMotorSet m) {
if (excludedManufacturers.contains(m.getManufacturer())) {
return false;
} else {
return true;
}
}
private boolean filterUsed(ThrustCurveMotorSet m) {
if (!hideUsedMotors) {
return true;
}
for (ThrustCurveMotor motor : usedMotors) {
if (m.matches(motor)) {
return false;
}
}
return true;
}
private boolean filterByDiameter(ThrustCurveMotorSet m) {
if (diameter == null) {
return true;
}
switch (diameterControl) {
default:
case ALL:
@ -69,7 +117,7 @@ class MotorRowFilter extends RowFilter<TableModel, Integer> {
}
public boolean filterByString(ThrustCurveMotorSet m) {
private boolean filterByString(ThrustCurveMotorSet m) {
main: for (String s : searchTerms) {
for (ThrustCurveMotorColumns col : ThrustCurveMotorColumns.values()) {
String str = col.getValue(m).toString().toLowerCase(Locale.getDefault());

View File

@ -0,0 +1,177 @@
/*
* Copyright (c) 2009-2011, EzWare
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.Redistributions
* in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.Neither the name of the
* EzWare nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
package net.sf.openrocket.gui.util;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.JList;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
/**
* The decorator for JList which makes it work like check list
* UI can be designed using JList and which can be later decorated to become a check list
* @author Eugene Ryzhikov
*
* @param <T> list item type
*/
public class CheckList<T> {
private final JList list;
private static final MouseAdapter checkBoxEditor = new CheckListEditor();
public static class Builder {
private JList list;
public Builder(JList list) {
this.list = list == null ? new JList() : list;
}
public Builder() {
this(null);
}
public <T> CheckList<T> build() {
return new CheckList<T>(list);
}
}
/**
* Wraps the standard JList and makes it work like check list
* @param list
*/
private CheckList(final JList list) {
if (list == null)
throw new NullPointerException();
this.list = list;
this.list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
if (!isEditorAttached())
list.addMouseListener(checkBoxEditor);
this.list.setCellRenderer(new CheckListRenderer());
setupKeyboardActions(list);
}
@SuppressWarnings("serial")
private void setupKeyboardActions(final JList list) {
String actionKey = "toggle-check";
list.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), actionKey);
list.getActionMap().put(actionKey, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
toggleIndex(list.getSelectedIndex());
}
});
}
private boolean isEditorAttached() {
for (MouseListener ml : list.getMouseListeners()) {
if (ml instanceof CheckListEditor)
return true;
}
return false;
}
public JList getList() {
return list;
}
/**
* Sets data to a check list. Simplification for setting new the model
* @param data
*/
public void setData(Collection<T> data) {
setModel(new DefaultCheckListModel<T>(data));
}
/**
* Sets the model for check list.
* @param model
*/
public void setModel(DefaultCheckListModel<T> model) {
list.setModel(model);
}
@SuppressWarnings("unchecked")
public DefaultCheckListModel<T> getModel() {
return (DefaultCheckListModel<T>) list.getModel();
}
/**
* Returns a collection of checked items.
* @return collection of checked items. Empty collection if nothing is selected
*/
public Collection<T> getCheckedItems() {
return getModel().getCheckedItems();
}
public Collection<T> getUncheckedItems() {
List<T> unchecked = new ArrayList<T>();
for (int i = getModel().getSize() - 1; i >= 0; i--) {
unchecked.add((T) getModel().getElementAt(i));
}
unchecked.removeAll(getCheckedItems());
return unchecked;
}
/**
* Resets checked elements
* @param elements
*/
public void setCheckedItems(Collection<T> elements) {
getModel().setCheckedItems(elements);
}
public void toggleIndex(int index) {
if (index >= 0 && index < list.getModel().getSize()) {
DefaultCheckListModel<T> model = getModel();
model.setCheckedIndex(index, !model.isCheckedIndex(index));
}
}
}

View File

@ -0,0 +1,86 @@
/*
* Copyright (c) 2009-2011, EzWare
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.Redistributions
* in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.Neither the name of the
* EzWare nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
package net.sf.openrocket.gui.util;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import javax.swing.JList;
import javax.swing.SwingUtilities;
/**
* Determines mouse click and
* 1. Toggles the check on selected item if clicked once
* 2. Clears checks and checks selected item if clicked more then once
*
* Created on Feb 4, 2011
* @author Eugene Ryzhikov
*
*/
final class CheckListEditor extends MouseAdapter {
@Override
public void mouseClicked(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e))
return;
JList list = (JList) e.getSource();
if (!list.isEnabled() || (!(list.getModel() instanceof DefaultCheckListModel<?>)))
return;
int index = list.locationToIndex(e.getPoint());
if (index < 0)
return;
Rectangle bounds = list.getCellBounds(index, index);
if (bounds.contains(e.getPoint())) {
@SuppressWarnings("unchecked")
DefaultCheckListModel<Object> model = (DefaultCheckListModel<Object>) list.getModel();
if (e.getClickCount() > 1) {
// clear all and check selected for more then 1 clicks
model.setCheckedItems(Arrays.asList(model.getElementAt(index)));
} else {
// simple toggle for 1 click
model.setCheckedIndex(index, !model.isCheckedIndex(index));
}
e.consume();
}
}
}

View File

@ -0,0 +1,228 @@
/*
* Copyright (c) 2009-2011, EzWare
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.Redistributions
* in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.Neither the name of the
* EzWare nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
package net.sf.openrocket.gui.util;
import java.awt.Color;
import java.awt.Component;
import java.awt.Rectangle;
import java.io.Serializable;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
public class CheckListRenderer extends JCheckBox implements ListCellRenderer, Serializable {
private static final long serialVersionUID = 1L;
private static final Border NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1);
private static final Border SAFE_NO_FOCUS_BORDER = NO_FOCUS_BORDER; // may change in the feature
/**
* Constructs a default renderer object for an item in a list.
*/
public CheckListRenderer() {
super();
setOpaque(true);
setBorder(getNoFocusBorder());
}
private static Border getNoFocusBorder() {
if (System.getSecurityManager() != null) {
return SAFE_NO_FOCUS_BORDER;
} else {
return NO_FOCUS_BORDER;
}
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
setComponentOrientation(list.getComponentOrientation());
Color bg = null;
Color fg = null;
JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null && !dropLocation.isInsert() && dropLocation.getIndex() == index) {
bg = UIManager.getColor("List.dropCellBackground");
fg = UIManager.getColor("List.dropCellForeground");
isSelected = true;
}
if (isSelected) {
setBackground(bg == null ? list.getSelectionBackground() : bg);
setForeground(fg == null ? list.getSelectionForeground() : fg);
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
if (value instanceof Icon) {
setIcon((Icon) value);
setText("");
} else {
setIcon(null);
setText(getObjectAsText(value));
}
setSelected(isChecked(list, index));
setEnabled(list.isEnabled());
setFont(list.getFont());
Border border = null;
if (cellHasFocus) {
if (isSelected) {
border = UIManager.getBorder("List.focusSelectedCellHighlightBorder");
}
if (border == null) {
border = UIManager.getBorder("List.focusCellHighlightBorder");
}
} else {
border = getNoFocusBorder();
}
setBorder(border);
return this;
}
protected String getObjectAsText(Object obj) {
return (obj == null) ? "" : obj.toString();
}
private boolean isChecked(JList list, int index) {
if (list.getModel() instanceof DefaultCheckListModel<?>) {
return ((DefaultCheckListModel<?>) list.getModel()).isCheckedIndex(index);
} else {
return false;
}
}
/**
* @return true if the background is opaque and differs from the JList's background; false otherwise
*/
@Override
public boolean isOpaque() {
Color back = getBackground();
Component p = getParent();
if (p != null) {
p = p.getParent();
}
// p should now be the JList.
boolean colorMatch = (back != null) && (p != null) && back.equals(p.getBackground()) && p.isOpaque();
return !colorMatch && super.isOpaque();
}
@Override
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
if ("text".equals(propertyName) ||
(("font".equals(propertyName) || "foreground".equals(propertyName)) &&
oldValue != newValue && getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) {
super.firePropertyChange(propertyName, oldValue, newValue);
}
}
// Methods below are overridden for performance reasons.
@Override
public void validate() {
}
@Override
public void invalidate() {
}
@Override
public void repaint() {
}
@Override
public void revalidate() {
}
@Override
public void repaint(long tm, int x, int y, int width, int height) {
}
@Override
public void repaint(Rectangle r) {
}
@Override
public void firePropertyChange(String propertyName, byte oldValue, byte newValue) {
}
@Override
public void firePropertyChange(String propertyName, char oldValue, char newValue) {
}
@Override
public void firePropertyChange(String propertyName, short oldValue, short newValue) {
}
@Override
public void firePropertyChange(String propertyName, int oldValue, int newValue) {
}
@Override
public void firePropertyChange(String propertyName, long oldValue, long newValue) {
}
@Override
public void firePropertyChange(String propertyName, float oldValue, float newValue) {
}
@Override
public void firePropertyChange(String propertyName, double oldValue, double newValue) {
}
@Override
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
}
@SuppressWarnings("serial")
public static class UIResource extends DefaultListCellRenderer implements javax.swing.plaf.UIResource {
}
}

View File

@ -0,0 +1,124 @@
/*
* Copyright (c) 2009-2011, EzWare
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.Redistributions
* in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.Neither the name of the
* EzWare nor the names of its contributors may be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
package net.sf.openrocket.gui.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.AbstractListModel;
/**
* Default model for check list. It is based on the list of items
* Implementation of checks is based on HashSet of checked items
*
* @author Eugene Ryzhikov
*
* @param <T> list element type
*/
public class DefaultCheckListModel<T> extends AbstractListModel {
private static final long serialVersionUID = 1L;
private final List<T> data = new ArrayList<T>();
private final Set<T> checks = new HashSet<T>();
public DefaultCheckListModel(Collection<? extends T> data) {
if (data == null)
return;
for (T object : data) {
this.data.add(object);
checks.clear();
}
}
public DefaultCheckListModel(T... data) {
this(Arrays.asList(data));
}
/* (non-Javadoc)
* @see org.oxbow.swingbits.list.ICheckListModel#getSize()
*/
@Override
public int getSize() {
return data().size();
}
private List<T> data() {
return data;
}
@Override
public Object getElementAt(int index) {
return data().get(index);
}
public boolean isCheckedIndex(int index) {
return checks.contains(data().get(index));
}
public void setCheckedIndex(int index, boolean value) {
T o = data().get(index);
if (value)
checks.add(o);
else
checks.remove(o);
fireContentsChanged(this, index, index);
}
public Collection<T> getCheckedItems() {
List<T> items = new ArrayList<T>(checks);
items.retainAll(data);
return Collections.unmodifiableList(items);
}
public void setCheckedItems(Collection<T> items) {
// if ( CollectionUtils.isEmpty(items)) return;
List<T> correctedItems = new ArrayList<T>(items);
correctedItems.retainAll(data);
checks.clear();
checks.addAll(correctedItems);
fireContentsChanged(this, 0, checks.size() - 1);
}
}

View File

@ -11,7 +11,7 @@ import net.sf.openrocket.util.ChangeSource;
*
* @param <E> the parameter type
*/
public interface FlightConfiguration<E extends ChangeSource> extends FlightConfigurableComponent {
public interface FlightConfiguration<E extends ChangeSource> extends FlightConfigurableComponent, Iterable<E> {
/**
* Return the default parameter value for this FlightConfiguration.

View File

@ -2,6 +2,7 @@ package net.sf.openrocket.rocketcomponent;
import java.util.EventObject;
import java.util.HashMap;
import java.util.Iterator;
import net.sf.openrocket.util.StateChangeListener;
import net.sf.openrocket.util.Utils;
@ -79,6 +80,10 @@ class FlightConfigurationImpl<E extends FlightConfigurableParameter<E>> implemen
fireEvent();
}
@Override
public Iterator<E> iterator() {
return map.values().iterator();
}
@Override

View File

@ -11,14 +11,18 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.prefs.Preferences;
import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
@ -54,6 +58,7 @@ import net.sf.openrocket.gui.util.Icons;
import net.sf.openrocket.gui.util.SwingPreferences;
import net.sf.openrocket.l10n.Translator;
import net.sf.openrocket.logging.Markers;
import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.motor.ThrustCurveMotor;
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
@ -105,13 +110,10 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
private static final ThrustCurveMotorComparator MOTOR_COMPARATOR = new ThrustCurveMotorComparator();
private final List<ThrustCurveMotorSet> database;
private CloseableDialog dialog = null;
final ThrustCurveMotorDatabaseModel model;
private final JTable table;
private final TableRowSorter<TableModel> sorter;
@ -192,9 +194,11 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
}
database = db;
model = new ThrustCurveMotorDatabaseModel(database);
final MotorRowFilter rowFilter = new MotorRowFilter(model, diameter);
List<Manufacturer> unselectedManusFromPreferences = ((SwingPreferences) Application.getPreferences()).getExcludedMotorManufacturers();
model = new ThrustCurveMotorDatabaseModel(database);
final MotorRowFilter rowFilter = new MotorRowFilter(mount, model);
rowFilter.setExcludedManufacturers(unselectedManusFromPreferences);
//// GUI
@ -256,6 +260,69 @@ public class ThrustCurveMotorSelectionPanel extends JPanel implements MotorSelec
});
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:
Set<Manufacturer> manus = new HashSet<Manufacturer>();
for (ThrustCurveMotorSet s : database) {
manus.add(s.getManufacturer());
}
final ManufacturerPopupSelector popup = new ManufacturerPopupSelector(manus, unselectedManusFromPreferences) {
@Override
public void onDismissed(List<Manufacturer> selectedManufacturers, List<Manufacturer> unselectedManufacturers) {
((SwingPreferences) Application.getPreferences()).setExcludedMotorManufacturers(unselectedManufacturers);
rowFilter.setExcludedManufacturers(unselectedManufacturers);
sorter.sort();
scrollSelectionVisible();
System.out.println("Here I am");
}
};
JButton manuFilter = new JButton("Manufacturer Filter");
manuFilter.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
popup.show(e.getComponent(), e.getX(), e.getY());
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
panel.add(manuFilter, "gapleft para, spanx, growx, wrap para");
}
// Motor selection table
table = new JTable(model);

View File

@ -6,6 +6,7 @@ import java.awt.Point;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@ -14,12 +15,10 @@ import java.util.Set;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.openrocket.arch.SystemInfo;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.preset.ComponentPreset;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.simulation.FlightDataType;
@ -30,6 +29,9 @@ import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.BugException;
import net.sf.openrocket.util.BuildProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
private static final Logger log = LoggerFactory.getLogger(SwingPreferences.class);
@ -575,9 +577,9 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
return materials;
}
//// Preset Component Favorites
@Override
public void setComponentFavorite(ComponentPreset preset, ComponentPreset.Type type, boolean favorite) {
Preferences prefs = PREFNODE.node("favoritePresets").node(type.name());
@ -599,35 +601,67 @@ public class SwingPreferences extends net.sf.openrocket.startup.Preferences {
}
return collection;
}
//// Decal Editor Setting
private final static String DECAL_EDITOR_PREFERNCE_NODE = "decalEditorPreference";
private final static String DECAL_EDITOR_USE_SYSTEM_DEFAULT = "<SYSTEM>";
public void clearDecalEditorPreference( ) {
putString(DECAL_EDITOR_PREFERNCE_NODE,null);
public void clearDecalEditorPreference() {
putString(DECAL_EDITOR_PREFERNCE_NODE, null);
}
public void setDecalEditorPreference(boolean useSystem, String commandLine) {
if ( useSystem ) {
putString(DECAL_EDITOR_PREFERNCE_NODE,DECAL_EDITOR_USE_SYSTEM_DEFAULT);
} else if ( commandLine != null ) {
if (useSystem) {
putString(DECAL_EDITOR_PREFERNCE_NODE, DECAL_EDITOR_USE_SYSTEM_DEFAULT);
} else if (commandLine != null) {
putString(DECAL_EDITOR_PREFERNCE_NODE, commandLine);
} else {
clearDecalEditorPreference();
}
}
public boolean isDecalEditorPreferenceSet() {
String s = getString(DECAL_EDITOR_PREFERNCE_NODE,null);
String s = getString(DECAL_EDITOR_PREFERNCE_NODE, null);
return s != null;
}
public boolean isDecalEditorPreferenceSystem() {
String s = getString(DECAL_EDITOR_PREFERNCE_NODE,null);
String s = getString(DECAL_EDITOR_PREFERNCE_NODE, null);
return DECAL_EDITOR_USE_SYSTEM_DEFAULT.equals(s);
}
public String getDecalEditorCommandLine() {
return getString(DECAL_EDITOR_PREFERNCE_NODE,null);
return getString(DECAL_EDITOR_PREFERNCE_NODE, null);
}
public List<Manufacturer> getExcludedMotorManufacturers() {
Preferences prefs = PREFNODE.node("excludedMotorManufacturers");
List<Manufacturer> collection = new ArrayList<Manufacturer>();
try {
String[] manuShortNames = prefs.keys();
for (String s : manuShortNames) {
Manufacturer m = Manufacturer.getManufacturer(s);
if (m != null) {
collection.add(m);
}
}
} catch (BackingStoreException e) {
}
return collection;
}
public void setExcludedMotorManufacturers(Collection<Manufacturer> manus) {
Preferences prefs = PREFNODE.node("excludedMotorManufacturers");
try {
for (String s : prefs.keys()) {
prefs.remove(s);
}
} catch (BackingStoreException e) {
}
for (Manufacturer m : manus) {
prefs.putBoolean(m.getSimpleName(), true);
}
}
}