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.talend.designer.runprocess.ui.MemoryRuntimeComposite.java

private void addListeners() {
    runtimeButton.addSelectionListener(new SelectionAdapter() {

        @Override//  w  w  w . j  av a 2  s  . c o m
        public void widgetSelected(SelectionEvent event) {

            getRemoteStatus();

            if (lock && runtimeButton.getText().equals(Messages.getString("ProcessComposite.exec"))) { //$NON-NLS-1$
                MessageDialog.openWarning(getShell(), "Warning", //$NON-NLS-1$
                        Messages.getString("ProcessView.anotherJobMonitoring")); //$NON-NLS-1$
                return;
            }

            if (isCommandlineRun) {
                MessageDialog.openWarning(getShell(), "Warning", //$NON-NLS-1$
                        Messages.getString("ProcessView.commandlineForbidden")); //$NON-NLS-1$
                return;
            }

            if (isRemoteRun && !isRemoteMonitoring) {
                MessageDialog.openWarning(getShell(), "Warning", //$NON-NLS-1$
                        Messages.getString("ProcessView.remoteMonitoringUnavailable")); //$NON-NLS-1$
                return;
            }

            if (processContext != null && !processContext.isRunning()
                    && runtimeButton.getText().equals(Messages.getString("ProcessComposite.exec"))) { //$NON-NLS-1$
                runtimeButton.setEnabled(false);
                exec();
            }
            if (processContext != null && processContext.isRunning()) {
                if (runtimeButton.getText().equals(Messages.getString("ProcessComposite.exec"))) {//$NON-NLS-1$
                    if (!acquireJVM()) {
                        runtimeButton.setEnabled(true);
                        MessageDialog.openWarning(getShell(), "Warning", //$NON-NLS-1$
                                Messages.getString("ProcessView.noJobRunning")); //$NON-NLS-1$
                        return;
                    }
                    initMonitoringModel();
                    refreshMonitorComposite();
                    processContext.setMonitoring(true);
                    AbstractRuntimeGraphcsComposite.setMonitoring(true);
                    setRuntimeButtonByStatus(false);

                    if (periodCombo.isEnabled() && periodCombo.getSelectionIndex() != 0) {
                        startCustomerGCSchedule();
                    }
                    String content = getExecutionInfo("Start"); //$NON-NLS-1$
                    messageManager.setStartMessage(content, getDisplay().getSystemColor(SWT.COLOR_BLUE),
                            getDisplay().getSystemColor(SWT.COLOR_WHITE));
                    ((RuntimeGraphcsComposite) chartComposite).displayReportField();
                    lock = true;

                } else if (runtimeButton.getText().equals(Messages.getString("ProcessComposite.kill"))) { //$NON-NLS-1$
                    processContext.kill();
                }
            } else {
                MessageDialog.openWarning(getShell(), "Warning", //$NON-NLS-1$
                        Messages.getString("ProcessView.noJobRunning")); //$NON-NLS-1$
            }
            runtimeButton.setEnabled(true);
        }
    });

    gcCheckButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            isGCSelected = gcCheckButton.getSelection();
            periodCombo.setEnabled(isGCSelected);
            if (!isGCSelected) {
                periodCombo.select(0);
                if (processContext != null && processContext.isRunning()) {
                    // cancel GC timer task during job running.
                    doScheduledGc(0);
                }
            }
        }
    });

    periodCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            startCustomerGCSchedule();
        }

    });

    propertyChangeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            runProcessContextChanged(evt);
        }
    };

}

From source file:ome.formats.importer.gui.ImportDialog.java

/**
 * Dialog explaining metadata limitations when changing the main dialog's naming settings
 * /*from  ww w  .j a v  a 2 s.  c om*/
 * @param frame - parent component
 */
public void sendNamingWarning(Component frame) {
    final JOptionPane optionPane = new JOptionPane(
            "\nNOTE: Some file formats do not include the file name in their metadata, "
                    + "\nand disabling this option may result in files being imported without a "
                    + "\nreference to their file name. For example, 'myfile.lsm [image001]' "
                    + "\nwould show up as 'image001' with this optioned turned off.",
            JOptionPane.WARNING_MESSAGE);
    final JDialog warningDialog = new JDialog(this, "Naming Warning!", true);
    warningDialog.setContentPane(optionPane);

    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (warningDialog.isVisible() && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                warningDialog.dispose();
            }
        }
    });

    warningDialog.toFront();
    warningDialog.pack();
    warningDialog.setLocationRelativeTo(frame);
    warningDialog.setVisible(true);
}

From source file:components.DialogDemo.java

