Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package convertAndUpload;
- import javax.swing.BorderFactory;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JProgressBar;
- import javax.swing.JTabbedPane;
- import javax.swing.JScrollPane;
- import javax.swing.JPanel;
- import javax.swing.JTable;
- import javax.swing.JTextArea;
- import javax.swing.ScrollPaneConstants;
- import javax.swing.JTextPane;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.SwingUtilities;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.table.TableColumn;
- import javax.swing.border.Border;
- import javax.swing.UIManager;
- import javax.swing.border.EmptyBorder;
- import javax.swing.event.DocumentEvent;
- import javax.swing.event.DocumentListener;
- import org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
- import org.jdesktop.swingx.autocomplete.ComboBoxCellEditor;
- import net.miginfocom.swing.MigLayout;
- import java.awt.Dimension;
- import java.awt.Cursor;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.IOException;
- import java.net.URISyntaxException;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashSet;
- import java.util.List;
- import com.google.gdata.util.ServiceException;
- public class Interface
- {
- private static JTable table;
- private static JTextField textField;
- private static JTextField textField_1;
- private static List<String> guildMembersNames;
- private static List<String> guildMembersNameTrimmed;
- private static DefaultTableModel tableModel;
- private final static Object lock = new Object();
- private static Member submission;
- private static List<Member> submissionMemberEntrys = new ArrayList<Member>();
- private static List<String> tableEntryRowAddress = new ArrayList<String>();
- static JProgressBar progressBar;
- static JTextArea textArea;
- public Interface() throws IOException, ServiceException, URISyntaxException, InterruptedException
- {
- JFrame frame = new JFrame();
- frame.setSize(700,600);
- frame.getContentPane().setLayout(new MigLayout("", "[700px]", "[600px]"));
- frame.setVisible(true);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
- frame.getContentPane().add(tabbedPane, "cell 0 0,grow");
- JPanel panel = new JPanel();
- JPanel update = new JPanel();
- update.setBounds(0, 0, 650, 550);
- update.setLayout(null);
- JTextArea txtrThisIsBeta = new JTextArea();
- txtrThisIsBeta.setEditable(false);
- txtrThisIsBeta.setBounds(10, 11, 630, 172);
- 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.");
- update.add(txtrThisIsBeta);
- JButton updateButton = new JButton("Update");
- updateButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- try {
- GuildData update = new GuildData();
- } catch (IOException | ServiceException | URISyntaxException e) {}
- }
- });
- updateButton.setBounds(10, 238, 200, 50);
- update.add(updateButton);
- JButton findAgainButton = new JButton("Find again");
- findAgainButton.setBounds(10, 299, 200, 50);
- update.add(findAgainButton);
- textArea = new JTextArea();
- textArea.setBounds(220, 238, 420, 257);
- update.add(textArea);
- JLabel lblLog = new JLabel("Update process log");
- lblLog.setBounds(370, 213, 115, 14);
- update.add(lblLog);
- panel.setPreferredSize(new Dimension(10, 70));
- panel.setLayout(null);
- tabbedPane.addTab("Update", null, update, null);
- JPanel panel_1 = new JPanel();
- panel_1.setBounds(0, 0, 700, 122);
- panel.add(panel_1);
- panel_1.setLayout(null);
- JTextPane txtpnPleaseEnterThe = new JTextPane();
- txtpnPleaseEnterThe.setBackground(UIManager.getColor("Button.background"));
- txtpnPleaseEnterThe.setAutoscrolls(false);
- txtpnPleaseEnterThe.setBorder(null);
- 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");
- txtpnPleaseEnterThe.setBounds(10, 6, 650, 66);
- panel_1.add(txtpnPleaseEnterThe);
- JLabel lblEvent = new JLabel("Event:");
- lblEvent.setBounds(10, 83, 46, 14);
- panel_1.add(lblEvent);
- textField = new JTextField();
- textField.setBounds(46, 83, 400, 14);
- textField.setColumns(10);
- panel_1.add(textField);
- textField_1 = new JTextField();
- textField_1.setColumns(10);
- textField_1.setBounds(510, 83, 41, 14);
- textField_1.getDocument().addDocumentListener(new DocumentListener()
- {
- public void changedUpdate(DocumentEvent e) {
- update();
- }
- public void removeUpdate(DocumentEvent e) {
- update();
- }
- public void insertUpdate(DocumentEvent e) {
- update();
- }
- public void update()
- {
- for(int i=0;i<table.getRowCount();i++)
- {
- table.setValueAt(Integer.parseInt(textField_1.getText()), i, 1);
- }
- }
- });
- panel_1.add(textField_1);
- JLabel lblValue = new JLabel("Value:");
- lblValue.setBounds(470, 83, 35, 14);
- panel_1.add(lblValue);
- for(int i=0; i<100;i++)
- {
- tableEntryRowAddress.add("");
- }
- JButton submit = new JButton("Submit");
- submit.setBounds(570, 83, 80, 14);
- submit.addActionListener(new ActionListener(){
- @Override
- public void actionPerformed(ActionEvent arg0) {
- for(int i=0;i<table.getRowCount();i++)
- {
- if(table.getValueAt(i, 3)!=null)
- {
- submission = new Member(table.getValueAt(i, 3).toString());
- submission.setVirtuePoints(table.getValueAt(i, 1).toString());
- submission.setAccountKey(tableEntryRowAddress.get(i).toString());
- submissionMemberEntrys.add(submission);
- }
- }
- try {
- GuildData.submitEventReportPerCell(submissionMemberEntrys);
- } catch (URISyntaxException | IOException | ServiceException e) {
- e.printStackTrace();
- }
- }});
- panel_1.add(submit);
- JScrollPane scrollPane = new JScrollPane(table);
- scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
- scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
- scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
- scrollPane.setBounds(0, 120, 667, 403);
- panel.add(scrollPane);
- guildMembersNameTrimmed = new ArrayList<String>();
- for(String name : guildMembersNames)
- {
- guildMembersNameTrimmed.add(name.substring(0, name.indexOf('#')));
- }
- HashSet<String> hs = new HashSet<String>();
- hs.addAll(guildMembersNameTrimmed);
- guildMembersNameTrimmed.clear();
- guildMembersNameTrimmed.addAll(hs);
- Collections.sort(guildMembersNameTrimmed);
- final String[] columnNames = {"Name", "Points", "Comments", "Account"};
- table = new JTable(new Object[11][4], columnNames)
- {
- private static final long serialVersionUID = 1L;
- @Override
- public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
- {
- if (!super.isEditing())
- {
- super.editCellAt(rowIndex, columnIndex);
- }
- int tempRow = rowIndex;
- if(tempRow>0&&table.getValueAt(tempRow-1, columnIndex)!=null)
- {
- String tempName = table.getValueAt(tempRow-1, columnIndex).toString();
- for(String name : guildMembersNames)
- {
- if(tempName.equals(name.substring(0, name.indexOf('#'))))
- {
- String namesRow = name.substring(name.indexOf('#')+1);
- if(namesRow.endsWith("@"))
- {
- table.setValueAt("@"+name.substring(0, name.indexOf('#')), tempRow-1, 3);
- tableEntryRowAddress.set(tempRow-1, namesRow.substring(0,namesRow.indexOf("@")));
- break;
- }
- else
- {
- for(String nameAcc : guildMembersNames)
- {
- if(nameAcc.endsWith(namesRow+"@"))
- {
- table.setValueAt("@"+nameAcc.substring(0, nameAcc.indexOf('#')), tempRow-1, 3);
- tableEntryRowAddress.set(tempRow-1, namesRow);
- break;
- }
- }
- }
- }
- }
- }
- super.changeSelection(rowIndex, columnIndex, toggle, extend);
- if(tempRow==table.getRowCount()-1)
- {
- tableModel.addRow(new String[]{"", "", "", ""});
- }
- }
- };
- tableModel = new DefaultTableModel(new Object[table.getRowCount()+1][4], columnNames);
- table.setSurrendersFocusOnKeystroke(true);
- table.setModel(tableModel);
- scrollPane.setViewportView(table);
- setupATable();
- tabbedPane.addTab("Events", null, panel, null);
- }
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public void setupATable() throws IOException, ServiceException, URISyntaxException, InterruptedException
- {
- Border raisedbevel = BorderFactory.createRaisedBevelBorder();
- Border loweredbevel = BorderFactory.createLoweredBevelBorder();
- table.getTableHeader().setBorder(BorderFactory.createCompoundBorder(raisedbevel, loweredbevel));
- final JComboBox comboBox = new JComboBox();
- table.setCellSelectionEnabled(true);
- table.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
- table.getTableHeader().setReorderingAllowed(false);
- comboBox.setModel(new DefaultComboBoxModel(guildMembersNameTrimmed.toArray()));
- comboBox.setEditable(false);
- AutoCompleteDecorator.decorate(comboBox);
- TableColumn namesColumn = table.getColumnModel().getColumn(0);
- table.setOpaque(true);
- comboBox.setOpaque(true);
- namesColumn.setCellEditor(new ComboBoxCellEditor(comboBox));
- }
- public static List<String> getMembersDataFromDB() throws IOException, ServiceException, URISyntaxException
- {
- // guildMembersNames = GuildData.getNamesListLine();
- guildMembersNames = GuildData.getNamesList();
- return guildMembersNames;
- }
- public static void main(String[] args) throws IOException, ServiceException, URISyntaxException, InterruptedException
- {
- guildMembersNames = getMembersDataFromDB();
- synchronized (lock)
- {
- lock.notify();
- }
- synchronized (lock)
- {
- while (guildMembersNames == null)
- {
- lock.wait();
- }
- }
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- try
- {
- @SuppressWarnings("unused")
- Interface inter = new Interface();
- }
- catch (IOException | ServiceException | URISyntaxException | InterruptedException e)
- {
- e.printStackTrace();
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement