Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Print figure operation yields blank page
Print figure operation yields blank page [message #220306] Fri, 28 July 2006 16:09 Go to next message
Eclipse UserFriend
Originally posted by: eclipse.chris-lott.org

All,

I am trying to reuse the core of the Draw2d print example given in the
draw2d cvs area:
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.draw2d. examples/src/org/eclipse/draw2d/examples/printing/PrintExamp le.java?rev=1.4&cvsroot=Tools_Project&content-type=t ext/vnd.viewcvs-markup

I'm using Eclipse 3.2, latest Gef/Draw2d. It's running on windows.

My code creates a figure with labels -- this is an attempt to print the
contents of a view like the properties view. I do not want to show the
figure in a shell on the screen using a lightweight system. I simply want
to create the figure, let the user pick the printer, and dump it to the
chosen printer. The problem is that the resulting page is always blank.
I don't know if this is a clipping problem, a color problem, or yet
something else. I have pared my code down to the method shown below.

Please note that I can print graphical diagrams just fine, along with
plain text, etc. so eclipse printing seems fine. It must be something
that I'm doing wrong. I would be just incredibly grateful for some help
because I've puzzled over this for so long that I'm starting to dream
about it! Please tell me what to try. Thanks in advance.

chris...

--

import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PrintFigureOperation;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.printing.PrintDialog;
import org.eclipse.swt.printing.Printer;
import org.eclipse.swt.printing.PrinterData;
import org.eclipse.swt.widgets.Shell;

public void printOneLabelFigure() {

Figure contents = new Figure();
contents.setLayoutManager(new FlowLayout());
contents.setBounds(new Rectangle(0, 0, 300, 300));
Font font = new Font(null, "Helvetica", 12, 0);
contents.setFont(font);

Label label = new Label("Test label");
label.setFont(font);
contents.add(label);

Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
PrintDialog pd = new PrintDialog(shell);
PrinterData pdata = pd.open();
if (pdata != null) {
Printer printer = new Printer(pdata);
PrintFigureOperation pfo = new PrintFigureOperation(printer, contents);
try {
pfo.run("test");
}
catch (Throwable t) {
t.printStackTrace();
}
finally {
printer.dispose();
}
}
font.dispose();
}
Re: Print figure operation yields blank page [message #220415 is a reply to message #220306] Mon, 31 July 2006 13:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.chris-lott.org

The answer here was that I was not using a FigureCanvas -- something to
bridge the gap between SWT (i.e., windows) and Draw2d. Once I added that,
and it brought along its Lightweight System under the covers, all worked
like a charm.

chris...
Re: Print figure operation yields blank page [message #220634 is a reply to message #220415] Wed, 02 August 2006 18:02 Go to previous message
Eclipse UserFriend
Originally posted by: jr_gz.yahoo.es

Hello Chris,

IŽm Jose Regino(sorry for my english) and IŽve got a similar problem that
you had but the problem is than I canŽt resolve it.

IŽm newer in eclipse and IŽm developing a plug-in that show a view that
contains:
-tableviewer to show text
-a part to paint rectangle and connections (representation of the text
file)

Something like this:
-View--------------------
| | |
| table | Canvas |
| viewer | |
| | |
-------------------------

I create the view "without problems" but when I try to print the Canvas
with your program ocurrs the next:
-I choose the printer
-The printer seem that begin to work, but nothing

Could you help me?






This is the code that represent the Canvas and try to print itŽs content(I
called it from the tipical createPartControl(Composite parent)of a
SampleView):


public static Figure Procesar_CAD(Canvas cani,TableItem item,Table table)
{
analizar(item,table); //read the file and prepare the estructures


LightweightSystem lws = new LightweightSystem(cani);
IFigure contents = new Figure();
contents.setLayoutManager(new XYLayout());
CompoundBorder border = new CompoundBorder(new LineBorder(),new
MarginBorder(3));

IFigure triangle=null;
IFigure compo=null;
IFigure fork=null;
IFigure ellipse= null;
IFigure ellipse32=null;
IFigure ellipse33=null;
IFigure triangle2=null;
IFigure triangle21=null;

Vector vector_componentes_pintados= new Vector(1000);
Vector vector_forks_pintados = new Vector(1000);
Figura fig=null;
Figura fig2=null;

int contador=0;
int tam_vec=0;

String nombre=null;
String nombre_componente=null;
String nombre_fork=null;


nombre=(String) vector_observers.get(0);
Button boton=boton_imprimir(contents);

triangle=pintar_observer(nombre,border,contents,triangle); //funciona

//creo los componentes, los forks y las conexiones entre ellos
tam_vec=vector_conexioninterfaz.size();
while(contador<tam_vec){
nombre=(String) vector_conexioninterfaz.get(contador);

//separo el nombre entre el componente y el fork
int pos=nombre.indexOf("-");
int longitud=nombre.length();

nombre_componente=nombre.substring(0,pos);
nombre_fork=nombre.substring(pos+1,longitud);


fig=buscarenvector(vector_componentes_pintados,nombre_compon ente);
if(fig==null){ //pinto el componente y lo uno con el observer
compo = new Label(nombre_componente);
compo.setBorder(border);
compo.setOpaque(true);
compo.setBackgroundColor(ColorConstants.lightBlue);

contents.add(compo, new Rectangle(10, 90+(contador*40), 60, 60));
ellipse32=pintar_elipse_mitad(ellipse32,ellipse33,contador,c ontents);
triangle21=pintar_triangulo(triangle2,triangle21,contador,co ntents);


connect2(contents,triangle,triangle21);



fig = new Figura(nombre_componente,10,90+(contador*40),60,60);
vector_componentes_pintados.add(fig);
}

else{
compo = new Label(fig.devolver_nombre());
compo.setBorder(border);
compo.setOpaque(true);
compo.setBackgroundColor(ColorConstants.lightBlue);
contents.add(compo, new
Rectangle(fig.devolver_pos1(),fig.devolver_pos2(),fig.devolv er_pos3(),fig.devolver_pos4()));

ellipse32=pintar_elipse_mitad2(ellipse32,ellipse33,contador, contents);
}


fig2=buscarenvector(vector_forks_pintados,nombre_fork);
if(fig2==null){ //pinto el fork
fork = new Label(nombre_fork);
fork.setBorder(border);
fork.setOpaque(true);
fork.setBackgroundColor(ColorConstants.lightGreen);
contents.add(fork, new Rectangle(330, 90+(contador*40), -1, -1));

ellipse=pintar_ellipse(ellipse,contador,contents);

fig2 = new Figura(nombre_fork,330, 90+(contador*40), -1, -1);
vector_forks_pintados.add(fig2);
}
else{
fork = new Label(fig2.devolver_nombre());
fork.setBorder(border);
fork.setOpaque(true);
fork.setBackgroundColor(ColorConstants.lightGreen);
contents.add(fork, new
Rectangle(fig2.devolver_pos1(),fig2.devolver_pos2(),fig2.dev olver_pos3(),fig2.devolver_pos4()));

ellipse=pintar_ellipse2(ellipse,contents,fig2);
}

connect(contents,ellipse32,ellipse);

contador++;
}




lws.setContents(contents);

//HERE begin your code
Shell shell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
PrintDialog pd = new PrintDialog(shell);
PrinterData pdata = pd.open();
if (pdata != null) {
Printer printer = new Printer(pdata);
PrintFigureOperation pfo = new PrintFigureOperation(printer, contents);
try {
pfo.run("test");
}
catch (Throwable t) {
System.out.println("DosenŽt work the printer");
}
finally {
printer.dispose();
}
}


}
Previous Topic:DirectEdit and FieldAssist
Next Topic:Synchornize scrollbars of two graphical viewers
Goto Forum:
  


Current Time: Thu Apr 25 09:04:45 GMT 2024

Powered by FUDForum. Page generated in 0.02731 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top