KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > JReportFrame


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * JReportFrame.java
28  *
29  * Created on 12 febbraio 2003, 21.51
30  *
31  */

32
33 package it.businesslogic.ireport.gui;
34 import bsh.Interpreter;
35 import it.businesslogic.ireport.CrosstabReportElement;
36 import it.businesslogic.ireport.FrameReportElement;
37 import it.businesslogic.ireport.IReportFont;
38 import it.businesslogic.ireport.SubReportElement;
39 import it.businesslogic.ireport.TransformationType;
40 import it.businesslogic.ireport.chart.gui.ChartSelectionJDialog;
41 import it.businesslogic.ireport.crosstab.gui.CrosstabEditor;
42 import it.businesslogic.ireport.gui.event.*;
43 import it.businesslogic.ireport.gui.wizard.SubreportWizard;
44 import it.businesslogic.ireport.undo.*;
45 import it.businesslogic.ireport.util.*;
46 import it.businesslogic.ireport.*;
47 import it.businesslogic.ireport.crosstab.CrosstabCell;
48 import it.businesslogic.ireport.crosstab.gui.CrosstabEditorPanel;
49 import it.businesslogic.ireport.crosstab.gui.CrosstabWizardDialog;
50 import it.businesslogic.ireport.gui.command.FormatCommand;
51 import java.awt.event.FocusEvent JavaDoc;
52 import java.awt.event.FocusListener JavaDoc;
53 import java.awt.event.KeyEvent JavaDoc;
54 import java.awt.event.KeyListener JavaDoc;
55 import java.awt.geom.*;
56 import java.util.*;
57 import java.awt.*;
58 import java.awt.image.*;
59 import java.io.File JavaDoc;
60 import java.net.URL JavaDoc;
61 import javax.swing.JOptionPane JavaDoc;
62 import javax.swing.JTextArea JavaDoc;
63 import javax.swing.JTextPane JavaDoc;
64 import javax.swing.text.SimpleAttributeSet JavaDoc;
65 import javax.swing.text.StyleConstants JavaDoc;
66 import javax.swing.text.StyledDocument JavaDoc;
67
68 /**
69  *
70  * @author Administrator
71  */

72 public class JReportFrame extends JMDIFrame implements LanguageChangedListener {
73
74     static int id = 0;
75     static java.awt.Cursor JavaDoc hsplit = null;
76     //private Graphics2D offscreen = null;
77
//private Graphics2D offscreenDoc = null;
78
//private BufferedImage offscreenImage = null;
79
//private BufferedImage offscreenImageDoc = null;
80
private int offscreenWidth = 0;
81     private Dimension offscreenDimension = null;
82     private boolean isDocDirty = true;
83
84     private MainFrame mf = null;
85     private BufferedImage[] shadowsImages = null;
86
87     /** This point rappresent coords of left top corner of the popup menu.... */
88     private java.awt.Point JavaDoc popup_opened_at = null;
89
90     /** true if the the user is trnsforming a new element....*/
91     private boolean transforming = false;
92
93     /** We are dragging a band ? */
94     boolean band_dragging=false;
95     /** We have started to drag a band from here */
96     int band_dragging_origin=0;
97     /** We are dragging this band... */
98     Band band_dragging_band=null;
99     /** State for XOR operation in band dragging... */
100     boolean first_draw_band=true;
101     boolean firstXORDraw = false ; //= false; // why not true?
102
boolean firstXORDrawTransforming = false;
103
104     int tabs = 0;
105
106     private TexturePaint mGridTexture = null;
107
108     /**
109      * This flag is true if we are selecting elements drawing a rectangle...
110      */

111     private boolean drag_selection_mode = false;
112     /**
113      * The origin of the selection rectangle...
114      */

115     private java.awt.Point JavaDoc drag_selection_origin = null;
116     /**
117      * The end of the selection rectangle...
118      */

119     private java.awt.Point JavaDoc drag_selection_end = null;
120     /**
121      * The flag is used to handle XOR operation on rectangle selection
122      */

123     private boolean first_draw_selection_rect = true;
124
125     /**
126      * Stroke to use when draw selection rectangle
127      */

128     private java.awt.Stroke JavaDoc selectionStroke = null;
129     
130     private JRulePanel jVerticalRule = null;
131
132     // Menus...
133
private javax.swing.JMenu JavaDoc jMenuAlign;
134     private javax.swing.JMenuItem JavaDoc jMenuItemAlignLeft;
135     private javax.swing.JMenuItem JavaDoc jMenuItemAlignRight;
136     private javax.swing.JMenuItem JavaDoc jMenuItemAlignTop;
137     private javax.swing.JMenuItem JavaDoc jMenuItemAlignBottom;
138     private javax.swing.JSeparator JavaDoc jSeparator19;
139     private javax.swing.JMenuItem JavaDoc jMenuItemAlignVerticalAxis;
140     private javax.swing.JMenuItem JavaDoc jMenuItemAlignHorizontalAxis ;
141     private javax.swing.JSeparator JavaDoc jSeparator20;
142     private javax.swing.JMenuItem JavaDoc jMenuItemAlignToBandTop;
143     private javax.swing.JMenuItem JavaDoc jMenuItemAlignToBandBottom;
144     private javax.swing.JMenu JavaDoc jMenuSize;
145     private javax.swing.JMenuItem JavaDoc jMenuItemSameWidth;
146     private javax.swing.JMenuItem JavaDoc jMenuItemSameWidthMax;
147     private javax.swing.JMenuItem JavaDoc jMenuItemSameWidthMin;
148     private javax.swing.JSeparator JavaDoc jSeparator17;
149     private javax.swing.JMenuItem JavaDoc jMenuItemSameHeight;
150     private javax.swing.JMenuItem JavaDoc jMenuItemSameHeightMax;
151     private javax.swing.JMenuItem JavaDoc jMenuItemSameHeightMin;
152     private javax.swing.JSeparator JavaDoc jSeparator18;
153     private javax.swing.JMenuItem JavaDoc jMenuItemSameSize;
154     private javax.swing.JMenu JavaDoc jMenuPosition;
155     private javax.swing.JMenuItem JavaDoc jMenuItemCenterH;
156     private javax.swing.JMenuItem JavaDoc jMenuItemCenterV;
157     private javax.swing.JMenuItem JavaDoc jMenuItemCenterInBand;
158     private javax.swing.JMenuItem JavaDoc jMenuItemCenterBackground;
159     private javax.swing.JMenuItem JavaDoc jMenuItemJoinLeft;
160     private javax.swing.JMenuItem JavaDoc jMenuItemJoinRight;
161     private javax.swing.JSeparator JavaDoc jSeparator5;
162     private javax.swing.JMenuItem JavaDoc jMenuHSpacing;
163     private javax.swing.JMenuItem JavaDoc jMenuItemHSMakeEqual;
164     private javax.swing.JMenuItem JavaDoc jMenuItemHSIncrease;
165     private javax.swing.JMenuItem JavaDoc jMenuItemHSDecrease;
166     private javax.swing.JMenuItem JavaDoc jMenuItemHSRemove;
167     private javax.swing.JMenuItem JavaDoc jMenuVSpacing;
168     private javax.swing.JMenuItem JavaDoc jMenuItemVSMakeEqual;
169     private javax.swing.JMenuItem JavaDoc jMenuItemVSIncrease;
170     private javax.swing.JMenuItem JavaDoc jMenuItemVSDecrease;
171     private javax.swing.JMenuItem JavaDoc jMenuItemVSRemove;
172     private javax.swing.JSeparator JavaDoc jSeparator8;
173     private javax.swing.JMenuItem JavaDoc jMenuItemBringToFront;
174     private javax.swing.JMenuItem JavaDoc jMenuItemSendToBack;
175     private javax.swing.JPopupMenu JavaDoc jPopupMenuElementMS;
176     private javax.swing.JMenuItem JavaDoc jMenuItemOrganize;
177     private javax.swing.JMenuItem JavaDoc jMenuItemRightMargin;
178     private javax.swing.JMenuItem JavaDoc jMenuItemLeftMargin;
179
180     private JTextPane JavaDoc floatingTextArea = new JTextPane JavaDoc(); //JTextArea();
181
private String JavaDoc previousFloatingTextAreaValue = "";
182
183     private java.util.List JavaDoc openedNodesDocumentStructure = null;
184
185     private TextReportElement onlineEditingTextReportElement = null;
186
187
188
189     /*
190      * This variable is used to say if the resistence moving an element with mouse was
191      * exceeded
192      */

193     boolean resistenceExceeded = false;
194
195     Point newObjectOrigin = null;
196
197     boolean trasforming = false;
198     int transformation_type= -1;
199     Point transformation_origin=null;
200     Point transformation_origin_end=null;
201     Point transformation_undo_delta=null;
202
203     /** Creates new form JReportFrame */
204     public JReportFrame(Report report) {
205
206         initComponents();
207         
208         jHorizontalRule.setJReportFrame( this );
209         jHorizontalRule.repaint();
210         jPanelReportContainer.setIgnoreRepaint(true);
211         
212         jVerticalRule = new JRulePanel();
213         jVerticalRule.setType(jVerticalRule.TYPE_VERTICAL);
214         jVerticalRule.setJReportFrame( this );
215         jPanelVRule.add(jVerticalRule, java.awt.BorderLayout.CENTER);
216         jVerticalRule.repaint();
217         
218         addFormatItemsToMenu(jPopupMenuElement);
219         this.windowID = id++;
220
221         floatingTextArea.setOpaque(true);
222         floatingTextArea.addFocusListener( new FocusListener JavaDoc() {
223             public void focusGained(FocusEvent JavaDoc e) {
224
225             }
226             public void focusLost(FocusEvent JavaDoc e) {
227                 floatingTextAreaFocusLost();
228             }
229         });
230
231         floatingTextArea.addKeyListener( new KeyListener JavaDoc()
232             {
233                 public void keyPressed(KeyEvent JavaDoc e) {
234                     if (e.getKeyCode() == e.VK_ENTER && (e.getModifiers() & e.SHIFT_DOWN_MASK) == 0)
235                     {
236                         e.consume();
237                         floatingTextAreaFocusLost();
238                     }
239                     if (e.getKeyCode() == e.VK_ESCAPE)
240                     {
241                         e.consume();
242                         floatingTextAreaFocusLost(false);
243                     }
244                 }
245                 public void keyReleased(KeyEvent JavaDoc e) {
246                 }
247                 public void keyTyped(KeyEvent JavaDoc e) {
248                 }
249             });
250
251
252
253         floatingTextArea.getDocument().addDocumentListener( new javax.swing.event.DocumentListener JavaDoc() {
254             public void changedUpdate(javax.swing.event.DocumentEvent JavaDoc evt) {
255                 floatingTextChanged();
256             }
257             public void insertUpdate(javax.swing.event.DocumentEvent JavaDoc evt) {
258                 floatingTextChanged();
259             }
260             public void removeUpdate(javax.swing.event.DocumentEvent JavaDoc evt) {
261                 floatingTextChanged();
262             }
263         });
264
265         selectionStroke = new java.awt.BasicStroke JavaDoc(
266                 (float)(2f),
267                 java.awt.BasicStroke.CAP_BUTT,
268                 java.awt.BasicStroke.JOIN_BEVEL,
269                 0f,
270                 new float[]{5f, 3f},
271                 0f
272                         );
273                 this.setPreferredSize(new Dimension(350,400));
274                 this.setNormalSize(new Dimension(350,400));
275                 if (hsplit == null) {
276                     hsplit = Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR);
277                 }
278                 this.jPanelReport.setJrf(this);
279                 this.report = report;
280
281                 this.newObjectType = ReportElementType.NONE;
282                 this.report=report;
283                 this.report.setReportFrame(this);
284                 this.setTitle(this.report.getName()+" "+this.report.getWidth()+"x"+this.report.getDesignHeight()+" ["+Misc.nvl(this.report.getFilename(),"unnamed")+"]");
285                 //System.out.println(this.getTitle());
286

287                 undoOperations = new Vector();
288                 clipboardObjects = new Vector();
289                 selectedElements = new Vector();
290                 transformation_undo_delta = new Point(0,0);
291
292                 zoomFactor = 1.0;
293                 
294                 transformationMinSize =5;
295
296                 undoIndex = -1;
297
298                 // Init images...
299
shadowsImages = new BufferedImage[5];
300
301                 shadowsImages[0] = Misc.loadBufferedImageFromResources(this,"it/businesslogic/ireport/icons/layout/sh_ur.gif");
302                 shadowsImages[1] = Misc.loadBufferedImageFromResources(this,"it/businesslogic/ireport/icons/layout/sh_r.gif");
303                 shadowsImages[2] = Misc.loadBufferedImageFromResources(this,"it/businesslogic/ireport/icons/layout/sh_lr.gif");
304                 shadowsImages[3] = Misc.loadBufferedImageFromResources(this,"it/businesslogic/ireport/icons/layout/sh_d.gif");
305                 shadowsImages[4] = Misc.loadBufferedImageFromResources(this,"it/businesslogic/ireport/icons/layout/sh_dl.gif");
306
307         /*
308         try {
309             cursorplus = new Cursor(ResourceManager.getResource( getClass(), "cursorplus.cur"));
310             cursorminus = new Cursor( ResourceManager.getResource(getClass(), "cursorminus.cur"));
311         } catch (Exception ex)
312         {}
313
314         if (cursorplus == null )
315         {
316                 if (com.ms.wfc.io.File.exists(com.ms.wfc.io.File.combine( getProgramDir(), "com\\businesslogic\\ireport\\ui\\cursorplus.cur")))
317                 cursorplus = new Cursor(com.ms.wfc.io.File.combine( getProgramDir(), "com\\businesslogic\\ireport\\ui\\cursorplus.cur"));
318         }
319
320         if (cursorminus == null )
321         {
322                 if (com.ms.wfc.io.File.exists(com.ms.wfc.io.File.combine( getProgramDir(), "com\\businesslogic\\ireport\\ui\\cursorminus.cur")))
323                         cursorminus = new Cursor( com.ms.wfc.io.File.combine( getProgramDir(), "com\\businesslogic\\ireport\\ui\\cursorminus.cur"));
324         }
325
326         if (cursorplus == null)
327                 cursorplus = Cursor.CROSS;
328         if (cursorminus == null)
329                 cursorminus = Cursor.CROSS;
330          */

331         /*
332         Enumeration enum = report.getElements().elements();
333         Brush br = new Brush(imageList2.getBitmap(0));
334         while (enum.hasMoreElements())
335         {
336                 ReportElement re = (ReportElement)enum.nextElement();
337                 re.hached = br;
338
339                 if (re instanceof SubReportElement)
340                 {
341                         ((SubReportElement)re).img = this.imageList4.getImage(0);
342                 }
343                 else if (re instanceof ImageReportElement )
344                 {
345
346                         ((ImageReportElement)re).defimg = imageList3.getBitmap(0);
347                 }
348                 }
349          */

350
351                 //offscreen.setBackground(new Color(128,128,128));
352
//setBackground(new Color(128,128,128));
353
//Screen screen = Screen.getPrimary();
354
offscreenDimension = Toolkit.getDefaultToolkit().getScreenSize();
355                 //offscreenImage = new java.awt.image.BufferedImage(offscreenDimension.width, offscreenDimension.height, java.awt.image.BufferedImage.TYPE_4BYTE_ABGR_PRE);
356
//offscreenImageDoc = new java.awt.image.BufferedImage(offscreenDimension.width, offscreenDimension.height, java.awt.image.BufferedImage.TYPE_4BYTE_ABGR_PRE);
357
//offscreen = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(offscreenImage);
358

359                 //offscreen.setBackground(new Color(128,128,128));
360
//offscreen.clearRect(0,0, offscreenDimension.width, offscreenDimension.height);
361
//offscreen.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
362
//offscreen.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
363
//offscreen.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
364

365                 //offscreenDoc = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(offscreenImageDoc);
366
//offscreenDoc.setBackground(new Color(128,128,128));
367
//offscreenDoc.clearRect(0,0, offscreenDimension.width, offscreenDimension.height);
368
//offscreenDoc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
369
//offscreenDoc.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
370
//offscreenDoc.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
371
//offscreen.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
372

373                 //redrawAll(offscreen,new Rectangle(0,0,report.getWidth(),report.getHeight()), 0);
374

375                 //redrawAll( offscreen,new Rectangle(0,0,report.getWidth(),report.getHeight()), 0);
376

377                 this.jHorizontalScrollBar.setValue(0);
378                 this.jVerticalScrollBar.setValue(0);
379
380                 updateTabs();
381
382                 for (int i=0; i<report.getElements().size(); ++i)
383                 {
384                     ReportElement re = (ReportElement)report.getElements().elementAt(i);
385                     if (re instanceof CrosstabReportElement)
386                     {
387                         addCrosstabEditor( (CrosstabReportElement)re);
388                     }
389                 }
390                 
391                 this.applyI18n();
392     }
393
394     public void floatingTextAreaFocusLost()
395     {
396         floatingTextAreaFocusLost(true);
397     }
398
399     public void floatingTextAreaFocusLost(boolean acceptModifications)
400     {
401
402         try {
403             if (onlineEditingTextReportElement != null)
404             {
405                 if (acceptModifications)
406                 {
407                         onlineEditingTextReportElement.setText( floatingTextArea.getText() );
408                         ReportElementChangedEvent changedEvent = new ReportElementChangedEvent(this , getSelectedElements() , ReportElementChangedEvent.CHANGED);
409                         changedEvent.setEventSource( this );
410                         changedEvent.setPropertyChanged( "text" );
411                         changedEvent.setNewValue( floatingTextArea.getText() );
412                         fireReportListenerReportElementsChanged(changedEvent);
413                         getMainFrame().getElementPropertiesDialog().updateSelection();
414                 }
415                 else
416                 {
417                     floatingTextArea.setText( onlineEditingTextReportElement.getText());
418                 }
419             }
420             
421             onlineEditingTextReportElement = null;
422             getReportPanel().remove( floatingTextArea );
423             getReportPanel().updateUI();
424
425         } catch (Exception JavaDoc ex) {}
426     }
427
428
429     /**
430      * Return the element at the point location (if any...)
431      */

432     public ReportElement getElementAt(Point location)
433     {
434         Point p = new Point(getLogicalDim((int)location.getX()+jHorizontalScrollBar.getValue()-10)+10,
435                         getLogicalDim((int)location.getY()+jVerticalScrollBar.getValue()-10)+10);
436
437         for (int i=report.getElements().size()-1; i>=0; --i)
438             {
439
440                 ReportElement re = (ReportElement)report.getElements().elementAt(i);
441                 if (re.intersects(p))
442                 {
443                     return re;
444                 }
445             }
446
447         return null;
448     }
449
450     public void floatingTextChanged()
451     {
452
453     }
454
455
456     /** This method is called from within the constructor to
457      * initialize the form.
458      * WARNING: Do NOT modify this code. The content of this method is
459      * always regenerated by the Form Editor.
460      */

461     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
462
private void initComponents() {
463         jPopupMenuBand = new javax.swing.JPopupMenu JavaDoc();
464         jMenuItemPasteOnBand = new javax.swing.JMenuItem JavaDoc();
465         jSeparator2 = new javax.swing.JSeparator JavaDoc();
466         jMenuItemBandProperties = new javax.swing.JMenuItem JavaDoc();
467         jPopupMenuElement = new javax.swing.JPopupMenu JavaDoc();
468         jMenuItemElementProperties = new javax.swing.JMenuItem JavaDoc();
469         jMenuItemElementChartProperties = new javax.swing.JMenuItem JavaDoc();
470         jMenuItemElementCrosstabProperties = new javax.swing.JMenuItem JavaDoc();
471         jMenuItemElementCrosstabDesignProperties = new javax.swing.JMenuItem JavaDoc();
472         jMenuItemElementOpenSubreport = new javax.swing.JMenuItem JavaDoc();
473         jMenuItemBandProperties1 = new javax.swing.JMenuItem JavaDoc();
474         jSeparator1 = new javax.swing.JSeparator JavaDoc();
475         jMenuItemCut = new javax.swing.JMenuItem JavaDoc();
476         jMenuItemCopy = new javax.swing.JMenuItem JavaDoc();
477         jMenuItemPaste = new javax.swing.JMenuItem JavaDoc();
478         jMenuItemDelete = new javax.swing.JMenuItem JavaDoc();
479         jSeparator3 = new javax.swing.JSeparator JavaDoc();
480         jMenuItemGroup = new javax.swing.JMenuItem JavaDoc();
481         jMenuItemUngroup = new javax.swing.JMenuItem JavaDoc();
482         jSeparator6 = new javax.swing.JSeparator JavaDoc();
483         jMenuItemCopyStyle = new javax.swing.JMenuItem JavaDoc();
484         jMenuItemPasteStyle = new javax.swing.JMenuItem JavaDoc();
485         jMenuItemTransformStaticText = new javax.swing.JMenuItem JavaDoc();
486         jMenuItemPattern = new javax.swing.JMenuItem JavaDoc();
487         jSeparator4 = new javax.swing.JSeparator JavaDoc();
488         jTabbedPane1 = new javax.swing.JTabbedPane JavaDoc();
489         jPanelSuperContainer = new javax.swing.JPanel JavaDoc();
490         jPanelReportContainer = new javax.swing.JPanel JavaDoc();
491         jPanelVRule = new javax.swing.JPanel JavaDoc();
492         jPanelHContainerRule = new javax.swing.JPanel JavaDoc();
493         jPanelCorner = new javax.swing.JPanel JavaDoc();
494         jHorizontalRule = new it.businesslogic.ireport.gui.JRulePanel();
495         jPanelReport = new it.businesslogic.ireport.gui.JReportPanel();
496         jVerticalScrollBar = new javax.swing.JScrollBar JavaDoc();
497         jPanelHScroll = new javax.swing.JPanel JavaDoc();
498         jHorizontalScrollBar = new javax.swing.JScrollBar JavaDoc();
499         jPanel1 = new javax.swing.JPanel JavaDoc();
500
501         jMenuItemPasteOnBand.setIcon(new javax.swing.ImageIcon JavaDoc(""));
502         jMenuItemPasteOnBand.setText("Paste here...");
503         jMenuItemPasteOnBand.addActionListener(new java.awt.event.ActionListener JavaDoc() {
504             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
505                 jMenuItemPasteOnBandActionPerformed(evt);
506             }
507         });
508         jMenuItemPasteOnBand.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
509             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
510                 jMenuItemPasteOnBandMouseClicked(evt);
511             }
512         });
513
514         jPopupMenuBand.add(jMenuItemPasteOnBand);
515
516         jPopupMenuBand.add(jSeparator2);
517
518         jMenuItemBandProperties.setIcon(new javax.swing.ImageIcon JavaDoc(""));
519         jMenuItemBandProperties.setText("Band properties");
520         jMenuItemBandProperties.addActionListener(new java.awt.event.ActionListener JavaDoc() {
521             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
522                 jMenuItemBandPropertiesActionPerformed(evt);
523             }
524         });
525
526         jPopupMenuBand.add(jMenuItemBandProperties);
527
528         jMenuItemElementProperties.setIcon(new javax.swing.ImageIcon JavaDoc(""));
529         jMenuItemElementProperties.setText("Properties");
530         jMenuItemElementProperties.addActionListener(new java.awt.event.ActionListener JavaDoc() {
531             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
532                 jMenuItemElementPropertiesActionPerformed(evt);
533             }
534         });
535         jMenuItemElementProperties.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
536             public void mouseClicked(java.awt.event.MouseEvent JavaDoc evt) {
537                 jMenuItemElementPropertiesMouseClicked(evt);
538             }
539         });
540
541         jPopupMenuElement.add(jMenuItemElementProperties);
542
543         jMenuItemElementChartProperties.setIcon(new javax.swing.ImageIcon JavaDoc(""));
544         jMenuItemElementChartProperties.setText("Chart properties");
545         jMenuItemElementChartProperties.addActionListener(new java.awt.event.ActionListener JavaDoc() {
546             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
547                 jMenuItemElementChartPropertiesActionPerformed(evt);
548             }
549         });
550
551         jPopupMenuElement.add(jMenuItemElementChartProperties);
552
553         jMenuItemElementCrosstabProperties.setIcon(new javax.swing.ImageIcon JavaDoc(""));
554         jMenuItemElementCrosstabProperties.setText("Crosstab properties");
555         jMenuItemElementCrosstabProperties.addActionListener(new java.awt.event.ActionListener JavaDoc() {
556             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
557                 jMenuItemElementCrosstabPropertiesActionPerformed(evt);
558             }
559         });
560
561         jPopupMenuElement.add(jMenuItemElementCrosstabProperties);
562
563         jMenuItemElementCrosstabDesignProperties.setIcon(new javax.swing.ImageIcon JavaDoc(""));
564         jMenuItemElementCrosstabDesignProperties.setText("Go to crosstab design tab....");
565         jMenuItemElementCrosstabDesignProperties.addActionListener(new java.awt.event.ActionListener JavaDoc() {
566             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
567                 jMenuItemElementCrosstabPropertiesActionPerformed1(evt);
568             }
569         });
570
571         jPopupMenuElement.add(jMenuItemElementCrosstabDesignProperties);
572
573         jMenuItemElementOpenSubreport.setIcon(new javax.swing.ImageIcon JavaDoc(""));
574         jMenuItemElementOpenSubreport.setText("Open subreport");
575         jMenuItemElementOpenSubreport.addActionListener(new java.awt.event.ActionListener JavaDoc() {
576             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
577                 jMenuItemElementOpenSubreportActionPerformed1(evt);
578             }
579         });
580
581         jPopupMenuElement.add(jMenuItemElementOpenSubreport);
582
583         jMenuItemBandProperties1.setIcon(new javax.swing.ImageIcon JavaDoc(""));
584         jMenuItemBandProperties1.setText("Band properties");
585         jMenuItemBandProperties1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
586             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
587                 jMenuItemBandPropertiesActionPerformed1(evt);
588             }
589         });
590
591         jPopupMenuElement.add(jMenuItemBandProperties1);
592
593         jPopupMenuElement.add(jSeparator1);
594
595         jMenuItemCut.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/cut.png")));
596         jMenuItemCut.setText("Cut");
597         jMenuItemCut.setEnabled(false);
598         jMenuItemCut.addActionListener(new java.awt.event.ActionListener JavaDoc() {
599             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
600                 jMenuItemCutActionPerformed(evt);
601             }
602         });
603
604         jPopupMenuElement.add(jMenuItemCut);
605
606         jMenuItemCopy.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/copy.png")));
607         jMenuItemCopy.setText("Copy");
608         jMenuItemCopy.setEnabled(false);
609         jMenuItemCopy.addActionListener(new java.awt.event.ActionListener JavaDoc() {
610             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
611                 jMenuItemCopyActionPerformed(evt);
612             }
613         });
614
615         jPopupMenuElement.add(jMenuItemCopy);
616
617         jMenuItemPaste.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/paste.png")));
618         jMenuItemPaste.setText("Paste");
619         jMenuItemPaste.setEnabled(false);
620         jMenuItemPaste.addActionListener(new java.awt.event.ActionListener JavaDoc() {
621             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
622                 jMenuItemPasteActionPerformed(evt);
623             }
624         });
625
626         jPopupMenuElement.add(jMenuItemPaste);
627
628         jMenuItemDelete.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/delete.png")));
629         jMenuItemDelete.setText("Delete");
630         jMenuItemDelete.setEnabled(false);
631         jMenuItemDelete.addActionListener(new java.awt.event.ActionListener JavaDoc() {
632             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
633                 jMenuItemDeleteActionPerformed(evt);
634             }
635         });
636
637         jPopupMenuElement.add(jMenuItemDelete);
638
639         jPopupMenuElement.add(jSeparator3);
640
641         jMenuItemGroup.setText("Group selected element(s)");
642         jMenuItemGroup.setEnabled(false);
643         jMenuItemGroup.addActionListener(new java.awt.event.ActionListener JavaDoc() {
644             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
645                 jMenuItemGroupActionPerformed(evt);
646             }
647         });
648
649         jPopupMenuElement.add(jMenuItemGroup);
650
651         jMenuItemUngroup.setText("Ungroup selected element(s)");
652         jMenuItemUngroup.setEnabled(false);
653         jMenuItemUngroup.addActionListener(new java.awt.event.ActionListener JavaDoc() {
654             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
655                 jMenuItemUngroupActionPerformed(evt);
656             }
657         });
658
659         jPopupMenuElement.add(jMenuItemUngroup);
660
661         jPopupMenuElement.add(jSeparator6);
662
663         jMenuItemCopyStyle.setEnabled(false);
664         jMenuItemCopyStyle.setLabel("Copy style");
665         jMenuItemCopyStyle.addActionListener(new java.awt.event.ActionListener JavaDoc() {
666             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
667                 jMenuItemCopyStyleActionPerformed(evt);
668             }
669         });
670
671         jPopupMenuElement.add(jMenuItemCopyStyle);
672
673         jMenuItemPasteStyle.setEnabled(false);
674         jMenuItemPasteStyle.setLabel("Paste style");
675         jMenuItemPasteStyle.addActionListener(new java.awt.event.ActionListener JavaDoc() {
676             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
677                 jMenuItemPasteStyleActionPerformed(evt);
678             }
679         });
680
681         jPopupMenuElement.add(jMenuItemPasteStyle);
682
683         jMenuItemTransformStaticText.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F3, 0));
684         jMenuItemTransformStaticText.setLabel("Transform in Textfield");
685         jMenuItemTransformStaticText.addActionListener(new java.awt.event.ActionListener JavaDoc() {
686             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
687                 jMenuItemTransformStaticTextActionPerformed(evt);
688             }
689         });
690
691         jPopupMenuElement.add(jMenuItemTransformStaticText);
692
693         jMenuItemPattern.setText("Field pattern");
694         jMenuItemPattern.addActionListener(new java.awt.event.ActionListener JavaDoc() {
695             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
696                 jMenuItemPatternActionPerformed(evt);
697             }
698         });
699
700         jPopupMenuElement.add(jMenuItemPattern);
701
702         jPopupMenuElement.add(jSeparator4);
703
704         try {
705             setSelected(true);
706         } catch (java.beans.PropertyVetoException JavaDoc e1) {
707             e1.printStackTrace();
708         }
709         addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
710             public void keyPressed(java.awt.event.KeyEvent JavaDoc evt) {
711                 formKeyPressed(evt);
712             }
713         });
714
715         jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener JavaDoc() {
716             public void stateChanged(javax.swing.event.ChangeEvent JavaDoc evt) {
717                 jTabbedPane1StateChanged(evt);
718             }
719         });
720
721         jPanelSuperContainer.setLayout(new java.awt.BorderLayout JavaDoc());
722
723         jPanelReportContainer.setLayout(new java.awt.BorderLayout JavaDoc());
724
725         jPanelVRule.setLayout(new java.awt.BorderLayout JavaDoc());
726
727         jPanelVRule.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
728         jPanelVRule.setMaximumSize(new java.awt.Dimension JavaDoc(16, 32000));
729         jPanelVRule.setMinimumSize(new java.awt.Dimension JavaDoc(16, 16));
730         jPanelVRule.setPreferredSize(new java.awt.Dimension JavaDoc(16, 32767));
731         jPanelReportContainer.add(jPanelVRule, java.awt.BorderLayout.WEST);
732
733         jPanelHContainerRule.setLayout(new java.awt.BorderLayout JavaDoc());
734
735         jPanelHContainerRule.setBackground(new java.awt.Color JavaDoc(255, 255, 255));
736         jPanelHContainerRule.setMaximumSize(new java.awt.Dimension JavaDoc(32767, 16));
737         jPanelHContainerRule.setMinimumSize(new java.awt.Dimension JavaDoc(16, 16));
738         jPanelHContainerRule.setPreferredSize(new java.awt.Dimension JavaDoc(32767, 16));
739         jPanelCorner.setLayout(null);
740
741         jPanelCorner.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
742         jPanelCorner.setMaximumSize(new java.awt.Dimension JavaDoc(16, 16));
743         jPanelCorner.setMinimumSize(new java.awt.Dimension JavaDoc(16, 16));
744         jPanelCorner.setPreferredSize(new java.awt.Dimension JavaDoc(16, 16));
745         jPanelHContainerRule.add(jPanelCorner, java.awt.BorderLayout.WEST);
746
747         jPanelHContainerRule.add(jHorizontalRule, java.awt.BorderLayout.CENTER);
748
749         jPanelReportContainer.add(jPanelHContainerRule, java.awt.BorderLayout.NORTH);
750
751         jPanelReport.setLayout(null);
752
753         jPanelReport.setToolTipText("");
754         jPanelReport.addComponentListener(new java.awt.event.ComponentAdapter JavaDoc() {
755             public void componentResized(java.awt.event.ComponentEvent JavaDoc evt) {
756                 jPanelReportComponentResized(evt);
757             }
758         });
759         jPanelReport.addMouseMotionListener(new java.awt.event.MouseMotionAdapter JavaDoc() {
760             public void mouseDragged(java.awt.event.MouseEvent JavaDoc evt) {
761                 jPanelReportMouseDragged(evt);
762             }
763             public void mouseMoved(java.awt.event.MouseEvent JavaDoc evt) {
764                 jPanelReportMouseMoved(evt);
765             }
766         });
767         jPanelReport.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
768             public void keyPressed(java.awt.event.KeyEvent JavaDoc evt) {
769                 jPanelReportKeyPressed(evt);
770             }
771         });
772         jPanelReport.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
773             public void mousePressed(java.awt.event.MouseEvent JavaDoc evt) {
774                 jPanelReportMousePressed(evt);
775             }
776             public void mouseReleased(java.awt.event.MouseEvent JavaDoc evt) {
777                 jPanelReportMouseReleased(evt);
778             }
779         });
780         jPanelReport.addAncestorListener(new javax.swing.event.AncestorListener JavaDoc() {
781             public void ancestorMoved(javax.swing.event.AncestorEvent JavaDoc evt) {
782             }
783             public void ancestorAdded(javax.swing.event.AncestorEvent JavaDoc evt) {
784                 jPanelReportAncestorAdded(evt);
785             }
786             public void ancestorRemoved(javax.swing.event.AncestorEvent JavaDoc evt) {
787             }
788         });
789         jPanelReport.addMouseWheelListener(new java.awt.event.MouseWheelListener JavaDoc() {
790             public void mouseWheelMoved(java.awt.event.MouseWheelEvent JavaDoc evt) {
791                 jPanelReportMouseWheelMoved(evt);
792             }
793         });
794
795         jPanelReportContainer.add(jPanelReport, java.awt.BorderLayout.CENTER);
796
797         jPanelSuperContainer.add(jPanelReportContainer, java.awt.BorderLayout.CENTER);
798
799         jVerticalScrollBar.setMaximum(0);
800         jVerticalScrollBar.addKeyListener(new java.awt.event.KeyAdapter JavaDoc() {
801             public void keyPressed(java.awt.event.KeyEvent JavaDoc evt) {
802                 jVerticalScrollBarKeyPressed(evt);
803             }
804         });
805         jVerticalScrollBar.addMouseListener(new java.awt.event.MouseAdapter JavaDoc() {
806             public void mouseReleased(java.awt.event.MouseEvent JavaDoc evt) {
807                 jVerticalScrollBarMouseReleased(evt);
808             }
809         });
810         jVerticalScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener JavaDoc() {
811             public void adjustmentValueChanged(java.awt.event.AdjustmentEvent JavaDoc evt) {
812                 jVerticalScrollBarAdjustmentValueChanged(evt);
813             }
814         });
815         jVerticalScrollBar.addMouseWheelListener(new java.awt.event.MouseWheelListener JavaDoc() {
816             public void mouseWheelMoved(java.awt.event.MouseWheelEvent JavaDoc evt) {
817                 jVerticalScrollBarMouseWheelMoved(evt);
818             }
819         });
820
821         jPanelSuperContainer.add(jVerticalScrollBar, java.awt.BorderLayout.EAST);
822
823         jPanelHScroll.setLayout(new java.awt.BorderLayout JavaDoc());
824
825         jHorizontalScrollBar.setMaximum(0);
826         jHorizontalScrollBar.setOrientation(javax.swing.JScrollBar.HORIZONTAL);
827         jHorizontalScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener JavaDoc() {
828             public void adjustmentValueChanged(java.awt.event.AdjustmentEvent JavaDoc evt) {
829                 jHorizontalScrollBarAdjustmentValueChanged(evt);
830             }
831         });
832
833         jPanelHScroll.add(jHorizontalScrollBar, java.awt.BorderLayout.CENTER);
834
835         jPanel1.setMaximumSize(new java.awt.Dimension JavaDoc(17, 17));
836         jPanel1.setMinimumSize(new java.awt.Dimension JavaDoc(17, 17));
837         jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(17, 17));
838         jPanelHScroll.add(jPanel1, java.awt.BorderLayout.EAST);
839
840         jPanelSuperContainer.add(jPanelHScroll, java.awt.BorderLayout.SOUTH);
841
842         jTabbedPane1.addTab("Main report", new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/mainreport.png")), jPanelSuperContainer);
843
844         getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);
845
846         pack();
847     }// </editor-fold>//GEN-END:initComponents
848

