Example usage for javax.swing.border EmptyBorder EmptyBorder

List of usage examples for javax.swing.border EmptyBorder EmptyBorder

Introduction

In this page you can find the example usage for javax.swing.border EmptyBorder EmptyBorder.

Prototype

public EmptyBorder(int top, int left, int bottom, int right) 

Source Link

Document

Creates an empty border with the specified insets.

Usage

From source file:org.datacleaner.windows.AnalysisJobBuilderWindowImpl.java

private JComponent getWindowPanelContent() {
    if (_datastore != null) {
        setDatastore(_datastore);/*from w  w  w.j a va2 s.c  o m*/
    }

    final SaveAnalysisJobActionListener saveAnalysisJobActionListener = _saveAnalysisJobActionListenerProvider
            .get();
    _saveButton.addActionListener(saveAnalysisJobActionListener);
    _saveAsButton.addActionListener(saveAnalysisJobActionListener);
    _saveAsButton.setActionCommand(SaveAnalysisJobActionListener.ACTION_COMMAND_SAVE_AS);

    // Run analysis
    _executeButton.addActionListener(execute(_analysisJobBuilder));

    _executionAlternativesButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final JMenuItem executeNormallyMenutItem = WidgetFactory.createMenuItem("Run normally",
                    IconUtils.ACTION_EXECUTE);
            executeNormallyMenutItem.addActionListener(execute(_analysisJobBuilder));

            final JMenuItem executePreviewMenuItem = WidgetFactory.createMenuItem("Run first N records",
                    IconUtils.ACTION_PREVIEW);
            executePreviewMenuItem.addActionListener(executePreview());

            final JMenuItem executeSingleThreadedMenuItem = WidgetFactory.createMenuItem("Run single-threaded",
                    IconUtils.MODEL_ROW);
            executeSingleThreadedMenuItem.addActionListener(executeSingleThreaded());

            final JPopupMenu menu = new JPopupMenu();
            menu.add(executeNormallyMenutItem);
            menu.addSeparator();
            menu.add(executePreviewMenuItem);
            menu.add(executeSingleThreadedMenuItem);

            final int horizontalPosition = -1 * menu.getPreferredSize().width
                    + _executionAlternativesButton.getWidth();
            menu.show(_executionAlternativesButton, horizontalPosition,
                    _executionAlternativesButton.getHeight());
        }
    });

    final JButton newJobButton = createToolbarButton("New", IconUtils.MENU_NEW);
    newJobButton.addActionListener(_newAnalysisJobActionListenerProvider.get());

    final JButton openJobButton = createToolbarButton("Open", IconUtils.MENU_OPEN);
    openJobButton.addActionListener(_openAnalysisJobActionListenerProvider.get());

    final JToggleButton moreButton = createMoreMenuButton();

    final JButton logoButton = new JButton(imageManager.getImageIcon("images/menu/dc-logo-30.png"));
    logoButton.setToolTipText("About DataCleaner");
    logoButton.setBorder(new EmptyBorder(0, 4, 0, 10));
    logoButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new AboutDialog(getWindowContext()).open();
        }
    });

    final JToolBar toolBar = WidgetFactory.createToolBar();
    toolBar.add(logoButton);
    toolBar.add(newJobButton);
    toolBar.add(openJobButton);
    toolBar.add(_saveButton);
    toolBar.add(_saveAsButton);
    toolBar.add(DCLabel.bright(" | "));
    toolBar.add(moreButton);

    toolBar.add(WidgetFactory.createToolBarSeparator());
    toolBar.add(_executeButton);
    toolBar.add(DCLabel.bright("|"));
    toolBar.add(_executionAlternativesButton);

    final JXStatusBar statusBar = WidgetFactory.createStatusBar(_statusLabel);
    statusBar.add(_classicViewButton);
    statusBar.add(_graphViewButton);
    statusBar.add(Box.createHorizontalStrut(10));

    final LicenceAndEditionStatusLabel statusLabel = new LicenceAndEditionStatusLabel(_glassPane);
    statusBar.add(statusLabel);

    final DCPanel toolBarPanel = new DCPanel(WidgetUtils.BG_COLOR_DARK);
    toolBarPanel.setLayout(new BorderLayout());
    toolBarPanel.add(toolBar, BorderLayout.CENTER);

    final DCPanel panel = new DCPersistentSizedPanel(_windowSizePreference);
    panel.setLayout(new BorderLayout());
    panel.add(toolBarPanel, BorderLayout.NORTH);
    panel.add(_leftPanel, BorderLayout.WEST);

    // newPanel.add(_tabbedPane, BorderLayout.NORTH);
    panel.add(_contentContainerPanel, BorderLayout.CENTER);

    panel.add(statusBar, BorderLayout.SOUTH);

    // invoke to trigger enablement/disablement of buttons.
    onSourceColumnsChanged();
    updateStatusLabel();

    WidgetUtils.centerOnScreen(this);
    return panel;
}

From source file:org.datacleaner.windows.AnalysisJobBuilderWindowImpl.java

private void applyMenuPopupButttonStyling(PopupButton popupButton) {
    popupButton.setBorder(new EmptyBorder(10, 4, 10, 4));
    popupButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    popupButton.setFocusPainted(false);/*  w w w  .j  av  a2  s .c om*/
    WidgetUtils.setDarkButtonStyle(popupButton);
    popupButton.setHorizontalTextPosition(SwingConstants.LEFT);
}

From source file:org.datacleaner.windows.AnalysisJobBuilderWindowImpl.java

private JToggleButton createViewToggleButton(final String text, final String iconPath) {
    final ImageIcon icon = imageManager.getImageIcon(iconPath);
    final JToggleButton button = new JToggleButton(text, icon);
    button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    button.setFont(WidgetUtils.FONT_SMALL);
    button.setForeground(WidgetUtils.BG_COLOR_BRIGHTEST);
    button.setBackground(WidgetUtils.BG_COLOR_DARK);
    button.setBorderPainted(false);//from  ww w. jav a2s . c o m
    button.setBorder(new CompoundBorder(WidgetUtils.BORDER_THIN, new EmptyBorder(0, 4, 0, 4)));
    return button;
}

From source file:org.datacleaner.windows.DataHubDatastoreDialog.java

