IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants Java Discussion :

[jTabbedPane] icone pour fermer


Sujet :

Composants Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    584
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 584
    Par défaut [jTabbedPane] icone pour fermer
    bonjour,

    J'aimerai savoir comment faire pour inserer une croix à droite du titre dans un tabbedPane (exemple eclipse).

    J'arrive à insérer un icon mais celui-ci se place à gauche.

    Faut'il ensuite placé un listener?

  2. #2
    Membre éclairé Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    584
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 584
    Par défaut
    bonjour,
    j'ai fais un tour avec mon ami Google mais je n'ai pas trouver de solution pour fermer mon TabbedPane

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    	    public void ajoutTabbed(String file, String nomFichierOuvert){ 
    	         tableau = new Table(file);//ajout du JTable
    	        /* JButton boutonFermeture = new JButton("Fermer",iconFermeture);
    	         boutonFermeture.addActionListener(new ActionListener (){
    	         	public void actionPerformed(ActionEvent e){
    	         	tabbedPane.remove(1);
    	         	}
    	         	});*/
     
    	         tabbedPane.addTab(nomFichierOuvert,iconFermeture, tableau);
    	         maHashMap.put(nomFichierOuvert, file);
    	   }

  3. #3
    Membre émérite
    Profil pro
    Développeur Back-End
    Inscrit en
    Avril 2003
    Messages
    782
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Back-End

    Informations forums :
    Inscription : Avril 2003
    Messages : 782
    Par défaut
    Bonjour,
    Voici un CloseableTabbedPane que tu peux mettre dans un package tabbedpane (par example) : (trouvé sur Google et simplifié)

    classe CloseableTabbedPane.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    import java.awt.event.MouseEvent;
    import javax.swing.JTabbedPane;
    import javax.swing.plaf.TabbedPaneUI;
     
    public class CloseableTabbedPane extends JTabbedPane {
     
    	private int overTabIndex = -1;
     
    	private CloseTabPaneUI paneUI;
     
    	public CloseableTabbedPane(boolean enhancedUI) {
    		super.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
     
    		if (enhancedUI)
    			paneUI = new CloseTabPaneEnhancedUI();
    		else
    			paneUI = new CloseTabPaneUI();
     
    		super.setUI(paneUI);
    	}
     
    	public int getOverTabIndex() {
    		return overTabIndex;
    	}
     
     
    	/**
             * bloquage de la méthode JTabbedPane
             */
    	public void setTabLayoutPolicy(int tabLayoutPolicy) {
    	}
     
    	/**
             * bloquage de la méthode JTabbedPane
             */
    	public void setTabPlacement(int tabPlacement) {
    	}
     
    	/**
             * Override JTabbedPane method. Does nothing.
             */
    	public void setUI(TabbedPaneUI ui) {
    	}
     
    	public void fireCloseTabEvent(MouseEvent e, int overTabIndex) {
    		remove(overTabIndex);
    	}
    }
    classe CloseTabPaneEnhancedUI.java
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.FontMetrics;
    import java.awt.GradientPaint;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
     
    import javax.swing.JComponent;
    import javax.swing.plaf.ComponentUI;
    import javax.swing.plaf.basic.BasicGraphicsUtils;
    import javax.swing.text.View;
     
    public class CloseTabPaneEnhancedUI extends CloseTabPaneUI {
     
    	private static final Color whiteColor = Color.white;
     
    	private static final Color transparent = new Color(0, 0, 0, 0);
     
    	private static final Color lightBlue = new Color(130, 200, 250, 50);
     
    	private static final Color lightWhite = new Color(200, 200, 200, 50);
     
    	private static final Color selectedColor = new Color(15, 70, 180);
     
    	public static ComponentUI createUI(JComponent c) {
    		return new CloseTabPaneEnhancedUI();
    	}
     
    	protected void paintFocusIndicator(Graphics g, int tabPlacement,
    			Rectangle[] rects, int tabIndex, Rectangle iconRect,
    			Rectangle textRect, boolean isSelected) {
    	}
     
    	protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex,
    			int x, int y, int w, int h, boolean isSelected) {
    		g.setColor(shadow);
     
    		g.drawLine(x, y + 2, x, y + h - 1); // left highlight
    		g.drawLine(x + 1, y + 1, x + 1, y + 1); // top-left highlight
    		g.drawLine(x + 2, y, x + w - 3, y); // top highlight
    		g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 1);
    		g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1); // top-right shadow
     
    		if (isSelected) {
    			//Do the highlights
    			g.setColor(lightHighlight);
    			g.drawLine(x + 2, y + 2, x + 2, y + h - 1);
    			g.drawLine(x + 3, y + 1, x + w - 3, y + 1);
    			g.drawLine(x + w - 3, y + 2, x + w - 3, y + 2);
    			g.drawLine(x + w - 2, y + 2, x + w - 2, y + h - 1);
     
    		}
     
    	}
     
    	protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
    			int selectedIndex, int x, int y, int w, int h) {
     
    		if (tabPane.getTabCount() < 1)
    			return;
     
    		g.setColor(shadow);
    		g.drawLine(x, y, x + w - 2, y);
    	}
     
    	protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,
    			int selectedIndex, int x, int y, int w, int h) {
     
    		if (tabPane.getTabCount() < 1)
    			return;
     
    		g.setColor(shadow);
     
    		g.drawLine(x, y, x, y + h - 3);
    	}
     
    	protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
    			int selectedIndex, int x, int y, int w, int h) {
     
    		if (tabPane.getTabCount() < 1)
    			return;
     
    		g.setColor(shadow);
    		g.drawLine(x + 1, y + h - 3, x + w - 2, y + h - 3);
    		g.drawLine(x + 1, y + h - 2, x + w - 2, y + h - 2);
    		g.setColor(shadow.brighter());
    		g.drawLine(x + 2, y + h - 1, x + w - 1, y + h - 1);
     
    	}
     
    	protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
    			int selectedIndex, int x, int y, int w, int h) {
     
    		if (tabPane.getTabCount() < 1)
    			return;
     
    		g.setColor(shadow);
     
    		g.drawLine(x + w - 3, y + 1, x + w - 3, y + h - 3);
    		g.drawLine(x + w - 2, y + 1, x + w - 2, y + h - 3);
    		g.setColor(shadow.brighter());
    		g.drawLine(x + w - 1, y + 2, x + w - 1, y + h - 2);
     
    	}
     
    	protected void paintTabBackground(Graphics g, int tabPlacement,
    			int tabIndex, int x, int y, int w, int h, boolean isSelected) {
    		if (isSelected) {
     
    			GradientPaint leftGradient;
    			GradientPaint rightGradient;
     
    			int delta = 10;
    			int delta2 = 8;
     
    				delta += BUTTONSIZE + WIDTHDELTA;
    				delta2 += BUTTONSIZE;
     
    			if (tabPane.isEnabledAt(tabIndex)) {
    				leftGradient = new GradientPaint(x, y, selectedColor,
    						x + w / 2, y, lightBlue);
     
    				rightGradient = new GradientPaint(x + w / 2, y, lightBlue, x
    						+ w + delta, y, transparent);
    			} else {
    				leftGradient = new GradientPaint(x, y, shadow, x + w / 2, y,
    						lightWhite);
     
    				rightGradient = new GradientPaint(x + w / 2, y, lightWhite, x
    						+ w + delta, y, transparent);
    			}
     
    			Graphics2D g2 = (Graphics2D) g;
    			g2.setPaint(leftGradient);
    			g2.fillRect(x + 2, y + 2, w / 2, h - 2);
    			g2.setPaint(rightGradient);
    			g2.fillRect(x + 2 + w / 2, y + 2, w / 2 - delta2, h - 2);
    		}
    	}
     
    	protected void paintText(Graphics g, int tabPlacement, Font font,
    			FontMetrics metrics, int tabIndex, String title,
    			Rectangle textRect, boolean isSelected) {
     
    		g.setFont(font);
     
    		View v = getTextViewForTab(tabIndex);
    		if (v != null) {
    			// html
    			v.paint(g, textRect);
    		} else {
    			// plain text
    			int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
     
    			if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
    				if (isSelected)
    					g.setColor(whiteColor);
    				else
    					g.setColor(tabPane.getForegroundAt(tabIndex));
     
    				BasicGraphicsUtils
    						.drawStringUnderlineCharAt(g, title, mnemIndex,
    								textRect.x, textRect.y + metrics.getAscent());
     
    			} else { // tab disabled
    				g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
    				BasicGraphicsUtils
    						.drawStringUnderlineCharAt(g, title, mnemIndex,
    								textRect.x, textRect.y + metrics.getAscent());
    				g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
    				BasicGraphicsUtils.drawStringUnderlineCharAt(g, title,
    						mnemIndex, textRect.x - 1, textRect.y
    								+ metrics.getAscent() - 1);
     
    			}
    		}
    	}
     
    	protected class ScrollableTabButton extends
    			CloseTabPaneUI.ScrollableTabButton {
     
    		public ScrollableTabButton(int direction) {
    			super(direction);
    			setRolloverEnabled(true);
    		}
     
    		public Dimension getPreferredSize() {
    			return new Dimension(16, calculateMaxTabHeight(0));
    		}
     
    		public void paint(Graphics g) {
    			Color origColor;
    			boolean isPressed, isRollOver, isEnabled;
    			int w, h, size;
     
    			w = getSize().width;
    			h = getSize().height;
    			origColor = g.getColor();
    			isPressed = getModel().isPressed();
    			isRollOver = getModel().isRollover();
    			isEnabled = isEnabled();
     
    			g.setColor(getBackground());
    			g.fillRect(0, 0, w, h);
     
    			g.setColor(shadow);
    			// Using the background color set above
    			if (direction == WEST) {
    				g.drawLine(0, 0, 0, h - 1); //left
    				g.drawLine(w - 1, 0, w - 1, 0); //right
    			} else
    				g.drawLine(w - 2, h - 1, w - 2, 0); //right
     
    			g.drawLine(0, 0, w - 2, 0); //top
     
    			if (isRollOver) {
    				//do highlights or shadows
     
    				Color color1;
    				Color color2;
     
    				if (isPressed) {
    					color2 = whiteColor;
    					color1 = shadow;
    				} else {
    					color1 = whiteColor;
    					color2 = shadow;
    				}
     
    				g.setColor(color1);
     
    				if (direction == WEST) {
    					g.drawLine(1, 1, 1, h - 1); //left
    					g.drawLine(1, 1, w - 2, 1); //top
    					g.setColor(color2);
    					g.drawLine(w - 1, h - 1, w - 1, 1); //right
    				} else {
    					g.drawLine(0, 1, 0, h - 1);
    					g.drawLine(0, 1, w - 3, 1); //top
    					g.setColor(color2);
    					g.drawLine(w - 3, h - 1, w - 3, 1); //right
    				}
     
    			}
     
    			//g.drawLine(0, h - 1, w - 1, h - 1); //bottom
     
    			// If there's no room to draw arrow, bail
    			if (h < 5 || w < 5) {
    				g.setColor(origColor);
    				return;
    			}
     
    			if (isPressed) {
    				g.translate(1, 1);
    			}
     
    			// Draw the arrow
    			size = Math.min((h - 4) / 3, (w - 4) / 3);
    			size = Math.max(size, 2);
    			paintTriangle(g, (w - size) / 2, (h - size) / 2, size, direction,
    					isEnabled);
     
    			// Reset the Graphics back to it's original settings
    			if (isPressed) {
    				g.translate(-1, -1);
    			}
    			g.setColor(origColor);
     
    		}
     
    	}
     
    	protected CloseTabPaneUI.ScrollableTabButton createScrollableTabButton(int direction) {
    		return new ScrollableTabButton(direction);
    	}
    }
    classe CloseTabPaneUI
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    1271
    1272
    1273
    1274
    1275
    1276
    1277
    1278
    1279
    1280
    1281
    1282
    1283
    1284
    1285
    1286
    1287
    1288
    1289
    1290
    1291
    1292
    1293
    1294
    1295
    1296
    1297
    1298
    1299
    1300
    1301
    1302
    1303
    1304
    1305
    1306
    1307
    1308
    1309
    1310
    1311
    1312
    1313
    1314
    1315
    1316
    1317
    1318
    1319
    1320
    1321
    1322
    1323
    1324
    1325
    1326
    1327
    1328
    1329
    1330
    1331
    1332
    1333
    1334
    1335
    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    1354
    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    1369
    1370
    1371
    1372
    1373
    1374
    1375
    1376
    1377
    1378
    1379
    1380
    1381
    1382
    1383
    1384
    1385
    1386
    1387
    1388
    1389
    1390
    1391
    1392
    1393
    1394
    1395
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Event;
    import java.awt.Font;
    import java.awt.FontMetrics;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Insets;
    import java.awt.LayoutManager;
    import java.awt.Point;
    import java.awt.Rectangle;
    import java.awt.Shape;
    import java.awt.event.ActionEvent;
    import java.awt.event.ContainerEvent;
    import java.awt.event.ContainerListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseMotionListener;
    import java.awt.image.BufferedImage;
    import java.util.Hashtable;
    import java.util.Vector;
     
    import javax.swing.AbstractAction;
    import javax.swing.ActionMap;
    import javax.swing.Icon;
    import javax.swing.InputMap;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.JViewport;
    import javax.swing.KeyStroke;
    import javax.swing.SwingConstants;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    import javax.swing.border.Border;
    import javax.swing.border.SoftBevelBorder;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    import javax.swing.plaf.ActionMapUIResource;
    import javax.swing.plaf.ComponentUI;
    import javax.swing.plaf.InputMapUIResource;
    import javax.swing.plaf.UIResource;
    import javax.swing.plaf.basic.BasicArrowButton;
    import javax.swing.plaf.basic.BasicHTML;
    import javax.swing.plaf.basic.BasicTabbedPaneUI;
    import javax.swing.text.View;
     
    import com.sun.java.swing.plaf.windows.WindowsIconFactory;
     
    public class CloseTabPaneUI extends BasicTabbedPaneUI {
     
     
    	private ContainerListener containerListener;
     
    	private Vector htmlViews;
     
    	private Hashtable mnemonicToIndexMap;
    	private InputMap mnemonicInputMap;
     
    	protected ScrollableTabSupport tabScroller;
     
    	private int tabCount;
     
    	protected MyMouseMotionListener motionListener;
     
     
    	private static final int INACTIVE = 0;
     
    	private static final int OVER = 1;
     
    	private static final int PRESSED = 2;
     
    	protected static final int BUTTONSIZE = 15;
     
    	protected static final int WIDTHDELTA = 5;
     
    	private static final Border PRESSEDBORDER = new SoftBevelBorder(
    			SoftBevelBorder.LOWERED);
     
    	private static final Border OVERBORDER = new SoftBevelBorder(
    			SoftBevelBorder.RAISED);
     
    	private BufferedImage closeImgB;
     
     
    	private BufferedImage closeImgI;
     
     
    	private JButton closeB;
     
     
    	private int overTabIndex = -1;
     
    	private int closeIndexStatus = INACTIVE;
     
    	private int maxIndexStatus = INACTIVE;
     
    	private boolean mousePressed = false;
     
     
     
     
    	public CloseTabPaneUI() {
     
    		super();
     
    		closeImgB = new BufferedImage(BUTTONSIZE, BUTTONSIZE,
    				BufferedImage.TYPE_4BYTE_ABGR);
     
     
    		closeImgI = new BufferedImage(BUTTONSIZE, BUTTONSIZE,
    				BufferedImage.TYPE_4BYTE_ABGR);
     
     
    		closeB = new JButton();
    		closeB.setSize(BUTTONSIZE, BUTTONSIZE);
     
     
    		WindowsIconFactory.createFrameCloseIcon().paintIcon(closeB,
    				closeImgI.createGraphics(), 0, 0);
     
     
    	}
     
     
     
     
     
    	protected int calculateTabWidth(int tabPlacement, int tabIndex,
    			FontMetrics metrics) {
    		int delta = 2;
    		delta += BUTTONSIZE + WIDTHDELTA;
     
    		return super.calculateTabWidth(tabPlacement, tabIndex, metrics) + delta;
    	}
     
    	protected int calculateTabHeight(int tabPlacement, int tabIndex,
    			int fontHeight) {
     
    		return super.calculateTabHeight(tabPlacement, tabIndex, fontHeight) + 5;
    	}
     
    	protected void layoutLabel(int tabPlacement, FontMetrics metrics,
    			int tabIndex, String title, Icon icon, Rectangle tabRect,
    			Rectangle iconRect, Rectangle textRect, boolean isSelected) {
    		textRect.x = textRect.y = iconRect.x = iconRect.y = 0;
     
    		View v = getTextViewForTab(tabIndex);
    		if (v != null) {
    			tabPane.putClientProperty("html", v);
    		}
     
    		SwingUtilities.layoutCompoundLabel((JComponent) tabPane, metrics,
    				title, icon, SwingUtilities.CENTER, SwingUtilities.LEFT,
    				SwingUtilities.CENTER, SwingUtilities.CENTER, tabRect,
    				iconRect, textRect, textIconGap);
     
    		tabPane.putClientProperty("html", null);
     
    		iconRect.x = tabRect.x + 8;
    		textRect.x = iconRect.x + iconRect.width + textIconGap;
    	}
     
    	protected MouseListener createMouseListener() {
    		return new MyMouseHandler();
    	}
     
    	protected ScrollableTabButton createScrollableTabButton(int direction) {
    		return new ScrollableTabButton(direction);
    	}
     
    	protected Rectangle newCloseRect(Rectangle rect) {
    		int dx = rect.x + rect.width;
    		int dy = (rect.y + rect.height) / 2 - 6;
    		return new Rectangle(dx - BUTTONSIZE - WIDTHDELTA, dy, BUTTONSIZE,
    				BUTTONSIZE);
    	}
     
    	protected Rectangle newMaxRect(Rectangle rect) {
    		int dx = rect.x + rect.width;
    		int dy = (rect.y + rect.height) / 2 - 6;
    		dx -= BUTTONSIZE;
     
    		return new Rectangle(dx - BUTTONSIZE - WIDTHDELTA, dy, BUTTONSIZE,
    				BUTTONSIZE);
    	}
     
    	protected void updateOverTab(int x, int y) {
    		if (overTabIndex != (overTabIndex = getTabAtLocation(x, y)))
    			tabScroller.tabPanel.repaint();
     
    	}
     
    	protected void updateCloseIcon(int x, int y) {
     
    		if (overTabIndex != -1) {
    			int newCloseIndexStatus = INACTIVE;
     
    			Rectangle closeRect = newCloseRect(rects[overTabIndex]);
    			if (closeRect.contains(x, y))
    				newCloseIndexStatus = mousePressed ? PRESSED : OVER;
     
    			if (closeIndexStatus != (closeIndexStatus = newCloseIndexStatus))
    				tabScroller.tabPanel.repaint();
    		}
    	}
     
    	protected void updateMaxIcon(int x, int y) {
    		if (overTabIndex != -1) {
    			int newMaxIndexStatus = INACTIVE;
     
    			Rectangle maxRect = newMaxRect(rects[overTabIndex]);
     
    			if (maxRect.contains(x, y))
    				newMaxIndexStatus = mousePressed ? PRESSED : OVER;
     
    			if (maxIndexStatus != (maxIndexStatus = newMaxIndexStatus))
    				tabScroller.tabPanel.repaint();
    		}
    	}
     
    	private void setTabIcons(int x, int y) {
    		//if the mouse isPressed
    		if (! mousePressed) {
    			updateOverTab(x, y);
    		}
     
    		updateCloseIcon(x, y);
    	}
     
    	public static ComponentUI createUI(JComponent c) {
    		return new CloseTabPaneUI();
    	}
     
    	/**
             * Invoked by <code>installUI</code> to create a layout manager object to
             * manage the <code>JTabbedPane</code>.
             * 
             * @return a layout manager object
             * 
             * @see TabbedPaneLayout
             * @see javax.swing.JTabbedPane#getTabLayoutPolicy
             */
    	protected LayoutManager createLayoutManager() {
     
    		return new TabbedPaneScrollLayout();
     
    	}
     
    	/*
    	 * In an attempt to preserve backward compatibility for programs which have
    	 * extended BasicTabbedPaneUI to do their own layout, the UI uses the
    	 * installed layoutManager (and not tabLayoutPolicy) to determine if
    	 * scrollTabLayout is enabled.
    	 */
     
    	/**
             * Creates and installs any required subcomponents for the JTabbedPane.
             * Invoked by installUI.
             * 
             * @since 1.4
             */
    	protected void installComponents() {
     
    		if (tabScroller == null) {
    			tabScroller = new ScrollableTabSupport(tabPane.getTabPlacement());
    			tabPane.add(tabScroller.viewport);
    			tabPane.add(tabScroller.scrollForwardButton);
    			tabPane.add(tabScroller.scrollBackwardButton);
    		}
     
    	}
     
    	/**
             * Removes any installed subcomponents from the JTabbedPane. Invoked by
             * uninstallUI.
             * 
             * @since 1.4
             */
    	protected void uninstallComponents() {
     
    		tabPane.remove(tabScroller.viewport);
    		tabPane.remove(tabScroller.scrollForwardButton);
    		tabPane.remove(tabScroller.scrollBackwardButton);
    		tabScroller = null;
     
    	}
     
    	protected void installListeners() {
    		if ((propertyChangeListener = createPropertyChangeListener()) != null) {
    			tabPane.addPropertyChangeListener(propertyChangeListener);
    		}
    		if ((tabChangeListener = createChangeListener()) != null) {
    			tabPane.addChangeListener(tabChangeListener);
    		}
    		if ((mouseListener = createMouseListener()) != null) {
    			tabScroller.tabPanel.addMouseListener(mouseListener);
    		}
     
    		if ((focusListener = createFocusListener()) != null) {
    			tabPane.addFocusListener(focusListener);
    		}
     
    		// PENDING(api) : See comment for ContainerHandler
    		if ((containerListener = new ContainerHandler()) != null) {
    			tabPane.addContainerListener(containerListener);
    			if (tabPane.getTabCount() > 0) {
    				htmlViews = createHTMLVector();
    			}
    		}
     
    		if ((motionListener = new MyMouseMotionListener()) != null) {
    			tabScroller.tabPanel.addMouseMotionListener(motionListener);
    		}
     
    	}
     
    	protected void uninstallListeners() {
    		if (mouseListener != null) {
    			tabScroller.tabPanel.removeMouseListener(mouseListener);
    			mouseListener = null;
    		}
     
    		if (motionListener != null) {
    			tabScroller.tabPanel.removeMouseMotionListener(motionListener);
    			motionListener = null;
    		}
     
    		if (focusListener != null) {
    			tabPane.removeFocusListener(focusListener);
    			focusListener = null;
    		}
     
    		// PENDING(api): See comment for ContainerHandler
    		if (containerListener != null) {
    			tabPane.removeContainerListener(containerListener);
    			containerListener = null;
    			if (htmlViews != null) {
    				htmlViews.removeAllElements();
    				htmlViews = null;
    			}
    		}
    		if (tabChangeListener != null) {
    			tabPane.removeChangeListener(tabChangeListener);
    			tabChangeListener = null;
    		}
    		if (propertyChangeListener != null) {
    			tabPane.removePropertyChangeListener(propertyChangeListener);
    			propertyChangeListener = null;
    		}
     
    	}
     
    	protected ChangeListener createChangeListener() {
    		return new TabSelectionHandler();
    	}
     
    	protected void installKeyboardActions() {
    		InputMap km = getMyInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
     
    		SwingUtilities.replaceUIInputMap(tabPane,
    				JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, km);
    		km = getMyInputMap(JComponent.WHEN_FOCUSED);
    		SwingUtilities.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED, km);
     
    		ActionMap am = createMyActionMap();
     
    		SwingUtilities.replaceUIActionMap(tabPane, am);
     
    		tabScroller.scrollForwardButton.setAction(am
    				.get("scrollTabsForwardAction"));
    		tabScroller.scrollBackwardButton.setAction(am
    				.get("scrollTabsBackwardAction"));
     
    	}
     
    	InputMap getMyInputMap(int condition) {
    		if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
    			return (InputMap) UIManager.get("TabbedPane.ancestorInputMap");
    		} else if (condition == JComponent.WHEN_FOCUSED) {
    			return (InputMap) UIManager.get("TabbedPane.focusInputMap");
    		}
    		return null;
    	}
     
    	ActionMap createMyActionMap() {
    		ActionMap map = new ActionMapUIResource();
    		map.put("navigateNext", new NextAction());
    		map.put("navigatePrevious", new PreviousAction());
    		map.put("navigateRight", new RightAction());
    		map.put("navigateLeft", new LeftAction());
    		map.put("navigateUp", new UpAction());
    		map.put("navigateDown", new DownAction());
    		map.put("navigatePageUp", new PageUpAction());
    		map.put("navigatePageDown", new PageDownAction());
    		map.put("requestFocus", new RequestFocusAction());
    		map.put("requestFocusForVisibleComponent",
    				new RequestFocusForVisibleAction());
    		map.put("setSelectedIndex", new SetSelectedIndexAction());
    		map.put("scrollTabsForwardAction", new ScrollTabsForwardAction());
    		map.put("scrollTabsBackwardAction", new ScrollTabsBackwardAction());
    		return map;
    	}
     
    	protected void uninstallKeyboardActions() {
    		SwingUtilities.replaceUIActionMap(tabPane, null);
    		SwingUtilities.replaceUIInputMap(tabPane,
    				JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
    		SwingUtilities
    				.replaceUIInputMap(tabPane, JComponent.WHEN_FOCUSED, null);
    	}
     
    	/**
             * Reloads the mnemonics. This should be invoked when a memonic changes,
             * when the title of a mnemonic changes, or when tabs are added/removed.
             */
    	private void updateMnemonics() {
    		resetMnemonics();
    		for (int counter = tabPane.getTabCount() - 1; counter >= 0; counter--) {
    			int mnemonic = tabPane.getMnemonicAt(counter);
     
    			if (mnemonic > 0) {
    				addMnemonic(counter, mnemonic);
    			}
    		}
    	}
     
    	/**
             * Resets the mnemonics bindings to an empty state.
             */
    	private void resetMnemonics() {
    		if (mnemonicToIndexMap != null) {
    			mnemonicToIndexMap.clear();
    			mnemonicInputMap.clear();
    		}
    	}
     
    	/**
             * Adds the specified mnemonic at the specified index.
             */
    	private void addMnemonic(int index, int mnemonic) {
    		if (mnemonicToIndexMap == null) {
    			initMnemonics();
    		}
    		mnemonicInputMap.put(KeyStroke.getKeyStroke(mnemonic, Event.ALT_MASK),
    				"setSelectedIndex");
    		mnemonicToIndexMap.put(new Integer(mnemonic), new Integer(index));
    	}
     
    	/**
             * Installs the state needed for mnemonics.
             */
    	private void initMnemonics() {
    		mnemonicToIndexMap = new Hashtable();
    		mnemonicInputMap = new InputMapUIResource();
    		mnemonicInputMap.setParent(SwingUtilities.getUIInputMap(tabPane,
    				JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT));
    		SwingUtilities
    				.replaceUIInputMap(tabPane,
    						JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
    						mnemonicInputMap);
    	}
     
    	// UI Rendering
     
    	public void paint(Graphics g, JComponent c) {
    		int tc = tabPane.getTabCount();
     
    		if (tabCount != tc) {
    			tabCount = tc;
    			updateMnemonics();
    		}
     
    		int selectedIndex = tabPane.getSelectedIndex();
    		int tabPlacement = tabPane.getTabPlacement();
     
    		ensureCurrentLayout();
     
    		// Paint content border
    		paintContentBorder(g, tabPlacement, selectedIndex);
     
    	}
     
    	protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects,
    			int tabIndex, Rectangle iconRect, Rectangle textRect) {
    		Rectangle tabRect = rects[tabIndex];
    		int selectedIndex = tabPane.getSelectedIndex();
    		boolean isSelected = selectedIndex == tabIndex;
    		boolean isOver = overTabIndex == tabIndex;
    		Graphics2D g2 = null;
    		Shape save = null;
    		boolean cropShape = false;
    		int cropx = 0;
    		int cropy = 0;
     
    		if (g instanceof Graphics2D) {
    			g2 = (Graphics2D) g;
     
    			// Render visual for cropped tab edge...
    			Rectangle viewRect = tabScroller.viewport.getViewRect();
    			int cropline;
     
    			cropline = viewRect.x + viewRect.width;
    			if ((tabRect.x < cropline)
    					&& (tabRect.x + tabRect.width > cropline)) {
     
    				cropx = cropline - 1;
    				cropy = tabRect.y;
    				cropShape = true;
    			}
     
    			if (cropShape) {
    				save = g2.getClip();
    				g2
    						.clipRect(tabRect.x, tabRect.y, tabRect.width,
    								tabRect.height);
     
    			}
    		}
     
    		paintTabBackground(g, tabPlacement, tabIndex, tabRect.x, tabRect.y,
    				tabRect.width, tabRect.height, isSelected);
     
    		paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y,
    				tabRect.width, tabRect.height, isSelected);
     
    		String title = tabPane.getTitleAt(tabIndex);
    		Font font = tabPane.getFont();
    		FontMetrics metrics = g.getFontMetrics(font);
    		Icon icon = getIconForTab(tabIndex);
     
    		layoutLabel(tabPlacement, metrics, tabIndex, title, icon, tabRect,
    				iconRect, textRect, isSelected);
     
    		paintText(g, tabPlacement, font, metrics, tabIndex, title, textRect,
    				isSelected);
     
    		paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
     
    		paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect,
    				textRect, isSelected);
     
    		if (cropShape) {
    			paintCroppedTabEdge(g, tabPlacement, tabIndex, isSelected, cropx,
    					cropy);
    			g2.setClip(save);
     
    		} else if (isOver || isSelected) {
     
    			int dx = tabRect.x + tabRect.width - BUTTONSIZE - WIDTHDELTA;
    			int dy = (tabRect.y + tabRect.height) / 2 - 6;
     
    			paintCloseIcon(g2, dx, dy, isOver);
    		}
     
    	}
     
    	protected void paintCloseIcon(Graphics g, int dx, int dy, boolean isOver) {
    		paintActionButton(g, dx, dy, closeIndexStatus, isOver, closeB,
    				closeImgB);
    		g.drawImage(closeImgI, dx, dy + 1, null);
    	}
     
     
    	protected void paintActionButton(Graphics g, int dx, int dy, int status,
    			boolean isOver, JButton button, BufferedImage image) {
     
    		button.setBorder(null);
     
    		if (isOver) {
    			switch (status) {
    			case OVER:
    				button.setBorder(OVERBORDER);
    				break;
    			case PRESSED:
    				button.setBorder(PRESSEDBORDER);
    				break;
    			}
    		}
     
    		button.setBackground(tabScroller.tabPanel.getBackground());
    		button.paint(image.getGraphics());
    		g.drawImage(image, dx, dy, null);
    	}
     
    	/*
    	 * This method will create and return a polygon shape for the given tab
    	 * rectangle which has been cropped at the specified cropline with a torn
    	 * edge visual. e.g. A "File" tab which has cropped been cropped just after
    	 * the "i": ------------- | ..... | | . | | ... . | | . . | | . . | | . . |
    	 * --------------
    	 * 
    	 * The x, y arrays below define the pattern used to create a "torn" edge
    	 * segment which is repeated to fill the edge of the tab. For tabs placed on
    	 * TOP and BOTTOM, this righthand torn edge is created by line segments
    	 * which are defined by coordinates obtained by subtracting xCropLen[i] from
    	 * (tab.x + tab.width) and adding yCroplen[i] to (tab.y). For tabs placed on
    	 * LEFT or RIGHT, the bottom torn edge is created by subtracting xCropLen[i]
    	 * from (tab.y + tab.height) and adding yCropLen[i] to (tab.x).
    	 */
     
    	private static final int CROP_SEGMENT = 12;
     
    	private void paintCroppedTabEdge(Graphics g, int tabPlacement,
    			int tabIndex, boolean isSelected, int x, int y) {
     
    		g.setColor(shadow);
    		g.drawLine(x, y, x, y + rects[tabIndex].height);
     
    	}
     
    	private void ensureCurrentLayout() {
    		if (!tabPane.isValid()) {
    			tabPane.validate();
    		}
    		/*
    		 * If tabPane doesn't have a peer yet, the validate() call will silently
    		 * fail. We handle that by forcing a layout if tabPane is still invalid.
    		 * See bug 4237677.
    		 */
    		if (!tabPane.isValid()) {
    			TabbedPaneLayout layout = (TabbedPaneLayout) tabPane.getLayout();
    			layout.calculateLayoutInfo();
    		}
    	}
     
    	/**
             * Returns the bounds of the specified tab in the coordinate space of the
             * JTabbedPane component. This is required because the tab rects are by
             * default defined in the coordinate space of the component where they are
             * rendered, which could be the JTabbedPane (for WRAP_TAB_LAYOUT) or a
             * ScrollableTabPanel (SCROLL_TAB_LAYOUT). This method should be used
             * whenever the tab rectangle must be relative to the JTabbedPane itself and
             * the result should be placed in a designated Rectangle object (rather than
             * instantiating and returning a new Rectangle each time). The tab index
             * parameter must be a valid tabbed pane tab index (0 to tab count - 1,
             * inclusive). The destination rectangle parameter must be a valid
             * <code>Rectangle</code> instance. The handling of invalid parameters is
             * unspecified.
             * 
             * @param tabIndex
             *            the index of the tab
             * @param dest
             *            the rectangle where the result should be placed
             * @return the resulting rectangle
             * 
             * @since 1.4
             */
     
    	protected Rectangle getTabBounds(int tabIndex, Rectangle dest) {
    		dest.width = rects[tabIndex].width;
    		dest.height = rects[tabIndex].height;
     
    		Point vpp = tabScroller.viewport.getLocation();
    		Point viewp = tabScroller.viewport.getViewPosition();
    		dest.x = rects[tabIndex].x + vpp.x - viewp.x;
    		dest.y = rects[tabIndex].y + vpp.y - viewp.y;
     
    		return dest;
    	}
     
    	private int getTabAtLocation(int x, int y) {
    		ensureCurrentLayout();
     
    		int tabCount = tabPane.getTabCount();
    		for (int i = 0; i < tabCount; i++) {
    			if (rects[i].contains(x, y)) {
    				return i;
    			}
    		}
    		return -1;
    	}
     
    	public int getOverTabIndex(){
    		return overTabIndex;
    	}
     
    	/**
             * Returns the index of the tab closest to the passed in location, note that
             * the returned tab may not contain the location x,y.
             */
    	private int getClosestTab(int x, int y) {
    		int min = 0;
    		int tabCount = Math.min(rects.length, tabPane.getTabCount());
    		int max = tabCount;
    		int tabPlacement = tabPane.getTabPlacement();
    		boolean useX = (tabPlacement == TOP || tabPlacement == BOTTOM);
    		int want = (useX) ? x : y;
     
    		while (min != max) {
    			int current = (max + min) / 2;
    			int minLoc;
    			int maxLoc;
     
    			if (useX) {
    				minLoc = rects[current].x;
    				maxLoc = minLoc + rects[current].width;
    			} else {
    				minLoc = rects[current].y;
    				maxLoc = minLoc + rects[current].height;
    			}
    			if (want < minLoc) {
    				max = current;
    				if (min == max) {
    					return Math.max(0, current - 1);
    				}
    			} else if (want >= maxLoc) {
    				min = current;
    				if (max - min <= 1) {
    					return Math.max(current + 1, tabCount - 1);
    				}
    			} else {
    				return current;
    			}
    		}
    		return min;
    	}
     
    	/**
             * Returns a point which is translated from the specified point in the
             * JTabbedPane's coordinate space to the coordinate space of the
             * ScrollableTabPanel. This is used for SCROLL_TAB_LAYOUT ONLY.
             */
    	private Point translatePointToTabPanel(int srcx, int srcy, Point dest) {
    		Point vpp = tabScroller.viewport.getLocation();
    		Point viewp = tabScroller.viewport.getViewPosition();
    		dest.x = srcx + vpp.x + viewp.x;
    		dest.y = srcy + vpp.y + viewp.y;
    		return dest;
    	}
     
    	// BasicTabbedPaneUI methods
     
    	// Tab Navigation methods
     
    	// REMIND(aim,7/29/98): This method should be made
    	// protected in the next release where
    	// API changes are allowed
    	//
    	boolean requestMyFocusForVisibleComponent() {
    		Component visibleComponent = getVisibleComponent();
    		if (visibleComponent.isFocusTraversable()) {
    			visibleComponent.requestFocus();
    			return true;
    		} else if (visibleComponent instanceof JComponent) {
    			if (((JComponent) visibleComponent).requestDefaultFocus()) {
    				return true;
    			}
    		}
    		return false;
    	}
     
    	private static class RightAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    			ui.navigateSelectedTab(EAST);
    		}
    	};
     
    	private static class LeftAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    			ui.navigateSelectedTab(WEST);
    		}
    	};
     
    	private static class UpAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    			ui.navigateSelectedTab(NORTH);
    		}
    	};
     
    	private static class DownAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    			ui.navigateSelectedTab(SOUTH);
    		}
    	};
     
    	private static class NextAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    			ui.navigateSelectedTab(NEXT);
    		}
    	};
     
    	private static class PreviousAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    			ui.navigateSelectedTab(PREVIOUS);
    		}
    	};
     
    	private static class PageUpAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    			int tabPlacement = pane.getTabPlacement();
    			if (tabPlacement == TOP || tabPlacement == BOTTOM) {
    				ui.navigateSelectedTab(WEST);
    			} else {
    				ui.navigateSelectedTab(NORTH);
    			}
    		}
    	};
     
    	private static class PageDownAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    			int tabPlacement = pane.getTabPlacement();
    			if (tabPlacement == TOP || tabPlacement == BOTTOM) {
    				ui.navigateSelectedTab(EAST);
    			} else {
    				ui.navigateSelectedTab(SOUTH);
    			}
    		}
    	};
     
    	private static class RequestFocusAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			pane.requestFocus();
    		}
    	};
     
    	private static class RequestFocusForVisibleAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    			ui.requestMyFocusForVisibleComponent();
    		}
    	};
     
    	/**
             * Selects a tab in the JTabbedPane based on the String of the action
             * command. The tab selected is based on the first tab that has a mnemonic
             * matching the first character of the action command.
             */
    	private static class SetSelectedIndexAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = (JTabbedPane) e.getSource();
     
    			if (pane != null && (pane.getUI() instanceof CloseTabPaneUI)) {
    				CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
    				String command = e.getActionCommand();
     
    				if (command != null && command.length() > 0) {
    					int mnemonic = (int) e.getActionCommand().charAt(0);
    					if (mnemonic >= 'a' && mnemonic <= 'z') {
    						mnemonic -= ('a' - 'A');
    					}
    					Integer index = (Integer) ui.mnemonicToIndexMap
    							.get(new Integer(mnemonic));
    					if (index != null && pane.isEnabledAt(index.intValue())) {
    						pane.setSelectedIndex(index.intValue());
    					}
    				}
    			}
    		}
    	};
     
    	private static class ScrollTabsForwardAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = null;
    			Object src = e.getSource();
    			if (src instanceof JTabbedPane) {
    				pane = (JTabbedPane) src;
    			} else if (src instanceof ScrollableTabButton) {
    				pane = (JTabbedPane) ((ScrollableTabButton) src).getParent();
    			} else {
    				return; // shouldn't happen
    			}
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
     
    			ui.tabScroller.scrollForward(pane.getTabPlacement());
     
    		}
    	}
     
    	private static class ScrollTabsBackwardAction extends AbstractAction {
    		public void actionPerformed(ActionEvent e) {
    			JTabbedPane pane = null;
    			Object src = e.getSource();
    			if (src instanceof JTabbedPane) {
    				pane = (JTabbedPane) src;
    			} else if (src instanceof ScrollableTabButton) {
    				pane = (JTabbedPane) ((ScrollableTabButton) src).getParent();
    			} else {
    				return; // shouldn't happen
    			}
    			CloseTabPaneUI ui = (CloseTabPaneUI) pane.getUI();
     
    			ui.tabScroller.scrollBackward(pane.getTabPlacement());
     
    		}
    	}
     
    	/**
             * This inner class is marked &quot;public&quot; due to a compiler bug. This
             * class should be treated as a &quot;protected&quot; inner class.
             * Instantiate it only within subclasses of BasicTabbedPaneUI.
             */
     
    	private class TabbedPaneScrollLayout extends TabbedPaneLayout {
     
    		protected int preferredTabAreaHeight(int tabPlacement, int width) {
    			return calculateMaxTabHeight(tabPlacement);
    		}
     
    		protected int preferredTabAreaWidth(int tabPlacement, int height) {
    			return calculateMaxTabWidth(tabPlacement);
    		}
     
    		public void layoutContainer(Container parent) {
    			int tabPlacement = tabPane.getTabPlacement();
    			int tabCount = tabPane.getTabCount();
    			Insets insets = tabPane.getInsets();
    			int selectedIndex = tabPane.getSelectedIndex();
    			Component visibleComponent = getVisibleComponent();
     
    			calculateLayoutInfo();
     
    			if (selectedIndex < 0) {
    				if (visibleComponent != null) {
    					// The last tab was removed, so remove the component
    					setVisibleComponent(null);
    				}
    			} else {
    				Component selectedComponent = tabPane
    						.getComponentAt(selectedIndex);
    				boolean shouldChangeFocus = false;
     
    				// In order to allow programs to use a single component
    				// as the display for multiple tabs, we will not change
    				// the visible compnent if the currently selected tab
    				// has a null component. This is a bit dicey, as we don't
    				// explicitly state we support this in the spec, but since
    				// programs are now depending on this, we're making it work.
    				//
    				if (selectedComponent != null) {
    					if (selectedComponent != visibleComponent
    							&& visibleComponent != null) {
    						if (SwingUtilities.findFocusOwner(visibleComponent) != null) {
    							shouldChangeFocus = true;
    						}
    					}
    					setVisibleComponent(selectedComponent);
    				}
    				int tx, ty, tw, th; // tab area bounds
    				int cx, cy, cw, ch; // content area bounds
    				Insets contentInsets = getContentBorderInsets(tabPlacement);
    				Rectangle bounds = tabPane.getBounds();
    				int numChildren = tabPane.getComponentCount();
     
    				if (numChildren > 0) {
     
    					// calculate tab area bounds
    					tw = bounds.width - insets.left - insets.right;
    					th = calculateTabAreaHeight(tabPlacement, runCount,
    							maxTabHeight);
    					tx = insets.left;
    					ty = insets.top;
     
    					// calculate content area bounds
    					cx = tx + contentInsets.left;
    					cy = ty + th + contentInsets.top;
    					cw = bounds.width - insets.left - insets.right
    							- contentInsets.left - contentInsets.right;
    					ch = bounds.height - insets.top - insets.bottom - th
    							- contentInsets.top - contentInsets.bottom;
     
    					for (int i = 0; i < numChildren; i++) {
    						Component child = tabPane.getComponent(i);
     
    						if (child instanceof ScrollableTabViewport) {
    							JViewport viewport = (JViewport) child;
    							Rectangle viewRect = viewport.getViewRect();
    							int vw = tw;
    							int vh = th;
     
    							int totalTabWidth = rects[tabCount - 1].x
    									+ rects[tabCount - 1].width;
    							if (totalTabWidth > tw) {
    								// Need to allow space for scrollbuttons
    								vw = Math.max(tw - 36, 36);
    								;
    								if (totalTabWidth - viewRect.x <= vw) {
    									// Scrolled to the end, so ensure the
    									// viewport size is
    									// such that the scroll offset aligns with a
    									// tab
    									vw = totalTabWidth - viewRect.x;
    								}
    							}
     
    							child.setBounds(tx, ty, vw, vh);
     
    						} else if (child instanceof ScrollableTabButton) {
    							ScrollableTabButton scrollbutton = (ScrollableTabButton) child;
    							Dimension bsize = scrollbutton.getPreferredSize();
    							int bx = 0;
    							int by = 0;
    							int bw = bsize.width;
    							int bh = bsize.height;
    							boolean visible = false;
     
    							int totalTabWidth = rects[tabCount - 1].x
    									+ rects[tabCount - 1].width;
     
    							if (totalTabWidth > tw) {
    								int dir = scrollbutton.scrollsForward() ? EAST
    										: WEST;
    								scrollbutton.setDirection(dir);
    								visible = true;
    								bx = dir == EAST ? bounds.width - insets.left
    										- bsize.width : bounds.width
    										- insets.left - 2 * bsize.width;
    								by = (tabPlacement == TOP ? ty + th
    										- bsize.height : ty);
    							}
     
    							child.setVisible(visible);
    							if (visible) {
    								child.setBounds(bx, by, bw, bh);
    							}
     
    						} else {
    							// All content children...
    							child.setBounds(cx, cy, cw, ch);
    						}
    					}
    					if (shouldChangeFocus) {
    						if (!requestMyFocusForVisibleComponent()) {
    							tabPane.requestFocus();
    						}
    					}
    				}
    			}
    		}
     
    		protected void calculateTabRects(int tabPlacement, int tabCount) {
    			FontMetrics metrics = getFontMetrics();
    			Dimension size = tabPane.getSize();
    			Insets insets = tabPane.getInsets();
    			Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
    			int fontHeight = metrics.getHeight();
    			int selectedIndex = tabPane.getSelectedIndex();
    			int i, j;
     
    			int x = tabAreaInsets.left - 2;
    			int y = tabAreaInsets.top;
    			int totalWidth = 0;
    			int totalHeight = 0;
     
    			//
    			// Calculate bounds within which a tab run must fit
    			//
     
    			maxTabHeight = calculateMaxTabHeight(tabPlacement);
     
    			runCount = 0;
    			selectedRun = -1;
     
    			if (tabCount == 0) {
    				return;
    			}
     
    			selectedRun = 0;
    			runCount = 1;
     
    			// Run through tabs and lay them out in a single run
    			Rectangle rect;
    			for (i = 0; i < tabCount; i++) {
    				rect = rects[i];
     
    				if (i > 0) {
    					rect.x = rects[i - 1].x + rects[i - 1].width - 1;
    				} else {
    					tabRuns[0] = 0;
    					maxTabWidth = 0;
    					totalHeight += maxTabHeight;
    					rect.x = x;
    				}
    				rect.width = calculateTabWidth(tabPlacement, i, metrics);
    				totalWidth = rect.x + rect.width;
    				maxTabWidth = Math.max(maxTabWidth, rect.width);
     
    				rect.y = y;
    				rect.height = maxTabHeight /* - 2 */;
     
    			}
     
    			//tabPanel.setSize(totalWidth, totalHeight);
    			tabScroller.tabPanel.setPreferredSize(new Dimension(totalWidth,
    					totalHeight));
    		}
    	}
     
    	private class ScrollableTabSupport implements ChangeListener {
    		public ScrollableTabViewport viewport;
     
    		public ScrollableTabPanel tabPanel;
     
    		public ScrollableTabButton scrollForwardButton;
     
    		public ScrollableTabButton scrollBackwardButton;
     
    		public int leadingTabIndex;
     
    		private Point tabViewPosition = new Point(0, 0);
     
    		ScrollableTabSupport(int tabPlacement) {
    			viewport = new ScrollableTabViewport();
    			tabPanel = new ScrollableTabPanel();
    			viewport.setView(tabPanel);
    			viewport.addChangeListener(this);
     
    			scrollForwardButton = createScrollableTabButton(EAST);
    			scrollBackwardButton = createScrollableTabButton(WEST);
    			//			scrollForwardButton = new ScrollableTabButton(EAST);
    			//			scrollBackwardButton = new ScrollableTabButton(WEST);
    		}
     
    		public void scrollForward(int tabPlacement) {
    			Dimension viewSize = viewport.getViewSize();
    			Rectangle viewRect = viewport.getViewRect();
     
    			if (tabPlacement == TOP || tabPlacement == BOTTOM) {
    				if (viewRect.width >= viewSize.width - viewRect.x) {
    					return; // no room left to scroll
    				}
    			} else { // tabPlacement == LEFT || tabPlacement == RIGHT
    				if (viewRect.height >= viewSize.height - viewRect.y) {
    					return;
    				}
    			}
    			setLeadingTabIndex(tabPlacement, leadingTabIndex + 1);
    		}
     
    		public void scrollBackward(int tabPlacement) {
    			if (leadingTabIndex == 0) {
    				return; // no room left to scroll
    			}
    			setLeadingTabIndex(tabPlacement, leadingTabIndex - 1);
    		}
     
    		public void setLeadingTabIndex(int tabPlacement, int index) {
    			leadingTabIndex = index;
    			Dimension viewSize = viewport.getViewSize();
    			Rectangle viewRect = viewport.getViewRect();
     
    			tabViewPosition.x = leadingTabIndex == 0 ? 0
    					: rects[leadingTabIndex].x;
     
    			if ((viewSize.width - tabViewPosition.x) < viewRect.width) {
    				// We've scrolled to the end, so adjust the viewport size
    				// to ensure the view position remains aligned on a tab boundary
    				Dimension extentSize = new Dimension(viewSize.width
    						- tabViewPosition.x, viewRect.height);
    				viewport.setExtentSize(extentSize);
    			}
     
    			viewport.setViewPosition(tabViewPosition);
    		}
     
    		public void stateChanged(ChangeEvent e) {
    			JViewport viewport = (JViewport) e.getSource();
    			int tabPlacement = tabPane.getTabPlacement();
    			int tabCount = tabPane.getTabCount();
    			Rectangle vpRect = viewport.getBounds();
    			Dimension viewSize = viewport.getViewSize();
    			Rectangle viewRect = viewport.getViewRect();
     
    			leadingTabIndex = getClosestTab(viewRect.x, viewRect.y);
     
    			// If the tab isn't right aligned, adjust it.
    			if (leadingTabIndex + 1 < tabCount) {
     
    				if (rects[leadingTabIndex].x < viewRect.x) {
    					leadingTabIndex++;
    				}
     
    			}
    			Insets contentInsets = getContentBorderInsets(tabPlacement);
     
    			tabPane.repaint(vpRect.x, vpRect.y + vpRect.height, vpRect.width,
    					contentInsets.top);
    			scrollBackwardButton.setEnabled(viewRect.x > 0);
    			scrollForwardButton.setEnabled(leadingTabIndex < tabCount - 1
    					&& viewSize.width - viewRect.x > viewRect.width);
     
    		}
     
    		public String toString() {
    			return new String("viewport.viewSize=" + viewport.getViewSize()
    					+ "\n" + "viewport.viewRectangle=" + viewport.getViewRect()
    					+ "\n" + "leadingTabIndex=" + leadingTabIndex + "\n"
    					+ "tabViewPosition=" + tabViewPosition);
    		}
     
    	}
     
    	private class ScrollableTabViewport extends JViewport implements UIResource {
    		public ScrollableTabViewport() {
    			super();
    			setScrollMode(SIMPLE_SCROLL_MODE);
    		}
    	}
     
    	private class ScrollableTabPanel extends JPanel implements UIResource {
    		public ScrollableTabPanel() {
    			setLayout(null);
    		}
     
    		public void paintComponent(Graphics g) {
    			super.paintComponent(g);
    			CloseTabPaneUI.this.paintTabArea(g, tabPane.getTabPlacement(),
    					tabPane.getSelectedIndex());
     
    		}
    	}
     
    	protected class ScrollableTabButton extends BasicArrowButton implements
    			UIResource, SwingConstants {
    		public ScrollableTabButton(int direction) {
    			super(direction, UIManager.getColor("TabbedPane.selected"),
    					UIManager.getColor("TabbedPane.shadow"), UIManager
    							.getColor("TabbedPane.darkShadow"), UIManager
    							.getColor("TabbedPane.highlight"));
     
    		}
     
    		public boolean scrollsForward() {
    			return direction == EAST || direction == SOUTH;
    		}
     
    	}
     
    	public class TabSelectionHandler implements ChangeListener {
    		public void stateChanged(ChangeEvent e) {
    			JTabbedPane tabPane = (JTabbedPane) e.getSource();
    			tabPane.revalidate();
    			tabPane.repaint();
     
    			if (tabPane.getTabLayoutPolicy() == JTabbedPane.SCROLL_TAB_LAYOUT) {
    				int index = tabPane.getSelectedIndex();
    				if (index < rects.length && index != -1) {
    					tabScroller.tabPanel.scrollRectToVisible(rects[index]);
    				}
    			}
    		}
    	}
     
    	private class ContainerHandler implements ContainerListener {
    		public void componentAdded(ContainerEvent e) {
    			JTabbedPane tp = (JTabbedPane) e.getContainer();
    			Component child = e.getChild();
    			if (child instanceof UIResource) {
    				return;
    			}
    			int index = tp.indexOfComponent(child);
    			String title = tp.getTitleAt(index);
    			boolean isHTML = BasicHTML.isHTMLString(title);
    			if (isHTML) {
    				if (htmlViews == null) { // Initialize vector
    					htmlViews = createHTMLVector();
    				} else { // Vector already exists
    					View v = BasicHTML.createHTMLView(tp, title);
    					htmlViews.insertElementAt(v, index);
    				}
    			} else { // Not HTML
    				if (htmlViews != null) { // Add placeholder
    					htmlViews.insertElementAt(null, index);
    				} // else nada!
    			}
    		}
     
    		public void componentRemoved(ContainerEvent e) {
    			JTabbedPane tp = (JTabbedPane) e.getContainer();
    			Component child = e.getChild();
    			if (child instanceof UIResource) {
    				return;
    			}
    			Integer indexObj = (Integer) tp
    					.getClientProperty("__index_to_remove__");
    			if (indexObj != null) {
    				int index = indexObj.intValue();
    				if (htmlViews != null && htmlViews.size() >= index) {
    					htmlViews.removeElementAt(index);
    				}
    			}
    		}
    	}
     
    	private Vector createHTMLVector() {
    		Vector htmlViews = new Vector();
    		int count = tabPane.getTabCount();
    		if (count > 0) {
    			for (int i = 0; i < count; i++) {
    				String title = tabPane.getTitleAt(i);
    				if (BasicHTML.isHTMLString(title)) {
    					htmlViews.addElement(BasicHTML.createHTMLView(tabPane,
    							title));
    				} else {
    					htmlViews.addElement(null);
    				}
    			}
    		}
    		return htmlViews;
    	}
     
    	class MyMouseHandler extends MouseHandler {
    		public MyMouseHandler() {
    			super();
    		}
     
    		public void mousePressed(MouseEvent e) {
    			if (closeIndexStatus == OVER) {
    				closeIndexStatus = PRESSED;
    				tabScroller.tabPanel.repaint();
    				return;
    			}
     
    			if (maxIndexStatus == OVER) {
    				maxIndexStatus = PRESSED;
    				tabScroller.tabPanel.repaint();
    				return;
    			}
     
    		}
     
    		public void mouseClicked(MouseEvent e) {
    			super.mousePressed(e);
    		}
     
    		public void mouseReleased(MouseEvent e) {
     
    			updateOverTab(e.getX(), e.getY());
     
    			if (overTabIndex == -1) {
    				return;
    			}
     
    			if ( e.isPopupTrigger()) {
    				super.mousePressed(e);
     
    				closeIndexStatus = INACTIVE; //Prevent undesired action when
    				maxIndexStatus = INACTIVE; //right-clicking on icons
     
    				return;
    			}
     
    			if (closeIndexStatus == PRESSED) {
    				closeIndexStatus = OVER;
    				tabScroller.tabPanel.repaint();
    				((CloseableTabbedPane) tabPane).fireCloseTabEvent(e, overTabIndex);
    				return;
    			}
     
     
    		}
     
    		public void mouseExited(MouseEvent e) {
    			if (!mousePressed) {
    				overTabIndex = -1;
    				tabScroller.tabPanel.repaint();
    			}
    		}
     
    	}
     
    	class MyMouseMotionListener implements MouseMotionListener {
     
    		public void mouseMoved(MouseEvent e) {
    			mousePressed = false;
    			setTabIcons(e.getX(), e.getY());
    		}
     
    		public void mouseDragged(MouseEvent e) {
    			mousePressed = true;
    			setTabIcons(e.getX(), e.getY());
    		}
    	}
     
    }
    et pour l'utiliser il faut simplement replacer tabbedPane = new JTabbedPane(); par tabbedPane = new CloseableTabbedPane (true);

  4. #4
    Membre éclairé Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    584
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 584
    Par défaut
    salut,

    Ecoute fnobb, je sais plus quoi te dire !
    De plus le résultat est super propre !

    Ca marche !

  5. #5
    Membre éclairé Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    584
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 584
    Par défaut
    Salut,

    Juste un petite question:

    par défaut, le bouton de fermeture correspond au look and feel de L'utilisateur.
    J'aimerai forcer le look and feel, juste pour le tebbedPane, car le gros bouton rouge d'xp est trop grand et ça ne rend pas très bien

    ou
    j'aimerai utiliser une image de croix personnaliser

    merci

  6. #6
    Membre émérite
    Profil pro
    Développeur Back-End
    Inscrit en
    Avril 2003
    Messages
    782
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Back-End

    Informations forums :
    Inscription : Avril 2003
    Messages : 782
    Par défaut
    essaie avec new CloseableTabbedPane (false);

  7. #7
    Membre éclairé Avatar de pingoui
    Homme Profil pro
    Activité professionnelle sans liens avec le developpement
    Inscrit en
    Juillet 2004
    Messages
    584
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Activité professionnelle sans liens avec le developpement
    Secteur : Industrie

    Informations forums :
    Inscription : Juillet 2004
    Messages : 584
    Par défaut
    ok merci
    j'essauerai ça chez moi, ici au boulot j'ai pas xp

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [JTabbedPane] Double clic pour fermer un onglet
    Par NicoV dans le forum Composants
    Réponses: 4
    Dernier message: 30/12/2010, 23h10
  2. enlever la croi pour fermer un formulaire en vba?
    Par xtaze dans le forum Access
    Réponses: 6
    Dernier message: 15/06/2005, 17h16
  3. [JDialog] une icone pour ma JDialog ?
    Par anitshka dans le forum Agents de placement/Fenêtres
    Réponses: 2
    Dernier message: 24/05/2005, 10h59
  4. code pour fermer un formulaire
    Par rippey dans le forum IHM
    Réponses: 2
    Dernier message: 21/10/2003, 15h51
  5. Context menu Windows - icone pour un item
    Par Cameleon45 dans le forum Composants VCL
    Réponses: 7
    Dernier message: 07/03/2003, 13h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo