Example usage for java.awt GridBagConstraints RELATIVE

List of usage examples for java.awt GridBagConstraints RELATIVE

Introduction

In this page you can find the example usage for java.awt GridBagConstraints RELATIVE.

Prototype

int RELATIVE

To view the source code for java.awt GridBagConstraints RELATIVE.

Click Source Link

Document

Specifies that this component is the next-to-last component in its column or row ( gridwidth , gridheight ), or that this component be placed next to the previously added component ( gridx , gridy ).

Usage

From source file:org.openmicroscopy.shoola.agents.metadata.rnd.GraphicsPane.java

/** 
 * Builds hosting the various sliders//from  w w  w.  j a va 2  s.com
 * 
 * @return See above.
 */
private JPanel buildGeneralPane() {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    content.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    content.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 2, 2, 0);
    c.gridy = 0;
    c.gridx = 0;
    if (model.isGeneralIndex()) {
        content.add(previewToolBar, c);
        c.gridy++;
        c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
        c.fill = GridBagConstraints.HORIZONTAL;
        content.add(new JSeparator(), c);
        c.gridy++;
    }
    content.add(controlsBar, c);
    c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last
    c.fill = GridBagConstraints.NONE;//reset to default
    c.weightx = 0.0;

    Iterator<ChannelSlider> i = sliders.iterator();
    while (i.hasNext()) {
        c.gridy++;
        content.add(i.next(), c);
    }
    c.gridy++;
    c.gridwidth = GridBagConstraints.REMAINDER; //end row
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 1.0;
    content.add(viewedBy, c);
    JPanel p = UIUtilities.buildComponentPanel(content);
    p.setBackground(content.getBackground());
    return p;
}

From source file:com.limegroup.gnutella.gui.LicenseWindow.java

/** Creates the top of the window. */
protected void createTopOfWindow(Container parent) {
    GridBagConstraints c = new GridBagConstraints();
    JLabel img = new URLLabel(getLargeLicenseURLString(), getLargeLicenseIcon());
    c.insets = new Insets(4, 4, 2, 0);
    parent.add(img, c);//from w  w w .  jav  a 2  s.c  o m

    JComponent line = new Line(ThemeFileHandler.TABLE_BACKGROUND_COLOR.getValue());
    c.insets = new Insets(0, 2, 0, 2);
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.fill = GridBagConstraints.VERTICAL;
    parent.add(line, c);

    JTextArea text = newTextArea(LICENSE.getLicense());
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(4, 0, 2, 4);
    parent.add(text, c);
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java

private JPanel creerComptePanel(final Compte compte) {

    final GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 1, 2);
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridx = GridBagConstraints.RELATIVE;
    c.gridy = 0;//from  ww w . j av  a2s  . c  o  m
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 1;
    c.weighty = 0;

    // Intitul du compte
    final JPanel panelCompte = new JPanel();
    panelCompte.setOpaque(false);
    panelCompte.setLayout(new GridBagLayout());
    panelCompte.setBorder(BorderFactory.createTitledBorder(compte.getNumero() + " " + compte.getNom()));

    // Bouton Dtails +/- du compte
    JButton boutonShow = new JButton("+/-");
    boutonShow.setOpaque(false);
    boutonShow.setHorizontalAlignment(SwingConstants.RIGHT);

    // Total du Compte
    JLabel labelCompteDebit = new JLabel(
            "Total Debit : " + GestionDevise.currencyToString(compte.getTotalDebit()));
    JLabel labelCompteCredit = new JLabel(
            " Credit : " + GestionDevise.currencyToString(compte.getTotalCredit()));
    // labelCompte.setFont(new Font(labelCompte.getFont().getFontName(), Font.BOLD, 12));
    labelCompteDebit.setHorizontalAlignment(SwingUtilities.LEFT);
    labelCompteCredit.setHorizontalAlignment(SwingUtilities.LEFT);

    JLabel labelTmp = new JLabel(compte.getNumero() + " " + compte.getNom());
    labelTmp.setHorizontalAlignment(SwingUtilities.LEFT);

    panelCompte.add(labelTmp, c);
    panelCompte.add(labelCompteDebit, c);
    panelCompte.add(labelCompteCredit, c);
    c.weightx = 1;
    c.anchor = GridBagConstraints.NORTHEAST;
    panelCompte.add(boutonShow, c);

    boutonShow.addActionListener(new ActionListener() {
        private boolean isShow = false;
        private JScrollPane scroll = null;

        public void actionPerformed(ActionEvent e) {

            System.err.println(this.isShow);
            // Afficher la JTable du compte
            if (!this.isShow) {
                // if (this.scroll == null) {
                System.err.println(compte);
                JTable tableCpt = createJTableCompte(compte);

                this.scroll = new JScrollPane(tableCpt);

                // calcul de la taille du JScrollPane
                Dimension d;
                System.err.println(tableCpt);
                if (tableCpt.getPreferredSize().height > 200) {
                    d = new Dimension(this.scroll.getPreferredSize().width, 200);
                } else {
                    d = new Dimension(this.scroll.getPreferredSize().width,
                            tableCpt.getPreferredSize().height + 30);
                }
                this.scroll.setPreferredSize(d);

                c.gridy++;
                c.gridwidth = 4;
                c.weightx = 1;
                c.fill = GridBagConstraints.HORIZONTAL;
                c.anchor = GridBagConstraints.NORTHWEST;
                panelCompte.add(this.scroll, c);
                /*
                 * } else { this.scroll.setVisible(true); }
                 */

            } else {
                // if (this.scroll != null) {
                panelCompte.remove(this.scroll);
                System.out.println("Hide scrollPane");
                // this.scroll.setVisible(false);

                // this.scroll.repaint();
                panelCompte.repaint();
                panelCompte.revalidate();
                // }
            }

            this.isShow = !this.isShow;
            SwingUtilities.getRoot(panelCompte).repaint();
        }
    });

    return panelCompte;
}

