hey Mike,

any reason not to implement an "experimental type" checkbox?

i like the nullify popup idea! not sure people will grasp the press left mouse 
button a little longer to see it concept. why didn't you use the standard right 
mouse button context menu access?

..ede

On 22.03.2015 12:56, jump-pilot-...@lists.sourceforge.net wrote:
> Revision: 4343
>           http://sourceforge.net/p/jump-pilot/code/4343
> Author:   michaudm
> Date:     2015-03-22 11:56:32 +0000 (Sun, 22 Mar 2015)
> Log Message:
> -----------
> Hide new attribute types from schema editor except Long and Boolean
> Add JPopupMenu to be able to nullify String/Boolean attribute values.
> 
> Modified Paths:
> --------------
>     core/trunk/ChangeLog
>     core/trunk/src/com/vividsolutions/jump/feature/AttributeType.java
>     
> core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java
>     core/trunk/src/com/vividsolutions/jump/workbench/ui/SchemaPanel.java
> 
> Modified: core/trunk/ChangeLog
> ===================================================================
> --- core/trunk/ChangeLog      2015-03-21 13:47:22 UTC (rev 4342)
> +++ core/trunk/ChangeLog      2015-03-22 11:56:32 UTC (rev 4343)
> @@ -1,5 +1,12 @@
>  # for display continuity sake please use 2 spaces instead of tabs
>  
> +2015-03-22 mmichaud <m.michael.mich...@orange.fr>
> +  * Hide unused AttributeType from the schema.
> +    Add a way to nullify attribute values in the Attribute panel :
> +    - String and boolean : press left button, and click on null menu item
> +    before releasing
> +    - Date and numerics : just empty the field
> +
>  2015-03-15 Giuseppe Aruta (ma15569) 
>    * Add RasterImageIOUtils.class, with various methods to perform
>      some raster image  Input/Output operations
> 
> Modified: core/trunk/src/com/vividsolutions/jump/feature/AttributeType.java
> ===================================================================
> --- core/trunk/src/com/vividsolutions/jump/feature/AttributeType.java 
> 2015-03-21 13:47:22 UTC (rev 4342)
> +++ core/trunk/src/com/vividsolutions/jump/feature/AttributeType.java 
> 2015-03-22 11:56:32 UTC (rev 4343)
> @@ -149,14 +149,16 @@
>     */
>    public static Collection<AttributeType> basicTypes() {
>      List<AttributeType> basicTypes = new ArrayList<AttributeType>();
> +    basicTypes.add(GEOMETRY);
>      basicTypes.add(STRING);
>      basicTypes.add(INTEGER);
>      basicTypes.add(LONG);
> -    basicTypes.add(FLOAT);
> +    //basicTypes.add(FLOAT);
>      basicTypes.add(DOUBLE);
>      basicTypes.add(DATE);
> -    basicTypes.add(TIMESTAMP);
> +    //basicTypes.add(TIMESTAMP);
>      basicTypes.add(BOOLEAN);
> +    basicTypes.add(OBJECT);
>      return basicTypes;
>    }
>  
> 
> Modified: 
> core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java
> ===================================================================
> --- 
> core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java  
>     2015-03-21 13:47:22 UTC (rev 4342)
> +++ 
> core/trunk/src/com/vividsolutions/jump/workbench/ui/AttributeTablePanel.java  
>     2015-03-22 11:56:32 UTC (rev 4343)
> @@ -26,40 +26,23 @@
>   */
>  package com.vividsolutions.jump.workbench.ui;
>  
> -import java.awt.Color;
> -import java.awt.Component;
> -import java.awt.Font;
> -import java.awt.Graphics2D;
> -import java.awt.GridBagConstraints;
> -import java.awt.GridBagLayout;
> -import java.awt.Insets;
> -import java.awt.event.KeyEvent;
> -import java.awt.event.MouseAdapter;
> -import java.awt.event.MouseEvent;
> -import java.awt.event.MouseMotionAdapter;
> +import java.awt.*;
> +import java.awt.event.*;
>  import java.awt.image.BufferedImage;
>  import java.math.BigDecimal;
>  import java.sql.Time;
>  import java.sql.Timestamp;
>  import java.text.DateFormat;
>  import java.text.SimpleDateFormat;
> -import java.util.ArrayList;
> -import java.util.Collection;
> -import java.util.Date;
> -import java.util.HashMap;
> -import java.util.Iterator;
> +import java.util.*;
>  
>  import javax.swing.*;
> -import javax.swing.event.ChangeEvent;
> -import javax.swing.event.ListSelectionEvent;
> -import javax.swing.event.ListSelectionListener;
> -import javax.swing.event.TableColumnModelEvent;
> -import javax.swing.event.TableColumnModelListener;
> -import javax.swing.event.TableModelEvent;
> -import javax.swing.event.TableModelListener;
> +import javax.swing.event.*;
>  import javax.swing.table.DefaultTableCellRenderer;
> +import javax.swing.table.TableCellEditor;
>  import javax.swing.table.TableCellRenderer;
>  import javax.swing.table.TableColumnModel;
> +import javax.swing.text.PlainDocument;
>  
>  import org.openjump.core.ui.plugin.view.ViewOptionsPlugIn;
>  
> @@ -151,7 +134,24 @@
>              } catch (IllegalArgumentException e) {
>                  formatter = DEFAULT_DATE_FORMAT;
>              }
> -            setDefaultEditor(Date.class, new 
> FlexibleDateParser.CellEditor(formatter));
> +            //setDefaultEditor(Date.class, new 
> FlexibleDateParser.CellEditor(formatter));
> +
> +            NullifyMouseAdapter nullifyMouseAdapter = new 
> NullifyMouseAdapter(MyTable.this);
> +
> +            DefaultCellEditor dateCellEditor = new 
> FlexibleDateParser.CellEditor(formatter);
> +            // I don't know why it does not work for Date cells
> +            // It is not a big problem as one can empty the date field to 
> nullify date value
> +            
> //dateCellEditor.getComponent().addMouseListener(nullifyMouseAdapter);
> +            setDefaultEditor(Date.class, dateCellEditor);
> +
> +            JTextField nullableTextField = new JTextField();
> +            nullableTextField.addMouseListener(nullifyMouseAdapter);
> +            setDefaultEditor(String.class, new 
> DefaultCellEditor(nullableTextField));
> +
> +            JCheckBox nullableCheckBox = new JCheckBox();
> +            nullableCheckBox.addMouseListener(nullifyMouseAdapter);
> +            setDefaultEditor(Boolean.class, new 
> DefaultCellEditor(nullableCheckBox));
> +
>          }
>  
>          //Row-stripe colour recommended in
> @@ -163,7 +163,7 @@
>               @Override
>          public TableCellRenderer getCellRenderer(int row, int column) {
>              if (!isEditButtonColumn(column)) {
> -                JComponent renderer = (JComponent) super.getCellRenderer(row,
> +                final JComponent renderer = (JComponent) 
> super.getCellRenderer(row,
>                          column);
>                  // Get the prefered date formatter from the 
> PersistentBlackboard
>                  Blackboard blackBoard = 
> PersistentBlackboardPlugIn.get(workbenchContext);
> @@ -262,8 +262,9 @@
>                          else setText(value.toString());
>                      }
>                  });
> +                setDefaultRenderer(Boolean.class, new NullableCheckBox());
>  
> -                             if 
> (AttributeTablePanel.this.getModel().getLayer().isEditable()
> +                if 
> (AttributeTablePanel.this.getModel().getLayer().isEditable()
>                                               && 
> !AttributeTablePanel.this.getModel()
>                                                       .isCellEditable(row, 
> column))
>                                       // Shade readonly cells light gray
> @@ -282,6 +283,81 @@
>          }
>      };
>  
> +    class NullableCheckBox extends JCheckBox implements TableCellRenderer {
> +        public NullableCheckBox() {
> +            super();
> +            setHorizontalAlignment(SwingConstants.CENTER);
> +        }
> +        public Component getTableCellRendererComponent(JTable table, Object 
> value, boolean isSelected, boolean hasFocus, int row, int column) {
> +            if (value == null) {
> +                //this.setBackground(Color.LIGHT_GRAY);
> +                this.setIcon(nullObject);
> +            } else {
> +                super.setSelected((Boolean)value);
> +            }
> +            return this;
> +        }
> +    }
> +
> +    // A popup menu item to set a value to null
> +    class PopUpNullifyCell extends JPopupMenu {
> +        JMenuItem anItem;
> +        public PopUpNullifyCell(){
> +            anItem = new JMenuItem(nullString);
> +            add(anItem);
> +        }
> +    }
> +
> +    // A mouse listener to display a PopUpNullifyCell
> +    // The popup is display after a left mouse pressed and disappear after 
> the mouse release
> +    // To nullify a value, click the PopUpNullifyCell between mouse press 
> and mouse release
> +    class NullifyMouseAdapter extends MouseAdapter {
> +        JTable table;
> +        PopUpNullifyCell menu;
> +
> +        NullifyMouseAdapter(final JTable table){
> +            super();
> +            this.table = table;
> +        }
> +
> +        @Override
> +        public void mousePressed(final MouseEvent e) {
> +            if (SwingUtilities.isLeftMouseButton(e)) {
> +                menu = new PopUpNullifyCell();
> +                final int row = 
> table.convertRowIndexToModel(table.getEditingRow());
> +                final int column = 
> table.convertColumnIndexToModel(table.getEditingColumn());
> +                menu.anItem.addActionListener(new ActionListener() {
> +                    @Override
> +                    public void actionPerformed(ActionEvent e) {
> +                        table.removeEditor();
> +                        table.getModel().setValueAt(null, row, column);
> +                        //System.out.println(row + "/" + column + " : " + 
> table.getModel().getValueAt(row, column));
> +                    }
> +                });
> +                // Wait 1/2 s before displaying the nullify popup menu,
> +                // so that the normal edition mode is not disturbed
> +                new Thread(new Runnable() {
> +                    @Override
> +                    public void run() {
> +                        try {
> +                            Thread.sleep(333);
> +                            if (menu!= null) menu.show(e.getComponent(), 
> e.getX() + 10, e.getY());
> +                        } catch(InterruptedException ie) {}
> +                    }
> +                }).start();
> +
> +            }
> +        }
> +
> +        @Override
> +        public void mouseReleased(MouseEvent e) {
> +            if (menu != null) {
> +                menu.setVisible(false);
> +                menu = null;
> +            }
> +        }
> +    };
> +
>      private ImageIcon buildPartlyEmptyIcon(ImageIcon icon) {
>        ImageIcon empty = buildEmptyIcon(icon);
>        // build mask
> 
> Modified: core/trunk/src/com/vividsolutions/jump/workbench/ui/SchemaPanel.java
> ===================================================================
> --- core/trunk/src/com/vividsolutions/jump/workbench/ui/SchemaPanel.java      
> 2015-03-21 13:47:22 UTC (rev 4342)
> +++ core/trunk/src/com/vividsolutions/jump/workbench/ui/SchemaPanel.java      
> 2015-03-22 11:56:32 UTC (rev 4343)
> @@ -400,7 +400,8 @@
>  
>      private void initCellEditors() {
>          fieldNameColumn().setCellEditor(new MyFieldNameEditor());
> -        dataTypeColumn().setCellEditor(new 
> MyDataTypeEditor(AttributeType.allTypes().toArray()));
> +        // Switched to basic types only (to get all types available, switch 
> to AttributeType.allTypes())
> +        dataTypeColumn().setCellEditor(new 
> MyDataTypeEditor(AttributeType.basicTypes().toArray()));
>          fieldNameColumn().setCellRenderer(
>              new StripingRenderer(table.getDefaultRenderer(String.class)));
>          dataTypeColumn().setCellRenderer(new StripingRenderer(new 
> TableCellRenderer() {
> @@ -790,12 +791,16 @@
>                      int index,
>                      boolean isSelected,
>                      boolean cellHasFocus) {
> -                    return originalRenderer.getListCellRendererComponent(
> -                        list,
> -                        (value != null) ? 
> capitalizeFirstLetter(value.toString()) : null,
> -                        index,
> -                        isSelected,
> -                        cellHasFocus);
> +                    Component component = 
> originalRenderer.getListCellRendererComponent(
> +                            list,
> +                            (value != null) ? 
> capitalizeFirstLetter(value.toString()) : null,
> +                            index,
> +                            isSelected,
> +                            cellHasFocus);
> +                    if (!AttributeType.basicTypes().contains(value)) {
> +                        component.setForeground(Color.RED);
> +                    }
> +                    return component;
>                  }
>              });
>          }
> 
> 
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming The Go Parallel Website, sponsored
> by Intel and developed in partnership with Slashdot Media, is your hub for all
> things parallel software development, from weekly thought leadership blogs to
> news, videos, case studies, tutorials and more. Take a look and join the 
> conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
> 

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to