List of usage examples for java.awt.print PageFormat PageFormat
public PageFormat()
From source file:org.jab.docsearch.DocSearch.java
/** * Constructor/*from ww w .j a va 2 s . c o m*/ */ public DocSearch() { super(I18n.getString("ds.windowtitle")); // get logger logger = Logger.getLogger(getClass().getName()); // File testCDFi = new File(cdRomDefaultHome); Properties sys = new Properties(System.getProperties()); if (testCDFi.exists()) { sys.setProperty("disableLuceneLocks", "true"); logger.info("DocSearch() Disabling Lucene Locks for CDROM indexes"); } else { sys.setProperty("disableLuceneLocks", "false"); } // checkCDROMDir(); defaultHndlr = getBrowserFile(); loadSettings(); // pPanel = new ProgressPanel("", 100L); pPanel.init(); phrase = new JRadioButton(I18n.getString("label.phrase")); searchField = new JComboBox(); searchIn = new JComboBox(searchOptsLabels); JLabel searchTypeLabel = new JLabel(I18n.getString("label.search_type")); JLabel searchInLabel = new JLabel(I18n.getString("label.search_in")); keywords = new JRadioButton(I18n.getString("label.keyword")); // searchLabel = new JLabel(I18n.getString("label.search_for")); searchButton = new JButton(I18n.getString("button.search")); searchButton.setActionCommand("ac_search"); searchButton.setMnemonic(KeyEvent.VK_A); // TODO alt text to resource htmlTag = "<img src=\"" + fEnv.getIconURL(FileType.HTML.getIcon()) + "\" border=\"0\" alt=\"Web Page Document\">"; wordTag = "<img src=\"" + fEnv.getIconURL(FileType.MS_WORD.getIcon()) + "\" border=\"0\" alt=\"MS Word Document\">"; excelTag = "<img src=\"" + fEnv.getIconURL(FileType.MS_EXCEL.getIcon()) + "\" border=\"0\" alt=\"MS Excel Document\">"; pdfTag = "<img src=\"" + fEnv.getIconURL(FileType.PDF.getIcon()) + "\" border=\"0\" alt=\"PDF Document\">"; textTag = "<img src=\"" + fEnv.getIconURL(FileType.TEXT.getIcon()) + "\" border=\"0\" alt=\"Text Document\">"; rtfTag = "<img src=\"" + fEnv.getIconURL(FileType.RTF.getIcon()) + "\" border=\"0\" alt=\"RTF Document\">"; ooImpressTag = "<img src=\"" + fEnv.getIconURL(FileType.OO_IMPRESS.getIcon()) + "\" border=\"0\" alt=\"OpenOffice Impress Document\">"; ooWriterTag = "<img src=\"" + fEnv.getIconURL(FileType.OO_WRITER.getIcon()) + "\" border=\"0\" alt=\"OpenOffice Writer Document\">"; ooCalcTag = "<img src=\"" + fEnv.getIconURL(FileType.OO_CALC.getIcon()) + "\" border=\"0\" alt=\"OpenOffice Calc Document\">"; ooDrawTag = "<img src=\"" + fEnv.getIconURL(FileType.OO_DRAW.getIcon()) + "\" border=\"0\" alt=\"OpenOffice Draw Document\">"; openDocumentTextTag = "<img src=\"" + fEnv.getIconURL(FileType.OPENDOCUMENT_TEXT.getIcon()) + "\" border=\"0\" alt=\"OpenDocument Text Document\">"; // idx = new Index(this); colors = new String[2]; colors[0] = "ffeffa"; colors[1] = "fdffda"; if (env.isWebStart()) { startPageString = getClass().getResource("/" + FileEnvironment.FILENAME_START_PAGE_WS).toString(); helpPageString = getClass().getResource("/" + FileEnvironment.FILENAME_HELP_PAGE_WS).toString(); if (startPageString != null) { logger.debug("DocSearch() Start Page is: " + startPageString); hasStartPage = true; } else { logger.error("DocSearch() Start Page NOT FOUND where expected: " + startPageString); } } else { startPageString = FileUtils.addFolder(fEnv.getStartDirectory(), FileEnvironment.FILENAME_START_PAGE); helpPageString = FileUtils.addFolder(fEnv.getStartDirectory(), FileEnvironment.FILENAME_HELP_PAGE); File startPageFile = new File(startPageString); if (startPageFile.exists()) { logger.debug("DocSearch() Start Page is: " + startPageString); hasStartPage = true; } else { logger.error("DocSearch() Start Page NOT FOUND where expected: " + startPageString); } } defaultSaveFolder = FileUtils.addFolder(fEnv.getWorkingDirectory(), "saved_searches"); searchField.setEditable(true); searchField.addItem(""); bg = new ButtonGroup(); bg.add(phrase); bg.add(keywords); keywords.setSelected(true); keywords.setToolTipText(I18n.getString("tooltip.keyword")); phrase.setToolTipText(I18n.getString("tooltip.phrase")); int iconInt = 2; searchField.setPreferredSize(new Dimension(370, 22)); // application icon Image iconImage = Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/ds.gif")); this.setIconImage(iconImage); // menu bar JMenuBar menuBar = createMenuBar(); // add menu to frame setJMenuBar(menuBar); // tool bar JToolBar toolbar = createToolBar(); editorPane = new JEditorPane("text/html", lastSearch); editorPane.setEditable(false); editorPane.addHyperlinkListener(new Hyperactive()); if (hasStartPage) { try { editorPane.setContentType("text/html"); if (setPage("home")) { logger.info("DocSearch() loaded start page: " + startPageString); } } catch (Exception e) { editorPane.setText(lastSearch); } } else { logger.warn("DocSearch() no start page loaded"); } scrollPane = new JScrollPane(editorPane); scrollPane.setPreferredSize(new Dimension(1024, 720)); scrollPane.setMinimumSize(new Dimension(900, 670)); scrollPane.setMaximumSize(new Dimension(1980, 1980)); // create panels // add printing stuff vista = new JComponentVista(editorPane, new PageFormat()); JPanel topPanel = new JPanel(); topPanel.add(searchLabel); topPanel.add(searchField); topPanel.add(searchButton); JPanel bottomPanel = new JPanel(); bottomPanel.add(searchTypeLabel); bottomPanel.add(keywords); bottomPanel.add(phrase); bottomPanel.add(searchInLabel); bottomPanel.add(searchIn); // GUI items for advanced searching useDate = new JCheckBox(I18n.getString("label.use_date_property")); fromField = new JTextField(11); JLabel fromLabel = new JLabel(I18n.getString("label.from")); JLabel toLabel = new JLabel(I18n.getString("label.to")); toField = new JTextField(11); cbl = new CheckBoxListener(); authorPanel = new JPanel(); useAuthor = new JCheckBox(I18n.getString("label.use_auth_property")); authorField = new JTextField(31); JLabel authorLabel = new JLabel(I18n.getString("label.author")); authorPanel.add(useAuthor); authorPanel.add(authorLabel); authorPanel.add(authorField); // combine stuff JPanel datePanel = new JPanel(); datePanel.add(useDate); datePanel.add(fromLabel); datePanel.add(fromField); datePanel.add(toLabel); datePanel.add(toField); JPanel metaPanel = new JPanel(); metaPanel.setLayout(new BorderLayout()); metaPanel.setBorder(new TitledBorder(I18n.getString("label.date_and_author"))); metaPanel.add(datePanel, BorderLayout.NORTH); metaPanel.add(authorPanel, BorderLayout.SOUTH); useDate.addActionListener(cbl); useAuthor.addActionListener(cbl); fromField.setText(DateTimeUtils.getLastYear()); toField.setText(DateTimeUtils.getToday()); authorField.setText(System.getProperty("user.name")); JPanel[] panels = new JPanel[numPanels]; for (int i = 0; i < numPanels; i++) { panels[i] = new JPanel(); } // add giu to panels panels[0].setLayout(new BorderLayout()); panels[0].add(topPanel, BorderLayout.NORTH); panels[0].add(bottomPanel, BorderLayout.SOUTH); panels[0].setBorder(new TitledBorder(I18n.getString("label.search_critera"))); searchButton.addActionListener(this); JPanel fileTypePanel = new JPanel(); useType = new JCheckBox(I18n.getString("label.use_filetype_property")); useType.addActionListener(cbl); fileType = new JComboBox(fileTypesToFindLabel); JLabel fileTypeLabel = new JLabel(I18n.getString("label.find_only_these_filetypes")); fileTypePanel.add(useType); fileTypePanel.add(fileTypeLabel); fileTypePanel.add(fileType); JPanel sizePanel = new JPanel(); useSize = new JCheckBox(I18n.getString("label.use_filesize_property")); useSize.addActionListener(cbl); // TODO l18n kbytes JLabel sizeFromLabel = new JLabel(I18n.getString("label.from") + " KByte"); JLabel sizeToLabel = new JLabel(I18n.getString("label.to") + " KByte"); sizeFromField = new JTextField(10); sizeFromField.setText("0"); sizeToField = new JTextField(10); sizeToField.setText("100"); sizePanel.add(useSize); sizePanel.add(sizeFromLabel); sizePanel.add(sizeFromField); sizePanel.add(sizeToLabel); sizePanel.add(sizeToField); JPanel sizeAndTypePanel = new JPanel(); sizeAndTypePanel.setLayout(new BorderLayout()); sizeAndTypePanel.setBorder(new TitledBorder(I18n.getString("label.filetype_and_size"))); sizeAndTypePanel.add(fileTypePanel, BorderLayout.NORTH); sizeAndTypePanel.add(sizePanel, BorderLayout.SOUTH); // set up the tabbed pane JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab(I18n.getString("label.general"), null, panels[0], I18n.getString("tooltip.general_search_criteria")); tabbedPane.addTab(I18n.getString("label.date_and_author"), null, metaPanel, I18n.getString("tooltip.date_auth_options")); tabbedPane.addTab(I18n.getString("label.filetype_and_size"), null, sizeAndTypePanel, I18n.getString("tooltip.filetype_and_size_options")); // gridbag getContentPane().setLayout(new GridLayout(1, numPanels + iconInt + 1)); GridBagLayout gridbaglayout = new GridBagLayout(); GridBagConstraints gridbagconstraints = new GridBagConstraints(); getContentPane().setLayout(gridbaglayout); gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; gridbagconstraints.insets = new Insets(1, 1, 1, 1); gridbagconstraints.gridx = 0; gridbagconstraints.gridy = 0; gridbagconstraints.gridwidth = 1; gridbagconstraints.gridheight = 1; gridbagconstraints.weightx = 1.0D; gridbagconstraints.weighty = 0.0D; gridbaglayout.setConstraints(toolbar, gridbagconstraints); getContentPane().add(toolbar); int start = 1; for (int i = 0; i < numPanels; i++) { if (i == 0) { gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; gridbagconstraints.insets = new Insets(1, 1, 1, 1); gridbagconstraints.gridx = 0; gridbagconstraints.gridy = i + start; gridbagconstraints.gridwidth = 1; gridbagconstraints.gridheight = 1; gridbagconstraints.weightx = 1.0D; gridbagconstraints.weighty = 0.0D; gridbaglayout.setConstraints(tabbedPane, gridbagconstraints); getContentPane().add(tabbedPane); } else { gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; gridbagconstraints.insets = new Insets(1, 1, 1, 1); gridbagconstraints.gridx = 0; gridbagconstraints.gridy = i + start; gridbagconstraints.gridwidth = 1; gridbagconstraints.gridheight = 1; gridbagconstraints.weightx = 1.0D; gridbagconstraints.weighty = 0.0D; gridbaglayout.setConstraints(panels[i], gridbagconstraints); getContentPane().add(panels[i]); } } // now add the results area gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; gridbagconstraints.insets = new Insets(1, 1, 1, 1); gridbagconstraints.gridx = 0; gridbagconstraints.gridy = iconInt; gridbagconstraints.gridwidth = 1; gridbagconstraints.gridheight = 1; gridbagconstraints.weightx = 1.0D; gridbagconstraints.weighty = 1.0D; gridbaglayout.setConstraints(scrollPane, gridbagconstraints); getContentPane().add(scrollPane); JPanel statusP = new JPanel(); statusP.setLayout(new BorderLayout()); statusP.add(dirLabel, BorderLayout.WEST); statusP.add(pPanel, BorderLayout.EAST); // now add the status label gridbagconstraints.fill = GridBagConstraints.HORIZONTAL; gridbagconstraints.insets = new Insets(1, 1, 1, 1); gridbagconstraints.gridx = 0; gridbagconstraints.gridy = numPanels + iconInt; gridbagconstraints.gridwidth = 1; gridbagconstraints.gridheight = 1; gridbagconstraints.weightx = 1.0D; gridbagconstraints.weighty = 0.0D; gridbaglayout.setConstraints(statusP, gridbagconstraints); getContentPane().add(statusP); // File testArchDir = new File(fEnv.getArchiveDirectory()); if (!testArchDir.exists()) { boolean madeDir = testArchDir.mkdir(); if (!madeDir) { logger.warn("DocSearch() Error creating directory: " + fEnv.getArchiveDirectory()); } else { logger.info("DocSearch() Directory created: " + fEnv.getArchiveDirectory()); } } loadIndexes(); // DocTypeHandler String handlersFiName; if (!isCDSearchTool) { handlersFiName = FileUtils.addFolder(fEnv.getWorkingDirectory(), DocTypeHandlerUtils.HANDLER_FILE); } else { handlersFiName = FileUtils.addFolder(cdRomDefaultHome, DocTypeHandlerUtils.HANDLER_FILE); } DocTypeHandlerUtils dthUtils = new DocTypeHandlerUtils(); if (!FileUtils.fileExists(handlersFiName)) { logger.warn("DocSearch() Handlers file not found at: " + handlersFiName); handlerList = dthUtils.getInitialHandler(env); } else { handlerList = dthUtils.loadHandler(handlersFiName); } }
From source file:org.jab.docsearch.DocSearch.java
/** * Method doSearch// w w w . ja va 2 s . c o m * * @param searchText Search text */ public void doSearch(String searchText) { // TODO format date with locale setStatus(I18n.getString("please_wait...") + " " + I18n.getString("searching") + " --> " + searchText); setSearching(true); setIsWorking(true); int srchMaxPos = indexes.size() * 3; if (srchMaxPos > 0) { pPanel.setMaxPos(srchMaxPos); } synchronized (this) { ArrayList[] sizeList = null; if (phrase.isSelected()) { if (searchText.indexOf("\"") == -1) { searchText = "\"" + searchText + "\""; } } // for each di - search and add the results int grandTotalHits = 0; int selectedFields = searchIn.getSelectedIndex(); String sField = searchOpts[selectedFields]; StringBuffer searchedIndexes = new StringBuffer(); StringBuffer bodyBuf = new StringBuffer(); StringBuffer hitBuf = new StringBuffer(); hitBuf.append("<html><head><title>"); hitBuf.append(I18n.getString("results_for_search")); hitBuf.append(' '); hitBuf.append(searchText); hitBuf.append("</title></head><body><h1 align=\"center\">"); hitBuf.append(I18n.getString("results_for_search")); hitBuf.append(": "); hitBuf.append("<strong><font color=\"blue\">"); hitBuf.append(searchText); hitBuf.append("</font></strong></h1>"); if (env.isGUIMode()) { if (logger.isDebugEnabled()) { logger.debug("doSearch() search for '" + searchText + "'"); } } else { System.out.println(I18n.getString("results_for_search") + ": " + searchText); } if (!indexes.isEmpty()) { try { int curSrchPos = 0; // add the items Iterator<DocSearcherIndex> iterator = indexes.iterator(); while (iterator.hasNext()) { curSrchPos++; if (curSrchPos > 0) { pPanel.setCurPos(curSrchPos); } DocSearcherIndex currentIndex = iterator.next(); boolean isCdRomIdx = currentIndex.isCdrom(); StringBuffer tempBuf = new StringBuffer(); if (currentIndex.getShouldBeSearched()) { String findText = ""; // create searcher Searcher searcher = new IndexSearcher(currentIndex.getIndexPath()); if ((searchText.indexOf("(") != -1) || (searchText.indexOf("[") != -1)) { findText = searchText; } else { // add body and title, or single field to query if (selectedFields == 0) { findText = "+(" + Index.FIELD_BODY + ":(" + searchText + ") OR " + Index.FIELD_TITLE + ":(" + searchText + "))"; } else { // TODO dont use sField directly, because it // is translated in other languages findText = "+" + sField + ":(" + searchText + ")"; } // add author to query if (useAuthor.isSelected()) { findText += " +" + Index.FIELD_AUTHOR + ":(" + authorField.getText() + ")"; } // add filetype to query if (useType.isSelected()) { findText += " +" + Index.FIELD_TYPE + ":(" + fileTypesToFind[fileType.getSelectedIndex()] + ")"; } } logger.debug("doSearch() query string '" + findText + "'"); setStatus(dsSrchStr + ": " + findText + "..."); // create query QueryParser queryParser = new QueryParser(Index.FIELD_BODY, new StandardAnalyzer()); Query query = queryParser.parse(findText); // check for date filter and search in index Hits hits; if (useDate.isSelected()) { String dateFrom = DateTimeUtils.getDateStringForIndex( DateTimeUtils.getDateFromString(fromField.getText())); String dateTo = DateTimeUtils .getDateStringForIndex(DateTimeUtils.getDateFromString(toField.getText())); RangeFilter rangeFilter = new RangeFilter(Index.FIELD_MODDATE, dateFrom, dateTo, true, true); if (logger.isDebugEnabled()) { logger.debug("doSearch() search with date range '" + rangeFilter + "'"); } hits = searcher.search(query, rangeFilter); } else { if (logger.isDebugEnabled()) { logger.debug("doSearch() search without date range"); } hits = searcher.search(query); } // check for search with filesize int numHits; if (useSize.isSelected()) { int minFilesize = 1; int maxFilesize = 2; try { minFilesize = Integer.parseInt(sizeFromField.getText()) * 1024; maxFilesize = Integer.parseInt(sizeToField.getText()) * 1024; } catch (Exception e) { setStatus(dsErrParseNums + " " + e.toString()); } sizeList = getHitsForFilesizeRange(hits, minFilesize, maxFilesize); numHits = sizeList[0].size(); } else { numHits = hits.length(); // NOT A SIZE QUERY } searchedIndexes.append("<li> <font color=\"blue\">"); searchedIndexes.append(currentIndex.getName()); searchedIndexes.append("</font> (<b>"); searchedIndexes.append(numHits); searchedIndexes.append("</b> "); searchedIndexes.append(I18n.getString("documents")); searchedIndexes.append(")</li>"); if (env.isGUIMode()) { if (logger.isDebugEnabled()) { logger.debug("doSearch() Index: " + currentIndex.getName()); } } else { System.out.println(I18n.getString("index") + ": " + currentIndex.getName()); } grandTotalHits += numHits; tempBuf.append("<p align=\"center\"><b>"); tempBuf.append(numHits); tempBuf.append("</b> "); tempBuf.append(I18n.getString("documents_found_in_index")); tempBuf.append("<b> "); tempBuf.append(currentIndex.getName()); tempBuf.append("</b></p>"); curSrchPos++; if (curSrchPos > 0) { pPanel.setCurPos(curSrchPos); } for (int i = 0; i < numHits; i++) { if (i > maxNumHitsShown) { setStatus(dsMxNumHits + " (" + maxNumHitsShown + ") " + I18n.getString("exceeded") + " (" + numHits + ")."); break; } // get document and score from result or special // result Document currentDocument; float currentScore; // filesize result? if (useSize.isSelected()) { currentDocument = (Document) sizeList[0].get(i); currentScore = ((Float) sizeList[1].get(i)).floatValue(); } else { currentDocument = hits.doc(i); currentScore = hits.score(i); } // title String currentTitle = Utils .convertTextToHTML(currentDocument.get(Index.FIELD_TITLE)); // filesize String currentFilesize = currentDocument.get(Index.FIELD_SIZE); // path or url String currentFile; if (!currentIndex.getIsWeb()) { if (!isCdRomIdx) { currentFile = currentDocument.get(Index.FIELD_PATH); } else { currentFile = getCDROMPath(currentDocument.get(Index.FIELD_URL)); } } else { currentFile = currentDocument.get(Index.FIELD_URL); } // type String currentTypeStr = currentDocument.get(Index.FIELD_TYPE); FileType currentType = FileType.fromValue(currentTypeStr); // author String currentAuthor = currentDocument.get(Index.FIELD_AUTHOR); if ("".equals(currentAuthor)) { currentAuthor = I18n.getString("unknown"); } // date String currentDate = currentDocument.get(Index.FIELD_MODDATE); if ("".equals(currentDate)) { currentDate = I18n.getString("unknown"); } else { currentDate = DateTimeUtils.getDateParsedFromIndex(currentDate); } String currentSummary = Utils .convertTextToHTML(currentDocument.get(Index.FIELD_SUMMARY)); // add it to our page - doc size title score tempBuf.append("<p align=\"left\">"); if (!currentIndex.getIsWeb()) { tempBuf.append("<a href=\""); tempBuf.append(fileString); tempBuf.append(currentFile); tempBuf.append("\">"); } else { tempBuf.append("<a href=\""); tempBuf.append(currentFile); tempBuf.append("\">"); } switch (currentType) { case HTML: // html tempBuf.append(htmlTag); break; case MS_WORD: // ms word tempBuf.append(wordTag); break; case MS_EXCEL: // ms excel tempBuf.append(excelTag); break; case PDF: // pdf tempBuf.append(pdfTag); break; case RTF: // rtf tempBuf.append(rtfTag); break; case OO_WRITER: // openoffice writer tempBuf.append(ooWriterTag); break; case OO_IMPRESS: // openoffice impress tempBuf.append(ooImpressTag); break; case OO_CALC: // openoffice calc tempBuf.append(ooCalcTag); break; case OO_DRAW: // openoffice draw tempBuf.append(ooDrawTag); break; case OPENDOCUMENT_TEXT: // opendocument text tempBuf.append(openDocumentTextTag); break; case TEXT: tempBuf.append(textTag); break; default: logger.error("doSearch() FileType." + currentType + " is not ok here!"); } tempBuf.append(" "); tempBuf.append(currentTitle); tempBuf.append("</a><br>"); tempBuf.append(currentSummary); tempBuf.append("<font color=\"green\"><br><em>"); tempBuf.append(currentDate); tempBuf.append(", "); tempBuf.append(Utils.getKStyle(currentFilesize)); tempBuf.append("bytes, "); tempBuf.append(currentAuthor); tempBuf.append(", <b>"); tempBuf.append(Utils.getPercentStringFromScore(currentScore)); tempBuf.append("</b></em></font><br><font color=\"gray\">"); tempBuf.append(currentFile); tempBuf.append("</font>"); tempBuf.append("</p>"); if (env.isGUIMode()) { if (logger.isDebugEnabled()) { logger.debug("doSearch() \n\n* " + currentTitle + "\n" + currentSummary + "\n" + currentDate + ", " + Utils.getKStyle(currentFilesize) + "bytes, " + currentAuthor + ", " + Utils.getPercentStringFromScore(currentScore) + "\n" + currentFile); } } else { System.out.println("\n\n* " + currentTitle + "\n" + currentSummary + "\n" + currentDate + ", " + Utils.getKStyle(currentFilesize) + "bytes, " + currentAuthor + ", " + Utils.getPercentStringFromScore(currentScore) + "\n" + currentFile); } } // end for hits // now add our results curSrchPos++; if (curSrchPos > 0) { pPanel.setCurPos(curSrchPos); } // add the footer bodyBuf.append(tempBuf); // close index searcher.close(); } // end if shouldbesearched else { tempBuf.append("<p align=\"left\">"); tempBuf.append(I18n.getString("index")); tempBuf.append(" <b>"); tempBuf.append(currentIndex.getName()); tempBuf.append("</b> "); tempBuf.append(dsWasNotSearched); tempBuf.append("</p>"); bodyBuf.append(tempBuf); } } // end while hasmore indexes // finish up the page hitBuf.append("<p align=\"left\"><strong>"); hitBuf.append(grandTotalHits); hitBuf.append("</strong> "); hitBuf.append(I18n.getString("documents_found_in_all_indexes")); hitBuf.append("</p>"); hitBuf.append("<ul>"); hitBuf.append(searchedIndexes); hitBuf.append("</ul>"); hitBuf.append(bodyBuf); hitBuf.append("</body></html>"); if (env.isGUIMode()) { if (logger.isDebugEnabled()) { logger.debug("doSearch() " + dsTotHits + ": " + grandTotalHits); } } else { System.out.println("\n" + dsTotHits + ": " + grandTotalHits); } // save last search lastSearch = hitBuf.toString(); // show result if (env.isGUIMode()) { editorPane.setText(lastSearch); editorPane.select(0, 0); // add search text in combobox if not exist int searchFieldCount = searchField.getItemCount(); boolean inThere = false; for (int i = 1; i < searchFieldCount; i++) { String tmpSrchTxt = (String) searchField.getItemAt(i); if (tmpSrchTxt != null) { if (tmpSrchTxt.equals(searchText)) { inThere = true; } } } // if search text new, than put it to searchfield and // select them if (!inThere) { searchField.addItem(searchText); searchField.setSelectedIndex(searchField.getItemCount() - 1); } vista = new JComponentVista(editorPane, new PageFormat()); // set current page to result curPage = "results"; } else { // TODO check if here ouput for command line needed! } } catch (IOException ioe) { logger.fatal("doSearch() failed with IOException", ioe); showMessage(dsErrPrfSrch, dsCrptdIdx + " :\n" + ioe.toString()); } catch (NullPointerException npe) { logger.fatal("doSearch() failed with NullPointerException", npe); showMessage(dsErrPrfSrch, dsCrptdIdx + " :\n" + npe.toString()); } catch (Exception e) { logger.fatal("doSearch() failed with Exception", e); showMessage(dsErrPrfSrch, e.toString()); } } else { showMessage(dsErrPrfSrch, dsMkIdx); } } setStatus(I18n.getString("search_complete")); setSearching(false); setIsWorking(false); pPanel.reset(); }
From source file:org.pentaho.reporting.engine.classic.core.MasterReport.java
private PageDefinition createDefaultPageDefinition() { final PageDefinition format; final ExtendedConfiguration config = ClassicEngineBoot.getInstance().getExtendedConfig(); if (config.getBoolProperty(ClassicEngineCoreModule.NO_PRINTER_AVAILABLE_KEY)) { format = new SimplePageDefinition(new PageFormat()); } else {/*w w w. j ava 2 s . c o m*/ format = new SimplePageDefinition(PrinterJob.getPrinterJob().defaultPage()); } return format; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
public void init(final LogicalPageBox rootBox, final OutputProcessorMetaData metaData, final ResourceManager resourceManager) { if (rootBox == null) { throw new NullPointerException(); }/*from ww w .j a v a2s .co m*/ if (metaData == null) { throw new NullPointerException(); } if (resourceManager == null) { throw new NullPointerException(); } this.resourceManager = resourceManager; this.metaData = metaData; this.rootBox = rootBox; this.width = StrictGeomUtility.toExternalValue(rootBox.getPageWidth()); this.height = StrictGeomUtility.toExternalValue(rootBox.getPageHeight()); final Paper paper = new Paper(); paper.setImageableArea(0, 0, width, height); this.pageFormat = new PageFormat(); this.pageFormat.setPaper(paper); this.strictClipping = "true".equals(metaData.getConfiguration().getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.StrictClipping")); this.outlineMode = "true".equals(metaData.getConfiguration().getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.debug.OutlineMode")); if ("true".equals(metaData.getConfiguration().getConfigProperty( "org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.debug.PrintPageContents"))) { ModelPrinter.INSTANCE.print(rootBox); } this.unalignedPageBands = metaData.isFeatureSupported(OutputProcessorFeature.UNALIGNED_PAGEBANDS); revalidateTextEllipseProcessStep = new RevalidateTextEllipseProcessStep(metaData); collectSelectedNodesStep = new CollectSelectedNodesStep(); this.clipOnWordBoundary = "true".equals(metaData.getConfiguration() .getConfigProperty("org.pentaho.reporting.engine.classic.core.LastLineBreaksOnWordBoundary")); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.base.layout.TableLayoutIT.java
public void run(final ValidationSequence sequence, final OutputProcessorMetaData metaData) throws ResourceKeyCreationException, ContentProcessingException, ReportProcessingException { // Set up the process .. final PageFormatFactory fmFactory = PageFormatFactory.getInstance(); final PageFormat pageFormat = new PageFormat(); pageFormat.setPaper(fmFactory.createPaper((double) sequence.getPageWidth(), 1000)); final SimplePageDefinition pageDefinition = new SimplePageDefinition(pageFormat); final ProcessingContext processingContext = new DefaultProcessingContext(); final DebugExpressionRuntime runtime = new DebugExpressionRuntime(new DefaultTableModel(), 0, processingContext);/*from www. j a v a 2s. co m*/ final TableDebugOutputProcessor outputProcessor = new TableDebugOutputProcessor(metaData); final TableDebugRenderer flowRenderer = new TableDebugRenderer(outputProcessor); final MasterReport report = new MasterReport(); report.setPageDefinition(pageDefinition); DebugReportRunner.resolveStyle(report); flowRenderer.startReport(report, processingContext, new DefaultPerformanceMonitorContext()); // execute .. (maybe it is not pretty, "... but it works") final ArrayList list = sequence.getContents(); for (int i = 0; i < list.size(); i++) { final Object o = list.get(i); if (o instanceof SourceChunk) { final SourceChunk chunk = (SourceChunk) o; flowRenderer.startSection(Renderer.SectionType.NORMALFLOW); final Band band = chunk.getRootBand(); DebugReportRunner.resolveStyle(band); flowRenderer.add(band, runtime); flowRenderer.endSection(); flowRenderer.applyAutoCommit(); if (Renderer.LayoutResult.LAYOUT_PAGEBREAK == flowRenderer.validatePages()) { flowRenderer.processPage(null, new Object(), true); } else { flowRenderer.processIncrementalUpdate(true); } flowRenderer.processIncrementalUpdate(true); } } flowRenderer.endReport(); if (Renderer.LayoutResult.LAYOUT_PAGEBREAK == flowRenderer.validatePages()) { assertTrue(flowRenderer.processPage(null, new Object(), true)); } else { fail(); } flowRenderer.startReport(report, processingContext, new DefaultPerformanceMonitorContext()); for (int i = 0; i < list.size(); i++) { final Object o = list.get(i); if (o instanceof SourceChunk) { final SourceChunk chunk = (SourceChunk) o; flowRenderer.startSection(Renderer.SectionType.NORMALFLOW); final Band band = chunk.getRootBand(); DebugReportRunner.resolveStyle(band); flowRenderer.add(band, runtime); flowRenderer.endSection(); flowRenderer.applyAutoCommit(); if (Renderer.LayoutResult.LAYOUT_PAGEBREAK == flowRenderer.validatePages()) { flowRenderer.processPage(null, new Object(), true); } else { flowRenderer.processIncrementalUpdate(true); } } else if (o instanceof ResultTable) { // perform the layouting first. final ResultTable chunk = (ResultTable) o; outputProcessor.validate(chunk); } } flowRenderer.endReport(); if (Renderer.LayoutResult.LAYOUT_PAGEBREAK == flowRenderer.validatePages()) { flowRenderer.processPage(null, new Object(), false); } else { fail(); } logger.debug("All ok"); }
From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java
public static PageFormat extractPageFormat(final PrintRequestAttributeSet attributeSet) { final Media media = (Media) attributeSet.get(Media.class); final MediaPrintableArea printableArea = (MediaPrintableArea) attributeSet.get(MediaPrintableArea.class); final OrientationRequested orientationRequested = (OrientationRequested) attributeSet .get(OrientationRequested.class); final MediaSize mediaSize = lookupMediaSize(media); if (mediaSize == null) { logger.warn("Unknown media encountered, unable to compute page sizes."); }//from w w w . j a va2s . com final PageFormat pageFormat = new PageFormat(); pageFormat.setPaper(createPaper(mediaSize, printableArea)); if (OrientationRequested.PORTRAIT.equals(orientationRequested)) { pageFormat.setOrientation(PageFormat.PORTRAIT); } else if (OrientationRequested.LANDSCAPE.equals(orientationRequested)) { pageFormat.setOrientation(PageFormat.LANDSCAPE); } else if (OrientationRequested.REVERSE_LANDSCAPE.equals(orientationRequested)) { pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE); } else if (OrientationRequested.REVERSE_PORTRAIT.equals(orientationRequested)) { pageFormat.setOrientation(PageFormat.PORTRAIT); } return pageFormat; }