Make the appearance dialog work better when switching between default
texture and custom. Also ensure that default texture names do not appear in the texture drop down.
This commit is contained in:
parent
fe8cc22f6b
commit
e254ff0e94
@ -34,6 +34,21 @@ public class AppearanceBuilder extends AbstractChangeSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AppearanceBuilder(Appearance a) {
|
public AppearanceBuilder(Appearance a) {
|
||||||
|
setAppearance(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetToDefaults() {
|
||||||
|
paint = new Color(0, 0, 0);
|
||||||
|
shine = 0;
|
||||||
|
offsetU = offsetV = 0;
|
||||||
|
centerU = centerV = 0;
|
||||||
|
scaleU = scaleV = 1;
|
||||||
|
rotation = 0;
|
||||||
|
image = null;
|
||||||
|
edgeMode = EdgeMode.REPEAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppearance(Appearance a) {
|
||||||
resetToDefaults();
|
resetToDefaults();
|
||||||
if (a != null) {
|
if (a != null) {
|
||||||
setPaint(a.getPaint());
|
setPaint(a.getPaint());
|
||||||
@ -50,17 +65,6 @@ public class AppearanceBuilder extends AbstractChangeSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetToDefaults() {
|
|
||||||
paint = new Color(0, 0, 0);
|
|
||||||
shine = 0;
|
|
||||||
offsetU = offsetV = 0;
|
|
||||||
centerU = centerV = 0;
|
|
||||||
scaleU = scaleV = 1;
|
|
||||||
rotation = 0;
|
|
||||||
image = null;
|
|
||||||
edgeMode = EdgeMode.REPEAT;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Appearance getAppearance() {
|
public Appearance getAppearance() {
|
||||||
|
|
||||||
Decal t = null;
|
Decal t = null;
|
||||||
|
@ -7,7 +7,7 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
import net.sf.openrocket.util.ChangeSource;
|
import net.sf.openrocket.util.ChangeSource;
|
||||||
|
|
||||||
public interface DecalImage extends ChangeSource {
|
public interface DecalImage extends ChangeSource, Comparable<DecalImage> {
|
||||||
|
|
||||||
public String getName();
|
public String getName();
|
||||||
|
|
||||||
|
@ -47,4 +47,9 @@ class ResourceDecalImage implements DecalImage {
|
|||||||
//Unimplemented, this can not change
|
//Unimplemented, this can not change
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(DecalImage o) {
|
||||||
|
return getName().compareTo(o.getName());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public class DecalModel extends AbstractListModel implements ComboBoxModel {
|
|||||||
@Override
|
@Override
|
||||||
public Object getSelectedItem() {
|
public Object getSelectedItem() {
|
||||||
DecalImage decal = ab.getImage();
|
DecalImage decal = ab.getImage();
|
||||||
if (decal == null) {
|
if (decal == null || !document.getDecalList().contains(decal)) {
|
||||||
return NONE_SELECTED;
|
return NONE_SELECTED;
|
||||||
} else {
|
} else {
|
||||||
return decal;
|
return decal;
|
||||||
|
@ -21,6 +21,7 @@ import javax.swing.SwingConstants;
|
|||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
import net.sf.openrocket.appearance.Appearance;
|
||||||
import net.sf.openrocket.appearance.AppearanceBuilder;
|
import net.sf.openrocket.appearance.AppearanceBuilder;
|
||||||
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
import net.sf.openrocket.appearance.Decal.EdgeMode;
|
||||||
import net.sf.openrocket.appearance.defaults.DefaultAppearance;
|
import net.sf.openrocket.appearance.defaults.DefaultAppearance;
|
||||||
@ -53,6 +54,13 @@ public class AppearancePanel extends JPanel {
|
|||||||
|
|
||||||
private AppearanceBuilder ab;
|
private AppearanceBuilder ab;
|
||||||
|
|
||||||
|
// We hang on to the user selected appearance when switching to default appearance.
|
||||||
|
// this appearance is restored if the user unchecks the "default" button.
|
||||||
|
private Appearance previousUserSelectedAppearance = null;
|
||||||
|
|
||||||
|
// We cache the default appearance for this component to make switching faster.
|
||||||
|
private Appearance defaultAppearance = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A non-unit that adjusts by a small amount, suitable for
|
* A non-unit that adjusts by a small amount, suitable for
|
||||||
* values that are on the 0-1 scale
|
* values that are on the 0-1 scale
|
||||||
@ -117,7 +125,14 @@ public class AppearancePanel extends JPanel {
|
|||||||
public AppearancePanel(final OpenRocketDocument document, final RocketComponent c) {
|
public AppearancePanel(final OpenRocketDocument document, final RocketComponent c) {
|
||||||
super(new MigLayout("fill", "[150][grow][150][grow]"));
|
super(new MigLayout("fill", "[150][grow][150][grow]"));
|
||||||
|
|
||||||
ab = new AppearanceBuilder(c.getAppearance() != null ? c.getAppearance() : DefaultAppearance.getDefaultAppearance(c));
|
previousUserSelectedAppearance = c.getAppearance();
|
||||||
|
defaultAppearance = DefaultAppearance.getDefaultAppearance(c);
|
||||||
|
if (previousUserSelectedAppearance == null) {
|
||||||
|
previousUserSelectedAppearance = new AppearanceBuilder().getAppearance();
|
||||||
|
ab = new AppearanceBuilder(defaultAppearance);
|
||||||
|
} else {
|
||||||
|
ab = new AppearanceBuilder(previousUserSelectedAppearance);
|
||||||
|
}
|
||||||
|
|
||||||
net.sf.openrocket.util.Color figureColor = c.getColor();
|
net.sf.openrocket.util.Color figureColor = c.getColor();
|
||||||
if (figureColor == null) {
|
if (figureColor == null) {
|
||||||
@ -223,9 +238,10 @@ public class AppearancePanel extends JPanel {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (materialDefault.isSelected()) {
|
if (materialDefault.isSelected()) {
|
||||||
c.setAppearance(null);
|
previousUserSelectedAppearance = (ab == null) ? null : ab.getAppearance();
|
||||||
|
ab.setAppearance(defaultAppearance);
|
||||||
} else {
|
} else {
|
||||||
c.setAppearance(ab.getAppearance());
|
ab.setAppearance(previousUserSelectedAppearance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -48,7 +48,6 @@ import javax.swing.event.TreeSelectionListener;
|
|||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import javax.swing.table.DefaultTableCellRenderer;
|
import javax.swing.table.DefaultTableCellRenderer;
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
import javax.swing.table.TableRowSorter;
|
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
import javax.swing.tree.TreePath;
|
import javax.swing.tree.TreePath;
|
||||||
|
|
||||||
@ -231,9 +230,6 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
selectedModifierTable.setRowSelectionAllowed(true);
|
selectedModifierTable.setRowSelectionAllowed(true);
|
||||||
selectedModifierTable.setColumnSelectionAllowed(false);
|
selectedModifierTable.setColumnSelectionAllowed(false);
|
||||||
selectedModifierTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
selectedModifierTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||||
TableRowSorter<ParameterSelectionTableModel> sorter = new TableRowSorter<ParameterSelectionTableModel>(selectedModifierTableModel);
|
|
||||||
sorter.setComparator(0, new SimulationModifierComparator());
|
|
||||||
selectedModifierTable.setRowSorter(sorter);
|
|
||||||
|
|
||||||
// Make sure spinner editor fits into the cell height
|
// Make sure spinner editor fits into the cell height
|
||||||
selectedModifierTable.setRowHeight(new JSpinner().getPreferredSize().height - 4);
|
selectedModifierTable.setRowHeight(new JSpinner().getPreferredSize().height - 4);
|
||||||
@ -733,6 +729,22 @@ public class GeneralOptimizationDialog extends JDialog {
|
|||||||
|
|
||||||
SimulationModifier[] modifiers = selectedModifiers.toArray(new SimulationModifier[0]);
|
SimulationModifier[] modifiers = selectedModifiers.toArray(new SimulationModifier[0]);
|
||||||
|
|
||||||
|
// Check for DeploymentAltitude modifier, if it's there, we want to make certain the DeploymentEvent
|
||||||
|
// is ALTITUDE:
|
||||||
|
for (SimulationModifier mod : modifiers) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
mod.initialize(simulation);
|
||||||
|
} catch (OptimizationException ex) {
|
||||||
|
updating = true;
|
||||||
|
startButton.setSelected(false);
|
||||||
|
startButton.setText(START_TEXT);
|
||||||
|
updating = false;
|
||||||
|
throw new BugException(ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Create and start the background worker
|
// Create and start the background worker
|
||||||
worker = new OptimizationWorker(simulation, parameter, goal, domain, modifiers) {
|
worker = new OptimizationWorker(simulation, parameter, goal, domain, modifiers) {
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user