/**
* Destination produce GUI for viewing and editing Destination info
*
*
*/
import java.awt.Container;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;
public class DestinationWindow {
private JFrame editDestinationFrame;
private final String destinationTitle;
private final String username;
private final String travelProjectName;
private DestinationReaderWriter dataArchive;
private static String ARRIVALTITLE = "Inresa";
private static String DEPARTURETITLE = "Utresa";
private static String LIVINGTITLE = "Boende";
private static String QUITBUTTONTEXT = "Avsluta";
// private static String MOREINFOTITLE = "Mer info om ";
//private static int NUMBEROFCOLUMNSINMOREINFO = 40;
//private static int NUMBEROFROWESINMOREINFO = 6;
// private String moreInfotext;
/**
* Create a instance of Destination that primely could be
* used to get an editDestination pop up,
* and Jpanel for viewing saved destination info
*
* @param destinationTitle
* @param username
* @param travelProjectName
*/
public DestinationWindow(String destinationTitle, String username, String travelProjectName) {
this.destinationTitle = destinationTitle;
this.username = username;
this.travelProjectName = travelProjectName;
dataArchive = new DestinationReaderWriter(destinationTitle, username, travelProjectName);
}
// Declare a private Enum class for all accepted type of
// destinationInfoBlocks
private enum TypeOfPanel {
VIEWING, EDITING
}
/**
* Return a frame for editing destination info.
*
*/
private void quitEditDestinationButtonAction(){
editDestinationFrame.dispose();
}
public JFrame getEditDestinationFrame(boolean firstTime){ //TODO
//First time variabels
//Spara en tom lista med short info som kan laddas till respektive shortInfo...
//First time metod i DestinationReaderWriter som skapar tomma listor till samtliga available
//Sätt frame egenskaper
// sätt bakgrund
return new JFrame();
}
/**
* Return a panel adjusted to fit in Travelplanners mainarea.
* The panel view all saved data about the destination.
* @return
*/
public JPanel getMainPanel(){
JPanel returnPanel = buildDestinationInfoPanel(TypeOfPanel.VIEWING);
return returnPanel;
}
/**
* Return a panel with box layouot that containing subPanels
* representing all available DestinationHeadlines
* @param typeOfPanel: specialise if the panel should be adjusted
* for editing or viewing destination data.
*/
private JPanel buildDestinationInfoPanel(TypeOfPanel typeOfPanel){
JPanel returnPanel = new JPanel(new MigLayout("wrap 1"));
returnPanel.add(buildDestinationInfoBlock(DestinationHeadline.ARRIVAL, typeOfPanel));
returnPanel.add(buildDestinationInfoBlock(DestinationHeadline.DEPARTURE, typeOfPanel));
returnPanel.add(buildDestinationInfoBlock(DestinationHeadline.LIVING, typeOfPanel));
if(typeOfPanel.equals(TypeOfPanel.EDITING)){
//TODO ADDA SAVE OCH AVBRYTKLASSS...
}
return returnPanel;
}
/**
* Return a panel with the specified Headline, and components associated with
* this Headline.
* @param headline Specify which kind of information that will be present in the panel
* @param editOrView specify if the data should be presented in editable textFields or
* static Labels
* @return
*
*/
private JPanel buildDestinationInfoBlock(DestinationHeadline headline, TypeOfPanel editOrView) {
JPanel returnPanel = new JPanel(new MigLayout("wrap 4"));
//Initialise headline and arrays representing data to be displaysed
String headlineOfBlock;
// String moreInfoText;
ArrayList<String> headlinesOfShortInforamtion = dataArchive.getShortDestinationInformationHeadlines(headline);
ArrayList<String> dataOfShortInformation = dataArchive.getShortDestinationInformationData(headline);
switch (headline){
case ARRIVAL:
headlineOfBlock = ARRIVALTITLE;
//moreInfoText = dataArchive.getMoreInformationText(headline);
break;
case DEPARTURE:
headlineOfBlock = DEPARTURETITLE;
//moreInfoText = dataArchive.getMoreInformationText(headline);
break;
case LIVING:
headlineOfBlock = LIVINGTITLE;
//moreInfoText = dataArchive.getMoreInformationText(headline);
break;
}
//Initialise Arrays of components representing subHeadlines and corresponding data
ArrayList<JLabel> subHeadlinesLabels;
ArrayList<JTextField> dataTextfields;
ArrayList<JLabel> dataLabels;
for (int i = 0; i < headlinesOfShortInforamtion.size(); i++ ){
JLabel subHeadlineLabel = new JLabel(headlinesOfShortInforamtion.get(i));
subHeadlinesLabels.add(i, subHeadlineLabel);
}
for (int j = 0; j < dataOfShortInformation.size(); j++ ){
JTextField dataTextfield = new JTextField(dataOfShortInformation.get(j));
dataTextfields.add(j, dataTextfield);
}
for (int k = 0; k < dataOfShortInformation.size(); k++ ){
JLabel dataLabel = new JLabel(dataOfShortInformation.get(k));
dataLabels.add(k, dataLabel);
}
//Initialise components not representing data saved in arrays
//HeadLineLabel
JLabel headlineLabel = new JLabel(headlineOfBlock);
//Buttons
JButton quitButtonEditDestination = new JButton(QUITBUTTONTEXT);
quitButtonEditDestination.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
quitEditDestinationButtonAction();
}
});
SaveDestinationInfoButton saveDestinationInfoButton = new SaveDestinationInfoButton(dataArchive, dataTextfields, headlinesOfShortInforamtion, headline, QUITBUTTONTEXT);
saveDestinationInfoButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
saveDestinationInfoButton.savefunktion();
}
});
returnPanel.add(comp)
return new JPanel();
}
}
//BLANDAT SKRÄP
//// More info Button action
//
//private void moreInfoButtonAction(DestinationHeadline typeOfInformation){
// JFrame MoreInfoFrame = new JFrame();
// String moreInfoString = dataArchive.getMoreInformationText(typeOfInformation);
// JOptionPane.showMessageDialog(MoreInfoFrame,moreInfoString,
// "Mer information", JOptionPane.INFORMATION_MESSAGE); //TODO fixa hårdkodningen på mer inforamtion
//}
//
//switch (editOrWiev){
// case EDITING:
// moreInfo = new JButton(MOREINFOTITLE);
//
// break;
// case VIEWING:
// viewOrEdit = new JLabel();
// break;
// }
//
//Components for typeOfPanel: Viewing
// JFrame MoreInfoFrame = new JFrame();
// JButton moreInfoButton = new JButton(MOREINFOTITLE + headlineOfBlock);
//TODO button actionlistener
// moreInfoButton.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// moreInfoButtonAction(headline);
// }
// });
////
//components for typeOfPanel Editing,
//JLabel moreInfoLabel = new JLabel(MOREINFOTITLE + headlineOfBlock);
//initalise JtextArea
//JTextArea moreInfoTextArea = new JTextArea(moreInfoText);
//moreInfoTextArea.setLineWrap(true);
//Fill panel
//initialise
// Layout Panel