Ignore:
Timestamp:
08/15/08 16:53:31 (16 years ago)
Author:
ra33
Message:

Added PDF writers

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/FrameGraphics.java

    r198 r226  
    287287
    288288                        Graphics2D bg = (Graphics2D) buffer.getGraphics();
    289                         bg.setClip(clip);
    290 
    291                         // TODO: Revise images and clip - VERY IMPORTANT
    292 
    293                         // Nicer looking lines, but may be too jerky while
    294                         // rubber-banding on older machines
    295                         if (UserSettings.AntiAlias)
    296                                 bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    297                                                 RenderingHints.VALUE_ANTIALIAS_ON);
    298                         // If we are doing @f etc... then have a clear background if its the
    299                         // default background color
    300                         Color backgroundColor = null;
    301                         // Need to allow transparency for frameImages
    302                         if (createVolitile) {
    303                                 backgroundColor = toPaint.getPaintBackgroundColor();
    304                         }else{
    305                                 backgroundColor = toPaint.getBackgroundColor();
    306                                 if (backgroundColor == null)
    307                                         backgroundColor = Item.TRANSPARENT;
    308                         }
    309 
    310                         bg.setColor(backgroundColor);
    311                         // bg.setColor(Color.pink); // TODO: TEMP FOR DEBUGGING
    312 
    313                         bg.fillRect(0, 0, _MaxSize.width, _MaxSize.height);
    314 
    315                         List<Item> visibleItems = new LinkedList<Item>();
    316                         List<InteractiveWidget> paintWidgets;
    317 
    318                         if (isActualFrame) {
    319                                 // Add all the items for this frame and any other from other
    320                                 // frames
    321                                 visibleItems.addAll(toPaint.getAllItems());
    322                                 paintWidgets = new LinkedList<InteractiveWidget>();
    323                                 AddAllOverlayWidgets(paintWidgets, toPaint,
    324                                                 new LinkedList<Frame>());
    325                         } else {
    326                                 visibleItems.addAll(toPaint.getVisibleItems());
    327                                 visibleItems.addAll(toPaint.getVectorItems());
    328                                 paintWidgets = toPaint.getInteractiveWidgets();
    329                         }
    330 
    331                         // FIRST: Paint widgets swing gui (not expeditee gui) .
    332                         // Note that these are the anchored widgets
    333                         ListIterator<InteractiveWidget> widgetItor = paintWidgets.listIterator(paintWidgets.size());
    334                         while (widgetItor.hasPrevious())  { // Paint first-in-last-serve ordering - like swing
    335                                 InteractiveWidget iw = widgetItor.previous();
    336                                 if (clip == null
    337                                                 || clip.intersects(iw.getComponant().getBounds()))
    338                                         iw.paint(bg);                           
    339                         }
    340 
    341                         // Filter out items that do not need to be painted
    342                         List<Item> paintItems;
    343                         HashSet<Item> fillOnlyItems = null; // only contains items that do
    344                         // not need drawing but fills
    345                         // might
    346 
    347                         if (clip == null) {
    348                                 paintItems = visibleItems;
    349                         } else {
    350                                 fillOnlyItems = new HashSet<Item>();
    351                                 paintItems = new LinkedList<Item>();
    352                                 for (Item i : visibleItems) {
    353                                         if (i.isInDrawingArea(clip)) {
    354                                                 paintItems.add(i);
    355                                         } else if (i.isEnclosed()) {
    356                                                 // just add all fill items despite possibility of fills
    357                                                 // not being in clip
    358                                                 // because it will be faster than having to test twice
    359                                                 // for fills that do need
    360                                                 // repainting.
    361                                                 fillOnlyItems.add(i);
     289                        paintFrame(toPaint, clip, isActualFrame, createVolitile, bg);
     290
     291                        bg.dispose();
     292                }
     293
     294                return toPaint.getBuffer();
     295        }
     296
     297        /**
     298         * @param toPaint
     299         * @param clip
     300         * @param isActualFrame
     301         * @param createVolitile
     302         * @param bg
     303         */
     304        public static void paintFrame(Frame toPaint, Area clip, boolean isActualFrame, boolean createVolitile, Graphics2D bg) {
     305                bg.setClip(clip);
     306
     307                // TODO: Revise images and clip - VERY IMPORTANT
     308
     309                // Nicer looking lines, but may be too jerky while
     310                // rubber-banding on older machines
     311                if (UserSettings.AntiAlias)
     312                        bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
     313                                        RenderingHints.VALUE_ANTIALIAS_ON);
     314                // If we are doing @f etc... then have a clear background if its the
     315                // default background color
     316                Color backgroundColor = null;
     317                // Need to allow transparency for frameImages
     318                if (createVolitile) {
     319                        backgroundColor = toPaint.getPaintBackgroundColor();
     320                }else{
     321                        backgroundColor = toPaint.getBackgroundColor();
     322                        if (backgroundColor == null)
     323                                backgroundColor = Item.TRANSPARENT;
     324                }
     325
     326                bg.setColor(backgroundColor);
     327                // bg.setColor(Color.pink); // TODO: TEMP FOR DEBUGGING
     328
     329                bg.fillRect(0, 0, _MaxSize.width, _MaxSize.height);
     330
     331                List<Item> visibleItems = new LinkedList<Item>();
     332                List<InteractiveWidget> paintWidgets;
     333
     334                if (isActualFrame) {
     335                        // Add all the items for this frame and any other from other
     336                        // frames
     337                        visibleItems.addAll(toPaint.getAllItems());
     338                        paintWidgets = new LinkedList<InteractiveWidget>();
     339                        AddAllOverlayWidgets(paintWidgets, toPaint,
     340                                        new LinkedList<Frame>());
     341                } else {
     342                        visibleItems.addAll(toPaint.getVisibleItems());
     343                        visibleItems.addAll(toPaint.getVectorItems());
     344                        paintWidgets = toPaint.getInteractiveWidgets();
     345                }
     346
     347                // FIRST: Paint widgets swing gui (not expeditee gui) .
     348                // Note that these are the anchored widgets
     349                ListIterator<InteractiveWidget> widgetItor = paintWidgets.listIterator(paintWidgets.size());
     350                while (widgetItor.hasPrevious())  { // Paint first-in-last-serve ordering - like swing
     351                        InteractiveWidget iw = widgetItor.previous();
     352                        if (clip == null
     353                                        || clip.intersects(iw.getComponant().getBounds()))
     354                                iw.paint(bg);                           
     355                }
     356
     357                // Filter out items that do not need to be painted
     358                List<Item> paintItems;
     359                HashSet<Item> fillOnlyItems = null; // only contains items that do
     360                // not need drawing but fills
     361                // might
     362
     363                if (clip == null) {
     364                        paintItems = visibleItems;
     365                } else {
     366                        fillOnlyItems = new HashSet<Item>();
     367                        paintItems = new LinkedList<Item>();
     368                        for (Item i : visibleItems) {
     369                                if (i.isInDrawingArea(clip)) {
     370                                        paintItems.add(i);
     371                                } else if (i.isEnclosed()) {
     372                                        // just add all fill items despite possibility of fills
     373                                        // not being in clip
     374                                        // because it will be faster than having to test twice
     375                                        // for fills that do need
     376                                        // repainting.
     377                                        fillOnlyItems.add(i);
     378                                }
     379                        }
     380                }
     381                // Only paint files and lines once ... between anchored AND free
     382                // items
     383                HashSet<Item> paintedFillsAndLines = new HashSet<Item>();
     384                PaintPictures(bg, paintItems, fillOnlyItems, paintedFillsAndLines);
     385                PaintLines(bg, visibleItems);
     386
     387                // Filter out free items that do not need to be painted
     388                // This is efficient in cases with animation while free items exist
     389
     390                List<Item> freeItemsToPaint = new LinkedList<Item>();
     391                // Dont paint the free items for the other frame in twin frames mode
     392                // if (toPaint == DisplayIO.getCurrentFrame()) {
     393                if (clip == null) {
     394                        freeItemsToPaint = FreeItems.getInstance();
     395                } else {
     396                        freeItemsToPaint = new LinkedList<Item>();
     397                        fillOnlyItems.clear();
     398                        for (Item i : FreeItems.getInstance()) {
     399                                if (i.isInDrawingArea(clip)) {
     400                                        freeItemsToPaint.add(i);
     401                                } else if (i.isEnclosed()) {
     402                                        fillOnlyItems.add(i);
     403                                }
     404                        }
     405                }
     406                // }
     407
     408                if (isActualFrame && toPaint == DisplayIO.getCurrentFrame())
     409                        PaintPictures(bg, freeItemsToPaint, fillOnlyItems,
     410                                        paintedFillsAndLines);
     411                // TODO if we can get transparency with FreeItems.getInstance()...
     412                // then text can be done before freeItems
     413                PaintNonLinesNonPicture(bg, paintItems);
     414
     415                // toPaint.setBufferValid(true);
     416
     417                if (isActualFrame && !isAudienceMode()) {
     418                        PaintItem(bg, toPaint.getNameItem());
     419                }
     420
     421                if (DisplayIO.isTwinFramesOn()) {
     422                        List<Item> lines = new LinkedList<Item>();
     423                        for (Item i : freeItemsToPaint) {
     424                                if (i instanceof Line) {
     425                                        Line line = (Line) i;
     426
     427                                        if (toPaint == DisplayIO.getCurrentFrame()) {
     428                                                // If exactly one end of the line is floating...
     429
     430                                                if (line.getEndItem().isFloating()
     431                                                                ^ line.getStartItem().isFloating()) {
     432                                                        // Line l = TransposeLine(line,
     433                                                        // line.getEndItem(),
     434                                                        // toPaint, 0, 0);
     435                                                        // if (l == null)
     436                                                        // l = TransposeLine(line,
     437                                                        // line.getStartItem(), toPaint, 0, 0);
     438                                                        // if (l == null)
     439                                                        // l = line;
     440                                                        // lines.add(l);
     441                                                } else {
     442                                                        // lines.add(line);
     443                                                }
     444                                        } else {
     445                                                // if (line.getEndItem().isFloating()
     446                                                // ^ line.getStartItem().isFloating()) {
     447                                                // lines.add(TransposeLine(line,
     448                                                // line.getEndItem(), toPaint,
     449                                                // FrameMouseActions.getY(), -DisplayIO
     450                                                // .getMiddle()));
     451                                                // lines.add(TransposeLine(line, line
     452                                                // .getStartItem(), toPaint,
     453                                                // FrameMouseActions.getY(), -DisplayIO
     454                                                // .getMiddle()));
     455                                                // }
    362456                                        }
    363457                                }
    364458                        }
    365                         // Only paint files and lines once ... between anchored AND free
    366                         // items
    367                         HashSet<Item> paintedFillsAndLines = new HashSet<Item>();
    368                         PaintPictures(bg, paintItems, fillOnlyItems, paintedFillsAndLines);
    369                         PaintLines(bg, visibleItems);
    370 
    371                         // Filter out free items that do not need to be painted
    372                         // This is efficient in cases with animation while free items exist
    373 
    374                         List<Item> freeItemsToPaint = new LinkedList<Item>();
    375                         // Dont paint the free items for the other frame in twin frames mode
    376                         // if (toPaint == DisplayIO.getCurrentFrame()) {
    377                         if (clip == null) {
    378                                 freeItemsToPaint = FreeItems.getInstance();
    379                         } else {
    380                                 freeItemsToPaint = new LinkedList<Item>();
    381                                 fillOnlyItems.clear();
    382                                 for (Item i : FreeItems.getInstance()) {
    383                                         if (i.isInDrawingArea(clip)) {
    384                                                 freeItemsToPaint.add(i);
    385                                         } else if (i.isEnclosed()) {
    386                                                 fillOnlyItems.add(i);
    387                                         }
    388                                 }
    389                         }
    390                         // }
    391 
    392                         if (isActualFrame && toPaint == DisplayIO.getCurrentFrame())
    393                                 PaintPictures(bg, freeItemsToPaint, fillOnlyItems,
    394                                                 paintedFillsAndLines);
    395                         // TODO if we can get transparency with FreeItems.getInstance()...
    396                         // then text can be done before freeItems
    397                         PaintNonLinesNonPicture(bg, paintItems);
    398 
    399                         // toPaint.setBufferValid(true);
    400 
    401                         if (isActualFrame && !isAudienceMode()) {
    402                                 PaintItem(bg, toPaint.getNameItem());
    403                         }
    404 
    405                         if (DisplayIO.isTwinFramesOn()) {
    406                                 List<Item> lines = new LinkedList<Item>();
    407                                 for (Item i : freeItemsToPaint) {
    408                                         if (i instanceof Line) {
    409                                                 Line line = (Line) i;
    410 
    411                                                 if (toPaint == DisplayIO.getCurrentFrame()) {
    412                                                         // If exactly one end of the line is floating...
    413 
    414                                                         if (line.getEndItem().isFloating()
    415                                                                         ^ line.getStartItem().isFloating()) {
    416                                                                 // Line l = TransposeLine(line,
    417                                                                 // line.getEndItem(),
    418                                                                 // toPaint, 0, 0);
    419                                                                 // if (l == null)
    420                                                                 // l = TransposeLine(line,
    421                                                                 // line.getStartItem(), toPaint, 0, 0);
    422                                                                 // if (l == null)
    423                                                                 // l = line;
    424                                                                 // lines.add(l);
    425                                                         } else {
    426                                                                 // lines.add(line);
    427                                                         }
    428                                                 } else {
    429                                                         // if (line.getEndItem().isFloating()
    430                                                         // ^ line.getStartItem().isFloating()) {
    431                                                         // lines.add(TransposeLine(line,
    432                                                         // line.getEndItem(), toPaint,
    433                                                         // FrameMouseActions.getY(), -DisplayIO
    434                                                         // .getMiddle()));
    435                                                         // lines.add(TransposeLine(line, line
    436                                                         // .getStartItem(), toPaint,
    437                                                         // FrameMouseActions.getY(), -DisplayIO
    438                                                         // .getMiddle()));
    439                                                         // }
    440                                                 }
    441                                         }
    442                                 }
    443                                 if (isActualFrame)
    444                                         PaintLines(bg, lines);
    445                         } else {
    446                                 // Dont paint the
    447                                 if (isActualFrame)
    448                                         PaintLines(bg, freeItemsToPaint);
    449                         }
    450 
    451                         if (isActualFrame && toPaint == DisplayIO.getCurrentFrame())
    452                                 PaintNonLinesNonPicture(bg, freeItemsToPaint);
    453 
    454                         // Repaint popups / drags... As well as final passes
    455                         if (isActualFrame) {
    456                                 PopupManager.getInstance().paintLayeredPane(bg, clip);
    457                                 for (FinalFrameRenderPass pass : _finalPasses) {
    458                                         pass.paint(bg);
    459                                 }
    460                         }
    461 
    462                         bg.dispose();
    463                 }
    464 
    465                 return toPaint.getBuffer();
     459                        if (isActualFrame)
     460                                PaintLines(bg, lines);
     461                } else {
     462                        // Dont paint the
     463                        if (isActualFrame)
     464                                PaintLines(bg, freeItemsToPaint);
     465                }
     466
     467                if (isActualFrame && toPaint == DisplayIO.getCurrentFrame())
     468                        PaintNonLinesNonPicture(bg, freeItemsToPaint);
     469
     470                // Repaint popups / drags... As well as final passes
     471                if (isActualFrame) {
     472                        PopupManager.getInstance().paintLayeredPane(bg, clip);
     473                        for (FinalFrameRenderPass pass : _finalPasses) {
     474                                pass.paint(bg);
     475                        }
     476                }
    466477        }
    467478
Note: See TracChangeset for help on using the changeset viewer.