Skip to content

Commit

Permalink
DarkLAF, further steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Wisser committed Jun 23, 2024
1 parent ecbe9e4 commit 2f42e62
Show file tree
Hide file tree
Showing 14 changed files with 2,526 additions and 2,382 deletions.
4 changes: 0 additions & 4 deletions src/main/engine/net/sf/jailer/JailerVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ public static void main(String[] args) {

}


// TODO
// TODO click on "Database"-Metadata table list with opened "Desktop" should open BrCoPa in Desktop

//TODO
//TODO icons: black"-"plus" and "filter"-icon (GraphView) are too bright

16 changes: 12 additions & 4 deletions src/main/gui/net/sf/jailer/ui/Colors.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.awt.RenderingHints;
import java.awt.Window;
import java.awt.color.ColorSpace;
import java.awt.event.ActionListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;
import java.awt.image.ColorModel;
Expand All @@ -30,9 +31,11 @@
import java.util.ArrayList;
import java.util.List;

import javax.swing.JMenuItem;
import javax.swing.Timer;

import net.sf.jailer.ui.UIUtil.PLAF;
import net.sf.jailer.ui.syntaxtextarea.RSyntaxTextAreaWithTheme;
import net.sf.jailer.ui.util.HSLColor;

/**
Expand Down Expand Up @@ -65,9 +68,6 @@ private static void initColors() {
Color_0_0_220.init(new Color(0, 0, 220), Color_0_100_255.dark);
Color_255_255_230.init(new Color(255, 255, 200), new Color(11, 44, 44));

// TODO
// TODO count darkLaf-processes (s11 or: "(b|B|s|s)d?")

// TODO
// TODO ext. copy: "maximize"-button icon recoloring

Expand Down Expand Up @@ -133,6 +133,8 @@ private static void initColors() {
Color_255_255_238.init(new Color(255, 255, 238), new Color(10, 40, 10));
Color_248_252_255.init(new Color(248, 252, 255), new Color(25, 38, 71));

Color_NeigbBG.init(new Color(255, 255, 255, 200), new Color(31, 39, 42));

// TODO
// TODO check "tranparent" todos

Expand Down Expand Up @@ -438,6 +440,7 @@ private static void initColors() {
public static LAFAwareColor Color_170_50_50 = new LAFAwareColor();
public static LAFAwareColor Color_255_235_20_75 = new LAFAwareColor();
public static LAFAwareColor Color_FlatTreeViewBG = new LAFAwareColor();
public static LAFAwareColor Color_NeigbBG = new LAFAwareColor();

public static String HTMLColor_000000;
public static String HTMLColor_0000B0;
Expand Down Expand Up @@ -469,7 +472,7 @@ private static void initColors() {

public static void init() {
if (!timerIsInitialized) {
inDarkLAFMode = "true".equals(System.getProperty("darkLAF"));
inDarkLAFMode = "true".equals(System.getProperty("darkLAF")); // TODO
if (inDarkLAFMode) {
Timer timer = new Timer(1000, e -> init());
timer.setInitialDelay(1000);
Expand Down Expand Up @@ -511,6 +514,11 @@ public static void init() {
initColors();
for (Window w : Window.getWindows()) {
w.repaint();
UIUtil.traverse(w, null, c-> null, (c, o) -> null, (t, c) -> {
if (c instanceof RSyntaxTextAreaWithTheme) {
((RSyntaxTextAreaWithTheme) c).initTheme();
}
});
}

if (inDarkLAFMode) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/gui/net/sf/jailer/ui/DataModelManagerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -3127,7 +3127,7 @@ public ToolSelectionBorder(int top, int left, int bottom, int right, Color color

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D g2d = (Graphics2D) g;
g2d.setPaint(new GradientPaint(x, y, color != null? color : Colors.Color_0_0_255, x + width, y, color != null? color : UIUtil.plaf == PLAF.FLATDARK? Colors.Color_0_255_0.brighter() : Colors.Color_0_255_0.darker())); // TODO
g2d.setPaint(new GradientPaint(x, y, color != null? color : Colors.Color_0_0_255, x + width, y, color != null? color : UIUtil.plaf == PLAF.FLATDARK? Colors.Color_0_255_0.brighter() : Colors.Color_0_255_0.darker()));

Area border = new Area(new Rectangle(x, y, width, height));
border.subtract(new Area(new Rectangle(x + margin.left, y + margin.top, width - margin.left - margin.right,
Expand Down
2 changes: 1 addition & 1 deletion src/main/gui/net/sf/jailer/ui/ExtractionModelFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,7 @@ private static void start(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
UIUtil.initPLAF();
UIUtil.readAndInitPLAF();

String file = null;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/main/gui/net/sf/jailer/ui/NeighborhoodPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
*/
public class NeighborhoodPanel extends javax.swing.JPanel {

private static final Color WHITE = Colors.Color_255_255_255_200;
private static final Color WHITE = Colors.Color_NeigbBG;
private static final Color SELECTED_COLOR = Colors.Color_0_255_255_150;

private int length = 2;
Expand Down
3 changes: 3 additions & 0 deletions src/main/gui/net/sf/jailer/ui/RestrictionEditor.form
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@
<SubComponents>
<Component class="javax.swing.JTextField" name="restriction">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="Colors.Color_255_255_255" type="code"/>
</Property>
<Property name="columns" type="int" value="32"/>
<Property name="toolTipText" type="java.lang.String" value="&lt;html&gt;&#xa;SQL expression to restrict the join condition. &lt;br&gt;&#xa;Keep empty to reach all associated rows.&#xa;&lt;/html&gt;"/>
</Properties>
Expand Down
1 change: 1 addition & 0 deletions src/main/gui/net/sf/jailer/ui/RestrictionEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private void initComponents() {
jPanel9.setOpaque(false);
jPanel9.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 0, 0));

