/**
   * Edits the line.
   *
   * @return true if the line has been edited; false otherwise
   */
  private boolean editLine() {
    if (line != null) {
      // make sure value is valid, otherwise don't do anything!
      if (!valueField.getInputVerifier().verify(valueField)) {
        valueField.requestFocusInWindow();
        return false;
      }
      // make sure width is valid, otherwise don't do anything!
      if (!widthField.getInputVerifier().verify(widthField)) {
        widthField.requestFocusInWindow();
        return false;
      }

      line.setValue(Double.parseDouble(valueField.getText()));
      line.getFormat().setWidth(Float.parseFloat(widthField.getText()));
      if (lineColor != null) {
        line.getFormat().setColor(lineColor);
      }
      LineStyle selectedLineStyle = (LineStyle) lineStyleCombobox.getSelectedItem();
      if (selectedLineStyle != null) {
        line.getFormat().setStyle(selectedLineStyle);
      }
    } else {
      return false;
    }

    return true;
  }
Example #2
0
  public boolean validarCampos() {

    boolean resp = true;
    int clv;

    usuario = txtusuario.getText();
    clave = new String(txtclave.getPassword());

    // si usuario esta vacio
    if (usuario.trim().length() == 0) {
      JOptionPane.showMessageDialog(
          this,
          "Por favor Ingrese el Usuario",
          "Campo Usuario (Obligatorio)",
          JOptionPane.ERROR_MESSAGE);
      resp = txtusuario.requestFocusInWindow();
      return resp;
    }
    // si clave esta vacio
    if (clave.trim().length() == 0) {
      JOptionPane.showMessageDialog(
          this,
          "Por favor ingrese la clave",
          "Campo Contraseña (Obligatorio)",
          JOptionPane.ERROR_MESSAGE);
      resp = false;
      return resp;
    }
    if (usuario.trim().length() < 3 || usuario.trim().length() > 20) {
      JOptionPane.showMessageDialog(
          this,
          "Debe ingresar mínimo 3 caracteres " + "y máximo 20",
          "Campo Usuario (Obligatorio)",
          JOptionPane.ERROR_MESSAGE);
      txtusuario.setText("");
      txtclave.setText("");
      txtusuario.requestFocusInWindow();
      resp = false;
      return resp;
    }

    if (clave.trim().length() < 3 || clave.trim().length() > 16) {
      JOptionPane.showMessageDialog(
          this,
          "Debe ingresar mínimo 3 caracteres " + "y máximo 16",
          "Campo Clave (Obligatorio)",
          JOptionPane.ERROR_MESSAGE);
      txtclave.setText("");
      txtclave.requestFocusInWindow();
      resp = false;
      return resp;
    }

    return resp;
  }
 protected void signalViolation(String msg) {
   final Color bg = _field.getBackground();
   _field.setBackground(Binding.INVALID_COLOR);
   MainFrame.getInstance().warn(msg);
   _field.setBackground(bg);
   _field.requestFocusInWindow();
 }
 @Override
 public void actionPerformed(ActionEvent e) {
   Day d = new Day(field.getText());
   Day date = DateChooser.chooseDate(title, d);
   field.setText(date.toString());
   field.requestFocusInWindow();
 }
  private void startEdit(int index) {
    if (index < 0) {
      return;
    }

    LibraryPlaylistsListCell cell = (LibraryPlaylistsListCell) _model.getElementAt(index);
    _selectedIndexToRename = cell.getPlaylist() != null ? index : -1;

    String text = cell.getText();

    Rectangle rect = _list.getUI().getCellBounds(_list, index, index);
    Dimension lsize = rect.getSize();
    Point llocation = rect.getLocation();
    _textName.setSize(lsize);
    _textName.setLocation(llocation);

    _textName.setText(text);
    _textName.setSelectionStart(0);
    _textName.setSelectionEnd(text.length());

    _textName.setVisible(true);

    _textName.requestFocusInWindow();
    _textName.requestFocus();
  }
