741 |
10 Oct 06 |
olle |
1 |
/* |
1652 |
22 May 07 |
gregory |
$Id$ |
741 |
10 Oct 06 |
olle |
3 |
|
1916 |
31 Aug 07 |
jari |
Copyright (C) 2006 Olle Mansson |
1916 |
31 Aug 07 |
jari |
Copyright (C) 2007 Gregory Vincic |
741 |
10 Oct 06 |
olle |
6 |
|
1652 |
22 May 07 |
gregory |
This file is part of Proteios. |
1652 |
22 May 07 |
gregory |
Available at http://www.proteios.org/ |
741 |
10 Oct 06 |
olle |
9 |
|
1652 |
22 May 07 |
gregory |
Proteios is free software; you can redistribute it and/or modify it |
1652 |
22 May 07 |
gregory |
under the terms of the GNU General Public License as published by |
1652 |
22 May 07 |
gregory |
the Free Software Foundation; either version 2 of the License, or |
1652 |
22 May 07 |
gregory |
(at your option) any later version. |
741 |
10 Oct 06 |
olle |
14 |
|
1652 |
22 May 07 |
gregory |
Proteios is distributed in the hope that it will be useful, but |
1652 |
22 May 07 |
gregory |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1652 |
22 May 07 |
gregory |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1652 |
22 May 07 |
gregory |
General Public License for more details. |
741 |
10 Oct 06 |
olle |
19 |
|
1652 |
22 May 07 |
gregory |
You should have received a copy of the GNU General Public License |
1652 |
22 May 07 |
gregory |
along with this program; if not, write to the Free Software |
1652 |
22 May 07 |
gregory |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
1652 |
22 May 07 |
gregory |
02111-1307, USA. |
1652 |
22 May 07 |
gregory |
24 |
*/ |
741 |
10 Oct 06 |
olle |
25 |
|
741 |
10 Oct 06 |
olle |
// Xerver Free Web Server |
741 |
10 Oct 06 |
olle |
// Copyright (C) 2002-2005 Omid Rouhani |
741 |
10 Oct 06 |
olle |
28 |
// |
741 |
10 Oct 06 |
olle |
29 |
// |
741 |
10 Oct 06 |
olle |
// This program is free software; you can redistribute it and/or |
741 |
10 Oct 06 |
olle |
// modify it under the terms of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// as published by the Free Software Foundation; either version 2 |
741 |
10 Oct 06 |
olle |
// of the License, or (at your option) any later version. |
741 |
10 Oct 06 |
olle |
34 |
// |
741 |
10 Oct 06 |
olle |
// This program is distributed in the hope that it will be useful, |
741 |
10 Oct 06 |
olle |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
741 |
10 Oct 06 |
olle |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
741 |
10 Oct 06 |
olle |
// GNU General Public License for more details. |
741 |
10 Oct 06 |
olle |
39 |
// |
741 |
10 Oct 06 |
olle |
// You should have received a copy of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// along with this program; if not, write to the Free Software |
741 |
10 Oct 06 |
olle |
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
741 |
10 Oct 06 |
olle |
43 |
// |
741 |
10 Oct 06 |
olle |
44 |
// |
741 |
10 Oct 06 |
olle |
45 |
// ############################################################# |
741 |
10 Oct 06 |
olle |
// ## YOU CAN CONTACT THE AUTHOR (OMID ROUHANI) AT: ## |
741 |
10 Oct 06 |
olle |
// ## HTTP://WWW.JAVASCRIPT.NU/XERVER/ ## |
741 |
10 Oct 06 |
olle |
48 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## IF YOUR SOFTWARE IS NOT RELEASED UNDER THE ## |
741 |
10 Oct 06 |
olle |
// ## GNU GENERAL PUBLIC LICENSE (GPL), ## |
741 |
10 Oct 06 |
olle |
// ## PLEASE DO NOT COPY ANYTHING FROM THIS SOURCE CODE!!! ## |
741 |
10 Oct 06 |
olle |
52 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## FOR FULL LICENSE, PLEASE READ "XERVER LICENSE". ## |
741 |
10 Oct 06 |
olle |
54 |
// ############################################################# |
741 |
10 Oct 06 |
olle |
55 |
|
1652 |
22 May 07 |
gregory |
56 |
package se.lu.thep.coreftpd.common; |
741 |
10 Oct 06 |
olle |
57 |
|
741 |
10 Oct 06 |
olle |
58 |
import java.awt.BorderLayout; |
741 |
10 Oct 06 |
olle |
59 |
import java.awt.Color; |
741 |
10 Oct 06 |
olle |
60 |
import java.awt.Container; |
741 |
10 Oct 06 |
olle |
61 |
import java.awt.Font; |
741 |
10 Oct 06 |
olle |
62 |
import java.awt.GridLayout; |
741 |
10 Oct 06 |
olle |
63 |
import javax.swing.JLabel; |
741 |
10 Oct 06 |
olle |
64 |
|
741 |
10 Oct 06 |
olle |
65 |
/** |
1652 |
22 May 07 |
gregory |
66 |
* |
1652 |
22 May 07 |
gregory |
* <B>About this class:</B> <BR> |
1652 |
22 May 07 |
gregory |
* This class contains only static methods that can be useful when creating a |
1652 |
22 May 07 |
gregory |
* Java application using Swing. The methods are not very advanced but might |
1652 |
22 May 07 |
gregory |
* still be useful. <BR> |
741 |
10 Oct 06 |
olle |
* One way of using this class is to extend it to some class of yours. |
1652 |
22 May 07 |
gregory |
72 |
* |
741 |
10 Oct 06 |
olle |
* @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a> |
741 |
10 Oct 06 |
olle |
* @version 1.0 |
741 |
10 Oct 06 |
olle |
75 |
*/ |
741 |
10 Oct 06 |
olle |
76 |
|
1652 |
22 May 07 |
gregory |
77 |
public class GUIMethods { |
1652 |
22 May 07 |
gregory |
78 |
public static final Font defaultFont = new Font("Arial", Font.PLAIN, 12); |
741 |
10 Oct 06 |
olle |
79 |
|
741 |
10 Oct 06 |
olle |
80 |
/** |
1652 |
22 May 07 |
gregory |
* Gets two <CODE>Container</CODE>s and puts them side by side. <BR> |
1652 |
22 May 07 |
gregory |
* The lefy <CODE>Container</CODE> (<CODE>c1</CODE>) will be as small |
1652 |
22 May 07 |
gregory |
* as possible. |
1652 |
22 May 07 |
gregory |
84 |
*/ |
1652 |
22 May 07 |
gregory |
85 |
public static Container make2ContainersTo1ContainerBeside(Container c1, |
1652 |
22 May 07 |
gregory |
86 |
Container c2) { |
1652 |
22 May 07 |
gregory |
87 |
Container thisCP = new Container(); |
741 |
10 Oct 06 |
olle |
88 |
thisCP.setLayout(new BorderLayout()); |
741 |
10 Oct 06 |
olle |
89 |
thisCP.add(c1, BorderLayout.WEST); |
741 |
10 Oct 06 |
olle |
90 |
thisCP.add(c2, BorderLayout.CENTER); |
741 |
10 Oct 06 |
olle |
91 |
return thisCP; |
741 |
10 Oct 06 |
olle |
92 |
} |
741 |
10 Oct 06 |
olle |
93 |
|
741 |
10 Oct 06 |
olle |
94 |
/** |
1652 |
22 May 07 |
gregory |
* Gets two <CODE>Container</CODE>s and puts them on top of each other. |
1652 |
22 May 07 |
gregory |
* <BR> |
1652 |
22 May 07 |
gregory |
* The top <CODE>Container</CODE> (<CODE>c1</CODE>) will be as small |
1652 |
22 May 07 |
gregory |
* as possible. |
1652 |
22 May 07 |
gregory |
99 |
*/ |
1652 |
22 May 07 |
gregory |
100 |
public static Container make2ContainersTo1ContainerAbove(Container c1, |
1652 |
22 May 07 |
gregory |
101 |
Container c2) { |
1652 |
22 May 07 |
gregory |
102 |
Container thisCP = new Container(); |
741 |
10 Oct 06 |
olle |
103 |
thisCP.setLayout(new BorderLayout()); |
741 |
10 Oct 06 |
olle |
104 |
thisCP.add(c1, BorderLayout.NORTH); |
741 |
10 Oct 06 |
olle |
105 |
thisCP.add(c2, BorderLayout.CENTER); |
741 |
10 Oct 06 |
olle |
106 |
return thisCP; |
741 |
10 Oct 06 |
olle |
107 |
} |
741 |
10 Oct 06 |
olle |
108 |
|
741 |
10 Oct 06 |
olle |
109 |
/** |
1652 |
22 May 07 |
gregory |
* Gets an array of <CODE>String</CODE>s and returns a <CODE>Container</CODE> |
1652 |
22 May 07 |
gregory |
* with this text. <BR> |
1652 |
22 May 07 |
gregory |
* Each <CODE>String</CODE> in the array will come on a separate line. |
1652 |
22 May 07 |
gregory |
113 |
*/ |
1652 |
22 May 07 |
gregory |
114 |
public static Container giveContainerWithText(String[] texts) { |
1652 |
22 May 07 |
gregory |
115 |
int textsLength = texts.length; // Optimization... |
1652 |
22 May 07 |
gregory |
116 |
Container CPWithFields = new Container(); |
1652 |
22 May 07 |
gregory |
117 |
CPWithFields.setLayout(new GridLayout(textsLength, 1)); |
741 |
10 Oct 06 |
olle |
118 |
|
1652 |
22 May 07 |
gregory |
119 |
for (int i = 0; i < textsLength; i++) // Optimization... |
741 |
10 Oct 06 |
olle |
120 |
{ |
1652 |
22 May 07 |
gregory |
121 |
JLabel tmpJLabel = new JLabel(texts[i]); |
741 |
10 Oct 06 |
olle |
122 |
tmpJLabel.setForeground(Color.black); |
741 |
10 Oct 06 |
olle |
123 |
tmpJLabel.setFont(defaultFont); |
741 |
10 Oct 06 |
olle |
124 |
CPWithFields.add(tmpJLabel); |
741 |
10 Oct 06 |
olle |
125 |
} |
741 |
10 Oct 06 |
olle |
126 |
|
741 |
10 Oct 06 |
olle |
127 |
return CPWithFields; |
741 |
10 Oct 06 |
olle |
128 |
} |
741 |
10 Oct 06 |
olle |
129 |
|
741 |
10 Oct 06 |
olle |
130 |
/** |
1652 |
22 May 07 |
gregory |
* Gets one <CODE>Container</CODE> (<CODE>con</CODE>) and returns a |
1652 |
22 May 07 |
gregory |
* new <CODE>Container</CODE> containing only <CODE>con</CODE>, but |
1652 |
22 May 07 |
gregory |
* where <CODE>con</CODE> will get a height as small as possible. |
1652 |
22 May 07 |
gregory |
134 |
*/ |
1652 |
22 May 07 |
gregory |
135 |
public static Container showAsNorthBorderLayout(Container con) { |
1652 |
22 May 07 |
gregory |
136 |
Container bigCP = new Container(); |
741 |
10 Oct 06 |
olle |
137 |
bigCP.setLayout(new BorderLayout()); |
741 |
10 Oct 06 |
olle |
138 |
bigCP.add(con, BorderLayout.NORTH); |
741 |
10 Oct 06 |
olle |
139 |
bigCP.add(new JLabel(), BorderLayout.CENTER); |
741 |
10 Oct 06 |
olle |
140 |
return bigCP; |
741 |
10 Oct 06 |
olle |
141 |
} |
741 |
10 Oct 06 |
olle |
142 |
} |