mirror of https://github.com/weisJ/darklaf.git
weisj
5 years ago
15 changed files with 1940 additions and 22 deletions
@ -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); |
||||
} |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -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(); |
||||
} |
||||
} |
After Width: | Height: | Size: 515 B |
After Width: | Height: | Size: 515 B |
After Width: | Height: | Size: 515 B |
After Width: | Height: | Size: 515 B |
@ -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(); |
||||
}); |
||||
} |
||||
} |
Loading…
Reference in new issue