[brailleblaster] [brailleblaster.newdesign] push by brandon....@xxxxxxxxx - Added print preview on 2013-05-28 00:44 GMT

  • From: brailleblaster@xxxxxxxxxxxxxx
  • To: brailleblaster@xxxxxxxxxxxxx
  • Date: Tue, 28 May 2013 00:44:59 +0000

Revision: 979673ca0b44
Branch:   default
Author:   Brandon Roller <brandon.r.roller@xxxxxxxxx>
Date:     Mon May 27 17:42:45 2013
Log:      Added print preview
http://code.google.com/p/brailleblaster/source/detail?r=979673ca0b44&repo=newdesign

Added:
 /src/main/org/brailleblaster/printers/PrintPreview.java
Modified:
 /src/main/org/brailleblaster/wordprocessor/BBMenu.java
 /src/main/org/brailleblaster/wordprocessor/DocumentManager.java
 /src/main/org/brailleblaster/wordprocessor/FontManager.java

=======================================
--- /dev/null
+++ /src/main/org/brailleblaster/printers/PrintPreview.java Mon May 27 17:42:45 2013
@@ -0,0 +1,116 @@
+package org.brailleblaster.printers;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Scanner;
+
+import org.brailleblaster.BBIni;
+import org.brailleblaster.abstractClasses.AbstractView;
+import org.brailleblaster.util.Notify;
+import org.brailleblaster.wordprocessor.BBDocument;
+import org.brailleblaster.wordprocessor.FontManager;
+import org.brailleblaster.wordprocessor.Message;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.VerifyKeyListener;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.events.TraverseListener;
+import org.eclipse.swt.events.VerifyEvent;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+
+public class PrintPreview {
+       Shell shell;
+       BBDocument doc;
+       PreviewText previewText;
+
+       final int MARGINS = 38;
+       final int PAGE_WIDTH = 619;
+       final int PAGE_HEIGHT = 825;
+
+       private class PreviewText extends AbstractView{
+               String text;
+               File f;
+
+               public PreviewText(Group group){
+                       super(group, 0, 100, 0, 100);
+                       this.view.setEditable(false);
+               }
+
+               public void setPreviewText(BBDocument doc){
+ String tempFilePath = BBIni.getTempFilesPath() + BBIni.getFileSep() + "tempBRF.brf";
+                       doc.createBrlFile(tempFilePath);
+                       this.f = new File(tempFilePath);
+                       try {
+                               Scanner scanner = new Scanner(this.f);
+                               this.text = scanner.useDelimiter("\\Z").next();
+                               scanner.close();
+                               this.view.setText(this.text);
+                               Font font = FontManager.getFont();
+                               this.view.setFont(font);
+                               this.view.setMargins(MARGINS, MARGINS, MARGINS, 
MARGINS);
+                               this.view.getShell().open();
+                       } catch (FileNotFoundException e) {
+ new Notify("Print Preview failed to open properly. Check to ensure your document does not contain errors");
+                               e.printStackTrace();
+                               this.view.getShell().dispose();
+                       }
+               }
+
+               public void deleteTempFile(){
+                       this.f.delete();
+               }
+
+               @Override
+               protected void setViewData(Message message) {
+                       // TODO Auto-generated method stub
+               }
+       }
+
+       public PrintPreview(Display display, BBDocument doc){
+               this.doc = doc;
+
+               this.shell = new Shell(display, SWT.SHELL_TRIM);
+               this.shell.setLayout(new FormLayout());
+               this.shell.setText("Print Preview");
+               this.shell.setSize(PAGE_WIDTH, PAGE_HEIGHT);
+
+               Group gp = new Group(this.shell, SWT.NONE);
+               FormData location = new FormData();
+           location.left = new FormAttachment(0);
+           location.right = new FormAttachment(100);
+           location.top = new FormAttachment (0);
+           location.bottom = new FormAttachment(100);
+           gp.setLayoutData (location);
+               gp.setLayout(new FormLayout());
+
+               this.previewText = new PreviewText(gp);
+
+               previewText.view.addVerifyKeyListener(new VerifyKeyListener(){
+                       @Override
+                       public void verifyKey(VerifyEvent e) {
+                               if(e.stateMask == SWT.MOD1 && e.keyCode == 'q'){
+                                       previewText.deleteTempFile();
+                                       shell.dispose();
+                                       e.doit = false;
+                               }
+                       }
+               });
+
+               this.shell.addListener(SWT.Close, new Listener() {
+                       public void handleEvent(Event event) {
+                               previewText.deleteTempFile();
+                               shell.dispose();
+               }
+            });
+
+               this.previewText.setPreviewText(this.doc);
+       }
+}
=======================================
--- /src/main/org/brailleblaster/wordprocessor/BBMenu.java Thu May 23 07:34:42 2013 +++ /src/main/org/brailleblaster/wordprocessor/BBMenu.java Mon May 27 17:42:45 2013
@@ -299,14 +299,19 @@
                        }
                });

+*/
                printPreviewItem = new MenuItem(fileMenu, SWT.PUSH);
-               printPreviewItem.setText(lh.localValue("PrintP&review"));
+ printPreviewItem.setText(lh.localValue("PrintP&review") + "\tAlt + HOME");
+               printPreviewItem.setAccelerator(SWT.MOD3 + SWT.HOME);
                printPreviewItem.addSelectionListener(new SelectionAdapter() {
                        public void widgetSelected(SelectionEvent e) {
-
+                               int index= wp.getFolder().getSelectionIndex();
+                               if(index != -1){
+                                       wp.getList().get(index).printPreview();
+                               }
                        }
                });
-*/
+
                printItem = new MenuItem(fileMenu, SWT.PUSH);
                printItem.setText(lh.localValue("&Print") + "\tCtrl + P");
                printItem.setAccelerator(SWT.MOD1 + 'p');
=======================================
--- /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Sun May 26 17:29:42 2013 +++ /src/main/org/brailleblaster/wordprocessor/DocumentManager.java Mon May 27 17:42:45 2013
@@ -50,6 +50,7 @@
 import org.brailleblaster.localization.LocaleHandler;
 import org.brailleblaster.mapping.MapList;
 import org.brailleblaster.mapping.TextMapElement;
+import org.brailleblaster.printers.PrintPreview;
 import org.brailleblaster.printers.PrintersManager;
 import org.brailleblaster.util.Notify;
 import org.brailleblaster.util.YesNoChoice;
@@ -524,6 +525,12 @@
PrintersManager pn = new PrintersManager(this.wp.getShell(), this.text.view);
                pn.beginPrintJob();
        }
+
+       public void printPreview(){
+               if(this.braille.view.getCharCount() > 0){
+                       PrintPreview pv = new PrintPreview(this.getDisplay(), 
this.document);
+               }
+       }

        public void toggleBrailleFont(){
                FontManager.toggleBrailleFont(this.wp, this);
=======================================
--- /src/main/org/brailleblaster/wordprocessor/FontManager.java Wed Mar 27 06:08:57 2013 +++ /src/main/org/brailleblaster/wordprocessor/FontManager.java Mon May 27 17:42:45 2013
@@ -178,4 +178,8 @@
                        dm.simBrailleDisplayed = false;
                }
        }
+
+       public static Font getFont(){
+               return daisyFont;
+       }
 }

Other related posts:

  • » [brailleblaster] [brailleblaster.newdesign] push by brandon....@xxxxxxxxx - Added print preview on 2013-05-28 00:44 GMT - brailleblaster