netbeans-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stephen cumminger <stephen.cummin...@sonideft.com>
Subject RE: Using HTML formatted text as Property Values in PropertySheetView
Date Fri, 18 May 2018 11:45:46 GMT
Just giving everyone an update in case it is of interest to anyone. It is actually the SheetCellRenderer/TableCellRenderer
that gets used by BaseTable/SheetTable that was giving me the issue. Although that part of
the NetBeans code appears that it should work correctly, I suspect it is not being passed
FeatureDescriptor values properly. As an experiment, I passed in a property that overwrote
getHTMLDisplayName() to return a valid html string. I expected that the “Name” first column
in the property sheet to show colored text (as per the html markup). Instead it stripped out
the html tags and provided the bare text. In short, it seems difficult to use html for either
the name or the value for a Property using a standard PropertySheetView. It eludes me in any
event.

I created my own PropertySheetView following https://blogs.oracle.com/geertjan/complex-properties-windows-on-the-netbeans-platform-part-1
For String and Integer values I use my own panel to display name/values that uses a JLabel
for both. It works quite well. For other classes I use another panel that encloses a PropertyPanel.
Incidentally, using a  PropertyPanel for each Property did not solve my HTML rendering requirement
either – I tried that first.

For those interested, here is the preliminary code I altered from Geertjan’s blog that works.
The Lookup was also modified to only listen for AbstractNode.

private void rewritePanel() {//rewrite our Properties Panel
        mainPanel.removeAll();
        AbstractNode node = nodeResult.allInstances().iterator().next();
        String displayName = node.getDisplayName();
        setDisplayName(displayName + " - Properties");

        Node.PropertySet[] sets = node.getPropertySets();
        for (int i=0;i<sets.length;i++)
        {
            Property<?>[] props = sets[i].getProperties();
            if (props.length==0) continue;
            String name=sets[i].getDisplayName();
            JPanel propnamepanel=new JPanel(new BorderLayout());
            mainPanel.add(propnamepanel, "dock north, wrap, growx, pushx");
            JLabel propnamelabel=new JLabel(name);
            Font f = propnamelabel.getFont();
            propnamelabel.setFont(f.deriveFont(f.getStyle() | Font.BOLD));//make font in Bold
            propnamelabel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 2, 0, 0));
            propnamepanel.add(propnamelabel, BorderLayout.WEST);
            propnamepanel.setBackground(new Color(255,255,204));
                for (Node.Property property : props)
                {
                    if (property.getValueType().equals(String.class)) {
                        property.setValue("suppressCustomEditor", true);
                    }
                    Object value=null;
                    try {
                         value= property.getValue();
                    } catch (IllegalAccessException | InvocationTargetException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                    JPanel ppJPanel;
                    if ((value instanceof String)||(value instanceof Integer)) ppJPanel= new
SingleStringPropertyJPanel(property);
                    else ppJPanel= new SinglePropertyJPanel(property);
                    mainPanel.add( ppJPanel, "dock north, wrap, growx, pushx");
                }
        }
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                mainPanel.validate();
                mainPanel.repaint();
                jPanel114.validate();//contains mainPanel
                jPanel114.repaint();
                jScrollPane5.doLayout();//may not be needed?
            }
        });

    }

Steve


From: stephen cumminger <stephen.cumminger@sonideft.com>
Sent: Wednesday, May 16, 2018 5:18 PM
To: Marco Rossi <marco@markreds.it>
Cc: users@netbeans.apache.org
Subject: RE: Using HTML formatted text as Property Values in PropertySheetView

It looks promising. I’ll give it a try. Thanks.

Steve


From: Marco Rossi <marco@markreds.it<mailto:marco@markreds.it>>
Sent: Wednesday, May 16, 2018 4:48 PM
To: stephen cumminger <stephen.cumminger@sonideft.com<mailto:stephen.cumminger@sonideft.com>>
Cc: users@netbeans.apache.org<mailto:users@netbeans.apache.org>
Subject: Re: Using HTML formatted text as Property Values in PropertySheetView

Why don’t you try to implements a custom property sheet editor with a JLabel (that supports
simple html rendering). Take a look here:
https://platform.netbeans.org/tutorials/nbm-property-editors.html

Il giorno 16 mag 2018, alle ore 17:58, stephen cumminger <stephen.cumminger@sonideft.com<mailto:stephen.cumminger@sonideft.com>>
ha scritto:

I am using PropertySupport.Reflection in the createSheet call of an AbstractNode to populate
several properties of interest in a PropertySheetView. Everything works fine, but I would
like to use html rendering for the property values. The String values currently have <html>
and <font> tags that get displayed/rendered properly in the hint/tooltip when you hover
your mouse over the value cell, but the value cell shows all the html tags as text. My tags
are limited and work fine in other tables where a JLabel is the default tablecellrenderer.
Does anyone know how to force the underlying org.openide.explorer.propertysheet.SheetTable
to render the provided String value as html?

<image001.png>

Steve

Mime
View raw message