[nb-tabbedpane~subversion:11] Started to change the code for slide button icons
- From: eppleton@kenai.com
- To: commits@nb-tabbedpane.kenai.com
- Subject: [nb-tabbedpane~subversion:11] Started to change the code for slide button icons
- Date: Thu, 30 Jul 2009 17:07:10 +0000
Project: nb-tabbedpane
Repository: subversion
Revision: 11
Author: eppleton
Date: 2009-07-30 17:07:08 UTC
Link:
Log Message:
------------
Started to change the code for slide button icons
Revisions:
----------
11
Modified Paths:
---------------
NBTabbedPane/src/core/windows/modules/othertabs/TabButton.java
NBTabbedPane/src/core/windows/modules/othertabs/CloseableTabComponent.java
NBTabbedPane/src/core/windows/modules/othertabs/JTabbedAdapter.java
Diffs:
------
Index: NBTabbedPane/src/core/windows/modules/othertabs/TabButton.java
===================================================================
--- NBTabbedPane/src/core/windows/modules/othertabs/TabButton.java
(revision 10)
+++ NBTabbedPane/src/core/windows/modules/othertabs/TabButton.java
(revision 11)
@@ -39,9 +39,22 @@
package core.windows.modules.othertabs;
import core.windows.modules.othertabs.CloseableTabComponent.SaveBoundsIcon;
+import java.awt.Component;
+import java.awt.Image;
import java.awt.event.MouseEvent;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.imageio.ImageIO;
import javax.swing.Icon;
+import javax.swing.ImageIcon;
import javax.swing.JLabel;
+import org.netbeans.swing.tabcontrol.TabDisplayer;
+import org.netbeans.swing.tabcontrol.WinsysInfoForTabbedContainer;
+import org.netbeans.swing.tabcontrol.plaf.TabControlButton;
+import org.netbeans.swing.tabcontrol.plaf.TabControlButtonFactory;
/**
*
@@ -49,10 +62,10 @@
*/
public class TabButton extends JLabel {
- SaveBoundsIcon enabled;
- SaveBoundsIcon hovered;
- SaveBoundsIcon pressed;
+ private static IconLoader iconCache;
String command;
+ int iconsIndex;
+ NBTabbedPane parent;
/**
* Returns teh command that is (maybe) executed when the Button is
pressed
@@ -62,22 +75,44 @@
return command;
}
- public TabButton(String command, Icon enabledIcon, Icon hoveredIcon,
Icon pressedIcon, Icon disabledIcon) {
+ public TabButton(String command, NBTabbedPane parent) {
super();
this.command = command;
- enabled = new SaveBoundsIcon(enabledIcon);
- hovered = new SaveBoundsIcon(hoveredIcon);
- pressed = new SaveBoundsIcon(pressedIcon);
+ this.parent = parent;
+
+ SaveBoundsIcon enabled = getButtonIcon(getButtonIconsIndex(),
TabControlButton.STATE_DEFAULT);
setIcon(enabled);
setSize(enabled.getIconWidth(), enabled.getIconHeight());
}
void setHovered() {
- setIcon(hovered);
+ setIcon(getButtonIcon(getButtonIconsIndex(),
TabControlButton.STATE_ROLLOVER));
}
+ protected int getButtonIconsIndex() {
+ int retValue = TabControlButton.ID_CLOSE_BUTTON;
+ if (command == TabDisplayer.COMMAND_ENABLE_AUTO_HIDE) {
+ retValue = TabControlButton.ID_PIN_BUTTON;
+ Component currentTab = parent.getSelectedComponent();
+ if (null != currentTab) {
+ WinsysInfoForTabbedContainer winsysInfo =
parent.getWinsysInfoForTabbedContainer();
+ if (null != winsysInfo) {
+ Object orientation =
winsysInfo.getOrientation(currentTab);
+ if (TabDisplayer.ORIENTATION_EAST.equals(orientation)) {
+ retValue = TabControlButton.ID_SLIDE_RIGHT_BUTTON;
+ } else if
(TabDisplayer.ORIENTATION_WEST.equals(orientation)) {
+ retValue = TabControlButton.ID_SLIDE_LEFT_BUTTON;
+ } else if
(TabDisplayer.ORIENTATION_SOUTH.equals(orientation)) {
+ retValue = TabControlButton.ID_SLIDE_DOWN_BUTTON;
+ }
+ }
+ }
+ }
+ return retValue;
+ }
+
void setEnabled() {
- setIcon(enabled);
+ setIcon(getButtonIcon(getButtonIconsIndex(),
TabControlButton.STATE_DEFAULT));
}
public void mouseMoved(MouseEvent e) {
@@ -88,4 +123,109 @@
setEnabled();
}
}
+
+ public SaveBoundsIcon getButtonIcon(int buttonId, int buttonState) {
+ SaveBoundsIcon res = null;
+ initIcons();
+ String[] paths = buttonIconPaths.get(buttonId);
+ if (null != paths && buttonState >= 0 && buttonState < paths.length)
{
+ res = getIcon(paths[buttonState]);
+ }
+ return res;
+ }
+
+ public static SaveBoundsIcon getIcon(String iconPath) {
+ if (null == iconCache) {
+ iconCache = new IconLoader();
+ }
+ return iconCache.obtainIcon(iconPath);
+ }
+
+ private static void initIcons() {
+ if (null == buttonIconPaths) {
+ buttonIconPaths = new HashMap<Integer, String[]>(7);
+
+ //close button
+ String[] iconPaths = new String[4];
+ iconPaths[TabControlButton.STATE_DEFAULT] =
"org/netbeans/swing/tabcontrol/resources/mac_bigclose_enabled.png"; // NOI18N
+ iconPaths[TabControlButton.STATE_PRESSED] =
"org/netbeans/swing/tabcontrol/resources/mac_bigclose_pressed.png"; // NOI18N
+ iconPaths[TabControlButton.STATE_DISABLED] =
iconPaths[TabControlButton.STATE_DEFAULT];
+ iconPaths[TabControlButton.STATE_ROLLOVER] =
"org/netbeans/swing/tabcontrol/resources/mac_bigclose_rollover.png"; // NOI18N
+ buttonIconPaths.put(TabControlButton.ID_CLOSE_BUTTON, iconPaths);
+
+ //slide/pin button
+ iconPaths = new String[4];
+ iconPaths[TabControlButton.STATE_DEFAULT] =
"org/netbeans/swing/tabcontrol/resources/mac_slideright_enabled.png"; //
NOI18N
+ iconPaths[TabControlButton.STATE_PRESSED] =
"org/netbeans/swing/tabcontrol/resources/mac_slideright_pressed.png"; //
NOI18N
+ iconPaths[TabControlButton.STATE_DISABLED] =
iconPaths[TabControlButton.STATE_DEFAULT];
+ iconPaths[TabControlButton.STATE_ROLLOVER] =
"org/netbeans/swing/tabcontrol/resources/mac_slideright_rollover.png"; //
NOI18N
+ buttonIconPaths.put(TabControlButton.ID_SLIDE_RIGHT_BUTTON,
iconPaths);
+
+ iconPaths = new String[4];
+ iconPaths[TabControlButton.STATE_DEFAULT] =
"org/netbeans/swing/tabcontrol/resources/mac_slideleft_enabled.png"; // NOI18N
+ iconPaths[TabControlButton.STATE_PRESSED] =
"org/netbeans/swing/tabcontrol/resources/mac_slideleft_pressed.png"; // NOI18N
+ iconPaths[TabControlButton.STATE_DISABLED] =
iconPaths[TabControlButton.STATE_DEFAULT];
+ iconPaths[TabControlButton.STATE_ROLLOVER] =
"org/netbeans/swing/tabcontrol/resources/mac_slideleft_rollover.png"; //
NOI18N
+ buttonIconPaths.put(TabControlButton.ID_SLIDE_LEFT_BUTTON,
iconPaths);
+
+ iconPaths = new String[4];
+ iconPaths[TabControlButton.STATE_DEFAULT] =
"org/netbeans/swing/tabcontrol/resources/mac_slidebottom_enabled.png"; //
NOI18N
+ iconPaths[TabControlButton.STATE_PRESSED] =
"org/netbeans/swing/tabcontrol/resources/mac_slidebottom_pressed.png"; //
NOI18N
+ iconPaths[TabControlButton.STATE_DISABLED] =
iconPaths[TabControlButton.STATE_DEFAULT];
+ iconPaths[TabControlButton.STATE_ROLLOVER] =
"org/netbeans/swing/tabcontrol/resources/mac_slidebottom_rollover.png"; //
NOI18N
+ buttonIconPaths.put(TabControlButton.ID_SLIDE_DOWN_BUTTON,
iconPaths);
+
+ iconPaths = new String[4];
+ iconPaths[TabControlButton.STATE_DEFAULT] =
"org/netbeans/swing/tabcontrol/resources/mac_pin_enabled.png"; // NOI18N
+ iconPaths[TabControlButton.STATE_PRESSED] =
"org/netbeans/swing/tabcontrol/resources/mac_pin_pressed.png"; // NOI18N
+ iconPaths[TabControlButton.STATE_DISABLED] =
iconPaths[TabControlButton.STATE_DEFAULT];
+ iconPaths[TabControlButton.STATE_ROLLOVER] =
"org/netbeans/swing/tabcontrol/resources/mac_pin_rollover.png"; // NOI18N
+ buttonIconPaths.put(TabControlButton.ID_PIN_BUTTON, iconPaths);
+ }
+ }
+ private static Map<Integer, String[]> buttonIconPaths;
+
+ /**
+ * Loader for icons. Caches loaded icons using hash map.
+ */
+ final private static class IconLoader {
+ /* mapping <String, Icon> from resource paths to icon objects, used
as cache */
+
+ private Map<String, SaveBoundsIcon> paths2Icons;
+
+ /**
+ * Finds and returns icon instance from cache, if present. Otherwise
+ * loads icon using given resource path and stores icon into cache
for
+ * next access.
+ *
+ * @return icon image
+ */
+ public SaveBoundsIcon obtainIcon(String iconPath) {
+ if (paths2Icons == null) {
+ paths2Icons = new HashMap<String, SaveBoundsIcon>(6);
+ }
+ SaveBoundsIcon icon = paths2Icons.get(iconPath);
+ if (icon == null) {
+ // not yet in cache, load and store
+ Image image = loadImage(iconPath);
+ if (image == null) {
+ throw new IllegalArgumentException("Icon with resource
path: " + iconPath + " can't be loaded, probably wrong path.");
+ }
+ icon = new SaveBoundsIcon(new ImageIcon(image));
+ paths2Icons.put(iconPath, icon);
+ }
+ return icon;
+ }
+ } // end of IconLoader
+
+ private static Image loadImage(String path) {
+ try {
+ URL url = TabControlButtonFactory.class.getResource("/" + path);
+ return ImageIO.read(url);
+ } catch (Exception e) {
+ Logger.getLogger(TabControlButtonFactory.class.getName()).
+ log(Level.WARNING, "Cannot load image", e);
+ return null;
+ }
+ }
}
Index:
NBTabbedPane/src/core/windows/modules/othertabs/CloseableTabComponent.java
===================================================================
---
NBTabbedPane/src/core/windows/modules/othertabs/CloseableTabComponent.java
(revision 10)
+++
NBTabbedPane/src/core/windows/modules/othertabs/CloseableTabComponent.java
(revision 11)
@@ -83,38 +83,11 @@
/** TODO support tooltip via shared instance */
/** TODO enable sliding **/
/** TODO read icons from properties and make them customizable */
- Icon closeEnabled =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_bigclose_enabled.png");
- Icon closeHovered =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_bigclose_rollover.png");
- Icon closePressed =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_bigclose_pressed.png");
-
if
(parent.getWinsysInfoForTabbedContainer().isTopComponentSlidingEnabled((TopComponent)
component)) {
- Icon slideEnabled = null;
- Icon slideHovered = null;
- Icon slidePressed = null;
-
- Object orientation =
parent.getWinsysInfoForTabbedContainer().getOrientation(component);
- if (orientation == TabDisplayer.ORIENTATION_WEST) {
- slideEnabled =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_slideleft_enabled.png");
- slideHovered =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_slideleft_rollover.png");
- slidePressed =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_slideleft_pressed.png");
- System.out.println("WEST");
- } else if (orientation == TabDisplayer.ORIENTATION_EAST) {
- slideEnabled =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_slideright_enabled.png");
- slideHovered =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_slideright_rollover.png");
- slidePressed =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_slideright_pressed.png");
- System.out.println("EAST");
- } else if (orientation == TabDisplayer.ORIENTATION_SOUTH) {
- slideEnabled =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_slidebottom_enabled.png");
- slideHovered =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_slidebottom_rollover.png");
- slidePressed =
TabControlButtonFactory.getIcon("org/netbeans/swing/tabcontrol/resources/mac_slidebottom_pressed.png");
- System.out.println("BOTTOM");
- }
- if (slideEnabled != null) {
- TabButton slideButton = new
TabButton(TabDisplayer.COMMAND_ENABLE_AUTO_HIDE, slideEnabled, slideHovered,
slidePressed, closeEnabled);
- buttonContainer.add(slideButton);
- }
+ TabButton slideButton = new
TabButton(TabDisplayer.COMMAND_ENABLE_AUTO_HIDE, parent);
+ buttonContainer.add(slideButton);
}
- TabButton closeButton = new TabButton(TabbedContainer.COMMAND_CLOSE,
closeEnabled, closeHovered, closePressed, closeEnabled);
+ TabButton closeButton = new TabButton(TabbedContainer.COMMAND_CLOSE,
parent);
/** TODO selection border paints behind the panel */
buttonContainer.setOpaque(false);
closeButton.setOpaque(false);
Index: NBTabbedPane/src/core/windows/modules/othertabs/JTabbedAdapter.java
===================================================================
--- NBTabbedPane/src/core/windows/modules/othertabs/JTabbedAdapter.java
(revision 10)
+++ NBTabbedPane/src/core/windows/modules/othertabs/JTabbedAdapter.java
(revision 11)
@@ -55,26 +55,17 @@
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
-import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
-
-/** TODO try to get rid of these dependencies */
-/** if possible also of this: */
import org.netbeans.swing.tabcontrol.customtabs.Tabbed;
-
-
import org.netbeans.swing.tabcontrol.ComponentConverter;
import org.netbeans.swing.tabcontrol.TabData;
-import org.netbeans.swing.tabcontrol.TabDisplayer;
import org.netbeans.swing.tabcontrol.TabbedContainer;
import org.netbeans.swing.tabcontrol.WinsysInfoForTabbedContainer;
import org.netbeans.swing.tabcontrol.event.TabActionEvent;
import org.netbeans.swing.tabcontrol.plaf.EqualPolygon;
import org.openide.util.WeakListeners;
-import org.openide.windows.Mode;
import org.openide.windows.TopComponent;
-import org.openide.windows.WindowManager;
/**
* A class that implements the Tabbed interface for a JTabbedPane
(NBTabbedPane)
|
[nb-tabbedpane~subversion:11] Started to change the code for slide button icons |
eppleton | 07/30/2009 |





