com.alee.laf.menu.WebPopupMenu Java Examples

The following examples show how to use com.alee.laf.menu.WebPopupMenu. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Utils.java    From desktopclient-java with GNU General Public License v3.0 6 votes vote down vote up
static WebPopupMenu createCopyMenu(boolean modifiable) {
    WebPopupMenu menu = new WebPopupMenu();
    if (modifiable) {
        Action cut = new DefaultEditorKit.CutAction();
        cut.putValue(Action.NAME, Tr.tr("Cut"));
        cut.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control X"));
        menu.add(cut);
    }

    Action copy = new DefaultEditorKit.CopyAction();
    copy.putValue(Action.NAME, Tr.tr("Copy"));
    copy.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control C"));
    menu.add(copy);

    if (modifiable) {
        Action paste = new DefaultEditorKit.PasteAction();
        paste.putValue(Action.NAME, Tr.tr("Paste"));
        paste.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control V"));
        menu.add(paste);
    }

    return menu;
}
 
Example #2
Source File: NavigatorWindow.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the minerals menu.
 */
private WebPopupMenu createMineralsMenu() {
	// Create the mineral options menu.
	WebPopupMenu mineralsMenu = new WebPopupMenu();

	// Create each mineral check box item.
	MineralMapLayer mineralMapLayer = (MineralMapLayer) mineralLayer;
	java.util.Map<String, Color> mineralColors = mineralMapLayer.getMineralColors();
	Iterator<String> i = mineralColors.keySet().iterator();
	while (i.hasNext()) {
		String mineralName = i.next();
		Color mineralColor = mineralColors.get(mineralName);
		boolean isMineralDisplayed = mineralMapLayer.isMineralDisplayed(mineralName);
		WebCheckBoxMenuItem mineralItem = new WebCheckBoxMenuItem(mineralName, isMineralDisplayed);
		mineralItem.setIcon(createColorLegendIcon(mineralColor, mineralItem));
		mineralItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				SwingUtilities.invokeLater(() -> {
					WebCheckBoxMenuItem checkboxItem = (WebCheckBoxMenuItem) event.getSource();
					((MineralMapLayer) mineralLayer).setMineralDisplayed(checkboxItem.getText(),
							checkboxItem.isSelected());
				});
			}
		});
		mineralsMenu.add(mineralItem);
	}

	mineralsMenu.pack();
	return mineralsMenu;
}
 
Example #3
Source File: ComponentUtils.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public JPopupMenu getComponentPopupMenu() {
    WebPopupMenu menu = new WebPopupMenu();

    if (mFile == null)
        return null; // should never happen

    WebMenuItem saveMenuItem = new WebMenuItem(Tr.tr("Save File As…"));
    saveMenuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (mFile == null)
                return; // should never happen

            File suggestedFile = new File(
                    mFileChooser.getCurrentDirectory(), mFile.getName());

            mFileChooser.setSelectedFile(suggestedFile);
            // fix WebLaf bug
            mFileChooser.getFileChooserPanel().setSelectedFiles(new File[]{suggestedFile});

            int option = mFileChooser.showSaveDialog(AttachmentPanel.this);
            if (option == JFileChooser.APPROVE_OPTION) {
                try {
                    Files.copy(mFile.toPath(), mFileChooser.getSelectedFile().toPath(),
                            StandardCopyOption.REPLACE_EXISTING);
                } catch (IOException ex) {
                    LOGGER.log(Level.WARNING, "can't copy file", ex);
                }
            }
        }
    });
    if (!mFile.exists()) {
        saveMenuItem.setEnabled(false);
        saveMenuItem.setToolTipText(Tr.tr("File does not exist"));
    }
    menu.add(saveMenuItem);

    return menu;
}
 
Example #4
Source File: ComponentUtils.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
private void showPopupMenu(MouseEvent e) {
    WebPopupMenu menu = new WebPopupMenu();
    WebMenuItem removeItem = new WebMenuItem(Tr.tr("Remove"));
    removeItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent event) {
                EditableAvatarImage.this.changeImage(null);
            }
        });
    removeItem.setEnabled(EditableAvatarImage.this.canRemove());
    menu.add(removeItem);
    menu.show(this, e.getX(), e.getY());
}
 
Example #5
Source File: ListView.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
private void onPopupClick(MouseEvent e) {
    int row = this.rowAtPoint(e.getPoint());

    if (!ArrayUtils.contains(this.getSelectedRows(), row))
        this.setSelectedItem(row);

    WebPopupMenu menu = this.rightClickMenu(this.getSelectedValues());
    menu.show(this, e.getX(), e.getY());
}
 
Example #6
Source File: WebSplitButtonExample.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns sample popup menu.
 *
 * @param button  split button for which sample menu should be created
 * @param addIcon whether or not button should contain icon
 * @param addText whether or not button should contain text
 * @return sample popup menu
 */
