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.ActionManager;
036: import com.artenum.so6.dataflow.StyleManager;
037: import com.artenum.so6.dataflow.graph.ConnectionNode;
038:
039: import java.awt.BorderLayout;
040: import java.awt.GridLayout;
041: import java.awt.Point;
042: import java.awt.event.MouseEvent;
043: import java.awt.event.MouseListener;
044:
045: import javax.swing.BorderFactory;
046: import javax.swing.Box;
047: import javax.swing.JComponent;
048: import javax.swing.JLabel;
049: import javax.swing.JPanel;
050:
051: /**
052: * @author Sebastien
053: */
054: public class ConnectionUI extends JPanel implements MouseListener {
055: private ConnectionNode node;
056: private JLabel nbTickets;
057: private JPanel update;
058: private JPanel commit;
059: private JLabel updateL;
060: private JLabel commitL;
061: private Point upPoint = null;
062: private Point downPoint = null;
063: private boolean init = false;
064:
065: public ConnectionUI(ConnectionNode node) {
066: super (new BorderLayout());
067: this .node = node;
068:
069: nbTickets = new JLabel(node.getText());
070: nbTickets.setHorizontalAlignment(JLabel.CENTER);
071: nbTickets.setToolTipText(node.getName());
072: nbTickets.setBackground(StyleManager.getInstance()
073: .getConnectionBGColor());
074: nbTickets.setForeground(StyleManager.getInstance()
075: .getConnectionFGColor());
076: nbTickets.setBorder(BorderFactory.createLineBorder(StyleManager
077: .getInstance().getConnectionBorderColor(), 4));
078: nbTickets.setOpaque(true);
079:
080: commit = new JPanel(new GridLayout(1, 3));
081: commit.setBackground(StyleManager.getInstance().getBGColor());
082: commitL = new JLabel("c");
083: commitL.setHorizontalAlignment(JLabel.CENTER);
084: commitL.setBackground(StyleManager.getInstance()
085: .getElectricalConnectorColor());
086: commitL.setOpaque(true);
087:
088: if (node.canMakeAction()) {
089: commitL.addMouseListener(this );
090: }
091:
092: commit.add(Box.createGlue());
093: commit.add(commitL);
094: commit.add(Box.createGlue());
095:
096: update = new JPanel(new GridLayout(1, 3));
097: update.setBackground(StyleManager.getInstance().getBGColor());
098: updateL = new JLabel("u");
099: updateL.setHorizontalAlignment(JLabel.CENTER);
100: updateL.setBackground(StyleManager.getInstance()
101: .getElectricalConnectorColor());
102: updateL.setOpaque(true);
103:
104: if (node.canMakeAction()) {
105: updateL.addMouseListener(this );
106: }
107:
108: update.add(Box.createGlue());
109: update.add(updateL);
110: update.add(Box.createGlue());
111:
112: add(BorderLayout.NORTH, update);
113: add(BorderLayout.CENTER, nbTickets);
114: add(BorderLayout.SOUTH, commit);
115: }
116:
117: private void updateConnectionPoints() {
118: Point p = getLocation();
119: p.x += (getWidth() / 2);
120: upPoint = (Point) p.clone();
121: p.y += getHeight();
122: downPoint = (Point) p.clone();
123: }
124:
125: public void updateCompomentPosition(boolean isSynchronizerAbove) {
126: if (isSynchronizerAbove) {
127: remove(update);
128: remove(commit);
129: add(BorderLayout.SOUTH, update);
130: add(BorderLayout.NORTH, commit);
131: } else {
132: remove(update);
133: remove(commit);
134: add(BorderLayout.NORTH, update);
135: add(BorderLayout.SOUTH, commit);
136: }
137:
138: validate();
139: }
140:
141: public Point getCommitPoint() {
142: updateConnectionPoints();
143:
144: if (commit.getBounds().getLocation().y == 0) {
145: return upPoint;
146: }
147:
148: return downPoint;
149: }
150:
151: public Point getUpdatePoint() {
152: updateConnectionPoints();
153:
154: if (update.getBounds().getLocation().y == 0) {
155: return upPoint;
156: }
157:
158: return downPoint;
159: }
160:
161: public void initActions() {
162: if (!init) {
163: if (node.canMakeAction()) {
164: commitL.setText(node.isUpToDate() ? "c" : " ");
165: updateL.setText(node.isUpToDate() ? " " : "u");
166: } else {
167: commitL.setText(" ");
168: updateL.setText(" ");
169: }
170: }
171: }
172:
173: public void mouseClicked(MouseEvent me) {
174: // Update/Commit/Nothing
175: String action = ((JLabel) me.getComponent()).getText();
176:
177: if (action.equals("u")) {
178: // update
179: ActionManager.getInstance()
180: .update(
181: node.getExternalProperties().getProperty(
182: "WscPath"));
183: } else if (action.equals("c")) {
184: // commit
185: ActionManager.getInstance()
186: .commit(
187: node.getExternalProperties().getProperty(
188: "WscPath"));
189: }
190: }
191:
192: public void mouseEntered(MouseEvent me) {
193: ((JComponent) me.getComponent()).setBackground(StyleManager
194: .getInstance().getElectricalConnectorColor().darker());
195: }
196:
197: public void mouseExited(MouseEvent me) {
198: ((JComponent) me.getComponent()).setBackground(StyleManager
199: .getInstance().getElectricalConnectorColor());
200: }
201:
202: public void mousePressed(MouseEvent me) {
203: }
204:
205: public void mouseReleased(MouseEvent me) {
206: }
207: }
|