From: <de...@us...> - 2012-07-18 15:37:18
|
Revision: 7509 http://fudaa.svn.sourceforge.net/fudaa/?rev=7509&view=rev Author: deniger Date: 2012-07-18 15:37:07 +0000 (Wed, 18 Jul 2012) Log Message: ----------- ajout m?\195?\169thode utilitaires Modified Paths: -------------- trunk/framework/ctulu-bu/src/main/java/com/memoire/bu/BuTable.java trunk/framework/ctulu-ui/src/main/java/org/fudaa/ctulu/gui/ActionTransferSource.java trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGTableGraphePanel.java Modified: trunk/framework/ctulu-bu/src/main/java/com/memoire/bu/BuTable.java =================================================================== --- trunk/framework/ctulu-bu/src/main/java/com/memoire/bu/BuTable.java 2012-07-18 15:21:48 UTC (rev 7508) +++ trunk/framework/ctulu-bu/src/main/java/com/memoire/bu/BuTable.java 2012-07-18 15:37:07 UTC (rev 7509) @@ -1,14 +1,10 @@ /** - * @modification $Date: 2006-09-19 14:35:10 $ - * @statut unstable - * @file BuTable.java - * @version 0.43 - * @author Guillaume Desnoix - * @email gui...@de... - * @license GNU General Public License 2 (GPL2) - * @copyright 1998-2005 Guillaume Desnoix + * @modification $Date: 2006-09-19 14:35:10 $ @statut unstable @file BuTable.java + * + * @version 0.43 + * @author Guillaume Desnoix @email gui...@de... @license GNU General Public License 2 (GPL2) @copyright + * 1998-2005 Guillaume Desnoix */ - package com.memoire.bu; import java.awt.Graphics; @@ -28,166 +24,148 @@ /** * Similar to JTable but add copy/select operations and row headers. + * * @see javax.swing.JTable */ public class BuTable - extends JTable - implements ClipboardOwner -{ - public BuTable() - { + extends JTable + implements ClipboardOwner { + + public BuTable() { this(null); } - public BuTable(TableModel _model) - { + public BuTable(TableModel _model) { super(_model); // if(FuLib.jdk()>=1.4) // { - setFocusCycleRoot(false); + setFocusCycleRoot(false); // } } - public BuTable(Object[][] _values, Object[] _names) - { - this(new BuTableStaticModel(_values,_names)); + public BuTable(Object[][] _values, Object[] _names) { + this(new BuTableStaticModel(_values, _names)); } - public boolean isFocusCycleRoot() - { + public boolean isFocusCycleRoot() { return false; } // Columns - - public void hideColumn(int _indexInModel) - { - Object o=getTableHeader(); - if(o instanceof BuTableColumnHeader) - ((BuTableColumnHeader)o).hideColumn - (getColumnModel().getColumn(_indexInModel)); + public void hideColumn(int _indexInModel) { + Object o = getTableHeader(); + if (o instanceof BuTableColumnHeader) { + ((BuTableColumnHeader) o).hideColumn(getColumnModel().getColumn(_indexInModel)); + } } - public void showColumn(int _indexInModel) - { - Object o=getTableHeader(); - if(o instanceof BuTableColumnHeader) - ((BuTableColumnHeader)o).showColumn - (getColumnModel().getColumn(_indexInModel)); + public void showColumn(int _indexInModel) { + Object o = getTableHeader(); + if (o instanceof BuTableColumnHeader) { + ((BuTableColumnHeader) o).showColumn(getColumnModel().getColumn(_indexInModel)); + } } - public void adjustColumnWidth(int _indexInModel) - { - Object o=getTableHeader(); - if(o instanceof BuTableColumnHeader) - ((BuTableColumnHeader)o).adjustWidth - (getColumnModel().getColumn(_indexInModel)); + public void adjustColumnWidth(int _indexInModel) { + Object o = getTableHeader(); + if (o instanceof BuTableColumnHeader) { + ((BuTableColumnHeader) o).adjustWidth(getColumnModel().getColumn(_indexInModel)); + } } - public void adjustVisibleColumns() - { - Object o=getTableHeader(); - if(o instanceof BuTableColumnHeader) - { - TableColumnModel m=getColumnModel(); - for(int i=m.getColumnCount()-1;i>=0;i--) - ((BuTableColumnHeader)o).adjustWidth(m.getColumn(i)); + public void adjustVisibleColumns() { + Object o = getTableHeader(); + if (o instanceof BuTableColumnHeader) { + TableColumnModel m = getColumnModel(); + for (int i = m.getColumnCount() - 1; i >= 0; i--) { + ((BuTableColumnHeader) o).adjustWidth(m.getColumn(i)); + } } } // Anti-aliasing - - public void paint(Graphics _g) - { - BuLib.setAntialiasing(this,_g); + public void paint(Graphics _g) { + BuLib.setAntialiasing(this, _g); super.paint(_g); } /* - public void setTableData(Object[][] _values, Object[] _names) - { - setModel(new BuTableStaticModel(_values,_names)); - } - */ + * public void setTableData(Object[][] _values, Object[] _names) { setModel(new BuTableStaticModel(_values,_names)); } + */ + private static final TableCellRenderer tcr_ = new BuTableCellRenderer(); - private static final TableCellRenderer tcr_=new BuTableCellRenderer(); - - public TableCellRenderer getDefaultRenderer(Class _columnClass) - { + public TableCellRenderer getDefaultRenderer(Class _columnClass) { return tcr_; } - public Object[][] getAllValues() - { - int nr =getRowCount(); - int nc =getColumnCount(); + public Object[][] getAllValues() { + int nr = getRowCount(); + int nc = getColumnCount(); - Object[][] r=new Object[nr][nc]; + Object[][] r = new Object[nr][nc]; - int i,j; - for(i=0;i<nr;i++) - for(j=0;j<nc;j++) - r[i][j]=getValueAt(i,j); + int i, j; + for (i = 0; i < nr; i++) { + for (j = 0; j < nc; j++) { + r[i][j] = getValueAt(i, j); + } + } return r; } - public Object[][] getSelectedValues() - { - int[] sr =getSelectedRows(); - int[] sc =getColumnModel().getSelectedColumns(); - boolean rsa=getRowSelectionAllowed(); - boolean csa=getColumnSelectionAllowed(); + public Object[][] getSelectedValues() { + int[] sr = getSelectedRows(); + int[] sc = getColumnModel().getSelectedColumns(); + boolean rsa = getRowSelectionAllowed(); + boolean csa = getColumnSelectionAllowed(); - Object[][] r=new Object[rsa ? sr.length : getRowCount()] - [csa ? sc.length : getColumnCount()]; + Object[][] r = new Object[rsa ? sr.length : getRowCount()][csa ? sc.length : getColumnCount()]; - int i,j; - for(i=0;i<r.length;i++) - for(j=0;j<r[i].length;j++) - r[i][j]=getValueAt(rsa ? sr[i] : i, csa ? sc[j] : j); + int i, j; + for (i = 0; i < r.length; i++) { + for (j = 0; j < r[i].length; j++) { + r[i][j] = getValueAt(rsa ? sr[i] : i, csa ? sc[j] : j); + } + } return r; } - public String[] getSelectedColumnNames() - { - int[] sc=getColumnModel().getSelectedColumns(); + public String[] getSelectedColumnNames() { + int[] sc = getColumnModel().getSelectedColumns(); - String[] r=new String[sc.length]; - for(int i=0;i<sc.length;i++) - r[i]=getColumnName(sc[i]); + String[] r = new String[sc.length]; + for (int i = 0; i < sc.length; i++) { + r[i] = getColumnName(sc[i]); + } return r; } - public void lostOwnership(Clipboard clipboard, Transferable contents) - { + public void lostOwnership(Clipboard clipboard, Transferable contents) { } - public String convertAllValues(String _separator) - { - return convert0(getAllValues(),_separator); + public String convertAllValues(String _separator) { + return convert0(getAllValues(), _separator); } - public String convertSelectedValues(String _separator) - { - return convert0(getSelectedValues(),_separator); + public String convertSelectedValues(String _separator) { + return convert0(getSelectedValues(), _separator); } - private String convert0(Object[][] _values,String _separator) - { - int l=_values.length; - StringBuffer r=new StringBuffer(l*40); + private String convert0(Object[][] _values, String _separator) { + int l = _values.length; + StringBuffer r = new StringBuffer(l * 40); - for(int i=0;i<l;i++) - { - for(int j=0;j<_values[i].length;j++) - { - if(j!=0) - r.append(_separator); - if(_values[i][j]!=null) - r.append(_values[i][j].toString()); + for (int i = 0; i < l; i++) { + for (int j = 0; j < _values[i].length; j++) { + if (j != 0) { + r.append(_separator); + } + if (_values[i][j] != null) { + r.append(_values[i][j].toString()); + } } r.append('\n'); } @@ -195,176 +173,104 @@ return r.toString(); } - public void copy() - { - Object[][] values=getSelectedValues(); - if((values==null)||(values.length==0)) - values=getAllValues(); + public Transferable createTransferable() { + Object[][] values = getSelectedValues(); + if ((values == null) || (values.length == 0)) { + values = getAllValues(); + } - String r=convert0(values,"\t"); + String r = convert0(values, "\t"); - if(!r.equals("")) - { - Clipboard clipboard=getToolkit().getSystemClipboard(); - StringSelection contents=new StringSelection(r); - clipboard.setContents(contents,this); + if (!r.equals("")) { + return new StringSelection(r); } + return null; } - public void select() - { - if(getColumnSelectionAllowed()&&getRowCount()>0) - setColumnSelectionInterval(0,getColumnCount()-1); - if(getRowSelectionAllowed()&&(getRowCount()>0)) - setRowSelectionInterval(0,getRowCount()-1); + public void copy() { + Transferable contents = createTransferable(); + if (contents != null) { + Clipboard clipboard = getToolkit().getSystemClipboard(); + clipboard.setContents(contents, this); + } } - public JList buildRowHeaders(boolean _letters) - { + public void select() { + if (getColumnSelectionAllowed() && getRowCount() > 0) { + setColumnSelectionInterval(0, getColumnCount() - 1); + } + if (getRowSelectionAllowed() && (getRowCount() > 0)) { + setRowSelectionInterval(0, getRowCount() - 1); + } + } + + public JList buildRowHeaders(boolean _letters) { /* - JList r=new JList - (new AbstractListModel() - { - public int getSize() { return getModel().getRowCount(); } - public Object getElementAt(int index) { return null; } - }); - r.setFixedCellWidth(40); - r.setFixedCellHeight(getRowHeight()+ - getIntercellSpacing().height); - r.setCellRenderer(new BuTableRowHeaderRenderer(this,_letters)); - r.setRequestFocusEnabled(false); - return r; - */ - return new BuTableRowHeader(this,_letters); + * JList r=new JList (new AbstractListModel() { public int getSize() { return getModel().getRowCount(); } public + * Object getElementAt(int index) { return null; } }); r.setFixedCellWidth(40); r.setFixedCellHeight(getRowHeight()+ + * getIntercellSpacing().height); r.setCellRenderer(new BuTableRowHeaderRenderer(this,_letters)); + * r.setRequestFocusEnabled(false); return r; + */ + return new BuTableRowHeader(this, _letters); } - public void addRowHeaders(JScrollPane _pane, boolean _letters) - { + public void addRowHeaders(JScrollPane _pane, boolean _letters) { _pane.setRowHeaderView(buildRowHeaders(_letters)); } - protected JTableHeader createDefaultTableHeader() - { + protected JTableHeader createDefaultTableHeader() { return new BuTableColumnHeader(columnModel); } - public void addColumn(TableColumn _column) - { + public void addColumn(TableColumn _column) { _column.setMinWidth(0); super.addColumn(_column); } /* - return new JTableHeader(columnModel) - { - public void paintComponent(Graphics _g) - { - BuLib.setAntialiasing(this,_g); - super.paintComponent(_g); + * return new JTableHeader(columnModel) { public void paintComponent(Graphics _g) { BuLib.setAntialiasing(this,_g); + * super.paintComponent(_g); + * + * JTable t=getTable(); if((t!=null)&&(t.getModel() instanceof BuTableSortModel)) { BuTableSortModel + * m=(BuTableSortModel)t.getModel(); Color old=_g.getColor(); int[] scs=m.getSortingColumns(); if(scs.length>0) { + * for(int j=0;j<scs.length;j++) { int c=scs[j]; if(c>=0) { String n=m.getColumnName(c); if(n!=null) { c=-1; for(int + * i=t.getColumnCount()-1;i>=0;i--) if(n.equals(t.getColumnName(i))) c=i; if(c>=0) { Rectangle r=getHeaderRect(c); + * _g.translate(r.x+r.width-10,r.y+r.height/2-3); BuLib.setColor(_g,Color.white); if(m.isAscending(c)) + * _g.fillPolygon(vbax,vbay,3); else _g.fillPolygon(vtax,vtay,3); BuLib.setColor(_g,(j==0) ? Color.black : + * Color.gray); if(m.isAscending(c)) _g.drawPolygon(vbax,vbay,3); else _g.drawPolygon(vtax,vtay,3); + * _g.translate(-(r.x+r.width-10),-(r.y+r.height/2-3)); } } } _g.setColor(old); } } } } }; } + */ - JTable t=getTable(); - if((t!=null)&&(t.getModel() instanceof BuTableSortModel)) - { - BuTableSortModel m=(BuTableSortModel)t.getModel(); - Color old=_g.getColor(); - int[] scs=m.getSortingColumns(); - if(scs.length>0) - { - for(int j=0;j<scs.length;j++) - { - int c=scs[j]; - if(c>=0) - { - String n=m.getColumnName(c); - if(n!=null) - { - c=-1; - for(int i=t.getColumnCount()-1;i>=0;i--) - if(n.equals(t.getColumnName(i))) c=i; - if(c>=0) - { - Rectangle r=getHeaderRect(c); - _g.translate(r.x+r.width-10,r.y+r.height/2-3); - BuLib.setColor(_g,Color.white); - if(m.isAscending(c)) _g.fillPolygon(vbax,vbay,3); - else _g.fillPolygon(vtax,vtay,3); - BuLib.setColor(_g,(j==0) ? Color.black : Color.gray); - if(m.isAscending(c)) _g.drawPolygon(vbax,vbay,3); - else _g.drawPolygon(vtax,vtay,3); - _g.translate(-(r.x+r.width-10),-(r.y+r.height/2-3)); - } - } - } - _g.setColor(old); - } - } - } - } - }; - } - */ - /* - public static void main(String[] _args) - { - JFrame frame=new JFrame("Test BuTable"); - - TableModel tm=new AbstractTableModel() - { - public int getRowCount() { return 101; } - //public String getColumnName(int col) { return ""+col; } - public int getColumnCount() { return 4; } - public Object getValueAt(int row, int col) - { - switch(col) - { - case 0: return FuFactoryInteger.get(row*(row%2==0 ? -row : row)); - case 1: return new String("["+row+"]"); - case 2: return FuFactoryBoolean.get(row%3==0); - case 3: return new java.util.Date(1000000*row); - } - return null; - } - }; - - - BuTableSortModel sorter=new BuTableSortModel(tm); - final BuTable tb=new BuTable(sorter); - sorter.addMouseListenerToHeaderInTable(tb); - - tb.setAutoResizeMode(tb.AUTO_RESIZE_OFF); - - tb.setColumnSelectionAllowed(true); - tb.setRowSelectionAllowed(true); - - //tb.getColumnModel().getSelectionModel(). - //setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - //tb.getSelectionModel(). - //setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - - TableCellRenderer tcr=new BuTableCellRenderer(); - for(int i=0;i<tb.getColumnCount();i++) - { - TableColumn c=tb.getColumn(tb.getColumnName(i)); - c.setCellRenderer(tcr); - } - - tb.hideColumn(2); - tb.adjustVisibleColumns(); - - JScrollPane sp=new JScrollPane(tb); - tb.addRowHeaders(sp,false); - frame.getContentPane().add(sp); - - frame.addWindowListener( new WindowAdapter() { - public void windowClosing( WindowEvent e ) { - System.err.println(tb.convertSelectedValues(",")); - System.exit(0); - } - }); - - frame.setSize(300,200); - frame.setVisible(true); - } - */ + * public static void main(String[] _args) { JFrame frame=new JFrame("Test BuTable"); + * + * TableModel tm=new AbstractTableModel() { public int getRowCount() { return 101; } //public String getColumnName(int + * col) { return ""+col; } public int getColumnCount() { return 4; } public Object getValueAt(int row, int col) { + * switch(col) { case 0: return FuFactoryInteger.get(row*(row%2==0 ? -row : row)); case 1: return new + * String("["+row+"]"); case 2: return FuFactoryBoolean.get(row%3==0); case 3: return new java.util.Date(1000000*row); + * } return null; } }; + * + * + * BuTableSortModel sorter=new BuTableSortModel(tm); final BuTable tb=new BuTable(sorter); + * sorter.addMouseListenerToHeaderInTable(tb); + * + * tb.setAutoResizeMode(tb.AUTO_RESIZE_OFF); + * + * tb.setColumnSelectionAllowed(true); tb.setRowSelectionAllowed(true); + * + * //tb.getColumnModel().getSelectionModel(). //setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + * //tb.getSelectionModel(). //setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + * + * TableCellRenderer tcr=new BuTableCellRenderer(); for(int i=0;i<tb.getColumnCount();i++) { TableColumn + * c=tb.getColumn(tb.getColumnName(i)); c.setCellRenderer(tcr); } + * + * tb.hideColumn(2); tb.adjustVisibleColumns(); + * + * JScrollPane sp=new JScrollPane(tb); tb.addRowHeaders(sp,false); frame.getContentPane().add(sp); + * + * frame.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { + * System.err.println(tb.convertSelectedValues(",")); System.exit(0); } }); + * + * frame.setSize(300,200); frame.setVisible(true); } + */ } Modified: trunk/framework/ctulu-ui/src/main/java/org/fudaa/ctulu/gui/ActionTransferSource.java =================================================================== --- trunk/framework/ctulu-ui/src/main/java/org/fudaa/ctulu/gui/ActionTransferSource.java 2012-07-18 15:21:48 UTC (rev 7508) +++ trunk/framework/ctulu-ui/src/main/java/org/fudaa/ctulu/gui/ActionTransferSource.java 2012-07-18 15:37:07 UTC (rev 7509) @@ -14,6 +14,7 @@ import javax.swing.text.JTextComponent; import com.memoire.bu.BuResource; +import javax.swing.*; import org.fudaa.ctulu.CtuluLibString; @@ -26,17 +27,16 @@ final JComponent source; final Action destAction; - /** * @param name * @param icon */ - public ActionTransferSource(final JComponent source, final String destAction,final String name,Icon icon) { + public ActionTransferSource(final JComponent source, final String destAction, final String name, Icon icon) { super(name, icon); this.source = source; this.destAction = source.getActionMap().get(destAction); super.putValue(ACTION_COMMAND_KEY, destAction); - super.putValue(SHORT_DESCRIPTION , name); + super.putValue(SHORT_DESCRIPTION, name); } protected boolean isStateEnable() { @@ -54,9 +54,15 @@ } public static boolean isSomethingToCopy(JComponent jc) { - if (jc instanceof JTextComponent) { return !CtuluLibString.isEmpty(((JTextComponent) jc).getSelectedText()); } - if (jc instanceof JTable) { return !((JTable) jc).getSelectionModel().isSelectionEmpty(); } - if (jc instanceof JTree) { return !((JTree) jc).getSelectionModel().isSelectionEmpty(); } + if (jc instanceof JTextComponent) { + return !CtuluLibString.isEmpty(((JTextComponent) jc).getSelectedText()); + } + if (jc instanceof JTable) { + return !((JTable) jc).getSelectionModel().isSelectionEmpty(); + } + if (jc instanceof JTree) { + return !((JTree) jc).getSelectionModel().isSelectionEmpty(); + } return false; } @@ -67,19 +73,30 @@ * @param destAction */ public CopyAction(JComponent source) { - super(source, "copy",BuResource.BU.getString("Copier"),BuResource.BU.getIcon("crystal_copier")); + super(source, getActionName(), BuResource.BU.getString("Copier"), BuResource.BU.getIcon("crystal_copier")); + final KeyStroke keyStroke = getKeyStroke(); + putValue(ACCELERATOR_KEY, keyStroke); + source.getInputMap().put(getKeyStroke(), "newCopy"); + source.getActionMap().put("newCopy", this); } + public static String getActionName() { + return "copy"; + } + + public static KeyStroke getKeyStroke() { + return KeyStroke.getKeyStroke("control C"); + } + @Override public boolean isStateEnable() { return isSomethingToCopy(source); } - } /** * Paste from the system clipboard. - * + * * @author deniger */ public static class PasteAction extends ActionTransferSource { @@ -89,17 +106,30 @@ * @param destAction */ public PasteAction(JComponent source) { - super(source, "paste",BuResource.BU.getString("Coller"),BuResource.BU.getIcon("crystal_coller")); + super(source, getActionName(), BuResource.BU.getString("Coller"), BuResource.BU.getIcon("crystal_coller")); + final KeyStroke keyStroke = getKeyStroke(); + putValue(ACCELERATOR_KEY, keyStroke); + source.getInputMap().put(getKeyStroke(), "newPaste"); + source.getActionMap().put("newPaste", this); } + public static String getActionName() { + return "paste"; + } + + public static KeyStroke getKeyStroke() { + return KeyStroke.getKeyStroke("control V"); + } + @Override public boolean isStateEnable() { TransferHandler transferHandler = source.getTransferHandler(); - if (transferHandler == null) return false; + if (transferHandler == null) { + return false; + } Transferable contents = source.getToolkit().getSystemClipboard().getContents(null); return transferHandler.canImport(new TransferSupport(source, contents)); } - } public static class CutAction extends ActionTransferSource { @@ -109,16 +139,29 @@ * @param destAction */ public CutAction(JComponent source) { - super(source, "paste",BuResource.BU.getString("Couper"),BuResource.BU.getIcon("crystal_couper")); + super(source, "cut", BuResource.BU.getString("Couper"), BuResource.BU.getIcon("crystal_couper")); + final KeyStroke keyStroke = getKeyStroke(); + putValue(ACCELERATOR_KEY, keyStroke); + source.getInputMap().put(getKeyStroke(), "newCut"); + source.getActionMap().put("newCut", this); } + public static String getActionName() { + return "paste"; + } + + public static KeyStroke getKeyStroke() { + return KeyStroke.getKeyStroke("control X"); + } + @Override public boolean isStateEnable() { TransferHandler transferHandler = source.getTransferHandler(); int mode = transferHandler.getSourceActions(source); - if(mode!=TransferHandler.COPY_OR_MOVE&& mode!=TransferHandler.MOVE) return false; + if (mode != TransferHandler.COPY_OR_MOVE && mode != TransferHandler.MOVE) { + return false; + } return isSomethingToCopy(source); } } - } Modified: trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGTableGraphePanel.java =================================================================== --- trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGTableGraphePanel.java 2012-07-18 15:21:48 UTC (rev 7508) +++ trunk/framework/ebli-1d/src/main/java/org/fudaa/ebli/courbe/EGTableGraphePanel.java 2012-07-18 15:37:07 UTC (rev 7509) @@ -258,6 +258,7 @@ /** * @param _tab ArrayList */ + @Override protected void insertTableInTable(final ArrayList _tab) { final EGTableModel model = getEGTableModel(); if (!model.isModelModifiable()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |