Skip to content

Commit fb3a4de

Browse files
committed
New Render Type
Low Lag Update Support
1 parent ac6df4a commit fb3a4de

File tree

7 files changed

+115
-42
lines changed

7 files changed

+115
-42
lines changed

Core/src/main/java/net/projectbarks/stemclasses/DayFetcherCallback.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public void onFailed(String message, DayDataFetcher.FailCause exception) {
7777
}
7878

7979
private boolean cacheCheck(String cache) {
80+
cache += R.config.getColor().getRGB() + ":" + R.config.getRenderMode() + ":" + R.config.isAnimate();
8081
if (this.cache != null && this.cache.equals(cache)) {
8182
return true;
8283
}

Core/src/main/java/net/projectbarks/stemclasses/r/Config.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ public class Config {
3232

3333
@Getter
3434
@Setter
35-
private boolean outline = true, autoUpdate = true, animate = true;
35+
private boolean autoUpdate = true, animate = true;
3636
@Getter
3737
@Setter
3838
private Color color = Color.BLACK;
3939
@Getter
4040
@Setter
41-
private Integer grade = LetterDay.GRADE_9_10;
41+
private Integer grade = LetterDay.GRADE_9_10, renderMode = 0;
4242

4343
public void load(String path) {
4444
Properties props = new Properties();
@@ -52,7 +52,7 @@ public void load(String path) {
5252
e.printStackTrace();
5353
}
5454

55-
setOutline(Boolean.valueOf(props.getProperty("OUTLINE", Boolean.toString(outline))));
55+
setRenderMode(Integer.valueOf(props.getProperty("RENDERMODE", Integer.toString(renderMode))));
5656
setAutoUpdate(Boolean.valueOf(props.getProperty("AUTOUPDATE", Boolean.toString(autoUpdate))));
5757
setAnimate(Boolean.valueOf(props.getProperty("ANIMATE", Boolean.toString(animate))));
5858
setColor(new Color(new Integer(props.getProperty("COLOR", String.valueOf(color.getRGB())))));
@@ -61,7 +61,7 @@ public void load(String path) {
6161

6262
public void save(String path) {
6363
Properties props = new Properties();
64-
props.setProperty("OUTLINE", Boolean.toString(outline));
64+
props.setProperty("RENDERMODE", Integer.toString(renderMode));
6565
props.setProperty("AUTOUPDATE", Boolean.toString(autoUpdate));
6666
props.setProperty("ANIMATE", Boolean.toString(animate));
6767
props.setProperty("COLOR", String.valueOf(color.getRGB()));

Core/src/main/java/net/projectbarks/stemclasses/r/R.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.projectbarks.stemclasses.r.Render.BaseRenderer;
44
import net.projectbarks.stemclasses.r.Render.OutlineRenderer;
55
import net.projectbarks.stemclasses.r.Render.SolidRenderer;
6+
import net.projectbarks.stemclasses.r.Render.TextRenderer;
67

78
import java.awt.*;
89
import java.awt.geom.Rectangle2D;
@@ -32,14 +33,17 @@ public class R {
3233
static {
3334
try {
3435
draw = new BaseRenderer() {
35-
private final BaseRenderer outline = new OutlineRenderer(), solid = new SolidRenderer();
36+
private final BaseRenderer outline = new OutlineRenderer(), solid = new SolidRenderer(), letter = new TextRenderer();
3637

3738
@Override
3839
public Image drawIcon(String text, Color color, boolean animate, float percent) {
39-
if (config.isOutline()) {
40-
return outline.drawIcon(text, color, animate, percent);
41-
} else {
42-
return solid.drawIcon(text, color, animate, percent);
40+
switch (config.getRenderMode()) {
41+
case 1:
42+
return solid.drawIcon(text, color, animate, percent);
43+
case 2:
44+
return letter.drawIcon(text, color, animate, percent);
45+
default:
46+
return outline.drawIcon(text, color, animate, percent);
4347
}
4448
}
4549

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package net.projectbarks.stemclasses.r.Render;
2+
3+
import java.awt.*;
4+
import java.awt.geom.Area;
5+
import java.awt.geom.Rectangle2D;
6+
import java.io.IOException;
7+
8+
/**
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
* <p/>
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU General Public License for more details.
18+
* <p/>
19+
* You should have received a copy of the GNU General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
* <p/>
22+
* Written By: brandon on 1/26/15
23+
*/
24+
public class TextRenderer extends BaseRenderer {
25+
26+
private Rectangle2D cachedBounds;
27+
private Font cachedFont;
28+
29+
public TextRenderer() throws IOException, FontFormatException {
30+
super();
31+
cachedBounds = null;
32+
cachedFont = null;
33+
}
34+
35+
@Override
36+
protected void draw(Graphics2D g2d, Rectangle2D bounds, String text, Color color, float scale, boolean animate, float percent) {
37+
g2d.setFont(find(g2d, bounds));
38+
Area colored = generateCenteredText(area(bounds), text, g2d), grey = (Area) colored.clone();
39+
if (animate) {
40+
grey.subtract(area(new Rectangle2D.Float(0,
41+
(float) bounds.getHeight() - ((float)bounds.getHeight() * (1f - percent)),
42+
(float) bounds.getWidth(),
43+
(float) bounds.getHeight() * (1f - percent))));
44+
colored.subtract(grey);
45+
g2d.setColor(GRAY);
46+
g2d.fill(grey);
47+
}
48+
g2d.setColor(color);
49+
g2d.fill(colored);
50+
}
51+
52+
private Font find(Graphics2D g2d, Rectangle2D bounds) {
53+
if (cachedFont != null && cachedBounds != null && cachedBounds.equals(bounds)) {
54+
return cachedFont;
55+
}
56+
57+
float size = (float) bounds.getHeight();
58+
Boolean up = null;
59+
while (true) {
60+
cachedFont = customFont.deriveFont(Font.PLAIN, size);
61+
int testHeight = g2d.getFontMetrics(cachedFont).getHeight();
62+
if (testHeight < bounds.getHeight() && up != Boolean.FALSE) {
63+
size += .1;
64+
up = Boolean.TRUE;
65+
} else if (testHeight > bounds.getHeight() && up != Boolean.TRUE) {
66+
size -= .1;
67+
up = Boolean.FALSE;
68+
} else {
69+
break;
70+
}
71+
}
72+
return cachedFont;
73+
}
74+
}

Core/src/main/java/net/projectbarks/stemclasses/views/Preferences.form

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<properties/>
1717
<border type="none"/>
1818
<children>
19-
<grid id="6f591" layout-manager="GridLayoutManager" row-count="8" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
19+
<grid id="6f591" layout-manager="GridLayoutManager" row-count="7" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
2020
<margin top="0" left="0" bottom="0" right="0"/>
2121
<constraints>
2222
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -38,7 +38,7 @@
3838
</component>
3939
<component id="d3b6c" class="javax.swing.JLabel">
4040
<constraints>
41-
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
41+
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
4242
</constraints>
4343
<properties>
4444
<font style="1"/>
@@ -47,36 +47,20 @@
4747
</component>
4848
<vspacer id="acc44">
4949
<constraints>
50-
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
50+
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
5151
</constraints>
5252
</vspacer>
53-
<component id="74ecc" class="javax.swing.JRadioButton" binding="solidRadioButton" default-binding="true">
54-
<constraints>
55-
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
56-
</constraints>
57-
<properties>
58-
<text value="Solid"/>
59-
</properties>
60-
</component>
61-
<component id="a1cb0" class="javax.swing.JRadioButton" binding="outlineRadioButton" default-binding="true">
62-
<constraints>
63-
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
64-
</constraints>
65-
<properties>
66-
<text value="Outline"/>
67-
</properties>
68-
</component>
6953
<component id="e7f05" class="javax.swing.JRadioButton" binding="enabledRadioButton" default-binding="true">
7054
<constraints>
71-
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
55+
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
7256
</constraints>
7357
<properties>
7458
<text value="Enabled"/>
7559
</properties>
7660
</component>
7761
<component id="889eb" class="javax.swing.JRadioButton" binding="disabledRadioButton" default-binding="true">
7862
<constraints>
79-
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
63+
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
8064
<preferred-size width="87" height="23"/>
8165
</grid>
8266
</constraints>
@@ -86,7 +70,7 @@
8670
</component>
8771
<vspacer id="50ce4">
8872
<constraints>
89-
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
73+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
9074
</constraints>
9175
</vspacer>
9276
<component id="fe4a4" class="javax.swing.JLabel">
@@ -111,6 +95,18 @@
11195
<grid row="0" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
11296
</constraints>
11397
</hspacer>
98+
<component id="2a7e" class="javax.swing.JComboBox" binding="designMode">
99+
<constraints>
100+
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
101+
</constraints>
102+
<properties>
103+
<model>
104+
<item value="Outline"/>
105+
<item value="Solid"/>
106+
<item value="Text"/>
107+
</model>
108+
</properties>
109+
</component>
114110
</children>
115111
</grid>
116112
<grid id="bbda2" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

Core/src/main/java/net/projectbarks/stemclasses/views/Preferences.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
*/
2525
public class Preferences {
2626
private JPanel panel1;
27-
private JRadioButton solidRadioButton, outlineRadioButton, enabledRadioButton, disabledRadioButton;
27+
private JRadioButton enabledRadioButton, disabledRadioButton;
2828
private JButton applyButton, cancelButton;
2929
private JLabel color, timePreview, notPreview;
30+
private JComboBox designMode;
3031

3132
private int rotateValue;
3233
private boolean end;
@@ -49,7 +50,7 @@ public static void display() {
4950
}
5051

5152
public void init() {
52-
(R.config.isOutline() ? outlineRadioButton : solidRadioButton).setSelected(true);
53+
designMode.setSelectedIndex(R.config.getRenderMode());
5354
(R.config.isAnimate() ? enabledRadioButton : disabledRadioButton).setSelected(true);
5455
color.setForeground(R.config.getColor());
5556

@@ -58,7 +59,7 @@ public void init() {
5859
@Override
5960
public void actionPerformed(ActionEvent e) {
6061
R.config.setAnimate(enabledRadioButton.isSelected());
61-
R.config.setOutline(outlineRadioButton.isSelected());
62+
R.config.setRenderMode(designMode.getSelectedIndex());
6263
R.config.setColor(color.getForeground());
6364
frame.dispose();
6465
}
@@ -105,12 +106,9 @@ public void run() {
105106
}
106107
}.start();
107108

108-
onClickDisableOther(solidRadioButton, outlineRadioButton);
109-
onClickDisableOther(outlineRadioButton, solidRadioButton);
110109
onClickDisableOther(enabledRadioButton, disabledRadioButton);
111110
onClickDisableOther(disabledRadioButton, enabledRadioButton);
112-
onUpdate(solidRadioButton);
113-
onUpdate(outlineRadioButton);
111+
onUpdate(designMode);
114112
onUpdate(enabledRadioButton);
115113
onUpdate(disabledRadioButton);
116114
onUpdate(color);
@@ -137,13 +135,13 @@ public void mouseClicked(MouseEvent e) {
137135
}
138136

139137
private void update() {
140-
boolean outline = R.config.isOutline();
141-
R.config.setOutline(outlineRadioButton.isSelected());
138+
Integer mode = R.config.getRenderMode();
139+
R.config.setRenderMode(designMode.getSelectedIndex());
142140
timePreview.setIcon(new ImageIcon(R.draw.drawIcon("STEM", color.getForeground(),
143141
enabledRadioButton.isSelected(), 0)));
144142
notPreview.setIcon(new ImageIcon(R.draw.drawIcon(rotateValue + "", color.getForeground(),
145143
enabledRadioButton.isSelected(), (float) rotateValue / 55)));
146-
R.config.setOutline(outline);
144+
R.config.setRenderMode(mode);
147145
}
148146

149147
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>net.projectbarks.stemclasses</groupId>
88
<artifactId>STEMClasses</artifactId>
99
<packaging>pom</packaging>
10-
<version>0.8.1</version>
10+
<version>0.9.0</version>
1111

1212
<build>
1313
<finalName>${project.artifactId}</finalName>

0 commit comments

Comments
 (0)