Browse Source

Added ToolBarUI.

pull/15/head
weisj 5 years ago
parent
commit
6f3b9c0ee3
  1. 52
      src/main/java/com/weis/darklaf/decorators/MouseResponder.java
  2. 72
      src/main/java/com/weis/darklaf/ui/toolbar/DarkToolBarBorder.java
  3. 309
      src/main/java/com/weis/darklaf/ui/toolbar/DarkToolBarUI.java
  4. 1207
      src/main/java/com/weis/darklaf/ui/toolbar/DarkToolBarUIBridge.java
  5. 50
      src/main/java/com/weis/darklaf/ui/toolbar/DropPreviewPanel.java
  6. 2
      src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipBorder.java
  7. 16
      src/main/resources/com/weis/darklaf/darcula.properties
  8. 2
      src/main/resources/com/weis/darklaf/darcula_windows.properties
  9. 11
      src/main/resources/com/weis/darklaf/icons/dark/navigation/horizontalGrip.svg
  10. 11
      src/main/resources/com/weis/darklaf/icons/dark/navigation/verticalGrip.svg
  11. 11
      src/main/resources/com/weis/darklaf/icons/light/navigation/horizontalGrip.svg
  12. 11
      src/main/resources/com/weis/darklaf/icons/light/navigation/verticalGrip.svg
  13. 180
      src/test/java/ToolBarDemo.java
  14. 10
      src/test/java/UIDemo.java
  15. 18
      src/test/java/UIManagerDefaults.java

52
src/main/java/com/weis/darklaf/decorators/MouseResponder.java

@ -0,0 +1,52 @@
package com.weis.darklaf.decorators;
import org.jetbrains.annotations.Contract;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.function.Consumer;
public class MouseResponder implements MouseListener {
private final Consumer<MouseEvent> consumer;
@Contract(pure = true)
public MouseResponder(final Consumer<MouseEvent> consumer) {
this.consumer = consumer;
}
@Override
public void mouseClicked(final MouseEvent e) {
if (consumer != null) {
consumer.accept(e);
}
}
@Override
public void mousePressed(final MouseEvent e) {
if (consumer != null) {
consumer.accept(e);
}
}
@Override
public void mouseReleased(final MouseEvent e) {
if (consumer != null) {
consumer.accept(e);
}
}
@Override
public void mouseEntered(final MouseEvent e) {
if (consumer != null) {
consumer.accept(e);
}
}
@Override
public void mouseExited(final MouseEvent e) {
if (consumer != null) {
consumer.accept(e);
}
}
}

72
src/main/java/com/weis/darklaf/ui/toolbar/DarkToolBarBorder.java

@ -0,0 +1,72 @@
package com.weis.darklaf.ui.toolbar;
import org.jetbrains.annotations.Contract;
import javax.swing.*;
import javax.swing.border.AbstractBorder;
import javax.swing.plaf.UIResource;
import java.awt.*;
public class DarkToolBarBorder extends AbstractBorder implements UIResource, SwingConstants {
public void paintBorder(final Component c, final Graphics g,
final int x, final int y, final int w, final int h) {
g.translate(x, y);
if (isFloatable(c)) {
if (((JToolBar) c).getOrientation() == HORIZONTAL) {
var icon = getHorizontalGrip();
int yIcon = h / 2 - icon.getIconHeight() / 2;
if (c.getComponentOrientation().isLeftToRight()) {
icon.paintIcon(c, g, 0, yIcon);
} else {
icon.paintIcon(c, g, w - icon.getIconWidth(), yIcon);
}
} else {
var icon = getVerticalGrip();
int xIcon = w / 2 - icon.getIconWidth() / 2;
icon.paintIcon(c, g, xIcon, 0);
}
}
g.translate(-x, -y);
}
@Contract("null -> false")
private boolean isFloatable(final Component c) {
return c instanceof JToolBar && ((JToolBar) c).isFloatable();
}
protected Icon getHorizontalGrip() {
return UIManager.getIcon("ToolBar.horizontalGrip.icon");
}
protected Icon getVerticalGrip() {
return UIManager.getIcon("ToolBar.verticalGrip.icon");
}
public Insets getBorderInsets(final Component c, final Insets newInsets) {
if (isFloatable(c)) {
if (((JToolBar) c).getOrientation() == HORIZONTAL) {
var icon = getHorizontalGrip();
if (c.getComponentOrientation().isLeftToRight()) {
newInsets.left = icon.getIconWidth();
} else {
newInsets.right = icon.getIconWidth();
}
} else {
newInsets.top = getVerticalGrip().getIconHeight();
}
}
if (c instanceof JToolBar) {
Insets margin = ((JToolBar) c).getMargin();
if (margin != null) {
newInsets.left += margin.left;
newInsets.top += margin.top;
newInsets.right += margin.right;
newInsets.bottom += margin.bottom;
}
}
return newInsets;
}
}

