Exemplo n.º 1
1
 @Override
 public void profileSelectionChanged(final Optional<MutableProfile> profile) {
   okButton.setEnabled(model.isSaveAllowed());
   deleteProfile.setEnabled(model.getSelectedProfile().isPresent());
   if (profile.isPresent()) {
     final int index = profilesModel.indexOf(profile.get());
     selectionModel.setLeadSelectionIndex(index);
   } else {
     selectionModel.setLeadSelectionIndex(-1);
   }
   addNickname.setEnabled(model.getSelectedProfile().isPresent());
   editNickname.setEnabled(model.getSelectedProfile().isPresent());
   addHighlight.setEnabled(model.getSelectedProfile().isPresent());
   editHighlight.setEnabled(model.getSelectedProfile().isPresent());
   name.setEnabled(model.getSelectedProfile().isPresent());
   name.setText(model.getSelectedProfileName().orElse(""));
   nicknames.setEnabled(model.getSelectedProfile().isPresent());
   nicknamesModel.clear();
   nicknamesModel.addAll(model.getSelectedProfileNicknames().orElse(Lists.newArrayList()));
   highlights.setEnabled(model.getSelectedProfile().isPresent());
   highlightsModel.clear();
   highlightsModel.addAll(model.getSelectedProfileHighlights().orElse(Lists.newArrayList()));
   realname.setEnabled(model.getSelectedProfile().isPresent());
   realname.setText(model.getSelectedProfileRealname().orElse(""));
   ident.setEnabled(model.getSelectedProfile().isPresent());
   ident.setText(model.getSelectedProfileIdent().orElse(""));
 }
Exemplo n.º 2
0
 @Override
 public void selectedProfileNicknameEdited(final String oldNickname, final String newNickname) {
   okButton.setEnabled(model.isSaveAllowed());
   nicknamesModel.set(nicknamesModel.indexOf(oldNickname), newNickname);
   addNickname.setEnabled(model.isSelectedProfileNicknamesValid());
   editNickname.setEnabled(model.isSelectedProfileNicknamesValid());
 }
Exemplo n.º 3
0
 @Override
 public void selectedProfileHighlightEdited(final String oldHighlight, final String newHighlight) {
   okButton.setEnabled(model.isSaveAllowed());
   highlightsModel.set(highlightsModel.indexOf(oldHighlight), newHighlight);
   deleteHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
   editHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
 }
Exemplo n.º 4
0
 private void setupProfileName(final JTextField name) {
   name.setEnabled(model.getSelectedProfileName().isPresent());
   name.setText(model.getSelectedProfileName().orElse(""));
   name.getDocument()
       .addDocumentListener(
           new ConsumerDocumentListener(s -> model.setSelectedProfileName(Optional.of(s))));
 }
Exemplo n.º 5
0
 @Override
 public void selectedProfileHighlightAdded(final String highlight) {
   okButton.setEnabled(model.isSaveAllowed());
   highlightsModel.add(highlight);
   deleteHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
   editHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
 }
Exemplo n.º 6
0
 @Override
 public void profileRemoved(final MutableProfile profile) {
   addNickname.setEnabled(model.isProfileListValid());
   addHighlight.setEnabled(model.isProfileListValid());
   okButton.setEnabled(model.isSaveAllowed());
   profilesModel.remove(profile);
 }
Exemplo n.º 7
0
 private void setupDeleteNickname(final JButton deleteNickname) {
   deleteNickname.setEnabled(model.getSelectedProfileSelectedNickname().isPresent());
   deleteNickname.addActionListener(
       l ->
           model
               .getSelectedProfileSelectedNickname()
               .ifPresent(model::removeSelectedProfileNickname));
 }
Exemplo n.º 8
0
 private void setupOKButton(final JButton okButton) {
   okButton.setEnabled(model.isSaveAllowed());
   okButton.addActionListener(
       l -> {
         model.save();
         dialog.dispose();
       });
 }
Exemplo n.º 9
0
 private void setupDeleteHighlight(final JButton deleteHighlight) {
   deleteHighlight.setEnabled(model.getSelectedProfileSelectedHighlight().isPresent());
   deleteHighlight.addActionListener(
       l ->
           model
               .getSelectedProfileSelectedHighlight()
               .ifPresent(model::removeSelectedProfileHighlight));
 }
Exemplo n.º 10
0
 private void setupProfileNicknames(final ReorderableJList<String> nicknames) {
   nicknamesModel = nicknames.getModel();
   nicknamesModel.addAll(model.getSelectedProfileNicknames().orElse(Lists.newArrayList()));
   nicknames.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   nicknames.setEnabled(model.getSelectedProfileNicknames().isPresent());
   nicknames.addListSelectionListener(
       l ->
           model.setSelectedProfileSelectedNickname(
               Optional.ofNullable(nicknames.getSelectedValue())));
 }
Exemplo n.º 11
0
 private void setupProfileHighlights(final ReorderableJList<String> highlights) {
   highlightsModel = highlights.getModel();
   highlightsModel.addAll(model.getSelectedProfileHighlights().orElse(Lists.newArrayList()));
   highlights.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   highlights.setEnabled(model.getSelectedProfileHighlights().isPresent());
   highlights.addListSelectionListener(
       l ->
           model.setSelectedProfileSelectedHighlight(
               Optional.ofNullable(highlights.getSelectedValue())));
 }
Exemplo n.º 12
0
 private void setupProfileIdent(final JTextField ident) {
   ident.setEnabled(model.getSelectedProfileIdent().isPresent());
   ident.setText(model.getSelectedProfileIdent().orElse(""));
   ident
       .getDocument()
       .addDocumentListener(
           new ConsumerDocumentListener(
               s -> {
                 if (model.getSelectedProfile().isPresent()) {
                   model.setSelectedProfileIdent(Optional.of(s));
                 }
               }));
 }
Exemplo n.º 13
0
 private void setupAddHighlight(final JButton addHighlight) {
   addHighlight.setEnabled(!model.getProfileList().isEmpty());
   addHighlight.addActionListener(
       e ->
           new StandardInputDialog(
                   dialog,
                   Dialog.ModalityType.DOCUMENT_MODAL,
                   iconManager,
                   "Profile Manager: Add Highlight",
                   "Enter highlight to add",
                   model.getSelectedProfileAddHighlightValidator(),
                   model::addSelectedProfileHighlight)
               .display());
 }
Exemplo n.º 14
0
 public void init(
     final JList<MutableProfile> profileList,
     final JButton addProfile,
     final JButton deleteProfile,
     final JTextField name,
     final ReorderableJList<String> nicknames,
     final JButton addNickname,
     final JButton editNickname,
     final JButton deleteNickname,
     final JTextField realname,
     final JTextField ident,
     final ReorderableJList<String> highlights,
     final JButton addHighlight,
     final JButton editHighlight,
     final JButton deleteHighlight,
     final JButton okButton,
     final JButton cancelButton) {
   this.deleteProfile = deleteProfile;
   this.name = name;
   this.nicknames = nicknames;
   this.addNickname = addNickname;
   this.editNickname = editNickname;
   this.deleteNickname = deleteNickname;
   this.realname = realname;
   this.ident = ident;
   this.highlights = highlights;
   this.addHighlight = addHighlight;
   this.editHighlight = editHighlight;
   this.deleteHighlight = deleteHighlight;
   this.okButton = okButton;
   model.loadModel();
   setupOKButton(okButton);
   setupCancelButton(cancelButton);
   setupProfileList(profileList);
   setupAddProfile(addProfile);
   setupDeleteProfile(deleteProfile);
   setupEditNickname(editNickname);
   setupAddNickname(addNickname);
   setupDeleteNickname(deleteNickname);
   setupProfileName(name);
   setupProfileNicknames(nicknames);
   setupProfileRealname(realname);
   setupProfileIdent(ident);
   setupProfileHighlights(highlights);
   setupAddHighlight(addHighlight);
   setupEditHighlight(editHighlight);
   setupDeleteHighlight(deleteHighlight);
   model.addListener(this);
 }
Exemplo n.º 15
0
 private void setupProfileList(final JList<MutableProfile> profileList) {
   selectionModel = new VetoableListSelectionModel();
   profilesModel = (GenericListModel<MutableProfile>) profileList.getModel();
   profilesModel.addAll(model.getProfileList());
   profileList.setSelectionModel(selectionModel);
   selectionModel.addVetoableSelectionListener(
       e -> {
         if (!model.canSwitchProfiles()) {
           throw new PropertyVetoException("Cannot switch with invalid profile", e);
         }
       });
   profileList.addListSelectionListener(
       l -> {
         if (!selectionModel.isSelectionEmpty()) {
           model.setSelectedProfile(Optional.ofNullable(profileList.getSelectedValue()));
         }
       });
 }
Exemplo n.º 16
0
 private void setupEditHighlight(final JButton editHighlight) {
   editHighlight.setEnabled(model.getSelectedProfileSelectedHighlight().isPresent());
   editHighlight.addActionListener(
       l ->
           model
               .getSelectedProfileSelectedHighlight()
               .ifPresent(
                   (String oldName) ->
                       new StandardInputDialog(
                               dialog,
                               Dialog.ModalityType.DOCUMENT_MODAL,
                               iconManager,
                               "Profile Manager: Edit Highlight",
                               "Enter new highlight",
                               model.getSelectedProfileEditHighlightValidator(),
                               (String newName) ->
                                   model.editSelectedProfileHighlight(oldName, newName))
                           .display()));
 }
Exemplo n.º 17
0
 private void setupAddProfile(final JButton addProfile) {
   addProfile.addActionListener(
       e ->
           new StandardInputDialog(
                   dialog,
                   Dialog.ModalityType.DOCUMENT_MODAL,
                   iconManager,
                   "Profile Manager: Add Profile",
                   "Enter the new profile's name",
                   model.getNewProfileNameValidator(),
                   (Consumer<String>) model::addProfile)
               .display());
 }
Exemplo n.º 18
0
 @Override
 public void selectedProfileHighlightRemoved(final String highlight) {
   okButton.setEnabled(model.isSaveAllowed());
   highlightsModel.remove(highlight);
 }
Exemplo n.º 19
0
 @Override
 public void selectedHighlightChanged(final Optional<String> highlight) {
   deleteHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
   editHighlight.setEnabled(model.isSelectedProfileHighlightsValid());
 }
Exemplo n.º 20
0
 @Override
 public void selectedProfileNicknameRemoved(final String nickname) {
   okButton.setEnabled(model.isSaveAllowed());
   nicknamesModel.remove(nickname);
 }
Exemplo n.º 21
0
 @Override
 public void selectedNicknameChanged(final Optional<String> nickname) {
   okButton.setEnabled(model.isSaveAllowed());
   deleteNickname.setEnabled(model.isSelectedProfileNicknamesValid());
   editNickname.setEnabled(model.isSelectedProfileNicknamesValid());
 }
Exemplo n.º 22
0
 @Override
 public void profileEdited(final MutableProfile profile) {
   okButton.setEnabled(model.isSaveAllowed());
 }