Example usage for java.beans PropertyChangeListener PropertyChangeListener

List of usage examples for java.beans PropertyChangeListener PropertyChangeListener

Introduction

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

Prototype

PropertyChangeListener

Source Link

Usage

From source file:org.openconcerto.erp.core.sales.shipment.component.BonDeLivraisonSQLComponent.java

public void addViews() {
    this.textTotalHT.setOpaque(false);
    this.textTotalTVA.setOpaque(false);
    this.textTotalTTC.setOpaque(false);

    this.selectCommande = new ElementComboBox();

    this.setLayout(new GridBagLayout());

    final GridBagConstraints c = new DefaultGridBagConstraints();

    // Champ Module
    c.gridx = 0;/*from  w w  w  .  j  a  v  a  2  s .  co  m*/
    c.gridy++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
    this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
    this.add(addP, c);

    c.gridy++;
    c.gridwidth = 1;

    // Numero
    JLabel labelNum = new JLabel(getLabelFor("NUMERO"));
    labelNum.setHorizontalAlignment(SwingConstants.RIGHT);
    this.add(labelNum, c);

    this.textNumeroUnique = new JUniqueTextField(16);
    c.gridx++;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    DefaultGridBagConstraints.lockMinimumSize(textNumeroUnique);
    this.add(this.textNumeroUnique, c);

    // Date
    c.gridx++;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    this.add(new JLabel(getLabelFor("DATE"), SwingConstants.RIGHT), c);

    JDate date = new JDate(true);
    c.gridx++;
    c.weightx = 0;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    this.add(date, c);

    // Reference
    c.gridy++;
    c.gridx = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);
    c.gridx++;
    c.weightx = 1;
    this.add(this.textNom, c);
    if (getTable().contains("DATE_LIVRAISON")) {
        // Date livraison
        c.gridx++;
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0;
        this.add(new JLabel(getLabelFor("DATE_LIVRAISON"), SwingConstants.RIGHT), c);

        JDate dateLivraison = new JDate(true);
        c.gridx++;
        c.weightx = 0;
        c.weighty = 0;
        c.fill = GridBagConstraints.NONE;
        this.add(dateLivraison, c);
        this.addView(dateLivraison, "DATE_LIVRAISON");
    }
    // Client
    JLabel labelClient = new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT);
    c.gridx = 0;
    c.gridy++;
    c.weightx = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weighty = 0;
    this.add(labelClient, c);

    c.gridx++;
    c.weightx = 0;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    this.comboClient = new ElementComboBox();
    this.add(this.comboClient, c);
    if (getTable().contains("SPEC_LIVRAISON")) {
        // Date livraison
        c.gridx++;
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0;
        this.add(new JLabel(getLabelFor("SPEC_LIVRAISON"), SwingConstants.RIGHT), c);

        JTextField specLivraison = new JTextField();
        c.gridx++;
        c.weightx = 0;
        c.weighty = 0;
        this.add(specLivraison, c);
        this.addView(specLivraison, "SPEC_LIVRAISON");
    }

    final ElementComboBox boxTarif = new ElementComboBox();
    this.comboClient.addValueListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (comboClient.getElement().getTable().contains("ID_TARIF")) {
                if (BonDeLivraisonSQLComponent.this.isFilling())
                    return;
                final SQLRow row = ((SQLRequestComboBox) evt.getSource()).getSelectedRow();
                if (row != null) {
                    // SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
                    // if (foreignRow.isUndefined() &&
                    // !row.getForeignRow("ID_DEVISE").isUndefined()) {
                    // SQLRowValues rowValsD = new SQLRowValues(foreignRow.getTable());
                    // rowValsD.put("ID_DEVISE", row.getObject("ID_DEVISE"));
                    // foreignRow = rowValsD;
                    //
                    // }
                    // tableBonItem.setTarif(foreignRow, true);
                    SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF");
                    if (!foreignRow.isUndefined()
                            && (boxTarif.getSelectedRow() == null
                                    || boxTarif.getSelectedId() != foreignRow.getID())
                            && JOptionPane.showConfirmDialog(null,
                                    "Appliquer les tarifs associs au client?") == JOptionPane.YES_OPTION) {
                        boxTarif.setValue(foreignRow.getID());
                        // SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow,
                        // true);
                    } else {
                        boxTarif.setValue(foreignRow.getID());
                    }
                }
            }
        }
    });

    // Bouton tout livrer
    JButton boutonAll = new JButton("Tout livrer");

    boutonAll.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            RowValuesTableModel m = BonDeLivraisonSQLComponent.this.tableBonItem.getModel();

            // on livre tout les lments
            for (int i = 0; i < m.getRowCount(); i++) {
                SQLRowValues rowVals = m.getRowValuesAt(i);
                Object o = rowVals.getObject("QTE");
                int qte = o == null ? 0 : ((Number) o).intValue();
                m.putValue(qte, i, "QTE_LIVREE");
            }
        }
    });

    // Tarif
    if (this.getTable().getFieldsName().contains("ID_TARIF")) {
        // TARIF
        c.gridy++;
        c.gridx = 0;
        c.weightx = 0;
        c.weighty = 0;
        c.gridwidth = 1;
        this.add(new JLabel("Tarif  appliquer"), c);
        c.gridx++;
        c.gridwidth = 1;

        c.weightx = 1;
        this.add(boxTarif, c);
        this.addView(boxTarif, "ID_TARIF");
        boxTarif.addModelListener("wantedID", new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                SQLRow selectedRow = boxTarif.getRequest().getPrimaryTable().getRow(boxTarif.getWantedID());
                tableBonItem.setTarif(selectedRow, !isFilling());
            }
        });
    }

    if (getTable().contains("A_ATTENTION")) {
        // Date livraison
        c.gridx++;
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0;
        this.add(new JLabel(getLabelFor("A_ATTENTION"), SwingConstants.RIGHT), c);

        JTextField specLivraison = new JTextField();
        c.gridx++;
        c.weightx = 0;
        c.weighty = 0;
        this.add(specLivraison, c);
        this.addView(specLivraison, "A_ATTENTION");
    }

    // Element du bon
    List<JButton> l = new ArrayList<JButton>();
    l.add(boutonAll);
    this.tableBonItem = new BonDeLivraisonItemTable(l);

    c.gridx = 0;
    c.gridy++;
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.BOTH;
    this.add(this.tableBonItem, c);
    c.anchor = GridBagConstraints.EAST;
    // Totaux
    reconfigure(this.textTotalHT);
    reconfigure(this.textTotalTVA);
    reconfigure(this.textTotalTTC);

    // Poids Total
    c.gridy++;
    c.gridx = 1;
    c.weightx = 0;
    c.weighty = 0;
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    this.addSQLObject(this.textPoidsTotal, "TOTAL_POIDS");
    this.addRequiredSQLObject(this.textTotalHT, "TOTAL_HT");
    this.addRequiredSQLObject(this.textTotalTVA, "TOTAL_TVA");
    this.addRequiredSQLObject(this.textTotalTTC, "TOTAL_TTC");
    TotalPanel panelTotal = new TotalPanel(tableBonItem, textTotalHT, textTotalTVA, textTotalTTC,
            new DeviseField(), new DeviseField(), new DeviseField(), new DeviseField(), new DeviseField(),
            textPoidsTotal, null);
    c.gridx = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 0;
    c.weighty = 0;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(panelTotal, c);

    c.anchor = GridBagConstraints.WEST;

    /*******************************************************************************************
     * * INFORMATIONS COMPLEMENTAIRES
     ******************************************************************************************/
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy++;
    TitledSeparator sep = new TitledSeparator("Informations complmentaires");
    c.insets = new Insets(10, 2, 1, 2);
    this.add(sep, c);
    c.insets = new Insets(2, 2, 1, 2);

    ITextArea textInfos = new ITextArea(4, 4);

    c.gridx = 0;
    c.gridy++;
    c.gridheight = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.BOTH;

    final JScrollPane scrollPane = new JScrollPane(textInfos);
    this.add(scrollPane, c);
    textInfos.setBorder(null);
    DefaultGridBagConstraints.lockMinimumSize(scrollPane);

    c.gridx = 0;
    c.gridy++;
    c.gridheight = 1;
    c.gridwidth = 4;
    c.weightx = 0;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;

    this.panelOO = new PanelOOSQLComponent(this);
    this.add(this.panelOO, c);

    this.addRequiredSQLObject(date, "DATE");
    this.addSQLObject(textInfos, "INFOS");
    this.addSQLObject(this.textNom, "NOM");
    this.addSQLObject(this.selectCommande, "ID_COMMANDE_CLIENT");
    this.addRequiredSQLObject(this.textNumeroUnique, "NUMERO");

    this.addRequiredSQLObject(this.comboClient, "ID_CLIENT");

    // Doit etre lock a la fin
    DefaultGridBagConstraints.lockMinimumSize(comboClient);

}