@Inject
public DataHubDatastoreDialog(WindowContext windowContext, MutableDatastoreCatalog datastoreCatalog,
        @Nullable DataHubDatastore originalDatastore, UserPreferences userPreferences) {
    super(originalDatastore, datastoreCatalog, windowContext, userPreferences);

    _hostTextField = WidgetFactory.createTextField("Hostname");
    _portTextField = WidgetFactory.createTextField("Port");
    _usernameTextField = WidgetFactory.createTextField("Username");
    _passwordTextField = WidgetFactory.createPasswordField();
    // _contextPathTextField =
    // WidgetFactory.createTextField("Context path");
    _securityModeSelector = new JComboBox<>(
            new String[] { DataHubSecurityMode.DEFAULT.toString(), DataHubSecurityMode.CAS.toString() });
    _securityModeSelector.setEditable(false);

    _urlLabel = DCLabel.bright("");
    _urlLabel.setForeground(WidgetUtils.BG_COLOR_LESS_BRIGHT);
    _urlLabel.setBorder(new EmptyBorder(5, 0, 5, 0));

    final DCDocumentListener genericDocumentListener = new DCDocumentListener() {
        @Override/*from w  w  w. jav a2  s. c o m*/
        protected void onChange(DocumentEvent event) {
            validateAndUpdate();
            updateUrlLabel();
        }
    };

    _httpsCheckBox = new JCheckBox("Use HTTPS?", false);
    _httpsCheckBox.setOpaque(false);
    _httpsCheckBox.setForeground(WidgetUtils.BG_COLOR_BRIGHTEST);
    _httpsCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            updateUrlLabel();
            validateAndUpdate();
        }
    });

    _acceptUnverifiedSslPeersCheckBox = new JCheckBox("Accept unverified SSL peers?", false);
    _acceptUnverifiedSslPeersCheckBox.setOpaque(false);
    _acceptUnverifiedSslPeersCheckBox.setForeground(WidgetUtils.BG_COLOR_BRIGHTEST);
    _acceptUnverifiedSslPeersCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            validateAndUpdate();
        }
    });

    _hostTextField.getDocument().addDocumentListener(genericDocumentListener);
    _portTextField.getDocument().addDocumentListener(genericDocumentListener);
    _usernameTextField.getDocument().addDocumentListener(genericDocumentListener);
    _passwordTextField.getDocument().addDocumentListener(genericDocumentListener);
    _securityModeSelector.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            validateAndUpdate();
            updateUrlLabel();
        }

    });

    _testButton = WidgetFactory.createDefaultButton("Test connection", IconUtils.ACTION_REFRESH);
    _testButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            final DataHubRepoConnection connection = createConnection();
            final String getTenantInfoUrl = connection.getUserInfoUrl();
            final HttpGet request = new HttpGet(getTenantInfoUrl);
            try (final MonitorHttpClient monitorHttpClient = connection.getHttpClient()) {
                final HttpResponse response = monitorHttpClient.execute(request);

                final StatusLine statusLine = response.getStatusLine();

                if (statusLine.getStatusCode() == HttpStatus.SC_OK
                        || statusLine.getStatusCode() == HttpStatus.SC_CREATED) {
                    // read response as JSON.
                    final InputStream content = response.getEntity().getContent();
                    final UserInfo userInfo;
                    try {
                        userInfo = new ObjectMapper().readValue(content, UserInfo.class);
                    } finally {
                        FileHelper.safeClose(content);
                    }
                    LOGGER.info("Get tenant info request responded with tenant name: {}", userInfo.tenant);
                    JOptionPane.showMessageDialog(DataHubDatastoreDialog.this, "Connection successful!");
                } else {
                    final String reasonPhrase = statusLine.getReasonPhrase();
                    WidgetUtils.showErrorMessage("Server reported error",
                            "Server replied with status " + statusLine.getStatusCode() + ":\n" + reasonPhrase);
                }
            } catch (Exception e) {
                // TODO: This dialog is shown behind the modal dialog
                WidgetUtils.showErrorMessage("Connection failed",
                        "Connecting to DataHub failed. Did you remember to fill in all the necessary fields?",
                        e);
            }
            validateAndUpdate();
        }

    });

    if (originalDatastore != null) {
        _hostTextField.setText(originalDatastore.getHost());
        _portTextField.setText(originalDatastore.getPort() + "");
        _httpsCheckBox.setSelected(originalDatastore.isHttps());
        _acceptUnverifiedSslPeersCheckBox.setSelected(originalDatastore.isAcceptUnverifiedSslPeers());
        if (originalDatastore.getSecurityMode().equals(DataHubSecurityMode.CAS)) {
            _securityModeSelector.setSelectedIndex(1);
        } else {
            _securityModeSelector.setSelectedIndex(0);
        }

        _datastoreNameTextField.setText(originalDatastore.getName());
        _datastoreNameTextField.setEditable(false);

        _usernameTextField.setText(originalDatastore.getUsername());
        _passwordTextField.setText(originalDatastore.getPassword());
    } else {
        _hostTextField.setText("localhost");
        _portTextField.setText("8080");
    }
    updateUrlLabel();
}

From source file:org.datacleaner.windows.FileTransferProgressWindow.java

@Override
protected JComponent getDialogContent() {
    final DCPanel centerPanel = new DCPanel();
    centerPanel.setLayout(new VerticalLayout(4));

    for (int i = 0; i < _filenames.length; i++) {

        final JLabel ofLabel = new JLabel(" of ");
        ofLabel.setForeground(WidgetUtils.BG_COLOR_BRIGHTEST);

        final DCPanel textPanel = new DCPanel();
        textPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
        textPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
        textPanel.add(_currentBytesLabels[i]);
        textPanel.add(ofLabel);//from ww  w  .j  a  v  a2  s.co m
        textPanel.add(_expectedBytesLabels[i]);

        centerPanel.add(_infoLabels[i]);
        centerPanel.add(_progressBars[i]);
        centerPanel.add(textPanel);
    }

    final DCPanel mainPanel = new DCPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(centerPanel, BorderLayout.CENTER);

    return mainPanel;
}

From source file:org.datacleaner.windows.ResultWindow.java

/**
 *
 * @param configuration/*from   ww  w. j av a2s  .  c om*/
 * @param job
 *            either this or result must be available
 * @param result
 *            either this or job must be available
 * @param jobFilename
 * @param windowContext
 * @param userPreferences
 * @param rendererFactory
 */