309
src/main/java/com/weis/darklaf/ui/toolbar/DarkToolBarUI.java

@ -0,0 +1,309 @@
package com.weis.darklaf.ui.toolbar;
import com.weis.darklaf.decorators.MouseResponder;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.plaf.ComponentUI;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class DarkToolBarUI extends DarkToolBarUIBridge {
private static final Robot robot = createRobot();
private final DropPreviewPanel previewPanel = new DropPreviewPanel();
private Timer timer = new Timer(5, e -> dragTo());
private Dimension verticalDim = new Dimension(0, 0);
private Dimension horizontalDim = new Dimension(0, 0);
@NotNull
@Contract(value = "_ -> new", pure = true)
public static ComponentUI createUI(final JComponent c) {
return new DarkToolBarUI();
}
@Nullable
private static Robot createRobot() {
try {
return new Robot();
} catch (AWTException e) {
return null;
}
}
@Override
public void installUI(final JComponent c) {
super.installUI(c);
previewPanel.setToolBar(toolBar);
dragWindow = createDragWindow(toolBar);
floatingToolBar = createFloatingWindow(toolBar);
}
@Override
protected void installListeners() {
super.installListeners();
}
@Override
protected void uninstallListeners() {
super.uninstallListeners();
}
public void paint(@NotNull final Graphics g, @NotNull final JComponent c) {
g.setColor(UIManager.getColor("ToolBar.background"));
g.fillRect(0, 0, c.getWidth(), c.getHeight());
}
@Override
protected void dragTo() {
if (toolBar.isFloatable()) {
Point offset = dragWindow.getOffset();
Point global = MouseInfo.getPointerInfo().getLocation();
Point dragPoint = new Point(global.x - offset.x, global.y - offset.y);
ensureDockingSource();
Point dockingPosition = dockingSource.getLocationOnScreen();
Point comparisonPoint = new Point(global.x - dockingPosition.x, global.y - dockingPosition.y);
if (canDock(dockingSource, comparisonPoint)) {
String constraint = getDockingConstraint(dockingSource, comparisonPoint);
setOrientation(mapConstraintToOrientation(constraint));
dockingSource.add(previewPanel, constraint);
} else {
setOrientation(mapConstraintToOrientation(constraintBeforeFloating));
dockingSource.remove(previewPanel);
}
updateDockingSource();
dragWindow.setLocation(dragPoint.x, dragPoint.y);
startDrag();
}
}
protected void startDrag() {
if (!dragWindow.isVisible()) {
dragWindow.getContentPane().add(toolBar);
updateDockingSource();
dragWindow.setVisible(true);
//Is needed to intercept ongoing drag.
SwingUtilities.invokeLater(() -> robot.mouseRelease(MouseEvent.BUTTON1_DOWN_MASK));
var oldOrientation = toolBar.getOrientation();
toolBar.setOrientation(SwingConstants.VERTICAL);
verticalDim = toolBar.getPreferredSize();
toolBar.setOrientation(SwingConstants.HORIZONTAL);
horizontalDim = toolBar.getPreferredSize();
toolBar.setOrientation(oldOrientation);
timer.start();
}
}
protected void stopDrag() {
dragWindow.setVisible(false);
timer.stop();
}
private void ensureDockingSource() {
if (dockingSource == null) {
dockingSource = toolBar.getParent();
}
}
@Override
public void setFloating(final boolean b, final Point p) {
if (toolBar.isFloatable()) {
boolean visible = false;
Window ancestor = SwingUtilities.getWindowAncestor(toolBar);
if (ancestor != null) {
visible = ancestor.isVisible();
}
if (dragWindow != null) {
stopDrag();
}
floating = b;
if (b) {
constraintBeforeFloating = calculateConstraint();
if (propertyListener != null) {
UIManager.addPropertyChangeListener(propertyListener);
}
floatingToolBar.getContentPane().add(toolBar, BorderLayout.CENTER);
if (floatingToolBar instanceof Window) {
((Window) floatingToolBar).pack();
((Window) floatingToolBar).setLocation(floatingX, floatingY);
if (visible) {
((Window) floatingToolBar).setVisible(true);
} else {
if (ancestor != null) {
ancestor.addWindowListener(new WindowAdapter() {
public void windowOpened(final WindowEvent e) {
((Window) floatingToolBar).setVisible(true);
}
});
}
}
}
} else {
if (floatingToolBar instanceof Window) {
((Window) floatingToolBar).setVisible(false);
}
floatingToolBar.getContentPane().remove(toolBar);
String constraint = getDockingConstraint(dockingSource, p);
if (constraint == null) {
constraint = BorderLayout.NORTH;
}
setOrientation(mapConstraintToOrientation(constraint));
dockingSource.add(toolBar, constraint);
updateDockingSource();
}
}
}
@Override
protected void floatAt() {
if (toolBar.isFloatable()) {
try {
Point offset = dragWindow.getOffset();
Point global = MouseInfo.getPointerInfo().getLocation();
setFloatingLocation(global.x - offset.x, global.y - offset.y);
if (dockingSource != null) {
Point dockingPosition = dockingSource.getLocationOnScreen();
Point comparisonPoint = new Point(global.x - dockingPosition.x,
global.y - dockingPosition.y);
if (canDock(dockingSource, comparisonPoint)) {
setFloating(false, comparisonPoint);
} else {
setFloating(true, null);
}
} else {
setFloating(true, null);
}
dockingSource.remove(previewPanel);
} catch (IllegalComponentStateException ignored) {
}
}
}
protected void updateDockingSource() {
dockingSource.invalidate();
Container dockingSourceParent = dockingSource.getParent();
if (dockingSourceParent != null) { dockingSourceParent.validate(); }
dockingSource.repaint();
}
protected String getDockingConstraint(final Component c, final Point p) {
if (p == null) return constraintBeforeFloating;
if (c.contains(p)) {
//North
if (p.y < horizontalDim.height && !isBlocked(c, BorderLayout.NORTH)) {
return BorderLayout.NORTH;
}
//South
if (p.y >= c.getHeight() - horizontalDim.height && !isBlocked(c, BorderLayout.SOUTH)) {
return BorderLayout.SOUTH;
}
// East
if (p.x >= c.getWidth() - verticalDim.width && !isBlocked(c, BorderLayout.EAST)) {
return BorderLayout.EAST;
}
// West
if (p.x < verticalDim.width && !isBlocked(c, BorderLayout.WEST)) {
return BorderLayout.WEST;
}
}
return null;
}
@Override
protected boolean isBlocked(final Component comp, final Object constraint) {
if (comp instanceof Container) {
Container cont = (Container) comp;
LayoutManager lm = cont.getLayout();
if (lm instanceof BorderLayout) {
BorderLayout blm = (BorderLayout) lm;
Component c = blm.getLayoutComponent(cont, constraint);
return (c != null && c != toolBar && c != previewPanel);
}
}
return false;
}
protected void setBorderToNonRollover(final Component c) {
}
@Override
protected void paintDragWindow(@NotNull final Graphics g) {
g.setColor(dragWindow.getBackground());
int w = dragWindow.getWidth();
int h = dragWindow.getHeight();
g.fillRect(0, 0, w, h);
g.setColor(dragWindow.getBorderColor());
g.fillRect(0, 0, w, 1);
g.fillRect(0, 0, 1, h);
g.fillRect(w - 1, 0, 1, h);
g.fillRect(0, h - 1, w, 1);
}
@Override
protected DragWindow createDragWindow(final JToolBar toolbar) {
Window frame = null;
if (toolBar != null) {
Container p = toolbar.getParent();
while (p != null && !(p instanceof Window)) {
p = p.getParent();
}
if (p != null) {
frame = (Window) p;
}
}
if (floatingToolBar instanceof Window) { frame = (Window) floatingToolBar; }
return new DarkDragWindow(frame);
}
protected class DarkDragWindow extends DragWindow {
protected DarkDragWindow(final Window w) {
super(w);
setLayout(new BorderLayout());
setBackground(toolBar.getBackground());
var glassPane = new JPanel();
glassPane.setOpaque(false);
glassPane.addMouseListener(new MouseResponder(e -> {
e.consume();
if (e.getID() == MouseEvent.MOUSE_RELEASED) {
floatAt();
}
}));
setGlassPane(glassPane);
glassPane.setVisible(true);
}
@Override
public void setOrientation(final int o) {
super.setOrientation(o);
var size = toolBar.getPreferredSize();
size.width += 2;
size.height += 2;
setSize(size);
doLayout();
}
@Override
public Point getOffset() {
return new Point(getWidth() / 2, getHeight() / 2);
}
}
}

