Compare commits
3
Commits
master
...
TEST-REMAKE
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6db06dd8b | ||
|
|
5b6028e3b9 | ||
|
|
1978cdacb8 |
No files matched your search
@@ -4,8 +4,12 @@
|
||||
*/
|
||||
package userprofilebuilder;
|
||||
|
||||
import userprofilebuilder.model.User;
|
||||
import userprofilebuilder.view.MainViewer;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author mudabbir
|
||||
@@ -18,8 +22,17 @@ public class App {
|
||||
public static void main(String[] args) {
|
||||
// TODO code application logic here
|
||||
new MainViewer();
|
||||
|
||||
// This is where your application will start
|
||||
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader("userprofile.csv"))) {
|
||||
while (reader.ready()) {
|
||||
String line = reader.readLine();
|
||||
String[] split = line.split(",");
|
||||
User hi = new User(split[0], split[1], split[2], split[3]);
|
||||
// add user to SINGLETON user group...
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,9 +4,6 @@
|
||||
*/
|
||||
package userprofilebuilder.model;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author
|
||||
@@ -14,8 +11,61 @@ import java.io.FileReader;
|
||||
*/
|
||||
public class User {
|
||||
|
||||
private String Profile;
|
||||
private String Title;
|
||||
private String Username;
|
||||
private String Email;
|
||||
|
||||
public static void addUser(String profile, String title, String name, String email) {
|
||||
|
||||
public User(String profile, String title, String username, String email)
|
||||
{
|
||||
this.Profile = profile;
|
||||
this.Title = title;
|
||||
this.Username = username;
|
||||
this.Email = email;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getProfile() {
|
||||
return Profile;
|
||||
}
|
||||
|
||||
public void setProfile(String profile) {
|
||||
this.Profile = profile;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return Title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
Title = title;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return Username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
Username = username;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return Email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
Email = email;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -4,10 +4,7 @@
|
||||
*/
|
||||
package userprofilebuilder.model;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
@@ -16,122 +13,18 @@ import java.util.ArrayList;
|
||||
* This is model class may be handy for putting data relevant groups of User Profiles in {many Users]
|
||||
*/
|
||||
public class UserGroup {
|
||||
public static String getUser(int row, String Pname, String file) {
|
||||
String text = "Default Text";
|
||||
String[] values = null;
|
||||
try (BufferedReader csvReader = new BufferedReader(new FileReader(file))) {
|
||||
while (csvReader.ready()) {
|
||||
String line = csvReader.readLine();
|
||||
values = line.split(",");
|
||||
|
||||
for (int i = 0; i < values.length; i = i + 4) {
|
||||
if (row == Integer.parseInt(String.valueOf(values[i].charAt(4)))) {
|
||||
if (Pname.equals("User Title")) {
|
||||
text = values[i + 1];
|
||||
System.out.println("Set radio button text to :" + text);
|
||||
return text;
|
||||
} else if (Pname.equals("User Name")) {
|
||||
text = values[i + 2];
|
||||
System.out.println("Set radio button text to :" + text);
|
||||
return text;
|
||||
} else if (Pname.equals("User Email")) {
|
||||
text = values[i + 3];
|
||||
System.out.println("Set radio button text to :" + text);
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("error with reader");
|
||||
}
|
||||
return text;
|
||||
}
|
||||
public ArrayList<User> users;
|
||||
|
||||
public static void SaveFor(String file, JFrame viewer, int TotalRows) {
|
||||
|
||||
ArrayList<String> Tab1 = new ArrayList<>();
|
||||
ArrayList<String> Tab2 = new ArrayList<>();
|
||||
ArrayList<String> Tab3 = new ArrayList<>();
|
||||
|
||||
try {
|
||||
FileWriter wr = new FileWriter(file);
|
||||
|
||||
JPanel mainPane = (JPanel) viewer.getContentPane();
|
||||
JTabbedPane jt = (JTabbedPane) mainPane.getComponent(0);
|
||||
|
||||
// for tab 1:
|
||||
|
||||
JPanel jp1 = (JPanel) jt.getComponentAt(0); // tab
|
||||
for (int row = 0; row < TotalRows; row++) {
|
||||
JPanel jp2 = (JPanel) jp1.getComponent(row); // row
|
||||
JRadioButton jr1 = (JRadioButton) jp2.getComponent(0); // always stays 0 --> selecting radio button
|
||||
Tab1.add(jr1.getText());
|
||||
}
|
||||
|
||||
//for tab 2:
|
||||
JPanel jp1new = (JPanel) jt.getComponentAt(1); // tab
|
||||
for (int row = 0; row < TotalRows; row++) {
|
||||
JPanel jp2 = (JPanel) jp1new.getComponent(row); // row
|
||||
JRadioButton jr1 = (JRadioButton) jp2.getComponent(0); // always stays 0 --> selecting radio button
|
||||
Tab2.add(jr1.getText());
|
||||
}
|
||||
|
||||
//for tab 3:
|
||||
JPanel jp1new1 = (JPanel) jt.getComponentAt(2); // tab
|
||||
for (int row = 0; row < TotalRows; row++) {
|
||||
JPanel jp2 = (JPanel) jp1new1.getComponent(row); // row
|
||||
JRadioButton jr1 = (JRadioButton) jp2.getComponent(0); // always stays 0 --> selecting radio button
|
||||
Tab3.add(jr1.getText());
|
||||
}
|
||||
|
||||
for (int i = 0; i < Tab1.size(); i++) {
|
||||
JPanel jp2 = (JPanel) jp1.getComponent(i);
|
||||
TitledBorder title = (TitledBorder) jp2.getBorder();
|
||||
String UserProfile = title.getTitle();
|
||||
String line = UserProfile + "," + Tab1.get(i) + "," + Tab2.get(i) + "," + Tab3.get(i);
|
||||
wr.write(line);
|
||||
wr.write("\n");
|
||||
}
|
||||
|
||||
wr.flush();
|
||||
wr.close();
|
||||
System.out.println("Successfully wrote to the file.");
|
||||
} catch (IOException e) {
|
||||
System.out.println("An error occurred while saving.");
|
||||
}
|
||||
}
|
||||
|
||||
public static int getLine(String file)
|
||||
public UserGroup()
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||
while (reader.readLine() != null){
|
||||
count++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("error with reader");
|
||||
}
|
||||
return count;
|
||||
users = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static String getUserRow(int row, String file) {
|
||||
String text = "";
|
||||
String[] values = null;
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
|
||||
for (int i = 0; i < row-1; i++)
|
||||
br.readLine();
|
||||
String line = br.readLine();
|
||||
values = line.split(",");
|
||||
|
||||
text = values[0];
|
||||
return text;
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("error with reader");
|
||||
}
|
||||
return text;
|
||||
public void addUser(User user)
|
||||
{
|
||||
users.add(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,86 +10,4 @@ import userprofilebuilder.view.MainViewer;
|
||||
|
||||
public class UserProfile {
|
||||
|
||||
public static void footer(JPanel tab)
|
||||
{
|
||||
JPanel page = new JPanel();
|
||||
|
||||
JButton displayProfile = new JButton("Display Profile");
|
||||
|
||||
ActionListener displayer = e -> {
|
||||
System.out.println("displayer clicked");
|
||||
};
|
||||
displayProfile.addActionListener(displayer);
|
||||
|
||||
JButton addProfile = new JButton("Add Profile");
|
||||
ActionListener adder = e -> {
|
||||
System.out.println("profile add button clicked");
|
||||
Adder();
|
||||
};
|
||||
addProfile.addActionListener(adder);
|
||||
|
||||
JPanel footer = new JPanel();
|
||||
|
||||
footer.add(displayProfile);
|
||||
footer.add(addProfile);
|
||||
|
||||
tab.add(footer);
|
||||
}
|
||||
|
||||
|
||||
public static void Adder()
|
||||
{
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new GridLayout(0,2));
|
||||
|
||||
JTextField JT1 = new JTextField("Enter Profile name");
|
||||
JLabel JT11 = new JLabel("Profile:");
|
||||
panel.add(JT11);
|
||||
panel.add(JT1);
|
||||
|
||||
JTextField JT2 = new JTextField("Enter Title");
|
||||
JLabel JT21 = new JLabel("Title:");
|
||||
panel.add(JT21);
|
||||
panel.add(JT2);
|
||||
|
||||
JTextField JT3 = new JTextField("Enter Name");
|
||||
JLabel JT31 = new JLabel("Name:");
|
||||
panel.add(JT31);
|
||||
panel.add(JT3);
|
||||
|
||||
JTextField JT4 = new JTextField("Enter Email");
|
||||
JLabel JT41 = new JLabel("Email:");
|
||||
panel.add(JT41);
|
||||
panel.add(JT4);
|
||||
|
||||
|
||||
//JOptionPane pane = new JOptionPane(panel, 3, 2); // content of dialogue box
|
||||
JOptionPane pane = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
|
||||
JDialog dialog = pane.createDialog("Rename Dialogue Box"); // title of dialogue box
|
||||
dialog.setVisible(true); // changed boiler plate code from .show() to .setVisible(true) because apparently IDE says it's better!!
|
||||
|
||||
// actions.
|
||||
|
||||
int choice = (int) pane.getValue();
|
||||
|
||||
if (choice == JOptionPane.OK_OPTION)
|
||||
{
|
||||
System.out.println("OK option pressed.");
|
||||
|
||||
String profile = JT11.getText();
|
||||
String title = JT21.getText();
|
||||
String name = JT31.getText();
|
||||
String email = JT41.getText();
|
||||
|
||||
User.addUser(profile, title, name, email);
|
||||
|
||||
}
|
||||
else if (choice == JOptionPane.CANCEL_OPTION) {
|
||||
System.out.println("Cancel option pressed.");
|
||||
dialog.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -23,218 +23,13 @@ import java.util.*;
|
||||
public class MainViewer {
|
||||
public JFrame viewer;
|
||||
public String file = "userprofile.csv";
|
||||
public ArrayList<JRadioButton> radioButtons = new ArrayList<>();
|
||||
int TotalRows;
|
||||
|
||||
public JTabbedPane JT;
|
||||
|
||||
public int a = UserGroup.getLine(file); // this represents a value that is to declare how many rows are to be made -- to be changed by the amount of lines in csv. ROW COUNT
|
||||
|
||||
|
||||
private void CreateRow(int count, JPanel jp, String Pname, ButtonGroup group)
|
||||
public MainViewer()
|
||||
{
|
||||
int row = count+1;
|
||||
|
||||
JPanel RowPanel = new JPanel();
|
||||
// setting the border title to the correct title
|
||||
TitledBorder RowTitle;
|
||||
RowTitle = BorderFactory.createTitledBorder(UserGroup.getUserRow(row, file));
|
||||
RowPanel.setBorder(RowTitle);
|
||||
// end of border title code
|
||||
|
||||
JRadioButton JR = new JRadioButton(UserGroup.getUser(row, Pname, file));
|
||||
|
||||
JButton JEdit = new JButton("Edit");
|
||||
JButton JDelete = new JButton("Delete");
|
||||
|
||||
|
||||
|
||||
|
||||
RowPanel.add(JR);
|
||||
RowPanel.add(JEdit);
|
||||
RowPanel.add(JDelete);
|
||||
|
||||
jp.add(RowPanel);
|
||||
|
||||
group.add(JR);
|
||||
|
||||
radioButtons.add(JR);
|
||||
|
||||
|
||||
System.out.println("Row number: "+ row + " Has been created!");
|
||||
|
||||
ActionListener EditListener = e -> {
|
||||
System.out.println("Edit Button clicked for Row: " + row + "\n- with Radio Button Text as: " + JR.getText() + "\n- For tab: " + Pname);
|
||||
DialogueBox(JR.getText(), JR, row, Pname);
|
||||
};
|
||||
JEdit.addActionListener(EditListener);
|
||||
|
||||
ActionListener RadioListener = e -> {
|
||||
System.out.println("Radio Button toggled for Row: " + row + "\n- with Radio Button Text as: " + JR.getText() + "\n- With state of radio button changed to: " + JR.isSelected() + "\n- For tab: " + Pname);
|
||||
ButtonSelector(JR.isSelected(), row);
|
||||
};
|
||||
JR.addActionListener(RadioListener);
|
||||
|
||||
ActionListener Deleter = e -> {
|
||||
System.out.println("Delete attempted for row: "+ row);
|
||||
rowDeleter(row);
|
||||
};
|
||||
JDelete.addActionListener(Deleter);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void DialogueBox(String JRtext, JRadioButton JR, int row, String Pname){
|
||||
|
||||
|
||||
JTextField JT = new JTextField(JRtext);
|
||||
JLabel JT1 = new JLabel("Enter new text:");
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new GridLayout(0,1));
|
||||
|
||||
panel.add(JT1);
|
||||
panel.add(JT);
|
||||
|
||||
|
||||
//JOptionPane pane = new JOptionPane(panel, 3, 2); // content of dialogue box
|
||||
JOptionPane pane = new JOptionPane(panel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
|
||||
JDialog dialog = pane.createDialog("Rename Dialogue Box"); // title of dialogue box
|
||||
dialog.setVisible(true); // changed boiler plate code from .show() to .setVisible(true) because apparently IDE says it's better!!
|
||||
|
||||
// actions.
|
||||
|
||||
int choice = (int) pane.getValue();
|
||||
|
||||
if (choice == JOptionPane.OK_OPTION)
|
||||
{
|
||||
System.out.println("OK option pressed and set text to: " + JT.getText() + " for row :" + row + "\n- in Tab: " + Pname);
|
||||
JR.setText(JT.getText());
|
||||
} else if (choice == JOptionPane.CANCEL_OPTION) {
|
||||
System.out.println("Cancel option pressed." + "\n- in Tab: " + Pname);
|
||||
dialog.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void TabMaker(String Pname, JTabbedPane JT)
|
||||
{
|
||||
ButtonGroup group = new ButtonGroup(); // getting button count -> also a way to get number of total rows.
|
||||
JPanel page = new JPanel();
|
||||
|
||||
page.setLayout(new GridLayout(0,1)); // Because i cant remember the orientation of grid layout params it's (x,y) AKA rows , columns
|
||||
|
||||
|
||||
// setting the border title to the correct title
|
||||
TitledBorder titled;
|
||||
String[] Tname = Pname.split(" ");
|
||||
titled = BorderFactory.createTitledBorder(Tname[1]);
|
||||
page.setBorder(titled);
|
||||
// end of border title code
|
||||
|
||||
JT.addTab(Pname, page);
|
||||
|
||||
for (int i=0; i<a; i++)
|
||||
{
|
||||
CreateRow(i, page, Pname, group);
|
||||
}
|
||||
|
||||
TotalRows = group.getButtonCount();
|
||||
UserProfile.footer(page);
|
||||
}
|
||||
|
||||
public MainViewer() // main viewer window
|
||||
{
|
||||
|
||||
UserProfile userProfile = new UserProfile();
|
||||
|
||||
viewer = new JFrame();
|
||||
viewer.setTitle("User Profile Builder");
|
||||
viewer.setSize(800,500);
|
||||
viewer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
radioButtons = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
JT = new JTabbedPane();
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
JMenu menu = new JMenu("file");
|
||||
|
||||
menuBar.add(menu);
|
||||
|
||||
JMenuItem open = new JMenuItem("Open");
|
||||
menu.add(open);
|
||||
ActionListener opener = e -> {
|
||||
System.out.println("Open file?");
|
||||
JFileChooser fileOpen = new JFileChooser(file, FileSystemView.getFileSystemView());
|
||||
fileOpen.showSaveDialog(null);
|
||||
file = (fileOpen.getSelectedFile()).toString();
|
||||
System.out.println(file);
|
||||
viewer.repaint();
|
||||
};
|
||||
open.addActionListener(opener);
|
||||
|
||||
|
||||
JMenuItem save = new JMenuItem("Save");
|
||||
menu.add(save);
|
||||
ActionListener SaveAction = e -> {
|
||||
System.out.println("Save attempt made");
|
||||
UserGroup.SaveFor(file, viewer, TotalRows);
|
||||
};
|
||||
save.addActionListener(SaveAction);
|
||||
|
||||
|
||||
JMenuItem quit = new JMenuItem("Quit");
|
||||
menu.add(quit);
|
||||
ActionListener quitter = e -> {
|
||||
System.exit(0);
|
||||
};
|
||||
quit.addActionListener(quitter);
|
||||
|
||||
viewer.setJMenuBar(menuBar);
|
||||
|
||||
TabMaker("User Title", JT);
|
||||
TabMaker("User Name", JT);
|
||||
TabMaker("User Email", JT);
|
||||
|
||||
|
||||
viewer.add(JT);
|
||||
|
||||
JT.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||
|
||||
viewer.setVisible(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void ButtonSelector(Boolean j, int row)
|
||||
{
|
||||
JPanel mainPane = (JPanel) viewer.getContentPane();
|
||||
JTabbedPane jt = (JTabbedPane) mainPane.getComponent(0);
|
||||
for (int i=0; i<3; i++) // 3 == the amount of tabs.
|
||||
{
|
||||
JPanel jp1 = (JPanel) jt.getComponentAt(i); // tab
|
||||
JPanel jp2 = (JPanel) jp1.getComponent(row-1); // row
|
||||
JRadioButton jr1 = (JRadioButton) jp2.getComponent(0); // always stays 0 --> selecting radio button
|
||||
jr1.setSelected(j);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void rowDeleter(int row)
|
||||
{
|
||||
JPanel mainPane = (JPanel) viewer.getContentPane();
|
||||
JTabbedPane jt = (JTabbedPane) mainPane.getComponent(0);
|
||||
for (int i=0; i<3; i++) // 3 == the amount of tabs.
|
||||
{
|
||||
JPanel jp1 = (JPanel) jt.getComponentAt(i); // tab
|
||||
JPanel jp2 = (JPanel) jp1.getComponent(row-1); // row
|
||||
jp1.remove(jp2);
|
||||
jp1.repaint();
|
||||
}
|
||||
TotalRows--;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user