-/**********************************************************************
- * 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;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.GridUtil;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.DiagramToolTip;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.NGC;
import org.eclipse.linuxtools.tmf.ui.views.uml2sd.SDWidget;
/**
* The class implements the actual print dialog UI for collecting printing data.
- *
+ *
* @version 1.0
* @author sveyrier
*/
// 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;
/**
*/
protected Text fToPage;
/**
- * The sequence diagram widget reference.
+ * The sequence diagram widget reference.
*/
protected SDWidget fSdView;
/**
*/
protected Text fTotalPages;
/**
- * A modify listener implementation to handle modifications.
+ * A modify listener implementation to handle modifications.
*/
protected ModifyListener fModifyListener;
/**
*/
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;
/**
*/
protected float fZoomFactor;
/**
- * The printer data reference.
+ * The printer data reference.
*/
protected PrinterData fPrinterData;
/**
*/
protected boolean fShowPrintButton;
/**
- * Test value
+ * Test value
*/
protected int fTest = 3;
/**
*/
protected WizardPage fParentWizardPage = null;
/**
- * Reference to parent print dialog.
+ * Reference to parent print dialog.
*/
protected SDPrintDialog fParentDialog = null;
// ------------------------------------------------------------------------
/**
* Local sequence diagram widget used to display overview of sequence diagram to print.
- * @version 1.0
+ * @version 1.0
*/
protected class LocalSD extends SDWidget {
if (fSdView.getContentsHeight() > fSdView.getContentsHeight()) {
return (int) (fSdView.getVisibleHeight() / (float) fTest / fSdView.fZoomValue);
}
- return (int) (super.getContentsHeight());
+ return super.getContentsHeight();
}
/*
if (fSdView.getVisibleWidth() > fSdView.getContentsWidth()) {
return (int) (fSdView.getVisibleWidth() / (float) fTest / fSdView.fZoomValue);
}
- return (int) (super.getContentsWidth());
+ return super.getContentsWidth();
}
/*
/**
* Creates page selection images.
- *
+ *
* @param img - Overview image
* @param width -The width value
* @param stepX - Step X
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)
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();
}
}
+ /**
+ * 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;
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$
}
}
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$
}
}
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];
/**
* Creates new grid data object.
- *
+ *
* @param span horizontal span.
* @return grid data
*/
/**
* Creates the dialog area.
- *
+ *
* @param parent The parent composite
* @return dialog control
*/
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()) {
});
- 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() {
/*
if (fShowPrintButton) {
Composite printerDlg = new Composite(parent, SWT.NONE);
- data = GridUtil.createHorizontalFill();
+ data = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
data.horizontalSpan = 6;
parentLayout = new GridLayout();
parentLayout.numColumns = 2;
printerDlg.setLayoutData(data);
Label label = new Label(printerDlg, SWT.NONE);
- label.setLayoutData(GridUtil.createHorizontalFill());
+ label.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
fPrinterDialog = new Button(printerDlg, SWT.PUSH);
fPrinterDialog.setText(SDMessages._115);
*/
@Override
public void widgetSelected(SelectionEvent e) {
-
printButtonSelected();
}
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();
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;
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) {
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() {
/**
* 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];
/**
* 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);
/**
* Returns the maximum number of pages.
- *
+ *
* @return maximum number of pages.
*/
public int maxNumOfPages() {
/**
* Returns the number of rows.
- *
+ *
* @return number of rows.
*/
public int getNbRow() {
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++;
}
/**
* Returns the number of lines.
- *
+ *
* @return number of lines
*/
public int getNbLines() {
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++;
}
/**
* Returns whether to print all pages or not.
- *
+ *
* @return <code>true</code> for all pages else <code>false</code>.
*/
public boolean printAll() {
}
/**
- * 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() {
/**
* 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() {
/**
* Returns the step in X direction.
- *
+ *
* @return step in X direction
*/
public float getStepX() {
/**
* Returns the step in Y direction.
- *
+ *
* @return step in Y direction
*/
public float getStepY() {
/**
* Returns the zoom factor
- *
+ *
* @return zoom factor
*/
public float getZoomFactor() {
/**
* Returns the printer data reference.
- *
+ *
* @return printer data reference
*/
public PrinterData getPrinterData() {
/**
* Returns the page number to start printing from.
- *
+ *
* @return page number to start printing from
*/
public int getFrom() {
/**
* Returns the page number to print to.
- *
+ *
* @return page number to print to
*/
public int getTo() {
/**
* Returns the shell reference.
- *
+ *
* @return the shell reference.
*/
public Shell getShell() {
/**
* Sets the shell.
- *
+ *
* @param shell The shell reference.
*/
public void setShell(Shell shell) {
/**
* Sets parent wizard page
- *
+ *
* @param parent The parent wizard page
*/
public void setParentWizardPage(WizardPage parent) {
/**
* Sets the parent dialog box.
- *
- * @param parent The parent dialog box.
+ *
+ * @param parent The parent dialog box.
*/
public void setParentDialog(SDPrintDialog parent) {
fParentDialog = parent;