Example usage for java.awt GridBagLayout GridBagLayout

List of usage examples for java.awt GridBagLayout GridBagLayout

Introduction

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

Prototype

public GridBagLayout() 

Source Link

Document

Creates a grid bag layout manager.

Usage

From source file:ShowDocument.java

public URLWindow(AppletContext appletContext) {
    super("Show a Document!");
    this.appletContext = appletContext;

    JPanel contentPane = new JPanel(new GridBagLayout());
    setContentPane(contentPane);//from  www .  ja v  a  2  s  .c o  m
    contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;

    JLabel label1 = new JLabel("URL of document to show: ", JLabel.TRAILING);
    add(label1, c);

    urlField = new JTextField("http://java.sun.com/", 20);
    label1.setLabelFor(urlField);
    urlField.addActionListener(this);
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;
    add(urlField, c);

    JLabel label2 = new JLabel("Window/frame to show it in: ", JLabel.TRAILING);
    c.gridwidth = 1;
    c.weightx = 0.0;
    add(label2, c);

    String[] strings = { "(browser's choice)", //don't specify
            "My Personal Window", //a window named "My Personal Window"
            "_blank", //a new, unnamed window
            "_self", "_parent", "_top" //the Frame that contained this applet
    };
    choice = new JComboBox(strings);
    label2.setLabelFor(choice);
    c.fill = GridBagConstraints.NONE;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.insets = new Insets(5, 0, 0, 0);
    c.anchor = GridBagConstraints.LINE_START;
    add(choice, c);

    JButton button = new JButton("Show document");
    button.addActionListener(this);
    c.weighty = 1.0;
    c.ipadx = 10;
    c.ipady = 10;
    c.insets = new Insets(10, 0, 0, 0);
    c.anchor = GridBagConstraints.PAGE_END;
    add(button, c);
}

From source file:com.intuit.tank.tools.debugger.FindReplaceDialog.java

/**
 * Constructs a new find dialog according to the specified type of dialog requested. The dialog can be either a FIND
 * dialog, either a REPLACE dialog. In both cases, components displayed remain the sames, but the ones specific to
 * replace feature are grayed out.//from ww  w  .  j  a va  2  s  .c o m
 * 
 * @param parent
 *            The window holder
 * @param type
 *            The type of the dialog: FindReplace.FIND or FindReplace.REPLACE
 * @param modal
 *            Displays dialog as a modal window if true
 */

