Source Code Cross Referenced for SelectionHandler.java in  » Report » pentaho-report » org » pentaho » reportdesigner » crm » report » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » pentaho report » org.pentaho.reportdesigner.crm.report 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:/*
0002: * Copyright 2006-2007 Pentaho Corporation.  All rights reserved.
0003: * This software was developed by Pentaho Corporation and is provided under the terms
0004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
0005: * this  file except in compliance with the license. If you need a copy of the license,
0006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt.
0007: *
0008: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
0009: * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to
0010: * the license for the specific language governing your rights and limitations.
0011: *
0012: * Additional Contributor(s): Martin Schmid gridvision engineering GmbH
0013: */
0014:package org.pentaho.reportdesigner.crm.report;
0015:
0016:import org.jetbrains.annotations.NonNls;
0017:import org.jetbrains.annotations.NotNull;
0018:import org.jetbrains.annotations.Nullable;
0019:import org.pentaho.reportdesigner.crm.report.lineal.GuideLine;
0020:import org.pentaho.reportdesigner.crm.report.lineal.LinealModel;
0021:import org.pentaho.reportdesigner.crm.report.model.BandReportElement;
0022:import org.pentaho.reportdesigner.crm.report.model.BandToplevelReportElement;
0023:import org.pentaho.reportdesigner.crm.report.model.LineDirection;
0024:import org.pentaho.reportdesigner.crm.report.model.LineReportElement;
0025:import org.pentaho.reportdesigner.crm.report.model.ReportElement;
0026:import org.pentaho.reportdesigner.crm.report.model.SubReportElement;
0027:import org.pentaho.reportdesigner.crm.report.model.TextFieldReportElement;
0028:import org.pentaho.reportdesigner.crm.report.util.GraphicUtils;
0029:import org.pentaho.reportdesigner.crm.report.util.ReportElementUtilities;
0030:import org.pentaho.reportdesigner.lib.client.commands.CommandManager;
0031:import org.pentaho.reportdesigner.lib.client.commands.CommandSettings;
0032:import org.pentaho.reportdesigner.lib.client.undo.Undo;
0033:import org.pentaho.reportdesigner.lib.client.util.DoubleDimension;
0034:
0035:import java.awt.*;
0036:import java.awt.event.MouseAdapter;
0037:import java.awt.event.MouseEvent;
0038:import java.awt.event.MouseMotionListener;
0039:import java.awt.geom.Point2D;
0040:import java.awt.geom.Rectangle2D;
0041:import java.util.ArrayList;
0042:import java.util.Arrays;
0043:import java.util.Collections;
0044:import java.util.Comparator;
0045:import java.util.LinkedHashSet;
0046:import java.util.logging.Level;
0047:import java.util.logging.Logger;
0048:
0049:/**
0050: * User: Martin
0051: * Date: 11.10.2005
0052: * Time: 10:56:00
0053: */
0054:public class SelectionHandler
0055:{
0056:    @NonNls
0057:    @NotNull
0058:    private static final Logger LOG = Logger.getLogger(SelectionHandler.class.getName());
0059:
0060:    @NotNull
0061:    private static final Color SELECTION_COLOR = Color.BLUE;
0062:    @NotNull
0063:    private static final Color DONT_SHOW_IN_LAYOUT_SELECTION_COLOR = new Color(0, 0, 255, 50);
0064:
0065:    @NotNull
0066:    private ReportPanel reportPanel;
0067:    @NotNull
0068:    private ReportElementSelectionModel reportElementSelectionModel;
0069:
0070:    @NotNull
0071:    private Point2D.Double pressedPoint;
0072:
0073:    @NotNull
0074:    private Point2D.Double tempPoint;
0075:    private boolean inlineEditingStarted;
0076:
0077:
0078:    private enum AdjustmentState
0079:    {
0080:        @NotNull NONE,
0081:        @NotNull RESIZE_N,
0082:        @NotNull RESIZE_S,
0083:        @NotNull RESIZE_W,
0084:        @NotNull RESIZE_E,
0085:        @NotNull RESIZE_NE,
0086:        @NotNull RESIZE_NW,
0087:        @NotNull RESIZE_SE,
0088:        @NotNull RESIZE_SW,
0089:
0090:        @NotNull MOVE,
0091:    }
0092:
0093:    @NotNull
0094:    private AdjustmentState adjustmentState;
0095:
0096:    @Nullable
0097:    private Rectangle2D.Double selectionRect;
0098:    @Nullable
0099:    private Rectangle2D.Double origSelectionRect;
0100:
0101:    @Nullable
0102:    private Rectangle2D.Double bandInsertionRect;
0103:    @Nullable
0104:    private BandReportElement insertionBand;
0105:
0106:    @Nullable
0107:    private Rectangle2D.Double c1;
0108:    @Nullable
0109:    private Rectangle2D.Double c2;
0110:    @Nullable
0111:    private Rectangle2D.Double c3;
0112:    @Nullable
0113:    private Rectangle2D.Double c4;
0114:
0115:    @Nullable
0116:    private Rectangle2D.Double e1;
0117:    @Nullable
0118:    private Rectangle2D.Double e2;
0119:    @Nullable
0120:    private Rectangle2D.Double e3;
0121:    @Nullable
0122:    private Rectangle2D.Double e4;
0123:
0124:    @Nullable
0125:    private ReportElement lastClickedElementInfo;
0126:
0127:    private boolean selectedInMousePressed;
0128:
0129:    private static final double SNAP_TO_GUIDLINE_THRESHOLD = 8;
0130:
0131:
0132:    public SelectionHandler(@NotNull final ReportPanel reportPanel, @NotNull final ReportElementSelectionModel reportElementSelectionModel)
0133:    {
0134:        this .reportPanel = reportPanel;
0135:        this .reportElementSelectionModel = reportElementSelectionModel;
0136:
0137:        pressedPoint = new Point2D.Double();
0138:
0139:        c1 = new Rectangle2D.Double();
0140:        c2 = new Rectangle2D.Double();
0141:        c3 = new Rectangle2D.Double();
0142:        c4 = new Rectangle2D.Double();
0143:        e1 = new Rectangle2D.Double();
0144:        e2 = new Rectangle2D.Double();
0145:        e3 = new Rectangle2D.Double();
0146:        e4 = new Rectangle2D.Double();
0147:
0148:        adjustmentState = AdjustmentState.NONE;
0149:
0150:        selectedInMousePressed = false;
0151:
0152:        tempPoint = new Point2D.Double();
0153:
0154:        reportElementSelectionModel.addBandElementModelListener(new BandElementModelAdapter()
0155:        {
0156:            public void selectionChanged()
0157:            {
0158:                origSelectionRect = null;
0159:                updateSelectionRects();
0160:            }
0161:
0162:
0163:            public void layoutChanged()
0164:            {
0165:                origSelectionRect = null;
0166:                updateSelectionRects();
0167:            }
0168:        });
0169:
0170:        reportPanel.addMouseListener(new MouseAdapter()
0171:        {
0172:            public void mouseClicked(@NotNull MouseEvent e)
0173:            {
0174:                if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1)
0175:                {
0176:                    if (LOG.isLoggable(Level.FINE)) LOG.log(Level.FINE, "SelectionHandler.mouseClicked e = " + e);
0177:                    if (reportElementSelectionModel.getNonDescendentsSelectedElementInfos().size() == 1)
0178:                    {
0179:                        ReportElement reportElement = reportElementSelectionModel.getNonDescendentsSelectedElementInfos().get(0);
0180:                        if (reportElement.isDescendant(reportPanel.getBandToplevelReportElement()))
0181:                        {
0182:                            reportPanel.startInlineEditing(reportElement, true);
0183:                        }
0184:                    }
0185:                }
0186:            }
0187:        });
0188:
0189:
0190:        reportPanel.addMouseListener(new MouseAdapter()
0191:        {
0192:            public void mousePressed(@NotNull final MouseEvent e)
0193:            {
0194:                if (e.getButton() == MouseEvent.BUTTON1)
0195:                {
0196:                    if (adjustmentState != AdjustmentState.NONE)
0197:                    {
0198:                        adjustmentState = AdjustmentState.NONE;
0199:                        reportPanel.getBandToplevelReportElement().validate();
0200:                        updateSelectionRects();
0201:                        reportPanel.repaint();
0202:                    }
0203:
0204:                    selectedInMousePressed = false;
0205:                    pressedPoint = getModelPoint(e.getPoint(), pressedPoint);
0206:
0207:                    if (reportElementSelectionModel.getNonDescendentsSelectedElementInfos().isEmpty() || !selectionContainsMouseEvent(getModelPoint(e.getPoint(), tempPoint)))
0208:                    {
0209:                        Point2D.Double p = getModelPoint(e.getPoint(), tempPoint);
0210:                        ReportElement nextElementInfo = reportElementSelectionModel.getNextElementInfo(reportPanel.getBandToplevelReportElement(), lastClickedElementInfo, p);
0211:
0212:                        if (nextElementInfo != null)
0213:                        {
0214:                            int onmask = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
0215:                            if ((e.getModifiersEx() & onmask) == onmask)
0216:                            {
0217:                                reportElementSelectionModel.addSelectedElement(nextElementInfo);//indirectly updates selection rects and repaints
0218:                            }
0219:                            else
0220:                            {
0221:                                reportElementSelectionModel.setSelection(Arrays.asList(nextElementInfo));//indirectly updates selection rects and repaints
0222:                            }
0223:
0224:                            if (selectionRect != null)
0225:                            {
0226:                                origSelectionRect = new Rectangle2D.Double();
0227:                                origSelectionRect.setRect(selectionRect);
0228:
0229:                                selectedInMousePressed = true;
0230:                                lastClickedElementInfo = nextElementInfo;
0231:                                adjustmentState = applyAdjustmentStateMouseMoved(getModelPoint(e.getPoint(), tempPoint));
0232:                            }
0233:                        }
0234:                        else
0235:                        {
0236:                            adjustmentState = AdjustmentState.NONE;
0237:                            reportElementSelectionModel.clearSelection();//indirectly updates selection rects and repaints
0238:                            selectedInMousePressed = false;
0239:                        }
0240:                    }
0241:                    else
0242:                    {
0243:                        adjustmentState = applyAdjustmentStateMouseMoved(getModelPoint(e.getPoint(), tempPoint));
0244:                    }
0245:                }
0246:
0247:
0248:                if (e.isPopupTrigger())
0249:                {
0250:                    reportPanel.requestFocus();
0251:                    EventQueue.invokeLater(new Runnable()
0252:                    {
0253:                        public void run()
0254:                        {
0255:                            CommandManager.createCommandPopupMenu(reportPanel.getReportDialog(), reportPanel.getPlace(), CommandSettings.SIZE_16).showPopupMenu(e);
0256:                        }
0257:                    });
0258:                }
0259:            }
0260:
0261:
0262:            public void mouseReleased(@NotNull final MouseEvent e)
0263:            {
0264:                if (inlineEditingStarted)
0265:                {
0266:                    inlineEditingStarted = false;
0267:                    return;
0268:                }
0269:
0270:                BandReportElement insertionBand = SelectionHandler.this .insertionBand;
0271:                if (e.getButton() == MouseEvent.BUTTON1)
0272:                {
0273:                    Undo undo = reportPanel.getReportDialog().getUndo();
0274:                    undo.startTransaction(UndoConstants.MOUSE_RELEASED);
0275:
0276:                    if (selectionRect != null)
0277:                    {
0278:                        origSelectionRect = new Rectangle2D.Double();
0279:                        origSelectionRect.setRect(selectionRect);
0280:                    }
0281:                    else
0282:                    {
0283:                        origSelectionRect = null;
0284:                    }
0285:
0286:                    if (pressedPoint.equals(getModelPoint(e.getPoint(), tempPoint)))
0287:                    {
0288:                        pressedPoint = getModelPoint(e.getPoint(), pressedPoint);
0289:
0290:                        if (!selectedInMousePressed)
0291:                        {
0292:                            if (e.getClickCount() == 1 && reportElementSelectionModel.getSelectedElementInfos().size() == 1 && reportElementSelectionModel.getSelectedElementInfos().get(0) instanceof  TextFieldReportElement)
0293:                            {
0294:                                reportPanel.startInlineEditing(reportElementSelectionModel.getSelectedElementInfos().get(0), false);
0295:                                inlineEditingStarted = true;
0296:                            }
0297:                            else
0298:                            {
0299:                                Point2D.Double p = getModelPoint(e.getPoint(), tempPoint);
0300:
0301:                                ReportElement nextElementInfo = reportElementSelectionModel.getNextElementInfo(reportPanel.getBandToplevelReportElement(), lastClickedElementInfo, p);
0302:                                if (nextElementInfo != null)
0303:                                {
0304:                                    reportElementSelectionModel.clearSelection();
0305:                                    reportElementSelectionModel.addSelectedElement(nextElementInfo);
0306:                                    lastClickedElementInfo = nextElementInfo;
0307:                                    origSelectionRect = new Rectangle2D.Double();
0308:                                    Rectangle2D.Double origSelectionRect = new Rectangle2D.Double();
0309:                                    origSelectionRect.setRect(nextElementInfo.getRectangle());
0310:                                    ReportElementUtilities.convertRectangle(origSelectionRect, nextElementInfo, null);
0311:                                    adjustmentState = applyAdjustmentStateMouseMoved(getModelPoint(e.getPoint(), tempPoint));
0312:
0313:                                    SelectionHandler.this .origSelectionRect = origSelectionRect;
0314:                                }
0315:                                else
0316:                                {
0317:                                    adjustmentState = AdjustmentState.NONE;
0318:                                    reportElementSelectionModel.clearSelection();
0319:                                    lastClickedElementInfo = null;
0320:                                }
0321:                            }
0322:                        }
0323:                    }
0324:                    else if (adjustmentState != AdjustmentState.NONE)
0325:                    {
0326:                        ArrayList<ReportElement> selectedElementInfos = reportElementSelectionModel.getNonDescendentsSelectedElementInfos();
0327:                        ArrayList<Rectangle2D.Double> newRects = new ArrayList<Rectangle2D.Double>();
0328:                        for (ReportElement reportElement : selectedElementInfos)
0329:                        {
0330:                            Rectangle2D.Double rect = new Rectangle2D.Double();//converted
0331:                            rect.setRect(reportElement.getRectangle());
0332:                            ReportElementUtilities.convertRectangle(rect, reportElement, null);
0333:
0334:                            double x = Math.max(0, rect.x);
0335:                            double y = Math.max(0, rect.y);
0336:                            double width = Math.min(reportPanel.getReport().getPageDefinition().getInnerPageSize().getWidth(), rect.width);
0337:                            double height = Math.min(reportPanel.getReport().getPageDefinition().getInnerPageSize().getHeight(), rect.height);
0338:                            x = Math.min(x, reportPanel.getReport().getPageDefinition().getInnerPageSize().getWidth() - width);
0339:                            y = Math.min(y, reportPanel.getReport().getPageDefinition().getInnerPageSize().getHeight() - height);
0340:                            newRects.add(new Rectangle2D.Double(x, y, width, height));
0341:                        }
0342:
0343:                        if (insertionBand == null)
0344:                        {
0345:                            for (int i = 0; i < selectedElementInfos.size(); i++)
0346:                            {
0347:                                ReportElement reportElement = selectedElementInfos.get(i);
0348:                                Rectangle2D.Double rect = newRects.get(i);
0349:
0350:                                if (reportElement.getParent() instanceof  BandReportElement)
0351:                                {
0352:                                    reportPanel.getBandToplevelReportElement().addChild(reportElement);
0353:                                }
0354:
0355:                                reportElement.setMinimumSize(new DoubleDimension(rect.width, rect.height));
0356:                                reportElement.setPosition(new Point2D.Double(rect.x, rect.y));
0357:                            }
0358:                        }
0359:                        else
0360:                        {
0361:                            for (int i = 0; i < selectedElementInfos.size(); i++)
0362:                            {
0363:                                ReportElement reportElement = selectedElementInfos.get(i);
0364:                                Rectangle2D.Double rect = newRects.get(i);
0365:                                reportElement.setMinimumSize(new DoubleDimension(rect.width, rect.height));
0366:
0367:                                Point2D.Double position = new Point2D.Double(rect.x, rect.y);
0368:                                ReportElementUtilities.convertPointToInner(position, insertionBand, null);
0369:
0370:                                ReportElement parent = reportElement.getParent();
0371:                                if (parent != null)
0372:                                {
0373:                                    parent.removeChild(reportElement);
0374:                                    reportElement.setPosition(position);
0375:                                    insertionBand.addChild(reportElement);
0376:                                }
0377:                            }
0378:                        }
0379:                    }
0380:
0381:                    applyAdjustmentStateMouseMoved(getModelPoint(e.getPoint(), tempPoint));
0382:                    SelectionHandler.this .adjustmentState = AdjustmentState.NONE;
0383:
0384:                    updateSubReportElements();
0385:
0386:                    undo.endTransaction();
0387:                }
0388:
0389:                if (e.isPopupTrigger())
0390:                {
0391:                    reportPanel.requestFocus();
0392:                    EventQueue.invokeLater(new Runnable()
0393:                    {
0394:                        public void run()
0395:                        {
0396:                            CommandManager.createCommandPopupMenu(reportPanel.getReportDialog(), reportPanel.getPlace(), CommandSettings.SIZE_16).showPopupMenu(e);
0397:                        }
0398:                    });
0399:                }
0400:
0401:                repaintInsertionRect();
0402:                bandInsertionRect = null;
0403:                SelectionHandler.this .insertionBand = null;
0404:            }
0405:
0406:
0407:            public void mouseClicked(@NotNull MouseEvent e)
0408:            {
0409:            }
0410:
0411:
0412:            public void mouseExited(@NotNull MouseEvent e)
0413:            {
0414:            }
0415:        });
0416:
0417:
0418:        reportPanel.addMouseMotionListener(new MouseMotionListener()
0419:        {
0420:            public void mouseDragged(@NotNull MouseEvent e)
0421:            {
0422:                if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK)
0423:                {
0424:                    if (adjustmentState == AdjustmentState.NONE)
0425:                    {
0426:                        return;
0427:                    }
0428:                    else
0429:                    {
0430:                        reportPanel.stopInlineEditing();
0431:
0432:                        ArrayList<ReportElement> selectedElementInfos = reportElementSelectionModel.getNonDescendentsSelectedElementInfos();
0433:
0434:                        double sf = reportPanel.getScaleFactor();
0435:                        Point2D.Double p = getModelPoint(e.getPoint(), tempPoint);
0436:
0437:                        BandReportElement bandReportElement = ReportElementUtilities.getDeepestBandReportElement(p, reportPanel.getBandToplevelReportElement(), selectedElementInfos);
0438:                        if (bandReportElement != null)
0439:                        {
0440:                            bandInsertionRect = bandReportElement.getReportLayoutManager().getDestinationRect(bandReportElement, selectedElementInfos);
0441:                            insertionBand = bandReportElement;
0442:                            repaintInsertionRect();
0443:                        }
0444:                        else
0445:                        {
0446:                            repaintInsertionRect();
0447:                            bandInsertionRect = null;
0448:                            insertionBand = null;
0449:                        }
0450:
0451:                        if (adjustmentState == AdjustmentState.MOVE)
0452:                        {
0453:                            checkGuidlinesForTopLine(p, sf, reportPanel);
0454:                            checkGuidlinesForBottomLine(p, sf, reportPanel);
0455:                            checkGuidlinesForLeftLine(p, sf, reportPanel);
0456:                            checkGuidlinesForRightLine(p, sf, reportPanel);
0457:
0458:                            checkPageBorderForLeftLine(p);
0459:                            checkPageBorderForRightLine(p);
0460:                            checkPageForTopBorder(p);
0461:                            checkPageForBottomBorder(p);
0462:
0463:                            for (ReportElement elementInfo : selectedElementInfos)
0464:                            {
0465:                                Rectangle2D.Double origRectangle = elementInfo.getOrigRectangle();
0466:
0467:                                double x = origRectangle.x + (p.getX() - pressedPoint.getX());
0468:                                double y = origRectangle.y + (p.getY() - pressedPoint.getY());
0469:                                double w = origRectangle.width;
0470:                                double h = origRectangle.height;
0471:
0472:                                repaintPanels(elementInfo, sf, x, y, w, h, reportElementSelectionModel);
0473:                            }
0474:                        }
0475:                        else if (adjustmentState == AdjustmentState.RESIZE_N)
0476:                        {
0477:                            checkGuidlinesForTopLine(p, sf, reportPanel);
0478:
0479:                            checkPageForTopBorder(p);
0480:
0481:                            for (ReportElement elementInfo : selectedElementInfos)
0482:                            {
0483:                                Rectangle2D.Double origRectangle = elementInfo.getOrigRectangle();
0484:                                double x = origRectangle.x;
0485:                                double y = Math.min(origRectangle.y + origRectangle.height, origRectangle.y + (p.getY() - pressedPoint.getY()));
0486:                                double w = origRectangle.width;
0487:                                double h = Math.max(0, origRectangle.height - (p.getY() - pressedPoint.getY()));
0488:
0489:                                repaintPanels(elementInfo, sf, x, y, w, h, reportElementSelectionModel);
0490:                            }
0491:                        }
0492:                        else if (adjustmentState == AdjustmentState.RESIZE_S)
0493:                        {
0494:                            checkGuidlinesForBottomLine(p, sf, reportPanel);
0495:
0496:                            checkPageForBottomBorder(p);
0497:
0498:                            for (ReportElement elementInfo : selectedElementInfos)
0499:                            {
0500:                                Rectangle2D.Double origRectangle = elementInfo.getOrigRectangle();
0501:                                double x = origRectangle.x;
0502:                                double y = origRectangle.y;
0503:                                double w = origRectangle.width;
0504:                                double h = Math.max(0, origRectangle.height + (p.getY() - pressedPoint.getY()));
0505:
0506:                                repaintPanels(elementInfo, sf, x, y, w, h, reportElementSelectionModel);
0507:                            }
0508:                        }
0509:                        else if (adjustmentState == AdjustmentState.RESIZE_W)
0510:                        {
0511:                            checkGuidlinesForLeftLine(p, sf, reportPanel);
0512:
0513:                            checkPageBorderForLeftLine(p);
0514:
0515:                            for (ReportElement elementInfo : selectedElementInfos)
0516:                            {
0517:                                Rectangle2D.Double origRectangle = elementInfo.getOrigRectangle();
0518:                                double x = Math.min(origRectangle.x + origRectangle.width, origRectangle.x + (p.getX() - pressedPoint.getX()));
0519:                                double y = origRectangle.y;
0520:                                double w = Math.max(0, origRectangle.width - (p.getX() - pressedPoint.getX()));
0521:                                double h = origRectangle.height;
0522:
0523:                                repaintPanels(elementInfo, sf, x, y, w, h, reportElementSelectionModel);
0524:                            }
0525:                        }
0526:                        else if (adjustmentState == AdjustmentState.RESIZE_E)
0527:                        {
0528:                            checkGuidlinesForRightLine(p, sf, reportPanel);
0529:
0530:                            checkPageBorderForRightLine(p);
0531:
0532:                            for (ReportElement elementInfo : selectedElementInfos)
0533:                            {
0534:                                Rectangle2D.Double origRectangle = elementInfo.getOrigRectangle();
0535:                                double x = origRectangle.x;
0536:                                double y = origRectangle.y;
0537:                                double w = Math.max(0, origRectangle.width + (p.getX() - pressedPoint.getX()));
0538:                                double h = origRectangle.height;
0539:
0540:                                repaintPanels(elementInfo, sf, x, y, w, h, reportElementSelectionModel);
0541:                            }
0542:                        }
0543:                        else if (adjustmentState == AdjustmentState.RESIZE_NE)
0544:                        {
0545:                            checkGuidlinesForTopLine(p, sf, reportPanel);
0546:                            checkGuidlinesForRightLine(p, sf, reportPanel);
0547:
0548:                            checkPageBorderForRightLine(p);
0549:                            checkPageForTopBorder(p);
0550:
0551:                            for (ReportElement elementInfo : selectedElementInfos)
0552:                            {
0553:                                Rectangle2D.Double origRectangle = elementInfo.getOrigRectangle();
0554:                                double x = origRectangle.x;
0555:                                double y = Math.min(origRectangle.y + origRectangle.height, origRectangle.y + (p.getY() - pressedPoint.getY()));
0556:                                double w = Math.max(0, origRectangle.width + (p.getX() - pressedPoint.getX()));
0557:                                double h = Math.max(0, origRectangle.height - (p.getY() - pressedPoint.getY()));
0558:
0559:                                repaintPanels(elementInfo, sf, x, y, w, h, reportElementSelectionModel);
0560:                            }
0561:                        }
0562:                        else if (adjustmentState == AdjustmentState.RESIZE_NW)
0563:                        {
0564:                            checkGuidlinesForTopLine(p, sf, reportPanel);
0565:                            checkGuidlinesForLeftLine(p, sf, reportPanel);
0566:
0567:                            checkPageBorderForLeftLine(p);
0568:                            checkPageForTopBorder(p);
0569:
0570:                            for (ReportElement elementInfo : selectedElementInfos)
0571:                            {
0572:                                Rectangle2D.Double origRectangle = elementInfo.getOrigRectangle();
0573:                                double x = Math.min(origRectangle.x + origRectangle.width, origRectangle.x + (p.getX() - pressedPoint.getX()));
0574:                                double y = Math.min(origRectangle.y + origRectangle.height, origRectangle.y + (p.getY() - pressedPoint.getY()));
0575:                                double w = Math.max(0, origRectangle.width - (p.getX() - pressedPoint.getX()));
0576:                                double h = Math.max(0, origRectangle.height - (p.getY() - pressedPoint.getY()));
0577:
0578:                                repaintPanels(elementInfo, sf, x, y, w, h, reportElementSelectionModel);
0579:                            }
0580:                        }
0581:                        else if (adjustmentState == AdjustmentState.RESIZE_SE)
0582:                        {
0583:                            checkGuidlinesForBottomLine(p, sf, reportPanel);
0584:                            checkGuidlinesForRightLine(p, sf, reportPanel);
0585:
0586:                            checkPageBorderForRightLine(p);
0587:                            checkPageForBottomBorder(p);
0588:
0589:                            for (ReportElement elementInfo : selectedElementInfos)
0590:                            {
0591:                                Rectangle2D.Double origRectangle = elementInfo.getOrigRectangle();
0592:                                double x = origRectangle.x;
0593:                                double y = origRectangle.y;
0594:                                double w = Math.max(0, origRectangle.width + (p.getX() - pressedPoint.getX()));
0595:                                double h = Math.max(0, origRectangle.height + (p.getY() - pressedPoint.getY()));
0596:
0597:                                repaintPanels(elementInfo, sf, x, y, w, h, reportElementSelectionModel);
0598:                            }
0599:                        }
0600:                        else if (adjustmentState == AdjustmentState.RESIZE_SW)
0601:                        {
0602:                            checkGuidlinesForBottomLine(p, sf, reportPanel);
0603:                            checkGuidlinesForLeftLine(p, sf, reportPanel);
0604:
0605:                            checkPageBorderForLeftLine(p);
0606:                            checkPageForBottomBorder(p);
0607:
0608:                            for (ReportElement elementInfo : selectedElementInfos)
0609:                            {
0610:                                Rectangle2D.Double origRectangle = elementInfo.getOrigRectangle();
0611:                                double x = Math.min(origRectangle.x + origRectangle.width, origRectangle.x + (p.getX() - pressedPoint.getX()));
0612:                                double y = origRectangle.y;
0613:                                double w = Math.max(0, origRectangle.width - (p.getX() - pressedPoint.getX()));
0614:                                double h = Math.max(0, origRectangle.height + (p.getY() - pressedPoint.getY()));
0615:
0616:                                repaintPanels(elementInfo, sf, x, y, w, h, reportElementSelectionModel);
0617:                            }
0618:                        }
0619:                    }
0620:
0621:                    updateSelectionRects();
0622:                }
0623:            }
0624:
0625:
0626:            public void mouseMoved(@NotNull MouseEvent e)
0627:            {
0628:                applyAdjustmentStateMouseMoved(getModelPoint(e.getPoint(), tempPoint));
0629:            }
0630:
0631:        });
0632:
0633:
0634:    }
0635:
0636:
0637:    public void updateSubReportElements()
0638:    {
0639:        ArrayList<SubReportElement> subReportElements = new ArrayList<SubReportElement>();
0640:        ArrayList<ReportElement> elementArrayList = reportPanel.getBandToplevelReportElement().getChildren();
0641:        double maxElementY = 0;
0642:        for (ReportElement reportElement : elementArrayList)
0643:        {
0644:            if (reportElement instanceof  SubReportElement)
0645:            {
0646:                SubReportElement subReportElement = (SubReportElement) reportElement;
0647:                subReportElements.add(subReportElement);
0648:            }
0649:            else
0650:            {
0651:                maxElementY = Math.max(maxElementY, reportElement.getRectangle().y + reportElement.getRectangle().height);
0652:            }
0653:        }
0654:
0655:        int startY = (int) (maxElementY + 1);
0656:
0657:        Collections.sort(subReportElements, new Comparator<SubReportElement>()
0658:        {
0659:            public int compare(@NotNull SubReportElement o1, @NotNull SubReportElement o2)
0660:            {
0661:                return o1.getRectangle().y < o2.getRectangle().y ? -1 : o1.getRectangle().y > o2.getRectangle().y ? 1 : 0;
0662:            }
0663:        });
0664:
0665:        for (int i = 0; i < subReportElements.size(); i++)
0666:        {
0667:            SubReportElement subReportElement = subReportElements.get(i);
0668:            subReportElement.setPosition(new Point2D.Double(0, startY + i * 20));
0669:            subReportElement.getRectangle().y = startY + i * 20;
0670:        }
0671:
0672:        updateSelectionRects();
0673:
0674:        //adjust structure according to the visual layout
0675:        BandToplevelReportElement parent = reportPanel.getBandToplevelReportElement();
0676:        for (SubReportElement subReportElement : subReportElements)
0677:        {
0678:            parent.removeChild(subReportElement);
0679:        }
0680:        for (SubReportElement subReportElement : subReportElements)
0681:        {
0682:            parent.addChild(subReportElement);
0683:        }
0684:    }
0685:
0686:
0687:    private void checkPageForTopBorder(@NotNull Point2D p)
0688:    {
0689:        Rectangle2D.Double rect = origSelectionRect;
0690:        if (rect != null)
0691:        {
0692:            if ((rect.y + (p.getY() - pressedPoint.getY()) < 0))
0693:            {
0694:                p.setLocation(p.getX(), 0 - rect.y + pressedPoint.getY());
0695:            }
0696:        }
0697:    }
0698:
0699:
0700:    private void checkPageForBottomBorder(@NotNull Point2D p)
0701:    {
0702:        double height = reportPanel.getReport().getPageDefinition().getInnerPageSize().getHeight();
0703:        Rectangle2D.Double rect = origSelectionRect;
0704:        if (rect != null)
0705:        {
0706:            if ((rect.y + rect.height + (p.getY() - pressedPoint.getY()) > height))
0707:            {
0708:                double diff = height - (rect.y + rect.height + (p.getY() - pressedPoint.getY()));
0709:                p.setLocation(p.getX(), p.getY() + diff);
0710:            }
0711:        }
0712:    }
0713:
0714:
0715:    private void checkPageBorderForLeftLine(@NotNull Point2D p)
0716:    {
0717:        Rectangle2D.Double rect = origSelectionRect;
0718:        if (rect != null)
0719:        {
0720:            if ((rect.x + (p.getX() - pressedPoint.getX()) < 0))
0721:            {
0722:                p.setLocation(0 - rect.x + pressedPoint.getX(), p.getY());
0723:            }
0724:        }
0725:    }
0726:
0727:
0728:    private void checkPageBorderForRightLine(@NotNull Point2D p)
0729:    {
0730:        double width = reportPanel.getReport().getPageDefinition().getInnerPageSize().getWidth();
0731:        Rectangle2D.Double rect = origSelectionRect;
0732:        if (rect != null)
0733:        {
0734:            if ((rect.x + rect.width + (p.getX() - pressedPoint.getX()) > width))
0735:            {
0736:                double diff = width - (rect.x + rect.width + (p.getX() - pressedPoint.getX()));
0737:                p.setLocation(p.getX() + diff, p.getY());
0738:            }
0739:        }
0740:    }
0741:
0742:
0743:    private void checkGuidlinesForTopLine(@NotNull Point2D p, double sf, @NotNull ReportPanel reportPanel)
0744:    {
0745:        //check for vertical guidlines
0746:        LinealModel linealModel = reportPanel.getVerticalLinealModel();
0747:        if (linealModel != null)
0748:        {
0749:            LinkedHashSet<GuideLine> verticalGuideLines = linealModel.getGuideLines();
0750:            for (GuideLine guideLine : verticalGuideLines)
0751:            {
0752:                Rectangle2D.Double rect = origSelectionRect;
0753:                if (rect != null)
0754:                {
0755:                    if (guideLine.isActive() &&
0756:                        (rect.y + (p.getY() - pressedPoint.getY())) + SNAP_TO_GUIDLINE_THRESHOLD / sf > guideLine.getPosition() &&
0757:                        (rect.y + (p.getY() - pressedPoint.getY())) - SNAP_TO_GUIDLINE_THRESHOLD / sf < guideLine.getPosition())
0758:                    {
0759:                        double diff = guideLine.getPosition() - (rect.y + (p.getY() - pressedPoint.getY()));
0760:                        p.setLocation(p.getX(), p.getY() + diff);
0761:                        return;
0762:                    }
0763:                }
0764:            }
0765:        }
0766:    }
0767:
0768:
0769:    private void checkGuidlinesForBottomLine(@NotNull Point2D p, double sf, @NotNull ReportPanel reportPanel)
0770:    {
0771:        //check for vertical guidlines
0772:        LinealModel linealModel = reportPanel.getVerticalLinealModel();
0773:        if (linealModel != null)
0774:        {
0775:            LinkedHashSet<GuideLine> verticalGuideLines = linealModel.getGuideLines();
0776:            for (GuideLine guideLine : verticalGuideLines)
0777:            {
0778:                Rectangle2D.Double rect = origSelectionRect;
0779:                if (rect != null)
0780:                {
0781:                    if (guideLine.isActive() &&
0782:                        (rect.y + rect.height + (p.getY() - pressedPoint.getY())) + SNAP_TO_GUIDLINE_THRESHOLD / sf > guideLine.getPosition() &&
0783:                        (rect.y + rect.height + (p.getY() - pressedPoint.getY())) - SNAP_TO_GUIDLINE_THRESHOLD / sf < guideLine.getPosition())
0784:                    {
0785:                        double diff = guideLine.getPosition() - (rect.y + rect.height + (p.getY() - pressedPoint.getY()));
0786:                        p.setLocation(p.getX(), p.getY() + diff);
0787:                        return;
0788:                    }
0789:                }
0790:            }
0791:        }
0792:    }
0793:
0794:
0795:    private void checkGuidlinesForLeftLine(@NotNull Point2D p, double sf, @NotNull ReportPanel reportPanel)
0796:    {
0797:        //check for horizontal guidlines
0798:        LinkedHashSet<GuideLine> horizontalGuideLines = reportPanel.getHorizontalLinealModel().getGuideLines();
0799:        for (GuideLine guideLine : horizontalGuideLines)
0800:        {
0801:            Rectangle2D.Double rect = origSelectionRect;
0802:            if (rect != null)
0803:            {
0804:                if (guideLine.isActive() &&
0805:                    (rect.x + (p.getX() - pressedPoint.getX())) + SNAP_TO_GUIDLINE_THRESHOLD / sf > guideLine.getPosition() &&
0806:                    (rect.x + (p.getX() - pressedPoint.getX())) - SNAP_TO_GUIDLINE_THRESHOLD / sf < guideLine.getPosition())
0807:                {
0808:                    double diff = guideLine.getPosition() - (rect.x + (p.getX() - pressedPoint.getX()));
0809:                    p.setLocation(p.getX() + diff, p.getY());
0810:                    return;
0811:                }
0812:            }
0813:        }
0814:    }
0815:
0816:
0817:    private void checkGuidlinesForRightLine(@NotNull Point2D p, double sf, @NotNull ReportPanel reportPanel)
0818:    {
0819:        //check for horizontal guidlines
0820:        LinkedHashSet<GuideLine> horizontalGuideLines = reportPanel.getHorizontalLinealModel().getGuideLines();
0821:        for (GuideLine guideLine : horizontalGuideLines)
0822:        {
0823:            Rectangle2D.Double rect = origSelectionRect;
0824:            if (rect != null)
0825:            {
0826:                if (guideLine.isActive() &&
0827:                    (rect.x + rect.width + (p.getX() - pressedPoint.getX())) + SNAP_TO_GUIDLINE_THRESHOLD / sf > guideLine.getPosition() &&
0828:                    (rect.x + rect.width + (p.getX() - pressedPoint.getX())) - SNAP_TO_GUIDLINE_THRESHOLD / sf < guideLine.getPosition())
0829:                {
0830:                    double diff = guideLine.getPosition() - (rect.x + rect.width + (p.getX() - pressedPoint.getX()));
0831:                    p.setLocation(p.getX() + diff, p.getY());
0832:                    return;
0833:                }
0834:            }
0835:        }
0836:    }
0837:
0838:
0839:    private void repaintPanels(@NotNull ReportElement elementInfo, double sf, double x, double y, double w, double h, @NotNull ReportElementSelectionModel reportElementSelectionModel)
0840:    {
0841:        ReportPanel rp = reportElementSelectionModel.getReportPanel(elementInfo);
0842:        if (rp != null)
0843:        {
0844:            repaintElementRectangle(elementInfo, sf, rp);//oldRectangle
0845:            if (rp.getBandToplevelReportElement().getVisualHeight() < y + h)
0846:            {
0847:                rp.getBandToplevelReportElement().setVisualHeight(y + h);
0848:            }
0849:            elementInfo.getRectangle().setRect(x, y, w, h);
0850:
0851:            //adjust possible children
0852:            if (elementInfo instanceof  BandReportElement)
0853:            {
0854:                BandReportElement bandReportElement = (BandReportElement) elementInfo;
0855:                bandReportElement.getReportLayoutManager().temporarilyLayoutReportElement(bandReportElement);
0856:            }
0857:
0858:            repaintElementRectangle(elementInfo, sf, rp);//newRetangle
0859:
0860:            rp.getSelectionHandler().updateSelectionRects();
0861:        }
0862:    }
0863:
0864:
0865:    private void repaintElementRectangle(@NotNull ReportElement elementInfo, double sf, @NotNull ReportPanel reportPanel)
0866:    {
0867:        Rectangle2D.Double rect = new Rectangle2D.Double();
0868:        rect.setRect(elementInfo.getRectangle());
0869:
0870:        ReportElementUtilities.convertRectangle(rect, elementInfo, null);
0871:        double bw = Math.max(10, elementInfo.getElementRepaintBorder() * sf);
0872:
0873:        int x = (int) ((rect.x) * sf - bw);
0874:        int y = (int) ((rect.y) * sf - bw);
0875:        int width = (int) ((rect.width) * sf + 2 * bw);
0876:        int height = (int) ((rect.height) * sf + 2 * bw);
0877:
0878:        reportPanel.repaint(x, y, width, height);
0879:    }
0880:
0881:
0882:    private void repaintInsertionRect()
0883:    {
0884:        BandReportElement insertionBand = this .insertionBand;
0885:        if (bandInsertionRect != null && insertionBand != null)
0886:        {
0887:            Rectangle2D.Double additionalRect = new Rectangle2D.Double(bandInsertionRect.x - 10, bandInsertionRect.y - 10, bandInsertionRect.width + 20, bandInsertionRect.height + 20);
0888:            ReportElementUtilities.convertRectangleIncludingSource(additionalRect, insertionBand, null);
0889:            reportPanel.repaint(additionalRect.getBounds());
0890:        }
0891:    }
0892:
0893:
0894:    @NotNull
0895:    private Point2D.Double getModelPoint(@NotNull Point point, @Nullable Point2D.Double dest)
0896:    {
0897:        double sf = reportPanel.getScaleFactor();
0898:        Point2D.Double d = dest;
0899:        if (d == null)
0900:        {
0901:            d = new Point2D.Double();
0902:        }
0903:        d.setLocation(point.x / sf, point.y / sf);
0904:        return d;
0905:    }
0906:
0907:
0908:    public void updateSelectionRects()
0909:    {
0910:        ArrayList<ReportElement> selected = reportElementSelectionModel.getNonDescendentsSelectedElementInfos();
0911:        ArrayList<ReportElement> selectedElementInfos = new ArrayList<ReportElement>();
0912:
0913:        for (ReportElement reportElement : selected)
0914:        {
0915:            if (reportElement.isDescendant(reportPanel.getBandToplevelReportElement()))
0916:            {
0917:                selectedElementInfos.add(reportElement);
0918:            }
0919:        }
0920:
0921:        if (!selectedElementInfos.isEmpty())
0922:        {
0923:            selectionRect = null;
0924:
0925:            c1 = null;
0926:            c2 = null;
0927:            c3 = null;
0928:            c4 = null;
0929:
0930:            e1 = null;
0931:            e2 = null;
0932:            e3 = null;
0933:            e4 = null;
0934:
0935:            boolean horizontalLine = false;
0936:            boolean verticalLine = false;
0937:            boolean subreport = false;
0938:
0939:            if (selectedElementInfos.size() == 1)
0940:            {
0941:                ReportElement reportElement = selectedElementInfos.iterator().next();
0942:                if (reportElement instanceof  LineReportElement)
0943:                {
0944:                    LineReportElement lineReportElement = (LineReportElement) reportElement;
0945:                    if (lineReportElement.getDirection() == LineDirection.HORIZONTAL && lineReportElement.getMinimumSize().getHeight() == 0)
0946:                    {
0947:                        horizontalLine = true;
0948:                    }
0949:                    else if (lineReportElement.getDirection() == LineDirection.VERTICAL && lineReportElement.getMinimumSize().getWidth() == 0)
0950:                    {
0951:                        verticalLine = true;
0952:                    }
0953:                }
0954:                else if (reportElement instanceof  SubReportElement)
0955:                {
0956:                    subreport = true;
0957:                }
0958:            }
0959:
0960:            for (ReportElement elementInfo : selectedElementInfos)
0961:            {
0962:                if (selectionRect == null)
0963:                {
0964:                    selectionRect = new Rectangle2D.Double();
0965:                    Rectangle2D.Double rect = new Rectangle2D.Double();
0966:                    rect.setRect(elementInfo.getRectangle());
0967:                    ReportElementUtilities.convertRectangle(rect, elementInfo, reportPanel.getBandToplevelReportElement());
0968:                    selectionRect.setRect(rect);
0969:                }
0970:                else
0971:                {
0972:                    Rectangle2D.Double rect = new Rectangle2D.Double();
0973:                    rect.setRect(elementInfo.getRectangle());
0974:                    ReportElementUtilities.convertRectangle(rect, elementInfo, reportPanel.getBandToplevelReportElement());
0975:
0976:                    Rectangle2D.union(selectionRect, rect, selectionRect);
0977:                }
0978:
0979:                if (elementInfo instanceof  SubReportElement)
0980:                {
0981:                    subreport = true;
0982:                }
0983:            }
0984:
0985:            if (origSelectionRect == null)
0986:            {
0987:                origSelectionRect = new Rectangle2D.Double();
0988:                origSelectionRect.setRect(selectionRect);
0989:            }
0990:
0991:            double sf = reportPanel.getScaleFactor();
0992:
0993:            //show resize handles
0994:            //corners
0995:            if (!horizontalLine && !verticalLine && !subreport)
0996:            {
0997:                c1 = new Rectangle2D.Double(selectionRect.x - 2 / sf, selectionRect.y - 2 / sf, 5 / sf, 5 / sf);
0998:                c2 = new Rectangle2D.Double(selectionRect.x + selectionRect.width - 2 / sf, selectionRect.y - 2 / sf, 5 / sf, 5 / sf);
0999:                c3 = new Rectangle2D.Double(selectionRect.x + selectionRect.width - 2 / sf, selectionRect.y + selectionRect.height - 2 / sf, 5 / sf, 5 / sf);
1000:                c4 = new Rectangle2D.Double(selectionRect.x - 2 / sf, selectionRect.y + selectionRect.height - 2 / sf, 5 / sf, 5 / sf);
1001:            }
1002:
1003:            //edges
1004:            if (!horizontalLine && !subreport)
1005:            {
1006:                e1 = new Rectangle2D.Double(selectionRect.x + selectionRect.width / 2 - 2 / sf, selectionRect.y - 2 / sf, 5 / sf, 5 / sf);
1007:                e3 = new Rectangle2D.Double(selectionRect.x + selectionRect.width / 2 - 2 / sf, selectionRect.y + selectionRect.height - 2 / sf, 5 / sf, 5 / sf);
1008:            }
1009:
1010:            if (!verticalLine && !subreport)
1011:            {
1012:                e2 = new Rectangle2D.Double(selectionRect.x + selectionRect.width - 2 / sf, selectionRect.y + selectionRect.height / 2 - 2 / sf, 5 / sf, 5 / sf);
1013:                e4 = new Rectangle2D.Double(selectionRect.x - 2 / sf, selectionRect.y + selectionRect.height / 2 - 2 / sf, 5 / sf, 5 / sf);
1014:            }
1015:        }
1016:        else
1017:        {
1018:            selectionRect = null;
1019:            origSelectionRect = null;
1020:
1021:            c1 = null;
1022:            c2 = null;
1023:            c3 = null;
1024:            c4 = null;
1025:
1026:            e1 = null;
1027:            e2 = null;
1028:            e3 = null;
1029:            e4 = null;
1030:        }
1031:
1032:    }
1033:
1034:
1035:    public void paintSelection(@NotNull GraphicsContext graphicsContext, @NotNull Graphics2D g2d)
1036:    {
1037:        if (selectionRect != null)
1038:        {
1039:            if (reportPanel.getReportDialog().getDrawSelectionType() == ReportDialog.DrawSelectionType.CLAMP)
1040:            {
1041:                Color origColor = g2d.getColor();
1042:                Stroke origStroke = g2d.getStroke();
1043:
1044:                g2d.setColor(Color.LIGHT_GRAY);
1045:                g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1));
1046:
1047:                ArrayList<ReportElement> selectedElementInfos = reportElementSelectionModel.getNonDescendentsSelectedElementInfos();
1048:                for (ReportElement elementInfo : selectedElementInfos)
1049:                {
1050:                    if (elementInfo.isDescendant(reportPanel.getBandToplevelReportElement()))
1051:                    {
1052:                        Rectangle2D.Double rect = new Rectangle2D.Double();
1053:                        rect.setRect(elementInfo.getRectangle());
1054:                        ReportElementUtilities.convertRectangle(rect, elementInfo, reportPanel.getBandToplevelReportElement());
1055:
1056:                        drawClampRectangle(g2d, GraphicUtils.getScaledRectangle(graphicsContext, rect));
1057:                    }
1058:                }
1059:
1060:                if (selectedElementInfos.size() == 1 && !ReportElementUtilities.isShowInLayoutGUI(selectedElementInfos.get(0)))
1061:                {
1062:                    g2d.setColor(DONT_SHOW_IN_LAYOUT_SELECTION_COLOR);
1063:                    drawClampRectangle(g2d, GraphicUtils.getScaledRectangle(graphicsContext, selectionRect));
1064:                }
1065:                else
1066:                {
1067:                    g2d.setColor(SELECTION_COLOR);
1068:                    drawClampRectangle(g2d, GraphicUtils.getScaledRectangle(graphicsContext, selectionRect));
1069:                }
1070:
1071:                g2d.setColor(origColor);
1072:                g2d.setStroke(origStroke);
1073:            }
1074:            else
1075:            {
1076:                Color origColor = g2d.getColor();
1077:                Stroke origStroke = g2d.getStroke();
1078:
1079:                g2d.setColor(Color.LIGHT_GRAY);
1080:                g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1, new float[]{2, 2}, 1));
1081:
1082:                ArrayList<ReportElement> selectedElementInfos = reportElementSelectionModel.getNonDescendentsSelectedElementInfos();
1083:                for (ReportElement elementInfo : selectedElementInfos)
1084:                {
1085:                    if (elementInfo.isDescendant(reportPanel.getBandToplevelReportElement()))
1086:                    {
1087:                        Rectangle2D.Double rect = new Rectangle2D.Double();
1088:                        rect.setRect(elementInfo.getRectangle());
1089:                        ReportElementUtilities.convertRectangle(rect, elementInfo, reportPanel.getBandToplevelReportElement());
1090:
1091:                        drawRectangle(g2d, GraphicUtils.getScaledRectangle(graphicsContext, rect));
1092:                    }
1093:                }
1094:
1095:                //draw dotted rectangle
1096:                if (selectedElementInfos.size() == 1 && !ReportElementUtilities.isShowInLayoutGUI(selectedElementInfos.get(0)))
1097:                {
1098:                    g2d.setColor(DONT_SHOW_IN_LAYOUT_SELECTION_COLOR);
1099:                    drawRectangle(g2d, GraphicUtils.getScaledRectangle(graphicsContext, selectionRect));
1100:
1101:                    double sf = graphicsContext.getScaleFactor();
1102:
1103:                    if (c1 != null) g2d.drawImage(IconLoader.getInstance().getDontShowInLayoutGUISelectionEdge().getImage(), (int) (c1.getX() * sf - 1), (int) (c1.getY() * sf - 1), null);
1104:                    if (c2 != null) g2d.drawImage(IconLoader.getInstance().getDontShowInLayoutGUISelectionEdge().getImage(), (int) (c2.getX() * sf - 1), (int) (c2.getY() * sf - 1), null);
1105:                    if (c3 != null) g2d.drawImage(IconLoader.getInstance().getDontShowInLayoutGUISelectionEdge().getImage(), (int) (c3.getX() * sf - 1), (int) (c3.getY() * sf - 1), null);
1106:                    if (c4 != null) g2d.drawImage(IconLoader.getInstance().getDontShowInLayoutGUISelectionEdge().getImage(), (int) (c4.getX() * sf - 1), (int) (c4.getY() * sf - 1), null);
1107:
1108:                    if (e1 != null) g2d.drawImage(IconLoader.getInstance().getDontShowInLayoutGUISelectionEdge().getImage(), (int) (e1.getX() * sf - 1), (int) (e1.getY() * sf - 1), null);
1109:                    if (e2 != null) g2d.drawImage(IconLoader.getInstance().getDontShowInLayoutGUISelectionEdge().getImage(), (int) (e2.getX() * sf - 1), (int) (e2.getY() * sf - 1), null);
1110:                    if (e3 != null) g2d.drawImage(IconLoader.getInstance().getDontShowInLayoutGUISelectionEdge().getImage(), (int) (e3.getX() * sf - 1), (int) (e3.getY() * sf - 1), null);
1111:                    if (e4 != null) g2d.drawImage(IconLoader.getInstance().getDontShowInLayoutGUISelectionEdge().getImage(), (int) (e4.getX() * sf - 1), (int) (e4.getY() * sf - 1), null);
1112:                }
1113:                else
1114:                {
1115:                    g2d.setColor(SELECTION_COLOR);
1116:                    drawRectangle(g2d, GraphicUtils.getScaledRectangle(graphicsContext, selectionRect));
1117:
1118:                    double sf = graphicsContext.getScaleFactor();
1119:
1120:                    if (c1 != null) g2d.drawImage(IconLoader.getInstance().getSelectionEdge().getImage(), (int) (c1.getX() * sf - 1), (int) (c1.getY() * sf - 1), null);
1121:                    if (c2 != null) g2d.drawImage(IconLoader.getInstance().getSelectionEdge().getImage(), (int) (c2.getX() * sf - 1), (int) (c2.getY() * sf - 1), null);
1122:                    if (c3 != null) g2d.drawImage(IconLoader.getInstance().getSelectionEdge().getImage(), (int) (c3.getX() * sf - 1), (int) (c3.getY() * sf - 1), null);
1123:                    if (c4 != null) g2d.drawImage(IconLoader.getInstance().getSelectionEdge().getImage(), (int) (c4.getX() * sf - 1), (int) (c4.getY() * sf - 1), null);
1124:
1125:                    if (e1 != null) g2d.drawImage(IconLoader.getInstance().getSelectionEdge().getImage(), (int) (e1.getX() * sf - 1), (int) (e1.getY() * sf - 1), null);
1126:                    if (e2 != null) g2d.drawImage(IconLoader.getInstance().getSelectionEdge().getImage(), (int) (e2.getX() * sf - 1), (int) (e2.getY() * sf - 1), null);
1127:                    if (e3 != null) g2d.drawImage(IconLoader.getInstance().getSelectionEdge().getImage(), (int) (e3.getX() * sf - 1), (int) (e3.getY() * sf - 1), null);
1128:                    if (e4 != null) g2d.drawImage(IconLoader.getInstance().getSelectionEdge().getImage(), (int) (e4.getX() * sf - 1), (int) (e4.getY() * sf - 1), null);
1129:                }
1130:
1131:
1132:                g2d.setColor(origColor);
1133:                g2d.setStroke(origStroke);
1134:            }
1135:
1136:            if (bandInsertionRect != null)
1137:            {
1138:                g2d.setColor(new Color(100, 150, 100));
1139:                ArrayList<ReportElement> selectedElementInfos = reportElementSelectionModel.getNonDescendentsSelectedElementInfos();
1140:                for (ReportElement elementInfo : selectedElementInfos)
1141:                {
1142:                    BandReportElement insertionBand = this .insertionBand;
1143:                    //noinspection ObjectEquality
1144:                    if (elementInfo != insertionBand && insertionBand != null)
1145:                    {
1146:                        Rectangle2D.Double rect = new Rectangle2D.Double();
1147:                        rect.setRect(bandInsertionRect);
1148:
1149:                        ReportElementUtilities.convertRectangleIncludingSource(rect, insertionBand, reportPanel.getBandToplevelReportElement());
1150:                        g2d.draw(GraphicUtils.getScaledRectangle(graphicsContext, rect));
1151:                    }
1152:                }
1153:            }
1154:        }
1155:    }
1156:
1157:
1158:    private void drawRectangle(@NotNull Graphics2D g2d, @NotNull Rectangle2D.Double rect)
1159:    {
1160:        g2d.drawLine((int) rect.x, (int) rect.y, (int) (rect.x + rect.width), (int) rect.y);
1161:        g2d.drawLine((int) rect.x, (int) (rect.y + rect.height), (int) (rect.x + rect.width), (int) (rect.y + rect.height));
1162:        g2d.drawLine((int) rect.x, (int) rect.y, (int) rect.x, (int) (rect.y + rect.height));
1163:        g2d.drawLine((int) (rect.x + rect.width), (int) rect.y, (int) (rect.x + rect.width), (int) (rect.y + rect.height));
1164:    }
1165:
1166:
1167:    private void drawClampRectangle(@NotNull Graphics2D g2d, @NotNull Rectangle2D.Double rect)
1168:    {
1169:        //top
1170:        g2d.drawLine((int) rect.x, (int) rect.y, (int) rect.x + 3, (int) rect.y);
1171:        g2d.drawLine((int) rect.x, (int) rect.y, (int) rect.x, (int) rect.y + 3);
1172:
1173:        g2d.drawLine((int) (rect.x + rect.width / 2) - 2, (int) rect.y, (int) (rect.x + rect.width / 2) + 2, (int) rect.y);
1174:        g2d.drawLine((int) (rect.x + rect.width / 2), (int) rect.y + 1, (int) (rect.x + rect.width / 2), (int) rect.y + 2);
1175:
1176:        g2d.drawLine((int) (rect.x + rect.width - 3), (int) rect.y, (int) (rect.x + rect.width), (int) rect.y);
1177:        g2d.drawLine((int) (rect.x + rect.width), (int) rect.y, (int) (rect.x + rect.width), (int) rect.y + 3);
1178:
1179:        //middle
1180:        g2d.drawLine((int) rect.x, (int) (rect.y + rect.height / 2) - 2, (int) rect.x, (int) (rect.y + rect.height / 2) + 2);
1181:        g2d.drawLine((int) rect.x + 1, (int) (rect.y + rect.height / 2), (int) rect.x + 2, (int) (rect.y + rect.height / 2));
1182:
1183:        g2d.drawLine((int) (rect.x + rect.width), (int) (rect.y + rect.height / 2) - 2, (int) (rect.x + rect.width), (int) (rect.y + rect.height / 2) + 2);
1184:        g2d.drawLine((int) (rect.x + rect.width - 2), (int) (rect.y + rect.height / 2), (int) (rect.x + rect.width) - 1, (int) (rect.y + rect.height / 2));
1185:
1186:        //low
1187:        g2d.drawLine((int) rect.x, (int) (rect.y + rect.height - 3), (int) rect.x, (int) (rect.y + rect.height));
1188:        g2d.drawLine((int) rect.x, (int) (rect.y + rect.height), (int) rect.x + 3, (int) (rect.y + rect.height));
1189:
1190:        g2d.drawLine((int) (rect.x + rect.width / 2) - 2, (int) (rect.y + rect.height), (int) (rect.x + rect.width / 2) + 2, (int) (rect.y + rect.height));
1191:        g2d.drawLine((int) (rect.x + rect.width / 2), (int) (rect.y + rect.height) - 2, (int) (rect.x + rect.width / 2), (int) (rect.y + rect.height) - 1);
1192:
1193:        g2d.drawLine((int) (rect.x + rect.width - 3), (int) (rect.y + rect.height), (int) (rect.x + rect.width), (int) (rect.y + rect.height));
1194:        g2d.drawLine((int) (rect.x + rect.width), (int) (rect.y + rect.height - 3), (int) (rect.x + rect.width), (int) (rect.y + rect.height));
1195:    }
1196:
1197:
1198:    private boolean selectionContainsMouseEvent(@NotNull Point2D p)
1199:    {
1200:        if (selectionRect == null)
1201:        {
1202:            return false;
1203:        }
1204:
1205:        if (selectionRect.contains(p))
1206:        {
1207:            return true;
1208:        }
1209:        else if (c1 != null && c1.contains(p))
1210:        {
1211:            return true;
1212:        }
1213:        else if (c2 != null && c2.contains(p))
1214:        {
1215:            return true;
1216:        }
1217:        else if (c3 != null && c3.contains(p))
1218:        {
1219:            return true;
1220:        }
1221:        else if (c4 != null && c4.contains(p))
1222:        {
1223:            return true;
1224:        }
1225:        else if (e1 != null && e1.contains(p))
1226:        {
1227:            return true;
1228:        }
1229:        else if (e2 != null && e2.contains(p))
1230:        {
1231:            return true;
1232:        }
1233:        else if (e3 != null && e3.contains(p))
1234:        {
1235:            return true;
1236:        }
1237:        else if (e4 != null && e4.contains(p))
1238:        {
1239:            return true;
1240:        }
1241:        else
1242:        {
1243:            if (reportElementSelectionModel.getNonDescendentsSelectedElementInfos().size() == 1)
1244:            {
1245:                ReportElement reportElement = reportElementSelectionModel.getNonDescendentsSelectedElementInfos().iterator().next();
1246:                if (reportElement instanceof  LineReportElement)
1247:                {
1248:                    LineReportElement lineReportElement = (LineReportElement) reportElement;
1249:                    if (lineReportElement.getMinimumSize().getHeight() == 0 || lineReportElement.getMinimumSize().getWidth() == 0)
1250:                    {
1251:                        Rectangle2D.Double rect = new Rectangle2D.Double(lineReportElement.getPosition().x - 3, lineReportElement.getPosition().y - 3, lineReportElement.getMinimumSize().getWidth() + 6, lineReportElement.getMinimumSize().getHeight() + 6);
1252:                        ReportElementUtilities.convertRectangle(rect, lineReportElement, null);
1253:                        if (rect.contains(p))
1254:                        {
1255:                            if (LOG.isLoggable(Level.FINE)) LOG.log(Level.FINE, "SelectionHandler.selectionContainsMouseEvent rect = " + rect);
1256:                            return true;
1257:                        }
1258:                    }
1259:                }
1260:            }
1261:        }
1262:
1263:        return false;
1264:    }
1265:
1266:
1267:    @NotNull
1268:    private AdjustmentState applyAdjustmentStateMouseMoved(@NotNull Point2D p)
1269:    {
1270:        Rectangle2D.Double sr = selectionRect;
1271:        if (sr == null)
1272:        {
1273:            reportPanel.setCursor(Cursor.getDefaultCursor());
1274:            return AdjustmentState.NONE;
1275:        }
1276:
1277:        if (c3 != null && c3.contains(p))
1278:        {
1279:            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR));
1280:            return AdjustmentState.RESIZE_SE;
1281:        }
1282:        else if (e2 != null && e2.contains(p))
1283:        {
1284:            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
1285:            return AdjustmentState.RESIZE_E;
1286:        }
1287:        else if (c2 != null && c2.contains(p))
1288:        {
1289:            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.NE_RESIZE_CURSOR));
1290:            return AdjustmentState.RESIZE_NE;
1291:        }
1292:        else if (e3 != null && e3.contains(p))
1293:        {
1294:            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR));
1295:            return AdjustmentState.RESIZE_S;
1296:        }
1297:        else if (c4 != null && c4.contains(p))
1298:        {
1299:            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.SW_RESIZE_CURSOR));
1300:            return AdjustmentState.RESIZE_SW;
1301:        }
1302:        else if (c1 != null && c1.contains(p))
1303:        {
1304:            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.NW_RESIZE_CURSOR));
1305:            return AdjustmentState.RESIZE_NW;
1306:        }
1307:        else if (e1 != null && e1.contains(p))
1308:        {
1309:            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR));
1310:            return AdjustmentState.RESIZE_N;
1311:        }
1312:        else if (e4 != null && e4.contains(p))
1313:        {
1314:            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
1315:            return AdjustmentState.RESIZE_W;
1316:        }
1317:        else if (sr.contains(p))
1318:        {
1319:            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
1320:            return AdjustmentState.MOVE;
1321:        }
1322:        else
1323:        {
1324:            //special handling for lines
1325:            if (sr.getHeight() == 0 || sr.getWidth() == 0)
1326:            {
1327:                ArrayList<ReportElement> selectedElementInfos = reportElementSelectionModel.getNonDescendentsSelectedElementInfos();
1328:                if (selectedElementInfos.size() == 1)
1329:                {
1330:                    ReportElement reportElement = selectedElementInfos.iterator().next();
1331:                    if (reportElement instanceof  LineReportElement)
1332:                    {
1333:                        Rectangle2D.Double widenedSelectionRect = new Rectangle2D.Double(sr.getX() - 3, sr.getY() - 3, sr.getWidth() + 6, sr.getHeight() + 6);
1334:                        if (widenedSelectionRect.contains(p))
1335:                        {
1336:                            reportPanel.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
1337:                            return AdjustmentState.MOVE;
1338:                        }
1339:                    }
1340:                }
1341:            }
1342:        }
1343:
1344:        reportPanel.setCursor(Cursor.getDefaultCursor());
1345:        return AdjustmentState.NONE;
1346:    }
1347:
1348:}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.