Example usage for javax.swing BoxLayout X_AXIS

List of usage examples for javax.swing BoxLayout X_AXIS

Introduction

In this page you can find the example usage for javax.swing BoxLayout X_AXIS.

Prototype

int X_AXIS

To view the source code for javax.swing BoxLayout X_AXIS.

Click Source Link

Document

Specifies that components should be laid out left to right.

Usage

From source file:FillViewportHeightDemo.java

public FillViewportHeightDemo() {
    super("Empty Table DnD Demo");

    tableModel = getDefaultTableModel();
    table = new JTable(tableModel);
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.setDropMode(DropMode.INSERT_ROWS);

    table.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferSupport support) {
            // for the demo, we'll only support drops (not clipboard paste)
            if (!support.isDrop()) {
                return false;
            }/*ww  w  .  j av  a  2  s.c o  m*/

            // we only import Strings
            if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            return true;
        }

        public boolean importData(TransferSupport support) {
            // if we can't handle the import, say so
            if (!canImport(support)) {
                return false;
            }

            // fetch the drop location
            JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation();

            int row = dl.getRow();

            // fetch the data and bail if this fails
            String data;
            try {
                data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor);
            } catch (UnsupportedFlavorException e) {
                return false;
            } catch (IOException e) {
                return false;
            }

            String[] rowData = data.split(",");
            tableModel.insertRow(row, rowData);

            Rectangle rect = table.getCellRect(row, 0, false);
            if (rect != null) {
                table.scrollRectToVisible(rect);
            }

            // demo stuff - remove for blog
            model.removeAllElements();
            model.insertElementAt(getNextString(count++), 0);
            // end demo stuff

            return true;
        }
    });

    JList dragFrom = new JList(model);
    dragFrom.setFocusable(false);
    dragFrom.setPrototypeCellValue(getNextString(100));
    model.insertElementAt(getNextString(count++), 0);
    dragFrom.setDragEnabled(true);
    dragFrom.setBorder(BorderFactory.createLoweredBevelBorder());

    dragFrom.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent me) {
            if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) {
                String text = (String) model.getElementAt(0);
                String[] rowData = text.split(",");
                tableModel.insertRow(table.getRowCount(), rowData);
                model.removeAllElements();
                model.insertElementAt(getNextString(count++), 0);
            }
        }
    });

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    JPanel wrap = new JPanel();
    wrap.add(new JLabel("Drag from here:"));
    wrap.add(dragFrom);
    p.add(Box.createHorizontalStrut(4));
    p.add(Box.createGlue());
    p.add(wrap);
    p.add(Box.createGlue());
    p.add(Box.createHorizontalStrut(4));
    getContentPane().add(p, BorderLayout.NORTH);

    JScrollPane sp = new JScrollPane(table);
    getContentPane().add(sp, BorderLayout.CENTER);
    fillBox = new JCheckBoxMenuItem("Fill Viewport Height");
    fillBox.addActionListener(this);

    JMenuBar mb = new JMenuBar();
    JMenu options = new JMenu("Options");
    mb.add(options);
    setJMenuBar(mb);

    JMenuItem clear = new JMenuItem("Reset");
    clear.addActionListener(this);
    options.add(clear);
    options.add(fillBox);

    getContentPane().setPreferredSize(new Dimension(260, 180));
}

From source file:edu.virginia.speclab.juxta.author.view.export.WebServiceExportDialog.java

/**
 * Create a UI panel to show export progress
 *//*from ww  w . ja  va  2  s.c  o  m*/
private void createStatusPane() {
    this.statusPanel = new JPanel();
    this.statusPanel.setBackground(Color.white);
    this.statusPanel.setLayout(new BorderLayout(5, 5));
    this.statusPanel.setBorder(BorderFactory.createEmptyBorder(15, 0, 0, 0));

    JPanel content = new JPanel();
    content.setBackground(Color.white);
    content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
    content.add(Box.createVerticalStrut(30));
    JLabel l = new JLabel("Status", SwingConstants.CENTER);
    l.setAlignmentX(CENTER_ALIGNMENT);
    l.setFont(JuxtaUserInterfaceStyle.LARGE_FONT);
    content.add(l);
    content.add(Box.createVerticalStrut(10));
    this.statusLabel = new JLabel("", SwingConstants.CENTER);
    this.statusLabel.setAlignmentX(CENTER_ALIGNMENT);
    this.setFont(JuxtaUserInterfaceStyle.NORMAL_FONT);
    content.add(this.statusLabel);
    this.statusPanel.add(content, BorderLayout.CENTER);

    JPanel p = new JPanel();
    p.setBackground(Color.white);
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    p.add(Box.createHorizontalGlue());
    this.workAnimation = new JLabel();
    this.workAnimation.setIcon(JuxtaUserInterfaceStyle.WORKING_ANIMATION);
    p.add(this.workAnimation);
    p.add(Box.createHorizontalGlue());
    this.statusPanel.add(p, BorderLayout.NORTH);
}

From source file:org.obiba.onyx.jade.instrument.summitdoppler.VantageABIInstrumentRunner.java

protected JPanel buildMeasureCountSubPanel() {
    // Add the results sub panel.
    JPanel panel = new JPanel();

    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

    panel.add(measureCountLabel = new MeasureCountLabel());

    panel.setAlignmentX(Component.LEFT_ALIGNMENT);

    return (panel);
}

From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java

private void addCloseButton() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.add(Box.createHorizontalGlue());
    JButton button = new JButton(i18n.getString(I18n.BUTTON_CLOSE_ID));
    panel.add(button);/*from   w  w  w. j  a va2  s. c  o  m*/
    panel.add(Box.createHorizontalGlue());
    button.addActionListener(closeAction());

    panel.setBorder(BorderFactory.createEmptyBorder(border, 0, 0, 0));
    add(panel, BorderLayout.SOUTH);
}

From source file:gtu._work.ui.DirectoryCompareUI.java

private void initGUI() {
    try {/*from w ww. j a va2 s . co  m*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
                {
                    jPanel2 = new JPanel();
                    BoxLayout jPanel2Layout = new BoxLayout(jPanel2, javax.swing.BoxLayout.X_AXIS);
                    jPanel2.setLayout(jPanel2Layout);
                    jPanel1.add(jPanel2, BorderLayout.NORTH);
                    jPanel2.setPreferredSize(new java.awt.Dimension(660, 36));
                    {
                        leftDirText = new JTextArea();
                        leftDirText.setPreferredSize(leftDirText.getPreferredSize());
                        leftDirText.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));
                        JCommonUtil.jTextFieldSetFilePathMouseEvent(leftDirText, true);
                        leftDirText.getDocument()
                                .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {
                                    @Override
                                    public void process(DocumentEvent event) {
                                    }
                                }));
                        jPanel2.add(leftDirText);
                        JTextFieldUtil.setupDragDropFilePath(leftDirText, null);
                    }
                    {
                        rightDirText = new JTextArea();
                        rightDirText.setPreferredSize(rightDirText.getPreferredSize());
                        rightDirText.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false));
                        JCommonUtil.jTextFieldSetFilePathMouseEvent(rightDirText, true);
                        rightDirText.getDocument()
                                .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {
                                    @Override
                                    public void process(DocumentEvent event) {
                                    }
                                }));
                        jPanel2.add(rightDirText);
                        JTextFieldUtil.setupDragDropFilePath(rightDirText, null);
                    }
                    {
                        executeBtn = new JButton();
                        jPanel2.add(executeBtn);
                        jPanel2.add(getResetBtn());
                        executeBtn.setText("\u958b\u59cb\u6bd4\u5c0d");
                        executeBtn.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                compareStart();
                            }
                        });
                    }
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(660, 362));
                    {
                        dirCompareTable = new JTable();
                        // JTableUtil.defaultSetting(dirCompareTable);
                        JTableUtil.defaultSetting_AutoResize(dirCompareTable);
                        jScrollPane1.setViewportView(dirCompareTable);
                        dirCompareTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                dirCompareTableMouseClicked(evt);
                            }
                        });
                        dirCompareTable.setModel(getDefaultTableModel());
                    }
                }
                {
                    jPanel3 = new JPanel();
                    FlowLayout jPanel3Layout = new FlowLayout();
                    jPanel3Layout.setAlignOnBaseline(true);
                    jPanel1.add(jPanel3, BorderLayout.SOUTH);
                    jPanel3.setLayout(jPanel3Layout);
                    jPanel3.setPreferredSize(new java.awt.Dimension(843, 62));
                    {
                        jLabel1 = new JLabel();
                        jPanel3.add(jLabel1);
                        jLabel1.setText("\u526f\u6a94\u540d");
                    }
                    {
                        DefaultComboBoxModel extensionNameComboBoxModel = new DefaultComboBoxModel();
                        extensionNameComboBox = new JComboBox();
                        jPanel3.add(extensionNameComboBox);
                        jPanel3.add(getDiffToolComboBox());
                        jPanel3.add(getJLabel2());
                        jPanel3.add(getSearchText());
                        jPanel3.add(getCompareStyleComboBox());
                        jPanel3.add(getResetQueryBtn());
                        addDiffMergeChkBox();
                        extensionNameComboBox.setModel(extensionNameComboBoxModel);
                        {
                            panel = new JPanel();
                            jTabbedPane1.addTab("New tab", null, panel, null);
                            panel.setLayout(new FormLayout(
                                    new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC,
                                            FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
                                            ColumnSpec.decode("default:grow"), },
                                    new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, }));
                            {
                                lblCustomCommand = new JLabel("custom command");
                                panel.add(lblCustomCommand, "2, 2, right, default");
                            }
                            {
                                customCompareText = new JTextField();
                                customCompareText.setText(
                                        "\"C:\\Program Files\\TortoiseGit\\bin\\TortoiseGitMerge.exe\"   /base:\"%s\" /theirs:\"%s\"");
                                panel.add(customCompareText, "4, 2, fill, default");
                                customCompareText.setColumns(10);
                            }
                            {
                                configSaveBtn = new JButton("");
                                configSaveBtn.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            boolean configChange = false;
                                            String customCompareUrl = customCompareText.getText();
                                            if (StringUtils.isNotBlank(customCompareUrl)) {
                                                configBean.getConfigProp().setProperty(CUSTOM_COMPARE_URL_KEY,
                                                        customCompareUrl);
                                                configChange = true;
                                            }
                                            if (configChange) {
                                                configBean.store();
                                                JCommonUtil._jOptionPane_showMessageDialog_info(
                                                        "?!");
                                            }
                                        } catch (Exception ex) {
                                            JCommonUtil.handleException(ex);
                                        }
                                    }
                                });
                                panel.add(configSaveBtn, "2, 36");
                            }
                        }
                        extensionNameComboBox.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                totalScanFiles(null);
                            }
                        });
                    }
                }
            }
        }
        pack();
        this.setSize(864, 563);

        JCommonUtil.setJFrameIcon(getOwner(), "images/ico/file_merge.ico");

        initConfigBean();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.dragoniade.deviantart.ui.PreferencesDialog.java

public PreferencesDialog(final DownloaderGUI owner, Properties config) {
    super(owner, "Preferences", true);

    HttpClientParams params = new HttpClientParams();
    params.setVersion(HttpVersion.HTTP_1_1);
    params.setSoTimeout(30000);//from   w w w  .j a v  a2s .c  o m
    client = new HttpClient(params);
    setProxy(ProxyCfg.parseConfig(config));

    sample = new Deviation();
    sample.setId(15972367L);
    sample.setTitle("Fella Promo");
    sample.setArtist("devart");
    sample.setImageDownloadUrl(DOWNLOAD_URL);
    sample.setImageFilename(Deviation.extractFilename(DOWNLOAD_URL));
    sample.setCollection(new Collection(1L, "MyCollect"));
    setLayout(new BorderLayout());
    panes = new JTabbedPane(JTabbedPane.TOP);

    JPanel genPanel = new JPanel();
    BoxLayout genLayout = new BoxLayout(genPanel, BoxLayout.Y_AXIS);
    genPanel.setLayout(genLayout);
    panes.add("General", genPanel);

    JLabel userLabel = new JLabel("Username");

    userLabel.setToolTipText("The username the account you want to download the favorites from.");

    userField = new JTextField(config.getProperty(Constants.USERNAME));

    userLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    userField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userField.setMaximumSize(new Dimension(Integer.MAX_VALUE, userField.getFont().getSize() * 2));

    genPanel.add(userLabel);
    genPanel.add(userField);

    JPanel radioPanel = new JPanel();
    BoxLayout radioLayout = new BoxLayout(radioPanel, BoxLayout.X_AXIS);
    radioPanel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    radioPanel.setBorder(new EmptyBorder(0, 5, 0, 5));

    radioPanel.setLayout(radioLayout);

    JLabel searchLabel = new JLabel("Search for");
    searchLabel
            .setToolTipText("Select what you want to download from that user: it favorites or it galleries.");
    searchLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searchLabel.setBorder(new EmptyBorder(0, 5, 0, 5));

    selectedSearch = SEARCH.lookup(config.getProperty(Constants.SEARCH, SEARCH.getDefault().getId()));
    buttonGroup = new ButtonGroup();

    for (final SEARCH search : SEARCH.values()) {
        JRadioButton radio = new JRadioButton(search.getLabel());
        radio.setAlignmentX(JLabel.LEFT_ALIGNMENT);
        radio.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                selectedSearch = search;
            }
        });

        buttonGroup.add(radio);
        radioPanel.add(radio);
        if (search.equals(selectedSearch)) {
            radio.setSelected(true);
        }
    }

    genPanel.add(radioPanel);

    final JTextField sampleField = new JTextField("");
    sampleField.setEditable(false);

    JLabel locationLabel = new JLabel("Download location");
    locationLabel.setToolTipText("The folder pattern where you want the file to be downloaded in.");

    JLabel legendsLabel = new JLabel(
            "<html><body>Field names: %user%, %artist%, %title%, %id%, %filename%, %collection%, %ext%<br></br>Example:</body></html>");
    legendsLabel.setToolTipText("An example of where a file will be downloaded to.");

    locationString = new StringBuilder();
    locationField = new JTextField(config.getProperty(Constants.LOCATION));
    locationField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationString.setLength(0);
            locationString.append(dest.getAbsolutePath());
            sampleField.setText(locationString.toString());
            if (useSameForMatureBox.isSelected()) {
                locationMatureString.setLength(0);
                locationMatureString.append(sampleField.getText());
                locationMatureField.setText(locationField.getText());
            }
        }

        public void keyTyped(KeyEvent e) {
        }

    });
    locationField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });
    JLabel locationMatureLabel = new JLabel("Mature download location");
    locationMatureLabel.setToolTipText(
            "The folder pattern where you want the file marked as 'Mature' to be downloaded in.");

    locationMatureString = new StringBuilder();
    locationMatureField = new JTextField(config.getProperty(Constants.MATURE));
    locationMatureField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationMatureString.setLength(0);
            locationMatureString.append(dest.getAbsolutePath());
            sampleField.setText(locationMatureString.toString());
        }

        public void keyTyped(KeyEvent e) {
        }

    });

    locationMatureField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationMatureString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });

    useSameForMatureBox = new JCheckBox("Use same location for mature deviation?");
    useSameForMatureBox.setSelected(locationLabel.getText().equals(locationMatureField.getText()));
    useSameForMatureBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (useSameForMatureBox.isSelected()) {
                locationMatureField.setEditable(false);
                locationMatureField.setText(locationField.getText());
                locationMatureString.setLength(0);
                locationMatureString.append(locationString);
            } else {
                locationMatureField.setEditable(true);
            }

        }
    });

    File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    sampleField.setText(dest.getAbsolutePath());
    locationString.append(sampleField.getText());

    dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    locationMatureString.append(dest.getAbsolutePath());

    locationLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationField.setMaximumSize(new Dimension(Integer.MAX_VALUE, locationField.getFont().getSize() * 2));
    locationMatureLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationMatureField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureField
            .setMaximumSize(new Dimension(Integer.MAX_VALUE, locationMatureField.getFont().getSize() * 2));
    useSameForMatureBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    legendsLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, legendsLabel.getFont().getSize() * 2));
    sampleField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    sampleField.setMaximumSize(new Dimension(Integer.MAX_VALUE, sampleField.getFont().getSize() * 2));

    genPanel.add(locationLabel);
    genPanel.add(locationField);

    genPanel.add(locationMatureLabel);
    genPanel.add(locationMatureField);
    genPanel.add(useSameForMatureBox);

    genPanel.add(legendsLabel);
    genPanel.add(sampleField);
    genPanel.add(Box.createVerticalBox());

    final KeyListener prxChangeListener = new KeyListener() {

        public void keyTyped(KeyEvent e) {
            proxyChangeState = true;
        }

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
        }
    };

    JPanel prxPanel = new JPanel();
    BoxLayout prxLayout = new BoxLayout(prxPanel, BoxLayout.Y_AXIS);
    prxPanel.setLayout(prxLayout);
    panes.add("Proxy", prxPanel);

    JLabel prxHostLabel = new JLabel("Proxy Host");
    prxHostLabel.setToolTipText("The hostname of the proxy server");
    prxHostField = new JTextField(config.getProperty(Constants.PROXY_HOST));
    prxHostLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxHostField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxHostField.getFont().getSize() * 2));

    JLabel prxPortLabel = new JLabel("Proxy Port");
    prxPortLabel.setToolTipText("The port of the proxy server (Default 80).");

    prxPortSpinner = new JSpinner();
    prxPortSpinner.setModel(new SpinnerNumberModel(
            Integer.parseInt(config.getProperty(Constants.PROXY_PORT, "80")), 1, 65535, 1));

    prxPortLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPortSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPortSpinner.getFont().getSize() * 2));

    JLabel prxUserLabel = new JLabel("Proxy username");
    prxUserLabel.setToolTipText("The username used for authentication, if applicable.");
    prxUserField = new JTextField(config.getProperty(Constants.PROXY_USERNAME));
    prxUserLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxUserField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxUserField.getFont().getSize() * 2));

    JLabel prxPassLabel = new JLabel("Proxy username");
    prxPassLabel.setToolTipText("The username used for authentication, if applicable.");
    prxPassField = new JPasswordField(config.getProperty(Constants.PROXY_PASSWORD));
    prxPassLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPassField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPassField.getFont().getSize() * 2));

    prxUseBox = new JCheckBox("Use a proxy?");
    prxUseBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            prxChangeListener.keyTyped(null);

            if (prxUseBox.isSelected()) {
                prxHostField.setEditable(true);
                prxPortSpinner.setEnabled(true);
                prxUserField.setEditable(true);
                prxPassField.setEditable(true);

            } else {
                prxHostField.setEditable(false);
                prxPortSpinner.setEnabled(false);
                prxUserField.setEditable(false);
                prxPassField.setEditable(false);
            }
        }
    });

    prxUseBox.setSelected(!Boolean.parseBoolean(config.getProperty(Constants.PROXY_USE)));
    prxUseBox.doClick();
    proxyChangeState = false;

    prxHostField.addKeyListener(prxChangeListener);
    prxUserField.addKeyListener(prxChangeListener);
    prxPassField.addKeyListener(prxChangeListener);
    prxPortSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            proxyChangeState = true;
        }
    });
    prxPanel.add(prxUseBox);

    prxPanel.add(prxHostLabel);
    prxPanel.add(prxHostField);

    prxPanel.add(prxPortLabel);
    prxPanel.add(prxPortSpinner);

    prxPanel.add(prxUserLabel);
    prxPanel.add(prxUserField);

    prxPanel.add(prxPassLabel);
    prxPanel.add(prxPassField);
    prxPanel.add(Box.createVerticalBox());

    final JPanel advPanel = new JPanel();
    BoxLayout advLayout = new BoxLayout(advPanel, BoxLayout.Y_AXIS);
    advPanel.setLayout(advLayout);
    panes.add("Advanced", advPanel);
    panes.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JTabbedPane pane = (JTabbedPane) e.getSource();

            if (proxyChangeState && pane.getSelectedComponent() == advPanel) {
                Properties properties = new Properties();
                properties.setProperty(Constants.PROXY_USERNAME, prxUserField.getText().trim());
                properties.setProperty(Constants.PROXY_PASSWORD, new String(prxPassField.getPassword()).trim());
                properties.setProperty(Constants.PROXY_HOST, prxHostField.getText().trim());
                properties.setProperty(Constants.PROXY_PORT, prxPortSpinner.getValue().toString());
                properties.setProperty(Constants.PROXY_USE, Boolean.toString(prxUseBox.isSelected()));
                ProxyCfg prx = ProxyCfg.parseConfig(properties);
                setProxy(prx);
                revalidateSearcher(null);
            }
        }
    });
    JLabel domainLabel = new JLabel("Deviant Art domain name");
    domainLabel.setToolTipText("The deviantART main domain, should it ever change.");

    domainField = new JTextField(config.getProperty(Constants.DOMAIN));
    domainLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    domainField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainField.setMaximumSize(new Dimension(Integer.MAX_VALUE, domainField.getFont().getSize() * 2));

    advPanel.add(domainLabel);
    advPanel.add(domainField);

    JLabel throttleLabel = new JLabel("Throttle search delay");
    throttleLabel.setToolTipText(
            "Slow down search query by inserting a pause between them. This help prevent abuse when doing a massive download.");

    throttleSpinner = new JSpinner();
    throttleSpinner.setModel(
            new SpinnerNumberModel(Integer.parseInt(config.getProperty(Constants.THROTTLE, "0")), 5, 60, 1));

    throttleLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    throttleSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, throttleSpinner.getFont().getSize() * 2));

    advPanel.add(throttleLabel);
    advPanel.add(throttleSpinner);

    JLabel searcherLabel = new JLabel("Searcher");
    searcherLabel.setToolTipText("Select a searcher that will look for your favorites.");

    searcherBox = new JComboBox();
    searcherBox.setRenderer(new TogglingRenderer());

    final AtomicInteger index = new AtomicInteger(0);
    searcherBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            Object selectedItem = combo.getSelectedItem();
            if (selectedItem instanceof SearchItem) {
                SearchItem item = (SearchItem) selectedItem;
                if (item.isValid) {
                    index.set(combo.getSelectedIndex());
                } else {
                    combo.setSelectedIndex(index.get());
                }
            }
        }
    });

    try {
        for (Class<Search> clazz : SearcherClassCache.getInstance().getClasses()) {

            Search searcher = clazz.newInstance();
            String name = searcher.getName();

            SearchItem item = new SearchItem(name, clazz.getName(), true);
            searcherBox.addItem(item);
        }
        String selectedClazz = config.getProperty(Constants.SEARCHER,
                com.dragoniade.deviantart.deviation.SearchRss.class.getName());
        revalidateSearcher(selectedClazz);
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }

    searcherLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    searcherBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, searcherBox.getFont().getSize() * 2));

    advPanel.add(searcherLabel);
    advPanel.add(searcherBox);

    advPanel.add(Box.createVerticalBox());

    add(panes, BorderLayout.CENTER);

    JButton saveBut = new JButton("Save");

    userField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            if (field.getText().trim().length() == 0) {
                JOptionPane.showMessageDialog(input, "The user musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The location must contains at least a %filename% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationMatureField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The Mature location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The Mature location must contains at least a %username% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    domainField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String domain = field.getText().trim();
            if (domain.length() == 0) {
                JOptionPane.showMessageDialog(input, "You must specify the deviantART main domain.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (domain.toLowerCase().startsWith("http://")) {
                JOptionPane.showMessageDialog(input,
                        "You must specify the deviantART main domain, not the full URL (aka www.deviantart.com).",
                        "Warning", JOptionPane.WARNING_MESSAGE);
                return false;
            }

            return true;
        }
    });
    locationField.setVerifyInputWhenFocusTarget(true);

    final JDialog parent = this;
    saveBut.addActionListener(new ActionListener() {

        String errorMsg = "The location is invalid or cannot be written to.";

        public void actionPerformed(ActionEvent e) {

            String username = userField.getText().trim();
            String location = locationField.getText().trim();
            String locationMature = locationMatureField.getText().trim();
            String domain = domainField.getText().trim();
            String throttle = throttleSpinner.getValue().toString();
            String searcher = searcherBox.getSelectedItem().toString();

            String prxUse = Boolean.toString(prxUseBox.isSelected());
            String prxHost = prxHostField.getText().trim();
            String prxPort = prxPortSpinner.getValue().toString();
            String prxUsername = prxUserField.getText().trim();
            String prxPassword = new String(prxPassField.getPassword()).trim();

            if (!testPath(location, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }
            if (!testPath(locationMature, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }

            Properties p = new Properties();
            p.setProperty(Constants.USERNAME, username);
            p.setProperty(Constants.LOCATION, location);
            p.setProperty(Constants.MATURE, locationMature);
            p.setProperty(Constants.DOMAIN, domain);
            p.setProperty(Constants.THROTTLE, throttle);
            p.setProperty(Constants.SEARCHER, searcher);
            p.setProperty(Constants.SEARCH, selectedSearch.getId());

            p.setProperty(Constants.PROXY_USE, prxUse);
            p.setProperty(Constants.PROXY_HOST, prxHost);
            p.setProperty(Constants.PROXY_PORT, prxPort);
            p.setProperty(Constants.PROXY_USERNAME, prxUsername);
            p.setProperty(Constants.PROXY_PASSWORD, prxPassword);

            owner.savePreferences(p);
            parent.dispose();
        }
    });

    JButton cancelBut = new JButton("Cancel");
    cancelBut.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            parent.dispose();
        }
    });

    JPanel buttonPanel = new JPanel();
    BoxLayout butLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS);
    buttonPanel.setLayout(butLayout);

    buttonPanel.add(saveBut);
    buttonPanel.add(cancelBut);
    add(buttonPanel, BorderLayout.SOUTH);

    pack();
    setResizable(false);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);
    setVisible(true);
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.ChartDisplayPanel.java

/**
 * Creates and lays out the controls inside this panel.
 * <p>/*from w w  w.j  av a 2s.  c  o m*/
 * This method is called upon initialization only.
 * </p>
 */
private void initControls() {
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

    add(createChartPanel());

    final Box buttonPanel = Box.createVerticalBox();
    final List<JButton> buttons = new ArrayList<JButton>(8);
    btnEnlarged = Utils.createButton(Messages.DI_VIEWENLARGED, Messages.TT_VIEWENLARGED, this);
    if (Plugin.hasFilter(originalParam.getClass())) {
        btnFilter = Utils.createButton(Messages.DI_FILTERDATA, Messages.TT_FILTERDATA, this);
    } else {
        btnFilter = null;
    }
    btnSaveChart = Utils.createButton(Messages.DI_EXPORTCHART, Messages.TT_SAVECHART, this);
    btnSaveData = Utils.createButton(Messages.DI_EXPORTDATA, Messages.TT_SAVEDATA, this);
    btnChartSettings = Utils.createButton(Messages.DI_CHARTSETTINGS, Messages.TT_CHARTSETTINGS, this);

    buttonPanel.add(btnChartSettings);
    buttons.add(btnChartSettings);
    buttonPanel.add(btnEnlarged);
    buttons.add(btnEnlarged);
    if (btnFilter != null) {
        buttonPanel.add(btnFilter);
        buttons.add(btnFilter);
    }
    buttonPanel.add(Box.createVerticalStrut(Utils.BORDER_SIZE * 2));
    if (decorators != null) {
        btnsDec = new JButton[decorators.length];
        for (int i = 0; i < decorators.length; ++i) {
            Decorator d = decorators[i];
            btnsDec[i] = Utils.createButton(d.getButtonLabel(), d.getButtonToolTip(), this);
            buttonPanel.add(btnsDec[i]);
            buttons.add(btnsDec[i]);
        }
        buttonPanel.add(Box.createVerticalStrut(Utils.BORDER_SIZE * 2));
    }
    buttonPanel.add(btnSaveChart);
    buttons.add(btnSaveChart);
    buttonPanel.add(btnSaveData);
    buttons.add(btnSaveData);
    buttonPanel.add(Box.createVerticalStrut(Utils.BORDER_SIZE * 2));
    buttonPanel.add(Box.createVerticalGlue());
    // Ensure buttons are large enough to fit all possible messages
    final JButton[] btnsArray = new JButton[buttons.size()];
    Utils.setSizes(buttons.toArray(btnsArray), preferred, preferred);
    add(buttonPanel);
    add(Box.createHorizontalGlue());
}

From source file:com.univocity.app.swing.DataAnalysisWindow.java

protected JPanel getProcessPanel() {
    if (processPanel == null) {
        processPanel = new JPanel();
        processPanel.setBorder(new TitledBorder("Process selection"));
        processPanel.setLayout(new BoxLayout(processPanel, BoxLayout.X_AXIS));
        addWithSpace(processPanel, getProcessListLabel(), 2);
        addWithSpace(processPanel, getProcessList(), 2);
        addWithSpace(processPanel, getExecuteProcessButton(), 2);
    }/* w w w  .ja va 2 s. co  m*/
    return processPanel;
}

From source file:edu.gmu.cs.sim.util.media.chart.SeriesAttributes.java

/** Builds a SeriesAttributes with the provided generator, name for the series, and index for the series.  Calls
 buildAttributes to construct custom elements in the LabelledList, then finally calls rebuildGraphicsDefinitions()
 to update the series. */// ww w  . jav  a 2s . com
public SeriesAttributes(ChartGenerator generator, String name, int index, SeriesChangeListener stoppable) {
    super(name);
    setStoppable(stoppable);
    this.generator = generator;
    seriesIndex = index;
    final JCheckBox check = new JCheckBox();
    check.setSelected(true);
    check.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setPlotVisible(check.isSelected());
        }
    });

    manipulators = new Box(BoxLayout.X_AXIS);
    buildManipulators();
    JLabel spacer = new JLabel("");
    spacer.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
    Box b = new Box(BoxLayout.X_AXIS);
    b.add(check);
    b.add(spacer);
    b.add(manipulators);
    b.add(Box.createGlue());
    addLabelled("Show", b);

    final PropertyField nameF = new PropertyField(name) {
        public String newValue(String newValue) {
            SeriesAttributes.this.setSeriesName(newValue);
            rebuildGraphicsDefinitions();
            return newValue;
        }
    };
    addLabelled("Series", nameF);

    buildAttributes();
    rebuildGraphicsDefinitions();
}

