Begin to add HTML generation helpers
This commit is contained in:
parent
b01bf6e129
commit
1980ff5fd8
9 changed files with 282 additions and 0 deletions
39
src/main/java/dev/zontreck/ariaslib/html/Background.java
Normal file
39
src/main/java/dev/zontreck/ariaslib/html/Background.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package dev.zontreck.ariaslib.html;
|
||||
|
||||
import dev.zontreck.ariaslib.html.bootstrap.Color;
|
||||
|
||||
public class Background extends Element
|
||||
{
|
||||
public Background ( Color color, boolean subtle, boolean gradient) {
|
||||
super ( "" );
|
||||
|
||||
bgColor=color;
|
||||
isSubtle=subtle;
|
||||
hasGradient=gradient;
|
||||
}
|
||||
|
||||
|
||||
public Color bgColor;
|
||||
public boolean isSubtle = false;
|
||||
public boolean hasGradient = false;
|
||||
|
||||
|
||||
/**
|
||||
* Generate a background string to be inserted into the class of a existing element
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "bg-" + bgColor.name ().toLowerCase ( ) + (isSubtle ? "-subtle" : "") + (hasGradient ? ".bg-gradient" : "");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a background string to be inserted into the class of a existing element
|
||||
*/
|
||||
public static String getBackgroundClass(Color color, boolean isSubtle, boolean hasGradient)
|
||||
{
|
||||
return "bg-"+color.name ().toLowerCase ( ) + (isSubtle ? "-subtle" : "") + (hasGradient ? ".bg-gradient" : "");
|
||||
}
|
||||
|
||||
}
|
37
src/main/java/dev/zontreck/ariaslib/html/Border.java
Normal file
37
src/main/java/dev/zontreck/ariaslib/html/Border.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package dev.zontreck.ariaslib.html;
|
||||
|
||||
import dev.zontreck.ariaslib.html.bootstrap.Color;
|
||||
|
||||
public class Border extends Element
|
||||
{
|
||||
public Border (Color color, boolean subtle) {
|
||||
super ( "" );
|
||||
|
||||
borderColor=color;
|
||||
isSubtle=subtle;
|
||||
}
|
||||
|
||||
|
||||
public Color borderColor;
|
||||
public boolean isSubtle = false;
|
||||
|
||||
|
||||
/**
|
||||
* Generate a border string to be inserted into the class of a existing element
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "border-" + borderColor.name ().toLowerCase ( ) + (isSubtle ? "-subtle" : "");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a border string to be inserted into the class of a existing element
|
||||
*/
|
||||
public static String getBorderClass(Color color, boolean isSubtle)
|
||||
{
|
||||
return "border-"+color.name ().toLowerCase ( ) + (isSubtle ? "-subtle" : "");
|
||||
}
|
||||
|
||||
}
|
52
src/main/java/dev/zontreck/ariaslib/html/Button.java
Normal file
52
src/main/java/dev/zontreck/ariaslib/html/Button.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package dev.zontreck.ariaslib.html;
|
||||
|
||||
import dev.zontreck.ariaslib.html.bootstrap.Color;
|
||||
|
||||
public class Button extends Element
|
||||
{
|
||||
public Color elementColor = Color.Primary;
|
||||
public boolean isOutline=false;
|
||||
public boolean isDisabled=false;
|
||||
|
||||
public enum ButtonSize
|
||||
{
|
||||
Normal,
|
||||
Large,
|
||||
Small
|
||||
}
|
||||
|
||||
public ButtonSize size = ButtonSize.Normal;
|
||||
|
||||
public String label = "Click me";
|
||||
|
||||
|
||||
public Button (String label) {
|
||||
super("button");
|
||||
this.label=label;
|
||||
}
|
||||
|
||||
private String getSizeText()
|
||||
{
|
||||
switch(size)
|
||||
{
|
||||
case Normal -> {
|
||||
return "";
|
||||
}
|
||||
case Large -> {
|
||||
return "btn-lg ";
|
||||
}
|
||||
case Small -> {
|
||||
return "btn-sm ";
|
||||
}
|
||||
default -> {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "<" + elementName + " type='button' class='btn " + getSizeText() + " " + (isDisabled?"disabled " : "") + "btn-" + (isOutline ? "outline-" : "") + elementColor.name ().toLowerCase ( )+ "'>" + label + "</" + elementName + ">";
|
||||
}
|
||||
}
|
39
src/main/java/dev/zontreck/ariaslib/html/DOM.java
Normal file
39
src/main/java/dev/zontreck/ariaslib/html/DOM.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package dev.zontreck.ariaslib.html;
|
||||
|
||||
public class DOM
|
||||
{
|
||||
/**
|
||||
* Generates a HTML Header that automatically includes dependencies
|
||||
* @return HTML
|
||||
*/
|
||||
public static String getHTMLHeader(String pageTitle)
|
||||
{
|
||||
return "<!doctype html>\n" +
|
||||
"<html lang=\"en\">\n" +
|
||||
" <head>\n" +
|
||||
" <!-- Required meta tags -->\n" +
|
||||
" <meta charset=\"utf-8\">\n" +
|
||||
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" +
|
||||
"\n" +
|
||||
" <!-- Bootstrap CSS -->\n" +
|
||||
" \n" +
|
||||
" <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM\" crossorigin=\"anonymous\">\n\n" +
|
||||
"\n" +
|
||||
" <title>"+pageTitle+"</title>\n" +
|
||||
" </head>\n" +
|
||||
" <body>\n" +
|
||||
"\n" +
|
||||
" <!-- Optional JavaScript; choose one of the two! -->\n" +
|
||||
"\n" +
|
||||
" <!-- Option 1: Bootstrap Bundle with Popper -->\n" +
|
||||
" \n" +
|
||||
" <script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz\" crossorigin=\"anonymous\"></script>\n\n" +
|
||||
"\n";
|
||||
}
|
||||
|
||||
|
||||
public static String closeHTML()
|
||||
{
|
||||
return "</body></html>";
|
||||
}
|
||||
}
|
11
src/main/java/dev/zontreck/ariaslib/html/Element.java
Normal file
11
src/main/java/dev/zontreck/ariaslib/html/Element.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package dev.zontreck.ariaslib.html;
|
||||
|
||||
public class Element
|
||||
{
|
||||
public String elementName;
|
||||
|
||||
public Element(String name)
|
||||
{
|
||||
elementName=name;
|
||||
}
|
||||
}
|
20
src/main/java/dev/zontreck/ariaslib/html/Opacity.java
Normal file
20
src/main/java/dev/zontreck/ariaslib/html/Opacity.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package dev.zontreck.ariaslib.html;
|
||||
|
||||
import dev.zontreck.ariaslib.util.Percent;
|
||||
|
||||
public class Opacity extends Element
|
||||
{
|
||||
public Opacity ( Percent val ) {
|
||||
super ( "" );
|
||||
value=val;
|
||||
}
|
||||
|
||||
public Percent value;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "bg-opacity-" + value.get();
|
||||
}
|
||||
}
|
19
src/main/java/dev/zontreck/ariaslib/html/TextColor.java
Normal file
19
src/main/java/dev/zontreck/ariaslib/html/TextColor.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package dev.zontreck.ariaslib.html;
|
||||
|
||||
import dev.zontreck.ariaslib.html.bootstrap.Color;
|
||||
|
||||
public class TextColor extends Element
|
||||
{
|
||||
public TextColor ( Color color ) {
|
||||
super ( "" );
|
||||
}
|
||||
|
||||
public Color color;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "text-" + color.name ().toLowerCase ( );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package dev.zontreck.ariaslib.html.bootstrap;
|
||||
|
||||
public enum Color
|
||||
{
|
||||
/**
|
||||
* Dark Blue
|
||||
*/
|
||||
Primary,
|
||||
|
||||
/**
|
||||
* Dark Gray
|
||||
*/
|
||||
Secondary,
|
||||
|
||||
/**
|
||||
* Dark Green
|
||||
*/
|
||||
Success,
|
||||
|
||||
/**
|
||||
* Dark Red
|
||||
*/
|
||||
Danger,
|
||||
|
||||
/**
|
||||
* Yellow
|
||||
*/
|
||||
Warning,
|
||||
|
||||
/**
|
||||
* Light Blue
|
||||
*/
|
||||
Info,
|
||||
|
||||
/**
|
||||
* Black
|
||||
*/
|
||||
Dark,
|
||||
|
||||
/**
|
||||
* Semi-gray
|
||||
*/
|
||||
Light,
|
||||
Black,
|
||||
White
|
||||
}
|
19
src/main/java/dev/zontreck/ariaslib/util/Percent.java
Normal file
19
src/main/java/dev/zontreck/ariaslib/util/Percent.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package dev.zontreck.ariaslib.util;
|
||||
|
||||
public class Percent
|
||||
{
|
||||
int current;
|
||||
int maximum;
|
||||
|
||||
public Percent(int cur, int max)
|
||||
{
|
||||
current=cur;
|
||||
maximum=max;
|
||||
}
|
||||
|
||||
|
||||
public int get()
|
||||
{
|
||||
return ((current * 100) / maximum);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue