001: package com.vividsolutions.jump.workbench.ui.cursortool;
002:
003: import java.awt.*;
004: import java.awt.geom.Point2D;
005:
006: import javax.swing.*;
007: import javax.swing.JLabel;
008: import javax.swing.JTextArea;
009:
010: import com.vividsolutions.jts.util.Assert;
011: import com.vividsolutions.jump.feature.*;
012: import com.vividsolutions.jump.workbench.model.Layer;
013: import com.vividsolutions.jump.workbench.ui.Viewport;
014: import com.vividsolutions.jump.workbench.ui.renderer.style.Style;
015:
016: public class NoteStyle implements Style {
017:
018: public static final int WIDTH = 80;
019: public static final int HEIGHT = 30;
020: public static final String NAME = "Notes";
021: public static final String CREATED = "CREATED";
022: public static final String MODIFIED = "MODIFIED";
023: public static final String TEXT = "TEXT";
024: public static final String GEOMETRY = "GEOMETRY";
025:
026: private JTextArea myTextArea = createTextArea();
027:
028: private Layer layer;
029:
030: public static FeatureSchema createFeatureSchema() {
031: return new FeatureSchema() {
032: {
033: addAttribute(CREATED, AttributeType.DATE);
034: addAttribute(MODIFIED, AttributeType.DATE);
035: addAttribute(TEXT, AttributeType.STRING);
036: addAttribute(GEOMETRY, AttributeType.GEOMETRY);
037: }
038: };
039: }
040:
041: public static JTextArea createTextArea() {
042: return new JTextArea() {
043:
044: {
045: setFont(new JLabel().getFont());
046: setLineWrap(true);
047: setWrapStyleWord(true);
048: setBorder(BorderFactory
049: .createLineBorder(Color.lightGray));
050: }
051: };
052: }
053:
054: public void paint(Feature f, Graphics2D g, Viewport viewport)
055: throws Exception {
056: paint(f, viewport.toViewPoint(f.getGeometry().getCoordinate()),
057: g);
058: }
059:
060: private void paint(Feature f, Point2D location, Graphics2D g) {
061: myTextArea.setText(f.getString(TEXT));
062: int ht = myTextArea.getPreferredSize().height;
063: int wt = myTextArea.getPreferredSize().width;
064: if (ht < HEIGHT)
065: ht = HEIGHT;
066: if (wt < WIDTH)
067: wt = WIDTH;
068: myTextArea.setBounds(0, 0, wt, ht);
069: //myTextArea.setBounds(0, 0, WIDTH, HEIGHT);
070: Composite originalComposite = g.getComposite();
071: g.translate(location.getX(), location.getY());
072: try {
073: g.setComposite(AlphaComposite.getInstance(
074: AlphaComposite.SRC_OVER, layer.getBasicStyle()
075: .getAlpha() / 255f));
076: myTextArea.paint(g);
077: } finally {
078: g.setComposite(originalComposite);
079: g.translate(-location.getX(), -location.getY());
080: }
081: }
082:
083: public void initialize(Layer layer) {
084: this .layer = layer;
085: myTextArea.setBackground(layer.getBasicStyle().getFillColor());
086: }
087:
088: public Object clone() {
089: try {
090: return super .clone();
091: } catch (CloneNotSupportedException e) {
092: Assert.shouldNeverReachHere();
093: return null;
094: }
095: }
096:
097: public void setEnabled(boolean enabled) {
098: throw new UnsupportedOperationException();
099: }
100:
101: public boolean isEnabled() {
102: return true;
103: }
104:
105: }
|