849     private void jPanelReportMouseWheelMoved(java.awt.event.MouseWheelEvent JavaDoc evt) {//GEN-FIRST:event_jPanelReportMouseWheelMoved
850
jVerticalScrollBarMouseWheelMoved(evt);
851     }//GEN-LAST:event_jPanelReportMouseWheelMoved
852

853     private void jVerticalScrollBarMouseWheelMoved(java.awt.event.MouseWheelEvent JavaDoc evt) {//GEN-FIRST:event_jVerticalScrollBarMouseWheelMoved
854

855        int notches = evt.getWheelRotation();
856
857        jVerticalScrollBar.setValue( jVerticalScrollBar.getValue() + ( notches * 30 ) );
858
859     }//GEN-LAST:event_jVerticalScrollBarMouseWheelMoved
860

861     private void jMenuItemBandPropertiesActionPerformed1(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemBandPropertiesActionPerformed1
862
jMenuItemBandPropertiesActionPerformed(evt);
863     }//GEN-LAST:event_jMenuItemBandPropertiesActionPerformed1
864

865     private void jMenuItemElementOpenSubreportActionPerformed1(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemElementOpenSubreportActionPerformed1
866

867         if (getSelectedElements().size() > 0)
868         {
869             ReportElement re = (ReportElement)getSelectedElements().elementAt(0);
870
871             //System.out.println(re);
872

873             if (re instanceof SubReportElement)
874             {
875                 SubReportElement sre = (SubReportElement)re;
876
877                 String JavaDoc subreportExp = sre.getSubreportExpression();
878                 String JavaDoc subreportExpClass = sre.getSubreportExpressionClass();
879
880                 if (subreportExpClass.equals("java.lang.String"))
881                 {
882                     try {
883                         Interpreter interpreter = prepareExpressionEvaluator();
884
885                         subreportExp = ""+ReportQueryDialog.recursiveInterpreter( interpreter, subreportExp, getReport().getParameters());
886
887
888                         if (subreportExp != null)
889                             {
890                                 String JavaDoc fileName = subreportExp+"";
891                                 
892                                 //fileName = Misc.string_replace("/","//",fileName);
893

894                                 if (fileName.toLowerCase().endsWith(".jasper"))
895                                 {
896                                    java.util.List JavaDoc possibleSourceFiles = new java.util.ArrayList JavaDoc();
897
898                                     possibleSourceFiles.add(fileName.substring(0, fileName.length() - 7) + ".jrxml");
899                                     possibleSourceFiles.add(fileName.substring(0, fileName.length() - 7) + ".xml");
900                                     
901                                     // Look in the same directory as this file...
902
File JavaDoc f = new File JavaDoc(fileName);
903                                     String JavaDoc fname = f.getName();
904                                     if (fname.length() > 7 && getReport().getFilename() != null && getReport().getFilename().length() > 0)
905                                     {
906                                         f = new File JavaDoc( getReport().getFilename());
907                                         possibleSourceFiles.add( f.getParent() + File.separator + fname.substring(0, fname.length() - 7) + ".jrxml");
908                                         possibleSourceFiles.add( f.getParent() + File.separator + fname.substring(0, fname.length() - 7) + ".xml");
909                                     }
910                                     
911                                     f = getFirstValidFile(possibleSourceFiles);
912                                     
913                                     if (f == null)
914                                     {
915                                         String JavaDoc message = "No one of the following possible source files for this subreport were found:\n\n";
916                                         for (int i=0; i<possibleSourceFiles.size(); ++i)
917                                         {
918                                             message += possibleSourceFiles.get(i)+"\n";
919                                         }
920                                         
921                                         throw new Exception JavaDoc(message);
922                                     }
923                                     
924                                     JReportFrame rf = MainFrame.getMainInstance().openFile(f);
925                                     rf.setSelected(true);
926                                 }
927
928                             }
929
930                     } catch (Exception JavaDoc ex)
931                     {
932                         JOptionPane.showMessageDialog(this,
933                                 I18n.getFormattedString( "messages.jReportFrame.errorOpeningSubreport","I have got a problem finding the subreport:\n{0}", new Object JavaDoc[]{ ex.getMessage()}) );
934                     }
935                 }
936             }
937
938         }
939     }//GEN-LAST:event_jMenuItemElementOpenSubreportActionPerformed1
940

941     private File JavaDoc getFirstValidFile(java.util.List JavaDoc list)
942     {
943         for (int i=0; i<list.size(); ++i)
944         {
945             String JavaDoc fileName = list.get(i)+"";
946             File JavaDoc f = new File JavaDoc(fileName);
947             
948             if (!f.exists())
949             {
950                 ReportClassLoader rcl = MainFrame.getMainInstance().getReportClassLoader();
951                 if (this.getReport().getFilename() != null)
952                 {
953                     File JavaDoc rfn = new File JavaDoc( this.getReport().getFilename() );
954                     rcl.addNoRelodablePath( rfn.getParent() );
955                 }
956                 try {
957                     URL JavaDoc url = rcl.getResource(fileName);
958
959                     if (url != null)
960                     {
961                         f = new File JavaDoc(url.getPath());
962                         if (!f.exists())
963                         {
964                             continue;
965                         }
966                     }
967                     else
968                     {
969                         continue;
970                     }
971                 } catch (Exception JavaDoc ex)
972                 {
973                     continue;
974                 }
975            }
976             
977            
978            return f;
979         }
980         
981         return null;
982     }
983     
984     private Interpreter prepareExpressionEvaluator() throws bsh.EvalError {
985         Interpreter interpreter = new Interpreter();
986         interpreter.setClassLoader(interpreter.getClass().getClassLoader());
987         return interpreter;
988
989         // return null;
990
}
991
992     private void jMenuItemElementCrosstabPropertiesActionPerformed1(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemElementCrosstabPropertiesActionPerformed1
993

994
995          if (getSelectedElements().size() > 0)
996         {
997             ReportElement re = (ReportElement)getSelectedElements().elementAt(0);
998
999             if (re instanceof CrosstabReportElement )
1000            {
1001                try {
1002                    jTabbedPane1.setSelectedComponent( getCrosstabEditor((CrosstabReportElement)re) );
1003                } catch (Exception JavaDoc ex){}
1004            }
1005        }
1006
1007    }//GEN-LAST:event_jMenuItemElementCrosstabPropertiesActionPerformed1
1008

1009    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent JavaDoc evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
1010

1011
1012
1013        //We have to check if the current panel is the first one or not...
1014
if (jTabbedPane1 == null || !jTabbedPane1.isVisible() || jTabbedPane1.getSelectedIndex() == 0)
1015        {
1016            MainFrame.getMainInstance().setCrosstabActive(null);
1017            MainFrame.getMainInstance().setComboBoxZoomFactor( this.zoomFactor * 100 );
1018        }
1019        else
1020        {
1021            MainFrame.getMainInstance().setCrosstabActive(getSelectedCrosstabEditorPanel().getCrosstabElement());
1022            MainFrame.getMainInstance().setComboBoxZoomFactor( this.getSelectedCrosstabEditorPanel().getZoomFactor() * 100 );
1023        }
1024
1025        MainFrame.getMainInstance().getElementPropertiesDialog().updateSelection();
1026        try {
1027            MainFrame.getMainInstance().updateCutAndPasteMenu(this);
1028        } catch (Exception JavaDoc ex)
1029        {
1030            ex.printStackTrace();
1031        }
1032
1033
1034    }//GEN-LAST:event_jTabbedPane1StateChanged
1035

1036    private void jMenuItemElementCrosstabPropertiesActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemElementCrosstabPropertiesActionPerformed
1037
if (getSelectedElements().size() > 0)
1038        {
1039            ReportElement re = (ReportElement)getSelectedElements().elementAt(0);
1040
1041            if (re instanceof CrosstabReportElement )
1042            {
1043                    it.businesslogic.ireport.crosstab.gui.CrosstabPropertiesDialog cpd = new it.businesslogic.ireport.crosstab.gui.CrosstabPropertiesDialog(getMainFrame(),true);
1044                    cpd.setCurrentCrosstabReportElement( (CrosstabReportElement)re);
1045                    cpd.setVisible(true);
1046            }
1047        }
1048    }//GEN-LAST:event_jMenuItemElementCrosstabPropertiesActionPerformed
1049

1050    private void jMenuItemUngroupActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemUngroupActionPerformed
1051
ungroupSelectedElements();
1052    }//GEN-LAST:event_jMenuItemUngroupActionPerformed
1053

1054    private void jMenuItemGroupActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemGroupActionPerformed
1055
groupSelectedElements();
1056    }//GEN-LAST:event_jMenuItemGroupActionPerformed
1057

1058    public boolean groupSelectedElements()
1059    {
1060        if (getSelectedElements().size() == 0) return false;
1061        boolean sameBand = true;
1062        Band theBand = null;
1063        Enumeration selectedElementEnum = getSelectedElements().elements();
1064
1065        while (selectedElementEnum.hasMoreElements())
1066        {
1067                ReportElement re = (ReportElement)selectedElementEnum.nextElement();
1068                if (theBand == null) theBand = re.getBand();
1069                else if (sameBand && theBand != re.getBand()) sameBand = false;
1070
1071                if (!sameBand) return false;
1072        }
1073
1074        selectedElementEnum = getSelectedElements().elements();
1075        String JavaDoc newGroup = getReport().createChildGroup("");
1076
1077        while (selectedElementEnum.hasMoreElements())
1078        {
1079                ReportElement re = (ReportElement)selectedElementEnum.nextElement();
1080                String JavaDoc oldGroup = re.getElementGroup();
1081                if (oldGroup.length() > 0) oldGroup = "." + oldGroup;
1082                re.setElementGroup(newGroup + oldGroup);
1083        }
1084
1085
1086        GroupEmentsOperation undoOp = new GroupEmentsOperation(this);
1087        undoOp.setAddedGroup(newGroup);
1088
1089        PositionedElement[] newPositionedElements = new PositionedElement[this.getSelectedElements().size()];
1090
1091        for (int i=0; i<this.getSelectedElements().size(); ++i)
1092        {
1093                ReportElement element = (ReportElement)getSelectedElements().elementAt(i);
1094                int oldPosition = getReport().getElements().indexOf(element);
1095                newPositionedElements[i] = new PositionedElement(element,oldPosition,oldPosition);
1096        }
1097
1098        // Reorder
1099
for (int i=0; i<this.getSelectedElements().size(); ++i)
1100        {
1101                ReportElement element = (ReportElement)getSelectedElements().elementAt(i);
1102                int newPosition = getReport().getElements().indexOf(element);
1103                undoOp.addElement(newPositionedElements[i].getElement(),newPositionedElements[i].getOldPosition() , newPosition);
1104        }
1105
1106        addUndoOperation(undoOp);
1107        getReportPanel().repaint();
1108        fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, new Vector() , ReportElementChangedEvent.REMOVED ));
1109        return true;
1110
1111      }
1112
1113
1114    public boolean ungroupSelectedElements()
1115    {
1116        if (getSelectedElements().size() == 0) return false;
1117        boolean sameBand = true;
1118        Band theBand = null;
1119        Enumeration selectedElementEnum = getSelectedElements().elements();
1120
1121        while (selectedElementEnum.hasMoreElements())
1122        {
1123                ReportElement re = (ReportElement)selectedElementEnum.nextElement();
1124                if (theBand == null) theBand = re.getBand();
1125                else if (sameBand && theBand != re.getBand()) sameBand = false;
1126
1127                if (!sameBand) return false;
1128        }
1129
1130        selectedElementEnum = getSelectedElements().elements();
1131
1132        UnGroupEmentsOperation undoOp = new UnGroupEmentsOperation(this);
1133
1134        GroupPositionedElement[] newPositionedElements = new GroupPositionedElement[this.getSelectedElements().size()];
1135
1136        for (int i=0; i<this.getSelectedElements().size(); ++i)
1137        {
1138                ReportElement element = (ReportElement)getSelectedElements().elementAt(i);
1139                String JavaDoc oldGroup = element.getElementGroup();
1140                String JavaDoc newGroup = oldGroup;
1141                if (newGroup.lastIndexOf(".")>=0)
1142                {
1143                    newGroup = newGroup.substring(0,newGroup.lastIndexOf("."));
1144                }
1145                else
1146                {
1147                    newGroup = "";
1148                }
1149                element.setElementGroup(newGroup);
1150                int oldPosition = getReport().getElements().indexOf(element);
1151                newPositionedElements[i] = new GroupPositionedElement(element,oldPosition,oldPosition, oldGroup,newGroup);
1152        }
1153
1154        // Reorder
1155
for (int i=0; i<this.getSelectedElements().size(); ++i)
1156        {
1157                ReportElement element = (ReportElement)getSelectedElements().elementAt(i);
1158                int newPosition = getReport().getElements().indexOf(element);
1159                undoOp.addElement(newPositionedElements[i].getElement(),newPositionedElements[i].getOldPosition() , newPosition, newPositionedElements[i].getOldElementGroup(), newPositionedElements[i].getNewElementGroup());
1160        }
1161
1162        addUndoOperation(undoOp);
1163        getReportPanel().repaint();
1164        fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, new Vector() , ReportElementChangedEvent.REMOVED ));
1165        return true;
1166
1167      }
1168
1169    private void jMenuItemElementChartPropertiesActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemElementChartPropertiesActionPerformed
1170

1171        if (getSelectedElements().size() > 0)
1172        {
1173            ReportElement re = (ReportElement)getSelectedElements().elementAt(0);
1174
1175            if (re instanceof ChartReportElement2 )
1176            {
1177                    it.businesslogic.ireport.chart.gui.ChartPropertiesDialog cpd = new it.businesslogic.ireport.chart.gui.ChartPropertiesDialog(getMainFrame(),true);
1178                    cpd.setChartElement( (ChartReportElement2)re);
1179                    cpd.setVisible(true);
1180            }
1181        }
1182
1183
1184    }//GEN-LAST:event_jMenuItemElementChartPropertiesActionPerformed
1185

1186    private void jMenuItemPatternActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemPatternActionPerformed
1187

1188        String JavaDoc pattern = "";
1189        FieldPatternDialog pd = new FieldPatternDialog( MainFrame.getMainInstance() ,true);
1190        pd.setVisible(true);
1191        if (pd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION ) {
1192
1193
1194            Enumeration selectedElementEnum = getSelectedElements().elements();
1195
1196            while (selectedElementEnum.hasMoreElements()) {
1197                ReportElement re = (ReportElement)selectedElementEnum.nextElement();
1198                if (re instanceof TextFieldReportElement) {
1199                    ((TextFieldReportElement)re).setPattern( pd.getPattern() );
1200                }
1201            }
1202        }
1203
1204
1205    }//GEN-LAST:event_jMenuItemPatternActionPerformed
1206

1207    private void jMenuItemPasteStyleActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemPasteStyleActionPerformed
1208

1209        pasteStyle();
1210
1211    }//GEN-LAST:event_jMenuItemPasteStyleActionPerformed
1212

1213    private void jMenuItemCopyStyleActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemCopyStyleActionPerformed
1214

1215        copyStyle();
1216
1217    }//GEN-LAST:event_jMenuItemCopyStyleActionPerformed
1218

1219    private void jMenuItemTransformStaticTextActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemTransformStaticTextActionPerformed
1220
transformStaticInTextFields();
1221    }//GEN-LAST:event_jMenuItemTransformStaticTextActionPerformed
1222

1223    private void jMenuItemDeleteActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemDeleteActionPerformed
1224
// Remove selected elements...
1225
this.deleteSelectedElements();
1226    }//GEN-LAST:event_jMenuItemDeleteActionPerformed
1227

1228    public void delete()
1229    {
1230        if (getSelectedCrosstabEditorPanel() != null)
1231        {
1232            getSelectedCrosstabEditorPanel().deleteSelectedElements();
1233        }
1234        else
1235        {
1236            this.deleteSelectedElements();
1237        }
1238    }
1239
1240    private void jMenuItemPasteActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemPasteActionPerformed
1241
paste();
1242    }//GEN-LAST:event_jMenuItemPasteActionPerformed
1243

1244    private void jMenuItemCopyActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemCopyActionPerformed
1245
copy();
1246    }//GEN-LAST:event_jMenuItemCopyActionPerformed
1247

1248    private void jMenuItemCutActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemCutActionPerformed
1249
cut();
1250    }//GEN-LAST:event_jMenuItemCutActionPerformed
1251

1252    private void jMenuItemBandPropertiesActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemBandPropertiesActionPerformed
1253

1254        if ( popup_opened_at != null ) {
1255
1256            // We must find the right band...
1257
int y = getLogicalDim( popup_opened_at.y - 10 + jVerticalScrollBar.getValue() ) + 10;
1258            Band myBand = getReport().getBandByPosition( y );
1259
1260            if ( myBand != null ) {
1261                getMainFrame().jMenuItemBandsActionPerformed( evt );
1262                getMainFrame().getBandsDialog().setSelectedBand( myBand.getName() );
1263            }
1264
1265        }
1266    }//GEN-LAST:event_jMenuItemBandPropertiesActionPerformed
1267

