-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved Tray and TrayManger to tray subpackage.
- Loading branch information
Showing
7 changed files
with
180 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
208 changes: 104 additions & 104 deletions
208
tomighty-swing/src/main/java/org/tomighty/resources/TrayIcons.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,104 @@ | ||
/* | ||
* Copyright (c) 2010-2012 Célio Cidral Junior. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.tomighty.resources; | ||
|
||
import java.awt.Dimension; | ||
import java.awt.Font; | ||
import java.awt.Image; | ||
|
||
import org.tomighty.resources.cache.Cache; | ||
import org.tomighty.resources.cache.Caches; | ||
import org.tomighty.resources.cache.Icons; | ||
import org.tomighty.time.Time; | ||
import org.tomighty.ui.Tray; | ||
import org.tomighty.ui.theme.Colors; | ||
import org.tomighty.ui.theme.Look; | ||
import org.tomighty.ui.util.Canvas; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class TrayIcons { | ||
|
||
public static final int DEFAULT_ICON_SIZE = 32; | ||
|
||
private Resources resources; | ||
private Tray tray; | ||
private Look look; | ||
private Caches caches; | ||
|
||
@Inject | ||
public void setResources(Resources resources) { | ||
this.resources = resources; | ||
} | ||
|
||
@Inject | ||
public void setTray(Tray tray) { | ||
this.tray = tray; | ||
} | ||
|
||
@Inject | ||
public void setLook(Look look) { | ||
this.look = look; | ||
} | ||
|
||
@Inject | ||
public void setCaches(Caches caches) { | ||
this.caches = caches; | ||
} | ||
|
||
public Image tomato() { | ||
int size = tray.iconSize().height; | ||
Image image = tomato(size); | ||
if (image == null) { | ||
image = tomato(DEFAULT_ICON_SIZE); | ||
} | ||
return image; | ||
} | ||
|
||
public Image time(Time time) { | ||
String iconName = iconNameFor(time); | ||
Cache cache = caches.of(Icons.class); | ||
if (cache.contains(iconName)) { | ||
return cache.get(iconName); | ||
} | ||
|
||
Dimension size = tray.iconSize(); | ||
Colors colors = look.colors(); | ||
Canvas canvas = new Canvas(size); | ||
canvas.fontSize((float) size.height * 0.58f); | ||
canvas.paintGradient(colors.background()); | ||
canvas.drawBorder(colors.background().darker().darker().darker()); | ||
canvas.drawCentralizedText(time.shortestString()); | ||
|
||
cache.store(canvas.image(), iconName); | ||
|
||
return canvas.image(); | ||
} | ||
|
||
private String iconNameFor(Time time) { | ||
Font font = Canvas.defaultFont(); | ||
Dimension size = tray.iconSize(); | ||
String colorName = look.colors().getClass().getSimpleName(); | ||
return font.getFontName() + "_" + size.width + "x" + size.height + "_" | ||
+ colorName + "_" + time.shortestString(); | ||
} | ||
|
||
private Image tomato(int size) { | ||
return resources.image("/tomato-" + size + ".png"); | ||
} | ||
|
||
} | ||
/* | ||
* Copyright (c) 2010-2012 Célio Cidral Junior. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.tomighty.resources; | ||
|
||
import java.awt.Dimension; | ||
import java.awt.Font; | ||
import java.awt.Image; | ||
|
||
import org.tomighty.resources.cache.Cache; | ||
import org.tomighty.resources.cache.Caches; | ||
import org.tomighty.resources.cache.Icons; | ||
import org.tomighty.time.Time; | ||
import org.tomighty.ui.tray.Tray; | ||
import org.tomighty.ui.theme.Colors; | ||
import org.tomighty.ui.theme.Look; | ||
import org.tomighty.ui.util.Canvas; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class TrayIcons { | ||
|
||
public static final int DEFAULT_ICON_SIZE = 32; | ||
|
||
private Resources resources; | ||
private Tray tray; | ||
private Look look; | ||
private Caches caches; | ||
|
||
@Inject | ||
public void setResources(Resources resources) { | ||
this.resources = resources; | ||
} | ||
|
||
@Inject | ||
public void setTray(Tray tray) { | ||
this.tray = tray; | ||
} | ||
|
||
@Inject | ||
public void setLook(Look look) { | ||
this.look = look; | ||
} | ||
|
||
@Inject | ||
public void setCaches(Caches caches) { | ||
this.caches = caches; | ||
} | ||
|
||
public Image tomato() { | ||
int size = tray.iconSize().height; | ||
Image image = tomato(size); | ||
if (image == null) { | ||
image = tomato(DEFAULT_ICON_SIZE); | ||
} | ||
return image; | ||
} | ||
|
||
public Image time(Time time) { | ||
String iconName = iconNameFor(time); | ||
Cache cache = caches.of(Icons.class); | ||
if (cache.contains(iconName)) { | ||
return cache.get(iconName); | ||
} | ||
|
||
Dimension size = tray.iconSize(); | ||
Colors colors = look.colors(); | ||
Canvas canvas = new Canvas(size); | ||
canvas.fontSize((float) size.height * 0.58f); | ||
canvas.paintGradient(colors.background()); | ||
canvas.drawBorder(colors.background().darker().darker().darker()); | ||
canvas.drawCentralizedText(time.shortestString()); | ||
|
||
cache.store(canvas.image(), iconName); | ||
|
||
return canvas.image(); | ||
} | ||
|
||
private String iconNameFor(Time time) { | ||
Font font = Canvas.defaultFont(); | ||
Dimension size = tray.iconSize(); | ||
String colorName = look.colors().getClass().getSimpleName(); | ||
return font.getFontName() + "_" + size.width + "x" + size.height + "_" | ||
+ colorName + "_" + time.shortestString(); | ||
} | ||
|
||
private Image tomato(int size) { | ||
return resources.image("/tomato-" + size + ".png"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 71 additions & 71 deletions
142
tomighty-swing/src/test/java/org/tomighty/resources/TrayIconsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
/* | ||
* Copyright (c) 2010-2012 Célio Cidral Junior. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.tomighty.resources; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.tomighty.ui.Tray; | ||
|
||
import java.awt.*; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class TrayIconsTest { | ||
|
||
private static final int TRAY_ICON_SIZE = 10; | ||
|
||
private TrayIcons trayIcons; | ||
private Tray tray; | ||
private Resources resources; | ||
|
||
@Before | ||
public void setUp() { | ||
tray = mock(Tray.class); | ||
resources = mock(Resources.class); | ||
trayIcons = new TrayIcons(); | ||
|
||
trayIcons.setTray(tray); | ||
trayIcons.setResources(resources); | ||
|
||
Dimension trayIconSize = new Dimension(TRAY_ICON_SIZE, TRAY_ICON_SIZE); | ||
when(tray.iconSize()).thenReturn(trayIconSize); | ||
} | ||
|
||
@Test | ||
public void testTomato() { | ||
Image expectedIcon = mock(Image.class); | ||
when(resources.image(resourceName(TRAY_ICON_SIZE))).thenReturn(expectedIcon); | ||
Image icon = trayIcons.tomato(); | ||
assertThat(icon, equalTo(expectedIcon)); | ||
} | ||
|
||
@Test | ||
public void testDefaultTomatoIcon() { | ||
Image defaultIcon = mock(Image.class); | ||
when(resources.image(resourceName(TrayIcons.DEFAULT_ICON_SIZE))).thenReturn(defaultIcon); | ||
Image icon = trayIcons.tomato(); | ||
assertThat(icon, equalTo(defaultIcon)); | ||
} | ||
|
||
private String resourceName(int iconSize) { | ||
return "/tomato-" + iconSize + ".png"; | ||
} | ||
|
||
} | ||
/* | ||
* Copyright (c) 2010-2012 Célio Cidral Junior. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.tomighty.resources; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.tomighty.ui.tray.Tray; | ||
|
||
import java.awt.*; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class TrayIconsTest { | ||
|
||
private static final int TRAY_ICON_SIZE = 10; | ||
|
||
private TrayIcons trayIcons; | ||
private Tray tray; | ||
private Resources resources; | ||
|
||
@Before | ||
public void setUp() { | ||
tray = mock(Tray.class); | ||
resources = mock(Resources.class); | ||
trayIcons = new TrayIcons(); | ||
|
||
trayIcons.setTray(tray); | ||
trayIcons.setResources(resources); | ||
|
||
Dimension trayIconSize = new Dimension(TRAY_ICON_SIZE, TRAY_ICON_SIZE); | ||
when(tray.iconSize()).thenReturn(trayIconSize); | ||
} | ||
|
||
@Test | ||
public void testTomato() { | ||
Image expectedIcon = mock(Image.class); | ||
when(resources.image(resourceName(TRAY_ICON_SIZE))).thenReturn(expectedIcon); | ||
Image icon = trayIcons.tomato(); | ||
assertThat(icon, equalTo(expectedIcon)); | ||
} | ||
|
||
@Test | ||
public void testDefaultTomatoIcon() { | ||
Image defaultIcon = mock(Image.class); | ||
when(resources.image(resourceName(TrayIcons.DEFAULT_ICON_SIZE))).thenReturn(defaultIcon); | ||
Image icon = trayIcons.tomato(); | ||
assertThat(icon, equalTo(defaultIcon)); | ||
} | ||
|
||
private String resourceName(int iconSize) { | ||
return "/tomato-" + iconSize + ".png"; | ||
} | ||
|
||
} |