{
final Segment content = attribute.getValueSegment ();
final String type = element.getAttributeValue ( ComponentStyleConverter.COMPONENT_TYPE_ATTRIBUTE );
final SupportedComponent selectedType = SupportedComponent.valueOf ( type );
return new LinkGeneratorResult ()
{
@Override
public HyperlinkEvent execute ()
{
try
{
final WebPopOver typeChooser = new WebPopOver ( parentComponent );
typeChooser.setCloseOnFocusLoss ( true );
typeChooser.setStyleId ( "editor-pop-over" );
typeChooser.setMargin ( 5, 0, 5, 0 );
final List<SupportedComponent> supportedComponents =
SupportedComponent.getPainterSupportedComponents ();
final WebList historyList = new WebList ( supportedComponents );
historyList.setOpaque ( false );
historyList.setVisibleRowCount ( Math.min ( 10, supportedComponents.size () ) );
historyList.setRolloverSelectionEnabled ( true );
historyList.setSelectedValue ( selectedType );
historyList.setCellRenderer ( new WebComboBoxCellRenderer ()
{
@Override
public Component getListCellRendererComponent ( final JList list, final Object value,
final int index, final boolean isSelected,
final boolean cellHasFocus )
{
final WebComboBoxElement renderer = ( WebComboBoxElement ) super
.getListCellRendererComponent ( list, value, index, isSelected, cellHasFocus );
final SupportedComponent type = ( SupportedComponent ) value;
if ( type != null )
{
renderer.setIcon ( type.getIcon () );
renderer.setText ( type.toString () );
}
return renderer;
}
} );
final Runnable commitChanges = new Runnable ()
{
@Override
public void run ()
{
final String typeString = historyList.getSelectedValue ().toString ();
source.replaceRange ( typeString, content.getBegin (), content.getEnd () );
typeChooser.dispose ();
}
};
historyList.addMouseListener ( new MouseAdapter ()
{
@Override
public void mouseReleased ( final MouseEvent e )
{
commitChanges.run ();
}
} );
historyList.addKeyListener ( new KeyAdapter ()
{
@Override
public void keyReleased ( final KeyEvent e )
{
if ( Hotkey.ENTER.isKeyTriggered ( e ) )
{
commitChanges.run ();
}
}
} );
final WebScrollPane scrollPane = new WebScrollPane ( historyList, false, false );
scrollPane.setOpaque ( false );
scrollPane.getViewport ().setOpaque ( false );
scrollPane.setShadeWidth ( 0 );
final WebScrollBar vsb = scrollPane.getWebVerticalScrollBar ();
vsb.setMargin ( WebComboBoxStyle.scrollBarMargin );
vsb.setPaintButtons ( WebComboBoxStyle.scrollBarButtonsVisible );
vsb.setPaintTrack ( WebComboBoxStyle.scrollBarTrackVisible );
LafUtils.setScrollBarStyleId ( scrollPane, "combo-box" );
typeChooser.add ( scrollPane );
final Rectangle wb =
source.getUI ().modelToView ( source, ( content.getBegin () + content.getEnd () ) / 2 );
typeChooser.show ( source, wb.x, wb.y, wb.width, wb.height, PopOverDirection.down );
return new HyperlinkEvent ( this, HyperlinkEvent.EventType.EXITED, null );
}
catch ( final BadLocationException e )
{
Log.error ( this, e );
return null;
}
}
@Override
public int getSourceOffset ()
{
return content.getBegin ();
}
};
}
}
}
}
else if ( propertyNodes.contains ( parentName ) )
{
final Segment content = element.getContent ();
final String contentString = content.toString ();
if ( booleanContent.contains ( contentString ) )
{
return new LinkGeneratorResult ()
{
@Override
public HyperlinkEvent execute ()
{
source.replaceRange ( contentString.equals ( trueString ) ? falseString : trueString, content.getBegin (),
content.getEnd () );
return new HyperlinkEvent ( this, HyperlinkEvent.EventType.EXITED, null );
}
@Override
public int getSourceOffset ()
{
return content.getBegin ();
}
};
}
else
{
if ( CompareUtils.contains ( name.toLowerCase (), colorContent ) )
{
final Color color = ( Color ) colorConverter.fromString ( contentString );
if ( color != null || contentString.equals ( ColorConverter.NULL_COLOR ) )
{
return new LinkGeneratorResult ()
{
@Override
public HyperlinkEvent execute ()
{
try
{
final WebPopOver colorChooser = new WebPopOver ( parentComponent );
colorChooser.setCloseOnFocusLoss ( true );
colorChooser.setStyleId ( "editor-pop-over" );
final WebColorChooserPanel colorChooserPanel = new WebColorChooserPanel ( false );
colorChooserPanel.setColor ( color != null ? color : Color.WHITE );
colorChooserPanel.addChangeListener ( new ChangeListener ()
{
private int length = content.getEnd () - content.getBegin ();
@Override
public void stateChanged ( final ChangeEvent e )
{
final Color newColor = colorChooserPanel.getColor ();
if ( color == null || newColor != null && !newColor.equals ( color ) )
{
final String colorString = colorConverter.toString ( newColor );
source.replaceRange ( colorString, content.getBegin (), content.getBegin () + length );
length = colorString.length ();
}
}
} );
colorChooser.add ( colorChooserPanel );
final Rectangle wb =
source.getUI ().modelToView ( source, ( content.getBegin () + content.getEnd () ) / 2 );
colorChooser.show ( source, wb.x, wb.y, wb.width, wb.height, PopOverDirection.down );
return new HyperlinkEvent ( this, HyperlinkEvent.EventType.EXITED, null );
}
catch ( final BadLocationException e )
{
Log.error ( this, e );
return null;
}
}
@Override
public int getSourceOffset ()
{
return content.getBegin ();
}
};
}
}
else if ( CompareUtils.contains ( name.toLowerCase (), transparencyContent ) )
{
final Float f = ( Float ) floatConverter.fromString ( contentString );
if ( f != null )
{
return new LinkGeneratorResult ()
{
@Override
public HyperlinkEvent execute ()
{
try