it.tidalwave.netbeans.swing.impl.ToolBarFromLayer Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* OpenBlueSky - NetBeans Platform Enhancements
* Copyright (C) 2006-2012 by Tidalwave s.a.s. (http://www.tidalwave.it)
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* WWW: http://openbluesky.java.net
* SCM: https://bitbucket.org/tidalwave/openbluesky-src
*
**********************************************************************************************************************/
package it.tidalwave.netbeans.swing.impl;
import java.awt.Component;
import java.util.logging.Logger;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JToolBar;
import org.openide.awt.Actions;
import org.openide.util.ContextAwareAction;
import org.openide.util.Lookup;
import org.openide.util.LookupEvent;
import org.openide.util.LookupListener;
import org.openide.util.Mutex;
import org.openide.util.Utilities;
import org.openide.util.actions.Presenter;
import org.openide.util.lookup.Lookups;
/**
* Utility for connecting layer entries to a toolbar.
* Similar to {@link Utilities#actionsForPath} and {@link Utilities#actionsToPopup(Action[], Lookup)}.
*
* From https://hg.kenai.com/hg/sqe~trunk/raw-file/tip/core.ui.components/src/org/nbheaven/sqe/core/ui/components/toolbar/ToolBarFromLayer.java
*/
public class ToolBarFromLayer {
private ToolBarFromLayer() {}
/**
* Makes a toolbar display actions or other components registered in a layer path.
* Dynamic changes to the layer should result in changes to the toolbar.
* Actions may wish to set the property {@code hideActionText} to true.
* @param toolBar a toolbar which will be fully populated
* @param path a layer path to load actions from
* @param context context to pass to any context-sensitive actions, or null
* @param largeIcons true to try to use 24x24 icons for actions defining {@code iconBase},
* false to use the default (usually 16x16) icons
*/
public static void connect(final JToolBar toolBar, String path, final Lookup context, final boolean largeIcons) {
final Lookup.Result