Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
StatusKey.java
1 
17 package net.squiz.matrix.ui;
18 
19 import javax.swing.*;
20 import java.awt.*;
21 import java.awt.image.*;
22 import javax.swing.border.*;
23 import net.squiz.matrix.core.*;
24 
30 public class StatusKey extends JPanel implements MatrixConstants {
31 
32  public static final int KEY_SIZE = 15;
33  public static final Color KEY_BORDER = new Color(0xCCCCCC);
34  public static final Font keyFont = new Font("key_font", Font.PLAIN, 10);
35  public static final Dimension fillerSize = new Dimension(1, 1);
36 
40  public StatusKey() {
41  createKey();
42  setBackground(Color.white);
43  setBorder(new EmptyBorder(3, 3, 3, 3));
44  setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
45  setMinimumSize(new Dimension(0,0));
46  setMaximumSize(new Dimension(0,200));
47  setPreferredSize(new Dimension(0,200));
48  }
49 
53  private void createKey() {
54  add(createColourKey(ARCHIVED_COLOUR, "Archived"));
55  add(createColourKey(UNDER_CONSTRUCTION_COLOUR, "Under Construction"));
56  add(createColourKey(PENDING_APPROVAL_COLOUR, "Pending Approval"));
57  add(createColourKey(APPROVED_COLOUR, "Approved"));
58  add(createColourKey(LIVE_COLOUR, "Live"));
59  add(createColourKey(LIVE_APPROVAL_COLOUR, "Up For Review"));
60  add(createColourKey(EDITING_COLOUR, "Safe Editing"));
61  add(createColourKey(EDITING_APPROVAL_COLOUR, "Safe Edit Pending Approval"));
62  add(createColourKey(EDITING_APPROVED_COLOUR, "Safe Edit Approved"));
63  }
64 
65  private JLabel createColourKey(Color c, String labelText) {
66  JLabel label = new JLabel(labelText);
67  label.setIcon(createIcon(c));
68  label.setFont(keyFont);
69 
70  add(new Box.Filler(fillerSize, fillerSize, fillerSize));
71 
72  return label;
73  }
74 
75  private Icon createIcon(Color c) {
76 
77  BufferedImage image = new BufferedImage(KEY_SIZE, KEY_SIZE, BufferedImage.TYPE_INT_RGB);
78  Graphics g = image.createGraphics();
79 
80  g.setColor(c);
81  g.fillRect(0, 0, KEY_SIZE, KEY_SIZE);
82  g.setColor(c.darker());
83  g.drawRect(0, 0, KEY_SIZE - 1, KEY_SIZE - 1);
84  g.dispose();
85  ImageIcon icon = new ImageIcon(image);
86 
87  return icon;
88  }
89 }