Example usage for java.beans PropertyChangeEvent getNewValue

List of usage examples for java.beans PropertyChangeEvent getNewValue

Introduction

In this page you can find the example usage for java.beans PropertyChangeEvent getNewValue.

Prototype

public Object getNewValue() 

Source Link

Document

Gets the new value for the property, expressed as an Object.

Usage

From source file:org.oyrm.kobo.postproc.KoboBatchTranscriber.java

@Override
public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getSource().equals(srd)) {
        if (evt.getPropertyName() == Constants.CHANGEPROP_NAME_NCOMPLETED) {
            this.setnTranscribed((Integer) evt.getNewValue());
        } else if (evt.getPropertyName() == Constants.CHANGEPROP_NAME_PROGRESS) {
            this.setSubProgress((Integer) evt.getNewValue());
        } else if (evt.getPropertyName() == Constants.CHANGEPROP_NAME_STATE) {
            this.getPropertyChangeSupport().firePropertyChange(evt);
        }/*from w  w w .  j  a  va 2  s.  c om*/
    }
}

From source file:MainWindow.java

public MainWindow() {
    // Login Routine
    loginDialog = new LoginDialog();
    // loginDialog.nameField.setText("cornelius.preidel@googlemail.com");
    // loginDialog.passwordField.setText("germany");
    loginDialog.setSize(400, 150);//from  www  .ja  v a 2 s  .  c  om
    loginDialog.setModal(true);
    loginDialog.setLocationRelativeTo(null);
    loginDialog.setVisible(true);

    // Get the connected ApiCore
    core = loginDialog._core;

    // Init the UI
    mainFrame = new JFrame("MainApplication");
    mainFrame.setSize(500, 500);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setLayout(new GridLayout(5, 1));

    // WebProjectsList webprojectlist = new WebProjectsList(core);
    // mainFrame.add(webprojectlist);

    // Create the APIS
    Teams teamsAPI = new Teams(core);
    final Projects projectsAPI = new Projects(core);
    final Divisions divisionsAPI = new Divisions(core);
    final Attachments attachmentAPI = new Attachments(core);
    final Issues issueAPI = new Issues(core);

    // TEAMS List
    TeamsList teamList = new TeamsList();
    teamList.setTeams(teamsAPI.GetTeams());
    mainFrame.add(teamList);

    // PROJECTS  List
    projectsList = new ProjectsList();
    mainFrame.add(projectsList);

    // DIVISIONS List
    divisionsList = new DivisionsList();
    // mainFrame.add(divisionsList);

    // DIVISIONS Table
    divisionsTable = new DivisionsTable(core);
    mainFrame.add(divisionsTable);

    // Attachments
    attachmentsList = new AttachmentsList();
    mainFrame.add(attachmentsList);

    // Attachments
    issuesList = new IssuesList();
    mainFrame.add(issuesList);

    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            String property = propertyChangeEvent.getPropertyName();
            if ("selectedTeam".equals(property)) {
                DtoTeam selectedTeam = (DtoTeam) propertyChangeEvent.getNewValue();

                // Set the global slug
                core.currentTeam = selectedTeam;
                projectsList.setProjects(projectsAPI.GetProjects());
            } else if ("selectedProject".equals(property)) {
                DtoProject selectedProject = (DtoProject) propertyChangeEvent.getNewValue();
                // Divisions
                divisionsList.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId()));
                divisionsTable.setDivisions(divisionsAPI.GetDivisions(selectedProject.GetId()));
                // Attachments
                attachmentsList.setAttachments(attachmentAPI.GetAttachments(selectedProject.GetId()));
                // Issues
                issuesList.setIssues(issueAPI.GetIssues(selectedProject.GetId()));
            } else if ("selectedDivision".equals(property)) {
                DtoDivision selectedDivision = (DtoDivision) propertyChangeEvent.getNewValue();
                // What to do with the division?
            } else if ("selectedIssue".equals(property)) {
                DtoIssue selectedDivision = (DtoIssue) propertyChangeEvent.getNewValue();
                // What to do with the division?
            } else {
                if ("selectedAttachment".equals(property)) {
                    DtoAttachment selectedAttachment = (DtoAttachment) propertyChangeEvent.getNewValue();
                    InputStream stream = attachmentAPI.DownloadAttachment(selectedAttachment.GetId());

                    try {
                        byte[] bytes = IOUtils.toByteArray(stream);
                        JFileChooser chooser = new JFileChooser();
                        int returnVal = chooser.showSaveDialog(chooser);
                        File file = chooser.getSelectedFile();

                        FileOutputStream fos = new FileOutputStream(file);
                        fos.write(bytes);
                        fos.flush();
                        fos.close();
                    } catch (IOException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            }
        }
    };

    // Add Listener
    teamList.addPropertyChangeListener(propertyChangeListener);
    projectsList.addPropertyChangeListener(propertyChangeListener);
    divisionsList.addPropertyChangeListener(propertyChangeListener);
    divisionsTable.addPropertyChangeListener(propertyChangeListener);
    attachmentsList.addPropertyChangeListener(propertyChangeListener);
    issuesList.addPropertyChangeListener(propertyChangeListener);
}

