Fixed a bug in the right justification code related to insets handling.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@346 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-10-09 19:46:31 +00:00
parent 4f0738bc19
commit 9037e049a4
3 changed files with 23 additions and 19 deletions
@@ -1,5 +1,5 @@
// //
// $Id: GroupLayoutTest.java,v 1.2 2001/08/11 22:43:28 mdb Exp $ // $Id: GroupLayoutTest.java,v 1.3 2001/10/09 19:46:31 mdb Exp $
// //
// samskivert library - useful routines for java programs // samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne // Copyright (C) 2001 Michael Bayne
@@ -33,9 +33,12 @@ public class GroupLayoutTest
GroupLayout layout = new HGroupLayout(); GroupLayout layout = new HGroupLayout();
layout.setJustification(GroupLayout.CENTER); layout.setJustification(GroupLayout.CENTER);
layout.setPolicy(GroupLayout.STRETCH); layout.setPolicy(GroupLayout.STRETCH);
layout.setJustification(GroupLayout.RIGHT);
layout.setGap(15); layout.setGap(15);
panel.setLayout(layout); panel.setLayout(layout);
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
JButton butone = new JButton("One"); JButton butone = new JButton("One");
panel.add(butone, GroupLayout.FIXED); panel.add(butone, GroupLayout.FIXED);
JButton buttwo = new JButton("Two"); JButton buttwo = new JButton("Two");
@@ -1,5 +1,5 @@
// //
// $Id: HGroupLayout.java,v 1.7 2001/10/09 19:21:37 mdb Exp $ // $Id: HGroupLayout.java,v 1.8 2001/10/09 19:46:31 mdb Exp $
// //
// samskivert library - useful routines for java programs // samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne // Copyright (C) 2001 Michael Bayne
@@ -95,7 +95,7 @@ public class HGroupLayout extends GroupLayout
b.height -= (insets.top + insets.bottom); b.height -= (insets.top + insets.bottom);
int nk = parent.getComponentCount(); int nk = parent.getComponentCount();
int sx = insets.left, sy = insets.top; int sx, sy;
int totwid, totgap = _gap * (info.count-1); int totwid, totgap = _gap * (info.count-1);
int freecount = info.count - info.numfix; int freecount = info.count - info.numfix;
@@ -135,11 +135,9 @@ public class HGroupLayout extends GroupLayout
case STRETCH: case STRETCH:
defhei = b.height; defhei = b.height;
break; break;
case EQUALIZE: case EQUALIZE:
defhei = info.maxhei; defhei = info.maxhei;
break; break;
default: default:
case NONE: case NONE:
break; break;
@@ -147,12 +145,17 @@ public class HGroupLayout extends GroupLayout
// do the justification-related calculations // do the justification-related calculations
switch (_justification) { switch (_justification) {
default:
case LEFT:
case TOP:
sx = insets.left;
break;
case CENTER: case CENTER:
sx += (b.width - totwid)/2; sx = insets.left + (b.width - totwid)/2;
break; break;
case RIGHT: case RIGHT:
case BOTTOM: case BOTTOM:
sx += b.width - totwid - insets.right; sx = insets.left + b.width - totwid;
break; break;
} }
@@ -186,12 +189,10 @@ public class HGroupLayout extends GroupLayout
case TOP: case TOP:
sy = insets.top; sy = insets.top;
break; break;
case RIGHT: case RIGHT:
case BOTTOM: case BOTTOM:
sy = b.height - newhei - insets.bottom; sy = insets.top + b.height - newhei;
break; break;
default: default:
case CENTER: case CENTER:
sy = insets.top + (b.height - newhei)/2; sy = insets.top + (b.height - newhei)/2;
@@ -1,5 +1,5 @@
// //
// $Id: VGroupLayout.java,v 1.7 2001/10/09 19:21:37 mdb Exp $ // $Id: VGroupLayout.java,v 1.8 2001/10/09 19:46:31 mdb Exp $
// //
// samskivert library - useful routines for java programs // samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne // Copyright (C) 2001 Michael Bayne
@@ -95,7 +95,7 @@ public class VGroupLayout extends GroupLayout
b.height -= (insets.top + insets.bottom); b.height -= (insets.top + insets.bottom);
int nk = parent.getComponentCount(); int nk = parent.getComponentCount();
int sx = insets.left, sy = insets.top; int sx, sy;
int tothei, totgap = _gap * (info.count-1); int tothei, totgap = _gap * (info.count-1);
int freecount = info.count - info.numfix; int freecount = info.count - info.numfix;
@@ -135,11 +135,9 @@ public class VGroupLayout extends GroupLayout
case STRETCH: case STRETCH:
defwid = b.width; defwid = b.width;
break; break;
case EQUALIZE: case EQUALIZE:
defwid = info.maxwid; defwid = info.maxwid;
break; break;
default: default:
case NONE: case NONE:
break; break;
@@ -147,12 +145,16 @@ public class VGroupLayout extends GroupLayout
// do the justification-related calculations // do the justification-related calculations
switch (_justification) { switch (_justification) {
default:
case LEFT:
case TOP:
sy = insets.top;
case CENTER: case CENTER:
sy += (b.height - tothei)/2; sy = insets.top + (b.height - tothei)/2;
break; break;
case RIGHT: case RIGHT:
case BOTTOM: case BOTTOM:
sy += b.height - tothei - insets.bottom; sy = insets.top + b.height - tothei;
break; break;
} }
@@ -186,12 +188,10 @@ public class VGroupLayout extends GroupLayout
case TOP: case TOP:
sx = insets.left; sx = insets.left;
break; break;
case RIGHT: case RIGHT:
case BOTTOM: case BOTTOM:
sx = b.width - newwid - insets.right; sx = insets.left + b.width - newwid;
break; break;
default: default:
case CENTER: case CENTER:
sx = insets.left + (b.width - newwid)/2; sx = insets.left + (b.width - newwid)/2;