Example usage for java.beans PropertyChangeEvent PropertyChangeEvent

List of usage examples for java.beans PropertyChangeEvent PropertyChangeEvent

Introduction

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

Prototype

public PropertyChangeEvent(Object source, String propertyName, Object oldValue, Object newValue) 

Source Link

Document

Constructs a new PropertyChangeEvent .

Usage

From source file:com.toolsverse.mvc.model.ModelImpl.java

/**
 * Executed when attribute value has changed.
 *
 * @param attributeName the attribute name
 * @param newValue the new value//from w ww  .  j  a  v a  2 s  . co m
 */
public void attributeChanged(String attributeName, Object newValue) {
    propertyChange(new PropertyChangeEvent(this, attributeName, null, newValue));
}

From source file:org.colombbus.tangara.FileUtils.java

private static void addDirectoryToJar(File directory, JarOutputStream output, String prefix,
        PropertyChangeListener listener) throws IOException {
    try {/*w w  w  . j a va  2s .c om*/
        File files[] = directory.listFiles();
        JarEntry entry = null;
        for (int i = 0; i < files.length; i++) {
            if (files[i].isDirectory()) {
                if (prefix != null) {
                    entry = new JarEntry(prefix + "/" + files[i].getName() + "/");
                    output.putNextEntry(entry);
                    addDirectoryToJar(files[i], output, prefix + "/" + files[i].getName(), listener);
                } else {
                    entry = new JarEntry(files[i].getName() + "/");
                    output.putNextEntry(entry);
                    addDirectoryToJar(files[i], output, files[i].getName(), listener);
                }
            } else {
                addFileToJar(files[i], output, prefix);
                if (listener != null) {
                    listener.propertyChange(new PropertyChangeEvent(directory, "fileAdded", null, null));
                }
            }
        }
    } catch (IOException e) {
        LOG.error("Error while adding directory '" + directory.getAbsolutePath() + "'", e);
        throw e;
    }
}

From source file:org.ngrinder.recorder.Recorder.java

/**
 * Initialize the frame with the given {@link TabbedPane}. It tries to get the last position and
 * location saved in the ${NGRINDER_RECORDER_HOME}/last_frame file.
 * //from  w w w  .  j a  va  2  s. c o  m
 * @param tabbedPane
 *            tabbedPane
 */
protected void initFrame(final TabbedPane tabbedPane) {
    File frameInfoFile = recorderConfig.getHome().getFile("last_frame");
    Dimension size = new Dimension(800, 600);
    Point location = null;
    if (frameInfoFile.exists()) {
        try {
            String readFileToString = FileUtils.readFileToString(frameInfoFile);
            Gson gson = new Gson();
            TypeToken<Pair<Dimension, Point>> typeToken = new TypeToken<Pair<Dimension, Point>>() {
            };
            Pair<Dimension, Point> frameInfo = gson.fromJson(readFileToString, typeToken.getType());
            size = frameInfo.getFirst();
            location = frameInfo.getSecond();

        } catch (Exception e) {
            LOGGER.error("Failed to load the frame info", e);
        }
    }
    Dimension screenSize = getFullScreenSize();

    if (screenSize.height < size.height || screenSize.width < size.width) {
        size = screenSize;
    }
    boolean frameUse = recorderConfig.getPropertyBoolean("use.frame", false);
    RecordingControlPanel recordingControlPanel = new RecordingControlPanel(proxy.getConnectionFilter());
    frame.getContentPane().add(createSplitPane(tabbedPane, recordingControlPanel));
    if (!frameUse) {
        frame.setUndecorated(true);
        new ComponentResizer(frame).setMinimumSize(new Dimension(800, 600));
        new ComponentMover(frame, tabbedPane);
    }
    frame.setTitle("nGrinder Recorder");
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    frame.getRootPane().setBorder(new EmptyBorder(5, 5, 5, 5));
    frame.setLocationByPlatform(true);
    frame.getRootPane().setMinimumSize(new Dimension(800, 600));
    frame.setLocationRelativeTo(null);
    frame.setIconImage(ResourceUtil.getIcon("recorder16x16.png").getImage());
    frame.setFocusable(true);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            tabbedPane.disposeAllTabs();
        }
    });

    if (location != null) {
        frame.setLocation(location);
    }

    frame.setSize(size);
    frame.setVisible(true);
    frame.requestFocusInWindow();
    MessageBus.getInstance().getPublisher(Topics.PREPARE_TO_VIEW).propertyChange(
            new PropertyChangeEvent(this, "Prepare to View", null, recorderConfig.getHome().getDirectory()));
    initDisplayDetectionScheduledTask();
}

From source file:org.ngrinder.recorder.proxy.ScriptRecorderProxy.java

/**
 * Start proxy.//from www .  j a va 2 s.  co m
 * 
 * This tries to create a proxy on the given ports. However if it's failed, it creates a proxy
 * with the randomly selected port.
 * 
 * @param defaultPort
 *            default port which will be used to try to make a socket.
 * @return real setup proxy info.
 */
public ProxyEndPointPair startProxy(int defaultPort) {
    // #recorder.additional.headers=header names to be recorded
    System.setProperty("DHTTPPlugin.additionalHeaders",
            recorderConfig.getProperty("recorder.additional.headers", ""));

    LOG.info("Initilize proxy..");
    m_filterContainer = new DefaultPicoContainer(new Caching());
    m_filterContainer.addComponent(LOG);
    UpdatableCommentSource commentSource = new CommentSourceImplementation();
    m_filterContainer.addComponent(commentSource);

    final FilterChain requestFilterChain = new FilterChain();
    final FilterChain responseFilterChain = new FilterChain();
    requestFilterChain.add(SwitchableRequestTcpProxyFilter.class);
    responseFilterChain.add(SwitchableResponseTcpProxyFilter.class);
    m_filterContainer.addComponent(SwitchableRequestTcpProxyFilter.class);
    m_filterContainer.addComponent(SwitchableResponseTcpProxyFilter.class);
    m_filterContainer.addComponent(NullFilter.class);
    m_filterContainer.addComponent(ConnectionAwareNullRequestFilter.class);
    m_filterContainer.addComponent(FileTypeFilterImpl.class);
    m_filterContainer.as(Characteristics.USE_NAMES).addComponent(HTTPResponseFilter.class);
    m_filterContainer.as(Characteristics.USE_NAMES).addComponent(HTTPRequestFilter.class);
    m_filterContainer.addComponent(SwitchableTcpProxyFilter.class);
    m_filterContainer.addComponent(AttributeStringParserImplementation.class);
    m_filterContainer.addComponent("eventListener", ConnectedHostHTTPFilterEventListener.class);
    m_filterContainer.addComponent("connectionCache", ConnectionCache.class);
    m_filterContainer.addComponent(ConnectionHandlerFactoryImplEx.class);
    m_filterContainer.addComponent(ParametersFromProperties.class);
    m_filterContainer.addComponent(HTTPRecordingImplEx.class);
    m_filterContainer.addComponent(ProcessHTTPRecordingWithFreeMarker.class);
    m_filterContainer.addComponent(ConnectionFilterImpl.class);
    m_filterContainer.addComponent(RegularExpressionsImplementation.class);
    m_filterContainer.addComponent(URIParserImplementation.class);
    m_filterContainer.addComponent(SimpleStringEscaper.class);
    m_filterContainer.addComponent(recorderConfig);
    m_filterContainer.start();
    LOG.info("Pico container initiated..");

    final SwitchableResponseTcpProxyFilter switchableResponseFilter = m_filterContainer
            .getComponent(SwitchableResponseTcpProxyFilter.class);
    final SwitchableRequestTcpProxyFilter switchableRequestFilter = m_filterContainer
            .getComponent(SwitchableRequestTcpProxyFilter.class);
    final HTTPResponseFilter httpResponseFilter = m_filterContainer.getComponent(HTTPResponseFilter.class);
    final HTTPRequestFilter httpRequestFilter = m_filterContainer.getComponent(HTTPRequestFilter.class);
    final NullFilter nullFilter = m_filterContainer.getComponent(NullFilter.class);
    final ConnectionAwareNullRequestFilter connectionAwareNullRequestFilter = m_filterContainer
            .getComponent(ConnectionAwareNullRequestFilter.class);
    final FileTypeFilterImpl fileTypeFilter = m_filterContainer.getComponent(FileTypeFilterImpl.class);
    final HTTPRecordingImplEx httpRecording = m_filterContainer.getComponent(HTTPRecordingImplEx.class);
    final ConnectedHostHTTPFilterEventListener connectionCache = m_filterContainer
            .getComponent(ConnectedHostHTTPFilterEventListener.class);
    final MessageBus messageBus = MessageBus.getInstance();
    MessageBusConnection connect = messageBus.connect();
    LOG.info("Register event handler..");
    connect.subscribe(Topics.START_RECORDING, new PropertyChangeListener() {
        @Override
        @SuppressWarnings("unchecked")
        public void propertyChange(PropertyChangeEvent evt) {
            initFileTypeFilter(fileTypeFilter, (List<FileTypeCategory>) evt.getNewValue());
            switchableResponseFilter.setTcpProxyFilter(httpResponseFilter);
            switchableRequestFilter.setTcpProxyFilter(httpRequestFilter);
        }
    });
    connect.subscribe(Topics.STOP_RECORDING, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            switchableResponseFilter.setTcpProxyFilter(nullFilter);
            switchableRequestFilter.setTcpProxyFilter(connectionAwareNullRequestFilter);
            Pair<List<FileTypeCategory>, Set<GenerationOption>> pair = cast(evt.getNewValue());
            initFileTypeFilter(fileTypeFilter, pair.getFirst());
            ProcessHTTPRecordingWithFreeMarker httpOutput = m_filterContainer
                    .getComponent(ProcessHTTPRecordingWithFreeMarker.class);
            HTTPRecordingImplEx recoding = m_filterContainer.getComponent(HTTPRecordingImplEx.class);
            StringWriter writer = new StringWriter();
            Set<GenerationOption> second = (Set<GenerationOption>) pair.getSecond();
            httpOutput.setGenerationOptions(second);
            httpOutput.setWriter(writer);
            recoding.generate();
            Language lang = Language.Jython;
            for (GenerationOption each : second) {
                if (StringUtils.equals("Language", each.getGroup())) {
                    lang = Language.valueOf(each.name());
                    break;
                }
            }
            Pair<Language, String> result = Pair.of(lang, writer.toString());
            messageBus.getPublisher(Topics.SHOW_SCRIPT)
                    .propertyChange(new PropertyChangeEvent(this, "Show Script", null, result));
        }

    });

    connect.subscribe(Topics.START_USER_PAGE, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            httpRecording.setNewPageRequested();
        }
    });

    connect.subscribe(Topics.RESET, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            connectionCache.dispose();
            httpRecording.reset();
        }
    });
    LOG.info("Try to start proxy..");
    InetAddress localHostAddress = NetworkUtil.getLocalHostAddress();
    int proxyPort = getAvailablePort(localHostAddress, defaultPort);

    LOG.info("Recorder port is HTTP:{} / HTTPS:{}", proxyPort, proxyPort);
    final EndPoint localHttpEndPoint = new EndPoint(localHostAddress.getHostAddress(), proxyPort);
    final EndPoint localHttpsEndPoint = new EndPoint(localHostAddress.getHostAddress(), proxyPort);
    ProxyEndPointPair proxyEndPointPair = new ProxyEndPointPair(localHttpEndPoint, localHttpsEndPoint);
    final TCPProxyFilter requestFilter = requestFilterChain.resolveFilter();
    final TCPProxyFilter responseFilter = responseFilterChain.resolveFilter();
    try {
        TCPProxySSLSocketFactory sslSocketFactory = ceateTCPProxySSlSocketFactory();
        m_httpProxyEngine = new HTTPProxyTCPProxyEngineEx(sslSocketFactory, requestFilter, responseFilter, LOG,
                localHttpEndPoint, null, null);
        Thread httpProxyThread = new Thread(m_httpProxyEngine);
        httpProxyThread.start();
        LOG.info("Finish proxy initailization.");
    } catch (Exception e) {
        throw new NGrinderRuntimeException("Failed to start the tcp proxy engine.", e);
    }
    return proxyEndPointPair;
}

From source file:edu.ku.brc.af.core.SchemaI18NService.java

/**
 * Creates a menu with the locate and a property listener. A property event is sent with the property
 * name set to "locale" with the current locale passed as the old value and the new locale as the new value.
 * @param frame the frame is passed in so the property listner can push and pop the frame before and after the listener is called.
 * @return the menu//from   ww w. j a va2 s .c o  m
 */
public JMenu createLocaleMenu(final JFrame frame, final PropertyChangeListener pcl) {
    JMenu localeMenu = createLocaleMenu(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            List<LocaleDlgItem> dlgItems = new ArrayList<LocaleDlgItem>();
            for (Locale l : getStdLocaleList(true)) {
                if (!l.getLanguage().equals("-")) {
                    dlgItems.add(new LocaleDlgItem(l));
                }
            }
            ChooseFromListDlg<LocaleDlgItem> localeDlg = new ChooseFromListDlg<LocaleDlgItem>(frame,
                    "Choose a Locale", dlgItems);
            UIHelper.centerAndShow(localeDlg);
            LocaleDlgItem selected = localeDlg.getSelectedObject();
            if (!localeDlg.isCancelled() && selected != null) {
                Locale newLocale = selected.getLocale();
                checkCurrentLocaleMenu();
                UIRegistry.pushWindow(frame);
                pcl.propertyChange(new PropertyChangeEvent(this, "locale", currentLocale, newLocale)); //$NON-NLS-1$
                UIRegistry.popWindow(frame);
            }
        }
    });
    checkCurrentLocaleMenu();
    return localeMenu;
}