From source file:org.zaproxy.zap.extension.exportreport.export.ExportReport.java

public void generateReport(ViewDelegate view, ExtensionExportReport extension) {
    FileList list = extension.getFileList();
    try {//from www  . j  a va2 s. c om
        if (fc == null) {
            fc = generateWriteableFileChooser(list);
            fc.addPropertyChangeListener(WritableFileChooser.FILE_FILTER_CHANGED_PROPERTY,
                    new PropertyChangeListener() {
                        @Override
                        public void propertyChange(PropertyChangeEvent evt) {
                            ReportFilter filter = (ReportFilter) evt.getNewValue();
                            String extension = (filter.getExtensionByDescription(filter.getDescription())
                                    .length() == 0 ? ""
                                            : "." + filter.getExtensionByDescription(filter.getDescription()));
                            fc.setSelectedFile(new File(extension));
                        }
                    });
        }

        int rc = fc.showSaveDialog(View.getSingleton().getMainFrame());

        boolean valid = false;
        String fileExtension = "";
        while (rc == WritableFileChooser.APPROVE_OPTION && !valid) {
            fileExtension = list.compareExtension(fc.getSelectedFile().getName());
            if (fileExtension.length() > 0) {
                valid = true;
            }
            if (!valid) {
                // Determine in v2.0 which method to use for display of
                // error messages based on feedback.
                // JOptionPane.showMessageDialog(null,
                // "The file " + fc.getSelectedFile() + " is not a valid
                // destination file.", "Open Error",
                // JOptionPane.ERROR_MESSAGE);
                view.showWarningDialog(Constant.messages
                        .getString("exportreport.message.error.file.destination", fc.getSelectedFile()));
                rc = fc.showSaveDialog(View.getSingleton().getMainFrame());
            }
        }

        if (rc == WritableFileChooser.APPROVE_OPTION && valid) {
            task = new Task(view, extension, fileExtension, fc.getSelectedFile());
            task.execute();
        }

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        view.showWarningDialog(Constant.messages.getString("exportreport.message.error.exception"));
    }
}

From source file:org.eclipse.php.composer.api.entities.AbstractJsonObject.java

private void installListener(final String property, JsonEntity entity) {
    if (entity != null) {
        listeners.put(property, new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                firePropertyChange(property + "." + evt.getPropertyName(), evt.getOldValue(), //$NON-NLS-1$
                        evt.getNewValue());
            }//from   www.  j  ava 2 s.  co m
        });

        entity.addPropertyChangeListener(listeners.get(property));
    }
}

