Skip to content

Commit

Permalink
Add AddEditMast frame
Browse files Browse the repository at this point in the history
  • Loading branch information
pete_ authored and pete_ committed Jun 4, 2019
1 parent b46ff77 commit 8e49bae
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 15 deletions.
89 changes: 74 additions & 15 deletions java/src/jmri/jmrit/display/controlPanelEditor/CircuitBuilder.java
Expand Up @@ -115,6 +115,7 @@ public class CircuitBuilder {
private EditPortalFrame _editPortalFrame; private EditPortalFrame _editPortalFrame;
private EditCircuitPaths _editPathsFrame; private EditCircuitPaths _editPathsFrame;
private EditPortalDirection _editDirectionFrame; private EditPortalDirection _editDirectionFrame;
private EditSignalFrame _editSignalFrame;


// list of icons making a circuit (OBlock) - used by editing frames to indicate block(s) being worked on // list of icons making a circuit (OBlock) - used by editing frames to indicate block(s) being worked on
private ArrayList<Positionable> _circuitIcons; // Dark Blue private ArrayList<Positionable> _circuitIcons; // Dark Blue
Expand Down Expand Up @@ -218,6 +219,14 @@ private void makeCircuitMenu() {
} }
editPortalDirection("editDirectionItem", true); editPortalDirection("editDirectionItem", true);
}); });
editItem = new JMenuItem(Bundle.getMessage("editSignalItem"));
_circuitMenu.add(editItem);
editItem.addActionListener((ActionEvent event) -> {
if (_cbFrame !=null) {
_cbFrame.dispose();
}
editSignalFrame("editSignalItem", true);
});
_todoMenu = new JMenu(Bundle.getMessage("circuitErrorsItem")); _todoMenu = new JMenu(Bundle.getMessage("circuitErrorsItem"));
_circuitMenu.add(_todoMenu); _circuitMenu.add(_todoMenu);
makeToDoMenu(); makeToDoMenu();
Expand Down Expand Up @@ -526,6 +535,29 @@ protected void editPortalDirection(String title, boolean fromMenu) {
} }
} }


protected void editSignalFrame(String title, boolean fromMenu) {
if (editingOK()) {
if (fromMenu) {
editCircuitDialog(title);
}
if (_currentBlock != null) {
_circuitIcons = _circuitMap.get(_currentBlock);
// check icons to be indicator type
if (!iconsConverted(_currentBlock)) {
queryConvertIcons(_currentBlock);
}
_editor.setSelectionGroup(makeSelectionGroup(_currentBlock, true));
_editor.disableMenus();
TargetPane targetPane = (TargetPane) _editor.getTargetPanel();
targetPane.setSelectGroupColor(_editGroupColor);
targetPane.setHighlightColor(_highlightColor);
_editSignalFrame = new EditSignalFrame(Bundle.getMessage("OpenSignalsTitle"), this, _currentBlock);
} else if (!fromMenu) {
selectPrompt();
}
}
}

protected void editCircuitPaths(String title, boolean fromMenu) { protected void editCircuitPaths(String title, boolean fromMenu) {
if (editingOK()) { if (editingOK()) {
if (fromMenu) { if (fromMenu) {
Expand Down Expand Up @@ -564,6 +596,8 @@ protected void hidePortalIcons() {
_editPathsFrame.clearListSelection(); _editPathsFrame.clearListSelection();
} else if (_editDirectionFrame != null) { } else if (_editDirectionFrame != null) {
_editDirectionFrame.clearListSelection(); _editDirectionFrame.clearListSelection();
} else if (_editSignalFrame != null) {
_editSignalFrame.clearListSelection();
} else { } else {
Iterator<PortalIcon> it = _portalIconMap.values().iterator(); Iterator<PortalIcon> it = _portalIconMap.values().iterator();
while (it.hasNext()) { while (it.hasNext()) {
Expand All @@ -573,7 +607,8 @@ protected void hidePortalIcons() {
} }


private boolean editingOK() { private boolean editingOK() {
if (_editCircuitFrame != null || _editPathsFrame != null || _editPortalFrame != null || _editDirectionFrame != null) { if (_editCircuitFrame != null || _editPathsFrame != null || _editPortalFrame != null ||
_editDirectionFrame != null || _editSignalFrame != null) {
// Already editing a circuit, ask for completion of that edit // Already editing a circuit, ask for completion of that edit
JOptionPane.showMessageDialog(_editCircuitFrame, JOptionPane.showMessageDialog(_editCircuitFrame,
Bundle.getMessage("AlreadyEditing"), Bundle.getMessage("ErrorTitle"), Bundle.getMessage("AlreadyEditing"), Bundle.getMessage("ErrorTitle"),
Expand All @@ -590,6 +625,9 @@ private boolean editingOK() {
} else if (_editDirectionFrame != null) { } else if (_editDirectionFrame != null) {
_editDirectionFrame.toFront(); _editDirectionFrame.toFront();
_editDirectionFrame.setVisible(true); _editDirectionFrame.setVisible(true);
} else if (_editSignalFrame != null) {
_editSignalFrame.toFront();
_editSignalFrame.setVisible(true);
} }
return false; return false;
} }
Expand Down Expand Up @@ -798,11 +836,6 @@ private void setPortalsPositionable(OBlock block, boolean set) {
} }


////////////////////////// Closing Editing Frames ////////////////////////// ////////////////////////// Closing Editing Frames //////////////////////////
protected void closeCircuitFrame() {
_editCircuitFrame = null;
closeCircuitBuilder();
}

/** /**
* Edit frame closing, set block's icons * Edit frame closing, set block's icons
* @param block OBlock to set icon selections into data maps * @param block OBlock to set icon selections into data maps
Expand Down Expand Up @@ -852,6 +885,11 @@ protected String setIconGroup(OBlock block) {
return null; return null;
} }


protected void closeCircuitFrame() {
_editCircuitFrame = null;
closeCircuitBuilder();
}

protected void closePathFrame(OBlock block) { protected void closePathFrame(OBlock block) {
if (_currentBlock != null) { if (_currentBlock != null) {
_currentBlock.deAllocate(null); _currentBlock.deAllocate(null);
Expand All @@ -874,6 +912,12 @@ protected void closePortalDirection(OBlock block) {
closeCircuitBuilder(); closeCircuitBuilder();
} }


protected void closeEditSignalFrame(OBlock block) {
setPortalsPositionable(block, false);
_editSignalFrame = null;
closeCircuitBuilder();
}

private void closeCircuitBuilder() { private void closeCircuitBuilder() {
_currentBlock = null; _currentBlock = null;
_circuitIcons = null; _circuitIcons = null;
Expand Down Expand Up @@ -1504,10 +1548,8 @@ private boolean okToAdd(Positionable pos, OBlock editBlock) {
*/ */
protected boolean saveSelectionGroup(ArrayList<Positionable> selectionGroup) { protected boolean saveSelectionGroup(ArrayList<Positionable> selectionGroup) {
_saveSelectionGroup = selectionGroup; _saveSelectionGroup = selectionGroup;
return _editCircuitFrame != null return _editCircuitFrame != null || _editPortalFrame != null || _editPathsFrame != null
|| _editPortalFrame != null || _editDirectionFrame != null || _editSignalFrame != null;
|| _editPathsFrame != null
|| _editDirectionFrame != null;
} }


/** /**
Expand All @@ -1531,6 +1573,9 @@ protected boolean doMousePressed(MouseEvent event, Positionable selection) {
} else if (_editDirectionFrame != null) { } else if (_editDirectionFrame != null) {
_editDirectionFrame.toFront(); _editDirectionFrame.toFront();
_editor.setSelectionGroup(_saveSelectionGroup); _editor.setSelectionGroup(_saveSelectionGroup);
} else if (_editSignalFrame != null) {
_editSignalFrame.toFront();
_editor.setSelectionGroup(_saveSelectionGroup);
} else { } else {
return false; return false;
} }
Expand All @@ -1540,8 +1585,12 @@ protected boolean doMousePressed(MouseEvent event, Positionable selection) {
public boolean doMouseReleased(Positionable selection, boolean dragging) { public boolean doMouseReleased(Positionable selection, boolean dragging) {
if (_editCircuitFrame != null || _editPathsFrame != null || _editDirectionFrame != null) { if (_editCircuitFrame != null || _editPathsFrame != null || _editDirectionFrame != null) {
return true; return true;
} else if (_editPortalFrame != null) { } else if (_editPortalFrame != null || _editSignalFrame != null) {
if (selection instanceof PortalIcon && _circuitIcons.contains(selection)) { if (selection instanceof PortalIcon && _circuitIcons.contains(selection)) {
if (_editSignalFrame != null) {
_editSignalFrame.setSelected((PortalIcon)selection);
return true;
}
if (dragging) { if (dragging) {
_editPortalFrame.checkPortalIconForUpdate((PortalIcon) selection, true); _editPortalFrame.checkPortalIconForUpdate((PortalIcon) selection, true);
} else { } else {
Expand All @@ -1555,7 +1604,8 @@ public boolean doMouseReleased(Positionable selection, boolean dragging) {


protected boolean doMouseClicked(List<Positionable> selections, MouseEvent event) { protected boolean doMouseClicked(List<Positionable> selections, MouseEvent event) {
if (_editCircuitFrame != null || _editPathsFrame != null if (_editCircuitFrame != null || _editPathsFrame != null
|| _editPortalFrame != null || _editDirectionFrame != null) { || _editPortalFrame != null || _editDirectionFrame != null
|| _editSignalFrame != null) {
if (selections != null && selections.size() > 0) { if (selections != null && selections.size() > 0) {
ArrayList<Positionable> tracks = new ArrayList<>(); ArrayList<Positionable> tracks = new ArrayList<>();
Iterator<Positionable> iter = selections.iterator(); Iterator<Positionable> iter = selections.iterator();
Expand Down Expand Up @@ -1637,7 +1687,7 @@ private Positionable getSelection(List<Positionable> tracks) {
* @return true to prevent dragging; false otherwise * @return true to prevent dragging; false otherwise
*/ */
public boolean doMouseDragged(Positionable selection, MouseEvent event) { public boolean doMouseDragged(Positionable selection, MouseEvent event) {
if (_editCircuitFrame != null || _editPathsFrame != null) { if (_editCircuitFrame != null || _editPathsFrame != null || _editSignalFrame != null) {
return true; // no dragging when editing return true; // no dragging when editing
} }
if (selection instanceof PortalIcon) { if (selection instanceof PortalIcon) {
Expand Down Expand Up @@ -1710,6 +1760,15 @@ private void handleSelection(Positionable selection, MouseEvent event) {
_editDirectionFrame.setPortalIcon(null, false); _editDirectionFrame.setPortalIcon(null, false);
} }
_editDirectionFrame.toFront(); _editDirectionFrame.toFront();
} else if (_editSignalFrame != null) {
if (log.isDebugEnabled()) {
log.debug("selection= " + (selection == null ? "null"
: selection.getClass().getName()));
}
if (selection instanceof PortalIcon) {
_editSignalFrame.setSelected((PortalIcon)selection);
}
_editSignalFrame.toFront();
} }
} }


Expand Down Expand Up @@ -1747,7 +1806,7 @@ class CBFrame extends jmri.util.JmriJFrame implements ListSelectionListener {
panel.add(makeButton("editPortalsItem", PORTAL)); panel.add(makeButton("editPortalsItem", PORTAL));
panel.add(makeButton("editCircuitPathsItem", OPATH)); panel.add(makeButton("editCircuitPathsItem", OPATH));
panel.add(makeButton("editDirectionItem", ARROW)); panel.add(makeButton("editDirectionItem", ARROW));
// panel.add(makeButton("editSignalItem", SIGNAL)); panel.add(makeButton("editSignalItem", SIGNAL));
b.setSelected(true); b.setSelected(true);
panel0.add(panel); panel0.add(panel);


Expand Down Expand Up @@ -1775,7 +1834,7 @@ class CBFrame extends jmri.util.JmriJFrame implements ListSelectionListener {
} else if (_which == ARROW) { } else if (_which == ARROW) {
editPortalDirection("editDirectionItem", false); editPortalDirection("editDirectionItem", false);
} else if (_which == SIGNAL) { } else if (_which == SIGNAL) {
//editSignal("editSignalItem", false); editSignalFrame("editSignalItem", false);
} }
} }
}); });
Expand Down
Expand Up @@ -14,6 +14,7 @@ editCircuitItem = Edit Circuit OBlock
OpenCircuitItem = Edit "{0}" Track OpenCircuitItem = Edit "{0}" Track
OpenPortalTitle = Edit "{0}" Portals OpenPortalTitle = Edit "{0}" Portals
OpenDirectionTitle= Edit "{0}" Portal Direction Arrows OpenDirectionTitle= Edit "{0}" Portal Direction Arrows
OpenSignalsTitle= Edit "{0}" Signal Masts
OpenPortalTitle2= Add/Edit Portals between "{0}" and "{1}" OpenPortalTitle2= Add/Edit Portals between "{0}" and "{1}"
OpenPathTitle = Add/Edit "{0}" Paths OpenPathTitle = Add/Edit "{0}" Paths
noCircuitsItem = No Detector Circuits are defined noCircuitsItem = No Detector Circuits are defined
Expand Down Expand Up @@ -113,6 +114,7 @@ blockName = Circuit Name:
portalName = Portal Name portalName = Portal Name
makePortal = Make Portal makePortal = Make Portal
PortalTitle = Portals into and out of circuit {0} PortalTitle = Portals into and out of circuit {0}
SignalTitle = Signal masts protecting block {0}
selectPortal = To make an icon for a Portal in the list, select it from the list, selectPortal = To make an icon for a Portal in the list, select it from the list,
dragIcon = then drag the icon below to its position between the circuits on the panel. dragIcon = then drag the icon below to its position between the circuits on the panel.
portalIconPosition=A portal icon must touch both Blocks of the Portal\nDrag the highlighted icon to a position straddling the two block circuits. portalIconPosition=A portal icon must touch both Blocks of the Portal\nDrag the highlighted icon to a position straddling the two block circuits.
Expand Down

0 comments on commit 8e49bae

Please sign in to comment.