protected static WebPopupMenu createSamplePopupMenu ( final WebSplitButton button, final boolean addIcon, final boolean addText )
{
    final PopupMenuGenerator generator = new PopupMenuGenerator ();
    createPopupMenuItem ( button, addIcon, addText, generator, DemoIcons.facebook16, "Facebook" );
    createPopupMenuItem ( button, addIcon, addText, generator, DemoIcons.twitter16, "Twitter" );
    createPopupMenuItem ( button, addIcon, addText, generator, DemoIcons.googleplus16, "Google Plus" );
    createPopupMenuItem ( button, addIcon, addText, generator, DemoIcons.linkedin16, "Linked In" );
    createPopupMenuItem ( button, addIcon, addText, generator, DemoIcons.pinterest16, "Pinterest" );
    generator.addSeparator ();
    createPopupMenuItem ( button, addIcon, addText, generator, DemoIcons.youtube16, "Youtube" );
    createPopupMenuItem ( button, addIcon, addText, generator, DemoIcons.vimeo16, "Vimeo" );
    return generator.getMenu ();
}
 
Example #7
Source File: NavigatorWindow.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
	 * Create the map options menu.
	 */
	private void createOptionsMenu() {
		// Create options menu.
		optionsMenu = new WebPopupMenu();
		optionsMenu.setToolTipText(Msg.getString("NavigatorWindow.menu.mapOptions")); //$NON-NLS-1$

		// Create day/night tracking menu item.
		dayNightItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.daylightTracking"), //$NON-NLS-1$
				mapLayerPanel.hasMapLayer(shadingLayer));
		dayNightItem.addActionListener(this);
		optionsMenu.add(dayNightItem);
		// Unchecked dayNightItem at the start of sim
		// globeNav.setDayNightTracking(false);
		dayNightItem.setSelected(false);

		// Create topographical map menu item.
		surfItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.surf"), //$NON-NLS-1$
				SurfMarsMap.TYPE.equals(mapLayerPanel.getMapType()));
		surfItem.addActionListener(this);
		optionsMenu.add(surfItem);
		
		// Create topographical map menu item.
		topoItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.topo"), //$NON-NLS-1$
				TopoMarsMap.TYPE.equals(mapLayerPanel.getMapType()));
		topoItem.addActionListener(this);
		optionsMenu.add(topoItem);

		// Create topographical map menu item.
		geoItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.geo"), //$NON-NLS-1$
				GeologyMarsMap.TYPE.equals(mapLayerPanel.getMapType()));
		geoItem.addActionListener(this);
		optionsMenu.add(geoItem);
		
	    ButtonGroup group = new ButtonGroup();
		group.add(surfItem);
		group.add(topoItem);
		group.add(geoItem);

//		JMenuItem mapItem = new JMenuItem(Msg.getString("NavigatorWindow.menu.selectMap"));//, KeyEvent.VK_M);
//		mapItem.add(geoItem);
//		mapItem.add(surfItem);
//		mapItem.add(geoItem);
//		optionsMenu.add(mapItem);
		
		// Create unit label menu item.
		unitLabelItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.showLabels"), //$NON-NLS-1$
				mapLayerPanel.hasMapLayer(unitLabelLayer));
		unitLabelItem.addActionListener(this);
		optionsMenu.add(unitLabelItem);

		// Create vehicle trails menu item.
		trailItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.showVehicleTrails"), //$NON-NLS-1$
				mapLayerPanel.hasMapLayer(trailLayer));
		trailItem.addActionListener(this);
		optionsMenu.add(trailItem);

		// Create landmarks menu item.
		landmarkItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.showLandmarks"), //$NON-NLS-1$
				mapLayerPanel.hasMapLayer(landmarkLayer));
		landmarkItem.addActionListener(this);
		optionsMenu.add(landmarkItem);

		// Create navpoints menu item.
		navpointItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.showNavPoints"), //$NON-NLS-1$
				mapLayerPanel.hasMapLayer(navpointLayer));
		navpointItem.addActionListener(this);
		optionsMenu.add(navpointItem);

		// Create explored site menu item.
		exploredSiteItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.showExploredSites"), //$NON-NLS-1$
				mapLayerPanel.hasMapLayer(exploredSiteLayer));
		exploredSiteItem.addActionListener(this);
		optionsMenu.add(exploredSiteItem);

		// Create minerals menu item.
		mineralItem = new WebCheckBoxMenuItem(Msg.getString("NavigatorWindow.menu.map.showMinerals"), //$NON-NLS-1$
				mapLayerPanel.hasMapLayer(mineralLayer));
		mineralItem.addActionListener(this);
		optionsMenu.add(mineralItem);

		optionsMenu.pack();
	}
 
Example #8
Source File: WebPathField.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
public WebPopupMenu getRootsMenu ()
{
    return rootsMenu;
}
 
Example #9
Source File: WebPathField.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
public void setRootsMenu ( final WebPopupMenu rootsMenu, final int childrenCount )
{
    this.rootsMenu = rootsMenu;
    this.rootsMenuItemsCount = childrenCount;
}
 
Example #10
Source File: TabMenuButton.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void actionPerformed ( @NotNull final ActionEvent e )
{
    // Creating menu to show
    final WebPopupMenu menu = new WebPopupMenu ( StyleId.tabbedpaneTabMenu.at ( this ) );
    final ButtonGroup group = new ButtonGroup ();
    for ( int tabIndex = 0; tabIndex < tabbedPane.getTabCount (); tabIndex++ )
    {
        final TabMenuItem menuItem = new TabMenuItem ( tabbedPane, menu, tabIndex );
        menu.add ( menuItem );
        group.add ( menuItem );
    }

    // Positioning it according to tab placement
    final boolean ltr = tabbedPane.getComponentOrientation ().isLeftToRight ();
    final Dimension menuSize = menu.getPreferredSize ();
    if ( tabbedPane.getTabPlacement () == JTabbedPane.TOP )
    {
        menu.show (
                this,
                ltr ? getWidth () - menuSize.width : 0,
                getHeight ()
        );
    }
    else if ( tabbedPane.getTabPlacement () == JTabbedPane.BOTTOM )
    {
        menu.show (
                this,
                ltr ? getWidth () - menuSize.width : 0,
                -menuSize.height
        );
    }
    else if ( ltr && tabbedPane.getTabPlacement () == JTabbedPane.LEFT ||
            !ltr && tabbedPane.getTabPlacement () == JTabbedPane.RIGHT )
    {
        menu.show (
                this,
                getWidth (),
                getHeight () - menuSize.height
        );
    }
    else if ( ltr && tabbedPane.getTabPlacement () == JTabbedPane.RIGHT ||
            !ltr && tabbedPane.getTabPlacement () == JTabbedPane.LEFT )
    {
        menu.show (
                this,
                -menuSize.width,
                getHeight () - menuSize.height
        );
    }
}
 
Example #11
Source File: TabMenuItem.java    From weblaf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constucts new {@link TabMenuItem}.
 *
 * @param tabbedPane {@link JTabbedPane} this item represents tab from
 * @param menu       {@link WebPopupMenu} this item will be added to
 * @param index      tab index
 */
public TabMenuItem ( @NotNull final JTabbedPane tabbedPane, @NotNull final WebPopupMenu menu, final int index )
{
    super ( StyleId.tabbedpaneTabMenuItem.at ( menu ) );
    this.tabbedPane = tabbedPane;
    this.index = index;

    // Enabled state
    setEnabled ( tabbedPane.isEnabledAt ( index ) );

    // Selected state
    setSelected ( tabbedPane.getSelectedIndex () == index );

    // Retrieving icon and title
    final Icon icon;
    final String title;
    final WTabbedPaneUI ui = LafUtils.getUI ( tabbedPane );
    if ( ui != null )
    {
        final Tab tab = ui.getTab ( index );
        if ( tab.getComponent () instanceof TabComponent )
        {
            // Retrieving icon and title from tab component
            final TabComponent tabComponent = ( TabComponent ) tab.getComponent ();
            icon = tabComponent.getIcon ();
            title = tabComponent instanceof JComponent && UILanguageManager.isRegisteredComponent ( ( JComponent ) tabComponent ) ?
                    UILanguageManager.getComponentKey ( ( JComponent ) tabComponent ) :
                    tabComponent.getTitle ();
        }
        else
        {
            // Trying to retrieve icon and title from tab directly
            icon = tab.getIcon ();
            title = UILanguageManager.isRegisteredComponent ( tab ) ?
                    UILanguageManager.getComponentKey ( tab ) :
                    tab.getText ();
        }
    }
    else
    {
        // Retrieving icon and title provided by JTabbedPane
        icon = tabbedPane.getIconAt ( index );
        title = tabbedPane.getTitleAt ( index );
    }

    // Using retrieved icon and title
    setIcon ( icon );

    // Updating text
    if ( icon != null || title != null )
    {
        // Checking for translation
        // todo This won't work with data correctly
        if ( title != null && LM.contains ( title ) )
        {
            // Using translation
            setLanguage ( title );
        }
        else
        {
            // Using plain text
            setText ( title );
        }
    }
    else
    {
        // Using default fallback title
        setLanguage ( "weblaf.tabbedpane.menu.tab", index + 1 );
    }

    // Tab selection action
    addActionListener ( this );
}
 
Example #12
Source File: PopupMenuGenerator.java    From weblaf with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs new {@link PopupMenuGenerator} using default {@link WebPopupMenu} and the specified {@link StyleId}.
 *
 * @param id {@link StyleId}
 */
public PopupMenuGenerator ( @NotNull final StyleId id )
{
    this ( new WebPopupMenu ( id ) );
}
 
Example #13
Source File: PopupMenuGenerator.java    From weblaf with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs new {@link PopupMenuGenerator} using the specified {@link WebPopupMenu}.
 *
 * @param menu {@link WebPopupMenu}
 */
public PopupMenuGenerator ( @NotNull final WebPopupMenu menu )
{
    super ( menu );
}
 
Example #14
Source File: ListView.java    From desktopclient-java with GNU General Public License v3.0 votes vote down vote up
protected abstract WebPopupMenu rightClickMenu(List<V> selectedValues);