public FindReplaceDialog(AgentDebuggerFrame parent, DialogType type) {
    super(parent, type == DialogType.REPLACE ? "Replace" : "Find", true);
    this.parent = parent;

    cbSearch = new JComboBox();
    cbSearch.setEditable(true);
    cbReplace = new JComboBox();
    cbReplace.setEditable(true);
    KeyHandler handler = new KeyHandler();
    tfSearchEditor = (JTextField) cbSearch.getEditor().getEditorComponent();
    tfSearchEditor.addKeyListener(handler);
    tfReplaceEditor = (JTextField) cbReplace.getEditor().getEditorComponent();
    tfReplaceEditor.addKeyListener(handler);

    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints constraints = new GridBagConstraints();
    getContentPane().setLayout(gridbag);
    ((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    int gridX = 0;
    int gridY = 0;
    JLabel findLabel = new JLabel("Find");
    buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0);
    constraints.anchor = GridBagConstraints.WEST;
    gridbag.setConstraints(findLabel, constraints);
    getContentPane().add(findLabel);
    gridX++;

    buildConstraints(constraints, gridX, gridY, 1, 1, 100, 0);
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.CENTER;
    gridbag.setConstraints(cbSearch, constraints);
    getContentPane().add(cbSearch);
    gridX++;

    btnFind = new JButton("Find");
    btnFind.setToolTipText("Find text in scripts");
    btnFind.setMnemonic('F');
    btnFind.addActionListener(this);
    buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0);
    constraints.anchor = GridBagConstraints.CENTER;
    gridbag.setConstraints(btnFind, constraints);
    getContentPane().add(btnFind);
    getRootPane().setDefaultButton(btnFind);
    gridX++;

    btnCancel = new JButton("Cancel");
    btnCancel.setMnemonic('C');
    btnCancel.addActionListener(this);
    buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0);
    constraints.anchor = GridBagConstraints.CENTER;
    gridbag.setConstraints(btnCancel, constraints);
    getContentPane().add(btnCancel);
    gridY++;
    gridX = 0;
    if (type == DialogType.REPLACE) {
        JLabel replaceLabel = new JLabel("Replace");
        buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0);
        constraints.anchor = GridBagConstraints.WEST;
        gridbag.setConstraints(replaceLabel, constraints);
        getContentPane().add(replaceLabel);
        gridX++;

        buildConstraints(constraints, gridX, gridY, 1, 1, 100, 0);
        constraints.fill = GridBagConstraints.HORIZONTAL;
        constraints.anchor = GridBagConstraints.CENTER;
        gridbag.setConstraints(cbReplace, constraints);
        getContentPane().add(cbReplace);
        gridX++;

        btnReplace = new JButton("Replace");
        btnReplace.setToolTipText("REplace in script");
        btnReplace.setMnemonic('R');
        btnReplace.addActionListener(this);
        buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0);
        constraints.anchor = GridBagConstraints.CENTER;
        gridbag.setConstraints(btnReplace, constraints);
        getContentPane().add(btnReplace);
        gridX++;

        btnReplaceAll = new JButton("Replace All");
        btnReplaceAll.addActionListener(this);
        buildConstraints(constraints, gridX, gridY, 1, 1, 0, 0);
        constraints.anchor = GridBagConstraints.CENTER;
        gridbag.setConstraints(btnReplaceAll, constraints);
        getContentPane().add(btnReplaceAll);
        btnReplace.addKeyListener(handler);
        btnReplaceAll.addKeyListener(handler);
        gridY++;
        gridX = 0;
    }

    TitledBorder border = new TitledBorder("Options");
    JPanel panel = new JPanel(new GridLayout(1, 4));
    panel.setBorder(border);
    checkboxWrap = new JCheckBox("Wrap Search");
    panel.add(checkboxWrap);

    checkboxMatchCase = new JCheckBox("Case sensitive");
    panel.add(checkboxMatchCase);

    checkboxRegexp = new JCheckBox("Regular expressions");
    panel.add(checkboxRegexp);

    buildConstraints(constraints, gridX, gridY, 4, 1, 100, 100);
    constraints.anchor = GridBagConstraints.WEST;
    gridbag.setConstraints(panel, constraints);
    getContentPane().add(panel);

    FontMetrics fm = getFontMetrics(getFont());
    cbSearch.setPreferredSize(new Dimension(18 * fm.charWidth('m'), (int) cbSearch.getPreferredSize().height));
    cbReplace
            .setPreferredSize(new Dimension(18 * fm.charWidth('m'), (int) cbReplace.getPreferredSize().height));

    pack();
    // setResizable(false);
    WindowUtil.centerOnParent(this);

    // patch by MJB 8/1/2002
    btnFind.addKeyListener(handler);

    btnCancel.addKeyListener(handler);
    checkboxMatchCase.addKeyListener(handler);
    checkboxRegexp.addKeyListener(handler);

}

From source file:com.sshtools.common.ui.HostsTab.java

/**
 * Creates a new HostsTab object./*from ww w . j a va  2s .c om*/
 *
 * @param hostKeyVerifier
 */
public HostsTab(AbstractKnownHostsKeyVerification hostKeyVerifier) {
    super();
    this.hostKeyVerifier = hostKeyVerifier;
    hosts = new JList(model = new HostsListModel());
    hosts.setVisibleRowCount(10);
    hosts.setCellRenderer(new HostRenderer());
    hosts.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            setAvailableActions();
        }
    });
    remove = new JButton("Remove", new ResourceIcon(REMOVE_ICON));
    remove.addActionListener(this);

    //deny = new JButton("Deny", new ResourceIcon(DENY_ICON));
    //deny.addActionListener(this);
    JPanel b = new JPanel(new GridBagLayout());
    b.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0));

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(0, 0, 4, 0);
    gbc.anchor = GridBagConstraints.NORTH;
    gbc.weightx = 1.0;
    UIUtil.jGridBagAdd(b, remove, gbc, GridBagConstraints.REMAINDER);
    gbc.weighty = 1.0;

    //UIUtil.jGridBagAdd(b, deny, gbc, GridBagConstraints.REMAINDER);
    JPanel s = new JPanel(new BorderLayout());
    s.add(new JScrollPane(hosts), BorderLayout.CENTER);
    s.add(b, BorderLayout.EAST);

    IconWrapperPanel w = new IconWrapperPanel(new ResourceIcon(GLOBAL_ICON), s);

    //  This tab
    setLayout(new BorderLayout());
    add(w, BorderLayout.CENTER);
    setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    reset();
}

From source file:EditorPaneExample18.java

public EditorPaneExample18() {
    super("JEditorPane Example 18");

    pane = new JEditorPane();
    pane.setEditable(true); // Editable
    getContentPane().add(new JScrollPane(pane), "Center");

    // Add a menu bar
    menuBar = new JMenuBar();
    setJMenuBar(menuBar);/* w ww .  ja  va  2 s  .c  o  m*/

    // Populate it
    createMenuBar();

    // Build the panel of controls
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridwidth = 1;
    c.gridheight = 1;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.0;
    c.weighty = 0.0;

    JLabel urlLabel = new JLabel("URL: ", JLabel.RIGHT);
    panel.add(urlLabel, c);
    JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT);
    c.gridy = 1;
    panel.add(loadingLabel, c);
    JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT);
    c.gridy = 2;
    panel.add(typeLabel, c);
    c.gridy = 3;
    panel.add(new JLabel(LOAD_TIME), c);

    c.gridy = 4;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    onlineLoad = new JCheckBox("Online Load");
    panel.add(onlineLoad, c);
    onlineLoad.setSelected(true);
    onlineLoad.setForeground(typeLabel.getForeground());

    c.gridy = 5;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.WEST;
    editableBox = new JCheckBox("Editable JEditorPane");
    panel.add(editableBox, c);
    editableBox.setSelected(true);
    editableBox.setForeground(typeLabel.getForeground());

    c.gridy = 6;
    c.weightx = 0.0;
    JButton saveButton = new JButton("Save");
    panel.add(saveButton, c);
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            EditorKit kit = pane.getEditorKit();
            try {
                if (kit instanceof RTFEditorKit) {
                    kit.write(System.out, pane.getDocument(), 0, pane.getDocument().getLength());
                    System.out.flush();
                } else {
                    if (writer == null) {
                        writer = new OutputStreamWriter(System.out);
                        pane.write(writer);
                        writer.flush();
                    }
                    kit.write(writer, pane.getDocument(), 0, pane.getDocument().getLength());
                    writer.flush();
                }
            } catch (Exception e) {
                System.out.println("Write failed");
            }
        }
    });

    c.gridx = 1;
    c.gridy = 0;
    c.weightx = 1.0;
    c.anchor = GridBagConstraints.EAST;
    c.fill = GridBagConstraints.HORIZONTAL;

    urlCombo = new JComboBox();
    panel.add(urlCombo, c);
    urlCombo.setEditable(true);
    loadingState = new JLabel(spaces, JLabel.LEFT);
    loadingState.setForeground(Color.black);
    c.gridy = 1;
    panel.add(loadingState, c);
    loadedType = new JLabel(spaces, JLabel.LEFT);
    loadedType.setForeground(Color.black);
    c.gridy = 2;
    panel.add(loadedType, c);
    timeLabel = new JLabel("");
    c.gridy = 3;
    panel.add(timeLabel, c);

    getContentPane().add(panel, "South");

    // Register a custom EditorKit for HTML
    ClassLoader loader = getClass().getClassLoader();
    if (loader != null) {
        // Java 2
        JEditorPane.registerEditorKitForContentType("text/html",
                "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit", loader);
    } else {
        // JDK 1.1
        JEditorPane.registerEditorKitForContentType("text/html",
                "AdvancedSwing.Chapter4.HiddenViewHTMLEditorKit");
    }

    // Allocate the empty tree model
    DefaultMutableTreeNode emptyRootNode = new DefaultMutableTreeNode("Empty");
    emptyModel = new DefaultTreeModel(emptyRootNode);

    // Create and place the heading tree
    tree = new JTree(emptyModel);
    tree.setPreferredSize(new Dimension(200, 200));
    getContentPane().add(new JScrollPane(tree), "East");

    // Change page based on combo selection
    urlCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (populatingCombo == true) {
                return;
            }
            Object selection = urlCombo.getSelectedItem();
            loadNewPage(selection);
        }
    });

    // Change editability based on the checkbox
    editableBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            pane.setEditable(editableBox.isSelected());
            pane.revalidate();
            pane.repaint();
        }
    });

    // Listen for page load to complete
    pane.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("page")) {
                loadComplete();
                displayLoadTime();
                populateCombo(findLinks(pane.getDocument(), null));
                TreeNode node = buildHeadingTree(pane.getDocument());
                tree.setModel(new DefaultTreeModel(node));

                createMenuBar();
                enableMenuBar(true);
                getRootPane().revalidate();

                enableInput();
                loadingPage = false;
            }
        }
    });

    // Listener for tree selection
    tree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent evt) {
            TreePath path = evt.getNewLeadSelectionPath();
            if (path != null) {
                DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
                Object userObject = node.getUserObject();
                if (userObject instanceof Heading) {
                    Heading heading = (Heading) userObject;
                    try {
                        Rectangle textRect = pane.modelToView(heading.getOffset());
                        textRect.y += 3 * textRect.height;
                        pane.scrollRectToVisible(textRect);
                    } catch (BadLocationException e) {
                    }
                }
            }
        }
    });

    // Listener for hypertext events
    pane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent evt) {
            // Ignore hyperlink events if the frame is busy
            if (loadingPage == true) {
                return;
            }
            if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                JEditorPane sp = (JEditorPane) evt.getSource();
                if (evt instanceof HTMLFrameHyperlinkEvent) {
                    HTMLDocument doc = (HTMLDocument) sp.getDocument();
                    doc.processHTMLFrameHyperlinkEvent((HTMLFrameHyperlinkEvent) evt);
                } else {
                    loadNewPage(evt.getURL());
                }
            } else if (evt.getEventType() == HyperlinkEvent.EventType.ENTERED) {
                pane.setCursor(handCursor);
            } else if (evt.getEventType() == HyperlinkEvent.EventType.EXITED) {
                pane.setCursor(defaultCursor);
            }
        }
    });
}

