tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / dialogs / SDPrintDialogUI.java
index cca6d73fc122ae4aa4ebcfc1a9bdf44d69808ca4..261ca3cadd3701abf91c612f87b53d48112b0974 100755 (executable)
@@ -1,16 +1,15 @@
-/********************************************************************** 
- * Copyright (c) 2005, 2008 IBM Corporation and others.
- * Copyright (c) 2011, 2012 Ericsson.
- *  
- * All rights reserved.   This program and the accompanying materials 
- * are made available under the terms of the Eclipse Public License v1.0 
- * which accompanies this distribution, and is available at 
- * http://www.eclipse.org/legal/epl-v10.html         
- * 
- * Contributors: 
- * IBM - Initial API and implementation
- * Bernd Hufmann - Updated for TMF 
+/**********************************************************************
+ * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
+ * All rights reserved.   This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     IBM - Initial API and implementation
+ *     Bernd Hufmann - Updated for TMF
  **********************************************************************/
+
 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.dialogs;
 
 import java.text.MessageFormat;
@@ -55,7 +54,7 @@ import org.eclipse.swt.widgets.Text;
 
 /**
  * The class implements the actual print dialog UI for collecting printing data.
- * 
+ *
  * @version 1.0
  * @author sveyrier
  */
@@ -64,15 +63,15 @@ public class SDPrintDialogUI {
     // Attributes
     // ------------------------------------------------------------------------
     /**
-     * The set horizontal pages number. 
+     * The set horizontal pages number.
      */
     protected Button fSetHPagesNumber;
     /**
-     * The set vertical pages number. 
+     * The set vertical pages number.
      */
     protected Button fSetVPagesNumber;
     /**
-     * Flag whether to use current zoom or not. 
+     * Flag whether to use current zoom or not.
      */
     protected Button fUseCurrentZoom;
     /**
@@ -100,7 +99,7 @@ public class SDPrintDialogUI {
      */
     protected Text fToPage;
     /**
-     *  The sequence diagram widget reference. 
+     *  The sequence diagram widget reference.
      */
     protected SDWidget fSdView;
     /**
@@ -116,7 +115,7 @@ public class SDPrintDialogUI {
      */
     protected Text fTotalPages;
     /**
-     * A modify listener implementation to handle modifications. 
+     * A modify listener implementation to handle modifications.
      */
     protected ModifyListener fModifyListener;
     /**
@@ -136,23 +135,40 @@ public class SDPrintDialogUI {
      */
     protected int fPageNum = -1;
     /**
-     * Number of first page. 
+     * Number of first page.
      */
     protected int fFirstPage = -1;
     /**
      * List of pages to print.
      */
     protected int fPagesList[];
+
+    /**
+     * Value for dividing the sequence diagram into pages
+     */
+    protected float fStepX;
+
+    /**
+     * Value for dividing the sequence diagram into pages
+     */
+    protected float fStepY;
+
+    /**
+     * Value for dividing the sequence diagram into pages
+     */
+    protected float sTX;
+
     /**
-     * Values for dividing sequence diagram into pages.   
+     * Value for dividing the sequence diagram into pages
      */
-    protected float fStepX, fStepY, sTX, sTY;
+    protected float sTY;
+
     /**
-     * Page which to print from. 
+     * Page which to print from.
      */
     protected int fFrom;
     /**
-     * Page which to print to. 
+     * Page which to print to.
      */
     protected int fTo;
     /**
@@ -192,7 +208,7 @@ public class SDPrintDialogUI {
      */
     protected float fZoomFactor;
     /**
-     * The printer data reference. 
+     * The printer data reference.
      */
     protected PrinterData fPrinterData;
     /**
@@ -216,7 +232,7 @@ public class SDPrintDialogUI {
      */
     protected boolean fShowPrintButton;
     /**
-     * Test value  
+     * Test value
      */
     protected int fTest = 3;
     /**
@@ -224,7 +240,7 @@ public class SDPrintDialogUI {
      */
     protected WizardPage fParentWizardPage = null;
     /**
-     * Reference to parent print dialog. 
+     * Reference to parent print dialog.
      */
     protected SDPrintDialog fParentDialog = null;
 
@@ -233,7 +249,7 @@ public class SDPrintDialogUI {
     // ------------------------------------------------------------------------
     /**
      * Local sequence diagram widget used to display overview of sequence diagram to print.
-     * @version 1.0 
+     * @version 1.0
      */
     protected class LocalSD extends SDWidget {
 
@@ -255,7 +271,7 @@ public class SDPrintDialogUI {
             if (fSdView.getContentsHeight() > fSdView.getContentsHeight()) {
                 return (int) (fSdView.getVisibleHeight() / (float) fTest / fSdView.fZoomValue);
             }
-            return (int) (super.getContentsHeight());
+            return super.getContentsHeight();
         }
 
         /*
@@ -267,7 +283,7 @@ public class SDPrintDialogUI {
             if (fSdView.getVisibleWidth() > fSdView.getContentsWidth()) {
                 return (int) (fSdView.getVisibleWidth() / (float) fTest / fSdView.fZoomValue);
             }
-            return (int) (super.getContentsWidth());
+            return super.getContentsWidth();
         }
 
         /*
@@ -280,7 +296,7 @@ public class SDPrintDialogUI {
 
         /**
          * Creates page selection images.
-         * 
+         *
          * @param img - Overview image
          * @param width -The width value
          * @param stepX - Step X
@@ -355,7 +371,7 @@ public class SDPrintDialogUI {
             imGC.dispose();
             return over;
         }
-        
+
         /*
          * (non-Javadoc)
          * @see org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget#drawContents(org.eclipse.swt.graphics.GC, int, int, int, int)
@@ -381,8 +397,6 @@ public class SDPrintDialogUI {
             if (!isEnabled()) {
                 Image toDel = d;
                 d = new Image(super.getShell().getDisplay(), drawRegionSelected(d, new Rectangle(0, 0, lw, lh), new RGB(221, 208, 200)));
-                // d, new Rectangle(0,0,((int)(stepX*overviewCanvas.zoomValue)),((int)(
-                // stepY*overviewCanvas.zoomValue))),new RGB(221,208,200)));
                 toDel.dispose();
             }
 
@@ -629,25 +643,46 @@ public class SDPrintDialogUI {
 
     }
 
+    /**
+     * A traverse listener implementation.
+     */
+    protected static class LocalTraverseListener implements TraverseListener {
+        /*
+         * (non-Javadoc)
+         * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
+         */
+        @Override
+        public void keyTraversed(TraverseEvent e) {
+            if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {
+                e.doit = true;
+            }
+        }
+    }
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
     /**
      * Constructor
-     * 
-     * @param shell The shell reference
-     * @param sdWidget The sequence diagram widget reference
+     *
+     * @param shell
+     *            The shell reference
+     * @param sdWidget
+     *            The sequence diagram widget reference
      */
     public SDPrintDialogUI(Shell shell, SDWidget sdWidget) {
         this(shell, sdWidget, false);
     }
-    
+
     /**
      * Constructor
-     * 
-     * @param shello The shell reference
-     * @param sdWidget The sequence diagram widget reference
-     * @param showPrintBtn Flag for showing print buttons
+     *
+     * @param shell
+     *            The shell reference
+     * @param sdWidget
+     *            The sequence diagram widget reference
+     * @param showPrintBtn
+     *            Flag for showing print buttons
      */
     public SDPrintDialogUI(Shell shell, SDWidget sdWidget, boolean showPrintBtn) {
         fShell = shell;
@@ -676,7 +711,7 @@ public class SDPrintDialogUI {
                         fCurrentPage.setSelection(false);
                         fAllPages.setSelection(true);
                     }
-                    if ("".equals(fHorPagesNum.getText())) { //$NON-NLS-1$ 
+                    if ("".equals(fHorPagesNum.getText())) { //$NON-NLS-1$
                         fHorPagesNum.setText("1"); //$NON-NLS-1$
                     }
                 }
@@ -687,7 +722,7 @@ public class SDPrintDialogUI {
                         fCurrentPage.setSelection(false);
                         fAllPages.setSelection(true);
                     }
-                    if (fVertPagesNum.getText() == "") { //$NON-NLS-1$
+                    if ("".equals(fVertPagesNum.getText())) { //$NON-NLS-1$
                         fVertPagesNum.setText("1"); //$NON-NLS-1$
                     }
                 }
@@ -706,7 +741,7 @@ public class SDPrintDialogUI {
                     fPagesList[0] = 1;
                     fPageNum = 1;
                     fFirstPage = 1;
-                } else if ((fOverviewCanvas.isEnabled() && (e.widget == fPageList)) && 
+                } else if ((fOverviewCanvas.isEnabled() && (e.widget == fPageList)) &&
                            (fPagesList == null || fPagesList.length <= 0)) {
 
                     fPagesList = new int[1];
@@ -755,7 +790,7 @@ public class SDPrintDialogUI {
 
     /**
      * Creates new grid data object.
-     * 
+     *
      * @param span horizontal span.
      * @return grid data
      */
@@ -767,7 +802,7 @@ public class SDPrintDialogUI {
 
     /**
      * Creates the dialog area.
-     * 
+     *
      * @param parent The parent composite
      * @return dialog control
      */
@@ -829,10 +864,7 @@ public class SDPrintDialogUI {
         data2.verticalSpan = 1;
 
         fOverviewCanvas = new LocalSD(g2, SWT.NO_BACKGROUND);
-        GridData seqDiagLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL// |GridData.GRAB_HORIZONTAL|
-                /* GridData.GRAB_VERTICAL| */| GridData.VERTICAL_ALIGN_FILL);
-        // seqDiagLayoutData.widthHint=400;
-        // seqDiagLayoutData.horizontalAlignment=GridData.HORIZONTAL_ALIGN_FILL;
+        GridData seqDiagLayoutData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
         fOverviewCanvas.setLayoutData(seqDiagLayoutData);
         // overviewCanvas.resizeContents(100,100);
         if (fSdView.getContentsWidth() < fSdView.getVisibleWidth() && fSdView.getContentsHeight() < fSdView.getVisibleHeight()) {
@@ -949,18 +981,7 @@ public class SDPrintDialogUI {
 
         });
 
-        fOverviewCanvas.addTraverseListener(new TraverseListener() {
-            /*
-             * (non-Javadoc)
-             * @see org.eclipse.swt.events.TraverseListener#keyTraversed(org.eclipse.swt.events.TraverseEvent)
-             */
-            @Override
-            public void keyTraversed(TraverseEvent e) {
-                if ((e.detail == SWT.TRAVERSE_TAB_NEXT) || (e.detail == SWT.TRAVERSE_TAB_PREVIOUS)) {
-                    e.doit = true;
-                }
-            }
-        });
+        fOverviewCanvas.addTraverseListener(new LocalTraverseListener());
 
         fOverviewCanvas.addFocusListener(new FocusListener() {
             /*
@@ -1004,7 +1025,6 @@ public class SDPrintDialogUI {
                  */
                 @Override
                 public void widgetSelected(SelectionEvent e) {
-
                     printButtonSelected();
                 }
 
@@ -1032,6 +1052,11 @@ public class SDPrintDialogUI {
         return fNbPages;
     }
 
+    /**
+     * Handler for when the OK button is pressed
+     *
+     * @return True if the operation was successful, false if there was an error
+     */
     public boolean okPressed() {
         fPrintAll = fAllPages.getSelection();
         fPrintCurrent = fCurrentPage.getSelection();
@@ -1130,20 +1155,20 @@ public class SDPrintDialogUI {
                 Printer printer = new Printer(fPrinterData);
                 if (fSetHPagesNumber.getSelection()) {
                     fNbPages = Integer.valueOf(fHorPagesNum.getText()).intValue();
-                    float z1 = (float) fSdView.getContentsWidth() / (cw);
+                    float z1 = fSdView.getContentsWidth() / cw;
                     float z2 = printer.getClientArea().width / ((float) fSdView.getContentsWidth() / fNbPages);
 
                     fStepY = printer.getClientArea().height / z1 / z2;
                     fStepX = cw / fNbPages;
                 } else if (fSetVPagesNumber.getSelection()) {
                     fNbPages = Integer.valueOf(fVertPagesNum.getText()).intValue();
-                    float z1 = (float) fSdView.getContentsHeight() / (ch);
+                    float z1 = fSdView.getContentsHeight() / ch;
                     float z2 = printer.getClientArea().height / ((float) fSdView.getContentsHeight() / fNbPages);
                     fStepX = printer.getClientArea().width / z1 / z2;
                     fStepY = ch / fNbPages;
                 } else {
                     float z1 = fSdView.getContentsWidth() / (cw);
-                    fStepX = ((float) fSdView.getVisibleWidth() / z1);
+                    fStepX = fSdView.getVisibleWidth() / z1;
                     fNbPages = Math.round(cw / fStepX);
                     if (fNbPages == 0) {
                         fNbPages = 1;
@@ -1151,7 +1176,7 @@ public class SDPrintDialogUI {
                     int pw = printer.getClientArea().width;
                     int ph = printer.getClientArea().height;
                     float z2 = pw / ((float) fSdView.getContentsWidth() / fNbPages);
-                    fStepY = ((float) ph / z1 / z2);
+                    fStepY = ph / z1 / z2;
                 }
             }
         } catch (NumberFormatException e) {
@@ -1164,12 +1189,12 @@ public class SDPrintDialogUI {
         if ((fSdView.getVisibleWidth() > fSdView.getContentsWidth()) && (fSetVPagesNumber.getSelection() || fSetHPagesNumber.getSelection())) {
             rat = (float) fSdView.getVisibleWidth() / (float) fSdView.getContentsWidth();
         }
-        fZoomFactor = (fOverviewCanvas.getContentsWidth() / cw) / fOverviewCanvas.getZoomFactor() * rat;// /view.getZoomFactor();
+        fZoomFactor = (fOverviewCanvas.getContentsWidth() / cw) / fOverviewCanvas.getZoomFactor() * rat;
     }
 
     /**
      * Returns the pages list.
-     * 
+     *
      * @return the pages list.
      */
     public int[] getPageList() {
@@ -1178,7 +1203,9 @@ public class SDPrintDialogUI {
 
     /**
      * Adds a page to pages list.
+     *
      * @param num
+     *            The number of the the new page
      */
     public void addToPagesList(int num) {
         int temp[] = new int[fPagesList.length + 1];
@@ -1190,7 +1217,9 @@ public class SDPrintDialogUI {
 
     /**
      * Removes a page from the pages list.
+     *
      * @param num
+     *            The number of the page to remove
      */
     public void removeFromPagesList(int num) {
         int pos = Arrays.binarySearch(fPagesList, num);
@@ -1203,7 +1232,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the maximum number of pages.
-     * 
+     *
      * @return maximum number of pages.
      */
     public int maxNumOfPages() {
@@ -1212,7 +1241,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the number of rows.
-     * 
+     *
      * @return number of rows.
      */
     public int getNbRow() {
@@ -1222,7 +1251,7 @@ public class SDPrintDialogUI {
             if (fStepX != 0) {
                 row = (int) (cw / fStepX);
                 if (fSetHPagesNumber.getSelection()) {
-                    row = Math.round((float) cw / fStepX);
+                    row = Math.round(cw / fStepX);
                 } else if ((cw % fStepX != 0)) {
                     row++;
                 }
@@ -1234,7 +1263,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the number of lines.
-     * 
+     *
      * @return number of lines
      */
     public int getNbLines() {
@@ -1244,7 +1273,7 @@ public class SDPrintDialogUI {
             if (fStepY != 0) {
                 line = (int) (ch / fStepY);
                 if (fSetVPagesNumber.getSelection()) {
-                    line = Math.round((float) ch / fStepY);
+                    line = Math.round(ch / fStepY);
                 } else if (ch % fStepY != 0) {
                     line++;
                 }
@@ -1256,7 +1285,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns whether to print all pages or not.
-     * 
+     *
      * @return <code>true</code> for all pages else <code>false</code>.
      */
     public boolean printAll() {
@@ -1264,8 +1293,8 @@ public class SDPrintDialogUI {
     }
 
     /**
-     * Returns whether to print only current page 
-     * 
+     * Returns whether to print only current page
+     *
      * @return <code>true</code> for current page only else <code>false</code>..
      */
     public boolean printCurrent() {
@@ -1274,16 +1303,16 @@ public class SDPrintDialogUI {
 
     /**
      * Returns whether to print selected pages.
-     * 
-     * @return <code>true</code> for selected pages only else <code>false</code>. 
+     *
+     * @return <code>true</code> for selected pages only else <code>false</code>.
      */
     public boolean printSelection() {
         return fPrintSelection;
     }
-    
+
     /**
      * Returns whether to print range of pages.
-     * 
+     *
      * @return <code>true</code> for range of pages only else <code>false</code>.
      */
     public boolean printRange() {
@@ -1292,7 +1321,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the step in X direction.
-     * 
+     *
      * @return step in X direction
      */
     public float getStepX() {
@@ -1301,7 +1330,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the step in Y direction.
-     * 
+     *
      * @return step in Y direction
      */
     public float getStepY() {
@@ -1310,7 +1339,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the zoom factor
-     * 
+     *
      * @return zoom factor
      */
     public float getZoomFactor() {
@@ -1319,7 +1348,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the printer data reference.
-     * 
+     *
      * @return printer data reference
      */
     public PrinterData getPrinterData() {
@@ -1328,7 +1357,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the page number to start printing from.
-     * 
+     *
      * @return page number to start printing from
      */
     public int getFrom() {
@@ -1337,7 +1366,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the page number to print to.
-     * 
+     *
      * @return page number to print to
      */
     public int getTo() {
@@ -1357,7 +1386,7 @@ public class SDPrintDialogUI {
 
     /**
      * Returns the shell reference.
-     * 
+     *
      * @return the shell reference.
      */
     public Shell getShell() {
@@ -1366,7 +1395,7 @@ public class SDPrintDialogUI {
 
     /**
      * Sets the shell.
-     * 
+     *
      * @param shell The shell reference.
      */
     public void setShell(Shell shell) {
@@ -1425,7 +1454,7 @@ public class SDPrintDialogUI {
 
     /**
      * Sets parent wizard page
-     * 
+     *
      * @param parent The parent wizard page
      */
     public void setParentWizardPage(WizardPage parent) {
@@ -1434,8 +1463,8 @@ public class SDPrintDialogUI {
 
     /**
      * Sets the parent dialog box.
-     * 
-     * @param parent The parent dialog box. 
+     *
+     * @param parent The parent dialog box.
      */
     public void setParentDialog(SDPrintDialog parent) {
         fParentDialog = parent;
This page took 0.031529 seconds and 5 git commands to generate.