Skip to content

Commit

Permalink
#8 #40 - JMenu vertical text alignment fixed
Browse files Browse the repository at this point in the history
#9 - Menu items with non-16-px icons are now properly rendered
#25 - JComboBox popup is now properly opened for the first time with RTL orientation
#28 - Menu items selection color scheme improved
#33 - All RTL-orientated menus are now properly rendered
A lot of improvements done to default popup menu positioning
All menu elements are now properly styled using WebLaF UIs
JavaDoc added into menu element classes and UIs
  • Loading branch information
mgarin committed Oct 7, 2013
1 parent b62370a commit ba262a1
Show file tree
Hide file tree
Showing 44 changed files with 3,106 additions and 2,687 deletions.
12 changes: 3 additions & 9 deletions src/com/alee/examples/content/SourceViewer.java
Expand Up @@ -770,9 +770,7 @@ public void actionPerformed ( ActionEvent e )
}
}

boolean ltr = rootElement.getComponentOrientation ().isLeftToRight ();
rootMenu.show ( rootElement, ltr ? 1 : rootElement.getWidth () - 1 - rootMenu.getPreferredSize ().width,
rootElement.getHeight () + 2 );
rootMenu.showBelowMiddle ( rootElement );
}
} );
classPath.add ( rootElement );
Expand Down Expand Up @@ -801,11 +799,7 @@ public void actionPerformed ( ActionEvent e )
{
packageMenu.add ( createEntryMenuItem ( menuEntry ) );
}

boolean ltr = rootElement.getComponentOrientation ().isLeftToRight ();
packageMenu.show ( element,
ltr ? classPath.getElementOverlap () : element.getWidth () - classPath.getElementOverlap () -
packageMenu.getPreferredSize ().width, element.getHeight () + 2 );
packageMenu.showBelowMiddle ( element );
}
}
} );
Expand Down Expand Up @@ -1034,7 +1028,7 @@ private String loadSource ( JarEntry lastEntry )
String source = loadString ( lastEntry );

