Don't like ads? PRO users don't see any ads ;-)

Untitled

By: ragnhild_karlsson on Apr 25th, 2012  |  syntax: Java  |  size: 7.63 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /**
  2.  * Destination produce GUI for viewing and editing Destination info
  3.  *
  4.  *
  5.  */
  6. import java.awt.Container;
  7. import java.awt.GridBagLayout;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.util.ArrayList;
  11. import java.util.Iterator;
  12.  
  13. import javax.swing.BoxLayout;
  14. import javax.swing.JButton;
  15. import javax.swing.JComponent;
  16. import javax.swing.JFrame;
  17. import javax.swing.JLabel;
  18. import javax.swing.JOptionPane;
  19. import javax.swing.JPanel;
  20. import javax.swing.JTextArea;
  21. import javax.swing.JTextField;
  22.  
  23. import net.miginfocom.swing.MigLayout;
  24.  
  25. public class DestinationWindow {
  26.  
  27.         private JFrame editDestinationFrame;
  28.         private final String destinationTitle;
  29.         private final String username;
  30.         private final String travelProjectName;
  31.         private DestinationReaderWriter dataArchive;   
  32.         private static String ARRIVALTITLE = "Inresa";
  33.         private static String DEPARTURETITLE = "Utresa";
  34.         private static String LIVINGTITLE = "Boende";
  35.         private static String QUITBUTTONTEXT = "Avsluta";
  36.         // private static String MOREINFOTITLE = "Mer info om ";
  37.         //private static int NUMBEROFCOLUMNSINMOREINFO = 40;
  38.         //private static int NUMBEROFROWESINMOREINFO = 6;
  39.         // private String moreInfotext;
  40.        
  41.         /**
  42.          * Create a instance of Destination that primely could be
  43.          * used to get an editDestination pop up,
  44.          * and Jpanel for viewing saved destination info
  45.          *
  46.          * @param destinationTitle
  47.          * @param username
  48.          * @param travelProjectName
  49.          */
  50.  
  51.         public DestinationWindow(String destinationTitle, String username, String travelProjectName) {
  52.                 this.destinationTitle = destinationTitle;
  53.                 this.username = username;
  54.                 this.travelProjectName = travelProjectName;
  55.                 dataArchive = new DestinationReaderWriter(destinationTitle, username, travelProjectName);
  56.         }
  57.        
  58.         // Declare a private Enum class for all accepted type of
  59.         // destinationInfoBlocks
  60.        
  61.        
  62.         private enum TypeOfPanel {
  63.                 VIEWING, EDITING
  64.         }
  65.  
  66.         /**
  67.          * Return a frame for editing destination info.
  68.          *
  69.          */
  70.        
  71.        
  72.         private void quitEditDestinationButtonAction(){
  73.                 editDestinationFrame.dispose();
  74.         }
  75.        
  76.         public JFrame getEditDestinationFrame(boolean firstTime){ //TODO
  77.                 //First time variabels
  78.                
  79.                
  80.                 //Spara en tom lista med short info som kan laddas till respektive shortInfo...
  81.                 //First time metod i DestinationReaderWriter som skapar tomma listor till samtliga available
  82.                
  83.                
  84.                 //Sätt frame egenskaper
  85.                 // sätt bakgrund
  86.                 return new JFrame();
  87.                
  88.         }
  89.        
  90.         /**
  91.          * Return a panel adjusted to fit in Travelplanners mainarea.
  92.          * The panel view all saved data about the destination.
  93.          * @return
  94.          */
  95.        
  96.         public JPanel getMainPanel(){
  97.                 JPanel returnPanel = buildDestinationInfoPanel(TypeOfPanel.VIEWING);
  98.                        
  99.                 return returnPanel;
  100.        
  101.                 }
  102.        
  103.        
  104.         /**
  105.          * Return a panel with box layouot that containing  subPanels
  106.          * representing all available DestinationHeadlines
  107.          * @param typeOfPanel: specialise if the panel should be adjusted
  108.          * for editing or viewing destination data.
  109.          */
  110.        
  111.         private JPanel buildDestinationInfoPanel(TypeOfPanel typeOfPanel){
  112.                
  113.         JPanel returnPanel = new JPanel(new MigLayout("wrap 1"));
  114.        
  115.         returnPanel.add(buildDestinationInfoBlock(DestinationHeadline.ARRIVAL, typeOfPanel));
  116.         returnPanel.add(buildDestinationInfoBlock(DestinationHeadline.DEPARTURE, typeOfPanel));
  117.         returnPanel.add(buildDestinationInfoBlock(DestinationHeadline.LIVING, typeOfPanel));
  118.        
  119.         if(typeOfPanel.equals(TypeOfPanel.EDITING)){
  120.                 //TODO ADDA SAVE OCH AVBRYTKLASSS...           
  121.                
  122.         }
  123.         return returnPanel;
  124.        
  125.         }
  126.                
  127.         /**
  128.          * Return a panel with the specified Headline, and components associated with
  129.          * this Headline.
  130.          * @param headline Specify which kind of information that will be present in the panel
  131.          * @param editOrView specify if the data should be presented in editable textFields or
  132.          * static Labels
  133.          * @return
  134.          *
  135.          */
  136.         private JPanel buildDestinationInfoBlock(DestinationHeadline headline, TypeOfPanel editOrView) {
  137.                
  138.                 JPanel returnPanel = new JPanel(new MigLayout("wrap 4"));
  139.                
  140.                 //Initialise headline and arrays representing data to be displaysed
  141.                
  142.                 String headlineOfBlock;
  143.                
  144.                                         // String moreInfoText;        
  145.                
  146.                 ArrayList<String> headlinesOfShortInforamtion = dataArchive.getShortDestinationInformationHeadlines(headline);
  147.                 ArrayList<String> dataOfShortInformation = dataArchive.getShortDestinationInformationData(headline);
  148.                                
  149.                 switch (headline){
  150.                 case ARRIVAL:
  151.                         headlineOfBlock = ARRIVALTITLE;
  152.                         //moreInfoText = dataArchive.getMoreInformationText(headline);
  153.                         break;
  154.                        
  155.                 case DEPARTURE:
  156.                         headlineOfBlock = DEPARTURETITLE;
  157.                         //moreInfoText = dataArchive.getMoreInformationText(headline);
  158.                         break;
  159.                 case LIVING:
  160.                         headlineOfBlock = LIVINGTITLE;
  161.                         //moreInfoText = dataArchive.getMoreInformationText(headline);
  162.                         break;
  163.                 }
  164.                                
  165.                 //Initialise Arrays of components representing subHeadlines and corresponding data
  166.  
  167.                 ArrayList<JLabel>  subHeadlinesLabels;
  168.                 ArrayList<JTextField> dataTextfields;
  169.                 ArrayList<JLabel> dataLabels;
  170.                                
  171.                 for (int i = 0; i < headlinesOfShortInforamtion.size(); i++ ){
  172.                         JLabel subHeadlineLabel = new JLabel(headlinesOfShortInforamtion.get(i));
  173.                         subHeadlinesLabels.add(i, subHeadlineLabel);
  174.                 }      
  175.                
  176.                 for (int j = 0; j < dataOfShortInformation.size(); j++ ){
  177.                         JTextField dataTextfield = new JTextField(dataOfShortInformation.get(j));
  178.                         dataTextfields.add(j, dataTextfield);
  179.                 }
  180.                
  181.                 for (int k = 0; k < dataOfShortInformation.size(); k++ ){
  182.                         JLabel dataLabel = new JLabel(dataOfShortInformation.get(k));
  183.                         dataLabels.add(k, dataLabel);
  184.                 }              
  185.                                
  186.                 //Initialise components not representing data saved in arrays  
  187.                
  188.                 //HeadLineLabel
  189.                 JLabel headlineLabel = new JLabel(headlineOfBlock);
  190.                
  191.                 //Buttons
  192.                 JButton quitButtonEditDestination = new JButton(QUITBUTTONTEXT);
  193.                 quitButtonEditDestination.addActionListener(new ActionListener() {
  194.                         public void actionPerformed(ActionEvent e) {
  195.                                 quitEditDestinationButtonAction();                     
  196.                         }
  197.                 });
  198.                
  199.                 SaveDestinationInfoButton saveDestinationInfoButton = new SaveDestinationInfoButton(dataArchive, dataTextfields, headlinesOfShortInforamtion, headline, QUITBUTTONTEXT);
  200.                 saveDestinationInfoButton.addActionListener(new ActionListener() {
  201.                         public void actionPerformed(ActionEvent e) {
  202.                                 saveDestinationInfoButton.savefunktion();                      
  203.                         }
  204.                 });
  205.                
  206.                
  207.                 returnPanel.add(comp)
  208.                
  209.                
  210.                 return new JPanel();
  211.  
  212.         }
  213.        
  214. }
  215.  
  216. //BLANDAT SKRÄP
  217.  
  218. //// More info Button action
  219. //
  220. //private void moreInfoButtonAction(DestinationHeadline typeOfInformation){
  221. //      JFrame MoreInfoFrame = new JFrame();
  222. //      String moreInfoString = dataArchive.getMoreInformationText(typeOfInformation);
  223. //      JOptionPane.showMessageDialog(MoreInfoFrame,moreInfoString,
  224. //      "Mer information", JOptionPane.INFORMATION_MESSAGE); //TODO fixa hårdkodningen på mer inforamtion
  225. //}
  226. //
  227.  
  228.  
  229. //switch (editOrWiev){
  230. //              case EDITING:
  231. //                      moreInfo = new JButton(MOREINFOTITLE);
  232. //                     
  233. //                      break;
  234. //              case VIEWING:
  235. //                      viewOrEdit = new JLabel();                     
  236. //              break; 
  237. //              }
  238. //
  239.        
  240.         //Components for typeOfPanel: Viewing
  241.        
  242.         // JFrame MoreInfoFrame = new JFrame();
  243.         // JButton moreInfoButton = new JButton(MOREINFOTITLE + headlineOfBlock);
  244.        
  245.                 //TODO button actionlistener
  246.        
  247. //      moreInfoButton.addActionListener(new ActionListener() {
  248. //      public void actionPerformed(ActionEvent e) {
  249. //              moreInfoButtonAction(headline);
  250. //      }
  251. //      });
  252. ////   
  253.         //components for typeOfPanel Editing,
  254.         //JLabel moreInfoLabel = new JLabel(MOREINFOTITLE + headlineOfBlock);                                                  
  255.                
  256.                 //initalise JtextArea
  257.                
  258.                 //JTextArea moreInfoTextArea = new JTextArea(moreInfoText);
  259.                 //moreInfoTextArea.setLineWrap(true);
  260.                
  261.                
  262.         //Fill panel
  263.                
  264.        
  265.                 //initialise
  266.  
  267. // Layout Panel