@Inject
protected ResultWindow(DataCleanerConfiguration configuration, @Nullable AnalysisJob job,
        @Nullable AnalysisResult result, @Nullable @JobFile FileObject jobFilename, WindowContext windowContext,
        UserPreferences userPreferences, RendererFactory rendererFactory) {
    super(windowContext);
    final boolean running = (result == null);

    _resultPanels = new IdentityHashMap<>();
    _configuration = configuration;
    _job = job;
    _jobFilename = jobFilename;
    _userPreferences = userPreferences;
    _rendererFactory = rendererFactory;

    final Ref<AnalysisResult> resultRef = new Ref<AnalysisResult>() {
        @Override
        public AnalysisResult get() {
            return getResult();
        }
    };

    Border buttonBorder = new CompoundBorder(WidgetUtils.BORDER_LIST_ITEM_SUBTLE,
            new EmptyBorder(10, 4, 10, 4));
    _cancelButton = WidgetFactory.createDefaultButton("Cancel job", IconUtils.ACTION_STOP);
    _cancelButton.setHorizontalAlignment(SwingConstants.LEFT);
    _cancelButton.setBorder(buttonBorder);

    _saveResultsPopupButton = WidgetFactory.createDefaultPopupButton("Save results",
            IconUtils.ACTION_SAVE_DARK);
    _saveResultsPopupButton.setHorizontalAlignment(SwingConstants.LEFT);
    _saveResultsPopupButton.setBorder(buttonBorder);
    _saveResultsPopupButton.setMenuPosition(MenuPosition.TOP);
    _saveResultsPopupButton.getMenu().setBorder(new MatteBorder(1, 0, 0, 1, WidgetUtils.BG_COLOR_MEDIUM));

    JMenuItem saveAsFileItem = WidgetFactory.createMenuItem("Save as result file", IconUtils.ACTION_SAVE_DARK);
    saveAsFileItem.addActionListener(new SaveAnalysisResultActionListener(resultRef, _userPreferences));
    saveAsFileItem.setBorder(buttonBorder);
    _saveResultsPopupButton.getMenu().add(saveAsFileItem);

    JMenuItem exportToHtmlItem = WidgetFactory.createMenuItem("Export to HTML", IconUtils.WEBSITE);
    exportToHtmlItem.addActionListener(
            new ExportResultToHtmlActionListener(resultRef, _configuration, _userPreferences));
    exportToHtmlItem.setBorder(buttonBorder);
    _saveResultsPopupButton.getMenu().add(exportToHtmlItem);

    JMenuItem publishToServerItem = WidgetFactory.createMenuItem("Publish to server",
            IconUtils.MENU_DQ_MONITOR);
    publishToServerItem.addActionListener(new PublishResultToMonitorActionListener(getWindowContext(),
            _userPreferences, resultRef, _jobFilename));
    publishToServerItem.setBorder(buttonBorder);
    _saveResultsPopupButton.getMenu().add(publishToServerItem);

    _tabbedPane = new VerticalTabbedPane() {
        private static final long serialVersionUID = 1L;

        @Override
        protected JComponent wrapInCollapsiblePane(final JComponent originalPanel) {
            DCPanel buttonPanel = new DCPanel();
            buttonPanel.setLayout(new VerticalLayout());
            buttonPanel.setBorder(new MatteBorder(1, 0, 0, 0, WidgetUtils.BG_COLOR_MEDIUM));

            buttonPanel.add(_saveResultsPopupButton);
            buttonPanel.add(_cancelButton);

            DCPanel wrappedPanel = new DCPanel();
            wrappedPanel.setLayout(new BorderLayout());
            wrappedPanel.add(originalPanel, BorderLayout.CENTER);
            wrappedPanel.add(buttonPanel, BorderLayout.SOUTH);
            return super.wrapInCollapsiblePane(wrappedPanel);
        }
    };

    final Dimension size = getDefaultWindowSize();
    _windowSizePreference = new WindowSizePreferences(_userPreferences, getClass(), size.width, size.height);
    _progressInformationPanel = new ProgressInformationPanel(running);
    _tabbedPane.addTab("Progress information",
            imageManager.getImageIcon("images/model/progress_information.png", IconUtils.ICON_SIZE_TAB),
            _progressInformationPanel);

    for (Func<ResultWindow, JComponent> pluggableComponent : PLUGGABLE_BANNER_COMPONENTS) {
        JComponent component = pluggableComponent.eval(this);
        if (component != null) {
            if (component instanceof AbstractButton) {
                AbstractButton button = (AbstractButton) component;
                JMenuItem menuItem = WidgetFactory.createMenuItem(button.getText(), button.getIcon());
                for (ActionListener listener : button.getActionListeners()) {
                    menuItem.addActionListener(listener);
                }
                menuItem.setBorder(buttonBorder);
                _saveResultsPopupButton.getMenu().add(menuItem);
            } else if (component instanceof JMenuItem) { // TODO: Not possible. JMenuItem is a subclass of AbstractButton. Reorder or remove?
                JMenuItem menuItem = (JMenuItem) component;
                menuItem.setBorder(buttonBorder);
                _saveResultsPopupButton.getMenu().add(menuItem);
            }
        }
    }

    if (running) {
        // run the job in a swing worker
        _result = null;
        _worker = new AnalysisRunnerSwingWorker(_configuration, _job, this);

        _cancelButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                _worker.cancelIfRunning();
            }
        });
    } else {
        // don't add the progress information, simply render the job asap
        _result = result;
        _worker = null;

        final Map<ComponentJob, AnalyzerResult> map = result.getResultMap();
        for (Entry<ComponentJob, AnalyzerResult> entry : map.entrySet()) {
            final ComponentJob componentJob = entry.getKey();
            final AnalyzerResult analyzerResult = entry.getValue();

            addResult(componentJob, analyzerResult);
        }
        _progressInformationPanel.onSuccess();

        WidgetUtils.invokeSwingAction(new Runnable() {
            @Override
            public void run() {
                if (_tabbedPane.getTabCount() > 1) {
                    // switch to the first available result panel
                    _tabbedPane.setSelectedIndex(1);
                }
            }
        });
    }

    updateButtonVisibility(running);
}