// Removing space-eating license notice
if ( source.startsWith ( "/*" ) )
if ( source.startsWith ( commentStart ) )
{
int index = source.indexOf ( commentEnd );
if ( index != -1 )
Expand Down
68 changes: 58 additions & 10 deletions src/com/alee/examples/groups/menubar/DefaultMenuBarExample.java
Expand Up @@ -18,13 +18,13 @@
package com.alee.examples.groups.menubar;

import com.alee.examples.content.DefaultExample;
import com.alee.laf.menu.WebMenu;
import com.alee.laf.menu.WebMenuBar;
import com.alee.laf.menu.WebMenuItem;
import com.alee.laf.menu.*;
import com.alee.managers.hotkey.Hotkey;
import com.alee.managers.tooltip.TooltipManager;
import com.alee.managers.tooltip.TooltipWay;

import javax.swing.*;

/**
* User: mgarin Date: 07.11.12 Time: 18:21
*/
Expand All @@ -42,7 +42,7 @@ public void setupMenuBar ( WebMenuBar menuBar )
add ( new WebMenuItem ( "New image", loadIcon ( "menubar/file_image.png" ) )
{
{
setHotkey ( Hotkey.CTRL_N );
setAccelerator ( Hotkey.CTRL_N );
}
} );
add ( new WebMenuItem ( "New music", loadIcon ( "menubar/file_music.png" ) ) );
Expand All @@ -58,7 +58,7 @@ public void setupMenuBar ( WebMenuBar menuBar )
add ( new WebMenuItem ( "Exit", loadIcon ( "menubar/file_exit.png" ) )
{
{
setHotkey ( Hotkey.ALT_F4 );
setAccelerator ( Hotkey.ALT_F4 );
}
} );
}
Expand All @@ -69,32 +69,80 @@ public void setupMenuBar ( WebMenuBar menuBar )
add ( new WebMenuItem ( "Cut", loadIcon ( "menubar/edit_cut.png" ) )
{
{
setHotkey ( Hotkey.CTRL_X );
setAccelerator ( Hotkey.CTRL_X );
}
} );
add ( new WebMenuItem ( "Copy", loadIcon ( "menubar/edit_copy.png" ) )
{
{
setHotkey ( Hotkey.CTRL_C );
setAccelerator ( Hotkey.CTRL_C );
}
} );
add ( new WebMenuItem ( "Paste", loadIcon ( "menubar/edit_paste.png" ) )
{
{
setHotkey ( Hotkey.CTRL_V );
setAccelerator ( Hotkey.CTRL_V );
setEnabled ( false );
}
} );
}
} );
menuBar.add ( new WebMenu ( "States", loadIcon ( "menubar/states.png" ) )
{
{
add ( new WebCheckBoxMenuItem ( "Checkbox item 1", loadIcon ( "menubar/check1.png" ) )
{
{
setAccelerator ( Hotkey.NUMBER_1 );
setSelected ( true );
}
} );
add ( new WebCheckBoxMenuItem ( "Checkbox item 2", loadIcon ( "menubar/check2.png" ) )
{
{
setAccelerator ( Hotkey.NUMBER_2 );
}
} );
addSeparator ();
final ButtonGroup buttonGroup = new ButtonGroup ();
add ( new WebRadioButtonMenuItem ( "Radio item 1", loadIcon ( "menubar/radio1.png" ) )
{
{
setAccelerator ( Hotkey.A );
setSelected ( true );
buttonGroup.add ( this );
}
} );
add ( new WebRadioButtonMenuItem ( "Radio item 2", loadIcon ( "menubar/radio2.png" ) )
{
{
setAccelerator ( Hotkey.B );
buttonGroup.add ( this );
}
} );
add ( new WebRadioButtonMenuItem ( "Radio item 3", loadIcon ( "menubar/radio3.png" ) )
{
{
setAccelerator ( Hotkey.C );
buttonGroup.add ( this );
}
} );
}
} );
menuBar.add ( new WebMenu ( "Menu tooltip", loadIcon ( "menubar/tooltip.png" ) )
{
{
TooltipManager.setTooltip ( this, "Menu tooltip" );
add ( new WebMenuItem ( "Menu item tooltip", loadIcon ( "menubar/tooltip.png" ) )
add ( new WebMenuItem ( "Trailing tooltip", loadIcon ( "menubar/tooltip.png" ) )
{
{
TooltipManager.setTooltip ( this, "Tip", TooltipWay.trailing );
}
} );
add ( new WebMenuItem ( "Bottom tooltip", loadIcon ( "menubar/tooltip.png" ) )
{
{
TooltipManager.setTooltip ( this, "Menu item tooltip", TooltipWay.trailing );
TooltipManager.setTooltip ( this, "Tip", TooltipWay.down );
}
} );
}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions src/com/alee/extended/filechooser/WebPathField.java
Expand Up @@ -750,8 +750,7 @@ public void actionPerformed ( ActionEvent e )
// todo Apply orientation globally on change, not here
WebPathField.this.transferFocus ();
SwingUtils.applyOrientation ( menu );
menu.show ( childs, childs.getComponentOrientation ().isLeftToRight () ? 0 :
childs.getWidth () - menu.getPreferredSize ().width, childs.getHeight () );
menu.showBelowMiddle ( childs );
}
} );
contentPanel.add ( childs );
Expand Down Expand Up @@ -794,7 +793,7 @@ public void popupMenuCanceled ( PopupMenuEvent e )
}
if ( canShortenPath () )
{
getRootsMenu ().add ( new JPopupMenu.Separator (), 0 );
getRootsMenu ().addSeparator ( 0 );
}
while ( canShortenPath () )
{
Expand Down Expand Up @@ -927,8 +926,7 @@ public void actionPerformed ( ActionEvent e )
{
WebPathField.this.transferFocus ();
SwingUtils.applyOrientation ( rootsMenu );
rootsMenu.show ( rootsArrowButton, rootsArrowButton.getComponentOrientation ().isLeftToRight () ? 0 :
rootsArrowButton.getWidth () - rootsMenu.getPreferredSize ().width, rootsArrowButton.getHeight () );
rootsMenu.showBelowMiddle ( rootsArrowButton );
}
} );