/** Creates the panel shown by the second tab. */
private JPanel createFeatureDialogBox() {
    final int numButtons = 5;
    JRadioButton[] radioButtons = new JRadioButton[numButtons];
    final ButtonGroup group = new ButtonGroup();

    JButton showItButton = null;/*from www.  ja v a  2 s .  c om*/

    final String pickOneCommand = "pickone";
    final String textEnteredCommand = "textfield";
    final String nonAutoCommand = "nonautooption";
    final String customOptionCommand = "customoption";
    final String nonModalCommand = "nonmodal";

    radioButtons[0] = new JRadioButton("Pick one of several choices");
    radioButtons[0].setActionCommand(pickOneCommand);

    radioButtons[1] = new JRadioButton("Enter some text");
    radioButtons[1].setActionCommand(textEnteredCommand);

    radioButtons[2] = new JRadioButton("Non-auto-closing dialog");
    radioButtons[2].setActionCommand(nonAutoCommand);

    radioButtons[3] = new JRadioButton("Input-validating dialog " + "(with custom message area)");
    radioButtons[3].setActionCommand(customOptionCommand);

    radioButtons[4] = new JRadioButton("Non-modal dialog");
    radioButtons[4].setActionCommand(nonModalCommand);

    for (int i = 0; i < numButtons; i++) {
        group.add(radioButtons[i]);
    }
    radioButtons[0].setSelected(true);

    showItButton = new JButton("Show it!");
    showItButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String command = group.getSelection().getActionCommand();

            //pick one of many
            if (command == pickOneCommand) {
                Object[] possibilities = { "ham", "spam", "yam" };
                String s = (String) JOptionPane.showInputDialog(frame,
                        "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE, icon, possibilities, "ham");

                //If a string was returned, say so.
                if ((s != null) && (s.length() > 0)) {
                    setLabel("Green eggs and... " + s + "!");
                    return;
                }

                //If you're here, the return value was null/empty.
                setLabel("Come on, finish the sentence!");

                //text input
            } else if (command == textEnteredCommand) {
                String s = (String) JOptionPane.showInputDialog(frame,
                        "Complete the sentence:\n" + "\"Green eggs and...\"", "Customized Dialog",
                        JOptionPane.PLAIN_MESSAGE, icon, null, "ham");

                //If a string was returned, say so.
                if ((s != null) && (s.length() > 0)) {
                    setLabel("Green eggs and... " + s + "!");
                    return;
                }

                //If you're here, the return value was null/empty.
                setLabel("Come on, finish the sentence!");

                //non-auto-closing dialog
            } else if (command == nonAutoCommand) {
                final JOptionPane optionPane = new JOptionPane(
                        "The only way to close this dialog is by\n" + "pressing one of the following buttons.\n"
                                + "Do you understand?",
                        JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);

                //You can't use pane.createDialog() because that
                //method sets up the JDialog with a property change
                //listener that automatically closes the window
                //when a button is clicked.
                final JDialog dialog = new JDialog(frame, "Click a button", true);
                dialog.setContentPane(optionPane);
                dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                dialog.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent we) {
                        setLabel("Thwarted user attempt to close window.");
                    }
                });
                optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                    public void propertyChange(PropertyChangeEvent e) {
                        String prop = e.getPropertyName();

                        if (dialog.isVisible() && (e.getSource() == optionPane)
                                && (JOptionPane.VALUE_PROPERTY.equals(prop))) {
                            //If you were going to check something
                            //before closing the window, you'd do
                            //it here.
                            dialog.setVisible(false);
                        }
                    }
                });
                dialog.pack();
                dialog.setLocationRelativeTo(frame);
                dialog.setVisible(true);

                int value = ((Integer) optionPane.getValue()).intValue();
                if (value == JOptionPane.YES_OPTION) {
                    setLabel("Good.");
                } else if (value == JOptionPane.NO_OPTION) {
                    setLabel("Try using the window decorations " + "to close the non-auto-closing dialog. "
                            + "You can't!");
                } else {
                    setLabel("Window unavoidably closed (ESC?).");
                }

                //non-auto-closing dialog with custom message area
                //NOTE: if you don't intend to check the input,
                //then just use showInputDialog instead.
            } else if (command == customOptionCommand) {
                customDialog.setLocationRelativeTo(frame);
                customDialog.setVisible(true);

                String s = customDialog.getValidatedText();
                if (s != null) {
                    //The text is valid.
                    setLabel("Congratulations!  " + "You entered \"" + s + "\".");
                }

                //non-modal dialog
            } else if (command == nonModalCommand) {
                //Create the dialog.
                final JDialog dialog = new JDialog(frame, "A Non-Modal Dialog");

                //Add contents to it. It must have a close button,
                //since some L&Fs (notably Java/Metal) don't provide one
                //in the window decorations for dialogs.
                JLabel label = new JLabel("<html><p align=center>" + "This is a non-modal dialog.<br>"
                        + "You can have one or more of these up<br>" + "and still use the main window.");
                label.setHorizontalAlignment(JLabel.CENTER);
                Font font = label.getFont();
                label.setFont(label.getFont().deriveFont(font.PLAIN, 14.0f));

                JButton closeButton = new JButton("Close");
                closeButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        dialog.setVisible(false);
                        dialog.dispose();
                    }
                });
                JPanel closePanel = new JPanel();
                closePanel.setLayout(new BoxLayout(closePanel, BoxLayout.LINE_AXIS));
                closePanel.add(Box.createHorizontalGlue());
                closePanel.add(closeButton);
                closePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5));

                JPanel contentPane = new JPanel(new BorderLayout());
                contentPane.add(label, BorderLayout.CENTER);
                contentPane.add(closePanel, BorderLayout.PAGE_END);
                contentPane.setOpaque(true);
                dialog.setContentPane(contentPane);

                //Show it.
                dialog.setSize(new Dimension(300, 150));
                dialog.setLocationRelativeTo(frame);
                dialog.setVisible(true);
            }
        }
    });

    return createPane(moreDialogDesc + ":", radioButtons, showItButton);
}

