Extend multi-select components to different-typed components
This commit is contained in:
parent
1c129e64a1
commit
ddbcf597c2
@ -947,7 +947,10 @@ CenteringRingCfg.tab.Generalproperties = General properties
|
|||||||
|
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = configuration
|
ComponentCfgDlg.configuration = configuration
|
||||||
ComponentCfgDlg.configuration1 =
|
ComponentCfgDlg.MultiComponent = Multi-component
|
||||||
|
ComponentCfgDlg.MultiComponentConfig = Multi-component configuration
|
||||||
|
ComponentCfgDlg.MultiComponentEdit = Multi-component edit
|
||||||
|
ComponentCfgDlg.MultiComponentEdit.ttip = <html>You are editing the following components:<br>
|
||||||
ComponentCfgDlg.Modify = Modify
|
ComponentCfgDlg.Modify = Modify
|
||||||
|
|
||||||
!StageConfig
|
!StageConfig
|
||||||
|
@ -678,7 +678,6 @@ CenteringRingCfg.tab.Generalproperties = Obecn
|
|||||||
|
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = konfigurace
|
ComponentCfgDlg.configuration = konfigurace
|
||||||
ComponentCfgDlg.configuration1 =
|
|
||||||
ComponentCfgDlg.Modify = Uprav
|
ComponentCfgDlg.Modify = Uprav
|
||||||
|
|
||||||
!StageConfig
|
!StageConfig
|
||||||
|
@ -734,7 +734,6 @@ CenteringRingCfg.tab.Generalproperties = Allgemeine Eigenschaften
|
|||||||
|
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = Konfiguration
|
ComponentCfgDlg.configuration = Konfiguration
|
||||||
ComponentCfgDlg.configuration1 =
|
|
||||||
ComponentCfgDlg.Modify = Verändern
|
ComponentCfgDlg.Modify = Verändern
|
||||||
|
|
||||||
!StageConfig
|
!StageConfig
|
||||||
|
@ -130,8 +130,7 @@ CompassSelectionButton.lbl.W = O
|
|||||||
|
|
||||||
ComponentCfgDlg.Modify = Modificar
|
ComponentCfgDlg.Modify = Modificar
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration =
|
ComponentCfgDlg.configuration = Configuraci\u00f3n
|
||||||
ComponentCfgDlg.configuration1 = Configuraci\u00f3n
|
|
||||||
|
|
||||||
ComponentIcons.Bodytube = Cuerpo tubular
|
ComponentIcons.Bodytube = Cuerpo tubular
|
||||||
ComponentIcons.Bulkhead = Disco de enganche
|
ComponentIcons.Bulkhead = Disco de enganche
|
||||||
|
@ -121,7 +121,6 @@ CompassSelectionButton.lbl.W = O
|
|||||||
ComponentCfgDlg.Modify = Modifier
|
ComponentCfgDlg.Modify = Modifier
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = configuration
|
ComponentCfgDlg.configuration = configuration
|
||||||
ComponentCfgDlg.configuration1 = configuration
|
|
||||||
|
|
||||||
ComponentIcons.Bodytube = Tube
|
ComponentIcons.Bodytube = Tube
|
||||||
ComponentIcons.Bulkhead = Cloison
|
ComponentIcons.Bulkhead = Cloison
|
||||||
|
@ -736,7 +736,6 @@ CenteringRingCfg.tab.Generalproperties = Proprieta' generali
|
|||||||
|
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = (configurazione)
|
ComponentCfgDlg.configuration = (configurazione)
|
||||||
ComponentCfgDlg.configuration1 =
|
|
||||||
ComponentCfgDlg.Modify = Modifica
|
ComponentCfgDlg.Modify = Modifica
|
||||||
|
|
||||||
!StageConfig
|
!StageConfig
|
||||||
|
@ -766,7 +766,6 @@ CenteringRingCfg.tab.Generalproperties = \u4E00\u822C
|
|||||||
|
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = \u30B3\u30F3\u30D5\u30A3\u30AE\u30E5\u30EC\u30FC\u30B7\u30E7\u30F3
|
ComponentCfgDlg.configuration = \u30B3\u30F3\u30D5\u30A3\u30AE\u30E5\u30EC\u30FC\u30B7\u30E7\u30F3
|
||||||
ComponentCfgDlg.configuration1 =
|
|
||||||
ComponentCfgDlg.Modify = \u5909\u66F4
|
ComponentCfgDlg.Modify = \u5909\u66F4
|
||||||
|
|
||||||
!StageConfig
|
!StageConfig
|
||||||
|
@ -889,7 +889,6 @@ CenteringRingCfg.tab.Generalproperties = Algemene eigenschappen
|
|||||||
|
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = configuratie
|
ComponentCfgDlg.configuration = configuratie
|
||||||
ComponentCfgDlg.configuration1 =
|
|
||||||
ComponentCfgDlg.Modify = Wijzigen
|
ComponentCfgDlg.Modify = Wijzigen
|
||||||
|
|
||||||
!StageConfig
|
!StageConfig
|
||||||
|
@ -680,7 +680,6 @@ update.dlg.latestVersion = Korzystasz z najnowszej wersji OpenRocket: %s.
|
|||||||
|
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = konfiguracja
|
ComponentCfgDlg.configuration = konfiguracja
|
||||||
ComponentCfgDlg.configuration1 =
|
|
||||||
ComponentCfgDlg.Modify = Zmodyfikuj
|
ComponentCfgDlg.Modify = Zmodyfikuj
|
||||||
|
|
||||||
!StageConfig
|
!StageConfig
|
||||||
|
@ -949,7 +949,6 @@ CenteringRingCfg.tab.Generalproperties = \u041E\u0441\u043D\u043E\u0432\u043D\u0
|
|||||||
|
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B
|
ComponentCfgDlg.configuration = \u043F\u0430\u0440\u0430\u043C\u0435\u0442\u0440\u044B
|
||||||
ComponentCfgDlg.configuration1 =
|
|
||||||
ComponentCfgDlg.Modify = \u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C
|
ComponentCfgDlg.Modify = \u0418\u0437\u043C\u0435\u043D\u0438\u0442\u044C
|
||||||
|
|
||||||
!StageConfig
|
!StageConfig
|
||||||
|
@ -838,7 +838,6 @@ CenteringRingCfg.tab.Generalproperties = General properties
|
|||||||
|
|
||||||
!ComponentConfigDialog
|
!ComponentConfigDialog
|
||||||
ComponentCfgDlg.configuration = configuration
|
ComponentCfgDlg.configuration = configuration
|
||||||
ComponentCfgDlg.configuration1 =
|
|
||||||
ComponentCfgDlg.Modify = Modify
|
ComponentCfgDlg.Modify = Modify
|
||||||
|
|
||||||
!StageConfig
|
!StageConfig
|
||||||
|
@ -1671,6 +1671,24 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether all components in the list have the same class as this component.
|
||||||
|
* @param components list to check
|
||||||
|
* @return true if all components are of the same class, false if not
|
||||||
|
*/
|
||||||
|
public boolean checkAllClassesEqual(List<RocketComponent> components) {
|
||||||
|
if (components == null || components.size() == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Class<? extends RocketComponent> myClass = this.getClass();
|
||||||
|
for (RocketComponent c : components) {
|
||||||
|
if (!c.getClass().equals(myClass)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the root component of the component tree.
|
* Get the root component of the component tree.
|
||||||
@ -1970,7 +1988,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
|
|||||||
* @return true if listener was successfully added, false if not
|
* @return true if listener was successfully added, false if not
|
||||||
*/
|
*/
|
||||||
public boolean addConfigListener(RocketComponent listener) {
|
public boolean addConfigListener(RocketComponent listener) {
|
||||||
if (listener == null || !this.getClass().equals(listener.getClass())) {
|
if (listener == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
configListeners.add(listener);
|
configListeners.add(listener);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.sf.openrocket.gui.components;
|
package net.sf.openrocket.gui.components;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@ -87,11 +88,9 @@ public class StyledLabel extends JLabel {
|
|||||||
|
|
||||||
private void checkPreferredSize(float size, Style style) {
|
private void checkPreferredSize(float size, Style style) {
|
||||||
String str = this.getText();
|
String str = this.getText();
|
||||||
if (str.startsWith("<html>") && str.indexOf("<br") < 0) {
|
if (str.startsWith("<html>") && !str.contains("<br")) {
|
||||||
StyledLabel label = new StyledLabel("plaintext", size, style);
|
StyledLabel label = new StyledLabel("plaintext", size, style);
|
||||||
label.validate();
|
label.validate();
|
||||||
//System.out.println("Plain-text label: " + label.getPreferredSize());
|
|
||||||
//System.out.println("HTML label: " + this.getPreferredSize());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,4 +107,8 @@ public class StyledLabel extends JLabel {
|
|||||||
font = font.deriveFont(style.getFontStyle());
|
font = font.deriveFont(style.getFontStyle());
|
||||||
this.setFont(font);
|
this.setFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFontColor(Color color) {
|
||||||
|
this.setForeground(color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,14 +37,15 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
|
|||||||
private static ComponentConfigDialog dialog = null;
|
private static ComponentConfigDialog dialog = null;
|
||||||
|
|
||||||
private OpenRocketDocument document = null;
|
private OpenRocketDocument document = null;
|
||||||
private RocketComponent component = null;
|
protected static RocketComponent component = null;
|
||||||
private RocketComponentConfig configurator = null;
|
private RocketComponentConfig configurator = null;
|
||||||
|
|
||||||
|
protected static boolean clearConfigListeners = true;
|
||||||
|
|
||||||
private final Window parent;
|
private final Window parent;
|
||||||
private static final Translator trans = Application.getTranslator();
|
private static final Translator trans = Application.getTranslator();
|
||||||
|
|
||||||
private ComponentConfigDialog(Window parent, OpenRocketDocument document, RocketComponent component,
|
private ComponentConfigDialog(Window parent, OpenRocketDocument document, RocketComponent component) {
|
||||||
List<RocketComponent> listeners) {
|
|
||||||
super(parent);
|
super(parent);
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
|
|
||||||
@ -63,21 +64,15 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
|
|||||||
configurator.invalidate();
|
configurator.invalidate();
|
||||||
document.getRocket().removeComponentChangeListener(ComponentConfigDialog.this);
|
document.getRocket().removeComponentChangeListener(ComponentConfigDialog.this);
|
||||||
ComponentConfigDialog.this.dispose();
|
ComponentConfigDialog.this.dispose();
|
||||||
component.clearConfigListeners();
|
if (clearConfigListeners) {
|
||||||
|
component.clearConfigListeners();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void windowClosing(WindowEvent e){}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void windowOpened(WindowEvent e) {
|
public void windowOpened(WindowEvent e) {
|
||||||
super.windowOpened(e);
|
super.windowOpened(e);
|
||||||
// Add config listeners
|
clearConfigListeners = true;
|
||||||
component.clearConfigListeners();
|
|
||||||
if (listeners != null) {
|
|
||||||
for (RocketComponent listener : listeners) {
|
|
||||||
component.addConfigListener(listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -104,7 +99,17 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
|
|||||||
configurator.updateFields();
|
configurator.updateFields();
|
||||||
|
|
||||||
//// configuration
|
//// configuration
|
||||||
setTitle(trans.get("ComponentCfgDlg.configuration1") + " " + component.getComponentName() + " " + trans.get("ComponentCfgDlg.configuration"));
|
List<RocketComponent> listeners = component.getConfigListeners();
|
||||||
|
if (component.checkAllClassesEqual(listeners)) {
|
||||||
|
if (listeners != null && listeners.size() > 0) {
|
||||||
|
setTitle("(" + trans.get("ComponentCfgDlg.MultiComponent") + ") " +
|
||||||
|
component.getComponentName() + " " + trans.get("ComponentCfgDlg.configuration"));
|
||||||
|
} else {
|
||||||
|
setTitle(component.getComponentName() + " " + trans.get("ComponentCfgDlg.configuration"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setTitle(trans.get("ComponentCfgDlg.MultiComponentConfig"));
|
||||||
|
}
|
||||||
|
|
||||||
this.pack();
|
this.pack();
|
||||||
}
|
}
|
||||||
@ -118,14 +123,18 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
|
|||||||
* Return the configurator panel of the current component.
|
* Return the configurator panel of the current component.
|
||||||
*/
|
*/
|
||||||
private RocketComponentConfig getDialogContents() {
|
private RocketComponentConfig getDialogContents() {
|
||||||
Constructor<? extends RocketComponentConfig> c =
|
List<RocketComponent> listeners = component.getConfigListeners();
|
||||||
|
boolean isSameClass = component.checkAllClassesEqual(listeners);
|
||||||
|
if (!isSameClass) {
|
||||||
|
return new RocketComponentConfig(document, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
Constructor<? extends RocketComponentConfig> constructor =
|
||||||
findDialogContentsConstructor(component);
|
findDialogContentsConstructor(component);
|
||||||
if (c != null) {
|
if (constructor != null) {
|
||||||
try {
|
try {
|
||||||
return c.newInstance(document, component);
|
return constructor.newInstance(document, component);
|
||||||
} catch (InstantiationException e) {
|
} catch (InstantiationException | IllegalAccessException e) {
|
||||||
throw new BugException("BUG in constructor reflection", e);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
throw new BugException("BUG in constructor reflection", e);
|
throw new BugException("BUG in constructor reflection", e);
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
throw Reflection.handleWrappedException(e);
|
throw Reflection.handleWrappedException(e);
|
||||||
@ -196,48 +205,35 @@ public class ComponentConfigDialog extends JDialog implements ComponentChangeLis
|
|||||||
|
|
||||||
|
|
||||||
////////// Static dialog /////////
|
////////// Static dialog /////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A singleton configuration dialog. Will create and show a new dialog if one has not
|
* A singleton configuration dialog. Will create and show a new dialog if one has not
|
||||||
* previously been used, or update the dialog and show it if a previous one exists.
|
* previously been used, or update the dialog and show it if a previous one exists.
|
||||||
*
|
*
|
||||||
* @param document the document to configure.
|
* @param document the document to configure.
|
||||||
* @param component the component to configure.
|
* @param component the component to configure.
|
||||||
* @param listeners config listeners for the component
|
|
||||||
*/
|
*/
|
||||||
public static void showDialog(Window parent, OpenRocketDocument document,
|
public static void showDialog(Window parent, OpenRocketDocument document,
|
||||||
RocketComponent component, List<RocketComponent> listeners) {
|
RocketComponent component) {
|
||||||
if (dialog != null)
|
if (dialog != null) {
|
||||||
|
// If the component is the same as the ComponentConfigDialog component, and the dialog is still visible,
|
||||||
|
// that means that the user did a ctr/cmd click on a new component => don't remove the config listeners of component
|
||||||
|
if (component.equals(ComponentConfigDialog.component)) {
|
||||||
|
ComponentConfigDialog.clearConfigListeners = false;
|
||||||
|
}
|
||||||
dialog.dispose();
|
dialog.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
dialog = new ComponentConfigDialog(parent, document, component, listeners);
|
dialog = new ComponentConfigDialog(parent, document, component);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
|
|
||||||
////Modify
|
////Modify
|
||||||
document.addUndoPosition(trans.get("ComponentCfgDlg.Modify") + " " + component.getComponentName());
|
document.addUndoPosition(trans.get("ComponentCfgDlg.Modify") + " " + component.getComponentName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* A singleton configuration dialog. Will create and show a new dialog if one has not
|
|
||||||
* previously been used, or update the dialog and show it if a previous one exists.
|
|
||||||
*
|
|
||||||
* @param document the document to configure.
|
|
||||||
* @param component the component to configure.
|
|
||||||
*/
|
|
||||||
public static void showDialog(Window parent, OpenRocketDocument document,
|
|
||||||
RocketComponent component) {
|
|
||||||
ComponentConfigDialog.showDialog(parent, document, component, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* package */
|
|
||||||
static void showDialog(RocketComponent component, List<RocketComponent> listeners) {
|
|
||||||
showDialog(dialog.parent, dialog.document, component, listeners);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* package */
|
/* package */
|
||||||
static void showDialog(RocketComponent component) {
|
static void showDialog(RocketComponent component) {
|
||||||
ComponentConfigDialog.showDialog(component, null);
|
ComponentConfigDialog.showDialog(dialog.parent, dialog.document, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,17 +82,10 @@ public abstract class FinSetConfig extends RocketComponentConfig {
|
|||||||
//// Convert fin set
|
//// Convert fin set
|
||||||
document.addUndoPosition(trans.get("FinSetConfig.Convertfinset"));
|
document.addUndoPosition(trans.get("FinSetConfig.Convertfinset"));
|
||||||
|
|
||||||
List<RocketComponent> listeners = new ArrayList<>();
|
|
||||||
for (RocketComponent listener : component.getConfigListeners()) {
|
|
||||||
if (listener instanceof FinSet) {
|
|
||||||
listeners.add(FreeformFinSet.convertFinSet((FinSet) listener));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RocketComponent freeform =
|
RocketComponent freeform =
|
||||||
FreeformFinSet.convertFinSet((FinSet) component);
|
FreeformFinSet.convertFinSet((FinSet) component);
|
||||||
|
|
||||||
ComponentConfigDialog.showDialog(freeform, listeners);
|
ComponentConfigDialog.showDialog(freeform);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.sf.openrocket.gui.configdialog;
|
package net.sf.openrocket.gui.configdialog;
|
||||||
|
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Container;
|
import java.awt.Container;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
@ -39,7 +40,6 @@ import net.sf.openrocket.gui.widgets.SelectColorButton;
|
|||||||
import net.sf.openrocket.l10n.Translator;
|
import net.sf.openrocket.l10n.Translator;
|
||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
import net.sf.openrocket.preset.ComponentPreset;
|
import net.sf.openrocket.preset.ComponentPreset;
|
||||||
import net.sf.openrocket.rocketcomponent.ComponentAssembly;
|
|
||||||
import net.sf.openrocket.rocketcomponent.*;
|
import net.sf.openrocket.rocketcomponent.*;
|
||||||
import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
|
import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
|
||||||
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
|
import net.sf.openrocket.rocketcomponent.position.AxialMethod;
|
||||||
@ -68,20 +68,39 @@ public class RocketComponentConfig extends JPanel {
|
|||||||
private JPanel buttonPanel;
|
private JPanel buttonPanel;
|
||||||
|
|
||||||
private JLabel infoLabel;
|
private JLabel infoLabel;
|
||||||
|
private StyledLabel multiCompEditLabel;
|
||||||
|
|
||||||
|
private boolean allSameType; // Checks whether all listener components are of the same type as <component>
|
||||||
|
private boolean allMassive; // Checks whether all listener components, and this component, are massive
|
||||||
|
|
||||||
public RocketComponentConfig(OpenRocketDocument document, RocketComponent component) {
|
public RocketComponentConfig(OpenRocketDocument document, RocketComponent component) {
|
||||||
setLayout(new MigLayout("fill, gap 4!, ins panel", "[]:5[]", "[growprio 5]5![fill, grow, growprio 500]5![growprio 5]"));
|
setLayout(new MigLayout("fill, gap 4!, ins panel", "[]:5[]", "[growprio 5]5![fill, grow, growprio 500]5![growprio 5]"));
|
||||||
|
|
||||||
this.document = document;
|
this.document = document;
|
||||||
this.component = component;
|
this.component = component;
|
||||||
|
|
||||||
|
// Check the listeners for the same type and massive status
|
||||||
|
allSameType = true;
|
||||||
|
allMassive = component.isMassive();
|
||||||
|
List<RocketComponent> listeners = component.getConfigListeners();
|
||||||
|
if (listeners != null && listeners.size() > 0) {
|
||||||
|
allSameType = component.checkAllClassesEqual(listeners);
|
||||||
|
if (allMassive) { // Only check if <component> is already massive
|
||||||
|
for (RocketComponent listener : listeners) {
|
||||||
|
if (!listener.isMassive()) {
|
||||||
|
allMassive = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//// Component name:
|
//// Component name:
|
||||||
JLabel label = new JLabel(trans.get("RocketCompCfg.lbl.Componentname"));
|
JLabel label = new JLabel(trans.get("RocketCompCfg.lbl.Componentname"));
|
||||||
//// The component name.
|
//// The component name.
|
||||||
label.setToolTipText(trans.get("RocketCompCfg.ttip.Thecomponentname"));
|
label.setToolTipText(trans.get("RocketCompCfg.ttip.Thecomponentname"));
|
||||||
this.add(label, "spanx, height 32!, split");
|
this.add(label, "spanx, height 32!, split");
|
||||||
|
|
||||||
componentNameField = new JTextField(15);
|
componentNameField = new JTextField(15);
|
||||||
textFieldListener = new TextFieldListener();
|
textFieldListener = new TextFieldListener();
|
||||||
componentNameField.addActionListener(textFieldListener);
|
componentNameField.addActionListener(textFieldListener);
|
||||||
@ -89,34 +108,38 @@ public class RocketComponentConfig extends JPanel {
|
|||||||
//// The component name.
|
//// The component name.
|
||||||
componentNameField.setToolTipText(trans.get("RocketCompCfg.ttip.Thecomponentname"));
|
componentNameField.setToolTipText(trans.get("RocketCompCfg.ttip.Thecomponentname"));
|
||||||
this.add(componentNameField, "growx");
|
this.add(componentNameField, "growx");
|
||||||
|
|
||||||
if (component.getPresetType() != null) {
|
if (allSameType && component.getPresetType() != null) {
|
||||||
// If the component supports a preset, show the preset selection box.
|
// If the component supports a preset, show the preset selection box.
|
||||||
presetModel = new PresetModel(this, document, component);
|
presetModel = new PresetModel(this, document, component);
|
||||||
presetComboBox = new JComboBox(presetModel);
|
presetComboBox = new JComboBox(presetModel);
|
||||||
presetComboBox.setEditable(false);
|
presetComboBox.setEditable(false);
|
||||||
this.add(presetComboBox, "");
|
this.add(presetComboBox, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
tabbedPane = new JTabbedPane();
|
tabbedPane = new JTabbedPane();
|
||||||
this.add(tabbedPane, "newline, span, growx, growy 100, wrap");
|
this.add(tabbedPane, "newline, span, growx, growy 100, wrap");
|
||||||
|
|
||||||
//// Override and Mass and CG override options
|
//// Override and Mass and CG override options
|
||||||
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Override"), null, overrideTab(),
|
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Override"), null, overrideTab(),
|
||||||
trans.get("RocketCompCfg.tab.MassandCGoverride"));
|
trans.get("RocketCompCfg.tab.MassandCGoverride"));
|
||||||
if (component.isMassive()) {
|
if (allMassive) {
|
||||||
//// Appearance options
|
//// Appearance options
|
||||||
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Appearance"), null, new AppearancePanel(document, component),
|
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Appearance"), null, new AppearancePanel(document, component),
|
||||||
"Appearance Tool Tip");
|
"Appearance Tool Tip");
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Comment and Specify a comment for the component
|
//// Comment and Specify a comment for the component
|
||||||
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Comment"), null, commentTab(),
|
tabbedPane.addTab(trans.get("RocketCompCfg.tab.Comment"), null, commentTab(),
|
||||||
trans.get("RocketCompCfg.tab.Specifyacomment"));
|
trans.get("RocketCompCfg.tab.Specifyacomment"));
|
||||||
|
|
||||||
|
// Set the default tab to 'Appearance' for a different-type multi-comp dialog (this is the most prominent use case)
|
||||||
|
if (listeners != null && listeners.size() > 0 && !allSameType) {
|
||||||
|
tabbedPane.setSelectedIndex(1);
|
||||||
|
}
|
||||||
|
|
||||||
addButtons();
|
addButtons();
|
||||||
|
|
||||||
updateFields();
|
updateFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,6 +151,12 @@ public class RocketComponentConfig extends JPanel {
|
|||||||
|
|
||||||
buttonPanel = new JPanel(new MigLayout("fillx, ins 5"));
|
buttonPanel = new JPanel(new MigLayout("fillx, ins 5"));
|
||||||
|
|
||||||
|
//// Multi-comp edit label
|
||||||
|
multiCompEditLabel = new StyledLabel(" ", 0, Style.BOLD);
|
||||||
|
//multiCompEditLabel.setFontColor(new Color(0, 0, 239));
|
||||||
|
multiCompEditLabel.setFontColor(new Color(170, 0, 100));
|
||||||
|
buttonPanel.add(multiCompEditLabel, "split 2");
|
||||||
|
|
||||||
//// Mass:
|
//// Mass:
|
||||||
infoLabel = new StyledLabel(" ", -1);
|
infoLabel = new StyledLabel(" ", -1);
|
||||||
buttonPanel.add(infoLabel, "growx");
|
buttonPanel.add(infoLabel, "growx");
|
||||||
@ -159,16 +188,17 @@ public class RocketComponentConfig extends JPanel {
|
|||||||
public void updateFields() {
|
public void updateFields() {
|
||||||
// Component name
|
// Component name
|
||||||
componentNameField.setText(component.getName());
|
componentNameField.setText(component.getName());
|
||||||
|
|
||||||
// Info label
|
// Info label
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
if (component.getPresetComponent() != null) {
|
if (allSameType && component.getPresetComponent() != null) {
|
||||||
ComponentPreset preset = component.getPresetComponent();
|
ComponentPreset preset = component.getPresetComponent();
|
||||||
sb.append(preset.getManufacturer() + " " + preset.getPartNo() + " ");
|
sb.append(preset.getManufacturer() + " " + preset.getPartNo() + " ");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (component.isMassive()) {
|
List<RocketComponent> listeners = component.getConfigListeners();
|
||||||
|
if (allMassive && (listeners == null || listeners.size() == 0)) { // TODO: support aggregate mass display for current component and listeners?
|
||||||
sb.append(trans.get("RocketCompCfg.lbl.Componentmass") + " ");
|
sb.append(trans.get("RocketCompCfg.lbl.Componentmass") + " ");
|
||||||
sb.append(UnitGroup.UNITS_MASS.getDefaultUnit().toStringUnit(
|
sb.append(UnitGroup.UNITS_MASS.getDefaultUnit().toStringUnit(
|
||||||
component.getComponentMass()));
|
component.getComponentMass()));
|
||||||
@ -193,6 +223,24 @@ public class RocketComponentConfig extends JPanel {
|
|||||||
} else {
|
} else {
|
||||||
infoLabel.setText("");
|
infoLabel.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Multi-comp edit label
|
||||||
|
if (listeners != null && listeners.size() > 0) {
|
||||||
|
multiCompEditLabel.setText(trans.get("ComponentCfgDlg.MultiComponentEdit"));
|
||||||
|
|
||||||
|
StringBuilder components = new StringBuilder(trans.get("ComponentCfgDlg.MultiComponentEdit.ttip"));
|
||||||
|
components.append(component.getName()).append(", ");
|
||||||
|
for (int i = 0; i < listeners.size(); i++) {
|
||||||
|
if (i < listeners.size() - 1) {
|
||||||
|
components.append(listeners.get(i).getName()).append(", ");
|
||||||
|
} else {
|
||||||
|
components.append(listeners.get(i).getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
multiCompEditLabel.setToolTipText(components.toString());
|
||||||
|
} else {
|
||||||
|
multiCompEditLabel.setText("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -333,16 +333,16 @@ public class BasicFrame extends JFrame {
|
|||||||
|
|
||||||
if (!ComponentConfigDialog.isDialogVisible())
|
if (!ComponentConfigDialog.isDialogVisible())
|
||||||
return;
|
return;
|
||||||
|
else
|
||||||
|
ComponentConfigDialog.disposeDialog();
|
||||||
|
|
||||||
RocketComponent c = (RocketComponent) paths[0].getLastPathComponent();
|
RocketComponent c = (RocketComponent) paths[0].getLastPathComponent();
|
||||||
List<RocketComponent> listeners = new ArrayList<>();
|
c.clearConfigListeners();
|
||||||
for (int i = 1; i < paths.length; i++) {
|
for (int i = 1; i < paths.length; i++) {
|
||||||
RocketComponent listener = (RocketComponent) paths[i].getLastPathComponent();
|
RocketComponent listener = (RocketComponent) paths[i].getLastPathComponent();
|
||||||
if (listener.getClass().equals(c.getClass())) {
|
c.addConfigListener(listener);
|
||||||
listeners.add((RocketComponent) paths[i].getLastPathComponent());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ComponentConfigDialog.showDialog(BasicFrame.this,
|
ComponentConfigDialog.showDialog(BasicFrame.this, BasicFrame.this.document, c);
|
||||||
BasicFrame.this.document, c, listeners);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1323,7 +1323,6 @@ public class BasicFrame extends JFrame {
|
|||||||
*
|
*
|
||||||
* @param worker the OpenFileWorker that loads the file.
|
* @param worker the OpenFileWorker that loads the file.
|
||||||
* @param displayName the file name to display in dialogs.
|
* @param displayName the file name to display in dialogs.
|
||||||
* @param file the File to set the document to (may be null).
|
|
||||||
* @param parent
|
* @param parent
|
||||||
* @param openRocketConfigDialog if true, will open the configuration dialog of the rocket. This is useful for examples.
|
* @param openRocketConfigDialog if true, will open the configuration dialog of the rocket. This is useful for examples.
|
||||||
* @return
|
* @return
|
||||||
|
@ -5,7 +5,6 @@ import java.awt.Toolkit;
|
|||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -879,16 +878,17 @@ public class RocketActions {
|
|||||||
List<RocketComponent> components = selectionModel.getSelectedComponents();
|
List<RocketComponent> components = selectionModel.getSelectedComponents();
|
||||||
Simulation[] sims = selectionModel.getSelectedSimulations();
|
Simulation[] sims = selectionModel.getSelectedSimulations();
|
||||||
|
|
||||||
if ((components != null) && (components.size() > 0) && checkAllClassesEqual(components)) {
|
if ((components != null) && (components.size() > 0)) {
|
||||||
// Do nothing if the config dialog is already visible
|
|
||||||
if (ComponentConfigDialog.isDialogVisible())
|
if (ComponentConfigDialog.isDialogVisible())
|
||||||
return;
|
ComponentConfigDialog.disposeDialog();
|
||||||
|
|
||||||
List<RocketComponent> listeners = null;
|
RocketComponent component = components.get(0);
|
||||||
if (components.size() > 1) {
|
if (components.size() > 1) {
|
||||||
listeners = components.subList(1, components.size());
|
for (int i = 1; i < components.size(); i++) {
|
||||||
|
component.addConfigListener(components.get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ComponentConfigDialog.showDialog(parentFrame, document, components.get(0), listeners);
|
ComponentConfigDialog.showDialog(parentFrame, document, component);
|
||||||
} else if (sims != null && sims.length > 0 && (simulationPanel != null)) {
|
} else if (sims != null && sims.length > 0 && (simulationPanel != null)) {
|
||||||
simulationPanel.editSimulation();
|
simulationPanel.editSimulation();
|
||||||
}
|
}
|
||||||
@ -898,25 +898,7 @@ public class RocketActions {
|
|||||||
public void clipboardChanged() {
|
public void clipboardChanged() {
|
||||||
List<RocketComponent> components = selectionModel.getSelectedComponents();
|
List<RocketComponent> components = selectionModel.getSelectedComponents();
|
||||||
|
|
||||||
this.setEnabled(checkAllClassesEqual(components) || isSimulationSelected());
|
this.setEnabled((components != null && components.size() > 0) || isSimulationSelected());
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether all components in the list have the same class
|
|
||||||
* @param components list to check
|
|
||||||
* @return true if all components are of the same class, false if not
|
|
||||||
*/
|
|
||||||
private boolean checkAllClassesEqual(List<RocketComponent> components) {
|
|
||||||
if (components == null || components.size() == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Class<? extends RocketComponent> myClass = components.get(0).getClass();
|
|
||||||
for (int i = 1; i < components.size(); i++) {
|
|
||||||
if (!components.get(i).getClass().equals(myClass)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user