Example usage for javax.swing JButton getParent

List of usage examples for javax.swing JButton getParent

Introduction

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

Prototype

public Container getParent() 

Source Link

Document

Gets the parent of this component.

Usage

From source file:com.game.ui.views.WeaponEditorPanel.java

@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equalsIgnoreCase("dropDown")) {
        JPanel panel = (JPanel) comboBox.getParent().getComponent(4);
        String name = comboBox.getSelectedItem().toString();
        for (Item item : GameBean.weaponDetails) {
            if (item instanceof Weapon) {
                Weapon weapon = (Weapon) item;
                if (weapon.getName().equalsIgnoreCase(name)) {
                    ((JTextField) panel.getComponent(2)).setText(name);
                    ((JComboBox) panel.getComponent(4)).setSelectedItem(weapon.getWeaponType());
                    ((JTextField) panel.getComponent(6)).setText(Integer.toString(weapon.getAttackRange()));
                    ((JTextField) panel.getComponent(8)).setText(Integer.toString(weapon.getAttackPts()));
                    return;
                }/*from  w  w  w.j  a  v  a2s  .  co m*/
            }
        }
    } else {
        JButton btn = (JButton) ae.getSource();
        JPanel panel = (JPanel) btn.getParent();
        String name = ((JTextField) panel.getComponent(2)).getText();

        String weaponType = (String) (((JComboBox) panel.getComponent(4)).getSelectedItem());
        String attackRnge = ((JTextField) panel.getComponent(6)).getText();
        String attackPts = ((JTextField) panel.getComponent(8)).getText();
        //            JLabel message = ((JLabel) this.getComponent(5));
        validationMess.setText("");
        validationMess.setVisible(false);
        if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(weaponType)
                && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(attackPts)) {
            validationMess.setVisible(false);
            Weapon weapon = new Weapon();
            weapon.setName(name);
            ;
            weapon.setAttackRange(Integer.parseInt(attackRnge));
            weapon.setAttackPts(Integer.parseInt(attackPts));
            weapon.setWeaponType(weaponType);
            boolean weaponAlrdyPresent = false;
            int position = GameUtils.getPositionOfWeaponItem(name);
            if (GameBean.weaponDetails == null) {
                GameBean.weaponDetails = new ArrayList<Item>();
            }
            if (position != -1) {
                GameBean.weaponDetails.remove(position);
            }
            GameBean.weaponDetails.add(weapon);
            try {
                GameUtils.writeItemsToXML(GameBean.weaponDetails, Configuration.PATH_FOR_WEAPONS);
                validationMess.setText("Saved Successfully..");
                validationMess.setVisible(true);
                if (!weaponAlrdyPresent) {
                    comboBox.removeActionListener(this);
                    comboBox.addItem(name);
                    comboBox.setSelectedItem(name);
                    comboBox.addActionListener(this);
                }
                TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location);
                if (tileInfo == null) {
                    tileInfo = new TileInformation();
                }
                tileInfo.setWeapon(weapon);
                GameBean.mapInfo.getPathMap().put(location, tileInfo);
                chkBox.setSelected(true);
                this.revalidate();
                return;
            } catch (Exception e) {
                System.out.println("WeaponEditorPanel : actionPerformed() : Some error occured " + e);
            }

        } else {
            validationMess.setText("Pls enter all the fields or pls choose a weapon from the drop down");
            validationMess.setVisible(true);
            panel.revalidate();
        }
    }
}

From source file:com.game.ui.views.CharachterEditorPanel.java

