Skip to content

Commit

Permalink
Moved Tray and TrayManger to tray subpackage.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccidral committed May 13, 2012
1 parent c7552f8 commit d13a01d
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 182 deletions.
2 changes: 1 addition & 1 deletion tomighty-swing/src/main/java/org/tomighty/Tomighty.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.tomighty.config.Options;
import org.tomighty.inject.TomightyModule;
import org.tomighty.plugin.PluginManager;
import org.tomighty.ui.TrayManager;
import org.tomighty.ui.tray.TrayManager;
import org.tomighty.ui.UiState;
import org.tomighty.ui.Window;
import org.tomighty.ui.state.InitialState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.tomighty.sound.Sounds;
import org.tomighty.time.DefaultTimer;
import org.tomighty.time.Timer;
import org.tomighty.ui.Tray;
import org.tomighty.ui.TrayManager;
import org.tomighty.ui.tray.Tray;
import org.tomighty.ui.tray.TrayManager;
import org.tomighty.ui.Window;
import org.tomighty.ui.swing.gauge.Gauge;
import org.tomighty.ui.theme.Look;
Expand Down
208 changes: 104 additions & 104 deletions tomighty-swing/src/main/java/org/tomighty/resources/TrayIcons.java
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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import java.awt.Dimension;
import java.awt.SystemTray;

import org.tomighty.ui.Tray;

public class AwtTray implements Tray {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.tomighty.ui;
package org.tomighty.ui.tray;

import java.awt.Dimension;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package org.tomighty.ui;
package org.tomighty.ui.tray;

import org.tomighty.bus.Bus;
import org.tomighty.bus.Subscriber;
Expand Down
142 changes: 71 additions & 71 deletions tomighty-swing/src/test/java/org/tomighty/resources/TrayIconsTest.java
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";
}

}

0 comments on commit d13a01d

Please sign in to comment.