1207
src/main/java/com/weis/darklaf/ui/toolbar/DarkToolBarUIBridge.java

File diff suppressed because it is too large Load Diff

50
src/main/java/com/weis/darklaf/ui/toolbar/DropPreviewPanel.java

@ -0,0 +1,50 @@
package com.weis.darklaf.ui.toolbar;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
public class DropPreviewPanel extends JComponent {
private JToolBar toolBar;
public void setToolBar(final JToolBar toolBar) {
this.toolBar = toolBar;
}
@Override
public void paint(@NotNull final Graphics g) {
g.setColor(getBackgroundColor());
g.fillRect(0, 0, getWidth(), getHeight());
}
protected Color getBackgroundColor() {
var useToolbar = Boolean.TRUE.equals(toolBar.getClientProperty("JToolBar.drag.useToolbarBackground"));
if (!useToolbar) {
var c = UIManager.getColor("ToolBar.dropColor");
if (c == null) {
return toolBar.getBackground();
}
}
return toolBar.getBackground();
}
@Override
public Dimension getPreferredSize() {
if (toolBar != null) { return toolBar.getPreferredSize(); }
return super.getPreferredSize();
}
@Override
public Dimension getMinimumSize() {
if (toolBar != null) { return toolBar.getMinimumSize(); }
return super.getMinimumSize();
}
@Override
public Dimension getMaximumSize() {
if (toolBar != null) { return toolBar.getMaximumSize(); }
return super.getMinimumSize();
}
}

