From: <dal...@us...> - 2016-08-09 18:42:01
|
Revision: 24490 http://sourceforge.net/p/jedit/svn/24490 Author: daleanson Date: 2016-08-09 18:41:58 +0000 (Tue, 09 Aug 2016) Log Message: ----------- Added option to print current page. Modified Paths: -------------- jEdit/trunk/org/gjt/sp/jedit/print/BufferPrintable1_7.java jEdit/trunk/org/gjt/sp/jedit/print/BufferPrinter1_7.java jEdit/trunk/org/gjt/sp/jedit/print/PrinterDialog.java Modified: jEdit/trunk/org/gjt/sp/jedit/print/BufferPrintable1_7.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/print/BufferPrintable1_7.java 2016-08-09 16:55:12 UTC (rev 24489) +++ jEdit/trunk/org/gjt/sp/jedit/print/BufferPrintable1_7.java 2016-08-09 18:41:58 UTC (rev 24490) @@ -87,6 +87,11 @@ reverse = b; } + public void setPrintRangeType(int printRangeType) + { + this.printRangeType = printRangeType; + } + //{{{ print() method // this can be called multiple times by the print system for the same page public int print(Graphics _gfx, PageFormat pageFormat, int pageIndex) throws PrinterException @@ -105,22 +110,38 @@ firstCall = false; } + if (printRangeType == PrinterDialog.CURRENT_PAGE) + { + int caretLine = view.getTextArea().getCaretLine(); + for (Integer i : pages.keySet()) + { + Range range = pages.get(i); + if (range.contains(caretLine)) + { + pageIndex = i; + break; + } + } + } + Log.log(Log.DEBUG, this, "Asked to print page " + pageIndex); - if (reverse) + if (reverse && printRangeType != PrinterDialog.CURRENT_PAGE) { pageIndex = pages.size() - 1 - pageIndex; Log.log(Log.DEBUG, this, "Reverse is on, changing page index to " + pageIndex); } Range range = pages.get(pageIndex); - if (range == null || !inRange(pageIndex)) + if ( (range == null || !inRange(pageIndex)) && printRangeType != PrinterDialog.CURRENT_PAGE ) { + Log.log(Log.DEBUG, this, "Returning NO_SUCH_PAGE for page " + pageIndex); return NO_SUCH_PAGE; } else { printPage(_gfx, pageFormat, pageIndex, true); } + Log.log(Log.DEBUG, this, "Returning PAGE_EXISTS for page " + pageIndex); return PAGE_EXISTS; } //}}} @@ -143,6 +164,7 @@ private Buffer buffer; private boolean selection; private boolean reverse; + private int printRangeType = PrinterDialog.ALL; private Font font; private SyntaxStyle[] styles; private boolean header; @@ -231,6 +253,7 @@ // last page Range range = new Range(startLine, currentPhysicalLine); pages.put(new Integer(pageCount), range); + Log.log(Log.DEBUG, this, "calculatePages, page " + pageCount + " has " + range); break; } if (!printFolds && !view.getTextArea().getDisplayManager().isLineVisible(currentPhysicalLine)) @@ -248,6 +271,7 @@ { Range range = new Range(startLine, currentPhysicalLine); pages.put(new Integer(pageCount), range); + Log.log(Log.DEBUG, this, "calculatePages, page " + pageCount + " has " + range); ++ pageCount; ++ currentPhysicalLine; startLine = currentPhysicalLine; @@ -455,6 +479,11 @@ return end; } + public boolean contains(int i) + { + return i >= start && i <= end; + } + public String toString() { StringBuilder sb = new StringBuilder(); Modified: jEdit/trunk/org/gjt/sp/jedit/print/BufferPrinter1_7.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/print/BufferPrinter1_7.java 2016-08-09 16:55:12 UTC (rev 24489) +++ jEdit/trunk/org/gjt/sp/jedit/print/BufferPrinter1_7.java 2016-08-09 18:41:58 UTC (rev 24490) @@ -72,7 +72,6 @@ PrintService printService = printerDialog.getPrintService(); OutputStream outputStream = null; - boolean reversePrinting = printerDialog.getReverse(); if (printService != null) { try @@ -94,7 +93,8 @@ } BufferPrintable1_7 printable = new BufferPrintable1_7(format, view, buffer); - printable.setReverse(reversePrinting); + printable.setReverse(printerDialog.getReverse()); + printable.setPrintRangeType(printerDialog.getPrintRangeType()); Doc doc = new SimpleDoc(printable, DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); try { job.print(doc, format); Modified: jEdit/trunk/org/gjt/sp/jedit/print/PrinterDialog.java =================================================================== --- jEdit/trunk/org/gjt/sp/jedit/print/PrinterDialog.java 2016-08-09 16:55:12 UTC (rev 24489) +++ jEdit/trunk/org/gjt/sp/jedit/print/PrinterDialog.java 2016-08-09 18:41:58 UTC (rev 24490) @@ -51,10 +51,14 @@ private boolean canceled = false; private Map<String, String> messageMap; private PageSetupPanel pageSetupPanel; - private int ALL = 0; - private int ODD = 1; - private int EVEN = 2; - private int onlyPrintPages = ALL; + public static int ALL = 0; + public static int ODD = 1; + public static int EVEN = 2; + public static int RANGE = 3; + public static int CURRENT_PAGE = 4; + public static int SELECTION = 5; + public static int onlyPrintPages = ALL; + private int printRangeType = ALL; private DocFlavor DOC_FLAVOR = DocFlavor.SERVICE_FORMATTED.PRINTABLE; private boolean reversePrinting = false; @@ -88,12 +92,10 @@ Attribute[] attrs = attributes.toArray(); // for debugging - /* for ( Attribute a : attrs ) { System.out.println( "+++++ before: " + a.getName() + " = " + a ); } - */ initMessages(); @@ -173,13 +175,11 @@ } // for debugging - /* Attribute[] attrs = PrinterDialog.this.attributes.toArray(); for ( Attribute a : attrs ) { System.out.println( "+++++ after: " + a.getName() + " = " + a ); } - */ PrinterDialog.this.setVisible( false ); PrinterDialog.this.dispose(); @@ -229,28 +229,48 @@ e.printStackTrace(); } } - - + + /** + * @return The print service selected by the user. + */ public PrintService getPrintService() { return selectedPrintService; } - - + + /** + * @return An attribute set containing all the values as selected by the user. + */ public PrintRequestAttributeSet getAttributes() { return attributes; } - - + + /** + * @return <code>true</code> if the user clicked the 'cancel' button. + */ public boolean isCanceled() { return canceled; } + /** + * @return <code>true</code> if the pages should be printed in reverse order, + * that is, the last page is printed first and the first page is printed last. + */ public boolean getReverse() { return reversePrinting; } + + /** + * @returns One of ALL, RANGE, CURRENT, or SELECTION, depending on whether the + * user has elected to print all pages, a range of pages, just the current page + * or just the selected text. + */ + public int getPrintRangeType() + { + return printRangeType; + } private PrintService[] getPrintServices() @@ -568,6 +588,8 @@ JRadioButton allPages; JRadioButton pages; + JRadioButton currentPage; + JRadioButton selection; JCheckBox collate; JCheckBox reverse; JTextField pagesField; @@ -584,7 +606,7 @@ printers.addListSelectionListener( PrinterDialog.this ); selectedPrintService = printers.getModel().getElementAt( 0 ); - JPanel rangePanel = new JPanel( new GridLayout( 2, 2, 6, 6 ) ); + JPanel rangePanel = new JPanel( new GridLayout( 4, 2, 6, 6 ) ); rangePanel.setBorder( BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), jEdit.getProperty( "print.dialog.Range", "Range" ) ), BorderFactory.createEmptyBorder( 11, 11, 11, 11 ) ) ); @@ -612,8 +634,12 @@ } } ); + + currentPage = new JRadioButton( jEdit.getProperty( "print.dialog.Current_page", "Current page") ); + selection = new JRadioButton( jEdit.getProperty( "print.dialog.Selection", "Selection") ); + - new MyButtonGroup( allPages, pages ); + new MyButtonGroup( allPages, pages, currentPage, selection ); Box pagesBox = Box.createHorizontalBox(); pagesBox.add( pages ); pagesBox.add( Box.createHorizontalStrut( 6 ) ); @@ -621,6 +647,10 @@ rangePanel.add( allPages ); rangePanel.add( Box.createGlue() ); rangePanel.add( pagesBox ); + rangePanel.add( Box.createGlue() ); + rangePanel.add( currentPage ); + rangePanel.add( Box.createGlue() ); + rangePanel.add( selection ); JPanel copiesPanel = new JPanel( new GridLayout( 3, 2, 6, 6 ) ); copiesPanel.setBorder( BorderFactory.createCompoundBorder( @@ -675,7 +705,8 @@ if (allPages.isSelected()) { - as.add(new PageRanges( 1, Integer.MAX_VALUE)); + as.add(new PageRanges( 1, 1000)); + printRangeType = ALL; } else if ( pages.isSelected() ) { @@ -691,7 +722,18 @@ e.printStackTrace(); } } + printRangeType = RANGE; } + else if (currentPage.isSelected()) + { + as.add(new PageRanges( 1 )); + printRangeType = CURRENT_PAGE; + } + else if (selection.isSelected()) + { + as.add(new PageRanges( 1, 1000)); + printRangeType = SELECTION; + } if ( collate.isSelected() ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |