Skip to content

Commit 8db56c9

Browse files
committed
Updated Java project
Added the Maven project nature Code updated to remove compilation warnings JFrameTest started in the UI frame to avoid treading errors
1 parent 5f90f15 commit 8db56c9

File tree

8 files changed

+451
-354
lines changed

8 files changed

+451
-354
lines changed

java/.classpath

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="src" path="src"/>
3+
<classpathentry kind="src" path="src/test/java"/>
44
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
55
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6-
<classpathentry kind="output" path="bin"/>
6+
<classpathentry kind="output" path="target/classes"/>
77
</classpath>

java/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Maven output
2+
target/
3+
4+
# Generated files
5+
*.ser
6+

java/.project

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
<arguments>
1111
</arguments>
1212
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
1318
</buildSpec>
1419
<natures>
20+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
1521
<nature>org.eclipse.jdt.core.javanature</nature>
1622
</natures>
1723
</projectDescription>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

java/pom.xml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
65

7-
<groupId>org.python-javaobj</groupId>
8-
<artifactId>python-javaobj</artifactId>
9-
<version>1.0-SNAPSHOT</version>
6+
<groupId>org.python-javaobj</groupId>
7+
<artifactId>python-javaobj</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
109

11-
<dependencies>
12-
13-
<dependency>
14-
<groupId>junit</groupId>
15-
<artifactId>junit</artifactId>
16-
<version>4.9</version>
17-
<scope>test</scope>
18-
</dependency>
19-
20-
</dependencies>
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
</properties>
2113

14+
<dependencies>
15+
<dependency>
16+
<groupId>junit</groupId>
17+
<artifactId>junit</artifactId>
18+
<version>4.9</version>
19+
<scope>test</scope>
20+
</dependency>
21+
</dependencies>
2222
</project>

java/src/test/java/CollectionsTest.java

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,51 @@
1212
import org.junit.Test;
1313

1414
class CollectionsSerializableBean implements Serializable {
15-
// Collections
16-
public Collection<String> arrayList;
17-
public Collection<String> linkedList;
18-
public Map<String, Object> hashMap;
19-
public Queue<String> queue;
20-
21-
public CollectionsSerializableBean()
22-
{
23-
super();
24-
25-
arrayList = new ArrayList<String>();
26-
arrayList.add("e1");
27-
arrayList.add("e2");
28-
29-
linkedList = new LinkedList<String>();
30-
linkedList.add("ll1");
31-
linkedList.add("ll2");
32-
33-
hashMap = new HashMap<String, Object>();
34-
hashMap.put("k1", null);
35-
hashMap.put("k2", "value2");
36-
hashMap.put("k3", arrayList);
37-
hashMap.put("k3", linkedList);
38-
39-
queue = new ConcurrentLinkedQueue<String>();
40-
queue.add("q1");
41-
queue.add("q2");
42-
queue.add("q3");
43-
}
15+
/**
16+
*
17+
*/
18+
private static final long serialVersionUID = 1L;
19+
20+
// Collections
21+
public Collection<String> arrayList;
22+
public Map<String, Object> hashMap;
23+
public Collection<String> linkedList;
24+
public Queue<String> queue;
25+
26+
public CollectionsSerializableBean() {
27+
super();
28+
29+
arrayList = new ArrayList<String>();
30+
arrayList.add("e1");
31+
arrayList.add("e2");
32+
33+
linkedList = new LinkedList<String>();
34+
linkedList.add("ll1");
35+
linkedList.add("ll2");
36+
37+
hashMap = new HashMap<String, Object>();
38+
hashMap.put("k1", null);
39+
hashMap.put("k2", "value2");
40+
hashMap.put("k3", arrayList);
41+
hashMap.put("k3", linkedList);
42+
43+
queue = new ConcurrentLinkedQueue<String>();
44+
queue.add("q1");
45+
queue.add("q2");
46+
queue.add("q3");
47+
}
4448
}
4549

