Skip to content

Commit

Permalink
Merge branch 'main' into Kimminseok
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim-minseok123 authored Jun 4, 2023
2 parents 286db1a + f92bb16 commit bccf80e
Show file tree
Hide file tree
Showing 20 changed files with 346 additions and 244 deletions.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

14 changes: 14 additions & 0 deletions AbortNewPatronCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

public class AbortNewPatronCommand implements ButtonCommand {
NewPatronView newPatronView;

public AbortNewPatronCommand(NewPatronView newPatronView) {
this.newPatronView = newPatronView;
}

@Override
public void execute() {
newPatronView.setDone(true);
newPatronView.getWindow().setVisible(false);
}
}
192 changes: 98 additions & 94 deletions AddPartyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@
*
*/

public class AddPartyView implements ActionListener, ListSelectionListener {

public class AddPartyView {
private int maxSize;
private ButtonCommand command;
private JFrame win;
private JButton addPatron, newPatron, remPatron, finished;
private JList partyList, allBowlers;
private Vector party, bowlerdb;
private Integer lock;
private Vector<String> party, bowlerdb;

private ControlDeskView controlDesk;

Expand All @@ -70,14 +68,15 @@ public AddPartyView(ControlDeskView controlDesk, int max) {
partyPanel.setLayout(new FlowLayout());
partyPanel.setBorder(new TitledBorder("Your Party"));

party = new Vector();
Vector empty = new Vector();
party = new Vector<String>();
Vector<String> empty = new Vector<String>();
empty.add("(Empty)");


AddPartyViewClickEvent listener = new AddPartyViewClickEvent();
partyList = new JList(empty);
partyList.setFixedCellWidth(120);
partyList.setVisibleRowCount(5);
partyList.addListSelectionListener(this);
partyList.addListSelectionListener(listener);
JScrollPane partyPane = new JScrollPane(partyList);
// partyPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
partyPanel.add(partyPane);
Expand All @@ -88,18 +87,18 @@ public AddPartyView(ControlDeskView controlDesk, int max) {
bowlerPanel.setBorder(new TitledBorder("Bowler Database"));

try {
bowlerdb = new Vector(BowlerFile.getBowlers());
bowlerdb = new Vector<String>(BowlerFile.getInstance().getBowlers());
} catch (Exception e) {
System.err.println("File Error");
bowlerdb = new Vector();
bowlerdb = new Vector<String>();
}
allBowlers = new JList(bowlerdb);
allBowlers.setVisibleRowCount(8);
allBowlers.setFixedCellWidth(120);
JScrollPane bowlerPane = new JScrollPane(allBowlers);
bowlerPane.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
allBowlers.addListSelectionListener(this);
allBowlers.addListSelectionListener(listener);
bowlerPanel.add(bowlerPane);

// Button Panel
Expand All @@ -108,10 +107,10 @@ public AddPartyView(ControlDeskView controlDesk, int max) {

Insets buttonMargin = new Insets(4, 4, 4, 4);

addPatron = createButton("Add to Party", new JPanel());
remPatron = createButton("Remove Member", new JPanel());
newPatron = createButton("New Patron", new JPanel());
finished = createButton("Finished", new JPanel());
addPatron = createButton("Add to Party", new JPanel(), listener);
remPatron = createButton("Remove Member", new JPanel(), listener);
newPatron = createButton("New Patron", new JPanel(), listener);
finished = createButton("Finished", new JPanel(), listener);

buttonPanel.add((JPanel) addPatron.getParent());
buttonPanel.add((JPanel) remPatron.getParent());
Expand All @@ -135,9 +134,9 @@ public AddPartyView(ControlDeskView controlDesk, int max) {
win.setVisible(true);

}
private JButton createButton(String buttonText, JPanel panel) { // 버튼 객체 생성
private JButton createButton(String buttonText, JPanel panel, AddPartyViewClickEvent listener) { // 버튼 객체 생성
JButton button = new JButton(buttonText);
button.addActionListener(this);
button.addActionListener(listener);
panel.setLayout(new FlowLayout());
panel.add(button);
return button;
Expand All @@ -148,92 +147,97 @@ public void setCommand(ButtonCommand command) {
public void buttonPressed() {
command.execute();
}

public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(addPatron)) {
if (selectedNick != null && party.size() < maxSize) {
if (party.contains(selectedNick)) {
System.err.println("Member already in Party");
} else {
party.add(selectedNick);
partyList.setListData(party);
}
}
}
if (e.getSource().equals(remPatron)) {
if (selectedMember != null) {
party.removeElement(selectedMember);
partyList.setListData(party);
}
}
if (e.getSource().equals(newPatron)) {
NewPatronView newPatron = new NewPatronView( this );
}
if (e.getSource().equals(finished)) {
if ( party != null && party.size() > 0) {
controlDesk.updateAddParty( this );
}
win.setVisible(false);
}

public String getSelectedNick() {
return selectedNick;
}

/**
* Handler for List actions
* @param e the ListActionEvent that triggered the handler
*/

public void valueChanged(ListSelectionEvent e) {
if (e.getSource().equals(allBowlers)) {
selectedNick =
((String) ((JList) e.getSource()).getSelectedValue());
}
if (e.getSource().equals(partyList)) {
selectedMember =
((String) ((JList) e.getSource()).getSelectedValue());
}
public String getSelectedMember() {
return selectedMember;
}
public int getMaxSize() {
return maxSize;
}
public JList getPartyList() {
return partyList;
}
public JFrame getWindow() {
return win;
}
public ControlDeskView getControlDesk() {
return controlDesk;
}
/**
* Accessor for Party
*/

/**
* Accessor for Party
*/

public Vector getNames() {
public Vector<String> getParty() {
return party;
}
/**
* Accessor for Party
*/

/**
* Called by NewPatronView to notify AddPartyView to update
*
* @param newPatron the NewPatronView that called this method
*/

public void updateNewPatron(NewPatronView newPatron) {
try {
Bowler checkBowler = BowlerFile.getBowlerInfo( newPatron.getNick() );
if ( checkBowler == null ) {
BowlerFile.putBowlerInfo(
newPatron.getNick(),
newPatron.getFull(),
newPatron.getEmail());
bowlerdb = new Vector(BowlerFile.getBowlers());
allBowlers.setListData(bowlerdb);
party.add(newPatron.getNick());
partyList.setListData(party);
} else {
System.err.println( "A Bowler with that name already exists." );
public Vector<String> getNames() {
return party;
}
public class AddPartyViewClickEvent implements ActionListener, ListSelectionListener {
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(addPatron)) {
setCommand(new AddPatronCommand(AddPartyView.this));
}
if (e.getSource().equals(remPatron)) {
setCommand(new RemovePatronCommand(AddPartyView.this));
}
if (e.getSource().equals(newPatron)) {
setCommand(new NewPatronCommand(AddPartyView.this));
}
} catch (Exception e2) {
System.err.println("File I/O Error");
if (e.getSource().equals(finished)) {
setCommand(new FinishedAddPartyCommand(AddPartyView.this));
}
buttonPressed();
}
}

/**
* Accessor for Party
*/
/**
* Handler for List actions
* @param e the ListActionEvent that triggered the handler
*/

public void valueChanged(ListSelectionEvent e) {
if (e.getSource().equals(allBowlers)) {
selectedNick =
((String) ((JList) e.getSource()).getSelectedValue());
}
if (e.getSource().equals(partyList)) {
selectedMember =
((String) ((JList) e.getSource()).getSelectedValue());
}
}

public Vector getParty() {
return party;
/**
* Called by NewPatronView to notify AddPartyView to update
*
* @param newPatron the NewPatronView that called this method
*/

public void updateNewPatron(NewPatronView newPatron) {
try {
Bowler checkBowler = BowlerFile.getInstance().getBowlerInfo( newPatron.getNick() );
if ( checkBowler == null ) {
BowlerFile.getInstance().putBowlerInfo(
newPatron.getNick(),
newPatron.getFull(),
newPatron.getEmail());
bowlerdb = new Vector<String>(BowlerFile.getInstance().getBowlers());
allBowlers.setListData(bowlerdb);
party.add(newPatron.getNick());
partyList.setListData(party);
} else {
String errMsg = "A Bowler with that name already exists.";
System.err.println(errMsg);
JOptionPane.showMessageDialog(win, errMsg, "Error", JOptionPane.ERROR_MESSAGE);
}
} catch (Exception e2) {
System.err.println("File I/O Error");
}
}
}

}
21 changes: 21 additions & 0 deletions AddPatronCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

public class AddPatronCommand implements ButtonCommand{
AddPartyView addPartyView;

public AddPatronCommand(AddPartyView addPartyView) {
this.addPartyView = addPartyView;
}

@Override
public void execute() {
if (addPartyView.getSelectedNick() != null && addPartyView.getParty().size() < addPartyView.getMaxSize()) {
if (addPartyView.getParty().contains(addPartyView.getSelectedNick())) {
System.err.println("Member already in Party");
} else {
addPartyView.getParty().add(addPartyView.getSelectedNick());
addPartyView.getPartyList().setListData(addPartyView.getParty());
}
}
}

}
14 changes: 3 additions & 11 deletions Bowler.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,8 @@ public String getEmail ( ) {
}

public boolean equals ( Bowler b) {
boolean retval = true;
if ( !(nickName.equals(b.getNickName())) ) {
retval = false;
}
if ( !(fullName.equals(b.getFullName())) ) {
retval = false;
}
if ( !(email.equals(b.getEmail())) ) {
retval = false;
}
return retval;
return nickName.equals(b.getNickName())
&& fullName.equals(b.getFullName())
&& email.equals(b.getEmail());
}
}
8 changes: 8 additions & 0 deletions BowlerDatabase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import java.io.IOException;
import java.util.List;

public interface BowlerDatabase {
Bowler getBowlerInfo(String nickName) throws IOException;
void putBowlerInfo(String nickName, String fullName, String email) throws IOException;
List<String> getBowlers() throws IOException;
}
Loading

0 comments on commit bccf80e

Please sign in to comment.