Example #6
0
  // Mode ajout
  public void modeAjout() {
    resetCollection();
    loadCollection();
    resetCategorie();
    loadCategorie();
    comboCollection.setEnabled(false);

    textTitre.setVisible(true);
    textTitre.setEnabled(true);
    textTitre.setEditable(true);
    textTitre.setText("");
    textTitre.requestFocusInWindow();

    textAnnee.setVisible(true);
    textAnnee.setEnabled(true);
    textAnnee.setEditable(true);
    textAnnee.setText("");

    comboType.setVisible(true);
    comboType.setEnabled(true);
    comboType.setSelectedIndex(1);

    comboEval.setVisible(true);
    comboEval.setEnabled(true);
    comboEval.setSelectedIndex(0);

    // Juste au cas que ca foire
    scrollCom.setEnabled(true);
    scrollCat.setEnabled(true);

    textCommentaires.setEnabled(true);
    textCommentaires.setEditable(true);
    textCommentaires.setBackground(Color.WHITE);
    textCommentaires.setText("");

    textCategories.setEnabled(true);
    textCategories.setEditable(false);
    textCategories.setBackground(GRIS);
    textCategories.setText("");

    optionCategories[0].setEnabled(true);
    optionCategories[1].setEnabled(false);

    for (int i = 0; i < infos_film.length; i++) {
      infos_film[i].setVisible(false);
    }

    for (int k = 0; k < modeButton.length; k++) {
      if (k == 2) {
        modeButton[k].setEnabled(true);
        modeButton[k].setVisible(true);
      } else {
        modeButton[k].setEnabled(false);
        modeButton[k].setVisible(false);
      }
    }
  }
 public void setSelected(boolean b) {
   super.setSelected(b);
   if (selected) {
     if (!(exprFieldX.hasFocus() || exprFieldY.hasFocus() || exprFieldZ.hasFocus())) {
       exprFieldX.requestFocusInWindow();
       fireCaretUpdate(exprFieldX);
     }
   }
 }
Example #8
0
  // Mode recherche
  public void modeRecherche() {
    resetCollection();

    comboCollection.setEnabled(false);

    textTitre.setVisible(true);
    textTitre.setEnabled(true);
    textTitre.setEditable(true);
    textTitre.setText("");
    textTitre.requestFocusInWindow();

    textAnnee.setVisible(true);
    textAnnee.setEnabled(true);
    textAnnee.setEditable(true);
    textAnnee.setText("");

    comboType.setVisible(true);
    comboType.setEnabled(true);
    comboType.setSelectedIndex(0);

    comboEval.setVisible(true);
    comboEval.setEnabled(false);
    // comboEval.setFont();
    comboEval.setSelectedIndex(0);

    textCommentaires.setEnabled(true);
    textCommentaires.setEditable(false);
    textCommentaires.setBackground(GRIS);
    textCommentaires.setText("");

    textCategories.setEnabled(true);
    textCategories.setEditable(false);
    textCategories.setBackground(GRIS);
    textCategories.setText("");

    for (int i = 0; i < infos_film.length; i++) {
      infos_film[i].setVisible(false);
    }

    for (int k = 0; k < modeButton.length; k++) {
      modeButton[k].setEnabled(false);
      modeButton[k].setVisible(false);
    }
    modeButton[5].setVisible(true);
    // modeButton[6].setVisible(true);

    boolean enabled = true;

    if (listeEstVide()) {
      enabled = false;
    }
    optionCategories[0].setEnabled(enabled);
    optionCategories[1].setEnabled(enabled);
    modeButton[5].setEnabled(enabled);
    modeButton[6].setEnabled(true);
  }
Example #9
0
  /**
   * Cr�e une nouvelle instance de CreeTrans
   *
   * @param mf fenetre principale de l'application
   * @param zg Zone graphique
   * @param auto automate
   * @param be barre d'�tat
   */
  public TransCreator(MainFrame mf, GraphicZone g, Automate auto, StateBar be) {

    super(JOptionPane.getFrameForComponent(mf), "Creating interaction", true);

    this.setResizable(false);

    this.gz = g;
    this.auto = auto;
    this.bar = be;
    this.mf = mf;

    be.displayInfo("Creating interaction");

    tfJPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    tfJPanel1.setBackground(Color.lightGray);
    tfJPanel1.add(new JLabel("Type  : "));
    groupe = new CheckboxGroup();
    plus = new Checkbox("activator", groupe, true);
    tfJPanel1.add(plus);
    minus = new Checkbox("inhibitor", groupe, false);
    tfJPanel1.add(minus);

    tfJPanel2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    tfJPanel2.setBackground(Color.lightGray);
    tfJPanel2.add(new JLabel("Threshold  = "));
    tf = new JTextField(auto.nbrCharTransLabel);
    tf.setText("1");
    tfJPanel2.add(tf);

    btJPanel = new JPanel(new GridLayout(1, 2, 0, 0));
    btJPanel.setBackground(Color.lightGray);
    ok = new Button("Ok");
    ok.setBackground(Color.lightGray);
    ok.addActionListener(this);
    cancel = new Button("Cancel");
    cancel.setBackground(Color.lightGray);
    cancel.addActionListener(this);
    btJPanel.add(ok);
    btJPanel.add(cancel);

    content = this.getContentPane();
    content.setLayout(new BorderLayout());
    content.setBackground(Color.lightGray);
    content.add(tfJPanel1, BorderLayout.NORTH);
    content.add(tfJPanel2, BorderLayout.CENTER);
    content.add(btJPanel, BorderLayout.SOUTH);

    this.pack();
    this.setLocationRelativeTo(this.mf);

    tf.requestFocusInWindow();

    // rendre la fenetre visible
    setVisible(true);
  }
Example #10
0
 public void activateChat() {
     input.setFocusable(true);
     input.requestFocusInWindow();
     //prevent key event propagate to input - but still not 100%
     SwingUtilities.invokeLater(new Runnable() {
         @Override
         public void run() {
             input.requestFocusInWindow();
         }
     });
 }
Example #11
0
 /**
  * @param shouldShow - flag noting whether the panel should be visible
  * @return the find/replace panel to be displayed
  */
 protected JPanel showFindAndReplacePanel(boolean shouldShow) {
   if (!shouldShow) {
     this.setVisible(false);
   } else {
     stopTableEditing();
     this.setVisible(true);
     findField.requestFocusInWindow();
     UsageTracker.incrUsageCount("WB.ShowFindReplace");
   }
   return this;
 }
Example #12
0
  /** This method reacts to state changes in the option pane. */
  public void propertyChange(PropertyChangeEvent e) {
    String prop = e.getPropertyName();

    if (isVisible()
        && (e.getSource() == optionPane)
        && (JOptionPane.VALUE_PROPERTY.equals(prop)
            || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
      Object value = optionPane.getValue();

      if (value == JOptionPane.UNINITIALIZED_VALUE) {
        // ignore reset
        return;
      }

      // Reset the JOptionPane's value.
      // If you don't do this, then if the user
      // presses the same button next time, no
      // property change event will be fired.
      optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);

      if (btnString1.equals(value)) {
        typedText = textField1.getText();
        String ucText = typedText.toUpperCase();
        if (magicWord.equals(ucText)) {
          // we're done; clear and dismiss the dialog
          clearAndHide();
        } else {
          // text was invalid
          textField1.selectAll();
          JOptionPane.showMessageDialog(
              iRuleDialog.this,
              "Sorry, \""
                  + typedText
                  + "\" "
                  + "isn't a valid response.\n"
                  + "Please enter "
                  + magicWord
                  + ".",
              "Try again",
              JOptionPane.ERROR_MESSAGE);
          typedText = null;
          textField1.requestFocusInWindow();
        }
      } else { // user closed dialog or clicked cancel
        mainGuiWindow.setLabel("It's OK.");
        typedText = null;
        clearAndHide();
      }
    }
  }
Example #13
0
  /**
   * A private onstructor for this class so that an instance can only be created via the main
   * method.
   */
  public void init() {
    createComponents();
    layoutComponents();
    sizeMortgageTable();

    // make sure that our principal field requests focus once the frame has
    // been displayed
    fieldPrincipal.requestFocusInWindow();

    // load the mortgages from the data file - do this after the UI has
    // been displayed so that there is more of the application for the
    // user to see so any error messages won't be as confusing
    loadMortgages();
  }
Example #14
0
 @Override
 public void keyPressed(KeyEvent e) {
   if (e.getKeyChar() == KeyEvent.VK_ENTER) {
     if (currentTF.getText().trim().isEmpty()) {
       currentTF.selectAll();
       return;
     } else if (nextTF.getText().trim().isEmpty()) {
       nextTF.requestFocusInWindow();
       nextTF.selectAll();
       return;
     } else {
       OKAction okAction = owner.new OKAction();
       okAction.actionPerformed(null);
     }
   }
 }
