Skip to content

Commit

Permalink
Merge pull request #4613 from geowar1/Do-Over-Decorations-and-Findbug…
Browse files Browse the repository at this point in the history
…-fixes

Do Over: Decorations and Findbug fixes
  • Loading branch information
bobjacobsen committed Dec 24, 2017
2 parents 96a2d57 + 313f6f2 commit 12064c5
Show file tree
Hide file tree
Showing 18 changed files with 2,730 additions and 190 deletions.
1 change: 1 addition & 0 deletions java/src/jmri/jmrit/display/layoutEditor/LayoutBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
Expand Down
145 changes: 117 additions & 28 deletions java/src/jmri/jmrit/display/layoutEditor/LayoutEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2707,12 +2707,14 @@ public void menuCanceled(MenuEvent event) {
});

//set track width menu item
JMenuItem widthItem = new JMenuItem(Bundle.getMessage("SetTrackWidth") + "...");
trackMenu.add(widthItem);
widthItem.addActionListener((ActionEvent event) -> {
//bring up enter track width dialog
enterTrackWidth();
});
// Note: Now set via LayoutTrackDrawingOptionsDialog (above)
//TODO: Dead code strip this
//JMenuItem widthItem = new JMenuItem(Bundle.getMessage("SetTrackWidth") + "...");
//trackMenu.add(widthItem);
//widthItem.addActionListener((ActionEvent event) -> {
// //bring up enter track width dialog
// enterTrackWidth();
//});

//track colors item menu item
JMenu trkColourMenu = new JMenu(Bundle.getMessage("TrackColorSubMenu"));
Expand Down Expand Up @@ -3086,11 +3088,9 @@ private void updateComboBoxDropDownListDisplayOrderFromPrefs(
}

//now try to get a preference specific to this combobox
JmriBeanComboBox jbcb = null;
if (inComponent instanceof JmriBeanComboBox) {
jbcb = (JmriBeanComboBox) inComponent;
} else if (inComponent instanceof JTextField) {
jbcb = (JmriBeanComboBox) SwingUtilities.getUnwrappedParent(inComponent);
JmriBeanComboBox jbcb = (JmriBeanComboBox) inComponent;
if (inComponent instanceof JTextField) {
jbcb = (JmriBeanComboBox) SwingUtilities.getUnwrappedParent(jbcb);
}
if (jbcb != null) {
String ttt = jbcb.getToolTipText();
Expand Down Expand Up @@ -5754,7 +5754,7 @@ private void showEditPopUps(MouseEvent event) {
&& (foundPointType <= LayoutTrack.TURNOUT_D)) {
// don't curently have edit popup for these
} else {
log.info("Unknown foundPointType:" + foundPointType);
log.warn("Unknown foundPointType:" + foundPointType);
}
} else {
do {
Expand Down Expand Up @@ -9334,15 +9334,18 @@ public void setHighlightSelectedBlock(boolean state) {
prefsMgr.setSimplePreferenceState(getWindowFrameRef() + ".highlightSelectedBlock", highlightSelectedBlockFlag);
});

if (highlightSelectedBlockFlag) {
//use the "Extra" color to highlight the selected block
if (!highlightBlockInComboBox(blockIDComboBox)) {
highlightBlockInComboBox(blockContentsComboBox);
// thread this so it won't break the AppVeyor checks
new Thread(() -> {
if (highlightSelectedBlockFlag) {
//use the "Extra" color to highlight the selected block
if (!highlightBlockInComboBox(blockIDComboBox)) {
highlightBlockInComboBox(blockContentsComboBox);
}
} else {
//undo using the "Extra" color to highlight the selected block
highlightBlock(null);
}
} else {
//undo using the "Extra" color to highlight the selected block
highlightBlock(null);
}
}).start();
}
} //setHighlightSelectedBlock

Expand Down Expand Up @@ -9579,6 +9582,8 @@ protected void draw(Graphics2D g2) {
}
drawLayoutTracksHidden(g2);
}
drawTrackSegmentsDashed(g2);

