Rework the motor table entry.

This commit is contained in:
kruland2607 2013-10-10 11:01:21 -05:00
parent 6641f959c5
commit 86a273272b
2 changed files with 76 additions and 11 deletions

View File

@ -139,9 +139,6 @@ public abstract class FlightConfigurablePanel<T extends FlightConfigurableCompon
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (!(c instanceof JLabel)) {
return c;
}
JLabel label = (JLabel) c;
switch (column) {

View File

@ -1,17 +1,28 @@
package net.sf.openrocket.gui.main.flightconfigpanel;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.table.TableCellRenderer;
import net.miginfocom.swing.MigLayout;
import net.sf.openrocket.gui.components.StyledLabel;
@ -19,8 +30,10 @@ import net.sf.openrocket.gui.components.StyledLabel.Style;
import net.sf.openrocket.gui.dialogs.flightconfiguration.IgnitionSelectionDialog;
import net.sf.openrocket.gui.dialogs.flightconfiguration.MotorMountConfigurationPanel;
import net.sf.openrocket.gui.dialogs.motor.MotorChooserDialog;
import net.sf.openrocket.gui.util.GUIUtil;
import net.sf.openrocket.motor.Motor;
import net.sf.openrocket.rocketcomponent.IgnitionConfiguration;
import net.sf.openrocket.rocketcomponent.IgnitionConfiguration.IgnitionEvent;
import net.sf.openrocket.rocketcomponent.MotorConfiguration;
import net.sf.openrocket.rocketcomponent.MotorMount;
import net.sf.openrocket.rocketcomponent.Rocket;
@ -28,6 +41,7 @@ import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Chars;
import net.sf.openrocket.util.Coordinate;
import net.sf.openrocket.util.Pair;
public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount> {
@ -220,15 +234,62 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
}
private class MotorTableCellRenderer extends FlightConfigurablePanel<MotorMount>.FlightConfigurableCellRenderer {
private class MotorTableCellRenderer implements TableCellRenderer {
private void setSelected( JComponent c, JTable table, boolean isSelected, boolean hasFocus ) {
c.setOpaque(true);
if ( isSelected) {
c.setBackground(table.getSelectionBackground());
c.setForeground(table.getSelectionForeground());
} else {
c.setBackground(table.getBackground());
c.setForeground(table.getForeground());
}
Border b = null;
if ( hasFocus ) {
if (isSelected) {
b = UIManager.getBorder("Table.focusSelectedCellHighlightBorder");
} else {
b = UIManager.getBorder("Table.focusCellHighligtBorder");
}
} else {
b = new EmptyBorder(1,1,1,1);
}
c.setBorder(b);
}
@Override
protected void format(MotorMount mount, String configId, JLabel label) {
public Component getTableCellRendererComponent(JTable table,Object value, boolean isSelected, boolean hasFocus, int row,int column) {
switch (column) {
case 0: {
JLabel label = new JLabel(descriptor.format(rocket, (String) value));
setSelected(label, table, isSelected, hasFocus);
return label;
}
default: {
Pair<String, MotorMount> v = (Pair<String, MotorMount>) value;
String id = v.getU();
MotorMount component = v.getV();
JLabel label = format(component, id);
setSelected(label, table, isSelected, hasFocus);
return label;
}
}
}
protected JLabel format(MotorMount mount, String configId) {
JLabel label = new JLabel();
label.setLayout(new BoxLayout(label, BoxLayout.X_AXIS));
MotorConfiguration motorConfig = mount.getMotorConfiguration().get(configId);
String motorString = getMotorSpecification(mount, motorConfig);
String ignitionString = getIgnitionEventString(configId, mount);
label.setText(motorString + " " + ignitionString);
JLabel motorDescriptionLabel = new JLabel(motorString);
label.add(motorDescriptionLabel);
label.add( Box.createRigidArea(new Dimension(10,0)));
JLabel ignitionLabel = getIgnitionEventString(configId, mount);
label.add(ignitionLabel);
label.validate();
return label;
// label.setText(motorString + " " + ignitionString);
}
private String getMotorSpecification(MotorMount mount, MotorConfiguration motorConfig) {
@ -250,24 +311,31 @@ public class MotorConfigurationPanel extends FlightConfigurablePanel<MotorMount>
return c.toAbsolute(Coordinate.NUL).length;
}
protected final void shaded(JLabel label) {
GUIUtil.changeFontStyle(label, Font.ITALIC);
label.setForeground(Color.GRAY);
}
private String getIgnitionEventString(String id, MotorMount mount) {
private JLabel getIgnitionEventString(String id, MotorMount mount) {
IgnitionConfiguration ignitionConfig = mount.getIgnitionConfiguration().get(id);
IgnitionConfiguration.IgnitionEvent ignitionEvent = ignitionConfig.getIgnitionEvent();
Double ignitionDelay = ignitionConfig.getIgnitionDelay();
boolean isDefault = mount.getIgnitionConfiguration().isDefault(id);
JLabel label = new JLabel();
String str = trans.get("MotorMount.IgnitionEvent.short." + ignitionEvent.name());
if (ignitionDelay > 0.001) {
if (ignitionEvent != IgnitionEvent.NEVER && ignitionDelay > 0.001) {
str = str + " + " + UnitGroup.UNITS_SHORT_TIME.toStringUnit(ignitionDelay);
}
if (isDefault) {
shaded(label);
String def = trans.get("MotorConfigurationTableModel.table.ignition.default");
str = def.replace("{0}", str);
}
return str;
label.setText(str);
return label;
}
}