public void test_findByAccessibleContext() throws Exception {
    JTextField textField = new JTextField();

    GuiComponent guiComponent = GuiComponentFactory.newGuiComponent(textField);
    assertFalse("Composant inretrouvable", guiComponent.isFindable());
    assertEquals(FindStrategyId.NONE, guiComponent.getBestFindStrategyId());

    textField.getAccessibleContext().setAccessibleName("Dododidon");

    assertTrue("Composant retrouvable par le contexte", guiComponent.isFindable());
    assertEquals(FindStrategyId.BY_ACCESSIBLE_CONTEXT, guiComponent.getBestFindStrategyId());
  }
示例#2
0
  private JPanel buildSnipeSettings() {
    JPanel tp = new JPanel();
    JLabel jl = new JLabel("How close to snipe (in seconds):");

    tp.setBorder(BorderFactory.createTitledBorder("Snipe Timing"));
    tp.setLayout(new BorderLayout());

    snipeTime = new JTextField();
    snipeTime.addMouseListener(JPasteListener.getInstance());
    snipeTime.setToolTipText("Number of seconds prior to auction end to fire a snipe.");

    snipeTime.setEditable(true);
    snipeTime
        .getAccessibleContext()
        .setAccessibleName("Default number of seconds prior to auction end to fire a snipe.");
    tp.add(jl, BorderLayout.NORTH);
    tp.add(snipeTime, BorderLayout.SOUTH);

    return (tp);
  }
  //  private int getDefaultTextComponentHeight() {
  //    if (defaultTextComponentHeight == -1) defaultTextComponentHeight = new
  // JComboBox().getPreferredSize().height;
  //    return defaultTextComponentHeight;
  //  }
  private void initComponents() {
    setLayout(new GridBagLayout());

    GridBagConstraints constraints;

    // takeLabel
    takeLabel = new JLabel(Bundle.SnapshotCustomizer_TakeLabelText());
    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 5, 5);
    add(takeLabel, constraints);

    // firstLineCaptionSpacer
    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 0);
    add(firstLineCaptionSpacer, constraints);

    ButtonGroup takeRadiosGroup = new ButtonGroup();
    JPanel takeRadiosContainer = new JPanel(new GridBagLayout());

    // takeSnapshotRadio
    takeSnapshotRadio = new JRadioButton();
    org.openide.awt.Mnemonics.setLocalizedText(
        takeSnapshotRadio, Bundle.SnapshotCustomizer_ProfilingDataRadioText());
    takeRadiosGroup.add(takeSnapshotRadio);
    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 5);
    takeRadiosContainer.add(takeSnapshotRadio, constraints);
    takeSnapshotRadio.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent e) {
            resetResultsCheckbox.setEnabled(takeSnapshotRadio.isSelected());
          }
        });

    // takeHeapdumpRadio
    takeHeapdumpRadio = new JRadioButton();
    org.openide.awt.Mnemonics.setLocalizedText(
        takeHeapdumpRadio, Bundle.SnapshotCustomizer_HeapDumpRadioText());
    takeRadiosGroup.add(takeHeapdumpRadio);
    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 0);
    takeRadiosContainer.add(takeHeapdumpRadio, constraints);

    JPanel takeRadiosSpacer = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    constraints = new GridBagConstraints();
    constraints.gridx = 2;
    constraints.gridy = 0;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.weightx = 1;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(0, 0, 0, 0);
    takeRadiosContainer.add(takeRadiosSpacer, constraints);

    // takeRadiosContainer
    constraints = new GridBagConstraints();
    constraints.gridx = 2;
    constraints.gridy = 0;
    constraints.weightx = 1;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(0, 0, 5, 0);
    add(takeRadiosContainer, constraints);

    //    return new Dimension(super.getMinimumSize().width, getDefaultTextComponentHeight());
    // --- next row ----------------------------------------------------------
    ButtonGroup saveRadiosGroup = new ButtonGroup();

    // lineLabel
    saveLabel = new JLabel(Bundle.SnapshotCustomizer_SaveLabelText());
    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 1;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 5);
    add(saveLabel, constraints);

    // secondLineCaptionSpacer
    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 0);
    add(secondLineCaptionSpacer, constraints);

    // saveToProjectRadio
    saveToProjectRadio = new JRadioButton();
    org.openide.awt.Mnemonics.setLocalizedText(
        saveToProjectRadio, Bundle.SnapshotCustomizer_ToProjectRadioText());
    saveRadiosGroup.add(saveToProjectRadio);
    saveToProjectRadio.addChangeListener(this);
    constraints.gridx = 2;
    constraints.gridy = 1;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 0);
    add(saveToProjectRadio, constraints);

    // --- next row ----------------------------------------------------------
    JPanel saveToFileSettingsContainer = new JPanel(new GridBagLayout());

    JPanel saveToFileSpacer = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(0, 0, 0, 0);
    takeRadiosContainer.add(saveToFileSpacer, constraints);

    // thirdLineCaptionSpacer
    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 2;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 0);
    add(thirdLineCaptionSpacer, constraints);

    // saveToFileRadio
    saveToFileRadio = new JRadioButton();
    org.openide.awt.Mnemonics.setLocalizedText(
        saveToFileRadio, Bundle.SnapshotCustomizer_ToDirectoryRadioText());
    saveRadiosGroup.add(saveToFileRadio);
    saveToFileRadio.setSelected(true);
    saveToFileRadio.addChangeListener(this);
    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 5);
    saveToFileSettingsContainer.add(saveToFileRadio, constraints);

    // saveToFileField
    saveToFileField =
        new JTextField("") { // NOI18N
          public Dimension getPreferredSize() {
            return new Dimension(super.getMinimumSize().width, super.getPreferredSize().height);
          }

          public Dimension getMinimumSize() {
            return getPreferredSize();
          }
        };
    saveToFileField
        .getAccessibleContext()
        .setAccessibleName(Bundle.SnapshotCustomizer_ToDirectoryRadioText());
    saveToFileField
        .getAccessibleContext()
        .setAccessibleDescription(Bundle.SnapshotCustomizer_SaveFieldAccessName());
    saveToFileField.getDocument().addDocumentListener(this);
    constraints = new GridBagConstraints();
    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.weightx = 1;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(0, 0, 0, 5);
    saveToFileSettingsContainer.add(saveToFileField, constraints);

    // saveToFileButton
    saveToFileButton = new JButton();
    org.openide.awt.Mnemonics.setLocalizedText(
        saveToFileButton, Bundle.SnapshotCustomizer_BrowseButtonText());
    saveToFileButton.addActionListener(this);
    constraints = new GridBagConstraints();
    constraints.gridx = 2;
    constraints.gridy = 0;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 0);
    saveToFileSettingsContainer.add(saveToFileButton, constraints);

    // saveToFileSettingsContainer
    constraints = new GridBagConstraints();
    constraints.gridx = 2;
    constraints.gridy = 2;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.insets = new Insets(0, 0, 8, 0);
    add(saveToFileSettingsContainer, constraints);

    // --- next row ----------------------------------------------------------
    resetResultsCheckbox = new JCheckBox();
    org.openide.awt.Mnemonics.setLocalizedText(
        resetResultsCheckbox, Bundle.SnapshotCustomizer_ResetResultsCheckboxText());
    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 3;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    constraints.anchor = GridBagConstraints.WEST;
    constraints.fill = GridBagConstraints.NONE;
    constraints.insets = new Insets(0, 0, 0, 0);
    add(resetResultsCheckbox, constraints);

    // --- next row ----------------------------------------------------------
    JPanel fillerPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
    constraints = new GridBagConstraints();
    constraints.gridx = 0;
    constraints.gridy = 4;
    constraints.weighty = 1;
    constraints.anchor = GridBagConstraints.NORTHWEST;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.insets = new Insets(0, 0, 0, 0);
    add(fillerPanel, constraints);
  }
  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">
  private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    lableWelcome = new javax.swing.JLabel();
    lableUser = new javax.swing.JLabel();
    labelPassword = new javax.swing.JLabel();
    btnLogIn = new javax.swing.JButton();
    txtfldPassword = new javax.swing.JPasswordField("Password", 8);
    txtfldUserName = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jPanel1.setBackground(new java.awt.Color(0, 51, 255));
    jPanel1.setBorder(
        javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 0, 102)));

    lableWelcome.setFont(new java.awt.Font("Times New Roman", 1, 18));
    lableWelcome.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    lableWelcome.setText("Please Log In To Proceed");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(
                lableWelcome,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE));
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                jPanel1Layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addComponent(lableWelcome)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    lableUser.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
    lableUser.setText("User Name:");

    labelPassword.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
    labelPassword.setText("Password   :"******"Times New Roman", 1, 14)); // NOI18N
    btnLogIn.setText("Log In");
    btnLogIn.addActionListener(
        new java.awt.event.ActionListener() {
          @Override
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            try {
              try {
                logIn(evt);
              } catch (SQLException ex) {
                Logger.getLogger(LogIn.class.getName()).log(Level.SEVERE, null, ex);
              }
            } catch (ClassNotFoundException ex) {
              Logger.getLogger(LogIn.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        });

    // Create key listener that will listen when someone press Backspace key
    KeyListener kl =
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent event) {
            if (event.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
              txtfldPassword.setEditable(true);
            }
          }
        };

    CaretListener caretListener =
        new CaretListener() {
          @Override
          public void caretUpdate(CaretEvent event) {
            int passwordLength = txtfldPassword.getText().length();

            // If password length equal to 8 characters, password field will uneditable
            if (passwordLength > 8) {
              txtfldPassword.setEditable(false);
            }
          }
        };

    txtfldPassword.setText("passWord");
    txtfldUserName.setText("User name");
    txtfldPassword.addKeyListener(kl);
    txtfldPassword.addCaretListener(caretListener);

    txtfldUserName.addFocusListener(
        new FocusListener() {
          @Override
          public void focusGained(FocusEvent fe) {
            txtfldUserName.setText("");
          }

          @Override
          public void focusLost(FocusEvent fe) {
            txtfldPassword.setText("Password");
          }
        });

    txtfldPassword.addFocusListener(
        new FocusListener() {
          @Override
          public void focusGained(FocusEvent fe) {
            txtfldPassword.setText("");
          }

          @Override
          public void focusLost(FocusEvent fe) {}
        });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(
                jPanel1,
                javax.swing.GroupLayout.Alignment.TRAILING,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                javax.swing.GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addContainerGap()
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnLogIn)
                            .addGroup(
                                layout
                                    .createParallelGroup(
                                        javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(
                                        layout
                                            .createSequentialGroup()
                                            .addComponent(labelPassword)
                                            .addGap(18, 18, 18)
                                            .addComponent(txtfldPassword))
                                    .addGroup(
                                        javax.swing.GroupLayout.Alignment.LEADING,
                                        layout
                                            .createSequentialGroup()
                                            .addComponent(lableUser)
                                            .addGap(18, 18, 18)
                                            .addComponent(
                                                txtfldUserName,
                                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                                197,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGap(0, 25, Short.MAX_VALUE)));
    layout.setVerticalGroup(
        layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(
                layout
                    .createSequentialGroup()
                    .addComponent(
                        jPanel1,
                        javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lableUser)
                            .addComponent(
                                txtfldUserName,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(
                        layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(labelPassword)
                            .addComponent(
                                txtfldPassword,
                                javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(btnLogIn)
                    .addContainerGap()));

    txtfldUserName.getAccessibleContext().setAccessibleName("");

    pack();
  } // </editor-fold>