List of usage examples for org.apache.poi.xwpf.usermodel ParagraphAlignment CENTER
ParagraphAlignment CENTER
To view the source code for org.apache.poi.xwpf.usermodel ParagraphAlignment CENTER.
Click Source Link
From source file:com.glodon.tika.SimpleTable.java
License:Apache License
/** * Create a table with some row and column styling. I "manually" add the * style name to the table, but don't check to see if the style actually * exists in the document. Since I'm creating it from scratch, it obviously * won't exist. When opened in MS Word, the table style becomes "Normal". * I manually set alternating row colors. This could be done using Themes, * but that's left as an exercise for the reader. The cells in the last * column of the table have 10pt. "Courier" font. * I make no claims that this is the "right" way to do it, but it worked * for me. Given the scarcity of XWPF examples, I thought this may prove * instructive and give you ideas for your own solutions. // w ww. ja v a 2 s . c o m * @throws Exception */ public static void createStyledTable() throws Exception { // Create a new document from scratch XWPFDocument doc = new XWPFDocument(); try { // -- OR -- // open an existing empty document with styles already defined //XWPFDocument doc = new XWPFDocument(new FileInputStream("base_document.docx")); // Create a new table with 6 rows and 3 columns int nRows = 6; int nCols = 3; XWPFTable table = doc.createTable(nRows, nCols); // Set the table style. If the style is not defined, the table style // will become "Normal". CTTblPr tblPr = table.getCTTbl().getTblPr(); CTString styleStr = tblPr.addNewTblStyle(); styleStr.setVal("StyledTable"); // Get a list of the rows in the table List<XWPFTableRow> rows = table.getRows(); int rowCt = 0; int colCt = 0; for (XWPFTableRow row : rows) { // get table row properties (trPr) CTTrPr trPr = row.getCtRow().addNewTrPr(); // set row height; units = twentieth of a point, 360 = 0.25" CTHeight ht = trPr.addNewTrHeight(); ht.setVal(BigInteger.valueOf(360)); // get the cells in this row List<XWPFTableCell> cells = row.getTableCells(); // add content to each cell for (XWPFTableCell cell : cells) { // get a table cell properties element (tcPr) CTTcPr tcpr = cell.getCTTc().addNewTcPr(); // set vertical alignment to "center" CTVerticalJc va = tcpr.addNewVAlign(); va.setVal(STVerticalJc.CENTER); // create cell color element CTShd ctshd = tcpr.addNewShd(); ctshd.setColor("auto"); ctshd.setVal(STShd.CLEAR); if (rowCt == 0) { // header row ctshd.setFill("A7BFDE"); } else if (rowCt % 2 == 0) { // even row ctshd.setFill("D3DFEE"); } else { // odd row ctshd.setFill("EDF2F8"); } // get 1st paragraph in cell's paragraph list XWPFParagraph para = cell.getParagraphs().get(0); // create a run to contain the content XWPFRun rh = para.createRun(); // style cell as desired if (colCt == nCols - 1) { // last column is 10pt Courier rh.setFontSize(10); rh.setFontFamily("Courier"); } if (rowCt == 0) { // header row rh.setText("header row, col " + colCt); rh.setBold(true); para.setAlignment(ParagraphAlignment.CENTER); } else { // other rows rh.setText("row " + rowCt + ", col " + colCt); para.setAlignment(ParagraphAlignment.LEFT); } colCt++; } // for cell colCt = 0; rowCt++; } // for row // write the file OutputStream out = new FileOutputStream("styledTable.docx"); try { doc.write(out); } finally { out.close(); } } finally { doc.close(); } }
From source file:com.min.word.core.MakeWordFileTest.java
License:Apache License
public static void main(String[] args) throws Exception { String fileName = "test.docx"; System.out.println("---------- Word Create Start ------------"); // word ? ?//from ww w . ja v a2 s . c o m XWPFDocument document = new XWPFDocument(); FileOutputStream out = new FileOutputStream(new File(fileName)); System.out.println("---------- Create Blank Success ------------"); //Paragraph ? XWPFParagraph paragraph = document.createParagraph(); System.out.println("---------- Create Paragraph Success ------------"); //border ? paragraph.setBorderBottom(Borders.BASIC_BLACK_DASHES); paragraph.setBorderLeft(Borders.BASIC_BLACK_DASHES); paragraph.setBorderRight(Borders.BASIC_BLACK_DASHES); paragraph.setBorderTop(Borders.BASIC_BLACK_DASHES); System.out.println("---------- Create Border Success ------------"); XWPFRun run = paragraph.createRun(); run.setText("At tutorialspoint.com, we strive hard to " + "provide quality tutorials for self-learning " + "purpose in the domains of Academics, Information " + "Technology, Management and Computer Programming Languages."); System.out.println("---------- Text Write to File ------------"); //Table ? XWPFTable table = document.createTable(); //row XWPFTableRow rowOne = table.getRow(0); rowOne.getCell(0).setText("Col One, Row One"); rowOne.addNewTableCell().setText("Col Tow, Row One"); rowOne.addNewTableCell().setText("Col Three, Row One"); //row XWPFTableRow rowTow = table.createRow(); rowTow.getCell(0).setText("Col One, Row Tow"); rowTow.getCell(1).setText("Col Tow, Row Tow"); rowTow.getCell(2).setText("Col Three, Row Tow"); //row XWPFTableRow rowThree = table.createRow(); rowThree.getCell(0).setText("Col One, Row Three"); rowThree.getCell(1).setText("Col Tow, Row Three"); rowThree.getCell(2).setText("Col Three, Row Three"); System.out.println("---------- Create Table Success ------------"); //Add Image XWPFParagraph imageParagraph = document.createParagraph(); XWPFRun imageRun = imageParagraph.createRun(); imageRun.addPicture(new FileInputStream("test.png"), XWPFDocument.PICTURE_TYPE_PNG, "test.png", Units.toEMU(300), Units.toEMU(300)); System.out.println("---------- Create Image Success ------------"); //Hyperlink XWPFParagraph hyperlink = document.createParagraph(); String id = hyperlink.getDocument().getPackagePart() .addExternalRelationship("http://niee.kr", XWPFRelation.HYPERLINK.getRelation()).getId(); CTR ctr = CTR.Factory.newInstance(); CTHyperlink ctHyperlink = hyperlink.getCTP().addNewHyperlink(); ctHyperlink.setId(id); CTText ctText = CTText.Factory.newInstance(); ctText.setStringValue("Hyper-Link TEST"); ctr.setTArray(new CTText[] { ctText }); // ???? ? CTColor color = CTColor.Factory.newInstance(); color.setVal("0000FF"); CTRPr ctrPr = ctr.addNewRPr(); ctrPr.setColor(color); ctrPr.addNewU().setVal(STUnderline.SINGLE); // CTFonts fonts = ctrPr.isSetRFonts() ? ctrPr.getRFonts() : ctrPr.addNewRFonts(); fonts.setAscii("?? "); fonts.setEastAsia("?? "); fonts.setHAnsi("?? "); // ? CTHpsMeasure sz = ctrPr.isSetSz() ? ctrPr.getSz() : ctrPr.addNewSz(); sz.setVal(new BigInteger("24")); ctHyperlink.setRArray(new CTR[] { ctr }); hyperlink.setAlignment(ParagraphAlignment.LEFT); hyperlink.setVerticalAlignment(TextAlignment.CENTER); System.out.println("---------- Create Hyperlink Success ------------"); //Font style XWPFParagraph fontStyle = document.createParagraph(); //set Bold an Italic XWPFRun boldAnItalic = fontStyle.createRun(); boldAnItalic.setBold(true); boldAnItalic.setItalic(true); boldAnItalic.setText("Bold an Italic"); boldAnItalic.addBreak(); //set Text Position XWPFRun textPosition = fontStyle.createRun(); textPosition.setText("Set Text Position"); textPosition.setTextPosition(100); //Set Strike through and font Size and Subscript XWPFRun otherStyle = fontStyle.createRun(); otherStyle.setStrike(true); otherStyle.setFontSize(20); otherStyle.setSubscript(VerticalAlign.SUBSCRIPT); otherStyle.setText(" Set Strike through and font Size and Subscript"); System.out.println("---------- Set Font Style ------------"); //Set Alignment Paragraph XWPFParagraph alignment = document.createParagraph(); //Alignment to Right alignment.setAlignment(ParagraphAlignment.RIGHT); XWPFRun alignRight = alignment.createRun(); alignRight.setText( "At tutorialspoint.com, we strive hard to " + "provide quality tutorials for self-learning " + "purpose in the domains of Academics, Information " + "Technology, Management and Computer Programming " + "Languages."); //Alignment to Center alignment = document.createParagraph(); //Alignment to Right alignment.setAlignment(ParagraphAlignment.CENTER); XWPFRun alignCenter = alignment.createRun(); alignCenter.setText("The endeavour started by Mohtashim, an AMU " + "alumni, who is the founder and the managing director " + "of Tutorials Point (I) Pvt. Ltd. He came up with the " + "website tutorialspoint.com in year 2006 with the help" + "of handpicked freelancers, with an array of tutorials" + " for computer programming languages. "); System.out.println("---------- Set Alignment ------------"); //word ? document.write(out); out.close(); System.out.println("---------- Save File Name : " + fileName + " ------------"); System.out.println("---------- Word Create End ------------"); }
From source file:csv2docxconverter.DocumentGenerator.java
/** * Generate DocX element from list of the rows containing account information * @param columnNames a list of columns for data parsing * @param contents list of data rows for parsing * @return an XWPFDocument representing a DocX file */// w w w . j av a 2s . c o m public XWPFDocument generateDocx(String[] columnNames, List contents) { XWPFDocument document = new XWPFDocument(); // create title XWPFParagraph title = document.createParagraph(); title.setAlignment(ParagraphAlignment.CENTER); XWPFRun titleRun = title.createRun(); titleRun.setText("G SUITE created accounts"); titleRun.setFontSize(18); for (int k = 0; k < contents.size(); k++) { List tableContent = (List) contents.get(k); // create title title = document.createParagraph(); title.setAlignment(ParagraphAlignment.CENTER); titleRun = title.createRun(); titleRun.setText("Table " + (k + 1)); titleRun.setFontSize(18); // create account table XWPFTable table = document.createTable(); // set "justified" alignment table.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(10000)); //create header for table setHeader(table, columnNames); // if account list is empty if (tableContent == null || tableContent.size() == 0) { // add empty row to the table XWPFTableRow emptyRow = table.createRow(); } else { String[] headerRow = null; // create rows in table for (int i = 0; i < tableContent.size(); i++) { if (i == 0) { headerRow = (String[]) tableContent.get(i); continue; } String[] csvRow = (String[]) tableContent.get(i); XWPFTableRow row = table.createRow(); //create cells in a row for (int j = 0; j < columnNames.length; j++) { int number = getColumnNumber(columnNames[j], headerRow); XWPFTableCell cell = row.getCell(j); if (cell != null) { XWPFRun run = setBodyCell(cell); if (number >= 0 && number < csvRow.length) { run.setText(csvRow[number]); } } } } } } return document; }
From source file:csv2docxconverter.DocumentGenerator.java
/** * Set header cell style//from ww w .j a va2 s . c o m */ private XWPFRun setHeaderCell(XWPFTableCell cell) { cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); XWPFParagraph paragraph = cell.getParagraphArray(0); paragraph.setAlignment(ParagraphAlignment.CENTER); paragraph.setSpacingBefore(8); paragraph.setSpacingAfter(8); XWPFRun run = paragraph.createRun(); run.setBold(true); return run; }
From source file:csv2docxconverter.DocumentGenerator.java
/** * Set body cell style/*w w w. ja v a 2 s .c o m*/ */ private XWPFRun setBodyCell(XWPFTableCell cell) { cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); XWPFParagraph paragraph = cell.getParagraphArray(0); paragraph.setAlignment(ParagraphAlignment.CENTER); paragraph.setSpacingBefore(4); paragraph.setSpacingAfter(4); return paragraph.createRun(); }
From source file:djpresentationMaker.forms.frmMainController.java
@Override public void initialize(URL url, ResourceBundle rb) { sql.setDatabase(clsHelper.getPath() + File.separatorChar + lang.getValue("database.key")); sql.open();//from w ww.ja v a2 s . c om accMain.setExpandedPane(tpnlSongAndSongbook); clsControlHelper.reloadTable(sql, tblSongbook, true); clsHelper.listRoots(tvPictures); Image img = new Image( DJPresentationMaker.class.getResourceAsStream("style" + File.separatorChar + "songbook.png")); cmdNewSongBook.setGraphic(new ImageView(img)); img = new Image(DJPresentationMaker.class.getResourceAsStream("style" + File.separatorChar + "song.png")); cmdNewSong.setGraphic(new ImageView(img)); clsControlHelper.reloadTable(sql, tblSongSongbook); clsControlHelper.loadEffects(sql, cmbMainEffect); clsControlHelper.resetObjects(true, false, txtMainSlideTitle, txtSongTitle, txtSongInterpret, txtSongAlbum, txtSongPartTitle, cmdSongPartAdd, txtMainSlideContent, txtSongPartContent); ctxMainSongbookDelete.setOnAction(event -> { sql.deleteRow("songbooks", "id=" + tblSongbook.getSelectionModel().getSelectedItem().getID()); clsControlHelper.reloadTable(sql, tblSongbook, true); }); menExtrasToViewer.setOnAction(event -> clsHelper.openFXML("forms/frmSongViewer.fxml", clsLang.getLangBundle(), "SongViewer", "style" + File.separatorChar + "logo_128.png")); ctxMainSongbookChange.setOnAction(event -> { DataTable dt = sql.getRows("songbooks", Arrays.asList("id", "title", "originalTitle", "publisher", "isbn", "release", "path", "description"), "id='" + tblSongbook.getSelectionModel().getSelectedItem().getID() + "'"); for (int i = 0; i <= dt.columnsCount() - 1; i++) { txtSongbookCover.setText(dt.get(0, "path").toString()); txtSongbookTitle.setText(dt.get(0, "title").toString()); txtSongbookOriginalTitle.setText(dt.get(0, "originalTitle").toString()); txtSongbookPublisher.setText(dt.get(0, "publisher").toString()); txtSongbookISBN.setText(dt.get(0, "isbn").toString()); dpSongbookRelease.setValue(LocalDate.parse(dt.get(0, "release").toString())); txtSongbookDescription.setText(dt.get(0, "description").toString()); songbookChange = true; if (txtSongbookCover.getText().contains("http://")) { ivSongbookCover.setImage(new Image(txtSongbookCover.getText())); } else { ivSongbookCover.setImage(new Image("file:///" + txtSongbookCover.getText())); } tpnlMain.getSelectionModel().select(pnlSongBook); songbookID = Integer.parseInt(dt.get(0, "id").toString()); cmdSongbookSubmit.setText("ndern"); } }); ctxSongChange.setOnAction(event -> { if (!tblSongSong.getSelectionModel().isEmpty()) { clsControlHelper.resetObjects(false, false, txtSongAlbum, txtSongInterpret, txtSongTitle); clsControlHelper.resetObjects(true, false, txtSongPartContent, txtSongPartTitle, lvSongPartOrder, lvSongParts, cmdSongPartAdd, cmdSongPartAddToOrder, cmdSongPartRemoveFromOrder); clsControlHelper.resetButtons(false, true, lang.getValue("change.key"), cmdSongSubmit); } }); ctxSongpartChange.setOnAction(event -> { if (!lvSongParts.getSelectionModel().isEmpty()) { String title = lvSongParts.getSelectionModel().getSelectedItem(); String song_id = tblSongSong.getSelectionModel().getSelectedItems().get(0).getID(); DataTable dt = sql.getRows("songparts", Arrays.asList("title", "content"), "title='" + title + "' AND song_id=" + song_id); txtSongPartTitle.setText(dt.get(0, "title").toString().replace("_", "'")); txtSongPartContent.setText(dt.get(0, "content").toString().replace("_", "'")); cmdSongPartAdd.setText(lang.getValue("change.key")); } }); ctxSongDelete.setOnAction(event -> { sql.deleteRow("songs", "id=" + tblSongSong.getSelectionModel().getSelectedItems().get(0).getID()); clsControlHelper.getSongsFromSongbook(sql, tblSongSongbook, tblSongSong, true); }); ctxSongpartDelete.setOnAction(event -> { String id = tblSongSong.getSelectionModel().getSelectedItems().get(0).getID(); sql.deleteRow("songparts", "title='" + lvSongParts.getSelectionModel().getSelectedItem() + "'"); Map<Integer, String> list = clsControlHelper.listSongPartsAndInfo(sql, tblSongSong, txtSongTitle, txtSongAlbum, txtSongInterpret); lvSongParts.getItems().clear(); for (String item : list.values()) { lvSongParts.getItems().add(item); } clsControlHelper.getOrderedParts(sql, id, lvSongPartOrder); }); menProgramSettings.setOnAction(event -> clsHelper.openFXML("forms/frmSettings.fxml", clsLang.getLangBundle(), lang.getValue("settings.key"), "style/logo_128.png")); cmdNewSongBook.setOnAction(event -> { if (tpnlMain.getSelectionModel().getSelectedItem().equals(pnlSongBook)) { tpnlMain.getSelectionModel().select(pnlMain); clearTab(2); } else { tpnlMain.getSelectionModel().select(pnlSongBook); songbookChange = false; clsControlHelper.reloadTable(sql, tblSongbook, true); } }); cmdNewSong.setOnAction(event -> { if (tpnlMain.getSelectionModel().getSelectedItem().equals(pnlSong)) { tpnlMain.getSelectionModel().select(pnlMain); clearTab(3); clsControlHelper.resetObjects(true, false, cmdSongPartAdd, txtSongTitle, txtSongInterpret, txtSongAlbum, txtSongPartTitle, txtSongPartContent); clsControlHelper.reloadTable(sql, tblSongSongbook); } else { tpnlMain.getSelectionModel().select(pnlSong); clsControlHelper.reloadTable(sql, tblSongbook, true); } }); cmdSongbookFind.setOnAction(event -> { clsXISBN service = new clsXISBN(txtSongbookISBN.getText()); txtSongbookPublisher.setText(service.getPublisher()); txtSongbookTitle.setText(service.getTitle()); if (!service.getYear().equals("")) { dpSongbookRelease.setValue(LocalDate.parse(service.getYear() + "-01-01")); } txtSongbookDescription.setText(service.getEdition()); currentIMGPath = "http://covers.librarything.com/devkey/b07988b337d9fecafa139c0203e87b29/medium/isbn/" + txtSongbookISBN.getText(); txtSongbookCover.setText(currentIMGPath); ivSongbookCover.setImage(new Image(currentIMGPath)); }); cmdSongbookReset.setOnAction(event -> clearTab(2)); cmdSongbookCover.setOnAction(event -> { if (!txtSongbookCover.getText().equals("") && new File(txtSongbookCover.getText()).exists() && !currentIMGPath.equals(txtSongbookCover.getText())) { currentIMGPath = txtSongbookCover.getText(); } else if (txtSongbookCover.getText().equals("")) { FileChooser fileChooser = new FileChooser(); FileChooser.ExtensionFilter extFilterJPG = new FileChooser.ExtensionFilter("JPG files (*.jpg)", "*.JPG"); FileChooser.ExtensionFilter extFilterPNG = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.PNG"); fileChooser.getExtensionFilters().addAll(extFilterJPG, extFilterPNG); File file = fileChooser.showOpenDialog(null); currentIMGPath = file.getPath(); txtSongbookCover.setText(currentIMGPath); } ivSongbookCover.setImage(new Image("file:///" + currentIMGPath)); }); ctxSongs.setOnShowing(event -> { if (!tblSongbook.getSelectionModel().isEmpty()) { if (tblSongbook.getSelectionModel().getSelectedItem().getID().equals("999999")) { ctxMainSongChange.setDisable(false); ctxMainSongDelete.setDisable(false); } else { ctxMainSongChange.setDisable(true); ctxMainSongDelete.setDisable(true); } } }); ctxMainSongChange.setOnAction(event -> { try { if (!tblSong.getSelectionModel().isEmpty()) { frmUserdefinedController controller = new frmUserdefinedController( tblSong.getSelectionModel().getSelectedItem().getName()); FXMLLoader loader = new FXMLLoader( DJPresentationMaker.class.getResource("forms/frmUserdefined.fxml")); loader.setController(controller); loader.setResources(clsLang.getLangBundle()); Parent root = loader.load(); Scene scene = new Scene(root); Stage stage = new Stage(); stage.setScene(scene); stage.setTitle(lang.getValue("frmMain.userdefined.key")); stage.getIcons() .add(new Image(DJPresentationMaker.class.getResourceAsStream("style/logo_128.png"))); stage.showAndWait(); } } catch (Exception ex) { clsHelper.printException(ex); } }); ctxMainSongDelete.setOnAction(event -> { try { if (!tblSong.getSelectionModel().isEmpty()) { sql.deleteRow("userdefined", "TITLE='" + tblSong.getSelectionModel().getSelectedItem().getName() + "'"); } } catch (Exception ex) { clsHelper.printException(ex); } }); cmdSongbookSubmit.setOnAction(event -> { songbook book = new songbook(txtSongbookTitle.getText(), txtSongbookPublisher.getText()); book.setOriginalTitle(txtSongbookOriginalTitle.getText()); book.setISBN(txtSongbookISBN.getText()); book.setPath(txtSongbookCover.getText()); book.setDescription(txtSongbookDescription.getText()); book.setRelease(dpSongbookRelease.getValue()); if (book.DataSetIsOkay()) { if (book.DataSetDontExist(sql) || songbookChange) { List<String> columns = Arrays.asList("title", "originalTitle", "publisher", "isbn", "release", "path", "description"); List<String> values = book.returnSongBook(); if (!songbookChange) { sql.addRow("songbooks", columns, values); } else { sql.updateRow("songbooks", columns, values, "id='" + songbookID + "'"); } songbookChange = false; clearTab(2); clsControlHelper.reloadTable(sql, tblSongbook, true); clsControlHelper.reloadTable(sql, tblSongSongbook); tpnlMain.getSelectionModel().select(pnlMain); } else { clsHelper.createAlert(Alert.AlertType.WARNING, lang.getValue("datasetExists.header.key"), lang.getValue("datasetExists.line.key"), ""); } } else { clsHelper.createAlert(Alert.AlertType.WARNING, lang.getValue("datasetIncompatible.header.key"), lang.getValue("datasetIncompatible.line.key"), ""); } cmdSongbookSubmit.setText(lang.getValue("finish.key")); }); tblSongbook.setOnMouseClicked( event -> clsControlHelper.getSongsFromSongbook(sql, tblSongbook, tblSong, false)); tblSongSongbook.setOnMouseClicked(event -> { clsControlHelper.getSongsFromSongbook(sql, tblSongSongbook, tblSongSong, true); cmdSongPartAdd.setDisable(true); }); tblSongSong.setOnMouseClicked(event1 -> { if (!tblSongSong.getSelectionModel().isEmpty()) { String id = tblSongSong.getSelectionModel().getSelectedItems().get(0).getID(); Map<Integer, String> values = clsControlHelper.listSongPartsAndInfo(sql, tblSongSong, txtSongTitle, txtSongAlbum, txtSongInterpret); if (!id.equals("0")) { lvSongParts.getItems().clear(); for (String item : values.values()) { lvSongParts.getItems().add(item); } clsControlHelper.getOrderedParts(sql, id, lvSongPartOrder); clsControlHelper.resetObjects(true, false, txtSongInterpret, txtSongAlbum, txtSongTitle); clsControlHelper.resetObjects(false, false, cmdSongPartAdd, txtSongPartTitle, txtSongPartContent, lvSongPartOrder, lvSongParts, cmdSongPartAddToOrder, cmdSongPartRemoveFromOrder); clsControlHelper.resetButtons(false, true, lang.getValue("add.key"), cmdSongSubmit); } else { clsControlHelper.resetObjects(false, true, lvSongParts, lvSongPartOrder, txtSongPartTitle, txtSongPartContent, txtSongTitle, txtSongInterpret, txtSongAlbum, cmdSongPartAdd); } } else { cmdSongPartAdd.setDisable(true); } }); tvPictures.setOnMouseClicked(event -> { if (!tvPictures.getSelectionModel().isEmpty()) { currentPicsPath = ((TreeItem) tvPictures.getSelectionModel().getSelectedItem()).getValue() .toString(); currentPicsPath = clsHelper.getPath(((TreeItem) tvPictures.getSelectionModel().getSelectedItem()), currentPicsPath); clsHelper.listFileSystem(currentPicsPath, ((TreeItem) tvPictures.getSelectionModel().getSelectedItem())); } }); cmdSongPartAdd.setOnMouseClicked(event -> { if (!cmdSongPartAdd.getText().equals(lang.getValue("change.key"))) { for (String item : lvSongParts.getItems()) { if (item.equals(txtSongPartTitle.getText())) { clsHelper.createAlert(Alert.AlertType.WARNING, lang.getValue("frmMain.SongPartExists.Title.key"), lang.getValue("frmMain.SongPartExists.Content1.key") + " " + txtSongPartTitle.getText() + " " + lang.getValue("frmMain.SongPartExists.Content2.key"), ""); return; } } if (lvSongParts.getItems().isEmpty()) { if (txtSongAlbum.getText().equals("") && txtSongTitle.getText().equals("") && txtSongInterpret.getText().equals("")) { clsHelper.createAlert(Alert.AlertType.ERROR, lang.getValue("generalInformation.header.key"), lang.getValue("generalInformation.line.key"), ""); } else { if (!tblSongSong.getSelectionModel().getSelectedItem().getID().equals("0")) { ObservableList list = tblSongSong.getItems(); for (int i = 0; i <= list.size() - 1; i++) { if (((SongModel) list.get(i)).getName().equals(txtSongTitle.getText())) { addSongPart(); return; } } } String songbook_id = tblSongSongbook.getSelectionModel().getSelectedItem().getID(); long song_id = sql.addRowGetID("songs", Arrays.asList("title", "interpret", "album", "songbook_id"), Arrays.asList("'" + txtSongTitle.getText() + "'", "'" + txtSongInterpret.getText() + "'", "'" + txtSongAlbum.getText() + "'", songbook_id)); sql.addRow("songparts", Arrays.asList("title", "content", "song_id"), Arrays.asList("'" + txtSongPartTitle.getText().replace("'", "_") + "'", "'" + txtSongPartContent.getText().replace("'", "_") + "'", String.valueOf(song_id))); clsControlHelper.getSongsFromSongbook(sql, tblSongSongbook, tblSongSong, true); for (int i = 0; i <= tblSongSong.getItems().size() - 1; i++) { if (tblSongSong.getItems().get(i).getName().equals(txtSongTitle.getText())) { tblSongSong.getSelectionModel().select(i); } } String strSong_id = tblSongSong.getSelectionModel().getSelectedItems().get(0).getID(); Map<Integer, String> list = clsControlHelper.listSongPartsAndInfo(sql, tblSongSong, txtSongTitle, txtSongAlbum, txtSongInterpret); lvSongParts.getItems().clear(); for (String item : list.values()) { lvSongParts.getItems().add(item); } clsControlHelper.getOrderedParts(sql, strSong_id, lvSongPartOrder); } } else { addSongPart(); } } else { String song_id = tblSongSong.getSelectionModel().getSelectedItem().getID(); String title = lvSongParts.getSelectionModel().getSelectedItem(); sql.updateRow("songparts", Arrays.asList("title", "content"), Arrays.asList("'" + txtSongPartTitle.getText().replace("'", "_") + "'", "'" + txtSongPartContent.getText().replace("'", "_") + "'"), "title='" + title + "' AND song_id=" + song_id); cmdSongPartAdd.setText(lang.getValue("add.key")); String strSong_id = tblSongSong.getSelectionModel().getSelectedItems().get(0).getID(); Map<Integer, String> list = clsControlHelper.listSongPartsAndInfo(sql, tblSongSong, txtSongTitle, txtSongAlbum, txtSongInterpret); lvSongParts.getItems().clear(); for (String item : list.values()) { lvSongParts.getItems().add(item); } clsControlHelper.getOrderedParts(sql, strSong_id, lvSongPartOrder); } txtSongPartContent.setText(""); txtSongPartTitle.setText(""); }); cmdSongSubmit.setOnMouseClicked(event -> { if (!tblSongSong.getSelectionModel().isEmpty()) { if (!cmdSongSubmit.getText().equals(lang.getValue("change.key"))) { String song_id = tblSongSong.getSelectionModel().getSelectedItem().getID(); sql.deleteRow("position", "song_id=" + song_id); for (int i = 1; i <= lvSongPartOrder.getItems().size(); i++) { String songpart_id = sql .getRows("songparts", Collections.singletonList("id"), "title='" + lvSongPartOrder.getItems().get(i - 1) + "' AND song_id=" + song_id) .get(0, "id").toString(); sql.addRow("position", Arrays.asList("song_id", "songpart_id", "position"), Arrays.asList(song_id, songpart_id, String.valueOf(i))); } Map<Integer, String> list = clsControlHelper.listSongPartsAndInfo(sql, tblSongSong, txtSongTitle, txtSongAlbum, txtSongInterpret); lvSongParts.getItems().clear(); for (String item : list.values()) { lvSongParts.getItems().add(item); } clsControlHelper.getOrderedParts(sql, song_id, lvSongPartOrder); txtSongPartContent.setText(""); txtSongPartTitle.setText(""); tpnlMain.getSelectionModel().select(pnlMain); } else { String song_id = tblSongSong.getSelectionModel().getSelectedItem().getID(); sql.updateRow("songs", Arrays.asList("title", "album", "interpret"), Arrays.asList("'" + txtSongTitle.getText() + "'", "'" + txtSongAlbum.getText() + "'", "'" + txtSongInterpret.getText() + "'"), "id=" + song_id); cmdSongSubmit.setText(lang.getValue("finish.key")); Map<Integer, String> list = clsControlHelper.listSongPartsAndInfo(sql, tblSongSong, txtSongTitle, txtSongAlbum, txtSongInterpret); lvSongParts.getItems().clear(); for (String item : list.values()) { lvSongParts.getItems().add(item); } clsControlHelper.getOrderedParts(sql, song_id, lvSongPartOrder); txtSongPartContent.setText(""); txtSongPartTitle.setText(""); tpnlMain.getSelectionModel().select(pnlMain); txtSongPartContent.setDisable(false); txtSongPartTitle.setDisable(false); lvSongPartOrder.setDisable(false); lvSongParts.setDisable(false); cmdSongPartAdd.setDisable(false); cmdSongPartAddToOrder.setDisable(false); cmdSongPartRemoveFromOrder.setDisable(false); } clearTab(3); clearTab(1); clsControlHelper.reloadTable(sql, tblSongbook, true); clsControlHelper.reloadTable(sql, tblSongSongbook); } }); cmdSongPartAddToOrder.setOnMouseClicked(event -> { if (!lvSongParts.getSelectionModel().isEmpty()) { lvSongPartOrder.getItems().add(lvSongParts.getSelectionModel().getSelectedItem()); } }); cmdSongPartRemoveFromOrder.setOnMouseClicked(event -> { if (!lvSongPartOrder.getSelectionModel().isEmpty()) { lvSongPartOrder.getItems().remove(lvSongPartOrder.getSelectionModel().getSelectedIndex()); } }); ctxMainSongAdd.setOnAction(event -> { if (!tblSong.getSelectionModel().isEmpty()) { String songbook_id = tblSongbook.getSelectionModel().getSelectedItem().getID(); String song_id = tblSong.getSelectionModel().getSelectedItem().getID(); String name = tblSong.getSelectionModel().getSelectedItem().getName(); clsControlHelper.listSlides(sql, tblMainSlides, name, song_id, songbook_id); } }); tblMainSlides.setOnMouseClicked(event -> { if (!tblMainSlides.getSelectionModel().isEmpty()) { if (!tblMainSlides.getSelectionModel().getSelectedItem().getSongBookID().equals("999999")) { String songbook_id = tblSongbook.getSelectionModel().getSelectedItem().getID(); SlideModel slide = tblMainSlides.getSelectionModel().getSelectedItem(); String id = sql .getRows("songs", Collections.singletonList("id"), "songbook_id=" + songbook_id + " AND title='" + slide.getSongTitle() + "'") .get(0, "id").toString(); DataTable dt = sql.getRows("songparts", Arrays.asList("title", "content"), "song_id=" + id + " AND title='" + slide.getSongPart() + "'"); txtMainSlideTitle.setText(dt.get(0, "title").toString()); txtMainSlideContent.setText(dt.get(0, "content").toString()); if (currentPicsPath != null) { ObservableList<SlideModel> model = tblMainSlides.getItems(); List<String> ls = new ArrayList<>(); String item = ""; for (SlideModel s : model) { if (!item.equals(s.getSongTitle())) { item = s.getSongTitle(); ls.add(s.getSongTitle()); } } SlideModel selected = tblMainSlides.getSelectionModel().getSelectedItem(); ls.stream().filter(strItem -> strItem.equals(selected.getSongTitle())).forEach(strItem -> { int index = ls.indexOf(strItem); List<String> existingPath = new ArrayList<>(); for (String current : new File(currentPicsPath).list()) { if (current.endsWith("jpg") || current.endsWith("JPG") || current.endsWith("png")) { existingPath.add(current); } } ivMainSlide.setImage( new Image("file:///" + currentPicsPath + "\\" + existingPath.get(index))); }); } cmdMainUserdefined.setDisable(false); } } }); cmdMainExport.setOnAction(event -> { try { if (!txtMainTitle.getText().equals("")) { anchpnlMain.setCursor(Cursor.WAIT); pbMain.setProgress(0.0); if (clsSettings.getMSOffice()) { clsPowerPoint ppt; if (cmbMainEffect.getSelectionModel().isEmpty()) { ppt = new clsPowerPoint(clsSettings.getPathToExport() + File.separatorChar + txtMainTitle.getText() + ".pptx"); } else { ppt = new clsPowerPoint( clsSettings.getPathToExport() + File.separatorChar + txtMainTitle.getText() + ".pptx", sql.getFile("pptFiles", "CONTENT", clsSettings.getPathToExport() + File.separatorChar + txtMainTitle.getText() + ".pptx", "effect='" + cmbMainEffect.getSelectionModel().getSelectedItem() + "'")); } pbMain.setProgress(0.1); List<Integer> picIDs = new ArrayList<>(); if (currentPicsPath != null) { if (new File(currentPicsPath).exists()) { for (String path : new File(currentPicsPath).list()) { if (path.endsWith("jpg") || path.endsWith("JPG") || path.endsWith("png")) { picIDs.add(ppt.addImage(currentPicsPath + File.separatorChar + path)); } } } } String currentSong = ""; int counter = 0; pbMain.setProgress(0.2); double sum = tblMainSlides.getItems().size() / 0.8; ObservableList<SlideModel> model = tblMainSlides.getItems(); for (SlideModel item : model) { if (!item.getSongBookID().equals("999999")) { String song_id = sql .getRows("songs", Collections.singletonList("id"), "songbook_id=" + item.getSongBookID() + " AND title='" + item.getSongTitle() + "'") .get(0, "id").toString(); DataTable dt = sql.getRows("songparts", Arrays.asList("title", "content"), "song_id=" + song_id + " and title='" + item.getSongPart() + "'"); ppt.createNewSlide(SlideLayout.BLANK); if (!currentSong.equals(item.getSongTitle())) { currentSong = item.getSongTitle(); counter++; } if (currentPicsPath != null) { try { ppt.addBackgroundImage(counter - 1); } catch (Exception ex) { System.out.println(ex.toString()); } } ppt.addPlaceholder(item.getSongTitle().replace("_", "'"), Placeholder.TITLE, false, TextAlign.CENTER); ppt.addPlaceholder(dt.get(0, "content").toString().replace("_", "'"), Placeholder.CONTENT, false, TextAlign.CENTER); pbMain.setProgress(pbMain.getProgress() + sum); } else { DataTable dt = sql.getRows("userdefined", Arrays.asList("PH_TITLE", "PH_CONTENT", "PH_POSITION", "MEDIA"), "TITLE='" + item.getSongTitle() + "'"); ppt.createNewSlide(SlideLayout.BLANK); for (int i = 0; i <= dt.rowsCount() - 1; i++) { switch (dt.get(i, "PH_POSITION").toString()) { case "0": ppt.addPlaceholder(dt.get(i, "PH_CONTENT").toString(), Placeholder.TITLE); break; case "1": ppt.addPlaceholder(dt.get(i, "PH_CONTENT").toString(), Placeholder.BODY); break; case "2": ppt.addPlaceholder(dt.get(i, "PH_CONTENT").toString(), Placeholder.CONTENT); break; case "3": ppt.addPlaceholder(dt.get(i, "PH_CONTENT").toString(), 80, 200, (ppt.getWidth() / 2) - 120, ppt.getHeight() - 280); break; case "4": ppt.addPlaceholder(dt.get(i, "PH_CONTENT").toString(), (ppt.getWidth() / 2) + 40, 200, (ppt.getWidth() / 2) - 120, ppt.getHeight() - 280); break; case "5": ppt.addBackgroundImage(ppt.addImage(sql.getFile("userdefined", "MEDIA", "TITLE='" + item.getSongTitle() + "' AND PH_TITLE='" + dt.get(i, "PH_TITLE").toString() + "'"))); break; case "6": ppt.addPlaceholder( ppt.addImage(sql.getFile("userdefined", "MEDIA", "TITLE='" + item.getSongTitle() + "' AND PH_TITLE='" + dt.get(i, "PH_TITLE").toString() + "'")), 80, 200, ppt.getWidth() - 160, ppt.getHeight() - 280); break; default: System.out.println("Not supported yet!"); } } } } ppt.save(); } if (clsSettings.getOpenDocument()) { try { clsODP.Effect effect = null; switch (cmbMainEffect.getSelectionModel().getSelectedIndex()) { case 0: effect = clsODP.Effect.Aufloesen; break; case 1: effect = clsODP.Effect.Karofoermig; break; case 2: effect = clsODP.Effect.Kreisfoermig; break; case 3: effect = clsODP.Effect.Nach_links_aufdecken; break; case 4: effect = clsODP.Effect.Von_links_rollen; break; case 5: effect = clsODP.Effect.Ueber_schwarz_blenden; break; default: effect = clsODP.Effect.Von_unten_rollen; } InputStream in = sql.getFile("templates", "CONTENT", "template.fodp", "FileName='template.fodp'"); in.close(); clsODP odp = new clsODP("template.fodp", clsSettings.getPathToExport() + File.separatorChar + txtMainTitle.getText().replace(" ", "_") + ".odp"); List<String> picIDs = new ArrayList<>(); if (currentPicsPath != null) { if (new File(currentPicsPath).exists()) { for (String path : new File(currentPicsPath).list()) { if (path.endsWith("jpg") || path.endsWith("JPG") || path.endsWith("png")) { picIDs.add(odp.addImage(currentPicsPath + File.separatorChar + path, path)); } } } } String currentSong = ""; int counter = 0; pbMain.setProgress(0.2); double sum = tblMainSlides.getItems().size() / 0.8; ObservableList<SlideModel> model = tblMainSlides.getItems(); int i = 1; for (SlideModel item : model) { if (!item.getSongBookID().equals("999999")) { if (!currentSong.equals(item.getSongTitle())) { currentSong = item.getSongTitle(); counter++; } String song_id = sql.getRows("songs", Collections.singletonList("id"), "songbook_id=" + item.getSongBookID() + " AND title='" + item.getSongTitle() + "'") .get(0, "id").toString(); DataTable dt = sql.getRows("songparts", Arrays.asList("title", "content"), "song_id=" + song_id + " and title='" + item.getSongPart() + "'"); if (currentPicsPath != null) { try { if (picIDs.size() == 0) { odp.addSlide(i, i, effect, item.getSongTitle().replace("_", "'"), dt.get(0, "content").toString().replace("_", "'")); } else { odp.addSlide(i, i, effect, item.getSongTitle().replace("_", "'"), dt.get(0, "content").toString().replace("_", "'"), picIDs.get(counter)); } } catch (Exception ex) { System.out.println(ex.toString()); } } else { odp.addSlide(i, i, clsODP.Effect.Aufloesen, item.getSongTitle().replace("_", "'"), dt.get(0, "content").toString().replace("_", "'")); } pbMain.setProgress(pbMain.getProgress() + sum); i++; } else { DataTable dt = sql.getRows("userdefined", Arrays.asList("PH_TITLE", "PH_CONTENT", "PH_POSITION", "MEDIA"), "TITLE='" + item.getSongTitle() + "'"); String title = "", image = ""; List<String> content = new ArrayList<>(); for (int j = 0; j <= dt.rowsCount() - 1; j++) { switch (dt.get(j, "PH_POSITION").toString()) { case "0": title = odp.buildHeader(dt.get(j, "PH_CONTENT").toString()); break; case "1": content.add(odp.buildcentralText(dt.get(j, "PH_CONTENT").toString(), 25.199, 3.506, 1.4, 5.751)); break; case "2": content.add(odp.buildcentralText(dt.get(j, "PH_CONTENT").toString(), 25.199, 12.179, 1.4, 4.914)); break; case "3": content.add(odp.buildcentralText(dt.get(j, "PH_CONTENT").toString(), 12.599, 12.179, 1.4, 4.914)); break; case "4": content.add(odp.buildcentralText(dt.get(j, "PH_CONTENT").toString(), 12.599, 12.179, 14, 4.914)); break; case "5": image = odp.addImage( sql.getFile("userdefined", "MEDIA", "TITLE='" + item.getSongTitle() + "' AND PH_TITLE='" + dt.get(j, "PH_TITLE").toString() + "'"), String.valueOf(new Date().getTime())); break; default: System.out.println("Not supported yet!"); } } if (image.equals("")) { odp.addSlide(i, i, effect, !title.equals(""), title, content); } else { odp.addSlide(i, i, effect, !title.equals(""), title, content, image); } } } odp.isLast(); } catch (Exception ex) { clsHelper.printException(ex); } } tblMainSlides.getColumns().clear(); txtMainTitle.setText(""); cmbMainEffect.getSelectionModel().select(null); tblSong.getItems().clear(); tblSongbook.getSelectionModel().clearSelection(); clearTab(1); clsControlHelper.reloadTable(sql, tblSongbook, true); anchpnlMain.setCursor(Cursor.DEFAULT); pbMain.setProgress(1); } else { clsHelper.createAlert(Alert.AlertType.WARNING, lang.getValue("frmMain.NoTitle.Title.key"), lang.getValue("frmMain.NoTitle.Content.key"), ""); } } catch (Exception ex) { clsHelper.printException(ex); } finally { anchpnlMain.setCursor(Cursor.DEFAULT); } }); tblSong.setOnMouseClicked(event -> { if (!tblSong.getSelectionModel().isEmpty()) { menExtrasExportAsWord.setDisable(false); menExtrasExportAsODT.setDisable(false); } }); menExtrasExportAsWord.setOnAction(event -> { clsXML xml = new clsXML(new File(clsHelper.getPath() + File.separatorChar + "config.xml")); clsWord doc = new clsWord(xml.getElementValue("PathToExport").replace(";", "") + File.separatorChar + tblSong.getSelectionModel().getSelectedItem().getName().replace(" ", "_") + ".doc"); doc.addHeader(tblSong.getSelectionModel().getSelectedItem().getName().replace("_", "'")); ObservableList<SlideModel> model = tblMainSlides.getItems(); List<String> paragraph = new ArrayList<>(); String interpret = ""; for (SlideModel item : model) { if (tblSong.getSelectionModel().getSelectedItem().getName().equals(item.getSongTitle())) { DataTable dt = sql.getRows("songs", Arrays.asList("id", "interpret"), "songbook_id=" + item.getSongBookID() + " AND title='" + item.getSongTitle() + "'"); DataTable dt2 = sql.getRows("songparts", Arrays.asList("title", "content"), "song_id=" + dt.get(0, "id").toString() + " and title='" + item.getSongPart() + "'"); paragraph.add(dt2.get(0, "content").toString().replace("_", "'")); interpret = dt.get(0, "interpret").toString(); } } doc.addSubTitle(interpret); for (String par : paragraph) { doc.addContent(par, ParagraphAlignment.CENTER); } doc.save(); }); menExtrasExportAsODT.setOnAction(event1 -> { try { FileInputStream in = sql.getFile("templates", "Content", clsSettings.getPathToExport() + File.separatorChar + tblSong.getSelectionModel().getSelectedItem().getName().replace(" ", "_") + ".odt", "FileName='template.fodt'"); Reader r = new InputStreamReader(in, "UTF8"); StringBuilder builder = new StringBuilder(); final int[] ch = new int[1]; while ((ch[0] = r.read()) != -1) { builder.append((char) ch[0]); } in.close(); String doccontent = builder.toString().replace("###Titel###", tblSong.getSelectionModel().getSelectedItem().getName().replace("_", "'")); String part = "", interpret = ""; ObservableList<SlideModel> model = tblMainSlides.getItems(); for (SlideModel item : model) { if (tblSong.getSelectionModel().getSelectedItem().getName().equals(item.getSongTitle())) { DataTable song = sql.getRows("songs", Arrays.asList("id", "interpret"), "songbook_id=" + item.getSongBookID() + " AND title='" + item.getSongTitle() + "'"); interpret = song.get(0, "interpret").toString(); DataTable dt = sql.getRows("songparts", Arrays.asList("title", "content"), "song_id=" + song.get(0, "id").toString() + " and title='" + item.getSongPart() + "'"); for (String line : dt.get(0, "content").toString().split("\n")) { part += "<text:p text:style-name=\"P2\">" + line + "</text:p>\n"; } part += "<text:p text:style-name=\"P1\"/>\n"; } } doccontent = doccontent.replace("###Content###", part); doccontent = doccontent.replace("###SubTitle###", interpret); Writer out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(clsSettings.getPathToExport() + File.separatorChar + tblSong.getSelectionModel().getSelectedItem().getName().replace(" ", "_") + ".odt"), "UTF8")); out.append(doccontent); out.flush(); out.close(); } catch (Exception ex) { clsHelper.printException(ex); } }); ctxSongOpenLyrics.setOnAction(event -> { if (!txtSongTitle.getText().equals("") && !txtSongInterpret.getText().equals("")) { clsLyricWiki lyric = new clsLyricWiki(txtSongInterpret.getText().replace(" ", "%20"), txtSongTitle.getText().replace(" ", "%20")); try { String ur = new URI(lyric.getURL()).toString(); if (!ur.equals("")) { Desktop.getDesktop().browse(new URI(lyric.getURL())); } else { clsHelper.createAlert(Alert.AlertType.INFORMATION, lang.getValue("frmMain.NothingFount.title.key"), lang.getValue("frmMain.NothingFount.content.key"), ""); } } catch (URISyntaxException | IOException e) { clsHelper.printException(e); } } }); ctxMainSongRemove.setOnAction(event -> { if (!tblSong.getSelectionModel().isEmpty()) { SongModel song = tblSong.getSelectionModel().getSelectedItem(); SongbookModel book = tblSongbook.getSelectionModel().getSelectedItem(); ObservableList<SlideModel> slides = tblMainSlides.getItems(); for (int i = 0; i <= slides.size() - 1; i++) { if (song.getName().equals(slides.get(i).getSongTitle()) && book.getID().equals(slides.get(i).getSongBookID())) { slides.remove(i); } } tblMainSlides.getItems().clear(); tblMainSlides.setItems(slides); } }); cmdMainUserdefined.setOnAction(event -> { try { frmUserdefinedController controller = new frmUserdefinedController(); FXMLLoader loader = new FXMLLoader( DJPresentationMaker.class.getResource("forms/frmUserdefined.fxml")); loader.setController(controller); loader.setResources(clsLang.getLangBundle()); Parent root = loader.load(); Scene scene = new Scene(root); Stage stage = new Stage(); stage.setScene(scene); stage.setTitle(lang.getValue("frmMain.userdefined.key")); stage.getIcons() .add(new Image(DJPresentationMaker.class.getResourceAsStream("style/logo_128.png"))); stage.showAndWait(); clsControlHelper.reloadTable(sql, tblSongbook, true); } catch (Exception ex) { clsHelper.printException(ex); } }); }
From source file:edu.cqupt.test.SimpleDocument.java
License:Apache License
public static void main(String[] args) throws Exception { XWPFDocument doc = new XWPFDocument(); XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); p1.setBorderBottom(Borders.DOUBLE);/*from w w w . j a v a2s . c o m*/ p1.setBorderTop(Borders.DOUBLE); p1.setBorderRight(Borders.DOUBLE); p1.setBorderLeft(Borders.DOUBLE); p1.setBorderBetween(Borders.SINGLE); p1.setVerticalAlignment(TextAlignment.TOP); XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setText("The quick brown fox"); r1.setBold(true); r1.setFontFamily("Courier"); r1.setUnderline(UnderlinePatterns.DOT_DOT_DASH); r1.setTextPosition(100); XWPFParagraph p2 = doc.createParagraph(); p2.setAlignment(ParagraphAlignment.RIGHT); // BORDERS p2.setBorderBottom(Borders.DOUBLE); p2.setBorderTop(Borders.DOUBLE); p2.setBorderRight(Borders.DOUBLE); p2.setBorderLeft(Borders.DOUBLE); p2.setBorderBetween(Borders.SINGLE); XWPFRun r2 = p2.createRun(); r2.setText("jumped over the lazy dog"); //r2.setStrike(true); r2.setFontSize(20); XWPFRun r3 = p2.createRun(); r3.setText("and went away"); //r3.setStrike(true); r3.setFontSize(20); r3.setSubscript(VerticalAlign.SUPERSCRIPT); XWPFParagraph p3 = doc.createParagraph(); //p3.setWordWrap(true); p3.setPageBreak(true); // p3.setAlignment(ParagraphAlignment.DISTRIBUTE); p3.setAlignment(ParagraphAlignment.BOTH); p3.setSpacingLineRule(LineSpacingRule.EXACT); p3.setIndentationFirstLine(600); XWPFRun r4 = p3.createRun(); r4.setTextPosition(20); r4.setText("??? " + "Whether 'tis nobler in the mind to suffer " + "The slings and arrows of outrageous fortune, " + "Or to take arms against a sea of troubles, " + "And by opposing end them? To die: to sleep; "); r4.addBreak(BreakType.PAGE); r4.setText("No more; and by a sleep to say we end " + "The heart-ache and the thousand natural shocks " + "That flesh is heir to, 'tis a consummation " + "Devoutly to be wish'd. To die, to sleep; " + "To sleep: perchance to dream: ay, there's the rub; " + "......."); r4.setItalic(true); // This would imply that this break shall be treated as a simple line // break, and break the line after that word: XWPFRun r5 = p3.createRun(); r5.setTextPosition(-10); r5.setText("For in that sleep of death what dreams may come"); r5.addCarriageReturn(); r5.setText("When we have shuffled off this mortal coil," + "Must give us pause: there's the respect" + "That makes calamity of so long life;"); r5.addBreak(); r5.setText("For who would bear the whips and scorns of time," + "The oppressor's wrong, the proud man's contumely,"); r5.addBreak(BreakClear.ALL); r5.setText("The pangs of despised love, the law's delay," + "The insolence of office and the spurns" + "......."); FileOutputStream out = new FileOutputStream("F://simple.docx"); doc.write(out); out.close(); }
From source file:edu.gatech.pmase.capstone.awesome.impl.output.DisasterResponseTradeStudyOutputer.java
License:Open Source License
/** * Creates the architecture attribute description cell. * * @param detailsCell the cell to create the description in * @param attrs the attributes to put into the description *//*from w w w . j a v a 2 s . c om*/ private void createArchitectureAttributeDescription(final XWPFTableCell detailsCell, final List<ArchitectureOptionAttribute> attrs) { for (int x = 0; x < attrs.size(); x++) { final ArchitectureOptionAttribute attr = attrs.get(x); LOGGER.debug("Creating architecture option description for attribute: " + attr.getLabel()); final XWPFParagraph para; if (x == 0) { para = detailsCell.getParagraphs().get(0); } else { para = detailsCell.addParagraph(); } final XWPFRun rh = para.createRun(); rh.setText(DisasterResponseTradeStudyOutputer.createAttribtueString(attr)); para.setAlignment(ParagraphAlignment.CENTER); } }
From source file:edu.gatech.pmase.capstone.awesome.impl.output.DisasterResponseTradeStudyOutputer.java
License:Open Source License
/** * Creates output for architecture options if no architecture was found. * * @param label the cell with the label//from www . j a va2 s. co m * @param optionName the name of the option to place */ private static void createNoOptionText(final XWPFTableCell label, final String optionName) { LOGGER.debug("Creationg No Option Text for option: " + optionName); final XWPFParagraph platPara = label.getParagraphs().get(0); final XWPFRun rh = platPara.createRun(); rh.setColor(DisasterResponseTradeStudyOutputer.NO_OPT_TEXT_COLOR); rh.setText("No " + optionName + " Satisfies Selections"); platPara.setAlignment(ParagraphAlignment.CENTER); }
From source file:eremeykin.pete.reports.ui.ReportAction.java
@Override public void actionPerformed(ActionEvent e) { resultChanged(null);/*w w w. j a v a 2 s. c o m*/ if (model == null) { return; } XWPFDocument doc = new XWPFDocument(); XWPFParagraph p1 = doc.createParagraph(); p1.setAlignment(ParagraphAlignment.CENTER); p1.setVerticalAlignment(TextAlignment.TOP); XWPFRun r1 = p1.createRun(); r1.setBold(true); r1.setText(""); r1.setBold(true); r1.setFontFamily("Times New Roman"); r1.setFontSize(24); r1.setTextPosition(10); XWPFParagraph p2 = doc.createParagraph(); p2.setAlignment(ParagraphAlignment.LEFT); p2.setVerticalAlignment(TextAlignment.CENTER); XWPFRun r2 = p2.createRun(); r2.setText(" ? : "); r2.setBold(false); r2.setFontFamily("Times New Roman"); r2.setFontSize(14); r2.setTextPosition(10); XWPFTable table = doc.createTable(1, 2); table.getCTTbl().addNewTblPr().addNewTblW().setW(BigInteger.valueOf(9000)); ModelParameter root = model.getRoot(); int row = 1; Map.Entry<ModelParameter, Integer> kv = model.getParameterAndLevelByID(root, 0); ModelParameter parameter = kv.getKey(); Integer level = kv.getValue(); ArrayList<Integer> ids = new ArrayList(model.asMap().keySet()); Collections.sort(ids); for (Integer each : ids) { table.createRow(); String text = ""; kv = model.getParameterAndLevelByID(root, each); parameter = kv.getKey(); level = kv.getValue(); for (int c = 0; c < level; c++) { text += " "; } table.getRow(row - 1).getCell(0).setText(text + parameter.toString()); table.getRow(row - 1).getCell(1).setText(parameter.getValue()); row++; } table.setWidth(80); XWPFParagraph p3 = doc.createParagraph(); p3.setAlignment(ParagraphAlignment.LEFT); p3.setVerticalAlignment(TextAlignment.CENTER); XWPFRun r3 = p3.createRun(); r3.addBreak(); r3.setText("\n : "); r3.setBold(false); r3.setFontFamily("Times New Roman"); r3.setFontSize(14); File uPlotFile = new File(WorkspaceManager.INSTANCE.getWorkspace().getAbsolutePath() + "/uplot.png"); try { byte[] picbytes = IOUtils.toByteArray(new FileInputStream(uPlotFile)); doc.addPictureData(picbytes, XWPFDocument.PICTURE_TYPE_PNG); XWPFRun pr = doc.createParagraph().createRun(); pr.addPicture(new FileInputStream(uPlotFile), Document.PICTURE_TYPE_PNG, "plot.png", Units.toEMU(450), Units.toEMU(337)); pr.addCarriageReturn(); pr.addBreak(BreakType.PAGE); pr.addBreak(BreakType.TEXT_WRAPPING); } catch (Exception ex) { Exceptions.printStackTrace(ex); } XWPFParagraph p4 = doc.createParagraph(); p4.setAlignment(ParagraphAlignment.LEFT); p4.setVerticalAlignment(TextAlignment.CENTER); XWPFRun r4 = p4.createRun(); r4.addBreak(); r4.setText("\n ?: "); r4.setBold(false); r4.setFontFamily("Times New Roman"); r4.setFontSize(14); File sPlotFile = new File(WorkspaceManager.INSTANCE.getWorkspace().getAbsolutePath() + "/splot.png"); try { byte[] picbytes = IOUtils.toByteArray(new FileInputStream(sPlotFile)); doc.addPictureData(picbytes, XWPFDocument.PICTURE_TYPE_PNG); XWPFParagraph pp = doc.createParagraph(); pp.createRun().addPicture(new FileInputStream(sPlotFile), Document.PICTURE_TYPE_PNG, "plot.png", Units.toEMU(450), Units.toEMU(337)); } catch (Exception ex) { Exceptions.printStackTrace(ex); } File reportFile = new File("report.docx"); try (FileOutputStream out = new FileOutputStream(reportFile)) { doc.write(out); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().edit(reportFile); } else { } } catch (IOException ex) { Exceptions.printStackTrace(ex); } }