public code v1

This commit is contained in:
Francisco Jesús Martínez Mimbrera
2026-05-23 00:32:57 +02:00
commit 759a8968a2
4357 changed files with 163763 additions and 0 deletions
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>flintstones.group</groupId>
<artifactId>flintstones.bundles</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>flintstones.helper.html</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<name>[bundle] Html</name>
</project>
+45
View File
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>flintstones.helper.html</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1779484362612</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
@@ -0,0 +1,20 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Html
Bundle-SymbolicName: flintstones.helper.html
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: flintstones.helper.html
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: flintstones.helper.data;visibility:=reexport,
flintstones.helper.debug;visibility:=reexport,
org.eclipse.swt,
org.eclipse.equinox.registry,
org.eclipse.osgi
Export-Package: flintstones.helper.html,
flintstones.helper.html.browser,
flintstones.helper.html.svg,
flintstones.helper.html.svg.chart,
flintstones.helper.html.svg.components,
flintstones.helper.html.table,
flintstones.helper.html.tags
Eclipse-BundleShape: dir
@@ -0,0 +1,28 @@
.matrix {
position: relative;
margin: 0 auto;
}
.matrix::before, .matrix::after {
content: "";
position: absolute;
top: 0;
border: 1px solid #000;
width: 6px;
height: 100%;
}
.matrix::before {
left: -6px;
border-right: 0px;
}
.matrix::after {
right: -6px;
border-left: 0px;
}
.matrix td {
padding: 5px;
text-align: center;
}
@@ -0,0 +1,21 @@
html{
background-color: #F0F0F0;
margin: 0px;
}
body{
margin: 0px;
}
small{
color: white;
}
.disabled{
width: 100%;
height: 100%;
background-color: grey;
background-color: rgba(128, 128, 128, 0.3);
position: absolute;
top: 0;
left: 0;
z-index: 999;
}
@@ -0,0 +1,3 @@
var bodyTag = document.getElementsByTagName("body");
var d = '<small>' +window.location.href+ '</small>';
bodyTag[0].innerHTML = bodyTag[0].innerHTML + d;
@@ -0,0 +1,37 @@
var console=(function(oldCons){
return {
log: function(text){
jConsoleLog(text);
// Your code
},
info: function (text) {
jConsoleLog(text);
// Your code
},
warn: function (text) {
jConsoleLog(text);
// Your code
},
error: function (text) {
jConsoleLog(text);
// Your code
}
};
}(window.console));
//Then redefine the old console
window.console = console;
console.log("Calm down");
function a(){
console.log("Wenas java 1");
console.log("Calm down a 1");
var p = prueba(1);
console.log(p);
console.log("Wenas java 2");
console.log("Calm down a 2");
}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e.snarkdown=n()}(this,function(){function e(e){return e.replace(RegExp("^"+(e.match(/^(\t| )+/)||"")[0],"gm"),"")}function n(e){return e.replace(/"/g,"&quot;")}function r(o){function c(e){var n=e.replace(/\*/g,"_").replace(/^( {2}\n\n*|\n{2,})/g,"\n\n"),r=f[f.length-1]===e,o=t[n];return o?o[1]?(f[r?"pop":"push"](e),o[r?1:0]):o[0]:e}function a(){for(var e="",n=f.length;n--;)e+=c(f[n]);return e}var l,u,s,p,g,i=/(?:^```(\w*)\n([\s\S]*?)\n```$)|((?:(?:^|\n+)(?:\t| {2,}).+)+\n*)|((?:(?:^|\n)([>*+-]|\d+\.)\s+.*)+)|(?:\!\[([^\]]*?)\]\(([^\)]+?)\))|(\[)|(\](?:\(([^\)]+?)\))?)|(?:(?:^|\n+)([^\s].*)\n(\-{3,}|={3,})(?:\n+|$))|(?:(?:^|\n+)(#{1,3})\s*(.+)(?:\n+|$))|(?:`([^`].*?)`)|( \n\n*|\n{2,}|__|\*\*|[_*])/gm,f=[],d="",m=0,h={};for(o=o.replace(/^\n+|\n+$/g,"").replace(/^\[(.+?)\]:\s*(.+)$/gm,function(e,n,r){return h[n.toLowerCase()]=r,""});s=i.exec(o);)u=o.substring(m,s.index),m=i.lastIndex,l=s[0],u.match(/[^\\](\\\\)*\\$/)||(s[2]||s[3]?l='<pre class="code '+(s[3]?"poetry":s[1].toLowerCase())+'">'+e((s[2]||s[3]).replace(/^\n+|\n+$/g,""))+"</pre>":s[5]?(g=s[5],"."===g.charAt(g.length-1)&&(g=".",s[4]=s[4].replace(/^\d+/gm,"")),p=r(e(s[4].replace(/^\s*[>*+.-]/gm,""))),">"!==g&&(g="."===g?"#":"*",p=p.replace(/^(.*)(\n|$)/gm,"<li>$1</li>")),l=t[g][0]+p+t[g][1]):s[7]?l='<img src="'+n(s[7])+'" alt="'+n(s[6])+'">':s[9]?(d=d.replace("<a>",'<a href="'+n(s[10]||h[u.toLowerCase()])+'">'),l=a()+"</a>"):s[8]?l="<a>":s[11]||s[13]?(g="h"+(s[13]?s[13].length:"="===s[12][0]?1:2),l="<"+g+">"+r(s[11]||s[14])+"</"+g+">"):s[15]?l="<code>"+s[15]+"</code>":s[16]&&(l=c(s[16]))),d+=u,d+=l;return(d+o.substring(m)+a()).trim()}var t={_:["<em>","</em>"],__:["<strong>","</strong>"],"\n\n":["<br />"],">":["<blockquote>","</blockquote>"],"*":["<ul>","</ul>"],"#":["<ol>","</ol>"]};return r});
//# sourceMappingURL=snarkdown.umd.js.map
@@ -0,0 +1,12 @@
/* Library snarkdown umd */
%s
var target = document.getElementById("content");
var source = document.getElementById("markdown-text");
var converter = new showdown.Converter(),
text = source.innerHTML,
html = converter.makeHtml(text);
target.innerHTML = html;
@@ -0,0 +1,8 @@
/* Library snarkdown umd */
%s
var target = document.getElementById("content");
var source = document.getElementById("markdown-text");
var html = snarkdown(source.innerHTML);
target.innerHTML = html;
@@ -0,0 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
assets/
@@ -0,0 +1,54 @@
package flintstones.helper.html;
import org.eclipse.swt.widgets.Composite;
import org.osgi.framework.FrameworkUtil;
import flintstones.helper.FileHelper;
import flintstones.helper.html.function.JConsoleFunction;
import flintstones.helper.html.function.JConsoleLog;
/**
* The Class HtmlTextTable.
*/
public class HtmlExp extends HtmlWidget {
/** The html. */
private StringBuilder html = new StringBuilder();
/**
* Instantiates a new html table.
*
* @param base the base
* @param values the values
* @param vertical the vertical
*/
public HtmlExp(Composite base) {
super(base);
new JConsoleLog(browser, "jConsoleLog");
new JConsoleFunction(browser, "prueba");
html.append("<button type=\"button\" onclick=\"a();\">Click Me!</button>");
html.append("<button type=\"button\" onclick=\"out();\">Click Me!</button>");
}
/* (non-Javadoc)
* @see flintstones.helper.html.table.HtmlWidget#getResult()
*/
@Override
protected String getResult() {
return html.toString();
}
@Override
String getScript() {
String js = FileHelper.readFile("./assets/js/exp.js", FrameworkUtil.getBundle(getClass()));
StringBuilder sb = new StringBuilder();
sb.append(js);
return sb.toString();
}
}
@@ -0,0 +1,123 @@
package flintstones.helper.html;
import java.io.IOException;
import java.net.URL;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.swt.widgets.Composite;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;
import flintstones.helper.FileHelper;
import flintstones.helper.html.tags.Div;
import flintstones.helper.html.tags.HtmlTag;
import flintstones.helper.html.tags.Text;
/**
* The Class HtmlMarkdown.
*/
public class HtmlMarkdown extends HtmlWidget {
/**
* Instantiates a new html markdown.
*
* @param base the base
*/
public HtmlMarkdown(Composite base) {
super(base);
HtmlTag div = body.add(new Div());
div.setId("content");
}
public void setFile(String markdownFile) {
setFile(markdownFile,null);
}
public void setFile(String markdownFile, Bundle bundle) {
if(bundle != null)
markdownFile = fixImagesPath(markdownFile, bundle);
HtmlTag div = body.add(new Div());
div.setId("markdown-text");
div.addClass("markdown-invisible");
div.add(new Text(markdownFile));
}
/* (non-Javadoc)
* @see flintstones.helper.html.table.HtmlWidget#getResult()
*/
@Override
protected String getResult() {
return body.toString();
}
/* (non-Javadoc)
* @see flintstones.helper.html.table.HtmlWidget#getScript()
*/
@Override
String getScript() {
String markdownLibrary = FileHelper.readFile("./assets/js/showdown.min.js", FrameworkUtil.getBundle(getClass()));
String jsTemplate = FileHelper.readFile("./assets/templates/showdown.template.js", FrameworkUtil.getBundle(getClass()));
StringBuilder sb = new StringBuilder();
sb.append(String.format(jsTemplate, markdownLibrary));
return sb.toString();
}
/* (non-Javadoc)
* @see flintstones.helper.html.table.HtmlWidget#getStyle()
*/
@Override
protected String getStyle(){
return ".markdown-invisible {display: none;} #content{text-align: justify !important;} img { width: 100%; } pre {background-color: aliceblue; }";
}
/**
* Fix images path to point the path in the filesystem
* Convert:
* ![imagen](borrar/tpr.jpg)
* into:
* [imagen](file:/C:/Users/igmunoz/Desktop/Eclipse RCP/eclipse/../flintstones/bundles/flintstones.application.debug/borrar/tpr.jpg)
*
* @param markdown the markdown
* @param bundle the bundle
* @return the string
*/
private String fixImagesPath(String markdown, Bundle bundle) {
StringBuilder sb = new StringBuilder();
for(String line : markdown.split("\n")) {
// Image linea
if(line.startsWith("!")) {
String[] parts = line.split("\\(");
// Online images will not be processed
String path = parts[1].replace(")","");
if(path.startsWith("http"))
continue;
URL url = bundle.getEntry(path);
String diskPath = null;
try {
URL fileUrl = FileLocator.toFileURL(url);
diskPath = fileUrl.toString();
} catch (IOException | NullPointerException e ) {
e.printStackTrace();
// return "# Fichero no encontrado " + url;
}
diskPath = diskPath.replaceAll(" ", "%20");
line = parts[0] + "(" + diskPath + ")";
}
sb.append(line);
sb.append("\n");
}
return sb.toString();
}
}
@@ -0,0 +1,41 @@
package flintstones.helper.html;
import org.eclipse.swt.widgets.Composite;
import org.osgi.framework.FrameworkUtil;
import flintstones.helper.FileHelper;
import flintstones.helper.html.tags.B;
import flintstones.helper.html.tags.HtmlTag;
import flintstones.helper.html.tags.Table;
import flintstones.helper.html.tags.Td;
import flintstones.helper.html.tags.Text;
import flintstones.helper.html.tags.Tr;
public class HtmlMatrix extends HtmlWidget {
public HtmlMatrix(Composite base, String[][] values) {
super(base);
HtmlTag table = body.add(new Table());
table.addClass("matrix");
for (String[] row : values) {
HtmlTag tr = table.add(new Tr());
for (String val : row) {
HtmlTag td = tr.add(new Td());
td.add(new B().add(new Text(val)));
}
}
}
@Override
protected String getResult() {
return body.toString();
}
@Override
protected String getStyle() {
return FileHelper.readFile("./assets/css/ahpmatrix.css", FrameworkUtil.getBundle(getClass()));
}
}
@@ -0,0 +1,189 @@
package flintstones.helper.html;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map.Entry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.osgi.framework.FrameworkUtil;
import flintstones.helper.FileHelper;
import flintstones.helper.html.tags.Body;
import flintstones.helper.html.tags.Div;
import flintstones.helper.html.tags.HtmlTag;
/**
* The Class HtmlWidget.
*/
public abstract class HtmlWidget {
/** The base. */
Composite base;
/** The browser. */
protected Browser browser;
protected HtmlTag disabled = new Div();
protected HtmlTag body = new Body();
boolean debug = false;
boolean isDisabled = false;
private HashMap<String, HashMap<String, String>> userCss = new HashMap<>();
/**
* Instantiates a new html widget.
*
* @param base the base
*/
public HtmlWidget(Composite base) {
this.base = base;
// If the composite to draw had an HtmlWidget, it just delete it so this new
// widget will replace it.
// It the composite have any other item, exception.
if (base.getChildren().length > 0) {
Arrays.stream(base.getChildren()).forEach(k -> {
if (k instanceof Browser) {
k.dispose();
} else {
throw new RuntimeException("Composite must have a HTMLWidget or be empty");
}
});
}
base.setLayout(new FillLayout());
browser = new Browser(base, SWT.NONE);
browser.setText("");
base.layout();
body.add(disabled);
}
/**
* Render.
*/
public void render() {
StringBuilder sb = new StringBuilder();
sb.append("<html><!DOCTYPE html>");
sb.append(getResult());
// Style
sb.append("<style>");
sb.append(getBaseStyle());
sb.append(getStyle());
sb.append(getUserStyle());
sb.append("</style>");
// Script
sb.append("<script>");
sb.append(getBaseScript());
sb.append(getScript());
sb.append("</script>");
sb.append("</html>");
browser.setText(sb.toString());
}
/**
* Gets the result.
*
* @return the result
*/
protected abstract String getResult();
/**
* Gets the style.
*
* @return the style
*/
protected String getStyle() {
return "";
};
/**
* Gets the script.
*
* @return the script
*/
String getScript() {
return "";
};
/**
* Gets the base style.
*
* @return the base style
*/
private String getBaseStyle() {
return FileHelper.readFile("./assets/css/widget.css", FrameworkUtil.getBundle(getClass()));
}
private String getBaseScript() {
if (!debug)
return "";
return FileHelper.readFile("./assets/js/debug.js", FrameworkUtil.getBundle(getClass()));
}
/**
* Gets the parent.
*
* @return the parent
*/
public Composite getParent() {
return base;
}
public void setCss(String selector, String key, String value) {
HashMap<String, String> selectorMap = userCss.get(selector);
if (selectorMap == null)
selectorMap = new HashMap<>();
selectorMap.put(key, value);
userCss.put(selector, selectorMap);
}
private String getUserStyle() {
StringBuilder sb = new StringBuilder();
for (Entry<String, HashMap<String, String>> selectorEntry : userCss.entrySet()) {
String selector = selectorEntry.getKey();
sb.append(selector);
sb.append("{ ");
for (Entry<String, String> propertyEntry : selectorEntry.getValue().entrySet()) {
String key = propertyEntry.getKey();
String val = propertyEntry.getValue();
sb.append(key);
sb.append(":");
sb.append(val);
sb.append(";");
}
sb.append("}");
}
return sb.toString();
}
public Browser getBrowser() {
return browser;
}
public void setEnabled(boolean isEnabled) {
if (isEnabled)
disabled.deleteClass("disabled");
else
disabled.addClass("disabled");
render();
}
}
@@ -0,0 +1,68 @@
package flintstones.helper.html.browser;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
import flintstones.helper.debug.DH;
import flintstones.helper.html.HtmlWidget;
public class BrowserShell {
private HtmlWidget widget;
private final Shell shell;
public BrowserShell() {
shell = new Shell(
Display.getDefault().getActiveShell(),
SWT.RESIZE |
SWT.MAX |
SWT.MIN |
SWT.CLOSE |
SWT.SYSTEM_MODAL
);
shell.setLayout(new GridLayout(2, false));
shell.setBackgroundMode(SWT.INHERIT_FORCE);
// Toolbar
Menu menuBar = new Menu(shell, SWT.BAR);
MenuItem addFirebugItem = new MenuItem(menuBar, SWT.PUSH);
addFirebugItem.setText("Debugger");
addFirebugItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
widget.getBrowser().setUrl("javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new%20Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');");
}
});
shell.setMenuBar(menuBar);
}
public Shell get() {
return shell;
}
public void setWidget(HtmlWidget widget) {
this.widget = widget;
}
public void open() {
DH.out("Hook things here");
shell.open();
}
}
@@ -0,0 +1,20 @@
package flintstones.helper.html.function;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.BrowserFunction;
import flintstones.helper.debug.DH;
public class JConsoleFunction extends BrowserFunction {
public JConsoleFunction(Browser browser, String name) {
super(browser, name);
}
@Override
public Object function(Object[] arguments) {
DH.out(arguments);
return 1;
}
}
@@ -0,0 +1,19 @@
package flintstones.helper.html.function;
import flintstones.helper.debug.DH;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.browser.BrowserFunction;
public class JConsoleLog extends BrowserFunction {
public JConsoleLog(Browser browser, String name) {
super(browser, name);
}
@Override
public Object function(Object[] arguments) {
DH.out(arguments);
return null;
}
}
@@ -0,0 +1,179 @@
package flintstones.helper.html.svg;
import flintstones.helper.html.tags.Text;
public class Svg {
public static enum LineStroke{ Normal, Dotted, Dashed };
public static enum CircleStroke{ Normal, Small, Big, Hollow };
public static Tag getVerticalLine(int x, int ystart, int size) {
return getLine(x, ystart, x, ystart + size);
}
public static Tag getHorizontalLine(int xstart, int y, int size) {
return getLine(xstart, y, xstart+size, y);
}
public static Tag getLine(int x, int y, int nx, int ny) {
// <line y1="40" x1="60" y2="1000" x2="60" stroke-width="5" fill="none" stroke="#000" >
Tag line = (Tag) new Tag("line")
.attr("y1",y)
.attr("y2",ny)
.attr("x1",x)
.attr("x2",nx)
.attr("stroke-width", 2)
.attr("fill", "none")
.attr("stroke", "#000");
return line;
}
public static void addStroke(Tag tag, int textsize, LineStroke stroke) {
if(stroke.equals(LineStroke.Dashed))
tag.attr("stroke-dasharray",(textsize/4)*5);
if(stroke.equals(LineStroke.Dotted))
tag.attr("stroke-dasharray",(textsize/4)*1.5);
}
public static Tag getText(int x, int y, int size, String textcontent) {
// <text dx="-22.5" x="810" y="1040" font-size="30" >555</text>
// int chars = textcontent.length();
// double mchars = (double)chars/4;
double mheight = (size*0.6)/2; // 0.6 -> Ratio alto-ancho de fuentes habitual.
Tag text = (Tag) new Tag("text")
.attr("x", x)
.attr("y", y )
// .attr("dx",-(mchars*size) )
.attr("dy", mheight)
.attr("text-anchor","middle")
.attr("font-size", size);
text.add(new Text(textcontent));
return text;
}
public static Tag getLeftMarker(int x, int y, int size, String textcontent) {
Tag group = new Tag("g");
Tag line = getHorizontalLine(x-(size/2), y, size);
Tag text = getText(x - size - size/2, y ,size, textcontent);
group.add(line);
group.add(text);
return group;
}
public static Tag getBottomMarker(int x, int y, int size, String textcontent) {
// <g ><line y1="990" x1="810" y2="1005" x2="810" stroke-width="2" fill="none" stroke="#000" ></line><text dx="-22.5" x="810" y="1040" font-size="30" >555</text></g>
Tag group = new Tag("g");
Tag line = getVerticalLine(x, y-(size/2), size);
Tag text = getText(x, y + size ,size, textcontent);
group.add(line);
group.add(text);
return group;
}
public static Tag getStar(int x, int y, int size) {
//<polygon transform="translate(795,525) scale(0.14285714285714285,0.14285714285714285)" points="100,10 40,198 190,78 10,78 160,198" ></polygon>
String points = "100,10 40,198 190,78 10,78 160,198";
int originalSize = 210;
double prod = (double) size/originalSize;
int tx = x - size/2;
int ty = y - size/2;
String translate = "translate("+tx+","+ty+")";
String scale = "scale("+prod+","+prod+")";
Tag star = (Tag) new Tag("polygon")
.attr("transform", translate + " " + scale )
.attr("points", points);
return star;
}
public static Tag getDot(int x, int y, int size) {
return getDot(x,y,size,CircleStroke.Normal);
}
public static Tag getDot(int x, int y, int size, CircleStroke stroke) {
if(stroke.equals(CircleStroke.Small))
size *= 2;
if(stroke.equals(CircleStroke.Normal))
size *= 5;
if(stroke.equals(CircleStroke.Big))
size *= 10;
// <circle cx="46" cy="45" r="40"></circle>
Tag circle = (Tag) new Tag("circle")
.attr("cx", x )
.attr("cy", y )
.attr("r", size);
return circle;
}
public static Tag getEllipse(int x, int y, int rx, int ry, CircleStroke stroke) {
Tag circle = (Tag) new Tag("ellipse")
.attr("cx", x )
.attr("cy", y )
.attr("rx", rx)
.attr("ry", ry)
.attr("fill","none")
.attr("stroke","black")
.attr("stroke-width","2");
return circle;
}
public static Tag getRectangle(int x, int y, int x2, int y2) {
int width = x2-x;
int height = y2-y;
Tag rect = (Tag) new Tag("rect")
.attr("x",x)
.attr("y",y)
.attr("width",width)
.attr("height",height)
.attr("fill","none")
.attr("style","stroke:black; stroke-width: 2");
return rect;
}
public static Tag getBox(int x, int y, int x2, int y2) {
int width = x2-x;
int height = y2-y;
Tag rect = (Tag) new Tag("rect")
.attr("x",x)
.attr("y",y)
.attr("width",width)
.attr("height",height);
// .attr("style","stroke:black; stroke-width: 2");
return rect;
}
}
@@ -0,0 +1,44 @@
package flintstones.helper.html.svg;
import org.eclipse.swt.widgets.Composite;
import flintstones.helper.html.HtmlWidget;
import flintstones.helper.html.svg.chart.SvgChartCanvas;
public class SvgBrowser extends HtmlWidget {
SvgCanvas canvas;
public SvgBrowser(Composite base) {
super(base);
}
public SvgBrowser(Composite base, SvgChartCanvas canvas) {
super(base);
this.canvas = canvas;
}
public void setCanvas(SvgCanvas canvas){
this.canvas = canvas;
}
@Override
protected String getResult() {
System.out.println(canvas);
return canvas.toString();
}
@Override
protected String getStyle() {
return "html, body { margin:0; padding:0; overflow:hidden; background-color: white; } svg { position: absolute; top: 5%; left: 5%; width: 90%; height: 90%; } text:hover {\r\n" +
" paint-order: stroke;\r\n" +
" stroke: #000000;\r\n" +
" stroke-width: 1px;\r\n" +
" stroke-linecap: butt;\r\n" +
" stroke-linejoin: miter;\r\n" +
"}";
};
}
@@ -0,0 +1,5 @@
package flintstones.helper.html.svg;
public class SvgCanvas {
}
@@ -0,0 +1,11 @@
package flintstones.helper.html.svg;
import flintstones.helper.html.tags.HtmlTag;
public class Tag extends HtmlTag {
public Tag(String name) {
super(name);
}
}
@@ -0,0 +1,217 @@
package flintstones.helper.html.svg.chart;
import flintstones.helper.DoubleHelper;
import flintstones.helper.html.svg.Svg;
import flintstones.helper.html.svg.Tag;
import flintstones.helper.html.svg.Svg.CircleStroke;
import flintstones.helper.html.svg.components.LineSeries;
import flintstones.helper.html.svg.components.Point;
public class SvgChart extends SvgChartCanvas {
double maxX;
double maxY;
public SvgChart(int sizeX, int sizeY, double maxX, double maxY) {
super(sizeX,sizeY);
this.maxX = maxX;
this.maxY = maxY;
Tag vline = (Tag) Svg.getVerticalLine(ix, iy, canvasHeigth).attr("stroke-width", 5);
Tag hline = (Tag) Svg.getHorizontalLine(ix, tHeight, canvasWidth).attr("stroke-width", 5);
svg.add(vline);
svg.add(hline);
}
public void drawMarkers(boolean left, boolean bottom, double distance) {
if(bottom) {
for(double i = 0.0; i < maxX; i+= distance) {
Double xper = getXPer(i);
Tag x = getBottonMarker(xper, DoubleHelper.Draw(i));
svg.add(x);
}
}
if(left) {
for(double i = 0.0; i < maxY; i+= distance) {
Double yper = getYPer(i);
Tag x = getLeftMarker(yper, DoubleHelper.Draw(i));
svg.add(x);
}
}
}
public Tag drawHorizontalLine(double ypos, double xposStart, double xposEnd) {
return drawLine(xposStart, ypos, xposEnd, ypos);
}
public Tag drawHorizontalLine(double ypos) {
return drawHorizontalLine(ypos,0,maxX);
}
//
public Tag drawVerticalLine(double xpos) {
return drawVerticalLine(xpos,0,maxY);
}
public Tag drawVerticalLine(double xpos, double yposStart, double yposEnd) {
return drawLine(xpos, yposStart, xpos, yposEnd);
}
//
public Tag drawLine(double xposStart, double yposStart, double xposEnd, double yposEnd) {
Double xperStart = getXPer(xposStart);
Double xperEnd = getXPer(xposEnd);
Double yperStart = getYPer(yposStart);
Double yperEnd = getYPer(yposEnd);
Tag line = getLine(xperStart, yperStart, xperEnd, yperEnd);
svg.add(line);
return line;
}
//
public Tag drawText(double xpos, double ypos, double yperExtra, String text) {
Double xper = getXPer(xpos);
Double yper = getYPer(ypos);
Tag textE = getText(xper, yper + yperExtra, text);
svg.add(textE);
return textE;
}
//
public Tag drawBottonMarker(double xpos, String text) {
Double xper = getXPer(xpos);
Tag x = getBottonMarker(xper, text);
svg.add(x);
return x;
}
//
public Tag drawLeftMarker(double ypos, String text) {
Double yper = getYPer(ypos);
Tag x = getLeftMarker(yper, text);
svg.add(x);
return x;
}
public Tag drawStar(double xpos, double ypos) {
Double xper = getXPer(xpos);
Double yper = getYPer(ypos);
Tag x = getStar(xper, yper);
svg.add(x);
return x;
}
public Tag drawBox(double xposStart, double yposStart, double xposEnd, double yposEnd) {
Double xperStart = getXPer(xposStart);
Double xperEnd = getXPer(xposEnd);
Double yperStart = getYPer(yposStart);
Double yperEnd = getYPer(yposEnd);
Tag rect = getBox(xperStart, yperStart, xperEnd, yperEnd);
svg.add(rect);
return rect;
}
//
// public Tag drawHollowCircle(double xper, double yper, int size ) {
// Tag x = getHollowCircle(xper, yper, size);
// svg.add(x);
// return x;
// }
//
// public Tag drawDot(double xper, double yper) {
// return drawDot(xper, yper, ts/10, CircleStroke.Normal);
// }
//
public Tag drawPoint(Point point, CircleStroke stroke) {
Double xper = getXPer(point.getFirst());
Double yper = getYPer(point.getSecond());
Tag x = getDot(xper, yper, ts, stroke);
svg.add(x);
return x;
}
public Tag drawLineSeries(LineSeries series) {
Double x = null;
Double y = null;
String color = series.getColor();
boolean showLegend = series.showLegend();
Tag g = new Tag("g");
for(Point point : series.getPoints()) {
Double nx = getXPer(point.getFirst());
Double ny = getYPer(point.getSecond());
Tag dot = (Tag) getDot(nx, ny, ts/10, CircleStroke.Small)
.attr("stroke",color)
.attr("stroke-width",5)
.attr("fill", color);
g.add(dot);
if(x != null && y != null) {
Tag line = getLine(x, y, nx, ny);
g.add(line)
.attr("stroke",color)
.attr("stroke-width",5);
}
// Valus on the top of the point
String p1Name = DoubleHelper.Draw(point.getFirst());
String p2Name = DoubleHelper.Draw(point.getSecond());
if(showLegend) {
Tag pointName = getText(nx, ny+3, p1Name + " | " + p2Name );
g.add(pointName);
}
if(series.showMarkers()) {
Tag bottomMarker = getBottonMarker(nx, p1Name);
svg.add(bottomMarker);
}
if(series.showMarkers()) {
Tag leftMarker = getLeftMarker(ny, p2Name);
svg.add(leftMarker);
}
x = nx;
y = ny;
}
svg.add(g);
return g;
}
public double getXPer(double xval) {
return (xval / maxX)*100;
}
public double getYPer(double yval) {
return (yval / maxY)*100;
}
}
@@ -0,0 +1,169 @@
package flintstones.helper.html.svg.chart;
import flintstones.helper.html.svg.Svg;
import flintstones.helper.html.svg.SvgCanvas;
import flintstones.helper.html.svg.Tag;
import flintstones.helper.html.svg.Svg.CircleStroke;
public class SvgChartCanvas extends SvgCanvas {
// Data
protected int canvasHeigth;
protected int canvasWidth;
protected int ix;
protected int iy;
protected int ts;
protected Tag svg;
protected int tHeight;
protected int tWidth;
public SvgChartCanvas(int sizeX, int sizeY) {
// Fill vars
canvasHeigth = sizeY;
canvasWidth = sizeX;
ix = canvasWidth / 25;
iy = canvasHeigth / 25;
ts = canvasHeigth > canvasWidth ? canvasHeigth / 50 : canvasWidth / 50;
tHeight = canvasHeigth + iy;
tWidth = canvasWidth + ix;
svg = (Tag) new Tag("svg")
.attr("xmlns","http://www.w3.org/2000/svg")
.attr("viewbox", "0 0 " + tWidth + " " + tHeight)
.attr("width", "100%")
.attr("height", "100%");
}
protected Tag getHorizontalLine(double yper, double xperStart, double xperEnd) {
return getLine(xperStart, yper, xperEnd, yper);
}
protected Tag getHorizontalLine(double yper) {
return getHorizontalLine(yper,0,100);
}
protected Tag getVerticalLine(double xper) {
return getVerticalLine(xper,0,100);
}
protected Tag getVerticalLine(double xper, double yperStart, double yperEnd) {
return getLine(xper, yperStart, xper, yperEnd);
}
protected Tag getLine(double xperStart, double yperStart, double xperEnd, double yperEnd) {
int xmin = realocateX(xperStart);
int xmax = realocateX(xperEnd);
int ymin = realocateY(yperStart);
int yend = realocateY(yperEnd);
Tag line = Svg.getLine(xmin+ix, ymin+iy, xmax+ix, yend+iy);
return line;
}
protected Tag getText(double xper, double yper, String text) {
int x = realocateX(xper);
int y = realocateY(yper);
Tag textTag = Svg.getText(x+ix, y+iy, ts, text);
return textTag;
}
protected Tag getBottonMarker(double xper, String text) {
int x = realocateX(xper);
Tag marker = Svg.getBottomMarker(x+ix, canvasHeigth + iy, ts, text);
return marker;
}
protected Tag getLeftMarker(double yper, String text) {
int y = realocateY(yper);
Tag marker = Svg.getLeftMarker(ix, y+iy, ts, text);
return marker;
}
protected Tag getStar(double xper, double yper) {
int x = realocateX(xper);
int y = realocateY(yper);
Tag star = Svg.getStar(ix+x, y+iy,ts);
return star;
}
protected Tag getBox(double xperStart, double yperStart, double xperEnd, double yperEnd) {
int xmin = realocateX(xperStart);
int xmax = realocateX(xperEnd);
int ymin = realocateY(yperStart);
int yend = realocateY(yperEnd);
return Svg.getBox(xmin+ix, ymin+iy, xmax+ix, yend+iy);
}
protected Tag getHollowCircle(double xper, double yper, int size ) {
CircleStroke stroke = CircleStroke.Hollow;
int x = realocateX(xper);
int y = realocateY(yper);
int rx = realocateX(size);
int ry = realocateY(100-size);
Tag elip = Svg.getEllipse(ix+x, y+iy,rx,ry,stroke);
return elip;
}
protected Tag getDot(double xper, double yper) {
return getDot(xper, yper, ts/10, CircleStroke.Normal);
}
protected Tag getDot(double xper, double yper, int size, CircleStroke stroke) {
int x = realocateX(xper);
int y = realocateY(yper);
Tag circle = Svg.getDot(ix+x, y+iy,size,stroke);
return circle;
}
private int realocateX(double xper) {
if(xper < 0.0 || xper > 100.0)
throw new RuntimeException("XPer Between 0,100 :( -> " + xper);
double prod = (double)canvasWidth / 100.0;
return (int) (xper*prod);
}
private int realocateY(double yper) {
yper = 100.0 - yper;
if(yper < 0 || yper > 100.0)
throw new RuntimeException("YPer Between 0,100 :( -> " + yper);
double prod = (double)canvasHeigth / 100.0;
return (int) (yper*prod);
}
@Override
public String toString() {
return svg.toString();
}
}
@@ -0,0 +1,56 @@
package flintstones.helper.html.svg.components;
import java.util.ArrayList;
import java.util.List;
public class LineSeries {
List<Point> points = new ArrayList<>();
boolean showLegend = false;
boolean showMarkers = false;
String color = "#ffffff";
public LineSeries() {}
public LineSeries(double[][] pointsM) {
for(double[] arr : pointsM) {
Point p = new Point(arr[0], arr[1]);
points.add(p);
}
}
public void add(Point p) {
points.add(p);
}
public void add(double a, double b) {
Point p = new Point(a, b);
points.add(p);
}
public void setColor(String color) {
this.color = color;
}
public String getColor() {
return color;
}
public void showLegend(boolean x) {showLegend = x;}
public boolean showLegend() {return showLegend;}
public void showMarkers(boolean x) {showMarkers = x;}
public boolean showMarkers() {return showMarkers;}
public List<Point> getPoints(){
return points;
}
}
@@ -0,0 +1,16 @@
package flintstones.helper.html.svg.components;
public class Point {
double a;
double b;
public Point(double a, double b) {
this.a = a;
this.b = b;
}
public double getFirst() {return a;}
public double getSecond() {return b;}
}
@@ -0,0 +1,310 @@
package flintstones.helper.html.table;
import java.util.LinkedHashMap;
import java.util.Map;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import flintstones.helper.html.HtmlWidget;
import flintstones.helper.html.tags.B;
import flintstones.helper.html.tags.HtmlTag;
import flintstones.helper.html.tags.Table;
import flintstones.helper.html.tags.Td;
import flintstones.helper.html.tags.Text;
import flintstones.helper.html.tags.Tr;
/**
* The Class HtmlTable.
*/
class GenericHtmlTable extends HtmlWidget {
private int row = 0;
private int col = 0;
private int numRows = 0;
private int numCols = 0;
private Composite base;
private Map<HtmlTag, String[]> content;
/**
* Instantiates a new html table.
*
* @param base the base
* @param values the values
* @param vertical the vertical
*/
public GenericHtmlTable(Composite base, HtmlTag[] values, boolean vertical) {
super(base);
this.base = base;
content = new LinkedHashMap<>();
HtmlTag table = body.add(new Table());
if (vertical) {
numRows = values.length;
numCols = 1;
for(int i = 0; i < values.length; i++) {
HtmlTag[] arr = new HtmlTag[1];
arr[0] = values[i];
addRow(table, arr);
}
} else {
numRows = 1;
numCols = values.length;
addRow(table, values);
}
}
/**
* Instantiates a new html table.
*
* @param base the base
* @param values the values
* @param headers the headers
* @param vertical the vertical
*/
public GenericHtmlTable(Composite base, HtmlTag[] values, String[] headers, boolean vertical) {
super(base);
this.base = base;
content = new LinkedHashMap<>();
HtmlTag table = body.add(new Table());
if (vertical) {
numRows = values.length;
numCols = 1;
for(int i = 0; i < values.length; i++) {
HtmlTag[] arr = new HtmlTag[1];
arr[0] = values[i];
addRow(table, arr, headers[i]);
}
} else {
numRows = 1;
numCols = values.length;
addHeaderRow(table, headers, false);
addRow(table, values);
}
}
/**
* Instantiates a new html table.
*
* @param base the base
* @param values the values
* @param colHeaders the col headers
* @param rowHeaders the row headers
*/
public GenericHtmlTable(Composite base, HtmlTag[][] values, String[] colHeaders, String[] rowHeaders) {
super(base);
this.base = base;
content = new LinkedHashMap<>();
numRows = values.length;
numCols = values[0].length;
HtmlTag table = body.add(new Table());
addHeaderRow(table, colHeaders, true);
for(int i = 0; i < values.length; i++)
addRow(table, values[i], rowHeaders[i]);
}
/**
* Instantiates a new html table.
*
* @param base the base
* @param values the values
* @param colHeaders the col headers
*/
public GenericHtmlTable(Composite base, HtmlTag[][] values, String[] colHeaders) {
super(base);
this.base = base;
content = new LinkedHashMap<>();
numRows = values.length;
numCols = values[0].length;
HtmlTag table = body.add(new Table());
addHeaderRow(table, colHeaders, false);
for(int i = 0; i < values.length; i++)
addRow(table, values[i]);
}
/**
* Adds the cell.
*
* @param content the content
*/
private void addCell(HtmlTag tr, HtmlTag content) {
String[] classes = new String[] {
"row_" + row,
"col_" + col,
"value_" + content
};
HtmlTag td = tr.add(new Td(classes));
td.add(content);
this.content.put(td, classes);
col++;
}
/**
* Adds the header cell.
*
* @param content the content
* @param isHorizontal the is horizontal
*/
private void addHeaderCell(HtmlTag tr, String content, boolean isHorizontal) {
String cssClass = isHorizontal ? "table__header-horizontal" : "table__header-vertical";
HtmlTag td = tr.add(new Td(new String[] {"table__header", cssClass}));
HtmlTag b = td.add(new B());
b.add(new Text(content));
}
/**
* Adds the row.
*
* @param values the values
*/
private void addRow(HtmlTag table, HtmlTag[] values) {
this.addRow(table, values, null);
}
/**
* Adds the row.
*
* @param values the values
* @param rowHeader the row header
*/
private void addRow(HtmlTag table, HtmlTag[] values, String rowHeader) {
HtmlTag tr = table.add(new Tr());
if (rowHeader != null)
addHeaderCell(tr, rowHeader, false);
for (HtmlTag value : values)
addCell(tr, value);
col = 0;
row++;
}
/**
* Adds the header row.
*
* @param values the values
* @param emptyCell the empty cell
*/
private void addHeaderRow(HtmlTag table, String[] values, boolean emptyCell) {
HtmlTag tr = table.add(new Tr());
if(emptyCell)
addHeaderCell(tr, "", true);
for (String value : values)
addHeaderCell(tr, value, true);
}
public int getNumberOfRows() {
return numRows;
}
public int getNumberOfColumns() {
return numCols;
}
public void refresh(String[][] values) {
HtmlTag[][] valuesTag = Text.asText(values);
int row, col;
String classes[];
for(int i = 0; i < valuesTag.length; ++i) {
for(int j = 0; j < valuesTag[i].length; ++j) {
for(HtmlTag tag: content.keySet()) {
classes = content.get(tag);
row = Integer.parseInt(classes[0].replace("row_", ""));
col = Integer.parseInt(classes[1].replace("col_", ""));
if(row == i && col == j) {
tag.clear();
tag.deleteClass("value_");
tag.add(valuesTag[row][col]);
break;
}
}
}
}
}
public void refresh(String[] values) {
HtmlTag[] valuesTag = Text.asText(values);
int col;
String classes[];
for(int i = 0; i < valuesTag.length; ++i) {
for(HtmlTag tag: content.keySet()) {
classes = content.get(tag);
col = Integer.parseInt(classes[1].replace("col_", ""));
if(col == i) {
tag.clear();
tag.deleteClass("value_");
tag.add(valuesTag[col]);
break;
}
}
}
}
public void dispose() {
clearContent();
for(Control child: base.getChildren())
child.dispose();
numCols = 0;
numRows = 0;
row = 0;
col = 0;
}
public void clearContent() {
for(HtmlTag tag: content.keySet())
tag.remove();
content.clear();
}
/* (non-Javadoc)
* @see flintstones.helper.html.table.HtmlWidget#getResult()
*/
@Override
public String getResult() {
return body.toString();
}
/* (non-Javadoc)
* @see flintstones.helper.html.table.HtmlWidget#getStyle()
*/
@Override
protected String getStyle() {
return "table, th, td { border: 1px solid black; }"
+ ".table__header{ background-color: aliceblue; width: 10%; white-space: nowrap; }"
+ "table { border-collapse: collapse; }"
+ "td{ padding: 5px; background-color: white; }"
+ "table{ width: 100%; font-size: 13px; }";
}
}
@@ -0,0 +1,13 @@
package flintstones.helper.html.table;
import org.eclipse.swt.widgets.Composite;
import flintstones.helper.html.tags.HtmlTag;
public class HtmlComboTable extends GenericHtmlTable {
public HtmlComboTable(Composite base, HtmlTag[][] values, String[] colHeaders, String[] rowHeaders) {
super(base, values, colHeaders, rowHeaders);
}
}
@@ -0,0 +1,25 @@
package flintstones.helper.html.table;
import org.eclipse.swt.widgets.Composite;
import flintstones.helper.html.tags.Text;
public class HtmlTextTable extends GenericHtmlTable {
public HtmlTextTable(Composite base, String[] values, boolean vertical) {
super(base, Text.asText(values), vertical);
}
public HtmlTextTable(Composite base, String[] values, String[] headers, boolean vertical) {
super(base, Text.asText(values), headers, vertical);
}
public HtmlTextTable(Composite base, String[][] values, String[] colHeaders, String[] rowHeaders) {
super(base, Text.asText(values), colHeaders, rowHeaders);
}
public HtmlTextTable(Composite base, String[][] values, String[] colHeaders) {
super(base, Text.asText(values), colHeaders);
}
}
@@ -0,0 +1,13 @@
package flintstones.helper.html.tags;
public class B extends HtmlTag {
public B(String[] classes) {
super("b", classes);
}
public B() {
super("b");
}
}
@@ -0,0 +1,13 @@
package flintstones.helper.html.tags;
public class Body extends HtmlTag {
public Body(String[] classes) {
super("body", classes);
}
public Body() {
super("body");
}
}
@@ -0,0 +1,13 @@
package flintstones.helper.html.tags;
public class Div extends HtmlTag {
public Div() {
super("div");
}
public Div(String[] classes) {
super("div", classes);
}
}
@@ -0,0 +1,125 @@
package flintstones.helper.html.tags;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class HtmlTag {
protected String id;
protected Set<String> classes = new HashSet<>();
protected List<HtmlTag> childNodes = new ArrayList<>();
protected Map<String, String> attributes = new HashMap<>();
protected String className;
protected HtmlTag(String name) {
className = name;
}
protected HtmlTag(String name, String[] classes) {
className = name;
for (String classs : classes)
addClass(classs);
}
public HtmlTag add(HtmlTag tag) {
childNodes.add(tag);
return tag;
}
public void deleteClass(String classs) {
classes.remove(classs);
}
public void addClass(String classs) {
classes.add(classs);
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public Set<String> getClasses() {
return this.classes;
}
public void clear() {
childNodes.clear();
}
public void remove() {
classes.clear();
childNodes.clear();
}
public String attr(String attr) {
return attributes.get(attr);
}
public HtmlTag attr(String key, String val) {
attributes.put(key, val);
return this;
}
public HtmlTag attr(String key, int val) {
return attr(key, val+"");
}
public HtmlTag attr(String key, double val) {
return attr(key, val+"");
}
@Override
public String toString() {
StringBuilder html = new StringBuilder();
html.append("<");
html.append(className);
html.append(" ");
if(id != null) {
html.append("id=\"");
html.append(id);
html.append("\" ");
}
if (classes.size() > 0) {
String classesS = String.join(" ", classes);
html.append("class=\"");
html.append(classesS);
html.append("\" ");
}
for(Entry<String,String> attr : attributes.entrySet()) {
html.append(attr.getKey());
html.append("=\"");
html.append(attr.getValue());
html.append("\" ");
}
html.append(">");
for (HtmlTag tag : childNodes)
html.append(tag.toString());
html.append("<");
html.append("/");
html.append(className);
html.append(">");
return html.toString();
}
public List<HtmlTag> getChildren(){
return childNodes;
}
}
@@ -0,0 +1,14 @@
package flintstones.helper.html.tags;
public class Table extends HtmlTag {
public Table() {
super("table");
}
public Table(String[] classes) {
super("table", classes);
}
}
@@ -0,0 +1,13 @@
package flintstones.helper.html.tags;
public class Td extends HtmlTag {
public Td() {
super("td");
}
public Td(String[] classes) {
super("td",classes);
}
}
@@ -0,0 +1,29 @@
package flintstones.helper.html.tags;
import java.util.Arrays;
public class Text extends HtmlTag {
private String textContent;
public Text(String text) {
super("");
textContent = text;
}
@Override
public String toString() {
return textContent;
}
public void setText(String text) {
textContent = text;
}
public static Text[] asText(String[] data) {
return Arrays.stream(data).map(k -> new Text(k)).toArray(Text[]::new);
}
public static Text[][] asText(String[][] data) {
return Arrays.stream(data).map( k -> asText(k) ).toArray(Text[][]::new);
}
}
@@ -0,0 +1,14 @@
package flintstones.helper.html.tags;
public class Tr extends HtmlTag{
public Tr() {
super("tr");
}
public Tr(String[] classes) {
super("tr",classes);
}
}