UI refactoring
This commit is contained in:
		
							parent
							
								
									d27a394813
								
							
						
					
					
						commit
						b2776f5e92
					
				| @ -1841,16 +1841,16 @@ RecoveryConfigurationPanel.table.deployment.default = Default ({0}) | ||||
| SeparationConfigurationPanel.table.separation.default = Default ({0}) | ||||
| 
 | ||||
| IgnitionSelectionDialog.opt.title = Which flight configurations are affected: | ||||
| IgnitionSelectionDialog.opt.default = Change the default ignition event for this motor | ||||
| IgnitionSelectionDialog.opt.default = Change all configurations using the default ignition event | ||||
| IgnitionSelectionDialog.opt.override = Override for the {0} flight configuration only | ||||
| 
 | ||||
| DeploymentSelectionDialog.opt.title = Which flight configurations are affected: | ||||
| DeploymentSelectionDialog.opt.default = Change the default deployment event for this recovery device | ||||
| DeploymentSelectionDialog.opt.default = Change all configuration using the default deployment event | ||||
| DeploymentSelectionDialog.opt.override = Override for the {0} flight configuration only | ||||
| 
 | ||||
| SeparationSelectionDialog.lbl.separation = Stage separation at: | ||||
| SeparationSelectionDialog.opt.title = Which flight configurations are affected: | ||||
| SeparationSelectionDialog.opt.default = Change the default separation event for this stage | ||||
| SeparationSelectionDialog.opt.default = Change all configuration using the default separation event | ||||
| SeparationSelectionDialog.opt.override = Override for the {0} flight configuration only | ||||
| 
 | ||||
| MotorConfigurationPanel.description = <b>Select the motors and motor ignition events of your rocket.</b><br> <em>Motor mounts:</em> Select which components function as motor mounts.<br> <em>Motor configurations:</em> Select the motor and ignition event for each motor mount. | ||||
|  | ||||
| @ -41,12 +41,13 @@ public class IgnitionSelectionDialog extends JDialog { | ||||
| 		 | ||||
| 		JPanel panel = new JPanel(new MigLayout("fill")); | ||||
| 		 | ||||
| 		boolean isDefault = component.getIgnitionConfiguration().isDefault(id); | ||||
| 		panel.add(new JLabel(trans.get("IgnitionSelectionDialog.opt.title")), "span, wrap rel"); | ||||
| 		final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), true); | ||||
| 		final JRadioButton defaultButton = new JRadioButton(trans.get("IgnitionSelectionDialog.opt.default"), isDefault); | ||||
| 		panel.add(defaultButton, "span, gapleft para, wrap rel"); | ||||
| 		String str = trans.get("IgnitionSelectionDialog.opt.override"); | ||||
| 		str = str.replace("{0}", rocket.getFlightConfigurationNameOrDescription(id)); | ||||
| 		final JRadioButton overrideButton = new JRadioButton(str, false); | ||||
| 		final JRadioButton overrideButton = new JRadioButton(str, !isDefault); | ||||
| 		panel.add(overrideButton, "span, gapleft para, wrap para"); | ||||
| 		 | ||||
| 		ButtonGroup buttonGroup = new ButtonGroup(); | ||||
| @ -90,6 +91,7 @@ public class IgnitionSelectionDialog extends JDialog { | ||||
| 		 | ||||
| 		panel.add(okButton, "sizegroup btn"); | ||||
| 		 | ||||
| 		 | ||||
| 		JButton cancel = new JButton(trans.get("button.cancel")); | ||||
| 		cancel.addActionListener(new ActionListener() { | ||||
| 			@Override | ||||
|  | ||||
| @ -1,5 +1,8 @@ | ||||
| package net.sf.openrocket.gui.dialogs.flightconfiguration; | ||||
| 
 | ||||
| import java.awt.Color; | ||||
| import java.awt.Component; | ||||
| import java.awt.Font; | ||||
| import java.awt.event.ActionEvent; | ||||
| import java.awt.event.ActionListener; | ||||
| import java.awt.event.MouseAdapter; | ||||
| @ -11,6 +14,7 @@ import javax.swing.JPanel; | ||||
| import javax.swing.JScrollPane; | ||||
| import javax.swing.JTable; | ||||
| import javax.swing.ListSelectionModel; | ||||
| import javax.swing.table.DefaultTableCellRenderer; | ||||
| import javax.swing.table.TableColumn; | ||||
| import javax.swing.table.TableColumnModel; | ||||
| 
 | ||||
| @ -82,11 +86,13 @@ public class MotorConfigurationPanel extends JPanel { | ||||
| 		configurationTable = new JTable(configurationTableModel); | ||||
| 		configurationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | ||||
| 		configurationTable.setRowSelectionAllowed(true); | ||||
| 		configurationTable.setDefaultRenderer(Object.class, new MotorTableCellRenderer()); | ||||
| 		 | ||||
| 		configurationTable.addMouseListener(new MouseAdapter() { | ||||
| 			@Override | ||||
| 			public void mouseClicked(MouseEvent e) { | ||||
| 				updateButtonState(); | ||||
| 				 | ||||
| 				if (e.getClickCount() == 2) { | ||||
| 					// FIXME:  Double-click on ignition column should select ignition | ||||
| 					// Double-click edits motor | ||||
| @ -142,7 +148,12 @@ public class MotorConfigurationPanel extends JPanel { | ||||
| 	} | ||||
| 	 | ||||
| 	public void fireTableDataChanged() { | ||||
| 		int selected = configurationTable.getSelectedRow(); | ||||
| 		configurationTableModel.fireTableDataChanged(); | ||||
| 		if (selected >= 0) { | ||||
| 			selected = Math.min(selected, configurationTable.getRowCount() - 1); | ||||
| 			configurationTable.getSelectionModel().setSelectionInterval(selected, selected); | ||||
| 		} | ||||
| 		updateButtonState(); | ||||
| 	} | ||||
| 	 | ||||
| @ -162,6 +173,11 @@ public class MotorConfigurationPanel extends JPanel { | ||||
| 			return null; | ||||
| 		} | ||||
| 		 | ||||
| 		return getMount(row); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	private MotorMount getMount(int row) { | ||||
| 		int count = 0; | ||||
| 		for (RocketComponent c : rocket) { | ||||
| 			if (c instanceof MotorMount) { | ||||
| @ -178,6 +194,8 @@ public class MotorConfigurationPanel extends JPanel { | ||||
| 		throw new IndexOutOfBoundsException("Invalid row, row=" + row + " count=" + count); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	 | ||||
| 	private void selectMotor() { | ||||
| 		String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); | ||||
| 		MotorMount mount = getCurrentMount(); | ||||
| @ -203,8 +221,7 @@ public class MotorConfigurationPanel extends JPanel { | ||||
| 		} | ||||
| 		 | ||||
| 		flightConfigurationDialog.fireContentsUpdated(); | ||||
| 		configurationTableModel.fireTableDataChanged(); | ||||
| 		updateButtonState(); | ||||
| 		fireTableDataChanged(); | ||||
| 	} | ||||
| 	 | ||||
| 	private void removeMotor() { | ||||
| @ -216,8 +233,7 @@ public class MotorConfigurationPanel extends JPanel { | ||||
| 		mount.getMotorConfiguration().resetDefault(id); | ||||
| 		 | ||||
| 		flightConfigurationDialog.fireContentsUpdated(); | ||||
| 		configurationTableModel.fireTableDataChanged(); | ||||
| 		updateButtonState(); | ||||
| 		fireTableDataChanged(); | ||||
| 	} | ||||
| 	 | ||||
| 	private void selectIgnition() { | ||||
| @ -233,8 +249,58 @@ public class MotorConfigurationPanel extends JPanel { | ||||
| 		dialog.setVisible(true); | ||||
| 		 | ||||
| 		flightConfigurationDialog.fireContentsUpdated(); | ||||
| 		configurationTableModel.fireTableDataChanged(); | ||||
| 		updateButtonState(); | ||||
| 		fireTableDataChanged(); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	private class MotorTableCellRenderer extends DefaultTableCellRenderer { | ||||
| 		 | ||||
| 		@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; | ||||
| 			 | ||||
| 			MotorMount mount = getMount(row); | ||||
| 			String id = rocket.getDefaultConfiguration().getFlightConfigurationID(); | ||||
| 			 | ||||
| 			switch (column) { | ||||
| 			case 0: | ||||
| 				regular(label); | ||||
| 				break; | ||||
| 			 | ||||
| 			case 1: | ||||
| 				if (mount.getMotorConfiguration().get(id).getMotor() != null) { | ||||
| 					regular(label); | ||||
| 				} else { | ||||
| 					shaded(label); | ||||
| 				} | ||||
| 				break; | ||||
| 			 | ||||
| 			case 2: | ||||
| 				if (mount.getIgnitionConfiguration().isDefault(id)) { | ||||
| 					shaded(label); | ||||
| 				} else { | ||||
| 					regular(label); | ||||
| 				} | ||||
| 				break; | ||||
| 			} | ||||
| 			 | ||||
| 			return label; | ||||
| 		} | ||||
| 		 | ||||
| 		private void shaded(JLabel label) { | ||||
| 			GUIUtil.changeFontStyle(label, Font.ITALIC); | ||||
| 			label.setForeground(Color.GRAY); | ||||
| 		} | ||||
| 		 | ||||
| 		private void regular(JLabel label) { | ||||
| 			GUIUtil.changeFontStyle(label, Font.PLAIN); | ||||
| 			label.setForeground(Color.BLACK); | ||||
| 		} | ||||
| 		 | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
|  | ||||
| @ -397,6 +397,19 @@ public class GUIUtil { | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Changes the style of the font of the specified label. | ||||
| 	 *  | ||||
| 	 * @param label			the component for which to change the font | ||||
| 	 * @param style			the change in the font style | ||||
| 	 */ | ||||
| 	public static void changeFontStyle(JLabel label, int style) { | ||||
| 		Font font = label.getFont(); | ||||
| 		font = font.deriveFont(style); | ||||
| 		label.setFont(font); | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	 | ||||
| 	/** | ||||
| 	 * Traverses recursively the component tree, and sets all applicable component  | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user