001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package com.artenum.so6.dataflow.graph.ui;
034:
035: import com.artenum.so6.dataflow.StyleManager;
036: import com.artenum.so6.dataflow.graph.SynchronizerNode;
037:
038: import java.awt.BorderLayout;
039: import java.awt.Dimension;
040: import java.awt.Point;
041: import java.awt.Rectangle;
042:
043: import javax.swing.BorderFactory;
044: import javax.swing.JLabel;
045: import javax.swing.JPanel;
046:
047: /**
048: * @author seb
049: */
050: public class SynchronizerUI extends JPanel {
051: public final double CONNECTOR_WIDTH = 21;
052: private Dimension totalSize;
053: private int nbConnections = 10;
054: private SynchronizerNode syncNode;
055: private Point[] connectionPoints;
056: private ElectricalConnectorLine north;
057: private JLabel content;
058: private ElectricalConnectorLine south;
059:
060: public SynchronizerUI(SynchronizerNode node) {
061: super (new BorderLayout());
062: this .syncNode = node;
063:
064: // set ui
065: setBackground(StyleManager.getInstance().getBGColor());
066: content = new JLabel(node.getText());
067: content.setOpaque(true);
068: content.setHorizontalAlignment(JLabel.CENTER);
069:
070: //content.setToolTipText(node.getName());
071: content.setBackground(StyleManager.getInstance()
072: .getSynchronizerBGColor());
073: content.setForeground(StyleManager.getInstance()
074: .getSynchronizerFGColor());
075: content.setBorder(BorderFactory.createLineBorder(StyleManager
076: .getInstance().getSynchronizerBorderColor(), 4));
077:
078: //System.out.println(nbConnections);
079: north = new ElectricalConnectorLine(nbConnections);
080: south = new ElectricalConnectorLine(nbConnections);
081:
082: //
083: add(BorderLayout.PAGE_START, north);
084: add(BorderLayout.CENTER, content);
085: add(BorderLayout.PAGE_END, south);
086:
087: //
088: computeNbConnection();
089: doLayout();
090: validate();
091: }
092:
093: public Dimension getPreferredSize() {
094: totalSize = content.getPreferredSize();
095:
096: int width = (int) Math.max(north.getPreferredSize().getWidth(),
097: totalSize.getWidth());
098: totalSize.width = width;
099: totalSize.height += 10;
100:
101: return totalSize;
102: }
103:
104: public Point[] getConnectionPointArray() {
105: Point[] result = new Point[nbConnections * 2];
106: Rectangle bounds = getBounds();
107: double step = totalSize.getWidth() / nbConnections;
108: result[0] = bounds.getLocation();
109: result[0].x += ((step * 3) / 4);
110: result[nbConnections] = bounds.getLocation();
111: result[nbConnections].x += ((step * 3) / 4);
112: result[nbConnections].y += bounds.getHeight();
113:
114: for (int i = 1; i < nbConnections; i++) {
115: result[i] = (Point) result[i - 1].clone();
116: result[i].x += step;
117: result[i + nbConnections] = (Point) result[i - 1
118: + nbConnections].clone();
119: result[i + nbConnections].x += step;
120: }
121:
122: connectionPoints = result;
123:
124: return connectionPoints;
125: }
126:
127: private void computeNbConnection() {
128: nbConnections = Math.max(
129: (syncNode.getConnections().size() + 2) / 2, content
130: .getText().length() / 2);
131: north.setNbConnection(nbConnections);
132: south.setNbConnection(nbConnections);
133: setSize(getPreferredSize());
134: }
135: }
|