From source file:net.sf.maltcms.chromaui.project.spi.project.ChromAUIProject.java

@Override
public void refresh() {
    pcs.firePropertyChange(new PropertyChangeEvent(this, "container", false, true));
}

From source file:de.schlichtherle.xml.GenericCertificate.java

/**
 * Encodes and signs the given <tt>content</tt> in this certificate and
 * locks it./*from  w ww . j  a  v a  2s.  c o m*/
 * <p>
 * Please note the following:
 * <ul>
 * <li>This method will throw a <tt>PropertyVetoException</tt> if this
 *     certificate is already locked, i.e. if it has been signed or
 *     verified before.</li>
 * <li>Because this method locks this certificate, a subsequent call to
 *     {@link #sign(Object, PrivateKey, Signature)} or
 *     {@link #verify(PublicKey, Signature)} is redundant
 *     and will throw a <tt>PropertyVetoException</tt>.
 *     Use {@link #isLocked()} to detect whether a
 *     generic certificate has been successfuly signed or verified before
 *     or call {@link #getContent()} and expect an 
 *     Exception to be thrown if it hasn't.</li>
 * <li>There is no way to unlock this certificate.
 *     Call the copy constructor of {@link GenericCertificate} if you
 *     need an unlocked copy of the certificate.</li>
 * </ul>
 * 
 * @param content The object to sign. This must either be a JavaBean or an
 *        instance of any other class which is supported by
 *        <tt>{@link PersistenceService}</tt>
 *        - maybe <tt>null</tt>.
 * @param signingKey The private key for signing
 *        - may <em>not</em> be <tt>null</tt>.
 * @param signingEngine The signature signing engine
 *        - may <em>not</em> be <tt>null</tt>.
 * 
 * @throws NullPointerException If the preconditions for the parameters
 *         do not hold.
 * @throws GenericCertificateIsLockedException If this certificate is
 *         already locked by signing or verifying it before.
 *         Note that this is actually a subclass of
 *         {@link PropertyVetoException}.
 * @throws PropertyVetoException If locking the certifificate (and thus
 *         signing the object) is vetoed by any listener.
 * @throws PersistenceServiceException If the object cannot be serialised.
 * @throws InvalidKeyException If the verification key is invalid.
 */
public synchronized final void sign(final Object content, final PrivateKey signingKey,
        final Signature signingEngine) throws NullPointerException, GenericCertificateIsLockedException,
        PropertyVetoException, PersistenceServiceException, InvalidKeyException {
    // Check parameters.
    if (signingKey == null)
        throw new NullPointerException("signingKey");
    if (signingEngine == null)
        throw new NullPointerException("signingEngine");

    // Check lock status.
    final PropertyChangeEvent evt = new PropertyChangeEvent(this, "locked", Boolean.valueOf(isLocked()),
            Boolean.TRUE); // NOI18N
    if (isLocked())
        throw new GenericCertificateIsLockedException(evt);

    // Notify vetoable listeners and give them a chance to veto.
    fireVetoableChange(evt);

    try {
        // Encode the object.
        final byte[] beo = PersistenceService.store2ByteArray(content);

        // Sign the byte encoded object.
        signingEngine.initSign(signingKey);
        signingEngine.update(beo);
        final byte[] b64es = Base64.encodeBase64(signingEngine.sign()); // the base64 encoded signature
        final String signature = new String(b64es, 0, b64es.length, BASE64_CHARSET);

        // Store results.
        setEncoded(new String(beo, XML_CHARSET));
        setSignature(signature);
        setSignatureAlgorithm(signingEngine.getAlgorithm());
        setSignatureEncoding(SIGNATURE_ENCODING); // NOI18N
    } catch (UnsupportedEncodingException cannotHappen) {
        throw new AssertionError(cannotHappen);
    } catch (SignatureException cannotHappen) {
        throw new AssertionError(cannotHappen);
    }

    // Lock this certificate and notify property change listeners.
    this.locked = true;
    firePropertyChange(evt);
}

From source file:jetbrains.buildServer.torrent.TorrentConfigurator.java

public void propertyChanged(String changedPropertyName, Object oldValue, Object newValue) {
    PropertyChangeEvent event = new PropertyChangeEvent(this, changedPropertyName, oldValue, newValue);
    for (PropertyChangeListener listener : myChangeListeners) {
        try {/*from   ww w.j av a 2  s .  com*/
            listener.propertyChange(event);
        } catch (Exception ex) {
        }
    }
}

From source file:com.interface21.beans.BeanWrapperImpl.java

/**
 * Convert the value to the required type (if necessary from a string),
 * to create a PropertyChangeEvent./*w  ww.  j a v a 2  s  .co  m*/
 * Conversions from String to any type use the setAsTest() method of
 * the PropertyEditor class. Note that a PropertyEditor must be registered
 * for this class for this to work. This is a standard Java Beans API.
 * A number of property editors are automatically registered by this class.
 * @param target target bean
 * @param propertyName name of the property
 * @param oldValue previous value, if available. May be null.
 * @param newValue proposed change value.
 * @param requiredType type we must convert to
 * @throws BeansException if there is an internal error
 * @return a PropertyChangeEvent, containing the converted type of the new
 * value.
 */
private PropertyChangeEvent createPropertyChangeEventWithTypeConversionIfNecessary(Object target,
        String propertyName, Object oldValue, Object newValue, Class requiredType) throws BeansException {
    return new PropertyChangeEvent(target, propertyName, oldValue,
            doTypeConversionIfNecessary(target, propertyName, oldValue, newValue, requiredType));
}

From source file:org.netbeans.modules.php.fuel.options.FuelPhpOptionsPanel.java

void store() {
    FuelPhpOptions options = FuelPhpOptions.getInstance();
    // notify autodetection
    options.setNotifyAutodetection(notifyAutodetectionCheckBox.isSelected());
    // default config
    options.setDefaultConfig(defaultConfigCheckBox.isSelected());
    options.setDefaultConfig(defaultConfigEditorPane.getText());

    if (isNetworkError) {
        return;/*  w  w  w  .  ja v a  2s  .  c o m*/
    }

    // branch
    String selectedItem = (String) branchesComboBox.getSelectedItem();
    if (selectedItem != null) {
        options.setGitBranchName(selectedItem);
    }

    // nodes
    List<String> selectedNodes = nodeList.getSelectedValuesList();
    options.setAvailableNodes(selectedNodes);
    Project[] openProjects = OpenProjects.getDefault().getOpenProjects();
    for (Project project : openProjects) {
        PhpModule phpModule = PhpModule.Factory.lookupPhpModule(project);
        if (phpModule != null) {
            if (FuelUtils.isFuelPHP(phpModule)) {
                FuelPhpModule fuelModule = FuelPhpModule.forPhpModule(phpModule);
                fuelModule.notifyPropertyChanged(
                        new PropertyChangeEvent(this, FuelPhpModule.PROPERTY_CHANGE_FUEL, null, null));
            }
        }
    }
}