From source file:org.squidy.designer.model.PipelineShape.java

@Override
protected void initializeShapeListeners() {
    super.initializeShapeListeners();

    // Listener that prepares the zoom out representation of the pipeline shape.
    addPropertyChangeListener(new PropertyChangeListener() {

        /*//from  w w  w . j  a  va 2s .c  om
         * (non-Javadoc)
         * 
         * @seejava.beans.PropertyChangeListener#propertyChange(java.beans.
         * PropertyChangeEvent)
         */
        public void propertyChange(PropertyChangeEvent evt) {
            prepareZoomOutRepresentation();
        }
    });
}

From source file:com.numenta.taurus.instance.InstanceListFragment.java

/**
 * InstanceListFragment constructor/*from   w  ww .  j av a2s  .c  om*/
 */
public InstanceListFragment() {
    // Listen for new instance data
    _instanceDataChangedReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            updateInstanceData();
        }
    };

    // Listen for favorites changes
    _favoritesChangedReceiver = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (_instanceFilter == InstanceFilter.Favorites) {
                filterFavorites();
            } else {
                clearFilter();
            }
        }
    };
}

From source file:org.rdv.viz.image.ImageViz.java

private void initImagePanel() {
    imagePanel = new ImagePanel();
    imagePanel.setBackground(Color.black);
    imagePanel.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent pce) {
            String propertyName = pce.getPropertyName();
            if (propertyName.equals(ImagePanel.AUTO_SCALING_PROPERTY)) {
                boolean autoScaling = (Boolean) pce.getNewValue();
                autoScaleMenuItem.setSelected(autoScaling);
                if (autoScaling) {
                    properties.remove(DATA_PANEL_PROPERTY_SCALE);
                    properties.remove(DATA_PANEL_PROPERTY_ORIGIN);
                } else {
                    properties.setProperty(DATA_PANEL_PROPERTY_SCALE, Double.toString(imagePanel.getScale()));
                    properties.setProperty(DATA_PANEL_PROPERTY_ORIGIN, pointToString(imagePanel.getOrigin()));
                }//from www.  ja  v  a2  s  .  co  m
            } else if (propertyName.equals(ImagePanel.SCALE_PROPERTY) && !imagePanel.isAutoScaling()) {
                properties.setProperty(DATA_PANEL_PROPERTY_SCALE, pce.getNewValue().toString());
            } else if (propertyName.equals(ImagePanel.ORIGIN_PROPERTY) && !imagePanel.isAutoScaling()) {
                Point origin = (Point) pce.getNewValue();
                String originString = pointToString(origin);
                properties.setProperty(DATA_PANEL_PROPERTY_ORIGIN, originString);
            } else if (propertyName.equals(ImagePanel.NAVIGATION_IMAGE_ENABLED_PROPERTY)) {
                boolean showNavigationImage = (Boolean) pce.getNewValue();
                showNavigationImageMenuItem.setSelected(showNavigationImage);
                if (showNavigationImage) {
                    properties.setProperty(DATA_PANEL_PROPERTY_SHOW_NAVIGATION_IMAGE, "true");
                } else {
                    properties.remove(DATA_PANEL_PROPERTY_SHOW_NAVIGATION_IMAGE);
                }
            }
        }
    });

    panel.add(imagePanel, BorderLayout.CENTER);
}

