001: /*
002: * Copyright 2005 Patrick Gotthardt
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package com.pagosoft.plaf;
017:
018: import javax.swing.*;
019: import javax.swing.event.*;
020: import javax.swing.plaf.*;
021: import javax.swing.plaf.basic.*;
022: import java.awt.*;
023: import java.awt.event.*;
024: import java.beans.PropertyChangeEvent;
025: import java.beans.PropertyChangeListener;
026: import java.util.logging.Logger;
027:
028: /**
029: * @todo Remove rollovertab-code for Java 5.0 - their implementation is much cleaner/faster than mine.
030: */
031: public class PgsTabbedPaneUI extends BasicTabbedPaneUI {
032: private boolean paintFocus;
033: private int rolloverTabIndex;
034: private TabRolloverHandler tabHandler;
035: private MyPropertyChangeHandler propHandler;
036: private TabbedPaneMouseWheelScroller tabScrollHandler;
037: private TabSelectionMouseHandler tabSelectionHandler;
038:
039: private static Logger logger = Logger.getLogger("PgsTabbedPaneUI");
040:
041: public static final String IS_SUB_TAB = "pgs.isSubTab";
042: public static final String IS_BUTTON_STYLE = "pgs.isButtonStyle";
043: public static final String NO_BORDER = "pgs.noBorder";
044:
045: public static ComponentUI createUI(JComponent c) {
046: return new PgsTabbedPaneUI();
047: }
048:
049: protected void installDefaults() {
050: super .installDefaults();
051: updateBackgroundOpacity();
052: paintFocus = UIManager.getBoolean("TabbedPane.focusPainted");
053: }
054:
055: protected void installListeners() {
056: super .installListeners();
057: if (tabHandler == null) {
058: tabHandler = new TabRolloverHandler();
059: }
060: tabPane.addMouseListener(tabHandler);
061: tabPane.addMouseMotionListener(tabHandler);
062:
063: if (propHandler == null) {
064: propHandler = new MyPropertyChangeHandler();
065: }
066: tabPane.addPropertyChangeListener(propHandler);
067:
068: if (PlafOptions.isWheelTabbedPaneEnabled()) {
069: if (tabScrollHandler == null) {
070: tabScrollHandler = new TabbedPaneMouseWheelScroller();
071: }
072: tabPane.addMouseWheelListener(tabScrollHandler);
073: }
074:
075: if (PlafOptions.isTabbedPaneRightClickSelectionEnabled()) {
076: if (tabSelectionHandler == null) {
077: tabSelectionHandler = new TabSelectionMouseHandler();
078: }
079: tabPane.addMouseListener(tabSelectionHandler);
080: }
081:
082: if (PlafOptions.isTabReorderingEnabled()) {
083: enableReordering();
084: }
085: }
086:
087: protected void uninstallListeners() {
088: super .uninstallListeners();
089: tabPane.removeMouseListener(tabHandler);
090: tabPane.removeMouseMotionListener(tabHandler);
091: tabPane.removePropertyChangeListener(propHandler);
092:
093: if (tabScrollHandler != null) {
094: tabPane.removeMouseWheelListener(tabScrollHandler);
095: }
096:
097: if (tabSelectionHandler != null) {
098: tabPane.removeMouseListener(tabSelectionHandler);
099: }
100:
101: disableReordering();
102: }
103:
104: private void updateBackgroundOpacity() {
105: if (isSubTab() || isButtonStyle()) {
106: tabPane.setOpaque(true);
107: if (isSubTab()) {
108: tabPane.setBackground(UIManager
109: .getColor("TabbedPane.background"));
110: } else if (isButtonStyle()) {
111: tabPane.setBackground(UIManager
112: .getColor("TabbedPane.buttonStyle.background"));
113: }
114: } else {
115: tabPane.setOpaque(false);
116: }
117: }
118:
119: /**
120: * This method is a hack or workaround for Jython...
121: */
122: private boolean checkBooleanClientProperty(Object key) {
123: Object o = tabPane.getClientProperty(key);
124: if (o == null) {
125: return false;
126: }
127:
128: if (o instanceof Boolean) {
129: return ((Boolean) o).booleanValue();
130: }
131: // Wow. That's unexpected...
132: if (o instanceof Integer) {
133: // Jython seems to use Integers instead of booleans,
134: // as we know it, let's be compatible to it.
135: return ((Integer) o).intValue() != 0;
136: }
137: // Well... we know the property has been set, but
138: // it seems like the user used wrong input. We just write out something
139: // and return true.
140: logger.warning("It seems like you've used a wrong type for '"
141: + key + "'. It should be a boolean, but is a "
142: + o.getClass().getName());
143: return true;
144: }
145:
146: private boolean isSubTab() {
147: return checkBooleanClientProperty(IS_SUB_TAB);
148: }
149:
150: private boolean isButtonStyle() {
151: return checkBooleanClientProperty(IS_BUTTON_STYLE);
152: }
153:
154: private void mySetRolloverTab(int x, int y) {
155: mySetRolloverTab(myTabForCoordinate(tabPane, x, y));
156: }
157:
158: private int myTabForCoordinate(JTabbedPane pane, int x, int y) {
159: Point p = new Point(x, y);
160: int tabCount = tabPane.getTabCount();
161: for (int i = 0; i < tabCount; i++) {
162: if (rects[i].contains(p.x, p.y)) {
163: return i;
164: }
165: }
166: return -1;
167: }
168:
169: protected void mySetRolloverTab(int index) {
170: tabPane.repaint();
171: rolloverTabIndex = index;
172: }
173:
174: protected int getRolloverTab() {
175: return rolloverTabIndex;
176: }
177:
178: protected void paintTabBackground(Graphics g, int tabPlacement,
179: int tabIndex, int x, int y, int w, int h, boolean isSelected) {
180: if (isButtonStyle()) {
181: if (isSelected) {
182: g
183: .setColor(UIManager
184: .getColor("TabbedPane.buttonStyle.selectedBackground"));
185: g.fillRect(x + 2, y + 2, w - 4, h - 4);
186: }
187: if (tabIndex == getRolloverTab()) {
188: g
189: .setColor(UIManager
190: .getColor("TabbedPane.buttonStyle.rolloverBackground"));
191: if (isSelected) {
192: g.fillRect(x + 2, y + 2, w - 4, h - 4);
193: } else {
194: g.fillRect(x, y, w, h);
195: }
196: }
197: return;
198: }
199: if (isSubTab() && !isSelected) {
200: return;
201: }
202: Graphics2D gfx = (Graphics2D) g;
203: if (isSelected) {
204: gfx.setColor(UIManager.getColor("TabbedPane.selected"));
205: } else {
206: Color a = UIManager.getColor("TabbedPane.tabGradientStart");
207: Color b = UIManager.getColor("TabbedPane.tabGradientEnd");
208: gfx
209: .setPaint(new GradientPaint(0, y + 1, a, 0, y + 1
210: + h, b));
211: }
212:
213: switch (tabPlacement) {
214: case LEFT:
215: gfx.fill(new Rectangle(x, y, w + 2, h));
216: break;
217: case RIGHT:
218: gfx.fill(new Rectangle(x - 2, y, w + 2, h));
219: break;
220: case BOTTOM:
221: gfx.fill(new Rectangle(x, y - 2, w, h + 2));
222: break;
223: case TOP:
224: default:
225: gfx.fill(new Rectangle(x, y, w - 2, h + 2));
226: break;
227: }
228:
229: // shall we paint a rollover-effect as well?
230: if (!isSelected && tabIndex == getRolloverTab()) {
231: RenderingHints oldHints = gfx.getRenderingHints();
232: gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
233: RenderingHints.VALUE_ANTIALIAS_ON);
234: gfx.setColor(PgsLookAndFeel.getPrimaryControl());
235: Stroke oldStroke = gfx.getStroke();
236: gfx.setStroke(PgsUtils.rolloverBorderStroke);
237: switch (tabPlacement) {
238: case LEFT:
239: gfx.drawRoundRect(x + 1, y + 1, w + 1, h - 3, 5, 5);
240: break;
241: case RIGHT:
242: gfx.drawRoundRect(x - 2, y + 1, w + 1, h - 2, 5, 5);
243: break;
244: case BOTTOM:
245: gfx.drawRoundRect(x + 1, y - 2, w - 3, h, 5, 5);
246: break;
247: case TOP:
248: default:
249: gfx.drawRoundRect(x + 1, y + 1, w - 4, h + 1, 5, 5);
250: break;
251: }
252: gfx.setStroke(oldStroke);
253: gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
254: oldHints.get(RenderingHints.KEY_ANTIALIASING));
255: //gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
256: }
257: }
258:
259: protected void paintTabBorder(Graphics g, int tabPlacement,
260: int tabIndex, int x, int y, int w, int h, boolean isSelected) {
261: if (isButtonStyle()) {
262: if (isSelected) {
263: g
264: .setColor(UIManager
265: .getColor("TabbedPane.buttonStyle.selectedBorder"));
266: g.drawRect(x + 2, y + 2, w - 4, h - 4);
267: }
268: if (tabIndex == getRolloverTab()) {
269: g
270: .setColor(UIManager
271: .getColor("TabbedPane.buttonStyle.rolloverBorder"));
272: if (isSelected) {
273: g.drawRect(x + 2, y + 2, w - 4, h - 4);
274: } else {
275: g.drawRect(x, y, w, h);
276: }
277: }
278: return;
279: }
280: if (isSubTab() && !isSelected) {
281: g.setColor(PgsLookAndFeel.getControlDarkShadow());
282: g.drawLine(x + w - 1, y, x + w - 1, y + h);
283: return;
284: }
285: Graphics2D gfx = (Graphics2D) g;
286: gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
287: RenderingHints.VALUE_ANTIALIAS_ON);
288: gfx.setColor(PgsLookAndFeel.getControlDarkShadow());
289: if (isSubTab()) {
290: switch (tabPlacement) {
291: case LEFT:
292: gfx.drawRect(x, y, w + 2, h);
293: break;
294: case RIGHT:
295: gfx.drawRect(x - 2, y, w + 2, h);
296: break;
297: case BOTTOM:
298: gfx.drawRect(x, y - 2, w, h + 2);
299: break;
300: case TOP:
301: default:
302: gfx.drawRect(x, y, w - 2, h + 2);
303: break;
304: }
305: } else {
306: switch (tabPlacement) {
307: case LEFT:
308: gfx.drawRoundRect(x, y, w + 2, h, 5, 5);
309: break;
310: case RIGHT:
311: gfx.drawRoundRect(x - 2, y, w + 2, h, 5, 5);
312: break;
313: case BOTTOM:
314: gfx.drawRoundRect(x, y - 2, w, h + 2, 5, 5);
315: break;
316: case TOP:
317: default:
318: gfx.drawRoundRect(x, y, w - 2, h + 2, 5, 5);
319: break;
320: }
321: }
322: gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
323: RenderingHints.VALUE_ANTIALIAS_OFF);
324: }
325:
326: protected void paintFocusIndicator(Graphics g, int tabPlacement,
327: Rectangle[] rects, int tabIndex, Rectangle iconRect,
328: Rectangle textRect, boolean isSelected) {
329: if (paintFocus) {
330: super .paintFocusIndicator(g, tabPlacement, rects, tabIndex,
331: iconRect, textRect, isSelected);
332: }
333: }
334:
335: protected void paintContentBorder(Graphics g, int tabPlacement,
336: int selectedIndex) {
337: int width = tabPane.getWidth();
338: int height = tabPane.getHeight();
339: Insets insets = tabPane.getInsets();
340: Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
341:
342: int x = insets.left;
343: int y = insets.top;
344: int w = width - insets.right - insets.left;
345: int h = height - insets.top - insets.bottom;
346:
347: boolean tabsOverlapBorder = true;
348: int tabAreaWidth = 0, tabAreaHeight = 0;
349:
350: switch (tabPlacement) {
351: case LEFT:
352: tabAreaWidth = calculateTabAreaWidth(tabPlacement,
353: runCount, maxTabWidth);
354: x += tabAreaWidth;
355: if (tabsOverlapBorder) {
356: x -= tabAreaInsets.right;
357: }
358: w -= (x - insets.left);
359: break;
360: case RIGHT:
361: tabAreaWidth = calculateTabAreaWidth(tabPlacement,
362: runCount, maxTabWidth);
363: w -= tabAreaWidth;
364: if (tabsOverlapBorder) {
365: w += tabAreaInsets.left;
366: }
367: break;
368: case BOTTOM:
369: tabAreaHeight = calculateTabAreaHeight(tabPlacement,
370: runCount, maxTabHeight);
371: h -= tabAreaHeight;
372: if (tabsOverlapBorder) {
373: h += tabAreaInsets.top;
374: }
375: break;
376: case TOP:
377: default:
378: tabAreaHeight = calculateTabAreaHeight(tabPlacement,
379: runCount, maxTabHeight);
380: y += tabAreaHeight;
381: if (tabsOverlapBorder) {
382: y -= tabAreaInsets.bottom;
383: }
384: h -= (y - insets.top);
385: }
386:
387: // Fill region behind content area
388: Color color = UIManager.getColor("TabbedPane.contentAreaColor");
389: Color selectedColor = UIManager.getColor("TabbedPane.selected");
390: if (color != null) {
391: g.setColor(color);
392: } else if (selectedColor == null) {
393: g.setColor(tabPane.getBackground());
394: } else {
395: g.setColor(selectedColor);
396: }
397: g.fillRect(x, y, w, h);
398:
399: if (checkBooleanClientProperty(NO_BORDER)) {
400: return;
401: }
402:
403: g.setColor(PgsLookAndFeel.getControlDarkShadow());
404: PgsUtils.drawRoundRect(g, x, y, w - 1, h - 1);
405:
406: // stupid hack... however, it works...
407: if (selectedIndex > -1 && !isButtonStyle()) {
408: Rectangle selRect = getTabBounds(selectedIndex, calcRect);
409: g.setColor(UIManager.getColor("TabbedPane.selected"));
410: switch (tabPlacement) {
411: case JTabbedPane.TOP:
412: g.fillRect(selRect.x + 1, selRect.y + selRect.height
413: - 2, selRect.width - 2, 1);
414: if (selectedIndex == 0) {
415: g.setColor(PgsLookAndFeel.getControlDarkShadow());
416: g.drawLine(x, selRect.y + selRect.height - 2, x,
417: selRect.y + selRect.height + 2);
418: }
419: break;
420: case JTabbedPane.BOTTOM:
421: g.fillRect(selRect.x + 1, selRect.y + 1,
422: selRect.width - 1, 1);
423: if (selectedIndex == 0) {
424: g.setColor(PgsLookAndFeel.getControlDarkShadow());
425: g.drawLine(x, selRect.y - 2, x, selRect.y + 2);
426: }
427: break;
428: case JTabbedPane.LEFT:
429: g.fillRect(selRect.x + selRect.width - 2,
430: selRect.y + 1, 1, selRect.height - 1);
431: if (selectedIndex == 0) {
432: g.setColor(PgsLookAndFeel.getControlDarkShadow());
433: g.drawLine(selRect.x + selRect.width - 2,
434: selRect.y, selRect.x + selRect.width + 2,
435: selRect.y);
436: }
437: break;
438: case JTabbedPane.RIGHT:
439: g.fillRect(selRect.x + 1, selRect.y + 1, 1,
440: selRect.height - 1);
441: if (selectedIndex == 0) {
442: g.setColor(PgsLookAndFeel.getControlDarkShadow());
443: g.drawLine(selRect.x - 2, selRect.y, selRect.x + 2,
444: selRect.y);
445: }
446: break;
447: }
448: }
449: }
450:
451: protected void paintText(Graphics g, int tabPlacement, Font font,
452: FontMetrics metrics, int tabIndex, String title,
453: Rectangle textRect, boolean isSelected) {
454: PgsUtils.installAntialiasing(g);
455: super .paintText(g, tabPlacement, font, metrics, tabIndex,
456: title, textRect, isSelected);
457: PgsUtils.uninstallAntialiasing(g);
458: }
459:
460: protected class TabRolloverHandler implements MouseListener,
461: MouseMotionListener {
462: public void mouseClicked(MouseEvent e) {
463: }
464:
465: public void mouseReleased(MouseEvent e) {
466: }
467:
468: public void mouseEntered(MouseEvent e) {
469: mySetRolloverTab(e.getX(), e.getY());
470: }
471:
472: public void mouseExited(MouseEvent e) {
473: mySetRolloverTab(-1);
474: }
475:
476: public void mousePressed(MouseEvent e) {
477: }
478:
479: public void mouseDragged(MouseEvent e) {
480: }
481:
482: public void mouseMoved(MouseEvent e) {
483: mySetRolloverTab(e.getX(), e.getY());
484: }
485: }
486:
487: public class MyPropertyChangeHandler implements
488: PropertyChangeListener {
489: public void propertyChange(PropertyChangeEvent e) {
490: if (IS_SUB_TAB.equals(e.getPropertyName())
491: || IS_BUTTON_STYLE.equals(e.getPropertyName())) {
492: updateBackgroundOpacity();
493: } else if ("wheelScrolling".equals(e.getPropertyName())) {
494: if (checkBooleanClientProperty("wheelScrolling")) {
495: if (tabScrollHandler == null) {
496: tabScrollHandler = new TabbedPaneMouseWheelScroller();
497: }
498: tabPane.addMouseWheelListener(tabScrollHandler);
499: } else {
500: if (tabScrollHandler != null) {
501: tabPane
502: .removeMouseWheelListener(tabScrollHandler);
503: }
504: }
505: } else if ("rightClickSelection"
506: .equals(e.getPropertyName())) {
507: if (checkBooleanClientProperty("rightClickSelection")) {
508: if (tabSelectionHandler == null) {
509: tabSelectionHandler = new TabSelectionMouseHandler();
510: }
511: tabPane.addMouseListener(tabSelectionHandler);
512: } else {
513: if (tabSelectionHandler != null) {
514: tabPane
515: .removeMouseListener(tabSelectionHandler);
516: }
517: }
518: } else if ("tabReordering".equals(e.getPropertyName())) {
519: if (checkBooleanClientProperty("tabReordering")) {
520: enableReordering();
521: } else {
522: disableReordering();
523: }
524: }
525: }
526: }
527:
528: protected JButton createScrollButton(int direction) {
529: if (direction != SOUTH && direction != NORTH
530: && direction != EAST && direction != WEST) {
531: throw new IllegalArgumentException(
532: "Direction must be one of: "
533: + "SOUTH, NORTH, EAST or WEST");
534: }
535: return new ScrollableTabButton(direction);
536: }
537:
538: private class ScrollableTabButton extends BasicArrowButton
539: implements UIResource, SwingConstants {
540: public ScrollableTabButton(int direction) {
541: super (direction, UIManager.getColor("TabbedPane.selected"),
542: UIManager.getColor("TabbedPane.shadow"), UIManager
543: .getColor("TabbedPane.darkShadow"),
544: UIManager.getColor("TabbedPane.highlight"));
545: setOpaque(false);
546: }
547:
548: public void paint(Graphics g) {
549: Color origColor;
550: boolean isPressed, isEnabled;
551: int w, h, size;
552:
553: w = getSize().width;
554: h = getSize().height;
555: origColor = g.getColor();
556: isPressed = getModel().isPressed();
557: isEnabled = isEnabled();
558:
559: if (isEnabled && getModel().isRollover()) {
560: g.setColor(isPressed ? PgsLookAndFeel
561: .getPrimaryControlShadow() : UIManager
562: .getColor("ToolBarButton.rolloverBackground"));
563: g.fillRect(0, 0, w - 2, h - 2);
564: g.setColor(UIManager
565: .getColor("ToolBarButton.rolloverBorderColor"));
566: g.drawRect(0, 0, w - 2, h - 2);
567: }
568:
569: // If there's no room to draw arrow, bail
570: if (h < 5 || w < 5) {
571: g.setColor(origColor);
572: return;
573: }
574:
575: if (isPressed) {
576: g.translate(1, 1);
577: }
578:
579: // Draw the arrow
580: size = Math.min((h - 4) / 3, (w - 4) / 3);
581: size = Math.max(size, 2);
582: paintTriangle(g, (w - size) / 2, (h - size) / 2, size,
583: direction, isEnabled);
584:
585: // Reset the Graphics back to it's original settings
586: if (isPressed) {
587: g.translate(-1, -1);
588: }
589: g.setColor(origColor);
590: }
591: }
592:
593: private TabReorderHandler tabReorderingHandler;
594:
595: public void enableReordering() {
596: if (tabReorderingHandler == null) {
597: tabReorderingHandler = new TabReorderHandler();
598: }
599: tabPane.addMouseListener(tabReorderingHandler);
600: tabPane.addMouseMotionListener(tabReorderingHandler);
601: }
602:
603: public void disableReordering() {
604: tabPane.removeMouseListener(tabReorderingHandler);
605: tabPane.removeMouseMotionListener(tabReorderingHandler);
606: }
607:
608: public class TabReorderHandler extends MouseInputAdapter {
609: private int draggedTabIndex;
610: private int dragStartX;
611:
612: protected TabReorderHandler() {
613: draggedTabIndex = -1;
614: }
615:
616: public void mouseReleased(MouseEvent e) {
617: draggedTabIndex = -1;
618: }
619:
620: public void mouseDragged(MouseEvent e) {
621: if (draggedTabIndex == -1) {
622: return;
623: }
624:
625: int targetTabIndex = myTabForCoordinate(tabPane, e.getX(),
626: e.getY());
627: if (targetTabIndex != -1
628: && targetTabIndex != draggedTabIndex) {
629: boolean isForwardDrag = e.getX() > dragStartX;
630: tabPane.insertTab(tabPane.getTitleAt(draggedTabIndex),
631: tabPane.getIconAt(draggedTabIndex), tabPane
632: .getComponentAt(draggedTabIndex),
633: tabPane.getToolTipTextAt(draggedTabIndex),
634: isForwardDrag ? targetTabIndex + 1
635: : targetTabIndex);
636: draggedTabIndex = targetTabIndex;
637: dragStartX = e.getX();
638: tabPane.setSelectedIndex(draggedTabIndex);
639: }
640: }
641:
642: public void mousePressed(MouseEvent e) {
643: dragStartX = e.getX();
644: draggedTabIndex = myTabForCoordinate(tabPane, dragStartX, e
645: .getY());
646: }
647: }
648:
649: public class TabSelectionMouseHandler extends MouseAdapter {
650: public void mouseClicked(MouseEvent e) {
651: // we only look at the right button
652: if (SwingUtilities.isRightMouseButton(e)) {
653: JTabbedPane tabPane = (JTabbedPane) e.getSource();
654: JPopupMenu menu = new JPopupMenu();
655:
656: int tabCount = tabPane.getTabCount();
657: for (int i = 0; i < tabCount; i++) {
658: menu.add(new SelectTabAction(tabPane, i));
659: }
660:
661: menu.show(tabPane, e.getX(), e.getY());
662: }
663: }
664: }
665:
666: public class SelectTabAction extends AbstractAction {
667: private JTabbedPane tabPane;
668: private int index;
669:
670: public SelectTabAction(JTabbedPane tabPane, int index) {
671: super (tabPane.getTitleAt(index), tabPane.getIconAt(index));
672:
673: this .tabPane = tabPane;
674: this .index = index;
675: }
676:
677: public void actionPerformed(ActionEvent e) {
678: tabPane.setSelectedIndex(index);
679: }
680: }
681:
682: public class TabbedPaneMouseWheelScroller implements
683: MouseWheelListener {
684: public void mouseWheelMoved(MouseWheelEvent e) {
685: JTabbedPane tabPane = (JTabbedPane) e.getSource();
686: int dir = e.getWheelRotation();
687: int selIndex = tabPane.getSelectedIndex();
688: int maxIndex = tabPane.getTabCount() - 1;
689: if ((selIndex == 0 && dir < 0)
690: || (selIndex == maxIndex && dir > 0)) {
691: selIndex = maxIndex - selIndex;
692: } else {
693: selIndex += dir;
694: }
695: tabPane.setSelectedIndex(selIndex);
696: /*int dir = e.getWheelRotation();
697: int selIndex = tabPane.getSelectedIndex();
698: // previous tab
699: if(dir < 0) {
700: // is it already the first index?
701: if(selIndex == 0) {
702: // select the last tab
703: selIndex = tabPane.getTabCount()-1;
704: } else {
705: // select the previous tab
706: selIndex--;
707: }
708: // next tab
709: } else {
710: // is it already the last index?
711: if(selIndex == tabPane.getTabCount()-1) {
712: // select the first tab
713: selIndex = 0;
714: } else {
715: // select the next tab
716: selIndex++;
717: }
718: }
719: tabPane.setSelectedIndex(selIndex);*/
720: }
721: }
722: }
|