From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.JPanCodeMatchMain.java

/**
 * This method initializes jPanel1   /*  w  w  w.  j a v  a 2s.c o  m*/
 *    
 * @return javax.swing.JPanel   
 */
public JSplitPane getJSplitPaneSourceCode() {
    if (jSplitPaneSourceCode == null) {
        GridBagConstraints gridBagConstraints14 = new GridBagConstraints();
        gridBagConstraints14.fill = GridBagConstraints.BOTH;
        gridBagConstraints14.weighty = 1.0;
        gridBagConstraints14.weightx = 1.0;
        GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
        gridBagConstraints17.fill = GridBagConstraints.BOTH;
        gridBagConstraints17.weighty = 1.0;
        gridBagConstraints17.weightx = 1.0;
        jSplitPaneSourceCode = new JSplitPane();
        jSplitPaneSourceCode.setBorder(BorderFactory.createTitledBorder(null, "Source Code",
                TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
                new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
        jSplitPaneSourceCode.setDividerSize(5);
        jSplitPaneSourceCode.setLeftComponent(getJPanMatchedSourceViewLeft());
        jSplitPaneSourceCode.setRightComponent(getJPanMatchedSourceViewRight());

        PropertyChangeListener propertyChangeListener = new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent changeEvent) {
                String propertyName = changeEvent.getPropertyName();
                if (propertyName.equals(JSplitPane.LAST_DIVIDER_LOCATION_PROPERTY)) {
                    if (getSimilarSnippets() != null) {
                        setNavigator();
                    }
                }
            }
        };

        jSplitPaneSourceCode.addPropertyChangeListener(propertyChangeListener);
    }
    return jSplitPaneSourceCode;
}

From source file:org.apache.log4j.chainsaw.LogUI.java

/**
 * Creates, activates, and then shows the Chainsaw GUI, optionally showing
 * the splash screen, and using the passed shutdown action when the user
 * requests to exit the application (if null, then Chainsaw will exit the vm)
 *
 * @param model//  w w  w .j  ava2s.co  m
 * @param newShutdownAction
 *                    DOCUMENT ME!
 */