From source file:org.tinymediamanager.ui.movies.MovieMediaFilesPanel.java

/**
 * Instantiates a new movie media information panel.
 * //from   www.  j  av a 2 s.  c  om
 * @param model
 *          the model
 */
public MovieMediaFilesPanel(MovieSelectionModel model) {
    this.movieSelectionModel = model;
    mediaFileEventList = new ObservableElementList<>(
            GlazedLists.threadSafeList(new BasicEventList<MediaFile>()),
            GlazedLists.beanConnector(MediaFile.class));

    setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("200px:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.NARROW_LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                    FormFactory.NARROW_LINE_GAP_ROWSPEC, RowSpec.decode("default:grow"),
                    FormFactory.NARROW_LINE_GAP_ROWSPEC, }));

    lblDateAddedT = new JLabel(BUNDLE.getString("metatag.dateadded")); //$NON-NLS-1$
    add(lblDateAddedT, "2, 2");

    lblDateAdded = new JLabel("");
    add(lblDateAdded, "4, 2");

    // btnPlay = new JButton("Play");
    // btnPlay.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent arg0) {
    // try {
    // Desktop.getDesktop().open(movieSelectionModel.getSelectedMovie().getMediaFiles(MediaFileType.VIDEO).get(0).getFile());
    // }
    // catch (Exception e) {
    //
    // }
    // }
    // if (!StringUtils.isEmpty(lblMoviePath.getNormalText())) {
    // // get the location from the label
    // StringBuilder movieFile = new
    // StringBuilder(lblMoviePath.getNormalText());
    // movieFile.append(File.separator);
    // movieFile.append(movieSelectionModel.getSelectedMovie().getMediaFiles().get(0).getFilename());
    // File f = new File(movieFile.toString());
    //
    // try {
    // if (f.exists()) {
    //
    // String vlcF = f.getAbsolutePath();
    // // F I X M E: german umlauts do not decode correctly; Bug in
    // // libDvdNav? so workaround;
    // if (vlcF.matches(".*[].*")) {
    // LOGGER.debug("VLC: workaround: german umlauts found - use system player");
    // Desk4op.getDesktop().open(f);
    // }
    // else {
    // try {
    //
    // if (!vlcF.startsWith("/")) {
    // // add the missing 3rd / in not start with one (eg windows)
    // vlcF = "/" + vlcF;
    // }
    // String mrl = new FileMrl().file(vlcF).value();
    //
    // final EmbeddedMediaPlayerComponent mediaPlayerComponent = new
    // EmbeddedMediaPlayerComponent();
    // JFrame frame = new JFrame("player");
    // frame.setLocation(100, 100);
    // frame.setSize(1050, 600);
    // frame.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
    // frame.setVisible(true);
    // frame.setContentPane(mediaPlayerComponent);
    // // mrl = mrl.replace("file://", ""); // does not work either
    //
    // LOGGER.debug("VLC: playing " + mrl);
    // Boolean ok = mediaPlayerComponent.getMediaPlayer().playMedia(mrl);
    // if (!ok) {
    // LOGGER.error("VLC: couldn't create player window!");
    // }
    // }
    // catch (RuntimeException e) {
    // LOGGER.warn("VLC: has not been initialized on startup - use system player");
    // Desktop.getDesktop().open(f);
    // }
    // catch (NoClassDefFoundError e) {
    // LOGGER.warn("VLC: has not been initialized on startup - use system player");
    // Desktop.getDesktop().open(f);
    // }
    //
    // } // end else
    // } // end exists
    // } // end try
    // catch (IOException e) {
    // LOGGER.error("Error opening file", e);
    // }
    // } // end isEmpty
    // }
    // });
    // add(btnPlay, "10, 2");

    lblMoviePathT = new JLabel(BUNDLE.getString("metatag.path")); //$NON-NLS-1$
    add(lblMoviePathT, "2, 4");

    lblMoviePath = new LinkLabel("");
    lblMoviePath.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (!StringUtils.isEmpty(lblMoviePath.getNormalText())) {
                Path path = Paths.get(lblMoviePath.getNormalText());
                try {
                    // get the location from the label
                    // check whether this location exists
                    if (Files.exists(path)) {
                        TmmUIHelper.openFile(path);
                    }
                } catch (Exception ex) {
                    LOGGER.error("open filemanager", ex);
                    MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, path,
                            "message.erroropenfolder", new String[] { ":", ex.getLocalizedMessage() }));
                }
            }
        }
    });
    lblMoviePathT.setLabelFor(lblMoviePath);
    lblMoviePathT.setLabelFor(lblMoviePath);
    add(lblMoviePath, "4, 4");

    lblFilesT = new JLabel(BUNDLE.getString("metatag.files")); //$NON-NLS-1$
    add(lblFilesT, "2, 6, default, top");

    panelMediaFiles = new MediaFilesPanel(mediaFileEventList);
    add(panelMediaFiles, "4, 6, 1, 1, fill, fill");

    initDataBindings();

    // install the propertychangelistener
    PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            String property = propertyChangeEvent.getPropertyName();
            Object source = propertyChangeEvent.getSource();
            // react on selection of a movie and change of media files
            if ((source.getClass() == MovieSelectionModel.class && "selectedMovie".equals(property))
                    || (source.getClass() == Movie.class && MEDIA_FILES.equals(property))) {
                // this does sometimes not work. simply wrap it
                try {
                    mediaFileEventList.getReadWriteLock().writeLock().lock();
                    mediaFileEventList.clear();
                    mediaFileEventList.addAll(movieSelectionModel.getSelectedMovie().getMediaFiles());
                } catch (Exception e) {
                } finally {
                    mediaFileEventList.getReadWriteLock().writeLock().unlock();
                }
                try {
                    panelMediaFiles.adjustColumns();
                } catch (Exception e) {
                }
            }
        }
    };

    movieSelectionModel.addPropertyChangeListener(propertyChangeListener);
}

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   ww  w  .  j a v  a  2 s  .  c  om*/
        });

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