2
src/main/java/com/weis/darklaf/ui/tooltip/DarkTooltipBorder.java

@ -23,7 +23,7 @@ public class DarkTooltipBorder implements Border, UIResource {
bubbleBorder.setThickness(1);
bubbleBorder.setPointerSize(8);
bubbleBorder.setPointerWidth(12);
bubbleBorder.setPointerSide(Alignment.EAST);
bubbleBorder.setPointerSide(Alignment.CENTER);
}

16
src/main/resources/com/weis/darklaf/darcula.properties

@ -86,15 +86,8 @@ OptionPane.errorIcon = dialog/errorDialog.s
ColorChooser.pipette.icon = misc/pipette.svg[aware]
ColorChooser.pipetteRollover.icon = misc/pipette_rollover.svg[aware]
#Shadows Experimental
#Shadow.Top.icon = shadow/top.svg(4,7)
#Shadow.TopRight.icon = shadow/topRight.svg(18,14)
#Shadow.Right.icon = shadow/right.svg(11,4)
#Shadow.BottomRight.icon = shadow/bottomRight.svg(18,22)
#Shadow.Bottom.icon = shadow/bottom.svg(4,14)
#Shadow.BottomLeft.icon = shadow/bottomLeft.svg(18,22)
#Shadow.Left.icon = shadow/left.svg(11,4)
#Shadow.TopLeft.icon = shadow/topLeft.svg(18,14)
ToolBar.horizontalGrip.icon = navigation/horizontalGrip.svg[aware](5,20)
ToolBar.verticalGrip.icon = navigation/verticalGrip.svg[aware](20,5)
#Darcula Colors
darcula.background = 3c3f41
@ -415,6 +408,11 @@ Tooltip.background = 4B4D4D
Tooltip.borderColor = 5B5D5F
ToolTip.border = com.weis.darklaf.ui.tooltip.DarkTooltipBorder
#ToolBar
ToolBarUI = com.weis.darklaf.ui.toolbar.DarkToolBarUI
ToolBar.border = com.weis.darklaf.ui.toolbar.DarkToolBarBorder
ToolBar.dropColor = 4B4B4B
#InternalFrame
InternalFrameUI = com.bulenkov.darcula.ui.DarculaInternalFrameUI
InternalFrame.border = com.bulenkov.darcula.ui.DarculaInternalFrameBorder

2
src/main/resources/com/weis/darklaf/darcula_windows.properties

@ -60,7 +60,7 @@ darcula.selectionForeground = bbbbbb
PopupMenu.border = com.weis.darklaf.ui.menu.DarkPopupMenuBorder
#Toolbar
ToolBarUI = com.bulenkov.darcula.ui.DarculaToolBarUI
ToolBarUI = com.weis.darklaf.ui.toolbar.DarkToolBarUI
ToolBar.floatingBackground = 3c3f41
ToolBar.floatingForeground = bbbbbb
ToolBar.borderColor = 555555

11
src/main/resources/com/weis/darklaf/icons/dark/navigation/horizontalGrip.svg

@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" width="5" height="20" viewBox="0 0 5 20">
<g fill="none" fill-rule="evenodd">
<rect height="6" width="1.5" y="0" x="0.5" fill="#AFB1B3"/>
<rect height="6" width="1.5" y="7" x="0.5" fill="#AFB1B3"/>
<rect height="6" width="1.5" y="14" x="0.5" fill="#AFB1B3"/>
<rect height="6" width="1.5" y="0" x="3" fill="#AFB1B3"/>
<rect height="6" width="1.5" y="7" x="3" fill="#AFB1B3"/>
<rect height="6" width="1.5" y="14" x="3" fill="#AFB1B3"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 515 B

11
src/main/resources/com/weis/darklaf/icons/dark/navigation/verticalGrip.svg

@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="5" viewBox="0 0 20 5">
<g fill="none" fill-rule="evenodd">
<rect width="6" height="1.5" x="0" y="0.5" fill="#AFB1B3"/>
<rect width="6" height="1.5" x="7" y="0.5" fill="#AFB1B3"/>
<rect width="6" height="1.5" x="14" y="0.5" fill="#AFB1B3"/>
<rect width="6" height="1.5" x="0" y="3" fill="#AFB1B3"/>
<rect width="6" height="1.5" x="7" y="3" fill="#AFB1B3"/>
<rect width="6" height="1.5" x="14" y="3" fill="#AFB1B3"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 515 B

11
src/main/resources/com/weis/darklaf/icons/light/navigation/horizontalGrip.svg