From source file:pcgen.gui2.tabs.SummaryInfoTab.java

private void initComponents() {
    this.setFocusCycleRoot(true);
    this.setFocusTraversalPolicyProvider(true);
    this.setFocusTraversalPolicy(new SummaryTabFocusTraversalPolicy());

    LanguageTableModel.initializeTable(languageTable);

    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    setPanelTitle(basicsPanel, LanguageBundle.getString("in_sumCharacterBasics")); //$NON-NLS-1$
    basicsPanel.setLayout(new GridBagLayout());
    deityComboBox.setRenderer(infoBoxRenderer);
    raceComboBox.setRenderer(infoBoxRenderer);
    classComboBox.setRenderer(classBoxRenderer);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 0.1;//  w w  w  .  j av a 2  s .  com
    gbc.weighty = 0.7;
    add(basicsPanel, gbc);

    setPanelTitle(todoPanel, LanguageBundle.getString("in_tipsString")); //$NON-NLS-1$
    initTodoPanel(todoPanel);
    gbc.gridy = 1;
    gbc.gridheight = GridBagConstraints.REMAINDER;
    add(todoPanel, gbc);

    initMiddlePanel(scoresPanel);
    gbc.gridy = GridBagConstraints.RELATIVE;
    gbc.weightx = 1;
    add(scoresPanel, gbc);

    JPanel rightPanel = new JPanel();
    setPanelTitle(racePanel, LanguageBundle.getString("in_raceString")); //$NON-NLS-1$
    setPanelTitle(classPanel, LanguageBundle.getString("in_sumClassLevel")); //$NON-NLS-1$
    initRightPanel(rightPanel);
    gbc.weightx = 0.1;
    gbc.weighty = 1;
    add(rightPanel, gbc);
}

From source file:com.limegroup.gnutella.gui.LicenseWindow.java

/**
 * Constructs the dialog itself.//from   ww w . j  a va  2s  .  com
 */
protected void constructDialog(Container parent) {
    // Add the 
    //  [ img ] | [ license ]
    createTopOfWindow(parent);

    GridBagConstraints c = new GridBagConstraints();

    // Add a -----------
    // line below img & license
    JComponent line = new Line(ThemeFileHandler.TABLE_BACKGROUND_COLOR.getValue());
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(0, 0, 2, 0);
    parent.add(line, c);

    // Create the details panel.
    buildDetails();

    // Add the details panel.
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(4, 4, 0, 4);
    c.weighty = 1;
    c.weightx = 1;
    parent.add(DETAILS, c);

    // Add a ------------
    // line below the details.
    line = new Line(ThemeFileHandler.TABLE_BACKGROUND_COLOR.getValue());
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.gridheight = GridBagConstraints.RELATIVE;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(2, 0, 2, 0);
    c.ipady = 0;
    c.weighty = 0;
    c.weightx = 0;
    parent.add(line, c);

    // Add an OK button out of the window.
    JButton button = new JButton(GUIMediator.getStringResource("GENERAL_OK_BUTTON_LABEL"));
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            LicenseWindow.this.dispose();
            LicenseWindow.this.setVisible(false);
        }
    });
    c.gridheight = GridBagConstraints.REMAINDER;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.insets = new Insets(0, 0, 4, 4);
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.EAST;
    parent.add(button, c);

    pack();
}

From source file:org.fhcrc.cpl.viewer.quant.gui.ProteinQuantSummaryFrame.java

License:asdf

/**
 * Initialize the GUI components//from  ww w.ja v  a 2  s  .c o  m
 */
