Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2003-2010 Flamingo Kirill Grouchnikov
* and Topologi.
* Contributed by Rick Jelliffe of Topologi
* in January 2006. in All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* o Neither the name of Flamingo Kirill Grouchnikov Topologi nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.pushingpixels.flamingo.internal.ui.bcb;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
import org.pushingpixels.flamingo.api.bcb.*;
import org.pushingpixels.flamingo.api.common.*;
import org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonKind;
import org.pushingpixels.flamingo.api.common.JCommandButton.CommandButtonPopupOrientationKind;
import org.pushingpixels.flamingo.api.common.icon.EmptyResizableIcon;
import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
import org.pushingpixels.flamingo.api.common.model.PopupButtonModel;
import org.pushingpixels.flamingo.api.common.popup.*;
import org.pushingpixels.flamingo.internal.utils.FlamingoUtilities;
/**
* Basic UI for breadcrumb bar ({@link JBreadcrumbBar}).
*
* @author Topologi
* @author Kirill Grouchnikov
* @author Pawel Hajda
*/
public class BasicBreadcrumbBarUI extends BreadcrumbBarUI {
/**
* The associated breadcrumb bar.
*/
protected JBreadcrumbBar breadcrumbBar;
protected JPanel mainPanel;
protected JScrollablePanel scrollerPanel;
protected ComponentListener componentListener;
protected JCommandButton dummy;
/**
* Contains the item path.
*/
protected LinkedList modelStack;
protected LinkedList buttonStack;
protected BreadcrumbPathListener pathListener;
private AtomicInteger atomicCounter;
/*
* (non-Javadoc)
*
* @see javax.swing.plaf.ComponentUI#createUI(javax.swing.JComponent)
*/
public static ComponentUI createUI(JComponent c) {
return new BasicBreadcrumbBarUI();
}
/*
* (non-Javadoc)
*
* @see javax.swing.plaf.ComponentUI#installUI(javax.swing.JComponent)
*/
@Override
public void installUI(JComponent c) {
this.breadcrumbBar = (JBreadcrumbBar) c;
this.modelStack = new LinkedList();
this.buttonStack = new LinkedList();
installDefaults(this.breadcrumbBar);
installComponents(this.breadcrumbBar);
installListeners(this.breadcrumbBar);
c.setLayout(createLayoutManager());
if (this.breadcrumbBar.getCallback() != null) {
SwingWorker, Void> worker = new SwingWorker, Void>() {
@Override
protected List doInBackground()
throws Exception {
return breadcrumbBar.getCallback().getPathChoices(null);
}
@Override
protected void done() {
try {
pushChoices(new BreadcrumbItemChoices(null, get()));
} catch (Exception exc) {
}
}
};
worker.execute();
}
this.dummy = new JCommandButton("Dummy", new EmptyResizableIcon(16));
this.dummy.setDisplayState(CommandButtonDisplayState.MEDIUM);
this.dummy
.setCommandButtonKind(CommandButtonKind.ACTION_AND_POPUP_MAIN_ACTION);
}
/*
* (non-Javadoc)
*
* @see javax.swing.plaf.ComponentUI#uninstallUI(javax.swing.JComponent)
*/
@Override
public void uninstallUI(JComponent c) {
c.setLayout(null);
uninstallListeners((JBreadcrumbBar) c);
uninstallComponents((JBreadcrumbBar) c);
uninstallDefaults((JBreadcrumbBar) c);
this.breadcrumbBar = null;
}
protected void installDefaults(JBreadcrumbBar bar) {
Font currFont = bar.getFont();
if ((currFont == null) || (currFont instanceof UIResource)) {
Font font = FlamingoUtilities.getFont(null, "BreadcrumbBar.font",
"Button.font", "Panel.font");
bar.setFont(font);
}
}
protected void installComponents(JBreadcrumbBar bar) {
this.mainPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
this.mainPanel.setBorder(new EmptyBorder(0, 0, 0, 0));
this.mainPanel.setOpaque(false);
this.scrollerPanel = new JScrollablePanel(this.mainPanel,
JScrollablePanel.ScrollType.HORIZONTALLY);
bar.add(this.scrollerPanel, BorderLayout.CENTER);
}
protected void installListeners(final JBreadcrumbBar bar) {
this.atomicCounter = new AtomicInteger(0);
this.componentListener = new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
updateComponents();
}
};
bar.addComponentListener(this.componentListener);
this.pathListener = new BreadcrumbPathListener() {
private SwingWorker pathChangeWorker;
@Override
public void breadcrumbPathEvent(BreadcrumbPathEvent event) {
final int indexOfFirstChange = event.getIndexOfFirstChange();
if ((this.pathChangeWorker != null)
&& !this.pathChangeWorker.isDone()) {
this.pathChangeWorker.cancel(true);
}
this.pathChangeWorker = new SwingWorker() {
@Override
protected Void doInBackground() throws Exception {
atomicCounter.incrementAndGet();
synchronized (BasicBreadcrumbBarUI.this) {
// remove stack elements after the first change
if (indexOfFirstChange == 0) {
modelStack.clear();
} else {
int toLeave = indexOfFirstChange * 2 + 1;
while (modelStack.size() > toLeave)
modelStack.removeLast();
}
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
updateComponents();
}
});
if (indexOfFirstChange == 0) {
List rootChoices = breadcrumbBar
.getCallback().getPathChoices(null);
BreadcrumbItemChoices bic = new BreadcrumbItemChoices(
null, rootChoices);
if (!this.isCancelled()) {
publish(bic);
}
}
List items = breadcrumbBar.getModel()
.getItems();
if (items != null) {
for (int itemIndex = indexOfFirstChange; itemIndex < items
.size(); itemIndex++) {
if (this.isCancelled())
break;
BreadcrumbItem item = items.get(itemIndex);
publish(item);
// now check if it has any children
List subPath = new ArrayList();
for (int j = 0; j <= itemIndex; j++) {
subPath.add(items.get(j));
}
BreadcrumbItemChoices bic = new BreadcrumbItemChoices(
item, breadcrumbBar.getCallback()
.getPathChoices(subPath));
if ((bic.getChoices() != null)
&& (bic.getChoices().length > 0)) {
// add the selector - the current item has
// children
publish(bic);
}
}
}
return null;
}
@Override
protected void process(List