1268    private void addFormatItemsToMenu(javax.swing.JComponent JavaDoc m){
1269
1270        jMenuAlign = new javax.swing.JMenu JavaDoc();
1271        jMenuAlign.setText(it.businesslogic.ireport.util.I18n.getString("align", "Align..."));
1272        jMenuItemAlignLeft = new javax.swing.JMenuItem JavaDoc();
1273        jMenuItemAlignLeft.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_align_left.png")));
1274        jMenuItemAlignLeft.setText(it.businesslogic.ireport.util.I18n.getString("alignLeft", "Align left"));
1275        jMenuItemAlignLeft.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1276            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1277                getMainFrame().jMenuItemAlignLeftActionPerformed(evt);
1278            }
1279        });
1280
1281        jMenuAlign.add(jMenuItemAlignLeft);
1282
1283        jMenuItemAlignRight = new javax.swing.JMenuItem JavaDoc();
1284        jMenuItemAlignRight.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_align_right.png")));
1285        jMenuItemAlignRight.setText(it.businesslogic.ireport.util.I18n.getString("alignRight", "Align right"));
1286        jMenuItemAlignRight.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1287            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1288                getMainFrame().jMenuItemAlignRightActionPerformed(evt);
1289            }
1290        });
1291
1292        jMenuAlign.add(jMenuItemAlignRight);
1293
1294        jMenuItemAlignTop = new javax.swing.JMenuItem JavaDoc();
1295        jMenuItemAlignTop.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_align_top.png")));
1296        jMenuItemAlignTop.setText(it.businesslogic.ireport.util.I18n.getString("alignTop", "Align top"));
1297        jMenuItemAlignTop.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1298            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1299                getMainFrame().jMenuItemAlignTopActionPerformed(evt);
1300            }
1301        });
1302
1303        jMenuAlign.add(jMenuItemAlignTop);
1304
1305        jMenuItemAlignBottom = new javax.swing.JMenuItem JavaDoc();
1306        jMenuItemAlignBottom.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_align_bottom.png")));
1307        jMenuItemAlignBottom.setText(it.businesslogic.ireport.util.I18n.getString("alignBottom", "Align bottom"));
1308        jMenuItemAlignBottom.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1309            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1310                getMainFrame().jMenuItemAlignBottomActionPerformed(evt);
1311            }
1312        });
1313
1314        jMenuAlign.add(jMenuItemAlignBottom);
1315
1316        jSeparator19 = new javax.swing.JSeparator JavaDoc();
1317        jMenuAlign.add(jSeparator19);
1318
1319        jMenuItemAlignVerticalAxis = new javax.swing.JMenuItem JavaDoc();
1320        jMenuItemAlignVerticalAxis.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_center_axis.png")));
1321        jMenuItemAlignVerticalAxis.setText(it.businesslogic.ireport.util.I18n.getString("alignVerticalAxis", "Align vertical axis"));
1322        jMenuItemAlignVerticalAxis.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1323            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1324                getMainFrame().jMenuItemAlignVerticalAxisActionPerformed(evt);
1325            }
1326        });
1327
1328        jMenuAlign.add(jMenuItemAlignVerticalAxis);
1329
1330        jMenuItemAlignHorizontalAxis = new javax.swing.JMenuItem JavaDoc();
1331        jMenuItemAlignHorizontalAxis.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_vcenter_axis.png")));
1332        jMenuItemAlignHorizontalAxis.setText(it.businesslogic.ireport.util.I18n.getString("alignHorizontalAxis", "Align horizontal axis"));
1333        jMenuItemAlignHorizontalAxis.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1334            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1335                getMainFrame().jMenuItemAlignHorizontalAxisActionPerformed(evt);
1336            }
1337        });
1338
1339        jMenuAlign.add(jMenuItemAlignHorizontalAxis);
1340
1341        jSeparator20 = new javax.swing.JSeparator JavaDoc();
1342        jMenuAlign.add(jSeparator20);
1343
1344        jMenuItemAlignToBandTop = new javax.swing.JMenuItem JavaDoc();
1345        jMenuItemAlignToBandTop.setText(it.businesslogic.ireport.util.I18n.getString("alignToBandTop", "Align to band top"));
1346        jMenuItemAlignToBandTop.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1347            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1348                getMainFrame().jMenuItemAlignToBandTopActionPerformed(evt);
1349            }
1350        });
1351
1352        jMenuAlign.add(jMenuItemAlignToBandTop);
1353
1354        jMenuItemAlignToBandBottom = new javax.swing.JMenuItem JavaDoc();
1355        jMenuItemAlignToBandBottom.setText(it.businesslogic.ireport.util.I18n.getString("alignToBandBottom", "Align to band bottom"));
1356        jMenuItemAlignToBandBottom.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1357            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1358                getMainFrame().jMenuItemAlignToBandBottomActionPerformed(evt);
1359            }
1360        });
1361
1362        jMenuAlign.add(jMenuItemAlignToBandBottom);
1363
1364        m.add(jMenuAlign);
1365
1366        jMenuSize = new javax.swing.JMenu JavaDoc();
1367        jMenuSize.setText(it.businesslogic.ireport.util.I18n.getString("size", "Size..."));
1368        jMenuItemSameWidth = new javax.swing.JMenuItem JavaDoc();
1369        jMenuItemSameWidth.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_same_hsize.png")));
1370        jMenuItemSameWidth.setText(it.businesslogic.ireport.util.I18n.getString("sameWidth", "Same width"));
1371        jMenuItemSameWidth.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1372            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1373                getMainFrame().jMenuItemSameWidthActionPerformed(evt);
1374            }
1375        });
1376
1377        jMenuSize.add(jMenuItemSameWidth);
1378
1379        jMenuItemSameWidthMax = new javax.swing.JMenuItem JavaDoc();
1380        jMenuItemSameWidthMax.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_same_hsize_plus.png")));
1381        jMenuItemSameWidthMax.setText(it.businesslogic.ireport.util.I18n.getString("sameWidthMax", "Same width (max)"));
1382        jMenuItemSameWidthMax.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1383            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1384                getMainFrame().jMenuItemSameWidthMaxActionPerformed(evt);
1385            }
1386        });
1387
1388        jMenuSize.add(jMenuItemSameWidthMax);
1389
1390        jMenuItemSameWidthMin = new javax.swing.JMenuItem JavaDoc();
1391        jMenuItemSameWidthMin.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_same_hsize_min.png")));
1392        jMenuItemSameWidthMin.setText(it.businesslogic.ireport.util.I18n.getString("sameWidthMin", "Same width (min)"));
1393        jMenuItemSameWidthMin.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1394            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1395                getMainFrame().jMenuItemSameWidthMinActionPerformed(evt);
1396            }
1397        });
1398
1399        jMenuSize.add(jMenuItemSameWidthMin);
1400
1401        jSeparator17 = new javax.swing.JSeparator JavaDoc();
1402        jMenuSize.add(jSeparator17);
1403
1404        jMenuItemSameHeight = new javax.swing.JMenuItem JavaDoc();
1405        jMenuItemSameHeight.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_same_vsize.png")));
1406        jMenuItemSameHeight.setText(it.businesslogic.ireport.util.I18n.getString("sameHeight", "Same height"));
1407        jMenuItemSameHeight.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1408            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1409                getMainFrame().jMenuItemSameHeightActionPerformed(evt);
1410            }
1411        });
1412
1413        jMenuSize.add(jMenuItemSameHeight);
1414
1415        jMenuItemSameHeightMin = new javax.swing.JMenuItem JavaDoc();
1416        jMenuItemSameHeightMin.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_same_vsize_min.png")));
1417        jMenuItemSameHeightMin.setText(it.businesslogic.ireport.util.I18n.getString("sameHeightMin", "Same height (min)"));
1418        jMenuItemSameHeightMin.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1419            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1420                getMainFrame().jMenuItemSameHeightMinActionPerformed(evt);
1421            }
1422        });
1423
1424        jMenuSize.add(jMenuItemSameHeightMin);
1425
1426        jMenuItemSameHeightMax = new javax.swing.JMenuItem JavaDoc();
1427        jMenuItemSameHeightMax.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_same_vsize_plus.png")));
1428        jMenuItemSameHeightMax.setText(it.businesslogic.ireport.util.I18n.getString("sameHeightMax", "Same height (max)"));
1429        jMenuItemSameHeightMax.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1430            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1431                getMainFrame().jMenuItemSameHeightMaxActionPerformed(evt);
1432            }
1433        });
1434
1435        jMenuSize.add(jMenuItemSameHeightMax);
1436
1437        jSeparator18 = new javax.swing.JSeparator JavaDoc();
1438        jMenuSize.add(jSeparator18);
1439
1440        jMenuItemSameSize = new javax.swing.JMenuItem JavaDoc();
1441        jMenuItemSameSize.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_same_size.png")));
1442        jMenuItemSameSize.setText(it.businesslogic.ireport.util.I18n.getString("sameSize", "Same size"));
1443        jMenuItemSameSize.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1444            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1445                getMainFrame().jMenuItemSameSizeActionPerformed(evt);
1446            }
1447        });
1448
1449        jMenuSize.add(jMenuItemSameSize);
1450
1451        m.add(jMenuSize);
1452
1453        jMenuPosition = new javax.swing.JMenu JavaDoc();
1454        jMenuPosition.setText(it.businesslogic.ireport.util.I18n.getString("position", "Position..."));
1455        jMenuItemCenterH = new javax.swing.JMenuItem JavaDoc();
1456        jMenuItemCenterH.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_hcenter.png")));
1457        jMenuItemCenterH.setText(it.businesslogic.ireport.util.I18n.getString("centerHorizontallyBandBased", "Center horizontally (band based)"));
1458        jMenuItemCenterH.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1459            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1460                getMainFrame().jMenuItemCenterHActionPerformed(evt);
1461            }
1462        });
1463
1464        jMenuPosition.add(jMenuItemCenterH);
1465
1466        jMenuItemCenterV = new javax.swing.JMenuItem JavaDoc();
1467        jMenuItemCenterV.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_vcenter.png")));
1468        jMenuItemCenterV.setText(it.businesslogic.ireport.util.I18n.getString("centerVerticallyBandBased", "Center vertically (band based)"));
1469        jMenuItemCenterV.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1470            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1471                getMainFrame().jMenuItemCenterVActionPerformed(evt);
1472            }
1473        });
1474
1475        jMenuPosition.add(jMenuItemCenterV);
1476
1477        jMenuItemCenterInBand = new javax.swing.JMenuItem JavaDoc();
1478        jMenuItemCenterInBand.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_ccenter.png")));
1479        jMenuItemCenterInBand.setText(it.businesslogic.ireport.util.I18n.getString("centerInBand", "Center in band"));
1480        jMenuItemCenterInBand.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1481            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1482                getMainFrame().jMenuItemCenterInBandActionPerformed(evt);
1483            }
1484        });
1485
1486        jMenuPosition.add(jMenuItemCenterInBand);
1487
1488        jMenuItemCenterBackground = new javax.swing.JMenuItem JavaDoc();
1489        jMenuItemCenterBackground.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/elem_bcenter.png")));
1490        jMenuItemCenterBackground.setText(it.businesslogic.ireport.util.I18n.getString("centerInBackground", "Center in background"));
1491        jMenuItemCenterBackground.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1492            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1493                getMainFrame().jMenuItemCenterBackgroundActionPerformed(evt);
1494            }
1495        });
1496
1497        jMenuPosition.add(jMenuItemCenterBackground);
1498
1499        jMenuItemJoinLeft = new javax.swing.JMenuItem JavaDoc();
1500        jMenuItemJoinLeft.setText(it.businesslogic.ireport.util.I18n.getString("joinSidesLeft", "Join sides left"));
1501        jMenuItemJoinLeft.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1502            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1503                getMainFrame().jMenuItemJoinLeftActionPerformed(evt);
1504            }
1505        });
1506
1507        jMenuPosition.add(jMenuItemJoinLeft);
1508
1509        jMenuItemJoinRight = new javax.swing.JMenuItem JavaDoc();
1510        jMenuItemJoinRight.setText(it.businesslogic.ireport.util.I18n.getString("joinSidesRight", "Join sides right"));
1511        jMenuItemJoinRight.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1512            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1513                getMainFrame().jMenuItemJoinRightActionPerformed(evt);
1514            }
1515        });
1516
1517        jMenuPosition.add(jMenuItemJoinRight);
1518
1519        jMenuItemLeftMargin = new javax.swing.JMenuItem JavaDoc();
1520        jMenuItemLeftMargin.setText("Join left page margin");
1521        jMenuItemLeftMargin.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_HOME, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
1522        jMenuItemLeftMargin.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1523            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1524                getMainFrame().jMenuItemLeftMarginActionPerformed(evt);
1525            }
1526        });
1527
1528        jMenuPosition.add(jMenuItemLeftMargin);
1529
1530        jMenuItemRightMargin = new javax.swing.JMenuItem JavaDoc();
1531        jMenuItemRightMargin.setText("Join right page margin");
1532        jMenuItemRightMargin.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_END, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
1533        jMenuItemRightMargin.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1534            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1535                getMainFrame().jMenuItemRightMarginActionPerformed(evt);
1536            }
1537        });
1538
1539        jMenuPosition.add(jMenuItemRightMargin);
1540
1541        m.add(jMenuPosition);
1542
1543        jSeparator5 = new javax.swing.JSeparator JavaDoc();
1544        m.add(jSeparator5);
1545
1546        jMenuHSpacing = new javax.swing.JMenu JavaDoc();
1547        jMenuHSpacing.setText(it.businesslogic.ireport.util.I18n.getString("horizontalSpacing", "Horizontal spacing..."));
1548
1549        jMenuItemHSMakeEqual = new javax.swing.JMenuItem JavaDoc();
1550        jMenuItemHSMakeEqual.setText(it.businesslogic.ireport.util.I18n.getString("makeEqual", "Make equal"));
1551        jMenuItemHSMakeEqual.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1552            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1553                getMainFrame().jMenuItemHSMakeEqualActionPerformed(evt);
1554            }
1555        });
1556
1557        jMenuHSpacing.add(jMenuItemHSMakeEqual);
1558
1559        jMenuItemHSIncrease = new javax.swing.JMenuItem JavaDoc();
1560        jMenuItemHSIncrease.setText(it.businesslogic.ireport.util.I18n.getString("increase", "Increase"));
1561        jMenuItemHSIncrease.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1562            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1563                getMainFrame().jMenuItemHSIncreaseActionPerformed(evt);
1564            }
1565        });
1566
1567        jMenuHSpacing.add(jMenuItemHSIncrease);
1568
1569        jMenuItemHSDecrease = new javax.swing.JMenuItem JavaDoc();
1570        jMenuItemHSDecrease.setText(it.businesslogic.ireport.util.I18n.getString("decrease", "Decrease"));
1571        jMenuItemHSDecrease.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1572            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1573                getMainFrame().jMenuItemHSDecreaseActionPerformed(evt);
1574            }
1575        });
1576
1577        jMenuHSpacing.add(jMenuItemHSDecrease);
1578
1579        jMenuItemHSRemove = new javax.swing.JMenuItem JavaDoc();
1580        jMenuItemHSRemove.setText(it.businesslogic.ireport.util.I18n.getString("remove", "Remove"));
1581        jMenuItemHSRemove.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1582            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1583                getMainFrame().jMenuItemHSRemoveActionPerformed(evt);
1584            }
1585        });
1586
1587        jMenuHSpacing.add(jMenuItemHSRemove);
1588
1589        m.add(jMenuHSpacing);
1590
1591        jMenuVSpacing = new javax.swing.JMenu JavaDoc();
1592        jMenuVSpacing.setText(it.businesslogic.ireport.util.I18n.getString("verticalSpacing", "Vertical spacing"));
1593        jMenuItemVSMakeEqual = new javax.swing.JMenuItem JavaDoc();
1594        jMenuItemVSMakeEqual.setText(it.businesslogic.ireport.util.I18n.getString("makeEqual", "Make equal"));
1595        jMenuItemVSMakeEqual.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1596            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1597                getMainFrame().jMenuItemVSMakeEqualActionPerformed(evt);
1598            }
1599        });
1600
1601        jMenuVSpacing.add(jMenuItemVSMakeEqual);
1602
1603        jMenuItemVSIncrease = new javax.swing.JMenuItem JavaDoc();
1604        jMenuItemVSIncrease.setText(it.businesslogic.ireport.util.I18n.getString("increase", "Increase"));
1605        jMenuItemVSIncrease.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1606            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1607                getMainFrame().jMenuItemVSIncreaseActionPerformed(evt);
1608            }
1609        });
1610
1611        jMenuVSpacing.add(jMenuItemVSIncrease);
1612
1613        jMenuItemVSDecrease = new javax.swing.JMenuItem JavaDoc();
1614        jMenuItemVSDecrease.setText(it.businesslogic.ireport.util.I18n.getString("decrease", "Decrease"));
1615        jMenuItemVSDecrease.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1616            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1617                getMainFrame().jMenuItemVSDecreaseActionPerformed(evt);
1618            }
1619        });
1620
1621        jMenuVSpacing.add(jMenuItemVSDecrease);
1622
1623        jMenuItemVSRemove = new javax.swing.JMenuItem JavaDoc();
1624        jMenuItemVSRemove.setText(it.businesslogic.ireport.util.I18n.getString("remove", "Remove"));
1625        jMenuItemVSRemove.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1626            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1627                getMainFrame().jMenuItemVSRemoveActionPerformed(evt);
1628            }
1629        });
1630
1631        jMenuVSpacing.add(jMenuItemVSRemove);
1632
1633        m.add(jMenuVSpacing);
1634
1635        jSeparator8 = new javax.swing.JSeparator JavaDoc();
1636        m.add(jSeparator8);
1637
1638        jMenuItemOrganize = new javax.swing.JMenuItem JavaDoc();
1639        //Modified by Felix Firgau for I18n on Feb 9th 2006
1640
jMenuItemOrganize.setText(it.businesslogic.ireport.util.I18n.getString("organizeAsTable","Organize as table"));
1641        jMenuItemOrganize.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
1642        jMenuItemOrganize.setIcon(new javax.swing.ImageIcon JavaDoc(""));
1643        jMenuItemOrganize.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1644            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1645                getMainFrame().jMenuItemOrganizeActionPerformed(evt);
1646            }
1647        });
1648
1649        m.add(jMenuItemOrganize);
1650
1651        jMenuItemBringToFront = new javax.swing.JMenuItem JavaDoc();
1652        jMenuItemBringToFront.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/sendtofront.png")));
1653        jMenuItemBringToFront.setText(it.businesslogic.ireport.util.I18n.getString("bringToFront", "Bring to front"));
1654        jMenuItemBringToFront.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1655            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1656                getMainFrame().jMenuItemBringToFrontActionPerformed(evt);
1657            }
1658        });
1659
1660        m.add(jMenuItemBringToFront);
1661
1662        jMenuItemSendToBack = new javax.swing.JMenuItem JavaDoc();
1663        jMenuItemSendToBack.setIcon(new javax.swing.ImageIcon JavaDoc(getClass().getResource("/it/businesslogic/ireport/icons/menu/sendtoback.png")));
1664        jMenuItemSendToBack.setText(it.businesslogic.ireport.util.I18n.getString("sendToBack", "Send to back"));
1665        jMenuItemSendToBack.addActionListener(new java.awt.event.ActionListener JavaDoc() {
1666            public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
1667                getMainFrame().jMenuItemSendToBackActionPerformed(evt);
1668            }
1669        });
1670
1671        m.add(jMenuItemSendToBack);
1672
1673    }
1674    private void jMenuItemElementPropertiesActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemElementPropertiesActionPerformed
1675
openElementPropertiesDialog();
1676    }//GEN-LAST:event_jMenuItemElementPropertiesActionPerformed
1677

1678    private void jMenuItemPasteOnBandActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemPasteOnBandActionPerformed
1679

1680        if (this.popup_opened_at != null) {
1681            pasteHere( popup_opened_at );
1682        }
1683    }//GEN-LAST:event_jMenuItemPasteOnBandActionPerformed
1684

1685    private void jMenuItemPasteOnBandMouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemPasteOnBandMouseClicked
1686

1687    }//GEN-LAST:event_jMenuItemPasteOnBandMouseClicked
1688

1689    private void jMenuItemElementPropertiesMouseClicked(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jMenuItemElementPropertiesMouseClicked
1690

1691    }//GEN-LAST:event_jMenuItemElementPropertiesMouseClicked
1692

1693    private void jVerticalScrollBarKeyPressed(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jVerticalScrollBarKeyPressed
1694

1695    }//GEN-LAST:event_jVerticalScrollBarKeyPressed
1696

1697    private void formKeyPressed(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_formKeyPressed
1698

1699
1700    }//GEN-LAST:event_formKeyPressed
1701

1702    private void jPanelReportKeyPressed(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_jPanelReportKeyPressed
1703

1704        /*
1705        mf.logOnConsole(evt.getKeyCode() + " "+
1706        (((evt.getModifiers() & evt.CTRL_MASK) != 0 ) ? "CTL " : "") +
1707        (((evt.getModifiers() & evt.ALT_MASK) != 0 ) ? "ALT " : "") +
1708        (((evt.getModifiers() & evt.SHIFT_MASK) != 0 ) ? "SHIFT " : "") + "\n");
1709         */

1710        /*
1711        if (( evt.getModifiers() & evt.CTRL_MASK) != 0 &&
1712            evt.getKeyCode() == java.awt.event.KeyEvent.VK_Z )
1713        {
1714          .undo();
1715          return;
1716        }
1717
1718        if (( evt.getModifiers() & evt.CTRL_MASK ) != 0 &&
1719            evt.getKeyCode() == java.awt.event.KeyEvent.VK_Y)
1720        {
1721          mf.redo();
1722          return;
1723        }
1724         */

1725
1726        // Standard speed:
1727
int x=1, y=1;
1728
1729        // Increase the speed of movement if the Shift key is pressed
1730
if (( evt.getModifiers() & evt.SHIFT_MASK ) != 0) {
1731            x = 10;
1732            y = 10;
1733        }
1734
1735
1736        //if ((evt.getModifiers() & evt.ALT_MASK) != 0)
1737
// System.out.println("Tasto:"+evt.getKeyCode());
1738
if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_DELETE) {
1739            this.deleteSelectedElements();
1740            return;
1741        }
1742        /* Begin code Robert Lamping, 12 July 2004 */
1743        /* Short cut keys for quick alignment */
1744        else if ( (( evt.getModifiers() & evt.SHIFT_MASK) != 0) &&
1745                (( evt.getModifiers() & evt.CTRL_MASK) != 0) ) {
1746
1747            /* all key presses when SHIFT/CTRL are both pressed */
1748
1749            /* Short cuts for alignments */
1750            /* most of them deactivated, since they are activated bia the menu options and their
1751             * short cuts
1752             */

1753            switch ( evt.getKeyCode()) {
1754                case java.awt.event.KeyEvent.VK_S:
1755                    /* shrink A3-A4 */
1756                    FormatCommand.getCommand(OperationType.SHRINK).execute();
1757                    break;
1758
1759// case java.awt.event.KeyEvent.VK_UP:
1760
// /* align top */
1761
// FormatCommand.getCommand(OperationType.ALIGN_TOP).execute();
1762
// break;
1763
// case java.awt.event.KeyEvent.VK_DOWN:
1764
// /* align bottom */
1765
// FormatCommand.getCommand(OperationType.ALIGN_BOTTOM).execute();
1766
// break;
1767
// case java.awt.event.KeyEvent.VK_LEFT:
1768
// /* align left */
1769
// FormatCommand.getCommand(OperationType.ALIGN_LEFT).execute();
1770
// break;
1771
// case java.awt.event.KeyEvent.VK_RIGHT:
1772
// /* align right */
1773
// FormatCommand.getCommand(OperationType.ALIGN_RIGHT).execute();
1774
// break;
1775
// case java.awt.event.KeyEvent.VK_PAGE_UP:
1776
// /* align against band top */
1777
// FormatCommand.getCommand(OperationType.ALIGN_TOP_TO_BAND).execute();
1778
// break;
1779
// case java.awt.event.KeyEvent.VK_PAGE_DOWN:
1780
// /* align against band bottom */
1781
// FormatCommand.getCommand(OperationType.ALIGN_BOTTOM_TO_BAND).execute();
1782
// break;
1783
// case java.awt.event.KeyEvent.VK_HOME:
1784
// /* align against left margin */
1785
// FormatCommand.getCommand(OperationType.ALIGN_TO_LEFT_MARGIN).execute();
1786
// break;
1787
// case java.awt.event.KeyEvent.VK_END:
1788
// /* align against right margin */
1789
// FormatCommand.getCommand(OperationType.ALIGN_TO_RIGHT_MARGIN).execute();
1790
// break;
1791
// case java.awt.event.KeyEvent.VK_L:
1792
// /* join left */
1793
// FormatCommand.getCommand(OperationType.JOIN_LEFT).execute();
1794
// break;
1795
// case java.awt.event.KeyEvent.VK_R:
1796
// /* join right */
1797
// FormatCommand.getCommand(OperationType.JOIN_RIGHT).execute();
1798
// break;
1799
// case java.awt.event.KeyEvent.VK_O:
1800
// /* organize as a table, with spacing inbetwween */
1801
// FormatCommand.getCommand(OperationType.ORGANIZE_AS_A_TABLE).execute();
1802
//
1803
// break;
1804
}
1805
1806        }
1807        /* End code Robert Lamping, 12 July 2004 */
1808
1809        else if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_UP) {
1810            y *= -1;
1811            x = 0;
1812
1813            // Remove selected elements...
1814
// Up of x...
1815
Vector changed_elements = new Vector();
1816            for (Iterator i = selectedElements.iterator(); i.hasNext(); ) {
1817                ReportElement element = (ReportElement) i.next();
1818                element.trasform(new Point(x,y), TransformationType.TRANSFORMATION_MOVE);
1819                element.adjustBand();
1820                changed_elements.add(element);
1821            }
1822            fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, changed_elements , ReportElementChangedEvent.CHANGED));
1823
1824            this.getMainFrame().getElementPropertiesDialog().updateSelection();
1825            jPanelReport.repaint();
1826        } else if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_LEFT) {
1827            x *= -1;
1828            y = 0;
1829
1830            // Up of x...
1831
Vector changed_elements = new Vector();
1832            for (Iterator i = selectedElements.iterator(); i.hasNext(); ) {
1833                ReportElement element = (ReportElement) i.next();
1834                element.trasform(new Point(x,y), TransformationType.TRANSFORMATION_MOVE);
1835                element.adjustBand();
1836                changed_elements.add(element);
1837            }
1838            fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, changed_elements , ReportElementChangedEvent.CHANGED));
1839            this.getMainFrame().getElementPropertiesDialog().updateSelection();
1840            jPanelReport.repaint();
1841        } else if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_RIGHT) {
1842            y=0;
1843            // Remove selected elements...
1844
// Up of x...
1845
Vector changed_elements = new Vector();
1846            for (Iterator i = selectedElements.iterator(); i.hasNext(); ) {
1847                ReportElement element = (ReportElement) i.next();
1848                element.trasform(new Point(x,y), TransformationType.TRANSFORMATION_MOVE);
1849                element.adjustBand();
1850                changed_elements.add(element);
1851            }
1852            fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, changed_elements , ReportElementChangedEvent.CHANGED));
1853            this.getMainFrame().getElementPropertiesDialog().updateSelection();
1854
1855            jPanelReport.repaint();
1856        } else if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_DOWN) {
1857            x = 0;
1858            // Remove selected elements...
1859
// Up of x...
1860
Vector changed_elements = new Vector();
1861            for (Iterator i = selectedElements.iterator(); i.hasNext(); ) {
1862                ReportElement element = (ReportElement) i.next();
1863                element.trasform(new Point(x,y), TransformationType.TRANSFORMATION_MOVE);
1864                element.adjustBand();
1865                changed_elements.add(element);
1866            }
1867            fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, changed_elements , ReportElementChangedEvent.CHANGED));
1868            this.getMainFrame().getElementPropertiesDialog().updateSelection();
1869            jPanelReport.repaint();
1870        } else if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_F2) {
1871            // Edit static Text
1872

1873            DeleteElementsOperation undoOp = new DeleteElementsOperation(this);
1874            for (Iterator i = selectedElements.iterator(); i.hasNext(); ) {
1875                ReportElement re = (ReportElement) i.next();
1876                if(re instanceof TextReportElement){
1877                    String JavaDoc te = ((TextReportElement)re).getText();
1878                    String JavaDoc result = javax.swing.JOptionPane.showInputDialog(this,
1879                            I18n.getString("messages.jReportFrame.insertValue", "Please enter new Value"),
1880                            te);
1881                    if(result != null && !result.equals("")){
1882                        ((TextReportElement)re).setText(result);
1883                        undoOp.addElement( re, getReport().getElements().indexOf(re));
1884                        fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, re , ReportElementChangedEvent.CHANGED));
1885                    }
1886                }
1887            }
1888            this.addUndoOperation(undoOp);
1889            this.getMainFrame().getElementPropertiesDialog().updateSelection();
1890            jPanelReport.repaint();
1891        } else if (evt.getKeyCode() == java.awt.event.KeyEvent.VK_F3) {
1892
1893            transformStaticInTextFields();
1894            this.getMainFrame().getElementPropertiesDialog().updateSelection();
1895        }
1896        /* Begin code by Robert Lamping, 12 july 2004 */
1897        /* Copy and paste via CTRL/INS and SHIFT insert */
1898        else if ( (( evt.getModifiers() & evt.CTRL_MASK) != 0 ) && evt.getKeyCode() == java.awt.event.KeyEvent.VK_INSERT) {
1899            copy();
1900        } else if ( (( evt.getModifiers() & evt.SHIFT_MASK) != 0) && evt.getKeyCode() == java.awt.event.KeyEvent.VK_INSERT) {
1901            paste();
1902        }
1903        /* End code Robert Lamping, 12 July 2004 */
1904
1905
1906    }//GEN-LAST:event_jPanelReportKeyPressed
1907

1908    private void jPanelReportMouseReleased(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jPanelReportMouseReleased
1909

1910        if (drag_selection_mode && evt.getButton() == evt.BUTTON1) {
1911
1912            Graphics2D gg = (Graphics2D)jPanelReport.getGraphics();
1913            gg.setXORMode(Color.GREEN);
1914
1915            Stroke s = gg.getStroke();
1916            gg.setStroke(selectionStroke);
1917
1918            if (!first_draw_selection_rect) {
1919                gg.drawRect((int)Math.min( drag_selection_origin.x, drag_selection_end.x),
1920                        (int)Math.min( drag_selection_origin.y, drag_selection_end.y),
1921                        (int)Math.abs( drag_selection_origin.x - drag_selection_end.x),
1922                        (int)Math.abs( drag_selection_origin.y - drag_selection_end.y));
1923            }
1924
1925            gg.setPaintMode();
1926            if (s != null) {
1927                gg.setStroke(s);
1928            }
1929            drag_selection_mode = false;
1930            first_draw_selection_rect = true;
1931
1932            if (( evt.getModifiers() & evt.SHIFT_MASK ) == 0){
1933                setSelectedElement(null);
1934            }
1935
1936            int delta_w = evt.getX()- drag_selection_origin.x;
1937            int delta_h = evt.getY()- drag_selection_origin.y;
1938            int delta_x = (delta_w < 0) ? delta_w: 0;
1939            int delta_y = (delta_h < 0) ? delta_h : 0;
1940
1941            if (jHorizontalScrollBar == null ||
1942                    jVerticalScrollBar == null ||
1943                    drag_selection_origin == null ||
1944                    drag_selection_end == null) {
1945                return;
1946            }
1947
1948            int originX = getLogicalDim( Math.min( drag_selection_origin.x-10+jHorizontalScrollBar.getValue(),
1949                    drag_selection_end.x-10+jHorizontalScrollBar.getValue()))+10;
1950            int originY = getLogicalDim( Math.min( drag_selection_origin.y-10+jVerticalScrollBar.getValue(),
1951                    drag_selection_end.y-10+jVerticalScrollBar.getValue()))+10;
1952            int width = getLogicalDim( Math.abs( delta_w ) );
1953            int height = getLogicalDim( Math.abs( delta_h ) );
1954
1955            // We need logical coordinates...
1956
java.awt.Rectangle JavaDoc rect = new java.awt.Rectangle JavaDoc( originX, originY, width, height );
1957            boolean selection_changed = false;
1958            for (Iterator i = getReport().getElements().iterator(); i.hasNext(); ) {
1959                ReportElement re = (ReportElement) i.next();
1960                if ( re.intersects( rect ) ) {
1961                    if (!selection_changed) selection_changed = true;
1962                    addSelectedElement(re,false);
1963                }
1964            }
1965            if (selection_changed) {
1966                fireSelectionChangedEvent();
1967            }
1968
1969        } else if (band_dragging && evt.getButton() == evt.BUTTON1 ) {
1970
1971            band_dragging = false;
1972            jPanelReport.setCursor( Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
1973
1974            // _________ BEGIN DRAGGING REAL TIME CODE ___________________
1975
// Work with logical dimensions...
1976
int delta = getLogicalDim( evt.getY()-band_dragging_origin );
1977
1978            int okHeight = band_dragging_band.getHeight();
1979            int requestedHeight = okHeight + delta;
1980
1981            if (delta != 0) {
1982                BandDraggedOperation undoOp = new BandDraggedOperation(this,band_dragging_band);
1983                // Search for min_height that don't cover elements in this band...
1984

1985                int band_h = report.getBandYLocation(band_dragging_band) +10;
1986
1987                int available_height = report.getHeight() - report.getTopMargin()- report.getBottomMargin();
1988
1989                if (!band_dragging_band.getName().equals("background") &&
1990                    !( band_dragging_band.getName().equals("title") && getReport().isIsTitleNewPage()) &&
1991                    !( band_dragging_band.getName().equals("summary") && getReport().isIsSummaryNewPage()))
1992                {
1993                    for (int i=0; i<report.getBands().size(); ++i)
1994                    {
1995                        Band aBand = (Band)report.getBands().elementAt(i);
1996
1997                        if (!(aBand.getName().equals("background")) &&
1998                            !(aBand.getName().equals("title") && getReport().isIsTitleNewPage()) &&
1999                            !(aBand.getName().equals("summary") && getReport().isIsSummaryNewPage()) &&
2000                            !(aBand == band_dragging_band))
2001                        {
2002                            available_height -= aBand.getHeight();
2003                        }
2004                    }
2005                }
2006
2007                okHeight = Math.max(0, Math.min(available_height, requestedHeight));
2008
2009                //System.out.println("Requested: " + requestedHeight + " " + available_height);
2010

2011                delta = okHeight - band_dragging_band.getHeight();
2012
2013                // Redraw all under the min height...
2014
band_dragging_band.setHeight( band_dragging_band.getHeight() + delta );
2015
2016                this.jPanelReportComponentResized( new java.awt.event.ComponentEvent JavaDoc( jPanelReport, 0 ));
2017
2018                //this.label1.setText("DRagged: "+band_dragging_band.name +" "+delta);
2019
int edge_y = Math.min(report.getBandYLocation(band_dragging_band)+band_dragging_band.getHeight(),
2020                        report.getBandYLocation(band_dragging_band)+band_dragging_band.getHeight()-delta);
2021
2022                //e = report.getElements().elements();
2023

2024                undoOp.setBandDelta(delta);
2025
2026                // Adjust all elements positions...
2027
//
2028
Vector containers = new Vector();
2029                for (Iterator i = report.getElements().iterator(); i.hasNext(); ) {
2030                    ReportElement re = (ReportElement) i.next();
2031                    if (re.getParentElement() != null &&
2032                        re.getParentElement().position.y < edge_y+10 ) continue;
2033                    
2034                    if (re instanceof FrameReportElement)
2035                    {
2036                        containers.add(re);
2037                    }
2038                
2039                    if (re.position.y >= edge_y+10 ||
2040                        (re.getParentElement() != null &&
2041                         re.getParentElement().position.y >= edge_y+10) ) {
2042                        // I should add the distance form the base of resized band, and my element...
2043
Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
2044
2045                        int space_before_band = band_h - re.position.y - re.height;
2046                        if (band_h <= report.getBandYLocation(re.band) +10){
2047                            space_before_band = 0;
2048                        }
2049                        re.setPosition(new Point(re.position.x,re.position.y+delta));
2050                        //this.updateElement(re,new Rectangle(re.position.x-5,re.position.y-5-delta,re.width+10, re.height+10+delta));
2051
Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
2052                        undoOp.addElement(re, oldBounds, newBounds );
2053                    }
2054                }
2055                addUndoOperation(undoOp);
2056            }
2057                        /*
2058                        getLogicalDim(panel9.getWidth()),getLogicalDim(panel9.getHeight()));
2059                        Rectangle rect = panel9.getDisplayRect(); //new Rectangle(0,0,report.getPagesize().x, report.getDesignHeight());
2060
2061                        // drag down all elements under this band...
2062                        redrawAll(offscreenbm.getGraphics(),rect,0);
2063                        Rectangle clipRect = panel9.getDisplayRect(); //new Rectangle(rect);
2064                        //clipRect.offset(-HScrollBar1.getValue(),-VScrollBar1.getValue());
2065                        //panel9.createGraphics().drawRect(clipRect,RasterOp.BLACK);
2066                        panel9.createGraphics().drawImage( offscreenbm,rect, clipRect ,false);
2067                         */

2068            this.getMainFrame().getDocumentStructurePanel().updateUI();
2069
2070            jPanelReport.repaint();
2071            // _________ STOP DRAGGING REAL TIME CODE ___________________
2072
/* TODO
2073                        if (selectedElements.size()>0)
2074                        {
2075                                MainForm mf = (MainForm)this.getMDIParent();
2076                                if (mf != null)
2077                                {
2078                                        if (mf.isPropertiesOpened())
2079                                        {
2080                                                mf.initReportForm();
2081                                                mf.ep.setEelement(this,getSelectedElements());
2082                                                mf.ep.setVisible(true);
2083                                        }
2084                                }
2085                        }
2086                         TODO */

2087        }
2088
2089        if (newObjectType != ReportElementType.NONE) {
2090            // The second point was clicked
2091

2092            firstXORDraw = true;
2093
2094            // Find the band to associate to the new element...
2095

2096            int evtX = snapToGridOrizzontally(evt.getX());
2097            int evtY = snapToGridVertically(evt.getY());
2098                
2099            int delta_w = evtX - newObjectOrigin.x; //gridMultiple(evt.getX()-newObjectOrigin.x);
2100
int delta_h = evtY - newObjectOrigin.y; //gridMultiple(evt.getY()-newObjectOrigin.y);
2101
int delta_x = (delta_w < 0) ? delta_w : 0;
2102            int delta_y = (delta_h < 0) ? delta_h : 0;
2103
2104            int originX = getLogicalDim( Math.min(newObjectOrigin.x-10+jHorizontalScrollBar.getValue(),
2105                    newObjectOrigin.x+delta_x-10+jHorizontalScrollBar.getValue()))+10;
2106            int originY = getLogicalDim( Math.min(newObjectOrigin.y-10+jVerticalScrollBar.getValue(),
2107                    newObjectOrigin.y+delta_y-10+jVerticalScrollBar.getValue()))+10;
2108            int width = getLogicalDim( Math.abs(delta_w) );
2109            int height = getLogicalDim( Math.abs(delta_h) );
2110
2111
2112            if (newObjectType == ReportElementType.LINE_ELEMENT) {
2113                /* When shift button is pressed too, then there will be no align ment on the grid */
2114                if ( ( evt.getModifiers() & evt.SHIFT_MASK) != 0) {
2115                    Point straight = straighten( delta_w, delta_h);
2116                    delta_w = straight.x;
2117                    delta_h = straight.y;
2118                }
2119            }
2120
2121            Band bname = getReport().getBandByPosition( originY );
2122
2123            ReportElement re = ReportElementFactory.create( newObjectType, originX, originY, getLogicalDim(delta_w), getLogicalDim(delta_h));
2124
2125            if (getReport().getStyles().size() > 0)
2126            {
2127                for (int i=0; i<getReport().getStyles().size(); ++i )
2128                {
2129                   Style s = (Style)getReport().getStyles().elementAt(i);
2130
2131                   if (s.getAttributeBoolean(s.ATTRIBUTE_isDefault,false) == true)
2132                   {
2133                       re.setStyle( s );
2134                   }
2135                }
2136            }
2137            /* Begin Code Robert Lamping, 13 july 2004 */
2138            // Element does not know about other elements, the frame does, so here we reset the key.
2139
// barcode becomes barcode-1, or higher depending on what the highest sub number is.
2140
// Same for graphcs image, or whatever initial name
2141
re.setKey( getNextElementKey( re.getKey()) ) ;
2142
2143            /* End Code Robert Lamping, 13 july 2004 */
2144
2145            re.setBand( bname );
2146
2147            for (int elnum = getReport().getElements().size()-1; elnum >= 0; --elnum)
2148            {
2149                ReportElement container_re = (ReportElement)getReport().getElements().elementAt(elnum);
2150                if (container_re instanceof FrameReportElement && container_re.getBand() == re.getBand())
2151                {
2152                    if ( container_re.getBounds().contains( re.getBounds()))
2153                    {
2154                        re.setParentElement( container_re);
2155                        break;
2156                    }
2157                }
2158            }
2159
2160
2161
2162
2163            boolean ok = true;
2164            if ( newObjectType == ReportElementType.CROSSTAB_ELEMENT ) {
2165
2166                CrosstabWizardDialog cw = new CrosstabWizardDialog(getMainFrame(),true);
2167                cw.setCrosstabReportElement((CrosstabReportElement)re);
2168                cw.setReport( this.getReport());
2169                cw.setVisible(true);
2170                ((CrosstabReportElement)re).setReport(this.getReport());
2171                addCrosstabEditor( (CrosstabReportElement)re );
2172
2173            }
2174            if ( newObjectType == ReportElementType.SUBREPORT_ELEMENT ) {
2175
2176                SubreportWizard sr = new SubreportWizard();
2177                sr.setSubReportElement((SubReportElement)re);
2178                sr.startWizard();
2179
2180            }
2181            if ( newObjectType == ReportElementType.CHART_ELEMENT ) {
2182
2183                // New JasperReports 0.6.9 implementation...
2184
ChartSelectionJDialog csd = new ChartSelectionJDialog(this.getMainFrame(),true);
2185                csd.setVisible(true);
2186                if (csd.getDialogResult() == javax.swing.JOptionPane.OK_OPTION) {
2187                    ChartReportElement2 cre = (ChartReportElement2)re ;
2188                    cre.setChart( csd.getChart() );
2189                } else {
2190                    ok = false;
2191                }
2192            }
2193            if ( newObjectType == ReportElementType.BREAK_ELEMENT ) {
2194
2195                // New JasperReports 0.6.9 implementation...
2196
re.setWidth( this.getReport().getWidth() - getReport().getLeftMargin() - getReport().getRightMargin() );
2197                re.getPosition().x = getReport().getLeftMargin()+10;
2198                re.setHeight(0);
2199                re.updateBounds();
2200                if (re.getBand() == null) ok=false;
2201            }
2202
2203            if (ok) {
2204
2205                report.getElements().addElement(re);
2206
2207                fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, re , ReportElementChangedEvent.ADDED));
2208
2209                addUndoOperation( new InsertElementOperation( this, re ) );
2210
2211
2212                            /*
2213                            if (selectedElements.size() > 0)
2214                            {
2215                                    ReportElement oldselected = (ReportElement)selectedElements.firstElement();
2216                                    Rectangle rect = new Rectangle(oldselected.position.x-5,oldselected.position.y-5,oldselected.width+10, oldselected.height+10);
2217                                    setSelectedElement(null);
2218                                    redrawAll(offscreen ,rect,5);
2219                                    Rectangle clipRect = new Rectangle(getZoomedDim(oldselected.position.x-10)-5+10-jHorizontalScrollBar.getValue(),
2220                                                                                                               getZoomedDim(oldselected.position.y-10)-5+10-jVerticalScrollBar.getValue(),
2221                                                                                                               getZoomedDim(oldselected.width)+10,
2222                                                                                                               getZoomedDim(oldselected.height)+10);
2223                                    clipRect.translate(-jHorizontalScrollBar.getValue(),-jVerticalScrollBar.getValue());
2224
2225                                    //panel9.createGraphics().drawImage( offscreenbm,clipRect, clipRect ,false);
2226                                    jPanelReport.getGraphics().drawImage( offscreenImage ,
2227                                                                          clipRect.x ,clipRect.y, clipRect.width,clipRect.height,
2228                                                                          clipRect.x ,clipRect.y, clipRect.width,clipRect.height,
2229                                                                          (ImageObserver)this);
2230                            }
2231                             */

2232                setSelectedElement(re);
2233            }
2234            newObjectOrigin = null;
2235            // Add undo operation...
2236
//UndoOperation uo = new UndoOperation(UndoOperationType.UNDO_INSERT);
2237
//uo.params.addElement(new Integer(1));
2238
//ReportElement clone = re.cloneMe();
2239

2240            //uo.params.addElement(clone);
2241
//addUndoOperation(uo);
2242
//repaint();
2243

2244            newObjectType = ReportElementType.NONE;
2245
2246            jPanelReport.setCursor( Cursor.getDefaultCursor());
2247            getMainFrame().setActiveTool(0);
2248
2249
2250        }
2251
2252        if (trasforming) {
2253            trasforming = false;
2254
2255            jPanelReport.setCursor( Cursor.getDefaultCursor());
2256
2257            if (transformation_type != TransformationType.TRANSFORMATION_MOVE || resistenceExceeded == true) {
2258                Point p = new Point(transformation_origin_end);
2259                p.x = getLogicalDim(p.x);
2260                p.y = getLogicalDim(p.y);
2261                p.x -= getLogicalDim(transformation_origin.x);
2262                p.y -= getLogicalDim(transformation_origin.y);
2263                
2264                // Now it's time to correct the deltas...
2265
// We simply have to do this correction because end coordinates can been calculated
2266
// with a strange percentage
2267

2268
2269                Vector selectedElementsToChange = new Vector();
2270                
2271                Enumeration e = getSelectedElements().elements();
2272                while (e.hasMoreElements()) {
2273                    ReportElement re = (ReportElement)e.nextElement();
2274                    if (!selectedElementsToChange.contains(re))
2275                    {
2276                        selectedElementsToChange.add(re);
2277                        if (transformation_type == TransformationType.TRANSFORMATION_MOVE)
2278                        {
2279                            if (re instanceof FrameReportElement)
2280                            {
2281                                // Add all child elements ..
2282
addChildElements(re, selectedElementsToChange);
2283                            }
2284                        }
2285                    }
2286                }
2287                e = selectedElementsToChange.elements();
2288                TransformElementsOperation undoOp = new TransformElementsOperation(this);
2289                Vector changed_elements = new Vector();
2290                
2291                while (e.hasMoreElements()) {
2292                    ReportElement re = (ReportElement)e.nextElement();
2293
2294                    
2295                    
2296                    undoOp.addElement( re );
2297
2298                    // Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
2299

2300                    if (re instanceof BreakReportElement)
2301                    {
2302                        Point specialP = new Point(0, p.y);
2303                        if (transformation_type == TransformationType.TRANSFORMATION_MOVE ||
2304                            transformation_type == TransformationType.TRANSFORMATION_RESIZE_N)
2305                        {
2306                            re.trasform(specialP, TransformationType.TRANSFORMATION_MOVE);
2307                        }
2308                        else
2309                        {
2310                            continue;
2311                        }
2312                    }
2313                    else
2314                    {
2315                        re.trasform(p, transformation_type);
2316                    }
2317                            
2318                    
2319                    // Band oldBand = re.getBand();
2320
if (re.getParentElement() == null)
2321                    {
2322                        re.adjustBand();
2323                    }
2324                    // Band newBand = re.getBand();
2325
// Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
2326
// undoOp.addElement(re, oldBounds, newBounds,oldBand,newBand);
2327

2328                    undoOp.captureUniqueModified(re);
2329                    changed_elements.add( re );
2330
2331                }
2332                addUndoOperation(undoOp);
2333                if (changed_elements.size() > 0) {
2334                    fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, changed_elements , ReportElementChangedEvent.CHANGED));
2335                }
2336
2337                jPanelReport.repaint();
2338            }
2339
2340                /*
2341                        if (p.x!=0 || p.y != 0)
2342                        {
2343                                UndoOperation uo = new UndoOperation(UndoOperationType.UNDO_TRANSFORMATION);
2344                                uo.params.addElement(p);
2345                                uo.params.addElement(new Integer( transformation_type ) );
2346                                Enumeration enum = selectedElements.elements();
2347                                while (enum.hasMoreElements())
2348                                {
2349                                                uo.params.addElement(enum.nextElement());
2350                                }
2351                                addUndoOperation(uo);
2352                        }
2353                 */