protected void initGUI() {
    //Global stuff
    setSize(fullWidth, fullHeight);

    eventPropertiesTable = new QuantEvent.QuantEventPropertiesTable();
    eventPropertiesTable.setVisible(true);
    JScrollPane eventPropsScrollPane = new JScrollPane();
    eventPropsScrollPane.setViewportView(eventPropertiesTable);
    eventPropsScrollPane.setSize(propertiesWidth, propertiesHeight);
    eventPropertiesDialog = new JDialog(this, "Event Properties");
    eventPropertiesDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    eventPropertiesDialog.setSize(propertiesWidth, propertiesHeight);
    eventPropertiesDialog.setContentPane(eventPropsScrollPane);

    ListenerHelper helper = new ListenerHelper(this);
    setTitle("Protein Summary");
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 1;
    gbc.weightx = 1;

    try {
        (getOwner()).setIconImage(ImageIO.read(WorkbenchFrame.class.getResourceAsStream("icon.gif")));
    } catch (Exception e) {
    }

    try {
        Localizer.renderSwixml("org/fhcrc/cpl/viewer/quant/gui/ProteinQuantSummaryFrame.xml", this);
        assert null != contentPanel;
        setContentPane(contentPanel);
    } catch (Exception x) {
        ApplicationContext.errorMessage("error creating dialog", x);
        throw new RuntimeException(x);
    }

    buttonSelectAllVisible.setEnabled(false);
    helper.addListener(buttonSelectAllVisible, "buttonSelectAllVisible_actionPerformed");
    buttonDeselectAll.setEnabled(false);
    helper.addListener(buttonDeselectAll, "buttonDeselectAll_actionPerformed");

    buildTurkHITsButton.setEnabled(false);
    helper.addListener(buildTurkHITsButton, "buttonBuildTurkHITs_actionPerformed");
    loadSelectedEventsButton.setEnabled(false);
    helper.addListener(loadSelectedEventsButton, "buttonLoadSelected_actionPerformed");
    autoAssessSelectedEventsButton.setEnabled(false);
    helper.addListener(autoAssessSelectedEventsButton, "buttonAutoAssess_actionPerformed");

    showPropertiesButton.setEnabled(false);
    helper.addListener(showPropertiesButton, "buttonShowProperties_actionPerformed");
    showProteinRatiosButton.setEnabled(false);
    helper.addListener(showProteinRatiosButton, "buttonShowProteinRatios_actionPerformed");

    //summary panel
    summaryPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
    summaryPanel.setPreferredSize(new Dimension(fullWidth, summaryPanelHeight));
    summaryPanel.setMinimumSize(new Dimension(200, summaryPanelHeight));
    gbc.fill = GridBagConstraints.NONE;

    gbc.gridwidth = 1;
    summaryPanel.add(buttonSelectAllVisible, gbc);
    summaryPanel.add(buttonDeselectAll, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    summaryPanel.add(showPropertiesButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    summaryPanel.add(showProteinRatiosButton, gbc);

    gbc.gridwidth = 1;

    summaryPanel.add(loadSelectedEventsButton, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    summaryPanel.add(autoAssessSelectedEventsButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    summaryPanel.add(buildTurkHITsButton, gbc);

    gbc.fill = GridBagConstraints.BOTH;

    eventsScrollPane = new JScrollPane();
    eventsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    eventsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    eventsPanel = new JPanel();
    eventsPanel.setLayout(new GridBagLayout());

    eventsTable = new QuantEventsSummaryTable();
    eventsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    eventsTable.getSelectionModel().addListSelectionListener(new EventsTableListSelectionHandler());
    eventsScrollPane.setViewportView(eventsTable);
    eventsScrollPane.setMinimumSize(new Dimension(400, 400));

    gbc.insets = new Insets(0, 0, 0, 0);
    mainPanel.add(eventsScrollPane, gbc);

    logRatioHistogramPanel = new PanelWithLogRatioHistAndFields();
    logRatioHistogramPanel.setBorder(BorderFactory.createTitledBorder("Log Ratios"));
    logRatioHistogramPanel.setPreferredSize(new Dimension(width - 10, 300));
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 100;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    add(logRatioHistogramPanel, gbc);

    //status message
    messageLabel = new JLabel();
    messageLabel.setBackground(Color.WHITE);
    messageLabel.setFont(Font.decode("verdana plain 12"));
    messageLabel.setText(" ");
    statusPanel = new JPanel();
    gbc.weighty = 1;
    statusPanel.setPreferredSize(new Dimension(width - 10, 50));
    statusPanel.add(messageLabel, gbc);
    add(statusPanel, gbc);

    //per-protein event summary table; disembodied
    //todo: move this into its own class? it's getting kind of complicated
    proteinRatiosTable = new JTable();
    proteinRatiosTable.setVisible(true);
    ListSelectionModel proteinTableSelectionModel = proteinRatiosTable.getSelectionModel();
    proteinTableSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    proteinTableSelectionModel.addListSelectionListener(new ProteinTableListSelectionHandler());
    JScrollPane proteinRatiosScrollPane = new JScrollPane();
    proteinRatiosScrollPane.setViewportView(proteinRatiosTable);
    proteinRatiosScrollPane.setPreferredSize(new Dimension(proteinDialogWidth,
            proteinDialogHeight - PROTEINTABLE_HISTPANEL_HEIGHT - PROTEINTABLE_SCATTERPLOTPANEL_HEIGHT - 70));
    proteinRatiosDialog = new JDialog(this, "Protein Ratios");
    proteinRatiosDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    proteinRatiosDialog.setSize(proteinDialogWidth, proteinDialogHeight);
    JPanel proteinRatiosContentPanel = new JPanel();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.BOTH;
    proteinRatiosContentPanel.add(proteinRatiosScrollPane, gbc);
    proteinRatiosDialog.setContentPane(proteinRatiosContentPanel);
    perProteinLogRatioHistogramPanel = new PanelWithLogRatioHistAndFields();
    perProteinLogRatioHistogramPanel.addRangeUpdateListener(new ProteinTableLogRatioHistogramListener());

    perProteinLogRatioHistogramPanel.setBorder(BorderFactory.createTitledBorder("Log Ratios"));
    perProteinLogRatioHistogramPanel
            .setPreferredSize(new Dimension(proteinDialogWidth - 10, PROTEINTABLE_HISTPANEL_HEIGHT));
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    proteinRatiosDialog.add(perProteinLogRatioHistogramPanel, gbc);

    perProteinPeptideLogRatioPanel = new JPanel();
    perProteinPeptideLogRatioPanel.setBorder(BorderFactory.createTitledBorder("By Peptide"));
    perProteinPeptideLogRatioPanel
            .setPreferredSize(new Dimension(proteinDialogWidth - 10, PROTEINTABLE_SCATTERPLOTPANEL_HEIGHT));
    proteinRatiosDialog.add(perProteinPeptideLogRatioPanel, gbc);
}

From source file:net.sf.taverna.t2.workbench.cagrid.CaGridComponent.java

protected void addcagridService() {
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;//from   ww w. j  a v  a2s.  c o m
    c.gridy = ++row;
    c.anchor = GridBagConstraints.LINE_END;
    c.ipadx = 5;
    c.ipady = 5;
    add(new JLabel("CaGrid Service URL :"), c);

    c.weightx = 0.1;
    c.anchor = GridBagConstraints.LINE_START;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = GridBagConstraints.RELATIVE;

    services = new JComboBox();
    services.addItem("https://bridled.ci.uchicago.edu:5000/wsrf/services/cagrid/TavernaWorkflowService");
    services.addItem("http://test.cagrid.org//wsrf/services/cagrid/TavernaWorkflowService");
    services.setSelectedIndex(0);
    //set the list of available caGrid workflow services here
    //services.addActionListener(new ServiceSelectionListener());
    services.setEditable(true);
    add(services, c);
    c.weightx = 0;

    //Action connectService = new ConnectServiceAction();
    testButton = new JButton("Test Service", WorkbenchIcons.configureIcon);
    testButton.setActionCommand("test");
    testButton.addActionListener(this);
    add(testButton, c);

    //Action addService = new NewServiceAction();
    //add(new JButton("addService"), c);

    //Action editService = new EditServiceAction();
    //editButton = new JButton("editService");
    //add(editButton, c);

    //Action removeService = new RemoveServiceAction();
    //removeButton = new JButton("removeService");
    //add(removeButton, c);
}

From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java

public void init() {
    this.addWindowListener(getWindowClosingListener());
    this.setTitle(windowTitle);
    this.setSize(windowWidth, windowHeight);
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    JPanel containerPanel = new JPanel();
    getContentPane().add(containerPanel);

    /*/*  w  ww .  j  ava  2s.c  o m*/
     * Use a BorderLayout for the main container so we can use the SOUTH
     * panel as a status bar and use the NORTH panel as a menu bar, etc.
     */
    containerPanel.setLayout(new BorderLayout());

    JPanel bottomPanel = new JPanel();
    containerPanel.add(bottomPanel, BorderLayout.SOUTH);
    bottomPanel.setLayout(new BorderLayout());

    JPanel buttonPanel = new JPanel();
    bottomPanel.add(buttonPanel, BorderLayout.CENTER);

    GridLayout gridLayout = new GridLayout(1, 2, 5, 5);
    buttonPanel.setLayout(gridLayout);
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    startButton = new JButton(startButtonText);
    startButton.addActionListener(getStartButtonActionListener(false));

    buttonPanel.add(startButton);

    debugButton = new JButton(debugButtonText);
    debugButton.addActionListener(getStartButtonActionListener(true));

    buttonPanel.add(debugButton);

    continueButton = new JButton(continueButtonText);
    continueButton.addActionListener(getContinueButtonActionListener());

    buttonPanel.add(continueButton);
    continueButton.setEnabled(false);

    stopButton = new JButton(stopButtonText);
    stopButton.addActionListener(getStopButtonActionListener());

    buttonPanel.add(stopButton);
    stopButton.setEnabled(false);

    JPanel statusPanel = new JPanel();
    bottomPanel.add(statusPanel, BorderLayout.SOUTH);

    statusLabel = new JLabel(statusNotRunning);
    statusPanel.add(statusLabel);

    /*
     * Next make a grid bag for the thirteen input elements with labels on
     * the left and spinners on the right.
     */
    JPanel mainPanel = new JPanel();
    GridBagLayout gridBagLayout = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.fill = GridBagConstraints.BOTH;
    constraints.insets = new Insets(5, 5, 5, 5);
    constraints.anchor = GridBagConstraints.WEST;
    mainPanel.setLayout(gridBagLayout);
    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    containerPanel.add(mainPanel, BorderLayout.CENTER);

    List<Cipher> ciphers = cipherDao.findAll();
    cipherMap = new HashMap<String, Cipher>();
    cipherComboBox = new JComboBox<String>();
    String cipherName;
    for (Cipher cipher : ciphers) {
        cipherName = cipher.getName();
        cipherMap.put(cipherName, cipher);

        cipherComboBox.addItem(cipherName);

        if (cipher.getName().equals(defaultCipher)) {
            cipherComboBox.setSelectedItem(cipherName);
        }
    }
    JLabel cipherNameLabel = new JLabel(cipherNameText);
    cipherComboBox.addActionListener(getCipherComboBoxActionListener());

    constraints.weightx = LAYOUT_LABEL_WEIGHT;
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    gridBagLayout.setConstraints(cipherNameLabel, constraints);
    mainPanel.add(cipherNameLabel);
    constraints.weightx = LAYOUT_INPUT_WEIGHT;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(cipherComboBox, constraints);
    mainPanel.add(cipherComboBox);

    appendGenerationsSpinner(gridBagLayout, constraints, mainPanel);

    appendRunContinuouslyCheckBox(gridBagLayout, constraints, mainPanel);

    appendPopulationSpinner(gridBagLayout, constraints, mainPanel);

    appendLifespanSpinner(gridBagLayout, constraints, mainPanel);

    appendSurvivalRateSpinner(gridBagLayout, constraints, mainPanel);

    appendMutationRateSpinner(gridBagLayout, constraints, mainPanel);

    appendMaxMutationsPerIndividualSpinner(gridBagLayout, constraints, mainPanel);

    appendCrossoverRateSpinner(gridBagLayout, constraints, mainPanel);

    appendMutateDuringCrossoverCheckBox(gridBagLayout, constraints, mainPanel);

    appendFitnessEvaluatorComboBox(gridBagLayout, constraints, mainPanel);

    appendCrossoverAlgorithmComboBox(gridBagLayout, constraints, mainPanel);

    appendMutationAlgorithmComboBox(gridBagLayout, constraints, mainPanel);

    appendSelectionAlgorithmComboBox(gridBagLayout, constraints, mainPanel);

    appendSelectorComboBox(gridBagLayout, constraints, mainPanel);

    appendCompareToKnownSolutionCheckBox(gridBagLayout, constraints, mainPanel);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            setVisible(true);
            toFront();
        }
    });
}

From source file:mazewar.Mazewar.java

/**
 * The place where all the pieces are put together.
 *//*from  ww w  .  j  ava 2s.  co m*/
public Mazewar(String zkServer, int zkPort, int port, String name, String game, boolean robot) {
    super("ECE419 Mazewar");
    consolePrintLn("ECE419 Mazewar started!");

    /* Set up parent */
    ZK_PARENT += game;

    // Throw up a dialog to get the GUIClient name.
    if (name != null) {
        clientId = name;
    } else {
        clientId = JOptionPane.showInputDialog("Enter your name");
    }
    if ((clientId == null) || (clientId.length() == 0)) {
        Mazewar.quit();
    }

    /* Connect to ZooKeeper and get sequencer details */
    List<ClientNode> nodeList = null;
    try {
        zkWatcher = new ZkWatcher();
        zkConnected = new CountDownLatch(1);
        zooKeeper = new ZooKeeper(zkServer + ":" + zkPort, ZK_TIMEOUT, new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                /* Release Lock if ZooKeeper is connected */
                if (event.getState() == SyncConnected) {
                    zkConnected.countDown();
                } else {
                    System.err.println("Could not connect to ZooKeeper!");
                    System.exit(0);
                }
            }
        });
        zkConnected.await();

        /* Successfully connected, now create our node on ZooKeeper */
        zooKeeper.create(Joiner.on('/').join(ZK_PARENT, clientId),
                Joiner.on(':').join(InetAddress.getLocalHost().getHostAddress(), port).getBytes(),
                ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL_SEQUENTIAL);

        /* Get Seed from Parent */
        mazeSeed = Long.parseLong(new String(zooKeeper.getData(ZK_PARENT, false, null)));

        /* Initialize Sequence Number */
        sequenceNumber = new AtomicInteger(zooKeeper.exists(ZK_PARENT, false).getVersion());

        /* Get list of nodes */
        nodeList = ClientNode.sortList(zooKeeper.getChildren(ZK_PARENT, false));
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }

    // Create the maze
    maze = new MazeImpl(new Point(mazeWidth, mazeHeight), mazeSeed);
    assert (maze != null);

    // Have the ScoreTableModel listen to the maze to find
    // out how to adjust scores.
    ScoreTableModel scoreModel = new ScoreTableModel();
    assert (scoreModel != null);
    maze.addMazeListener(scoreModel);

    /* Initialize packet queue */
    packetQueue = new ArrayBlockingQueue<MazePacket>(QUEUE_SIZE);
    sequencedQueue = new PriorityBlockingQueue<MazePacket>(QUEUE_SIZE, new Comparator<MazePacket>() {
        @Override
        public int compare(MazePacket o1, MazePacket o2) {
            return o1.sequenceNumber.compareTo(o2.sequenceNumber);
        }
    });

    /* Inject Event Bus into Client */
    Client.setEventBus(eventBus);

    /* Initialize ZMQ Context */
    context = ZMQ.context(2);

    /* Set up publisher */
    publisher = context.socket(ZMQ.PUB);
    publisher.bind("tcp://*:" + port);
    System.out.println("ZeroMQ Publisher Bound On: " + port);

    try {
        Thread.sleep(100);
    } catch (Exception e) {
        e.printStackTrace();
    }

    /* Set up subscriber */
    subscriber = context.socket(ZMQ.SUB);
    subscriber.subscribe(ArrayUtils.EMPTY_BYTE_ARRAY);

    clients = new ConcurrentHashMap<String, Client>();
    try {
        for (ClientNode client : nodeList) {
            if (client.getName().equals(clientId)) {
                clientPath = ZK_PARENT + "/" + client.getPath();
                guiClient = robot ? new RobotClient(clientId) : new GUIClient(clientId);
                clients.put(clientId, guiClient);
                maze.addClient(guiClient);
                eventBus.register(guiClient);
                subscriber.connect("tcp://" + new String(zooKeeper.getData(clientPath, false, null)));
            } else {
                addRemoteClient(client);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    checkNotNull(guiClient, "Should have received our clientId in CLIENTS list!");

    // Create the GUIClient and connect it to the KeyListener queue
    this.addKeyListener(guiClient);
    this.isRobot = robot;

    // Use braces to force constructors not to be called at the beginning of the
    // constructor.
    /*{
    maze.addClient(new RobotClient("Norby"));
    maze.addClient(new RobotClient("Robbie"));
    maze.addClient(new RobotClient("Clango"));
    maze.addClient(new RobotClient("Marvin"));
    }*/

    // Create the panel that will display the maze.
    overheadPanel = new OverheadMazePanel(maze, guiClient);
    assert (overheadPanel != null);
    maze.addMazeListener(overheadPanel);

    // Don't allow editing the console from the GUI
    console.setEditable(false);
    console.setFocusable(false);
    console.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder()));

    // Allow the console to scroll by putting it in a scrollpane
    JScrollPane consoleScrollPane = new JScrollPane(console);
    assert (consoleScrollPane != null);
    consoleScrollPane
            .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Console"));

    // Create the score table
    scoreTable = new JTable(scoreModel);
    assert (scoreTable != null);
    scoreTable.setFocusable(false);
    scoreTable.setRowSelectionAllowed(false);

    // Allow the score table to scroll too.
    JScrollPane scoreScrollPane = new JScrollPane(scoreTable);
    assert (scoreScrollPane != null);
    scoreScrollPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Scores"));

    // Create the layout manager
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();
    getContentPane().setLayout(layout);

    // Define the constraints on the components.
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1.0;
    c.weighty = 3.0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    layout.setConstraints(overheadPanel, c);
    c.gridwidth = GridBagConstraints.RELATIVE;
    c.weightx = 2.0;
    c.weighty = 1.0;
    layout.setConstraints(consoleScrollPane, c);
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    layout.setConstraints(scoreScrollPane, c);

    // Add the components
    getContentPane().add(overheadPanel);
    getContentPane().add(consoleScrollPane);
    getContentPane().add(scoreScrollPane);

    // Pack everything neatly.
    pack();

    // Let the magic begin.
    setVisible(true);
    overheadPanel.repaint();
    this.requestFocusInWindow();
}