public static void createChainsawGUI(ApplicationPreferenceModel model, Action newShutdownAction) {

    if (model.isOkToRemoveSecurityManager()) {
        MessageCenter.getInstance()
                .addMessage("User has authorised removal of Java Security Manager via preferences");
        System.setSecurityManager(null);
        // this SHOULD set the Policy/Permission stuff for any
        // code loaded from our custom classloader.  
        // crossing fingers...
        Policy.setPolicy(new Policy() {

            public void refresh() {
            }

            public PermissionCollection getPermissions(CodeSource codesource) {
                Permissions perms = new Permissions();
                perms.add(new AllPermission());
                return (perms);
            }
        });
    }

    final LogUI logUI = new LogUI();
    logUI.applicationPreferenceModel = model;

    if (model.isShowSplash()) {
        showSplash(logUI);
    }
    logUI.cyclicBufferSize = model.getCyclicBufferSize();
    logUI.pluginRegistry = repositoryExImpl.getPluginRegistry();

    logUI.handler = new ChainsawAppenderHandler();
    logUI.handler.addEventBatchListener(logUI.new NewTabEventBatchReceiver());

    /**
     * TODO until we work out how JoranConfigurator might be able to have
     * configurable class loader, if at all.  For now we temporarily replace the
     * TCCL so that Plugins that need access to resources in 
     * the Plugins directory can find them (this is particularly
     * important for the Web start version of Chainsaw
     */
    //configuration initialized here
    logUI.ensureChainsawAppenderHandlerAdded();
    logger = LogManager.getLogger(LogUI.class);

    //set hostname, application and group properties which will cause Chainsaw and other apache-generated
    //logging events to route (by default) to a tab named 'chainsaw-log'
    PropertyRewritePolicy policy = new PropertyRewritePolicy();
    policy.setProperties("hostname=chainsaw,application=log,group=chainsaw");

    RewriteAppender rewriteAppender = new RewriteAppender();
    rewriteAppender.setRewritePolicy(policy);

    Enumeration appenders = Logger.getLogger("org.apache").getAllAppenders();
    if (!appenders.hasMoreElements()) {
        appenders = Logger.getRootLogger().getAllAppenders();
    }
    while (appenders.hasMoreElements()) {
        Appender nextAppender = (Appender) appenders.nextElement();
        rewriteAppender.addAppender(nextAppender);
    }
    Logger.getLogger("org.apache").removeAllAppenders();
    Logger.getLogger("org.apache").addAppender(rewriteAppender);
    Logger.getLogger("org.apache").setAdditivity(false);

    //commons-vfs uses httpclient for http filesystem support, route this to the chainsaw-log tab as well
    appenders = Logger.getLogger("httpclient").getAllAppenders();
    if (!appenders.hasMoreElements()) {
        appenders = Logger.getRootLogger().getAllAppenders();
    }
    while (appenders.hasMoreElements()) {
        Appender nextAppender = (Appender) appenders.nextElement();
        rewriteAppender.addAppender(nextAppender);
    }
    Logger.getLogger("httpclient").removeAllAppenders();
    Logger.getLogger("httpclient").addAppender(rewriteAppender);
    Logger.getLogger("httpclient").setAdditivity(false);

    //set the commons.vfs.cache logger to info, since it can contain password information
    Logger.getLogger("org.apache.commons.vfs.cache").setLevel(Level.INFO);

    Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable e) {
            e.printStackTrace();
            logger.error("Uncaught exception in thread " + t, e);
        }
    });

    String config = configurationURLAppArg;
    if (config != null) {
        logger.info("Command-line configuration arg provided (overriding auto-configuration URL) - using: "
                + config);
    } else {
        config = model.getConfigurationURL();
    }

    if (config != null && (!config.trim().equals(""))) {
        config = config.trim();
        try {
            URL configURL = new URL(config);
            logger.info("Using '" + config + "' for auto-configuration");
            logUI.loadConfigurationUsingPluginClassLoader(configURL);
        } catch (MalformedURLException e) {
            logger.error("Initial configuration - failed to convert config string to url", e);
        } catch (IOException e) {
            logger.error("Unable to access auto-configuration URL: " + config);
        }
    }

    //register a listener to load the configuration when it changes (avoid having to restart Chainsaw when applying a new configuration)
    //this doesn't remove receivers from receivers panel, it just triggers DOMConfigurator.configure.
    model.addPropertyChangeListener("configurationURL", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            String newConfiguration = evt.getNewValue().toString();
            if (newConfiguration != null && !(newConfiguration.trim().equals(""))) {
                newConfiguration = newConfiguration.trim();
                try {
                    logger.info("loading updated configuration: " + newConfiguration);
                    URL newConfigurationURL = new URL(newConfiguration);
                    File file = new File(newConfigurationURL.toURI());
                    if (file.exists()) {
                        logUI.loadConfigurationUsingPluginClassLoader(newConfigurationURL);
                    } else {
                        logger.info("Updated configuration but file does not exist");
                    }
                } catch (MalformedURLException e) {
                    logger.error("Updated configuration - failed to convert config string to URL", e);
                } catch (URISyntaxException e) {
                    logger.error("Updated configuration - failed to convert config string to URL", e);
                }
            }
        }
    });

    LogManager.getRootLogger().setLevel(Level.TRACE);
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            logUI.activateViewer();
        }
    });

    logger.info("SecurityManager is now: " + System.getSecurityManager());

    if (newShutdownAction != null) {
        logUI.setShutdownAction(newShutdownAction);
    } else {
        logUI.setShutdownAction(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
    }
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditorControl.java

/** Brings up the folder chooser to select where to save the files. 
 * /*  w  w w  .ja  v a 2s .c  om*/
 * @param format One of the formats defined by <code>FigureParam</code>.
 * @see org.openmicroscopy.shoola.env.data.model.FigureParam
 */
void saveAs(final int format) {
    String v = FigureParam.FORMATS.get(format);
    JFrame f = MetadataViewerAgent.getRegistry().getTaskBar().getFrame();
    List<FileFilter> filters = new ArrayList<FileFilter>();
    switch (format) {
    case FigureParam.JPEG:
        filters.add(new JPEGFilter());
        break;
    case FigureParam.PNG:
        filters.add(new PNGFilter());
        break;
    case FigureParam.TIFF:
        filters.add(new TIFFFilter());
    }
    FileChooser chooser = new FileChooser(f, FileChooser.FOLDER_CHOOSER, "Save As",
            "Select where to save locally the images as " + v, filters);
    try {
        File file = UIUtilities.getDefaultFolder();
        if (file != null)
            chooser.setCurrentDirectory(file);
    } catch (Exception ex) {
    }
    String s = UIUtilities.removeFileExtension(view.getRefObjectName());
    if (s != null && s.trim().length() > 0)
        chooser.setSelectedFile(s);
    chooser.setApproveButtonText("Save");
    IconManager icons = IconManager.getInstance();
    chooser.setTitleIcon(icons.getIcon(IconManager.SAVE_AS_48));
    chooser.addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            String name = evt.getPropertyName();
            if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) {
                String value = (String) evt.getNewValue();
                File folder = null;
                if (StringUtils.isEmpty(value))
                    folder = UIUtilities.getDefaultFolder();
                else
                    folder = new File(value);
                Object src = evt.getSource();
                if (src instanceof FileChooser) {
                    ((FileChooser) src).setVisible(false);
                    ((FileChooser) src).dispose();
                }
                model.saveAs(folder, format);
            }
        }
    });
    chooser.centerDialog();
}

