Exemplo n.º 1
0
  @Override
  public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals(TaskSearcher.PROP_TYPE)) {
      if (!EqualsUtils.equals(this.searcherType.getSelectedItem(), evt.getNewValue()))
        this.searcherType.setSelectedItem(evt.getNewValue());
    }

    if (evt.getPropertyName().equals(TaskSearcher.PROP_TITLE)) {
      if (!EqualsUtils.equals(this.searcherTitle.getText(), evt.getNewValue()))
        this.searcherTitle.setText((String) evt.getNewValue());
    }

    if (evt.getPropertyName().equals(TaskSearcher.PROP_ICON)) {
      if (!EqualsUtils.equals(this.searcherTitle.getText(), evt.getNewValue())) {
        this.searcherIcon.setIcon(
            (String) evt.getNewValue() == null
                ? ImageUtils.getResourceImage("remove.png", 24, 24)
                : ImageUtils.getImage((String) evt.getNewValue(), 24, 24));
        this.searcherIcon.setText(
            (String) evt.getNewValue() == null
                ? Translations.getString("searcheredit.searcher.no_icon")
                : (String) evt.getNewValue());
      }
    }
  }
  private void initialize() {
    this.setModal(true);
    this.setTitle(Translations.getString("general.manage_task_templates"));
    this.setSize(800, 700);
    this.setResizable(true);
    this.setLayout(new BorderLayout());
    this.setDefaultCloseOperation(HIDE_ON_CLOSE);

    if (this.getOwner() != null) this.setLocationRelativeTo(this.getOwner());

    JXHeader header = new JXHeader();
    header.setTitle(Translations.getString("header.title.manage_task_templates"));
    header.setDescription(Translations.getString("header.description.manage_task_templates"));
    header.setIcon(ImageUtils.getResourceImage("template.png", 32, 32));

    this.add(header, BorderLayout.NORTH);
    this.add(new TaskTemplateConfigurationPanel(), BorderLayout.CENTER);

    this.initializeButtonsPanel();
  }
Exemplo n.º 3
0
  private void initialize() {
    this.setLayout(new BorderLayout());

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    FormBuilder builder = new FormBuilder("right:pref, 4dlu, fill:default:grow");

    // Type
    DefaultComboBoxModel searcherTypeModel = new DefaultComboBoxModel();
    searcherTypeModel.addElement(TaskSearcherType.GENERAL);
    searcherTypeModel.addElement(TaskSearcherType.PERSONAL);

    this.searcherType = new JComboBox(searcherTypeModel);
    this.searcherType.setSelectedItem(this.searcher.getType());
    this.searcherType.addItemListener(
        new ItemListener() {

          @Override
          public void itemStateChanged(ItemEvent e) {
            TaskSearcherType type =
                (TaskSearcherType) TaskSearcherPanel.this.searcherType.getSelectedItem();

            if (type != null) TaskSearcherPanel.this.searcher.setType(type);
          }
        });

    builder.appendI15d("searcheredit.searcher.type", true, this.searcherType);

    // Icon
    JPanel iconPanel = new JPanel(new BorderLayout());

    this.searcherIcon = new JButton();
    iconPanel.add(this.searcherIcon, BorderLayout.CENTER);
    this.searcherIcon.setIcon(
        this.searcher.getIcon() == null
            ? ImageUtils.getResourceImage("remove.png", 24, 24)
            : ImageUtils.getImage(this.searcher.getIcon(), 24, 24));
    this.searcherIcon.setText(
        this.searcher.getIcon() == null
            ? Translations.getString("searcheredit.searcher.no_icon")
            : this.searcher.getIcon());
    this.searcherIcon.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

            if (TaskSearcherPanel.this.searcher.getIcon() != null) {
              File file = new File(TaskSearcherPanel.this.searcher.getIcon());
              fileChooser.setCurrentDirectory(file);
            }

            fileChooser.setFileFilter(
                new FileFilter() {

                  @Override
                  public String getDescription() {
                    return Translations.getString("general.images");
                  }

                  @Override
                  public boolean accept(File f) {
                    if (f.isDirectory()) return true;

                    String extention = FileUtils.getExtention(f.getName());

                    String[] imageExtentions =
                        new String[] {"jpeg", "jpg", "gif", "tiff", "tif", "png"};

                    for (int i = 0; i < imageExtentions.length; i++)
                      if (imageExtentions[i].equals(extention)) return true;

                    return false;
                  }
                });

            int result = fileChooser.showOpenDialog(MainFrame.getInstance().getFrame());

            if (result == JFileChooser.APPROVE_OPTION)
              TaskSearcherPanel.this.searcher.setIcon(
                  fileChooser.getSelectedFile().getAbsolutePath());
          }
        });

    final JButton searcherRemoveIcon =
        new JButton(ImageUtils.getResourceImage("remove.png", 16, 16));
    iconPanel.add(searcherRemoveIcon, BorderLayout.EAST);
    searcherRemoveIcon.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            TaskSearcherPanel.this.searcher.setIcon(null);
          }
        });

    builder.appendI15d("searcheredit.searcher.icon", true, iconPanel);

    // Title
    this.searcherTitle = new JTextField(this.searcher.getTitle());
    this.searcherTitle.addKeyListener(
        new KeyAdapter() {

          @Override
          public void keyReleased(KeyEvent e) {
            TaskSearcherPanel.this.searcher.setTitle(
                TaskSearcherPanel.this.searcherTitle.getText());
          }
        });

    builder.appendI15d("searcheredit.searcher.title", true, this.searcherTitle);

    // Lay out the panel
    panel.add(builder.getPanel(), BorderLayout.CENTER);

    this.add(panel, BorderLayout.NORTH);
  }