restriction.setBackground(Colors.Color_255_255_255);
restriction.setColumns(32);
restriction.setToolTipText("<html>\nSQL expression to restrict the join condition. <br>\nKeep empty to reach all associated rows.\n</html>");
jPanel9.add(restriction);
Expand Down
17 changes: 13 additions & 4 deletions src/main/gui/net/sf/jailer/ui/SessionForUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@ public static SessionForUI createSession(DataSource dataSource, DBMS dbms, Integ
final SessionForUI session = new SessionForUI(dataSource, dbms, isolationLevel, shutDownImmediatelly, testOnly);
final AtomicReference<Connection> con = new AtomicReference<Connection>();
final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
session.connectionDialog = new JDialog(w, "Connecting");
Window owner = w;
if (!w.isShowing()) {
for (Window vw: Window.getWindows()) {
if (vw.isShowing() && vw.isFocused()) {
owner = vw;
break;
}
}
}
session.connectionDialog = new JDialog(owner, "Connecting");
session.connectionDialog.setUndecorated(true);
session.connectionDialog.setModal(true);
Thread thread = new Thread(new Runnable() {
Expand Down Expand Up @@ -120,8 +129,8 @@ public void run() {
thread.setDaemon(true);
thread.start();
Point p;
if (w.isShowing()) {
p = w.getLocationOnScreen();
if (owner.isShowing()) {
p = owner.getLocationOnScreen();
} else {
p = new Point(0, 0);
}
Expand Down Expand Up @@ -155,7 +164,7 @@ public void run() {

session.connectionDialog.getContentPane().add(session.connectingPanel);
session.connectionDialog.pack();
session.connectionDialog.setLocation(los.x + w.getWidth() / 2 - session.connectionDialog.getWidth() / 2, los.y + w.getHeight() / 2 - session.connectionDialog.getHeight() / 2);
session.connectionDialog.setLocation(los.x + owner.getWidth() / 2 - session.connectionDialog.getWidth() / 2, los.y + owner.getHeight() / 2 - session.connectionDialog.getHeight() / 2);

Timer timer = new Timer(500, e -> {
session.connectingPanel.setBackground(Colors.Color_255_255_255.equals(session.connectingPanel.getBackground())? Colors.Color_255_230_230 : Colors.Color_255_255_255);
Expand Down
62 changes: 48 additions & 14 deletions src/main/gui/net/sf/jailer/ui/UIUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
import javax.swing.ToolTipManager;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
Expand Down Expand Up @@ -1668,10 +1669,7 @@ public void run() {
*/
public static void initPLAFMenuItem(final JMenu plafMenu, final Component parentComponent) {
ButtonGroup buttonGroup = new ButtonGroup();
for (PLAF p: PLAF.values()) {
if (p == PLAF.NIMBUS) {
continue;
}
for (PLAF p: UIUtil.availablePlafs) {
JRadioButtonMenuItem item = new JRadioButtonMenuItem();
buttonGroup.add(item);
if (p == plaf) {
Expand All @@ -1682,7 +1680,10 @@ public static void initPLAFMenuItem(final JMenu plafMenu, final Component parent
@Override
public void actionPerformed(ActionEvent e) {
UISettings.store(UISettings.USE_NATIVE_PLAF, p.name());
JOptionPane.showMessageDialog(parentComponent, "The \"look and feel\" has been changed.\n(Will be effective after restart)", "Look&Feel", JOptionPane.INFORMATION_MESSAGE);
plaf = p;
p.install();
initPLAF();
// JOptionPane.showMessageDialog(parentComponent, "The \"look and feel\" has been changed.\n(Will be effective after restart)", "Look&Feel", JOptionPane.INFORMATION_MESSAGE);
}
});
plafMenu.add(item);
Expand Down Expand Up @@ -2129,18 +2130,45 @@ public static void stopDW() {
hiddenWindows.clear();
}

// TODO
// TODO offer only flat lafs (light, dark). Don't offer Nimbus and Native
public static enum PLAF {
FLAT("Flat", true), NIMBUS("Nimbus", false), NATIVE("Native", false), FLATDARK("FlatDark", true);
FLAT("Light Theme", true) {
public void install() {
FlatLightLaf.setup();
try {
javax.swing.UIManager.setLookAndFeel(new com.formdev.flatlaf.FlatLightLaf());
} catch (UnsupportedLookAndFeelException e) {
throw new RuntimeException(e);
}
com.formdev.flatlaf.FlatLaf.updateUI();
}
},
NIMBUS("Nimbus", false) {
public void install() {
}
}, NATIVE("Native", false) {
public void install() {
}
}, FLATDARK("Dark Theme", true) {
public void install() {
FlatDarkLaf.setup();
try {
javax.swing.UIManager.setLookAndFeel(new com.formdev.flatlaf.FlatDarkLaf());
} catch (UnsupportedLookAndFeelException e) {
throw new RuntimeException(e);
}
com.formdev.flatlaf.FlatLaf.updateUI();
}
};

PLAF(String description, boolean isFlat) {
this.description = description;
this.isFlat = isFlat;
}
public final String description;
public final boolean isFlat;
abstract public void install();
};
public static PLAF[] availablePlafs = new PLAF[] { PLAF.FLAT, PLAF.FLATDARK };

public static PLAF plaf = PLAF.NATIVE;

Expand All @@ -2158,23 +2186,26 @@ public static void checkPLAF(Component parentComponent) {
UISettings.store("OLD_PLAF", plaf.name());
}

public static void initPLAF() {
public static void readAndInitPLAF() {
FlatLaf.registerCustomDefaultsSource("net.sf.jailer.ui.resource");

Object plafSetting = UISettings.restore(UISettings.USE_NATIVE_PLAF);
plaf = PLAF.FLAT;
if (Boolean.FALSE.equals(plafSetting)) {
plaf = PLAF.FLAT;
UISettings.store(UISettings.USE_NATIVE_PLAF, plaf.name());
} else if (Boolean.TRUE.equals(plafSetting)) {
plaf = PLAF.NATIVE;
UISettings.store(UISettings.USE_NATIVE_PLAF, plaf.name());
// } else if (Boolean.TRUE.equals(plafSetting)) {
// plaf = PLAF.NATIVE;
// UISettings.store(UISettings.USE_NATIVE_PLAF, plaf.name());
} else if (plafSetting instanceof PLAF) {
plaf = (PLAF) plafSetting;
UISettings.store(UISettings.USE_NATIVE_PLAF, plaf.name());
} else if (plafSetting instanceof String) {
try {
plaf = PLAF.valueOf((String) plafSetting);
if (!plaf.isFlat) {
plaf = PLAF.FLAT;
}
} catch (Exception e) {
// ignore
}
Expand All @@ -2184,7 +2215,7 @@ public static void initPLAF() {
// TODO
// TODO remove
if (System.getProperty("darkLAF").equalsIgnoreCase("true")) {
plaf = PLAF.FLATDARK;
// plaf = PLAF.FLATDARK;
}
} catch (Exception e) {
// ignore
Expand All @@ -2193,7 +2224,10 @@ public static void initPLAF() {
if (plaf == PLAF.NIMBUS) {
plaf = PLAF.FLAT;
}

initPLAF();
}

public static void initPLAF() {
switch (plaf) {
case NATIVE:
// nothing to do
Expand Down
Loading

0 comments on commit 2f42e62

Please sign in to comment.