From source file:com.leclercb.taskunifier.gui.main.Main.java

private static void loadProxies() {
    boolean p = SETTINGS.getBooleanProperty("proxy.use_system_proxies");
    System.setProperty("java.net.useSystemProxies", p + "");

    SETTINGS.addPropertyChangeListener("proxy.use_system_proxies", new PropertyChangeListener() {

        @Override// ww w . ja v a 2s .  co  m
        public void propertyChange(PropertyChangeEvent evt) {
            boolean p = SETTINGS.getBooleanProperty("proxy.use_system_proxies");
            System.setProperty("java.net.useSystemProxies", p + "");
        }

    });
}

From source file:org.myrobotlab.service.MarySpeech.java

private void showProgressPanel(List<ComponentDescription> comps, boolean install) {
    final ProgressPanel pp = new ProgressPanel(comps, install);
    final JOptionPane optionPane = new JOptionPane(pp, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION,
            null, new String[] { "Abort" }, "Abort");
    // optionPane.setPreferredSize(new Dimension(640,480));
    final JDialog dialog = new JDialog((Frame) null, "Progress", false);
    dialog.setContentPane(optionPane);/*from www . ja  v  a  2 s.  c o m*/
    optionPane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent e) {
            String prop = e.getPropertyName();

            if (dialog.isVisible() && (e.getSource() == optionPane)
                    && (prop.equals(JOptionPane.VALUE_PROPERTY))) {
                pp.requestExit();
                dialog.setVisible(false);
            }
        }
    });
    dialog.pack();
    dialog.setVisible(true);
    new Thread(pp).start();
}

From source file:org.talend.designer.runprocess.ui.DebugProcessTosComposite.java

/**
 * DOC Administrator DebugProcessComposite constructor comment.
 * /*ww w . j a va 2  s . c o  m*/
 * @param parent
 * @param style
 */
