Skip to content

Commit

Permalink
Version #1.1
Browse files Browse the repository at this point in the history
Fix bugs in custom logic and create readme
  • Loading branch information
DUNNIK authored Jun 5, 2021
2 parents d57b24c + 142d35b commit b2da64f
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Project exclude paths
/out/
/.idea/
/YoPlugin.jar/
Binary file added ExamplesForReadme/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file modified YoPlugin.jar
Binary file not shown.
5 changes: 3 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<idea-plugin>
<id>https://github.com/DUNNIK</id>
<name>YoPlugin</name>
<version>1.0</version>
<version>1.1</version>
<idea-version since-build="193"/>
<vendor email="dns.56@mail.ru" url="https://github.com/DUNNIK">DUNNIK</vendor>

<description><![CDATA[
Yo! This plugin is created to diversify your shitcode with your any pictures.<br/>
Yo! This plugin works to diversify your shit code with any pictures.<br/>
<img width="500" src="https://raw.githubusercontent.com/DUNNIK/YoPlugin/develop/ExamplesForReadme/marioExample.gif"/><br/>
<img width="500" src="https://raw.githubusercontent.com/DUNNIK/YoPlugin/develop/ExamplesForReadme/sonicExample.gif"/><br/>
<img width="500" src="https://raw.githubusercontent.com/DUNNIK/YoPlugin/develop/ExamplesForReadme/picachuExample.gif"/><br/>
Expand All @@ -22,6 +22,7 @@
<change-notes><![CDATA[
<ul>
<li>Version 1.0. Add 4 gifs and field for custom gifs</li>
<li>Version 1.1. Fixed bugs related to the user icon</li>
</ul>
]]>
</change-notes>
Expand Down
7 changes: 6 additions & 1 deletion src/icons/YoIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -40,6 +44,7 @@ public static String getMarioPath() {
return MARIO_PATH;
}


@NotNull
@Contract("_ -> new")
public static ImageIcon loadIcon(URL url) {
Expand Down
27 changes: 23 additions & 4 deletions src/logic/YoProgressBarUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
13 changes: 12 additions & 1 deletion src/settings/YoSettingsComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/settings/YoSettingsConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit b2da64f

Please sign in to comment.