001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: StructureEditor.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.gui.old;
009:
010: import javax.swing.*;
011:
012: import com.uwyn.rife.config.Config;
013: import com.uwyn.rife.swing.Images;
014: import com.uwyn.rife.swing.JBorderlessButton;
015: import com.uwyn.rife.swing.JBorderlessToggleButton;
016: import com.uwyn.rife.tools.Localization;
017: import java.awt.BorderLayout;
018: import java.awt.GridBagConstraints;
019: import java.awt.GridBagLayout;
020: import java.awt.Insets;
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023: import java.awt.event.MouseEvent;
024: import java.awt.event.MouseListener;
025:
026: public class StructureEditor extends JPanel implements ActionListener,
027: MouseListener {
028: private JScrollPane mScrollPane = null;
029:
030: private JBorderlessButton mStructurePanelPanButton = null;
031: private StructurePanelPanWindow mStructurePanelPanWindow = null;
032:
033: private JPanel mStructureToolbar = null;
034: private ButtonGroup mStructureToolbarButtonGroup = null;
035: private JBorderlessToggleButton mStructureToolbarSelectionButton = null;
036: private JBorderlessToggleButton mStructureToolbarZoomButton = null;
037: private JBorderlessToggleButton mStructureToolbarElementButton = null;
038: private JBorderlessToggleButton mStructureToolbarConnectorButton = null;
039: private JBorderlessToggleButton mStructureToolbarGridShowButton = null;
040: private JBorderlessToggleButton mStructureToolbarGridSnapButton = null;
041: private StructurePanel mStructurePanel = null;
042:
043: public StructureEditor() {
044: super ();
045:
046: mStructureToolbarButtonGroup = new ButtonGroup();
047: mStructureToolbarSelectionButton = new JBorderlessToggleButton(
048: Images.getRepInstance().getImageIcon(
049: "buttons/selection.gif"));
050: mStructureToolbarSelectionButton.setBorder(null);
051: mStructureToolbarSelectionButton.setSelected(true);
052: mStructureToolbarSelectionButton.addActionListener(this );
053: mStructureToolbarSelectionButton.setToolTipText(Localization
054: .getString("rife.tooltip.tool.selection"));
055: mStructureToolbarButtonGroup
056: .add(mStructureToolbarSelectionButton);
057: mStructureToolbarZoomButton = new JBorderlessToggleButton(
058: Images.getRepInstance()
059: .getImageIcon("buttons/zoom.gif"));
060: mStructureToolbarZoomButton.setBorder(null);
061: mStructureToolbarZoomButton.addActionListener(this );
062: mStructureToolbarZoomButton.addMouseListener(this );
063: mStructureToolbarZoomButton.setToolTipText(Localization
064: .getString("rife.tooltip.tool.zoom"));
065: mStructureToolbarButtonGroup.add(mStructureToolbarZoomButton);
066: mStructureToolbarElementButton = new JBorderlessToggleButton(
067: Images.getRepInstance().getImageIcon(
068: "buttons/element.gif"));
069: mStructureToolbarElementButton.setBorder(null);
070: mStructureToolbarElementButton.addActionListener(this );
071: mStructureToolbarElementButton.setToolTipText(Localization
072: .getString("rife.tooltip.tool.element"));
073: mStructureToolbarButtonGroup
074: .add(mStructureToolbarElementButton);
075: mStructureToolbarConnectorButton = new JBorderlessToggleButton(
076: Images.getRepInstance().getImageIcon(
077: "buttons/connector.gif"));
078: mStructureToolbarConnectorButton.setBorder(null);
079: mStructureToolbarConnectorButton.addActionListener(this );
080: mStructureToolbarConnectorButton.setToolTipText(Localization
081: .getString("rife.tooltip.tool.connector"));
082: mStructureToolbarButtonGroup
083: .add(mStructureToolbarConnectorButton);
084: mStructureToolbarGridShowButton = new JBorderlessToggleButton(
085: Images.getRepInstance().getImageIcon(
086: "buttons/gridshow.gif"));
087: mStructureToolbarGridShowButton.setBorder(null);
088: mStructureToolbarGridShowButton.addActionListener(this );
089: mStructureToolbarGridShowButton.setToolTipText(Localization
090: .getString("rife.tooltip.tool.gridshow"));
091: mStructureToolbarGridShowButton.setSelected(Config
092: .getRepInstance().getBool("GRID_SHOW"));
093: mStructureToolbarGridSnapButton = new JBorderlessToggleButton(
094: Images.getRepInstance().getImageIcon(
095: "buttons/gridsnap.gif"));
096: mStructureToolbarGridSnapButton.setBorder(null);
097: mStructureToolbarGridSnapButton.addActionListener(this );
098: mStructureToolbarGridSnapButton.setToolTipText(Localization
099: .getString("rife.tooltip.tool.gridsnap"));
100: mStructureToolbarGridSnapButton.setSelected(Config
101: .getRepInstance().getBool("GRID_SNAP"));
102:
103: mStructureToolbar = new JPanel();
104: mStructureToolbar.setLayout(new GridBagLayout());
105: mStructureToolbar.setBorder(BorderFactory.createEmptyBorder(5,
106: 5, 5, 5));
107:
108: GridBagConstraints constraints = new GridBagConstraints();
109: constraints.gridx = 0;
110: constraints.gridy = 0;
111: constraints.gridwidth = 1;
112: constraints.gridheight = 1;
113: constraints.weightx = 1;
114: constraints.weighty = 0;
115: constraints.anchor = GridBagConstraints.NORTH;
116: constraints.fill = GridBagConstraints.BOTH;
117: constraints.insets = new Insets(0, 0, 0, 0);
118: mStructureToolbar.add(mStructureToolbarSelectionButton,
119: constraints);
120: constraints.gridy = 1;
121: mStructureToolbar.add(
122: new JSeparator(SwingConstants.HORIZONTAL), constraints);
123: constraints.gridy = 2;
124: mStructureToolbar.add(mStructureToolbarZoomButton, constraints);
125: constraints.gridy = 3;
126: mStructureToolbar.add(
127: new JSeparator(SwingConstants.HORIZONTAL), constraints);
128: constraints.gridy = 4;
129: mStructureToolbar.add(mStructureToolbarElementButton,
130: constraints);
131: constraints.gridy = 5;
132: mStructureToolbar.add(mStructureToolbarConnectorButton,
133: constraints);
134: constraints.gridy = 6;
135: mStructureToolbar.add(
136: new JSeparator(SwingConstants.HORIZONTAL), constraints);
137: constraints.gridy = 7;
138: mStructureToolbar.add(mStructureToolbarGridShowButton,
139: constraints);
140: constraints.gridy = 8;
141: constraints.insets = new Insets(1, 0, 0, 0);
142: mStructureToolbar.add(mStructureToolbarGridSnapButton,
143: constraints);
144: constraints.gridy = 9;
145: constraints.weighty = 1;
146: constraints.insets = new Insets(0, 0, 0, 0);
147: mStructureToolbar.add(new JPanel(), constraints);
148:
149: mScrollPane = new JScrollPane();
150: mScrollPane
151: .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
152: mScrollPane
153: .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
154: mStructurePanelPanButton = new JBorderlessButton(Images
155: .getRepInstance().getImageIcon("buttons/pan.gif"));
156: mStructurePanelPanButton.setDefaultCapable(false);
157: mStructurePanelPanButton.setBorder(null);
158: mStructurePanelPanButton.addMouseListener(this );
159: mStructurePanelPanButton.setToolTipText(Localization
160: .getString("rife.tooltip.tool.pan"));
161: mScrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER,
162: mStructurePanelPanButton);
163:
164: mStructurePanel = new StructurePanel(mScrollPane);
165: mStructurePanel.setVisible(true);
166:
167: mScrollPane.setViewportView(mStructurePanel);
168: mScrollPane.setVisible(true);
169: mScrollPane.getViewport().setScrollMode(
170: JViewport.BLIT_SCROLL_MODE);
171:
172: mStructureToolbar.setVisible(true);
173:
174: setLayout(new BorderLayout());
175: add(mStructureToolbar, BorderLayout.WEST);
176: add(mScrollPane, BorderLayout.CENTER);
177:
178: for (int i = 1; i <= 5; i++) {
179: mStructurePanel.addElement("test_element_" + i);
180: }
181: }
182:
183: public StructurePanel getStructurePanel() {
184: return mStructurePanel;
185: }
186:
187: public void actionPerformed(ActionEvent e) {
188: Object source = e.getSource();
189:
190: if (source == mStructureToolbarSelectionButton) {
191: mStructurePanel
192: .setActiveTool(StructurePanel.SELECTION_TOOL);
193: } else if (source == mStructureToolbarZoomButton) {
194: mStructurePanel.setActiveTool(StructurePanel.ZOOMIN_TOOL);
195: } else if (source == mStructureToolbarElementButton) {
196: mStructurePanel.setActiveTool(StructurePanel.ELEMENT_TOOL);
197: } else if (source == mStructureToolbarConnectorButton) {
198: mStructurePanel
199: .setActiveTool(StructurePanel.CONNECTOR_TOOL);
200: } else if (source == mStructureToolbarGridShowButton) {
201: Config.getRepInstance().setParameter("GRID_SHOW",
202: "" + mStructureToolbarGridShowButton.isSelected());
203: mStructurePanel.repaint();
204: } else if (source == mStructureToolbarGridSnapButton) {
205: Config.getRepInstance().setParameter("GRID_SNAP",
206: "" + mStructureToolbarGridSnapButton.isSelected());
207: }
208: }
209:
210: public void mouseClicked(MouseEvent e) {
211: Object source = e.getSource();
212:
213: if (source == mStructureToolbarZoomButton) {
214: if (e.getClickCount() == 2) {
215: mStructurePanel.changeZoom(1 / mStructurePanel
216: .getScaleFactor());
217: }
218: }
219: }
220:
221: public void mousePressed(MouseEvent e) {
222: Object source = e.getSource();
223:
224: if (source == mStructurePanelPanButton
225: && ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0)) {
226: mStructurePanel.setScrollActive(true);
227: mStructurePanel.repaint();
228:
229: mStructurePanelPanWindow = new StructurePanelPanWindow(
230: mStructurePanel, mStructurePanelPanButton, e
231: .getPoint());
232: mStructurePanelPanButton
233: .addMouseMotionListener(mStructurePanelPanWindow);
234: }
235: }
236:
237: public void mouseReleased(MouseEvent e) {
238: Object source = e.getSource();
239:
240: if (source == mStructurePanelPanButton
241: && ((e.getModifiers() & MouseEvent.BUTTON1_MASK) != 0)) {
242: mStructurePanelPanButton
243: .removeMouseMotionListener(mStructurePanelPanWindow);
244:
245: mStructurePanelPanWindow.setVisible(false);
246: mStructurePanelPanWindow.dispose();
247: mStructurePanelPanWindow = null;
248:
249: mStructurePanel.setScrollActive(false);
250: mStructurePanel.repaint();
251: }
252: }
253:
254: public void mouseEntered(MouseEvent e) {
255: }
256:
257: public void mouseExited(MouseEvent e) {
258: }
259: }
|