From source file:org.opencastproject.staticfiles.endpoint.StaticFileRestService.java

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)/*  w w w  . j  a  v a  2s .  c o  m*/
@Path("")
@RestQuery(name = "postStaticFile", description = "Post a new static resource", bodyParameter = @RestParameter(description = "The static resource file", isRequired = true, name = "BODY", type = RestParameter.Type.FILE), reponses = {
        @RestResponse(description = "Returns the id of the uploaded static resource", responseCode = HttpServletResponse.SC_CREATED),
        @RestResponse(description = "No filename or file to upload found", responseCode = HttpServletResponse.SC_BAD_REQUEST),
        @RestResponse(description = "The upload size is too big", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "")
public Response postStaticFile(@Context HttpServletRequest request) {
    if (maxUploadSize > 0 && request.getContentLength() > maxUploadSize) {
        logger.warn("Preventing upload of static file as its size {} is larger than the max size allowed {}",
                request.getContentLength(), maxUploadSize);
        return Response.status(Status.BAD_REQUEST).build();
    }
    ProgressInputStream inputStream = null;
    try {
        String filename = null;
        if (ServletFileUpload.isMultipartContent(request)) {
            boolean isDone = false;
            for (FileItemIterator iter = new ServletFileUpload().getItemIterator(request); iter.hasNext();) {
                FileItemStream item = iter.next();
                if (item.isFormField()) {
                    continue;
                } else {
                    logger.debug("Processing file item");
                    filename = item.getName();
                    inputStream = new ProgressInputStream(item.openStream());
                    inputStream.addPropertyChangeListener(new PropertyChangeListener() {
                        @Override
                        public void propertyChange(PropertyChangeEvent evt) {
                            long totalNumBytesRead = (Long) evt.getNewValue();
                            if (totalNumBytesRead > maxUploadSize) {
                                logger.warn("Upload limit of {} bytes reached, returning a bad request.",
                                        maxUploadSize);
                                throw new WebApplicationException(Status.BAD_REQUEST);
                            }
                        }
                    });
                    isDone = true;
                }
                if (isDone)
                    break;
            }
        } else {
            logger.warn("Request is not multi part request, returning a bad request.");
            return Response.status(Status.BAD_REQUEST).build();
        }

        if (filename == null) {
            logger.warn("Request was missing the filename, returning a bad request.");
            return Response.status(Status.BAD_REQUEST).build();
        }

        if (inputStream == null) {
            logger.warn("Request was missing the file, returning a bad request.");
            return Response.status(Status.BAD_REQUEST).build();
        }

        String uuid = staticFileService.storeFile(filename, inputStream);
        try {
            return Response.created(getStaticFileURL(uuid)).entity(uuid).build();
        } catch (NotFoundException e) {
            logger.error("Previous stored file with uuid {} couldn't beren found: {}", uuid,
                    ExceptionUtils.getStackTrace(e));
            return Response.serverError().build();
        }
    } catch (WebApplicationException e) {
        return e.getResponse();
    } catch (Exception e) {
        logger.error("Unable to store file because: {}", ExceptionUtils.getStackTrace(e));
        return Response.serverError().build();
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:org.yccheok.jstock.gui.analysis.OperatorFigure.java

public void propertyChange(java.beans.PropertyChangeEvent propertyChangeEvent) {
    if (propertyChangeEvent.getPropertyName().equals("value")) {
        this.setValue("" + propertyChangeEvent.getNewValue());
    } else if (propertyChangeEvent.getPropertyName().equals("attribute")) {
        this.setAttribute("" + propertyChangeEvent.getNewValue());
    } else {//w  ww .j  ava  2s  .  co m
        log.error("Unknown property change : " + propertyChangeEvent.getPropertyName());
    }
}

From source file:ui.frame.UILogin.java

public UILogin() {
    super("Login");

    Label l = new Label();

    setLayout(new BorderLayout());
    this.setPreferredSize(new Dimension(400, 300));

    Panel p = new Panel();

    loginPanel = p.createPanel(Layouts.grid, 4, 2);
    loginPanel.setBorder(new EmptyBorder(25, 25, 0, 25));
    lblUser = l.createLabel("Username:");
    lblPassword = l.createLabel("Password:");
    lblURL = l.createLabel("Server URL");
    lblBucket = l.createLabel("Bucket");

    tfURL = new JTextField();
    tfURL.setText("kaiup.kaisquare.com");
    tfBucket = new JTextField();
    PromptSupport.setPrompt("BucketName", tfBucket);
    tfUser = new JTextField();
    PromptSupport.setPrompt("Username", tfUser);
    pfPassword = new JPasswordField();
    PromptSupport.setPrompt("Password", pfPassword);

    buttonPanel = p.createPanel(Layouts.flow);
    buttonPanel.setBorder(new EmptyBorder(0, 0, 25, 0));
    Button b = new Button();
    JButton btnLogin = b.createButton("Login");
    JButton btnExit = b.createButton("Exit");
    btnLogin.setPreferredSize(new Dimension(150, 50));
    btnExit.setPreferredSize(new Dimension(150, 50));
    Component[] arrayBtn = { btnExit, btnLogin };
    p.addComponentsToPanel(buttonPanel, arrayBtn);

    Component[] arrayComponents = { lblURL, tfURL, lblBucket, tfBucket, lblUser, tfUser, lblPassword,
            pfPassword };// www  .ja v  a 2  s.c o  m
    p.addComponentsToPanel(loginPanel, arrayComponents);
    add(loginPanel, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
    pack();
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLocationRelativeTo(null);

    setVisible(true);
    btnLogin.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() {
                @Override
                protected Void doInBackground() throws Exception {
                    if (tfUser.getText().equals("") || String.valueOf(pfPassword.getPassword()).equals("")
                            || tfBucket.getText().equals("")) {
                        JOptionPane.showMessageDialog(Data.mainFrame, "Please fill up all the fields", "Error",
                                JOptionPane.ERROR_MESSAGE);
                    } else {
                        String username = tfUser.getText();
                        String password = String.valueOf(pfPassword.getPassword());
                        Data.URL = Data.protocol + tfURL.getText();
                        Data.targetURL = Data.protocol + tfURL.getText() + "/api/" + tfBucket.getText() + "/";

                        String response = api.loginBucket(Data.targetURL, username, password);

                        try {

                            if (DesktopAppMain.checkResult(response)) {
                                JSONObject responseJSON = new JSONObject(response);
                                Data.sessionKey = responseJSON.get("session-key").toString();
                                response = api.getUserFeatures(Data.targetURL, Data.sessionKey);
                                if (checkFeatures(response)) {
                                    Data.mainFrame = new KAIQRFrame();
                                    Data.mainFrame.uiInventorySelect = new UIInventorySelect();
                                    Data.mainFrame.addPanel(Data.mainFrame.uiInventorySelect, "inventory");
                                    Data.mainFrame.showPanel("inventory");
                                    Data.mainFrame.pack();
                                    setVisible(false);
                                    Data.mainFrame.setVisible(true);

                                } else {
                                    JOptionPane.showMessageDialog(Data.loginFrame,
                                            "User does not have necessary features", "Error",
                                            JOptionPane.ERROR_MESSAGE);
                                }
                            } else {
                                JOptionPane.showMessageDialog(Data.loginFrame, "Wrong username/password",
                                        "Error", JOptionPane.ERROR_MESSAGE);
                            }

                        } catch (JSONException e1) {
                            e1.printStackTrace();
                        }
                    }

                    return null;
                }
            };

            Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource());
            final JDialog dialog = new JDialog(win, "Login", ModalityType.APPLICATION_MODAL);

            mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (evt.getPropertyName().equals("state")) {
                        if (evt.getNewValue() == SwingWorker.StateValue.DONE) {
                            dialog.dispose();
                        }
                    }
                }
            });

            mySwingWorker.execute();

            JProgressBar progressBar = new JProgressBar();
            progressBar.setIndeterminate(true);
            JPanel panel = new JPanel(new BorderLayout());
            panel.add(progressBar, BorderLayout.CENTER);
            panel.add(new JLabel("Logging in .........."), BorderLayout.PAGE_START);
            dialog.add(panel);
            dialog.pack();
            dialog.setBounds(50, 50, 300, 100);
            dialog.setLocationRelativeTo(Data.mainFrame);
            dialog.setVisible(true);
        }
    });

    btnExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }

    });

}

