Exemple #1
0
  /**
   * Show a project
   *
   * @param function the action being taken
   * @param p the project
   * @param parentId the parent project id
   * @throws Exception
   */
  private void showProject(Action function, Project p, Integer parentId) throws Exception {

    // set the link panel to show this project's links
    linkPanel.setOwner(p);

    // show all possible parent projects
    parentProjectComboBox.removeAllItems();
    parentProjectComboBox.addItem("");
    Collection<Project> projects = TaskModel.getReference().getProjects();
    if (projects != null) {
      for (Project project : projects) {
        // add open projects that are not the current one
        if ((p == null || p.getKey() != project.getKey())
            && project.getStatus().equals(Resource.getResourceString("OPEN")))
          parentProjectComboBox.addItem(getProjectString(project));
      }
    }

    // if we are showing an existing project - fill in the gui fields for it
    if (p != null) {
      // task number
      projectIdText.setText(Integer.toString(p.getKey()));
      projectIdText.setEditable(false);

      // window title - "Item N"
      windowTitle = Resource.getResourceString("Item_") + " " + p.getKey();

      // due date
      GregorianCalendar gc = new GregorianCalendar();
      Date dd = p.getDueDate();
      if (dd != null) {
        gc.setTime(dd);
        dueDateChooser.setCalendar(gc);
      }

      GregorianCalendar gc2 = new GregorianCalendar();
      dd = p.getStartDate();
      if (dd != null) gc2.setTime(dd);
      startDateChooser.setCalendar(gc2);

      int daysleft = DateUtil.daysLeft(p.getDueDate());
      daysLeftText.setText(Integer.toString(daysleft));

      String cat = p.getCategory();
      if (cat != null && !cat.equals("")) {
        categoryBox.setSelectedItem(cat);
      } else {
        categoryBox.setSelectedIndex(0);
      }

      description.setText(p.getDescription());

      statusComboBox.setEditable(false);

      Collection<Task> ptasks = TaskModel.getReference().getTasks(p.getKey());
      totalTaskCount.setText(Integer.toString(ptasks.size()));

      int openTasks = 0;
      for (Task pt : ptasks) {
        if (!TaskModel.isClosed(pt)) {
          openTasks++;
        }
      }
      openTaskCount.setText(Integer.toString(openTasks));

      // set parent project
      Integer pid = p.getParent();
      if (pid != null) {
        Project par = TaskModel.getReference().getProject(pid.intValue());
        if (TaskModel.isClosed(par)) {
          // if parent closed - would not have been added before
          parentProjectComboBox.addItem(getProjectString(par));
        }
        parentProjectComboBox.setSelectedItem(getProjectString(par));
      }

      // add the task list
      if (taskPanel == null) {
        taskPanel = new TaskListPanel(TaskView.getProjectString(p));
        taskPanel.addClosedTaskFilter();
        taskBorder.add(
            taskPanel, GridBagConstraintsFactory.create(0, 0, GridBagConstraints.BOTH, 1.0, 1.0));
      }

    } else {
      // set fields for a new project

      projectIdText.setText("NEW");
      projectIdText.setEditable(false);

      // title
      windowTitle = Resource.getResourceString("NEW_Item");
      statusComboBox.addItem(Resource.getResourceString("OPEN"));
      statusComboBox.setEnabled(false);
      categoryBox.setSelectedIndex(0);
      description.setText(""); // desc
      totalTaskCount.setText("");
      openTaskCount.setText("");

      // parent id may have been passed in
      if (parentId != null) {
        Project par = TaskModel.getReference().getProject(parentId.intValue());
        if (TaskModel.isClosed(par)) {
          parentProjectComboBox.addItem(getProjectString(par));
        }
        parentProjectComboBox.setSelectedItem(getProjectString(par));

        String cat = par.getCategory();
        if (cat != null && !cat.equals("")) {
          categoryBox.setSelectedItem(cat);
        } else {
          categoryBox.setSelectedIndex(0);
        }

        GregorianCalendar gc = new GregorianCalendar();
        Date dd = par.getDueDate();
        if (dd != null) {
          gc.setTime(dd);
          dueDateChooser.setCalendar(gc);
        }

        Date sd = par.getStartDate();
        if (sd != null) {
          gc.setTime(sd);
          startDateChooser.setCalendar(gc);
        }
      }
    }

    // can't change status on a new project
    if (p == null) {
      statusComboBox.setEnabled(false);
    }

    // cloning takes the fields filled in for an existing task and resets
    // only those
    // that don't apply to the clone
    if (function == Action.CLONE) {
      // need new task number
      projectIdText.setText("CLONE");
      projectIdText.setEditable(false);

      statusComboBox.removeAllItems();
      statusComboBox.addItem(Resource.getResourceString("OPEN"));
      statusComboBox.setEnabled(false);

    }
    // change existing task
    else if (function == Action.CHANGE) {

      String state = null;
      if (p != null) state = p.getStatus();

      // set next state pulldown - projects only move between open and
      // closed
      statusComboBox.removeAllItems();
      statusComboBox.addItem(Resource.getResourceString("OPEN"));
      statusComboBox.addItem(Resource.getResourceString("CLOSED"));
      statusComboBox.setSelectedItem(state);
      statusComboBox.setEnabled(true);
    }
  }
  /** Instantiates a new miscellaneous options panel. */
  public MiscellaneousOptionsPanel() {

    this.setLayout(new java.awt.GridBagLayout());

    ResourceHelper.setText(splashbox, "splash");
    this.add(splashbox, GridBagConstraintsFactory.create(0, 0, GridBagConstraints.BOTH));

    ResourceHelper.setText(stackbox, "stackonerr");
    this.add(stackbox, GridBagConstraintsFactory.create(0, 1, GridBagConstraints.BOTH));

    JLabel sportlabel = new JLabel();
    ResourceHelper.setText(sportlabel, "socket_port");
    this.add(sportlabel, GridBagConstraintsFactory.create(0, 2, GridBagConstraints.BOTH));

    this.add(socketPort, GridBagConstraintsFactory.create(1, 2, GridBagConstraints.BOTH));

    useSysTray.setText(Resource.getResourceString("enable_systray"));
    this.add(useSysTray, GridBagConstraintsFactory.create(0, 3, GridBagConstraints.BOTH));

    startToSysTray.setText(Resource.getResourceString("StartToSysTray"));
    this.add(startToSysTray, GridBagConstraintsFactory.create(0, 4, GridBagConstraints.BOTH));

    dateInSysTray.setText(Resource.getResourceString("show_date_in_systray"));
    this.add(dateInSysTray, GridBagConstraintsFactory.create(0, 5, GridBagConstraints.BOTH));

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

    backp.add(
        new JLabel(Resource.getResourceString("backup_dir") + ": "),
        GridBagConstraintsFactory.create(0, 0, GridBagConstraints.NONE));

    backp.add(backupDir, GridBagConstraintsFactory.create(1, 0, GridBagConstraints.BOTH, 1.0, 0.0));

    JButton bb = new JButton();
    ResourceHelper.setText(bb, "Browse");
    bb.addActionListener(
        new java.awt.event.ActionListener() {
          @Override
          public void actionPerformed(java.awt.event.ActionEvent evt) {
            String dbdir = OptionsPanel.chooseDir();
            if (dbdir == null) {
              return;
            }

            backupDir.setText(dbdir);
          }
        });
    backp.add(bb, GridBagConstraintsFactory.create(2, 0, GridBagConstraints.NONE));

    backp.add(
        new JLabel(Resource.getResourceString("on_shutdown")),
        GridBagConstraintsFactory.create(0, 1, GridBagConstraints.BOTH));

    shutdownAction.addItem(Resource.getResourceString("prompt_for_backup"));
    shutdownAction.addItem(Resource.getResourceString("exit_no_backup"));
    shutdownAction.addItem(Resource.getResourceString("write_backup_file"));
    shutdownAction.addItem(Resource.getResourceString("backup_with_email"));

    backp.add(
        shutdownAction, GridBagConstraintsFactory.create(1, 1, GridBagConstraints.BOTH, 1.0, 0.0));

    GridBagConstraints gbc1 =
        GridBagConstraintsFactory.create(0, 6, GridBagConstraints.BOTH, 1.0, 0.0);
    gbc1.gridwidth = 2;
    this.add(backp, gbc1);

    ResourceHelper.setText(colorprint, "Print_In_Color?");
    this.add(colorprint, GridBagConstraintsFactory.create(0, 8, GridBagConstraints.BOTH));

    dynamicLoading.setText(Resource.getResourceString("enable_plugins"));
    gbc1 = GridBagConstraintsFactory.create(0, 9, GridBagConstraints.BOTH);
    gbc1.gridwidth = 2;
    this.add(dynamicLoading, gbc1);

    verboseLogging.setText(Resource.getResourceString("verbose_logging"));
    gbc1 = GridBagConstraintsFactory.create(0, 10, GridBagConstraints.BOTH);
    gbc1.gridwidth = 2;
    this.add(verboseLogging, gbc1);

    useProxy.setText(Resource.getResourceString("Use_Proxy"));
    gbc1 = GridBagConstraintsFactory.create(0, 11, GridBagConstraints.BOTH);
    gbc1.gridwidth = 2;
    this.add(useProxy, gbc1);

    this.add(
        new JLabel(Resource.getResourceString("proxy_host")),
        GridBagConstraintsFactory.create(0, 12, GridBagConstraints.BOTH));
    this.add(proxyHostText, GridBagConstraintsFactory.create(1, 12, GridBagConstraints.BOTH));

    this.add(
        new JLabel(Resource.getResourceString("proxy_port")),
        GridBagConstraintsFactory.create(0, 13, GridBagConstraints.BOTH));
    this.add(proxyPortText, GridBagConstraintsFactory.create(1, 13, GridBagConstraints.BOTH));
  }
Exemple #3
0
  /** Initialize the UI. */
  private void initComponents() // GEN-BEGIN:initComponents
      {

    setLayout(new GridBagLayout());

    /*
     * project info panel
     */
    JPanel projectInfoPanel = new JPanel();
    projectInfoPanel.setLayout(new GridBagLayout());

    projectInfoPanel.setBorder(new TitledBorder(Resource.getResourceString("ProjectInformation")));

    projectIdText = new JTextField();
    projectIdText.setText("projectIdText");

    description = new JTextField();
    JLabel lblItemNum = new JLabel();
    lblItemNum.setText(Resource.getResourceString("Item_#"));

    dueDateChooser = new JDateChooser();
    JLabel lblStartDate = new JLabel();
    JLabel lblDueDate = new JLabel();
    statusComboBox = new JComboBox();
    JLabel catlabel = new JLabel();

    JLabel lblStatus = new JLabel();
    ResourceHelper.setText(lblStatus, "Status");
    lblStatus.setLabelFor(statusComboBox);

    startDateChooser = new JDateChooser();
    ResourceHelper.setText(lblStartDate, "Start_Date");
    lblStartDate.setLabelFor(startDateChooser);

    ResourceHelper.setText(lblDueDate, "Due_Date");
    lblDueDate.setLabelFor(dueDateChooser);

    ResourceHelper.setText(catlabel, "Category");
    categoryBox = new JComboBox();
    catlabel.setLabelFor(categoryBox);

    projectInfoPanel.add(
        lblItemNum, GridBagConstraintsFactory.create(0, 0, GridBagConstraints.BOTH));
    projectInfoPanel.add(
        lblStatus, GridBagConstraintsFactory.create(0, 1, GridBagConstraints.BOTH));
    projectInfoPanel.add(catlabel, GridBagConstraintsFactory.create(0, 2, GridBagConstraints.BOTH));
    JLabel descLabel = new JLabel();
    descLabel.setText(Resource.getResourceString("Description"));
    projectInfoPanel.add(
        descLabel, GridBagConstraintsFactory.create(0, 3, GridBagConstraints.BOTH));

    projectInfoPanel.add(
        projectIdText, GridBagConstraintsFactory.create(1, 0, GridBagConstraints.BOTH));
    projectInfoPanel.add(
        statusComboBox, GridBagConstraintsFactory.create(1, 1, GridBagConstraints.BOTH, 1.0, 0.0));
    projectInfoPanel.add(
        categoryBox, GridBagConstraintsFactory.create(1, 2, GridBagConstraints.BOTH, 1.0, 0.0));
    GridBagConstraints dgbc =
        GridBagConstraintsFactory.create(1, 3, GridBagConstraints.BOTH, 1.0, 0.0);
    dgbc.gridwidth = 5;
    projectInfoPanel.add(description, dgbc);

    JLabel parentLabel = new JLabel(Resource.getResourceString("parent"));
    projectInfoPanel.add(
        parentLabel, GridBagConstraintsFactory.create(2, 0, GridBagConstraints.BOTH));
    projectInfoPanel.add(
        lblStartDate, GridBagConstraintsFactory.create(2, 1, GridBagConstraints.BOTH));
    projectInfoPanel.add(
        lblDueDate, GridBagConstraintsFactory.create(2, 2, GridBagConstraints.BOTH));

    projectInfoPanel.add(
        parentProjectComboBox,
        GridBagConstraintsFactory.create(3, 0, GridBagConstraints.BOTH, 1.0, 0.0));
    projectInfoPanel.add(
        startDateChooser,
        GridBagConstraintsFactory.create(3, 1, GridBagConstraints.BOTH, 1.0, 0.0));
    projectInfoPanel.add(
        dueDateChooser, GridBagConstraintsFactory.create(3, 2, GridBagConstraints.BOTH, 1.0, 0.0));

    JLabel daysLeftLabel = new JLabel();
    daysLeftLabel.setText(Resource.getResourceString("Days_Left"));
    daysLeftLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
    daysLeftLabel.setHorizontalAlignment(SwingConstants.RIGHT);
    projectInfoPanel.add(daysLeftLabel, GridBagConstraintsFactory.create(4, 0));
    JLabel totalLabel = new JLabel();
    totalLabel.setText(Resource.getResourceString("total_tasks"));
    projectInfoPanel.add(totalLabel, GridBagConstraintsFactory.create(4, 1));
    JLabel openLabel = new JLabel();
    openLabel.setText(Resource.getResourceString("open_tasks"));
    projectInfoPanel.add(openLabel, GridBagConstraintsFactory.create(4, 2));

    daysLeftText = new JTextField();
    daysLeftText.setEditable(false);
    projectInfoPanel.add(
        daysLeftText, GridBagConstraintsFactory.create(5, 0, GridBagConstraints.BOTH, 1.0, 0.0));
    totalTaskCount = new JTextField();
    totalTaskCount.setEditable(false);
    projectInfoPanel.add(
        totalTaskCount, GridBagConstraintsFactory.create(5, 1, GridBagConstraints.BOTH, 1.0, 0.0));
    openTaskCount = new JTextField();
    openTaskCount.setEditable(false);
    projectInfoPanel.add(
        openTaskCount, GridBagConstraintsFactory.create(5, 2, GridBagConstraints.BOTH, 1.0, 0.0));

    add(
        projectInfoPanel,
        GridBagConstraintsFactory.create(0, 0, GridBagConstraints.BOTH, 1.0, 0.0));

    /*
     * button panel
     */
    JPanel buttonPanel = new JPanel();
    JButton savebutton = new JButton();

    savebutton.setIcon(new ImageIcon(getClass().getResource("/resource/Save16.gif")));
    ResourceHelper.setText(savebutton, "Save");
    savebutton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent evt) {
            saveProject();
          }
        });
    buttonPanel.add(savebutton, savebutton.getName());

    GridBagConstraints bc =
        GridBagConstraintsFactory.create(0, 7, GridBagConstraints.BOTH, 0.0, 0.0);
    bc.gridwidth = 6;
    projectInfoPanel.add(buttonPanel, bc);

    /*
     * link panel
     */

    linkPanel.setBorder(new TitledBorder(Resource.getResourceString("links")));
    add(linkPanel, GridBagConstraintsFactory.create(0, 2, GridBagConstraints.BOTH));

    /*
     * panel that will contain the project's task list
     */
    taskBorder = new JPanel();
    taskBorder.setBorder(new TitledBorder(Resource.getResourceString("tasks")));
    taskBorder.setLayout(new GridBagLayout());

    add(taskBorder, GridBagConstraintsFactory.create(0, 3, GridBagConstraints.BOTH, 1.0, 1.0));
  }