Example usage for java.awt.event MouseEvent getSource

List of usage examples for java.awt.event MouseEvent getSource

Introduction

In this page you can find the example usage for java.awt.event MouseEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:org.rdv.ui.TimeSlider.java

/**
 * Called whn the mouse is released. Used to tell when the value control is
 * being adjusted.//from w w w  .  ja v a 2 s  .  c  o  m
 * 
 * @param me  the mouse event that triggered this
 */
public void mouseReleased(MouseEvent me) {
    if (me.getSource() == valueButton) {
        isAdjusting = false;
    }
}

From source file:HelloUniverse.java

public void mouseDragged(MouseEvent e) {
    Point pos = e.getPoint();/*from w  w  w . ja  va 2 s .c  o  m*/

    int diffX = pos.x - oldMousePos.x;
    int diffY = pos.y - oldMousePos.y;

    switch (mode) {
    case NONE:
        break;
    case SLIDE_Y:
        // Overwrite the old pip
        drawYPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), yAngle);
        if (diffX < 0)
            yAngle -= angleStep;
        else if (diffX > 0)
            yAngle += angleStep;

        yAngle = constrainAngle(yAngle);

        // Draw the new Pip
        drawYPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), yAngle);
        oldMousePos = pos;
        break;
    case SLIDE_X:
        // Overwrite the old pip
        drawXPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), xAngle);
        if (diffY < 0)
            xAngle -= angleStep;
        else if (diffY > 0)
            xAngle += angleStep;

        xAngle = constrainAngle(xAngle);

        // Draw the new Pip
        drawXPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), xAngle);
        oldMousePos = pos;
        break;
    case SLIDE_Z:
        drawZPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), zAngle);

        if (diffX < 0)
            zAngle -= angleStep;
        else if (diffX > 0)
            zAngle += angleStep;

        zAngle = constrainAngle(zAngle);
        drawZPip((Graphics2D) ((Canvas) e.getSource()).getGraphics(), zAngle);
        oldMousePos = pos;
        break;
    default:
        throw (new RuntimeException("Internal Error"));
    }
}

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 ww  w .  ja  v  a 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:org.rdv.ui.TimeSlider.java

/**
 * Called when the mouse is pressed. Used to tell when the value control is
 * being adjusted.//from  w  w w  .  j  a  va2 s. co  m
 * 
 * @param me  the mouse event that triggered this
 */
public void mousePressed(MouseEvent me) {
    clickStart = me.getX();

    if (me.getSource() == valueButton) {
        isAdjusting = true;
    }
}

From source file:org.rdv.ui.TimeSlider.java

/**
 * Called when the mouse is clicked. Used to set the time value when there is
 * a click on the time slider.//from  ww w.j  a  v  a  2 s.com
 * 
 * @param me  the mouse event that triggered this
 */
