This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 27794
Collapse All | Expand All

(-)core/src/org/netbeans/core/windows/frames/PerimeterPane.java (-53 / +341 lines)
Line 77 Link Here
77
78
79
    // Fields used by dragging paint.
80
    private boolean drag;
81
    private java.awt.image.BufferedImage image;
82
    private Rectangle horiz;
83
    private Rectangle vert;
84
    private Point newLoc;
85
    private int deltaX;
86
    private int deltaY;
87
    private int orientation;
88
    
89
    private void setDragging(boolean drag) {
90
        this.drag = drag;
91
        if(!drag) {
92
            image = null;
93
            horiz = null;
94
            vert = null;
95
            newLoc = null;
96
            deltaX = 0;
97
            deltaY = 0;
98
            orientation = 0;
99
        }
100
    }
101
    
102
    /** Overrides superclass method, to provide more efficient paint during
103
     * dragging. */
104
    public void paint(Graphics g) {
105
        if(!drag) {
106
            super.paint(g);
107
        } else {
108
            // Get image of pane for this drag session.
109
            if(image == null) {
110
                Rectangle clip = g.getClipBounds();
111
                image = new java.awt.image.BufferedImage(
112
                    clip.width, clip.height,
113
                    java.awt.image.BufferedImage.TYPE_INT_ARGB);
114
                super.paint(image.getGraphics());
115
                g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
116
            }
117
118
            Rectangle h = horiz;
119
            Rectangle v = vert;
120
121
            // [PENDING ]Following is not enough, it is after this paint invalidated or what.
122
            // Needs to find out why, the background is grayed.
123
            // This needs to be resolved to get the best speed.
124
//            if(h != null) {
125
//                java.awt.image.BufferedImage subImage = image.getSubimage(h.x, h.y, h.width, h.height);
126
//                g.drawImage(subImage, h.x, h.y, subImage.getWidth(), subImage.getHeight(), null);
127
//            } 
128
//            if(v != null) {
129
//                java.awt.image.BufferedImage subImage = image.getSubimage(v.x, v.y, v.width, v.height);
130
//                g.drawImage(subImage, v.x, v.y, subImage.getWidth(), subImage.getHeight(), null);
131
//            }
132
            g.drawImage(image, 0, 0, image.getWidth(this), image.getHeight(this), null);
133
            
134
            
135
            Point newPoint = newLoc;
136
            
137
            if(!getBounds().contains(newPoint)) {
138
                return;
139
            }
140
            
141
            Color old = g.getColor();
142
            g.setColor(Color.darkGray);
143
            
144
            // Draw horizontal split.
145
            if(h != null && newPoint != null) {
146
                h.setLocation(h.x, newPoint.y + deltaY);
147
                if(orientation == 3) { // WEST
148
                    h.setBounds(h.x, h.y, (newPoint.x + deltaX) - h.x, h.height);
149
                } 
150
                else if(orientation == 4) {
151
                    h.setBounds((newPoint.x + deltaX), h.y, h.width - ((newPoint.x + deltaX) - h.x), h.height);
152
                }
153
                g.fillRect(h.x, h.y, h.width, h.height);
154
            }
155
            
156
            // Draw vertical split.
157
            if(v != null && newPoint != null) {
158
                v.setLocation(newPoint.x + deltaX, v.y);
159
                if(orientation == 1) { // NORTH
160
                    v.setBounds(v.x, v.y, v.width, (newPoint.y + deltaY) - v.y);
161
                }
162
                else if(orientation == 2) { // SOUTH
163
                    v.setBounds(v.x, (newPoint.y + deltaY), v.width, v.height - ((newPoint.y + deltaY) - v.y));
164
                }
165
                
166
                g.fillRect(v.x, v.y, v.width, v.height);
167
            }
168
            
169
            g.setColor(old);
170
        }
171
        
172
173
    }
Line 307 Link Here
404
405
        // Fields working when dragging 'split'
406
        private Rectangle horizontal;
407
        private Rectangle vertical;
Line 313 Link Here
313
                // get original position
414
                // update mouse location
314
--
Lines 315-316 Link Here
315
                // resizing if clicked directly on JPanel
416
316
                resizing = (pPane.getComponentAt(mouseLocation) == pPane);
417
                Point point = mouseLocation;
317
--
418
                // No resizing if not clicked directly at pane.
419
                if(pPane.getComponentAt(point) != pPane) {
420
                    return;
421
                }
422
                
423
                // Retrieve split rectangles.
424
                Component top = (Component)pPane.components.get(PerimeterLayout.NORTH);
425
                Component bottom = (Component)pPane.components.get(PerimeterLayout.SOUTH);
426
                Component center = (Component)pPane.components.get(PerimeterLayout.CENTER);
427
                Component left = (Component)pPane.components.get(PerimeterLayout.WEST);
428
                Component right = (Component)pPane.components.get(PerimeterLayout.EAST);
429
                
430
                // is horizontal?
431
                if(top != null && center != null) {
432
                    // is horizontal between top and center.
433
                    tryToSetHorizontal(top, center, point.y);
434
                }
435
                if(horizontal == null && center != null && bottom != null) {
436
                    // is between center and bottom
437
                    tryToSetHorizontal(center, bottom, point.y);
438
                }
439
                // when center is missing also left or right could be under top/ or above bottom.
440
                if(horizontal == null && top != null && left != null && center == null) {
441
                    tryToSetHorizontal(top, left, point.y);
442
                }
443
                if(horizontal == null && top != null && right != null && center == null) {
444
                    tryToSetHorizontal(top, right, point.y);
445
                }
446
                if(horizontal == null && left != null && bottom != null && center == null) {
447
                    tryToSetHorizontal(left, bottom, point.y);
448
                }
449
                if(horizontal == null && right != null && bottom != null && center == null) {
450
                    tryToSetHorizontal(right, bottom, point.y);
451
                }
452
                // even top and bottom could be side by side.
453
                if(horizontal == null && top != null && bottom != null && center == null
454
                && (left == null || (left.getBounds().x < top.getBounds().x
455
                        || left.getBounds().x < bottom.getBounds().x))
456
                && (right == null
457
                        || ((top.getBounds().x + top.getBounds().width) < (right.getBounds().x + right.getBounds().width)
458
                        ||  (bottom.getBounds().x + bottom.getBounds().width) < (right.getBounds().x + right.getBounds().width)))) {
459
                    // is between top and bottom while center is missing.
460
                    tryToSetHorizontal(top, bottom, point.y);
461
                }
462
                
463
                
464
                
465
                // is vertical?
466
                if(left != null && center != null) {
467
                    // is horizontal between left and center.
468
                    tryToSetVertical(left, center, point.x);
469
                }
470
                if(vertical == null && center != null && right != null) {
471
                    // is between center and right
472
                    tryToSetVertical(center, right, point.x);
473
                }
474
                // when center is missing also top or bottom could be right from left or left from righ.
475
                if(vertical == null && left != null && top != null && center == null) {
476
                    tryToSetVertical(left, top, point.x);
477
                }
478
                if(vertical == null && left != null && bottom != null && center == null) {
479
                    tryToSetVertical(left, bottom, point.x);
480
                }
481
                if(vertical == null && top != null && right != null && center == null) {
482
                    tryToSetVertical(top, right, point.x);
483
                }
484
                if(vertical == null && bottom != null && right != null && center == null) {
485
                    tryToSetVertical(bottom, right, point.x);
486
                }
487
                // even left and right could be side by side.
488
                if(vertical == null && left != null && right != null && center == null
489
                && (top == null || (top.getBounds().y < left.getBounds().y || top.getBounds().y < right.getBounds().y))
490
                && (bottom == null
491
                        || ((left.getBounds().y + left.getBounds().height) < (top.getBounds().y + top.getBounds().height)
492
                        ||  (right.getBounds().y + right.getBounds().height) < (bottom.getBounds().y + bottom.getBounds().height)))) {
493
                    // is between left and right while center is missing.
494
                    tryToSetVertical(left, right, point.x);
495
                }
496
497
                // No resizing if the splits were not found.
498
                if(horizontal != null || vertical != null) {
499
                    resizing = true;
500
                } else {
501
                    resizing = false;
502
                    return;
503
                }
504
505
                // Sets values to pane.
506
                pPane.horiz = horizontal;
507
                pPane.vert = vertical;
508
                if(vertical != null) {
509
                    pPane.deltaX = point.x - vertical.x;
510
                }
511
                if(horizontal != null) {
512
                    pPane.deltaY = point.y - horizontal.y;
513
                }
