Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.Properties;
- import java.util.List;
- import java.util.ArrayList;
- import java.util.ListIterator;
- import javax.swing.*;
- import com.serena.dmclient.api.LoginFailedException;
- import com.serena.dmclient.api.Request;
- import java.util.Properties;
- public class MainFrame {
- /*
- * Nytt
- */
- String username, password, product, project;
- static boolean loggedIn = false;
- Dimensions di = new Dimensions();
- Properties properties = new Properties();
- protected MainFrame null;
- MainFrame() {
- try {
- properties.load(new FileInputStream("userdata.properties"));
- } catch(IOException ex) {}
- }
- private static void createAndShowGUI(final MainFrame mf) {
- final Session session = new Session();
- JFrame frame = new JFrame("Dimensions helper");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLocationRelativeTo(null);
- final JPanel contentPane = new JPanel();
- contentPane.setLayout(new CardLayout(5, 5));
- Win1 win1 = new Win1();
- contentPane.add(win1);
- Win2 win2 = new Win2();
- contentPane.add(win2);
- Win3 win3 = new Win3();
- contentPane.add(win3);
- /*
- * Laddar tidigare data från properties-filen
- */
- win1.setUsername(session.properties.getProperty("username", ""));
- win2.setProduct(session.properties.getProperty("product", ""));
- win2.setDesignpart(session.properties.getProperty("designpart", ""));
- JPanel buttonPanel = new JPanel();
- final JButton previousButton = new JButton("< PREVIOUS");
- previousButton.setEnabled(false);
- final JButton nextButton = new JButton("NEXT >");
- final JButton cancelButton = new JButton("CANCEL");
- buttonPanel.add(cancelButton);
- buttonPanel.add(previousButton);
- buttonPanel.add(nextButton);
- nextButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- nextButton.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
- Component[] contents = contentPane.getComponents();
- for(Component component : contents) {
- if(component.isVisible() && component instanceof Interface1) {
- Interface1 window = (Interface1) component;
- String username = window.getUsername();
- String password = window.getPassword();
- //boolean login = session.login(username, password);
- //loggedIn = mf.login(username, password);
- System.out.print(mf.login(username, password));
- if(loggedIn) {
- nextButton.setCursor(Cursor.getDefaultCursor());
- CardLayout cardLayout = (CardLayout) contentPane.getLayout();
- cardLayout.next(contentPane);
- previousButton.setEnabled(true);
- } else {
- JOptionPane.showMessageDialog(component, "Wrong username and/or password",
- "Error", JOptionPane.ERROR_MESSAGE);
- }
- break;
- } else if(component.isVisible() && component instanceof Interface2) {
- Interface2 window = (Interface2) component;
- String items = window.getItems();
- String product = window.getProduct();
- String designpart = window.getDesignpart();
- //List<Item> items2 = session.test(items, product, designpart);
- List<Item> itemList = session.test(testitem, testproduct, testproj);
- List<Item> finalItemList = new ArrayList<Item>();
- List<Request> relatedRequests = new ArrayList<Request>();
- finalItemList.addAll(itemList);
- for(int i=0; i<itemList.size(); i++) {
- finalItemList.addAll(itemList.get(i).getPreviousRevisions());
- }
- for(int j=0; j<finalItemList.size(); j++) {
- relatedRequests.addAll(finalItemList.get(j).getRelatedRequests());
- System.out.print(finalItemList.get(j).status + "\n");
- }
- }
- nextButton.setCursor(Cursor.getDefaultCursor());
- //break;
- }
- }
- });
- cancelButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent ae) {
- session.terminateConnection();
- System.exit(0);
- }
- });
- frame.add(contentPane);
- frame.add(buttonPanel, BorderLayout.PAGE_END);
- frame.setSize(400, 400);
- frame.setVisible(true);
- }
- public boolean login(String username, String password) {
- this.username = username;
- this.password = password;
- try {
- di.getDimensionsConnection(username2, password2");
- loggedIn = true;
- try {
- properties.setProperty("username", this.username);
- properties.store(new FileOutputStream("userdata.properties"), null);
- } catch(Exception e) {}
- } catch(LoginFailedException e) {
- System.out.print(e);
- loggedIn = false;
- }
- return loggedIn;
- }
- public boolean isLoggedOn() {
- return loggedIn;
- }
- public List<Item> test(String input, String product, String project) {
- String[] itemsArr = input.split(",");
- String newItemsArr[] = new String[itemsArr.length];
- for(int i=0; i<itemsArr.length; i++) {
- newItemsArr[i] = itemsArr[i].replaceAll("\"", "");
- }
- return di.getItems2(newItemsArr, product, project);
- }
- public static void main(String[] args) {
- SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- createAndShowGUI();
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment