-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSupportMethods.java
More file actions
108 lines (97 loc) · 4.01 KB
/
SupportMethods.java
File metadata and controls
108 lines (97 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Created by James Page on 4/8/2017.
*/
package Main;
import java.awt.*;
public class SupportMethods {
protected static int[] createArrRange(int start, int end) {
int[] numArr = new int[end];
for (int num = start, element = 0; num <= end; num++, element++){
numArr[element] = num;
}
return numArr;
}
protected static String[] createArrRange(String firstElement, int startNum, int endNum) {
String[] strArr = new String[endNum+1];
strArr[0] = firstElement;
for (int num = startNum, element = 1; num <= endNum; num++, element++){
strArr[element] = Integer.toString(num);
}
return strArr;
}
protected static String getLongestStrFromArr(String[] arr){
int index = 0;
int elementLength = arr[0].length();
for(int i = 1; i < arr.length; i++) {
if(arr[i].length() > elementLength) {
index = i; elementLength = arr[i].length();
}
}
return arr[index];
}
protected static String getLongestStrFromArr(String[][] arr){
int firstIndex = 0;
int secondIndex = 0;
int elementLength = arr[0][0].length();
for(int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++)
{
if(arr[i][j].length() > elementLength) {
firstIndex = i;
secondIndex = j;
elementLength = arr[i][j].length();
}
}
}
return arr[firstIndex][secondIndex];
}
protected static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch(NumberFormatException e) {
return false;
} catch(NullPointerException e) {
return false;
}
// String can be changed into an integer
return true;
}
protected static GridBagConstraints setGbc(int gridx, int gridy, int gridWidth, int gridHeight, int ipadx, int ipady, String anchorLocation, double weightx, double weighty, Insets insets){
GridBagConstraints gbc = new GridBagConstraints();
if (anchorLocation.toUpperCase().equals("NORTHWEST")){
gbc.anchor = GridBagConstraints.NORTHWEST;
} else if (anchorLocation.toUpperCase().equals("NORTH")){
gbc.anchor = GridBagConstraints.NORTH;
} else if (anchorLocation.toUpperCase().equals("NORTHEAST")){
gbc.anchor = GridBagConstraints.NORTHEAST;
} else if (anchorLocation.toUpperCase().equals("WEST")){
gbc.anchor = GridBagConstraints.WEST;
} else if (anchorLocation.toUpperCase().equals("EAST")){
gbc.anchor = GridBagConstraints.EAST;
} else if (anchorLocation.toUpperCase().equals("SOUTHWEST")){
gbc.anchor = GridBagConstraints.SOUTHWEST;
} else if (anchorLocation.toUpperCase().equals("SOUTH")){
gbc.anchor = GridBagConstraints.SOUTH;
} else if (anchorLocation.toUpperCase().equals("SOUTHEAST")){
gbc.anchor = GridBagConstraints.SOUTHEAST;
} else {
gbc.anchor = GridBagConstraints.CENTER;
}
gbc.gridx = gridx; // column
gbc.gridy = gridy; // row
gbc.gridwidth = gridWidth; // number of columns
gbc.gridheight = gridHeight; // number of rows
gbc.ipadx = ipadx; // width of object
gbc.ipady = ipady; // height of object
gbc.weightx = weightx; // shifts rows to side of set anchor
gbc.weighty = weighty; // shifts columns to side of set anchor
gbc.insets = insets; // placement inside cell
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.fill = GridBagConstraints.VERTICAL;
return gbc;
}
protected static Insets setInsets(int top, int left, int bottom, int right){
Insets insets = new Insets(top,left,bottom,right);
return insets;
}
}