From source file:org.docx4all.ui.main.WordMLEditor.java

JComponent createMainPanel() {
    _desktop = new JDesktopPane();
    _desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    _desktop.setBackground(Color.LIGHT_GRAY);

    JPanel toolbar = FxScriptUIHelper.getInstance().createToolBar();

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(toolbar, BorderLayout.NORTH);
    panel.add(_desktop, BorderLayout.CENTER);

    panel.setBorder(new EmptyBorder(0, 2, 2, 2)); // top, left, bottom, right
    panel.setPreferredSize(new Dimension(640, 480));

    return panel;
}

From source file:org.eclipse.om2m.ipe.sample.gui.GUI.java

/**
 * Creates the frame.// w w  w .jav a2s .c  o  m
 */
public GUI() {
    setLocationByPlatform(true);
    setVisible(false);
    setResizable(false);
    setTitle("Sample Simulated IPE");
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width - 500) / 2, (screenSize.height - 570) / 2, 497, 570);

    contentPanel = new JPanel();
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPanel);
    contentPanel.setLayout(null);

    // Lamp0 Switcher0
    JPanel panel_Lamp0 = new JPanel();
    panel_Lamp0.setBounds(10, 5, 319, 260);
    contentPanel.add(panel_Lamp0);
    panel_Lamp0.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp0.setLayout(null);
    LABEL_LAMP_0.setIcon(iconLampOFF);
    LABEL_LAMP_0.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_0.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_0.setBounds(10, 9, 149, 240);
    panel_Lamp0.add(LABEL_LAMP_0);

    // Lamp0 Switch Button
    JButton button_Lamp0 = new JButton();
    button_Lamp0.setOpaque(false);
    button_Lamp0.setPressedIcon(iconButtonON);
    button_Lamp0.setIcon(iconButtonOFF);
    button_Lamp0.setBounds(187, 44, 122, 155);
    panel_Lamp0.add(button_Lamp0);
    button_Lamp0.setMinimumSize(new Dimension(30, 23));
    button_Lamp0.setMaximumSize(new Dimension(30, 23));
    button_Lamp0.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher0 = new JLabel("Switch LAMP_0");
    labelSwitcher0.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher0.setFocusCycleRoot(true);
    labelSwitcher0.setBorder(null);
    labelSwitcher0.setAutoscrolls(true);
    labelSwitcher0.setBounds(187, 199, 118, 29);
    panel_Lamp0.add(labelSwitcher0);
    // Listener for Lamp0 Switch Button
    button_Lamp0.addActionListener(new java.awt.event.ActionListener() {
        // Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp0 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp0 state
                    SampleMonitor.switchLamp(LAMP_0);
                }
            }.start();
        }
    });

    // Lamp1 Switcher 1
    JPanel panel_Lamp1 = new JPanel();
    panel_Lamp1.setBounds(10, 271, 319, 260);
    contentPanel.add(panel_Lamp1);
    panel_Lamp1.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp1.setLayout(null);

    LABEL_LAMP_1.setIcon(iconLampOFF);
    LABEL_LAMP_1.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_1.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_1.setBounds(10, 9, 154, 240);
    panel_Lamp1.add(LABEL_LAMP_1);

    // Lamp1 Switch Button
    JButton button_Lamp1 = new JButton();
    button_Lamp1.setOpaque(false);
    button_Lamp1.setPressedIcon(iconButtonON);
    button_Lamp1.setIcon(iconButtonOFF);
    button_Lamp1.setBounds(187, 44, 122, 156);
    panel_Lamp1.add(button_Lamp1);
    button_Lamp1.setMinimumSize(new Dimension(30, 23));
    button_Lamp1.setMaximumSize(new Dimension(30, 23));
    button_Lamp1.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher1 = new JLabel("Switch LAMP_1");
    labelSwitcher1.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher1.setFocusCycleRoot(true);
    labelSwitcher1.setBorder(null);
    labelSwitcher1.setAutoscrolls(true);
    labelSwitcher1.setBounds(187, 199, 118, 29);
    panel_Lamp1.add(labelSwitcher1);
    // Listener for Lamp1 Switch Button
    button_Lamp1.addActionListener(new java.awt.event.ActionListener() {
        //Switch Button clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp1 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp1 state
                    SampleMonitor.switchLamp(LAMP_1);
                }
            }.start();
        }
    });

    // Switcher All lamps
    JButton buttonAllLamp = new JButton();
    buttonAllLamp.setOpaque(false);
    buttonAllLamp.setPressedIcon(iconButtonON);
    buttonAllLamp.setIcon(iconButtonOFF);
    buttonAllLamp.setBounds(339, 190, 145, 168);
    contentPanel.add(buttonAllLamp);
    buttonAllLamp.setMinimumSize(new Dimension(30, 23));
    buttonAllLamp.setMaximumSize(new Dimension(30, 23));
    buttonAllLamp.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitchAll = new JLabel("Switch All");
    labelSwitchAll.setAutoscrolls(true);
    labelSwitchAll.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitchAll.setFocusCycleRoot(true);
    labelSwitchAll.setBorder(null);
    labelSwitchAll.setBounds(371, 369, 85, 29);
    contentPanel.add(labelSwitchAll);
    // Listener of Switch all Button
    buttonAllLamp.addActionListener(new java.awt.event.ActionListener() {
        // Switch Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change all lamps states
            new Thread() {
                public void run() {
                    // Send switch all request to create a content with the current State
                    SampleMonitor.switchAll();
                }
            }.start();
        }
    });

    lampObserver = new SampleModel.LampObserver() {

        @Override
        public void onLampStateChange(String lampId, boolean state) {
            setLabel(lampId, state);
        }
    };
    SampleModel.addObserver(lampObserver);
}

