Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Comment trapper un evenement MouseEvent issu de javax.swing.plaf.basic.BasicTableUI$Handler

Thread view: 
philippe.bodard@videotron.ca - 20 Oct 2007 20:51 GMT
Bonjour,
Dans un cas particulier , apres un clic dans une cellule gérée 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

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'évènement via un MouseHandler que je rajoute à ma
classe JTableModule .
Je le traite mais cependant malgré le dispose() , il est quand meme
pris en compte par le BasicTableUI$Handler
D'ou ma problématique .
Trapper cet évènement pour identifier pourquoi la source est invalide
avant qu,il soit pris en compte par BasicTableUI$Handler

Merci

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().toString());
            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().toString());
            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, Object
value, boolean isSelected, int row, int column){
            logger.log(Level.INFO,"getTableCellEditorComponent with value : " +
value + " row :" + row + " column :" + column);
            return super.getTableCellEditorComponent(table, value, 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 - 21 Oct 2007 07:15 GMT
On Sat, 20 Oct 2007 12:51:47 -0700, philippe.bodard@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érée 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
[quoted text clipped - 33 lines]
>
>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;
>
[quoted text clipped - 217 lines]
>
>}
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

philippe.bodard@videotron.ca - 21 Oct 2007 15:10 GMT
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
>
[quoted text clipped - 291 lines]
>
> - Afficher le texte des messages précédents -

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
Sabine Dinis Blochberger - 22 Oct 2007 12:40 GMT
> On Sat, 20 Oct 2007 12:51:47 -0700, philippe.bodard@videotron.ca
>
[quoted text clipped - 14 lines]
> like to be able to intercept the event  before it reaches the JTable
> handler.

You can use e.consume() to stop it bubbling up through the component
hierarchy after you're done with it.
Signature

Sabine Dinis Blochberger

Op3racional
www.op3racional.eu

philippe.bodard@videotron.ca - 25 Oct 2007 02:26 GMT
On 22 oct, 07:40, Sabine Dinis Blochberger <no.s...@here.invalid>
wrote:
> > On Sat, 20 Oct 2007 12:51:47 -0700, philippe.bod...@videotron.ca
>
[quoted text clipped - 23 lines]
>
> - Afficher le texte des messages précédents -

despite the fact that i have consumed the event , it is processed by
the AWTEventMulticaster of the BasicTableUI.
I have not found a way to cath this wrong MouseEvent in the
BasicTableUI.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.