drawLayoutTracksBallast(g2);
drawLayoutTracksTies(g2);
drawLayoutTracksRails2(g2);
Expand All @@ -9588,6 +9593,8 @@ protected void draw(Graphics2D g2) {
drawPositionablePoints(g2, false);
drawPositionablePoints(g2, true);

drawDecorations(g2);

// things that only get drawn in edit mode
if (isEditable()) {
drawLayoutTrackEditControls(g2);
Expand All @@ -9610,19 +9617,59 @@ protected void draw(Graphics2D g2) {
} // draw

private void drawLayoutTracksHidden(Graphics2D g2) {
Stroke stroke = new BasicStroke(1.F);
Stroke dashedStroke = new BasicStroke(1.F,
BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.F,
new float[]{6.F, 4.F}, 0);

//setup for drawing hidden sideline rails
g2.setStroke(new BasicStroke(1.0f));
g2.setColor(getLayoutTrackDrawingOptions().getSideRailColor());
g2.setStroke(stroke);
boolean main = false, block = false, hidden = true, dashed = false;
draw1(g2, main, block, hidden, dashed);
g2.setStroke(dashedStroke);
draw1(g2, main, block, hidden, dashed = true);
//setup for drawing mainline rails
g2.setStroke(new BasicStroke(2.0f));
g2.setColor(getLayoutTrackDrawingOptions().getMainRailColor());
g2.setStroke(stroke);
draw1(g2, main, block, hidden, dashed = false);
g2.setStroke(dashedStroke);
draw1(g2, main, block, hidden, dashed = true);
}

private void drawTrackSegmentsDashed(Graphics2D g2) {
boolean main = false, block = false, hidden = false, dashed = true;
float[] dashArray = new float[]{6.F, 4.F};
//setup for drawing dashed sideline rails
int railWidth = getLayoutTrackDrawingOptions().getSideRailWidth();
float railDisplacement = ((railWidth * 2.F)
+ getLayoutTrackDrawingOptions().getSideRailGap()) / 2.F;
g2.setStroke(new BasicStroke(
railWidth,
BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
10.F, dashArray, 10));
g2.setColor(getLayoutTrackDrawingOptions().getSideRailColor());
if ((getLayoutTrackDrawingOptions().getSideRailCount() & 1) == 1) {
draw1(g2, main, block, hidden, dashed);
}
if (getLayoutTrackDrawingOptions().getSideRailCount() >= 2) {
draw2(g2, main, railDisplacement, dashed);
}
//setup for drawing dashed mainline rails
main = true;
g2.setStroke(new BasicStroke(
getLayoutTrackDrawingOptions().getMainRailWidth(),
BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
10.F, dashArray, 10));
g2.setColor(getLayoutTrackDrawingOptions().getMainRailColor());
if ((getLayoutTrackDrawingOptions().getMainRailCount() & 1) == 1) {
draw1(g2, main, block, hidden, dashed);
}
if (getLayoutTrackDrawingOptions().getMainRailCount() >= 2) {
draw2(g2, main, railDisplacement, dashed);
}
}

private void drawLayoutTracksBallast(Graphics2D g2) {
//setup for drawing sideline ballast
int ballastWidth = getLayoutTrackDrawingOptions().getSideBallastWidth();
Expand Down Expand Up @@ -9756,10 +9803,14 @@ private void draw1(Graphics2D g2,
boolean isDashed) {
for (LayoutTrack layoutTrack : layoutTrackList) {
if (!(layoutTrack instanceof PositionablePoint)) {
if ((isHidden == layoutTrack.isHidden())
&& (!isDashed || ((layoutTrack instanceof TrackSegment)
&& (((TrackSegment) layoutTrack).isDashed())))) {
layoutTrack.draw1(g2, isMain, isBlock);
if (isHidden == layoutTrack.isHidden()) {
if ((layoutTrack instanceof TrackSegment)) {
if (((TrackSegment) layoutTrack).isDashed() == isDashed) {
layoutTrack.draw1(g2, isMain, isBlock);
}
} else if (!isDashed) {
layoutTrack.draw1(g2, isMain, isBlock);
}
}
}
}
Expand All @@ -9774,13 +9825,27 @@ private void drawPositionablePoints(Graphics2D g2, boolean isMain) {
}

private void draw2(Graphics2D g2, boolean isMain, float railDisplacement) {
draw2(g2, isMain, railDisplacement, false);
}

private void draw2(Graphics2D g2, boolean isMain, float railDisplacement, boolean isDashed) {
for (LayoutTrack layoutTrack : layoutTrackList) {
if (!layoutTrack.isHidden()) {
if ((layoutTrack instanceof TrackSegment)) {
if (((TrackSegment) layoutTrack).isDashed() == isDashed) {
layoutTrack.draw2(g2, isMain, railDisplacement);
}
} else if (!isDashed) {
layoutTrack.draw2(g2, isMain, railDisplacement);
}
}
}

private void drawDecorations(Graphics2D g2) {
for (LayoutTrack tr : layoutTrackList) {
tr.drawDecorations(g2);
}
}

private void drawTrackSegmentInProgress(Graphics2D g2) {
//check for segment in progress
if (isEditable() && (beginObject != null) && trackButton.isSelected()) {
Expand Down Expand Up @@ -9923,13 +9988,16 @@ private void drawPanelGrid(Graphics2D g2) {
int wideMod = gridSize1st * gridSize2nd;
int wideMin = gridSize1st / 2;

Rectangle2D clipBounds = g2.getClipBounds();
//log.info("drawPanelGrid() clipBounds: " + clipBounds);

// granulize puts these on gridSize1st increments
int minX = 0;
int minY = 0;
int maxX = (int) MathUtil.granulize(panelWidth, gridSize1st);
int maxY = (int) MathUtil.granulize(panelHeight, gridSize1st);

log.debug("drawPanelGrid: minX: {}, minY: {}, maxX: {}, maxY: {}", minX, minY, maxX, maxY);
//log.info(" minX: {}, minY: {}, maxX: {}, maxY: {}", minX, minY, maxX, maxY);

Point2D startPt = new Point2D.Double();
Point2D stopPt = new Point2D.Double();
Expand All @@ -9939,6 +10007,27 @@ private void drawPanelGrid(Graphics2D g2) {
g2.setColor(Color.gray);
g2.setStroke(narrow);

// calculate the bounds for the scroll pane
JScrollPane scrollPane = getPanelScrollPane();
Rectangle scrollBounds = scrollPane.getViewportBorderBounds();
//log.info(" scrollBounds: " + scrollBounds);

Rectangle2D newClipBounds = SwingUtilities.convertRectangle(
scrollPane.getParent(), scrollBounds, this);
newClipBounds = MathUtil.rectangle2DToRectangle(scrollPane.getVisibleRect());
//log.info(" newClipBounds: " + newClipBounds);

double scale = getZoom();
int width = (int) (newClipBounds.getWidth() / scale);
int height = (int) (newClipBounds.getHeight() / scale);
int originX = (int) (scrollPane.getHorizontalScrollBar().getValue() / scale);
int originY = (int) (scrollPane.getVerticalScrollBar().getValue() / scale);
//log.info(" origin: {{}, {}}", originX, originY);

//newClipBounds = new Rectangle2D.Double(originX, originY, width, height);
//log.info(" newClipBounds: " + newClipBounds);
g2.setClip(originX, originY, width, height);

//draw horizontal lines
for (int y = minY; y <= maxY; y += gridSize1st) {
startPt.setLocation(minX, y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ MainlineBox = Mainline
MainlineCheckBoxTip = Sets track segment type - check for mainline track, uncheck for side track.
Solid = Solid
Style = Style

MainlineCheckBoxMenuItemTitle = Mainline
MainlineCheckBoxMenuItemToolTip = Sets track segment type - check for mainline track, uncheck for side track.
HiddenCheckBoxMenuItemTitle = Hidden
HiddenCheckBoxMenuItemToolTip = Check this to hide the track when not in edit mode
DashedCheckBoxMenuItemTitle = Dashed
DashedCheckBoxMenuItemToolTip = Sets track segment style - checked for dashed, unchecked for solid.
FlippedCheckBoxMenuItemTitle = Flipped
FlippedCheckBoxMenuItemToolTip = Check this move the center of the arc/circle to the other side of the track

LevelCrossingToolTip = Select to add a level crossing track when next clicking with shift down.
SingleSlipToolTip = Select to add a single slip when next clicking with shift down.
DoubleSlipToolTip = Select to add a double slip when next clicking with shift down.
Expand Down Expand Up @@ -591,8 +601,10 @@ TCTErrorUnableToCreate = Unable to create Transit {0}

# Use with track segments
ChangeTo = Change To
#Circle, Ellipse & Bezier are in > DisplayBundle
FlipAngle = Flip Angle
#Circle, Ellipse & Bezier are in DisplayBundle.properties file
FlipAngleCheckBoxMenuItemTitle = Flip Angle
FlipAngleCheckBoxMenuItemToolTip = Flips the side of the track that the arc center is on

ShowConstruct = Show Construction Line
HideConstruct = Hide Construction Line
AddBezierControlPointAfter = Add Control Point After
Expand Down Expand Up @@ -624,7 +636,7 @@ Line=Line
#check menu items
CheckMenuTitle = Check
ReCheckMenuTitle = Re-Check
CheckMenuToolTip = Use this menu to run layout editor checks
CheckMenuToolTip = Select this menu to run layout editor checks
CheckInProgressMenuItemTitle = Check In Progress...
CheckInProgressMenuItemToolTip = Checking is in progress... (please wait)
CheckNoResultsMenuItemTitle = No Results
Expand Down Expand Up @@ -705,3 +717,80 @@ SideTieColorToolTip = Click this button to set the color of sideline ties
SideTieGapToolTip = Click this button to set the distance between sideline ties
SideTieLengthToolTip = Click this button to set the length of sideline ties
SideTieWidthToolTip = Click this button to set the width of sideline ties

#
# decorations
#
DecorationMenuTitle = Decorations
DecorationMenuToolTip = Select this menu to change decoration settings for this track
# style
DecorationStyleMenuTitle = Style
DecorationStyleMenuToolTip = Select the style of arrow decorations to add to this track
DecorationNoneMenuItemTitle = None
DecorationNoneMenuItemToolTip = Select this to remove this decoration from this track

# end
DecorationEndMenuTitle = End
DecorationEndMenuToolTip = Select at which end(s) to add this decoration
DecorationStartMenuItemTitle = Start
DecorationStartMenuItemToolTip = Select this to add this decoration at the beginning of this track
DecorationEndMenuItemTitle = End
DecorationEndMenuItemToolTip = Select this to add this decoration at the end of this track
DecorationEntryMenuItemTitle = Entry
DecorationEntryMenuItemToolTip = Select this to add this decoration at the entry of this track
DecorationExitMenuItemTitle = Exit
DecorationExitMenuItemToolTip = Select this to add this decoration at the exit of this track
DecorationBothMenuItemTitle = Both
DecorationBothMenuItemToolTip = Select this to add this decoration at both ends of this track
# side
DecorationSideMenuTitle = Side
DecorationSideMenuToolTip = Select on which side(s) to add this decoration
DecorationSideLeftMenuItemTitle = Left
DecorationSideLeftMenuItemToolTip = Select this to add this decoration to the left side of this track
DecorationSideRightMenuItemTitle = Right
DecorationSideRightMenuItemToolTip = Select this to add this decoration to the right side of this track
DecorationSideBothMenuItemTitle = Both
DecorationSideBothMenuItemToolTip = Select this to add this decoration to both sides of this track

DecorationColorMenuItemTitle = Color
DecorationColorMenuItemToolTip = Select this to change the color of this decoration
DecorationLineWidthMenuItemTitle = Line Width
DecorationLineWidthMenuItemToolTip = Select this to change the line width of this decoration
DecorationLengthMenuItemTitle = Length
DecorationLengthMenuItemToolTip = Select this to change the length of this decoration
DecorationGapMenuItemTitle = Space
DecorationGapMenuItemToolTip = Select this to change the space between multiple decorations
DecorationFlipMenuItemTitle = Flip
DecorationFlipMenuItemToolTip = Select this to flip the direction of the decorations for this track

# Arrows
ArrowsMenuTitle = Arrows
ArrowsMenuToolTip = Select this menu to change arrow decoration settings for this track
ArrowsDirectionMenuTitle = Direction
ArrowsDirectionMenuToolTip = Select the direction to point the arrows
ArrowsDirectionInMenuItemTitle = In
ArrowsDirectionInMenuItemToolTip = Select this to draw arrows pointing in
ArrowsDirectionOutMenuItemTitle = Out
ArrowsDirectionOutMenuItemToolTip = Select this to draw arrows pointing out
ArrowsDirectionBothMenuItemTitle = Both
ArrowsDirectionBothMenuItemToolTip = Select this to draw arrow(s) pointing in and out

# Bridge
BridgeMenuTitle = Bridge
BridgeMenuToolTip = Select this menu to change bridge decoration settings for this track
BridgeApproachWidthMenuItemTitle = Approach Width
BridgeApproachWidthMenuItemToolTip = Select this to change the width of the approaches on the bridge decoration for this track
BridgeDeckWidthMenuItemTitle = Deck Width
BridgeDeckWidthMenuItemToolTip = Select this to change the distance between the sides of the bridge decorations for this track

# End Bumper
EndBumperMenuTitle = End Bumpers
EndBumperMenuToolTip = Select this menu to change the end bumper decoration settings for this track

# Tunnel
TunnelMenuTitle = Tunnel
TunnelMenuToolTip = Select this menu to change the tunnel decoration settings for this track
TunnelFloorWidthMenuItemTitle = Floor Width
TunnelFloorWidthMenuItemToolTip = Select this menu to change the tunnel floor width
TunnelEntranceWidthMenuItemTitle = Entrance Width
TunnelEntranceWidthMenuItemToolTip = Select this menu to change the tunnel entrance width
Original file line number Diff line number Diff line change
Expand Up @@ -2667,7 +2667,8 @@ public void setSignalsAtXoverTurnout(@Nonnull MultiIconEditor theEditor,
xovers.add(layoutTurnout);
}
}
JComboBox jcb = new JComboBox(xovers.toArray());
JComboBox<LayoutTurnout> jcb = new JComboBox<>(
xovers.toArray(new LayoutTurnout[xovers.size()]));
jcb.setEditable(true);
JOptionPane.showMessageDialog(layoutEditor, jcb,
Bundle.getMessage("MakeLabel",
Expand Down
Loading

0 comments on commit 12064c5

Please sign in to comment.