001: /*
002: * $Id: JGraphpadHeavyweightRenderer.java,v 1.4 2006/08/10 08:59:57 gaudenz Exp $
003: * Copyright (c) 2001-2005, Gaudenz Alder
004: *
005: * All rights reserved.
006: *
007: * This file is licensed under the JGraph software license, a copy of which
008: * will have been provided to you in the file LICENSE at the root of your
009: * installation directory. If you are unable to locate this file please
010: * contact JGraph sales for another copy.
011: */
012: package com.jgraph.pad.graph;
013:
014: import java.awt.Color;
015: import java.awt.Component;
016: import java.awt.Graphics;
017: import java.awt.GridBagConstraints;
018: import java.awt.GridBagLayout;
019:
020: import javax.swing.JButton;
021: import javax.swing.JCheckBox;
022: import javax.swing.JComboBox;
023: import javax.swing.JLabel;
024: import javax.swing.JPanel;
025: import javax.swing.JScrollPane;
026: import javax.swing.JSpinner;
027: import javax.swing.JTextField;
028: import javax.swing.JToggleButton;
029: import javax.swing.border.LineBorder;
030:
031: import org.jgraph.JGraph;
032:
033: public class JGraphpadHeavyweightRenderer extends JPanel implements
034: Cloneable {
035:
036: protected JTextField text = new JTextField(10);
037:
038: protected JCheckBox checkbox = new JCheckBox("Check");
039:
040: protected JSpinner spinner = new JSpinner();
041:
042: protected JComboBox combo = new JComboBox(new Object[] { "Red",
043: "Green", "Blue" });
044:
045: protected JToggleButton toggle = new JToggleButton("Toggle");
046:
047: public JGraphpadHeavyweightRenderer() {
048: super (new GridBagLayout());
049: setBorder(new ScaledLineBorder(Color.BLACK, 1));
050: GridBagConstraints c = new GridBagConstraints();
051: c.anchor = GridBagConstraints.NORTHWEST;
052: c.fill = GridBagConstraints.BOTH;
053: c.ipadx = 4;
054: c.ipady = 2;
055: c.weighty = 0.0;
056: c.weightx = 1.0;
057: c.gridwidth = 1;
058: c.gridheight = 1;
059: c.gridx = 0;
060:
061: c.ipady = 4;
062: c.gridy = 0;
063: c.gridx = 0;
064: c.weightx = 0.3;
065: JLabel label = new JLabel("Text:");
066: add(label, c);
067:
068: c.gridy = 0;
069: c.gridx = 1;
070: c.weightx = 0.7;
071: c.gridwidth = 2;
072: add(text, c);
073:
074: c.gridy = 1;
075: c.gridx = 0;
076: c.gridwidth = 3;
077: c.weighty = 1.0;
078: c.weightx = 1.0;
079: JGraph graph = new JGraph();
080: JScrollPane scrollPane = new JScrollPane(graph);
081: add(scrollPane, c);
082:
083: c.weighty = 0.0;
084: c.gridy = 2;
085: c.gridx = 0;
086: c.gridwidth = 1;
087: checkbox.setOpaque(false);
088: add(checkbox, c);
089:
090: c.gridx = 1;
091: c.gridwidth = 2;
092: combo.setOpaque(false);
093: add(combo, c);
094:
095: c.gridwidth = 1;
096: c.gridy = 3;
097: c.gridx = 0;
098: spinner.setOpaque(false);
099: add(spinner, c);
100:
101: c.gridx = 1;
102: JButton button = new JButton("Button");
103: button.setOpaque(false);
104: add(button, c);
105:
106: c.gridx = 2;
107: toggle.setOpaque(false);
108: add(toggle, c);
109: }
110:
111: /**
112: * Workaround for the line border in Swing that has bad offsets and
113: * asymetric line widths when zoomed.
114: */
115: public class ScaledLineBorder extends LineBorder {
116:
117: public ScaledLineBorder(Color color) {
118: this (color, 1);
119: }
120:
121: public ScaledLineBorder(Color color, int thickness) {
122: super (color, thickness + 2, false);
123: }
124:
125: public void paintBorder(Component c, Graphics g, int x, int y,
126: int width, int height) {
127: Color oldColor = g.getColor();
128: int i;
129:
130: g.setColor(lineColor);
131: int thickness = this .thickness - 2;
132: for (i = 0; i < thickness; i++) {
133: g.drawRect(x + i + 1, y + i + 1, width - i - i - 2,
134: height - i - i - 2);
135: }
136: g.setColor(oldColor);
137: }
138:
139: }
140:
141: public Object clone() {
142: JGraphpadHeavyweightRenderer clone = new JGraphpadHeavyweightRenderer();
143: clone.checkbox.setSelected(checkbox.isSelected());
144: clone.text.setText(text.getText());
145: clone.spinner.setValue(spinner.getValue());
146: clone.combo.setSelectedIndex(combo.getSelectedIndex());
147: clone.toggle.setSelected(toggle.isSelected());
148: return clone;
149: }
150:
151: }
|