Skip to content

Commit f987785

Browse files
committed
Fixed #11
1 parent af9b93c commit f987785

File tree

4 files changed

+92
-28
lines changed

4 files changed

+92
-28
lines changed

src/io/github/rowak/nanoleafdesktop/Main.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
public class Main extends JFrame
8282
{
83-
public static final Version VERSION = new Version("v0.8.2", true);
83+
public static final Version VERSION = new Version("v0.8.2", false);
8484
public static final String VERSION_HOST =
8585
"https://api.github.com/repos/rowak/nanoleaf-desktop/releases";
8686
public static final String GIT_REPO = "https://github.com/rowak/nanoleaf-desktop";
@@ -345,6 +345,20 @@ public void run()
345345
sce.printStackTrace();
346346
}
347347

348+
BasicEffects.initializeBasicEffects();
349+
try
350+
{
351+
List<Effect> effects = BasicEffects.getBasicEffects(devices).get(0);
352+
for (Effect ef : effects)
353+
{
354+
basicEffectsPanel.addEffect(ef.getName());
355+
}
356+
}
357+
catch (StatusCodeException sce)
358+
{
359+
sce.printStackTrace();
360+
}
361+
348362
if (regEffectsPanel.getModel().size() > 0)
349363
{
350364
regEffectsPanel.setViewportView(regEffectsPanel.getList());
@@ -722,20 +736,7 @@ private void initPanelCanvas()
722736

723737
private void initEffectsPanels()
724738
{
725-
BasicEffects.initializeBasicEffects();
726739
basicEffectsPanel = new EffectsPanel("Basic Effects", this, devices, canvas);
727-
try
728-
{
729-
List<Effect> effects = BasicEffects.getBasicEffects(devices).get(0);
730-
for (Effect ef : effects)
731-
{
732-
basicEffectsPanel.addEffect(ef.getName());
733-
}
734-
}
735-
catch (StatusCodeException sce)
736-
{
737-
sce.printStackTrace();
738-
}
739740
getContentPane().add(basicEffectsPanel, "cell 0 1,grow");
740741

741742
regEffectsPanel = new EffectsPanel("Color Effects", this, devices, canvas);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.github.rowak.nanoleafdesktop.models;
2+
3+
public class BasicEffect
4+
{
5+
private String name;
6+
private int hue, sat;
7+
8+
public BasicEffect(String name, int hue, int sat)
9+
{
10+
this.name = name;
11+
this.hue = hue;
12+
this.sat = sat;
13+
}
14+
15+
public String getName()
16+
{
17+
return name;
18+
}
19+
20+
public void setName(String name)
21+
{
22+
this.name = name;
23+
}
24+
25+
public int getHue()
26+
{
27+
return hue;
28+
}
29+
30+
public void setHue(int hue)
31+
{
32+
this.hue = hue;
33+
}
34+
35+
public int getSaturation()
36+
{
37+
return sat;
38+
}
39+
40+
public void setSaturation(int sat)
41+
{
42+
this.sat = sat;
43+
}
44+
}

src/io/github/rowak/nanoleafdesktop/tools/BasicEffects.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.github.rowak.StatusCodeException.UnauthorizedException;
1515
import io.github.rowak.effectbuilder.StaticEffectBuilder;
1616
import io.github.rowak.nanoleafdesktop.Main;
17+
import io.github.rowak.nanoleafdesktop.models.BasicEffect;
1718

1819
public class BasicEffects
1920
{
@@ -150,6 +151,26 @@ public static List<List<Effect>> getBasicEffects(Aurora[] devices)
150151
return basicEffects;
151152
}
152153

154+
public static List<BasicEffect> getBasicEffects()
155+
{
156+
List<BasicEffect> basicEffects = new ArrayList<BasicEffect>();
157+
PropertyManager manager = new PropertyManager(Main.PROPERTIES_FILEPATH);
158+
String strEffects = manager.getProperty("basicEffects");
159+
if (strEffects != null)
160+
{
161+
JSONArray arr = new JSONArray(strEffects);
162+
for (int i = 0; i < arr.length(); i++)
163+
{
164+
JSONObject obj = arr.getJSONObject(i);
165+
String name = obj.getString("name");
166+
int hue = obj.getInt("hue");
167+
int sat = obj.getInt("sat");
168+
basicEffects.add(new BasicEffect(name, hue, sat));
169+
}
170+
}
171+
return basicEffects;
172+
}
173+
153174
private static Effect getEffect(String name, int hue, int sat, Aurora device)
154175
throws UnauthorizedException, StatusCodeException
155176
{

src/io/github/rowak/nanoleafdesktop/ui/panel/EffectsPanel.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.github.rowak.Effect;
1818
import io.github.rowak.StatusCodeException;
1919
import io.github.rowak.nanoleafdesktop.Main;
20+
import io.github.rowak.nanoleafdesktop.models.BasicEffect;
2021
import io.github.rowak.nanoleafdesktop.tools.BasicEffects;
2122
import io.github.rowak.nanoleafdesktop.tools.UIConstants;
2223
import io.github.rowak.nanoleafdesktop.ui.dialog.LoadingSpinner;
@@ -149,23 +150,20 @@ private void setBasicEffectForDevices(String effectName)
149150
{
150151
try
151152
{
152-
List<List<Effect>> basicEffects = BasicEffects.getBasicEffects(devices);
153-
int efIndex = -1;
154-
for (int i = 0; i < basicEffects.get(0).size(); i++)
153+
List<BasicEffect> basicEffects = BasicEffects.getBasicEffects();
154+
for (BasicEffect ef : basicEffects)
155155
{
156-
if (basicEffects.get(0).get(i).getName().equals(effectName))
156+
if (ef.getName().equals(effectName))
157157
{
158-
efIndex = i;
159-
}
160-
}
161-
if (efIndex != -1)
162-
{
163-
for (int i = 0; i < devices.length; i++)
164-
{
165-
devices[i].effects().displayEffect(basicEffects.get(i).get(efIndex));
158+
for (int i = 0; i < devices.length; i++)
159+
{
160+
devices[i].state().setHue(ef.getHue());
161+
devices[i].state().setSaturation(ef.getSaturation());
162+
}
163+
canvas.checkAuroraState();
164+
parent.loadStateComponents();
165+
break;
166166
}
167-
canvas.checkAuroraState();
168-
parent.loadStateComponents();
169167
}
170168
}
171169
catch (StatusCodeException sce)

0 commit comments

Comments
 (0)