Index: core/src/org/netbeans/core/windows/frames/PerimeterPane.java =================================================================== RCS file: /cvs/core/src/org/netbeans/core/windows/frames/PerimeterPane.java,v --- core/src/org/netbeans/core/windows/frames/PerimeterPane.java 1.22 +++ core/src/org/netbeans/core/windows/frames/PerimeterPane.java @@ -77,0 +77,97 @@ + + + // Fields used by dragging paint. + private boolean drag; + private java.awt.image.BufferedImage image; + private Rectangle horiz; + private Rectangle vert; + private Point newLoc; + private int deltaX; + private int deltaY; + private int orientation; + + private void setDragging(boolean drag) { + this.drag = drag; + if(!drag) { + image = null; + horiz = null; + vert = null; + newLoc = null; + deltaX = 0; + deltaY = 0; + orientation = 0; + } + } + + /** Overrides superclass method, to provide more efficient paint during + * dragging. */ + public void paint(Graphics g) { + if(!drag) { + super.paint(g); + } else { + // Get image of pane for this drag session. + if(image == null) { + Rectangle clip = g.getClipBounds(); + image = new java.awt.image.BufferedImage( + clip.width, clip.height, + java.awt.image.BufferedImage.TYPE_INT_ARGB); + super.paint(image.getGraphics()); + g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null); + } + + Rectangle h = horiz; + Rectangle v = vert; + + // [PENDING ]Following is not enough, it is after this paint invalidated or what. + // Needs to find out why, the background is grayed. + // This needs to be resolved to get the best speed. +// if(h != null) { +// java.awt.image.BufferedImage subImage = image.getSubimage(h.x, h.y, h.width, h.height); +// g.drawImage(subImage, h.x, h.y, subImage.getWidth(), subImage.getHeight(), null); +// } +// if(v != null) { +// java.awt.image.BufferedImage subImage = image.getSubimage(v.x, v.y, v.width, v.height); +// g.drawImage(subImage, v.x, v.y, subImage.getWidth(), subImage.getHeight(), null); +// } + g.drawImage(image, 0, 0, image.getWidth(this), image.getHeight(this), null); + + + Point newPoint = newLoc; + + if(!getBounds().contains(newPoint)) { + return; + } + + Color old = g.getColor(); + g.setColor(Color.darkGray); + + // Draw horizontal split. + if(h != null && newPoint != null) { + h.setLocation(h.x, newPoint.y + deltaY); + if(orientation == 3) { // WEST + h.setBounds(h.x, h.y, (newPoint.x + deltaX) - h.x, h.height); + } + else if(orientation == 4) { + h.setBounds((newPoint.x + deltaX), h.y, h.width - ((newPoint.x + deltaX) - h.x), h.height); + } + g.fillRect(h.x, h.y, h.width, h.height); + } + + // Draw vertical split. + if(v != null && newPoint != null) { + v.setLocation(newPoint.x + deltaX, v.y); + if(orientation == 1) { // NORTH + v.setBounds(v.x, v.y, v.width, (newPoint.y + deltaY) - v.y); + } + else if(orientation == 2) { // SOUTH + v.setBounds(v.x, (newPoint.y + deltaY), v.width, v.height - ((newPoint.y + deltaY) - v.y)); + } + + g.fillRect(v.x, v.y, v.width, v.height); + } + + g.setColor(old); + } + + + } @@ -307,0 +404,4 @@ + + // Fields working when dragging 'split' + private Rectangle horizontal; + private Rectangle vertical; @@ -313,1 +414,1 @@ - // get original position --- + // update mouse location @@ -315,2 +416,129 @@ - // resizing if clicked directly on JPanel - resizing = (pPane.getComponentAt(mouseLocation) == pPane); --- + + Point point = mouseLocation; + // No resizing if not clicked directly at pane. + if(pPane.getComponentAt(point) != pPane) { + return; + } + + // Retrieve split rectangles. + Component top = (Component)pPane.components.get(PerimeterLayout.NORTH); + Component bottom = (Component)pPane.components.get(PerimeterLayout.SOUTH); + Component center = (Component)pPane.components.get(PerimeterLayout.CENTER); + Component left = (Component)pPane.components.get(PerimeterLayout.WEST); + Component right = (Component)pPane.components.get(PerimeterLayout.EAST); + + // is horizontal? + if(top != null && center != null) { + // is horizontal between top and center. + tryToSetHorizontal(top, center, point.y); + } + if(horizontal == null && center != null && bottom != null) { + // is between center and bottom + tryToSetHorizontal(center, bottom, point.y); + } + // when center is missing also left or right could be under top/ or above bottom. + if(horizontal == null && top != null && left != null && center == null) { + tryToSetHorizontal(top, left, point.y); + } + if(horizontal == null && top != null && right != null && center == null) { + tryToSetHorizontal(top, right, point.y); + } + if(horizontal == null && left != null && bottom != null && center == null) { + tryToSetHorizontal(left, bottom, point.y); + } + if(horizontal == null && right != null && bottom != null && center == null) { + tryToSetHorizontal(right, bottom, point.y); + } + // even top and bottom could be side by side. + if(horizontal == null && top != null && bottom != null && center == null + && (left == null || (left.getBounds().x < top.getBounds().x + || left.getBounds().x < bottom.getBounds().x)) + && (right == null + || ((top.getBounds().x + top.getBounds().width) < (right.getBounds().x + right.getBounds().width) + || (bottom.getBounds().x + bottom.getBounds().width) < (right.getBounds().x + right.getBounds().width)))) { + // is between top and bottom while center is missing. + tryToSetHorizontal(top, bottom, point.y); + } + + + + // is vertical? + if(left != null && center != null) { + // is horizontal between left and center. + tryToSetVertical(left, center, point.x); + } + if(vertical == null && center != null && right != null) { + // is between center and right + tryToSetVertical(center, right, point.x); + } + // when center is missing also top or bottom could be right from left or left from righ. + if(vertical == null && left != null && top != null && center == null) { + tryToSetVertical(left, top, point.x); + } + if(vertical == null && left != null && bottom != null && center == null) { + tryToSetVertical(left, bottom, point.x); + } + if(vertical == null && top != null && right != null && center == null) { + tryToSetVertical(top, right, point.x); + } + if(vertical == null && bottom != null && right != null && center == null) { + tryToSetVertical(bottom, right, point.x); + } + // even left and right could be side by side. + if(vertical == null && left != null && right != null && center == null + && (top == null || (top.getBounds().y < left.getBounds().y || top.getBounds().y < right.getBounds().y)) + && (bottom == null + || ((left.getBounds().y + left.getBounds().height) < (top.getBounds().y + top.getBounds().height) + || (right.getBounds().y + right.getBounds().height) < (bottom.getBounds().y + bottom.getBounds().height)))) { + // is between left and right while center is missing. + tryToSetVertical(left, right, point.x); + } + + // No resizing if the splits were not found. + if(horizontal != null || vertical != null) { + resizing = true; + } else { + resizing = false; + return; + } + + // Sets values to pane. + pPane.horiz = horizontal; + pPane.vert = vertical; + if(vertical != null) { + pPane.deltaX = point.x - vertical.x; + } + if(horizontal != null) { + pPane.deltaY = point.y - horizontal.y; + } + pPane.newLoc = point; + + // Set orientation when both split are positioned. + if(horizontal != null && vertical != null) { + if(!vertical.contains(point.x, point.y + (horizontal.height + 1))) { + pPane.orientation = 1; // NORTH + } + else if(!vertical.contains(point.x, point.y - (horizontal.height + 1))) { + pPane.orientation = 2; // SOUTH + } + else if(!horizontal.contains(point.x + (vertical.width + 1), point.y)) { + pPane.orientation = 3; // WEST + } + else if(!horizontal.contains(point.x - (vertical.width + 1), point.y)) { + pPane.orientation = 4; // EAST + } + } + } + } + + private void tryToSetHorizontal(Component top, Component bottom, int y) { + if((top.getBounds().y + top.getBounds().height) <= y + && bottom.getBounds().y >= y) { + horizontal = getHorizontalSplitRect(top.getBounds(), bottom.getBounds()); + } + } + + private void tryToSetVertical(Component left, Component right, int x) { + if((left.getBounds().x + left.getBounds().width) <= x + && right.getBounds().x >= x) { + vertical = getVerticalSplitRect(left.getBounds(), right.getBounds()); @@ -320,0 +548,18 @@ + private Rectangle getHorizontalSplitRect(Rectangle top, Rectangle bottom) { + return new Rectangle( + Math.min(top.x, bottom.x), + top.y + top.height, + Math.max(top.width, bottom.width), + bottom.y - (top.y + top.height) + );; + } + + private Rectangle getVerticalSplitRect(Rectangle left, Rectangle right) { + return new Rectangle( + left.x + left.width, + Math.min(left.y, right.y), + right.x - (left.x + left.width), + Math.max(left.height, right.height) + ); + } + @@ -324,0 +570,5 @@ + + horizontal = null; + vertical = null; + + pPane.setDragging(false); @@ -325,0 +576,7 @@ + + Point newLoc = me.getPoint(); + Rectangle rect = pPane.getBounds(); + rect.setLocation(0, 0); + if(rect.contains(newLoc)) { + updateComponents(newLoc); + } @@ -330,0 +588,2 @@ + pPane.setDragging(true); + @@ -340,44 +600,4 @@ - HashMap comps = pPane.components; - Rectangle pRect = pPane.getBounds(); - // resize appropriate comps if mouse pressed in proper pos - // e.g. for the SOUTH component, we check that we are south - // of the desktop/NORTH component and north of the SOUTH - // component - if (outcodes[NORTHSIDE] == Rectangle.OUT_BOTTOM) { - // resize the north panel - Component comp = (Component)comps.get(PerimeterLayout.NORTH); - if(comp != null) { // #25357 - Rectangle rect = comp.getBounds(); - rect.height = newLoc.y; - comp.setBounds(rect); - } - } - if (outcodes[SOUTHSIDE] == Rectangle.OUT_TOP) { - // resize the south panel - Component comp = (Component)comps.get(PerimeterLayout.SOUTH); - if(comp != null) { // #25357 - Rectangle rect = comp.getBounds(); - rect.height = pRect.height - newLoc.y - layout.getGap(); - comp.setBounds(rect); - } - } - if (outcodes[EASTSIDE] == Rectangle.OUT_LEFT) { - // resize the east panel - Component comp = (Component)comps.get(PerimeterLayout.EAST); - if(comp != null) { // #25357 - Rectangle rect = comp.getBounds(); - rect.width = pRect.width - newLoc.x - layout.getGap(); - rect.x = newLoc.x; - comp.setBounds(rect); - } - } - if (outcodes[WESTSIDE] == Rectangle.OUT_RIGHT) { - // resize the west panel - Component comp = (Component)comps.get(PerimeterLayout.WEST); - if(comp != null) { // #25357 - Rectangle rect = comp.getBounds(); - rect.width = newLoc.x; - comp.setBounds(rect); - } - } - --- + // updateComponents(newLoc); + pPane.newLoc = newLoc; + pPane.repaint(); + @@ -386,1 +606,0 @@ - pPane.revalidate(); @@ -391,0 +610,52 @@ + private void updateComponents(Point newLoc) { + HashMap comps = pPane.components; + Rectangle pRect = pPane.getBounds(); + // resize appropriate comps if mouse pressed in proper pos + // e.g. for the SOUTH component, we check that we are south + // of the desktop/NORTH component and north of the SOUTH + // component + if (outcodes[NORTHSIDE] == Rectangle.OUT_BOTTOM) { +// System.err.println("\nUpdating north"); // TEMP + // resize the north panel + Component comp = (Component)comps.get(PerimeterLayout.NORTH); + if(comp != null) { // #25357 + Rectangle rect = comp.getBounds(); + rect.height = newLoc.y; + comp.setBounds(rect); + } + } + if (outcodes[SOUTHSIDE] == Rectangle.OUT_TOP) { +// System.err.println("\nUpdating south"); // TEMP + // resize the south panel + Component comp = (Component)comps.get(PerimeterLayout.SOUTH); + if(comp != null) { // #25357 + Rectangle rect = comp.getBounds(); + rect.height = pRect.height - newLoc.y - layout.getGap(); + comp.setBounds(rect); + } + } + if (outcodes[EASTSIDE] == Rectangle.OUT_LEFT) { +// System.err.println("\nUpdating west"); // TEMP + // resize the east panel + Component comp = (Component)comps.get(PerimeterLayout.EAST); + if(comp != null) { // #25357 + Rectangle rect = comp.getBounds(); + rect.width = pRect.width - newLoc.x - layout.getGap(); + rect.x = newLoc.x; + comp.setBounds(rect); + } + } + if (outcodes[WESTSIDE] == Rectangle.OUT_RIGHT) { +// System.err.println("\nUpdating east"); // TEMP + // resize the west panel + Component comp = (Component)comps.get(PerimeterLayout.WEST); + if(comp != null) { // #25357 + Rectangle rect = comp.getBounds(); + rect.width = newLoc.x; + comp.setBounds(rect); + } + } + pPane.revalidate(); + } + + @@ -475,1 +746,22 @@ - return (compRect.contains(newLoc) ? comp.getBounds().outcode(newLoc) : 0); --- + int outcode = (compRect.contains(newLoc) ? comp.getBounds().outcode(newLoc) : 0); + +// // Clear vertical outcodes if horizontal split was not found. +// if(horizontal == null) { +// if((outcode & Rectangle.OUT_TOP) == Rectangle.OUT_TOP) { +// outcode ^= Rectangle.OUT_TOP; +// } +// if((outcode & Rectangle.OUT_BOTTOM) == Rectangle.OUT_BOTTOM) { +// outcode ^= Rectangle.OUT_BOTTOM; +// } +// } +// // Clear horizontal outcodes if vertical split was not found. +// if(vertical == null) { +// if((outcode & Rectangle.OUT_LEFT) == Rectangle.OUT_LEFT) { +// outcode ^= Rectangle.OUT_LEFT; +// } +// if((outcode & Rectangle.OUT_RIGHT) == Rectangle.OUT_RIGHT) { +// outcode ^= Rectangle.OUT_RIGHT; +// } +// } + + return outcode;