public void mouseClicked(MouseEvent me) {
    double time;
    if (me.getSource() == this) {
        time = getTimeFromX(me.getX());
    } else if (me.getSource() == valueButton) {
        time = getTimeFromX(valueButton.getX() + me.getX());
    } else {
        return;
    }

    if (me.getButton() == MouseEvent.BUTTON1) {
        setValue(time);
    } else if (me.getButton() == MouseEvent.BUTTON3) {
        EventMarker eventMarker = getMarkerClosestToTime(time);
        if (eventMarker != null) {
            double markerTime = Double.parseDouble(eventMarker.getProperty("timestamp"));
            setValue(markerTime);
        }
    }
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java

/**
 * Helper method to create the tool bar hosting the management items.
 * /*w w  w. ja v a 2  s  . co  m*/
 * @return See above.
 */
private JComponent createManagementBar() {
    bar = new JToolBar();
    bar.setFloatable(false);
    bar.setRollover(true);
    bar.setBorder(null);
    JToggleButton button = new JToggleButton(controller.getAction(TreeViewerControl.INSPECTOR));
    button.setSelected(true);
    bar.add(button);

    button = new JToggleButton(controller.getAction(TreeViewerControl.METADATA));
    button.setSelected(true);
    bar.add(button);

    JButton b = new JButton(controller.getAction(TreeViewerControl.BROWSE));
    UIUtilities.unifiedButtonLookAndFeel(b);
    bar.add(b);
    switch (TreeViewerAgent.runAsPlugin()) {
    case TreeViewer.IMAGE_J:
        b = UIUtilities.formatButtonFromAction(controller.getAction(TreeViewerControl.VIEW));
        UIUtilities.unifiedButtonLookAndFeel(b);
        b.addMouseListener(new MouseAdapter() {

            /**
             * Displays the menu when the user releases the mouse.
             * @see MouseListener#mouseReleased(MouseEvent)
             */
            public void mouseReleased(MouseEvent e) {
                controller.showMenu(TreeViewer.VIEW_MENU, (JComponent) e.getSource(), e.getPoint());
            }
        });
        bar.add(b);
        break;
    default:
        b = new JButton(controller.getAction(TreeViewerControl.VIEW));
        UIUtilities.unifiedButtonLookAndFeel(b);
        bar.add(b);
    }

    bar.add(new JSeparator(JSeparator.VERTICAL));
    //Now register the agent if any
    TaskBar tb = TreeViewerAgent.getRegistry().getTaskBar();
    List<JComponent> l = tb.getToolBarEntries(TaskBar.AGENTS);
    if (l != null) {
        Iterator<JComponent> i = l.iterator();
        JComponent comp;
        while (i.hasNext()) {
            comp = i.next();
            UIUtilities.unifiedButtonLookAndFeel(comp);
            bar.add(comp);
        }
        bar.add(new JSeparator(JSeparator.VERTICAL));
    }
    fullScreen = new JToggleButton(controller.getAction(TreeViewerControl.FULLSCREEN));
    fullScreen.setSelected(model.isFullScreen());
    //bar.add(fullScreen);
    if (TreeViewerAgent.isAdministrator()) {
        b = new JButton(controller.getAction(TreeViewerControl.UPLOAD_SCRIPT));
        UIUtilities.unifiedButtonLookAndFeel(b);
        bar.add(b);
    }
    TreeViewerAction a = controller.getAction(TreeViewerControl.AVAILABLE_SCRIPTS);
    b = new JButton(a);
    Icon icon = b.getIcon();
    Dimension d = new Dimension(UIUtilities.DEFAULT_ICON_WIDTH, UIUtilities.DEFAULT_ICON_HEIGHT);
    if (icon != null)
        d = new Dimension(icon.getIconWidth(), icon.getIconHeight());
    busyLabel = new JXBusyLabel(d);
    busyLabel.setVisible(true);
    b.addMouseListener((RunScriptAction) a);
    UIUtilities.unifiedButtonLookAndFeel(b);
    scriptButton = b;
    bar.add(b);
    index = bar.getComponentCount() - 1;

    bar.add(new JSeparator(JSeparator.VERTICAL));

    MouseAdapter adapter = new MouseAdapter() {

        /**
         * Shows the menu corresponding to the display mode.
         */
        public void mousePressed(MouseEvent me) {
            createGroupsAndUsersMenu((Component) me.getSource(), me.getPoint());
        }
    };

    a = controller.getAction(TreeViewerControl.SWITCH_USER);
    IconManager icons = IconManager.getInstance();
    menuButton = new JButton(icons.getIcon(IconManager.FILTER_MENU));
    menuButton.setVisible(true);
    menuButton.setText(GROUP_DISPLAY_TEXT);
    menuButton.setHorizontalTextPosition(SwingConstants.LEFT);
    menuButton.addMouseListener(adapter);
    bar.add(menuButton);
    setPermissions();
    return bar;
}

From source file:de.tor.tribes.ui.views.DSWorkbenchDoItYourselfAttackPlaner.java

private void fireAdeptEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireAdeptEvent
    int[] rows = jAttackTable.getSelectedRows();
    if (rows == null || rows.length == 0) {
        showInfo("Keine Angriffe ausgewhlt");
        return;/* w w w.ja va2s .  c  o m*/
    }
    if (evt.getSource() == jAdeptTimeButton) {
        Date newArrive = jNewArriveSpinner.getSelectedDate();
        if (newArrive.getTime() < System.currentTimeMillis()) {
            showError("Ankunftszeit darf nicht in der Vergangenheit liegen");
            return;
        }
        for (int r = rows.length - 1; r >= 0; r--) {
            int row = jAttackTable.convertRowIndexToModel(rows[r]);
            Attack a = (Attack) AttackManager.getSingleton().getDoItYourselfAttacks().get(row);
            a.setArriveTime(newArrive);
        }

    } else if (evt.getSource() == jAdeptUnitButton) {
        UnitHolder newUnit = (UnitHolder) jUnitComboBox.getSelectedItem();
        if (newUnit == null) {
            showError("Keine Einheit ausgewhlt");
            return;
        }

        for (int r = rows.length - 1; r >= 0; r--) {
            int row = jAttackTable.convertRowIndexToModel(rows[r]);
            Attack a = (Attack) AttackManager.getSingleton().getDoItYourselfAttacks().get(row);
            a.setUnit(newUnit);
        }
    } else if (evt.getSource() == jAdeptTypeButton) {
        StandardAttack newType = (StandardAttack) jAttackTypeComboBox.getSelectedItem();
        if (newType == null) {
            showError("Kein Angriffstyp ausgewhlt");
            return;
        }

        for (int r = rows.length - 1; r >= 0; r--) {
            int row = jAttackTable.convertRowIndexToModel(rows[r]);
            Attack a = (Attack) AttackManager.getSingleton().getDoItYourselfAttacks().get(row);
            a.setType(newType.getIcon());
            a.setTroopsByType();
        }
    }
    AttackManager.getSingleton().revalidate(true);
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * MouseListener used to select items from the list of Rule descriptions, allows for deletion of Rules
 * //from  w  w  w.j a  va  2s. c  om
 * @return
 */
private MouseListener getRuleListMouseAdapter() {

    return new MouseListener() {

        private JList list;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                list = ((JList) e.getSource());
                list.setSelectedIndex(getRow(e.getPoint()));

                JPopupMenu menu = new JPopupMenu();
                menu.add(new RemoveRule(list));

                Point pt = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), list);
                menu.show(list, pt.x, pt.y);
            }
        }

        private int getRow(Point point) {
            return list.locationToIndex(point);
        }

        public void mouseClicked(MouseEvent arg0) {

        }

        public void mouseEntered(MouseEvent arg0) {

        }

        public void mouseExited(MouseEvent arg0) {

        }

        public void mouseReleased(MouseEvent arg0) {

        }
    };
}

