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 (-45 / +331 lines)
Lines 74-79 Link Here
74
            g.fillRect (0,0,getWidth(), getHeight());
74
            g.fillRect (0,0,getWidth(), getHeight());
75
        }
75
        }
76
    }
76
    }
77
78
79
    // Fields used by dragging paint.
80
    private boolean drag;
81
    private Rectangle horiz;
82
    private Rectangle vert;
83
    private Point newLoc;
84
    private int deltaX;
85
    private int deltaY;
86
    private int orientation;
87
    
88
    private void setDragging(boolean drag) {
89
        this.drag = drag;
90
        
91
        if(!drag) {
92
            horiz = null;
93
            vert = null;
94
            newLoc = null;
95
            deltaX = 0;
96
            deltaY = 0;
97
            orientation = 0;
98
        }
99
    }
100
    
101
    /** Overrides superclass method, to provide more efficient paint during
102
     * dragging. */
103
    public void paint(Graphics g) {
104
        super.paint(g);
105
106
        if(drag) {
107
            Rectangle h = horiz;
108
            Rectangle v = vert;
109
110
            Point newPoint = newLoc;
111
            
112
            if(!getBounds().contains(newPoint)) {
113
                return;
114
            }
115
            
116
            Color old = g.getColor();
117
            g.setColor(Color.darkGray);
118
            
119
            // Draw horizontal split.
120
            if(h != null && newPoint != null) {
121
                h.setLocation(h.x, newPoint.y + deltaY);
122
                if(orientation == 3) { // WEST
123
                    h.setBounds(h.x, h.y, (newPoint.x + deltaX) - h.x, h.height);
124
                } 
125
                else if(orientation == 4) {
126
                    h.setBounds((newPoint.x + deltaX), h.y, h.width - ((newPoint.x + deltaX) - h.x), h.height);
127
                }
128
                g.fillRect(h.x, h.y, h.width, h.height);
129
            }
130
            
131
            // Draw vertical split.
132
            if(v != null && newPoint != null) {
133
                v.setLocation(newPoint.x + deltaX, v.y);
134
                if(orientation == 1) { // NORTH
135
                    v.setBounds(v.x, v.y, v.width, (newPoint.y + deltaY) - v.y);
136
                }
137
                else if(orientation == 2) { // SOUTH
138
                    v.setBounds(v.x, (newPoint.y + deltaY), v.width, v.height - ((newPoint.y + deltaY) - v.y));
139
                }
140
                
141
                g.fillRect(v.x, v.y, v.width, v.height);
142
            }
143
            
144
            g.setColor(old);
145
        }
146
    }
77
    
147
    
78
    /**
148
    /**
79
     * Relese resources so that PerimeterPane instance can be garbage collected.
149
     * Relese resources so that PerimeterPane instance can be garbage collected.
Lines 304-309 Link Here
304
374
305
        // save the old cursor...
375
        // save the old cursor...
306
        int oldCursorType = pPane.getCursor().getType();
376
        int oldCursorType = pPane.getCursor().getType();
377
378
        // Fields working when dragging 'split'
379
        private Rectangle horizontal;
380
        private Rectangle vertical;
307
        boolean sizingCursorSet = false;
381
        boolean sizingCursorSet = false;
308
        
382
        
309
        public PerimeterGapListener() {
383
        public PerimeterGapListener() {
Lines 311-332 Link Here
311
385
312
        public void mousePressed(final MouseEvent me) {
386
        public void mousePressed(final MouseEvent me) {
313
            if ((me.getModifiers() & me.BUTTON1_MASK) != 0) {
387
            if ((me.getModifiers() & me.BUTTON1_MASK) != 0) {
314
                // get original position
388
                // update mouse location
315
                mouseLocation = me.getPoint();
389
                mouseLocation = me.getPoint();
316
                // resizing if clicked directly on JPanel
390
317
                resizing = (pPane.getComponentAt(mouseLocation) == pPane);
391
                Point point = mouseLocation;
392
                // No resizing if not clicked directly at pane.
393
                if(pPane.getComponentAt(point) != pPane) {
394
                    return;
395
                }
396
                
397
                // Retrieve split rectangles.
398
                Component top = (Component)pPane.components.get(PerimeterLayout.NORTH);
399
                Component bottom = (Component)pPane.components.get(PerimeterLayout.SOUTH);
400
                Component center = (Component)pPane.components.get(PerimeterLayout.CENTER);
401
                Component left = (Component)pPane.components.get(PerimeterLayout.WEST);
402
                Component right = (Component)pPane.components.get(PerimeterLayout.EAST);
403
                
404
                // is horizontal?
405
                if(top != null && center != null) {
406
                    // is horizontal between top and center.
407
                    tryToSetHorizontal(top, center, point.y);
408
                }
409
                if(horizontal == null && center != null && bottom != null) {
410
                    // is between center and bottom
411
                    tryToSetHorizontal(center, bottom, point.y);
412
                }
413
                // when center is missing also left or right could be under top/ or above bottom.
414
                if(horizontal == null && top != null && left != null && center == null) {
415
                    tryToSetHorizontal(top, left, point.y);
416
                }
417
                if(horizontal == null && top != null && right != null && center == null) {
418
                    tryToSetHorizontal(top, right, point.y);
419
                }
420
                if(horizontal == null && left != null && bottom != null && center == null) {
421
                    tryToSetHorizontal(left, bottom, point.y);
422
                }
423
                if(horizontal == null && right != null && bottom != null && center == null) {
424
                    tryToSetHorizontal(right, bottom, point.y);
425
                }
426
                // even top and bottom could be side by side.
427
                if(horizontal == null && top != null && bottom != null && center == null
428
                && (left == null || (left.getBounds().x < top.getBounds().x
429
                        || left.getBounds().x < bottom.getBounds().x))
430
                && (right == null
431
                        || ((top.getBounds().x + top.getBounds().width) < (right.getBounds().x + right.getBounds().width)
432
                        ||  (bottom.getBounds().x + bottom.getBounds().width) < (right.getBounds().x + right.getBounds().width)))) {
433
                    // is between top and bottom while center is missing.
434
                    tryToSetHorizontal(top, bottom, point.y);
435
                }
436
                
437
                
438
                
439
                // is vertical?
440
                if(left != null && center != null) {
441
                    // is horizontal between left and center.
442
                    tryToSetVertical(left, center, point.x);
443
                }
444
                if(vertical == null && center != null && right != null) {
445
                    // is between center and right
446
                    tryToSetVertical(center, right, point.x);
447
                }
448
                // when center is missing also top or bottom could be right from left or left from righ.
449
                if(vertical == null && left != null && top != null && center == null) {
450
                    tryToSetVertical(left, top, point.x);
451
                }
452
                if(vertical == null && left != null && bottom != null && center == null) {
453
                    tryToSetVertical(left, bottom, point.x);
454
                }
455
                if(vertical == null && top != null && right != null && center == null) {
456
                    tryToSetVertical(top, right, point.x);
457
                }
458
                if(vertical == null && bottom != null && right != null && center == null) {
459
                    tryToSetVertical(bottom, right, point.x);
460
                }
461
                // even left and right could be side by side.
462
                if(vertical == null && left != null && right != null && center == null
463
                && (top == null || (top.getBounds().y < left.getBounds().y || top.getBounds().y < right.getBounds().y))
464
                && (bottom == null
465
                        || ((left.getBounds().y + left.getBounds().height) < (top.getBounds().y + top.getBounds().height)
466
                        ||  (right.getBounds().y + right.getBounds().height) < (bottom.getBounds().y + bottom.getBounds().height)))) {
467
                    // is between left and right while center is missing.
468
                    tryToSetVertical(left, right, point.x);
469
                }
470
471
                // No resizing if the splits were not found.
472
                if(horizontal != null || vertical != null) {
473
                    resizing = true;
474
                } else {
475
                    resizing = false;
476
                    return;
477
                }
478
479
                // Sets values to pane.
480
                pPane.horiz = horizontal;
481
                pPane.vert = vertical;
482
                if(vertical != null) {
483
                    pPane.deltaX = point.x - vertical.x;
484
                }
485
                if(horizontal != null) {
486
                    pPane.deltaY = point.y - horizontal.y;
487
                }
488
                pPane.newLoc =  point;
489
490
                // Set orientation when both split are positioned.
491
                if(horizontal != null && vertical != null) {
492
                    if(!vertical.contains(point.x, point.y + (horizontal.height + 1))) {
493
                        pPane.orientation = 1; // NORTH
494
                    } 
495
                    else if(!vertical.contains(point.x, point.y - (horizontal.height + 1))) {
496
                        pPane.orientation = 2; // SOUTH
497
                    }
498
                    else if(!horizontal.contains(point.x + (vertical.width + 1), point.y)) {
499
                        pPane.orientation = 3; // WEST
500
                    }
501
                    else if(!horizontal.contains(point.x - (vertical.width + 1), point.y)) {
502
                        pPane.orientation = 4; // EAST
503
                    }
504
                }
318
            }
505
            }
319
        }
506
        }
507
508
        private void tryToSetHorizontal(Component top, Component bottom, int y) {
509
            if((top.getBounds().y + top.getBounds().height) <= y
510
            && bottom.getBounds().y >= y) {
511
                horizontal = getHorizontalSplitRect(top.getBounds(), bottom.getBounds());
512
            }
513
        }
514
515
        private void tryToSetVertical(Component left, Component right, int x) {
516
            if((left.getBounds().x + left.getBounds().width) <= x
517
            && right.getBounds().x >= x) {
518
                vertical = getVerticalSplitRect(left.getBounds(), right.getBounds());
519
            }
520
        }
521
        private Rectangle getHorizontalSplitRect(Rectangle top, Rectangle bottom) {
522
            return new Rectangle(
523
                Math.min(top.x, bottom.x),
524
                top.y + top.height,
525
                Math.max(top.width, bottom.width),
526
                bottom.y - (top.y + top.height)
527
            );;
528
        }
529
        
530
        private Rectangle getVerticalSplitRect(Rectangle left, Rectangle right) {
531
            return new Rectangle(
532
                left.x + left.width,
533
                Math.min(left.y, right.y),
534
                right.x - (left.x + left.width),
535
                Math.max(left.height, right.height)
536
            );
537
        }
538
        
320
        
539
        
321
        public void mouseReleased(final MouseEvent me) {
540
        public void mouseReleased(final MouseEvent me) {
322
            // resizing done
541
            // resizing done
323
            resizing = false;
542
            resizing = false;
543
            
544
            horizontal = null;
545
            vertical = null;
546
            
547
            pPane.setDragging(false);
324
            dragging = false;
548
            dragging = false;
549
550
            Point newLoc = me.getPoint();
551
            Rectangle rect = pPane.getBounds();
552
            rect.setLocation(0, 0);
553
            if(rect.contains(newLoc)) {
554
                updateComponents(newLoc);
555
            }
325
            pPane.setCursor(Cursor.getPredefinedCursor(oldCursorType));
556
            pPane.setCursor(Cursor.getPredefinedCursor(oldCursorType));
557
            pPane.repaint();
326
        }
558
        }
327
559
328
        public void mouseDragged(final MouseEvent me) {
560
        public void mouseDragged(final MouseEvent me) {
329
            if (resizing == true) {
561
            if (resizing == true) {
562
                pPane.setDragging(true);
563
                
330
                dragging = true;
564
                dragging = true;
331
                // get new position
565
                // get new position
332
                Point newLoc = me.getPoint();
566
                Point newLoc = me.getPoint();
Lines 338-394 Link Here
338
                
572
                
339
                // only move if greater than CHANGE pixels than the last position
573
                // only move if greater than CHANGE pixels than the last position
340
                if (newLoc.distance(mouseLocation) > CHANGE) {
574
                if (newLoc.distance(mouseLocation) > CHANGE) {
341
                    HashMap comps = pPane.components;
575
                    // updateComponents(newLoc); // old fashion
342
                    Rectangle pRect = pPane.getBounds();
576
                    
343
                    // resize appropriate comps if mouse pressed in proper pos
577
                    pPane.newLoc = newLoc;
344
                    // e.g. for the SOUTH component, we check that we are south
578
                    
345
                    // of the desktop/NORTH component and north of the SOUTH 
579
                    Rectangle h = horiz;
346
                    // component
580
                    Rectangle v = vert;
347
                    if (outcodes[NORTHSIDE] == Rectangle.OUT_BOTTOM) {
581
348
                        // resize the north panel
582
                    
349
                        Component comp = (Component)comps.get(PerimeterLayout.NORTH);
583
                    Point newPoint = newLoc;
350
                        if(comp != null) { // #25357
584
                    // Repaint new splits.
351
                            Rectangle rect = comp.getBounds();
585
                    if(getBounds().contains(newPoint)) {
352
                            rect.height = newLoc.y;
586
                        // Draw horizontal split.
353
                            comp.setBounds(rect);
587
                        if(h != null && newPoint != null) {
354
                        }
588
                            Rectangle hh = (Rectangle)h.clone();
355
                    }
589
                            hh.setLocation(hh.x, newPoint.y + deltaY);
356
                    if (outcodes[SOUTHSIDE] == Rectangle.OUT_TOP) {
590
                            if(orientation == 3) { // WEST
357
                        // resize the south panel
591
                                hh.setBounds(hh.x, hh.y, (newPoint.x + deltaX) - hh.x, h.height);
358
                        Component comp = (Component)comps.get(PerimeterLayout.SOUTH);
592
                            } 
359
                        if(comp != null) { // #25357
593
                            else if(orientation == 4) {
360
                            Rectangle rect = comp.getBounds();
594
                                hh.setBounds((newPoint.x + deltaX), hh.y, hh.width - ((newPoint.x + deltaX) - h.x), hh.height);
361
                            rect.height = pRect.height - newLoc.y - layout.getGap();
595
                            }
362
                            comp.setBounds(rect);
596
                            h = h.union(hh);
363
                        }
597
                        }
364
                    }
598
365
                    if (outcodes[EASTSIDE] == Rectangle.OUT_LEFT) {
599
                        // Draw vertical split.
366
                        // resize the east panel
600
                        if(v != null && newPoint != null) {
367
                        Component comp = (Component)comps.get(PerimeterLayout.EAST);
601
                            Rectangle vv = (Rectangle)v.clone();
368
                        if(comp != null) { // #25357
602
                            vv.setLocation(newPoint.x + deltaX, vv.y);
369
                            Rectangle rect = comp.getBounds();
603
                            if(orientation == 1) { // NORTH
370
                            rect.width = pRect.width - newLoc.x - layout.getGap();
604
                                vv.setBounds(vv.x, vv.y, vv.width, (newPoint.y + deltaY) - vv.y);
371
                            rect.x = newLoc.x;
605
                            }
372
                            comp.setBounds(rect);
606
                            else if(orientation == 2) { // SOUTH
607
                                vv.setBounds(vv.x, (newPoint.y + deltaY), vv.width, vv.height - ((newPoint.y + deltaY) - vv.y));
608
                            }
609
                            v = v.union(vv);
373
                        }
610
                        }
374
                    }
611
                    }
375
                    if (outcodes[WESTSIDE] == Rectangle.OUT_RIGHT) {
612
376
                        // resize the west panel
613
                    // Paint regions: horizontal and vertical if necessary.
377
                        Component comp = (Component)comps.get(PerimeterLayout.WEST);
614
                    if(h != null) {
378
                        if(comp != null) { // #25357
615
                        pPane.repaint(h);
379
                            Rectangle rect = comp.getBounds();
616
                    } 
380
                            rect.width = newLoc.x;
617
                    if(v != null) {
381
                            comp.setBounds(rect);
618
                        pPane.repaint(v);
382
                        }
383
                    }
619
                    }
384
                    
620
385
                    // update the postition
621
                    // update the postition
386
                    mouseLocation = newLoc;
622
                    mouseLocation = newLoc;
387
                    pPane.revalidate();
388
                }
623
                }
389
            }
624
            }
390
        }
625
        }
391
        
626
        
627
        private void updateComponents(Point newLoc) {
628
            HashMap comps = pPane.components;
629
            Rectangle pRect = pPane.getBounds();
630
            // resize appropriate comps if mouse pressed in proper pos
631
            // e.g. for the SOUTH component, we check that we are south
632
            // of the desktop/NORTH component and north of the SOUTH 
633
            // component
634
            if (outcodes[NORTHSIDE] == Rectangle.OUT_BOTTOM) {
635
                // resize the north panel
636
                Component comp = (Component)comps.get(PerimeterLayout.NORTH);
637
                if(comp != null) { // #25357
638
                    Rectangle rect = comp.getBounds();
639
                    rect.height = newLoc.y;
640
                    comp.setBounds(rect);
641
                }
642
            }
643
            if (outcodes[SOUTHSIDE] == Rectangle.OUT_TOP) {
644
                // resize the south panel
645
                Component comp = (Component)comps.get(PerimeterLayout.SOUTH);
646
                if(comp != null) { // #25357
647
                    Rectangle rect = comp.getBounds();
648
                    rect.height = pRect.height - newLoc.y - layout.getGap();
649
                    comp.setBounds(rect);
650
                }
651
            }
652
            if (outcodes[EASTSIDE] == Rectangle.OUT_LEFT) {
653
                // resize the east panel
654
                Component comp = (Component)comps.get(PerimeterLayout.EAST);
655
                if(comp != null) { // #25357
656
                    Rectangle rect = comp.getBounds();
657
                    rect.width = pRect.width - newLoc.x - layout.getGap();
658
                    rect.x = newLoc.x;
659
                    comp.setBounds(rect);
660
                }
661
            }
662
            if (outcodes[WESTSIDE] == Rectangle.OUT_RIGHT) {
663
                // resize the west panel
664
                Component comp = (Component)comps.get(PerimeterLayout.WEST);
665
                if(comp != null) { // #25357
666
                    Rectangle rect = comp.getBounds();
667
                    rect.width = newLoc.x;
668
                    comp.setBounds(rect);
669
                }
670
            }
671
            pPane.revalidate();
672
        }
673
        
674
        
675
        
392
        /** Required for MouseMotionListener. */
676
        /** Required for MouseMotionListener. */
393
        public void mouseMoved(final java.awt.event.MouseEvent me) {
677
        public void mouseMoved(final java.awt.event.MouseEvent me) {
394
            Component comp = pPane.getComponentAt(me.getPoint());
678
            Component comp = pPane.getComponentAt(me.getPoint());
Lines 473-479 Link Here
473
            compRect.grow(gap * 2, gap * 2);
757
            compRect.grow(gap * 2, gap * 2);
474
            
758
            
475
            // return an outcode if the mouse is within the gaps between comp's
759
            // return an outcode if the mouse is within the gaps between comp's
476
            return (compRect.contains(newLoc) ? comp.getBounds().outcode(newLoc) : 0);
760
            int outcode = (compRect.contains(newLoc) ? comp.getBounds().outcode(newLoc) : 0);
761
            
762
            return outcode;
477
        }
763
        }
478
764
479
        // note that the center component is not considered when choosing 
765
        // note that the center component is not considered when choosing 

Return to bug 27794