pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/mil-lion/HelloJavaSE/commit/79c4a14d6b98cd3bea3f3a3a92d7399d7d457a8c

href="https://github.githubassets.com/assets/global-d18f184ea1a06a2c.css" /> Добавлен адаптер XML для класса java.awt.Color в список аттрибутов: r… · mil-lion/HelloJavaSE@79c4a14 · GitHub
Skip to content

Commit 79c4a14

Browse files
committed
Добавлен адаптер XML для класса java.awt.Color в список аттрибутов: red,green, blue
1 parent de230ee commit 79c4a14

3 files changed

Lines changed: 137 additions & 2 deletions

File tree

src/main/java/ru/lionsoft/javase/hello/gui/shapes/AbstractShape.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
1616
import ru.lionsoft.javase.hello.gui.ShapeDraw;
1717
import ru.lionsoft.javase.hello.json.ColorJsonAdapter;
18-
import ru.lionsoft.javase.hello.xml.jaxb.ColorXmlAdapter;
18+
import ru.lionsoft.javase.hello.xml.jaxb.ColorTextXmlAdapter;
1919

2020
/**
2121
* Абстрактный класс с общими свойствами всех фигур
@@ -56,7 +56,7 @@ public AbstractShape(Color color, int x, int y) {
5656
* @return the value of color
5757
*/
5858
// @XmlAttribute
59-
@XmlJavaTypeAdapter(ColorXmlAdapter.class)
59+
@XmlJavaTypeAdapter(ColorTextXmlAdapter.class)
6060
@JsonbTypeAdapter(ColorJsonAdapter.class)
6161
public Color getColor() {
6262
return color;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* File: ColorRgbXmlAdapter.java
3+
* Project: HelloJavaSE
4+
* Date: 3 июн. 2020 г. 15:22:19
5+
* Author: Igor Morenko <morenko at lionsoft.ru>
6+
*
7+
* Copyright 2005-2020 LionSoft LLC. All rights reserved.
8+
*/
9+
package ru.lionsoft.javase.hello.xml.jaxb;
10+
11+
import java.awt.Color;
12+
import javax.xml.bind.annotation.XmlAccessType;
13+
import javax.xml.bind.annotation.XmlAccessorType;
14+
import javax.xml.bind.annotation.XmlAttribute;
15+
import javax.xml.bind.annotation.adapters.XmlAdapter;
16+
17+
/**
18+
*
19+
* @author Igor Morenko <morenko at lionsoft.ru>
20+
*/
21+
public class ColorRgbXmlAdapter extends XmlAdapter<ColorRgbXmlAdapter.ColorValueType, Color> {
22+
23+
@Override
24+
public Color unmarshal(ColorValueType vt) throws Exception {
25+
return new Color(vt.red, vt.green, vt.blue);
26+
}
27+
28+
@Override
29+
public ColorValueType marshal(Color bt) throws Exception {
30+
return new ColorValueType(bt.getRed(), bt.getGreen(), bt.getBlue());
31+
}
32+
33+
@XmlAccessorType(XmlAccessType.FIELD)
34+
public static class ColorValueType {
35+
36+
@XmlAttribute
37+
public int red;
38+
39+
@XmlAttribute
40+
public int green;
41+
42+
@XmlAttribute
43+
public int blue;
44+
45+
public ColorValueType() {
46+
}
47+
48+
public ColorValueType(int red, int green, int blue) {
49+
this.red = red;
50+
this.green = green;
51+
this.blue = blue;
52+
}
53+
54+
55+
}
56+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* File: ColorTextXmlAdapter.java
3+
* Project: HelloJavaSE
4+
* Date: 5 дек. 2018 г. 21:20:21
5+
* Author: Igor Morenko <morenko at lionsoft.ru>
6+
*
7+
* Copyright 2005-2018 LionSoft LLC. All rights reserved.
8+
*/
9+
package ru.lionsoft.javase.hello.xml.jaxb;
10+
11+
import java.awt.Color;
12+
import javax.xml.bind.annotation.adapters.XmlAdapter;
13+
14+
/**
15+
*
16+
* @author Igor Morenko <morenko at lionsoft.ru>
17+
*/
18+
public class ColorTextXmlAdapter extends XmlAdapter<String, Color> {
19+
20+
private static final String BLACK = "black";
21+
private static final String BLUE = "blue";
22+
private static final String CYAN = "cyan";
23+
private static final String DARK_GRAY = "darkGray";
24+
private static final String GRAY = "gray";
25+
private static final String GREEN = "green";
26+
private static final String LIGHT_GRAY = "lightGray";
27+
private static final String MAGENTA = "magenta";
28+
private static final String ORANGE = "orange";
29+
private static final String PINK = "pink";
30+
private static final String RED = "red";
31+
private static final String WHITE = "white";
32+
private static final String YELLOW = "yellow";
33+
34+
@Override
35+
public Color unmarshal(String vt) throws Exception {
36+
if (vt.startsWith("#")) {
37+
// Decode Hex Color
38+
int rgb = Integer.parseUnsignedInt(vt.substring(1), 16);
39+
return new Color(rgb);
40+
}
41+
switch (vt) {
42+
case BLACK: return Color.BLACK;
43+
case BLUE: return Color.BLUE;
44+
case CYAN: return Color.CYAN;
45+
case DARK_GRAY: return Color.DARK_GRAY;
46+
case GRAY: return Color.GRAY;
47+
case GREEN: return Color.GREEN;
48+
case LIGHT_GRAY: return Color.LIGHT_GRAY;
49+
case MAGENTA: return Color.MAGENTA;
50+
case ORANGE: return Color.ORANGE;
51+
case PINK: return Color.PINK;
52+
case RED: return Color.RED;
53+
case WHITE: return Color.WHITE;
54+
case YELLOW: return Color.YELLOW;
55+
}
56+
57+
return Color.BLACK;
58+
}
59+
60+
@Override
61+
public String marshal(Color bt) throws Exception {
62+
if (bt.equals(Color.BLACK)) return BLACK;
63+
if (bt.equals(Color.BLUE)) return BLUE;
64+
if (bt.equals(Color.CYAN)) return CYAN;
65+
if (bt.equals(Color.DARK_GRAY)) return DARK_GRAY;
66+
if (bt.equals(Color.GRAY)) return GRAY;
67+
if (bt.equals(Color.GREEN)) return GREEN;
68+
if (bt.equals(Color.LIGHT_GRAY)) return LIGHT_GRAY;
69+
if (bt.equals(Color.MAGENTA)) return MAGENTA;
70+
if (bt.equals(Color.ORANGE)) return ORANGE;
71+
if (bt.equals(Color.PINK)) return PINK;
72+
if (bt.equals(Color.RED)) return RED;
73+
if (bt.equals(Color.WHITE)) return WHITE;
74+
if (bt.equals(Color.YELLOW)) return YELLOW;
75+
// Alpha, Red, Green, Blue
76+
return String.format("#%08X", bt.getRGB());
77+
}
78+
79+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy