use of org.eclipse.swt.printing.PrintDialog in project eclipse.platform.text by eclipse.
the class TextViewer method print.
/**
* {@inheritDoc}
*
* @since 3.4
*/
@Override
public void print(StyledTextPrintOptions options) {
final Shell shell = fTextWidget.getShell();
if (Printer.getPrinterList().length == 0) {
// $NON-NLS-1$
String title = JFaceTextMessages.getString("TextViewer.warning.noPrinter.title");
// $NON-NLS-1$
String msg = JFaceTextMessages.getString("TextViewer.warning.noPrinter.message");
MessageDialog.openWarning(shell, title, msg);
return;
}
final PrintDialog dialog = new PrintDialog(shell, SWT.PRIMARY_MODAL);
dialog.setPrinterData(fgPrinterData);
final PrinterData data = dialog.open();
if (data != null) {
final Printer printer = new Printer(data);
final Runnable styledTextPrinter = fTextWidget.print(printer, options);
Thread printingThread = new // $NON-NLS-1$
Thread(// $NON-NLS-1$
"Printing") {
@Override
public void run() {
styledTextPrinter.run();
printer.dispose();
}
};
printingThread.start();
/*
* FIXME:
* Should copy the printer data to avoid threading issues,
* but this is currently not possible, see http://bugs.eclipse.org/297957
*/
fgPrinterData = data;
fgPrinterData.startPage = 1;
fgPrinterData.endPage = 1;
fgPrinterData.scope = PrinterData.ALL_PAGES;
fgPrinterData.copyCount = 1;
}
}
use of org.eclipse.swt.printing.PrintDialog in project eclipse.platform.swt by eclipse.
the class DialogTab method createControlWidgets.
/**
* Creates the "Control" widget children.
*/
@Override
void createControlWidgets() {
/* Create the combo */
String[] strings = { ControlExample.getResourceString("ColorDialog"), ControlExample.getResourceString("DirectoryDialog"), ControlExample.getResourceString("FileDialog"), ControlExample.getResourceString("FontDialog"), ControlExample.getResourceString("PrintDialog"), ControlExample.getResourceString("MessageBox") };
dialogCombo = new Combo(dialogStyleGroup, SWT.READ_ONLY);
dialogCombo.setItems(strings);
dialogCombo.setText(strings[0]);
dialogCombo.setVisibleItemCount(strings.length);
/* Create the create dialog button */
createButton = new Button(dialogStyleGroup, SWT.NONE);
createButton.setText(ControlExample.getResourceString("Create_Dialog"));
createButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
/* Create a group for the various dialog button style controls */
Group buttonStyleGroup = new Group(controlGroup, SWT.NONE);
buttonStyleGroup.setLayout(new GridLayout());
buttonStyleGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
buttonStyleGroup.setText(ControlExample.getResourceString("Button_Styles"));
/* Create the button style buttons */
okButton = new Button(buttonStyleGroup, SWT.CHECK);
okButton.setText("SWT.OK");
cancelButton = new Button(buttonStyleGroup, SWT.CHECK);
cancelButton.setText("SWT.CANCEL");
yesButton = new Button(buttonStyleGroup, SWT.CHECK);
yesButton.setText("SWT.YES");
noButton = new Button(buttonStyleGroup, SWT.CHECK);
noButton.setText("SWT.NO");
retryButton = new Button(buttonStyleGroup, SWT.CHECK);
retryButton.setText("SWT.RETRY");
abortButton = new Button(buttonStyleGroup, SWT.CHECK);
abortButton.setText("SWT.ABORT");
ignoreButton = new Button(buttonStyleGroup, SWT.CHECK);
ignoreButton.setText("SWT.IGNORE");
/* Create a group for the icon style controls */
Group iconStyleGroup = new Group(controlGroup, SWT.NONE);
iconStyleGroup.setLayout(new GridLayout());
iconStyleGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
iconStyleGroup.setText(ControlExample.getResourceString("Icon_Styles"));
/* Create the icon style buttons */
iconErrorButton = new Button(iconStyleGroup, SWT.RADIO);
iconErrorButton.setText("SWT.ICON_ERROR");
iconInformationButton = new Button(iconStyleGroup, SWT.RADIO);
iconInformationButton.setText("SWT.ICON_INFORMATION");
iconQuestionButton = new Button(iconStyleGroup, SWT.RADIO);
iconQuestionButton.setText("SWT.ICON_QUESTION");
iconWarningButton = new Button(iconStyleGroup, SWT.RADIO);
iconWarningButton.setText("SWT.ICON_WARNING");
iconWorkingButton = new Button(iconStyleGroup, SWT.RADIO);
iconWorkingButton.setText("SWT.ICON_WORKING");
noIconButton = new Button(iconStyleGroup, SWT.RADIO);
noIconButton.setText(ControlExample.getResourceString("No_Icon"));
/* Create a group for the modal style controls */
Group modalStyleGroup = new Group(controlGroup, SWT.NONE);
modalStyleGroup.setLayout(new GridLayout());
modalStyleGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
modalStyleGroup.setText(ControlExample.getResourceString("Modal_Styles"));
/* Create the modal style buttons */
primaryModalButton = new Button(modalStyleGroup, SWT.RADIO);
primaryModalButton.setText("SWT.PRIMARY_MODAL");
applicationModalButton = new Button(modalStyleGroup, SWT.RADIO);
applicationModalButton.setText("SWT.APPLICATION_MODAL");
systemModalButton = new Button(modalStyleGroup, SWT.RADIO);
systemModalButton.setText("SWT.SYSTEM_MODAL");
/* Create a group for the file dialog style controls */
Group fileDialogStyleGroup = new Group(controlGroup, SWT.NONE);
fileDialogStyleGroup.setLayout(new GridLayout());
fileDialogStyleGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
fileDialogStyleGroup.setText(ControlExample.getResourceString("File_Dialog_Styles"));
/* Create the file dialog style buttons */
openButton = new Button(fileDialogStyleGroup, SWT.RADIO);
openButton.setText("SWT.OPEN");
saveButton = new Button(fileDialogStyleGroup, SWT.RADIO);
saveButton.setText("SWT.SAVE");
multiButton = new Button(fileDialogStyleGroup, SWT.CHECK);
multiButton.setText("SWT.MULTI");
/* Create the orientation group */
if (RTL_SUPPORT_ENABLE) {
createOrientationGroup();
}
/* Create a group for other style and setting controls */
Group otherGroup = new Group(controlGroup, SWT.NONE);
otherGroup.setLayout(new GridLayout());
otherGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
otherGroup.setText(ControlExample.getResourceString("Other"));
/* Create the other style and setting controls */
sheetButton = new Button(otherGroup, SWT.CHECK);
sheetButton.setText("SWT.SHEET");
usePreviousResultButton = new Button(otherGroup, SWT.CHECK);
usePreviousResultButton.setText(ControlExample.getResourceString("Use_Previous_Result"));
effectsVisibleButton = new Button(otherGroup, SWT.CHECK);
effectsVisibleButton.setText("FontDialog.setEffectsVisible");
/* Add the listeners */
dialogCombo.addSelectionListener(widgetSelectedAdapter(event -> dialogSelected(event)));
createButton.addSelectionListener(widgetSelectedAdapter(event -> createButtonSelected(event)));
SelectionListener buttonStyleListener = widgetSelectedAdapter(event -> buttonStyleSelected(event));
okButton.addSelectionListener(buttonStyleListener);
cancelButton.addSelectionListener(buttonStyleListener);
yesButton.addSelectionListener(buttonStyleListener);
noButton.addSelectionListener(buttonStyleListener);
retryButton.addSelectionListener(buttonStyleListener);
abortButton.addSelectionListener(buttonStyleListener);
ignoreButton.addSelectionListener(buttonStyleListener);
/* Set default values for style buttons */
okButton.setEnabled(false);
cancelButton.setEnabled(false);
yesButton.setEnabled(false);
noButton.setEnabled(false);
retryButton.setEnabled(false);
abortButton.setEnabled(false);
ignoreButton.setEnabled(false);
iconErrorButton.setEnabled(false);
iconInformationButton.setEnabled(false);
iconQuestionButton.setEnabled(false);
iconWarningButton.setEnabled(false);
iconWorkingButton.setEnabled(false);
noIconButton.setEnabled(false);
saveButton.setEnabled(false);
openButton.setEnabled(false);
openButton.setSelection(true);
multiButton.setEnabled(false);
noIconButton.setSelection(true);
effectsVisibleButton.setEnabled(false);
effectsVisibleButton.setSelection(true);
}
use of org.eclipse.swt.printing.PrintDialog in project eclipse.platform.swt by eclipse.
the class Test_org_eclipse_swt_printing_PrintDialog method setUp.
@Override
@Before
public void setUp() {
super.setUp();
printDialog = new PrintDialog(shell, SWT.NONE);
setDialog(printDialog);
}
use of org.eclipse.swt.printing.PrintDialog in project eclipse.platform.swt by eclipse.
the class ImageAnalyzer method menuPrint.
void menuPrint() {
if (image == null)
return;
try {
// Ask the user to specify the printer.
PrintDialog dialog = new PrintDialog(shell, SWT.NONE);
if (printerData != null)
dialog.setPrinterData(printerData);
printerData = dialog.open();
if (printerData == null)
return;
Printer printer = new Printer(printerData);
Point screenDPI = display.getDPI();
Point printerDPI = printer.getDPI();
int scaleFactor = printerDPI.x / screenDPI.x;
Rectangle trim = printer.computeTrim(0, 0, 0, 0);
if (printer.startJob(currentName)) {
if (printer.startPage()) {
GC gc = new GC(printer);
int transparentPixel = imageData.transparentPixel;
if (transparentPixel != -1 && !transparent) {
imageData.transparentPixel = -1;
}
Image printerImage = new Image(printer, imageData);
gc.drawImage(printerImage, 0, 0, imageData.width, imageData.height, -trim.x, -trim.y, scaleFactor * imageData.width, scaleFactor * imageData.height);
if (transparentPixel != -1 && !transparent) {
imageData.transparentPixel = transparentPixel;
}
printerImage.dispose();
gc.dispose();
printer.endPage();
}
printer.endJob();
}
printer.dispose();
} catch (SWTError e) {
MessageBox box = new MessageBox(shell, SWT.ICON_ERROR);
box.setMessage(bundle.getString("Printing_error") + e.getMessage());
box.open();
}
}
use of org.eclipse.swt.printing.PrintDialog in project org.csstudio.display.builder by kasemir.
the class PrintAction method run.
/**
* {@inheritDoc}
*/
@Override
public void run() {
// Get snapshot. Disposed at end of printing
final Image snapshot = media_pool.get(ImageConverter.convertToSWT(graph.getImage()));
if (snapshot == null) {
Logger.getLogger(getClass().getName()).fine("Cannot obtain image");
return;
}
// Printer GUI
final PrintDialog dlg = new PrintDialog(shell);
PrinterData data = dlg.open();
if (data == null) {
Logger.getLogger(getClass().getName()).fine("Cannot obtain printer");
snapshot.dispose();
return;
}
// At least on Linux, access to SWT Printer must be on UI thread.
// Printing in other thread can deadlock with UI thread.
final Printer printer = new Printer(data);
try {
if (!printer.startJob("Data Browser")) {
Logger.getLogger(getClass().getName()).fine("Cannot start print job");
return;
}
try {
// Printer page info
final Rectangle area = printer.getClientArea();
final Rectangle trim = printer.computeTrim(0, 0, 0, 0);
final Point dpi = printer.getDPI();
// Compute layout
final Rectangle image_rect = snapshot.getBounds();
// Leave one inch on each border.
// (copied the computeTrim stuff from an SWT example.
// Really no clue...)
final int left_right = dpi.x + trim.x;
final int top_bottom = dpi.y + trim.y;
final int printed_width = area.width - 2 * left_right;
// Try to scale height according to on-screen aspect ratio.
final int max_height = area.height - 2 * top_bottom;
final int printed_height = Math.min(max_height, image_rect.height * printed_width / image_rect.width);
// Print one page
printer.startPage();
final GC gc = new GC(printer);
gc.drawImage(snapshot, 0, 0, image_rect.width, image_rect.height, left_right, top_bottom, printed_width, printed_height);
printer.endPage();
} finally {
printer.endJob();
}
} finally {
printer.dispose();
snapshot.dispose();
}
}
Aggregations