@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equalsIgnoreCase("dropDown")) {
        JComboBox comboBox = (JComboBox) ae.getSource();
        JPanel panel = (JPanel) comboBox.getParent().getComponent(4);
        String name = comboBox.getSelectedItem().toString();
        for (GameCharacter enemy : GameBean.enemyDetails) {
            if (enemy.getName().equalsIgnoreCase(name)) {
                ((JTextField) panel.getComponent(2)).setText(enemy.getName());
                ((JTextField) panel.getComponent(4)).setText(enemy.getImagePath());
                ((JTextField) panel.getComponent(6)).setText(new Integer(enemy.getHealth()).toString());
                ((JTextField) panel.getComponent(8)).setText(new Integer(enemy.getAttackPts()).toString());
                ((JTextField) panel.getComponent(10)).setText(new Integer(enemy.getArmor()).toString());
                ((JTextField) panel.getComponent(12)).setText(new Integer(enemy.getAttackRange()).toString());
                ((JTextField) panel.getComponent(14)).setText(new Integer(enemy.getMovement()).toString());
                return;
            }/*www .  j  ava  2s. com*/
        }
    } else {
        JButton btn = (JButton) ae.getSource();
        JPanel panel = (JPanel) btn.getParent();
        int indexOfBtn = btn.getAccessibleContext().getAccessibleIndexInParent();
        String name = ((JTextField) panel.getComponent(2)).getText();
        String image = ((JTextField) panel.getComponent(4)).getText();
        String health = ((JTextField) panel.getComponent(6)).getText();
        String attackPts = ((JTextField) panel.getComponent(8)).getText();
        String armourPts = ((JTextField) panel.getComponent(10)).getText();
        String attackRnge = ((JTextField) panel.getComponent(12)).getText();
        String movement = ((JTextField) panel.getComponent(14)).getText();
        System.out.println("Index : " + indexOfBtn);
        JLabel message = ((JLabel) this.getComponent(5));
        message.setText("");
        message.setVisible(false);
        if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(image) && StringUtils.isNotBlank(health)
                && StringUtils.isNotBlank(attackPts) && StringUtils.isNotBlank(armourPts)
                && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(movement)) {
            message.setVisible(false);
            GameCharacter character = new GameCharacter();
            character.setName(name);
            character.setAttackPts(Integer.parseInt(attackPts));
            character.setAttackRange(Integer.parseInt(attackRnge));
            character.setHealth(Integer.parseInt(health));
            character.setImagePath(image);
            character.setMovement(Integer.parseInt(movement));
            character.setArmor(Integer.parseInt(armourPts));
            boolean characterAlrdyPresent = false;
            for (int i = 0; i < GameBean.enemyDetails.size(); i++) {
                GameCharacter charFromList = GameBean.enemyDetails.get(i);
                if (charFromList.getName().equalsIgnoreCase(name)) {
                    GameBean.enemyDetails.remove(i);
                    GameBean.enemyDetails.add(i, character);
                    characterAlrdyPresent = true;
                }
            }
            if (!characterAlrdyPresent) {
                GameBean.enemyDetails.add(character);
            }
            try {
                GameUtils.writeCharactersToXML(GameBean.enemyDetails, Configuration.PATH_FOR_ENEMY_CHARACTERS);
                message.setText("Saved Successfully..");
                message.setVisible(true);
                if (!characterAlrdyPresent) {
                    comboBox.addItem(name);
                    comboBox.setSelectedItem(name);
                }
                TileInformation tileInfo = GameBean.mapInfo.getPathMap().get(location);
                if (tileInfo == null) {
                    tileInfo = new TileInformation();
                }
                tileInfo.setEnemy(character);
                GameBean.mapInfo.getPathMap().put(location, tileInfo);
                chkBox.setSelected(true);
                this.revalidate();
                return;
            } catch (Exception e) {
                System.out.println("CharachterEditorPanel : actionPerformed() : Some error occured " + e);
                e.printStackTrace();
            }

        } else {
            message.setText("Pls enter all the fields or pls choose a character from the drop down");
            message.setVisible(true);
            this.revalidate();
        }
    }
}

From source file:com.game.ui.views.ItemPanel.java

@Override
public void actionPerformed(ActionEvent ae) {
    validationMess.setText("");
    validationMess.setVisible(false);//  w  w  w  . j av  a2s  .  c o  m
    if (ae.getActionCommand().equalsIgnoreCase("dropDown")) {
        JPanel panel = (JPanel) comboBox.getParent().getComponent(4);
        String name = comboBox.getSelectedItem().toString();
        if (ringPanel) {
            getRingDetailForName(name, panel);
        } else if (armourPanel) {
            getArmourDetailForName(name, panel);
        } else if (potionPanel) {
            getPotionDetailForName(name, panel);
        } else if (treasurePanel) {
            getTreasureDetailForName(name, panel);
        }
    } else {
        JButton btn = (JButton) ae.getSource();
        JPanel panel = (JPanel) btn.getParent();
        String name = ((JTextField) panel.getComponent(2)).getText();
        if (ringPanel) {
            persistRingData(name, panel);
        } else if (armourPanel) {
            persistArmourData(name, panel);
        } else if (potionPanel) {
            persistPotionData(name, panel);
        } else if (treasurePanel) {
            persistTreasure(name, panel);
        }
    }
    this.revalidate();
}

From source file:net.sf.taverna.t2.workbench.views.results.processor.RenderedProcessorResultComponent.java

