88import edu .wpi .grip .core .events .ExceptionClearedEvent ;
99import edu .wpi .grip .core .events .ExceptionEvent ;
1010import edu .wpi .grip .ui .util .DPIUtility ;
11- import javafx .animation .FadeTransition ;
12- import javafx .animation .Timeline ;
11+ import javafx .animation .*;
1312import javafx .application .Platform ;
1413import javafx .geometry .HPos ;
1514import javafx .geometry .Insets ;
1615import javafx .geometry .VPos ;
17- import javafx .scene .Node ;
1816import javafx .scene .Parent ;
1917import javafx .scene .control .*;
18+ import javafx .scene .image .ImageView ;
2019import javafx .scene .layout .GridPane ;
2120import javafx .scene .layout .Priority ;
2221import javafx .scene .paint .Color ;
2524import javafx .util .Duration ;
2625import org .apache .commons .lang3 .text .WordUtils ;
2726import org .controlsfx .control .PopOver ;
28- import org .controlsfx .glyphfont .FontAwesome ;
29- import org .controlsfx .glyphfont .Glyph ;
3027
3128import java .util .Optional ;
3229
3330import static com .google .common .base .Preconditions .checkNotNull ;
3431
3532/**
3633 * Listens and responds to events posted by the {@link edu.wpi.grip.core.util.ExceptionWitness}
37- *
3834 */
3935public final class ExceptionWitnessResponderButton extends Button {
4036 @ VisibleForTesting
@@ -64,11 +60,13 @@ protected static class ExceptionPopOver extends PopOver {
6460
6561 private ExceptionPopOver (String title ) {
6662 super ();
63+
6764 setTitle (title );
6865 stackTrace .setEditable (false );
6966
7067 getStyleClass ().add (this .STYLE_CLASS );
7168 setHeaderAlwaysVisible (true );
69+ setDetachable (false );
7270
7371 GridPane .setHalignment (errorMessage , HPos .CENTER );
7472 GridPane .setValignment (errorMessage , VPos .CENTER );
@@ -98,6 +96,7 @@ private ExceptionPopOver(String title) {
9896
9997 /**
10098 * Assigns the contents of the popover using the data from the exception event.
99+ *
101100 * @param event The event that this popover should display.
102101 */
103102 private void assignFromExceptionEvent (ExceptionEvent event ) {
@@ -127,22 +126,33 @@ private void assignFromExceptionEvent(ExceptionEvent event) {
127126 */
128127 @ Inject
129128 ExceptionWitnessResponderButton (@ Assisted Object origin , @ Assisted String popOverTitle ) {
130- super (null , addFadeTransition (
131- new Glyph ("FontAwesome" , FontAwesome .Glyph .EXCLAMATION_TRIANGLE )
132- .color (Color .RED ).size (DPIUtility .MINI_ICON_SIZE )));
129+ super ();
130+
133131 this .origin = checkNotNull (origin , "The origin can not be null" );
134132 this .popOverTitle = checkNotNull (popOverTitle , "The pop over title can not be null" );
135133 this .tooltip = new Tooltip ();
136134 this .getStyleClass ().add (STYLE_CLASS );
137135
138- this . setOnAction ( event -> getPopover (). show ( this ) );
136+ ImageView icon = new ImageView ( "/edu/wpi/grip/ui/icons/warning.png" );
139137
140- this .setVisible (false );
138+ setOnMouseClicked (event -> getPopover ().show (this ));
139+ setVisible (false );
140+ setContentDisplay (ContentDisplay .GRAPHIC_ONLY );
141+ setGraphic (icon );
142+ icon .setFitWidth (DPIUtility .SMALL_ICON_SIZE );
143+ icon .setFitHeight (DPIUtility .SMALL_ICON_SIZE );
144+
145+ FadeTransition ft = new FadeTransition (Duration .millis (750 ), icon );
146+ ft .setToValue (0.1 );
147+ ft .setCycleCount (Transition .INDEFINITE );
148+ ft .setAutoReverse (true );
149+ ft .play ();
141150 }
142151
143152 /**
144153 * If the popover hasn't been created before then this creates the popover.
145154 * Otherwise it returns the popover that was constructed the first time this method was run.
155+ *
146156 * @return The popover for this button
147157 */
148158 private synchronized ExceptionPopOver getPopover () {
@@ -165,8 +175,6 @@ public void onExceptionEvent(ExceptionEvent event) {
165175 Platform .runLater (() -> {
166176 // Update the text of the tooltip to this event
167177 tooltip .setText (WordUtils .wrap (event .getMessage (), 90 , null , true ));
168- // The tooltip is removed when the exception is cleared
169- setTooltip (tooltip );
170178
171179 getPopover ().assignFromExceptionEvent (event );
172180 this .setVisible (true );
@@ -181,23 +189,7 @@ public void onExceptionClearedEvent(ExceptionClearedEvent event) {
181189 Platform .runLater (() -> {
182190 getPopover ().hide ();
183191 setVisible (false );
184- setTooltip (null );
185192 });
186193 }
187194 }
188-
189- /**
190- * Creates a fade transition on a node.
191- * @param node The node to add the transition too.
192- * @return The node that the transition is now applied to.
193- */
194- private static Node addFadeTransition (Node node ) {
195- FadeTransition ft = new FadeTransition (Duration .millis (750 ), node );
196- ft .setFromValue (1.0 );
197- ft .setToValue (0.1 );
198- ft .setCycleCount (Timeline .INDEFINITE );
199- ft .setAutoReverse (true );
200- ft .play ();
201- return node ;
202- }
203195}
0 commit comments