Align ribbon zoom label to zoom combobox

This commit is contained in:
SiboVG 2022-05-31 01:55:00 +02:00
parent ac57e0851d
commit 0ff3c739e2
3 changed files with 51 additions and 31 deletions

View File

@ -295,7 +295,7 @@ public class FreeformFinSetConfig extends FinSetConfig {
panel.add(new StyledLabel(trans.get("FreeformFinSetConfig.lbl.ctrlClick"), -2), "spanx 3, wrap"); panel.add(new StyledLabel(trans.get("FreeformFinSetConfig.lbl.ctrlClick"), -2), "spanx 3, wrap");
// row of controls at the bottom of the tab: // row of controls at the bottom of the tab:
panel.add(selector, "aligny bottom, gap unrel"); panel.add(selector.getAsPanel(), "aligny bottom, gap unrel");
panel.add(scaleButton, ""); panel.add(scaleButton, "");
panel.add(importButton, ""); panel.add(importButton, "");
panel.add(exportCsvButton, ""); panel.add(exportCsvButton, "");

View File

@ -325,14 +325,19 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
// Zoom level selector // Zoom level selector
scaleSelector = new ScaleSelector(scrollPane); scaleSelector = new ScaleSelector(scrollPane);
ribbon.add(new JLabel(trans.get("RocketPanel.lbl.Zoom")), "cell 1 0, center"); JButton zoomOutButton = scaleSelector.getZoomOutButton();
ribbon.add(scaleSelector, "gapleft para, cell 1 1"); JComboBox<String> scaleSelectorCombo = scaleSelector.getScaleSelectorCombo();
JButton zoomInButton = scaleSelector.getZoomInButton();
ribbon.add(zoomOutButton, "gapleft para, cell 1 1");
ribbon.add(new JLabel(trans.get("RocketPanel.lbl.Zoom")), "cell 2 0, spanx 2");
ribbon.add(scaleSelectorCombo, "cell 2 1");
ribbon.add(zoomInButton, "cell 3 1");
// Show CG/CP // Show CG/CP
JCheckBox showCGCP = new JCheckBox(); JCheckBox showCGCP = new JCheckBox();
showCGCP.setText(trans.get("RocketPanel.checkbox.ShowCGCP")); showCGCP.setText(trans.get("RocketPanel.checkbox.ShowCGCP"));
showCGCP.setSelected(true); showCGCP.setSelected(true);
ribbon.add(showCGCP, "cell 2 1, gapleft para"); ribbon.add(showCGCP, "cell 4 1, gapleft para");
showCGCP.addActionListener(new ActionListener() { showCGCP.addActionListener(new ActionListener() {
@Override @Override
@ -352,21 +357,21 @@ public class RocketPanel extends JPanel implements TreeSelectionListener, Change
Dimension d_sep = sep.getPreferredSize(); Dimension d_sep = sep.getPreferredSize();
d_sep.height = (int) (0.7 * ribbon.getPreferredSize().height); d_sep.height = (int) (0.7 * ribbon.getPreferredSize().height);
sep.setPreferredSize(d_sep); sep.setPreferredSize(d_sep);
ribbon.add(sep, "cell 3 0, spany 2, gapleft para, gapright para"); ribbon.add(sep, "cell 5 0, spany 2, gapleft para, gapright para");
// Stage selector // Stage selector
StageSelector stageSelector = new StageSelector( rkt ); StageSelector stageSelector = new StageSelector( rkt );
rkt.addChangeListener(stageSelector); rkt.addChangeListener(stageSelector);
ribbon.add(new JLabel(trans.get("RocketPanel.lbl.Stages")), "cell 4 0, pushx"); ribbon.add(new JLabel(trans.get("RocketPanel.lbl.Stages")), "cell 6 0, pushx");
ribbon.add(stageSelector, "cell 4 1, pushx"); ribbon.add(stageSelector, "cell 6 1, pushx");
// Flight configuration selector // Flight configuration selector
//// Flight configuration: //// Flight configuration:
JLabel label = new JLabel(trans.get("RocketPanel.lbl.Flightcfg")); JLabel label = new JLabel(trans.get("RocketPanel.lbl.Flightcfg"));
ribbon.add(label, "cell 5 0"); ribbon.add(label, "cell 7 0");
final ConfigurationComboBox configComboBox = new ConfigurationComboBox(rkt); final ConfigurationComboBox configComboBox = new ConfigurationComboBox(rkt);
ribbon.add(configComboBox, "cell 5 1, width 16%, wmin 100"); ribbon.add(configComboBox, "cell 7 1, width 16%, wmin 100");
add(ribbon, "growx, span, wrap"); add(ribbon, "growx, span, wrap");

View File

@ -17,7 +17,7 @@ import net.sf.openrocket.gui.widgets.SelectColorButton;
import net.sf.openrocket.util.StateChangeListener; import net.sf.openrocket.util.StateChangeListener;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ScaleSelector extends JPanel { public class ScaleSelector {
public static final double MINIMUM_ZOOM = 0.01; // == 1 % public static final double MINIMUM_ZOOM = 0.01; // == 1 %
public static final double MAXIMUM_ZOOM = 1000.00; // == 10,000 % public static final double MAXIMUM_ZOOM = 1000.00; // == 10,000 %
@ -36,16 +36,16 @@ public class ScaleSelector extends JPanel {
} }
private final ScaleScrollPane scrollPane; private final ScaleScrollPane scrollPane;
private final JComboBox<String> scaleSelector; private final JComboBox<String> scaleSelectorCombo;
private final JButton zoomOutButton;
private final JButton zoomInButton;
public ScaleSelector(ScaleScrollPane scroll) { public ScaleSelector(ScaleScrollPane scroll) {
super(new MigLayout("insets 0"));
this.scrollPane = scroll; this.scrollPane = scroll;
// Zoom out button // Zoom out button
JButton button = new SelectColorButton(Icons.ZOOM_OUT); zoomOutButton = new SelectColorButton(Icons.ZOOM_OUT);
button.addActionListener(new ActionListener() { zoomOutButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
final double oldScale = scrollPane.getUserScale(); final double oldScale = scrollPane.getUserScale();
@ -54,17 +54,16 @@ public class ScaleSelector extends JPanel {
setZoomText(); setZoomText();
} }
}); });
add(button);
// Zoom level selector // Zoom level selector
scaleSelector = new JComboBox<>(SCALE_LABELS); scaleSelectorCombo = new JComboBox<>(SCALE_LABELS);
scaleSelector.setEditable(true); scaleSelectorCombo.setEditable(true);
setZoomText(); setZoomText();
scaleSelector.addActionListener(new ActionListener() { scaleSelectorCombo.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
String text = (String) scaleSelector.getSelectedItem(); String text = (String) scaleSelectorCombo.getSelectedItem();
if (text == null) return; if (text == null) return;
text = text.replaceAll("%", "").trim(); text = text.replaceAll("%", "").trim();
@ -93,11 +92,10 @@ public class ScaleSelector extends JPanel {
update(); update();
} }
}); });
add(scaleSelector);
// Zoom in button // Zoom in button
button = new SelectColorButton(Icons.ZOOM_IN); zoomInButton = new SelectColorButton(Icons.ZOOM_IN);
button.addActionListener(new ActionListener() { zoomInButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
double scale = scrollPane.getUserScale(); double scale = scrollPane.getUserScale();
@ -106,8 +104,27 @@ public class ScaleSelector extends JPanel {
update(); update();
} }
}); });
add(button); }
public JPanel getAsPanel() {
JPanel panel = new JPanel(new MigLayout("insets 0"));
panel.add(zoomOutButton);
panel.add(scaleSelectorCombo);
panel.add(zoomInButton);
return panel;
}
public JComboBox<String> getScaleSelectorCombo() {
return scaleSelectorCombo;
}
public JButton getZoomOutButton() {
return zoomOutButton;
}
public JButton getZoomInButton() {
return zoomInButton;
} }
private void setZoomText() { private void setZoomText() {
@ -116,8 +133,8 @@ public class ScaleSelector extends JPanel {
if (scrollPane.isFitting()) { if (scrollPane.isFitting()) {
text = "Fit (" + text + ")"; text = "Fit (" + text + ")";
} }
if (!text.equals(scaleSelector.getSelectedItem())) if (!text.equals(scaleSelectorCombo.getSelectedItem()))
scaleSelector.setSelectedItem(text); scaleSelectorCombo.setSelectedItem(text);
} }
private static double getNextLargerScale(final double currentScale) { private static double getNextLargerScale(final double currentScale) {
@ -148,12 +165,10 @@ public class ScaleSelector extends JPanel {
return currentScale * 1.5; return currentScale * 1.5;
} }
@Override
public void setEnabled(boolean b){ public void setEnabled(boolean b){
for ( Component c : getComponents() ){ zoomInButton.setEnabled(b);
c.setEnabled(b); scaleSelectorCombo.setEnabled(b);
} zoomOutButton.setEnabled(b);
super.setEnabled(b);
} }
public void update(){ public void update(){