Skip to content

Commit

Permalink
fix SML edit pane resizing, scroll center, label alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
silverailscolo committed Oct 28, 2018
1 parent 31ea425 commit d3bc8f7
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 37 deletions.
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/signalling/SignallingBundle.properties
Expand Up @@ -40,7 +40,7 @@ ColumnAspect = Aspect
ButtonDiscover = Discover

LabelSelectChecked = <html>Select {0}<br>to be checked:</html>
LabelAutogenerated = <html>These {0} are<br>auto generated<br>and can't be<br>changed:</html>
LabelAutogenerated = <html>These {0} are<br>auto generated<br>and can''t be<br>changed:</html>
SourceMast = Source Mast
DestMast = Destination Mast

Expand Down
14 changes: 9 additions & 5 deletions java/src/jmri/jmrit/signalling/SignallingFrame.java
Expand Up @@ -2,13 +2,16 @@

import javax.swing.BoxLayout;
import javax.swing.JButton;
import jmri.SignalMast;
import jmri.util.JmriJFrame;

/**
* Provide a JFrame to display a table of Signal Mast Logic.
* Provide a JFrame to display a pane to edit the Signal Mast Logic for one Signal Mast.
*
* @author Kevin Dickerson Copyright (C) 2011
* @author Egbert Broerse 2018
*/
public class SignallingFrame extends jmri.util.JmriJFrame {
public class SignallingFrame extends JmriJFrame {

public SignallingFrame() {
super(false, true);
Expand All @@ -21,16 +24,17 @@ public SignallingFrame() {
* Set the Signal Mast Logic frame's initial state.
*
* @param source The Signal Mast this SML is directly linked to
* @param dest The Signal Mast this SML is looking at
* @param dest The Signal Mast this SML is looking at
* @see SignallingPanel(SignalMast, SignalMast, JmriJFrame)
*/
public void initComponents(jmri.SignalMast source, jmri.SignalMast dest) {
public void initComponents(SignalMast source, SignalMast dest) {
// the following code sets the frame's initial state
sigPanel = new SignallingPanel(source, dest, this);

setTitle(Bundle.getMessage("SignallingPairs")); // NOI18N
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));

getContentPane().add(sigPanel);
getContentPane().add(sigPanel); // panels are created in SignallingPanel()

addHelpMenu("package.jmri.jmrit.signalling.AddEditSignallingLogic", true); // NOI18N

Expand Down
73 changes: 43 additions & 30 deletions java/src/jmri/jmrit/signalling/SignallingPanel.java
Expand Up @@ -2,8 +2,10 @@

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeListener;
Expand All @@ -12,6 +14,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.DefaultCellEditor;
Expand Down Expand Up @@ -48,6 +51,7 @@
import jmri.jmrit.display.layoutEditor.LayoutBlockManager;
import jmri.swing.RowSorterUtil;
import jmri.util.swing.JmriBeanComboBox;
import jmri.util.swing.JmriPanel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -56,16 +60,16 @@
* Masts).
*
* @author Kevin Dickerson Copyright (C) 2011
* @author Egbert Broerse Copyright (C) 2017
* @author Egbert Broerse Copyright (C) 2017, 2018
*/
public class SignallingPanel extends jmri.util.swing.JmriPanel {
public class SignallingPanel extends JmriPanel {

JmriBeanComboBox sourceMastBox;
JmriBeanComboBox destMastBox;
JLabel fixedSourceMastLabel = new JLabel();
JLabel fixedDestMastLabel = new JLabel();
JLabel sourceMastLabel = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("SourceMast"))); // NOI18N
JLabel destMastLabel = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("DestMast"))); // NOI18N
JLabel sourceMastLabel = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("SourceMast")), JLabel.TRAILING); // NOI18N
JLabel destMastLabel = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("DestMast")), JLabel.TRAILING); // NOI18N
JButton cancelButton = new JButton(Bundle.getMessage("ButtonCancel")); // NOI18N
JButton updateButton = new JButton(Bundle.getMessage("UpdateLogicButton")); // NOI18N
JButton applyButton = new JButton(Bundle.getMessage("ButtonApply")); // NOI18N
Expand All @@ -87,8 +91,8 @@ public class SignallingPanel extends jmri.util.swing.JmriPanel {

JFrame jFrame;

// Siae of the individual bean tables inside the shared pane
static final Dimension TABLESIZEPREFERRED = new Dimension(720, 200);
// Size of the individual bean tables inside the shared pane
static final Dimension TABLESIZEPREFERRED = new Dimension(720, 200);

/**
* Create an empty JPanel to configure a new Signal Mast Logic.
Expand All @@ -115,9 +119,9 @@ public SignallingPanel(SignalMast source, SignalMast dest, JFrame frame) {
this.sourceMast = source;
this.sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).getSignalMastLogic(source);
fixedSourceMastLabel = new JLabel(sourceMast.getDisplayName());
if (dest != null) {
frame.setTitle(source.getDisplayName() + " to " + dest.getDisplayName());
}
// if (dest != null) {
// frame.setTitle(source.getDisplayName() + " to " + dest.getDisplayName());
// }
}
if ((dest != null) && (sml != null)) {
this.destMast = dest;
Expand All @@ -133,39 +137,46 @@ public SignallingPanel(SignalMast source, SignalMast dest, JFrame frame) {

Float pathSpeed = sml.getMaximumSpeed(dest);
if (pathSpeed == 0.0f) {
mastSpeed.setText(Bundle.getMessage("PathSpeed") + " : " + Bundle.getMessage("NoneSet")); // NOI18N
mastSpeed.setText(Bundle.getMessage("MakeLabel", Bundle.getMessage("PathSpeed")) + " " + Bundle.getMessage("NoneSet")); // NOI18N
} else {
String speed = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getNamedSpeed(pathSpeed);
if (speed != null) {
mastSpeed.setText(Bundle.getMessage("PathSpeed") + " : " + speed); // NOI18N
mastSpeed.setText(Bundle.getMessage("MakeLabel", Bundle.getMessage("PathSpeed")) + " " + speed); // NOI18N
} else {
mastSpeed.setText(Bundle.getMessage("PathSpeed") + " : " + Float.toString(pathSpeed)); // NOI18N
mastSpeed.setText(Bundle.getMessage("MakeLabel", Bundle.getMessage("PathSpeed")) + " " + Float.toString(pathSpeed)); // NOI18N
}
}
} else if (dest == null) {
sml = null;
}

sourceMastBox = new JmriBeanComboBox(smm, sourceMast, JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
sourceMastBox.setMaximumSize(sourceMastBox.getPreferredSize());
destMastBox = new JmriBeanComboBox(smm, destMast, JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
destMastBox.setMaximumSize(destMastBox.getPreferredSize());

JPanel containerPanel = new JPanel();
containerPanel.setLayout(new BoxLayout(containerPanel, BoxLayout.Y_AXIS));
// directly add sub-panes onto JFrame's content pane to allow resizing (2018)
Container contentPane = frame.getContentPane();

JPanel header = new JPanel();
header.setLayout(new BoxLayout(header, BoxLayout.Y_AXIS));

JPanel mastGrid = new JPanel();
GridLayout layout = new GridLayout(2, 2, 10, 0); // (int rows, int cols, int hgap, int vgap)
mastGrid.setLayout(layout);
// row 1
mastGrid.add(sourceMastLabel);

JPanel sourcePanel = new JPanel();
sourcePanel.setLayout(new BoxLayout(sourcePanel, BoxLayout.X_AXIS));
sourcePanel.add(sourceMastLabel);
sourcePanel.add(sourceMastBox);
sourcePanel.add(fixedSourceMastLabel);

header.add(sourcePanel);
mastGrid.add(sourcePanel);
// row 2
mastGrid.add(destMastLabel);

JPanel destPanel = new JPanel();
destPanel.setLayout(new BoxLayout(destPanel, BoxLayout.X_AXIS));
destPanel.add(destMastLabel);
destPanel.add(destMastBox);
destPanel.add(fixedDestMastLabel);

Expand All @@ -186,7 +197,9 @@ public void actionPerformed(ActionEvent e) {
}
});

header.add(destPanel);
mastGrid.add(destPanel);
header.add(mastGrid);

header.add(mastSpeed);

JPanel editor = new JPanel();
Expand Down Expand Up @@ -236,11 +249,12 @@ public void actionPerformed(ActionEvent e) {
}
}
}

});
header.add(editor);
header.add(allowAutoMastGeneration);
header.add(lockTurnouts);

// selection radiobuttons for All/Included items
JPanel py = new JPanel();
py.add(new JLabel(Bundle.getMessage("Show"))); // NOI18N
selGroup = new ButtonGroup();
Expand Down Expand Up @@ -279,21 +293,22 @@ public void actionPerformed(ActionEvent e) {
});
py.add(new JLabel(" " + Bundle.getMessage("Elements"))); // NOI18N
header.add(py);
contentPane.add(header);

containerPanel.add(header);

// build_x_Panel() returns a JScrollFrame
JTabbedPane detailsTab = new JTabbedPane();
detailsTab.add(Bundle.getMessage("Blocks"), buildBlocksPanel()); // NOI18N
detailsTab.add(Bundle.getMessage("Turnouts"), buildTurnoutPanel()); // NOI18N
detailsTab.add(Bundle.getMessage("Sensors"), buildSensorPanel()); // NOI18N
detailsTab.add(Bundle.getMessage("SignalMasts"), buildSignalMastPanel()); // NOI18N

containerPanel.add(detailsTab);
JScrollPane detailsScrollPane = new JScrollPane(detailsTab); // make set of 1-2 tables scrollable on smaller screens
contentPane.add(detailsScrollPane);

JPanel footer = new JPanel();
footer.setLayout(new FlowLayout(FlowLayout.TRAILING));

//Cancel button
// Cancel button
footer.add(cancelButton);
cancelButton.addActionListener(new ActionListener() {
@Override
Expand All @@ -302,7 +317,7 @@ public void actionPerformed(ActionEvent e) {
}
});

//Update button
// Update button
footer.add(updateButton);
updateButton.addActionListener(new ActionListener() {
@Override
Expand All @@ -313,7 +328,7 @@ public void actionPerformed(ActionEvent e) {
updateButton.setToolTipText(Bundle.getMessage("UpdateButtonToolTip")); // NOI18N
updateButton.setVisible(true);

//Apply (and Close) button
// Apply (and Close) button
footer.add(applyButton);
applyButton.addActionListener(new ActionListener() {
@Override
Expand All @@ -324,9 +339,9 @@ public void actionPerformed(ActionEvent e) {
applyButton.setToolTipText(Bundle.getMessage("ApplyButtonToolTip")); // NOI18N
applyButton.setVisible(true);

containerPanel.add(footer);
contentPane.add(Box.createVerticalGlue()); // glue above buttons
contentPane.add(footer);

add(containerPanel);
if (sourceMast != null) { // edit an existing SML, fix source mast
fixedSourceMastLabel.setVisible(true);
sourceMastBox.setVisible(false);
Expand Down Expand Up @@ -355,7 +370,6 @@ public void actionPerformed(ActionEvent e) {
JScrollPane _manualSignalMastScrollPane;
JScrollPane _autoSignalMastScrollPane;
JScrollPane _autoTurnoutScrollPane;

JScrollPane _manualSensorScrollPane;

JPanel p2xc = null;
Expand Down Expand Up @@ -506,7 +520,6 @@ JPanel buildBlocksPanel() {
p2xaSpace.setVisible(false);

return blockPanel;

}

JPanel p2xa = new JPanel();
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/signalling/SignallingSourcePanel.java
Expand Up @@ -58,7 +58,7 @@ public SignallingSourcePanel(final SignalMast sourceMast) {
super();
sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).getSignalMastLogic(sourceMast);
this.sourceMast = sourceMast;
fixedSourceMastLabel = new JLabel(Bundle.getMessage("SourceMast") + ": " + sourceMast.getDisplayName()); // NOI18N
fixedSourceMastLabel = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("SourceMast")) + " " + sourceMast.getDisplayName()); // NOI18N
if (sml != null) {
_signalMastList = sml.getDestinationList();
}
Expand Down

0 comments on commit d3bc8f7

Please sign in to comment.