Skip to content

Commit

Permalink
Everywhere: Remove usage of internal API DefaultLookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
weisJ committed May 18, 2021
1 parent 9ee79f4 commit db7d560
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
24 changes: 23 additions & 1 deletion core/src/main/java/com/github/weisj/darklaf/ui/UIAction.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2021 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.ui;

import javax.swing.Action;
import java.beans.PropertyChangeListener;

import javax.swing.Action;

public abstract class UIAction implements Action {
private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@
import javax.swing.plaf.basic.BasicListUI;
import javax.swing.text.Position;

import sun.swing.DefaultLookup;
import com.github.weisj.darklaf.ui.UIAction;

import com.github.weisj.darklaf.ui.BasicTransferable;
import com.github.weisj.darklaf.ui.DragRecognitionSupport;
import com.github.weisj.darklaf.ui.UIAction;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.LazyActionMap;
import com.github.weisj.darklaf.util.PropertyKey;
Expand Down Expand Up @@ -615,11 +613,11 @@ protected Handler getHandler() {
*/
InputMap getInputMap(final int condition) {
if (condition == JComponent.WHEN_FOCUSED) {
InputMap keyMap = (InputMap) DefaultLookup.get(list, this, "List.focusInputMap");
InputMap keyMap = (InputMap) UIManager.get("List.focusInputMap", list.getLocale());
InputMap rtlKeyMap;

if (isLeftToRight || ((rtlKeyMap =
(InputMap) DefaultLookup.get(list, this, "List.focusInputMap.RightToLeft")) == null)) {
(InputMap) UIManager.get("List.focusInputMap.RightToLeft", list.getLocale())) == null)) {
return keyMap;
} else {
rtlKeyMap.setParent(keyMap);
Expand Down Expand Up @@ -1248,7 +1246,7 @@ protected void paintDropLine(final Graphics g) {
return;
}

Color c = DefaultLookup.getColor(list, this, "List.dropLineColor", null);
Color c = UIManager.getColor("List.dropLineColor");
if (c != null) {
g.setColor(c);
Rectangle rect = getDropLineRect(loc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import javax.swing.plaf.basic.BasicMenuItemUI;

import sun.swing.MenuItemLayoutHelper;
import com.github.weisj.darklaf.ui.UIAction;

import com.github.weisj.darklaf.ui.UIAction;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.LazyActionMap;
import com.github.weisj.darklaf.util.StringUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicOptionPaneUI;

import sun.swing.DefaultLookup;

public class DarkOptionPaneUI extends BasicOptionPaneUI {

Expand All @@ -39,16 +38,16 @@ public static ComponentUI createUI(final JComponent x) {
@Override
protected Container createButtonArea() {
JPanel bottom = new JPanel();
Border border = (Border) DefaultLookup.get(optionPane, this, "OptionPane.buttonAreaBorder");
Border border = (Border) UIManager.get("OptionPane.buttonAreaBorder");
bottom.setName("OptionPane.buttonArea");
if (border != null) {
bottom.setBorder(border);
}
bottom.setLayout(new DarkButtonAreaLayout(
DefaultLookup.getBoolean(optionPane, this, "OptionPane.sameSizeButtons", false),
DefaultLookup.getInt(optionPane, this, "OptionPane.buttonPadding", 6),
DefaultLookup.getInt(optionPane, this, "OptionPane.buttonOrientation", SwingConstants.CENTER),
DefaultLookup.getBoolean(optionPane, this, "OptionPane.isYesLast", false)));
UIManager.getBoolean("OptionPane.sameSizeButtons"),
UIManager.getInt("OptionPane.buttonPadding"),
UIManager.getInt("OptionPane.buttonOrientation"),
UIManager.getBoolean("OptionPane.isYesLast")));
addButtonComponents(bottom, getButtons(), getInitialValueIndex());
return bottom;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,7 @@ protected void layoutTabComponents() {
// center component
int x = outerX + (outerWidth - width) / 2;
int y = outerY + (outerHeight - height) / 2;

int tabPlacement = tabPane.getTabPlacement();
boolean isSeleceted = i == tabPane.getSelectedIndex();

c.setBounds(x + getTabLabelShiftX(tabPlacement, i, isSeleceted),
y + getTabLabelShiftY(tabPlacement, i, isSeleceted), width, height);
c.setBounds(x, y, width, height);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;

import sun.swing.DefaultLookup;
import com.github.weisj.darklaf.ui.UIAction;

import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.LazyActionMap;
import com.github.weisj.darklaf.util.PropertyKey;
Expand Down Expand Up @@ -659,7 +657,7 @@ protected View getTextViewForTab(final int tabIndex) {
protected int getTabLabelShiftX(final int tabPlacement, final int tabIndex, final boolean isSelected) {
Rectangle tabRect = rects[tabIndex];
String propKey = (isSelected ? "selectedLabelShift" : "labelShift");
int nudge = DefaultLookup.getInt(tabPane, this, "TabbedPane." + propKey, 1);
int nudge = UIManager.getInt("TabbedPane." + propKey);

switch (tabPlacement) {
case LEFT:
Expand All @@ -683,8 +681,8 @@ protected int getTabLabelShiftX(final int tabPlacement, final int tabIndex, fina
*/
protected int getTabLabelShiftY(final int tabPlacement, final int tabIndex, final boolean isSelected) {
Rectangle tabRect = rects[tabIndex];
int nudge = (isSelected ? DefaultLookup.getInt(tabPane, this, "TabbedPane.selectedLabelShift", -1)
: DefaultLookup.getInt(tabPane, this, "TabbedPane.labelShift", 1));
int nudge = (isSelected ? UIManager.getInt("TabbedPane.selectedLabelShift")
: UIManager.getInt("TabbedPane.labelShift"));

switch (tabPlacement) {
case BOTTOM:
Expand Down Expand Up @@ -857,9 +855,9 @@ protected MouseListener createMouseListener() {
*/
InputMap getInputMap(final int condition) {
if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
return (InputMap) DefaultLookup.get(tabPane, this, "TabbedPane.ancestorInputMap");
return (InputMap) UIManager.get("TabbedPane.ancestorInputMap", tabPane.getLocale());
} else if (condition == JComponent.WHEN_FOCUSED) {
return (InputMap) DefaultLookup.get(tabPane, this, "TabbedPane.focusInputMap");
return (InputMap) UIManager.get("TabbedPane.focusInputMap", tabPane.getLocale());
}
return null;
}
Expand Down Expand Up @@ -1509,7 +1507,7 @@ protected Insets getContentBorderInsets(final int tabPlacement) {
*/
protected void navigateSelectedTab(final int direction) {
int tabPlacement = tabPane.getTabPlacement();
int current = DefaultLookup.getBoolean(tabPane, this, "TabbedPane.selectionFollowsFocus", true)
int current = !Boolean.FALSE.equals(UIManager.get("TabbedPane.selectionFollowsFocus"))
? tabPane.getSelectedIndex()
: getFocusIndex();
int tabCount = tabPane.getTabCount();
Expand Down Expand Up @@ -1682,7 +1680,7 @@ protected void selectAdjacentRunTab(final int tabPlacement, final int tabIndex,
* @param index the index
*/
protected void navigateTo(final int index) {
if (DefaultLookup.getBoolean(tabPane, this, "TabbedPane.selectionFollowsFocus", true)) {
if (!Boolean.FALSE.equals(UIManager.get("TabbedPane.selectionFollowsFocus"))) {
tabPane.setSelectedIndex(index);
} else {
// Just move focus (not selection)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;

import sun.swing.DefaultLookup;

import com.github.weisj.darklaf.ui.DragRecognitionSupport;
import com.github.weisj.darklaf.util.DarkUIUtil;
import com.github.weisj.darklaf.util.PropertyUtil;
Expand Down Expand Up @@ -179,11 +177,11 @@ protected MouseInputListener createMouseInputListener() {
*/
InputMap getInputMap(final int condition) {
if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
InputMap keyMap = (InputMap) DefaultLookup.get(table, this, "Table.ancestorInputMap");
InputMap keyMap = (InputMap) UIManager.get("Table.ancestorInputMap", table.getLocale());
InputMap rtlKeyMap;

if (table.getComponentOrientation().isLeftToRight() || ((rtlKeyMap =
(InputMap) DefaultLookup.get(table, this, "Table.ancestorInputMap.RightToLeft")) == null)) {
(InputMap) UIManager.get("Table.ancestorInputMap.RightToLeft", table.getLocale())) == null)) {
return keyMap;
} else {
rtlKeyMap.setParent(keyMap);
Expand Down

0 comments on commit db7d560

Please sign in to comment.