From source file:org.eclipse.om2m.ipu.sample.GUI.java

/**
 * Creates the frame.//from   ww w  . ja  va 2  s .  c  o m
 */
public GUI() {
    setLocationByPlatform(true);
    setResizable(false);
    setTitle("Sample Simulated IPU");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width - 500) / 2, (screenSize.height - 570) / 2, 497, 570);

    contentPanel = new JPanel();
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPanel);
    contentPanel.setLayout(null);

    // Lamp0 Switcher0
    JPanel panel_Lamp0 = new JPanel();
    panel_Lamp0.setBounds(10, 5, 319, 260);
    contentPanel.add(panel_Lamp0);
    panel_Lamp0.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp0.setLayout(null);
    LABEL_LAMP_0.setIcon(iconLampOFF);
    LABEL_LAMP_0.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_0.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_0.setBounds(10, 9, 149, 240);
    panel_Lamp0.add(LABEL_LAMP_0);

    // Lamp0 Switch Button
    JButton button_Lamp0 = new JButton();
    button_Lamp0.setOpaque(false);
    button_Lamp0.setPressedIcon(iconButtonON);
    button_Lamp0.setIcon(iconButtonOFF);
    button_Lamp0.setBounds(187, 44, 122, 155);
    panel_Lamp0.add(button_Lamp0);
    button_Lamp0.setMinimumSize(new Dimension(30, 23));
    button_Lamp0.setMaximumSize(new Dimension(30, 23));
    button_Lamp0.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher0 = new JLabel("Switch LAMP_0");
    labelSwitcher0.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher0.setFocusCycleRoot(true);
    labelSwitcher0.setBorder(null);
    labelSwitcher0.setAutoscrolls(true);
    labelSwitcher0.setBounds(187, 199, 118, 29);
    panel_Lamp0.add(labelSwitcher0);
    // Listener for Lamp0 Switch Button
    button_Lamp0.addActionListener(new java.awt.event.ActionListener() {
        // Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp0 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp0 state
                    Switchs.switchLamp(LAMP_0, !SampleMonitor.LAMPS.get(LAMP_0).getState());
                }
            }.start();
        }
    });

    // Lamp1 Switcher 1
    JPanel panel_Lamp1 = new JPanel();
    panel_Lamp1.setBounds(10, 271, 319, 260);
    contentPanel.add(panel_Lamp1);
    panel_Lamp1.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp1.setLayout(null);

    LABEL_LAMP_1.setIcon(iconLampOFF);
    LABEL_LAMP_1.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_1.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_1.setBounds(10, 9, 154, 240);
    panel_Lamp1.add(LABEL_LAMP_1);

    // Lamp1 Switch Button
    JButton button_Lamp1 = new JButton();
    button_Lamp1.setOpaque(false);
    button_Lamp1.setPressedIcon(iconButtonON);
    button_Lamp1.setIcon(iconButtonOFF);
    button_Lamp1.setBounds(187, 44, 122, 156);
    panel_Lamp1.add(button_Lamp1);
    button_Lamp1.setMinimumSize(new Dimension(30, 23));
    button_Lamp1.setMaximumSize(new Dimension(30, 23));
    button_Lamp1.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher1 = new JLabel("Switch LAMP_1");
    labelSwitcher1.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher1.setFocusCycleRoot(true);
    labelSwitcher1.setBorder(null);
    labelSwitcher1.setAutoscrolls(true);
    labelSwitcher1.setBounds(187, 199, 118, 29);
    panel_Lamp1.add(labelSwitcher1);
    // Listener for Lamp1 Switch Button
    button_Lamp1.addActionListener(new java.awt.event.ActionListener() {
        //Switch Button clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp1 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp1 state
                    Switchs.switchLamp(LAMP_1, !SampleMonitor.LAMPS.get(LAMP_1).getState());
                }
            }.start();
        }
    });

    // Switcher All lamps
    JButton buttonAllLamp = new JButton();
    buttonAllLamp.setOpaque(false);
    buttonAllLamp.setPressedIcon(iconButtonON);
    buttonAllLamp.setIcon(iconButtonOFF);
    buttonAllLamp.setBounds(339, 190, 145, 168);
    contentPanel.add(buttonAllLamp);
    buttonAllLamp.setMinimumSize(new Dimension(30, 23));
    buttonAllLamp.setMaximumSize(new Dimension(30, 23));
    buttonAllLamp.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitchAll = new JLabel("Switch All");
    labelSwitchAll.setAutoscrolls(true);
    labelSwitchAll.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitchAll.setFocusCycleRoot(true);
    labelSwitchAll.setBorder(null);
    labelSwitchAll.setBounds(371, 369, 85, 29);
    contentPanel.add(labelSwitchAll);
    // Listener of Switch all Button
    buttonAllLamp.addActionListener(new java.awt.event.ActionListener() {
        // Switch Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change all lamps states
            new Thread() {
                public void run() {
                    // Send switch all request to create a content with the current State
                    Switchs.switchAll(!(SampleMonitor.LAMPS.get(LAMP_0).getState()
                            && SampleMonitor.LAMPS.get(LAMP_1).getState()));
                }
            }.start();
        }
    });
}

