-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
09ca653
commit a4d236d
Showing
10 changed files
with
514 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package Controller; | ||
|
||
import Model.*; | ||
import View.*; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
public class Controller { | ||
//singleton | ||
|
||
private static Controller instance = new Controller(); | ||
private Controller(){} | ||
|
||
public static Controller getInstance() { | ||
return instance; | ||
} | ||
|
||
|
||
|
||
public void searchBySlang(String _slang){ | ||
ArrayList<Slang> slangs = new ArrayList<Slang>(); | ||
Slang req = new Slang(_slang); | ||
Slang res = Repository.getInstance().findBySlang(req); | ||
if(res == null){ | ||
JOptionPane.showMessageDialog(null, "We do not have any slang like this","Search warning", JOptionPane.WARNING_MESSAGE); | ||
req.addMeaning("This slang doesn't exist"); | ||
Repository.getInstance().addSlangHistory(req); | ||
slangs.add(req); | ||
return; | ||
} | ||
else{ | ||
Repository.getInstance().addSlangHistory(res); | ||
slangs.add(res); | ||
} | ||
ResultsView resultsView = new ResultsView(slangs); | ||
|
||
} | ||
public void searchByKeyword(String _keyword){ | ||
Keyword keyword = Repository.getInstance().findByKeyword( | ||
new Keyword(_keyword) | ||
); | ||
if(keyword == null){ | ||
JOptionPane.showMessageDialog(null, "We do not have any slang like this","Search warning", JOptionPane.WARNING_MESSAGE); | ||
return; | ||
} | ||
ResultsView resultsView = new ResultsView(keyword.getSlangs()); | ||
|
||
} | ||
public ArrayList<Slang> getSlangHistory(){ | ||
return Repository.getInstance().getSlangHistory(); | ||
} | ||
public void addSlang(String _slang, String _meaning){ | ||
Slang slang = new Slang(_slang, _meaning); | ||
Slang check = Repository.getInstance() | ||
.findBySlang(slang); | ||
if(check == null){ | ||
Repository.getInstance().addSlang(slang); | ||
JOptionPane.showMessageDialog(null,"Successfully Added !!!"); | ||
} | ||
else{ | ||
String[] options = {"Overwrite", "Dupplicate"}; | ||
int i = JOptionPane.showOptionDialog(null, "Overwrite or duplicate", "Select an Option", | ||
JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); | ||
if(i == 0){ | ||
Repository.getInstance().overwriteSlang(slang); | ||
JOptionPane.showMessageDialog(null,"Successfully Overwrited !!!"); | ||
} | ||
if(i == 1){ | ||
Repository.getInstance().duplicateSlang(slang); | ||
JOptionPane.showMessageDialog(null,"Successfully Duplicated !!!"); | ||
} | ||
} | ||
} | ||
public void deleteSlang(String _slang){ | ||
Slang slang = new Slang(_slang); | ||
if(Repository.getInstance().findBySlang(slang) == null){ | ||
JOptionPane.showConfirmDialog(null, "We do not have any slang like this"); | ||
|
||
}else{ | ||
Repository.getInstance().deleteSlang(slang); | ||
JOptionPane.showMessageDialog(null, "Successfully Deleted !!!"); | ||
} | ||
} | ||
public void resetDictionary(){ | ||
Repository.getInstance().reset("slang.txt"); | ||
JOptionPane.showMessageDialog(null, "Successfully reseted !!!"); | ||
|
||
} | ||
public ArrayList<Slang> randomSlang(){ | ||
ArrayList<Slang> slangs = new ArrayList<Slang>(); | ||
slangs.add(Repository.getInstance().randomSlang()); | ||
return slangs; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
package Controller; | ||
|
||
import View.*; | ||
import Model.*; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class HomeController { | ||
HomeView homeView; | ||
ArrayList<Slang> slangArrayList = new ArrayList<Slang>(); | ||
public void init(){ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package View; | ||
import Controller.Controller; | ||
|
||
import javax.swing.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.GridBagConstraints; | ||
import java.awt.GridBagLayout; | ||
import javax.swing.JButton; | ||
import javax.swing.JFrame; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.SwingUtilities; | ||
import javax.swing.border.EmptyBorder; | ||
|
||
public class AddView { | ||
|
||
private class AddPanel extends JPanel{ | ||
JTextField slangTextField; | ||
JTextField meaningTextField; | ||
JButton button; | ||
public AddPanel(){ | ||
setBorder(new EmptyBorder(60, 60, 60 ,60 )); | ||
setLayout(new GridBagLayout()); | ||
GridBagConstraints gbc = new GridBagConstraints(); | ||
gbc.gridwidth = GridBagConstraints.REMAINDER; | ||
gbc.anchor = GridBagConstraints.NORTH; | ||
|
||
gbc.anchor = GridBagConstraints.EAST; | ||
gbc.fill = GridBagConstraints.HORIZONTAL; | ||
|
||
add(new JLabel("Slang: ")); | ||
slangTextField = new JTextField("", 15); | ||
add(slangTextField,gbc); | ||
|
||
add(new JLabel("Definition: ")); | ||
meaningTextField = new JTextField("", 15); | ||
add(meaningTextField, gbc); | ||
|
||
button = new JButton("Add Slang"); | ||
button.addActionListener( | ||
new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent actionEvent) { | ||
Controller.getInstance().addSlang( | ||
slangTextField.getText(), | ||
meaningTextField.getText() | ||
); | ||
} | ||
} | ||
); | ||
add(button); | ||
|
||
} | ||
|
||
} | ||
public AddView(){ | ||
SwingUtilities.invokeLater(new Runnable() { | ||
@Override | ||
public void run() { | ||
JFrame frame = new JFrame(); | ||
frame.add(new AddView.AddPanel()); | ||
frame.pack(); | ||
frame.setLocationRelativeTo(null); | ||
frame.setVisible(true); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.