Example #15
0
 private void initRound() {
   SpringLayout mainLayout = new SpringLayout();
   setLayout(mainLayout);
   resultButton.setEnabled(false);
   betButton.setEnabled(true);
   inputImage.add(betInput);
   controlPanel.add(betLabel);
   controlPanel.add(inputImage);
   controlPanel.add(betButton);
   add(recordLabel);
   add(record);
   add(dealerPanel);
   add(playerPanel);
   add(controlPanel);
   add(moneyLabel);
   add(money);
   add(resultButton);
   mainLayout.putConstraint(SpringLayout.WEST, recordLabel, 154, SpringLayout.WEST, this);
   mainLayout.putConstraint(SpringLayout.NORTH, recordLabel, 20, SpringLayout.NORTH, this);
   mainLayout.putConstraint(SpringLayout.NORTH, record, 15, SpringLayout.NORTH, this);
   mainLayout.putConstraint(SpringLayout.WEST, record, 20, SpringLayout.EAST, recordLabel);
   mainLayout.putConstraint(SpringLayout.WEST, dealerPanel, 180, SpringLayout.WEST, this);
   mainLayout.putConstraint(SpringLayout.NORTH, dealerPanel, 70, SpringLayout.NORTH, this);
   mainLayout.putConstraint(SpringLayout.WEST, playerPanel, 180, SpringLayout.WEST, this);
   mainLayout.putConstraint(SpringLayout.NORTH, playerPanel, 10, SpringLayout.SOUTH, dealerPanel);
   mainLayout.putConstraint(SpringLayout.SOUTH, moneyLabel, -20, SpringLayout.SOUTH, this);
   mainLayout.putConstraint(SpringLayout.WEST, moneyLabel, 5, SpringLayout.WEST, this);
   mainLayout.putConstraint(SpringLayout.WEST, money, 20, SpringLayout.EAST, moneyLabel);
   mainLayout.putConstraint(SpringLayout.SOUTH, money, -15, SpringLayout.SOUTH, this);
   mainLayout.putConstraint(SpringLayout.SOUTH, resultButton, -13, SpringLayout.SOUTH, this);
   mainLayout.putConstraint(SpringLayout.EAST, resultButton, -70, SpringLayout.EAST, this);
   mainLayout.putConstraint(
       SpringLayout.SOUTH, controlPanel, -5, SpringLayout.NORTH, resultButton);
   assignCards();
   numReplaced = 0;
   betInput.setText(null);
   betInput.requestFocusInWindow();
 }
