Example usage for java.awt Cursor WAIT_CURSOR

List of usage examples for java.awt Cursor WAIT_CURSOR

Introduction

In this page you can find the example usage for java.awt Cursor WAIT_CURSOR.

Prototype

int WAIT_CURSOR

To view the source code for java.awt Cursor WAIT_CURSOR.

Click Source Link

Document

The wait cursor type.

Usage

From source file:com.ssn.event.controller.SSNUntaggedMediaController.java

@Override
public void mouseClicked(MouseEvent e) {
    Object mouseEventObj = e.getSource();
    if (mouseEventObj != null && mouseEventObj instanceof JLabel) {
        JLabel label = (JLabel) mouseEventObj;
        JLabel toolbarLabel = SSNHomeController.currentLabel;
        this.getHomeModel().getHomeForm().getHomeController().setIconImage(toolbarLabel,
                "/icon/tagged-untagged-media.png", "allUntagged", SSNConstants.SSN_TOOLBAR_WHITE_FONT_COLOR);
        this.getHomeModel().getHomeForm().getHomeController().setIconImage(SSNToolBar.desktopHomeLabel,
                "/icon/white_icon/home.png", "home", SSNConstants.SSN_TEXT_LABEL_YELLOW_COLOR);
        this.getHomeModel().getHomeForm().setCursor(new Cursor(Cursor.WAIT_CURSOR));
        int timoutCount = 0;
        logger.info("mouseClicked() label " + label.getName());
        switch (label.getName()) {
        case "FacebookMedia":
            untaggedMediaForm.dispose();
            String facebookMessage = "User denied for OurHive App permission on facebook.";
            if ((this.getHomeModel().getHomeForm().getFacebookAccessGrant() != null
                    && !this.getHomeModel().getHomeForm().isLoggedInFromFaceBook()
                    && getFaceBookConnection() != null)
                    && this.getHomeModel().getHomeForm().isIsSocialSearched()) {

                try {
                    File searchFolder = new File(SSNHelper.getFacebookPhotosDirPath());
                    File folder = new File(SSNHelper.getSsnDefaultDirPath());
                    File[] files = searchFolder.listFiles();
                    String defaultAlbumPath = "";
                    if (searchFolder.list().length > 0) {
                        defaultAlbumPath = (searchFolder.listFiles())[0].getAbsolutePath();
                        files = new File(defaultAlbumPath).listFiles();
                    }//from  w  w w  .j  a va  2s .c  om

                    List<File> fileList = new ArrayList<File>();
                    for (File f : files) {
                        fileList.add(f);
                    }
                    Iterator<File> iterator = fileList.iterator();
                    while (iterator.hasNext()) {
                        File f = iterator.next();
                        boolean check = false;
                        try {
                            check = SSNDao
                                    .checkMediaExist(folder.getAbsolutePath() + File.separator + f.getName());
                        } catch (SQLException ex) {
                            //ex.printStackTrace();
                            logger.error(ex);
                        }
                        if (check) {
                            // iterator.remove();
                        }
                    }
                    File[] fileArray = new File[fileList.size()];
                    for (int i = 0; i < fileList.size(); i++) {
                        fileArray[i] = fileList.get(i);
                    }

                    //this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText("facebookMedia");
                    // this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText(defaultAlbumPath);

                    //this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                    this.getHomeModel().getHomeForm().getFileNamesToBeDeleted().clear();
                    //this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                    SSNHelper.toggleDeleteAndShareImages(false, this.getHomeModel().getHomeForm());
                    SSNGalleryHelper contentPane = new SSNGalleryHelper(fileArray,
                            this.getHomeModel().getHomeForm());

                    contentPane.setBackground(SSNConstants.SSN_BLACK_BACKGROUND_COLOR);
                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().removeAll();
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().removeAll();

                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().add(this.getHomeModel()
                            .getHomeForm().getScrollPane(contentPane, SSNHelper.getAlbumNameFromPath(
                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText())));
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(this.getHomeModel()
                            .getHomeForm()
                            .getSortPanel("Date", false, SSNHelper.getAlbumNameFromPath(
                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText())),
                            BorderLayout.NORTH);
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(
                            this.getHomeModel().getHomeForm().getSsnHomeCenterPanel(), BorderLayout.CENTER);
                    this.getHomeModel().getSSNMediaFolderProperties(
                            this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText(), fileArray);

                    renderLeftPanel();
                    this.getHomeModel().getHomeForm().revalidate();
                } catch (IOException ex) {
                    //java.util.logging.Logger.getLogger(SSNUntaggedMediaController.class.getName()).log(Level.SEVERE, null, ex);
                    logger.error(ex);
                }

            } else {

                logger.info("Facebook login user not logged in mouseClicked switch case else part");
                LoginWithFacebook.deniedPermission = false;
                AccessGrant facebookAccessGrant = getHomeModel().getHomeForm().getFacebookAccessGrant();
                if (facebookAccessGrant == null) {
                    try {

                        LoginWithFacebook loginWithFacebook = new LoginWithFacebook(null);
                        loginWithFacebook.setHomeForm(getHomeModel().getHomeForm());
                        loginWithFacebook.login();
                        boolean processFurther = false;

                        while (!processFurther) {
                            if (LoginWithFacebook.deniedPermission) {
                                break;
                            }
                            facebookAccessGrant = getHomeModel().getHomeForm().getFacebookAccessGrant();
                            if (facebookAccessGrant == null) {

                                if (timoutCount > (5 * 5000)) {
                                    LoginWithFacebook.deniedPermission = true;
                                    facebookMessage = "No response from Facebook.";
                                    SSNHttpServer.getHttpServer().stop(0);
                                    break;
                                } else {
                                    Thread.sleep(5000);
                                    timoutCount += 5000;
                                }
                            } else {
                                processFurther = true;
                            }
                        }
                    } catch (InterruptedException ex) {
                        logger.error(ex);
                        //ex.printStackTrace();
                    } catch (Exception ex) {
                        logger.error(ex);
                        //ex.printStackTrace();
                    }
                }
                if (!LoginWithFacebook.deniedPermission) {
                    //                            FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory(SSNConstants.SSN_FACEBOOK_API_KEY,
                    //                                    SSNConstants.SSN_FACEBOOK_SECRET_KEY);
                    Connection<Facebook> connection = getFaceBookConnection();
                    Facebook facebook = connection.getApi();
                    MediaOperations mediaOperations = facebook.mediaOperations();

                    PagedList<Album> albums = mediaOperations.getAlbums();

                    if (albums.size() > 0) {
                        Collections.sort(albums, new Comparator<Album>() {
                            @Override
                            public int compare(final Album object1, final Album object2) {
                                return object1.getName().compareTo(object2.getName());
                            }
                        });
                    }

                    if (albums != null && !albums.isEmpty()) {
                        try {
                            List<Photo> completePhotoList = new ArrayList<Photo>();
                            String albumName = "";
                            for (Album album : albums) {
                                List<Photo> listPhoto = new ArrayList<Photo>();
                                int captured = 0;
                                do {

                                    PagingParameters pagingParameters = new PagingParameters(100, captured,
                                            null, Calendar.getInstance().getTimeInMillis());
                                    listPhoto = mediaOperations.getPhotos(album.getId(), pagingParameters);
                                    captured += listPhoto.size();
                                    completePhotoList.addAll(listPhoto);
                                    albumName = album.getName();
                                    File facebookPhotosDir = new File(SSNHelper.getFacebookPhotosDirPath()
                                            + album.getName() + File.separator);
                                    if (!facebookPhotosDir.exists()) {
                                        facebookPhotosDir.mkdir();
                                    }

                                } while (listPhoto.size() > 0);
                                break;
                            }
                            File searchFolder = new File(
                                    SSNHelper.getFacebookPhotosDirPath() + File.separator + albumName);
                            if (!searchFolder.exists()) {
                                searchFolder.mkdirs();
                            } else {
                                //delete whole directory and create new one each time  
                                FileUtils.deleteDirectory(searchFolder);
                                searchFolder.mkdir();
                            }

                            for (Photo photo : completePhotoList) {
                                try {
                                    String imageUrl = "";
                                    for (Photo.Image image : photo.getImages()) {
                                        if (image != null && image.getHeight() <= 500) {
                                            imageUrl = image.getSource();
                                            break;
                                        }
                                    }

                                    if (imageUrl.isEmpty()) {
                                        imageUrl = photo.getSource();
                                    }
                                    URL url = new URL(imageUrl);
                                    File file = new File(searchFolder.getAbsolutePath() + File.separator
                                            + photo.getId() + ".jpg");
                                    if (!file.exists()) {
                                        try {
                                            FileUtils.copyURLToFile(url, file);
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                            logger.error(ex);
                                        }
                                    }
                                } catch (MalformedURLException ex) {
                                    //    java.util.logging.Logger.getLogger(SSNUntaggedMediaController.class.getName()).log(Level.SEVERE, null, ex);
                                    logger.error(ex);
                                }

                            }

                            this.getHomeModel().getHomeForm().setIsSocialSearched(true);
                            File[] files = searchFolder.listFiles();
                            File folder = new File(SSNHelper.getSsnDefaultDirPath());
                            List<File> tempFileList = Arrays.asList(files);

                            List<File> fileList = new ArrayList<File>();
                            fileList.addAll(tempFileList);

                            Iterator<File> iterator = fileList.iterator();
                            while (iterator.hasNext()) {
                                File f = iterator.next();
                                boolean check = false;
                                try {
                                    check = SSNDao.checkMediaExist(
                                            folder.getAbsolutePath() + File.separator + f.getName());
                                } catch (SQLException ex) {
                                    ex.printStackTrace();
                                }
                                if (check) {
                                    //iterator.remove();
                                }
                            }
                            File[] fileArray = new File[fileList.size()];
                            for (int j = 0; j < fileList.size(); j++) {
                                fileArray[j] = fileList.get(j);
                            }
                            String rootPath = SSNHelper.getSsnHiveDirPath();
                            //this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText("facebookMedia");
                            //this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);

                            this.getHomeModel().getHomeForm().ssnFileExplorer.m_display
                                    .setText(searchFolder.getAbsolutePath());
                            // this.getHomeModel().getHomeForm().getFileNamesToBeDeleted().clear();
                            // this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                            // this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                            SSNHelper.toggleDeleteAndShareImages(false, this.getHomeModel().getHomeForm());
                            SSNGalleryHelper contentPane = new SSNGalleryHelper(fileArray,
                                    this.getHomeModel().getHomeForm());

                            contentPane.setBackground(SSNConstants.SSN_BLACK_BACKGROUND_COLOR);
                            this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().removeAll();
                            this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().removeAll();

                            this.getHomeModel().getHomeForm().getSsnHomeCenterPanel()
                                    .add(this.getHomeModel().getHomeForm().getScrollPane(contentPane,
                                            SSNHelper.getAlbumNameFromPath(
                                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display
                                                            .getText())));
                            this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel()
                                    .add(this.getHomeModel().getHomeForm().getSortPanel("Date", false,
                                            SSNHelper.getAlbumNameFromPath(
                                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display
                                                            .getText())),
                                            BorderLayout.NORTH);
                            this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(
                                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel(),
                                    BorderLayout.CENTER);
                            this.getHomeModel().getSSNMediaFolderProperties(
                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText(),
                                    fileArray);

                            renderLeftPanel();
                            this.getHomeModel().getHomeForm().revalidate();
                            // System.out.println("Show gallery  " + new Date());
                        } catch (IOException ex) {
                            logger.error(ex);
                        }

                    }
                } else {
                    SSNMessageDialogBox messageDialogBox = new SSNMessageDialogBox();
                    messageDialogBox.initDialogBoxUI(SSNDialogChoice.NOTIFICATION_DIALOG.getType(), "Alert", "",
                            facebookMessage);
                    messageDialogBox.setFocusable(true);
                }
            }
            break;
        case "InstagramMedia":
            untaggedMediaForm.dispose();
            String instagarmMessage = "User denied for OurHive App permission on instagram!";
            if ((this.getHomeModel().getHomeForm().getInstagramAccessGrant() != null
                    && !this.getHomeModel().getHomeForm().isLoggedInFromInstagram())
                    || this.getHomeModel().getHomeForm().isInstagramSearched()) {
                try {
                    // System.out.println("inside ");
                    File searchFolder = new File(
                            SSNHelper.getSsnWorkSpaceDirPath() + File.separator + "Instagram Media");
                    File folder = new File(SSNHelper.getSsnHiveDirPath() + File.separator + "InstagramMedia");
                    File[] files = searchFolder.listFiles();
                    List<File> fileList = new ArrayList<File>();
                    for (File f : files) {
                        fileList.add(f);
                    }
                    Iterator<File> iterator = fileList.iterator();
                    while (iterator.hasNext()) {
                        File f = iterator.next();
                        boolean check = false;
                        try {
                            check = SSNDao
                                    .checkMediaExist(folder.getAbsolutePath() + File.separator + f.getName());
                        } catch (SQLException ex) {
                            ex.printStackTrace();
                        }
                        if (check) {
                            // iterator.remove();
                        }
                    }
                    File[] fileArray = new File[fileList.size()];
                    for (int i = 0; i < fileList.size(); i++) {
                        fileArray[i] = fileList.get(i);
                    }

                    String rootPath = SSNHelper.getSsnHiveDirPath();

                    this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionPath(null);
                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText("instagramMedia");

                    //this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                    //this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText(searchFolder.getAbsolutePath());
                    this.getHomeModel().getHomeForm().getFileNamesToBeDeleted().clear();
                    this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                    SSNHelper.toggleDeleteAndShareImages(false, this.getHomeModel().getHomeForm());
                    SSNGalleryHelper contentPane = new SSNGalleryHelper(fileArray,
                            this.getHomeModel().getHomeForm());

                    contentPane.setBackground(SSNConstants.SSN_BLACK_BACKGROUND_COLOR);
                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().removeAll();
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().removeAll();

                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().add(
                            this.getHomeModel().getHomeForm().getScrollPane(contentPane, "Instagram Media"));
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(this.getHomeModel()
                            .getHomeForm()
                            .getSortPanel("Date", false, SSNHelper.getAlbumNameFromPath(
                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText())),
                            BorderLayout.NORTH);
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(
                            this.getHomeModel().getHomeForm().getSsnHomeCenterPanel(), BorderLayout.CENTER);
                    this.getHomeModel().getSSNMediaFolderProperties(
                            this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText(), fileArray);
                    renderLeftPanel();
                    this.getHomeModel().getHomeForm().revalidate();
                } catch (IOException ex) {
                    logger.error(ex);
                }
            } else {
                try {
                    // System.out.println("cancle " + LoginWithInstagram.deniedInstagramPermission);
                    LoginWithInstagram.deniedInstagramPermission = false;
                    AccessGrant instgramAccessGrant = getHomeModel().getHomeForm().getInstagramAccessGrant();
                    if (instgramAccessGrant == null) {
                        try {

                            LoginWithInstagram loginWithInstagram = new LoginWithInstagram(
                                    getHomeModel().getHomeForm());

                            loginWithInstagram.login();
                            boolean processFurther = false;
                            while (!processFurther) {
                                if (LoginWithInstagram.deniedInstagramPermission) {
                                    break;
                                }
                                instgramAccessGrant = getHomeModel().getHomeForm().getInstagramAccessGrant();
                                if (instgramAccessGrant == null) {
                                    if (timoutCount > (5 * 5000)) {
                                        LoginWithInstagram.deniedInstagramPermission = true;
                                        instagarmMessage = "No response from instagram.";
                                        SSNHttpServer.getHttpServer().stop(0);
                                        break;
                                    } else {
                                        Thread.sleep(5000);
                                        timoutCount += 5000;
                                    }
                                } else {
                                    processFurther = true;
                                }
                            }
                        } catch (InterruptedException ex) {
                            logger.error(ex);
                        }
                    }
                    if (!LoginWithInstagram.deniedInstagramPermission) {
                        String urlString = String.format(
                                "https://api.instagram.com/v1/users/self/media/recent/?access_token=%s",
                                instgramAccessGrant.getAccessToken());
                        List<InstagramMedia> imageList = new ArrayList<>();
                        getMedia(urlString, imageList);
                        File searchFolder = new File(
                                SSNHelper.getSsnWorkSpaceDirPath() + File.separator + "Instagram Media");
                        if (!searchFolder.exists()) {
                            searchFolder.mkdirs();
                        } else {
                            //delete whole directory and create new one each time  
                            FileUtils.deleteDirectory(searchFolder);
                            searchFolder.mkdir();
                        }
                        for (InstagramMedia photo : imageList) {
                            String imageUrl = photo.getImageUrl();

                            URL url = new URL(imageUrl);
                            File file = new File(
                                    searchFolder.getAbsolutePath() + File.separator + photo.getId() + ".jpg");
                            if (!file.exists()) {
                                try {

                                    FileUtils.copyURLToFile(url, file);

                                } catch (Exception ex) {
                                    logger.error(ex);
                                }
                            }
                        }
                        this.getHomeModel().getHomeForm().setInstagramSearched(true);
                        File[] files = searchFolder.listFiles();
                        File folder = new File(SSNHelper.getSsnDefaultDirPath());
                        List<File> fileList = new ArrayList<File>();
                        for (File f : files) {
                            fileList.add(f);
                        }
                        Iterator<File> iterator = fileList.iterator();
                        while (iterator.hasNext()) {
                            File f = iterator.next();
                            boolean check = false;
                            try {
                                check = SSNDao.checkMediaExist(
                                        folder.getAbsolutePath() + File.separator + f.getName());
                            } catch (SQLException ex) {
                                ex.printStackTrace();
                                logger.error(ex);
                            }
                            if (check) {
                                //  iterator.remove();
                            }
                        }
                        File[] fileArray = new File[fileList.size()];
                        for (int j = 0; j < fileList.size(); j++) {
                            fileArray[j] = fileList.get(j);
                        }
                        String rootPath = SSNHelper.getSsnHiveDirPath();

                        this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                        this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionPath(null);
                        this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText("instagramMedia");

                        //this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                        // this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText(searchFolder.getAbsolutePath());
                        this.getHomeModel().getHomeForm().getFileNamesToBeDeleted().clear();
                        //this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);

                        SSNHelper.toggleDeleteAndShareImages(false, this.getHomeModel().getHomeForm());
                        SSNGalleryHelper contentPane = new SSNGalleryHelper(fileArray,
                                this.getHomeModel().getHomeForm());

                        contentPane.setBackground(SSNConstants.SSN_BLACK_BACKGROUND_COLOR);
                        this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().removeAll();
                        this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().removeAll();

                        this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().add(this.getHomeModel()
                                .getHomeForm().getScrollPane(contentPane, "Instagram Media"));
                        this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(this.getHomeModel()
                                .getHomeForm()
                                .getSortPanel("Date", false, SSNHelper.getAlbumNameFromPath(
                                        this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText())),
                                BorderLayout.NORTH);
                        this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(
                                this.getHomeModel().getHomeForm().getSsnHomeCenterPanel(), BorderLayout.CENTER);
                        this.getHomeModel().getSSNMediaFolderProperties(
                                this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText(),
                                fileArray);

                        renderLeftPanel();
                        this.getHomeModel().getHomeForm().revalidate();
                    } else {
                        SSNMessageDialogBox messageDialogBox = new SSNMessageDialogBox();
                        messageDialogBox.initDialogBoxUI(SSNDialogChoice.NOTIFICATION_DIALOG.getType(), "Alert",
                                "", instagarmMessage);
                        messageDialogBox.setFocusable(true);
                    }

                } catch (ProtocolException ex) {
                    // ex.printStackTrace();
                    logger.error(ex);
                    //             java.util.logging.Logger.getLogger(SSNUntaggedMediaController.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    //ex.printStackTrace();
                    logger.error(ex);
                    //         java.util.logging.Logger.getLogger(SSNUntaggedMediaController.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
            break;
        case "deviceMedia":
            untaggedMediaForm.dispose();
            this.getHomeModel().findTagUntaggedMedia();
            break;
        case "Cancel":
            untaggedMediaForm.dispose();
        }
        SSNHomeController.isUnTaggedOpen = false;
        untaggedMediaForm.dispose();
        this.getHomeModel().getHomeForm().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}

From source file:SimpleHelp.java

/**
 * Notification of a change relative to a hyperlink. From:
 * java.swing.event.HyperlinkListener/*from  w  ww . j  a v  a2s .  c om*/
 */
public void hyperlinkUpdate(HyperlinkEvent e) {
    if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
        URL target = e.getURL();
        // System.out.println("linkto: " + target);

        // Get the help panel's cursor and the wait cursor
        Cursor oldCursor = help.getCursor();
        Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        help.setCursor(waitCursor);

        // Now arrange for the page to get loaded asynchronously,
        // and the cursor to be set back to what it was.
        SwingUtilities.invokeLater(new PageLoader(target, oldCursor));
    }
}

From source file:com.mirth.connect.manager.ManagerController.java

public void startMirthWorker() {
    PlatformUI.MANAGER_DIALOG.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    ManagerController.getInstance().setEnabledOptions(false, false, false, false);

    SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
        private String errorMessage = null;

        public Void doInBackground() {
            errorMessage = startMirth();
            return null;
        }//w  w  w.  j av a  2  s .c o m

        public void done() {
            if (errorMessage == null) {
                PlatformUI.MANAGER_TRAY.alertInfo("The Mirth Connect Service was started successfully.");
            } else {
                PlatformUI.MANAGER_TRAY.alertError(errorMessage);
            }

            updateMirthServiceStatus();
            PlatformUI.MANAGER_DIALOG.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };

    worker.execute();
}

From source file:ste.travian.gui.WorldController.java

/**
 * Shows the map chart/* ww  w. j a v a  2 s  .com*/
 */
public void showMap() {
    mainWindow.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    executor.execute(new Runnable() {
        public void run() {
            try {
                load();
                mainWindow.showMap(getWorldPanel());
                //
                // do not move the line below, it needs to be here so
                // that all components will have the wait cursor set
                //
                mainWindow.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            } catch (Exception e) {
                mainWindow.setCursor(Cursor.getDefaultCursor());
                mainWindow.error("Error creating the map", e);
            }
        }
    });
}

From source file:nz.govt.natlib.ndha.manualdeposit.bulkupload.BulkUploadForm.java

public void setWaitCursor(final boolean isWaiting) {
    glass.setVisible(isWaiting);//from w ww . jav  a2s  . com
    if (isWaiting) {
        final Cursor hourglass = new Cursor(Cursor.WAIT_CURSOR);
        setCursor(hourglass);
    } else {
        final Cursor normal = new Cursor(Cursor.DEFAULT_CURSOR);
        setCursor(normal);
    }
}

From source file:edu.scripps.fl.pubchem.xmltool.gui.PubChemXMLCreatorGUI.java

public void actionPerformed(ActionEvent e) {
    try {/*ww  w .j a va2s  .c  om*/
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        if (e.getSource() == jbnFileTemplate) {
            gc.fileChooser(jtfFileTemplate, ".xml", "open");
            jtfFileTemplate.setEnabled(true);
        } else if (e.getSource() == jbnFileExcel) {
            gc.fileChooser(jtfFileExcel, ".xlsx", "open");
        } else if (e.getSource() == jbnRunCreator) {
            String stringTemplate = jtfFileTemplate.getText();
            InputStream fileTemplate;
            if (stringTemplate.equals(template) | stringTemplate.equals("")) {
                URL url = getClass().getClassLoader().getResource("blank.xml");
                fileTemplate = url.openStream();
            } else
                fileTemplate = new FileInputStream(jtfFileTemplate.getText());
            File fileExcel = new File(jtfFileExcel.getText());
            File fileOutput = File.createTempFile("pubchem", ".xml");
            fileOutput.deleteOnExit();
            PubChemAssay assay = new PubChemXMLCreatorController().createPubChemXML(fileTemplate, fileExcel,
                    fileOutput);
            String message = assay.getMessage();
            if (!message.equals("")) {
                int nn = JOptionPane.showOptionDialog(this,
                        notError + message + "\nWould you like to edit your Excel Workbook?", SwingGUI.APP_NAME,
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
                if (nn == JOptionPane.YES_OPTION) {
                    log.info("Opening Excel Workbook with Desktop: " + fileExcel);
                    Desktop.getDesktop().open(fileExcel);
                } else {
                    log.info("Opening XML file: " + fileOutput);
                    Desktop.getDesktop().open(fileOutput);
                }
            } else {
                log.info("Opening XML file: " + fileOutput);
                Desktop.getDesktop().open(fileOutput);
            }
        } else if (e.getSource() == jbnReportCreator) {
            File fileExcel = new File(jtfFileExcel.getText());
            File filePDFOutput = File.createTempFile("PubChem_PDF_Report", ".pdf");
            File fileWordOutput = File.createTempFile("PubChem_Word_Report", ".docx");
            filePDFOutput.deleteOnExit();
            fileWordOutput.deleteOnExit();
            ArrayList<PubChemAssay> assay = new ReportController().createReport(pcDep, fileExcel, filePDFOutput,
                    fileWordOutput, isInternal);
            String message = null;
            for (PubChemAssay xx : assay) {
                message = xx.getMessage();
                if (!message.equals("")) {
                    int nn = JOptionPane.showOptionDialog(this,
                            notError + message + "\nWould you like to edit your Excel Workbook?",
                            SwingGUI.APP_NAME, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null,
                            null, null);
                    if (nn == JOptionPane.YES_OPTION) {
                        log.info("Opening Excel Workbook with Desktop: " + fileExcel);
                        Desktop.getDesktop().open(fileExcel);
                    } else {
                        gc.openPDF(isInternal, filePDFOutput, this);
                        Desktop.getDesktop().open(fileWordOutput);
                    }
                } else {
                    gc.openPDF(isInternal, filePDFOutput, this);
                    Desktop.getDesktop().open(fileWordOutput);
                }
            }
        }
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    } catch (Throwable throwable) {
        SwingGUI.handleError(this, throwable);
    }
}

From source file:FTPApp.java

protected boolean connect() {
    monitorTextArea.setText("");
    setButtonStates(false);/*www . j  a v  a  2s.  c  o  m*/
    closeButton.setText("Cancel");
    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    String user = userNameTextField.getText();
    if (user.length() == 0) {
        setMessage("Please enter user name");
        setButtonStates(true);
        return false;
    }
    String password = new String(passwordTextField.getPassword());
    String sUrl = urlTextField.getText();
    if (sUrl.length() == 0) {
        setMessage("Please enter URL");
        setButtonStates(true);
        return false;
    }
    localFileName = fileTextField.getText();

    // Parse URL
    int index = sUrl.indexOf("//");
    if (index >= 0)
        sUrl = sUrl.substring(index + 2);

    index = sUrl.indexOf("/");
    String host = sUrl.substring(0, index);
    sUrl = sUrl.substring(index + 1);

    String sDir = "";
    index = sUrl.lastIndexOf("/");
    if (index >= 0) {
        sDir = sUrl.substring(0, index);
        sUrl = sUrl.substring(index + 1);
    }
    remoteFileName = sUrl;

    try {
        setMessage("Connecting to host " + host);
        ftpClient = new FtpClient(host);
        ftpClient.login(user, password);
        setMessage("User " + user + " login OK");
        setMessage(ftpClient.welcomeMsg);
        ftpClient.cd(sDir);
        setMessage("Directory: " + sDir);
        ftpClient.binary();
        return true;
    } catch (Exception ex) {
        setMessage("Error: " + ex.toString());
        setButtonStates(true);
        return false;
    }
}

From source file:Interfaces.EstadisticaGui.java

private void dibujarGraficos() {
    this.setCursor(new Cursor(Cursor.WAIT_CURSOR));
    abrirBase();//from   w  ww .j  ava  2s.com
    panelGrande.removeAll();
    Integer anio = (Integer) spinnerAnio.getValue();
    // Creamos y rellenamos el modelo de datos
    LazyList<Categoria> categorias = Categoria.findAll();
    Iterator<Categoria> it = categorias.iterator();
    while (it.hasNext()) {
        Categoria c = it.next();
        if (!c.getString("nombre").equals("COMPRAS")) {
            DefaultCategoryDataset dataset = new DefaultCategoryDataset();
            float[] ingreso = calcularIngreso(c.getInteger("id"), anio);
            dataset.setValue(ingreso[0], c.getString("nombre"), "Enero");
            dataset.setValue(ingreso[1], c.getString("nombre"), "Febrero");
            dataset.setValue(ingreso[2], c.getString("nombre"), "Marzo");
            dataset.setValue(ingreso[3], c.getString("nombre"), "Abril");
            dataset.setValue(ingreso[4], c.getString("nombre"), "Mayo");
            dataset.setValue(ingreso[5], c.getString("nombre"), "Junio");
            dataset.setValue(ingreso[6], c.getString("nombre"), "Julio");
            dataset.setValue(ingreso[7], c.getString("nombre"), "Agosto");
            dataset.setValue(ingreso[8], c.getString("nombre"), "Septiembre");
            dataset.setValue(ingreso[9], c.getString("nombre"), "Octubre");
            dataset.setValue(ingreso[10], c.getString("nombre"), "Noviembre");
            dataset.setValue(ingreso[11], c.getString("nombre"), "Diciembre");
            JFreeChart chart = ChartFactory.createBarChart3D(
                    "Ingresos en la categoria " + c.getString("nombre"), "mes", "Pesos", dataset,
                    PlotOrientation.VERTICAL, true, true, false);
            // Creacin del panel con el grfico
            ChartPanel panelGrafico = new ChartPanel(chart);
            CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();
            org.jfree.chart.axis.CategoryAxis categoryaxis = categoryplot.getDomainAxis();
            categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.2D));
            CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
            categoryitemrenderer.setBaseItemLabelsVisible(true);
            JPanel panelParaGrafico = new JPanel();
            panelParaGrafico.setLayout(new BorderLayout());
            panelGrande.add(panelParaGrafico);
            panelParaGrafico.add(panelGrafico);
        }
    }
    this.pack();
    this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

}

From source file:EditorPaneExample11.java

public EditorPaneExample11() {
    super("JEditorPane Example 11");

    pane = new JEditorPane();
    pane.setEditable(false); // Read-only
    getContentPane().add(new JScrollPane(pane), "Center");

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;/*from w w  w. j a v a2  s .  c o  m*/
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);
    c.gridy = 3;
    panel.add(new JLabel(LOAD_TIME), c);

    c.gridy = 4;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    onlineLoad = new JCheckBox("Online Load");
    panel.add(onlineLoad, c);
    onlineLoad.setSelected(true);
    onlineLoad.setForeground(typeLabel.getForeground());

    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;

    urlCombo = new JComboBox();
    panel.add(urlCombo, c);
    urlCombo.setEditable(true);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);
    timeLabel = new JLabel("");
    c.gridy = 3;
    panel.add(timeLabel, c);

    getContentPane().add(panel, "South");

    // Allocate the empty tree model
    DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty");
    emptyModel = new DefaultTreeModel(emptyRootNode);

    // Create and place the heading tree
    tree = new JTree(emptyModel);
    tree.setPreferredSize(new Dimension(200, 200));
    getContentPane().add(new JScrollPane(tree), "East");

    // Change page based on combo selection
    urlCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (populatingCombo == true) {
                return;
            }
            Object selection = urlCombo.getSelectedItem();
            try {
                // Check if the new page and the old
                // page are the same.
                URL url;
                if (selection instanceof URL) {
                    url = (URL) selection;
                } else {
                    url = new URL((String) selection);
                }

                URL loadedURL = pane.getPage();
                if (loadedURL != null && loadedURL.sameFile(url)) {
                    return;
                }

                // Try to display the page
                urlCombo.setEnabled(false); // Disable input
                urlCombo.paintImmediately(0, 0, urlCombo.getSize().width, urlCombo.getSize().height);
                setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                // Busy cursor
                loadingState.setText("Loading...");
                loadingState.paintImmediately(0, 0, loadingState.getSize().width,
                        loadingState.getSize().height);
                loadedType.setText("");
                loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height);

                timeLabel.setText("");
                timeLabel.paintImmediately(0, 0, timeLabel.getSize().width, timeLabel.getSize().height);

                // Display an empty tree while loading
                tree.setModel(emptyModel);
                tree.paintImmediately(0, 0, tree.getSize().width, tree.getSize().height);

                startTime = System.currentTimeMillis();

                // Choose the loading method
                if (onlineLoad.isSelected()) {
                    // Usual load via setPage
                    pane.setPage(url);
                    loadedType.setText(pane.getContentType());
                } else {
                    pane.setContentType("text/html");
                    loadedType.setText(pane.getContentType());
                    if (loader == null) {
                        loader = new HTMLDocumentLoader();
                    }
                    HTMLDocument doc = loader.loadDocument(url);
                    loadComplete();
                    pane.setDocument(doc);
                    displayLoadTime();
                    populateCombo(findLinks(doc, null));
                    TreeNode node = buildHeadingTree(doc);
                    tree.setModel(new DefaultTreeModel(node));
                    enableInput();
                }
            } catch (Exception e) {
                System.out.println(e);
                JOptionPane.showMessageDialog(pane,
                        new String[] { "Unable to open file", selection.toString() }, "File Open Error",
                        JOptionPane.ERROR_MESSAGE);
                loadingState.setText("Failed");
                enableInput();
            }
        }
    });

    // Listen for page load to complete
    pane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("page")) {
                loadComplete();
                displayLoadTime();
                populateCombo(findLinks(pane.getDocument(), null));
                TreeNode node = buildHeadingTree(pane.getDocument());
                tree.setModel(new DefaultTreeModel(node));
                enableInput();
            }
        }
    });

    // Listener for tree selection
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getNewLeadSelectionPath();
            if (path != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object userObject = node.getUserObject();
                if (userObject instanceof Heading) {
                    Heading heading = (Heading) userObject;
                    try {
                        Rectangle textRect = pane.modelToView(heading.getOffset());
                        textRect.y += 3 * textRect.height;
                        pane.scrollRectToVisible(textRect);
                    } catch (BadLocationException e) {
                    }
                }
            }
        }
    });
}

From source file:org.tinymediamanager.ui.dialogs.RegisterDonatorVersionDialog.java

public RegisterDonatorVersionDialog() {
    super(BUNDLE.getString("tmm.registerdonator"), "registerDonator"); //$NON-NLS-1$
    setBounds(166, 5, 400, 300);//  w w w  .  ja  v a2 s .c  om
    boolean isDonator = Globals.isDonator();
    Properties props = null;
    if (isDonator) {
        props = License.decrypt();
    }

    {
        JPanel panelContent = new JPanel();
        getContentPane().add(panelContent, BorderLayout.CENTER);
        panelContent.setLayout(new FormLayout(
                new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                        FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("250px:grow"),
                        FormFactory.RELATED_GAP_COLSPEC, },
                new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                        FormFactory.PARAGRAPH_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                        FormFactory.UNRELATED_GAP_ROWSPEC, }));

        {
            JTextArea textArea = new JTextArea();
            textArea.setOpaque(false);
            textArea.setLineWrap(true);
            textArea.setWrapStyleWord(true);
            textArea.setEditable(false);
            panelContent.add(textArea, "2, 2, 3, 1, default, center");
            if (isDonator) {
                textArea.setText(BUNDLE.getString("tmm.registerdonator.thanks")); //$NON-NLS-1$
            } else {
                textArea.setText(BUNDLE.getString("tmm.registerdonator.hint")); //$NON-NLS-1$
            }
        }
        {
            JLabel lblName = new JLabel(BUNDLE.getString("tmm.registerdonator.name")); //$NON-NLS-1$
            panelContent.add(lblName, "2, 4, right, default");
            tfName = new JTextField("");
            lblName.setLabelFor(tfName);
            panelContent.add(tfName, "4, 4, fill, default");
            tfName.setColumns(10);
            if (isDonator) {
                tfName.setText(props.getProperty("user"));
                tfName.setEnabled(false);
            }
        }
        {
            JLabel lblEmailAddress = new JLabel(BUNDLE.getString("tmm.registerdonator.email")); //$NON-NLS-1$
            panelContent.add(lblEmailAddress, "2, 6, right, default");
            tfEmailAddress = new JTextField("");
            lblEmailAddress.setLabelFor(tfEmailAddress);
            panelContent.add(tfEmailAddress, "4, 6, fill, default");
            tfEmailAddress.setColumns(10);
            if (isDonator) {
                tfEmailAddress.setText(props.getProperty("email"));
                tfEmailAddress.setEnabled(false);
            }
        }
    }
    {
        JPanel panelButtons = new JPanel();
        panelButtons.setBorder(new EmptyBorder(4, 4, 4, 4));
        getContentPane().add(panelButtons, BorderLayout.SOUTH);
        EqualsLayout layout = new EqualsLayout(5);
        layout.setMinWidth(100);
        panelButtons.setLayout(layout);
        {
            JButton btnRegister = new JButton(BUNDLE.getString("Button.register")); //$NON-NLS-1$
            btnRegister.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    try {
                        LOGGER.debug("registering for donator version: ", tfEmailAddress.getText());
                        Properties p = new Properties();
                        p.setProperty("user", tfName.getText());
                        p.setProperty("email", tfEmailAddress.getText());
                        p.setProperty("generated", String.valueOf(new Date().getTime()));
                        p.setProperty("uuid", FileUtils.readFileToString(new File("tmm.uuid")));

                        // get encrypted string and write tmm.lic
                        if (License.encrypt(p) && License.isValid()) {
                            JOptionPane.showMessageDialog(RegisterDonatorVersionDialog.this,
                                    BUNDLE.getString("tmm.registerdonator.success")); //$NON-NLS-1$
                            setVisible(false);
                        } else {
                            JOptionPane.showMessageDialog(RegisterDonatorVersionDialog.this,
                                    BUNDLE.getString("tmm.registerdonator.error")); //$NON-NLS-1$
                        }
                    } catch (Exception ex) {
                        LOGGER.error("Error registering donator version: " + ex.getMessage());
                    }
                    setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
            });
            if (isDonator) {
                btnRegister.setEnabled(false);
            }
            panelButtons.add(btnRegister);
        }
        {
            JButton btnClose = new JButton(BUNDLE.getString("Button.close")); //$NON-NLS-1$
            btnClose.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent arg0) {
                    setVisible(false);
                }
            });
            panelButtons.add(btnClose);
        }
    }
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            tfName.requestFocus();
        }
    });
}