diff --git a/.gitignore b/.gitignore index 6eea64e..bd2803a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ # Project exclude paths /out/ /.idea/ +/YoPlugin.jar/ diff --git a/ExamplesForReadme/img.png b/ExamplesForReadme/img.png new file mode 100644 index 0000000..d84376b Binary files /dev/null and b/ExamplesForReadme/img.png differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..69d69a5 --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +# YoPlugin + +Yo! This plugin works to diversify your shit code with any pictures. + + +![MarioProgressBar](https://raw.githubusercontent.com/DUNNIK/YoPlugin/develop/ExamplesForReadme/marioExample.gif) + +![SonicProgressBar](https://raw.githubusercontent.com/DUNNIK/YoPlugin/develop/ExamplesForReadme/sonicExample.gif) + +![PikachuProgressBar](https://raw.githubusercontent.com/DUNNIK/YoPlugin/develop/ExamplesForReadme/picachuExample.gif) + +![NianCatProgressBar](https://raw.githubusercontent.com/DUNNIK/YoPlugin/develop/ExamplesForReadme/nyanCatExample.gif) + +This is the plugin for [JetBrains Products](https://www.jetbrains.com/) based on the Nyan Progress Bar by Dmitry Batkovitch and Mario Progress Bar by Kylian Meulin. It shows various Progress bars and allows you to customize the loader yourself in settings. (But the picture or gif should be 20 pixels height ...) + +## How to install? + +You can install YoPlugin from the [JetBrains Plugin Repository](https://plugins.jetbrains.com/plugin/7973-sonarlint), directly available in the IDE preferences. + +## Where are the settings located? +------------ + File -> Settings -> Tools -> YoPlugin Settings + +## How do you add your image? + +![img.png](ExamplesForReadme/img.png) + + Chose image or gif file -> Click on Custom + +### Size of image + +####Your icon should be no more than 20 pixels high. +At the moment, changing the size of the icon is not implemented. The current solution broke the gif animation. So, if someone suggests a solution, I will be grateful. \ No newline at end of file diff --git a/YoPlugin.jar b/YoPlugin.jar index 4371fb7..2f12ba2 100644 Binary files a/YoPlugin.jar and b/YoPlugin.jar differ diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 415c66f..4d0181e 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -1,12 +1,12 @@ https://github.com/DUNNIK YoPlugin - 1.0 + 1.1 DUNNIK + Yo! This plugin works to diversify your shit code with any pictures.