Example #16
0
  // *********************************************CONSTRUCTOR METHOD
  public EPoverty() throws IOException {
    UIManager.put("Button.select", Color.BLACK);

    // ******************************************CREATE MAIN PANEL
    setTitle("|||E-Poverty || V-0.1 (SKELETON)|||");
    setSize(500, 275);
    setLocation(500, 200);
    setVisible(true);
    setResizable(false);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    mainPanel = new JPanel();
    setContentPane(mainPanel);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
    // ******************************************END OF CREATING MAIN PANEL

    /* CREATE THE TOP AND BOTTOM PANELS, ADDING BACKGROUND IMAGES
     *
     * BackgroundPanel is an extension to JPanel that makes it easy to
     * paint images as a background on the panel, or add a gradient
     * fill as the background (this is what you currently see on the
     * back of all the tabs.  The constructors can be seen in the
     * BackgroundPanel.java class if you need or want to use them.
     */
    BackgroundPanel topPanel = new BackgroundPanel(background);
    Dimension top = new Dimension(500, 125);
    topPanel.setPreferredSize(top);
    GradientPaint paintTop = new GradientPaint(0, 0, Color.DARK_GRAY, 100, 100, Color.BLACK);
    topPanel.setPaint(paintTop);

    BackgroundPanel bottomPanel = new BackgroundPanel(null, BackgroundPanel.ACTUAL, 1.0f, 0.5f);
    Dimension bottom = new Dimension(500, 75);
    bottomPanel.setPreferredSize(bottom);
    GradientPaint paintBottom = new GradientPaint(50, 200, Color.WHITE, 100, 50, Color.BLACK);
    bottomPanel.setPaint(paintBottom);

    // *******************************************ADD PANELS TO THE MAIN
    mainPanel.add(topPanel);
    mainPanel.add(bottomPanel);

    // ******************************************ADD COMPONENTS TO THE BOTTOM PANEL
    bottomPanel.setLayout(new GridBagLayout());
    GridBagConstraints gBC = new GridBagConstraints();
    gBC.fill = GridBagConstraints.HORIZONTAL;

    // *****************************************FIRST ROW (BLANK)
    JLabel blank = new JLabel("");
    gBC.weightx = 1;
    gBC.weighty = 1;
    gBC.gridx = 0;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 1;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 2;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 3;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 4;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    blank = new JLabel("");
    gBC.gridx = 5;
    gBC.gridy = 0;
    bottomPanel.add(blank, gBC);

    // *****************************************SECOND ROW (LOGIN)
    blank = new JLabel("LOGIN");
    gBC.gridx = 1;
    gBC.gridy = 1;
    gBC.gridheight = 2;
    gBC.gridwidth = 2;
    blank.setForeground(Color.WHITE);
    blank.setFont(new Font("Serif", Font.PLAIN, 16));
    bottomPanel.add(blank, gBC);
    blank.setHorizontalTextPosition(SwingConstants.RIGHT);

    login_TF = new JTextField("*****@*****.**");
    gBC.gridx = 3;
    gBC.gridy = 1;
    login_TF.setEditable(true);
    login_TF.setBackground(Color.WHITE);
    login_TF.setFont(new Font("Serif", Font.PLAIN, 16));
    login_TF.setForeground(Color.LIGHT_GRAY);
    bottomPanel.add(login_TF, gBC);
    login_TF.requestFocusInWindow();

    // ******************************************THIRD ROW (PASSWORD)
    blank = new JLabel("PASSWORD");
    gBC.gridx = 1;
    gBC.gridy = 3;
    blank.setForeground(Color.WHITE);
    blank.setFont(new Font("Serif", Font.PLAIN, 16));
    blank.setHorizontalTextPosition(JLabel.RIGHT);
    bottomPanel.add(blank, gBC);

    password_TF = new JPasswordField("password");
    gBC.gridx = 3;
    gBC.gridy = 3;
    password_TF.setEditable(true);
    password_TF.setForeground(Color.WHITE);
    password_TF.setFont(new Font("Serif", Font.PLAIN, 16));
    bottomPanel.add(password_TF, gBC);

    // *****************************************FOURTH ROW (BLANK)
    blank = new JLabel("");
    gBC.gridx = 1;
    gBC.gridy = 3;
    gBC.gridheight = 1;
    bottomPanel.add(blank, gBC);

    // *****************************************FIFTH ROW (BUTTONS)
    JButton login_BTN = new JButton("");
    gBC.gridx = 3;
    gBC.gridy = 5;
    gBC.gridwidth = 1;
    login_BTN.setIcon(new ImageIcon(login));
    login_BTN.setMargin(new Insets(0, 0, 0, 0));
    login_BTN.setBackground(Color.LIGHT_GRAY);
    login_BTN.setRolloverEnabled(false);
    login_BTN.setFocusPainted(false);
    login_BTN.setContentAreaFilled(false);
    bottomPanel.add(login_BTN, gBC);

    JButton settings_BTN = new JButton("Settings");
    gBC.gridx = 5;
    gBC.gridy = 5;
    gBC.gridheight = 3;
    settings_BTN.setIcon(new ImageIcon(settings));
    settings_BTN.setMargin(new Insets(0, 0, 0, 0));
    settings_BTN.setHorizontalAlignment(SwingConstants.RIGHT);
    settings_BTN.setVerticalTextPosition(SwingConstants.CENTER);
    settings_BTN.setHorizontalTextPosition(SwingConstants.LEFT);
    settings_BTN.setBackground(Color.LIGHT_GRAY);
    settings_BTN.setBorderPainted(false);
    settings_BTN.setRolloverEnabled(false);
    settings_BTN.setFocusPainted(false);
    settings_BTN.setContentAreaFilled(false);
    bottomPanel.add(settings_BTN, gBC);

    // *****************************************SIXTH ROW (BLANK)
    blank = new JLabel("");
    gBC.gridx = 1;
    gBC.gridy = 5;
    bottomPanel.add(blank, gBC);

    // This makes sure all components are painted on the screen correctly
    mainPanel.validate();

    // ADD AN ACTION LISTENER TO THE BUTTON THAT WILL CHECK THE LOGIN INFO AND LOG INTO THE DATABASE
    login_BTN.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            String passwordHash = "";
            // Hash the password for comparison
            try {
              passwordHash = SimpleSHA1.SHA1(password_TF.getText());
            } catch (NoSuchAlgorithmException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            } catch (UnsupportedEncodingException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            }

            String checkAdminSQL =
                "SELECT p.password FROM persons AS p, admins AS a "
                    + "WHERE p.personId = a.personId "
                    + "AND p.emailAddress = \""
                    + login_TF.getText()
                    + "\" ";

            try {
              // *********************************CHECK LOGIN AND PASSWORD
              new DBconnection(url, driver, dbLogin, dbPassword);
              conn = DBconnection.getConnection();
              PreparedStatement stmt = (PreparedStatement) conn.prepareStatement(checkAdminSQL);
              ResultSet rs = (ResultSet) stmt.executeQuery();

              // IF THERE IS NO NEXT RECORD, E-MAIL IS NOT THAT OF AN ADMIN
              if (!rs.next()) {
                new Warnings("You do not have login rights.");
              } else {
                String dbPass = rs.getObject(1).toString();

                // CHECK VALUE OF RETURNED PASSWORD TO VALUE ENTERED
                if (dbPass.equals(passwordHash)) {
                  try {
                    new EPovertyMain();
                    EPovertyMain.updateStatus("Logged in");
                    dispose();

                  } catch (IOException ex) {
                    Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
                  }
                } else {
                  new Warnings("Incorrect Password.");
                }
              }

              rs.close();
              stmt.close();
              DBconnection.closeConnection();

            } catch (ClassNotFoundException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        }); // END OF LOGIN BUTTON LISTENER

    settings_BTN.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              new Settings();
            } catch (ClassNotFoundException ex) {
              Logger.getLogger(EPoverty.class.getName()).log(Level.SEVERE, null, ex);
            }
          }
        }); // END OF SETTINGS BUTTON LISTENER
  }
Example #17
0
 // Setter fokus i vinduet til textfeltet. Brukes i "Skisenter"
 public void setFocus() {
   kortid.requestFocusInWindow();
 }
  private void initializeComponent(final Frame owner) {
    this.addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            if (owner == null) {
              System.exit(0);
            }
            owner.setEnabled(true);
            dispose();
          }
        });

    serverLabel = new JLabel("Server name");
    serverField = new JTextField(ClientGameConfiguration.get("DEFAULT_SERVER"));
    serverField.setEditable(true);
    serverPortLabel = new JLabel("Server port");
    serverPortField = new JTextField(ClientGameConfiguration.get("DEFAULT_PORT"));

    usernameLabel = new JLabel("Choose a username");
    usernameField = new JTextField();
    usernameField.setDocument(new LowerCaseLetterDocument());

    passwordLabel = new JLabel("Choose a password");
    passwordField = new JPasswordField();

    passwordretypeLabel = new JLabel("Retype password");
    passwordretypeField = new JPasswordField();

    emailLabel = new JLabel("E-mail address (optional)");
    emailField = new JTextField();

    // createAccountButton
    //
    createAccountButton = new JButton();
    createAccountButton.setText("Create Account");
    createAccountButton.setMnemonic(KeyEvent.VK_C);
    this.rootPane.setDefaultButton(createAccountButton);
    createAccountButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(final ActionEvent e) {
            createAccountButton_actionPerformed(e, false);
          }
        });

    //
    // contentPane
    //
    int padding = SBoxLayout.COMMON_PADDING;
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(new SBoxLayout(SBoxLayout.VERTICAL, padding));
    contentPane.setBorder(BorderFactory.createEmptyBorder(padding, padding, padding, padding));

    JComponent grid =
        new JComponent() {
          private static final long serialVersionUID = 1L;
        };
    grid.setLayout(new GridLayout(6, 2, padding, padding));
    contentPane.add(grid, SBoxLayout.constraint(SLayout.EXPAND_X, SLayout.EXPAND_Y));

    // row 0
    grid.add(serverLabel);
    grid.add(serverField);

    // row 1
    grid.add(serverPortLabel);
    grid.add(serverPortField);

    // row 2
    grid.add(usernameLabel);
    grid.add(usernameField);

    // row 3
    grid.add(passwordLabel);
    grid.add(passwordField);

    // row 4
    grid.add(passwordretypeLabel);
    grid.add(passwordretypeField);

    // row 5
    grid.add(emailLabel);
    grid.add(emailField);

    // Warning label
    JLabel logLabel =
        new JLabel(
            "<html><body><p><font size=\"-2\">On login information which identifies your computer on <br>the internet will be logged to prevent abuse (like many <br>attempts to guess a password in order to hack an <br>account or creation of many accounts to cause trouble). <br>Furthermore all events and actions that happen within <br>the game-world (like solving quests, attacking monsters) <br>are logged. This information is used to analyse bugs and <br>in rare cases for abuse handling.</font></p></body></html>");
    // Add a bit more empty space around it
    logLabel.setBorder(BorderFactory.createEmptyBorder(padding, padding, padding, padding));
    logLabel.setAlignmentX(CENTER_ALIGNMENT);
    contentPane.add(logLabel, SBoxLayout.constraint(SLayout.EXPAND_X, SLayout.EXPAND_Y));

    createAccountButton.setAlignmentX(RIGHT_ALIGNMENT);
    contentPane.add(createAccountButton);

    // CreateAccountDialog
    this.setTitle("Create New Account");
    this.setResizable(false);
    // required on Compiz
    this.pack();

    usernameField.requestFocusInWindow();
    if (owner != null) {
      owner.setEnabled(false);
      this.setLocationRelativeTo(owner);
    }
  }
Example #19
0
 // Setter fokus i vinduet til textfeltet
 private void resetFocus() {
   kortid.requestFocusInWindow();
 }
  public BundleOptionsFrame(String displayName, String instanceName, List<OptionGroup> options) {
    setResizable(false);
    this.displayName = displayName;
    content = (JComponent) getContentPane();
    content.setLayout(new GridBagLayout());

    final BundleOptionsFrame frame = this;

    // Close button
    Action closeAction =
        new AbstractAction("Close") {
          @Override
          public void actionPerformed(ActionEvent e) {
            frame.setVisible(false);
          }
        };
    JButton close_button = new JButton(closeAction);
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = currentRow++;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(2, 2, 2, 2);
    content.add(close_button, c);

    // Escape key binding
    JComponent root = frame.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "close");
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
        .put(KeyStroke.getKeyStroke("ctrl W"), "close");
    root.getActionMap().put("close", closeAction);

    if (instanceName != null) {
      // Predicate name
      StringOption opt = new StringOption();
      opt.setDisplayName("Predicate name");
      opt.setDefault(instanceName);
      instanceNameField = new StringField(opt);
      instanceNameField.addChangeListener(
          new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
              updateTitle();
            }
          });
      addField(instanceNameField);
      JTextField tf = (JTextField) instanceNameField.getComponent();
      tf.selectAll();
      tf.requestFocusInWindow();
    } else {
      // We're a codec; no instance name
      instanceNameField = null;
    }
    updateTitle();

    // Options
    ExampleField example = null;
    for (OptionGroup group : options) {
      addSeparator(group.getDisplayName());
      for (Option option : group.getOptions()) {
        OptionField field;
        if (option instanceof BooleanOption) {
          field = new BooleanField((BooleanOption) option);
        } else if (option instanceof StringOption) {
          field = new StringField((StringOption) option);
        } else if (option instanceof NumberOption) {
          field = new NumberField((NumberOption) option);
        } else if (option instanceof ChoiceOption) {
          field = new ChoiceField((ChoiceOption) option);
        } else if (option instanceof ExampleOption) {
          if (example != null) {
            throw new IllegalArgumentException("Cannot display more than one ExampleOption");
          }
          example = new ExampleField((ExampleOption) option);
          field = example;
        } else {
          throw new IllegalArgumentException("Unknown option type");
        }
        addField(field);
        optionFields.add(field);
      }
    }
    this.exampleField = example;

    pack();
  }
  @Override
  public void editLabel() {
    if (logger.isLoggable(Level.FINE)) {
      logger.fine("Edit ie hyperlink");
    }
    labelEditing = true;
    _jLabelTextField =
        new JTextField(getModel().getValue()) {
          /**
           * Overrides paint
           *
           * @see javax.swing.JComponent#paint(java.awt.Graphics)
           */
          @Override
          public void paint(Graphics g) {
            super.paint(g);
            if (getModel().isCustomButton()) {
              Rectangle bounds = getBounds();
              g.setColor(getBackgroundColor());
              g.fillRect(0, 0, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE);
              g.fillRect(
                  0, bounds.height - ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE);
              g.fillRect(
                  bounds.width - ROUNDED_BORDER_SIZE, 0, ROUNDED_BORDER_SIZE, ROUNDED_BORDER_SIZE);
              g.fillRect(
                  bounds.width - ROUNDED_BORDER_SIZE,
                  bounds.height - ROUNDED_BORDER_SIZE,
                  ROUNDED_BORDER_SIZE,
                  ROUNDED_BORDER_SIZE);
            }
          }

          /**
           * Overrides getPreferredSize
           *
           * @see javax.swing.JComponent#getPreferredSize()
           */
          @Override
          public Dimension getPreferredSize() {
            if (getModel().isCustomButton()) {
              String s = _jLabelTextField.getText();
              if (s == null) {
                return new Dimension(30, 15);
              } else {
                return new Dimension(
                    (int)
                        (getFontMetrics(getFont()).getStringBounds(s, getGraphics()).getWidth()
                            + 32),
                    15);
              }
            } else {
              return super.getPreferredSize();
            }
          }
        };
    _jLabelTextField.setFont(_jLabel.getFont());
    _jLabelTextField.setForeground(_jLabel.getForeground());
    _jLabelTextField.setBackground(_jLabel.getBackground());
    if (getModel().isCustomButton()) {
      _jLabelTextField.setBorder(
          BorderFactory.createMatteBorder(0, 15, 1, 15, _jLabel.getBackground()));
    } else {
      _jLabelTextField.setBorder(BorderFactory.createEmptyBorder(0, 10, 1, 10));
    }
    // _jLabelTextField.setForeground(getFlexoNode().getTextColor());
    _jLabelTextField.setBounds(_jLabel.getBounds());
    _jLabelTextField.setHorizontalAlignment(SwingConstants.CENTER);
    _jLabelTextField.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent event) {
            finalizeEditHyperlink();
          }
        });
    _jLabelTextField.getDocument().addDocumentListener(new TriggerRepaintDocumentListener(this));
    _jLabelTextField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusLost(FocusEvent arg0) {
            finalizeEditHyperlink();
          }
        });
    remove(_jLabel);
    add(_jLabelTextField);
    _jLabelTextField.requestFocusInWindow();
    _jLabelTextField.selectAll();
    _jLabelTextField.revalidate();
    _jLabelTextField.repaint();
    revalidate();
    repaint();
  }
Example #22
0
  private void btConfirmarActionPerformed(java.awt.event.ActionEvent evt) {
    String nome = textfieldNome.getText();
    String cpf = textFieldCpf.getText();
    String rua = textFieldRua.getText();
    String bairro = textFieldBairro.getText();
    String cidade = textFieldCidade.getText();
    String complemento = textFieldComplemento.getText();
    String telefone = textFieldTelefone.getText();
    String email = textFieldEmail.getText();
    String telefoneOpcional = textFieldTelefoneOpcional.getText();
    String estado = comboEstado.getSelectedItem().toString();
    int numero = 0;
    try {
      numero = Integer.parseInt(textFieldNumero.getText());
    } catch (NumberFormatException ex) {
      javax.swing.JOptionPane.showMessageDialog(null, "Preencha apenas com número.");
      textFieldNumero.setText("");
      textFieldNumero.requestFocusInWindow();
    }
    double limite = Double.parseDouble(textFieldLimite.getText());

    if ((nome.equals(""))
        || (cpf.equals("   .   .   -  "))
        || (rua.equals(""))
        || (bairro.equals(""))
        || (cidade.equals(""))
        || (telefone.equals("(  ) 9     -    "))) {
      if (nome.equals("")) {
        javax.swing.JOptionPane.showMessageDialog(null, "Preencha o nome.");
        textfieldNome.requestFocusInWindow();
      } else if (cpf.equals("   .   .   -  ")) {
        javax.swing.JOptionPane.showMessageDialog(null, "Preecha o CPF.");
        textFieldCpf.requestFocusInWindow();
      } else if (rua.equals("")) {
        javax.swing.JOptionPane.showMessageDialog(null, "Preecha o nome da Rua.");
        textFieldRua.requestFocusInWindow();
      } else if (bairro.equals("")) {
        javax.swing.JOptionPane.showMessageDialog(null, "Preecha o nome do Bairro.");
        textFieldBairro.requestFocusInWindow();
      } else if (cidade.equals("")) {
        javax.swing.JOptionPane.showMessageDialog(null, "Preecha o nome da Cidade.");
        textFieldCidade.requestFocusInWindow();
      } else {
        javax.swing.JOptionPane.showMessageDialog(null, "Preecha o número de telefone.");
        textFieldTelefone.requestFocusInWindow();
      }
    } else {
      classes.Cliente cn =
          new classes.Cliente(
              cpf,
              nome,
              cidade,
              rua,
              bairro,
              numero,
              complemento,
              estado,
              limite,
              telefone,
              email,
              telefoneOpcional);
      DAO.ClienteDAO cd = new DAO.ClienteDAO();
      cd.edit(c, cn);
      dispose();
      new VisualizarClientes(p).setVisible(true);
    }
  }
 protected void clear() {
   _field.setText("");
   _field.requestFocusInWindow();
 }