2354            transformation_undo_delta = new Point(0,0);
2355            transformation_type = TransformationType.TRANSFORMATION_NONE;
2356                /*
2357                        MainForm mf = (MainForm)this.getMDIParent();
2358                        if (mf != null)
2359                        {
2360                                if (mf.isPropertiesOpened())
2361                                {
2362                                        mf.initReportForm();
2363                                        mf.ep.setEelement(this,getSelectedElements());
2364                                        mf.ep.setVisible(true);
2365                                }
2366                        }
2367                 */

2368            getMainFrame().getElementPropertiesDialog().updateSelection();
2369        }
2370
2371    }//GEN-LAST:event_jPanelReportMouseReleased
2372

2373
2374    /**
2375     * Single Click
2376     * - Left button: ...
2377     * //TODO
2378     * - Right button: ...
2379     * //TODO
2380     *
2381     * Double click
2382     * - On a band split: If no elements are selected, then a double click on a band split tries to
2383     * reduce the bandheight to the enclosing rectangle around the elements in the band above the split.
2384     * Elements in the top marging are not taken into account.
2385     * - Otherwise
2386     * @param evt
2387     */

2388    private void jPanelReportMousePressed(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jPanelReportMousePressed
2389

2390        jPanelReport.requestFocus();
2391        if (evt.getButton() == evt.BUTTON1 && evt.getClickCount() < 2)
2392        {
2393
2394            if (newObjectType != ReportElementType.NONE)
2395            {
2396                firstXORDraw = false;
2397                newObjectOrigin = new Point(snapToGridOrizzontally(evt.getX()),snapToGridVertically(evt.getY()));
2398                mouse.x = newObjectOrigin.x;
2399                mouse.y = newObjectOrigin.y;
2400                return;
2401            }
2402
2403            // Begin code Robert Lamping, 18 July 2004
2404
// Zoom in interactively with SHIFT/CTRL + LEFT mouse button
2405
if ( (( evt.getModifiers() & evt.SHIFT_MASK) != 0) &&
2406                    (( evt.getModifiers() & evt.CTRL_MASK) != 0) )
2407            {
2408                // multiply zoomfactor by 2 and zoom in with current mouse position as center!
2409
//Point center = new Point(
2410
Point clickPoint = this.realPoint( evt.getX(), evt.getY() );
2411                setZoomFactor( getZoomFactor() * 2 );
2412                getMainFrame().setComboBoxZoomFactor( getZoomFactor() * 100 );
2413                centerSelectedElements( clickPoint ); // if not present use clickPoint
2414
return;
2415            }
2416            // End code Robert Lamping, 18 July 2004
2417

2418
2419            if (selectedElements.size() > 0 && (( evt.getModifiers() & evt.SHIFT_MASK ) == 0))
2420            {
2421                // We are transformation mode?
2422
if (transformation_type >=0)
2423                {
2424                    trasforming = true;
2425                    firstXORDrawTransforming = true;
2426                    transformation_origin = new Point(evt.getX(),evt.getY());
2427                    transformation_undo_delta = new Point(0,0);
2428                    transformation_origin_end = new Point(evt.getX(),evt.getY());
2429                    return;
2430                }
2431            }
2432
2433            if (jPanelReport.getCursor() == hsplit)
2434            {
2435
2436                first_draw_band=true;
2437                int bl = evt.getY() + jVerticalScrollBar.getValue();
2438                int y=report.getTopMargin();
2439                boolean found=false;
2440                Band band=null;
2441
2442                if (( evt.getModifiers() & evt.SHIFT_MASK ) != 0)
2443                {
2444                    //label1.setText("Inverse search");
2445
y = report.getDesignHeight()-report.getBottomMargin();
2446                    for (int b =report.getBands().size()-1; b>=0; --b)
2447                    {
2448                        band = (Band)report.getBands().elementAt(b);
2449                        if (bl>getZoomedDim(y)+10-3 && bl < getZoomedDim(y)+10+3)
2450                        {
2451                            break;
2452                        }
2453                        y -= band.getHeight();
2454                    }
2455                }
2456                else
2457                {
2458                    for (Iterator i = getReport().getBands().iterator(); i.hasNext(); )
2459                    {
2460                        band = (Band) i.next();
2461                        y += band.getHeight();
2462                        if (bl>getZoomedDim(y)+10-3 && bl < getZoomedDim(y)+10+3)
2463                        {
2464                            break;
2465                        }
2466                    }
2467                }
2468                if (band != null)
2469                {
2470                    band_dragging = true;
2471                    band_dragging_origin = evt.getY();
2472                    band_dragging_band = band;
2473
2474                    //this.label1.setText(band_dragging_band.name + " band height: " +(band_dragging_band.height));
2475
return;
2476                }
2477            }
2478            for (int i=report.getElements().size()-1; i>=0; --i)
2479            {
2480
2481                ReportElement re = (ReportElement)report.getElements().elementAt(i);
2482                if (re.intersects(new Point(getLogicalDim(evt.getX()+jHorizontalScrollBar.getValue()-10)+10,
2483                        getLogicalDim(evt.getY()+jVerticalScrollBar.getValue()-10)+10)) ||
2484                    (re instanceof BreakReportElement && re.intersects(new Rectangle(
2485                               0, getLogicalDim(evt.getY()+jVerticalScrollBar.getValue()-10)+10,
2486                               getReport().getWidth(), 1)
2487                          ))
2488                     )
2489                {
2490                    if (selectedElements.size()>0 && re == ((ReportElement)selectedElements.firstElement())) return;
2491                    // 1.<Cancel old corona...
2492

2493                    if (selectedElements.size() > 0 && (( evt.getModifiers() & evt.SHIFT_MASK ) == 0))
2494                    {
2495                        setSelectedElement(null);
2496                    }
2497
2498                    if ((( evt.getModifiers() & evt.SHIFT_MASK ) == 0) || selectedElements.size()==0)
2499                    {
2500                        //getSelectedElements().removeAllElements();
2501
setSelectedElement(re);
2502                        jPanelReport.repaint();
2503                    }
2504                    else if (( evt.getModifiers() & evt.SHIFT_MASK ) != 0)
2505                    {
2506                        if (getSelectedElements().contains(re))
2507                        {
2508                            getSelectedElements().remove(re);
2509                            jPanelReport.repaint();
2510                        }
2511                        else
2512                        {
2513                            addSelectedElement(re);
2514                        }
2515                    }
2516                    else
2517                    {
2518                        setSelectedElement(re);
2519                    }
2520                    trasforming = true;
2521                    firstXORDrawTransforming = true;
2522                    transformation_origin = new Point(evt.getX(),evt.getY());
2523                    transformation_origin_end = new Point(evt.getX(),evt.getY());
2524
2525                    if (getMainFrame().isEMMActive())
2526                        transformation_type = TransformationType.TRANSFORMATION_NONE;
2527                    else
2528                        transformation_type = TransformationType.TRANSFORMATION_MOVE;
2529
2530                    jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR ));
2531                    return;
2532
2533                }
2534            }
2535            getMainFrame().getElementPropertiesDialog().updateSelection();
2536
2537            /*
2538            if (selectedElements.size()>0 && (( evt.getModifiers() & evt.SHIFT_MASK ) == 0))
2539            {
2540                ReportElement myre = (ReportElement)selectedElements.firstElement();
2541                if (myre != null)
2542                {
2543                        Rectangle rect = new Rectangle(myre.position.x-5,myre.position.y-5,myre.width+10, myre.height+10);
2544                        setSelectedElement(null);
2545                }
2546            }
2547             */

2548
2549            if (( evt.getModifiers() & evt.SHIFT_MASK ) == 0 && getSelectedElements().size() > 0)
2550                setSelectedElement(null);
2551
2552            // We can enter in drag selection mode...
2553
drag_selection_mode = true;
2554            first_draw_selection_rect = true;
2555            drag_selection_origin = new Point(evt.getX(),evt.getY());
2556        }
2557        else if (evt.getButton() == evt.BUTTON3)
2558        {
2559
2560            // Begin code Robert Lamping, 18 July 2004
2561
// Zoom out interactively with SHIFT/CTRL = RIGHT mouse button
2562
if ( (( evt.getModifiers() & evt.SHIFT_MASK) != 0) &&
2563                    (( evt.getModifiers() & evt.CTRL_MASK) != 0) )
2564            {
2565                // divide zoomfactor by 2 and zoom in with current mouse position as center!
2566
//Point center = new Point(
2567
Point clickPoint = this.realPoint( evt.getX(), evt.getY() );
2568                setZoomFactor( getZoomFactor() / 2 );
2569                getMainFrame().setComboBoxZoomFactor( getZoomFactor() * 100 );
2570                centerSelectedElements( clickPoint ); // if not present use clickPoint
2571
return;
2572            }
2573            // End code Robert Lamping, 18 July 2004
2574

2575            popup_opened_at = evt.getPoint();
2576            boolean found = false;
2577            //1. We must see if we are over an object...
2578
for (int i=report.getElements().size()-1; i>=0; --i)
2579            {
2580                ReportElement re = (ReportElement)report.getElements().elementAt(i);
2581                if (re.intersects(new Point(getLogicalDim(evt.getX()+jHorizontalScrollBar.getValue()-10)+10,getLogicalDim(evt.getY()+jVerticalScrollBar.getValue()-10)+10)))
2582                {
2583
2584                    if ( this.getSelectedElements().size() <= 1 )
2585                        setSelectedElement(re);
2586                    // if ( this.getSelectedElements().size() > 0 && (( evt.getModifiers() & evt.SHIFT_MASK ) != 0))
2587
// {
2588
// addSelectedElement(re);
2589
// }
2590
// else
2591
// setSelectedElement(re);
2592

2593                    found = true;
2594                    break;
2595                }
2596            }
2597
2598            jMenuItemElementChartProperties.setVisible(false);
2599            jMenuItemElementCrosstabProperties.setVisible(false);
2600            jMenuItemElementCrosstabDesignProperties.setVisible(false);
2601            jMenuItemElementOpenSubreport.setVisible(false);
2602            if (getSelectedElements().size() > 0)
2603            {
2604                if (getSelectedElements().elementAt(0) instanceof ChartReportElement2)
2605                {
2606                    jMenuItemElementChartProperties.setVisible(true);
2607                }
2608
2609                if (getSelectedElements().elementAt(0) instanceof CrosstabReportElement)
2610                {
2611                    jMenuItemElementCrosstabProperties.setVisible(true);
2612                    jMenuItemElementCrosstabDesignProperties.setVisible(true);
2613                }
2614
2615                if (getSelectedElements().elementAt(0) instanceof SubReportElement)
2616                {
2617                    jMenuItemElementOpenSubreport.setVisible(true);
2618                }
2619
2620                this.jMenuItemCopy.setEnabled(true);
2621                this.jMenuItemCut.setEnabled(true);
2622                this.jMenuItemDelete.setEnabled(true);
2623                this.jMenuItemCopyStyle.setEnabled(true);
2624            }
2625            else
2626            {
2627                this.jMenuItemCopy.setEnabled(false);
2628                this.jMenuItemCut.setEnabled(false);
2629                this.jMenuItemDelete.setEnabled(false);
2630                this.jMenuItemCopyStyle.setEnabled(false);
2631            }
2632
2633
2634            if (getMainFrame().getStyleClipboard() != null)
2635            {
2636                this.jMenuItemPasteStyle.setEnabled(true);
2637            }
2638            else
2639            {
2640                this.jMenuItemPasteStyle.setEnabled(false);
2641            }
2642
2643            if (getMainFrame().getClipBoard().size() > 0)
2644            {
2645                this.jMenuItemPaste.setEnabled(true);
2646            }
2647            else
2648            {
2649                this.jMenuItemPaste.setEnabled(false);
2650            }
2651
2652            Enumeration selectedElementEnum = getSelectedElements().elements();
2653            boolean allTextFields = true;
2654            boolean onGroup = false; // true if at least an element belong to a group
2655
boolean sameBand = true;
2656            Band theBand = null;
2657            while (selectedElementEnum.hasMoreElements())
2658            {
2659                ReportElement re = (ReportElement)selectedElementEnum.nextElement();
2660                if (allTextFields && !(re instanceof TextFieldReportElement))
2661                {
2662                    allTextFields = false;
2663                }
2664
2665                if (!onGroup && !re.getElementGroup().equals("")) onGroup = true;
2666
2667                if (theBand == null) theBand = re.getBand();
2668                else if (sameBand && theBand != re.getBand()) sameBand = false;
2669
2670                if (!allTextFields && onGroup && !sameBand) break;
2671            }
2672
2673            jMenuItemPattern.setEnabled( allTextFields );
2674
2675            jMenuItemGroup.setEnabled( sameBand );
2676            jMenuItemUngroup.setEnabled( onGroup );
2677
2678            if(found)
2679            {
2680                // we have find an element, open the contextual menu over it...
2681

2682                if ( this.getSelectedElements().size() == 1 )
2683                {
2684                    //Show Popup with menu for one element
2685
jMenuHSpacing.setEnabled(false);
2686                    jMenuVSpacing.setEnabled(false);
2687                    jPopupMenuElement.show(jPanelReport,evt.getX(),evt.getY());
2688
2689                    return;
2690                }
2691                if ( this.getSelectedElements().size() > 1 )
2692                {
2693                    //Show Popup with special menu for more elements
2694
jMenuHSpacing.setEnabled(true);
2695                    jMenuVSpacing.setEnabled(true);
2696                    jPopupMenuElement.show(jPanelReport,evt.getX(),evt.getY());
2697                    return;
2698                }
2699
2700
2701            }
2702            // Looking for the band....
2703
jPopupMenuBand.show(jPanelReport,evt.getX(),evt.getY());
2704            return;
2705        }
2706        else if (evt.getButton() == evt.BUTTON1 && evt.getClickCount() == 2)
2707        {
2708
2709            // Begin code Robert Lamping, 18 July 2004
2710
// --------------------------------------------------------------------------------
2711
// ZOOM IN
2712
// --------------------------------------------------------------------------------
2713
if ( (( evt.getModifiers() & evt.SHIFT_MASK) != 0) &&
2714                    (( evt.getModifiers() & evt.CTRL_MASK) != 0) )
2715            {
2716                Point clickPoint = this.realPoint( evt.getX(), evt.getY() );
2717                setZoomFactor( getZoomFactor() * 2 );
2718                getMainFrame().setComboBoxZoomFactor( getZoomFactor() * 100 );
2719                centerSelectedElements( clickPoint); // if not present use clickPoint
2720
return;
2721            }
2722            // End code Robert Lamping, 18 July 2004
2723

2724
2725            // Begin code Robert Lamping, 24 July 2004
2726
// --------------------------------------------------------------------------------
2727
// Double click on band: move band split to lowest element in band if any.
2728
// Otherwise no action.
2729
// --------------------------------------------------------------------------------
2730

2731            if (getSelectedElements().size() == 0)
2732            {
2733
2734                // If there are any elements in the band just above the band limit,
2735
// then set the band height to the maximum Y position of the elements.
2736
// THis way the band just encloses the elements.
2737

2738                // TEST: Create square in detail band. Square must be smaller than band
2739
// double click on lower detail band split.
2740
// Expected result: band height aligns under element bottom.
2741

2742                // We must find the right band split
2743

2744                Band band = null;
2745                int y = report.getTopMargin();
2746                int clicked_y = evt.getY() + jVerticalScrollBar.getValue();
2747                int proximity = 3 ;
2748
2749                for (Iterator i = getReport().getBands().iterator(); i.hasNext(); )
2750                {
2751                    band = (Band) i.next();
2752                    y += band.getHeight();
2753                    if ( clicked_y > getZoomedDim(y) + 10 - proximity && clicked_y < getZoomedDim(y) + 10 + proximity)
2754                    {
2755                        break;
2756                    }
2757                }
2758
2759                if ( band != null )
2760                {
2761                    int bandHeight = band.getHeight();
2762                    shrinkBand( band );
2763                    if ( bandHeight != band.getHeight() )
2764                    {
2765                        jPanelReport.repaint();
2766                        return;
2767                    }
2768                }
2769
2770            }
2771            else
2772            {
2773                // double clicked within a selected element
2774
// check if you clicked on South
2775
// in case of a text element, this will reset the height to fontsize() + 2
2776

2777                //logOnConsole( "Try to check whether you clicked on south\n");
2778
//traverse all selectedelement and check whether you clicked on south.
2779
// if so then adjust the element height to textheight + 2
2780

2781
2782                //int clicked_x = evt.getX() + jHorizontalScrollBar.getValue();
2783
//int clicked_y = evt.getY() + jVerticalScrollBar.getValue();
2784
//int proximity = 4 ;
2785
//Rectangle clickedRect = new Rectangle( clicked_x - proximity, clicked_y - proximity, 2* proximity, 2* proximity);
2786
//logOnConsole( "Clickpoint: " + clicked_x + " " + clicked_y + "\n");
2787

2788                Rectangle cursor = new Rectangle(evt.getX()+jHorizontalScrollBar.getValue(),
2789                        evt.getY()+jVerticalScrollBar.getValue(),
2790                        1,1);
2791                Rectangle grip = new Rectangle();
2792                grip.width = 5;
2793                grip.height = 5;
2794
2795                ReportElement clickedRe = null;
2796
2797                for (Iterator i = report.getElements().iterator(); i.hasNext(); )
2798                {
2799                    ReportElement re = (ReportElement) i.next();
2800
2801                    // Grip settings for South:
2802
grip.x = getZoomedDim(re.position.x+(re.width/2)-10)+10-2;
2803                    grip.y = getZoomedDim(re.position.y+re.height-10)+10;
2804
2805                    if (cursor.intersects(grip))
2806                    {
2807                        clickedRe = re;
2808                        break ;
2809                    }
2810                }
2811
2812                if ( clickedRe != null && getMainFrame().getProperties().getProperty("EnableTextResizeClick","true").equals("true") )
2813                {
2814                    // logOnConsole( "South clicked of " + clickedRe.getKey() + " \n");
2815
if (clickedRe instanceof TextReportElement )
2816                    {
2817                        TransformElementsOperation undoOp = new TransformElementsOperation(this);
2818                        TextReportElement tre = (TextReportElement) clickedRe;
2819
2820                        undoOp.addElement(tre);
2821
2822                        //Rectangle oldBounds = clickedRe.getBounds();
2823
tre.setHeight( tre.getFontSize() + 3 );
2824                        tre.updateBounds();
2825
2826                        //Rectangle newBounds = clickedRe.getBounds();
2827

2828                        // let the transformationElement capture its needs
2829
undoOp.captureUniqueModified(tre);
2830                        // add a task to the undo operation.
2831
// undoOp.addElement(clickedRe, oldBounds, newBounds );
2832

2833                        // Pass the undo tasks to the undo cluster.
2834
addUndoOperation(undoOp);
2835
2836                        // repaint the screen
2837
jPanelReport.repaint();
2838                        return;
2839                    }
2840                }
2841                else
2842                {
2843                    // Check if we are over a textreportelement
2844
if (getSelectedElements().size() == 1)
2845                    {
2846                        ReportElement re = (ReportElement)getSelectedElements().elementAt(0);
2847                        if (re instanceof TextReportElement)
2848                        {
2849                            TextReportElement tre = (TextReportElement) re;
2850
2851                            Rectangle textArea = new Rectangle();
2852                            textArea.width = getZoomedDim(re.getWidth());
2853                            textArea.height = getZoomedDim(re.getHeight());
2854                            textArea.x = getZoomedDim(re.position.x-10)+10;
2855                            textArea.y = getZoomedDim(re.position.y-10)+10;
2856
2857
2858                            try {
2859
2860                            if (cursor.intersects( textArea))
2861                            {
2862                                onlineEditingTextReportElement = tre;
2863                                floatingTextArea.setText( tre.getText() );
2864                                floatingTextArea.setOpaque( true );
2865                                
2866                                textArea.x -= jHorizontalScrollBar.getValue();
2867                                textArea.y -= jVerticalScrollBar.getValue();
2868
2869                                //floatingTextArea.setFont( new Font(tre.getFontName(), (() ? Font.BOLD : 0) & ((tre.isItalic()) ? Font.BOLD : Font.ITALIC) , (int)getZoomedDim(tre.getFontSize())));
2870
floatingTextArea.setForeground( tre.getFgcolor());
2871                                floatingTextArea.setBackground( tre.getBgcolor());
2872                                this.getReportPanel().add(floatingTextArea);
2873                                floatingTextArea.setBounds( textArea );
2874                                floatingTextArea.setSelectionStart(0);
2875                                floatingTextArea.setSelectionEnd(tre.getText().length());
2876                                SimpleAttributeSet JavaDoc set=new SimpleAttributeSet JavaDoc();
2877                                
2878                                StyledDocument JavaDoc doc=floatingTextArea.getStyledDocument();
2879                                if (tre.getAlign().equals("Center"))
2880                                {
2881                                    StyleConstants.setAlignment(set,StyleConstants.ALIGN_CENTER);
2882                                }
2883                                else if (tre.getAlign().equals("Right"))
2884                                {
2885                                    StyleConstants.setAlignment(set,StyleConstants.ALIGN_RIGHT);
2886                                }
2887                                else if (tre.getAlign().equals("Left"))
2888                                {
2889                                    StyleConstants.setAlignment(set,StyleConstants.ALIGN_LEFT);
2890                                }
2891                                else if (tre.getAlign().equals("Justified"))
2892                                {
2893                                    StyleConstants.setAlignment(set,StyleConstants.ALIGN_JUSTIFIED);
2894                                }
2895                                
2896                                StyleConstants.setFontFamily(set, tre.getFontName() );
2897                                StyleConstants.setFontSize(set, (int)getZoomedDim(tre.getFontSize()) );
2898                                StyleConstants.setBold(set,tre.isBold());
2899                                StyleConstants.setBold(set,tre.isItalic());
2900                                StyleConstants.setStrikeThrough(set,tre.isStrikeTrought());
2901                                StyleConstants.setUnderline(set,tre.isUnderline());
2902                                
2903                                floatingTextArea.setParagraphAttributes(set,true);
2904                                
2905                                this.getReportPanel().updateUI();
2906                                floatingTextArea.requestFocusInWindow();
2907
2908                                //floatingTextArea.requestFocusInWindow();
2909
//floatingTextArea.invalidate();
2910
//floatingTextArea.repaint();
2911
}
2912                            } catch (Exception JavaDoc ex)
2913                            {
2914                                ex.printStackTrace();
2915                            }
2916                        }
2917                        else
2918                        {
2919                            openElementPropertiesDialog();
2920                        }
2921                    }
2922                    else
2923                    {
2924                        openElementPropertiesDialog();
2925                    }
2926                }
2927            }
2928            // End code Robert Lamping, 24 July 2004, modified june 4, 2005
2929

2930            // otherwise try to open
2931
// openElementPropertiesDialog();
2932
}
2933    }//GEN-LAST:event_jPanelReportMousePressed
2934

