Skip to content

Commit

Permalink
Merge pull request #46 from imfarias/alteracao-layout-painel
Browse files Browse the repository at this point in the history
{FEATURE} Alteração de layout do painel HTML
  • Loading branch information
clagomess authored Feb 23, 2021
2 parents 68ade5b + a3e0735 commit 4de7420
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 19 deletions.
10 changes: 10 additions & 0 deletions src/main/java/br/com/pirilampo/bean/MainForm.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package br.com.pirilampo.bean;

import br.com.pirilampo.constant.PainelFechado;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
Expand All @@ -12,6 +13,7 @@ public class MainForm {
@FXML protected TextField txtLogoSrc;
@FXML protected Button btnSelecionarLogoSrc;
@FXML protected ToggleGroup tipLayoutPdf;
@FXML protected ToggleGroup tipPainelFechado;
@FXML protected ColorPicker clrMenu;
@FXML protected ColorPicker clrTextoMenu;
@FXML protected CheckBox sitEmbedarImagens;
Expand All @@ -32,5 +34,13 @@ protected void setData(Parametro parametro){
this.clrMenu.setValue(Color.web(parametro.getClrMenu()));
this.clrTextoMenu.setValue(Color.web(parametro.getClrTextoMenu()));
this.sitEmbedarImagens.setSelected(parametro.getSitEmbedarImagens());

if(parametro.getTipPainelFechado() != null) {
this.tipPainelFechado.getToggles().forEach(toggle -> {
if(PainelFechado.valueOf(toggle.getUserData().toString()).equals(parametro.getTipPainelFechado())) {
toggle.setSelected(true);
}
});
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/br/com/pirilampo/bean/Parametro.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import br.com.pirilampo.constant.Artefato;
import br.com.pirilampo.constant.Compilacao;
import br.com.pirilampo.constant.LayoutPdf;
import br.com.pirilampo.constant.PainelFechado;
import javafx.scene.paint.Color;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -18,6 +19,7 @@ public class Parametro {
private String txtVersao = "1.0";
private String txtLogoSrc;
private LayoutPdf tipLayoutPdf = LayoutPdf.RETRATO;
private PainelFechado tipPainelFechado = PainelFechado.ABERTO;
private String clrMenu = "#14171A";
private String clrTextoMenu = "#DDDDDD";
private Boolean sitEmbedarImagens = true;
Expand All @@ -32,6 +34,7 @@ public Parametro(MainForm form){
this.txtVersao = !StringUtils.isEmpty(form.txtVersao.getText()) ? form.txtVersao.getText() : this.txtVersao;
this.txtLogoSrc = form.txtLogoSrc.getText();
this.tipLayoutPdf = LayoutPdf.valueOf((String) form.tipLayoutPdf.getSelectedToggle().getUserData());
this.tipPainelFechado = PainelFechado.valueOf((String) form.tipPainelFechado.getSelectedToggle().getUserData());
this.clrMenu = colorHex(form.clrMenu.getValue());
this.clrTextoMenu = colorHex(form.clrTextoMenu.getValue());
this.sitEmbedarImagens = form.sitEmbedarImagens.isSelected();
Expand All @@ -56,6 +59,7 @@ public Parametro(Properties properties){
this.clrMenu = !StringUtils.isEmpty(properties.getProperty("clrMenu")) ? properties.getProperty("clrMenu") : this.clrMenu;
this.clrTextoMenu = !StringUtils.isEmpty(properties.getProperty("clrTextoMenu")) ? properties.getProperty("clrTextoMenu") : this.clrTextoMenu;
this.sitEmbedarImagens = !StringUtils.isEmpty(properties.getProperty("sitEmbedarImagens")) ? Boolean.valueOf(properties.getProperty("sitEmbedarImagens")) : this.sitEmbedarImagens;
this.tipPainelFechado = !StringUtils.isEmpty(properties.getProperty("tipPainelFechado")) ? PainelFechado.valueOf(properties.getProperty("tipPainelFechado")) : this.tipPainelFechado;
}

public String colorHex(Color color){
Expand Down
1 change: 1 addition & 0 deletions src/main/java/br/com/pirilampo/constant/HtmlTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final public class HtmlTemplate {
public static final String HTML_CHILDREN = "<div class=\"panel panel-default\">\n" +
"<div class=\"panel-heading\" style=\"cursor: pointer;\" data-toggle=\"collapse\" data-target=\"#scenario-%s\"><h3>%s</h3></div>\n%s\n</div>\n";
public static final String HTML_CHILDREN_BODY = "<div id=\"scenario-%s\" class=\"panel-body collapse in\">%s</div>\n";
public static final String HTML_CHILDREN_BODY_CLOSED = "<div id=\"scenario-%s\" class=\"panel-body collapse\">%s</div>\n";
public static final String HTML_CHILDREN_TABLE = "<div class=\"table-responsive\">\n" +
"<table class=\"table table-condensed table-bordered table-hover table-striped\">\n" +
"<thead>\n%s\n</thead>\n" +
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/br/com/pirilampo/constant/PainelFechado.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package br.com.pirilampo.constant;

public enum PainelFechado {
FECHADO("F"), ABERTO("A");

private final String vl;

PainelFechado(String vl){
this.vl = vl;
}

public String getValue(){
return vl;
}
}
21 changes: 21 additions & 0 deletions src/main/java/br/com/pirilampo/controller/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import java.util.prefs.Preferences;

@Slf4j
public class MainController extends MainForm implements Initializable {
Expand Down Expand Up @@ -74,21 +75,41 @@ private void selecionarFonte(boolean isFonteMaster){
File file;
final Compilacao compilacao = Compilacao.valueOf((String) tipCompilacao.getSelectedToggle().getUserData());

Preferences prefs = Preferences.userRoot().node(getClass().getName());

String folder = prefs.get("LAST_USED_FOLDER", "");

if(compilacao == Compilacao.FEATURE){
FileChooser chooser = new FileChooser();
chooser.setTitle("Selecionar Fonte");

FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("Feature", "*.feature");
chooser.getExtensionFilters().add(extFilter);

if(folder != "") {
File folderFile = new File(folder);
if(folderFile.exists()) {
chooser.setInitialDirectory(new File(folder));
}
}

file = chooser.showOpenDialog(new Stage());
}else{
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle("Selecionar Pasta");

if(folder != "") {
File folderFile = new File(folder);
if(folderFile.exists()) {
directoryChooser.setInitialDirectory(new File(folder));
}
}

file = directoryChooser.showDialog(new Stage());
}

if(file != null) {
prefs.put("LAST_USED_FOLDER", file.getAbsolutePath());
if(!isFonteMaster && compilacao != Compilacao.FEATURE){
setData(PropertiesUtil.getData(file.getAbsolutePath()));
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/br/com/pirilampo/core/Compilador.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void compilarPasta(Parametro parametro) throws Exception {

// Gera a feture
ParseDocument pd = new ParseDocument(parametro, f);
String featureHtml = pd.getFeatureHtml();
String featureHtml = pd.getFeatureHtml(parametro.getTipPainelFechado().getValue());
paginaHtmlAnexo.addAll(pd.getPaginaHtmlAnexo());
indice.putAll(pd.getIndice());

Expand Down Expand Up @@ -217,7 +217,7 @@ public void compilarFeaturePdf(Parametro parametro) throws Exception {
String path = (StringUtils.isNotEmpty(parametro.getTxtOutputTarget()) ? parametro.getTxtOutputTarget() : feature.getParent());
path += File.separator + feature.getName().replace(Resource.getExtension(feature), "") + ".pdf";

pp.buildHtml(path, html, css, parametro.getTipLayoutPdf().getValue());
pp.buildHtml(path, html, css, parametro.getTipLayoutPdf().getValue(), parametro.getTipPainelFechado().getValue());
}

public void compilarPastaPdf(Parametro parametro) throws Exception {
Expand Down Expand Up @@ -266,7 +266,7 @@ public void compilarPastaPdf(Parametro parametro) throws Exception {
log.info("GERANDO PDF");
ProgressBind.setProgress(-1);

pp.buildHtml(outDir + File.separator + "index.pdf", html.toString(), css, parametro.getTipLayoutPdf().getValue());
pp.buildHtml(outDir + File.separator + "index.pdf", html.toString(), css, parametro.getTipLayoutPdf().getValue(), parametro.getTipPainelFechado().getValue());
}
}
}
22 changes: 16 additions & 6 deletions src/main/java/br/com/pirilampo/core/ParseDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import br.com.pirilampo.bean.Indice;
import br.com.pirilampo.bean.Parametro;
import br.com.pirilampo.constant.HtmlTemplate;
import br.com.pirilampo.constant.PainelFechado;
import br.com.pirilampo.exception.FeatureException;
import gherkin.AstBuilder;
import gherkin.Parser;
Expand All @@ -15,7 +16,10 @@
import org.apache.commons.lang.StringUtils;
import org.commonmark.renderer.html.HtmlRenderer;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -72,10 +76,10 @@ private void setIndiceName(final String name){
public static String getFeatureHtml(Parametro parametro, File feature) throws Exception {
ParseDocument pd = new ParseDocument(parametro, feature);

return pd.getFeatureHtml();
return pd.getFeatureHtml(parametro.getTipPainelFechado().getValue());
}

public String getFeatureHtml() throws Exception {
public String getFeatureHtml(String painelFechado) throws Exception {
Parser<GherkinDocument> parser = new Parser<>(new AstBuilder());
TokenMatcher matcher = new TokenMatcher();
String html = null;
Expand All @@ -89,7 +93,7 @@ public String getFeatureHtml() throws Exception {
this.gd = parser.parse(in, matcher);

if (this.gd != null) {
html = getHtml();
html = getHtml(painelFechado);
}

log.info("OK: {}", feature.getAbsolutePath());
Expand All @@ -100,7 +104,7 @@ public String getFeatureHtml() throws Exception {
return html;
}

private String getHtml(){
private String getHtml(String painelFechado){
StringBuilder html = new StringBuilder();

if(gd != null){
Expand Down Expand Up @@ -192,11 +196,17 @@ private String getHtml(){
}
}

String bodyHtml = String.format(HtmlTemplate.HTML_CHILDREN_BODY, scenarioIdx, body);

if (PainelFechado.FECHADO.getValue().equals(painelFechado)) {
bodyHtml = String.format(HtmlTemplate.HTML_CHILDREN_BODY_CLOSED, scenarioIdx, body);
}

html.append(String.format(
HtmlTemplate.HTML_CHILDREN,
scenarioIdx,
StringEscapeUtils.escapeHtml("".equals(sd.getName()) ? sd.getKeyword() : sd.getName()),
String.format(HtmlTemplate.HTML_CHILDREN_BODY, scenarioIdx, body)
bodyHtml
));

scenarioIdx++;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/br/com/pirilampo/core/ParsePdf.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public String getImageRootPath() {
}
}

public void buildHtml(String path, String html, String css, String layout) throws Exception {
public void buildHtml(String path, String html, String css, String layout, String painelFechado) throws Exception {
// Apply preferences and build metadata.
Document document = new Document(layout.equals("R") ? PageSize.A4 : PageSize.A4.rotate());
PdfWriter pw = PdfWriter.getInstance(document, new FileOutputStream(path));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/br/com/pirilampo/util/PropertiesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static Properties parametroToProperties(Parametro parametro){
prop.setProperty("clrMenu", parametro.getClrMenu());
prop.setProperty("clrTextoMenu", parametro.getClrTextoMenu());
prop.setProperty("sitEmbedarImagens", parametro.getSitEmbedarImagens().toString());
prop.setProperty("tipPainelFechado", parametro.getTipPainelFechado().toString());

return prop;
}
Expand Down
28 changes: 20 additions & 8 deletions src/main/resources/fxml/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,20 @@
</RadioButton>
<Separator GridPane.rowIndex="5" prefWidth="200.0" />

<Label GridPane.rowIndex="6" text="Layout HTML" style="-fx-font-size: 12px; -fx-font-weight: bolder"/>
<GridPane GridPane.rowIndex="7" hgap="10.0" vgap="10.0">
<Label GridPane.rowIndex="6" text="Layout Painel" style="-fx-font-size: 12px; -fx-font-weight: bolder"/>
<fx:define>
<ToggleGroup fx:id="tipPainelFechado" />
</fx:define>
<RadioButton GridPane.rowIndex="7" toggleGroup="$tipPainelFechado" text="Aberto" userData="ABERTO" mnemonicParsing="false" selected="true"/>
<RadioButton GridPane.rowIndex="7" toggleGroup="$tipPainelFechado" text="Fechado" userData="FECHADO" mnemonicParsing="false">
<GridPane.margin>
<Insets left="100.0"/>
</GridPane.margin>
</RadioButton>
<Separator GridPane.rowIndex="8" prefWidth="200.0" />

<Label GridPane.rowIndex="9" text="Layout HTML" style="-fx-font-size: 12px; -fx-font-weight: bolder"/>
<GridPane GridPane.rowIndex="10" hgap="10.0" vgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints hgrow="ALWAYS" />
Expand All @@ -99,8 +111,8 @@
</GridPane>
<Separator prefWidth="200.0" GridPane.rowIndex="8" />

<Label GridPane.rowIndex="9" text="Gerar Documentação" style="-fx-font-size: 12px; -fx-font-weight: bolder" />
<GridPane GridPane.rowIndex="10" hgap="10.0">
<Label GridPane.rowIndex="11" text="Gerar Documentação" style="-fx-font-size: 12px; -fx-font-weight: bolder" />
<GridPane GridPane.rowIndex="12" hgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints hgrow="ALWAYS" />
Expand All @@ -117,7 +129,7 @@
<RadioButton GridPane.columnIndex="1" toggleGroup="$tipCompilacao" onAction="#tipCompilacaoChange" text="Individual" userData="FEATURE" mnemonicParsing="false"/>
<RadioButton GridPane.columnIndex="2" toggleGroup="$tipCompilacao" onAction="#tipCompilacaoChange" text="Diff/Comparação" userData="DIFF" mnemonicParsing="false"/>
</GridPane>
<GridPane GridPane.rowIndex="11" hgap="10.0" vgap="10.0">
<GridPane GridPane.rowIndex="13" hgap="10.0" vgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints hgrow="ALWAYS" />
Expand All @@ -130,7 +142,7 @@
<TextField GridPane.rowIndex="1" GridPane.columnIndex="0" fx:id="txtSrcFonteMaster" promptText="Pasta Fonte Master" disable="true"/>
<Button GridPane.rowIndex="1" GridPane.columnIndex="1" fx:id="btnSelecionarFonteMaster" onAction="#selecionarFonteMaster" text="Selecionar" disable="true"/>
</GridPane>
<GridPane GridPane.rowIndex="12" hgap="10.0">
<GridPane GridPane.rowIndex="14" hgap="10.0">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" />
<ColumnConstraints hgrow="ALWAYS" />
Expand All @@ -142,6 +154,6 @@
<Button GridPane.columnIndex="0" fx:id="btnGerarHtml" onAction="#compilarHtml" text="Gerar HTML"/>
<Button GridPane.columnIndex="1" fx:id="btnGerarPdf" onAction="#compilarPdf" text="Gerar PDF"/>
</GridPane>
<ProgressBar GridPane.rowIndex="13" fx:id="progressBar" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" progress="0.0" />
<TextArea fx:id="txtConsole" GridPane.rowIndex="14" maxHeight="60" editable="false" style="-fx-font-family: monospace;" wrapText="true"/>
<ProgressBar GridPane.rowIndex="15" fx:id="progressBar" maxHeight="-Infinity" maxWidth="1.7976931348623157E308" progress="0.0" />
<TextArea fx:id="txtConsole" GridPane.rowIndex="16" maxHeight="60" editable="false" style="-fx-font-family: monospace;" wrapText="true"/>
</GridPane>
Loading

0 comments on commit 4de7420

Please sign in to comment.