Skip to content

Commit

Permalink
task assigning: show priority icon
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0ffrey committed Apr 28, 2016
1 parent 54aaca7 commit 7abe426
Show file tree
Hide file tree
Showing 8 changed files with 431 additions and 6 deletions.
Expand Up @@ -24,6 +24,7 @@
import java.util.Random;

import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
Expand Down
Expand Up @@ -36,8 +36,6 @@
import javax.swing.SwingConstants;

import org.optaplanner.examples.common.swingui.SolutionPanel;
import org.optaplanner.examples.pas.domain.RequiredPatientEquipment;
import org.optaplanner.examples.pas.domain.RoomEquipment;
import org.optaplanner.examples.taskassigning.domain.Employee;
import org.optaplanner.examples.taskassigning.domain.Skill;
import org.optaplanner.examples.taskassigning.domain.Task;
Expand All @@ -51,12 +49,19 @@ public class TaskOverviewPanel extends JPanel implements Scrollable {
public static final int ROW_HEIGHT = 40;
public static final int TIME_COLUMN_WIDTH = 60;

private final ImageIcon[] priorityIcons;

private TangoColorFactory customerColorFactory;
private TangoColorFactory skillColorFactory;

private int consumedDuration = 0;

public TaskOverviewPanel() {
priorityIcons = new ImageIcon[] {
new ImageIcon(getClass().getResource("priorityMinor.png")),
new ImageIcon(getClass().getResource("priorityMajor.png")),
new ImageIcon(getClass().getResource("priorityCritical.png"))
};
setLayout(null);
setMinimumSize(new Dimension(HEADER_COLUMN_WIDTH * 2, ROW_HEIGHT * 8));
}
Expand Down Expand Up @@ -193,12 +198,13 @@ private class TaskOrEmployeeIcon implements Icon {

private static final int SKILL_ICON_WIDTH = 8;
private static final int SKILL_ICON_HEIGHT = 16;
private static final int CUSTOMER_SKILL_GAP = 4;
private static final int CUSTOMER_ICON_WIDTH = 8;
private static final int CUSTOMER_ICON_HEIGHT = 16;
private static final int GAP = 4;

private final Color customerColor;
private final List<Color> skillColorList;
private final ImageIcon priorityIcon;

private TaskOrEmployeeIcon(Task task) {
customerColor = customerColorFactory.pickColor(task.getCustomer());
Expand All @@ -207,6 +213,7 @@ private TaskOrEmployeeIcon(Task task) {
for (Skill skill : skillList) {
skillColorList.add(skillColorFactory.pickColor(skill));
}
priorityIcon = priorityIcons[task.getPriority().ordinal()];
}

private TaskOrEmployeeIcon(Employee employee) {
Expand All @@ -216,16 +223,31 @@ private TaskOrEmployeeIcon(Employee employee) {
for (Skill skill : skillSet) {
skillColorList.add(skillColorFactory.pickColor(skill));
}
priorityIcon = null;
}

@Override
public int getIconWidth() {
return skillColorList.size() * SKILL_ICON_WIDTH + (customerColor == null ? 0 : CUSTOMER_ICON_WIDTH + CUSTOMER_SKILL_GAP);
int width = skillColorList.size() * SKILL_ICON_WIDTH;
if (customerColor != null) {
width += GAP + CUSTOMER_ICON_WIDTH;
}
if (priorityIcon != null) {
width += GAP + priorityIcon.getIconWidth();
}
return width;
}

@Override
public int getIconHeight() {
return Math.max(SKILL_ICON_HEIGHT, CUSTOMER_ICON_HEIGHT);
int height = SKILL_ICON_HEIGHT;
if (CUSTOMER_ICON_HEIGHT > height) {
height = CUSTOMER_ICON_HEIGHT;
}
if (priorityIcon != null && priorityIcon.getIconHeight() > height) {
height = priorityIcon.getIconHeight();
}
return height;
}

@Override
Expand All @@ -238,14 +260,19 @@ public void paintIcon(Component c, Graphics g, int x, int y) {
g.drawRect(innerX + 1, y + 1, SKILL_ICON_WIDTH - 2, SKILL_ICON_HEIGHT - 2);
innerX += SKILL_ICON_WIDTH;
}
innerX += CUSTOMER_SKILL_GAP;
if (customerColor != null) {
innerX += GAP;
g.setColor(customerColor);
g.fillOval(innerX + 1, y + 4, CUSTOMER_ICON_WIDTH - 2, CUSTOMER_ICON_HEIGHT - 8);
g.setColor(TangoColorFactory.ALUMINIUM_5);
g.drawOval(innerX + 1, y + 4, CUSTOMER_ICON_WIDTH - 2, CUSTOMER_ICON_HEIGHT - 8);
innerX += CUSTOMER_ICON_WIDTH;
}
if (priorityIcon != null) {
innerX += GAP;
priorityIcon.paintIcon(c, g, innerX, y);
innerX += priorityIcon.getIconWidth();
}
}

}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7abe426

Please sign in to comment.