2935    private void jHorizontalScrollBarAdjustmentValueChanged(java.awt.event.AdjustmentEvent JavaDoc evt) {//GEN-FIRST:event_jHorizontalScrollBarAdjustmentValueChanged
2936
floatingTextAreaFocusLost();
2937        isDocDirty = true;
2938        //logOnConsole( "jHorizontalScrollBar.getValue() : " + jHorizontalScrollBar.getValue() + "\n" );
2939
jPanelReport.repaint();
2940        jHorizontalRule.repaint();
2941    }//GEN-LAST:event_jHorizontalScrollBarAdjustmentValueChanged
2942

2943    private void jPanelReportComponentResized(java.awt.event.ComponentEvent JavaDoc evt) {//GEN-FIRST:event_jPanelReportComponentResized
2944
if (jPanelReport.getWidth() >= (getZoomedDim( report.getWidth())+19)) {
2945            jHorizontalScrollBar.setMaximum(report.getWidth());
2946            jHorizontalScrollBar.setVisibleAmount( jHorizontalScrollBar.getMaximum());
2947            jHorizontalScrollBar.setValue(0);
2948            ////VScrollBar1_scroll(VScrollBar1, new ScrollEvent( ScrollEventType.ENDSCROLL,0));
2949
} else {
2950            jHorizontalScrollBar.setMaximum((getZoomedDim( report.getWidth()) +19));
2951            this.jHorizontalScrollBar.setVisibleAmount(jPanelReport.getWidth());
2952            this.jHorizontalScrollBar.setBlockIncrement( this.jHorizontalScrollBar.getVisibleAmount() );
2953        }
2954
2955        if (jPanelReport.getHeight() >= getZoomedDim(report.getDesignHeight())+19) {
2956            jVerticalScrollBar.setMaximum(report.getDesignHeight());
2957            jVerticalScrollBar.setVisibleAmount( jVerticalScrollBar.getMaximum());
2958            jVerticalScrollBar.setValue(0);
2959            //VScrollBar1_scroll(VScrollBar1, new ScrollEvent( ScrollEventType.ENDSCROLL,0));
2960
} else {
2961            jVerticalScrollBar.setMaximum(getZoomedDim( report.getDesignHeight())+19);
2962            this.jVerticalScrollBar.setVisibleAmount(jPanelReport.getHeight());
2963            this.jVerticalScrollBar.setBlockIncrement( this.jVerticalScrollBar.getVisibleAmount() );
2964        }
2965        // getMainFrame().updateFitToPage(this); deactivated by Robert
2966

2967        jPanelReport.repaint();
2968    }//GEN-LAST:event_jPanelReportComponentResized
2969

2970    private void jVerticalScrollBarMouseReleased(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jVerticalScrollBarMouseReleased
2971

2972    }//GEN-LAST:event_jVerticalScrollBarMouseReleased
2973

2974    private void jVerticalScrollBarAdjustmentValueChanged(java.awt.event.AdjustmentEvent JavaDoc evt) {//GEN-FIRST:event_jVerticalScrollBarAdjustmentValueChanged
2975

2976        floatingTextAreaFocusLost();
2977        isDocDirty = true;
2978        jPanelReport.repaint();
2979        jVerticalRule.repaint();
2980    }//GEN-LAST:event_jVerticalScrollBarAdjustmentValueChanged
2981

2982    private void jPanelReportMouseDragged(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jPanelReportMouseDragged
2983

2984        this.jHorizontalRule.setCursorPosition(evt.getX());
2985        this.jVerticalRule.setCursorPosition(evt.getY());
2986        if (mouse == null) {
2987            mouse = new Point();
2988        }
2989
2990        if (drag_selection_mode == true) {
2991            Graphics2D gg = (Graphics2D)jPanelReport.getGraphics();
2992            gg.setXORMode(Color.GREEN);
2993            Stroke s = gg.getStroke();
2994            gg.setStroke(selectionStroke);
2995            if (!first_draw_selection_rect) {
2996                gg.drawRect((int)Math.min( drag_selection_origin.x, drag_selection_end.x),
2997                        (int)Math.min( drag_selection_origin.y, drag_selection_end.y),
2998                        (int)Math.abs( drag_selection_origin.x - drag_selection_end.x),
2999                        (int)Math.abs( drag_selection_origin.y - drag_selection_end.y));
3000            }
3001
3002            drag_selection_end = new java.awt.Point JavaDoc(evt.getX(), evt.getY());
3003            // Draw the new rectangle...
3004
gg.drawRect((int)Math.min( drag_selection_origin.x, drag_selection_end.x),
3005                    (int)Math.min( drag_selection_origin.y, drag_selection_end.y),
3006                    (int)Math.abs( drag_selection_origin.x - drag_selection_end.x),
3007                    (int)Math.abs( drag_selection_origin.y - drag_selection_end.y));
3008            gg.setPaintMode();
3009            first_draw_selection_rect = false;
3010            if (s != null) gg.setStroke(s);
3011        }
3012
3013        if (newObjectType == ReportElementType.NONE && !transforming) {
3014            // Is the mouse over a band line ?...
3015
if (band_dragging) {
3016                // 2. delta = Max altezza banda precedente e position delta
3017
int delta = getLogicalDim( evt.getY() - band_dragging_origin );
3018                //this.label1.setText(band_dragging_band.name + " band height: " +(band_dragging_band.height));
3019
if (delta != 0) {
3020
3021                    // Vediamo se e' possibile andare piu' su...
3022
// Non possiamo andare piu' su della banda prima...
3023
// 1. Cerchiamo la banda precedente...
3024

3025                    int min_logical_base = report.getTopMargin()+10;
3026                    int base_position=0;// = Math.max(min_logical_base, getReport().getBandYLocation(band_dragging_band) +delta);
3027
base_position = getZoomedDim(report.getBandYLocation(band_dragging_band))+10- jVerticalScrollBar.getValue();
3028                    Graphics gg = jPanelReport.getGraphics();
3029                    gg.setXORMode(Color.WHITE);
3030                    if (!first_draw_band) {
3031                        gg.drawLine( 0,Math.max(mouse.y,base_position),jPanelReport.getWidth(),Math.max(mouse.y,base_position) );
3032
3033                    }
3034                    gg.drawLine(0,Math.max(evt.getY(),base_position),jPanelReport.getWidth(),Math.max(evt.getY(),base_position) );
3035                    gg.setPaintMode();
3036                    first_draw_band = false;
3037                    //this.label1.setText(band_dragging_band.name + " band height: " +(band_dragging_band.height + delta));
3038
}
3039            }
3040        }
3041
3042        if (newObjectType != ReportElementType.NONE && newObjectOrigin!= null) {
3043
3044            /* In the process of defing the second point. */
3045
3046            Graphics gg = jPanelReport.getGraphics();
3047            gg.setXORMode(Color.WHITE);
3048            int delta_x = 0;
3049            int delta_y = 0;
3050
3051            if (newObjectType != ReportElementType.LINE_ELEMENT && !firstXORDraw) {
3052                delta_x = mouse.x- newObjectOrigin.x;
3053                delta_y = mouse.y-newObjectOrigin.y;
3054
3055                delta_x = (delta_x <0) ? delta_x : 0;
3056                delta_y = (delta_y<0) ? delta_y : 0;
3057            }
3058
3059
3060            int delta_w = 0;
3061            int delta_h = 0;
3062            if (!firstXORDraw) {
3063                int mevtX = snapToGridOrizzontally(mouse.x);
3064                int mevtY = snapToGridVertically(mouse.y);
3065                
3066                delta_w = mevtX - newObjectOrigin.x; //gridMultiple(evtX-newObjectOrigin.x);
3067
delta_h = mevtY - newObjectOrigin.y; //gridMultiple(evtY-newObjectOrigin.y);
3068
delta_x = (delta_w<0) ? delta_w: 0;
3069                delta_y = (delta_h<0) ? delta_h : 0;
3070            }
3071
3072            int evtX = snapToGridOrizzontally(evt.getX());
3073            int evtY = snapToGridVertically(evt.getY());
3074                
3075            if (newObjectType == ReportElementType.LINE_ELEMENT) {
3076
3077/* if ( ( evt.getModifiers() & evt.SHIFT_MASK) != 0) {
3078                  if (( delta_w + delta_h ) > 0 ) {
3079                      double cos = Math.PI * delta_w / Math.sqrt( (delta_w* delta_w) + (delta_h*delta_h) );
3080                      logOnConsole( "Cosinus: " + cos + "\n");
3081
3082                      if ( Math.abs( cos ) > Math.abs( Math.cos(0.25 * Math.PI ) ) ) {
3083                          delta_h = 0 ;
3084                      }
3085                  }
3086                }
3087 */

3088                /* overwrite the other one, so that it disappears */
3089                
3090                if ( ( evt.getModifiers() & evt.SHIFT_MASK) != 0) {
3091                    Point straight = straighten( delta_w, delta_h);
3092                    delta_w = straight.x;
3093                    delta_h = straight.y;
3094                }
3095                
3096
3097                if (!firstXORDraw) {
3098                    gg.drawLine( newObjectOrigin.x, newObjectOrigin.y, newObjectOrigin.x+delta_w,newObjectOrigin.y+delta_h);
3099                }
3100                
3101                delta_w = evtX-newObjectOrigin.x; //gridMultiple(evt.getX()-newObjectOrigin.x);
3102
delta_h = evtY-newObjectOrigin.y; //gridMultiple(evt.getY()-newObjectOrigin.y);
3103

3104                
3105                if ( ( evt.getModifiers() & evt.SHIFT_MASK) != 0) {
3106                    Point straight = straighten( delta_w, delta_h);
3107                    delta_w = straight.x;
3108                    delta_h = straight.y;
3109                }
3110                
3111
3112/* if ( ( evt.getModifiers() & evt.SHIFT_MASK) != 0) {
3113                  if (( delta_w + delta_h ) > 0 ) {
3114                      double cos = Math.PI * delta_w / Math.sqrt( (delta_w* delta_w) + (delta_h*delta_h) );
3115                      logOnConsole( "Cosinus: " + cos + "\n");
3116
3117                      if ( Math.abs( cos ) > Math.abs( Math.cos(0.25 * Math.PI ) ) ) {
3118                          delta_h = 0 ;
3119                      }
3120                  }
3121                }
3122 */

3123                gg.drawLine( newObjectOrigin.x, newObjectOrigin.y, newObjectOrigin.x+delta_w,newObjectOrigin.y+delta_h);
3124                mouse.x = newObjectOrigin.x+delta_w;
3125                mouse.y = newObjectOrigin.x+delta_y;
3126
3127            } else if (newObjectType == ReportElementType.ELLIPSE_ELEMENT) {
3128                if (!firstXORDraw) gg.drawOval( newObjectOrigin.x+delta_x, snapToGridVertically(newObjectOrigin.y+delta_y), Math.abs(delta_w), Math.abs(delta_h));
3129
3130                //delta_w = gridMultiple(evt.getX()-newObjectOrigin.x);
3131
//delta_h = gridMultiple(evt.getY()-newObjectOrigin.y);
3132
delta_w = evtX-newObjectOrigin.x; //gridMultiple(evt.getX()-newObjectOrigin.x);
3133
delta_h = evtY-newObjectOrigin.y; //gridMultiple(evt.getY()-newObjectOrigin.y);
3134

3135                delta_x = (delta_w<0) ? delta_w: 0;
3136                delta_y = (delta_h<0) ? delta_h : 0;
3137                gg.drawOval( newObjectOrigin.x+delta_x, snapToGridVertically(newObjectOrigin.y+delta_y), Math.abs(delta_w), Math.abs(delta_h));
3138            } else if (newObjectType == ReportElementType.ROUND_RECTANGLE_ELEMENT) {
3139                if (!firstXORDraw) {
3140                    gg.drawRoundRect( newObjectOrigin.x+delta_x, snapToGridVertically(newObjectOrigin.y+delta_y), Math.abs(delta_w), Math.abs(delta_h),20,20);
3141                }
3142                //delta_w = gridMultiple(evt.getX()-newObjectOrigin.x);
3143
//delta_h = gridMultiple(evt.getY()-newObjectOrigin.y);
3144
delta_w = evtX-newObjectOrigin.x; //gridMultiple(evt.getX()-newObjectOrigin.x);
3145
delta_h = evtY-newObjectOrigin.y; //gridMultiple(evt.getY()-newObjectOrigin.y);
3146
delta_x = (delta_w<0) ? delta_w: 0;
3147                delta_y = (delta_h<0) ? delta_h : 0;
3148                //gg.drawRect( snapToGridOrizzontally(newObjectOrigin.x+w_delta_x), snapToGridVertically(newObjectOrigin.y+delta_y), gridMultiple(Math.abs(evt.getX()-newObjectOrigin.x)), gridMultiple(Math.abs(evt.getY()-newObjectOrigin.y)));
3149
gg.drawRoundRect( newObjectOrigin.x+delta_x, snapToGridVertically(newObjectOrigin.y+delta_y), Math.abs(delta_w), Math.abs(delta_h),20,20);
3150            } else {
3151                if (!firstXORDraw) {
3152                    gg.drawRect( newObjectOrigin.x+delta_x, snapToGridVertically(newObjectOrigin.y+delta_y), Math.abs(delta_w), Math.abs(delta_h));
3153                }
3154                //delta_w = gridMultiple(evt.getX()-newObjectOrigin.x);
3155
//delta_h = gridMultiple(evt.getY()-newObjectOrigin.y);
3156
delta_w = evtX-newObjectOrigin.x; //gridMultiple(evt.getX()-newObjectOrigin.x);
3157
delta_h = evtY-newObjectOrigin.y; //gridMultiple(evt.getY()-newObjectOrigin.y);
3158
delta_x = (delta_w<0) ? delta_w: 0;
3159                delta_y = (delta_h<0) ? delta_h : 0;
3160                //gg.drawRect( snapToGridOrizzontally(newObjectOrigin.x+w_delta_x), snapToGridVertically(newObjectOrigin.y+delta_y), gridMultiple(Math.abs(evt.getX()-newObjectOrigin.x)), gridMultiple(Math.abs(evt.getY()-newObjectOrigin.y)));
3161
gg.drawRect( newObjectOrigin.x+delta_x, snapToGridVertically(newObjectOrigin.y+delta_y), Math.abs(delta_w), Math.abs(delta_h));
3162                //gg.drawRect( newObjectOrigin.x+delta_x, newObjectOrigin.y+delta_y, Math.abs(delta_from_origin), Math.abs(evt.getY()-newObjectOrigin.y));
3163
}
3164
3165            firstXORDraw = false;
3166            gg.setPaintMode();
3167
3168            //mouse.x = mouse.x + delta_from_origin;
3169
//mouse.y = evt.getY();
3170
//return;
3171
}
3172        if (selectedElements.size() >0 && newObjectType == ReportElementType.NONE && transformation_origin_end != null) {
3173            int new_transformation_origin_end_x = transformation_origin_end.x;
3174            int new_transformation_origin_end_y = transformation_origin_end.y;
3175
3176            if (transformation_type >=0 && trasforming) {
3177                Graphics gg = jPanelReport.getGraphics();
3178                gg.setXORMode(Color.WHITE);
3179                if (!firstXORDrawTransforming) {
3180                    // redraw old rectangles...
3181
// transformation_origin
3182
// transformation_origin_end
3183
// Pain a rectangle....
3184

3185                    // if no modifications is needed, return...
3186

3187                    //if (this.isSnapToGrid()) {
3188

3189                        new_transformation_origin_end_x = evt.getX();
3190                        new_transformation_origin_end_y = evt.getY();
3191                        
3192                        // New code for snap to grid....
3193
new_transformation_origin_end_x = optimizeX(evt.getX(), transformation_origin.x, transformation_type, (ReportElement)getSelectedElements().elementAt(0));
3194                        new_transformation_origin_end_y = optimizeY(evt.getY(), transformation_origin.y, transformation_type, (ReportElement)getSelectedElements().elementAt(0));
3195                        /*
3196                        if (Math.abs( transformation_origin_end.x - evt.getX())%(getGridSize()*getZoomFactor()) == 0)
3197                            new_transformation_origin_end_x = evt.getX();
3198                        
3199                        if (Math.abs( transformation_origin_end.y - evt.getY() )%(getGridSize()*getZoomFactor()) == 0)
3200                            new_transformation_origin_end_y = evt.getY();
3201                        */

3202                        
3203                        if (new_transformation_origin_end_x == transformation_origin_end.x &&
3204                                new_transformation_origin_end_y == transformation_origin_end.y) {
3205                            return;
3206                        }
3207                        
3208                    //} else {
3209
// new_transformation_origin_end_x = evt.getX();
3210
// new_transformation_origin_end_y = evt.getY();
3211
//}
3212

3213                    Enumeration e = getSelectedElements().elements();
3214                    while (e.hasMoreElements()) {
3215                        ReportElement re = (ReportElement)e.nextElement();
3216                        Rectangle bounds = new Rectangle(getZoomedDim(re.getPosition().x-10)+10,
3217                                getZoomedDim(re.getPosition().y-10)+10,
3218                                getZoomedDim(re.getWidth()),
3219                                getZoomedDim(re.getHeight()));
3220                        // Scale rectangle...
3221
if (transformation_type == TransformationType.TRANSFORMATION_MOVE) {
3222                            // First of all we must see if the resistence was Exceeded...
3223
if (resistenceExceeded) {
3224                                // Change location...
3225
bounds.translate( transformation_origin_end.x-transformation_origin.x,
3226                                        transformation_origin_end.y-transformation_origin.y);
3227                                gg.drawRect(bounds.x-jHorizontalScrollBar.getValue(), bounds.y-jVerticalScrollBar.getValue(),bounds.width, bounds.height );
3228                            }
3229                        } else if (transformation_type == TransformationType.TRANSFORMATION_RESIZE_SE ||
3230                                transformation_type == TransformationType.TRANSFORMATION_RESIZE_S ||
3231                                transformation_type == TransformationType.TRANSFORMATION_RESIZE_E) {
3232                            // Change location...
3233
int x_delta = ( transformation_type == TransformationType.TRANSFORMATION_RESIZE_SE || transformation_type == TransformationType.TRANSFORMATION_RESIZE_E) ? transformation_origin_end.x-transformation_origin.x : 0;
3234                            int y_delta = ( transformation_type == TransformationType.TRANSFORMATION_RESIZE_SE || transformation_type == TransformationType.TRANSFORMATION_RESIZE_S) ? transformation_origin_end.y-transformation_origin.y : 0;
3235                            bounds.setSize( Math.max(0, bounds.width + x_delta),
3236                                    Math.max(0, bounds.height + y_delta));
3237                            gg.drawRect(bounds.x-jHorizontalScrollBar.getValue(), bounds.y-jVerticalScrollBar.getValue(),bounds.width, bounds.height );
3238                        } else if (transformation_type == TransformationType.TRANSFORMATION_RESIZE_NW ||
3239                                transformation_type == TransformationType.TRANSFORMATION_RESIZE_N ||
3240                                transformation_type == TransformationType.TRANSFORMATION_RESIZE_W) {
3241                            // Change location...
3242
int x_delta = ( transformation_type == TransformationType.TRANSFORMATION_RESIZE_NW || transformation_type == TransformationType.TRANSFORMATION_RESIZE_W) ? transformation_origin_end.x-transformation_origin.x : 0;
3243                            int y_delta = ( transformation_type == TransformationType.TRANSFORMATION_RESIZE_NW || transformation_type == TransformationType.TRANSFORMATION_RESIZE_N) ? transformation_origin_end.y-transformation_origin.y : 0;
3244                            int height_grow = Math.min( y_delta,bounds.height);
3245                            int width_grow = Math.min( x_delta,bounds.width);
3246                            bounds.translate(width_grow,height_grow);
3247                            bounds.setSize( bounds.width - width_grow, bounds.height - height_grow);
3248                            gg.drawRect(bounds.x-jHorizontalScrollBar.getValue(), bounds.y-jVerticalScrollBar.getValue(),bounds.width, bounds.height );
3249                        } else if (transformation_type == TransformationType.TRANSFORMATION_RESIZE_NE) {
3250                            // Change location...
3251
int x_delta = Math.max(-bounds.width,(transformation_origin_end.x-transformation_origin.x));
3252                            int y_delta = Math.min(bounds.height, (transformation_origin_end.y-transformation_origin.y) );
3253                            bounds.y += y_delta;
3254                            bounds.height -= y_delta;
3255                            bounds.width += x_delta;
3256                            gg.drawRect(bounds.x-jHorizontalScrollBar.getValue(), bounds.y-jVerticalScrollBar.getValue(),bounds.width, bounds.height );
3257                        } else if (transformation_type == TransformationType.TRANSFORMATION_RESIZE_SW) {
3258                            // Change location...
3259
int x_delta = Math.min(bounds.width, (transformation_origin_end.x-transformation_origin.x) );
3260                            int y_delta = Math.max(-bounds.height,(transformation_origin_end.y-transformation_origin.y));
3261                            bounds.x += x_delta;
3262                            bounds.width -= x_delta;
3263                            bounds.height += y_delta;
3264                            gg.drawRect(bounds.x-jHorizontalScrollBar.getValue(), bounds.y-jVerticalScrollBar.getValue(),bounds.width, bounds.height );
3265                        }
3266                    }
3267                }
3268
3269                    /*
3270                    if (Math.abs( transformation_origin_end.x - evt.getX())%(getGridSize()*getZoomFactor()) == 0)
3271                        transformation_origin_end.x = evt.getX();
3272                    if (Math.abs( transformation_origin_end.y - evt.getY() )%(getGridSize()*getZoomFactor()) == 0)
3273                        transformation_origin_end.y = evt.getY();
3274                     */

3275                transformation_origin_end.x = new_transformation_origin_end_x;
3276                transformation_origin_end.y = new_transformation_origin_end_y;
3277
3278                Enumeration e = getSelectedElements().elements();
3279                while (e.hasMoreElements()) {
3280                    ReportElement re = (ReportElement)e.nextElement();
3281                    Rectangle bounds = new Rectangle(getZoomedDim(re.getPosition().x-10)+10-jHorizontalScrollBar.getValue(),
3282                            getZoomedDim(re.getPosition().y-10)+10-jVerticalScrollBar.getValue(),
3283                            getZoomedDim(re.getWidth()),
3284                            getZoomedDim(re.getHeight()));
3285                    // Scale rectangle...
3286
if (transformation_type == TransformationType.TRANSFORMATION_MOVE) {
3287                        // Change location...
3288
if (Math.abs(transformation_origin_end.x-transformation_origin.x) >5 ||
3289                                Math.abs(transformation_origin_end.y-transformation_origin.y) >5)
3290                            resistenceExceeded = true;
3291                        if (resistenceExceeded) {
3292                            // Search the closest x,y that match a grid intersection...
3293

3294                            int pex = gridMultiple( transformation_origin_end.x-10 )+10;
3295                            int pey = gridMultiple( transformation_origin_end.y-10 )+10;
3296                            int pox = gridMultiple( transformation_origin.x-10 )+10;
3297                            int poy = gridMultiple( transformation_origin.y-10 )+10;
3298
3299                            //System.out.println("x: "+transformation_origin_end + " y:" + transformation_origin_end.y);
3300

3301                            //this.getGraphics().drawOval( grid_multiple_x, grid_multiple_y, 5,5);
3302

3303                            bounds.translate( transformation_origin_end.x-transformation_origin.x,
3304                                    transformation_origin_end.y-transformation_origin.y);
3305                            gg.drawRect(bounds.x, bounds.y,bounds.width, bounds.height );
3306                        }
3307                    } else if (transformation_type == TransformationType.TRANSFORMATION_RESIZE_SE ||
3308                            transformation_type == TransformationType.TRANSFORMATION_RESIZE_S ||
3309                            transformation_type == TransformationType.TRANSFORMATION_RESIZE_E) {
3310                        // Change location...
3311
int x_delta = ( transformation_type == TransformationType.TRANSFORMATION_RESIZE_SE || transformation_type == TransformationType.TRANSFORMATION_RESIZE_E) ? transformation_origin_end.x-transformation_origin.x : 0;
3312                        int y_delta = ( transformation_type == TransformationType.TRANSFORMATION_RESIZE_SE || transformation_type == TransformationType.TRANSFORMATION_RESIZE_S) ? transformation_origin_end.y-transformation_origin.y : 0;
3313                        bounds.setSize( Math.max(0, bounds.width + x_delta),
3314                                Math.max(0, bounds.height + y_delta));
3315                        gg.drawRect(bounds.x, bounds.y,bounds.width, bounds.height );
3316                    } else if (transformation_type == TransformationType.TRANSFORMATION_RESIZE_NW ||
3317                            transformation_type == TransformationType.TRANSFORMATION_RESIZE_N ||
3318                            transformation_type == TransformationType.TRANSFORMATION_RESIZE_W) {
3319                        // Change location...
3320
int x_delta = ( transformation_type == TransformationType.TRANSFORMATION_RESIZE_NW || transformation_type == TransformationType.TRANSFORMATION_RESIZE_W) ? transformation_origin_end.x-transformation_origin.x : 0;
3321                        int y_delta = ( transformation_type == TransformationType.TRANSFORMATION_RESIZE_NW || transformation_type == TransformationType.TRANSFORMATION_RESIZE_N) ? transformation_origin_end.y-transformation_origin.y : 0;
3322                        int height_grow = Math.min( y_delta,bounds.height);
3323                        int width_grow = Math.min( x_delta,bounds.width);
3324                        bounds.translate(width_grow,height_grow);
3325                        bounds.setSize( bounds.width - width_grow, bounds.height - height_grow);
3326                        gg.drawRect(bounds.x, bounds.y,bounds.width, bounds.height );
3327                    } else if (transformation_type == TransformationType.TRANSFORMATION_RESIZE_NE) {
3328                        // Change location...
3329
int x_delta = Math.max(-bounds.width,(transformation_origin_end.x-transformation_origin.x));
3330                        int y_delta = Math.min(bounds.height, (transformation_origin_end.y-transformation_origin.y) );
3331                        bounds.y += y_delta;
3332                        bounds.height -= y_delta;
3333                        bounds.width += x_delta;
3334                        gg.drawRect(bounds.x, bounds.y,bounds.width, bounds.height );
3335                    } else if (transformation_type == TransformationType.TRANSFORMATION_RESIZE_SW) {
3336                        // Change location...
3337
int x_delta = Math.min(bounds.width, (transformation_origin_end.x-transformation_origin.x) );
3338                        int y_delta = Math.max(-bounds.height , (transformation_origin_end.y-transformation_origin.y));
3339                        bounds.x += x_delta;
3340                        bounds.width -= x_delta;
3341                        bounds.height += y_delta;
3342                        gg.drawRect(bounds.x, bounds.y,bounds.width, bounds.height );
3343                    }
3344                }
3345
3346                firstXORDrawTransforming = false;
3347                gg.setPaintMode();
3348            }
3349
3350        }
3351        mouse.x = evt.getX();
3352        mouse.y = evt.getY();
3353
3354    }//GEN-LAST:event_jPanelReportMouseDragged
3355

