Example usage for javax.swing GroupLayout GroupLayout

List of usage examples for javax.swing GroupLayout GroupLayout

Introduction

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

Prototype

public GroupLayout(Container host) 

Source Link

Document

Creates a GroupLayout for the specified Container .

Usage

From source file:volker.streaming.music.gui.NowPlayingFrame.java

public NowPlayingFrame(final File cfgFile) {
    this.cfgFile = cfgFile;

    frame = this;
    setTitle("NowPlaying - LastFM integration");
    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);

    lastfmConfig = LastFmConfig.fromFile(cfgFile);
    config = Config.fromFile(cfgFile);//from w ww.ja  v  a2s. co  m

    configPanel = new ConfigPanel(this, lastfmConfig);

    previewTrack = new Track("Beyonce", "Halo", "I Am... Sasha Fierce");
    formatter = new Formatter(Formatter.DEFAULT_EXCEPTIONS);
    formatPanel = new FormatPanel(this, config, formatter, previewTrack);

    apiPanel = new ApiPanel(config, lastfmConfig, formatter);

    saveButton = new JButton("Save configuration");
    saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveConfig();
        }
    });
    savePanel = new JPanel(new GridBagLayout());
    savePanel.add(saveButton);

    layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);

    layout.setHorizontalGroup(layout.createSequentialGroup().addContainerGap()
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(configPanel)
                    .addComponent(formatPanel).addComponent(apiPanel).addComponent(savePanel))
            .addContainerGap());

    layout.setVerticalGroup(layout.createSequentialGroup().addContainerGap().addComponent(configPanel)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(formatPanel)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(apiPanel)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(savePanel).addContainerGap());

    pack();

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            LastFmConfig storedLfm = LastFmConfig.fromFile(cfgFile);
            Config stored = Config.fromFile(cfgFile);
            if (!stored.contentEquals(config) || !storedLfm.contentEquals(lastfmConfig)) {
                int opt = JOptionPane.showConfirmDialog(frame,
                        "You have unsaved configuration changes.\nDo you want to save them?", "Unsaved changes",
                        JOptionPane.YES_NO_CANCEL_OPTION);
                switch (opt) {
                case JOptionPane.YES_OPTION:
                    saveConfig();
                case JOptionPane.NO_OPTION:
                    System.exit(0);
                    break;
                case JOptionPane.CANCEL_OPTION:
                    break;
                default:
                    LOG.error("Unknown response to closing window");
                }
            } else {
                System.exit(0);
            }
        }
    });
}

From source file:wsattacker.sso.openid.attacker.gui.MainGui.java

/**
 * This method is called from within the constructor to
 * initialize the form.//from  w  w  w .  j a  va2s.com
 * WARNING: Do NOT modify this code. The content of this method is
 * always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
    bindingGroup = new BindingGroup();

    saveFileChooser = new JFileChooser();
    loadFileChooser = new JFileChooser();
    xmlFileFilter = new XmlFileFilter();
    controller = new ServerController();
    serverStatusToIconConverter = new ServerStatusToIconConverter();
    splitPane = new JSplitPane();
    jXTaskPaneContainer1 = new JXTaskPaneContainer();
    attackerIdpTaskPane = new JXTaskPane();
    analyzerIdpTaskPane = new JXTaskPane();
    evaluationTaskPane = new JXTaskPane();
    logTaskPane = new JXTaskPane();
    menuBar = new JMenuBar();
    fileMenu = new JMenu();
    saveItem = new JMenuItem();
    loadItem = new JMenuItem();
    jSeparator2 = new JPopupMenu.Separator();
    clearLogMenuItem = new JMenuItem();
    jSeparator1 = new JPopupMenu.Separator();
    exitNoConfigSave = new JMenuItem();
    exitAndSaveConfig = new JMenuItem();

    saveFileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
    saveFileChooser.setFileFilter(xmlFileFilter);

    loadFileChooser.setFileFilter(xmlFileFilter);
    loadFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent evt) {
            formWindowOpened(evt);
        }

        public void windowClosing(WindowEvent evt) {
            formWindowClosing(evt);
        }
    });

    splitPane.setBorder(null);
    splitPane.setDividerLocation(200);
    splitPane.setDividerSize(0);

    jXTaskPaneContainer1.setMinimumSize(new Dimension(200, 259));
    jXTaskPaneContainer1.setPreferredSize(new Dimension(200, 10));
    VerticalLayout verticalLayout1 = new VerticalLayout();
    verticalLayout1.setGap(14);
    jXTaskPaneContainer1.setLayout(verticalLayout1);

    attackerIdpTaskPane.setFocusable(false);
    attackerIdpTaskPane.setTitle("Attacker IdP");

    Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, controller,
            ELProperty.create("${attackerServer.status}"), attackerIdpTaskPane, BeanProperty.create("icon"));
    binding.setConverter(serverStatusToIconConverter);
    bindingGroup.addBinding(binding);

    jXTaskPaneContainer1.add(attackerIdpTaskPane);

    analyzerIdpTaskPane.setFocusable(false);
    analyzerIdpTaskPane.setTitle("Analyzer IdP");

    binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, controller,
            ELProperty.create("${analyzerServer.status}"), analyzerIdpTaskPane, BeanProperty.create("icon"));
    binding.setConverter(serverStatusToIconConverter);
    bindingGroup.addBinding(binding);

    jXTaskPaneContainer1.add(analyzerIdpTaskPane);

    evaluationTaskPane.setFocusable(false);
    evaluationTaskPane.setTitle("Evaluation");
    jXTaskPaneContainer1.add(evaluationTaskPane);

    logTaskPane.setFocusable(false);
    logTaskPane.setTitle("Other");
    jXTaskPaneContainer1.add(logTaskPane);

    splitPane.setLeftComponent(jXTaskPaneContainer1);

    fileMenu.setMnemonic('F');
    fileMenu.setText("File");

    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK));
    saveItem.setText("Save Config");
    saveItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            saveItemActionPerformed(evt);
        }
    });
    fileMenu.add(saveItem);

    loadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.ALT_MASK));
    loadItem.setText("Load Config");
    loadItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            loadItemActionPerformed(evt);
        }
    });
    fileMenu.add(loadItem);
    fileMenu.add(jSeparator2);

    clearLogMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
    clearLogMenuItem.setText("Clear Log");
    clearLogMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            clearLogMenuItemActionPerformed(evt);
        }
    });
    fileMenu.add(clearLogMenuItem);
    fileMenu.add(jSeparator1);

    exitNoConfigSave.setText("Exit (without saving config)");
    exitNoConfigSave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            exitNoConfigSaveActionPerformed(evt);
        }
    });
    fileMenu.add(exitNoConfigSave);

    exitAndSaveConfig.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.META_MASK));
    exitAndSaveConfig.setText("Exit");
    exitAndSaveConfig.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            exitAndSaveConfigActionPerformed(evt);
        }
    });
    fileMenu.add(exitAndSaveConfig);

    menuBar.add(fileMenu);

    setJMenuBar(menuBar);

    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(splitPane,
            GroupLayout.DEFAULT_SIZE, 960, Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addComponent(splitPane,
            GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE));

    bindingGroup.bind();

    pack();
}