use of java.awt.Color in project fastjson by alibaba.
the class ColorSerializerTest method test_rgb.
public void test_rgb() throws Exception {
JSONSerializer serializer = new JSONSerializer();
Assert.assertEquals(AwtCodec.class, serializer.getObjectWriter(Color.class).getClass());
VO vo = new VO();
vo.setValue(new Color(1, 1, 1, 0));
Assert.assertEquals("{\"value\":{\"r\":1,\"g\":1,\"b\":1}}", JSON.toJSONString(vo, SerializerFeature.WriteMapNullValue));
}
use of java.awt.Color in project Openfire by igniterealtime.
the class BeanUtils method decode.
/**
* Decodes a String into an object of the specified type. If the object
* type is not supported, null will be returned.
*
* @param type the type of the property.
* @param value the encode String value to decode.
* @return the String value decoded into the specified type.
* @throws Exception
*/
private static Object decode(Class type, String value) throws Exception {
if (type.getName().equals("java.lang.String")) {
return value;
}
if (type.getName().equals("boolean")) {
return Boolean.valueOf(value);
}
if (type.getName().equals("int")) {
return Integer.valueOf(value);
}
if (type.getName().equals("long")) {
return Long.valueOf(value);
}
if (type.getName().equals("float")) {
return Float.valueOf(value);
}
if (type.getName().equals("double")) {
return Double.valueOf(value);
}
if (type.getName().equals("java.util.Date")) {
try {
return dateFormatter.parse(value);
} catch (Exception ignored) {
// Ignore.
}
}
if (type.getName().equals("java.awt.Color")) {
StringTokenizer tokens = new StringTokenizer(value, ",");
int red = Integer.parseInt(tokens.nextToken());
int green = Integer.parseInt(tokens.nextToken());
int blue = Integer.parseInt(tokens.nextToken());
return new Color(red, green, blue);
}
if (type.getName().equals("java.lang.Class")) {
return ClassUtils.forName(value);
}
return null;
}
use of java.awt.Color in project Smack by igniterealtime.
the class EnhancedDebugger method addAdhocPacketPanel.
private void addAdhocPacketPanel() {
// Create UI elements for sending ad-hoc messages.
final JTextArea adhocMessages = new JTextArea();
adhocMessages.setEditable(true);
adhocMessages.setForeground(new Color(1, 94, 35));
tabbedPane.add("Ad-hoc message", new JScrollPane(adhocMessages));
tabbedPane.setToolTipTextAt(3, "Panel that allows you to send adhoc packets");
// Add pop-up menu.
JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Message");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<message to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"><body></body></message>");
}
});
menu.add(menuItem);
menuItem = new JMenuItem("IQ Get");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<iq type=\"get\" to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"><query xmlns=\"\"></query></iq>");
}
});
menu.add(menuItem);
menuItem = new JMenuItem("IQ Set");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<iq type=\"set\" to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"><query xmlns=\"\"></query></iq>");
}
});
menu.add(menuItem);
menuItem = new JMenuItem("Presence");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<presence to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"/>");
}
});
menu.add(menuItem);
menu.addSeparator();
menuItem = new JMenuItem("Send");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!"".equals(adhocMessages.getText())) {
AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText());
try {
connection.sendStanza(packetToSend);
} catch (InterruptedException | NotConnectedException e1) {
LOGGER.log(Level.WARNING, "exception", e);
}
}
}
});
menu.add(menuItem);
menuItem = new JMenuItem("Clear");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText(null);
}
});
menu.add(menuItem);
// Add listener to the text area so the popup menu can come up.
adhocMessages.addMouseListener(new PopupListener(menu));
}
use of java.awt.Color in project Openfire by igniterealtime.
the class ConversationUtils method buildPDFContent.
private ByteArrayOutputStream buildPDFContent(Conversation conversation, Map<String, Font> colorMap) {
Font roomEvent = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.ITALIC, new Color(0xFF, 0x00, 0xFF));
try {
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
writer.setPageEvent(new PDFEventListener());
document.open();
Paragraph p = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.title", MonitoringConstants.NAME), FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD));
document.add(p);
document.add(Chunk.NEWLINE);
ConversationInfo coninfo = new ConversationUtils().getConversationInfo(conversation.getConversationID(), false);
String participantsDetail;
if (coninfo.getAllParticipants() == null) {
participantsDetail = coninfo.getParticipant1() + ", " + coninfo.getParticipant2();
} else {
participantsDetail = String.valueOf(coninfo.getAllParticipants().length);
}
Paragraph chapterTitle = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.participants", MonitoringConstants.NAME) + " " + participantsDetail, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
document.add(chapterTitle);
Paragraph startDate = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.startdate", MonitoringConstants.NAME) + " " + coninfo.getDate(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
document.add(startDate);
Paragraph duration = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.duration", MonitoringConstants.NAME) + " " + coninfo.getDuration(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
document.add(duration);
Paragraph messageCount = new Paragraph(LocaleUtils.getLocalizedString("archive.search.pdf.messagecount", MonitoringConstants.NAME) + " " + conversation.getMessageCount(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD));
document.add(messageCount);
document.add(Chunk.NEWLINE);
Paragraph messageParagraph;
for (ArchivedMessage message : conversation.getMessages()) {
String time = JiveGlobals.formatTime(message.getSentDate());
String from = message.getFromJID().getNode();
if (conversation.getRoom() != null) {
from = message.getToJID().getResource();
}
String body = message.getBody();
String prefix;
if (!message.isRoomEvent()) {
prefix = "[" + time + "] " + from + ": ";
Font font = colorMap.get(message.getFromJID().toString());
if (font == null) {
font = colorMap.get(message.getFromJID().toBareJID());
}
if (font == null) {
font = FontFactory.getFont(FontFactory.HELVETICA, 12f, Font.BOLD, Color.BLACK);
}
messageParagraph = new Paragraph(new Chunk(prefix, font));
} else {
prefix = "[" + time + "] ";
messageParagraph = new Paragraph(new Chunk(prefix, roomEvent));
}
messageParagraph.add(body);
messageParagraph.add(" ");
document.add(messageParagraph);
}
document.close();
return baos;
} catch (DocumentException e) {
Log.error("error creating PDF document: " + e.getMessage(), e);
return null;
}
}
use of java.awt.Color in project OpenNotebook by jaltekruse.
the class ColorAttribute method clone.
@Override
public MathObjectAttribute clone() {
ColorAttribute newColor;
newColor = new ColorAttribute(getName());
if (getValue() != null) {
newColor.setValue(new Color(getValue().getRed(), getValue().getGreen(), getValue().getBlue()));
}
copyRootManagedFields(newColor);
return newColor;
}
Aggregations