3356    private void jPanelReportMouseMoved(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jPanelReportMouseMoved
3357
this.jHorizontalRule.setCursorPosition(evt.getX());
3358        this.jVerticalRule.setCursorPosition(evt.getY());
3359        if (mouse == null) mouse = new Point();
3360        if (newObjectType == ReportElementType.NONE && !transforming) {
3361            // Is the mouse over a band line ?...
3362
int bl = evt.getY() + jVerticalScrollBar.getValue();
3363            Enumeration e = report.getBands().elements();
3364            int y= report.getTopMargin();
3365            boolean found=false;
3366            while (!found && e.hasMoreElements()) {
3367                Band band = (Band)e.nextElement();
3368                y += band.getHeight();
3369                if (bl>getZoomedDim(y)+10-3 && bl < getZoomedDim(y)+3+10) {
3370                    jPanelReport.setCursor( hsplit);
3371                    //this.label1.setText("Drag "+band.name);
3372
found = true;
3373                }
3374            }
3375            if (!found && jPanelReport.getCursor() == hsplit) {
3376                jPanelReport.setCursor( Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
3377            }
3378        }
3379
3380        if (selectedElements.size() >0 && newObjectType == ReportElementType.NONE) {
3381            // We are trasformation mode?
3382
{
3383                // Vediamo se siamo sopra la figura...
3384
Enumeration e = selectedElements.elements();
3385                boolean found = false;
3386                boolean sizeall = false;
3387                while (!found && e.hasMoreElements() ) {
3388
3389                    ReportElement selectedRe = (ReportElement)e.nextElement();
3390                    Rectangle grip = new Rectangle(getZoomedDim(selectedRe.position.x-10)-5+10, getZoomedDim(selectedRe.position.y-10)-5+10,
3391                            getZoomedDim(selectedRe.width)+10,getZoomedDim(selectedRe.height)+10);
3392                    Rectangle cursor = new Rectangle(evt.getX()+jHorizontalScrollBar.getValue(),
3393                            evt.getY()+jVerticalScrollBar.getValue(),
3394                            1,1);
3395
3396                    if (cursor.intersects(grip)) {
3397                        sizeall = true;
3398                        // Vediamo se interseca una grip...
3399
grip.width = 5;
3400                        grip.height = 5;
3401
3402                        if (cursor.intersects(grip)) {
3403                            jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.NW_RESIZE_CURSOR ));
3404                            found =true;
3405                            transformation_type = TransformationType.TRANSFORMATION_RESIZE_NW;
3406                        }
3407
3408                        if (!found) {
3409                            grip.x = getZoomedDim(selectedRe.position.x-10+selectedRe.width)+10;
3410                            grip.y = getZoomedDim(selectedRe.position.y-10)+10-5;
3411                            grip.width = 5;
3412                            grip.height = 5;
3413                            if (cursor.intersects(grip)) {
3414                                jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.NE_RESIZE_CURSOR ));
3415                                found =true;
3416                                transformation_type = TransformationType.TRANSFORMATION_RESIZE_NE;
3417                            }
3418                        }
3419
3420                        if (!found) {
3421                            grip.x = getZoomedDim(selectedRe.position.x-10)+10-5;
3422                            grip.y = getZoomedDim(selectedRe.position.y+(selectedRe.height/2)-10)+10-2;
3423                            grip.width = 5;
3424                            grip.height = 5;
3425                            if (cursor.intersects(grip)) {
3426                                jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.W_RESIZE_CURSOR));
3427                                found =true;
3428                                transformation_type = TransformationType.TRANSFORMATION_RESIZE_W;
3429                            }
3430                        }
3431
3432                        if (!found) {
3433                            grip.x = getZoomedDim(selectedRe.position.x-10)+10-5;
3434                            grip.y = getZoomedDim(selectedRe.position.y-10+selectedRe.height)+10;
3435                            grip.width = 5;
3436                            grip.height = 5;
3437                            if (cursor.intersects(grip)) {
3438                                jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.SW_RESIZE_CURSOR));
3439                                found =true;
3440                                transformation_type = TransformationType.TRANSFORMATION_RESIZE_SW;
3441                            }
3442                        }
3443
3444                        if (!found) {
3445                            grip.x = getZoomedDim(selectedRe.position.x+(selectedRe.width/2)-10)+10-2;
3446                            grip.y = getZoomedDim(selectedRe.position.y-10)+10-5;
3447                            grip.width = 5;
3448                            grip.height = 5;
3449                            if (cursor.intersects(grip)) {
3450                                jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.N_RESIZE_CURSOR));
3451                                found =true;
3452                                transformation_type = TransformationType.TRANSFORMATION_RESIZE_N;
3453                            }
3454                        }
3455
3456                        if (!found) {
3457                            grip.x = getZoomedDim(selectedRe.position.x+(selectedRe.width/2)-10)+10-2;
3458                            grip.y = getZoomedDim(selectedRe.position.y+selectedRe.height-10)+10;
3459                            grip.width = 5;
3460                            grip.height = 5;
3461                            if (cursor.intersects(grip)) {
3462                                jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.S_RESIZE_CURSOR));
3463                                found =true;
3464                                transformation_type = TransformationType.TRANSFORMATION_RESIZE_S;
3465                            }
3466                        }
3467
3468                        if (!found) {
3469                            grip.x = getZoomedDim(selectedRe.position.x+selectedRe.width-10)+10;
3470                            grip.y = getZoomedDim(selectedRe.position.y+selectedRe.height-10)+10;
3471                            grip.width = 5;
3472                            grip.height = 5;
3473                            if (cursor.intersects(grip)) {
3474                                jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.SE_RESIZE_CURSOR));
3475                                found =true;
3476                                transformation_type = TransformationType.TRANSFORMATION_RESIZE_SE;
3477                            }
3478                        }
3479
3480                        if (!found) {
3481                            grip.x = getZoomedDim(selectedRe.position.x+selectedRe.width-10)+10;
3482                            grip.y = getZoomedDim(selectedRe.position.y+(selectedRe.height/2)-10)+10-2;
3483                            grip.width = 5;
3484                            grip.height = 5;
3485                            if (cursor.intersects(grip)) {
3486                                jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.E_RESIZE_CURSOR));
3487                                found =true;
3488                                transformation_type = TransformationType.TRANSFORMATION_RESIZE_E;
3489                            }
3490                        }
3491
3492                        if (!found) {
3493                            jPanelReport.setCursor(Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR));
3494
3495                            if (getMainFrame().isEMMActive())
3496                                transformation_type = TransformationType.TRANSFORMATION_NONE;
3497                            else {
3498                                transformation_type = TransformationType.TRANSFORMATION_MOVE;
3499                                resistenceExceeded = false;
3500                            }
3501                        }
3502                    }
3503                }
3504                if (!sizeall) {
3505                    jPanelReport.setCursor(Cursor.getDefaultCursor());
3506                    transformation_type = TransformationType.TRANSFORMATION_NONE;
3507                }
3508            }
3509        }
3510
3511        if (getMainFrame().getProperties().getProperty("ShowToolTipsInDesign","false").equals("true"))
3512        {
3513            Band bbb = getReport().getBandByPosition( getLogicalDim(evt.getY()+jVerticalScrollBar.getValue()-10)+10);
3514            if ( ((ReportPanelToolTip)getReportPanel().createToolTip()).getBand() == null ||
3515                 ((ReportPanelToolTip)getReportPanel().createToolTip()).getBand() != bbb )
3516            {
3517                ((ReportPanelToolTip)getReportPanel().createToolTip()).setBand(bbb);
3518                 getReportPanel().setToolTipText( ((ReportPanelToolTip)getReportPanel().createToolTip()).getTipText());
3519            }
3520        }
3521        else
3522        {
3523            getReportPanel().setToolTipText( null );
3524        }
3525
3526        mouse.x = evt.getX();
3527        mouse.y = evt.getY();
3528
3529
3530
3531    }//GEN-LAST:event_jPanelReportMouseMoved
3532

3533    /* Unuseful...
3534    public String getToolTipByMousePosition(Point position)
3535    {
3536        Point p_to_intersect = new Point(getLogicalDim(position.x+jHorizontalScrollBar.getValue()-10)+10,getLogicalDim(position.y+jVerticalScrollBar.getValue()-10)+10);
3537        for (int i=report.getElements().size()-1; i>=0; --i) {
3538            ReportElement re = (ReportElement)report.getElements().elementAt(i);
3539            if (re.intersects(p_to_intersect)) {
3540               return "Element: " + re.getName()+"\nBand: " + re.getBand().getName();
3541            }
3542        }
3543
3544        Band bbb = getReport().getBandByPosition( getLogicalDim(position.y+jVerticalScrollBar.getValue()-10) );
3545        if (bbb != null)
3546        {
3547             return "Band: " + bbb.getName();
3548        }
3549        return null;
3550    }
3551    */

3552    private void jPanelReportAncestorAdded(javax.swing.event.AncestorEvent JavaDoc evt) {//GEN-FIRST:event_jPanelReportAncestorAdded
3553
// Add your handling code here:
3554
}//GEN-LAST:event_jPanelReportAncestorAdded
3555

3556    /** Getter for property report.
3557     * @return Value of property report.
3558     *
3559     */

3560    public it.businesslogic.ireport.Report getReport() {
3561        return report;
3562    }
3563
3564
3565    /** Getter for property selectedElements.
3566     * @return Value of property selectedElements.
3567     *
3568     */

3569    public java.util.Vector JavaDoc getSelectedElements() {
3570        return selectedElements;
3571    }
3572
3573    /** Setter for property selectedElements.
3574     * @param selectedElements New value of property selectedElements.
3575     *
3576     */

3577    public void setSelectedElements(java.util.Vector JavaDoc selectedElements) {
3578        this.selectedElements = selectedElements;
3579    }
3580
3581    /** Getter for property clipboardObjects.
3582     * @return Value of property clipboardObjects.
3583     *
3584     */

3585    public java.util.Vector JavaDoc getClipboardObjects() {
3586        return clipboardObjects;
3587    }
3588
3589    /** Setter for property clipboardObjects.
3590     * @param clipboardObjects New value of property clipboardObjects.
3591     *
3592     */

3593    public void setClipboardObjects(java.util.Vector JavaDoc clipboardObjects) {
3594        this.clipboardObjects = clipboardObjects;
3595    }
3596
3597    // Variables declaration - do not modify//GEN-BEGIN:variables
3598
private it.businesslogic.ireport.gui.JRulePanel jHorizontalRule;
3599    private javax.swing.JScrollBar JavaDoc jHorizontalScrollBar;
3600    private javax.swing.JMenuItem JavaDoc jMenuItemBandProperties;
3601    private javax.swing.JMenuItem JavaDoc jMenuItemBandProperties1;
3602    private javax.swing.JMenuItem JavaDoc jMenuItemCopy;
3603    private javax.swing.JMenuItem JavaDoc jMenuItemCopyStyle;
3604    private javax.swing.JMenuItem JavaDoc jMenuItemCut;
3605    private javax.swing.JMenuItem JavaDoc jMenuItemDelete;
3606    private javax.swing.JMenuItem JavaDoc jMenuItemElementChartProperties;
3607    private javax.swing.JMenuItem JavaDoc jMenuItemElementCrosstabDesignProperties;
3608    private javax.swing.JMenuItem JavaDoc jMenuItemElementCrosstabProperties;
3609    private javax.swing.JMenuItem JavaDoc jMenuItemElementOpenSubreport;
3610    private javax.swing.JMenuItem JavaDoc jMenuItemElementProperties;
3611    private javax.swing.JMenuItem JavaDoc jMenuItemGroup;
3612    private javax.swing.JMenuItem JavaDoc jMenuItemPaste;
3613    private javax.swing.JMenuItem JavaDoc jMenuItemPasteOnBand;
3614    private javax.swing.JMenuItem JavaDoc jMenuItemPasteStyle;
3615    private javax.swing.JMenuItem JavaDoc jMenuItemPattern;
3616    private javax.swing.JMenuItem JavaDoc jMenuItemTransformStaticText;
3617    private javax.swing.JMenuItem JavaDoc jMenuItemUngroup;
3618    private javax.swing.JPanel JavaDoc jPanel1;
3619    private javax.swing.JPanel JavaDoc jPanelCorner;
3620    private javax.swing.JPanel JavaDoc jPanelHContainerRule;
3621    private javax.swing.JPanel JavaDoc jPanelHScroll;
3622    private it.businesslogic.ireport.gui.JReportPanel jPanelReport;
3623    private javax.swing.JPanel JavaDoc jPanelReportContainer;
3624    private javax.swing.JPanel JavaDoc jPanelSuperContainer;
3625    private javax.swing.JPanel JavaDoc jPanelVRule;
3626    private javax.swing.JPopupMenu JavaDoc jPopupMenuBand;
3627    private javax.swing.JPopupMenu JavaDoc jPopupMenuElement;
3628    private javax.swing.JSeparator JavaDoc jSeparator1;
3629    private javax.swing.JSeparator JavaDoc jSeparator2;
3630    private javax.swing.JSeparator JavaDoc jSeparator3;
3631    private javax.swing.JSeparator JavaDoc jSeparator4;
3632    private javax.swing.JSeparator JavaDoc jSeparator6;
3633    private javax.swing.JTabbedPane JavaDoc jTabbedPane1;
3634    private javax.swing.JScrollBar JavaDoc jVerticalScrollBar;
3635    // End of variables declaration//GEN-END:variables
3636

3637    private Report report;
3638
3639    private int undoIndex = -1;
3640    private Vector undoOperations;
3641    private Vector clipboardObjects;
3642    private Vector selectedElements;
3643
3644    /**
3645     * Zoom factor used in this frame...
3646     */

3647    private double zoomFactor;
3648
3649    /**
3650     * Actual mouse position...
3651     */

3652    private Point mouse = null;
3653
3654    private boolean lensMode;
3655
3656    private int newObjectType;
3657
3658    private boolean showGrid;
3659
3660    private int transformationMinSize;
3661
3662    private boolean snapToGrid;
3663
3664    private int windowID;
3665
3666    /** Utility field used by event firing mechanism. */
3667    private javax.swing.event.EventListenerList JavaDoc listenerList = null;
3668
3669    public JReportPanel getReportPanel() {
3670        return this.jPanelReport;
3671    }
3672    public void drawVoidDoc(Graphics2D g) {
3673        // Paint the background.
3674
g.setColor(new Color(128, 128, 128));
3675        // Fill a very large rectangle. Clipping will only paint what is
3676
// necessary.
3677
g.fillRect(0, 0, 100000, 100000);
3678
3679        // Due to optimize document drawing, we use a cache. Redraw void doc only if it+
3680
// is dirty...
3681
/*
3682        if (!isDocDirty)
3683        {
3684            return;
3685        }
3686         */

3687
3688        //g.clearRect(0,0,offscreenImageDoc.getWidth(), offscreenImageDoc.getHeight());
3689
int horizontal_scroll = jHorizontalScrollBar.getValue();
3690        int vertical_scroll = jVerticalScrollBar.getValue();
3691        int zoomed_width = getZoomedDim(report.getWidth());
3692        int design_height = report.getDesignHeight();
3693        int zoomed_height = getZoomedDim(design_height);
3694
3695
3696        g.setColor(Color.WHITE);
3697        g.fillRect( 10- horizontal_scroll,10-vertical_scroll,zoomed_width , zoomed_height);
3698        g.setColor(Color.BLACK);
3699        g.drawRect( 9-horizontal_scroll, 9-vertical_scroll, zoomed_width,zoomed_height );
3700
3701        // Paint shadow corner top-right
3702
g.setPaint( new TexturePaint( shadowsImages[0], new Rectangle2D.Double( zoomed_width+10-horizontal_scroll,9-vertical_scroll,9,9)));
3703        g.fillRect(zoomed_width+10-horizontal_scroll,9-vertical_scroll,9,9);
3704
3705        // Paint shadow corner top-right
3706
g.setPaint( new TexturePaint( shadowsImages[1], new Rectangle2D.Double( zoomed_width+10-horizontal_scroll,18-vertical_scroll,9,9)));
3707        g.fillRect( zoomed_width+10-horizontal_scroll,18-vertical_scroll, 9,zoomed_height-8);
3708
3709        g.setPaint(new TexturePaint( shadowsImages[2], new Rectangle2D.Double( zoomed_width+10-horizontal_scroll,zoomed_height+10-vertical_scroll,9,9)));
3710        g.fillRect( zoomed_width+10-horizontal_scroll,zoomed_height+10-vertical_scroll,9,9);
3711
3712        g.setPaint(new TexturePaint( shadowsImages[3], new Rectangle2D.Double( 9-horizontal_scroll,zoomed_height+10-vertical_scroll, zoomed_width+2,9)));
3713        g.fillRect( 9-horizontal_scroll,zoomed_height+10-vertical_scroll, zoomed_width+1,9);
3714
3715        g.setPaint(new TexturePaint( shadowsImages[4], new Rectangle2D.Double( 9-horizontal_scroll,zoomed_height+10-vertical_scroll,9,9)));
3716        g.fillRect( 9-horizontal_scroll,zoomed_height+10-vertical_scroll,9,9);
3717
3718        // Draw grid...
3719

3720        g.setColor(new Color(230,230,230));
3721        if (this.isShowGrid()) {
3722            /*
3723            
3724            //g.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT,
3725            // BasicStroke.JOIN_MITER, 1,
3726            // dashPattern, 0));
3727            float[] fArray = {2f,2f};
3728            BasicStroke m_Dashed3 = new BasicStroke(1, BasicStroke.CAP_SQUARE,
3729                    BasicStroke.JOIN_BEVEL, 1.0f, fArray, 0.0f);
3730            g.setStroke(m_Dashed3);
3731
3732            int zoomed_grid_size = getZoomedDim(this.gridSize);
3733            int grid_left = 10+ zoomed_grid_size - horizontal_scroll;
3734            int line_top = 10-vertical_scroll+1;
3735            int line_bottom = getZoomedDim(design_height)+10-vertical_scroll-2;
3736
3737            if (zoomed_grid_size>2) {
3738                int i=1;
3739                grid_left = 10 - horizontal_scroll + getZoomedDim(i*this.gridSize);
3740
3741                while (grid_left < zoomed_width+10-horizontal_scroll) {
3742                    g.drawLine(grid_left, line_top, grid_left, line_bottom);
3743                    i++;
3744                    grid_left = 10 - horizontal_scroll + getZoomedDim(i*this.gridSize);
3745                }
3746            }
3747
3748            int grid_top = 10 - vertical_scroll;
3749            int line_left = 10-horizontal_scroll+1;
3750            int line_right = zoomed_width+10-horizontal_scroll-1;
3751            if (zoomed_grid_size>2) {
3752                int i=1;
3753                grid_top = 10 - vertical_scroll + getZoomedDim(i*this.gridSize);
3754                while (grid_top < line_bottom ) {
3755                    g.drawLine(line_left,grid_top,line_right,grid_top);
3756                    i++;
3757                    grid_top = 10 - vertical_scroll + getZoomedDim(i*this.gridSize);
3758                }
3759            }
3760
3761            
3762             */

3763             Stroke defaultStroke = g.getStroke();
3764            float[] fArray = {2f,2f};
3765            BasicStroke m_Dashed3 = new BasicStroke(1,
3766            BasicStroke.CAP_SQUARE,
3767            BasicStroke.JOIN_BEVEL, 1.0f, fArray, 0.0f);
3768            g.setStroke(m_Dashed3);
3769
3770            int zoomed_grid_size = getZoomedDim(this.getGridSize());
3771
3772            // mGridTexture is a member of type TexturePaint
3773
if ( mGridTexture == null ||
3774            mGridTexture.getImage().getWidth() != zoomed_grid_size ) {
3775            BufferedImage img = new BufferedImage(
3776            zoomed_grid_size, zoomed_grid_size,
3777            BufferedImage.TYPE_INT_RGB );
3778
3779            Graphics2D g2 = img.createGraphics();
3780
3781            g2.setColor(Color.WHITE);
3782            g2.fillRect( 0, 0, zoomed_grid_size,
3783            zoomed_grid_size );
3784
3785            g2.setColor( new Color(230,230,230) );
3786            g2.setStroke( m_Dashed3 );
3787
3788            g2.drawLine( zoomed_grid_size-1, 0,
3789            zoomed_grid_size-1, zoomed_grid_size-1 );
3790            
3791            g2.drawLine( 0, zoomed_grid_size-1,
3792            zoomed_grid_size-1, zoomed_grid_size-1 );
3793
3794            mGridTexture = new TexturePaint( img, new
3795            Rectangle( 10, 10, zoomed_grid_size, zoomed_grid_size ) );
3796
3797            } // if
3798

3799            Paint oldPaint = g.getPaint();
3800            g.setPaint( mGridTexture );
3801
3802            g.translate( -horizontal_scroll, -vertical_scroll);
3803
3804            g.fillRect( 10, 10, zoomed_width-1, zoomed_height-1 );
3805
3806            g.translate( horizontal_scroll, vertical_scroll );
3807
3808            g.setPaint(oldPaint);
3809            g.setStroke(defaultStroke);
3810        }
3811
3812
3813
3814        // Draw document structure lines...
3815
g.setColor(new Color(170,170,255));
3816        // LEFT MARGINE LINE
3817
g.drawLine( getZoomedDim(report.getLeftMargin())+10-horizontal_scroll,
3818                10-vertical_scroll,
3819                getZoomedDim(report.getLeftMargin())+10-horizontal_scroll,
3820                zoomed_height+10-vertical_scroll-2);
3821
3822        // RIGHT MARGIN LINE
3823
g.drawLine(getZoomedDim(report.getWidth()- report.getRightMargin())+10-horizontal_scroll,
3824                10-vertical_scroll,
3825                getZoomedDim(report.getWidth()-report.getRightMargin())+10-horizontal_scroll,
3826                zoomed_height+10-vertical_scroll-2);
3827
3828        g.drawLine( 10-horizontal_scroll,
3829                getZoomedDim(report.getTopMargin())+10-vertical_scroll,
3830                zoomed_width+10-horizontal_scroll-2,
3831                getZoomedDim(report.getTopMargin())+10-vertical_scroll);
3832
3833        g.drawLine( 10-horizontal_scroll,
3834                getZoomedDim(design_height-report.getBottomMargin())+10-vertical_scroll,
3835                zoomed_width+10-horizontal_scroll-2,
3836                getZoomedDim(design_height- report.getBottomMargin())+10-vertical_scroll);
3837
3838        int y=report.getTopMargin();
3839
3840        Band page_header=null;
3841        Band page_footer=null;
3842
3843        Enumeration e = report.getBands().elements();
3844        while (e.hasMoreElements()) {
3845            g.setColor(new Color(170,170,170));
3846            Band band = (Band)e.nextElement();
3847            y += band.getHeight();
3848            g.drawLine( 10-horizontal_scroll,
3849                    getZoomedDim(y)+10-vertical_scroll,
3850                    zoomed_width+10-horizontal_scroll-2,
3851                    getZoomedDim(y)+10-vertical_scroll);
3852
3853            g.setFont( new Font( "Arial", Font.PLAIN, getZoomedDim(20)));
3854            // We must center the text..
3855
int txt_width = g.getFontMetrics().stringWidth(band.getName())/2;
3856            int txt_height = g.getFontMetrics().getHeight()/2;
3857            txt_height -= g.getFontMetrics().getMaxDescent();
3858            g.setColor(new Color(220,220,255));
3859                /*
3860                g.setClip(getZoomedDim(report.getLeftMargin())+10-horizontal_scroll,
3861                          getZoomedDim(y-band.getHeight())+10-vertical_scroll,
3862                          getZoomedDim(report.getWidth()),
3863                          getZoomedDim(band.getHeight()));
3864                 */

3865            //Rectangle orgClipBounds = g.getClipBounds();
3866

3867            Java2DUtil.setClip(g,
3868                    getZoomedDim(report.getLeftMargin())+10-horizontal_scroll,
3869                    getZoomedDim(y-band.getHeight())+10-vertical_scroll,
3870                    getZoomedDim(report.getWidth()),
3871                    getZoomedDim(band.getHeight()));
3872               /*
3873                g.setClip(getZoomedDim(report.getLeftMargin())+10-horizontal_scroll,
3874                          getZoomedDim(y-band.getHeight())+10-vertical_scroll,
3875                          getZoomedDim(report.getWidth()),
3876                          getZoomedDim(band.getHeight()));
3877                */

3878
3879            g.drawString( band.getName(),
3880                    getZoomedDim(report.getWidth()/2)+10-horizontal_scroll - txt_width,
3881                    getZoomedDim(y)+10-vertical_scroll + txt_height - getZoomedDim(band.getHeight()/2) ); //, zoomed_width, getZoomedDim(band.getHeight()
3882
//g.drawLine(0, getZoomedDim(y)+10-vertical_scroll - txt_height - getZoomedDim(band.getHeight()/2), 700,getZoomedDim(y)+10-vertical_scroll - txt_height - getZoomedDim(band.getHeight()/2));
3883
//g.drawLine(0, getZoomedDim(y)+10-vertical_scroll + txt_height - getZoomedDim(band.getHeight()/2), 700,getZoomedDim(y)+10-vertical_scroll + txt_height - getZoomedDim(band.getHeight()/2));
3884

3885            /* g.setClip(null); */
3886
3887            //g.setClip(orgClipBounds);
3888
Java2DUtil.resetClip(g);
3889
3890            if (band.getName().equals("pageHeader")) page_header = band;
3891            if (band.getName().equals("pageFooter")) page_footer = band;
3892        }
3893
3894        // PAint columns...
3895
int y1 = report.getBandYLocation(report.getBandByName("columnHeader") );
3896        int y2 = report.getBandYLocation(page_footer);
3897
3898        for (int i=0; i< report.getColumnCount()-1; ++i) {
3899            int x = 10+getZoomedDim(report.getLeftMargin()+report.getColumnWidth() + i*(report.getColumnWidth()+report.getColumnSpacing()));
3900            //if (i !=0 ) {
3901
//}
3902
if (x<10+zoomed_width)
3903                g.drawLine( x-horizontal_scroll, getZoomedDim(y1)+10-vertical_scroll,
3904                        x-horizontal_scroll, getZoomedDim(y2)+10-vertical_scroll);
3905            x = 10 + getZoomedDim(report.getLeftMargin() + report.getColumnWidth()+report.getColumnSpacing() + i *(report.getColumnWidth()+report.getColumnSpacing()));
3906
3907            if (x<10+zoomed_width)
3908                g.drawLine( x-horizontal_scroll, getZoomedDim(y1)+10-vertical_scroll,
3909                        x-horizontal_scroll, getZoomedDim(y2)+10-vertical_scroll);
3910        }
3911         /*
3912                g.setPen(new Pen(new Color(170,170,255)));
3913                g.drawLine( 10,getZoomedDim(report.topMargin)+10, getZoomedDim(report.getPagesize().x)+10, getZoomedDim(report.topMargin)+10);
3914                g.drawLine( 10,getZoomedDim(report.getDesignHeight())- getZoomedDim(report.topMargin)+10, getZoomedDim(report.getPagesize().x)+10,getZoomedDim(report.getDesignHeight())- getZoomedDim(report.topMargin)+10);
3915          */

3916        // g.setPen(new Pen(Color.BLACK ));
3917

3918        // Draw guide lines...
3919
Stroke oldStroke = g.getStroke();
3920        g.setStroke(jHorizontalRule.getDottedStroke());
3921        g.setColor(Color.BLACK);
3922        g.setXORMode(java.awt.Color.YELLOW);
3923        for (int i=0; i<jHorizontalRule.getGuideLines().size(); ++i)
3924        {
3925            Integer JavaDoc pos = (Integer JavaDoc)jHorizontalRule.getGuideLines().get(i);
3926            int posI = pos.intValue();
3927            // Calc posI....
3928
posI = 10 + (int)(posI*getZoomFactor()) - getHScroll();
3929            g.drawLine(posI, 0,posI,getHeight());
3930        }
3931        
3932        for (int i=0; i<jVerticalRule.getGuideLines().size(); ++i)
3933        {
3934            Integer JavaDoc pos = (Integer JavaDoc)jVerticalRule.getGuideLines().get(i);
3935            int posI = pos.intValue();
3936            // Calc posI....
3937
posI = 10 + (int)(posI*getZoomFactor()) - getVScroll();
3938            g.drawLine(0, posI, getWidth(),posI);
3939        }
3940        g.setPaintMode();
3941        g.setStroke(oldStroke);
3942        
3943        isDocDirty = false;
3944    }
3945
3946    public int getReversedZoomedDim(int dim) {
3947        if (zoomFactor == 1.0) return dim;
3948        return (int)((double)dim/zoomFactor);
3949    }
3950
3951    public int getZoomedDim(int dim) {
3952        if (zoomFactor == 1.0) return dim;
3953        //if (((double)dim*(double)zoom_factor)<0.5) return 1;
3954
// Truncate, don't round!!
3955
return (int)((double)dim*zoomFactor);
3956        //return (int)Math.ceil((double)dim*zoom_factor);
3957
}
3958
3959    public int getLogicalDim(int dim) {
3960        if (zoomFactor == 1.0) return dim;
3961        //if (Math.abs( ((double)dim/(double)zoom_factor)) < 1 &&
3962
// Math.abs( ((double)dim/(double)zoom_factor)) > 0) return 1;
3963
// Truncate, don't round!!
3964
return (int)((double)dim/zoomFactor);
3965        //return (int)Math.ceil((double)dim/zoom_factor);
3966
}
3967
3968    /** Getter for property zoomFactor.
3969     * @return Value of property zoomFactor.
3970     *
3971     */

3972    public double getZoomFactor() {
3973        return zoomFactor;
3974    }
3975
3976    /** Setter for property zoomFactor.
3977     * @param zoomFactor New value of property zoomFactor.
3978     *
3979     */

3980    public void setZoomFactor(double zoomFactor) {
3981
3982        floatingTextAreaFocusLost();
3983        if (getSelectedCrosstabEditorPanel() != null)
3984        {
3985            getSelectedCrosstabEditorPanel().setZoomFactor(zoomFactor);
3986        }
3987        else
3988        {
3989            if (this.zoomFactor != zoomFactor) {
3990                this.zoomFactor = zoomFactor;
3991                this.jPanelReportComponentResized( new java.awt.event.ComponentEvent JavaDoc( jPanelReport,0));
3992                isDocDirty = true;
3993                this.getReportPanel().repaint();
3994                this.jHorizontalRule.repaint();
3995                this.jVerticalRule.repaint();
3996            }
3997        }
3998    }
3999
4000    public void updateAntialiasMode()
4001    {
4002        this.getReportPanel().repaint();
4003    }
4004    public void paintReportPanel(Graphics g) {
4005                /*
4006                redrawAll(offscreen ,null, 0);
4007                g.drawImage( offscreenImage , 0,0, offscreenImage.getWidth(), offscreenImage.getHeight(), (ImageObserver)this);
4008                 */

4009        
4010        try {
4011        Graphics2D g2 = (Graphics2D) g;
4012
4013
4014        if (this.getMainFrame().getProperties().getProperty("Antialias","true").equals("false"))
4015        {
4016
4017            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
4018                    RenderingHints.VALUE_ANTIALIAS_OFF);
4019            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
4020                    RenderingHints.VALUE_STROKE_PURE);
4021            g2.setRenderingHint(RenderingHints.KEY_DITHERING,
4022                    RenderingHints.VALUE_DITHER_DISABLE);
4023        }
4024        else
4025        {
4026
4027            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
4028                    RenderingHints.VALUE_ANTIALIAS_ON);
4029            g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,
4030                    RenderingHints.VALUE_STROKE_DEFAULT);
4031            g2.setRenderingHint(RenderingHints.KEY_DITHERING,
4032                    RenderingHints.VALUE_DITHER_ENABLE);
4033        }
4034
4035        //long start = System.currentTimeMillis();
4036
//int number = 1;
4037
//System.out.println("redrawAll: (clip=" + g2.getClipRect() + ")");
4038
//for(int i=0; i<number; i++)
4039
//{
4040
redrawAll(g2, g2.getClipRect(), 0);
4041        //}
4042
//long stop = System.currentTimeMillis();
4043
//System.out.println(number + " paints took " + ((stop - start) / 1000.0) + " seconds");
4044

4045        } catch (Throwable JavaDoc ex)
4046        {
4047            ex.printStackTrace();
4048        }
4049    }
4050
4051
4052    private void redrawAll(Graphics2D g, Rectangle clipRect, int margin) {
4053        //g.clearRect(0,0,offscreenImage.getWidth(), offscreenImage.getHeight());
4054
//System.out.println("redraw all "+clipRect);
4055
if (clipRect ==null) {
4056            clipRect = new Rectangle(0,0,this.getReport().getWidth(),this.getReport().getDesignHeight());
4057        }
4058
4059        //clipRect.x += jHorizontalScrollBar.getValue();
4060
//clipRect.y += jVerticalScrollBar.getValue();
4061
//g.setClip(clipRect);
4062

4063        g.clearRect(0,0, (int) clipRect.getWidth(), (int) clipRect.getHeight());
4064/*
4065                                 = new Rectangle( getZoomedDim2(clipRect.x-10 - margin)+ margin +10 + jHorizontalScrollBar.getValue(),
4066                                        getZoomedDim2(clipRect.y-10 - margin)+ margin +10 + jVerticalScrollBar.getValue(),
4067                                        getZoomedDim2(clipRect.width-2*margin)+2*margin,
4068                                        getZoomedDim2(clipRect.height-2*margin)+2*margin);
4069 */

4070        Rectangle realRect = new Rectangle(
4071                getReversedZoomedDim(clipRect.x-10-margin+jHorizontalScrollBar.getValue())+ margin +10,
4072                getReversedZoomedDim(clipRect.y-10-margin+jVerticalScrollBar.getValue())+ margin +10,
4073                getReversedZoomedDim(clipRect.width-2*margin)+2*margin,
4074                getReversedZoomedDim(clipRect.height-2*margin)+2*margin);
4075
4076                /*
4077realRect = new Rectangle(
4078  getZoomedDim2(clipRect.x + jHorizontalScrollBar.getValue()) + margin,
4079  getZoomedDim2(clipRect.y + jVerticalScrollBar.getValue()) + margin,
4080  getZoomedDim2(clipRect.width),
4081  getZoomedDim2(clipRect.height));
4082                 */

4083
4084        //g.setPaint(Color.CYAN);
4085
//g.fillRect( 0 ,0,offscreenWidth ,offscreenDimension.height);
4086
//
4087
// 1. Draw the void document...
4088
//g.setClip( realRect );
4089
drawVoidDoc(g);
4090
4091/*
4092                                g.drawImage( offscreenImageDoc , clipRect.x,clipRect.y, clipRect.x + clipRect.width, clipRect.y + clipRect.height,
4093                                                                 clipRect.x,clipRect.y, clipRect.x + clipRect.width, clipRect.y + clipRect.height, (ImageObserver)this);
4094 */

4095        // g.drawImage( offscreenImageDoc , 0,0, offscreenImageDoc.getWidth(), offscreenImageDoc.getHeight(), (ImageObserver)this);
4096
//g.setClip( realRect );
4097
// 2. Draw all Reportelements...
4098
Enumeration e = report.getElements().elements();
4099        while (e.hasMoreElements()) {
4100            ReportElement re = (ReportElement)e.nextElement();
4101            if (re.intersects(realRect) || re instanceof BreakReportElement)
4102                re.drawObject(g, getZoomFactor(), jHorizontalScrollBar.getValue(), jVerticalScrollBar.getValue());
4103        }
4104
4105        // If there's a selected element, draw a corona
4106
if (selectedElements.size()>0) {
4107            //clipRect.x -=5;
4108
//clipRect.y -=5;
4109
//clipRect.width +=10;
4110
//clipRect.height +=10;
4111
e = selectedElements.elements();
4112            boolean master=true;
4113            while (e.hasMoreElements()) {
4114                ReportElement re = (ReportElement)e.nextElement();
4115                if (re.intersects(realRect))
4116                    re.drawCorona( g,getZoomFactor(), jHorizontalScrollBar.getValue(), jVerticalScrollBar.getValue(), master);
4117                master = false;
4118            }
4119        }
4120
4121        //g.setPaint(Color.CYAN);
4122
//g.fillRect(realRect.x, realRect.y, realRect.width-2, realRect.height-2);
4123

4124    }
4125
4126    public MainFrame getMainFrame() {
4127        if (mf != null) return mf;
4128        // Retrieve parent while != MainFrame
4129
Container parent = this.getDesktopPane().getParent();
4130        while (parent != null && !(parent instanceof MainFrame)) {
4131            parent = parent.getParent();
4132        }
4133        if (parent != null) {
4134            mf = (MainFrame)parent;
4135            return mf;
4136        } else
4137            return null;
4138    }
4139
4140    /** Getter for property lensMode.
4141     * @return Value of property lensMode.
4142     *
4143     */

4144    public boolean isLensMode() {
4145        return lensMode;
4146    }
4147
4148    /** Setter for property lensMode.
4149     * @param lensMode New value of property lensMode.
4150     *
4151     */

4152    public void setLensMode(boolean lensMode) {
4153        //
4154
if (this.lensMode == lensMode) return;
4155        if (lensMode == true)
4156            jPanelReport.setCursor( java.awt.Cursor.getDefaultCursor());
4157        else {
4158            //if (getShiftState())
4159
//if (this.is
4160
// panel9.setCursor(cursorminus );
4161
// else
4162
// panel9.setCursor(cursorplus);
4163
}
4164        this.lensMode = lensMode;
4165    }
4166
4167    /** Getter for property newObjectType.
4168     * @return Value of property newObjectType.
4169     *
4170     */

4171    public int getNewObjectType() {
4172        return newObjectType;
4173    }
4174
4175    /** Setter for property newObjectType.
4176     * @param newObjectType New value of property newObjectType.
4177     *
4178     */

4179    public void setNewObjectType(int newObjectType) {
4180
4181
4182        if (this.newObjectType == newObjectType) return;
4183
4184        if (newObjectType == ReportElementType.NONE) {
4185                /*
4186                if (!first_draw2) panel9.createGraphics().drawLines(new Point[]{new Point(ne.x, ne.y),new Point(mouse.x, ne.y),new Point(mouse.x, mouse.y),new Point(ne.x, mouse.y),new Point(ne.x, ne.y)},RasterOp.SOURCE.xorWith(RasterOp.TARGET));
4187                first_draw2 = true;
4188                panel9.setCursor(Cursor.DEFAULT);
4189                ne = null;
4190                 */

4191            jPanelReport.setCursor( java.awt.Cursor.getDefaultCursor());
4192        } else {
4193            jPanelReport.setCursor( java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.CROSSHAIR_CURSOR));
4194        }
4195        this.newObjectType = newObjectType;
4196
4197        for (int i=1; i<jTabbedPane1.getTabCount(); ++i)
4198        {
4199            if ( jTabbedPane1.getComponentAt(i) instanceof CrosstabEditor)
4200            {
4201                CrosstabEditor ce= (CrosstabEditor)jTabbedPane1.getComponentAt(i);
4202                ce.getPanelEditor().setNewObjectType(newObjectType );
4203            }
4204        }
4205    }
4206
4207
4208
4209    public void setSelectedElement(ReportElement el, boolean fireEvent) {
4210        // Cancello le corone attorno a tutti gli elementi selezionati...
4211
boolean makerefreshAll = false;
4212        //if (selectedElements.size() > 0)
4213
makerefreshAll=true;
4214        getSelectedElements().removeAllElements();
4215        // getMainFrame().getElementPropertiesDialog().updateSelection();
4216
/*
4217                while (selectedElements.size() > 0)
4218                {
4219
4220
4221                        ReportElement re = (ReportElement)selectedElements.elementAt(0);
4222                        selectedElements.removeElementAt(0);
4223
4224                        if (makerefreshAll) continue;
4225
4226                        Rectangle rect = new Rectangle(re.position.x-5,re.position.y-5,re.width+10, re.height+10);
4227
4228                        redrawAll(offscreen ,rect,5);
4229                        Rectangle clipRect = new Rectangle(getZoomedDim(re.position.x-10)-5+10-jHorizontalScrollBar.getValue(),
4230                                                                                           getZoomedDim(re.position.y-10)-5+10-jVerticalScrollBar.getValue(),
4231                                                                                           getZoomedDim(re.width)+10,
4232                                                                                           getZoomedDim(re.height)+10);
4233                        jPanelReport.getGraphics().drawImage( offscreenImage ,
4234                                                                      clipRect.x ,clipRect.y, clipRect.width,clipRect.height,
4235                                                                      clipRect.x ,clipRect.y, clipRect.width,clipRect.height,
4236                                                                      (ImageObserver)this);
4237
4238                }
4239                     */

4240
4241        if (el != null) {
4242            Rectangle rect = new Rectangle(el.position.x-5,el.position.y-5,el.width+10, el.height+10);
4243            selectedElements.addElement(el);
4244
4245            getMainFrame().setCutCopyEnabled(true);
4246                        /*
4247                        if (!makerefreshAll)
4248                        {
4249                                redrawAll(offscreen ,rect,5);
4250                                Rectangle clipRect = new Rectangle(getZoomedDim(el.position.x-10)-5+10-jHorizontalScrollBar.getValue(),
4251                                                                                           getZoomedDim(el.position.y-10)-5+10-jVerticalScrollBar.getValue(),
4252                                                                                           getZoomedDim(el.width)+10,
4253                                                                                           getZoomedDim(el.height)+10);
4254
4255                                jPanelReport.getGraphics().drawImage( offscreenImage ,
4256                                                                      clipRect.x ,clipRect.y, clipRect.width,clipRect.height,
4257                                                                      clipRect.x ,clipRect.y, clipRect.width,clipRect.height,
4258                                                                      (ImageObserver)this);
4259                        }
4260                         */

4261        } else {
4262            getMainFrame().setCutCopyEnabled(false);
4263        }
4264        if (makerefreshAll) {
4265            jPanelReport.repaint();
4266        }
4267
4268               /*
4269                MainForm mf = (MainForm)this.getMDIParent();
4270                if (mf != null)
4271                {
4272                        if (mf.isPropertiesOpened())
4273                        {
4274                                        mf.initReportForm();
4275                                        mf.ep.setEelement(this,getSelectedElements());
4276                                        mf.ep.setVisible(true);
4277                        }
4278                }
4279                */

4280
4281        if (fireEvent) {
4282            ReportElementsSelectionEvent rece = new ReportElementsSelectionEvent(this, this.getSelectedElements()) ;
4283
4284            this.fireReportListenerReportElementsSelectionChanged(rece );
4285            getMainFrame().getElementPropertiesDialog().updateSelection();
4286        }
4287    }
4288
4289    public void setSelectedElement(ReportElement el) {
4290        setSelectedElement(el, true);
4291    }
4292
4293    public void fireSelectionChangedEvent() {
4294        ReportElementsSelectionEvent rece = new ReportElementsSelectionEvent(this, this.getSelectedElements()) ;
4295
4296        this.fireReportListenerReportElementsSelectionChanged(rece );
4297        getMainFrame().getElementPropertiesDialog().updateSelection();
4298    }
4299
4300    public void addSelectedElement(ReportElement el) {
4301        addSelectedElement(el, true);
4302    }
4303
4304    public void addSelectedElement(ReportElement el, boolean fireEvent) {
4305        if (selectedElements.contains(el)) return;
4306        //label1.setText("ADDED");
4307
// Faccio una corona non selected attorno al nuovo elemento...
4308
Rectangle rect = new Rectangle(el.position.x-5,el.position.y-5,el.width+10, el.height+10);
4309        selectedElements.addElement(el);
4310                /*
4311                redrawAll(offscreen ,rect,5);
4312                Rectangle clipRect = new Rectangle(getZoomedDim(el.position.x-10)-5+10-jHorizontalScrollBar.getValue(),
4313                                                                        getZoomedDim(el.position.y-10)-5+10-jVerticalScrollBar.getValue(),
4314                                                                        getZoomedDim(el.width)+10,
4315                                                                        getZoomedDim(el.height)+10);
4316                jPanelReport.getGraphics().drawImage( offscreenImage ,
4317                                                                      clipRect.x ,clipRect.y, clipRect.width,clipRect.height,
4318                                                                      clipRect.x ,clipRect.y, clipRect.width,clipRect.height,
4319                                                                      (ImageObserver)this);
4320                 */

4321        jPanelReport.repaint();
4322
4323        if (fireEvent) {
4324            fireSelectionChangedEvent();
4325        }
4326
4327        getMainFrame().setCutCopyEnabled(true);
4328    }
4329
4330    /** Getter for property jPanelReport.
4331     * @return Value of property jPanelReport.
4332     *
4333     */

4334    public it.businesslogic.ireport.gui.JReportPanel getJPanelReport() {
4335        return jPanelReport;
4336    }
4337
4338    /** Setter for property jPanelReport.
4339     * @param jPanelReport New value of property jPanelReport.
4340     *
4341     */

4342    public void setJPanelReport(it.businesslogic.ireport.gui.JReportPanel jPanelReport) {
4343        this.jPanelReport = jPanelReport;
4344    }
4345
4346    /** Getter for property showGrid.
4347     * @return Value of property showGrid.
4348     *
4349     */

4350    public boolean isShowGrid() {
4351        return showGrid;
4352    }
4353
4354    /** Setter for property showGrid.
4355     * @param showGrid New value of property showGrid.
4356     *
4357     */

4358    public void setShowGrid(boolean showGrid) {
4359
4360        if (this.showGrid == showGrid) return;
4361
4362        this.showGrid = showGrid;
4363        isDocDirty = true;
4364        jPanelReport.repaint();
4365    }
4366
4367    /** Getter for property gridSize.
4368     * @return Value of property gridSize.
4369     *
4370     */

4371    public int getGridSize() {
4372        try {
4373            return Integer.parseInt(MainFrame.getMainInstance().getProperties().getProperty("GridSize","10"));
4374        } catch (Exception JavaDoc ex)
4375        {
4376          return 60;
4377        }
4378    }
4379
4380    /** Getter for property transformationMinSize.
4381     * @return Value of property transformationMinSize.
4382     *
4383     */

4384    public int getTransformationMinSize() {
4385        return transformationMinSize;
4386    }
4387
4388    /** Setter for property transformationMinSize.
4389     * @param transformationMinSize New value of property transformationMinSize.
4390     *
4391     */

4392    public void setTransformationMinSize(int transformationMinSize) {
4393        this.transformationMinSize = transformationMinSize;
4394    }
4395
4396    public int snapToGridVertically(int scaledYPoint) {
4397        
4398        int real_o_y = getLogicalDim((int)(scaledYPoint + jVerticalScrollBar.getValue() - 10)) + 10;
4399        
4400        return getZoomedDim(closestXMagneticElement(real_o_y,getGridSize(), jVerticalRule.getGuideLines()) -10)+10-getVScroll();
4401        
4402        /*
4403        if (!isSnapToGrid()) return scaledYPoint;
4404
4405        int vertical_scroll = jVerticalScrollBar.getValue();
4406        int zoomed_grid_size = getZoomedDim(this.getGridSize());
4407        int grid_top = 10+ zoomed_grid_size - vertical_scroll;
4408        int design_height = report.getDesignHeight();
4409        int line_bottom = getZoomedDim(design_height)+10-vertical_scroll-2;
4410
4411        if (zoomed_grid_size>2) {
4412            int i=1;
4413            while (grid_top < line_bottom ) {
4414                if ( Math.abs(grid_top - scaledYPoint) <= zoomed_grid_size/2) {
4415                    return grid_top;
4416                }
4417                i++;
4418                grid_top = 10 - vertical_scroll + getZoomedDim(i*this.getGridSize());
4419            }
4420        }
4421        return scaledYPoint;
4422         */

4423    }
4424
4425    public int snapToGridOrizzontally(int scaledXPoint) {
4426        
4427        int real_o_x = getLogicalDim((int)(scaledXPoint + jHorizontalScrollBar.getValue() - 10)) + 10;
4428        
4429        return getZoomedDim(closestXMagneticElement(real_o_x,getGridSize(), jHorizontalRule.getGuideLines()) -10)+10-getHScroll();
4430        /*
4431        if (!isSnapToGrid()) return scaledXPoint;
4432        // get closest horizontal grid to the
4433        // get closest vetical grid to the
4434        int horizontal_scroll = jHorizontalScrollBar.getValue();
4435        //int vertical_scroll = jVerticalScrollBar.getValue();
4436        int zoomed_width = getZoomedDim(report.getWidth());
4437        //int design_height = report.getDesignHeight();
4438        //int zoomed_height = getZoomedDim(design_height);
4439        int zoomed_grid_size = getZoomedDim(this.getGridSize());
4440        int grid_left = 10+ zoomed_grid_size - horizontal_scroll;
4441
4442        //int line_bottom = getZoomedDim(design_height)+10-vertical_scroll-2;
4443        if (zoomed_grid_size>2) {
4444            int i=1;
4445            while (grid_left < zoomed_width+10-horizontal_scroll) {
4446                if ( Math.abs(grid_left - scaledXPoint) <= zoomed_grid_size/2) {
4447                    return grid_left;
4448                }
4449                i++;
4450                grid_left = 10 - horizontal_scroll + getZoomedDim(i*this.getGridSize());
4451            }
4452        }
4453        return scaledXPoint;
4454         */

4455    }
4456
4457    public int gridMultiple( int zoomedDim) {
4458        if (!isSnapToGrid()) {
4459            return zoomedDim;
4460        }
4461
4462        int zoomedGridSize = getZoomedDim(this.getGridSize());
4463        double val = Math.abs(zoomedDim);
4464        if ( zoomedGridSize > 1.0 ) {
4465            val = Math.floor( ( val + (0.5 * zoomedGridSize)) / zoomedGridSize ) * zoomedGridSize;
4466        }
4467
4468        return (int) ( (zoomedDim >= 0) ? val : -val );
4469    }
4470
4471    // no need for gridMultipleMinues
4472
/*
4473    public int gridMultipleMinus( int zoomedDim) {
4474        // Round ++...
4475        if (!isSnapToGrid()) {
4476            return zoomedDim;
4477        }
4478
4479        int zoomed_grid_size = getZoomedDim(this.gridSize);
4480        int val = Math.abs(zoomedDim);
4481        if (val%zoomed_grid_size == 0) {
4482            return zoomedDim;
4483        }
4484        if( val%zoomed_grid_size <= zoomed_grid_size/2) {
4485            while ( val%zoomed_grid_size != 0) {
4486                val--;
4487            }
4488        }
4489        else {
4490            while ( val%zoomed_grid_size != 0) {
4491                val++;
4492            }
4493        }
4494        return (zoomedDim >= 0) ? val : -val;
4495    }
4496     */

4497
4498
4499    /** Getter for property snapToGrid.
4500     * @return Value of property snapToGrid.
4501     *
4502     */

4503    public boolean isSnapToGrid() {
4504        return snapToGrid;
4505    }
4506
4507    /** Setter for property snapToGrid.
4508     * @param snapToGrid New value of property snapToGrid.
4509     *
4510     */

4511    public void setSnapToGrid(boolean snapToGrid) {
4512        this.snapToGrid = snapToGrid;
4513    }
4514
4515    /** Getter for property isDocDirty.
4516     * @return Value of property isDocDirty.
4517     *
4518     */

4519    public boolean isIsDocDirty() {
4520        return isDocDirty;
4521    }
4522
4523    /** Setter for property isDocDirty.
4524     * @param isDocDirty New value of property isDocDirty.
4525     *
4526     */

4527    public void setIsDocDirty(boolean isDocDirty) {
4528        this.isDocDirty = isDocDirty;
4529    }
4530
4531    public void checkSelection(boolean repaint) {
4532        boolean needRepaint = false;
4533        for (int i=0; i< getSelectedElements().size(); ++i) {
4534            // Delete all objects that don't exists..
4535
ReportElement selected = (ReportElement)getSelectedElements().get(i);
4536            if (!this.getReport().getElements().contains(selected)) {
4537                getSelectedElements().removeElementAt(i);
4538                i--;
4539                needRepaint = true;
4540            }
4541        }
4542        if (repaint && needRepaint) {
4543            jPanelReport.repaint();
4544        }
4545    }
4546
4547    /** Getter for property windowID.
4548     * @return Value of property windowID.
4549     *
4550     */

4551    public int getWindowID() {
4552        return windowID;
4553    }
4554
4555    /** Setter for property windowID.
4556     * @param windowID New value of property windowID.
4557     *
4558     */

4559    public void setWindowID(int windowID) {
4560        this.windowID = windowID;
4561    }
4562
4563    /** Registers ReportListener to receive events.
4564     * @param listener The listener to register.
4565     *
4566     */

4567    public synchronized void addReportListener(it.businesslogic.ireport.gui.event.ReportListener listener) {
4568        if (listenerList == null ) {
4569            listenerList = new javax.swing.event.EventListenerList JavaDoc();
4570        }
4571        listenerList.add(it.businesslogic.ireport.gui.event.ReportListener.class, listener);
4572    }
4573
4574    /** Removes ReportListener from the list of listeners.
4575     * @param listener The listener to remove.
4576     *
4577     */

4578    synchronized void removeReportListener(it.businesslogic.ireport.gui.event.ReportListener listener) {
4579        listenerList.remove(it.businesslogic.ireport.gui.event.ReportListener.class, listener);
4580    }
4581
4582    /** Notifies all registered listeners about the event.
4583     *
4584     * @param event The event to be fired
4585     *
4586     */

4587    public void fireReportListenerReportElementsSelectionChanged(it.businesslogic.ireport.gui.event.ReportElementsSelectionEvent event) {
4588        if (listenerList == null) return;
4589        Object JavaDoc[] listeners = listenerList.getListenerList();
4590        for (int i = listeners.length-2; i>=0; i-=2) {
4591            if (listeners[i]==it.businesslogic.ireport.gui.event.ReportListener.class) {
4592                ((it.businesslogic.ireport.gui.event.ReportListener)listeners[i+1]).reportElementsSelectionChanged(event);
4593            }
4594        }
4595    }
4596
4597    /** Notifies all registered listeners about the event.
4598     *
4599     * @param event The event to be fired
4600     *
4601     */

4602    public void fireReportListenerReportElementsChanged(it.businesslogic.ireport.gui.event.ReportElementChangedEvent event) {
4603        if (listenerList == null) return;
4604        Object JavaDoc[] listeners = listenerList.getListenerList();
4605        for (int i = listeners.length-2; i>=0; i-=2) {
4606            if (listeners[i]==it.businesslogic.ireport.gui.event.ReportListener.class) {
4607                ((it.businesslogic.ireport.gui.event.ReportListener)listeners[i+1]).reportElementsChanged(event);
4608            }
4609        }
4610    }
4611
4612    /** Notifies all registered listeners about the event.
4613     *
4614     * @param event The event to be fired
4615     *
4616     */

4617    public void fireReportListenerReportBandChanged(it.businesslogic.ireport.gui.event.ReportBandChangedEvent event) {
4618        if (listenerList == null) return;
4619        Object JavaDoc[] listeners = listenerList.getListenerList();
4620        for (int i = listeners.length-2; i>=0; i-=2) {
4621            if (listeners[i]==it.businesslogic.ireport.gui.event.ReportListener.class) {
4622                ((it.businesslogic.ireport.gui.event.ReportListener)listeners[i+1]).reportBandChanged(event);
4623            }
4624        }
4625    }
4626
4627
4628        /* Return the operation that must be invoked on undo
4629         * Return null if no undo operation is available
4630         */

4631    public UndoOperation getUndoOperation() {
4632        if (this.undoOperations.size() > 0 && undoIndex >= 0)
4633            return (UndoOperation)this.undoOperations.elementAt(undoIndex);
4634        return null;
4635    }
4636
4637        /* This call "consume" the undo operation and update
4638         * internally the poiter of the undo list...
4639         */

4640    public void undo() {
4641        if (getUndoOperation() != null) {
4642            UndoOperation u = getUndoOperation();
4643            u.undo();
4644            this.undoIndex--;
4645
4646            this.getReport().decrementReportChanges();
4647            getMainFrame().updateOpenedDocumentsList();
4648        }
4649    }
4650
4651        /* This call "consume" the redo operation and update
4652         * internally the poiter of the undo list...
4653         */

4654    public void redo() {
4655        if (getRedoOperation() != null) {
4656            getRedoOperation().redo();
4657            this.undoIndex++;
4658
4659            this.getReport().incrementReportChanges();
4660            getMainFrame().updateOpenedDocumentsList();
4661        }
4662    }
4663
4664        /* Return the redo operation that must be invoked on redo
4665         * Return null if no redo operation is available
4666         */

4667    public UndoOperation getRedoOperation() {
4668        if (this.undoOperations.size() > undoIndex+1)
4669            return (UndoOperation)this.undoOperations.elementAt(undoIndex+1);
4670        return null;
4671    }
4672
4673    public void addUndoOperation(UndoOperation undo) {
4674        // Remove all operations from the index...
4675
while (this.undoOperations.size() > undoIndex+1) {
4676            this.undoOperations.removeElementAt( undoIndex+1 );
4677        }
4678        undoOperations.addElement(undo);
4679        undoIndex++;
4680        
4681        getReport().incrementReportChanges();
4682        
4683        /*
4684        try {
4685            getMainFrame().updateOpenedDocumentsList();
4686        } catch (Exception ex) {
4687            System.out.println( "[1]" + ex);
4688            ex.printStackTrace();
4689        }
4690        */

4691        try {
4692            getMainFrame().updateUndoMenu(this);
4693        } catch (Exception JavaDoc ex) {
4694            System.out.println( "[2]" + ex);
4695            ex.printStackTrace();
4696        }
4697    }
4698
4699    public void deleteSelectedElements() {
4700        // Remove selected elements...
4701
Enumeration e = selectedElements.elements();
4702
4703        DeleteElementsOperation undoOp = new DeleteElementsOperation(this);
4704        Vector deletedElements = new Vector();
4705
4706        while (e.hasMoreElements()) {
4707
4708            ReportElement re = (ReportElement) e.nextElement();
4709            if ( getReport().getElements().contains( re))
4710            {
4711                undoOp.addElement( re, getReport().getElements().indexOf(re));
4712                getReport().getElements().remove( re );
4713                deletedElements.add(re);
4714                if (re instanceof FrameReportElement)
4715                {
4716                    removeSubElements(re, undoOp, deletedElements);
4717                }
4718                if (re instanceof CrosstabReportElement)
4719                {
4720                    removeCrosstabEditor((CrosstabReportElement)re);
4721                }
4722            }
4723            //fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, re , ReportElementChangedEvent.REMOVED));
4724
}
4725
4726        fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, deletedElements, ReportElementChangedEvent.REMOVED ));
4727        this.setSelectedElement(null);
4728        this.addUndoOperation(undoOp);
4729        //selectedElements.removeAllElements();
4730

4731        jPanelReport.repaint();
4732    }
4733
4734    protected void removeSubElements(ReportElement parentElement, DeleteElementsOperation undoOp, Vector deletedElements)
4735    {
4736        for (int i=0; i<getReport().getElements().size(); ++i)
4737        {
4738            ReportElement re = (ReportElement)getReport().getElements().elementAt(i);
4739            if (re.getParentElement() == parentElement)
4740            {
4741                undoOp.addElement( re, getReport().getElements().indexOf(re));
4742                getReport().getElements().remove( re );
4743                i--;
4744                deletedElements.add(re);
4745                if (re instanceof FrameReportElement)
4746                {
4747                    removeSubElements(re, undoOp, deletedElements);
4748                }
4749                if (re instanceof CrosstabReportElement)
4750                {
4751                    removeCrosstabEditor((CrosstabReportElement)re);
4752                }
4753
4754            }
4755        }
4756    }
4757
4758    public void cut() {
4759        Vector copiedElements = new Vector();
4760
4761        Vector tmpSelectedElements = null;
4762        if (getSelectedCrosstabEditorPanel() != null)
4763        {
4764            tmpSelectedElements = getSelectedCrosstabEditorPanel().getSelectedElements();
4765        }
4766        else
4767        {
4768            tmpSelectedElements = this.getSelectedElements();
4769        }
4770
4771        Enumeration e = tmpSelectedElements.elements();
4772        while (e.hasMoreElements()) {
4773            ReportElement er = (ReportElement)e.nextElement();
4774            copiedElements.add(er.cloneMe());
4775        }
4776
4777
4778        if (copiedElements.size() > 0) {
4779            getMainFrame().setClipBoardContent(copiedElements);
4780        }
4781
4782        // Remove selected elements...
4783
if (getSelectedCrosstabEditorPanel() != null)
4784        {
4785            getSelectedCrosstabEditorPanel().deleteSelectedElements();
4786        }
4787        else
4788        {
4789            this.deleteSelectedElements();
4790        }
4791        getMainFrame().updateCutAndPasteMenu(this);
4792
4793    }
4794
4795    public void copy() {
4796        Vector copiedElements = new Vector();
4797
4798        Vector tmpSelectedElements = null;
4799        if (getSelectedCrosstabEditorPanel() != null)
4800        {
4801            tmpSelectedElements = getSelectedCrosstabEditorPanel().getSelectedElements();
4802        }
4803        else
4804        {
4805            tmpSelectedElements = this.getSelectedElements();
4806        }
4807
4808        Enumeration e = tmpSelectedElements.elements();
4809        while (e.hasMoreElements()) {
4810            ReportElement er = (ReportElement)e.nextElement();
4811            if (!(er instanceof CrosstabReportElement))
4812            {
4813                copiedElements.add(er.cloneMe());
4814            }
4815        }
4816        if (copiedElements.size() > 0) {
4817            getMainFrame().setClipBoardContent(copiedElements);
4818        }
4819
4820        getMainFrame().updateCutAndPasteMenu(this);
4821    }
4822
4823    public void paste() {
4824        // Add elements...
4825
pasteHere(null);
4826     }
4827
4828    public void pasteHere(Point p) {
4829        // Add elements...
4830

4831        Enumeration e = getMainFrame().getClipBoard().elements();
4832        ReportElement container = null;
4833
4834        Vector tmpSelectedElements = null;
4835        if (getSelectedCrosstabEditorPanel() != null)
4836        {
4837            tmpSelectedElements = getSelectedCrosstabEditorPanel().getSelectedElements();
4838        }
4839        else
4840        {
4841            tmpSelectedElements = this.getSelectedElements();
4842        }
4843
4844        if (tmpSelectedElements.size() > 0)
4845        {
4846            container = (ReportElement)tmpSelectedElements.elementAt(0);
4847            if (!(container instanceof FrameReportElement))
4848            {
4849                container = null;
4850            }
4851        }
4852
4853        if (getSelectedCrosstabEditorPanel() != null)
4854        {
4855            getSelectedCrosstabEditorPanel().setSelectedElement(null);
4856        }
4857        else
4858        {
4859            setSelectedElement(null);
4860        }
4861
4862        Vector addedElements = new Vector();
4863
4864
4865        int y = 0;
4866        if (p != null){
4867
4868            if (getSelectedCrosstabEditorPanel() != null)
4869            {
4870               y = getSelectedCrosstabEditorPanel().getZoomedDim(p.y-10);
4871            }
4872            else
4873            {
4874               y= getLogicalDim( p.y-10+jVerticalScrollBar.getValue())+10;
4875            }
4876        }
4877
4878        CrosstabReportElement crReportElement = null;
4879        if (getSelectedCrosstabEditorPanel() != null) crReportElement = getSelectedCrosstabEditorPanel().getCrosstabElement();
4880
4881        while (e.hasMoreElements()) {
4882            ReportElement re = ((ReportElement)e.nextElement()).cloneMe();
4883
4884            re.setKey( getNextElementKey(re.getKey()) );
4885
4886
4887            if (getSelectedCrosstabEditorPanel() != null)
4888            {
4889                if (re instanceof BreakReportElement ||
4890                    re instanceof ChartReportElement ||
4891                    re instanceof ChartReportElement2 ||
4892                    re instanceof CrosstabReportElement ||
4893                    re instanceof SubReportElement) continue;
4894                
4895                CrosstabCell cell = null;
4896                if (getSelectedCrosstabEditorPanel().isDefaultCellMode())
4897                {
4898                   cell = getSelectedCrosstabEditorPanel().getWhenNoDataCell();
4899
4900                }
4901                else if (p != null)
4902                {
4903                     cell = getSelectedCrosstabEditorPanel().getCellByPoint(p);
4904                     if (cell == null) cell = (CrosstabCell)getSelectedCrosstabEditorPanel().getCrosstabElement().getCells().elementAt(0);
4905                }
4906                re.setBand(null);
4907                if (re.getCell() != null)
4908                {
4909                    // Update relative position...
4910
re.setRelativePosition(new Point(re.getPosition().x - re.getCell().getLeft()-10,
4911                                                     re.getPosition().y - re.getCell().getTop()-10));
4912                }
4913                else
4914                {
4915                    re.setRelativePosition(new Point(0,0));
4916                }
4917
4918                //System.out.println(re.getRelativePosition());
4919

4920                // Copia da cella a cella...
4921
if (cell != null)
4922                {
4923                    re.setCell(cell);
4924                    re.getPosition().x = re.getRelativePosition().x + re.getCell().getLeft()+10;
4925                    re.getPosition().y = re.getRelativePosition().y + re.getCell().getTop()+10;
4926                }
4927                else if (getSelectedCrosstabEditorPanel().getCrosstabElement().getCells().contains( re.getCell()))
4928                {
4929                    re.getPosition().x += 10;
4930                    re.getRelativePosition().x += 10;
4931                    re.getPosition().y += 10;
4932                    re.getRelativePosition().y += 10;
4933                }
4934                else
4935                {
4936                    cell = (CrosstabCell)getSelectedCrosstabEditorPanel().getCrosstabElement().getCells().elementAt(0);
4937                    re.setCell(cell);
4938                    re.getPosition().x = re.getRelativePosition().x + re.getCell().getLeft()+10;
4939                    re.getPosition().y = re.getRelativePosition().y + re.getCell().getTop()+10;
4940                }
4941
4942            }
4943            else
4944            {
4945                String JavaDoc bandName = (re.getBand() == null) ? "" : re.getBand().getName();
4946                Band b = getReport().getBandByName( bandName );
4947                re.setBand( b );
4948
4949
4950                if (p !=null)
4951                {
4952                    int ylocation = getReport().getBandYLocation( b );
4953                    Band myBand = null;
4954
4955                    Enumeration enum_bands = getReport().getBands().elements();
4956                    while (enum_bands.hasMoreElements()) {
4957                        Band bb = (Band)enum_bands.nextElement();
4958                        if (report.getBandYLocation(bb)+10 <= y) {
4959                            myBand = bb;
4960                        }
4961                    }
4962
4963                    if (myBand == null) return;
4964
4965                    int ylocation2 = getReport().getBandYLocation( myBand );
4966
4967                    Point location = re.getPosition();
4968                    location.y += ylocation2 - ylocation;
4969
4970                    re.setBand( myBand );
4971                    re.setPosition(location);
4972                }
4973                else
4974                {
4975                    if (re.getPosition().y > getReport().getDesignHeight()-getReport().getBottomMargin())
4976                    {
4977                        re.getPosition().y = getReport().getDesignHeight()-1-getReport().getBottomMargin();
4978                    }
4979                    if (b == null) b = getReport().getBandByPosition( re.getPosition().y );
4980                    re.setBand( b );
4981                    java.awt.Point JavaDoc p2 = re.getPosition();
4982                    int add_x = this.getGridSize();
4983                    if (re instanceof BreakReportElement) add_x = 0;
4984                    re.setPosition(new java.awt.Point JavaDoc(p2.x+add_x,p2.y+this.getGridSize()));
4985                }
4986
4987                if (container != null)
4988                {
4989                     re.setBand( container.getBand());
4990                     re.setParentElement( container);
4991                }
4992                else
4993                {
4994                     re.setParentElement( null );
4995                }
4996
4997            }
4998
4999            if (re instanceof CrosstabReportElement)
5000            {
5001                addCrosstabEditor((CrosstabReportElement)re);
5002            }
5003            re.updateBounds();
5004
5005            // We must find the right band to paste into...
5006
//re.setBand( bname );
5007
//
5008

5009            addUndoOperation( new InsertElementOperation(this, crReportElement, re) );
5010
5011            if (getSelectedCrosstabEditorPanel() != null)
5012            {
5013                crReportElement.getElements().addElement(re);
5014                getSelectedCrosstabEditorPanel().addSelectedElement(re);
5015            }
5016            else
5017            {
5018                report.getElements().addElement(re);
5019                addSelectedElement(re, false);
5020            }
5021            addedElements.add(re);
5022        }
5023        fireReportListenerReportElementsChanged(new ReportElementChangedEvent(this, crReportElement, addedElements , ReportElementChangedEvent.ADDED));
5024
5025        if (crReportElement != null)
5026        {
5027            getSelectedCrosstabEditorPanel().fireSelectionChangedEvent();
5028        }
5029        else
5030        {
5031            fireSelectionChangedEvent();
5032        }
5033
5034        getMainFrame().updateCutAndPasteMenu(this);
5035
5036    }
5037
5038    public void openElementPropertiesDialog(){
5039        // If there is at least an element selected, open the properties window...
5040
MainFrame mainFrame = getMainFrame();
5041
5042
5043        if ((getSelectedCrosstabEditorPanel() != null && getSelectedCrosstabEditorPanel().getSelectedElements().size() > 0) ||
5044            getSelectedElements().size() > 0)
5045        {
5046            if (!mainFrame.getElementPropertiesDialog().isVisible()) {
5047                //mainFrame.getElementPropertiesDialog().updateSelection();
5048
mainFrame.getElementPropertiesDialog().setVisible(true);
5049            }
5050        }
5051
5052        if (getSelectedCrosstabEditorPanel() != null) getSelectedCrosstabEditorPanel().requestFocus();
5053        else jPanelReport.requestFocus();
5054    }
5055
5056    public void updateTitle() {
5057
5058        this.setTitle(this.report.getName()+" "+this.report.getWidth()+"x"+this.report.getDesignHeight()+" ["+Misc.nvl(this.report.getFilename(),"unnamed")+"]");
5059
5060    }
5061
5062    /**
5063     *
5064     */

5065    public void bringToFront() {
5066        Enumeration e = this.getSelectedElements().elements();
5067
5068        ChangeEmentsOrderOperation undoOp = new ChangeEmentsOrderOperation(this);
5069
5070        while (e.hasMoreElements()) {
5071            ReportElement element = (ReportElement)e.nextElement();
5072
5073            int oldPosition = getReport().getElements().indexOf(element);
5074            getReport().getElements().remove(element);
5075            getReport().getElements().addElement(element);
5076            int newPosition = getReport().getElements().indexOf(element);
5077            undoOp.addElement(element,oldPosition, newPosition);
5078        }
5079
5080        if (undoOp.getElements().size() > 0) {
5081            addUndoOperation(undoOp);
5082        }
5083        getReportPanel().repaint();
5084        // We must update the tree... the order i changed...
5085
/* TODO */
5086    }
5087
5088    public void sendToBack() {
5089        Enumeration e = this.getSelectedElements().elements();
5090
5091        ChangeEmentsOrderOperation undoOp = new ChangeEmentsOrderOperation(this);
5092
5093        while (e.hasMoreElements()) {
5094            ReportElement element = (ReportElement)e.nextElement();
5095
5096            int oldPosition = getReport().getElements().indexOf(element);
5097            getReport().getElements().remove(element);
5098            if (element.getParentElement() != null)
5099            {
5100                getReport().getElements().insertElementAt( element, getReport().getElements().indexOf(element.getParentElement())+1);
5101            }
5102            else
5103            {
5104                 getReport().getElements().insertElementAt(element,0);
5105            }
5106            int newPosition = 0;
5107            undoOp.addElement(element,oldPosition, newPosition);
5108        }
5109
5110        if (undoOp.getElements().size() > 0) {
5111            addUndoOperation(undoOp);
5112        }
5113        getReportPanel().repaint();
5114        // We must update the tree... the order is changed...
5115
/* TODO */
5116    }
5117
5118    /*
5119    public void makeOperation(int operationType) {
5120        if (getSelectedElements().isEmpty()) return;
5121
5122        Enumeration e = getSelectedElements().elements();
5123        ReportElement re = null;
5124        FormatElementsOperation undoOp = new FormatElementsOperation(this, operationType);
5125
5126        switch (operationType) {
5127            case OperationType.ALIGN_LEFT:
5128                int left= ((ReportElement)getSelectedElements().firstElement()).getPosition().x;
5129
5130                while (e.hasMoreElements()){
5131                    re = (ReportElement)e.nextElement();
5132                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5133                    re.setPosition(new Point(left, re.getPosition().y));
5134                    re.updateBounds();
5135                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5136                    undoOp.addElement(re, oldBounds, newBounds );
5137                }
5138                break;
5139            case OperationType.ALIGN_RIGHT:
5140                int right= ((ReportElement)getSelectedElements().firstElement()).getPosition().x+((ReportElement)getSelectedElements().firstElement()).getWidth();
5141                while (e.hasMoreElements()){
5142                    re = (ReportElement)e.nextElement();
5143                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5144                    re.setPosition(new Point(right-re.getWidth(), re.getPosition().y));
5145                    re.updateBounds();
5146                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5147                    undoOp.addElement(re, oldBounds, newBounds );
5148                }
5149                break;
5150            case OperationType.ALIGN_TOP:
5151                int top= ((ReportElement)getSelectedElements().firstElement()).getPosition().y;
5152                while (e.hasMoreElements()){
5153                    re = (ReportElement)e.nextElement();
5154                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5155                    re.setPosition(new Point(re.getPosition().x, top));
5156                    re.updateBounds();
5157                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5158                    undoOp.addElement(re, oldBounds, newBounds );
5159                }
5160                break;
5161            case OperationType.ALIGN_BOTTOM:
5162                int bottom= ((ReportElement)getSelectedElements().firstElement()).getPosition().y+((ReportElement)getSelectedElements().firstElement()).height;
5163                while (e.hasMoreElements()){
5164                    re = (ReportElement)e.nextElement();
5165                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5166                    re.setPosition(new Point(re.getPosition().x, bottom-re.height));
5167                    re.updateBounds();
5168                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5169                    undoOp.addElement(re, oldBounds, newBounds );
5170                }
5171                break;
5172            case OperationType.ALIGN_HORIZONTAL_AXIS:
5173                re = (ReportElement)getSelectedElements().firstElement();
5174                int center = re.getPosition().y + (re.getHeight()/2);
5175                while (e.hasMoreElements()){
5176                    re = (ReportElement)e.nextElement();
5177                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5178                    re.setPosition(new Point(re.getPosition().x, center-(re.getHeight()/2) ));
5179                    re.updateBounds();
5180                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5181                    undoOp.addElement(re, oldBounds, newBounds );
5182                }
5183                break;
5184            case OperationType.ALIGN_VERTICAL_AXIS:
5185                re = (ReportElement)getSelectedElements().firstElement();
5186                center = re.getPosition().x + (re.getWidth()/2);
5187                while (e.hasMoreElements()){
5188                    re = (ReportElement)e.nextElement();
5189                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5190                    re.setPosition(new Point(center-(re.getWidth()/2), re.getPosition().y));
5191                    re.updateBounds();
5192                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5193                    undoOp.addElement(re, oldBounds, newBounds );
5194                }
5195                break;
5196            case OperationType.ALIGN_CENTER_HORIZONTALLY:
5197            case OperationType.CENTER_IN_BAND_H:
5198                re = (ReportElement)getSelectedElements().firstElement();
5199
5200                while (e.hasMoreElements()){
5201                    re = (ReportElement)e.nextElement();
5202                    center = 10+this.getReport().getWidth()/2;
5203                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5204                    re.setPosition(new Point(center-(re.getWidth()/2), re.getPosition().y));
5205                    re.updateBounds();
5206                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5207                    undoOp.addElement(re, oldBounds, newBounds );
5208                }
5209                break;
5210            case OperationType.ALIGN_CENTER_VERTICALLY:
5211            case OperationType.CENTER_IN_BAND_V:
5212                re = (ReportElement)getSelectedElements().firstElement();
5213                while (e.hasMoreElements()){
5214                    re = (ReportElement)e.nextElement();
5215                    center = this.report.getBandYLocation(re.getBand())+10+re.getBand().getHeight()/2;
5216                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5217                    re.setPosition(new Point(re.getPosition().x, center-(re.getHeight()/2)));
5218                    re.updateBounds();
5219                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5220                    undoOp.addElement(re, oldBounds, newBounds );
5221                }
5222                break;
5223            case OperationType.ALIGN_CENTER:
5224            case OperationType.CENTER_IN_BAND:
5225                re = (ReportElement)getSelectedElements().firstElement();
5226                int centerx = 10+this.getReport().getWidth()/2;
5227                int centery = this.report.getBandYLocation(re.getBand())+10+re.getBand().getHeight()/2;
5228                while (e.hasMoreElements()){
5229                    re = (ReportElement)e.nextElement();
5230                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5231                    re.setPosition(new Point(centerx-(re.getWidth()/2), this.report.getBandYLocation(re.getBand())+10+re.getBand().getHeight()/2-(re.getHeight()/2)));
5232                    re.updateBounds();
5233                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5234                    undoOp.addElement(re, oldBounds, newBounds );
5235                }
5236                break;
5237            case OperationType.SAME_WIDTH:
5238                re = (ReportElement)getSelectedElements().firstElement();
5239                int width = re.getWidth();
5240                while (e.hasMoreElements()){
5241                    re = (ReportElement)e.nextElement();
5242                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5243                    re.trasform(new Point(width-re.getWidth(),0), TransformationType.TRANSFORMATION_RESIZE_SE);
5244                    re.updateBounds();
5245                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5246                    undoOp.addElement(re, oldBounds, newBounds );
5247                }
5248                break;
5249            case OperationType.SAME_WIDTH_MAX:
5250                re = (ReportElement)getSelectedElements().firstElement();
5251                // Looking for the max with...
5252                Enumeration enum2 = getSelectedElements().elements();
5253                width = re.getWidth();
5254                while (enum2.hasMoreElements()) {
5255                    re = (ReportElement)enum2.nextElement();
5256                    if (width <= re.getWidth()) width =re.getWidth();
5257                }
5258                while (e.hasMoreElements()){
5259                    re = (ReportElement)e.nextElement();
5260                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5261                    re.trasform(new Point(width-re.getWidth(),0), TransformationType.TRANSFORMATION_RESIZE_SE);
5262                    re.updateBounds();
5263                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5264                    undoOp.addElement(re, oldBounds, newBounds );
5265                }
5266                break;
5267            case OperationType.SAME_WIDTH_MIN:
5268                re = (ReportElement)getSelectedElements().firstElement();
5269                // Looking for the max with...
5270                enum2 = getSelectedElements().elements();
5271                width = re.getWidth();
5272                while (enum2.hasMoreElements()) {
5273                    re = (ReportElement)enum2.nextElement();
5274                    if (width > re.getWidth()) width =re.getWidth();
5275                }
5276                while (e.hasMoreElements()){
5277                    re = (ReportElement)e.nextElement();
5278                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5279                    re.trasform(new Point(width-re.getWidth(),0), TransformationType.TRANSFORMATION_RESIZE_SE);
5280                    re.updateBounds();
5281                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5282                    undoOp.addElement(re, oldBounds, newBounds );
5283                }
5284                break;
5285            case OperationType.SAME_HEIGHT:
5286                re = (ReportElement)getSelectedElements().firstElement();
5287                int height = re.height;
5288                while (e.hasMoreElements()){
5289                    re = (ReportElement)e.nextElement();
5290                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5291                    re.trasform(new Point(0,height-re.height), TransformationType.TRANSFORMATION_RESIZE_SE);
5292                    re.updateBounds();
5293                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5294                    undoOp.addElement(re, oldBounds, newBounds );
5295                }
5296                break;
5297            case OperationType.SAME_HEIGHT_MAX:
5298                re = (ReportElement)getSelectedElements().firstElement();
5299                height = re.getHeight();
5300                enum2 = getSelectedElements().elements();
5301                while (enum2.hasMoreElements()) {
5302                    re = (ReportElement)enum2.nextElement();
5303                    if (height <= re.getHeight()) height =re.getHeight();
5304                }
5305                while (e.hasMoreElements()){
5306                    re = (ReportElement)e.nextElement();
5307                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5308                    re.trasform(new Point(0,height-re.height), TransformationType.TRANSFORMATION_RESIZE_SE);
5309                    re.updateBounds();
5310                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5311                    undoOp.addElement(re, oldBounds, newBounds );
5312                }
5313                break;
5314            case OperationType.SAME_HEIGHT_MIN:
5315                re = (ReportElement)getSelectedElements().firstElement();
5316                height = re.getHeight();
5317                enum2 = getSelectedElements().elements();
5318                while (enum2.hasMoreElements()) {
5319                    re = (ReportElement)enum2.nextElement();
5320                    if (height > re.getHeight()) height =re.getHeight();
5321                }
5322                while (e.hasMoreElements()){
5323                    re = (ReportElement)e.nextElement();
5324                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5325                    re.trasform(new Point(0,height-re.height), TransformationType.TRANSFORMATION_RESIZE_SE);
5326                    re.updateBounds();
5327                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5328                    undoOp.addElement(re, oldBounds, newBounds );
5329                }
5330                break;
5331            case OperationType.SAME_SIZE:
5332                re = (ReportElement)getSelectedElements().firstElement();
5333                height = re.height;
5334                width = re.getWidth();
5335                while (e.hasMoreElements()){
5336                    re = (ReportElement)e.nextElement();
5337                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5338                    re.trasform(new Point(width-re.getWidth(),height-re.height), TransformationType.TRANSFORMATION_RESIZE_SE);
5339                    re.updateBounds();
5340                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5341                    undoOp.addElement(re, oldBounds, newBounds );
5342                }
5343                break;
5344            case OperationType.ALIGN_TOP_TO_BAND:
5345                while (e.hasMoreElements()){
5346                    re = (ReportElement)e.nextElement();
5347                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5348                    re.trasform(new Point(0,getReport().getBandYLocation( re.band)+10- re.getPosition().y), TransformationType.TRANSFORMATION_MOVE);
5349                    re.updateBounds();
5350                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5351                    undoOp.addElement(re, oldBounds, newBounds );
5352                }
5353                break;
5354
5355            // Begin code Robert Lamping, 12 July 2004
5356            case OperationType.ALIGN_BOTTOM_TO_BAND:
5357                while (e.hasMoreElements()){
5358                    re = (ReportElement)e.nextElement();
5359                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5360                    //re.trasform(new Point(0,getReport().getBandYLocation( re.band)+10- re.getPosition().y), TransformationType.TRANSFORMATION_MOVE);
5361                    re.trasform( new Point(0, getReport().getBandYLocation( re.band)+10 + re.band.getHeight() -
5362                            ( re.getPosition().y + re.getHeight() ) ), TransformationType.TRANSFORMATION_MOVE);
5363                    re.updateBounds();
5364                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5365                    undoOp.addElement(re, oldBounds, newBounds );
5366                }
5367                break;
5368
5369            case OperationType.ALIGN_TO_LEFT_MARGIN:
5370                int leftMargin= getReport().getLeftMargin();
5371                //((ReportElement)getSelectedElements().firstElement()).getPosition().x;
5372
5373                while (e.hasMoreElements()){
5374                    re = (ReportElement)e.nextElement();
5375                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5376                    re.setPosition(new Point(leftMargin + 10, re.getPosition().y));
5377                    re.updateBounds();
5378                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5379                    undoOp.addElement(re, oldBounds, newBounds );
5380                }
5381                break;
5382
5383            case OperationType.ALIGN_TO_RIGHT_MARGIN:
5384                int rightMargin= getReport().getRightMargin();
5385
5386                while (e.hasMoreElements()){
5387                    re = (ReportElement)e.nextElement();
5388                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5389                    re.setPosition(new Point(this.getReport().getWidth() - rightMargin-re.getWidth()+ 10, re.getPosition().y));
5390                    re.updateBounds();
5391                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5392                    undoOp.addElement(re, oldBounds, newBounds );
5393                }
5394                break;
5395            case OperationType.MOVE_TO_LEFT_MARGIN:
5396                // Move all elements to the left over the distance between first element and left margin
5397                re = (ReportElement)getSelectedElements().firstElement();
5398                int deltaLeft = re.getPosition().x - getReport().getLeftMargin();
5399
5400                while (e.hasMoreElements()){
5401                    re = (ReportElement)e.nextElement();
5402                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5403                    re.setPosition(new Point(re.getPosition().x + 10 - deltaLeft, re.getPosition().y));
5404                    re.updateBounds();
5405                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5406                    undoOp.addElement(re, oldBounds, newBounds );
5407                }
5408                break;
5409            // End code Robert Lamping, 12 July 2004
5410            case OperationType.ORGANIZE_AS_A_TABLE:
5411
5412                e = getSelectedElements().elements();
5413                while (e.hasMoreElements()){
5414                    re = (ReportElement)e.nextElement();
5415                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5416                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5417                    undoOp.addElement(re, oldBounds, newBounds );
5418                }
5419
5420                makeOperation( OperationType.ALIGN_TOP_TO_BAND);
5421                // Remove all operations from the index...
5422                while (this.undoOperations.size() > undoIndex) {
5423                    this.undoOperations.removeElementAt( undoIndex);
5424                }
5425                undoIndex--;
5426                this.getReport().decrementDirty();
5427                makeOperation( OperationType.JOIN_LEFT);
5428                // Remove all operations from the index...
5429                while (this.undoOperations.size() > undoIndex) {
5430                    this.undoOperations.removeElementAt( undoIndex);
5431                }
5432                undoIndex--;
5433                this.getReport().decrementDirty();
5434                makeOperation( OperationType.MOVE_TO_LEFT_MARGIN);
5435                // Remove all operations from the index...
5436                while (this.undoOperations.size() > undoIndex) {
5437                    this.undoOperations.removeElementAt( undoIndex);
5438                }
5439                undoIndex--;
5440                this.getReport().decrementDirty();
5441                makeOperation( OperationType.SAME_HEIGHT_MIN);
5442                // Remove all operations from the index...
5443                while (this.undoOperations.size() > undoIndex) {
5444                    this.undoOperations.removeElementAt( undoIndex);
5445                }
5446                undoIndex--;
5447                this.getReport().decrementDirty();
5448                makeOperation( OperationType.INCREASE_SPACE_H);
5449                // Remove all operations from the index...
5450                while (this.undoOperations.size() > undoIndex) {
5451                    this.undoOperations.removeElementAt( undoIndex);
5452                }
5453                undoIndex--;
5454                this.getReport().decrementDirty();
5455
5456                e = getSelectedElements().elements();
5457                int kkk = 0;
5458                while (e.hasMoreElements()){
5459                    re = (ReportElement)e.nextElement();
5460                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5461                    ((ElementTransformation)undoOp.getTransformations().elementAt(kkk)).newBounds = newBounds;
5462                    kkk++;
5463                }
5464                break;
5465            case OperationType.JOIN_LEFT:
5466            case OperationType.REMOVE_SPACE_H:
5467                // 1 Search for all different bands...
5468
5469                Vector used_bands = new Vector();
5470                enum2 = getSelectedElements().elements();
5471                while (enum2.hasMoreElements()) {
5472                    re = (ReportElement)enum2.nextElement();
5473                    if (!used_bands.contains(re.getBand())) {
5474                        used_bands.add(re.getBand());
5475                    }
5476                }
5477                // 2 For any bands, create a vector of elements of this bands order by left position...
5478                // 2b Set positions using the array....
5479                Enumeration bands_enum = used_bands.elements();
5480                while (bands_enum.hasMoreElements()) {
5481
5482                    Band b = (Band)bands_enum.nextElement();
5483
5484                    Vector myElements = new Vector();
5485                    enum2 = getSelectedElements().elements();
5486                    while (enum2.hasMoreElements()) {
5487                        re = (ReportElement)enum2.nextElement();
5488                        if (re.getBand() == b) {
5489                            // insert this element in the right position...
5490                            if (myElements.size() == 0) myElements.add(re);
5491                            else {
5492                                boolean inserted=false;
5493                                for (int i=0; i<myElements.size(); ++i) {
5494                                    ReportElement re2 = (ReportElement)myElements.elementAt(i);
5495                                    if (re.getPosition().x < re2.getPosition().x) {
5496                                        myElements.insertElementAt(re, i);
5497                                        inserted = true;
5498
5499                                        break;
5500                                    }
5501                                }
5502                                if (!inserted)
5503                                    myElements.addElement(re);
5504                            }
5505                        }
5506                    }
5507
5508                    // Repositioning elements...
5509                    int actual_x =0;
5510                    for (int k=0; k<myElements.size(); ++k) {
5511                        re = (ReportElement)myElements.elementAt(k);
5512                        if (k==0) {
5513                            actual_x = ((ReportElement)myElements.elementAt(k)).getPosition().x;
5514                        }
5515
5516                        Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5517                        re.setPosition( new Point(actual_x, re.getPosition().y) );
5518                        actual_x += re.getWidth();
5519                        re.updateBounds();
5520                        Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5521                        undoOp.addElement(re, oldBounds, newBounds );
5522                    }
5523                }
5524                break;
5525            case OperationType.JOIN_RIGHT:
5526
5527                // 1 Search for all different bands...
5528
5529                used_bands = new Vector();
5530                enum2 = getSelectedElements().elements();
5531                while (enum2.hasMoreElements()) {
5532                    re = (ReportElement)enum2.nextElement();
5533                    if (!used_bands.contains(re.getBand())) {
5534                        used_bands.add(re.getBand());
5535                    }
5536                }
5537
5538                // 2 For any bands, create a vector of elements of this bands order by left position...
5539                // 2b Set positions using the array....
5540                bands_enum = used_bands.elements();
5541                while (bands_enum.hasMoreElements()) {
5542
5543                    Band b = (Band)bands_enum.nextElement();
5544                    Vector myElements = new Vector();
5545                    enum2 = getSelectedElements().elements();
5546                    while (enum2.hasMoreElements()) {
5547                        re = (ReportElement)enum2.nextElement();
5548                        if (re.getBand() == b) {
5549                            // insert this element in the right position...
5550                            if (myElements.size() == 0) myElements.add(re);
5551                            else {
5552                                boolean inserted=false;
5553                                for (int i=0; i<myElements.size(); ++i) {
5554                                    ReportElement re2 = (ReportElement)myElements.elementAt(i);
5555                                    if (re.getPosition().x > re2.getPosition().x) {
5556                                        myElements.insertElementAt(re, i);
5557                                        inserted = true;
5558                                        //System.out.println("Inserito re:" + re.getPosition().x + " pos:" + i );
5559                                        break;
5560                                    }
5561                                }
5562                                if (!inserted)
5563                                    myElements.addElement(re);
5564                            }
5565                        }
5566                    }
5567
5568                    // Repositioning elements...
5569                    int actual_x =0;
5570                    for (int k=0; k<myElements.size(); ++k) {
5571                        re = (ReportElement)myElements.elementAt(k);
5572                        if (k==0) {
5573                            actual_x = re.getPosition().x+re.getWidth();
5574                        }
5575
5576                        Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5577                        re.setPosition( new Point(actual_x-re.getWidth(), re.getPosition().y) );
5578                        actual_x -= re.getWidth();
5579                        re.updateBounds();
5580                        Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5581                        undoOp.addElement(re, oldBounds, newBounds );
5582                    }
5583                }
5584                break;
5585            case OperationType.EQUALS_SPACE_H:
5586                // 1. Use an ordered array...
5587                if (getSelectedElements().size() <= 1) break;
5588                Vector myElements = new Vector();
5589
5590                enum2 = getSelectedElements().elements();
5591                while (enum2.hasMoreElements()) {
5592                    re = (ReportElement)enum2.nextElement();
5593                    // insert this element in the right position...
5594                    if (myElements.size() == 0) myElements.add(re);
5595                    else {
5596                        boolean inserted=false;
5597                        for (int i=0; i<myElements.size(); ++i) {
5598                            ReportElement re2 = (ReportElement)myElements.elementAt(i);
5599                            if (re.getPosition().x < re2.getPosition().x) {
5600                                myElements.insertElementAt(re, i);
5601                                inserted = true;
5602                                //System.out.println("Inserito re:" + re.getPosition().x + " pos:" + i );
5603                                break;
5604                            }
5605                        }
5606                        if (!inserted)
5607                            myElements.addElement(re);
5608                    }
5609                }
5610
5611
5612
5613                // Find the rightest element...
5614
5615                int total_width=0;
5616                int available_width=0;
5617                int min_x = 0;
5618                int max_x = 0;
5619                re = (ReportElement)myElements.firstElement();
5620                min_x = re.getPosition().x;
5621                max_x = re.getPosition().x+re.getWidth();
5622                enum2 = myElements.elements();
5623                ReportElement leftElement = re;
5624                ReportElement rightElement = re;
5625                while (enum2.hasMoreElements()) {
5626                    re = (ReportElement)enum2.nextElement();
5627                    if (min_x > re.getPosition().x) {
5628                        min_x =re.getPosition().x;
5629                    }
5630                    if (max_x < re.getPosition().x+re.getWidth()) {
5631                        max_x =re.getPosition().x+re.getWidth();
5632                        rightElement = re;
5633                    }
5634                    available_width += re.getWidth();
5635                }
5636                available_width = max_x - min_x - available_width;
5637                available_width /= myElements.size()-1;
5638                System.out.println("Space: " + available_width);
5639
5640                int actual_x = leftElement.getPosition().x + leftElement.getWidth() + available_width;
5641                e = myElements.elements();
5642                while (e.hasMoreElements()){
5643                    re = (ReportElement)e.nextElement();
5644                    if (re == leftElement) continue;
5645                    if (re == rightElement) continue;
5646
5647                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5648                    re.setPosition(new Point(actual_x, re.getPosition().y) );
5649                    re.updateBounds();
5650                    actual_x += re.getWidth() + available_width;
5651                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5652                    undoOp.addElement(re, oldBounds, newBounds );
5653                }
5654                break;
5655            case OperationType.INCREASE_SPACE_H:
5656                // 1. Use an ordered array...
5657                if (getSelectedElements().size() <= 1) break;
5658                myElements = new Vector();
5659
5660                enum2 = getSelectedElements().elements();
5661                while (enum2.hasMoreElements()) {
5662                    re = (ReportElement)enum2.nextElement();
5663                    // insert this element in the right position...
5664                    if (myElements.size() == 0) myElements.add(re);
5665                    else {
5666                        boolean inserted=false;
5667                        for (int i=0; i<myElements.size(); ++i) {
5668                            ReportElement re2 = (ReportElement)myElements.elementAt(i);
5669                            if (re.getPosition().x < re2.getPosition().x) {
5670                                myElements.insertElementAt(re, i);
5671                                inserted = true;
5672                                //System.out.println("Inserito re:" + re.getPosition().x + " pos:" + i );
5673                                break;
5674                            }
5675                        }
5676                        if (!inserted)
5677                            myElements.addElement(re);
5678                    }
5679                }
5680
5681                e = myElements.elements();
5682
5683                for (int i=1; i< myElements.size(); ++i){
5684                    re = (ReportElement)myElements.elementAt(i);
5685                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5686                    re.setPosition(new Point(re.getPosition().x+5*i, re.getPosition().y) );
5687                    re.updateBounds();
5688                    Rectangle newBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5689                    undoOp.addElement(re, oldBounds, newBounds );
5690                }
5691                break;
5692            case OperationType.DECREASE_SPACE_H:
5693                // 1. Use an ordered array...
5694                if (getSelectedElements().size() <= 1) break;
5695                myElements = new Vector();
5696
5697                enum2 = getSelectedElements().elements();
5698                while (enum2.hasMoreElements()) {
5699                    re = (ReportElement)enum2.nextElement();
5700                    // insert this element in the right position...
5701                    if (myElements.size() == 0) myElements.add(re);
5702                    else {
5703                        boolean inserted=false;
5704                        for (int i=0; i<myElements.size(); ++i) {
5705                            ReportElement re2 = (ReportElement)myElements.elementAt(i);
5706                            if (re.getPosition().x < re2.getPosition().x) {
5707                                myElements.insertElementAt(re, i);
5708                                inserted = true;
5709                                //System.out.println("Inserito re:" + re.getPosition().x + " pos:" + i );
5710                                break;
5711                            }
5712                        }
5713                        if (!inserted)
5714                            myElements.addElement(re);
5715                    }
5716                }
5717
5718                e = myElements.elements();
5719
5720                for (int i=1; i< myElements.size(); ++i){
5721                    re = (ReportElement)myElements.elementAt(i);
5722                    Rectangle oldBounds = new Rectangle( re.getPosition().x, re.getPosition().y, re.getWidth(), re.getHeight());
5723                    re.setPosition(new Point(Math.max( re.getPosition().x-5*i, ((ReportElement)myElements.elementAt(i-1)).getPosition().x), re.getPosition().y) );