From source file:DragPictureDemo2.java

public void mouseDragged(MouseEvent e) {
    //Don't bother to drag if the component displays no image.
    if (image == null)
        return;//from  w  w  w. jav  a2 s .com

    if (firstMouseEvent != null) {
        e.consume();

        //If they are holding down the control key, COPY rather than MOVE
        int ctrlMask = InputEvent.CTRL_DOWN_MASK;
        int action = ((e.getModifiersEx() & ctrlMask) == ctrlMask) ? TransferHandler.COPY
                : TransferHandler.MOVE;

        int dx = Math.abs(e.getX() - firstMouseEvent.getX());
        int dy = Math.abs(e.getY() - firstMouseEvent.getY());
        //Arbitrarily define a 5-pixel shift as the
        //official beginning of a drag.
        if (dx > 5 || dy > 5) {
            //This is a drag, not a click.
            JComponent c = (JComponent) e.getSource();
            TransferHandler handler = c.getTransferHandler();
            //Tell the transfer handler to initiate the drag.
            handler.exportAsDrag(c, firstMouseEvent, action);
            firstMouseEvent = null;
        }
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.FormPane.java

/**
 * Creates all the UI form the Form. //from   w ww  . j av  a  2s . c  o  m
 */
protected void buildUI() {
    headers.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems());
    Collections.sort(headers);

    MouseAdapter clickable = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            selectControl(e.getSource());
        }

        @Override
        public void mouseClicked(MouseEvent e) {
            selectedInputPanel = getInputPanel(e.getSource());
            controlPropsBtn.setEnabled(true);

            if (controlPropsDlg != null) {
                controlPropsDlg.setControl(selectedInputPanel);
            }

            if (e.getClickCount() == 2 && (controlPropsDlg == null || !controlPropsDlg.isVisible())) {
                UsageTracker.incrUsageCount("WB.FormPropsTool");
                showControlProps();
            }

        }
    };

    Point topLeftPnt = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);

    final int LAYOUT_SPACING = 4;
    short maxY = 0;
    Vector<InputPanel> delayedLayout = new Vector<InputPanel>();
    int maxWidthOffset = 0;
    for (WorkbenchTemplateMappingItem wbtmi : headers) {
        // Create the InputPanel and make it draggable
        InputPanel panel = new InputPanel(wbtmi, wbtmi.getCaption(), createUIComp(wbtmi), this, clickable);

        Dimension size = panel.getPreferredSize();
        panel.setSize(size);
        panel.setPreferredSize(size);

        // Finds the largest label
        maxWidthOffset = Math.max(panel.getTextFieldOffset(), maxWidthOffset);

        int x = wbtmi.getXCoord();
        int y = wbtmi.getYCoord();
        if (y < topLeftPnt.y || (y == topLeftPnt.y && x < topLeftPnt.x)) {
            firstComp = panel.getComp();
            topLeftPnt.setLocation(x, y);
        }

        // Add it to the Form (drag canvas)
        uiComps.add(panel);
        add(panel);

        // NOTE: that the constructor sets the x,y storage from WorkbenchTemplateMappingItem object
        // so the ones with XCoord and YCoord set do not need to be positioned
        if (wbtmi.getXCoord() == null || wbtmi.getYCoord() == null || wbtmi.getXCoord() == -1
                || wbtmi.getYCoord() == -1) {
            delayedLayout.add(panel); // remember this for later once we know the Max Y

        } else {
            maxY = (short) Math.max(wbtmi.getYCoord() + size.height, maxY);
        }
    }

    // Now align the control by their text fields and skips the ones that have actual positions defined.
    // NOTE: We set the X,Y into the Mapping so that each item knows where it is, then if the user
    // drags and drop anything or save the template everyone knows where they are suppose to be
    // 
    int inx = 0;
    int maxX = 0;
    int y = maxY + LAYOUT_SPACING;
    for (InputPanel panel : uiComps) {
        WorkbenchTemplateMappingItem wbtmi = headers.get(inx);
        if (delayedLayout.contains(panel)) {
            int x = maxWidthOffset - panel.getTextFieldOffset();
            panel.setLocation(x, y);
            wbtmi.setXCoord((short) x);
            wbtmi.setYCoord((short) y);

            Dimension size = panel.getPreferredSize();
            y += size.height + LAYOUT_SPACING;

        }
        Rectangle r = panel.getBounds();
        maxX = Math.max(maxX, r.x + r.width);
        inx++;
    }

    initialSize = new Dimension(maxX, y);

    controlPropsBtn = createIconBtn("ControlEdit", IconManager.IconSize.NonStd, "WB_EDIT_CONTROL", false,
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    UsageTracker.getUsageCount("WBFormPropsTool");
                    showControlProps();
                }
            });

    addArrowTraversalKeys();
}