예제 #1
0
  /** Creates the editor component of the property editor. */
  public void createComponent() {
    JCheckBox c = new JCheckBox();

    c.setEnabled(!readonly);
    c.addKeyListener(this);
    c.addChangeListener(this);
    c.addFocusListener(this);

    component = c;
  }
예제 #2
0
  private void createComponents() {

    Box box0 = Box.createVerticalBox();
    Box box1 = Box.createVerticalBox();
    Box box2 = Box.createVerticalBox();
    Box box3 = Box.createHorizontalBox();
    Box box4 = Box.createVerticalBox();
    Box box5 = Box.createHorizontalBox();

    lMonitor = new JLabel(rb.getString("lbl_folder"));
    // lMonitor.setAlignmentX(Component.CENTER_ALIGNMENT);
    // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    lClearFolder = new JLabel(rb.getString("lbl_clear_folder"));
    lTimer = new JLabel(rb.getString("lbl_timer"));

    jTxtFolderMonitorName = new JTextField(props.getProperty(Property.MONITORFOLDER), 20);
    jTxtFolderMonitorName.addActionListener(new MyActionListener(ComponentID.TXTF_FOLDER));
    jTxtFolderMonitorName.addKeyListener(new MyKeyListener());
    jTxtFolderMonitorName.addFocusListener(new MyFocusListener(ComponentID.TXTF_FOLDER));

    jTxtTimer = new JTextField(props.getProperty(Property.TIMER), 20);
    jTxtTimer.addActionListener(new MyActionListener(ComponentID.TXTF_TIMER));
    jTxtTimer.addKeyListener(new MyKeyListener());
    jTxtTimer.addFocusListener(new MyFocusListener(ComponentID.TXTF_TIMER));

    JCheckBox jCBClearFolder = new JCheckBox();
    jCBClearFolder.addActionListener(new MyActionListener(ComponentID.CHK_CLEAR_FOLDER));
    jCBClearFolder.addKeyListener(new MyKeyListener());

    buttonPanel = new JPanel();
    buttonPanel.setBorder(new TitledBorder(new EtchedBorder(), rb.getString("brd_monitor_button")));

    jbnStop = new JButton(rb.getString("b_stop"));
    jbnStop.setMnemonic(KeyEvent.VK_P);
    jbnStart = new JButton(rb.getString("b_start"));
    jbnStart.setMnemonic(KeyEvent.VK_S);

    buttonPanel.add(jbnStart);
    buttonPanel.add(jbnStop);

    jbnStop.addActionListener(new MyActionListener(ComponentID.B_STOP));
    jbnStop.addKeyListener(new MyKeyListener());
    jbnStart.addActionListener(new MyActionListener(ComponentID.B_START));
    jbnStart.addKeyListener(new MyKeyListener());

    box0.add(lMonitor);
    box0.add(Box.createVerticalStrut(10));
    box0.add(lClearFolder);
    box0.add(Box.createVerticalStrut(10));
    box0.add(lTimer);

    box1.add(jTxtFolderMonitorName);
    box1.setAlignmentX(LEFT_ALIGNMENT);
    box1.add(jCBClearFolder);
    box1.add(jTxtTimer);
    //		box1.setBorder(new BevelBorder(BevelBorder.LOWERED));

    box3.add(box0);
    box3.add(Box.createHorizontalStrut(10));
    box3.add(box1);
    //		box3.add(box2);

    //		box4.add(box3);
    //		box4.setBorder(new BevelBorder(BevelBorder.LOWERED));
    //		box4.add(box1);
    box5.add(box3);
    box5.add(Box.createHorizontalStrut(10));
    //		box5.setBorder(new BevelBorder(BevelBorder.LOWERED));
    box5.add(buttonPanel);
    container.add(box5);

    ControlWindowMenuBar cwm = new ControlWindowMenuBar();
    Property.getInstance().addPropertyChangeListener(Property.RESOURCEBUNDLE, cwm);
    Property.getInstance().addPropertyChangeListener(Property.RESOURCEBUNDLE, new MyKeyListener());

    setJMenuBar(cwm);
  }
  /** Create the panel. */
  public TorrentClientSectionConfig(ConfigView parentView, Manager manager) {
    super(parentView);
    setManager(manager);
    setInitialVariables();

    setBackground(PanelProperties.BACKGROUND);
    JLabel lblNewLabel = new JLabel("RPC Server");
    lblNewLabel.setFont(new Font("Calibri", Font.PLAIN, 15));

    userLabel = new JLabel("Usuario");
    userLabel.setFont(new Font("Calibri", Font.PLAIN, 15));
    userLabel.setBackground(PanelProperties.TRANSPARENT_BACKGROUND);

    passwordLabel = new JLabel("Password");
    passwordLabel.setFont(new Font("Calibri", Font.PLAIN, 15));
    passwordLabel.setBackground(PanelProperties.TRANSPARENT_BACKGROUND);

    userField = new JTextField();
    userField.setFont(new Font("Calibri", Font.PLAIN, 15));
    userField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            userField.selectAll();
          }
        });
    userField.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            TorrentClientSectionConfig.this.parentView.keyReleased(e);
          }
        });
    userField.setColumns(10);

    passwordField = new JPasswordField();
    passwordField.setFont(new Font("Calibri", Font.PLAIN, 15));
    passwordField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            passwordField.selectAll();
          }
        });
    passwordField.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            TorrentClientSectionConfig.this.parentView.keyReleased(e);
          }
        });

    needsAuthCheckBox = new JCheckBox("Necesita autenticaci\u00F3n");
    needsAuthCheckBox.setFont(new Font("Calibri", Font.PLAIN, 15));
    needsAuthCheckBox.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
              needsAuthCheckBox.doClick();
            } else {
              TorrentClientSectionConfig.this.parentView.keyReleased(e);
            }
          }
        });
    needsAuthCheckBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            JCheckBox checkBox = (JCheckBox) arg0.getSource();
            if (!checkBox.isSelected()) {
              userField.setText("");
              passwordField.setText("");
            }
            enableAuthFields(checkBox.isSelected());
          }
        });

    needsAuthCheckBox.setSelected(initialNeedsAuth);
    enableAuthFields(initialNeedsAuth);
    userField.setText(initialUser);
    passwordField.setText(initialPassword);

    rpcServerField = new JTextField();
    rpcServerField.setFont(new Font("Calibri", Font.PLAIN, 15));
    rpcServerField.addFocusListener(
        new FocusAdapter() {
          @Override
          public void focusGained(FocusEvent e) {
            rpcServerField.selectAll();
          }
        });
    rpcServerField.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyReleased(KeyEvent e) {
            TorrentClientSectionConfig.this.parentView.keyReleased(e);
          }
        });
    rpcServerField.setColumns(10);
    setRPCFieldText(initialRpcServer);

    GroupLayout groupLayout = new GroupLayout(this);
    groupLayout.setHorizontalGroup(
        groupLayout
            .createParallelGroup(Alignment.TRAILING)
            .addGroup(
                Alignment.LEADING,
                groupLayout
                    .createSequentialGroup()
                    .addGap(48)
                    .addGroup(
                        groupLayout
                            .createParallelGroup(Alignment.LEADING, false)
                            .addComponent(needsAuthCheckBox)
                            .addGroup(
                                groupLayout
                                    .createSequentialGroup()
                                    .addComponent(lblNewLabel)
                                    .addPreferredGap(
                                        ComponentPlacement.RELATED,
                                        GroupLayout.DEFAULT_SIZE,
                                        Short.MAX_VALUE)
                                    .addComponent(
                                        rpcServerField,
                                        GroupLayout.PREFERRED_SIZE,
                                        224,
                                        GroupLayout.PREFERRED_SIZE))
                            .addGroup(
                                groupLayout
                                    .createSequentialGroup()
                                    .addGroup(
                                        groupLayout
                                            .createParallelGroup(Alignment.LEADING)
                                            .addComponent(userLabel)
                                            .addComponent(passwordLabel))
                                    .addGap(38)
                                    .addGroup(
                                        groupLayout
                                            .createParallelGroup(Alignment.LEADING, false)
                                            .addComponent(passwordField)
                                            .addComponent(
                                                userField,
                                                GroupLayout.PREFERRED_SIZE,
                                                225,
                                                GroupLayout.PREFERRED_SIZE))))
                    .addContainerGap(97, Short.MAX_VALUE)));
    groupLayout.setVerticalGroup(
        groupLayout
            .createParallelGroup(Alignment.LEADING)
            .addGroup(
                groupLayout
                    .createSequentialGroup()
                    .addGap(36)
                    .addGroup(
                        groupLayout
                            .createParallelGroup(Alignment.BASELINE)
                            .addComponent(lblNewLabel)
                            .addComponent(
                                rpcServerField,
                                GroupLayout.PREFERRED_SIZE,
                                GroupLayout.DEFAULT_SIZE,
                                GroupLayout.PREFERRED_SIZE))
                    .addGap(19)
                    .addComponent(needsAuthCheckBox)
                    .addGap(18)
                    .addGroup(
                        groupLayout
                            .createParallelGroup(Alignment.BASELINE)
                            .addComponent(userLabel)
                            .addComponent(
                                userField,
                                GroupLayout.PREFERRED_SIZE,
                                GroupLayout.DEFAULT_SIZE,
                                GroupLayout.PREFERRED_SIZE))
                    .addGap(28)
                    .addGroup(
                        groupLayout
                            .createParallelGroup(Alignment.BASELINE)
                            .addComponent(passwordLabel)
                            .addComponent(
                                passwordField,
                                GroupLayout.PREFERRED_SIZE,
                                GroupLayout.DEFAULT_SIZE,
                                GroupLayout.PREFERRED_SIZE))
                    .addContainerGap(36, Short.MAX_VALUE)));
    setLayout(groupLayout);
  }
  @Override
  protected void init() {
    GridBagLayout layout = new GridBagLayout();
    setLayout(layout);
    setPreferredSize(new Dimension(275, 275));

    String[] months = {
      "September",
      "October",
      "November",
      "December",
      "January",
      "February",
      "March",
      "April",
      "May",
      "June"
    };

    JComboBox<String> courseSelectorinit;
    if (AllCourses.getInstance().getNames().length == 0) {
      String[] defaultOption = {"No Course"};
      courseSelectorinit = new JComboBox<>(defaultOption);
    } else {
      courseSelectorinit = new JComboBox<>(AllCourses.getInstance().getNames());
    }
    final JComboBox<String> courseSelector = courseSelectorinit;
    JLabel name = new JLabel("Name"), units = new JLabel("Units");
    final JTextField nameField = new JTextField(), unitsField = new JTextField();
    final JTextField orderField = new JTextField();
    JLabel orderLabel = new JLabel("Order");
    final JTextField weightField = new JTextField();
    JLabel weightLabel = new JLabel("Weight");
    final JCheckBox finished = new JCheckBox("Finished");
    JLabel monthLabel = new JLabel("Month completed");
    final JComboBox<String> month = new JComboBox<>(months);
    done = new JButton("Done");
    cancel = new JButton("Cancel");

    name.setHorizontalAlignment(SwingConstants.CENTER);
    units.setHorizontalAlignment(SwingConstants.CENTER);
    orderLabel.setHorizontalAlignment(SwingConstants.CENTER);
    weightLabel.setHorizontalAlignment(SwingConstants.CENTER);
    monthLabel.setHorizontalAlignment(SwingConstants.CENTER);

    courseSelector.setSelectedItem(currentWork.getCourseName());
    nameField.setText(currentWork.getName());
    nameField.setCaretPosition(0);
    unitsField.setText(String.valueOf(currentWork.getUnits()));
    orderField.setText(String.valueOf(currentWork.getOrder()));
    weightField.setText(String.valueOf(currentWork.getWeight()));
    finished.setSelected(currentWork.isComplete());
    if (currentWork.isComplete()) {
      month.setSelectedIndex(currentWork.getMonthComplete());
    } else {
      month.setSelectedIndex(Workload.convertMonth(DateTime.now().getMonthOfYear()));
    }

    courseSelector.addKeyListener(doneListener);
    nameField.addKeyListener(doneListener);
    unitsField.addKeyListener(doneListener);
    orderField.addKeyListener(doneListener);
    weightField.addKeyListener(doneListener);
    finished.addKeyListener(doneListener);
    month.addKeyListener(doneListener);
    done.addKeyListener(doneListener);
    cancel.addKeyListener(doneListener);

    done.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            try {
              editWork(
                  courseSelector.getSelectedItem().toString(),
                  nameField.getText(),
                  Integer.parseInt(unitsField.getText()),
                  Integer.parseInt(orderField.getText()),
                  finished.isSelected(),
                  month.getSelectedIndex(),
                  Integer.parseInt(weightField.getText()));
              dispose();
            } catch (NumberFormatException ex) {
              new ErrorMessage(ex, "Please input real numbers").createAndViewGUI();
            }
          }
        });
    cancel.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });

    GridBagConstraints constraints = new GridBagConstraints();

    constraints.fill = GridBagConstraints.BOTH;
    constraints.insets = new Insets(5, 8, 5, 8);
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.gridwidth = 2;
    layout.addLayoutComponent(courseSelector, constraints);
    constraints.gridy = 1;
    constraints.gridx = 0;
    constraints.gridwidth = 1;
    layout.addLayoutComponent(name, constraints);
    constraints.gridx = 1;
    layout.addLayoutComponent(nameField, constraints);
    constraints.gridy = 2;
    constraints.gridx = 0;
    layout.addLayoutComponent(units, constraints);
    constraints.gridx = 1;
    layout.addLayoutComponent(unitsField, constraints);
    constraints.gridy = 3;
    constraints.gridx = 0;
    layout.addLayoutComponent(orderLabel, constraints);
    constraints.gridx = 1;
    layout.addLayoutComponent(orderField, constraints);
    constraints.gridx = 0;
    constraints.gridy = 4;
    layout.addLayoutComponent(weightLabel, constraints);
    constraints.gridx = 1;
    layout.addLayoutComponent(weightField, constraints);
    constraints.gridwidth = 2;
    constraints.gridy = 5;
    constraints.gridx = 1;
    constraints.insets = new Insets(0, 0, 0, 0);
    layout.addLayoutComponent(monthLabel, constraints);
    constraints.gridy = 6;
    constraints.gridx = 0;
    constraints.gridwidth = 1;
    constraints.insets = new Insets(5, 8, 5, 8);
    layout.addLayoutComponent(finished, constraints);
    constraints.gridx = 1;
    layout.addLayoutComponent(month, constraints);
    constraints.gridy = 7;
    constraints.gridx = 0;
    layout.addLayoutComponent(done, constraints);
    constraints.gridx = 1;
    layout.addLayoutComponent(cancel, constraints);

    add(courseSelector);
    add(name);
    add(nameField);
    add(units);
    add(unitsField);
    add(orderField);
    add(orderLabel);
    add(weightLabel);
    add(weightField);
    add(monthLabel);
    add(finished);
    add(month);
    add(done);
    add(cancel);
  }