@@ -22,6 +22,7 @@
  • Version 1.0. Add 4 gifs and field for custom gifs
  • +
  • Version 1.1. Fixed bugs related to the user icon
  • ]]>
    diff --git a/src/icons/YoIcons.java b/src/icons/YoIcons.java index a261092..d8af2e3 100644 --- a/src/icons/YoIcons.java +++ b/src/icons/YoIcons.java @@ -4,6 +4,8 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; +import java.io.File; +import java.net.MalformedURLException; import java.net.URL; public class YoIcons { @@ -14,7 +16,9 @@ public class YoIcons { private static final String SKELETONS_PATH = "/Gifs/Скелеты.gif"; private static final String NYAN_CAT_PATH = "/Gifs/NyanCat.gif"; - private YoIcons() { throw new IllegalStateException("Utility class"); } + public YoIcons() { + + } public static String getZombiePath() { return ZOMBIE_PATH; @@ -40,6 +44,7 @@ public static String getMarioPath() { return MARIO_PATH; } + @NotNull @Contract("_ -> new") public static ImageIcon loadIcon(URL url) { diff --git a/src/logic/YoProgressBarUi.java b/src/logic/YoProgressBarUi.java index af5e021..7223cc0 100644 --- a/src/logic/YoProgressBarUi.java +++ b/src/logic/YoProgressBarUi.java @@ -23,6 +23,9 @@ import java.awt.geom.Area; import java.awt.geom.Rectangle2D; import java.awt.geom.RoundRectangle2D; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; public class YoProgressBarUi extends BasicProgressBarUI { @@ -67,7 +70,7 @@ private boolean isNotInstanceOfGraphic2D(Graphics g2d){ //Универсальный метод рисования, который должен делать правильные вещи для всех линейных индикаторов выполнения прыгающих ящиков. @Override protected void paintIndeterminate(Graphics g2d, JComponent component) { - if (!(g2d instanceof Graphics2D)) { + if (isNotInstanceOfGraphic2D(g2d)) { return; } @@ -121,7 +124,7 @@ protected void paintIndeterminate(Graphics g2d, JComponent component) { graphics2D.fill(area); } var state = YoProgressBarUiState.getInstance(); - var currentIcon = YoIcons.loadIcon(this.getClass().getResource(state.getCurrentIconPath())); + var currentIcon = YoIcons.loadIcon(cleanURL(state.getCurrentIconPath())); currentIcon.paintIcon(progressBar, graphics2D, offset2 - JBUIScale.scale(5), -(component.getHeight() - barRectHeight) / 2); @@ -138,10 +141,25 @@ protected void paintIndeterminate(Graphics g2d, JComponent component) { config.restore(); } + private URL cleanURL(String filePath){ + var url = this.getClass().getResource(filePath); + if (url == null){ + try { + url = createUrlFromPath(filePath); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + } + return url; + } + private URL createUrlFromPath(String filePath) throws MalformedURLException { + return new File(filePath).toURI().toURL(); + } + //Универсальный метод рисования, который должен делать правильные вещи почти для всех линейных, определенных индикаторов прогресса. @Override protected void paintDeterminate(Graphics graphics, JComponent component) { - if (!(graphics instanceof Graphics2D)) { + if (isNotInstanceOfGraphic2D(graphics)) { return; } @@ -194,7 +212,8 @@ protected void paintDeterminate(Graphics graphics, JComponent component) { graphics2D.fill(new RoundRectangle2D.Float(2f * off, 2f * off, amountFull - JBUIScale.scale(5f), progressBarHeight - JBUIScale.scale(5f), JBUIScale.scale(7f), JBUIScale.scale(7f))); - var currentIcon = YoIcons.loadIcon(this.getClass().getResource(state.getCurrentIconPath())); + + var currentIcon = YoIcons.loadIcon(cleanURL(state.getCurrentIconPath())); currentIcon.paintIcon(progressBar, graphics2D, amountFull - JBUIScale.scale(5), -(component.getHeight() - progressBarHeight) / 2); graphics2D.translate(0, -(component.getHeight() - progressBarHeight) / 2); diff --git a/src/settings/YoSettingsComponent.java b/src/settings/YoSettingsComponent.java index d4af699..de3393e 100644 --- a/src/settings/YoSettingsComponent.java +++ b/src/settings/YoSettingsComponent.java @@ -10,8 +10,11 @@ import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.awt.*; +import java.io.File; import java.util.ArrayList; import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Supports creating and managing a {@link JPanel} for the Settings Dialog. @@ -72,11 +75,19 @@ private void addButtonAction(@NotNull JButton button) { int ret = fileChooser.showDialog(null, "Open file"); if (ret == JFileChooser.APPROVE_OPTION) { var file = fileChooser.getSelectedFile(); - userIconPath.setText(file.getPath()); + userIconPath.setText(clearFilePath(file.getPath())); } }); } + private String clearFilePath(String filePath) { + var separator = File.separator; + var filePathAfterChangingSeparator = filePath.replaceAll(Matcher.quoteReplacement(separator), "/"); + var regex = "^.*:"; + var pattern = Pattern.compile(regex); + var matcher = pattern.matcher(filePathAfterChangingSeparator); + return matcher.replaceFirst(""); + } public JRadioButton getCurrentButton() { return currentButton; } diff --git a/src/settings/YoSettingsConfigurable.java b/src/settings/YoSettingsConfigurable.java index 8d1ce1a..e1b783a 100644 --- a/src/settings/YoSettingsConfigurable.java +++ b/src/settings/YoSettingsConfigurable.java @@ -5,7 +5,6 @@ import com.intellij.openapi.options.Configurable; import handler.YoCommand; import handler.YoHandler; -import org.h2.util.StringUtils; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.Nullable; @@ -62,7 +61,7 @@ public void apply() { changeDesign.toDo(); } private boolean isNotImpossibleToCustom() { - return StringUtils.isWhitespaceOrEmpty(yoSettingsComponent.getCustomPath()) && yoSettingsComponent.getCurrentButtonText().equals("Custom"); + return yoSettingsComponent.getCustomPath().trim().isEmpty() && yoSettingsComponent.getCurrentButtonText().equals("Custom"); } @Override public void reset() {