4650
public class CollectionsTest {
4751

48-
ObjectOutputStream oos;
4952
FileOutputStream fos;
53+
ObjectOutputStream oos;
5054

5155
@Test
52-
public void testCollections() throws Exception {
53-
oos = new ObjectOutputStream(fos = new FileOutputStream("objCollections.ser"));
54-
oos.writeObject(new CollectionsSerializableBean());
55-
oos.flush();
56-
}
56+
public void testCollections() throws Exception {
57+
oos = new ObjectOutputStream(fos = new FileOutputStream(
58+
"objCollections.ser"));
59+
oos.writeObject(new CollectionsSerializableBean());
60+
oos.flush();
61+
}
5762
}

java/src/test/java/JFrameTest.java

Lines changed: 96 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,126 @@
2525

2626
public class JFrameTest extends JFrame {
2727

28+
class CheckableItem implements Serializable {
29+
/**
30+
*
31+
*/
32+
private static final long serialVersionUID = 1L;
33+
34+
private boolean isSelected;
35+
36+
private final String str;
37+
38+
public CheckableItem(final String str) {
39+
this.str = str;
40+
isSelected = false;
41+
}
42+
43+
public boolean isSelected() {
44+
return isSelected;
45+
}
46+
47+
public void setSelected(final boolean b) {
48+
isSelected = b;
49+
}
50+
51+
@Override
52+
public String toString() {
53+
return str;
54+
}
55+
}
56+
57+
class CheckListRenderer extends JCheckBox implements
58+
ListCellRenderer<CheckableItem> {
59+
60+
/**
61+
*
62+
*/
63+
private static final long serialVersionUID = 1L;
64+
65+
public CheckListRenderer() {
66+
setBackground(UIManager.getColor("List.textBackground"));
67+
setForeground(UIManager.getColor("List.textForeground"));
68+
}
69+
70+
@Override
71+
public Component getListCellRendererComponent(
72+
final JList<? extends CheckableItem> list,
73+
final CheckableItem value, final int index,
74+
final boolean isSelected, final boolean hasFocus) {
75+
setEnabled(list.isEnabled());
76+
setSelected(value.isSelected());
77+
setFont(list.getFont());
78+
setText(value.toString());
79+
return this;
80+
}
81+
}
82+
83+
/**
84+
*
85+
*/
86+
private static final long serialVersionUID = 1L;
87+
88+
public static void main(final String args[]) {
89+
90+
final JFrameTest frame = new JFrameTest();
91+
frame.addWindowListener(new WindowAdapter() {
92+
@Override
93+
public void windowClosing(final WindowEvent e) {
94+
System.exit(0);
95+
}
96+
});
97+
frame.setSize(300, 200);
98+
frame.setVisible(true);
99+
}
100+
28101
public JFrameTest() {
29102
super("CheckList Example");
30-
String[] strs = { "swing", "home", "basic", "metal", "JList" };
103+
final String[] strs = { "swing", "home", "basic", "metal", "JList" };
31104

32-
final JList list = new JList(createData(strs));
105+
final JList<CheckableItem> list = new JList<CheckableItem>(
106+
createData(strs));
33107

34108
list.setCellRenderer(new CheckListRenderer());
35109
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
36110
list.setBorder(new EmptyBorder(0, 4, 0, 0));
37111
list.addMouseListener(new MouseAdapter() {
38-
public void mouseClicked(MouseEvent e) {
39-
int index = list.locationToIndex(e.getPoint());
40-
CheckableItem item = (CheckableItem) list.getModel()
41-
.getElementAt(index);
112+
@Override
113+
public void mouseClicked(final MouseEvent e) {
114+
final int index = list.locationToIndex(e.getPoint());
115+
final CheckableItem item = list.getModel().getElementAt(index);
42116
item.setSelected(!item.isSelected());
43-
Rectangle rect = list.getCellBounds(index, index);
117+
final Rectangle rect = list.getCellBounds(index, index);
44118
list.repaint(rect);
45119
}
46120
});
47-
JScrollPane sp = new JScrollPane(list);
121+
final JScrollPane sp = new JScrollPane(list);
48122

49123
final JTextArea textArea = new JTextArea(3, 10);
50-
JScrollPane textPanel = new JScrollPane(textArea);
51-
JButton printButton = new JButton("print");
124+
final JScrollPane textPanel = new JScrollPane(textArea);
125+
final JButton printButton = new JButton("print");
52126
printButton.addActionListener(new ActionListener() {
53-
public void actionPerformed(ActionEvent e) {
54-
ListModel model = list.getModel();
55-
int n = model.getSize();
127+
@Override
128+
public void actionPerformed(final ActionEvent e) {
129+
final ListModel<CheckableItem> model = list.getModel();
130+
final int n = model.getSize();
56131
for (int i = 0; i < n; i++) {
57-
CheckableItem item = (CheckableItem) model.getElementAt(i);
132+
final CheckableItem item = model.getElementAt(i);
58133
if (item.isSelected()) {
59134
textArea.append(item.toString());
60135
textArea.append(System.getProperty("line.separator"));
61136
}
62137
}
63138
}
64139
});
65-
JButton clearButton = new JButton("clear");
140+
final JButton clearButton = new JButton("clear");
66141
clearButton.addActionListener(new ActionListener() {
67-
public void actionPerformed(ActionEvent e) {
142+
@Override
143+
public void actionPerformed(final ActionEvent e) {
68144
textArea.setText("");
69145
}
70146
});
71-
JPanel panel = new JPanel(new GridLayout(2, 1));
147+
final JPanel panel = new JPanel(new GridLayout(2, 1));
72148
panel.add(printButton);
73149
panel.add(clearButton);
74150

@@ -77,68 +153,12 @@ public void actionPerformed(ActionEvent e) {
77153
getContentPane().add(textPanel, BorderLayout.SOUTH);
78154
}
79155

80-
private CheckableItem[] createData(String[] strs) {
81-
int n = strs.length;
82-
CheckableItem[] items = new CheckableItem[n];
156+
private CheckableItem[] createData(final String[] strs) {
157+
final int n = strs.length;
158+
final CheckableItem[] items = new CheckableItem[n];
83159
for (int i = 0; i < n; i++) {
84160
items[i] = new CheckableItem(strs[i]);
85161
}
86162
return items;
87163
}
88-
89-
class CheckableItem implements Serializable {
90-
private String str;
91-
92-
private boolean isSelected;
93-
94-
public CheckableItem(String str) {
95-
this.str = str;
96-
isSelected = false;
97-
}
98-
99-
public void setSelected(boolean b) {
100-
isSelected = b;
101-
}
102-
103-
public boolean isSelected() {
104-
return isSelected;
105-
}
106-
107-
public String toString() {
108-
return str;
109-
}
110-
}
111-
112-
class CheckListRenderer extends JCheckBox implements ListCellRenderer {
113-
114-
public CheckListRenderer() {
115-
setBackground(UIManager.getColor("List.textBackground"));
116-
setForeground(UIManager.getColor("List.textForeground"));
117-
}
118-
119-
public Component getListCellRendererComponent(JList list, Object value,
120-
int index, boolean isSelected, boolean hasFocus) {
121-
setEnabled(list.isEnabled());
122-
setSelected(((CheckableItem) value).isSelected());
123-
setFont(list.getFont());
124-
setText(value.toString());
125-
return this;
126-
}
127-
}
128-
129-
public static void main(String args[]) {
130-
try {
131-
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
132-
} catch (Exception evt) {
133-
}
134-
135-
JFrameTest frame = new JFrameTest();
136-
frame.addWindowListener(new WindowAdapter() {
137-
public void windowClosing(WindowEvent e) {
138-
System.exit(0);
139-
}
140-
});
141-
frame.setSize(300, 200);
142-
frame.setVisible(true);
143-
}
144164
}

0 commit comments

Comments
 (0)