1 /*********************************************************************
5 * Purpose : Utility functions for GridBag layout and centering
8 * Copyright : Written by and Copyright (C) 2003 the SourceForge
9 * Privoxy team. http://www.privoxy.org/
11 * Based on the Internet Junkbuster originally written
12 * by and Copyright (C) 1997 Anonymous Coders and
13 * Junkbusters Corporation. http://www.junkbusters.com
15 * This program is free software; you can redistribute it
16 * and/or modify it under the terms of the GNU General
17 * Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at
19 * your option) any later version.
21 * This program is distributed in the hope that it will
22 * be useful, but WITHOUT ANY WARRANTY; without even the
23 * implied warranty of MERCHANTABILITY or FITNESS FOR A
24 * PARTICULAR PURPOSE. See the GNU General Public
25 * License for more details.
27 * The GNU General Public License should be included with
28 * this file. If not, you can view it at
29 * http://www.gnu.org/copyleft/gpl.html
30 * or write to the Free Software Foundation, Inc., 59
31 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
35 *********************************************************************/
37 package org.privoxy.activityconsole;
42 * The ActivityConsoleGuiUtil class: Helper routines for the GridBag layout.
43 * @author Last Modified By: $Author$
44 * @version $Rev$-$Date$$State$
46 public class ActivityConsoleGuiUtil
48 private static final String
49 COPYRIGHT = org.privoxy.activityconsole.Copyright.COPYRIGHT;
51 /** constrain - Helper method for setting a componets constraints in a gridbag layout;
52 * takes all of the possible parameters for grid constraints.
53 * @param container conatiner to add the component to
54 * @param component component that will be added
55 * @param grid_x x value
56 * @param grid_y y value
57 * @param grid_width grid width for the component
58 * @param grid_height grid height for the component
59 * @param fill fill value
60 * @param anchor anchor value
61 * @param weight_x weight x
62 * @param weight_y weight y
63 * @param top top inset
64 * @param left left inset
65 * @param bottom bottom inset
66 * @param right right inset
69 public static void constrain(Container container,
84 GridBagConstraints c = new GridBagConstraints();
87 c.gridwidth = grid_width;
88 c.gridheight = grid_height;
93 if (top+bottom+left+right > 0)
94 c.insets = new Insets(top, left, bottom, right);
96 ((GridBagLayout)container.getLayout()).setConstraints(component, c);
97 container.add(component);
100 public static void constrain(Container container,
113 GridBagConstraints.NONE,
114 GridBagConstraints.NORTHWEST,
115 0.0, 0.0, 0, 0, 0, 0);
118 public static void constrain(Container container,
135 GridBagConstraints.NONE,
136 GridBagConstraints.NORTHWEST,
137 0.0, 0.0, top, left, bottom, right);
140 /** constrainLast - Helper method for setting a componets constraints in a gridbag layout;
141 * takes all of the possible parameters for grid constraints.
142 * @param container conatiner to add the component to
143 * @param component component that will be added
144 * @param grid_x x value
145 * @param grid_y y value
146 * @param top top inset
147 * @param left left inset
148 * @param bottom bottom inset
149 * @param right right inset
152 public static void constrainLast(Container container,
165 GridBagConstraints.REMAINDER,1,
166 GridBagConstraints.HORIZONTAL,
167 GridBagConstraints.NORTHWEST,
168 0.0, 0.0, top, left, bottom, right);
171 /** constrain - Helper method for setting a componets constraints in a gridbag layout;
172 * takes all of the possible parameters for grid constraints.
173 * @param container conatiner to add the component to
174 * @param component component that will be added
177 * @param int top inset
178 * @param int left inset
179 * @param int bottom inset
180 * @param int right inset
183 public static void constrain(Container container, Component component,
184 int grid_x, int grid_y,int top, int left, int bottom, int right)
191 GridBagConstraints.NONE,
192 GridBagConstraints.NORTHWEST,
193 0.0, 0.0, top, left, bottom, right);
196 public static Rectangle center(Dimension dim)
198 final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
200 final Rectangle centeredRect =
201 new Rectangle( (screenSize.width - dim.width) /2,
202 (screenSize.height - dim.height) /2,