From source file:org.eobjects.datacleaner.panels.OpenAnalysisJobPanel.java

public OpenAnalysisJobPanel(final FileObject file, final AnalyzerBeansConfiguration configuration,
        final OpenAnalysisJobActionListener openAnalysisJobActionListener) {
    super(WidgetUtils.BG_COLOR_LESS_BRIGHT, WidgetUtils.BG_COLOR_LESS_BRIGHT);
    _file = file;/*  w w w .j a v  a  2 s. c o  m*/
    _openAnalysisJobActionListener = openAnalysisJobActionListener;

    setLayout(new BorderLayout());
    setBorder(WidgetUtils.BORDER_LIST_ITEM);

    final AnalysisJobMetadata metadata = getMetadata(configuration);
    final String jobName = metadata.getJobName();
    final String jobDescription = metadata.getJobDescription();
    final String datastoreName = metadata.getDatastoreName();

    final boolean isDemoJob = isDemoJob(metadata);

    final DCPanel labelListPanel = new DCPanel();
    labelListPanel.setLayout(new VerticalLayout(4));
    labelListPanel.setBorder(new EmptyBorder(4, 4, 4, 0));

    final String title;
    final String filename = file.getName().getBaseName();
    if (Strings.isNullOrEmpty(jobName)) {
        final String extension = FileFilters.ANALYSIS_XML.getExtension();
        if (filename.toLowerCase().endsWith(extension)) {
            title = filename.substring(0, filename.length() - extension.length());
        } else {
            title = filename;
        }
    } else {
        title = jobName;
    }

    final JButton titleButton = new JButton(title);
    titleButton.setFont(WidgetUtils.FONT_HEADER1);
    titleButton.setForeground(WidgetUtils.BG_COLOR_BLUE_MEDIUM);
    titleButton.setHorizontalAlignment(SwingConstants.LEFT);
    titleButton.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, WidgetUtils.BG_COLOR_MEDIUM));
    titleButton.setToolTipText("Open job");
    titleButton.setOpaque(false);
    titleButton.setMargin(new Insets(0, 0, 0, 0));
    titleButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    titleButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isDemoDatastoreConfigured(datastoreName, configuration)) {
                _openAnalysisJobActionListener.openFile(_file);
            }
        }
    });

    final JButton executeButton = new JButton(executeIcon);
    executeButton.setOpaque(false);
    executeButton.setToolTipText("Execute job directly");
    executeButton.setMargin(new Insets(0, 0, 0, 0));
    executeButton.setBorderPainted(false);
    executeButton.setHorizontalAlignment(SwingConstants.RIGHT);
    executeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isDemoDatastoreConfigured(datastoreName, configuration)) {
                final ImageIcon executeIconLarge = ImageManager.get().getImageIcon(IconUtils.ACTION_EXECUTE);
                final String question = "Are you sure you want to execute the job\n'" + title + "'?";
                final int choice = JOptionPane.showConfirmDialog(null, question, "Execute job?",
                        JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, executeIconLarge);
                if (choice == JOptionPane.YES_OPTION) {
                    final Injector injector = _openAnalysisJobActionListener.openAnalysisJob(_file);
                    if (injector != null) {
                        final ResultWindow resultWindow = injector.getInstance(ResultWindow.class);
                        resultWindow.open();
                        resultWindow.startAnalysis();
                    }
                }
            }
        }
    });

    final DCPanel titlePanel = new DCPanel();
    titlePanel.setLayout(new BorderLayout());
    titlePanel.add(DCPanel.around(titleButton), BorderLayout.CENTER);
    titlePanel.add(executeButton, BorderLayout.EAST);

    labelListPanel.add(titlePanel);

    if (!Strings.isNullOrEmpty(jobDescription)) {
        String desc = StringUtils.replaceWhitespaces(jobDescription, " ");
        desc = StringUtils.replaceAll(desc, "  ", " ");
        final JLabel label = new JLabel(desc);
        label.setFont(WidgetUtils.FONT_SMALL);
        labelListPanel.add(label);
    }

    final Icon icon;
    {
        if (!StringUtils.isNullOrEmpty(datastoreName)) {
            final JLabel label = new JLabel(" " + datastoreName);
            label.setFont(WidgetUtils.FONT_SMALL);
            labelListPanel.add(label);

            final Datastore datastore = configuration.getDatastoreCatalog().getDatastore(datastoreName);
            if (isDemoJob) {
                icon = demoBadgeIcon;
            } else {
                icon = IconUtils.getDatastoreSpecificAnalysisJobIcon(datastore);
            }
        } else {
            icon = ImageManager.get().getImageIcon(IconUtils.MODEL_JOB, IconUtils.ICON_SIZE_LARGE);
        }
    }

    final JLabel iconLabel = new JLabel(icon);
    iconLabel.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));

    add(iconLabel, BorderLayout.WEST);
    add(labelListPanel, BorderLayout.CENTER);
}