-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewPosts.java
168 lines (136 loc) · 4.83 KB
/
ViewPosts.java
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* Lisette Isais' assigned part for WeShare Project
*/
package application;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TextArea;
import javafx.scene.layout.AnchorPane;
import javafx.scene.shape.Circle;
public class ViewPosts {
@FXML
private Circle homeBtn;
@FXML
private TextArea UserName;
@FXML
private TextArea PostContent;
@FXML
private Button Next;
@FXML
private ListView<String> commentDisplay;
@FXML
private TextArea commentBox;
@FXML
private Button Post;
@FXML
private AnchorPane ViewPostsPane;
@FXML
// initialize() will have first post displayed when scene is opened
public void initialize() throws IOException {
/*
* File file = new File ("post.properties"); if (!(file.exists())) {
* file.createNewFile(); } HashMap<String, String> h=new HashMap<String,
* String>(); // File file=new File("post.properties"); FileInputStream
* reader=new FileInputStream(file); Properties properties=new Properties();
*
* properties.load(reader); reader.close();
*
* for(String key: properties.stringPropertyNames()){
* PostContent.setText(properties.get(key).toString()); h.put(key,
* properties.get(key).toString()); UserName.setText(key); // h.findFirst();
* //PostContent.setText(properties.get(key).toString()); }
*/
File file = new File("post.properties");
if (!(file.exists())) {
file.createNewFile();
}
HashMap<String, String> h = new HashMap<String, String>();
FileInputStream reader = new FileInputStream(file);
Properties properties = new Properties();
properties.load(reader);
reader.close();
// while (!Next.isPressed()) {
for (String key : properties.stringPropertyNames()) {
h.put(key, properties.get(key).toString());
UserName.setText(key);
PostContent.setText(properties.get(key).toString());
}
// }
/*
* Iterator<Entry<String, String>> postIterator = h.entrySet().iterator();
* while(!Next.isPressed()) { while (postIterator.hasNext()) { Map.Entry
* postContent = (Map.Entry)postIterator.next(); String content =
* (String)postContent.getValue(); String name = (String)postContent.getKey();
* PostContent.setText(content); UserName.setText(name); } }
*/
}
// nextPost() iterates through user's posts one by one
@FXML
public void nextPost(ActionEvent event) throws IOException {
File file = new File("post.properties");
if (!(file.exists())) {
file.createNewFile();
}
HashMap<String, String> h = new HashMap<String, String>();
FileInputStream reader = new FileInputStream(file);
Properties properties = new Properties();
properties.load(reader);
reader.close();
// while (!Next.isPressed()) {
for (String key : properties.stringPropertyNames()) {
h.put(key, properties.get(key).toString());
UserName.setText(key);
PostContent.setText(properties.get(key).toString());
}
// }
/* FIXME: CLEAR COMMENT BOX WHEN CHANGING TO NEXT POST */
/*
* Iterator postIterator = h.entrySet().iterator();
*
* while (postIterator.hasNext()) { Map.Entry postContent =
* (Map.Entry)postIterator.next(); String content =
* (String)postContent.getValue(); PostContent.setText(content); }
*/
}
// displayComments() displays user's comments for post
@FXML
public void displayComments(ActionEvent event) throws IOException {
File file = new File("comment.properties");
if (!(file.exists())) {
file.createNewFile();
}
String input = commentBox.getText();
HashMap<String, String> h = new HashMap<String, String>();
FileInputStream reader = new FileInputStream(file);
Properties properties = new Properties();
properties.load(reader);
reader.close();
commentDisplay.getItems().addAll(input);
// stores items into variable "key"
for (String key : properties.stringPropertyNames()) {
h.put(key, properties.get(key).toString());
commentDisplay.getItems().addAll(key, h.get(key));
commentDisplay.getItems().addAll(input, h.get(input));
}
commentBox.clear();
}
// this method changes scenes to home
/*
* public void goHome(ActionEvent event) throws IOException { inventPane =
* FXMLLoader.load(getClass().getResource("Main.fxml")); // pane I am going to
* Scene scene = new Scene(inventPane); //pane i'm going to show Stage window =
* (Stage) ((Node)event.getSource()).getScene().getWindow(); //pane I am on
* window.setScene(scene); window.show(); }
*/
}