From e63d2f7abb47f2b4f4c25fd22ddef1adf1cf8ef8 Mon Sep 17 00:00:00 2001 From: weisj Date: Sun, 15 Sep 2019 02:12:14 +0200 Subject: [PATCH] Ported html styling. --- src/main/java/com/weis/darklaf/DarkLaf.java | 22 +- .../resources/com/weis/darklaf/darcula.css | 337 ++++++++++++++++++ .../com/weis/darklaf/darcula.properties | 56 +-- src/test/java/ScrollPaneDemo.java | 5 +- 4 files changed, 363 insertions(+), 57 deletions(-) create mode 100644 src/main/resources/com/weis/darklaf/darcula.css diff --git a/src/main/java/com/weis/darklaf/DarkLaf.java b/src/main/java/com/weis/darklaf/DarkLaf.java index 5ee65569..aaa72e52 100644 --- a/src/main/java/com/weis/darklaf/DarkLaf.java +++ b/src/main/java/com/weis/darklaf/DarkLaf.java @@ -11,9 +11,15 @@ import javax.swing.*; import javax.swing.plaf.basic.BasicLookAndFeel; import javax.swing.plaf.metal.MetalLookAndFeel; import javax.swing.text.DefaultEditorKit; +import javax.swing.text.html.HTMLEditorKit; +import javax.swing.text.html.StyleSheet; import java.awt.event.InputEvent; import java.awt.event.KeyEvent; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.Reader; import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Properties; import java.util.logging.ConsoleHandler; @@ -25,12 +31,14 @@ import java.util.logging.Logger; */ public class DarkLaf extends BasicLookAndFeel { private static final Logger LOGGER = Logger.getLogger(DarkLaf.class.getName()); + static { LOGGER.setUseParentHandlers(false); ConsoleHandler handler = new ConsoleHandler(); handler.setFormatter(new LogFormatter()); LOGGER.addHandler(handler); } + private static final String NAME = "Darklaf"; private BasicLookAndFeel base; @@ -65,6 +73,18 @@ public class DarkLaf extends BasicLookAndFeel { defaults.put("ComboBox.actionMap", metalDefaults.get("ComboBox.actionMap")); } + private static void patchStyledEditorKit() { + StyleSheet defaultStyles = new StyleSheet(); + try (Reader r = new BufferedReader( + new InputStreamReader(DarkLaf.class.getResourceAsStream("darcula.css"), + StandardCharsets.UTF_8))) { + defaultStyles.loadRules(r, null); + new HTMLEditorKit().setStyleSheet(defaultStyles); + } catch (Throwable e) { + LOGGER.severe(e.getMessage()); + } + } + @SuppressWarnings({"HardCodedStringLiteral"}) private static void initInputMapDefaults(@NotNull final UIDefaults defaults) { // Make ENTER work in JTrees @@ -143,7 +163,7 @@ public class DarkLaf extends BasicLookAndFeel { initInputMapDefaults(defaults); initIdeaDefaults(defaults); patchComboBox(metalDefaults, defaults); - defaults.remove("Spinner.arrowButtonBorder"); + patchStyledEditorKit(); if (SystemInfo.isMac && !"true".equalsIgnoreCase(System.getProperty("apple.laf.useScreenMenuBar", "false"))) { diff --git a/src/main/resources/com/weis/darklaf/darcula.css b/src/main/resources/com/weis/darklaf/darcula.css new file mode 100644 index 00000000..772fbaa0 --- /dev/null +++ b/src/main/resources/com/weis/darklaf/darcula.css @@ -0,0 +1,337 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +body { + font-size: 14pt; + font-family: Serif, serif; + font-weight: normal; + margin-left: 0; + margin-right: 0; + color: #bbbbbb; +} + +p { + margin-top: 15px; +} + +h1 { + font-size: x-large; + font-weight: bold; + margin-top: 10px; + margin-bottom: 10px; +} + +h2 { + font-size: large; + font-weight: bold; + margin-top: 10px; + margin-bottom: 10px; +} + +h3 { + font-size: medium; + font-weight: bold; + margin-top: 10px; + margin-bottom: 10px; +} + +h4 { + font-size: small; + font-weight: bold; + margin-top: 10px; + margin-bottom: 10px; +} + +h5 { + font-size: x-small; + font-weight: bold; + margin-top: 10px; + margin-bottom: 10px; +} + +h6 { + font-size: xx-small; + font-weight: bold; + margin-top: 10px; + margin-bottom: 10px; +} + +li p { + margin-top: 0; + margin-bottom: 0; +} + +td p { + margin-top: 0; +} + +menu li p { + margin-top: 0; + margin-bottom: 0; +} + +menu li { + margin: 0; +} + +menu { + margin-left-ltr: 40px; + margin-right-rtl: 40px; + margin-top: 10px; + margin-bottom: 10px; +} + +dir li p { + margin-top: 0; + margin-bottom: 0; +} + +dir li { + margin: 0; +} + +dir { + margin-left-ltr: 40px; + margin-right-rtl: 40px; + margin-top: 10px; + margin-bottom: 10px; +} + +dd { + margin-left-ltr: 40px; + margin-right-rtl: 40px; + margin-top: 0; + margin-bottom: 0; +} + +dd p { + margin: 0; +} + +dt { + margin-top: 0; + margin-bottom: 0; +} + +dl { + margin-left: 0; + margin-top: 10px; + margin-bottom: 10px; +} + +ol li { + margin: 0; +} + +ol { + margin-top: 10px; + margin-bottom: 10px; + margin-left-ltr: 50px; + margin-right-rtl: 50px; + list-style-type: decimal; +} + +ol li p { + margin-top: 0; + margin-bottom: 0; +} + +ul li { + margin: 0; +} + +ul { + margin-top: 10px; + margin-bottom: 10px; + margin-left-ltr: 50px; + margin-right-rtl: 50px; + list-style-type: disc; + -bullet-gap: 10px; +} + +ul li ul li { + margin: 0; +} + +ul li ul { + list-style-type: circle; + margin-left-ltr: 25px; + margin-right-rtl: 25px; +} + +ul li ul li ul li { + margin: 0; +} + +ul li ul li ul { + list-style-type: square; + margin-left-ltr: 25px; + margin-right-rtl: 25px; +} + +ul li menu { + list-style-type: circle; + margin-left-ltr: 25px; + margin-right-rtl: 25px; +} + +ul li p { + margin-top: 0; + margin-bottom: 0; +} + +a { + color: #589df6; + text-decoration: underline; +} + +address { + color: #589df6; + font-style: italic; +} + +big { + font-size: x-large; +} + +small { + font-size: x-small; +} + +samp { + font-size: small; + font-family: Monospaced, monospace; +} + +cite { + font-style: italic; +} + +code { + font-size: small; + font-family: Monospaced, monospace; +} + +dfn { + font-style: italic; +} + +em { + font-style: italic; +} + +i { + font-style: italic; +} + +b { + font-weight: bold; +} + +kbd { + font-size: small; + font-family: Monospaced, monospace; +} + +s { + text-decoration: line-through; +} + +strike { + text-decoration: line-through; +} + +strong { + font-weight: bold; +} + +sub { + vertical-align: sub; +} + +sup { + vertical-align: sub; +} + +tt { + font-family: Monospaced, monospace; +} + +u { + text-decoration: underline; +} + +var { + font-weight: bold; + font-style: italic; +} + +table { + border-color: Gray; + border-style: outset; +} + +tr { + text-align: left; +} + +td { + border-color: Gray; + border-style: inset; + padding: 3px; +} + +th { + text-align: center; + font-weight: bold; + border-color: Gray; + border-style: inset; + padding: 3px; +} + +blockquote { + margin: 5px 35px; +} + +center { + text-align: center; +} + +pre { + margin-top: 5px; + margin-bottom: 5px; + font-family: Monospaced, monospace; +} + +pre p { + margin-top: 0; +} + +caption { + caption-side: top; + text-align: center; +} + +table { + border: none; +} + +td { + border: none; +} + +nobr { + white-space: nowrap; +} \ No newline at end of file diff --git a/src/main/resources/com/weis/darklaf/darcula.properties b/src/main/resources/com/weis/darklaf/darcula.properties index 2b6b7606..47189015 100644 --- a/src/main/resources/com/weis/darklaf/darcula.properties +++ b/src/main/resources/com/weis/darklaf/darcula.properties @@ -239,6 +239,7 @@ Spinner.activeBackground = 45494A Spinner.arrowButtonInsets = 2,2,2,2 Spinner.editorBorderPainted = false Spinner.arrowButtonSize = 16,5 +Spinner.arrowButtonBorder = null #Menu (done) Menu.maxGutterIconWidth = 18 @@ -347,57 +348,4 @@ InternalFrameTitlePane.darcula.selected.borderColorBottom = 313C4C InternalFrameTitlePane.darcula.backgroundColor = 3A3D3F InternalFrameTitlePane.darcula.selected.backgroundColor = 424D5F InternalFrameTitlePane.darcula.buttonColor = 8B8B8B -InternalFrameTitlePane.darcula.hovered.buttonColor = A8A8A8 - - - - -###Custom### - -#Misc -Button.separator = 5F5F5F -Focus.color = ff0000 - -#TabbedPane -DnDTabbedPaneUI = edu.kit.mima.gui.laf.DarkDnDTabbedPaneUI -EditorTabbedPaneUI = edu.kit.mima.gui.laf.DarkEditorTabbedPaneUI -DnDTabbedPane.selectionAccent = 40B6E0 -DnDTabbedPane.selectedTab = 515658 -DnDTabbedPane.dropColor = 4B4B4B -DnDTabbedPane.selectedTab2 = 343638 -DnDTabbedPane.selectionAccentUnfocused = 787878 - -#Numbering -Numbering.foreground = 606366 -Numbering.background = 313335 -Numbering.selectedForeground = a3a3a3 -Numbering.selectedBackground = 323232 -Numbering.font = Monospaced-0-12 - -#Editor -Editor.selectedBackground = 323232 -Editor.selection = 2852a0 -Editor.breakpoint = 3a2323 -Editor.mark = 2D71D2 -Editor.vertLine = 515151 - -#TabFrame -TabFramePopup.background = 3c3f41 -TabFramePopup.focus = 3B4754 -TabFramePopup.borderColor = 323232 -TabFrameTab.selected = 2D2F30 -TabFrameTab.hover = 353739 -TabFrameTab.selectedFontColor = ffffff -TabFrameTab.defaultForeground = bbbbbb -TabFrame.line = 515151 - -#Tooltip -Tooltip.background = 4B4D4D -Tooltip.borderColor = 5B5D5F - -#Terminal -Terminal.background = 2b2b2b - -#FileDialog -FileDialog.errorBorder = 73454B -FileDialog.error = 593D41 +InternalFrameTitlePane.darcula.hovered.buttonColor = A8A8A8 \ No newline at end of file diff --git a/src/test/java/ScrollPaneDemo.java b/src/test/java/ScrollPaneDemo.java index 5fcb3136..f7f26f17 100644 --- a/src/test/java/ScrollPaneDemo.java +++ b/src/test/java/ScrollPaneDemo.java @@ -15,8 +15,8 @@ public final class ScrollPaneDemo extends MultiSplitLayout { LafManager.loadLaf(LafManager.Theme.Dark); final var frame = new JFrame(); frame.setSize(500, 500); - var overlayScroll = new JScrollPane(new JTextPane() {{ - setText("orem ipsum dolor sit amet, consectetur adipiscing elit. In tempor quis nibh a semper. Nullam" + var overlayScroll = new JScrollPane(new JEditorPane() {{ + setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit. In tempor quis nibh a semper. Nullam" + " auctor, erat non viverra commodo, libero orci aliquam quam, ac interdum nunc est sed " + "ligula. Aliquam vel velit non dolor accumsan blandit id eu metus. Aenean iaculis urna in " + "placerat aliquam. Aliquam dui quam, bibendum sed magna in, cursus ornare est. Quisque " @@ -44,6 +44,7 @@ public final class ScrollPaneDemo extends MultiSplitLayout { + "sapien."); // setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); setFont(Font.getFont(Font.MONOSPACED)); + }}); frame.setContentPane(new JPanel(new BorderLayout()) {{ add(overlayScroll, BorderLayout.CENTER);