From source file:com.digitalgeneralists.assurance.ui.components.ScanPathMappingPanel.java

protected void initializeComponent() {
    if (!this.initialized) {
        if (this.mappingDefinition == null) {
            this.mode = AssuranceDialogMode.ADD;
            this.dialogTitle = "Add New Path Mapping";
            this.mappingDefinition = new ScanMappingDefinition();
        } else {//from   ww w .j  a va2  s.  c om
            this.mode = AssuranceDialogMode.EDIT;
            this.dialogTitle = "Edit Path Mapping";
        }

        GridBagLayout gridbag = new GridBagLayout();
        this.setLayout(gridbag);

        final JPanel scanPathsPanel = new JPanel();
        scanPathsPanel.setLayout(new GridBagLayout());

        Border pathsPanelBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
        pathsPanelBorder = BorderFactory.createTitledBorder(pathsPanelBorder, "Paths", TitledBorder.CENTER,
                TitledBorder.TOP);

        GridBagConstraints scanPathsPanelConstraints = new GridBagConstraints();
        scanPathsPanelConstraints.anchor = GridBagConstraints.NORTH;
        scanPathsPanelConstraints.fill = GridBagConstraints.HORIZONTAL;
        scanPathsPanelConstraints.gridx = 0;
        scanPathsPanelConstraints.gridy = 0;
        scanPathsPanelConstraints.weightx = 1.0;
        scanPathsPanelConstraints.weighty = 1.0;
        scanPathsPanelConstraints.gridheight = 1;
        scanPathsPanelConstraints.gridwidth = 2;
        scanPathsPanelConstraints.insets = new Insets(5, 5, 5, 5);

        scanPathsPanel.setBorder(pathsPanelBorder);
        this.add(scanPathsPanel, scanPathsPanelConstraints);

        GridBagConstraints sourcePathFieldConstraints = new GridBagConstraints();
        sourcePathFieldConstraints.anchor = GridBagConstraints.NORTH;
        sourcePathFieldConstraints.fill = GridBagConstraints.HORIZONTAL;
        sourcePathFieldConstraints.gridx = 0;
        sourcePathFieldConstraints.gridy = 0;
        sourcePathFieldConstraints.weightx = 1.0;
        sourcePathFieldConstraints.weighty = 1.0;
        sourcePathFieldConstraints.gridheight = 1;
        sourcePathFieldConstraints.gridwidth = 1;
        sourcePathFieldConstraints.insets = new Insets(0, 5, 5, 5);

        GridBagConstraints targetPathFieldConstraints = new GridBagConstraints();
        targetPathFieldConstraints.anchor = GridBagConstraints.NORTH;
        targetPathFieldConstraints.fill = GridBagConstraints.HORIZONTAL;
        targetPathFieldConstraints.gridx = 0;
        targetPathFieldConstraints.gridy = 1;
        targetPathFieldConstraints.weightx = 1.0;
        targetPathFieldConstraints.weighty = 1.0;
        targetPathFieldConstraints.gridheight = 1;
        targetPathFieldConstraints.gridwidth = 1;
        targetPathFieldConstraints.insets = new Insets(5, 5, 5, 5);

        scanPathsPanel.add(this.sourcePathPickerField, sourcePathFieldConstraints);
        scanPathsPanel.add(this.targetPathPickerField, targetPathFieldConstraints);

        if (mappingDefinition != null) {
            File source = mappingDefinition.getSource();
            if (source != null) {
                this.sourcePathPickerField.setValue(source.getPath());
            } else {
                this.sourcePathPickerField.setValue("");
            }
            File target = mappingDefinition.getTarget();
            if (target != null) {
                this.targetPathPickerField.setValue(target.getPath());
            } else {
                this.targetPathPickerField.setValue("");
            }
        }

        Border existingExclusionsPanelBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
        existingExclusionsPanelBorder = BorderFactory.createTitledBorder(existingExclusionsPanelBorder,
                "Exclusions", TitledBorder.CENTER, TitledBorder.TOP);

        GridBagConstraints existingExclusionsPanelConstraints = new GridBagConstraints();
        existingExclusionsPanelConstraints.anchor = GridBagConstraints.WEST;
        existingExclusionsPanelConstraints.fill = GridBagConstraints.BOTH;
        existingExclusionsPanelConstraints.gridx = 0;
        existingExclusionsPanelConstraints.gridy = 1;
        existingExclusionsPanelConstraints.weightx = 1.0;
        existingExclusionsPanelConstraints.weighty = 0.9;
        existingExclusionsPanelConstraints.gridheight = 1;
        existingExclusionsPanelConstraints.gridwidth = 2;
        existingExclusionsPanelConstraints.insets = new Insets(0, 5, 0, 5);

        JPanel existingExclusionsPanel = new JPanel();
        GridBagLayout panelGridbag = new GridBagLayout();
        existingExclusionsPanel.setLayout(panelGridbag);
        existingExclusionsPanel.setBorder(existingExclusionsPanelBorder);
        this.add(existingExclusionsPanel, existingExclusionsPanelConstraints);

        GridBagConstraints existingExclusionsListConstraints = new GridBagConstraints();
        existingExclusionsListConstraints.anchor = GridBagConstraints.WEST;
        existingExclusionsListConstraints.fill = GridBagConstraints.BOTH;
        existingExclusionsListConstraints.gridx = 0;
        existingExclusionsListConstraints.gridy = 0;
        existingExclusionsListConstraints.weightx = 1.0;
        existingExclusionsListConstraints.weighty = 0.9;
        existingExclusionsListConstraints.gridheight = 1;
        existingExclusionsListConstraints.gridwidth = 2;
        existingExclusionsListConstraints.insets = new Insets(5, 5, 5, 5);

        this.mappingDefinition = (ScanMappingDefinition) ModelUtils.initializeEntity(this.mappingDefinition,
                ScanMappingDefinition.EXCLUSIONS_PROPERTY);
        this.exclusionsPanel = new ListInputPanel<FileReference>(this.mappingDefinition, this);
        existingExclusionsPanel.add(this.exclusionsPanel, existingExclusionsListConstraints);

        this.initialized = true;
    }
}

