languageBox = new JComboBox(new DefaultComboBoxModel(langsToChoose.toArray()));
- languageBox.setSelectedIndex(langsToChoose.indexOf(Locale.getDefault().toString().toLowerCase()));
- languageBox.addActionListener(e -> {
- Locale.setDefault(Locale.forLanguageTag(languageBox.getSelectedItem().toString())); // Change lang on update
- });
- // Set where it goes
- languageBox.setBounds(rootPosOnLeft ? x : x - langBoxWidth, themeOnBottom ? y : y + langBoxHeight, langBoxWidth, langBoxHeight);
- // And finally add it
- add(languageBox);
-
-
- // ========== THEMING ========== //
- /**
- // TODO: Change the theme to a toggle switch rather than having 2 buttons
- int themeButtonSize = 25;
- JButton lightMode = null;
- JButton darkMode = null;
- // Try to set the icons for them
- try
- {
- lightMode = new JButton(new ImageIcon(
- new FlatSVGIcon(JarUtils.accessFile("assets/distanthorizons/textures/jar/themeLight.svg")).getImage() // Get the image
- .getScaledInstance(themeButtonSize, themeButtonSize, Image.SCALE_DEFAULT) // Scale it to the correct size
- ));
- darkMode = new JButton(new ImageIcon(
- new FlatSVGIcon(JarUtils.accessFile("assets/distanthorizons/textures/jar/themeDark.svg")).getImage() // Get the image
- .getScaledInstance(themeButtonSize, themeButtonSize, Image.SCALE_DEFAULT) // Scale it to the correct size
- ));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- // Where do the buttons go
- lightMode.setBounds(rootPosOnLeft ? x : x - (themeButtonSize * 2), themeOnBottom ? y + langBoxHeight : y, themeButtonSize, themeButtonSize);
- darkMode.setBounds(rootPosOnLeft ? x + themeButtonSize : x - themeButtonSize, themeOnBottom ? y + langBoxHeight : y, themeButtonSize, themeButtonSize);
- // Tell buttons what to do
- lightMode.addActionListener(e -> {
- FlatLightLaf.setup();
- FlatLightLaf.updateUI();
- });
- darkMode.addActionListener(e -> {
- FlatDarkLaf.setup();
- FlatDarkLaf.updateUI();
- });
- // Finally add the buttons
- add(lightMode);
- add(darkMode);
- */
- }
-
- public BaseJFrame addLogo()
- {
- int logoHeight = 200;
-
- JPanel logo = new JPanel()
- {
- @Override
- protected void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- try
- {
- BufferedImage image = ImageIO.read(JarUtils.accessFile("assets/distanthorizons/logo.png"));
- int logoWidth = (int) ((double) logoHeight * ((double) image.getWidth() / (double) image.getHeight())); // Calculate the aspect ratio and set the height correctly to not stretch it
- g.drawImage(image, (getWidth() / 2) - (logoWidth / 2), 0, logoWidth, logoHeight, this); // Resize image and draw it
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- };
- logo.setBounds(logo.getX(), logo.getY(), logo.getWidth(), logo.getHeight());
-
- add(logo);
-
- return this;
- }
-
-
-
-
- // This part of the code is taken from the official java docs at https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
-
- // Specify the look and feel to use by defining the LOOKANDFEEL constant
- // Valid values are: null (use the default), "Metal", "System", "Motif", and "GTK"
- final static String LOOKANDFEEL = "GTK";
- private static void initLookAndFeel()
- {
- String lookAndFeel = null;
-
- if (LOOKANDFEEL != null)
- {
- if (LOOKANDFEEL.equals("Metal"))
- {
- lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
- // an alternative way to set the Metal L&F is to replace the
- // previous line with:
- // lookAndFeel = "javax.swing.plaf.metal.MetalLookAndFeel";
-
- }
- else if (LOOKANDFEEL.equals("System"))
- {
- lookAndFeel = UIManager.getSystemLookAndFeelClassName();
- }
- else if (LOOKANDFEEL.equals("Motif"))
- {
- lookAndFeel = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
- }
- else if (LOOKANDFEEL.equals("GTK"))
- {
- lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
- }
- else
- {
- System.err.println("Unexpected value of LOOKANDFEEL specified: "
- + LOOKANDFEEL);
- lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
- }
-
- try
- {
- UIManager.setLookAndFeel(lookAndFeel);
- }
- catch (ClassNotFoundException e)
- {
- System.err.println("Couldn't find class for specified look and feel:"
- + lookAndFeel);
- System.err.println("Did you include the L&F library in the class path?");
- System.err.println("Using the default look and feel.");
- }
- catch (UnsupportedLookAndFeelException e)
- {
- System.err.println("Can't use the specified look and feel ("
- + lookAndFeel
- + ") on this platform.");
- System.err.println("Using the default look and feel.");
- }
- catch (Exception e)
- {
- System.err.println("Couldn't get specified look and feel ("
- + lookAndFeel
- + "), for some reason.");
- System.err.println("Using the default look and feel.");
- e.printStackTrace();
- }
- }
- }
-
-}
-
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/JSwitch.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/JSwitch.java
deleted file mode 100644
index 29fb07235..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/JSwitch.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.jar.gui;
-
-import java.awt.*;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.beans.ConstructorProperties;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-
-import javax.swing.*;
-import javax.swing.plaf.ButtonUI;
-
-/**
- * A switch button cus Java dosnt have one
- *
- *
- * Ever wanted a switch like
- * this
- * or
- * this?
- * Well now you can this this class!
- *
- *
- * Based off Java's JButton
- *
- * @author coolGi
- */
-// TODO: Make this for the theme (and finish the documentation once it is done)
-@SuppressWarnings("serial")
-public class JSwitch extends AbstractButton
-{
- private static final String uiClassID = "SwitchUI";
-
- /** Creates a switch with no set text or icons */
- public JSwitch()
- {
- this(null, null, null, null);
- }
-
- /**
- * Creates a switch with an icon
- *
- * @param offIcon The deactivated icon image
- * @param onIcon The activated icon image
- */
- public JSwitch(Icon offIcon, Icon onIcon)
- {
- this(null, null, offIcon, onIcon);
- }
-
- /**
- * Creates a switch with text
- *
- * @param offText the deactivated text of the button
- * @param onText the activated text of the button
- */
- @ConstructorProperties({"text"})
- public JSwitch(String offText, String onText)
- {
- this(offText, onText, null, null);
- }
-
- /**
- * Creates a switch where properties are taken from the
- * Action supplied.
- *
- * @param a the Action used to specify the code that runs when pressing
- */
- public JSwitch(Action a)
- {
- this();
- setAction(a);
- }
-
- /**
- * Creates a switch with initial text and an icon
- *
- * @param offText the deactivated text of the button
- * @param onText the activated text of the button
- * @param offIcon The deactivated icon image
- * @param onIcon The activated icon image
- */
- public JSwitch(String offText, String onText, Icon offIcon, Icon onIcon)
- {
- // Create the model
- setModel(new DefaultButtonModel());
-
-// this.trueLabel = trueLabel;
-// this.falseLabel = falseLabel;
-// double trueLenth = getFontMetrics( getFont() ).getStringBounds( trueLabel, getGraphics() ).getWidth();
-// double falseLenght = getFontMetrics( getFont() ).getStringBounds( falseLabel, getGraphics() ).getWidth();
-// max = (int)Math.max( trueLenth, falseLenght );
-// gap = Math.max( 5, 5+(int)Math.abs(trueLenth - falseLenght ) );
-// thumbBounds = new Dimension(max+gap*2,20);
-// globalWitdh = max + thumbBounds.width+gap*2;
-// setModel( new DefaultButtonModel() );
-// setSelected( false );
-// addMouseListener( new MouseAdapter() {
-// @Override
-// public void mouseReleased( MouseEvent e ) {
-// if(new Rectangle( getPreferredSize() ).contains( e.getPoint() )) {
-// setSelected( !isSelected() );
-// }
-// }
-// });
- }
-
- /**
- * Resets the UI property to a value from the current look and feel
- *
- * @see JComponent#updateUI
- */
- public void updateUI()
- {
- setUI((ButtonUI) UIManager.getUI(this));
- }
-
-
- @Override
- public void setSelected(boolean b)
- {
-// if(b){
-// setText( trueLabel );
-// setBackground( green );
-// } else {
-// setBackground( red );
-// setText( falseLabel );
-// }
- super.setSelected(b);
- }
-
-
- /**
- * Returns a string that specifies the name of the L&F class
- * that renders this component.
- *
- * @return the string "ButtonUI"
- * @see JComponent#getUIClassID
- * @see UIDefaults#getUI
- */
- public String getUIClassID()
- {
- return uiClassID;
- }
-
-
- /**
- * Overrides JComponent.removeNotify to check if
- * this button is currently set as the default button on the
- * RootPane, and if so, sets the RootPane's
- * default button to null to ensure the
- * RootPane doesn't hold onto an invalid button reference.
- */
- public void removeNotify()
- {
- JRootPane root = SwingUtilities.getRootPane(this);
- super.removeNotify();
- }
-
-}
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/JSwitchBox.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/JSwitchBox.java
deleted file mode 100644
index 0c1630b0e..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/JSwitchBox.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.jar.gui;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.GradientPaint;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.Rectangle;
-import java.awt.RenderingHints;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.geom.Rectangle2D;
-
-import javax.swing.AbstractButton;
-import javax.swing.DefaultButtonModel;
-import javax.swing.JLabel;
-import javax.swing.UIManager;
-import javax.swing.border.Border;
-
-/**
- * Taken from https://github.com/sshtools/ui/blob/master/src/main/java/com/sshtools/ui/swing/JSwitchBox.java
- *
- * @author sshtools
- */
-// TODO: Merge this with my own JSwitch rather than use all their code
-// TODO: Make it work with the theme rather than do whatever it is doing now
-public class JSwitchBox extends AbstractButton
-{
- private Color shadow1 = UIManager.getColor("controlHighlight");
- private Color shadow2 = UIManager.getColor("control");
- private Color colorBright = UIManager.getColor("Button.light");
- private Color red = UIManager.getColor("controlShadow");
- private Color redf = UIManager.getColor("Button.foreground");
- private Color trackBackground = UIManager.getColor("textHighlight");
- private Color trackBackgroundText = UIManager.getColor("textHighlightText");
- private Border buttonBorder = UIManager.getBorder("Button.border");
- private Border trackBorder = UIManager.getBorder("Button.border");
-
- private Font font = new JLabel().getFont();
- private int gap = 5;
- private int globalWitdh = 0;
- private final String trueLabel;
- private final String falseLabel;
- private Dimension thumbBounds;
- private Rectangle2D bounds;
- private int max;
-
- public JSwitchBox(String trueLabel, String falseLabel)
- {
- setBackground(UIManager.getColor("Panel.background"));
- this.trueLabel = trueLabel;
- this.falseLabel = falseLabel;
- FontMetrics fontMetrics = getFontMetrics(getFont());
- double trueLenth = fontMetrics
- .getStringBounds(trueLabel, getGraphics()).getWidth();
- double falseLenght = fontMetrics.getStringBounds(falseLabel,
- getGraphics()).getWidth();
- max = (int) Math.max(trueLenth, falseLenght);
- gap = Math.max(5, 5 + (int) Math.abs(trueLenth - falseLenght));
- thumbBounds = new Dimension(max + gap * 2,
- (int) ((float) fontMetrics.getHeight() * 1.5));
- globalWitdh = max + thumbBounds.width + gap * 2;
- setModel(new DefaultButtonModel());
- setSelected(false);
- addMouseListener(new MouseAdapter()
- {
- @Override
- public void mouseReleased(MouseEvent e)
- {
- if (new Rectangle(getPreferredSize()).contains(e.getPoint()))
- {
- setSelected(!isSelected());
- }
- }
- });
- }
-
- @Override
- public Dimension getPreferredSize()
- {
- return new Dimension(globalWitdh, thumbBounds.height);
- }
-
- @Override
- public void setSelected(boolean b)
- {
- if (b)
- {
- setText(trueLabel);
- setBackground(trackBackground);
- setForeground(trackBackgroundText);
- }
- else
- {
- setBackground(red);
- setForeground(redf);
- setText(falseLabel);
- }
- super.setSelected(b);
- }
-
- @Override
- public void setText(String text)
- {
- super.setText(text);
- }
-
- @Override
- public int getHeight()
- {
-
- return getPreferredSize().height;
- }
-
- @Override
- public int getWidth()
- {
- return getPreferredSize().width;
- }
-
- @Override
- public Font getFont()
- {
- return font;
- }
-
- @Override
- protected void paintComponent(Graphics g)
- {
- g.setColor(getBackground());
- g.fillRect(0, 0, getWidth(), getHeight() - 4);
- Graphics2D g2 = (Graphics2D) g;
-
- // g2.setColor(black);
- // g2.drawRoundRect(1, 1, getWidth() - 2 - 1, getHeight() - 2 - 1, 2,
- // 2);
- // g2.setColor(white);
- // g2.drawRoundRect(1 + 1, 1 + 1, getWidth() - 2 - 3, getHeight() - 2 -
- // 3,
- // 2, 2);
-
- trackBorder.paintBorder(this, g2, 0, 2, getWidth(), getHeight() - 4);
-
- int buttonX = 0;
- int textX = 0;
- if (isSelected())
- {
- textX = thumbBounds.width;
- }
- else
- {
- buttonX = thumbBounds.width;
- }
- int y = 0;
- int w = thumbBounds.width;
- int h = thumbBounds.height;
-
- g2.setPaint(new GradientPaint(buttonX, (int) (y - 0.1 * h), shadow2,
- buttonX, (int) (y + 1.2 * h), shadow1));
- g2.fillRect(buttonX, y, w, h);
- g2.setPaint(new GradientPaint(buttonX, (int) (y + .65 * h), shadow1,
- buttonX, (int) (y + 1.3 * h), shadow2));
- g2.fillRect(buttonX, (int) (y + .65 * h), w, (int) (h - .65 * h));
-
- if (w > 14)
- {
- int size = 10;
- g2.setColor(colorBright);
- g2.fillRect(buttonX + w / 2 - size / 2, y + h / 2 - size / 2, size,
- size);
- g2.setColor(colorBright.darker());
- g2.fillRect(buttonX + w / 2 - 4, h / 2 - 4, 2, 2);
- g2.fillRect(buttonX + w / 2 - 1, h / 2 - 4, 2, 2);
- g2.fillRect(buttonX + w / 2 + 2, h / 2 - 4, 2, 2);
- g2.setColor(colorBright.darker().darker());
- g2.fillRect(buttonX + w / 2 - 4, h / 2 - 2, 2, 6);
- g2.fillRect(buttonX + w / 2 - 1, h / 2 - 2, 2, 6);
- g2.fillRect(buttonX + w / 2 + 2, h / 2 - 2, 2, 6);
- g2.setColor(colorBright.darker());
- g2.fillRect(buttonX + w / 2 - 4, h / 2 + 2, 2, 2);
- g2.fillRect(buttonX + w / 2 - 1, h / 2 + 2, 2, 2);
- g2.fillRect(buttonX + w / 2 + 2, h / 2 + 2, 2, 2);
- }
-
- buttonBorder.paintBorder(this, g2, buttonX, y, w, h);
- // g2.setColor(black);
- // g2.drawRoundRect(x, y, w - 1, h - 1, 2, 2);
- // g2.setColor(white);
- // g2.drawRoundRect(x + 1, y + 1, w - 3, h - 3, 2, 2);
-
- g2.setColor(getForeground());
- g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
- g2.setFont(getFont());
- g2.drawString(getText(), textX + gap, y + h / 2 + h / 4);
- }
-
-}
\ No newline at end of file
diff --git a/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/cusomJObject/JBox.java b/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/cusomJObject/JBox.java
deleted file mode 100644
index bab0feb49..000000000
--- a/core/src/main/java/com/seibel/distanthorizons/core/jar/gui/cusomJObject/JBox.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * This file is part of the Distant Horizons mod
- * licensed under the GNU LGPL v3 License.
- *
- * Copyright (C) 2020 James Seibel
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see .
- */
-
-package com.seibel.distanthorizons.core.jar.gui.cusomJObject;
-
-import javax.swing.*;
-import java.awt.*;
-
-/**
- * A rectangular box that can be placed with java swing
- *
- * @author coolGi
- */
-public class JBox extends JComponent
-{
- private static final String uiClassID = "BoxBarUI";
-
- private Color color;
-
- private int x;
- private int y;
- private int width;
- private int height;
-
- public JBox()
- {
- this(null);
- }
-
- public JBox(Color color)
- {
- this.color = color;
- }
-
- public JBox(Color color, Rectangle rectangle)
- {
- this(color, rectangle.x, rectangle.y, rectangle.width, rectangle.height);
- }
-
- public JBox(Color color, int x, int y, int width, int height)
- {
- this.color = color;
- setBounds(x, y, width, height);
- }
-
- public void setColor(Color color)
- {
- this.color = color;
- }
-
- @Override
- public void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- g.setColor(color);
- g.fillRect(0, 0, getBounds().width, getBounds().height);
- }
-
-}