Re: Comment trapper un evenement MouseEvent issu de javax.swing.plaf.basic.BasicTableUI$Handler
On 21 oct, 02:15, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
On Sat, 20 Oct 2007 12:51:47 -0700, philippe.bod...@videotron.ca
Here is a translation based on my high school French and Babelfish..
Please take it with a large grain of salt:
Bonjour,
Dans un cas particulier , apres un clic dans une cellule g=E9r=E9e par
JTable , j'ai une exception issu du
handler de la table .
J'aimerai pourvoir etre capable de trapper cet evenement avant qu'il
soit pris en compte par le handler de la table
Good day.
In one particular case, after I click in a cell managed by JTable, I
am getting an exception originating in the JTable handler. I would
like to be able to intercept the event before it reaches the JTable
handler.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(Unknown
Source)
at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown
Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown
Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
ci joint le source de la classe JTableModule qui gere la table
J'esperai trapper l'=E9v=E8nement via un MouseHandler que je rajoute =E0=
ma
classe JTableModule .
Je le traite mais cependant malgr=E9 le dispose() , il est quand meme
pris en compte par le BasicTableUI$Handler
D'ou ma probl=E9matique .
Trapper cet =E9v=E8nement pour identifier pourquoi la source est invalide
avant qu,il soit pris en compte par BasicTableUI$Handler
Merci
Here is the source for the JTableModule class which control the table.
I hope it will intercept the event via a MouseHandler that I add
with my JTableModule class. I treat? it but however in spite of the
dispose(), it behaves the same way by BasicTableUI$Handler. It is
important to intercept this event to identify why the source is
invalid, before it is processed by BasicTableUI$Handler
Thanks
package terri.gui.table;
/*
@(#)JTableModule.java 1.17 07/10/26
*
*/
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import javax.swing.plaf.basic.BasicTableUI;
import terri.InvokerUI;
import terri.entities.*;
import terri.gui.MessageWindow;
import terri.managers.file.*;
import terri.utilities.*;
import java.lang.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.awt.event.*;
import java.awt.*;
import java.beans.*;
public class JTableModule extends JTable {
JScrollPane scrollPane;
TableColumn tableColumn0;
final int columnWidth0 = 30;
Logger logger;
JTableModule jTableModule;
TableColumnModel tableColumnModel;
MouseListener[] mls;
class MyTableUI extends BasicTableUI {
public MouseInputListener createMouseInputListener() {
return mouseHandler;
}
}
MyTableUI myTableUI;
class MouseHandler extends MouseInputAdapter {
public void mousePressed(MouseEvent e) {
logger.log(Level.INFO,"source =" + e.getSource().t=
oString());
if (!e.getComponent().isValid()) {
logger.log(Level.INFO,"Component Source invalid, evt
consumed");
e.consume();
}
else
super.mousePressed(e);
logger.log(Level.INFO,"Mouse pressed (# of clicks: "
+ e.getClickCount() + ")");
}
public void mouseReleased(MouseEvent e) {
logger.log(Level.INFO,"source =" + e.getSource().t=
oString());
if (!e.getComponent().isValid()) {
logger.log(Level.INFO,"Component Source invalide, evt
consumed");
e.consume();
}
else
super.mouseReleased(e);
logger.log(Level.INFO,"Mouse released (# of clicks: "
+ e.getClickCount() + ")");
}
}
MouseHandler mouseHandler;
class ListSelectionModelTableModule extends DefaultListSelectionModel
{
public boolean isSelectedIndex(int index) {
boolean result;
result=super.isSelectedIndex(index);
if (listSelectionColumnModel.getAnchorSelectionIndex=
() != 0) {
result=false;
}
// logger.log(Level.INFO,"isSelected (" + index + ") result ==
" +
result);
return result;
}
}
ListSelectionModelTableModule listSelectionRowModelTableModule;
ListSelectionModel listSelectionColumnModel;
//Default cell editor
DefaultCellEditor cellEditor = new DefaultCellEditor(new
JTextField()) {
public void cancelCellEditing() {
logger.log(Level.INFO,"cancel editing");
super.cancelCellEditing();
}
public boolean stopCellEditing() {
logger.log(Level.INFO,"stop editing");
return super.stopCellEditing();
}
public Component getTableCellEditorComponent(JTable table, O=
bject
value, boolean isSelected, int row, int column){
logger.log(Level.INFO,"getTableCellEditorComponent w=
ith value : " +
value + " row :" + row + " column :" + column);
return super.getTableCellEditorComponent(table, valu=
e, isSelected,
row,column);
}
};
// Cell renderer used by column 0 with specifics background and
foreground colors.
DefaultTableCellRenderer col0Renderer =
new DefaultTableCellRenderer() {
Color beige = new Color(245, 245, 220);
public void setValue(Object value) {
setBackground(beige);
setForeground(Color.black);
super.setValue(value);
}
};
public JTableModule(AbstractTableModel dataModel) {
int indexMouseListener;
//logger
logger= Logger.getLogger("terri.gui.table.JTableModule");
//set the common log file handler
logger.addHandler(InvokerUI.getCommonLogFileHandler());
//initialize the list , index of the model
logger.log(Level.INFO,"new JTableModule");
//Affect the tableModel
setModel(dataModel);
logger.log(Level.INFO,"setModel");
//Column0 specifications
specifyColumn0();
logger.log(Level.INFO,"specifyColumn0");
//specific editor
//this.setCellEditor(cellEditor);
putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
logger.log(Level.INFO,"putClientProperty");
//list selection model for excel selection row behavior
jTableModule=this;
tableColumnModel=this.getColumnModel();
listSelectionColumnModel=tableColumnModel.getSelectionModel();
listSelectionRowModelTableModule= new
ListSelectionModelTableModule();
this.setSelectionModel(listSelectionRowModelTableModule);
//selection behavior
this.setRowSelectionAllowed(true);
this.setCellSelectionEnabled(true);
this.setColumnSelectionAllowed(false);
//mouse Handler for TableUI
//mouseHandler=new MouseHandler();
//this.setUI(myTableUI);
//trap mouse events for debugging
/*
mouseHandler=new MouseHandler();
mls = (MouseListener[])
(this.getListeners(MouseListener.class));
for (indexMouseListener=0;indexMouseListener<
mls.length;indexMouseListener++)
this.removeMouseListener(mls[indexMouseListener]);
this.addMouseListener(mouseHandler);
*/
// Affect a scrollPane
scrollPane = new JScrollPane(this);
logger.log(Level.INFO,"fin new JTableModule");
};
public JScrollPane getScrollPane() { return scrollPane; }
//render specifications for column 0
private void specifyColumn0() {
// max size and not resizable with gray color
tableColumn0= this.getColumn(" ");
tableColumn0.setMaxWidth(columnWidth0);
tableColumn0.setResizable(false);
tableColumn0.setCellRenderer(col0Renderer);
}
//special views behaviours to add
public void tableChanged(TableModelEvent e ) {
super.tableChanged(e);
}
}
--
Roedy Green Canadian Mind Products
The Java Glossaryhttp://mindprod.com- Masquer le texte des messages pr=E9=
c=E9dents -
- Afficher le texte des messages pr=E9c=E9dents -- Masquer le texte des m=
essages pr=E9c=E9dents -
- Afficher le texte des messages pr=E9c=E9dents -
Thank you very much Roedy for you translation
It explains very well my needs
I am waiting now for any idea to solve my problem
bye
Philip