From source file:edu.harvard.mcz.imagecapture.BulkMediaFrame.java

@Override
public void propertyChange(PropertyChangeEvent evt) {
    log.debug(evt.getPropertyName());//from   w  w w  . ja  v  a 2  s.  c  om
    if (evt.getPropertyName() == "progress") {
        int progress = (Integer) evt.getNewValue();
        progressBar.setValue(progress);
        progressBar.setStringPainted(true);
        log.debug(progress);
    }
}

From source file:de.bstreit.java.springaop.test.observablebean.PropertyChangeSupportTest.java

private void checkPropChangeEvent(final String fieldName, final Object oldValue, Object newValue) {

    final PropertyChangeEvent propChangeEvent = propChangeEvents.get(propChangeEventIdx++);

    assertEquals(fieldName, propChangeEvent.getPropertyName());
    assertEquals(oldValue, propChangeEvent.getOldValue());
    assertEquals(newValue, propChangeEvent.getNewValue());

}

From source file:org.drugis.mtc.presentation.results.NetworkInconsistencyFactorsTableModel.java

public NetworkInconsistencyFactorsTableModel(InconsistencyWrapper<?> networkModel,
        ValueModel modelConstructed) {/* ww w .ja v  a  2 s .c  om*/
    d_model = networkModel;
    d_modelConstructed = modelConstructed;
    d_listener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            fireTableDataChanged();
        }
    };

    if (d_modelConstructed.getValue().equals(true)) {
        attachListeners();
    }
    d_modelConstructed.addValueChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getNewValue().equals(true)) {
                fireTableStructureChanged();
                attachListeners();
            }
        }
    });
}