Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@

# Created by https://www.gitignore.io/api/java,intellij

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries

# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle:
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/

# Mongo Explorer plugin:
.idea/**/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Ruby plugin and RubyMine
/.rakeTasks

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
.idea/sonarlint

### Java ###
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*


# End of https://www.gitignore.io/api/java,intellij
42 changes: 25 additions & 17 deletions src/NyanProgressBarUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@
import java.awt.geom.*;

public class NyanProgressBarUi extends BasicProgressBarUI {
private static final float ONE_OVER_SEVEN = 1f / 7;
private static final Color VIOLET = new Color(90, 0, 157);


{

}
@SuppressWarnings({"MethodOverridesStaticMethodOfSuperclass", "UnusedDeclaration"})
public static ComponentUI createUI(JComponent c) {
c.setBorder(JBUI.Borders.empty().asUIResource());
Expand Down Expand Up @@ -74,9 +68,7 @@ protected void paintIndeterminate(Graphics g2d, JComponent c) {
int h = c.getPreferredSize().height;
if (!isEven(c.getHeight() - h)) h++;

LinearGradientPaint baseRainbowPaint = new LinearGradientPaint(0, JBUI.scale(2), 0, h - JBUI.scale(6),
new float[]{ONE_OVER_SEVEN * 1, ONE_OVER_SEVEN * 2, ONE_OVER_SEVEN * 3, ONE_OVER_SEVEN * 4, ONE_OVER_SEVEN * 5, ONE_OVER_SEVEN * 6, ONE_OVER_SEVEN * 7},
new Color[]{Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.cyan, Color.blue, VIOLET});
LinearGradientPaint baseRainbowPaint = getRainbowPaintFromHeight(h);

g.setPaint(baseRainbowPaint);

Expand All @@ -88,11 +80,6 @@ protected void paintIndeterminate(Graphics g2d, JComponent c) {
g.translate(0, (c.getHeight() - h) / 2);
int x = -offset;


// LinearGradientPaint baseRainbowPaint = new LinearGradientPaint(0, JBUI.scale(2), 0, h - JBUI.scale(6),
// new float[]{ONE_OVER_SEVEN * 1, ONE_OVER_SEVEN * 2, ONE_OVER_SEVEN * 3, ONE_OVER_SEVEN * 4, ONE_OVER_SEVEN * 5, ONE_OVER_SEVEN * 6, ONE_OVER_SEVEN * 7},
// new Color[]{Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.cyan, Color.blue, VIOLET});

Paint old = g.getPaint();
g.setPaint(baseRainbowPaint);

Expand Down Expand Up @@ -204,9 +191,7 @@ protected void paintDeterminate(Graphics g, JComponent c) {
g2.setColor(c.getParent().getBackground());
g2.fill(new RoundRectangle2D.Float(off, off, w - 2f*off - off, h - 2f*off - off, R, R));
// g2.setColor(progressBar.getForeground());
g2.setPaint(new LinearGradientPaint(0, JBUI.scale(2), 0, h - JBUI.scale(6),
new float[]{ONE_OVER_SEVEN * 1, ONE_OVER_SEVEN * 2, ONE_OVER_SEVEN * 3, ONE_OVER_SEVEN * 4, ONE_OVER_SEVEN * 5, ONE_OVER_SEVEN * 6, ONE_OVER_SEVEN * 7},
new Color[]{Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.cyan, Color.blue, VIOLET}));
g2.setPaint(getRainbowPaintFromHeight(h));

NyanIcons.CAT_ICON.paintIcon(progressBar, g2, amountFull - JBUI.scale(10), -JBUI.scale(6));
g2.fill(new RoundRectangle2D.Float(2f*off,2f*off, amountFull - JBUI.scale(5f), h - JBUI.scale(5f), JBUI.scale(7f), JBUI.scale(7f)));
Expand Down Expand Up @@ -258,6 +243,29 @@ private void paintString(Graphics g, int x, int y, int w, int h, int fillStart,
g2.setClip(oldClip);
}

/** Create a gradient such as [0, 0.99, 1, 1.99, ...], [RED, RED, ORANGE, ORANGE, ..] */
private LinearGradientPaint getRainbowPaintFromHeight(float scaledHeight) {

int numRainbowColors = RainbowColors.RAINBOW_ARRAY.length;
float epsilon = 0.000001f;

float[] fractionList = new float[numRainbowColors * 2];
Color[] colorList = new Color[numRainbowColors * 2];

for (int i = 0; i < numRainbowColors; i++) {
fractionList[i * 2] = (float) i / numRainbowColors;
fractionList[i * 2 + 1] = ((i + 1) - epsilon) / numRainbowColors;

colorList[i * 2] = RainbowColors.RAINBOW_ARRAY[i];
colorList[i * 2 + 1] = RainbowColors.RAINBOW_ARRAY[i];
}

return new LinearGradientPaint(0, JBUI.scale(1),
0, scaledHeight - JBUI.scale(3),
fractionList, colorList);
}


@Override
protected int getBoxLength(int availableLength, int otherDimension) {
return availableLength;
Expand Down
12 changes: 12 additions & 0 deletions src/RainbowColors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import java.awt.*;

public class RainbowColors {
static final Color RED = new Color(255, 0, 0);
static final Color ORANGE = new Color(255, 154, 0);
static final Color YELLOW = new Color(255, 255, 0);
static final Color GREEN = new Color(25, 255, 0);
static final Color BLUE = new Color(0, 150, 255);
static final Color VIOLET = new Color(100, 30, 255);

static final Color[] RAINBOW_ARRAY = new Color[]{RED, ORANGE, YELLOW, GREEN, BLUE, VIOLET};
}