/**
 * Creates the component./*from www . ja  v  a2s  . c o  m*/
 */
public RenderedProcessorResultComponent(RendererRegistry rendererRegistry,
        List<SaveIndividualResultSPI> saveActions) {
    this.rendererRegistry = rendererRegistry;
    setLayout(new BorderLayout());
    setBorder(new EtchedBorder());

    // Results type combo box
    renderersComboBox = new JComboBox<>();
    renderersComboBox.setModel(new DefaultComboBoxModel<String>()); // initially empty

    renderersComboBox.setRenderer(new ColorCellRenderer());
    renderersComboBox.setEditable(false);
    renderersComboBox.setEnabled(false); // initially disabled

    // Set the new listener - listen for changes in the currently selected renderer
    renderersComboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == SELECTED && !ERROR_DOCUMENT.equals(e.getItem()))
                // render the result using the newly selected renderer
                renderResult();
        }
    });

    JPanel resultsTypePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    resultsTypePanel.add(new JLabel("Value type"));
    resultsTypePanel.add(renderersComboBox);

    // Refresh (re-render) button
    refreshButton = new JButton("Refresh", refreshIcon);
    refreshButton.setEnabled(false);
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            renderResult();
            refreshButton.getParent().requestFocusInWindow();
            /*
             * so that the button does not stay focused after it is clicked
             * on and did its action
             */
        }
    });
    resultsTypePanel.add(refreshButton);

    // Check box for wrapping text if result is of type "text/plain"
    wrapTextCheckBox = new JCheckBox(WRAP_TEXT);
    wrapTextCheckBox.setVisible(false);
    wrapTextCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            // Should have only one child component holding the rendered result
            // Check for empty just as well
            if (renderedResultPanel.getComponents().length == 0)
                return;
            if (renderedResultPanel.getComponent(0) instanceof DialogTextArea) {
                nodeToWrapSelection.put(node.hashCode(), e.getStateChange() == SELECTED);
                renderResult();
            }
        }
    });

    resultsTypePanel.add(wrapTextCheckBox);
    // 'Save result' buttons panel
    saveButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    for (SaveIndividualResultSPI action : saveActions) {
        action.setResultReference(null);
        final JButton saveButton = new JButton(action.getAction());
        saveButton.setEnabled(false);
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveButton.getParent().requestFocusInWindow();
                /*
                 * so that the button does not stay focused after it is
                 * clicked on and did its action
                 */
            }
        });
        saveButtonsPanel.add(saveButton);
    }

    // Top panel contains result type combobox and various save buttons
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, LINE_AXIS));
    topPanel.add(resultsTypePanel);
    topPanel.add(saveButtonsPanel);

    // Rendered results panel - initially empty
    renderedResultPanel = new JPanel(new BorderLayout());
    renderedResultPanel.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Add all components
    add(topPanel, NORTH);
    add(new JScrollPane(renderedResultPanel), CENTER);
}

From source file:net.sf.taverna.t2.workbench.views.results.workflow.RenderedResultComponent.java

/**
 * Creates the component.//from ww  w  .j  a  va  2  s .  c  o m
 */
public RenderedResultComponent(RendererRegistry rendererRegistry, List<SaveIndividualResultSPI> saveActions) {
    this.rendererRegistry = rendererRegistry;
    setLayout(new BorderLayout());

    // Results type combo box
    renderersComboBox = new JComboBox<>();
    renderersComboBox.setModel(new DefaultComboBoxModel<String>()); // initially empty

    renderersComboBox.setRenderer(new ColorCellRenderer());
    renderersComboBox.setEditable(false);
    renderersComboBox.setEnabled(false); // initially disabled

    // Set the new listener - listen for changes in the currently selected renderer
    renderersComboBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED && !ERROR_DOCUMENT.equals(e.getItem()))
                // render the result using the newly selected renderer
                renderResult();
        }
    });

    JPanel resultsTypePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    resultsTypePanel.add(new JLabel("Value type"));
    resultsTypePanel.add(renderersComboBox);

    // Refresh (re-render) button
    refreshButton = new JButton("Refresh", refreshIcon);
    refreshButton.setEnabled(false);
    refreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            renderResult();
            refreshButton.getParent().requestFocusInWindow();
            /*
             * so that the button does not stay focused after it is clicked
             * on and did its action
             */
        }
    });
    resultsTypePanel.add(refreshButton);

    // Check box for wrapping text if result is of type "text/plain"
    wrapTextCheckBox = new JCheckBox(WRAP_TEXT);
    wrapTextCheckBox.setVisible(false);
    wrapTextCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            // Should have only one child component holding the rendered result
            // Check for empty just as well
            if (renderedResultPanel.getComponents().length == 0)
                return;
            Component component = renderedResultPanel.getComponent(0);
            if (component instanceof DialogTextArea) {
                nodeToWrapSelection.put(path, e.getStateChange() == SELECTED);
                renderResult();
            }
        }
    });

    resultsTypePanel.add(wrapTextCheckBox);

    // 'Save result' buttons panel
    saveButtonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    for (SaveIndividualResultSPI action : saveActions) {
        action.setResultReference(null);
        final JButton saveButton = new JButton(action.getAction());
        saveButton.setEnabled(false);
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                saveButton.getParent().requestFocusInWindow();
                /*
                 * so that the button does not stay focused after it is
                 * clicked on and did its action
                 */
            }
        });
        saveButtonsPanel.add(saveButton);
    }

    // Top panel contains result type combobox and various save buttons
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, LINE_AXIS));
    topPanel.add(resultsTypePanel);
    topPanel.add(saveButtonsPanel);

    // Rendered results panel - initially empty
    renderedResultPanel = new JPanel(new BorderLayout());

    // Add all components
    add(topPanel, NORTH);
    add(new JScrollPane(renderedResultPanel), CENTER);
}

From source file:com._17od.upm.gui.AccountDialog.java

public AccountDialog(AccountInformation account, JFrame parentWindow, boolean readOnly,
        ArrayList existingAccounts) {
    super(parentWindow, true);

    boolean addingAccount = false;

    //Request focus on Account JDialog when mouse clicked
    this.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 1) {
                requestFocus();/* w  w  w. jav a 2  s .c om*/

            }
        }
    });

    // Set the title based on weather we've been opened in readonly mode and
    // weather the
    // Account passed in is empty or not
    String title = null;
    if (readOnly) {
        title = Translator.translate("viewAccount");
    } else if (!readOnly && account.getAccountName().trim().equals("")) {
        title = Translator.translate("addAccount");
        addingAccount = true;
    } else {
        title = Translator.translate("editAccount");
    }
    setTitle(title);

    this.pAccount = account;
    this.existingAccounts = existingAccounts;
    this.parentWindow = parentWindow;

    getContentPane().setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    Container container = getContentPane();

    // The AccountName Row
    JLabel accountLabel = new JLabel(Translator.translate("account"));
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(accountLabel, c);

    // This panel will hold the Account field and the copy and paste
    // buttons.
    JPanel accountPanel = new JPanel(new GridBagLayout());

    accountName = new JTextField(new String(pAccount.getAccountName()), 20);
    if (readOnly) {
        accountName.setEditable(false);
    }
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    accountPanel.add(accountName, c);
    accountName.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            accountName.selectAll();
        }
    });

    JButton acctCopyButton = new JButton();
    acctCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    acctCopyButton.setToolTipText("Copy");
    acctCopyButton.setEnabled(true);
    acctCopyButton.setMargin(new Insets(0, 0, 0, 0));
    acctCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextField(accountName);
        }
    });
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    accountPanel.add(acctCopyButton, c);

    JButton acctPasteButton = new JButton();
    acctPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    acctPasteButton.setToolTipText("Paste");
    acctPasteButton.setEnabled(!readOnly);
    acctPasteButton.setMargin(new Insets(0, 0, 0, 0));
    acctPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextField(accountName);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    accountPanel.add(acctPasteButton, c);

    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(accountPanel, c);

    // Userid Row
    JLabel useridLabel = new JLabel(Translator.translate("userid"));
    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(useridLabel, c);

    // This panel will hold the User ID field and the copy and paste
    // buttons.
    JPanel idPanel = new JPanel(new GridBagLayout());

    userId = new JTextField(new String(pAccount.getUserId()), 20);
    if (readOnly) {
        userId.setEditable(false);
    }
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    idPanel.add(userId, c);
    userId.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            userId.selectAll();
        }
    });

    JButton idCopyButton = new JButton();
    idCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    idCopyButton.setToolTipText("Copy");
    idCopyButton.setEnabled(true);
    idCopyButton.setMargin(new Insets(0, 0, 0, 0));
    idCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextField(userId);
        }
    });
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    idPanel.add(idCopyButton, c);

    JButton idPasteButton = new JButton();
    idPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    idPasteButton.setToolTipText("Paste");
    idPasteButton.setEnabled(!readOnly);
    idPasteButton.setMargin(new Insets(0, 0, 0, 0));
    idPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextField(userId);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    idPanel.add(idPasteButton, c);

    c.gridx = 1;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(idPanel, c);

    // Password Row
    JLabel passwordLabel = new JLabel(Translator.translate("password"));
    c.gridx = 0;
    c.gridy = 2;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(15, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(passwordLabel, c);

    // This panel will hold the password, generate password button, copy and
    // paste buttons, and hide password checkbox
    JPanel passwordPanel = new JPanel(new GridBagLayout());

    password = new JPasswordField(new String(pAccount.getPassword()), 20);
    // allow CTRL-C on the password field
    password.putClientProperty("JPasswordField.cutCopyAllowed", Boolean.TRUE);
    password.setEditable(!readOnly);
    password.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            password.selectAll();
        }
    });
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(password, c);

    JButton generateRandomPasswordButton = new JButton(Translator.translate("generate"));
    if (readOnly) {
        generateRandomPasswordButton.setEnabled(false);
    }
    generateRandomPasswordButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionevent) {
            // Get the user's preference about including or not Escape
            // Characters to generated passwords
            Boolean includeEscapeChars = new Boolean(
                    Preferences.get(Preferences.ApplicationOptions.INCLUDE_ESCAPE_CHARACTERS, "true"));
            int pwLength = Preferences.getInt(Preferences.ApplicationOptions.ACCOUNT_PASSWORD_LENGTH, 8);
            String Password;

            if ((includeEscapeChars.booleanValue()) && (pwLength > 3)) {
                // Verify that the generated password satisfies the criteria
                // for strong passwords(including Escape Characters)
                do {
                    Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue());
                } while (!(CheckPassStrong(Password, includeEscapeChars.booleanValue())));

            } else if (!(includeEscapeChars.booleanValue()) && (pwLength > 2)) {
                // Verify that the generated password satisfies the criteria
                // for strong passwords(excluding Escape Characters)
                do {
                    Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue());
                } while (!(CheckPassStrong(Password, includeEscapeChars.booleanValue())));

            } else {
                // Else a weak password of 3 or less chars will be produced
                Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue());
            }
            password.setText(Password);
        }
    });
    if (addingAccount) {
        generateRandomPasswordButton.doClick();
    }
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(generateRandomPasswordButton, c);

    JButton pwCopyButton = new JButton();
    pwCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    pwCopyButton.setToolTipText("Copy");
    pwCopyButton.setEnabled(true);
    pwCopyButton.setMargin(new Insets(0, 0, 0, 0));
    pwCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextField(password);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(pwCopyButton, c);

    JButton pwPasteButton = new JButton();
    pwPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    pwPasteButton.setToolTipText("Paste");
    pwPasteButton.setEnabled(!readOnly);
    pwPasteButton.setMargin(new Insets(0, 0, 0, 0));
    pwPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextField(password);
        }
    });
    c.gridx = 3;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(pwPasteButton, c);

    JCheckBox hidePasswordCheckbox = new JCheckBox(Translator.translate("hide"), true);
    defaultEchoChar = password.getEchoChar();
    hidePasswordCheckbox.setMargin(new Insets(5, 0, 5, 0));
    hidePasswordCheckbox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                password.setEchoChar(defaultEchoChar);
            } else {
                password.setEchoChar((char) 0);
            }
        }
    });

    Boolean hideAccountPassword = new Boolean(
            Preferences.get(Preferences.ApplicationOptions.ACCOUNT_HIDE_PASSWORD, "true"));
    hidePasswordCheckbox.setSelected(hideAccountPassword.booleanValue());

    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(hidePasswordCheckbox, c);

    c.gridx = 1;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(passwordPanel, c);

    // URL Row
    JLabel urlLabel = new JLabel(Translator.translate("url"));
    c.gridx = 0;
    c.gridy = 3;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(urlLabel, c);

    // This panel will hold the URL field and the copy and paste buttons.
    JPanel urlPanel = new JPanel(new GridBagLayout());

    url = new JTextField(new String(pAccount.getUrl()), 20);
    if (readOnly) {
        url.setEditable(false);
    }
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    urlPanel.add(url, c);
    url.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            url.selectAll();
        }
    });

    final JButton urlLaunchButton = new JButton();
    urlLaunchButton.setIcon(Util.loadImage("launch-url-sm.png"));
    urlLaunchButton.setToolTipText("Launch URL");
    urlLaunchButton.setEnabled(true);
    urlLaunchButton.setMargin(new Insets(0, 0, 0, 0));
    urlLaunchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String urlText = url.getText();

            // Check if the selected url is null or emty and inform the user
            // via JoptioPane message
            if ((urlText == null) || (urlText.length() == 0)) {
                JOptionPane.showMessageDialog(urlLaunchButton.getParent(),
                        Translator.translate("EmptyUrlJoptionpaneMsg"),
                        Translator.translate("UrlErrorJoptionpaneTitle"), JOptionPane.WARNING_MESSAGE);
                // Check if the selected url is a valid formated url(via
                // urlIsValid() method) and inform the user via JoptioPane
                // message
            } else if (!(urlIsValid(urlText))) {
                JOptionPane.showMessageDialog(urlLaunchButton.getParent(),
                        Translator.translate("InvalidUrlJoptionpaneMsg"),
                        Translator.translate("UrlErrorJoptionpaneTitle"), JOptionPane.WARNING_MESSAGE);
                // Call the method LaunchSelectedURL() using the selected
                // url as input
            } else {
                LaunchSelectedURL(urlText);
            }
        }
    });
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    urlPanel.add(urlLaunchButton, c);

    JButton urlCopyButton = new JButton();
    urlCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    urlCopyButton.setToolTipText("Copy");
    urlCopyButton.setEnabled(true);
    urlCopyButton.setMargin(new Insets(0, 0, 0, 0));
    urlCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextField(url);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    urlPanel.add(urlCopyButton, c);

    JButton urlPasteButton = new JButton();
    urlPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    urlPasteButton.setToolTipText("Paste");
    urlPasteButton.setEnabled(!readOnly);
    urlPasteButton.setMargin(new Insets(0, 0, 0, 0));
    urlPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextField(url);
        }
    });
    c.gridx = 3;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    urlPanel.add(urlPasteButton, c);

    c.gridx = 1;
    c.gridy = 3;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(urlPanel, c);

    // Notes Row
    JLabel notesLabel = new JLabel(Translator.translate("notes"));
    c.gridx = 0;
    c.gridy = 4;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(notesLabel, c);

    // This panel will hold the Notes text area and the copy and paste
    // buttons.
    JPanel notesPanel = new JPanel(new GridBagLayout());

    notes = new JTextArea(new String(pAccount.getNotes()), 10, 20);
    if (readOnly) {
        notes.setEditable(false);
    }
    notes.setLineWrap(true); // Enable line wrapping.
    notes.setWrapStyleWord(true); // Line wrap at whitespace.
    JScrollPane notesScrollPane = new JScrollPane(notes);
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.BOTH;
    notesPanel.add(notesScrollPane, c);

    JButton notesCopyButton = new JButton();
    notesCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    notesCopyButton.setToolTipText("Copy");
    notesCopyButton.setEnabled(true);
    notesCopyButton.setMargin(new Insets(0, 0, 0, 0));
    notesCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextArea(notes);
        }
    });
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    notesPanel.add(notesCopyButton, c);

    JButton notesPasteButton = new JButton();
    notesPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    notesPasteButton.setToolTipText("Paste");
    notesPasteButton.setEnabled(!readOnly);
    notesPasteButton.setMargin(new Insets(0, 0, 0, 0));
    notesPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextArea(notes);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    notesPanel.add(notesPasteButton, c);

    c.gridx = 1;
    c.gridy = 4;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(notesPanel, c);

    // Seperator Row
    JSeparator sep = new JSeparator();
    c.gridx = 0;
    c.gridy = 5;
    c.anchor = GridBagConstraints.PAGE_END;
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(sep, c);

    // Button Row
    JPanel buttonPanel = new JPanel();
    JButton okButton = new JButton(Translator.translate("ok"));
    // Link Enter key to okButton
    getRootPane().setDefaultButton(okButton);
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            okButtonAction();
        }
    });
    buttonPanel.add(okButton);
    if (!readOnly) {
        JButton cancelButton = new JButton(Translator.translate("cancel"));
        cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                closeButtonAction();
            }
        });
        buttonPanel.add(cancelButton);
    }
    c.gridx = 0;
    c.gridy = 6;
    c.anchor = GridBagConstraints.PAGE_END;
    c.insets = new Insets(5, 0, 5, 0);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.NONE;
    container.add(buttonPanel, c);
}