Adjusted ChatWindow and ContactsChooserDialog to new interface
This commit is contained in:
parent
4c70702d02
commit
10f498ca03
@ -25,6 +25,7 @@ import envoy.client.net.WriteProxy;
|
||||
import envoy.client.ui.ContextMenu;
|
||||
import envoy.client.ui.Theme;
|
||||
import envoy.client.ui.list.ComponentList;
|
||||
import envoy.client.ui.list.ComponentList.SelectionMode;
|
||||
import envoy.client.ui.list.ComponentListModel;
|
||||
import envoy.client.ui.primary.PrimaryButton;
|
||||
import envoy.client.ui.primary.PrimaryScrollPane;
|
||||
@ -125,18 +126,21 @@ public class ChatWindow extends JFrame {
|
||||
contentPane.setLayout(gbl_contentPane);
|
||||
|
||||
messageList.setBorder(new EmptyBorder(space, space, space, space));
|
||||
messageList.setSelectionMode(SelectionMode.SINGLE);
|
||||
Map<String, ActionListener> commands = new HashMap<>() {
|
||||
|
||||
private static final long serialVersionUID = -2755235774946990126L;
|
||||
|
||||
{
|
||||
put("forward selected message",
|
||||
evt -> forwardMessageToMultipleUsers(messageList.getSelection().get(0),
|
||||
ContactsChooserDialog.showForwardingDialog("Forward selected message to", messageList.getSelection().get(0), client)));
|
||||
evt -> forwardMessageToMultipleUsers(messageList
|
||||
.getSingleSelectedElement(),
|
||||
ContactsChooserDialog
|
||||
.showForwardingDialog("Forward selected message to", messageList.getSingleSelectedElement(), client)));
|
||||
put("copy", evt -> {
|
||||
// TODO should be enhanced to allow also copying of message attachments,
|
||||
// especially pictures
|
||||
StringSelection copy = new StringSelection(messageList.getSelection().get(0).getText());
|
||||
StringSelection copy = new StringSelection(messageList.getSingleSelectedElement().getText());
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(copy, copy);
|
||||
});
|
||||
// TODO insert implementation to edit and delete messages
|
||||
|
@ -15,6 +15,7 @@ import envoy.client.data.Settings;
|
||||
import envoy.client.net.Client;
|
||||
import envoy.client.ui.Theme;
|
||||
import envoy.client.ui.list.ComponentList;
|
||||
import envoy.client.ui.list.ComponentList.SelectionMode;
|
||||
import envoy.client.ui.list.ComponentListModel;
|
||||
import envoy.client.ui.renderer.MessageListRenderer;
|
||||
import envoy.client.ui.renderer.UserComponentListRenderer;
|
||||
@ -69,7 +70,7 @@ public class ContactsChooserDialog extends JDialog {
|
||||
dialog.getContentPanel()
|
||||
.add(new MessageListRenderer(client.getSender().getId()).getListCellComponent(null, message, false), BorderLayout.NORTH);
|
||||
List<User> results = new ArrayList<>();
|
||||
dialog.addOkButtonActionListener(e -> { results.addAll(dialog.getContactList().getSelection()); dialog.dispose(); });
|
||||
dialog.addOkButtonActionListener(e -> { results.addAll(dialog.getContactList().getSelectedElements()); dialog.dispose(); });
|
||||
ComponentListModel<User> contactListModel = dialog.getContactList().getModel();
|
||||
client.getContacts().getContacts().forEach(user -> contactListModel.add(user));
|
||||
dialog.setVisible(true);
|
||||
@ -82,7 +83,7 @@ public class ContactsChooserDialog extends JDialog {
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
private ContactsChooserDialog() {
|
||||
contactList.enableMultipleSelection();
|
||||
contactList.setSelectionMode(SelectionMode.MULTIPLE);
|
||||
// setBounds(100, 100, 450, 300);
|
||||
setModal(true);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
|
@ -30,8 +30,26 @@ public class ComponentList<E> extends JPanel {
|
||||
|
||||
private static final long serialVersionUID = 1759644503942876737L;
|
||||
|
||||
/**
|
||||
* Defines the possible modes of selection that can be performed by the user
|
||||
*
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
public static enum SelectionMode {
|
||||
NONE, SINGLE, MULTIPLE
|
||||
/**
|
||||
* Selection is completely ignored.
|
||||
*/
|
||||
NONE,
|
||||
|
||||
/**
|
||||
* Only a single element can be selected.
|
||||
*/
|
||||
SINGLE,
|
||||
|
||||
/**
|
||||
* Multiple elements can be selected regardless of their position.
|
||||
*/
|
||||
MULTIPLE
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,6 +220,30 @@ public class ComponentList<E> extends JPanel {
|
||||
*/
|
||||
public Set<Integer> getSelection() { return selection; }
|
||||
|
||||
/**
|
||||
* @return a set of all selected elements
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
public Set<E> getSelectedElements() {
|
||||
var selectedElements = new HashSet<E>();
|
||||
selection.forEach(i -> selectedElements.add(model.get(i)));
|
||||
return selectedElements;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the index of an arbitrary selected element
|
||||
* @throws java.util.NoSuchElementException if no selection is present
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
public int getSingleSelection() { return selection.iterator().next(); }
|
||||
|
||||
/**
|
||||
* @return an arbitrary selected element
|
||||
* @throws java.util.NoSuchElementException if no selection is present
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
public E getSingleSelectedElement() { return model.get(getSingleSelection()); }
|
||||
|
||||
/**
|
||||
* @return the model
|
||||
* @since Envoy v0.1-beta
|
||||
@ -221,13 +263,13 @@ public class ComponentList<E> extends JPanel {
|
||||
public void setRenderer(ComponentListCellRenderer<E> renderer) { this.renderer = renderer; }
|
||||
|
||||
/**
|
||||
* @return the selectionMode
|
||||
* @return the selection mode
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
public SelectionMode getSelectionMode() { return selectionMode; }
|
||||
|
||||
/**
|
||||
* @param selectionMode the selectionMode to set
|
||||
* @param selectionMode the selection mode to set
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
public void setSelectionMode(SelectionMode selectionMode) { this.selectionMode = selectionMode; }
|
||||
|
Reference in New Issue
Block a user