Save commit
This commit is contained in:
@@ -4,17 +4,18 @@ import com.formdev.flatlaf.FlatDarkLaf;
|
||||
import com.formdev.flatlaf.FlatLightLaf;
|
||||
import com.seibel.lod.core.handlers.dependencyInjection.SingletonHandler;
|
||||
import com.seibel.lod.core.jar.DarkModeDetector;
|
||||
import com.seibel.lod.core.jar.BaseJFrame;
|
||||
import com.seibel.lod.core.jar.gui.BaseJFrame;
|
||||
import com.seibel.lod.core.jar.installer.GitlabGetter;
|
||||
import com.seibel.lod.core.jar.JarDependencySetup;
|
||||
import com.seibel.lod.core.jar.installer.WebDownloader;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* The main class when you run the standalone jar
|
||||
@@ -22,13 +23,14 @@ import java.util.Locale;
|
||||
* @author coolGi
|
||||
*/
|
||||
public class JarMain {
|
||||
public static final File jarFile = new File(JarMain.class.getProtectionDomain().getCodeSource().getLocation().getPath());
|
||||
public static final boolean isDarkTheme = DarkModeDetector.isDarkMode();
|
||||
public static boolean isOffline = WebDownloader.netIsAvailable();
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Sets up the local
|
||||
if (JarMain.accessFile("assets/lod/lang/"+Locale.getDefault().toString().toLowerCase()+".json") == null) {
|
||||
System.out.println("The language setting ["+Locale.getDefault().toString().toLowerCase()+"] isn't allowed yet. Defaulting to ["+Locale.US.toString().toLowerCase()+"].");
|
||||
if (JarMain.accessFile("assets/lod/lang/" + Locale.getDefault().toString().toLowerCase() + ".json") == null) {
|
||||
System.out.println("The language setting [" + Locale.getDefault().toString().toLowerCase() + "] isn't allowed yet. Defaulting to [" + Locale.US.toString().toLowerCase() + "].");
|
||||
Locale.setDefault(Locale.US);
|
||||
}
|
||||
// Set up the theme
|
||||
@@ -49,38 +51,48 @@ public class JarMain {
|
||||
System.out.println("If you want the installer then please use Linux or for the time being.\nMacOS support/testing will come later on");
|
||||
}
|
||||
|
||||
// All code beyond this point is messy and will be rewritten later as I dont like it
|
||||
// ===============================================================================================================
|
||||
|
||||
BaseJFrame frame = new BaseJFrame(false, false).addExtraButtons();
|
||||
BaseJFrame frame = new BaseJFrame(false, false);
|
||||
frame.addExtraButtons(true);
|
||||
// String[] optionsToChoose = {"Apple", "Orange", "Banana", "Pineapple"};
|
||||
// JComboBox<String> jTest = new JComboBox<>(optionsToChoose);
|
||||
// jTest.setBounds(400, 250, 140, 20);
|
||||
// frame.add(jTest);
|
||||
// jTest.addActionListener(e -> { System.out.println("test"); });
|
||||
|
||||
|
||||
// Buttons which you want to be stacked vertically should be added with this (`frame.add(obj, this);`)
|
||||
GridBagConstraints verticalLayout = new GridBagConstraints();
|
||||
verticalLayout.gridy = GridBagConstraints.RELATIVE;
|
||||
verticalLayout.gridx = 0;
|
||||
verticalLayout.fill = GridBagConstraints.HORIZONTAL;
|
||||
verticalLayout.weightx = 1.0;
|
||||
verticalLayout.anchor = GridBagConstraints.NORTH;
|
||||
|
||||
|
||||
// Old style
|
||||
/*
|
||||
JFileChooser minecraftDirPop = new JFileChooser();
|
||||
if (getOperatingSystem().equals(OperatingSystem.WINDOWS))
|
||||
minecraftDirPop.setCurrentDirectory(new File(System.getenv("APPDATA")+"/.minecraft/mods"));
|
||||
minecraftDirPop.setCurrentDirectory(new File(System.getenv("APPDATA") + "/.minecraft/mods"));
|
||||
if (getOperatingSystem().equals(OperatingSystem.LINUX))
|
||||
minecraftDirPop.setCurrentDirectory(new File(System.getProperty("user.home")+"/.minecraft/mods"));
|
||||
minecraftDirPop.setCurrentDirectory(new File(System.getProperty("user.home") + "/.minecraft/mods"));
|
||||
minecraftDirPop.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
JButton minecraftDirBtn = new JButton("Click to select install path");
|
||||
minecraftDirBtn.addActionListener(e -> {
|
||||
if (minecraftDirPop.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION)
|
||||
minecraftDirBtn.setText(minecraftDirPop.getSelectedFile().toString());
|
||||
});
|
||||
minecraftDirBtn.setBounds(frame.getWidth()/2 - (200/2), 250, 200, 20);
|
||||
minecraftDirBtn.setBounds(frame.getWidth() / 2 - (200 / 2), 250, 200, 20);
|
||||
frame.add(minecraftDirBtn);
|
||||
|
||||
JComboBox<String> modVersions = new JComboBox<>(
|
||||
Arrays.copyOf(GitlabGetter.readableReleaseNames.toArray(), GitlabGetter.readableReleaseNames.toArray().length, String[].class)
|
||||
);
|
||||
modVersions.setBounds(frame.getWidth()/2 - (200/2), 280, 200, 20);
|
||||
modVersions.setBounds(frame.getWidth() / 2 - (200 / 2), 280, 200, 20);
|
||||
|
||||
JComboBox<String> modMcVersion = new JComboBox<>();
|
||||
modMcVersion.setBounds(frame.getWidth()/2 - (200/2), 310, 200, 20);
|
||||
modMcVersion.setModel( new DefaultComboBoxModel(
|
||||
modMcVersion.setBounds(frame.getWidth() / 2 - (200 / 2), 310, 200, 20);
|
||||
modMcVersion.setModel(new DefaultComboBoxModel(
|
||||
Arrays.copyOf(
|
||||
GitlabGetter.getMcVersionsInRelease(GitlabGetter.releaseNames.get(modVersions.getSelectedIndex())).toArray(),
|
||||
GitlabGetter.getMcVersionsInRelease(GitlabGetter.releaseNames.get(modVersions.getSelectedIndex())).toArray().length,
|
||||
@@ -88,8 +100,8 @@ public class JarMain {
|
||||
))
|
||||
);
|
||||
|
||||
modVersions.addActionListener( e -> {
|
||||
modMcVersion.setModel( new DefaultComboBoxModel(
|
||||
modVersions.addActionListener(e -> {
|
||||
modMcVersion.setModel(new DefaultComboBoxModel(
|
||||
Arrays.copyOf(
|
||||
GitlabGetter.getMcVersionsInRelease(GitlabGetter.releaseNames.get(modVersions.getSelectedIndex())).toArray(),
|
||||
GitlabGetter.getMcVersionsInRelease(GitlabGetter.releaseNames.get(modVersions.getSelectedIndex())).toArray().length,
|
||||
@@ -107,9 +119,9 @@ public class JarMain {
|
||||
// Runtime.getRuntime().exec("java -jar " + System.getProperty("java.io.tmpdir") + "/fabricInstaller.jar");
|
||||
// } catch (Exception e) {e.printStackTrace();}
|
||||
|
||||
JButton installMod = new JButton("Install "+ModInfo.READABLE_NAME);
|
||||
installMod.setBounds(frame.getWidth()/2 - (200/2), 340, 200, 20);
|
||||
installMod.addActionListener( e -> {
|
||||
JButton installMod = new JButton("Install " + ModInfo.READABLE_NAME);
|
||||
installMod.setBounds(frame.getWidth() / 2 - (200 / 2), 340, 200, 20);
|
||||
installMod.addActionListener(e -> {
|
||||
if (minecraftDirPop.getSelectedFile() == null) {
|
||||
JOptionPane.showMessageDialog(frame, "Please select your install directory", ModInfo.READABLE_NAME, JOptionPane.WARNING_MESSAGE);
|
||||
return;
|
||||
@@ -123,14 +135,16 @@ public class JarMain {
|
||||
try {
|
||||
if (downloadPath.toString().contains("curseforge.com"))
|
||||
downloadPath = new URL(downloadPath.toString() + "/file");
|
||||
} catch (Exception f) { f.printStackTrace(); }
|
||||
} catch (Exception f) {
|
||||
f.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
WebDownloader.downloadAsFile(
|
||||
downloadPath,
|
||||
minecraftDirPop.getSelectedFile().toPath().resolve(
|
||||
ModInfo.NAME+"-"+GitlabGetter.releaseNames.get(modVersions.getSelectedIndex())+"-"+((String) modMcVersion.getSelectedItem())+".jar"
|
||||
).toFile());
|
||||
downloadPath,
|
||||
minecraftDirPop.getSelectedFile().toPath().resolve(
|
||||
ModInfo.NAME + "-" + GitlabGetter.releaseNames.get(modVersions.getSelectedIndex()) + "-" + ((String) modMcVersion.getSelectedItem()) + ".jar"
|
||||
).toFile());
|
||||
|
||||
JOptionPane.showMessageDialog(frame, "Installation done. \nYou can now close the installer", ModInfo.READABLE_NAME, JOptionPane.INFORMATION_MESSAGE);
|
||||
} catch (Exception f) {
|
||||
@@ -138,8 +152,91 @@ public class JarMain {
|
||||
}
|
||||
});
|
||||
frame.add(installMod);
|
||||
*/
|
||||
// Selected versions
|
||||
// (What does atomic reference mean. I'm just using it cus java hates having normal strings)
|
||||
AtomicReference<String> modVersion = new AtomicReference<String>("");
|
||||
AtomicReference<String> minecraftVersion = new AtomicReference<String>("");
|
||||
|
||||
frame.addLogo();
|
||||
|
||||
|
||||
// This is for the pannel to select MinecraftVersion
|
||||
JPanel modMinecraftVersionsPannel = new JPanel(new GridBagLayout());
|
||||
JScrollPane modMinecraftVersionsScroll = new JScrollPane(modMinecraftVersionsPannel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
// Sets all the layout stuff for it
|
||||
modMinecraftVersionsScroll.setBounds(150, 225, 150, frame.getHeight()-255);
|
||||
modMinecraftVersionsScroll.setBorder(null); // Disables the border
|
||||
modMinecraftVersionsScroll.setWheelScrollingEnabled(true);
|
||||
// List to store all the buttons
|
||||
ArrayList<JButton> modMinecraftReleaseButtons = new ArrayList<>();
|
||||
// Add the pannel to the main frame
|
||||
frame.add(modMinecraftVersionsScroll);
|
||||
|
||||
|
||||
|
||||
// This is for selecting the mod version
|
||||
JPanel modVersionsPannel = new JPanel(new GridBagLayout());
|
||||
JScrollPane modVersionsScroll = new JScrollPane(modVersionsPannel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
|
||||
// Sets all the layout stuff for it
|
||||
modVersionsScroll.setBounds(0, 225, 150, frame.getHeight()-255);
|
||||
modVersionsScroll.setBorder(null); // Disables the border
|
||||
modVersionsScroll.setWheelScrollingEnabled(true);
|
||||
// List to store all the buttons
|
||||
ArrayList<JButton> modReleaseButtons = new ArrayList<>();
|
||||
|
||||
// Add all the buttons
|
||||
for (String release: GitlabGetter.readableReleaseNames) {
|
||||
JButton btn = new JButton(release);
|
||||
btn.setBackground(UIManager.getColor ("Panel.background")); // Does the same thing as removing the background
|
||||
btn.setBorderPainted(false); // Removes the borders
|
||||
btn.setHorizontalAlignment(SwingConstants.LEFT); // Sets the text to be on the left side rather than the center
|
||||
|
||||
btn.addActionListener(e -> {
|
||||
modVersion.set(GitlabGetter.releaseNames.get(GitlabGetter.readableReleaseNames.indexOf(btn.getText())));
|
||||
|
||||
// Clears the selected colors for the rest of the buttons
|
||||
for (JButton currentBtn: modReleaseButtons)
|
||||
currentBtn.setBackground(UIManager.getColor ("Panel.background"));
|
||||
btn.setBackground(UIManager.getColor("Button.background")); // Sets this to the selected color
|
||||
|
||||
// Clears the minecraft version panel
|
||||
modMinecraftVersionsPannel.removeAll();
|
||||
modMinecraftReleaseButtons.clear();
|
||||
|
||||
// Adds all the buttons for the minecraft panel
|
||||
for (String releaseMC: GitlabGetter.getMcVersionsInRelease(GitlabGetter.releaseNames.get(GitlabGetter.readableReleaseNames.indexOf(btn.getText())))) {
|
||||
// No need to comment most of these as it is the same this as before
|
||||
JButton btnMC = new JButton(releaseMC);
|
||||
btnMC.setBackground(UIManager.getColor ("Panel.background"));
|
||||
btnMC.setBorderPainted(false);
|
||||
btnMC.setHorizontalAlignment(SwingConstants.LEFT);
|
||||
|
||||
btnMC.addActionListener(f -> {
|
||||
minecraftVersion.set(btnMC.getText());
|
||||
|
||||
for (JButton currentBtn: modMinecraftReleaseButtons)
|
||||
currentBtn.setBackground(UIManager.getColor ("Panel.background"));
|
||||
btnMC.setBackground(UIManager.getColor("Button.background"));
|
||||
});
|
||||
modMinecraftVersionsPannel.add(btnMC, verticalLayout);
|
||||
modMinecraftReleaseButtons.add(btnMC);
|
||||
}
|
||||
modMinecraftVersionsPannel.repaint(); // Update the minecraft ver panel
|
||||
frame.validate(); // Update the frame
|
||||
});
|
||||
|
||||
modVersionsPannel.add(btn, verticalLayout);
|
||||
modReleaseButtons.add(btn);
|
||||
}
|
||||
|
||||
frame.add(modVersionsScroll);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
frame.addLogo(); // Has to be ran at the end cus of a bug with java swing (it may not be a bug but idk how to fix it so I'll call it a bug)
|
||||
|
||||
frame.validate(); // Update to add the widgets
|
||||
frame.setVisible(true); // Start the ui
|
||||
|
||||
+20
-13
@@ -1,7 +1,6 @@
|
||||
package com.seibel.lod.core.jar;
|
||||
package com.seibel.lod.core.jar.gui;
|
||||
|
||||
import com.formdev.flatlaf.FlatDarkLaf;
|
||||
import com.formdev.flatlaf.FlatLaf;
|
||||
import com.formdev.flatlaf.FlatLightLaf;
|
||||
import com.formdev.flatlaf.extras.FlatSVGIcon;
|
||||
import com.seibel.lod.core.JarMain;
|
||||
@@ -11,11 +10,8 @@ import com.seibel.lod.core.wrapperInterfaces.config.IConfigWrapper;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
@@ -45,7 +41,12 @@ public class BaseJFrame extends JFrame {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
|
||||
public BaseJFrame addExtraButtons() { // TODO: Change everything to paint rather than using J stuff
|
||||
/**
|
||||
* Buttons for language and theme changing
|
||||
*
|
||||
* @param side If false it would be on the bottom left and if True then it would be on the bottom right
|
||||
*/
|
||||
public void addExtraButtons(boolean side) {
|
||||
// ========== LANGUAGE ==========
|
||||
int langBoxHeight = 25;
|
||||
int langBoxWidth = 100;
|
||||
@@ -68,13 +69,16 @@ public class BaseJFrame extends JFrame {
|
||||
Locale.setDefault(Locale.forLanguageTag(languageBox.getSelectedItem().toString())); // Change lang on update
|
||||
} );
|
||||
// Set where it goes
|
||||
languageBox.setBounds(0, getHeight()-(langBoxHeight*2), langBoxWidth, langBoxHeight);
|
||||
if (side)
|
||||
languageBox.setBounds(getWidth()-langBoxWidth, getHeight()-(langBoxHeight*2), langBoxWidth, langBoxHeight);
|
||||
else
|
||||
languageBox.setBounds(0, getHeight()-(langBoxHeight*2), 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;
|
||||
@@ -90,8 +94,14 @@ public class BaseJFrame extends JFrame {
|
||||
));
|
||||
} catch (Exception e) {e.printStackTrace();}
|
||||
// Where do the buttons go
|
||||
lightMode.setBounds(0, getHeight()-(themeButtonSize*2)-langBoxHeight, themeButtonSize, themeButtonSize);
|
||||
darkMode.setBounds(themeButtonSize, getHeight()-(themeButtonSize*2)-langBoxHeight, themeButtonSize, themeButtonSize);
|
||||
if (side) {
|
||||
lightMode.setBounds(getWidth()-(themeButtonSize*2), getHeight() - (themeButtonSize * 2) - langBoxHeight, themeButtonSize, themeButtonSize);
|
||||
darkMode.setBounds(getWidth()-themeButtonSize, getHeight() - (themeButtonSize * 2) - langBoxHeight, themeButtonSize, themeButtonSize);
|
||||
}
|
||||
else {
|
||||
lightMode.setBounds(0, getHeight() - (themeButtonSize * 2) - langBoxHeight, themeButtonSize, themeButtonSize);
|
||||
darkMode.setBounds(themeButtonSize, getHeight() - (themeButtonSize * 2) - langBoxHeight, themeButtonSize, themeButtonSize);
|
||||
}
|
||||
// Tell buttons what to do
|
||||
lightMode.addActionListener(e -> {
|
||||
FlatLightLaf.setup();
|
||||
@@ -104,9 +114,6 @@ public class BaseJFrame extends JFrame {
|
||||
// Finally add the buttons
|
||||
add(lightMode);
|
||||
add(darkMode);
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseJFrame addLogo() {
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.seibel.lod.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
|
||||
*
|
||||
* <p>
|
||||
* Ever wanted a switch like
|
||||
* <code><a href="https://www.overflowarchives.com/wp-content/uploads/2020/05/overflow-archives-unity-3d-switch-button-ui.jpg">this</a></code>
|
||||
* or
|
||||
* <code><a href="https://c8.alamy.com/comp/2E3PHHW/day-night-mode-switch-ui-button-light-dark-mode-slider-theme-2E3PHHW.jpg">this</a></code>?
|
||||
* Well now you can this this class!
|
||||
* </p>
|
||||
*
|
||||
* Based off Java's JButton
|
||||
*
|
||||
* @author coolGi
|
||||
*/
|
||||
@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
|
||||
* <code>Action</code> supplied.
|
||||
*
|
||||
* @param a the <code>Action</code> 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 <code>JComponent.removeNotify</code> to check if
|
||||
* this button is currently set as the default button on the
|
||||
* <code>RootPane</code>, and if so, sets the <code>RootPane</code>'s
|
||||
* default button to <code>null</code> to ensure the
|
||||
* <code>RootPane</code> doesn't hold onto an invalid button reference.
|
||||
*/
|
||||
public void removeNotify() {
|
||||
JRootPane root = SwingUtilities.getRootPane(this);
|
||||
super.removeNotify();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
package com.seibel.lod.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);
|
||||
}
|
||||
}
|
||||
@@ -110,6 +110,28 @@ public class GitlabGetter {
|
||||
|
||||
return null;
|
||||
}
|
||||
/** Gets the update log of a release */
|
||||
public static String getVersionDescription(String version) {
|
||||
try {
|
||||
if (!version.equals("1.6.0a")) { // We have to do this cus 1.6.0a stuffed up some ordering
|
||||
// Do this hack to remove all the mcVer-1.6.0a items from the releaseNames
|
||||
int newVer = releaseNames.indexOf(version);
|
||||
if (releaseNames.indexOf(version) > releaseNames.size()-14)
|
||||
newVer += 2;
|
||||
|
||||
return ((JSONObject) projectRelease.get(newVer)).get("description").toString();
|
||||
} else {
|
||||
for (int i = 0; i < projectRelease.size(); i++) {
|
||||
JSONObject currentRelease = ((JSONObject) new JSONParser().parse(projectRelease.get(i).toString()));
|
||||
if (currentRelease.get("tag_name").toString().contains("-1.6.0a"))
|
||||
return currentRelease.get("description").toString();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static JSONArray getScuffedReleaseArray(String version) {
|
||||
|
||||
@@ -19,11 +19,9 @@ public class WebDownloader {
|
||||
final URLConnection conn = url.openConnection();
|
||||
conn.connect();
|
||||
conn.getInputStream().close();
|
||||
return true;
|
||||
} catch (MalformedURLException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.seibel.lod.core.jar.tui;
|
||||
|
||||
// TUI stands for terminal ui btw
|
||||
public class BaseTUI {
|
||||
}
|
||||
Reference in New Issue
Block a user