-
-
-
-01 /*
-02 * Copyright 2010-2012 Pinaki Poddar
-03 *
-04 *
-05 * Licensed under the Apache License, Version 2.0 (the "License");
-06 * you may not use this file except in compliance with the License.
-07 * You may obtain a copy of the License at
-08 *
-09 * http://www.apache.org/licenses/LICENSE-2.0
-10 *
-11 * Unless required by applicable law or agreed to in writing, software
-12 * distributed under the License is distributed on an "AS IS" BASIS,
-13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-14 * See the License for the specific language governing permissions and
-15 * limitations under the License.
-16 */
-17 package jpa.tools.swing;
-18
-19 import java.awt.Color;
-20 import java.awt.GridLayout;
-21 import java.awt.image.BufferedImage;
-22
-23 import javax.persistence.metamodel.Attribute;
-24 import javax.swing.BorderFactory;
-25 import javax.swing.ImageIcon;
-26 import javax.swing.JComponent;
-27 import javax.swing.JLabel;
-28 import javax.swing.JPanel;
-29
-30 /**
-31 * Displays color codes of each attribute type.
-32 *
-33 * @author Pinaki Poddar
-34 *
-35 */
-36 @SuppressWarnings("serial")
-37 public class AttributeLegendView extends JPanel {
-38
-39 public AttributeLegendView() {
-40 super(true);
-41 setBorder(BorderFactory.createTitledBorder("Attribute Legends"));
-42 setLayout(new GridLayout(0,3));
-43 add(createColoredLabel("IDENTITY", Color.RED));
-44 add(createColoredLabel("VERSION", Color.DARK_GRAY));
-45 for (Attribute.PersistentAttributeType type : Attribute.PersistentAttributeType.values()) {
-46 add(createColoredLabel(type.toString().replace('_', ' '), MetamodelHelper.getColor(type)));
-47 }
-48 }
-49
-50 JComponent createColoredLabel(String text, Color c) {
-51 int width = 40;
-52 int height = 20;
-53 BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
-54 for (int i = 0; i < width; i++)
-55 for (int j = 0; j < height; j++)
-56 bimage.setRGB(i, j, c.getRGB());
-57 JLabel label = new JLabel(text, new ImageIcon(bimage), JLabel.LEADING);
-58 return label;
-59 }
-60
-61 }
-
- |
-
-
-