From source file:es.emergya.ui.gis.popups.SDSDialog.java

public SDSDialog(Recurso r) {
    super();//from   www.  j  av  a2  s. com
    setAlwaysOnTop(true);
    setResizable(false);
    iconTransparente = LogicConstants.getIcon("48x48_transparente");
    iconEnviando = LogicConstants.getIcon("anim_enviando");
    destino = r;
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            cancel.doClick();
        }
    });

    // setPreferredSize(new Dimension(400, 150));
    setTitle(i18n.getString("window.sds.titleBar") + " " + r.getIdentificador());
    try {
        setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getIconImage());
    } catch (Throwable e) {
        LOG.error("There is no icon image", e);
    }

    JPanel base = new JPanel();

    base.setBackground(Color.WHITE);
    base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

    // Icono del titulo
    JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING));
    final JLabel titleLabel = new JLabel(i18n.getString("window.sds.title"),
            LogicConstants.getIcon("tittleventana_icon_enviarsds"), JLabel.LEFT);

    titleLabel.setFont(LogicConstants.deriveBoldFont(12f));
    title.add(titleLabel);
    title.setOpaque(false);
    base.add(title);

    // Espacio para el mensaje
    sds = new JTextArea(7, 40);
    sds.setLineWrap(true);

    final JScrollPane sdsp = new JScrollPane(sds);

    sdsp.setOpaque(false);
    sdsp.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.BLACK),
            i18n.getString("Admin.message") + "\t (0/" + maxChars + ")"));
    sds.setDocument(new PlainDocument() {
        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            if (this.getLength() + str.length() <= maxChars) {
                super.insertString(offs, str, a);
            }
        }
    });
    sds.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateChars(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateChars(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateChars(e);
        }

        private void updateChars(DocumentEvent e) {
            ((TitledBorder) sdsp.getBorder()).setTitle(
                    i18n.getString("Admin.message") + "\t (" + sds.getText().length() + "/" + maxChars + ")");
            sdsp.repaint();
            send.setEnabled(!sds.getText().isEmpty());
            notification.setForeground(Color.WHITE);
            notification.setText("PLACEHOLDER");
        }
    });
    base.add(sdsp);

    // Area para mensajes
    JPanel notificationArea = new JPanel();

    notificationArea.setOpaque(false);
    notification = new JLabel("TEXT");
    notification.setForeground(Color.WHITE);
    notificationArea.add(notification);
    base.add(notificationArea);

    JPanel buttons = new JPanel();

    buttons.setOpaque(false);
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    send = new JButton(i18n.getString("Buttons.send"),
            LogicConstants.getIcon("ventanacontextual_button_enviarsds"));
    send.addActionListener(this);
    send.setEnabled(false);
    buttons.add(send);
    buttons.add(Box.createHorizontalGlue());
    progressIcon = new JLabel(iconTransparente);
    buttons.add(progressIcon);
    buttons.add(Box.createHorizontalGlue());
    cancel = new JButton(i18n.getString("Buttons.cancel"), LogicConstants.getIcon("button_cancel"));
    cancel.addActionListener(this);
    buttons.add(cancel);
    base.add(buttons);
    getContentPane().add(base);
    pack();

    int x;
    int y;
    Container myParent;
    try {
        myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getContentPane();
        java.awt.Point topLeft = myParent.getLocationOnScreen();
        Dimension parentSize = myParent.getSize();

        Dimension mySize = getSize();

        if (parentSize.width > mySize.width)
            x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
        else
            x = topLeft.x;

        if (parentSize.height > mySize.height)
            y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
        else
            y = topLeft.y;

        setLocation(x, y);
    } catch (Throwable e1) {
        LOG.error("There is no basic window!", e1);
    }
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent arg0) {
            deleteErrorMessage();
        }

        @Override
        public void windowClosed(WindowEvent arg0) {
            deleteErrorMessage();
        }

        private void deleteErrorMessage() {
            SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {
                @Override
                protected Object doInBackground() throws Exception {
                    if (bandejaSalida != null) {
                        MessageGenerator.remove(bandejaSalida.getId());
                    }

                    bandejaSalida = null;

                    return null;
                }

                @Override
                protected void done() {
                    super.done();
                    SDSDialog.this.sds.setText("");
                    SDSDialog.this.sds.setEnabled(true);
                    SDSDialog.this.sds.repaint();
                    SDSDialog.this.progressIcon.setIcon(iconTransparente);
                    SDSDialog.this.progressIcon.repaint();
                    SDSDialog.this.notification.setText("");
                    SDSDialog.this.notification.repaint();
                }
            };

            sw.execute();
        }
    });
}