| 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 |
package org.pushingpixels.substance.flamingo.ribbon.ui; |
| 31 |
|
| 32 |
import java.awt.*; |
| 33 |
import java.awt.geom.Arc2D; |
| 34 |
import java.awt.geom.GeneralPath; |
| 35 |
import java.util.HashMap; |
| 36 |
import java.util.Map; |
| 37 |
|
| 38 |
import javax.swing.*; |
| 39 |
import javax.swing.border.EmptyBorder; |
| 40 |
import javax.swing.event.ChangeEvent; |
| 41 |
import javax.swing.event.ChangeListener; |
| 42 |
|
| 43 |
import org.pushingpixels.flamingo.api.ribbon.*; |
| 44 |
import org.pushingpixels.flamingo.internal.ui.ribbon.BasicRibbonUI; |
| 45 |
import org.pushingpixels.flamingo.internal.ui.ribbon.RibbonUI; |
| 46 |
import org.pushingpixels.flamingo.internal.ui.ribbon.appmenu.JRibbonApplicationMenuButton; |
| 47 |
import org.pushingpixels.flamingo.internal.utils.FlamingoUtilities; |
| 48 |
import org.pushingpixels.lafwidget.LafWidgetUtilities; |
| 49 |
import org.pushingpixels.lafwidget.utils.RenderingUtils; |
| 50 |
import org.pushingpixels.substance.api.*; |
| 51 |
import org.pushingpixels.substance.api.painter.border.SubstanceBorderPainter; |
| 52 |
import org.pushingpixels.substance.api.painter.fill.MatteFillPainter; |
| 53 |
import org.pushingpixels.substance.internal.painter.DecorationPainterUtils; |
| 54 |
import org.pushingpixels.substance.internal.painter.SeparatorPainterUtils; |
| 55 |
import org.pushingpixels.substance.internal.ui.SubstanceRootPaneUI; |
| 56 |
import org.pushingpixels.substance.internal.utils.*; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
public class SubstanceRibbonFrameTitlePane extends SubstanceTitlePane { |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
private class SubstanceContextualGroupComponent extends JComponent { |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
RibbonContextualTaskGroup taskGroup; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public SubstanceContextualGroupComponent( |
| 83 |
RibbonContextualTaskGroup taskGroup) { |
| 84 |
this.taskGroup = taskGroup; |
| 85 |
this.setOpaque(false); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
@Override |
| 94 |
protected void paintComponent(Graphics g) { |
| 95 |
int width = this.getWidth(); |
| 96 |
int height = this.getHeight(); |
| 97 |
Color hueColor = this.taskGroup.getHueColor(); |
| 98 |
|
| 99 |
Graphics2D g2d = (Graphics2D) g.create(); |
| 100 |
Paint paint = new GradientPaint(0, 0, SubstanceColorUtilities |
| 101 |
.getAlphaColor(hueColor, 0), 0, height, |
| 102 |
SubstanceColorUtilities.getAlphaColor(hueColor, |
| 103 |
(int) (255 * RibbonContextualTaskGroup.HUE_ALPHA))); |
| 104 |
g2d = (Graphics2D) g.create(); |
| 105 |
|
| 106 |
g2d.setPaint(paint); |
| 107 |
g2d.fillRect(0, 0, width, height); |
| 108 |
|
| 109 |
g2d.setColor(hueColor); |
| 110 |
g2d.drawLine(1, height - 1, width, height - 1); |
| 111 |
|
| 112 |
JRibbon ribbon = getRibbon(); |
| 113 |
|
| 114 |
SubstanceColorScheme scheme = SubstanceCoreUtilities.getSkin( |
| 115 |
rootPane).getEnabledColorScheme( |
| 116 |
DecorationAreaType.PRIMARY_TITLE_PANE); |
| 117 |
|
| 118 |
|
| 119 |
FontMetrics fm = this.getFontMetrics(ribbon.getFont()); |
| 120 |
int yOffset = (height - fm.getHeight()) / 2; |
| 121 |
RenderingUtils.installDesktopHints(g2d, this); |
| 122 |
|
| 123 |
int offset = SubstanceSizeUtils.getAdjustedSize(SubstanceSizeUtils |
| 124 |
.getComponentFontSize(this), 5, 2, 1, false); |
| 125 |
if (getComponentOrientation().isLeftToRight()) { |
| 126 |
SubstanceTextUtilities.paintText(g2d, this, new Rectangle( |
| 127 |
offset, yOffset, width, height - yOffset), |
| 128 |
this.taskGroup.getTitle(), -1, ribbon.getFont(), |
| 129 |
SubstanceColorUtilities.getForegroundColor(scheme), |
| 130 |
null); |
| 131 |
} else { |
| 132 |
SubstanceTextUtilities.paintText(g2d, this, new Rectangle(width |
| 133 |
- offset |
| 134 |
- g2d.getFontMetrics().stringWidth( |
| 135 |
this.taskGroup.getTitle()), yOffset, width, |
| 136 |
height - yOffset), this.taskGroup.getTitle(), -1, |
| 137 |
ribbon.getFont(), SubstanceColorUtilities |
| 138 |
.getForegroundColor(scheme), null); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
SeparatorPainterUtils.paintSeparator(ribbon, g2d, 2, height, |
| 143 |
SwingConstants.VERTICAL, false, height / 3, 0, true); |
| 144 |
|
| 145 |
|
| 146 |
g2d.translate(width - 1, 0); |
| 147 |
SeparatorPainterUtils.paintSeparator(ribbon, g2d, 2, height, |
| 148 |
SwingConstants.VERTICAL, false, height / 3, 0, true); |
| 149 |
|
| 150 |
g2d.dispose(); |
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
private class TaskbarPanel extends JPanel { |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public TaskbarPanel() { |
| 164 |
super(new TaskbarLayout()); |
| 165 |
this.setOpaque(false); |
| 166 |
int insets = SubstanceSizeUtils.getAdjustedSize(SubstanceSizeUtils |
| 167 |
.getComponentFontSize(this), 2, 3, 1, false); |
| 168 |
this.setBorder(new EmptyBorder(insets, insets, insets, insets)); |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
@Override |
| 177 |
protected void paintComponent(Graphics g) { |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
protected Shape getOutline(double insets) { |
| 188 |
double width = this.getWidth() - 2 * insets - 1; |
| 189 |
double height = this.getHeight() - 2 * insets - 1; |
| 190 |
float radius = (float) height; |
| 191 |
|
| 192 |
if (getComponentCount() == 0) { |
| 193 |
return null; |
| 194 |
} else { |
| 195 |
GeneralPath outline = new GeneralPath(); |
| 196 |
JRibbonApplicationMenuButton menuButton = FlamingoUtilities |
| 197 |
.getApplicationMenuButton(SwingUtilities |
| 198 |
.getWindowAncestor(this)); |
| 199 |
|
| 200 |
boolean ltr = getComponentOrientation().isLeftToRight(); |
| 201 |
|
| 202 |
double alpha = Math.asin((radius - insets / 2) |
| 203 |
/ (radius + insets / 2)); |
| 204 |
|
| 205 |
if (ltr) { |
| 206 |
|
| 207 |
outline.moveTo(insets + width - height / 2, insets); |
| 208 |
|
| 209 |
|
| 210 |
outline |
| 211 |
.append(new Arc2D.Double(insets + width - height, |
| 212 |
insets, height, height, 90, -180, |
| 213 |
Arc2D.OPEN), true); |
| 214 |
|
| 215 |
outline.lineTo(insets, insets + height); |
| 216 |
if (menuButton != null) { |
| 217 |
double arcSpan = 90; |
| 218 |
if (insets != 0) { |
| 219 |
arcSpan = 180.0 * alpha / Math.PI; |
| 220 |
} |
| 221 |
outline.append(new Arc2D.Double(insets - 2 * height, |
| 222 |
insets, 2 * height, 2 * height, 0, arcSpan, |
| 223 |
Arc2D.OPEN), true); |
| 224 |
} else { |
| 225 |
outline.lineTo(insets, insets); |
| 226 |
} |
| 227 |
} else { |
| 228 |
|
| 229 |
outline.moveTo(insets + height / 2, 0); |
| 230 |
|
| 231 |
outline.append(new Arc2D.Double(insets, 0, height, height, |
| 232 |
90, 180, Arc2D.OPEN), true); |
| 233 |
|
| 234 |
outline.lineTo(width - 1, insets + height); |
| 235 |
if (menuButton != null) { |
| 236 |
double arcSpan = -90; |
| 237 |
if (insets != 0) { |
| 238 |
arcSpan = -180.0 * alpha / Math.PI; |
| 239 |
} |
| 240 |
outline.append(new Arc2D.Double(width - 1, 0, |
| 241 |
2 * height, 2 * height, 180, arcSpan, |
| 242 |
Arc2D.OPEN), true); |
| 243 |
} else { |
| 244 |
outline.lineTo(width - 1, 0); |
| 245 |
} |
| 246 |
} |
| 247 |
outline.closePath(); |
| 248 |
|
| 249 |
return outline; |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
@Override |
| 259 |
public Dimension getPreferredSize() { |
| 260 |
Dimension result = super.getPreferredSize(); |
| 261 |
return new Dimension(result.width + result.height / 2, |
| 262 |
result.height); |
| 263 |
} |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
protected Map<RibbonContextualTaskGroup, SubstanceContextualGroupComponent> taskComponentMap; |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
protected ChangeListener ribbonFrameChangeListener; |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
protected TaskbarPanel taskbarPanel; |
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
public SubstanceRibbonFrameTitlePane(JRootPane root, SubstanceRootPaneUI ui) { |
| 291 |
super(root, ui); |
| 292 |
this.taskComponentMap = new HashMap<RibbonContextualTaskGroup, SubstanceContextualGroupComponent>(); |
| 293 |
this.taskbarPanel = new TaskbarPanel(); |
| 294 |
this.markExtraComponent(this.taskbarPanel, ExtraComponentKind.LEADING); |
| 295 |
this.add(this.taskbarPanel); |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
@Override |
| 304 |
protected LayoutManager createLayout() { |
| 305 |
return new RibbonFrameTitlePaneLayout(); |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
@Override |
| 314 |
public void addNotify() { |
| 315 |
super.addNotify(); |
| 316 |
|
| 317 |
JRibbon ribbon = this.getRibbon(); |
| 318 |
ribbon.putClientProperty(BasicRibbonUI.IS_USING_TITLE_PANE, |
| 319 |
Boolean.TRUE); |
| 320 |
|
| 321 |
this.syncRibbonState(); |
| 322 |
|
| 323 |
this.ribbonFrameChangeListener = new ChangeListener() { |
| 324 |
@Override |
| 325 |
public void stateChanged(ChangeEvent e) { |
| 326 |
syncRibbonState(); |
| 327 |
} |
| 328 |
}; |
| 329 |
ribbon.addChangeListener(this.ribbonFrameChangeListener); |
| 330 |
} |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
@Override |
| 338 |
public void removeNotify() { |
| 339 |
JRibbon ribbon = this.getRibbon(); |
| 340 |
ribbon.putClientProperty(BasicRibbonUI.IS_USING_TITLE_PANE, null); |
| 341 |
|
| 342 |
for (SubstanceContextualGroupComponent groupComp : this.taskComponentMap |
| 343 |
.values()) { |
| 344 |
this.remove(groupComp); |
| 345 |
} |
| 346 |
|
| 347 |
ribbon.removeChangeListener(this.ribbonFrameChangeListener); |
| 348 |
this.ribbonFrameChangeListener = null; |
| 349 |
|
| 350 |
super.removeNotify(); |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
protected void syncRibbonState() { |
| 358 |
|
| 359 |
for (SubstanceContextualGroupComponent groupComp : this.taskComponentMap |
| 360 |
.values()) { |
| 361 |
this.remove(groupComp); |
| 362 |
} |
| 363 |
this.taskComponentMap.clear(); |
| 364 |
JRibbon ribbon = this.getRibbon(); |
| 365 |
for (int i = 0; i < ribbon.getContextualTaskGroupCount(); i++) { |
| 366 |
RibbonContextualTaskGroup group = ribbon.getContextualTaskGroup(i); |
| 367 |
if (!ribbon.isVisible(group)) |
| 368 |
continue; |
| 369 |
SubstanceContextualGroupComponent taskGroupComponent = new SubstanceContextualGroupComponent( |
| 370 |
group); |
| 371 |
taskGroupComponent.applyComponentOrientation(this.getRibbon() |
| 372 |
.getComponentOrientation()); |
| 373 |
this.add(taskGroupComponent); |
| 374 |
this.taskComponentMap.put(group, taskGroupComponent); |
| 375 |
this.markExtraComponent(taskGroupComponent, |
| 376 |
ExtraComponentKind.MIDDLING); |
| 377 |
} |
| 378 |
|
| 379 |
this.taskbarPanel.removeAll(); |
| 380 |
this.taskbarPanel.setPreferredSize(null); |
| 381 |
for (Component taskbarComp : ribbon.getTaskbarComponents()) { |
| 382 |
this.taskbarPanel.add(taskbarComp); |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
protected class RibbonFrameTitlePaneLayout extends TitlePaneLayout { |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
@Override |
| 400 |
public void layoutContainer(Container c) { |
| 401 |
super.layoutContainer(c); |
| 402 |
|
| 403 |
JRibbon ribbon = getRibbon(); |
| 404 |
boolean ltr = ribbon.getComponentOrientation().isLeftToRight(); |
| 405 |
RibbonUI ribbonUI = ribbon.getUI(); |
| 406 |
|
| 407 |
if (ltr) { |
| 408 |
|
| 409 |
for (Map.Entry<RibbonContextualTaskGroup, SubstanceContextualGroupComponent> entry : taskComponentMap |
| 410 |
.entrySet()) { |
| 411 |
Rectangle taskGroupBounds = ribbonUI |
| 412 |
.getContextualTaskGroupBounds(entry.getKey()); |
| 413 |
|
| 414 |
|
| 415 |
int minTrailingX = c.getWidth(); |
| 416 |
|
| 417 |
for (int i = 0; i < c.getComponentCount(); i++) { |
| 418 |
Component child = c.getComponent(i); |
| 419 |
if (!child.isVisible()) |
| 420 |
continue; |
| 421 |
if (child instanceof JComponent) { |
| 422 |
ExtraComponentKind kind = (ExtraComponentKind) ((JComponent) child) |
| 423 |
.getClientProperty(EXTRA_COMPONENT_KIND); |
| 424 |
if (kind == ExtraComponentKind.LEADING) |
| 425 |
continue; |
| 426 |
if (child instanceof SubstanceContextualGroupComponent) |
| 427 |
continue; |
| 428 |
|
| 429 |
minTrailingX = Math.min(child.getX(), minTrailingX); |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
int width = taskGroupBounds.width; |
| 434 |
if (taskGroupBounds.x + width > (minTrailingX - 5)) { |
| 435 |
width = minTrailingX - 5 - taskGroupBounds.x; |
| 436 |
} |
| 437 |
entry.getValue().setBounds( |
| 438 |
new Rectangle(taskGroupBounds.x, 0, width, c |
| 439 |
.getHeight())); |
| 440 |
|
| 441 |
|
| 442 |
entry.getValue().setVisible( |
| 443 |
!ribbonUI.isShowingScrollsForTaskToggleButtons()); |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
taskbarPanel.setVisible(true); |
| 448 |
Dimension pref = taskbarPanel.getPreferredSize(); |
| 449 |
if (taskbarPanel.getComponentCount() == 0) { |
| 450 |
|
| 451 |
|
| 452 |
pref.width = 0; |
| 453 |
} |
| 454 |
|
| 455 |
SubstanceRibbonRootPaneUI rootPaneUI = (SubstanceRibbonRootPaneUI) getRootPane() |
| 456 |
.getUI(); |
| 457 |
JRibbonApplicationMenuButton menuButton = rootPaneUI.applicationMenuButton; |
| 458 |
|
| 459 |
if (menuButton != null) { |
| 460 |
if (menuButton.isVisible()) { |
| 461 |
int maxLeadingX = menuButton.getX() |
| 462 |
+ menuButton.getWidth() + 2 |
| 463 |
* getTaskBarLayoutGap(taskbarPanel); |
| 464 |
if (taskbarPanel.isVisible()) { |
| 465 |
taskbarPanel.setBounds(maxLeadingX, 0, pref.width, |
| 466 |
c.getHeight()); |
| 467 |
} |
| 468 |
menuBar.setVisible(false); |
| 469 |
} else { |
| 470 |
if (taskbarPanel.isVisible()) { |
| 471 |
if (pref.width == 0) { |
| 472 |
taskbarPanel.setBounds(menuBar.getX() |
| 473 |
+ menuBar.getWidth(), 0, pref.width, c |
| 474 |
.getHeight()); |
| 475 |
} else { |
| 476 |
taskbarPanel.setBounds(menuBar.getX() |
| 477 |
+ menuBar.getWidth() + 5, 0, |
| 478 |
pref.width, c.getHeight()); |
| 479 |
} |
| 480 |
} |
| 481 |
menuBar.setVisible(true); |
| 482 |
} |
| 483 |
} else { |
| 484 |
menuBar.setVisible(true); |
| 485 |
} |
| 486 |
} else { |
| 487 |
|
| 488 |
for (Map.Entry<RibbonContextualTaskGroup, SubstanceContextualGroupComponent> entry : taskComponentMap |
| 489 |
.entrySet()) { |
| 490 |
Rectangle taskGroupBounds = ribbonUI |
| 491 |
.getContextualTaskGroupBounds(entry.getKey()); |
| 492 |
|
| 493 |
|
| 494 |
int maxTrailingX = 0; |
| 495 |
|
| 496 |
for (int i = 0; i < c.getComponentCount(); i++) { |
| 497 |
Component child = c.getComponent(i); |
| 498 |
if (!child.isVisible()) |
| 499 |
continue; |
| 500 |
if (child instanceof JComponent) { |
| 501 |
ExtraComponentKind kind = (ExtraComponentKind) ((JComponent) child) |
| 502 |
.getClientProperty(EXTRA_COMPONENT_KIND); |
| 503 |
if (kind == ExtraComponentKind.LEADING) |
| 504 |
continue; |
| 505 |
if (child instanceof SubstanceContextualGroupComponent) |
| 506 |
continue; |
| 507 |
|
| 508 |
maxTrailingX = Math.max(child.getX() |
| 509 |
+ child.getWidth(), maxTrailingX); |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
int width = taskGroupBounds.width; |
| 514 |
int x = taskGroupBounds.x; |
| 515 |
if (taskGroupBounds.x < (maxTrailingX + 5)) { |
| 516 |
int diff = maxTrailingX + 5 - taskGroupBounds.x; |
| 517 |
x += diff; |
| 518 |
width -= diff; |
| 519 |
} |
| 520 |
entry.getValue().setBounds( |
| 521 |
new Rectangle(x, 0, width, c.getHeight())); |
| 522 |
|
| 523 |
|
| 524 |
entry.getValue().setVisible( |
| 525 |
!ribbonUI.isShowingScrollsForTaskToggleButtons()); |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
taskbarPanel.setVisible(true); |
| 530 |
Dimension pref = taskbarPanel.getPreferredSize(); |
| 531 |
if (taskbarPanel.getComponentCount() == 0) { |
| 532 |
|
| 533 |
|
| 534 |
pref.width = 0; |
| 535 |
} |
| 536 |
|
| 537 |
SubstanceRibbonRootPaneUI rootPaneUI = (SubstanceRibbonRootPaneUI) getRootPane() |
| 538 |
.getUI(); |
| 539 |
JRibbonApplicationMenuButton menuButton = rootPaneUI.applicationMenuButton; |
| 540 |
|
| 541 |
if (menuButton != null) { |
| 542 |
if (menuButton.isVisible()) { |
| 543 |
int maxLeadingX = menuButton.getX() - 2 |
| 544 |
* getTaskBarLayoutGap(taskbarPanel); |
| 545 |
if (taskbarPanel.isVisible()) { |
| 546 |
taskbarPanel.setBounds(maxLeadingX - pref.width, 0, |
| 547 |
pref.width, c.getHeight()); |
| 548 |
} |
| 549 |
menuBar.setVisible(false); |
| 550 |
} else { |
| 551 |
if (taskbarPanel.isVisible()) { |
| 552 |
if (pref.width == 0) { |
| 553 |
taskbarPanel.setBounds(menuBar.getX(), 0, |
| 554 |
pref.width, c.getHeight()); |
| 555 |
} else { |
| 556 |
taskbarPanel.setBounds(menuBar.getX() - 5 |
| 557 |
- pref.width, 0, pref.width, c |
| 558 |
.getHeight()); |
| 559 |
} |
| 560 |
} |
| 561 |
menuBar.setVisible(true); |
| 562 |
} |
| 563 |
} else { |
| 564 |
menuBar.setVisible(true); |
| 565 |
} |
| 566 |
} |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
private class TaskbarLayout implements LayoutManager { |
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
@Override |
| 583 |
public void addLayoutComponent(String name, Component c) { |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
@Override |
| 592 |
public void removeLayoutComponent(Component c) { |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
@Override |
| 601 |
public Dimension preferredLayoutSize(Container c) { |
| 602 |
Insets ins = c.getInsets(); |
| 603 |
int pw = 0; |
| 604 |
int gap = getTaskBarLayoutGap(c); |
| 605 |
for (Component regComp : getRibbon().getTaskbarComponents()) { |
| 606 |
|
| 607 |
if (regComp.isVisible()){ |
| 608 |
pw += regComp.getPreferredSize().width; |
| 609 |
pw += gap; |
| 610 |
} |
| 611 |
} |
| 612 |
return new Dimension(pw + ins.left + ins.right, c.getParent() |
| 613 |
.getHeight()); |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
@Override |
| 622 |
public Dimension minimumLayoutSize(Container c) { |
| 623 |
return this.preferredLayoutSize(c); |
| 624 |
} |
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
@Override |
| 632 |
public void layoutContainer(Container c) { |
| 633 |
Insets ins = c.getInsets(); |
| 634 |
int gap = getTaskBarLayoutGap(c); |
| 635 |
boolean ltr = getComponentOrientation().isLeftToRight(); |
| 636 |
int x = ltr ? ins.left : c.getWidth() - ins.right; |
| 637 |
for (Component regComp : getRibbon().getTaskbarComponents()) { |
| 638 |
|
| 639 |
if (regComp.isVisible()){ |
| 640 |
int pw = regComp.getPreferredSize().width; |
| 641 |
if (ltr) { |
| 642 |
regComp.setBounds(x, ins.top, pw, c.getHeight() - ins.top |
| 643 |
- ins.bottom); |
| 644 |
x += (pw + gap); |
| 645 |
} else { |
| 646 |
regComp.setBounds(x - pw, ins.top, pw, c.getHeight() |
| 647 |
- ins.top - ins.bottom); |
| 648 |
x -= (pw + gap); |
| 649 |
} |
| 650 |
} |
| 651 |
} |
| 652 |
} |
| 653 |
} |
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
private JRibbon getRibbon() { |
| 662 |
JRibbonFrame ribbonFrame = (JRibbonFrame) SwingUtilities |
| 663 |
.getWindowAncestor(this); |
| 664 |
JRibbon ribbon = ribbonFrame.getRibbon(); |
| 665 |
return ribbon; |
| 666 |
} |
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
private int getTaskBarLayoutGap(Container c) { |
| 676 |
return SubstanceSizeUtils.getAdjustedSize(SubstanceSizeUtils |
| 677 |
.getComponentFontSize(c), 1, 6, 1, false); |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
@Override |
| 688 |
public void paintComponent(Graphics g) { |
| 689 |
super.paintComponent(g); |
| 690 |
|
| 691 |
Graphics2D g2d = (Graphics2D) g.create(); |
| 692 |
if (taskbarPanel.getWidth() != 0) { |
| 693 |
g2d.translate(taskbarPanel.getX(), taskbarPanel.getY()); |
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
paintTaskBarPanelOutline(g2d, this.taskbarPanel); |
| 699 |
g2d.translate(-taskbarPanel.getX(), -taskbarPanel.getY()); |
| 700 |
} |
| 701 |
|
| 702 |
if (SubstanceLookAndFeel.getCurrentSkin(this).getOverlayPainters( |
| 703 |
DecorationAreaType.PRIMARY_TITLE_PANE).isEmpty()) { |
| 704 |
|
| 705 |
SubstanceColorScheme compScheme = SubstanceColorSchemeUtilities |
| 706 |
.getColorScheme(this, ColorSchemeAssociationKind.SEPARATOR, |
| 707 |
ComponentState.ENABLED); |
| 708 |
Color sepColor = compScheme.isDark() ? SeparatorPainterUtils |
| 709 |
.getSeparatorShadowColor(compScheme) |
| 710 |
: SeparatorPainterUtils.getSeparatorDarkColor(compScheme); |
| 711 |
g2d.setColor(sepColor); |
| 712 |
g2d.drawLine(0, this.getHeight() - 1, this.getWidth(), this |
| 713 |
.getHeight() - 1); |
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
} |
| 718 |
g2d.dispose(); |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
protected static void paintTaskBarPanelOutline(Graphics g, |
| 730 |
TaskbarPanel taskbarPanel) { |
| 731 |
int borderDelta = (int) Math.floor(SubstanceSizeUtils |
| 732 |
.getBorderStrokeWidth(SubstanceSizeUtils |
| 733 |
.getComponentFontSize(taskbarPanel)) / 2.0); |
| 734 |
int borderThickness = (int) SubstanceSizeUtils |
| 735 |
.getBorderStrokeWidth(SubstanceSizeUtils |
| 736 |
.getComponentFontSize(taskbarPanel)); |
| 737 |
|
| 738 |
Shape contour = taskbarPanel.getOutline(borderDelta); |
| 739 |
Shape contourInner = taskbarPanel.getOutline(borderDelta |
| 740 |
+ borderThickness); |
| 741 |
|
| 742 |
SubstanceColorScheme colorScheme = SubstanceColorSchemeUtilities |
| 743 |
.getColorScheme(taskbarPanel, ComponentState.ENABLED); |
| 744 |
SubstanceColorScheme borderScheme = SubstanceColorSchemeUtilities |
| 745 |
.getColorScheme(taskbarPanel, |
| 746 |
ColorSchemeAssociationKind.BORDER, |
| 747 |
ComponentState.ENABLED); |
| 748 |
SubstanceBorderPainter borderPainter = SubstanceCoreUtilities |
| 749 |
.getBorderPainter(taskbarPanel); |
| 750 |
|
| 751 |
Graphics2D g2d = (Graphics2D) g.create(); |
| 752 |
g2d.setComposite(AlphaComposite.SrcOver.derive(0.6f)); |
| 753 |
if (contour != null) { |
| 754 |
Shape clip = g2d.getClip(); |
| 755 |
g2d.clip(contour); |
| 756 |
DecorationPainterUtils.paintDecorationBackground(g2d, taskbarPanel, |
| 757 |
true); |
| 758 |
g2d.setComposite(LafWidgetUtilities.getAlphaComposite(taskbarPanel, |
| 759 |
0.3f, g)); |
| 760 |
MatteFillPainter.INSTANCE.paintContourBackground(g2d, taskbarPanel, |
| 761 |
taskbarPanel.getWidth(), taskbarPanel.getHeight(), contour |
| 762 |
.getBounds(), false, colorScheme, false); |
| 763 |
g2d.setComposite(LafWidgetUtilities.getAlphaComposite(taskbarPanel, |
| 764 |
1.0f, g)); |
| 765 |
g2d.setClip(clip); |
| 766 |
|
| 767 |
} |
| 768 |
borderPainter.paintBorder(g2d, taskbarPanel, taskbarPanel.getWidth(), |
| 769 |
taskbarPanel.getHeight(), contour, contourInner, borderScheme); |
| 770 |
g2d.dispose(); |
| 771 |
} |
| 772 |
} |