From source file:gov.loc.repository.bagger.ui.NewBagFrame.java

private JPanel createComponents() {
    TitlePane titlePane = new TitlePane();
    initStandardCommands();//from w ww  .  j  ava2  s. c om
    JPanel pageControl = new JPanel(new BorderLayout());
    JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("NewBagFrame.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("NewBagFrame.description")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);

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

    int row = 0;
    layoutBagVersionSelection(contentPane, row++);
    layoutProfileSelection(contentPane, row++);

    if (getPreferredSize() != null) {
        contentPane.setPreferredSize(getPreferredSize());
    }

    GuiStandardUtils.attachDialogBorder(contentPane);
    pageControl.add(contentPane);
    JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;
}

From source file:com.digitalgeneralists.assurance.ui.components.ScanLaunchPanel.java

private void initializeComponent() {
    if (!this.initialized) {
        GridBagLayout gridbag = new GridBagLayout();
        this.setLayout(gridbag);

        GridBagConstraints existingScansPanelConstraints = new GridBagConstraints();
        existingScansPanelConstraints.anchor = GridBagConstraints.WEST;
        existingScansPanelConstraints.fill = GridBagConstraints.BOTH;
        existingScansPanelConstraints.gridx = 0;
        existingScansPanelConstraints.gridy = 0;
        existingScansPanelConstraints.weightx = 1.0;
        existingScansPanelConstraints.weighty = 1.0;
        existingScansPanelConstraints.gridheight = 2;
        existingScansPanelConstraints.gridwidth = 1;
        existingScansPanelConstraints.insets = new Insets(0, 0, 0, 0);

        JPanel existingScansPanel = new JPanel();
        GridBagLayout panelGridbag = new GridBagLayout();
        existingScansPanel.setLayout(panelGridbag);
        this.add(existingScansPanel, existingScansPanelConstraints);

        GridBagConstraints existingScansListConstraints = new GridBagConstraints();
        existingScansListConstraints.anchor = GridBagConstraints.WEST;
        existingScansListConstraints.fill = GridBagConstraints.BOTH;
        existingScansListConstraints.gridx = 0;
        existingScansListConstraints.gridy = 0;
        existingScansListConstraints.weightx = 1.0;
        existingScansListConstraints.weighty = 0.9;
        existingScansListConstraints.gridheight = 1;
        existingScansListConstraints.gridwidth = 2;
        existingScansListConstraints.insets = new Insets(5, 5, 5, 5);

        GridBagConstraints existingScanDefinitionsListConstraints = new GridBagConstraints();
        existingScanDefinitionsListConstraints.anchor = GridBagConstraints.WEST;
        existingScanDefinitionsListConstraints.fill = GridBagConstraints.BOTH;
        existingScanDefinitionsListConstraints.gridx = 0;
        existingScanDefinitionsListConstraints.gridy = 0;
        existingScanDefinitionsListConstraints.weightx = 1.0;
        existingScanDefinitionsListConstraints.weighty = 0.9;
        existingScanDefinitionsListConstraints.gridheight = 1;
        existingScanDefinitionsListConstraints.gridwidth = 2;
        existingScanDefinitionsListConstraints.insets = new Insets(5, 5, 5, 5);

        this.existingScanDefinitionsListPanel = new ListInputPanel<ScanDefinition>(this, this);
        existingScansPanel.add(this.existingScanDefinitionsListPanel, existingScanDefinitionsListConstraints);

        GridBagConstraints scanButtonConstraints = new GridBagConstraints();
        scanButtonConstraints.anchor = GridBagConstraints.NORTHEAST;
        scanButtonConstraints.fill = GridBagConstraints.BOTH;
        scanButtonConstraints.gridx = 1;
        scanButtonConstraints.gridy = 0;
        scanButtonConstraints.weightx = 1.0;
        scanButtonConstraints.weighty = 1.0;

        this.startScanButton.setActionCommand(AssuranceActions.scanAction);

        this.add(this.startScanButton, scanButtonConstraints);

        GridBagConstraints scanAndMergeButtonConstraints = new GridBagConstraints();
        scanAndMergeButtonConstraints.anchor = GridBagConstraints.SOUTHEAST;
        scanAndMergeButtonConstraints.fill = GridBagConstraints.BOTH;
        scanAndMergeButtonConstraints.gridx = 1;
        scanAndMergeButtonConstraints.gridy = 1;
        scanAndMergeButtonConstraints.weightx = 1.0;
        scanAndMergeButtonConstraints.weighty = 1.0;

        this.startScanAndMergeButton.setActionCommand(AssuranceActions.scanAndMergeAction);

        this.add(this.startScanAndMergeButton, scanAndMergeButtonConstraints);

        this.startScanAndMergeButton.addActionListener(this);
        this.startScanButton.addActionListener(this);

        this.startScanButton.setEnabled(false);
        this.startScanAndMergeButton.setEnabled(false);

        this.addAncestorListener(new AncestorListener() {
            public void ancestorAdded(AncestorEvent event) {
                applicationDelegate.addEventObserver(ScanStartedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanDefinitionDeletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanDefinitionSavedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.addEventObserver(ScanDefinitionsLoadedEvent.class,
                        (IEventObserver) event.getSource());
            }//from  w  w  w . j  a  va  2s.  c  o  m

            public void ancestorRemoved(AncestorEvent event) {
                applicationDelegate.removeEventObserver(ScanStartedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanCompletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanDefinitionDeletedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanDefinitionSavedEvent.class,
                        (IEventObserver) event.getSource());
                applicationDelegate.removeEventObserver(ScanDefinitionsLoadedEvent.class,
                        (IEventObserver) event.getSource());
            }

            public void ancestorMoved(AncestorEvent event) {
            }
        });

        this.initialized = true;
    }
}

From source file:be.ac.ua.comp.scarletnebula.gui.ServerCellRenderer.java

@Override
public Component getListCellRendererComponent(final JList list, final Object value, final int index,
        final boolean isSelected, final boolean cellHasFocus) {
    // Dirty hack: the last item in the serverlist is always a fake server
    // that when double clicked produces an "add new server" wizard.
    if (value == null) {
        return getNewServerServer(list, index, isSelected);
    }//from www .ja va 2s.  com
    final Server server = (Server) value;

    final JPanel p = createServerPanel(server, list, index, isSelected);
    final Color foreground = getForegroundColor(list, index, isSelected);

    final JLabel label = getServernameComponent(server, foreground);
    final JLabel tags = getTagComponent(server, foreground);
    // final ChartPanel chartPanel = getChartPanelComponent();

    final GraphPanelCache gcp = GraphPanelCache.get();

    final Component chartOrNothing;

    if (server.getServerStatistics() == null) {
        chartOrNothing = new JLabel();
    } else {
        chartOrNothing = gcp.inBareServerCache(server) ? gcp.getBareChartPanel(server)
                : createAndStoreBareChartPanel(list, server);
    }

    p.setLayout(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1.0;
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(5, 5, 1, 5);
    c.anchor = GridBagConstraints.FIRST_LINE_START;

    p.add(label, c);
    c.insets = new Insets(0, 5, 5, 5);
    c.gridy = 1;
    p.add(tags, c);

    c.fill = GridBagConstraints.BOTH;
    c.weighty = 1.0;
    c.gridy = 2;
    p.add(chartOrNothing, c);

    return p;

}

From source file:de.tud.kom.p2psim.impl.skynet.visualization.SkyNetVisualization.java

private SkyNetVisualization() {
    super("Metric-Visualization");
    createLookAndFeel();/*from  w  w  w . j a  v  a2  s. c  o  m*/
    displayedMetrics = new HashMap<String, MetricsPlot>();
    setLayout(new GridLayout(1, 1));
    addWindowListener(this);
    graphix = new JPanel(new GridBagLayout());
    graphix.setLayout(new BoxLayout(graphix, BoxLayout.PAGE_AXIS));
    mb = new JMenuBar();
    JScrollPane scroller = new JScrollPane(graphix, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // calculating the size of the application-window as well as of all
    // components, that depend on the size of the window
    Toolkit kit = Toolkit.getDefaultToolkit();
    int appWidth = kit.getScreenSize().width * 3 / 4;
    int appHeight = kit.getScreenSize().height * 3 / 4;
    scroller.setPreferredSize(new Dimension(appWidth, appHeight));
    getContentPane().add(scroller);
    maxPlotsPerRow = 1;
    while ((maxPlotsPerRow + 1) * PLOT_WIDTH < appWidth) {
        maxPlotsPerRow++;
    }
    log.warn("Creating the visualization...");
    mb.add(new JMenu("File"));
    JMenu met = new JMenu("Available Metrics");
    met.setEnabled(false);
    mb.add(met);
    setJMenuBar(mb);
}

From source file:net.erdfelt.android.sdkfido.ui.SdkFidoFrame.java

private Component createBody() {
    Container body = new Container();

    body.setLayout(new GridBagLayout());
    JTabbedPane tabs = new JTabbedPane();

    tabs.addTab("SDKs", createSdkPanel());
    tabs.addTab("Work Dir", createWorkDirPanel());

    body.add(tabs, new GBC().fillWide().margin(5, 5, 5, 5).endRow());
    body.add(createConsolePane(), new GBC().fillBoth().margin(0, 5, 5, 5).weightTall(1.0).endBoth());

    return body;/*from  ww  w .j av a2 s.  c o m*/
}