Expand Down
6 changes: 3 additions & 3 deletions src/com/alee/extended/transition/TransitionUtils.java
Expand Up @@ -102,7 +102,7 @@ public static BlockType getActualValue ( final BlockType blockType )
/**
* Returns actual curtain type for the specified curtain type.
*
* @param blockType curtain type to process
* @param curtainType curtain type to process
* @return actual curtain type for the specified curtain type
*/
public static CurtainType getActualValue ( final CurtainType curtainType )
Expand All @@ -121,7 +121,7 @@ public static CurtainType getActualValue ( final CurtainType curtainType )
/**
* Returns actual slide type for the specified slide type.
*
* @param blockType slide type to process
* @param slideType slide type to process
* @return actual slide type for the specified slide type
*/
public static SlideType getActualValue ( final SlideType slideType )
Expand All @@ -140,7 +140,7 @@ public static SlideType getActualValue ( final SlideType slideType )
/**
* Returns actual zoom type for the specified zoom type.
*
* @param blockType zoom type to process
* @param zoomType zoom type to process
* @return actual zoom type for the specified zoom type
*/
public static ZoomType getActualValue ( final ZoomType zoomType )
Expand Down
23 changes: 18 additions & 5 deletions src/com/alee/extended/tree/WebAsyncTreeFilterField.java
Expand Up @@ -27,6 +27,7 @@
import com.alee.utils.swing.DocumentChangeListener;
import com.alee.utils.text.TextProvider;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
Expand All @@ -44,6 +45,18 @@