public DebugProcessTosComposite(Composite parent, int style) {
    super(parent, style);
    setExpandHorizontal(true);
    setExpandVertical(true);
    this.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));

    FormData layouData = new FormData();
    layouData.left = new FormAttachment(0, 0);
    layouData.right = new FormAttachment(100, 0);
    layouData.top = new FormAttachment(0, 0);
    layouData.bottom = new FormAttachment(100, 0);
    setLayoutData(layouData);

    this.setLayout(new FormLayout());
    final Composite panel = new Composite(this, SWT.NONE);
    setContent(panel);
    // panel.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_RED));
    FormLayout layout = new FormLayout();
    layout.marginWidth = 5 + 2;
    layout.marginHeight = 4;
    layout.spacing = 6 + 1;
    panel.setLayout(layout);

    Group execGroup = new Group(panel, SWT.NONE);
    execGroup.setText("Debug"); //$NON-NLS-1$
    GridLayout layout5 = new GridLayout();
    layout5.marginHeight = 0;
    layout5.marginWidth = 0;
    execGroup.setLayout(layout5);

    FormData layouDatag = new FormData();
    layouDatag.left = new FormAttachment(0, 0);
    layouDatag.right = new FormAttachment(100, 0);
    layouDatag.top = new FormAttachment(0, 0);
    layouDatag.bottom = new FormAttachment(100, 0);
    execGroup.setLayoutData(layouDatag);

    ScrolledComposite execScroll = new ScrolledComposite(execGroup, SWT.V_SCROLL | SWT.H_SCROLL);
    execScroll.setExpandHorizontal(true);
    execScroll.setExpandVertical(true);
    execScroll.setLayoutData(new GridData(GridData.FILL_BOTH));

    Composite execContent = new Composite(execScroll, SWT.NONE);
    execContent.setLayout(new FormLayout());
    execScroll.setContent(execContent);

    Composite execHeader = new Composite(execContent, SWT.NONE);
    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = 7;
    formLayout.marginHeight = 4;
    formLayout.spacing = 7;
    execHeader.setLayout(formLayout);

    FormData layoutData = new FormData();
    layoutData.left = new FormAttachment(0, 0);
    layoutData.right = new FormAttachment(100, 0);
    layoutData.top = new FormAttachment(0, 0);
    layoutData.bottom = new FormAttachment(0, 50);
    execHeader.setLayoutData(layoutData);

    Composite toolBarComposite = new Composite(execHeader, SWT.NONE);
    toolBarComposite.setLayout(new FillLayout());

    toolBar = new ToolBar(toolBarComposite, SWT.FLAT | SWT.RIGHT);

    itemDropDown = new ToolItem(toolBar, SWT.ARROW);
    itemDropDown.setText(Messages.getString("ProcessComposite.traceDebug"));//$NON-NLS-1$
    itemDropDown.setData(ProcessView.TRACEDEBUG_ID);
    itemDropDown.setToolTipText(Messages.getString("ProcessComposite.traceDebug"));//$NON-NLS-1$
    itemDropDown.setImage(ImageProvider.getImage(ERunprocessImages.DEBUG_TRACE_ACTION));

    menu = new Menu(execHeader);
    itemDropDown.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            if (event.detail == SWT.ARROW) {
                Rectangle bounds = itemDropDown.getBounds();
                Point point = toolBar.toDisplay(bounds.x, bounds.y + bounds.height);
                menu.setLocation(point);
                menu.setVisible(true);
            } else {
                ToolItem item = (ToolItem) event.widget;
                errorMessMap.clear();
                if (item.getData().equals(ProcessView.DEBUG_ID)) {
                    debug();
                } else /* if (item.getData().equals(ProcessView.TRACEDEBUG_ID)) */ {
                    execButtonPressed();
                }
            }
        }
    });

    // debug
    final MenuItem menuItem1 = new MenuItem(menu, SWT.PUSH);
    menuItem1.setText(" " + Messages.getString("ProcessDebugDialog.javaDebug"));//$NON-NLS-1$//$NON-NLS-2$
    menuItem1.setImage(ImageProvider.getImage(ERunprocessImages.DEBUG_PROCESS_ACTION));
    menuItem1.setData(ProcessView.DEBUG_ID);
    menuItem1.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent event) {
            if (!itemDropDown.getData().equals(ProcessView.PAUSE_ID)
                    && !itemDropDown.getData().equals(ProcessView.RESUME_ID)) {
                itemDropDown.setText(menuItem1.getText());
                itemDropDown.setData(ProcessView.DEBUG_ID);
                itemDropDown.setImage(ImageProvider.getImage(ERunprocessImages.DEBUG_PROCESS_ACTION));
                itemDropDown.setToolTipText(Messages.getString("ProcessDebugDialog.javaDebug"));//$NON-NLS-1$
                toolBar.getParent().getParent().layout();
                manager.setBooleanTrace(false);
                addTrace(ProcessView.DEBUG_ID);
            }
        }
    });
    IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault()
            .getService(IBrandingService.class);
    if (brandingService.getBrandingConfiguration().isAllowDebugMode()) {
        // trace
        debugMenuItem = new MenuItem(menu, SWT.PUSH);
        debugMenuItem.setText(" " + Messages.getString("ProcessComposite.traceDebug")); //$NON-NLS-1$//$NON-NLS-2$
        debugMenuItem.setData(ProcessView.TRACEDEBUG_ID);
        debugMenuItem.setImage(ImageProvider.getImage(ERunprocessImages.DEBUG_TRACE_ACTION));
        debugMenuItem.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                if (!itemDropDown.getData().equals(ProcessView.PAUSE_ID)
                        && !itemDropDown.getData().equals(ProcessView.RESUME_ID)) {
                    itemDropDown.setText(debugMenuItem.getText());
                    itemDropDown.setData(ProcessView.TRACEDEBUG_ID);
                    itemDropDown.setImage(ImageProvider.getImage(ERunprocessImages.DEBUG_TRACE_ACTION));
                    itemDropDown.setToolTipText(Messages.getString("ProcessComposite.traceDebug"));//$NON-NLS-1$
                    toolBar.getParent().getParent().layout();
                    manager.setBooleanTrace(true);
                    addTrace(ProcessView.TRACEDEBUG_ID);

                }

            }
        });
    }
    toolBar.setEnabled(false);
    // see the feature 6366,qli comment.
    // make a judge when the text change in diffrent languages.
    // changed to use FillLayout to resolve this problem, see TDI-28943
    if (brandingService.getBrandingConfiguration().isAllowDebugMode()) {
        itemDropDown.setText(debugMenuItem.getText());
    } else {
        itemDropDown.setText(menuItem1.getText());
    }

    killBtn = new Button(execHeader, SWT.PUSH);
    killBtn.setText(Messages.getString("ProcessComposite.kill")); //$NON-NLS-1$
    killBtn.setToolTipText(Messages.getString("ProcessComposite.killHint")); //$NON-NLS-1$
    killBtn.setImage(ImageProvider.getImage(ERunprocessImages.KILL_PROCESS_ACTION));
    // setButtonLayoutData(killBtn);
    killBtn.setEnabled(false);
    FormData formDatap = new FormData();
    formDatap.left = new FormAttachment(toolBarComposite, 0, SWT.RIGHT);
    formDatap.width = 80;
    formDatap.top = new FormAttachment(toolBarComposite, 0, SWT.CENTER);
    // formDatap.bottom = new FormAttachment(0, 30);
    formDatap.height = 30;
    killBtn.setLayoutData(formDatap);
    clearTracePerfBtn = new Button(execHeader, SWT.PUSH);
    clearTracePerfBtn.setText(Messages.getString("ProcessComposite.clear")); //$NON-NLS-1$
    clearTracePerfBtn.setToolTipText(Messages.getString("ProcessComposite.clearHint")); //$NON-NLS-1$
    clearTracePerfBtn.setImage(ImageProvider.getImage(RunProcessPlugin
            .imageDescriptorFromPlugin(RunProcessPlugin.PLUGIN_ID, "icons/process_stat_clear.gif"))); //$NON-NLS-1$
    clearTracePerfBtn.setEnabled(false);
    formDatap = new FormData();
    formDatap.left = new FormAttachment(killBtn, 0, SWT.RIGHT);
    formDatap.width = 80;
    formDatap.top = new FormAttachment(toolBarComposite, 0, SWT.CENTER);
    // formDatap.bottom = new FormAttachment(0, 30);
    formDatap.height = 30;
    clearTracePerfBtn.setLayoutData(formDatap);
    consoleText = new StyledText(execContent, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
    FormData formDataco = new FormData();
    formDataco.top = new FormAttachment(0, 50);
    formDataco.left = new FormAttachment(0, 10);
    formDataco.right = new FormAttachment(100, 0);
    formDataco.bottom = new FormAttachment(100, -30);
    consoleText.setLayoutData(formDataco);
    // feature 6875, add searching capability, nma
    consoleText.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent evt) {
            // select all
            if ((evt.stateMask == SWT.CTRL) && (evt.keyCode == 'a')) {
                if (consoleText.getText().length() > 0) {
                    consoleText.setSelection(0, (consoleText.getText().length() - 1));
                }
            }
            // search special string value
            else if ((evt.stateMask == SWT.CTRL) && (evt.keyCode == 'f')) {
                FindDialog td = new FindDialog(Display.getCurrent().getActiveShell());
                td.setConsoleText(consoleText);
                td.setBlockOnOpen(true);
                td.open();

            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {

        }
    });
    if (!setConsoleFont()) {
        Font font = new Font(parent.getDisplay(), "courier", 8, SWT.NONE); //$NON-NLS-1$
        consoleText.setFont(font);
    }

    // sash.setSashWidth(1);
    // sash.setWeights(new int[] { 7, 1, H_WEIGHT });

    pcl = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            runProcessContextChanged(evt);
        }
    };
    streamListener = new IStreamListener() {

        @Override
        public void streamAppended(String text, IStreamMonitor monitor) {
            IProcessMessage message = new ProcessMessage(ProcessMessage.MsgType.STD_OUT, text);
            processContext.addDebugResultToConsole(message);
        }
    };
    addListeners();
    createLineLimitedControl(execContent);
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelTesting.java

