001: /**
002: * Miroslav Popov, Jul 20, 2005
003: */package org.enhydra.jawe.components.graph;
004:
005: import java.awt.BorderLayout;
006: import java.awt.Font;
007: import java.awt.Rectangle;
008:
009: import javax.swing.Icon;
010: import javax.swing.JLabel;
011: import javax.swing.JPanel;
012: import javax.swing.JSplitPane;
013: import javax.swing.JTextArea;
014: import javax.swing.SwingConstants;
015:
016: /**
017: * Default panel for jawe object such as activity, route etc. It has icon and name.
018: *
019: * @author Miroslav Popov
020: */
021: public class DefaultCellPanel extends JPanel {
022:
023: // 0 - divLocation = icon space, divLocation - with = name space
024: protected int divLocation = 20;
025:
026: protected JSplitPane split;
027: protected JTextArea name = new JTextArea();
028: protected JLabel mainIcon = new JLabel();
029:
030: protected int orientation = 0;
031:
032: protected DefaultCellPanel() {
033: name.setText("-");
034: name.setOpaque(false);
035: mainIcon.setIcon(null);
036: mainIcon.setVerticalAlignment(SwingConstants.TOP);
037:
038: setOpaque(false);
039: setLayout(new BorderLayout());
040: split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mainIcon,
041: name);
042: split.setDividerLocation(divLocation);
043: split.setBorder(null);
044: split.setDividerSize(0);
045: split.setOpaque(false);
046:
047: add(split);
048: }
049:
050: public void showIcon(boolean show) {
051: mainIcon.setVisible(show);
052: }
053:
054: public Icon getMainIcon() {
055: return mainIcon.getIcon();
056: }
057:
058: public void setMainIcon(Icon mainIcon) {
059: this .mainIcon.setIcon(mainIcon);
060: }
061:
062: public String getDisplayName() {
063: return name.getText();
064: }
065:
066: public void setDisplayName(String name) {
067: this .name.setForeground(GraphUtilities.getGraphController()
068: .getGraphSettings().getTextColor());
069: this .name.setText(name);
070: }
071:
072: public void wrapName(boolean wrap) {
073: name.setLineWrap(wrap);
074: }
075:
076: public void wrapStyle(boolean word) {
077: name.setWrapStyleWord(word);
078: }
079:
080: public void setFont(Font font) {
081: if (name != null)
082: name.setFont(font);
083: }
084:
085: /**
086: * Set text and icon on panel depending on parameter place 1 - icon bottom, text up 2 - icon top,
087: * text bottom 3 - icon right, text left default - icon left, text right
088: *
089: * @param place
090: */
091: public void setTextPosition(int place) {
092: orientation = place;
093: arrangeSplit();
094: }
095:
096: public void arrangeSplit() {
097: remove(split);
098: switch (orientation) {
099: case 1:
100: split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, name,
101: mainIcon);
102: split.setDividerLocation(GraphUtilities
103: .getGraphController().getGraphSettings()
104: .getActivityHeight()
105: - divLocation);
106: break;
107: case 2:
108: split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, mainIcon,
109: name);
110: split.setDividerLocation(divLocation);
111: break;
112: case 3:
113: split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, name,
114: mainIcon);
115: split.setDividerLocation(GraphUtilities
116: .getGraphController().getGraphSettings()
117: .getActivityWidth()
118: - divLocation);
119: break;
120: default:
121: split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
122: mainIcon, name);
123: split.setDividerLocation(divLocation);
124: break;
125: }
126: split.setBorder(null);
127: split.setDividerSize(0);
128: split.setOpaque(false);
129: add(split);
130: }
131:
132: public void setBounds(Rectangle rect) {
133: super .setBounds(rect);
134: if (split != null) {
135: int iconSize = 0;
136:
137: switch (orientation) {
138: case GraphSettings.UP:
139: if (mainIcon.isVisible()) {
140: iconSize = mainIcon.getIcon().getIconWidth();
141: }
142:
143: name.setBounds(name.getX(), name.getY(), rect.width,
144: rect.height - iconSize - 3);
145: mainIcon.setLocation(0, rect.height - iconSize);
146: break;
147: case GraphSettings.DOWN:
148: if (mainIcon.isVisible()) {
149: iconSize = mainIcon.getIcon().getIconWidth();
150: }
151: name.setBounds(name.getX(), name.getY(), rect.width,
152: rect.height - iconSize - 3);
153: break;
154: case GraphSettings.LEFT:
155: if (mainIcon.isVisible()) {
156: iconSize = mainIcon.getIcon().getIconWidth();
157: }
158: name.setBounds(name.getX(), name.getY(), rect.width
159: - iconSize - 3, rect.height);
160: mainIcon.setLocation(rect.width - iconSize, 0);
161: break;
162: default:
163: if (mainIcon.isVisible()) {
164: iconSize = mainIcon.getIcon().getIconWidth();
165: }
166: name.setBounds(name.getX(), name.getY(), rect.width
167: - iconSize - 3, rect.height);
168: break;
169: }
170:
171: split.setBounds(rect);
172: }
173: }
174: }
|