@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" width="5" height="20" viewBox="0 0 5 20">
<g fill="none" fill-rule="evenodd">
<rect height="6" width="1.5" y="0" x="0.5" fill="#6E6E6E"/>
<rect height="6" width="1.5" y="7" x="0.5" fill="#6E6E6E"/>
<rect height="6" width="1.5" y="14" x="0.5" fill="#6E6E6E"/>
<rect height="6" width="1.5" y="0" x="3" fill="#6E6E6E"/>
<rect height="6" width="1.5" y="7" x="3" fill="#6E6E6E"/>
<rect height="6" width="1.5" y="14" x="3" fill="#6E6E6E"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 515 B

11
src/main/resources/com/weis/darklaf/icons/light/navigation/verticalGrip.svg

@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="5" viewBox="0 0 20 5">
<g fill="none" fill-rule="evenodd">
<rect width="6" height="1.5" x="0" y="0.5" fill="#6E6E6E"/>
<rect width="6" height="1.5" x="7" y="0.5" fill="#6E6E6E"/>
<rect width="6" height="1.5" x="14" y="0.5" fill="#6E6E6E"/>
<rect width="6" height="1.5" x="0" y="3" fill="#6E6E6E"/>
<rect width="6" height="1.5" x="7" y="3" fill="#6E6E6E"/>
<rect width="6" height="1.5" x="14" y="3" fill="#6E6E6E"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 515 B

180
src/test/java/ToolBarDemo.java

