Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.38 KB | None | 0 0
  1. package convertAndUpload;
  2.  
  3. import javax.swing.BorderFactory;
  4. import javax.swing.DefaultComboBoxModel;
  5. import javax.swing.JButton;
  6. import javax.swing.JComboBox;
  7. import javax.swing.JFrame;
  8. import javax.swing.JProgressBar;
  9. import javax.swing.JTabbedPane;
  10. import javax.swing.JScrollPane;
  11. import javax.swing.JPanel;
  12. import javax.swing.JTable;
  13. import javax.swing.JTextArea;
  14. import javax.swing.ScrollPaneConstants;
  15. import javax.swing.JTextPane;
  16. import javax.swing.JLabel;
  17. import javax.swing.JTextField;
  18. import javax.swing.SwingUtilities;
  19. import javax.swing.table.DefaultTableModel;
  20. import javax.swing.table.TableColumn;
  21. import javax.swing.border.Border;
  22. import javax.swing.UIManager;
  23. import javax.swing.border.EmptyBorder;
  24. import javax.swing.event.DocumentEvent;
  25. import javax.swing.event.DocumentListener;
  26.  
  27. import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
  28. import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor;
  29.  
  30. import net.miginfocom.swing.MigLayout;
  31.  
  32. import java.awt.Dimension;
  33. import java.awt.Cursor;
  34. import java.awt.event.ActionEvent;
  35. import java.awt.event.ActionListener;
  36. import java.io.IOException;
  37. import java.net.URISyntaxException;
  38. import java.util.ArrayList;
  39. import java.util.Collections;
  40. import java.util.HashSet;
  41. import java.util.List;
  42.  
  43. import com.google.gdata.util.ServiceException;
  44.  
  45. public class Interface
  46. {  
  47.     private static JTable table;
  48.     private static JTextField textField;
  49.     private static JTextField textField_1;
  50.     private static List<String> guildMembersNames;
  51.     private static List<String> guildMembersNameTrimmed;
  52.     private static DefaultTableModel tableModel;
  53.     private final static Object lock = new Object();
  54.     private static Member submission;
  55.     private static List<Member> submissionMemberEntrys = new ArrayList<Member>();
  56.     private static List<String> tableEntryRowAddress = new ArrayList<String>();
  57.     static JProgressBar progressBar;
  58.     static JTextArea textArea;
  59.    
  60.     public Interface() throws IOException, ServiceException, URISyntaxException, InterruptedException
  61.     {
  62.         JFrame frame = new JFrame();
  63.         frame.setSize(700,600);
  64.         frame.getContentPane().setLayout(new MigLayout("", "[700px]", "[600px]"));
  65.         frame.setVisible(true);
  66.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  67.         JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  68.         frame.getContentPane().add(tabbedPane, "cell 0 0,grow");
  69.        
  70.         JPanel panel = new JPanel();
  71.        
  72.         JPanel update = new JPanel();
  73.         update.setBounds(0, 0, 650, 550);
  74.         update.setLayout(null);
  75.        
  76.         JTextArea txtrThisIsBeta = new JTextArea();
  77.         txtrThisIsBeta.setEditable(false);
  78.         txtrThisIsBeta.setBounds(10, 11, 630, 172);
  79.         txtrThisIsBeta.setText("If its the first time you start the app click Update and it will ask you to find\r\nGuildData.lua inside SavedVariables foldier, it wont ask you to do so again.\r\n\r\nText window in a middle will report on statistics as well as on problems \r\nif any of them encountered, as well as data about how long it took to \r\ncomplete the update.  \t\t\t\t\t\t\t\t\r\n\r\nBeta version 0.1 expect errors/problems/other nasty stuff.");
  80.         update.add(txtrThisIsBeta);
  81.        
  82.         JButton updateButton = new JButton("Update");
  83.         updateButton.addActionListener(new ActionListener() {
  84.             public void actionPerformed(ActionEvent arg0) {
  85.                 try {
  86.                     GuildData update = new GuildData();
  87.                 } catch (IOException | ServiceException | URISyntaxException e) {}
  88.             }
  89.         });
  90.         updateButton.setBounds(10, 238, 200, 50);
  91.         update.add(updateButton);
  92.        
  93.         JButton findAgainButton = new JButton("Find again");
  94.         findAgainButton.setBounds(10, 299, 200, 50);
  95.         update.add(findAgainButton);
  96.        
  97.         textArea = new JTextArea();
  98.         textArea.setBounds(220, 238, 420, 257);
  99.         update.add(textArea);
  100.        
  101.         JLabel lblLog = new JLabel("Update process log");
  102.         lblLog.setBounds(370, 213, 115, 14);
  103.         update.add(lblLog);
  104.  
  105.         panel.setPreferredSize(new Dimension(10, 70));
  106.         panel.setLayout(null);
  107.        
  108.         tabbedPane.addTab("Update", null, update, null);
  109.        
  110.         JPanel panel_1 = new JPanel();
  111.         panel_1.setBounds(0, 0, 700, 122);
  112.         panel.add(panel_1);
  113.         panel_1.setLayout(null);
  114.        
  115.         JTextPane txtpnPleaseEnterThe = new JTextPane();
  116.         txtpnPleaseEnterThe.setBackground(UIManager.getColor("Button.background"));
  117.         txtpnPleaseEnterThe.setAutoscrolls(false);
  118.         txtpnPleaseEnterThe.setBorder(null);
  119.         txtpnPleaseEnterThe.setText("Please enter the names of members who attended, their Points earned and reason for adjustment if its not default (events value) which will be added to all members automatically.\r\n");
  120.         txtpnPleaseEnterThe.setBounds(10, 6, 650, 66);
  121.         panel_1.add(txtpnPleaseEnterThe);
  122.        
  123.         JLabel lblEvent = new JLabel("Event:");
  124.         lblEvent.setBounds(10, 83, 46, 14);
  125.         panel_1.add(lblEvent);
  126.        
  127.         textField = new JTextField();
  128.         textField.setBounds(46, 83, 400, 14);
  129.         textField.setColumns(10);
  130.         panel_1.add(textField);
  131.        
  132.         textField_1 = new JTextField();
  133.         textField_1.setColumns(10);
  134.         textField_1.setBounds(510, 83, 41, 14);
  135.         textField_1.getDocument().addDocumentListener(new DocumentListener()
  136.         {
  137.                   public void changedUpdate(DocumentEvent e) {
  138.                     update();
  139.                   }
  140.                   public void removeUpdate(DocumentEvent e) {
  141.                     update();
  142.                   }
  143.                   public void insertUpdate(DocumentEvent e) {
  144.                     update();
  145.                   }
  146.  
  147.                   public void update()
  148.                   {
  149.                       for(int i=0;i<table.getRowCount();i++)
  150.                       {
  151.                           table.setValueAt(Integer.parseInt(textField_1.getText()), i, 1);
  152.                       }
  153.                   }
  154.                 });
  155.         panel_1.add(textField_1);
  156.        
  157.         JLabel lblValue = new JLabel("Value:");
  158.         lblValue.setBounds(470, 83, 35, 14);
  159.         panel_1.add(lblValue);
  160.        
  161.         for(int i=0; i<100;i++)
  162.         {
  163.             tableEntryRowAddress.add("");  
  164.         }
  165.        
  166.         JButton submit = new JButton("Submit");
  167.         submit.setBounds(570, 83, 80, 14);
  168.         submit.addActionListener(new ActionListener(){
  169.  
  170.             @Override
  171.             public void actionPerformed(ActionEvent arg0) {
  172.                 for(int i=0;i<table.getRowCount();i++)
  173.                 {
  174.                     if(table.getValueAt(i, 3)!=null)
  175.                     {
  176.                         submission = new Member(table.getValueAt(i, 3).toString());
  177.                         submission.setVirtuePoints(table.getValueAt(i, 1).toString());
  178.                         submission.setAccountKey(tableEntryRowAddress.get(i).toString());
  179.                         submissionMemberEntrys.add(submission);
  180.                     }
  181.                 }
  182.                 try {
  183.                     GuildData.submitEventReportPerCell(submissionMemberEntrys);
  184.                 } catch (URISyntaxException | IOException | ServiceException e) {
  185.                     e.printStackTrace();
  186.                 }
  187.             }});
  188.         panel_1.add(submit);
  189.        
  190.         JScrollPane scrollPane = new JScrollPane(table);
  191.         scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
  192.         scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
  193.         scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
  194.         scrollPane.setBounds(0, 120, 667, 403);
  195.         panel.add(scrollPane);
  196.         guildMembersNameTrimmed = new ArrayList<String>();
  197.         for(String name : guildMembersNames)
  198.         {
  199.             guildMembersNameTrimmed.add(name.substring(0, name.indexOf('#')));
  200.         }
  201.         HashSet<String> hs = new HashSet<String>();
  202.         hs.addAll(guildMembersNameTrimmed);
  203.         guildMembersNameTrimmed.clear();
  204.         guildMembersNameTrimmed.addAll(hs);
  205.         Collections.sort(guildMembersNameTrimmed);
  206.         final String[] columnNames = {"Name", "Points", "Comments", "Account"};
  207.         table = new JTable(new Object[11][4], columnNames)
  208.         {
  209.             private static final long serialVersionUID = 1L;
  210.             @Override
  211.             public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
  212.             {
  213.        
  214.                 if (!super.isEditing())
  215.                 {
  216.                     super.editCellAt(rowIndex, columnIndex);
  217.                 }
  218.                 int tempRow = rowIndex;
  219.                 if(tempRow>0&&table.getValueAt(tempRow-1, columnIndex)!=null)
  220.                 {
  221.                     String tempName = table.getValueAt(tempRow-1, columnIndex).toString();
  222.                     for(String name : guildMembersNames)
  223.                     {
  224.                         if(tempName.equals(name.substring(0, name.indexOf('#'))))
  225.                         {
  226.                             String namesRow = name.substring(name.indexOf('#')+1);
  227.                             if(namesRow.endsWith("@"))
  228.                             {
  229.                                 table.setValueAt("@"+name.substring(0, name.indexOf('#')), tempRow-1, 3);
  230.                                 tableEntryRowAddress.set(tempRow-1, namesRow.substring(0,namesRow.indexOf("@")));
  231.                                 break;
  232.                             }
  233.                             else
  234.                             {
  235.                                  for(String nameAcc : guildMembersNames)
  236.                                  {
  237.                                      if(nameAcc.endsWith(namesRow+"@"))
  238.                                      {
  239.                                          table.setValueAt("@"+nameAcc.substring(0, nameAcc.indexOf('#')), tempRow-1, 3);
  240.                                          tableEntryRowAddress.set(tempRow-1, namesRow);
  241.                                          break;
  242.                                      }
  243.                                  }
  244.                             }          
  245.                         }
  246.                     }  
  247.                 }
  248.                 super.changeSelection(rowIndex, columnIndex, toggle, extend);
  249.                 if(tempRow==table.getRowCount()-1)
  250.                 {
  251.                     tableModel.addRow(new String[]{"", "", "", ""});
  252.                 }
  253.             }
  254.         };
  255.         tableModel = new DefaultTableModel(new Object[table.getRowCount()+1][4], columnNames);
  256.         table.setSurrendersFocusOnKeystroke(true);
  257.         table.setModel(tableModel);
  258.         scrollPane.setViewportView(table);
  259.         setupATable();
  260.         tabbedPane.addTab("Events", null, panel, null);
  261.     }
  262.  
  263.    
  264.  
  265.     @SuppressWarnings({ "unchecked", "rawtypes" })
  266.     public void setupATable() throws IOException, ServiceException, URISyntaxException, InterruptedException
  267.     {
  268.         Border raisedbevel = BorderFactory.createRaisedBevelBorder();
  269.         Border loweredbevel = BorderFactory.createLoweredBevelBorder();
  270.         table.getTableHeader().setBorder(BorderFactory.createCompoundBorder(raisedbevel, loweredbevel));
  271.         final JComboBox comboBox = new JComboBox();
  272.         table.setCellSelectionEnabled(true);
  273.         table.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
  274.         table.getTableHeader().setReorderingAllowed(false);
  275.         comboBox.setModel(new DefaultComboBoxModel(guildMembersNameTrimmed.toArray()));
  276.         comboBox.setEditable(false);
  277.         AutoCompleteDecorator.decorate(comboBox);
  278.         TableColumn namesColumn = table.getColumnModel().getColumn(0);
  279.         table.setOpaque(true);
  280.         comboBox.setOpaque(true);
  281.         namesColumn.setCellEditor(new ComboBoxCellEditor(comboBox));
  282.     }
  283.    
  284.    
  285.     public static List<String> getMembersDataFromDB() throws IOException, ServiceException, URISyntaxException
  286.     {
  287. //      guildMembersNames = GuildData.getNamesListLine();
  288.         guildMembersNames = GuildData.getNamesList();
  289.         return guildMembersNames;
  290.     }
  291.    
  292.     public static void main(String[] args) throws IOException, ServiceException, URISyntaxException, InterruptedException
  293.     {
  294.         guildMembersNames = getMembersDataFromDB();
  295.         synchronized (lock)
  296.         {
  297.             lock.notify();
  298.         }
  299.          synchronized (lock)
  300.         {
  301.              while (guildMembersNames == null)
  302.              {
  303.                 lock.wait();
  304.              }
  305.         }
  306.        
  307.         SwingUtilities.invokeLater(new Runnable()
  308.         {
  309.             public void run()
  310.             {
  311.                 try
  312.                 {
  313.                     @SuppressWarnings("unused")
  314.                     Interface inter = new Interface();
  315.                 }
  316.                 catch (IOException | ServiceException | URISyntaxException | InterruptedException e)
  317.                 {
  318.                     e.printStackTrace();
  319.                 }
  320.             }
  321.         });
  322.     }
  323. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement