Example usage for java.awt Label Label

List of usage examples for java.awt Label Label

Introduction

In this page you can find the example usage for java.awt Label Label.

Prototype

public Label() throws HeadlessException 

Source Link

Document

Constructs an empty label.

Usage

From source file:ru.jcorp.smartstreets.gui.map.MapEditor.java

public MapEditor() {
    super(true);/*from  w w  w . ja  v a2 s . c o m*/

    setBorder(new LineBorder(Color.BLACK));
    setLayout(new BorderLayout());

    loadImages();

    graphModel = new DirectedSparseGraph<GraphNode, GraphLink>();

    graphLayout = new StaticLayout<GraphNode, GraphLink>(graphModel);
    graphView = new VisualizationViewer<GraphNode, GraphLink>(graphLayout);

    NodesFactory nodesFactory = new NodesFactory(this);
    LinesFactory linesFactory = new LinesFactory();

    final RenderContext<GraphNode, GraphLink> renderContext = graphView.getRenderContext();

    graphMouse = new EditingModalGraphMouse<GraphNode, GraphLink>(renderContext, nodesFactory, linesFactory) {

        @Override
        protected void loadPlugins() {
            pickingPlugin = new PickingGraphMousePlugin<GraphNode, GraphLink>();
            animatedPickingPlugin = new AnimatedPickingGraphMousePlugin<GraphNode, GraphLink>();
            translatingPlugin = new TranslatingGraphMousePlugin(InputEvent.BUTTON1_MASK);
            scalingPlugin = new ScalingGraphMousePlugin(new CrossoverScalingControl(), 0, in, out);
            rotatingPlugin = new RotatingGraphMousePlugin();
            shearingPlugin = new ShearingGraphMousePlugin();
            labelEditingPlugin = new LabelEditingGraphMousePlugin<GraphNode, GraphLink>();
            annotatingPlugin = new AnnotatingGraphMousePlugin<GraphNode, GraphLink>(rc);

            popupEditingPlugin = new GraphPopupMousePlugin(MapEditor.this, vertexFactory, edgeFactory);
            editingPlugin = new GraphEditMousePlugin(MapEditor.this, vertexFactory, edgeFactory);

            add(scalingPlugin);
            setMode(Mode.EDITING);
        }
    };
    graphMouse.setMode(ModalGraphMouse.Mode.EDITING);
    graphView.setGraphMouse(graphMouse);

    renderContext.setVertexLabelTransformer(new NodesLabeler());
    renderContext.setEdgeLabelTransformer(new LinesLabeler());

    renderContext.setVertexIconTransformer(new Transformer<GraphNode, Icon>() {
        @Override
        public Icon transform(GraphNode graphNode) {
            SmartMapNode node = graphNode.getMapNode();
            if (sourceNode == node)
                return sourceMarker;
            if (destNode == node)
                return destMarker;
            TrafficLight trafficLight = graphNode.getMapNode().getTrafficLight();
            Policeman policeman = graphNode.getMapNode().getPoliceman();
            boolean hasLighter = trafficLight != null && trafficLight.getGreenDuration() != null
                    && trafficLight.getGreenDuration() > 0 && trafficLight.getRedDuration() != null
                    && trafficLight.getGreenDuration() > 0;
            boolean hasPoliceman = policeman != null;

            if (hasPoliceman && hasLighter)
                return lightPolicemanMarker;

            if (hasPoliceman)
                return policeMarker;

            if (hasLighter)
                return lightMarker;

            return null;
        }
    });

    renderContext.setEdgeShapeTransformer(new AbstractEdgeShapeTransformer<GraphNode, GraphLink>() {

        private GeneralPath instance = new GeneralPath();

        @Override
        public Shape transform(Context<Graph<GraphNode, GraphLink>, GraphLink> graphGraphLinkContext) {
            instance.reset();
            instance.moveTo(0.0f, 5.0f);
            instance.lineTo(1.0f, 5.0f);
            return instance;
        }
    });
    graphView.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR);

    final Transformer<GraphLink, Paint> defaultEdgePainter = graphView.getRenderContext()
            .getEdgeDrawPaintTransformer();
    Transformer<GraphLink, Paint> linkDrawer = new Transformer<GraphLink, Paint>() {
        private final Color PATH_COLOR = new Color(0x0C9E0C);

        @Override
        public Paint transform(GraphLink graphLink) {
            if (path != null) {
                SmartMapLine line = graphLink.getMapLine();
                SmartMapNode startNode = line.getStartNode();
                SmartMapNode endNode = line.getEndNode();

                int startNodeIndex = path.indexOf(startNode);
                int endNodeIndex = path.indexOf(endNode);

                if (startNodeIndex >= 0 && endNodeIndex >= 0 && Math.abs(endNodeIndex - startNodeIndex) == 1) {
                    if (graphLink.isCoDirectional() && (startNodeIndex > endNodeIndex))
                        return PATH_COLOR;
                    if (!graphLink.isCoDirectional() && (startNodeIndex < endNodeIndex))
                        return PATH_COLOR;
                }
            }
            RoadSign sign = graphLink.getRoadSign();
            if (sign != null && sign.getRuleType() == RuleType.JOURNEY_IS_FORBIDDEN) {
                return Color.WHITE;
            }
            return defaultEdgePainter.transform(graphLink);
        }
    };
    graphView.getRenderContext().setEdgeDrawPaintTransformer(linkDrawer);
    graphView.getRenderContext().setArrowDrawPaintTransformer(linkDrawer);
    graphView.getRenderContext().setArrowFillPaintTransformer(linkDrawer);

    graphView.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            graphView.repaint();
        }
    });

    GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(graphView);

    this.add(scrollPane, BorderLayout.CENTER);

    valueLabel = new Label();
    this.add(valueLabel, BorderLayout.SOUTH);
}