private static final char DEFAULT_SEPARATOR = ',';
private static final char DEFAULT_QUOTE = '"';
- public static List<String> parseLine(String cvsLine) {
- return parseLine(cvsLine, DEFAULT_SEPARATOR, DEFAULT_QUOTE);
+ public static List<String> parseLine(String csvLine) {
+ return parseLine(csvLine, DEFAULT_SEPARATOR, DEFAULT_QUOTE);
}
- public static List<String> parseLine(String cvsLine, char separators) {
- return parseLine(cvsLine, separators, DEFAULT_QUOTE);
+ public static List<String> parseLine(String csvLine, char separators) {
+ return parseLine(csvLine, separators, DEFAULT_QUOTE);
}
- public static List<String> parseLine(String cvsLine, char separators, char customQuote) {
+ public static List<String> parseLine(String csvLine, char separators, char customQuote) {
List<String> result = new ArrayList<>();
//if empty, return!
- if (cvsLine == null && cvsLine.isEmpty()) {
+ if (csvLine == null && csvLine.isEmpty()) {
return result;
}
boolean startCollectChar = false;
boolean doubleQuotesInColumn = false;
- char[] chars = cvsLine.toCharArray();
+ char[] chars = csvLine.toCharArray();
for (char ch : chars) {
private String[] colorsList = {"black", "blue", "brown", "green"};
Eye() {
+ //this.color = Color.white;
sortColorList();
}
import javax.swing.*;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.util.Arrays;
-public class EyeView extends JPanel {
+public class EyeView extends JPanel implements ListSelectionListener {
private Eye eyeObj;
private JLabel label;
private JList colorsList;
this.colorsList.setLayoutOrientation(JList.VERTICAL);
this.colorsList.setSelectedIndex(Arrays.asList(this.getEyeObj().getColorsList()).indexOf(this.getEyeObj().getStrColor()));
this.colorsList.setCellRenderer(new EyeCellRenderer());
+ this.colorsList.addListSelectionListener(this);
add(label);
add(colorsList);
}
return colorsList;
}
+ @Override
+ public void valueChanged(ListSelectionEvent listSelectionEvent) {
+ Eye currentEye = new Eye((String) getColorsList().getSelectedValue());
+ PersonLeftPanel personLeftPanel = MainWindowsView.getInstance().getCurrentPersonView().getPersonPanel().getLeftPanel();
+ }
+
private static class EyeCellRenderer extends DefaultListCellRenderer {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
- MainWindowsView mainWindows = new MainWindowsView(programName, emptyPersonView);
+ MainWindowsView mainWindows = MainWindowsView.getInstance();
+ mainWindows.setMainWindowsView(programName, emptyPersonView);
mainWindows.showGUI();
}
});
import java.util.ArrayList;
public class MainWindowsView extends JFrame {
+ private static MainWindowsView ourInstance = new MainWindowsView();
+ private PersonView currentPersonView;
- MainWindowsView(String title, PersonView view) {
+ private MainWindowsView() {
+ }
+
+ public void setMainWindowsView(String title, PersonView personView) {
+ this.currentPersonView = personView;
Container panel = getContentPane();
//Create and set up the window.
setTitle(title);
- setSize(view.getDimension());
+ setSize(getCurrentPersonView().getDimension());
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.add(component);
}
- panel.add(view.getNorthPanel(), BorderLayout.NORTH);
- panel.add(view.getSouthPanel(), BorderLayout.SOUTH);
- panel.add(view.getEastPanel(), BorderLayout.EAST);
- panel.add(view.getWestPanel(), BorderLayout.WEST);
- panel.add(view.getPersonPanel(), BorderLayout.CENTER);
+ panel.add(getCurrentPersonView().getNorthPanel(), BorderLayout.NORTH);
+ panel.add(getCurrentPersonView().getSouthPanel(), BorderLayout.SOUTH);
+ panel.add(getCurrentPersonView().getEastPanel(), BorderLayout.EAST);
+ panel.add(getCurrentPersonView().getWestPanel(), BorderLayout.WEST);
+ panel.add(getCurrentPersonView().getPersonPanel(), BorderLayout.CENTER);
+ }
+
+ public static MainWindowsView getInstance() {
+ return ourInstance;
+ }
+
+ public PersonView getCurrentPersonView() {
+ return currentPersonView;
}
/**
import java.io.File;
import java.io.IOException;
-public class LeftPersonPanel extends JPanel {
+public class PersonLeftPanel extends JPanel {
private JLabel leftLabel = new JLabel();
private Image personImage;
- LeftPersonPanel() {
+ PersonLeftPanel() {
leftLabel.setText("Current person");
add(leftLabel);
try {
}
}
- public Image getPersonImage() {
- return personImage;
- }
-
public void paintComponent(Graphics g) {
super.paintComponent(g);
import javax.swing.*;
public class PersonPanel extends JPanel {
- private LeftPersonPanel leftPanel = new LeftPersonPanel();
- private RightPersonPanel rightPanel = new RightPersonPanel();
+ private PersonLeftPanel leftPanel = new PersonLeftPanel();
+ private PersonRightPanel rightPanel = new PersonRightPanel();
public PersonPanel() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
public void setRightContentText(String rightContentText) {
this.rightPanel.setContentText(rightContentText);
}
+
+ public PersonLeftPanel getLeftPanel() {
+ return leftPanel;
+ }
+
+ public PersonRightPanel getRightPanel() {
+ return rightPanel;
+ }
}
import java.io.File;
import java.io.IOException;
-public class RightPersonPanel extends JPanel {
+public class PersonRightPanel extends JPanel {
private JLabel rightLabel = new JLabel();
private String contentText = new String();
private Image personImage;
- RightPersonPanel() {
+ PersonRightPanel() {
rightLabel.setText("Closest person found");
add(rightLabel);
try {