Skip to content

Commit

Permalink
Update for Java8
Browse files Browse the repository at this point in the history
Signed-off-by: weisj <weisj@arcor.de>
  • Loading branch information
weisJ committed Jan 20, 2020
1 parent a1e4ccc commit 480e5f3
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
*/
public class DarkColorChooserPanel extends AbstractColorChooserPanel implements ColorListener {

public static final String TRANSPARENCY_ENABLED_PROPERTY
= "TransparencyEnabled";

private final ColorPipette pipette;
private final ColorWheelPanel colorWheelPanel;
private final JFormattedTextField textHex;
Expand Down Expand Up @@ -330,7 +333,6 @@ public Icon getSmallDisplayIcon() {
return null;
}

@Override
public boolean isColorTransparencySelectionEnabled() {
return colorWheelPanel.isColorTransparencySelectionEnabled();
}
Expand All @@ -356,7 +358,6 @@ private void updatePreviewFromTextFields() {
isChanging = false;
}

@Override
public void setColorTransparencySelectionEnabled(final boolean b) {
boolean oldValue = isColorTransparencySelectionEnabled();
if (b != oldValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,22 @@ protected void togglePopup() {
hide();
} else if (lastEvent == 0 || (System.currentTimeMillis() - lastEvent) > 250) {
visible = true;
System.out.println("here");
SwingUtilities.invokeLater(this::show);
}
}

@Override
public void show() {
super.show();
}


@Override
public void hide() {
super.hide();
}

protected void reset() {
lastEvent = 0;
if (visible) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.github.weisj.darklaf.ui.BasicTransferable;
import com.github.weisj.darklaf.ui.DragRecognitionSupport;
import com.github.weisj.darklaf.util.DarkSwingUtil;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.LazyActionMap;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -243,8 +244,8 @@ protected void paintCell(
final Graphics g,
final int row,
final Rectangle rowBounds,
final ListCellRenderer<Object> cellRenderer,
final ListModel<Object> dataModel,
final ListCellRenderer cellRenderer,
final ListModel dataModel,
final ListSelectionModel selModel,
final int leadIndex) {
Object value = dataModel.getElementAt(row);
Expand Down Expand Up @@ -769,15 +770,15 @@ public void uninstallUI(final JComponent c) {
*
* @throws NullPointerException {@inheritDoc}
*/
public int locationToIndex(final JList<?> list, final Point location) {
public int locationToIndex(final JList list, final Point location) {
maybeUpdateLayoutState();
return convertLocationToModel(location.x, location.y);
}

/**
* {@inheritDoc}
*/
public Point indexToLocation(final JList<?> list, final int index) {
public Point indexToLocation(final JList list, final int index) {
maybeUpdateLayoutState();
Rectangle rect = getCellBounds(list, index, index);

Expand All @@ -790,7 +791,7 @@ public Point indexToLocation(final JList<?> list, final int index) {
/**
* {@inheritDoc}
*/
public Rectangle getCellBounds(final JList<?> list, final int index1, final int index2) {
public Rectangle getCellBounds(final JList list, final int index1, final int index2) {
maybeUpdateLayoutState();

int minIndex = Math.min(index1, index2);
Expand Down Expand Up @@ -1962,7 +1963,7 @@ else if (Objects.equals(propertyName, "selectionModel")) {
updateLayoutStateNeeded |= cellRendererChanged;
redrawList();
} else if (Objects.equals(propertyName, "font")
|| SwingUtilities2.isScaleChanged(e)) {
|| DarkSwingUtil.isScaleChanged(e)) {
updateLayoutStateNeeded |= fontChanged;
redrawList();
} else if (Objects.equals(propertyName, "prototypeCellValue")) {
Expand Down Expand Up @@ -2843,7 +2844,6 @@ private void adjustScrollPositionIfNecessary(final JList<?> list, final int inde
}
}

@Override
public boolean accept(final Object c) {
Object name = getName();
if (name == SELECT_PREVIOUS_COLUMN_CHANGE_LEAD ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/
package com.github.weisj.darklaf.ui.tabbedpane;

import com.github.weisj.darklaf.util.DarkSwingUtil;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import sun.swing.SwingUtilities2;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
Expand Down Expand Up @@ -107,7 +107,7 @@ public void propertyChange(@NotNull final PropertyChangeEvent e) {
} else if (Objects.equals(name, "indexForNullComponent")) {
ui.isRunsDirty = true;
updateHtmlViews((Integer) e.getNewValue(), true);
} else if (Objects.equals(name, "font") || SwingUtilities2.isScaleChanged(e)) {
} else if (Objects.equals(name, "font") || DarkSwingUtil.isScaleChanged(e)) {
ui.calculatedBaseline = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ public Actions(final String name) {
super(name);
}

@Override
public boolean accept(final Object sender) {
if (sender instanceof JTableHeader) {
JTableHeader th = (JTableHeader) sender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,6 @@ protected void calcNextPos(final int dx, final int minX, final int maxX,
}
}

@Override
public boolean accept(final Object sender) {
String key = getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
*/
package com.github.weisj.darklaf.ui.text;

import com.github.weisj.darklaf.util.DarkSwingUtil;
import com.github.weisj.darklaf.util.GraphicsContext;
import com.github.weisj.darklaf.util.GraphicsUtil;
import sun.awt.SunToolkit;
import sun.swing.DefaultLookup;
import sun.swing.SwingUtilities2;

import javax.swing.*;
import javax.swing.plaf.ActionMapUIResource;
Expand Down Expand Up @@ -192,7 +192,7 @@ protected void updateFocusAcceleratorBinding(final boolean changed) {
if (accelerator != '\0') {
km.put(KeyStroke.getKeyStroke(accelerator, getFocusAcceleratorKeyMask()), "requestFocus");
km.put(KeyStroke.getKeyStroke(accelerator,
SwingUtilities2.setAltGraphMask(getFocusAcceleratorKeyMask())),
DarkSwingUtil.setAltGraphMask(getFocusAcceleratorKeyMask())),
"requestFocus");
}
}
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/com/github/weisj/darklaf/util/DarkSwingUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* MIT License
*
* Copyright (c) 2020 Jannis Weis
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.github.weisj.darklaf.util;

import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.geom.AffineTransform;
import java.beans.PropertyChangeEvent;
import java.util.Objects;

public class DarkSwingUtil {

public static int setAltGraphMask(final int modifier) {
return (modifier | InputEvent.ALT_GRAPH_DOWN_MASK);
}

public static boolean isScaleChanged(final PropertyChangeEvent ev) {
return isScaleChanged(ev.getPropertyName(), ev.getOldValue(), ev.getNewValue());
}

public static boolean isScaleChanged(final String name, final Object oldValue, final Object newValue) {
if (oldValue != newValue && "graphicsConfiguration".equals(name)) {
GraphicsConfiguration newGC = (GraphicsConfiguration) oldValue;
GraphicsConfiguration oldGC = (GraphicsConfiguration) newValue;
AffineTransform newTx = newGC != null ? newGC.getDefaultTransform() : null;
AffineTransform oldTx = oldGC != null ? oldGC.getDefaultTransform() : null;
return !Objects.equals(newTx, oldTx);
} else {
return false;
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion src/test/java/ColorChooserDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void main(final String[] args) {
SwingUtilities.invokeLater(() -> {
LafManager.install();
JColorChooser.showDialog(null, "Color Chooser with transparency",
Color.RED, true);
Color.RED);
});
}
}
2 changes: 1 addition & 1 deletion src/test/java/SVGTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void main(final String[] args) throws URISyntaxException, SVGEleme
JFrame frame = new JFrame();
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
var svgPanel = new SVGPanel() {
SVGPanel svgPanel = new SVGPanel() {
};
frame.setContentPane(svgPanel);
svgPanel.setAntiAlias(true);
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/ScrollPaneDemo.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.util.StringUtil;
import org.jdesktop.swingx.MultiSplitLayout;

import javax.swing.*;
Expand All @@ -15,8 +16,8 @@ public static void main(final String[] args) {
LafManager.install();
final JFrame frame = new JFrame();
frame.setSize(500, 500);
var overlayScroll = new JTextPane() {{
setText(TestResources.LOREM_IPSUM.repeat(10));
JTextPane overlayScroll = new JTextPane() {{
setText(StringUtil.repeat(TestResources.LOREM_IPSUM, 10));
setFont(Font.getFont(Font.MONOSPACED));
// setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
// SimpleAttributeSet attribs = new SimpleAttributeSet();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/SplitPaneDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void main(final String[] args) {
LafManager.install();
final JFrame frame = new JFrame();
frame.setSize(500, 500);
var splitPane = new JSplitPane() {
JSplitPane splitPane = new JSplitPane() {
};
splitPane.setLeftComponent(new JPanel() {{
setBackground(Color.RED);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/TabFrameDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.github.weisj.darklaf.components.text.NumberedTextComponent;
import com.github.weisj.darklaf.components.text.NumberingPane;
import com.github.weisj.darklaf.icons.IconLoader;
import com.github.weisj.darklaf.util.StringUtil;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
Expand Down Expand Up @@ -125,7 +126,7 @@ protected static JTree createTree() {
@NotNull
private static Component createTextArea() {
NumberedTextComponent numberPane = new NumberedTextComponent(new NonWrappingTextPane() {{
setText((TestResources.LOREM_IPSUM).repeat(10));
setText(StringUtil.repeat(TestResources.LOREM_IPSUM, 10));
setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
}});
NumberingPane numbering = numberPane.getNumberingPane();
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/TabbedPaneDemo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.github.weisj.darklaf.LafManager;
import com.github.weisj.darklaf.components.ClosableTabbedPane;
import com.github.weisj.darklaf.util.StringUtil;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
Expand All @@ -23,7 +24,7 @@ public static void main(final String[] args) {

for (int i = 0; i < 4; i++) {
JTextPane editor = new JTextPane();
editor.setText("TabPaneDemo TabPane-" + j + "\n".repeat(i + 1));
editor.setText(StringUtil.repeat("TabPaneDemo TabPane-" + j + "\n", i + 1));
tabbedPane.addTab("Tab (" + i + "," + j + ")", editor);
}
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/UIDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void actionPerformed(final ActionEvent e) {
statusBar.add(new JLabel("test3"));
content.add(statusBar, BorderLayout.SOUTH);

var defaultButton = new JButton("default") {{
JButton defaultButton = new JButton("default") {{
setDefaultCapable(true);
}};

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/UIManagerDefaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private JMenu createLAFMenu() {
*/
@NotNull
private JComponent buildNorthComponent() {
comboBox = new JComboBox<>() {
comboBox = new JComboBox<String>() {
@Override
public Dimension getPreferredSize() {
return new Dimension(200, getUI().getPreferredSize(this).height);
Expand Down

0 comments on commit 480e5f3

Please sign in to comment.