From source file:com.architexa.diagrams.relo.jdt.parts.CompartmentedCodeUnitEditPart.java

private CompartmentCUEditPart realizeCompartment(Resource compartmentType) {
    // create the compartments
    final CompartmentCodeUnit ccu = generateCompartment(compartmentType, getCU());
    ccu.registerTypes(compartmentMap);/*from   w w  w  .  ja va2  s. c om*/

    // install any needed policies
    ArtifactFragment compAF = getRootController().getRootArtifact().getArtifact(ccu);

    // initialize the compartments
    getArtifact().addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            ccu.firePropChang(evt.getPropertyName());
            String propName = evt.getPropertyName();
            if (ArtifactFragment.Policy_Contents_Changed.equals(propName)) {
                colorFigure(ColorDPolicy.getColor(getCU()));
            }
        }
    });

    // update children
    this.refreshChildren();

    CompartmentCUEditPart cep = (CompartmentCUEditPart) getRootController().findArtifactEditPart(compAF);

    final IFigure classFigure = (IFigure) CompartmentedCodeUnitEditPart.super.getFigure().getChildren().get(0);
    if (classFigure != null)
        NonEmptyFigureSupport.listenToModel(getArtFrag(), ((CodeUnitFigure) classFigure).nonEmptyFigure);
    return cep;
}

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