From source file:org.fhcrc.cpl.viewer.quant.gui.QuantitationReviewer.java

/**
 * Initialize all GUI components and display the UI
 *///from   w w  w . j  a  v a2 s  .co  m
protected void initGUI() {
    settingsCLM = new ProteinQuantChartsCLM(false);

    setTitle("Qurate");
    try {
        setIconImage(ImageIO.read(WorkbenchFrame.class.getResourceAsStream("icon.gif")));
    } catch (Exception e) {
    }

    try {
        Localizer.renderSwixml("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewer.xml", this);
        assert null != contentPanel;
    } catch (Exception x) {
        ApplicationContext.errorMessage("error creating dialog", x);
        throw new RuntimeException(x);
    }

    //Menu
    openFileAction = new OpenFileAction(this);
    createChartsAction = new CreateChartsAction();
    filterPepXMLAction = new FilterPepXMLAction(this);
    proteinSummaryAction = new ProteinSummaryAction(this);

    try {
        JMenuBar jmenu = (JMenuBar) Localizer.getSwingEngine(this)
                .render("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewerMenu.xml");
        for (int i = 0; i < jmenu.getMenuCount(); i++)
            jmenu.getMenu(i).getPopupMenu().setLightWeightPopupEnabled(false);
        this.setJMenuBar(jmenu);
    } catch (Exception x) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_LOADING_MENUS"), x);
        throw new RuntimeException(x);
    }

    //Global stuff
    setSize(fullWidth, fullHeight);
    setContentPane(contentPanel);
    ListenerHelper helper = new ListenerHelper(this);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 1;
    gbc.weightx = 1;

    leftPanel.setLayout(new GridBagLayout());
    leftPanel.setBorder(BorderFactory.createLineBorder(Color.gray));

    //Properties panel stuff
    propertiesTable = new QuantEvent.QuantEventPropertiesTable();
    propertiesScrollPane = new JScrollPane();
    propertiesScrollPane.setViewportView(propertiesTable);
    propertiesScrollPane.setMinimumSize(new Dimension(propertiesWidth, propertiesHeight));

    //event summary table; disembodied
    eventSummaryTable = new QuantEventsSummaryTable();
    eventSummaryTable.setVisible(true);
    ListSelectionModel tableSelectionModel = eventSummaryTable.getSelectionModel();
    tableSelectionModel.addListSelectionListener(new EventSummaryTableListSelectionHandler());
    JScrollPane eventSummaryScrollPane = new JScrollPane();
    eventSummaryScrollPane.setViewportView(eventSummaryTable);
    eventSummaryScrollPane.setSize(propertiesWidth, propertiesHeight);
    eventSummaryFrame = new Frame("All Events");
    eventSummaryFrame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            eventSummaryFrame.setVisible(false);
        }
    });
    eventSummaryFrame.setSize(950, 450);
    eventSummaryFrame.add(eventSummaryScrollPane);

    //fields related to navigation
    navigationPanel = new JPanel();
    backButton = new JButton("<");
    backButton.setToolTipText("Previous Event");
    backButton.setMaximumSize(new Dimension(50, 30));
    backButton.setEnabled(false);
    forwardButton = new JButton(">");
    forwardButton.setToolTipText("Next Event");
    forwardButton.setMaximumSize(new Dimension(50, 30));
    forwardButton.setEnabled(false);
    showEventSummaryButton = new JButton("Show All");
    showEventSummaryButton.setToolTipText("Show all events in a table");
    showEventSummaryButton.setEnabled(false);

    helper.addListener(backButton, "buttonBack_actionPerformed");
    helper.addListener(forwardButton, "buttonForward_actionPerformed");
    helper.addListener(showEventSummaryButton, "buttonShowEventSummary_actionPerformed");

    gbc.fill = GridBagConstraints.NONE;
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    gbc.anchor = GridBagConstraints.WEST;
    navigationPanel.add(backButton, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    navigationPanel.add(forwardButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    navigationPanel.add(showEventSummaryButton, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    navigationPanel.setBorder(BorderFactory.createTitledBorder("Event"));
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Fields related to curation of events
    curationPanel = new JPanel();
    curationPanel.setLayout(new GridBagLayout());
    curationPanel.setBorder(BorderFactory.createTitledBorder("Curation"));
    //Quantitation curation
    JPanel quantCurationPanel = new JPanel();
    quantCurationPanel.setLayout(new GridBagLayout());
    quantCurationPanel.setBorder(BorderFactory.createTitledBorder("Quantitation"));
    quantCurationButtonGroup = new ButtonGroup();
    JRadioButton unknownRadioButton = new JRadioButton("?");
    JRadioButton goodRadioButton = new JRadioButton("Good");
    JRadioButton badRadioButton = new JRadioButton("Bad");
    onePeakRatioRadioButton = new JRadioButton("1-Peak");

    unknownRadioButton.setEnabled(false);
    goodRadioButton.setEnabled(false);
    badRadioButton.setEnabled(false);
    onePeakRatioRadioButton.setEnabled(false);

    quantCurationButtonGroup.add(unknownRadioButton);
    quantCurationButtonGroup.add(goodRadioButton);
    quantCurationButtonGroup.add(badRadioButton);
    quantCurationButtonGroup.add(onePeakRatioRadioButton);

    unknownRadioButtonModel = unknownRadioButton.getModel();
    goodRadioButtonModel = goodRadioButton.getModel();
    badRadioButtonModel = badRadioButton.getModel();
    onePeakRadioButtonModel = onePeakRatioRadioButton.getModel();

    helper.addListener(unknownRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(goodRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(badRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(onePeakRadioButtonModel, "buttonCuration_actionPerformed");

    gbc.anchor = GridBagConstraints.WEST;
    quantCurationPanel.add(unknownRadioButton, gbc);
    quantCurationPanel.add(badRadioButton, gbc);
    quantCurationPanel.add(goodRadioButton, gbc);
    quantCurationPanel.add(onePeakRatioRadioButton, gbc);

    gbc.anchor = GridBagConstraints.PAGE_START;
    //ID curation
    JPanel idCurationPanel = new JPanel();
    idCurationPanel.setLayout(new GridBagLayout());
    idCurationPanel.setBorder(BorderFactory.createTitledBorder("ID"));
    idCurationButtonGroup = new ButtonGroup();
    JRadioButton idUnknownRadioButton = new JRadioButton("?");
    JRadioButton idGoodRadioButton = new JRadioButton("Good");
    JRadioButton idBadRadioButton = new JRadioButton("Bad");
    idUnknownRadioButton.setEnabled(false);
    idGoodRadioButton.setEnabled(false);
    idBadRadioButton.setEnabled(false);

    idCurationButtonGroup.add(idUnknownRadioButton);
    idCurationButtonGroup.add(idGoodRadioButton);
    idCurationButtonGroup.add(idBadRadioButton);
    idUnknownRadioButtonModel = idUnknownRadioButton.getModel();
    idGoodRadioButtonModel = idGoodRadioButton.getModel();
    idBadRadioButtonModel = idBadRadioButton.getModel();
    helper.addListener(idUnknownRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idGoodRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idBadRadioButton, "buttonIDCuration_actionPerformed");
    gbc.anchor = GridBagConstraints.WEST;
    idCurationPanel.add(idUnknownRadioButton, gbc);
    idCurationPanel.add(idBadRadioButton, gbc);
    idCurationPanel.add(idGoodRadioButton, gbc);

    gbc.gridwidth = GridBagConstraints.RELATIVE;
    curationPanel.add(quantCurationPanel, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    curationPanel.add(idCurationPanel, gbc);

    //curation comment
    commentTextField = new JTextField();
    commentTextField.setToolTipText("Comment on this event");
    //saves after every keypress.  Would be more efficient to save when navigating away or saving to file
    commentTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            if (quantEvents == null)
                return;
            QuantEvent quantEvent = quantEvents.get(displayedEventIndex);
            //save the comment, being careful about tabs and new lines
            quantEvent.setComment(commentTextField.getText().replace("\t", " ").replace("\n", " "));
        }

        public void keyTyped(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });
    curationPanel.add(commentTextField, gbc);

    assessmentPanel = new JPanel();
    assessmentPanel.setLayout(new GridBagLayout());
    assessmentPanel.setBorder(BorderFactory.createTitledBorder("Algorithmic Assessment"));
    assessmentTypeTextField = new JTextField();
    assessmentTypeTextField.setEditable(false);
    assessmentPanel.add(assessmentTypeTextField, gbc);
    assessmentDescTextField = new JTextField();
    assessmentDescTextField.setEditable(false);
    assessmentPanel.add(assessmentDescTextField, gbc);

    //Theoretical peak distribution
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    theoreticalPeaksPanel = new JPanel();
    theoreticalPeaksPanel.setBorder(BorderFactory.createTitledBorder("Theoretical Peaks"));
    theoreticalPeaksPanel.setLayout(new GridBagLayout());
    theoreticalPeaksPanel.setMinimumSize(new Dimension(leftPanelWidth - 10, theoreticalPeaksPanelHeight));
    theoreticalPeaksPanel.setMaximumSize(new Dimension(1200, theoreticalPeaksPanelHeight));
    showTheoreticalPeaks();

    //Add everything to the left panel
    gbc.insets = new Insets(0, 5, 0, 5);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    leftPanel.addComponentListener(new LeftPanelResizeListener());
    gbc.weighty = 10;
    gbc.fill = GridBagConstraints.VERTICAL;
    leftPanel.add(propertiesScrollPane, gbc);
    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_END;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(assessmentPanel, gbc);
    leftPanel.add(theoreticalPeaksPanel, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(curationPanel, gbc);
    leftPanel.add(navigationPanel, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Chart display
    multiChartDisplay = new TabbedMultiChartDisplayPanel();
    multiChartDisplay.setResizeDelayMS(0);

    rightPanel.addComponentListener(new RightPanelResizeListener());
    rightPanel.add(multiChartDisplay, gbc);

    //status message
    messageLabel.setBackground(Color.WHITE);
    messageLabel.setFont(Font.decode("verdana plain 12"));
    messageLabel.setText(" ");

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    //paranoia.  Sometimes it seems Qurate doesn't exit when you close every window
    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(WindowEvent e) {
            if (e.getNewState() == WindowEvent.WINDOW_CLOSED) {
                dispose();
                System.exit(0);
            }
        }
    });

}