public class WebAsyncTreeFilterField<E extends AsyncUniqueNode> extends WebTextField
{
/**
* Used icons.
*/
public static final ImageIcon settingsIcon =
new ImageIcon ( WebAsyncTreeFilterField.class.getResource ( "icons/filter/settings.png" ) );
public static final ImageIcon matchCaseIcon =
new ImageIcon ( WebAsyncTreeFilterField.class.getResource ( "icons/filter/matchCase.png" ) );
public static final ImageIcon useSpaceAsSeparatorIcon =
new ImageIcon ( WebAsyncTreeFilterField.class.getResource ( "icons/filter/useSpaceAsSeparator.png" ) );
public static final ImageIcon searchFromStartIcon =
new ImageIcon ( WebAsyncTreeFilterField.class.getResource ( "icons/filter/searchFromStart.png" ) );

/**
* Async tree to which this field should apply filtering.
*/
Expand Down Expand Up @@ -107,15 +120,15 @@ protected void init ()

protected void initFilterIcon ()
{
filterIcon = new WebImage ( WebAsyncTreeFilterField.class, "icons/filter.png" );
filterIcon = new WebImage ( WebAsyncTreeFilterField.class, "icons/filter/settings.png" );
filterIcon.setMargin ( 0, 2, 0, 2 );
filterIcon.setCursor ( Cursor.getDefaultCursor () );
filterIcon.addMouseListener ( new MouseAdapter ()
{
@Override
public void mousePressed ( final MouseEvent e )
{
settingsMenu.showUnder ( WebAsyncTreeFilterField.this );
settingsMenu.showBelowMiddle ( filterIcon );
}
} );
setLeadingComponent ( filterIcon );
Expand All @@ -125,7 +138,7 @@ protected void initSettingsMenu ()
{
settingsMenu = new WebPopupMenu ();

matchCaseItem = new WebCheckBoxMenuItem ( "Match case" );
matchCaseItem = new WebCheckBoxMenuItem ( "Match case", matchCaseIcon );
matchCaseItem.addActionListener ( new ActionListener ()
{
@Override
Expand All @@ -137,7 +150,7 @@ public void actionPerformed ( final ActionEvent e )
} );
settingsMenu.add ( matchCaseItem );

useSpaceAsSeparatorItem = new WebCheckBoxMenuItem ( "Use space as separator" );
useSpaceAsSeparatorItem = new WebCheckBoxMenuItem ( "Use space as separator", useSpaceAsSeparatorIcon );
useSpaceAsSeparatorItem.addActionListener ( new ActionListener ()
{
@Override
Expand All @@ -149,7 +162,7 @@ public void actionPerformed ( final ActionEvent e )
} );
settingsMenu.add ( useSpaceAsSeparatorItem );

searchFromStartItem = new WebCheckBoxMenuItem ( "Search from beginning" );
searchFromStartItem = new WebCheckBoxMenuItem ( "Search from beginning", searchFromStartIcon );
searchFromStartItem.addActionListener ( new ActionListener ()
{
@Override
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 17 additions & 1 deletion src/com/alee/extended/window/TestFrame.java
Expand Up @@ -667,10 +667,26 @@ public TestFrame displayFrame ()
*/
public static String getFrameTitle ( final Component component )
{
// Tested class name
final String className = ( component != null ? ReflectUtils.getClassName ( component.getClass () ) : "TestFrame" ) + " ";
final String libVersion = "[ " + VersionManager.getLibraryVersion ().toString () + " ] ";

// WebLaF version
String libVersion = "";
try
{
libVersion = "[ " + VersionManager.getLibraryVersion ().toString () + " ] ";
}
catch ( Throwable e )
{
// Cannot load version now
}

// Undelying OS name and version
final String osVersion = "[ " + SystemUtils.getOsName () + " " + SystemUtils.getOsArch () + " ] ";

// JRE version
final String jreVersion = "[ JRE " + SystemUtils.getJavaVersionString () + " " + SystemUtils.getJreArch () + "-bit ]";

return className + libVersion + osVersion + jreVersion;
}
}
19 changes: 7 additions & 12 deletions src/com/alee/laf/WebLookAndFeel.java
Expand Up @@ -456,18 +456,13 @@ protected void initComponentDefaults ( final UIDefaults table )
table.put ( "Tree.drawsFocusBorderAroundIcon", Boolean.FALSE );
table.put ( "Tree.drawDashedFocusIndicator", Boolean.FALSE );

// Disabled foreground color
table.put ( "MenuItem.disabledForeground", StyleConstants.disabledTextColor );
// We don't need uneven heights
table.put ( "MenuItem.evenHeight", Boolean.TRUE );

// // JMenu expand spacing
// // Up-down menu expand
// table.put ( "Menu.menuPopupOffsetX", StyleConstants.shadeWidth );
// table.put ( "Menu.menuPopupOffsetY", -StyleConstants.shadeWidth / 2 );
// // Left-right menu expand
// table.put ( "Menu.submenuPopupOffsetX", StyleConstants.shadeWidth / 2 );
// table.put ( "Menu.submenuPopupOffsetY", 0 );
// JMenu expand spacing
// Up-down menu expand
table.put ( "Menu.menuPopupOffsetX", 0 );
table.put ( "Menu.menuPopupOffsetY", 0 );
// Left-right menu expand
table.put ( "Menu.submenuPopupOffsetX", 0 );
table.put ( "Menu.submenuPopupOffsetY", 0 );

// Table defaults
table.put ( "Table.cellNoFocusBorder", LafUtils.createWebBorder ( 1, 1, 1, 1 ) );
Expand Down
12 changes: 6 additions & 6 deletions src/com/alee/laf/combobox/WebComboBoxCellRenderer.java
Expand Up @@ -26,13 +26,13 @@

public class WebComboBoxCellRenderer extends DefaultListCellRenderer
{
private JComboBox comboBox;
private WebComboBoxElement renderer;
protected Component component;
protected WebComboBoxElement renderer;

public WebComboBoxCellRenderer ( JComboBox comboBox )
public WebComboBoxCellRenderer ( Component component )
{
super ();
this.comboBox = comboBox;
this.component = component;
this.renderer = new WebComboBoxElement ();
}

Expand All @@ -49,8 +49,8 @@ public Component getListCellRendererComponent ( JList list, Object value, int in
renderer.setSelected ( isSelected );
renderer.updatePainter ();

renderer.setEnabled ( comboBox.isEnabled () );
renderer.setFont ( comboBox.getFont () );
renderer.setEnabled ( component.isEnabled () );
renderer.setFont ( component.getFont () );
renderer.setForeground ( isSelected ? list.getSelectionForeground () : list.getForeground () );
renderer.setComponentOrientation ( list.getComponentOrientation () );

Expand Down

0 comments on commit ba262a1

Please sign in to comment.