/**
 * Start proxy.//from  ww  w .ja v a  2 s.c o  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:ca.uhn.hl7v2.testpanel.ui.editor.Hl7V2MessageEditorPanel.java

/**
 * Create the panel./*from ww  w . j  a  va2  s .c o  m*/
 */
public Hl7V2MessageEditorPanel(final Controller theController) {
    setBorder(null);
    myController = theController;

    ButtonGroup encGrp = new ButtonGroup();
    setLayout(new BorderLayout(0, 0));

    mysplitPane = new JSplitPane();
    mysplitPane.setResizeWeight(0.5);
    mysplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
    add(mysplitPane);

    mysplitPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent theEvt) {
            double ratio = (double) mysplitPane.getDividerLocation() / mysplitPane.getHeight();
            ourLog.debug("Resizing split to ratio: {}", ratio);
            Prefs.getInstance().setHl7EditorSplit(ratio);
        }
    });

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            mysplitPane.setDividerLocation(Prefs.getInstance().getHl7EditorSplit());
        }
    });

    messageEditorContainerPanel = new JPanel();
    messageEditorContainerPanel.setBorder(null);
    mysplitPane.setRightComponent(messageEditorContainerPanel);
    messageEditorContainerPanel.setLayout(new BorderLayout(0, 0));

    myMessageEditor = new JEditorPane();
    Highlighter h = new UnderlineHighlighter();
    myMessageEditor.setHighlighter(h);
    // myMessageEditor.setFont(Prefs.getHl7EditorFont());
    myMessageEditor.setSelectedTextColor(Color.black);

    myMessageEditor.setCaret(new EditorCaret());

    myMessageScrollPane = new JScrollPane(myMessageEditor);
    messageEditorContainerPanel.add(myMessageScrollPane);

    JToolBar toolBar = new JToolBar();
    messageEditorContainerPanel.add(toolBar, BorderLayout.NORTH);
    toolBar.setFloatable(false);
    toolBar.setRollover(true);

    myFollowToggle = new JToggleButton("Follow");
    myFollowToggle.setToolTipText("Keep the message tree (above) and the message editor (below) in sync");
    myFollowToggle.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            theController.setMessageEditorInFollowMode(myFollowToggle.isSelected());
        }
    });
    myFollowToggle.setIcon(new ImageIcon(
            Hl7V2MessageEditorPanel.class.getResource("/ca/uhn/hl7v2/testpanel/images/updown.png")));
    myFollowToggle.setSelected(theController.isMessageEditorInFollowMode());
    toolBar.add(myFollowToggle);

    myhorizontalStrut = Box.createHorizontalStrut(20);
    toolBar.add(myhorizontalStrut);

    mylabel_4 = new JLabel("Encoding");
    toolBar.add(mylabel_4);

    myRdbtnEr7 = new JRadioButton("ER7");
    myRdbtnEr7.setMargin(new Insets(1, 2, 0, 1));
    toolBar.add(myRdbtnEr7);

    myRdbtnXml = new JRadioButton("XML");
    myRdbtnXml.setMargin(new Insets(1, 5, 0, 1));
    toolBar.add(myRdbtnXml);
    encGrp.add(myRdbtnEr7);
    encGrp.add(myRdbtnXml);

    treeContainerPanel = new JPanel();
    mysplitPane.setLeftComponent(treeContainerPanel);
    treeContainerPanel.setLayout(new BorderLayout(0, 0));

    mySpinnerIconOn = new ImageIcon(
            Hl7V2MessageEditorPanel.class.getResource("/ca/uhn/hl7v2/testpanel/images/spinner.gif"));
    mySpinnerIconOff = new ImageIcon();

    myTreePanel = new Hl7V2MessageTree(theController);
    myTreePanel.setWorkingListener(new IWorkingListener() {

        public void startedWorking() {
            mySpinner.setText("");
            mySpinner.setIcon(mySpinnerIconOn);
            mySpinnerIconOn.setImageObserver(mySpinner);
        }

        public void finishedWorking(String theStatus) {
            mySpinner.setText(theStatus);

            mySpinner.setIcon(mySpinnerIconOff);
            mySpinnerIconOn.setImageObserver(null);
        }
    });
    myTreeScrollPane = new JScrollPane(myTreePanel);

    myTopTabBar = new JTabbedPane();
    treeContainerPanel.add(myTopTabBar);
    myTopTabBar.setBorder(null);

    JPanel treeContainer = new JPanel();
    treeContainer.setLayout(new BorderLayout(0, 0));
    treeContainer.add(myTreeScrollPane);

    myTopTabBar.add("Message Tree", treeContainer);

    mytoolBar_1 = new JToolBar();
    mytoolBar_1.setFloatable(false);
    treeContainer.add(mytoolBar_1, BorderLayout.NORTH);

    mylabel_3 = new JLabel("Show");
    mytoolBar_1.add(mylabel_3);

    myShowCombo = new JComboBox();
    mytoolBar_1.add(myShowCombo);
    myShowCombo.setPreferredSize(new Dimension(130, 27));
    myShowCombo.setMinimumSize(new Dimension(130, 27));
    myShowCombo.setMaximumSize(new Dimension(130, 32767));

    collapseAllButton = new JButton();
    collapseAllButton.setBorderPainted(false);
    collapseAllButton.addMouseListener(new HoverButtonMouseAdapter(collapseAllButton));
    collapseAllButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myTreePanel.collapseAll();
        }
    });
    collapseAllButton.setToolTipText("Collapse All");
    collapseAllButton.setIcon(new ImageIcon(
            Hl7V2MessageEditorPanel.class.getResource("/ca/uhn/hl7v2/testpanel/images/collapse_all.png")));
    mytoolBar_1.add(collapseAllButton);

    expandAllButton = new JButton();
    expandAllButton.setBorderPainted(false);
    expandAllButton.addMouseListener(new HoverButtonMouseAdapter(expandAllButton));
    expandAllButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            myTreePanel.expandAll();
        }
    });
    expandAllButton.setToolTipText("Expand All");
    expandAllButton.setIcon(new ImageIcon(
            Hl7V2MessageEditorPanel.class.getResource("/ca/uhn/hl7v2/testpanel/images/expand_all.png")));
    mytoolBar_1.add(expandAllButton);

    myhorizontalGlue = Box.createHorizontalGlue();
    mytoolBar_1.add(myhorizontalGlue);

    mySpinner = new JButton("");
    mySpinner.setForeground(Color.DARK_GRAY);
    mySpinner.setHorizontalAlignment(SwingConstants.RIGHT);
    mySpinner.setMaximumSize(new Dimension(200, 15));
    mySpinner.setPreferredSize(new Dimension(200, 15));
    mySpinner.setMinimumSize(new Dimension(200, 15));
    mySpinner.setBorderPainted(false);
    mySpinner.setSize(new Dimension(16, 16));
    mytoolBar_1.add(mySpinner);
    myProfileComboboxModel = new ProfileComboModel();

    myTablesComboModel = new TablesComboModel(myController);

    mytoolBar = new JToolBar();
    mytoolBar.setFloatable(false);
    mytoolBar.setRollover(true);
    treeContainerPanel.add(mytoolBar, BorderLayout.NORTH);

    myOutboundInterfaceCombo = new JComboBox();
    myOutboundInterfaceComboModel = new DefaultComboBoxModel();

    mylabel_1 = new JLabel("Send");
    mytoolBar.add(mylabel_1);
    myOutboundInterfaceCombo.setModel(myOutboundInterfaceComboModel);
    myOutboundInterfaceCombo.setMaximumSize(new Dimension(200, 32767));
    mytoolBar.add(myOutboundInterfaceCombo);

    mySendButton = new JButton("Send");
    mySendButton.addMouseListener(new HoverButtonMouseAdapter(mySendButton));
    mySendButton.setBorderPainted(false);
    mySendButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // int selectedIndex =
            // myOutboundInterfaceComboModel.getIndexOf(myOutboundInterfaceComboModel.getSelectedItem());
            int selectedIndex = myOutboundInterfaceCombo.getSelectedIndex();
            OutboundConnection connection = myController.getOutboundConnectionList().getConnections()
                    .get(selectedIndex);
            activateSendingActivityTabForConnection(connection);
            myController.sendMessages(connection, myMessage,
                    mySendingActivityTable.provideTransmissionCallback());
        }
    });

    myhorizontalStrut_2 = Box.createHorizontalStrut(20);
    myhorizontalStrut_2.setPreferredSize(new Dimension(2, 0));
    myhorizontalStrut_2.setMinimumSize(new Dimension(2, 0));
    myhorizontalStrut_2.setMaximumSize(new Dimension(2, 32767));
    mytoolBar.add(myhorizontalStrut_2);

    mySendOptionsButton = new JButton("Options");
    mySendOptionsButton.setBorderPainted(false);
    final HoverButtonMouseAdapter sendOptionsHoverAdaptor = new HoverButtonMouseAdapter(mySendOptionsButton);
    mySendOptionsButton.addMouseListener(sendOptionsHoverAdaptor);
    mySendOptionsButton.setIcon(new ImageIcon(
            Hl7V2MessageEditorPanel.class.getResource("/ca/uhn/hl7v2/testpanel/images/sendoptions.png")));
    mytoolBar.add(mySendOptionsButton);
    mySendOptionsButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent theE) {
            if (mySendOptionsPopupDialog != null) {
                mySendOptionsPopupDialog.doHide();
                mySendOptionsPopupDialog = null;
                return;
            }
            mySendOptionsPopupDialog = new SendOptionsPopupDialog(Hl7V2MessageEditorPanel.this, myMessage,
                    mySendOptionsButton, sendOptionsHoverAdaptor);
            Point los = mySendOptionsButton.getLocationOnScreen();
            mySendOptionsPopupDialog.setLocation(los.x, los.y + mySendOptionsButton.getHeight());
            mySendOptionsPopupDialog.setVisible(true);
        }
    });

    mySendButton.setIcon(new ImageIcon(
            Hl7V2MessageEditorPanel.class.getResource("/ca/uhn/hl7v2/testpanel/images/button_execute.png")));
    mytoolBar.add(mySendButton);

    myhorizontalStrut_1 = Box.createHorizontalStrut(20);
    mytoolBar.add(myhorizontalStrut_1);

    mylabel_2 = new JLabel("Validate");
    mytoolBar.add(mylabel_2);

    myProfileCombobox = new JComboBox();
    mytoolBar.add(myProfileCombobox);
    myProfileCombobox.setPreferredSize(new Dimension(200, 27));
    myProfileCombobox.setMinimumSize(new Dimension(200, 27));
    myProfileCombobox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (myHandlingProfileComboboxChange) {
                return;
            }

            myHandlingProfileComboboxChange = true;
            try {
                if (myProfileCombobox.getSelectedIndex() == 0) {
                    myMessage.setValidationContext(null);
                } else if (myProfileCombobox.getSelectedIndex() == 1) {
                    myMessage.setValidationContext(new DefaultValidation());
                } else if (myProfileCombobox.getSelectedIndex() > 0) {
                    ProfileGroup profile = myProfileComboboxModel.myProfileGroups
                            .get(myProfileCombobox.getSelectedIndex());
                    myMessage.setRuntimeProfile(profile);

                    // } else if (myProfileCombobox.getSelectedItem() ==
                    // ProfileComboModel.APPLY_CONFORMANCE_PROFILE) {
                    // IOkCancelCallback<Void> callback = new
                    // IOkCancelCallback<Void>() {
                    // public void ok(Void theArg) {
                    // myProfileComboboxModel.update();
                    // }
                    //
                    // public void cancel(Void theArg) {
                    // myProfileCombobox.setSelectedIndex(0);
                    // }
                    // };
                    // myController.chooseAndLoadConformanceProfileForMessage(myMessage,
                    // callback);
                }
            } catch (ProfileException e2) {
                ourLog.error("Failed to load profile", e2);
            } finally {
                myHandlingProfileComboboxChange = false;
            }
        }
    });
    myProfileCombobox.setMaximumSize(new Dimension(300, 32767));
    myProfileCombobox.setModel(myProfileComboboxModel);

    myhorizontalStrut_4 = Box.createHorizontalStrut(20);
    myhorizontalStrut_4.setPreferredSize(new Dimension(2, 0));
    myhorizontalStrut_4.setMinimumSize(new Dimension(2, 0));
    myhorizontalStrut_4.setMaximumSize(new Dimension(2, 32767));
    mytoolBar.add(myhorizontalStrut_4);

    // mySendingPanel = new JPanel();
    // mySendingPanel.setBorder(null);
    // myTopTabBar.addTab("Sending", null, mySendingPanel, null);
    // mySendingPanel.setLayout(new BorderLayout(0, 0));

    mySendingActivityTable = new ActivityTable();
    mySendingActivityTable.setController(myController);
    myTopTabBar.addTab("Sending", null, mySendingActivityTable, null);

    // mySendingPanelScrollPanel = new JScrollPane();
    // mySendingPanelScrollPanel.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    // mySendingPanelScrollPanel.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    // mySendingPanelScrollPanel.setColumnHeaderView(mySendingActivityTable);
    //
    // mySendingPanel.add(mySendingPanelScrollPanel, BorderLayout.CENTER);

    bottomPanel = new JPanel();
    bottomPanel.setPreferredSize(new Dimension(10, 20));
    bottomPanel.setMinimumSize(new Dimension(10, 20));
    add(bottomPanel, BorderLayout.SOUTH);
    GridBagLayout gbl_bottomPanel = new GridBagLayout();
    gbl_bottomPanel.columnWidths = new int[] { 98, 74, 0 };
    gbl_bottomPanel.rowHeights = new int[] { 16, 0 };
    gbl_bottomPanel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    gbl_bottomPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
    bottomPanel.setLayout(gbl_bottomPanel);

    mylabel = new JLabel("Terser Path:");
    mylabel.setHorizontalTextPosition(SwingConstants.LEFT);
    mylabel.setHorizontalAlignment(SwingConstants.LEFT);
    GridBagConstraints gbc_label = new GridBagConstraints();
    gbc_label.fill = GridBagConstraints.VERTICAL;
    gbc_label.weighty = 1.0;
    gbc_label.anchor = GridBagConstraints.NORTHWEST;
    gbc_label.gridx = 0;
    gbc_label.gridy = 0;
    bottomPanel.add(mylabel, gbc_label);

    myTerserPathTextField = new JLabel();
    myTerserPathTextField.setForeground(Color.BLUE);
    myTerserPathTextField.setFont(new Font("Lucida Console", Font.PLAIN, 13));
    myTerserPathTextField.setBorder(null);
    myTerserPathTextField.setBackground(SystemColor.control);
    myTerserPathTextField.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (StringUtils.isNotEmpty(myTerserPathTextField.getText())) {
                myTerserPathPopupMenu.show(myTerserPathTextField, 0, 0);
            }
        }
    });

    GridBagConstraints gbc_TerserPathTextField = new GridBagConstraints();
    gbc_TerserPathTextField.weightx = 1.0;
    gbc_TerserPathTextField.fill = GridBagConstraints.HORIZONTAL;
    gbc_TerserPathTextField.gridx = 1;
    gbc_TerserPathTextField.gridy = 0;
    bottomPanel.add(myTerserPathTextField, gbc_TerserPathTextField);

    initLocal();

}

From source file:VASSAL.build.module.map.LOS_Thread.java

/**
 * Expects to be added to a {@link Map}.  Adds a button to the map
 * window's toolbar.  Pushing the button pushes a MouseListener
 * onto the Map that draws the thread.  Adds some entries to
 * preferences/* w  w w  . j av  a 2  s. c o m*/
 *
 * @see Map#pushMouseListener*/
public void addTo(Buildable b) {
    idMgr.add(this);
    map = (Map) b;
    map.getView().addMouseMotionListener(this);
    map.addDrawComponent(this);
    map.getToolBar().add(launch);
    GameModule.getGameModule().addCommandEncoder(this);
    GameModule.getGameModule().getPrefs().addOption(getConfigureName(),
            new BooleanConfigurer(SNAP_LOS, Resources.getString("LOS_Thread.snap_thread_preference")));

    if (fixedColor == null) {
        ColorConfigurer config = new ColorConfigurer(LOS_COLOR,
                Resources.getString("LOS_Thread.thread_color_preference"));
        GameModule.getGameModule().getPrefs().addOption(getConfigureName(), config);
        threadColor = (Color) GameModule.getGameModule().getPrefs().getValue(LOS_COLOR);
        config.addPropertyChangeListener(new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                threadColor = (Color) evt.getNewValue();
            }
        });
        config.fireUpdate();
    }
}