/**
 * Adds event-listeners to the project's combobox.
 *///from ww w  . ja v a2 s  .c o m
protected void addEventListener() {
    comboBoxProjects.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            boolean b = false;
            Color c = null;
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    b = true;
                    c = Color.WHITE;
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    comboBoxRoom1.removeAllItems();
                    comboBoxRoom2.removeAllItems();
                    comboBoxRoom3.removeAllItems();
                    comboBoxRoom4.removeAllItems();
                    comboBoxRoom5.removeAllItems();
                    comboBoxRoom6.removeAllItems();
                    comboBoxRoom7.removeAllItems();
                    for (int i = 0; i < building.getRooms().length; i++) {
                        comboBoxRoom1.addItem(building.getRooms()[i]);
                        comboBoxRoom2.addItem(building.getRooms()[i]);
                        comboBoxRoom3.addItem(building.getRooms()[i]);
                        comboBoxRoom4.addItem(building.getRooms()[i]);
                        comboBoxRoom5.addItem(building.getRooms()[i]);
                        comboBoxRoom6.addItem(building.getRooms()[i]);
                        comboBoxRoom7.addItem(building.getRooms()[i]);
                    }
                    for (int i = 0; i < building.getCellars().length; i++) {
                        comboBoxRoom1.addItem(building.getCellars()[i]);
                        comboBoxRoom2.addItem(building.getCellars()[i]);
                        comboBoxRoom3.addItem(building.getCellars()[i]);
                        comboBoxRoom4.addItem(building.getCellars()[i]);
                        comboBoxRoom5.addItem(building.getCellars()[i]);
                        comboBoxRoom6.addItem(building.getCellars()[i]);
                        comboBoxRoom7.addItem(building.getCellars()[i]);
                    }
                    comboBoxRoom7.setSelectedIndex(comboBoxRoom7.getItemCount() - 1);
                    sliderStartTime.setMaximum(building.getValueCount() - 168);
                    spnrStartTime.setModel(new SpinnerNumberModel(0, 0, building.getValueCount() - 168, 1));
                } else {
                    b = false;
                    c = null;
                }
            } else {
                b = false;
                c = null;
            }
            lblSelectRooms.setEnabled(b);
            lblStartTime.setEnabled(b);
            panelCampaign.setEnabled(b);
            btnMaximize.setVisible(isSimulated);
            btnPdf.setVisible(isSimulated);
            btnCsv.setVisible(isSimulated);
            lblExportChartTo.setVisible(isSimulated);
            sliderStartTime.setEnabled(b);
            spnrStartTime.setEnabled(b);
            comboBoxRoom1.setEnabled(b);
            comboBoxRoom2.setEnabled(b);
            comboBoxRoom3.setEnabled(b);
            comboBoxRoom4.setEnabled(b);
            comboBoxRoom5.setEnabled(b);
            comboBoxRoom6.setEnabled(b);
            comboBoxRoom7.setEnabled(b);
            panelCampaign.setBackground(c);
        }
    });
    comboBoxProjects.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            boolean b = false;
            Color c = null;
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    b = true;
                    c = Color.WHITE;
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    comboBoxRoom1.removeAllItems();
                    comboBoxRoom2.removeAllItems();
                    comboBoxRoom3.removeAllItems();
                    comboBoxRoom4.removeAllItems();
                    comboBoxRoom5.removeAllItems();
                    comboBoxRoom6.removeAllItems();
                    comboBoxRoom7.removeAllItems();
                    for (int i = 0; i < building.getRooms().length; i++) {
                        comboBoxRoom1.addItem(building.getRooms()[i]);
                        comboBoxRoom2.addItem(building.getRooms()[i]);
                        comboBoxRoom3.addItem(building.getRooms()[i]);
                        comboBoxRoom4.addItem(building.getRooms()[i]);
                        comboBoxRoom5.addItem(building.getRooms()[i]);
                        comboBoxRoom6.addItem(building.getRooms()[i]);
                        comboBoxRoom7.addItem(building.getRooms()[i]);
                    }
                    for (int i = 0; i < building.getCellars().length; i++) {
                        comboBoxRoom1.addItem(building.getCellars()[i]);
                        comboBoxRoom2.addItem(building.getCellars()[i]);
                        comboBoxRoom3.addItem(building.getCellars()[i]);
                        comboBoxRoom4.addItem(building.getCellars()[i]);
                        comboBoxRoom5.addItem(building.getCellars()[i]);
                        comboBoxRoom6.addItem(building.getCellars()[i]);
                        comboBoxRoom7.addItem(building.getCellars()[i]);
                    }
                    comboBoxRoom7.setSelectedIndex(comboBoxRoom7.getItemCount() - 1);
                    sliderStartTime.setMaximum(building.getValueCount() - 168);
                    spnrStartTime.setModel(new SpinnerNumberModel(0, 0, building.getValueCount() - 168, 1));
                } else {
                    b = false;
                    c = null;
                }
            } else {
                b = false;
                c = null;
            }
            lblSelectRooms.setEnabled(b);
            lblStartTime.setEnabled(b);
            panelCampaign.setEnabled(b);
            btnMaximize.setVisible(isSimulated);
            btnPdf.setVisible(isSimulated);
            btnCsv.setVisible(isSimulated);
            lblExportChartTo.setVisible(isSimulated);
            sliderStartTime.setEnabled(b);
            spnrStartTime.setEnabled(b);
            comboBoxRoom1.setEnabled(b);
            comboBoxRoom2.setEnabled(b);
            comboBoxRoom3.setEnabled(b);
            comboBoxRoom4.setEnabled(b);
            comboBoxRoom5.setEnabled(b);
            comboBoxRoom6.setEnabled(b);
            comboBoxRoom7.setEnabled(b);
            panelCampaign.setBackground(c);
        }
    });
}