@ -0,0 +1,180 @@
/*
* Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Oracle or the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ToolBarDemo.java requires the following addditional files:
* images/Back24.gif
* images/Forward24.gif
* images/Up24.gif
*/
import com.weis.darklaf.LafManager;
import org.jetbrains.annotations.NotNull;
import javax.swing.JToolBar;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import java.net.URL;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ToolBarDemo extends JPanel implements ActionListener {
private JTextArea textArea;
private static final String PREVIOUS = "previous";
private static final String UP = "up";
private static final String NEXT = "next";
private ToolBarDemo() {
super(new BorderLayout());
//Create the toolbar.
JToolBar toolBar = new JToolBar("Still draggable");
addButtons(toolBar);
//Create the text area used for output. Request
//enough space for 5 rows and 30 columns.
textArea = new JTextArea(5, 30);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
//Lay out the main panel.
setPreferredSize(new Dimension(450, 130));
add(toolBar, BorderLayout.PAGE_START);
add(scrollPane, BorderLayout.CENTER);
}
private void addButtons(@NotNull final JToolBar toolBar) {
JButton button;
//first button
button = makeNavigationButton("Back24", PREVIOUS,
"Back to previous something-or-other", "Previous");
toolBar.add(button);
//second button
button = makeNavigationButton("Up24", UP,
"Up to something-or-other", "Up");
toolBar.add(button);
//third button
button = makeNavigationButton("Forward24", NEXT,
"Forward to something-or-other", "Next");
toolBar.add(button);
}
@NotNull
private JButton makeNavigationButton(final String imageName,
final String actionCommand,
final String toolTipText,
final String altText) {
//Look for the image.
String imgLocation = "images/" + imageName + ".gif";
URL imageURL = ToolBarDemo.class.getResource(imgLocation);
//Create and initialize the button.
JButton button = new JButton();
button.setActionCommand(actionCommand);
button.setToolTipText(toolTipText);
button.addActionListener(this);
if (imageURL != null) { //image found
button.setIcon(new ImageIcon(imageURL, altText));
} else { //no image found
button.setText(altText);
System.err.println("Resource not found: " + imgLocation);
}
return button;
}
public void actionPerformed(@NotNull final ActionEvent e) {
String cmd = e.getActionCommand();
String description = null;
// Handle each button.
if (PREVIOUS.equals(cmd)) { //first button clicked
description = "taken you to the previous <something>.";
} else if (UP.equals(cmd)) { // second button clicked
description = "taken you up one level to <something>.";
} else if (NEXT.equals(cmd)) { // third button clicked
description = "taken you to the next <something>.";
}
displayResult("If this were a real app, it would have "
+ description);
}
private void displayResult(final String actionDescription) {
String newline = "\n";
textArea.append(actionDescription + newline);
textArea.setCaretPosition(textArea.getDocument().getLength());
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event dispatch thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("ToolBarDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Add content to the window.
frame.add(new ToolBarDemo());
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(final String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(() -> {
LafManager.loadLaf(LafManager.Theme.Dark);
//Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
});
}
}

10
src/test/java/UIDemo.java

@ -1,7 +1,10 @@
import com.bulenkov.darcula.ui.DarculaToolBarUI;
import com.weis.darklaf.LafManager;
import com.weis.darklaf.components.TextFieldHistory;
import com.weis.darklaf.icons.IconLoader;
import org.jdesktop.swingx.JXStatusBar;
import org.jdesktop.swingx.JXTaskPane;
import org.jdesktop.swingx.JXTaskPaneContainer;
import javax.swing.*;
import java.awt.*;
@ -21,6 +24,11 @@ public final class UIDemo {
LafManager.loadLaf(LafManager.Theme.Dark);
JFrame.setDefaultLookAndFeelDecorated(true);
JXTaskPaneContainer taskpanecontainer = new JXTaskPaneContainer();
JXTaskPane taskpane = new JXTaskPane();
taskpane.setTitle("My Tasks");
taskpanecontainer.add(taskpane);
JFrame frame = new JFrame("UIDemo");
Icon folderIcon = IconLoader.get().getUIAwareIcon("files/folder.svg");
@ -134,7 +142,7 @@ public final class UIDemo {
putClientProperty("JButton.buttonType", "square");
}});
}});
panel.add(new JPanel());
panel.add(taskpanecontainer);
panel.add(new JPanel());
panel.add(new JPanel() {{
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

18
src/test/java/UIManagerDefaults.java

@ -45,7 +45,7 @@ public class UIManagerDefaults implements ItemListener {
/*
* Constructor
*/
public UIManagerDefaults() {
private UIManagerDefaults() {
items = new TreeMap<>();
models = new HashMap<>();
@ -83,7 +83,7 @@ public class UIManagerDefaults implements ItemListener {
* The content pane should be added to a high level container
*/
@NotNull
public JComponent getContentPane() {
private JComponent getContentPane() {
return contentPane;
}
@ -194,8 +194,7 @@ public class UIManagerDefaults implements ItemListener {
* The item map will contain items for each component or
* items for each attribute type.
*/
@NotNull
private TreeMap<String, TreeMap<String, Object>> buildItemsMap() {
private void buildItemsMap() {
final UIDefaults defaults = UIManager.getLookAndFeelDefaults();
// Build of Map of items and a Map of attributes for each item
for (final Object key : new HashSet<>(defaults.keySet())) {
@ -211,7 +210,6 @@ public class UIManagerDefaults implements ItemListener {
// Add the attribute to the map for this componenent
attributeMap.put(key.toString(), value);
}
return items;
}
/*
@ -462,7 +460,7 @@ public class UIManagerDefaults implements ItemListener {
try {
wrappee.paintIcon(c, g, x, y);
} catch (@NotNull final ClassCastException e) {
createStandIn(e, x, y);
createStandIn(e);
standIn.paintIcon(c, g, x, y);
}
}
@ -478,20 +476,20 @@ public class UIManagerDefaults implements ItemListener {
return wrappee.getIconHeight();
}
private void createStandIn(@NotNull final ClassCastException e, final int x, final int y) {
private void createStandIn(@NotNull final ClassCastException e) {
try {
final Class<?> clazz = getClass(e);
final JComponent standInComponent = getSubstitute(clazz);
standIn = createImageIcon(standInComponent, x, y);
standIn = createImageIcon(standInComponent);
} catch (@NotNull final Exception e1) {
// something went wrong - fallback to this painting
standIn = this;
}
}
@Contract("_, _, _ -> new")
@Contract("_ -> new")
@NotNull
private Icon createImageIcon(final JComponent standInComponent, final int x, final int y) {
private Icon createImageIcon(final JComponent standInComponent) {
final BufferedImage image =
new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB);
final Graphics g = image.createGraphics();

Loading…
Cancel
Save