Accueil > > > SELECTIONLISTSPANEL
SELECTIONLISTSPANEL
Information sur la source
Description
Panneau intégrant deux listes permettant la selection d'éléments de l'une vers l'autre.
Source
- package com.infodavid.gui;
- /*
- * Copyright (c) 2001 David Rolland
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * -Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * -Redistribution in binary form must reproduct the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * This software is provided "AS IS," without a warranty of any kind. ALL
- * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
- * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
- * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. D.Rolland SHALL NOT BE
- * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
- * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL D.Rolland
- * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
- * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
- * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
- * OR INABILITY TO USE SOFTWARE, EVEN IF D.Rolland HAS BEEN ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGES.
- *
- * You acknowledge that Software is not designed,licensed or intended for use in
- * the design, construction, operation or maintenance of any nuclear facility.
- */
- import javax.swing.JSplitPane;
- import javax.swing.JList;
- import javax.swing.JButton;
-
- import java.awt.dnd.*;
-
- import java.awt.BorderLayout;
-
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
-
- import sun.net.www.MimeEntry;
-
- import java.beans.PropertyVetoException;
-
- /* infodavid */
- import com.infodavid.lang.LanguageObject;
- import com.infodavid.lang.Language;
-
- import com.infodavid.gui.events.ActionToChangeListener;
- import com.infodavid.gui.events.ActionToDropListener;
- /**
- * Title:
- * Description:
- * Copyright: Copyright (c) 2001
- * Company: David Rolland, infodavid@chez.com
- * @author David Rolland, infodavid@chez.com
- * @version 0.2
- */
- public class SelectionListsPanel extends AbstractPanel {
- private class DefaultGlobalListTargetListener extends ActionToDropListener {
- public DefaultGlobalListTargetListener(ActionListener al) { super(al); }
-
- public boolean isDragAcceptable(DropTargetEvent e) {
- return (adding || removing) && isEnabled();
- }
-
- public boolean isDropAcceptable(DropTargetEvent e) {
- return adding && isEnabled();
- }
-
- public void dragEnter(DropTargetDragEvent e) {
- removing = false;
-
- if (!isDragAcceptable(e)) {
- e.rejectDrag();
- }
- }
-
- public void dragExit(DropTargetEvent e) {
- if (adding) {
- adding = false;
- }
- else {
- removing = true;
- }
- }
-
- public void drop(DropTargetDropEvent e) {
- if (!isDropAcceptable(e)) {
- e.rejectDrop();
- }
- else {
- e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
-
- super.drop(e);
-
- adding = false;
-
- e.dropComplete(true);
- }
- }
- }
-
- private class DefaultSelectionListTargetListener extends ActionToDropListener {
- public DefaultSelectionListTargetListener(ActionListener al) { super(al); }
-
- public boolean isDragAcceptable(DropTargetEvent e) {
- return (adding || removing) && isEnabled();
- }
-
- public boolean isDropAcceptable(DropTargetEvent e) {
- return removing && isEnabled();
- }
-
- public void dragEnter(DropTargetDragEvent e) {
- adding = false;
-
- if (!isDragAcceptable(e)) {
- e.rejectDrag();
- }
- }
-
- public void dragExit(DropTargetEvent e) {
- if (removing) {
- removing = false;
- }
- else {
- adding = true;
- }
- }
-
- public void drop(DropTargetDropEvent e) {
- if (!isDropAcceptable(e)) {
- e.rejectDrop();
- }
- else {
- e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
-
- super.drop(e);
-
- removing = false;
-
- e.dropComplete(true);
- }
- }
- }
-
- private ListPanel selectionPanel = null;
- private ListPanel globalPanel = null;
- private JButton add = null;
- private JButton remove = null;
- private boolean removing = false;
- private boolean adding = false;
-
- /**
- * Constructeur
- *
- * @param Language Dictionnaire
- * @param int Orientation
- * @exception PropertyVetoException Exception liée à la validité du dictionnaire
- */
- public SelectionListsPanel(Language lang, int orientation) throws PropertyVetoException {
- if (lang == null) {
- throw new IllegalArgumentException(getClass().getName() +
- "." + getClass().getName() + "(Language)");
- }
-
- initializePanel(lang, orientation);
- }
-
- /**
- * Non disponible
- *
- * @exception IllegalAccessError Exception liée a la non implementation
- */
- public MimeEntry[] getMimeType() {
- throw new IllegalAccessError(getClass().getName() +
- ".getMimeType(), not used !");
- }
-
- public ListPanel getSelectionPanel() { return selectionPanel; }
-
- public JList getSelectionList() { return getSelectionPanel().getList(); }
-
- public JList getGlobalList() { return getGlobalPanel().getList(); }
-
- public ListPanel getGlobalPanel() { return globalPanel; }
-
- private void initializePanel(Language language, int orientation)
- throws PropertyVetoException {
-
- LanguageObject lang = null;
-
- selectionPanel = new ListPanel();
- remove = new JButton();
- lang = language.get("Remove", remove);
- selectionPanel.getContentPanel().add(remove, BorderLayout.SOUTH);
-
- globalPanel = new ListPanel();
- add = new JButton();
- lang = language.get("Add", add);
- globalPanel.getContentPanel().add(add, BorderLayout.SOUTH);
-
- JSplitPane splitPane = new JSplitPane(
- orientation,
- selectionPanel.getContentPanel(),
- globalPanel.getContentPanel()
- );
-
- splitPane.setContinuousLayout(true);
- splitPane.setDoubleBuffered(true);
- splitPane.setOneTouchExpandable(true);
-
- setContentComponent(splitPane);
- }
-
- public void addActionListener(ActionListener l) {
- super.addActionListener(l);
-
- selectionPanel.addActionListener(l);
- globalPanel.addActionListener(l);
-
- add.addActionListener(l);
- remove.addActionListener(l);
-
- JList list = (JList)selectionPanel.getContentComponent();
- list.setDragEnabled(true);
- list.setDropTarget(
- new DropTarget(
- list,
- new DefaultSelectionListTargetListener(l)
- )
- );
-
- list = (JList)globalPanel.getContentComponent();
- list.setDragEnabled(true);
- list.setDropTarget(
- new DropTarget(
- list,
- new DefaultGlobalListTargetListener(l)
- )
- );
- }
-
- public void removeActionListener(ActionListener l) {
- super.removeActionListener(l);
-
- add.removeActionListener(l);
- remove.removeActionListener(l);
-
- selectionPanel.removeActionListener(l);
- globalPanel.removeActionListener(l);
-
- JList list = (JList)selectionPanel.getContentComponent();
- list.setDropTarget(null);
-
- list = (JList)globalPanel.getContentComponent();
- list.setDropTarget(null);
- }
-
- public static void main(String[] args) {
- try {
- javax.swing.JFrame f = new javax.swing.JFrame();
- SelectionListsPanel p = new SelectionListsPanel(new Language(), JSplitPane.HORIZONTAL_SPLIT);
-
- p.setTitle("Test");
- p.getGlobalPanel().setTitle("Global");
- p.getSelectionPanel().setTitle("Selection");
-
-
-
- p.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.out.println(e);
- }
- });
-
- JList list = p.getGlobalList();
- list.setListData(new String[] { "item1" });
-
- list = p.getSelectionList();
- list.setListData(new String[] { "item2", "item3" });
-
- f.getContentPane().add(p.getContentPanel());
- f.pack();
- f.show();
- } catch (Exception e) { e.printStackTrace(); }
- }
- }
package com.infodavid.gui;
/*
* Copyright (c) 2001 David Rolland
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* -Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* -Redistribution in binary form must reproduct the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
* IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
* NON-INFRINGEMENT, ARE HEREBY EXCLUDED. D.Rolland SHALL NOT BE
* LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL D.Rolland
* BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
* INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
* CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
* OR INABILITY TO USE SOFTWARE, EVEN IF D.Rolland HAS BEEN ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that Software is not designed,licensed or intended for use in
* the design, construction, operation or maintenance of any nuclear facility.
*/
import javax.swing.JSplitPane;
import javax.swing.JList;
import javax.swing.JButton;
import java.awt.dnd.*;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import sun.net.www.MimeEntry;
import java.beans.PropertyVetoException;
/* infodavid */
import com.infodavid.lang.LanguageObject;
import com.infodavid.lang.Language;
import com.infodavid.gui.events.ActionToChangeListener;
import com.infodavid.gui.events.ActionToDropListener;
/**
* Title:
* Description:
* Copyright: Copyright (c) 2001
* Company: David Rolland, infodavid@chez.com
* @author David Rolland, infodavid@chez.com
* @version 0.2
*/
public class SelectionListsPanel extends AbstractPanel {
private class DefaultGlobalListTargetListener extends ActionToDropListener {
public DefaultGlobalListTargetListener(ActionListener al) { super(al); }
public boolean isDragAcceptable(DropTargetEvent e) {
return (adding || removing) && isEnabled();
}
public boolean isDropAcceptable(DropTargetEvent e) {
return adding && isEnabled();
}
public void dragEnter(DropTargetDragEvent e) {
removing = false;
if (!isDragAcceptable(e)) {
e.rejectDrag();
}
}
public void dragExit(DropTargetEvent e) {
if (adding) {
adding = false;
}
else {
removing = true;
}
}
public void drop(DropTargetDropEvent e) {
if (!isDropAcceptable(e)) {
e.rejectDrop();
}
else {
e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
super.drop(e);
adding = false;
e.dropComplete(true);
}
}
}
private class DefaultSelectionListTargetListener extends ActionToDropListener {
public DefaultSelectionListTargetListener(ActionListener al) { super(al); }
public boolean isDragAcceptable(DropTargetEvent e) {
return (adding || removing) && isEnabled();
}
public boolean isDropAcceptable(DropTargetEvent e) {
return removing && isEnabled();
}
public void dragEnter(DropTargetDragEvent e) {
adding = false;
if (!isDragAcceptable(e)) {
e.rejectDrag();
}
}
public void dragExit(DropTargetEvent e) {
if (removing) {
removing = false;
}
else {
adding = true;
}
}
public void drop(DropTargetDropEvent e) {
if (!isDropAcceptable(e)) {
e.rejectDrop();
}
else {
e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
super.drop(e);
removing = false;
e.dropComplete(true);
}
}
}
private ListPanel selectionPanel = null;
private ListPanel globalPanel = null;
private JButton add = null;
private JButton remove = null;
private boolean removing = false;
private boolean adding = false;
/**
* Constructeur
*
* @param Language Dictionnaire
* @param int Orientation
* @exception PropertyVetoException Exception liée à la validité du dictionnaire
*/
public SelectionListsPanel(Language lang, int orientation) throws PropertyVetoException {
if (lang == null) {
throw new IllegalArgumentException(getClass().getName() +
"." + getClass().getName() + "(Language)");
}
initializePanel(lang, orientation);
}
/**
* Non disponible
*
* @exception IllegalAccessError Exception liée a la non implementation
*/
public MimeEntry[] getMimeType() {
throw new IllegalAccessError(getClass().getName() +
".getMimeType(), not used !");
}
public ListPanel getSelectionPanel() { return selectionPanel; }
public JList getSelectionList() { return getSelectionPanel().getList(); }
public JList getGlobalList() { return getGlobalPanel().getList(); }
public ListPanel getGlobalPanel() { return globalPanel; }
private void initializePanel(Language language, int orientation)
throws PropertyVetoException {
LanguageObject lang = null;
selectionPanel = new ListPanel();
remove = new JButton();
lang = language.get("Remove", remove);
selectionPanel.getContentPanel().add(remove, BorderLayout.SOUTH);
globalPanel = new ListPanel();
add = new JButton();
lang = language.get("Add", add);
globalPanel.getContentPanel().add(add, BorderLayout.SOUTH);
JSplitPane splitPane = new JSplitPane(
orientation,
selectionPanel.getContentPanel(),
globalPanel.getContentPanel()
);
splitPane.setContinuousLayout(true);
splitPane.setDoubleBuffered(true);
splitPane.setOneTouchExpandable(true);
setContentComponent(splitPane);
}
public void addActionListener(ActionListener l) {
super.addActionListener(l);
selectionPanel.addActionListener(l);
globalPanel.addActionListener(l);
add.addActionListener(l);
remove.addActionListener(l);
JList list = (JList)selectionPanel.getContentComponent();
list.setDragEnabled(true);
list.setDropTarget(
new DropTarget(
list,
new DefaultSelectionListTargetListener(l)
)
);
list = (JList)globalPanel.getContentComponent();
list.setDragEnabled(true);
list.setDropTarget(
new DropTarget(
list,
new DefaultGlobalListTargetListener(l)
)
);
}
public void removeActionListener(ActionListener l) {
super.removeActionListener(l);
add.removeActionListener(l);
remove.removeActionListener(l);
selectionPanel.removeActionListener(l);
globalPanel.removeActionListener(l);
JList list = (JList)selectionPanel.getContentComponent();
list.setDropTarget(null);
list = (JList)globalPanel.getContentComponent();
list.setDropTarget(null);
}
public static void main(String[] args) {
try {
javax.swing.JFrame f = new javax.swing.JFrame();
SelectionListsPanel p = new SelectionListsPanel(new Language(), JSplitPane.HORIZONTAL_SPLIT);
p.setTitle("Test");
p.getGlobalPanel().setTitle("Global");
p.getSelectionPanel().setTitle("Selection");
p.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println(e);
}
});
JList list = p.getGlobalList();
list.setListData(new String[] { "item1" });
list = p.getSelectionList();
list.setListData(new String[] { "item2", "item3" });
f.getContentPane().add(p.getContentPanel());
f.pack();
f.show();
} catch (Exception e) { e.printStackTrace(); }
}
}
Conclusion
Tester le main...
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
JList et selection [ par tof008 ]
Bonjour à tous!J'ai un problème qui me bloque depuis quelques heures : Je veux pouvoir selectionner un element d'une JList, mais a chaque fois que je
Jlist selection [ par scaryman ]
bonour je voudrais savoir comment désactiver la selection d'une entrée de JList par appui sur une touche du clavier. Merci ++
evenement après selection dans une jlist [ par bygui ]
Bonjour,voila j'aimerais appelé une methode à chaque fois que l'utilisateur selectionne un element d'une liste.Je dois san
Une JList de JPanel [ par frater_sinister ]
Bonjour,J'ai un petit soucis avec les Jlist. J'arriver a les manipuler avec des elements String mais pas avec des éléments JPanel. Mon code source:imp
Problème de JList [ par GillesWebmaster ]
Bonsoir ,J'ai un problème de JList: je crées une JList sans aucun problème mais je n'arrive pas 
Annuler une sélection [ par jarod34 ]
Bonjour, J'ai un Jpanel dans lequel j'affiche des miniatures. Je peut les selectionner pour les renommers. Mon problème c'est qu'une fois séléction
Désactiver selection jList [ par tototitanium ]
Bonjour, J'aimerais désactiver la sélection d'un élément d'un jlist mais sans griser la zone. Le problème c'est qu'en utilisant jListTest.setEnabled(
problème d'ajouter une ligne sur jtable [ par ulysse00 ]
salut tout le monde j'ai un problème avec jtable je n'arrive pas à ajouter des nouveaux enregistremnt sur jtable pour mieux comprendre j'ai une table
rotation image java [ par marwa77 ]
bnj, je suis débutante en java. mon interface graphique contient un JPanel où j'affiche une image dans un JLabel intégré dans ce JPanel.cette image ap
Enregistrement dans une base de données Acces à partir de jList et jTextField [ par oussamatel ]
[color=blue]salut à tous,[/color] j'ai presque fini le travail que j'ai a faire, un petit truc me dérange encore. alors, je veux enregistrer dans un
|
Derniers Blogs
[FRAMEWORK 4] LES TASKS ET LE THREAD UI[FRAMEWORK 4] LES TASKS ET LE THREAD UI par fathi
Je viens de passer quelques temps au TechDay's et j'ai pu voir pas mal de session intéressante. Par contre une chose m'a un peu étonné lors de certaines de ces sessions qui abordaient les améliorations du framework .NET (donc le 4.5) : en gros, bea...
Cliquez pour lire la suite de l'article par fathi WORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBEWORKFLOW FOUNDATION 3 A UN PIED DANS LA TOMBE par JeremyJeanson
Depuis déjà un an, je conseille vivement les utilisateurs de Workflow Foundation 3 à migrer vers la version 4. L'information qui va suivre ne devrait donc pas trop prendre au dépourvu les personnes qui m'ont suivi. Je profite de ce poste, pour faire le re...
Cliquez pour lire la suite de l'article par JeremyJeanson TECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PCTECHDAYS PARIS 2012 : NOUVELLES TENDANCES DU POSTE DE TRAVAIL - BRING YOUR OWN PC par ROMELARD Fabrice
Speakers: Thierry Rapatout, Antoine Petit et Xavier Trebbia Cette session entre dans le cadre des RDV Décideurs des TechDays 2012, elle est liée à la consumérisation de l'IT et la mise en place du "DeskTop as a Service" dans de plus en ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLETECHDAYS PARIS 2012 : SYSTEM CENTER SERVICE MANAGER 2012 VUE D'ENSEMBLE par ROMELARD Fabrice
Speakers: Julien Marechal, Gautier Confiant, Sébastien MEYER La session débute par le positionnement de la solution System Center par rapport aux concepts d'organisation ITIL. Le portail du catalogue de se...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE SECOND JOURTECHDAYS PARIS 2012 : PLEINIèRE SECOND JOUR par ROMELARD Fabrice
Après une première journée dédiée aux développeurs, cette seconde journée est dédiée au monde des entreprises et de ses applications. Ainsi, cette pleinière est dédiée à faire un 360 de l'évolution des applications Business aux demandes ac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
RE : SQLRE : SQL par Julien39
Cliquez pour lire la suite par Julien39
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|