514
                pPane.newLoc =  point;
515
516
                // Set orientation when both split are positioned.
517
                if(horizontal != null && vertical != null) {
518
                    if(!vertical.contains(point.x, point.y + (horizontal.height + 1))) {
519
                        pPane.orientation = 1; // NORTH
520
                    } 
521
                    else if(!vertical.contains(point.x, point.y - (horizontal.height + 1))) {
522
                        pPane.orientation = 2; // SOUTH
523
                    }
524
                    else if(!horizontal.contains(point.x + (vertical.width + 1), point.y)) {
525
                        pPane.orientation = 3; // WEST
526
                    }
527
                    else if(!horizontal.contains(point.x - (vertical.width + 1), point.y)) {
528
                        pPane.orientation = 4; // EAST
529
                    }
530
                }
531
            }
532
        }
533
534
        private void tryToSetHorizontal(Component top, Component bottom, int y) {
535
            if((top.getBounds().y + top.getBounds().height) <= y
536
            && bottom.getBounds().y >= y) {
537
                horizontal = getHorizontalSplitRect(top.getBounds(), bottom.getBounds());
538
            }
539
        }
540
541
        private void tryToSetVertical(Component left, Component right, int x) {
542
            if((left.getBounds().x + left.getBounds().width) <= x
543
            && right.getBounds().x >= x) {
544
                vertical = getVerticalSplitRect(left.getBounds(), right.getBounds());
Line 320 Link Here
548
        private Rectangle getHorizontalSplitRect(Rectangle top, Rectangle bottom) {
549
            return new Rectangle(
550
                Math.min(top.x, bottom.x),
551
                top.y + top.height,
552
                Math.max(top.width, bottom.width),
553
                bottom.y - (top.y + top.height)
554
            );;
555
        }
556
        
557
        private Rectangle getVerticalSplitRect(Rectangle left, Rectangle right) {
558
            return new Rectangle(
559
                left.x + left.width,
560
                Math.min(left.y, right.y),
561
                right.x - (left.x + left.width),
562
                Math.max(left.height, right.height)
563
            );
564
        }
565
        
Line 324 Link Here
570
            
571
            horizontal = null;
572
            vertical = null;
573
            
574
            pPane.setDragging(false);
Line 325 Link Here
576
577
            Point newLoc = me.getPoint();
578
            Rectangle rect = pPane.getBounds();
579
            rect.setLocation(0, 0);
580
            if(rect.contains(newLoc)) {
581
                updateComponents(newLoc);
582
            }
Line 330 Link Here
588
                pPane.setDragging(true);
589
                
Lines 340-383 Link Here
340
                    HashMap comps = pPane.components;
600
                    // updateComponents(newLoc);
341
                    Rectangle pRect = pPane.getBounds();
601
                    pPane.newLoc = newLoc;
342
                    // resize appropriate comps if mouse pressed in proper pos
602
                    pPane.repaint();
343
                    // e.g. for the SOUTH component, we check that we are south
603
344
                    // of the desktop/NORTH component and north of the SOUTH 
345
                    // component
346
                    if (outcodes[NORTHSIDE] == Rectangle.OUT_BOTTOM) {
347
                        // resize the north panel
348
                        Component comp = (Component)comps.get(PerimeterLayout.NORTH);
349
                        if(comp != null) { // #25357
350
                            Rectangle rect = comp.getBounds();
351
                            rect.height = newLoc.y;
352
                            comp.setBounds(rect);
353
                        }
354
                    }
355
                    if (outcodes[SOUTHSIDE] == Rectangle.OUT_TOP) {
356
                        // resize the south panel
357
                        Component comp = (Component)comps.get(PerimeterLayout.SOUTH);
358
                        if(comp != null) { // #25357
359
                            Rectangle rect = comp.getBounds();
360
                            rect.height = pRect.height - newLoc.y - layout.getGap();
361
                            comp.setBounds(rect);
362
                        }
363
                    }
364
                    if (outcodes[EASTSIDE] == Rectangle.OUT_LEFT) {
365
                        // resize the east panel
366
                        Component comp = (Component)comps.get(PerimeterLayout.EAST);
367
                        if(comp != null) { // #25357
368
                            Rectangle rect = comp.getBounds();
369
                            rect.width = pRect.width - newLoc.x - layout.getGap();
370
                            rect.x = newLoc.x;
371
                            comp.setBounds(rect);
372
                        }
373
                    }
374
                    if (outcodes[WESTSIDE] == Rectangle.OUT_RIGHT) {
375
                        // resize the west panel
376
                        Component comp = (Component)comps.get(PerimeterLayout.WEST);
377
                        if(comp != null) { // #25357
378
                            Rectangle rect = comp.getBounds();
379
                            rect.width = newLoc.x;
380
                            comp.setBounds(rect);
381
                        }
382
                    }
383
                    
384
--
Line 386 Link Here
386
                    pPane.revalidate();
Line 391 Link Here
610
        private void updateComponents(Point newLoc) {
611
            HashMap comps = pPane.components;
612
            Rectangle pRect = pPane.getBounds();
613
            // resize appropriate comps if mouse pressed in proper pos
614
            // e.g. for the SOUTH component, we check that we are south
615
            // of the desktop/NORTH component and north of the SOUTH 
616
            // component
617
            if (outcodes[NORTHSIDE] == Rectangle.OUT_BOTTOM) {
618
//                System.err.println("\nUpdating north"); // TEMP
619
                // resize the north panel
620
                Component comp = (Component)comps.get(PerimeterLayout.NORTH);
621
                if(comp != null) { // #25357
622
                    Rectangle rect = comp.getBounds();
623
                    rect.height = newLoc.y;
624
                    comp.setBounds(rect);
625
                }
626
            }
627
            if (outcodes[SOUTHSIDE] == Rectangle.OUT_TOP) {
628
//                System.err.println("\nUpdating south"); // TEMP
629
                // resize the south panel
630
                Component comp = (Component)comps.get(PerimeterLayout.SOUTH);
631
                if(comp != null) { // #25357
632
                    Rectangle rect = comp.getBounds();
633
                    rect.height = pRect.height - newLoc.y - layout.getGap();
634
                    comp.setBounds(rect);
635
                }
636
            }
637
            if (outcodes[EASTSIDE] == Rectangle.OUT_LEFT) {
638
//                System.err.println("\nUpdating west"); // TEMP
639
                // resize the east panel
640
                Component comp = (Component)comps.get(PerimeterLayout.EAST);
641
                if(comp != null) { // #25357
642
                    Rectangle rect = comp.getBounds();
643
                    rect.width = pRect.width - newLoc.x - layout.getGap();
644
                    rect.x = newLoc.x;
645
                    comp.setBounds(rect);
646
                }
647
            }
648
            if (outcodes[WESTSIDE] == Rectangle.OUT_RIGHT) {
649
//                System.err.println("\nUpdating east"); // TEMP
650
                // resize the west panel
651
                Component comp = (Component)comps.get(PerimeterLayout.WEST);
652
                if(comp != null) { // #25357
653
                    Rectangle rect = comp.getBounds();
654
                    rect.width = newLoc.x;
655
                    comp.setBounds(rect);
656
                }
657
            }
658
            pPane.revalidate();
659
        }
660
        
661
        
Line 475 Link Here
475
            return (compRect.contains(newLoc) ? comp.getBounds().outcode(newLoc) : 0);
746
            int outcode = (compRect.contains(newLoc) ? comp.getBounds().outcode(newLoc) : 0);
476
--
747
            
748
//            // Clear vertical outcodes if horizontal split was not found.
749
//            if(horizontal == null) {
750
//                if((outcode & Rectangle.OUT_TOP) == Rectangle.OUT_TOP) {
751
//                    outcode ^= Rectangle.OUT_TOP;
752
//                }
753
//                if((outcode & Rectangle.OUT_BOTTOM) == Rectangle.OUT_BOTTOM) {
754
//                    outcode ^= Rectangle.OUT_BOTTOM;
755
//                }
756
//            }
757
//            // Clear horizontal outcodes if vertical split was not found.
758
//            if(vertical == null) {
759
//                if((outcode & Rectangle.OUT_LEFT) == Rectangle.OUT_LEFT) {
760
//                    outcode ^= Rectangle.OUT_LEFT;
761
//                }
762
//                if((outcode & Rectangle.OUT_RIGHT) == Rectangle.OUT_RIGHT) {
763
//                    outcode ^= Rectangle.OUT_RIGHT;
764
//                }
765
//            }
766
            
767
            return outcode;

Return to bug 27794