Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@smutek
Created September 15, 2018 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smutek/85885372e82406a139d18906114d546b to your computer and use it in GitHub Desktop.
Save smutek/85885372e82406a139d18906114d546b to your computer and use it in GitHub Desktop.
CMIS 141 Week 4 Discussion
/*
* File: CreateAlertComponent.java
* Author: James Smutek
* Date: September 15, 2018
* Purpose: Create instances of Twitter Bootstrap's "Alert" Web Component
* @see: https://getbootstrap.com/docs/4.0/components/alerts/
*/
public class CreateAlertComponent {
// Variables
private int modifierKey;
private String modifier;
private String[] modifierValues = {
"default", "primary", "secondary", "success", "danger", "info", "warning", "light", "dark"
};
private String message;
private String markup;
/** Default Alert Component Constructor Creates a default instance of the alert component. */
public CreateAlertComponent() {
modifierKey = 0;
modifier = modifierValues[modifierKey];
message = "<p>This is the default alert type.</p>";
markup = buildMarkup(modifier, message);
}
/**
* Alert Component Constructor Creates an alert component.
*
* @param int modifierKey The array index of the desired component modifier.
* @param String message The message to display in the alert component instance.
*/
public CreateAlertComponent(int modifierKey, String message) {
this.modifierKey = modifierKey;
this.modifier = modifierValues[modifierKey];
this.message = message;
this.markup = buildMarkup(modifier, message);
}
/**
* Builds the HTML markup for the alert.
*
* @param modifier String. The desired modifier type.
* @param message String. The message to display in the alert.
* @return String. The assembled HTML markup.
*/
private String buildMarkup(String modifier, String message) {
return "<div class=\"alert alert-"
+ modifier
+ "\" role=\"alert\">\n"
+ " "
+ message
+ "\n"
+ "</div>";
}
/**
* Getter for the assembled HTML markup.
*
* @return
*/
public String getMarkup() {
return markup;
}
}
/*
* File: TestCreateAlertComponent.java
* Author: James Smutek
* Date: September 15, 2018
* Purpose: Test CreateAlertComponent
*/
public class TestCreateAlertComponent {
public static void main(String[] args) {
System.out.println();
// Default
CreateAlertComponent alert = new CreateAlertComponent();
System.out.println(alert.getMarkup());
System.out.println();
// Primary
String messagePrimary = "<p>This is the primary alert type.</p>";
CreateAlertComponent alertPrimary = new CreateAlertComponent(1, messagePrimary);
System.out.println(alertPrimary.getMarkup());
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment