예제 #1
0
  private void save() {
    if (!mSubjectField.getText().equals(mThread.getSubject())) {
      mThread.setSubject(mSubjectField.getText());
    }
    //        List<?> participants = mParticipantsList.getCheckedValues();
    //        Set<User> threadUser = new HashSet<>();
    //        for (Object o: participants) {
    //            threadUser.add(((UserElement) o).user);
    //        }
    //        mThread.setUser(threadUser);

    KonThread.ViewSettings newSettings;
    if (mColorOpt.isSelected()) newSettings = new KonThread.ViewSettings(mColor.getBottomBgColor());
    else if (mImgOpt.isSelected() && !mImgChooser.getSelectedFiles().isEmpty())
      newSettings =
          new KonThread.ViewSettings(mImgChooser.getSelectedFiles().get(0).getAbsolutePath());
    else newSettings = new KonThread.ViewSettings();

    if (!newSettings.equals(mThread.getViewSettings())) {
      mThread.setViewSettings(newSettings);
    }
  }
예제 #2
0
  ThreadDetails(final Component focusGainer, KonThread thread) {
    mThread = thread;

    GroupPanel groupPanel = new GroupPanel(View.GAP_BIG, false);
    groupPanel.setMargin(View.MARGIN_BIG);

    groupPanel.add(new WebLabel(Tr.tr("Edit Chat")).setBoldFont());
    groupPanel.add(new WebSeparator(true, true));

    // editable fields
    groupPanel.add(new WebLabel(Tr.tr("Subject:")));
    String subj = mThread.getSubject();
    mSubjectField = new WebTextField(subj, 22);
    mSubjectField.setInputPrompt(subj);
    mSubjectField.setHideInputPromptOnFocus(false);
    groupPanel.add(mSubjectField);
    groupPanel.add(new WebSeparator(true, true));

    final WebSlider colorSlider = new WebSlider(WebSlider.HORIZONTAL);

    groupPanel.add(new WebLabel(Tr.tr("Custom Background")));
    mColorOpt = new WebRadioButton(Tr.tr("Color:") + " ");
    Optional<Color> optBGColor = mThread.getViewSettings().getBGColor();
    mColorOpt.setSelected(optBGColor.isPresent());
    mColorOpt.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            colorSlider.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
          }
        });
    mColor = new WebButton();
    mColor.setMinimumHeight(25);
    Color oldColor = optBGColor.orElse(DEFAULT_BG);
    mColor.setBottomBgColor(oldColor);
    groupPanel.add(new GroupPanel(GroupingType.fillLast, mColorOpt, mColor));

    colorSlider.setMinimum(0);
    colorSlider.setMaximum(100);
    colorSlider.setPaintTicks(false);
    colorSlider.setPaintLabels(false);
    colorSlider.setEnabled(optBGColor.isPresent());
    final GradientData gradientData = GradientData.getDefaultValue();
    // TODO set location for color
    gradientData.getColor(0);
    colorSlider.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent e) {
            float v = colorSlider.getValue() / (float) 100;
            Color c = gradientData.getColorForLocation(v);
            mColor.setBottomBgColor(c);
            mColor.repaint();
          }
        });
    groupPanel.add(colorSlider);

    mImgOpt = new WebRadioButton(Tr.tr("Image:") + " ");
    String imgPath = mThread.getViewSettings().getImagePath();
    mImgOpt.setSelected(!imgPath.isEmpty());
    mImgOpt.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            mImgChooser.setEnabled(e.getStateChange() == ItemEvent.SELECTED);
            mImgChooser.getChooseButton().setEnabled(e.getStateChange() == ItemEvent.SELECTED);
          }
        });
    mImgChooser = Utils.createImageChooser(!imgPath.isEmpty(), imgPath);
    groupPanel.add(new GroupPanel(GroupingType.fillLast, mImgOpt, mImgChooser));
    UnselectableButtonGroup.group(mColorOpt, mImgOpt);
    groupPanel.add(new WebSeparator());

    //        groupPanel.add(new WebLabel(Tr.tr("Participants:")));
    //        mParticipantsList = new WebCheckBoxList();
    //        mParticipantsList.setVisibleRowCount(10);
    //        for (User oneUser : UserList.getInstance().getAll()) {
    //            boolean selected = mThread.getUser().contains(oneUser);
    //            mParticipantsList.getCheckBoxListModel().addCheckBoxElement(
    //                    new UserElement(oneUser),
    //                    selected);
    //        }
    final WebButton saveButton = new WebButton(Tr.tr("Save"));
    //        mParticipantsList.getModel().addListDataListener(new ListDataListener() {
    //            @Override
    //            public void intervalAdded(ListDataEvent e) {
    //            }
    //            @Override
    //            public void intervalRemoved(ListDataEvent e) {
    //            }
    //            @Override
    //            public void contentsChanged(ListDataEvent e) {
    //                saveButton.setEnabled(!mParticipantsList.getCheckedValues().isEmpty());
    //            }
    //        });
    //
    //        groupPanel.add(new WebScrollPane(mParticipantsList));
    //        groupPanel.add(new WebSeparator(true, true));

    this.add(groupPanel, BorderLayout.CENTER);

    saveButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            //                if (mParticipantsList.getCheckedValues().size() > 1) {
            //                        String infoText = Tr.t/r("More than one receiver not supported
            // (yet).");
            //                        WebOptionPane.showMessageDialog(ThreadListView.this,
            //                                infoText,
            //                                Tr.t/r("Sorry"),
            //                                WebOptionPane.INFORMATION_MESSAGE);
            //                    return;
            //                }
            ThreadDetails.this.save();

            // close popup
            focusGainer.requestFocus();
          }
        });
    // this.getRootPane().setDefaultButton(saveButton);

    GroupPanel buttonPanel = new GroupPanel(2, saveButton);
    buttonPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    this.add(buttonPanel, BorderLayout.SOUTH);
  }