| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | public class DefaultColorTable implements ColorTableMapping |
| | | { |
| | | public class DefaultColorTable implements ColorTableMapping { |
| | | private static DefaultColorTable _instance = null; |
| | | |
| | | public static ColorTableMapping getInstance() |
| | | { |
| | | if (_instance == null) |
| | | { |
| | | public static ColorTableMapping getInstance() { |
| | | if (_instance == null) { |
| | | _instance = new DefaultColorTable(); |
| | | } |
| | | |
| | |
| | | |
| | | private ArrayList<Color> colortable = null; |
| | | |
| | | private DefaultColorTable() |
| | | { |
| | | private DefaultColorTable() { |
| | | initializeColorTable(); |
| | | } |
| | | |
| | | private void initializeColorTable() |
| | | { |
| | | if (colortable != null) |
| | | { |
| | | private void initializeColorTable() { |
| | | if (colortable != null) { |
| | | return; |
| | | } |
| | | |
| | |
| | | colortable.add(254, new Color(30, 52, 0)); |
| | | } |
| | | |
| | | public List findId(Color color) |
| | | { |
| | | public List findId(Color color) { |
| | | ArrayList<Integer> codelist = new ArrayList<Integer>(); |
| | | for (int i = 0; i < colortable.size(); i++) |
| | | { |
| | | for (int i = 0; i < colortable.size(); i++) { |
| | | Color colorDef = colortable.get(i); |
| | | if (colorDef.equals(color)) |
| | | { |
| | | if (colorDef.equals(color)) { |
| | | codelist.add(i); |
| | | } |
| | | } |
| | | return codelist; |
| | | } |
| | | |
| | | public Color getColor(int i) |
| | | { |
| | | public Color getColor(int i) { |
| | | return colortable.get(i); |
| | | } |
| | | |
| | | public String getColorCode(int i) |
| | | { |
| | | public String getColorCode(int i) { |
| | | Color color = colortable.get(i); |
| | | if (!color.equals(Color.WHITE)) |
| | | return colorToString(colortable.get(i)); |
| | | return colorToString(Color.GRAY); |
| | | } |
| | | |
| | | public boolean contain(Color color) |
| | | { |
| | | for (Color colorDef : colortable) |
| | | { |
| | | if (colorDef.equals(color)) |
| | | { |
| | | public boolean contain(Color color) { |
| | | for (Color colorDef : colortable) { |
| | | if (colorDef.equals(color)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private static String colorToString(Color c) |
| | | { |
| | | private static String colorToString(Color c) { |
| | | char[] buf = new char[7]; |
| | | buf[0] = '#'; |
| | | String s = Integer.toHexString(c.getRed()); |
| | | if (s.length() == 1) |
| | | { |
| | | if (s.length() == 1) { |
| | | buf[1] = '0'; |
| | | buf[2] = s.charAt(0); |
| | | } else |
| | | { |
| | | } else { |
| | | buf[1] = s.charAt(0); |
| | | buf[2] = s.charAt(1); |
| | | } |
| | | s = Integer.toHexString(c.getGreen()); |
| | | if (s.length() == 1) |
| | | { |
| | | if (s.length() == 1) { |
| | | buf[3] = '0'; |
| | | buf[4] = s.charAt(0); |
| | | } else |
| | | { |
| | | } else { |
| | | buf[3] = s.charAt(0); |
| | | buf[4] = s.charAt(1); |
| | | } |
| | | s = Integer.toHexString(c.getBlue()); |
| | | if (s.length() == 1) |
| | | { |
| | | if (s.length() == 1) { |
| | | buf[5] = '0'; |
| | | buf[6] = s.charAt(0); |
| | | } else |
| | | { |
| | | } else { |
| | | buf[5] = s.charAt(0); |
| | | buf[6] = s.charAt(1); |
| | | } |