View | Details | Raw Unified | Return to bug 42741
Collapse All | Expand All

(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/swing/svg/SVGUserAgentGUIAdapter.java (-2 / +5 lines)
Lines 22-27 Link Here
22
import java.awt.Component;
22
import java.awt.Component;
23
import javax.swing.JDialog;
23
import javax.swing.JDialog;
24
import javax.swing.JOptionPane;
24
import javax.swing.JOptionPane;
25
26
import org.apache.batik.util.gui.ErrorConsole;
25
import org.apache.batik.util.gui.JErrorPane;
27
import org.apache.batik.util.gui.JErrorPane;
26
28
27
/**
29
/**
Lines 53-60 Link Here
53
     * Displays an error resulting from the specified Exception.
55
     * Displays an error resulting from the specified Exception.
54
     */
56
     */
55
    public void displayError(Exception ex) {
57
    public void displayError(Exception ex) {
56
        JErrorPane pane = new JErrorPane(ex, JOptionPane.ERROR_MESSAGE);
58
//        JErrorPane pane = new JErrorPane(ex, JOptionPane.ERROR_MESSAGE);
57
        JDialog dialog = pane.createDialog(parentComponent, "ERROR");
59
    	ErrorConsole console = new ErrorConsole(ex, JOptionPane.ERROR_MESSAGE);
60
        JDialog dialog = console.createDialog(parentComponent, "ERROR");
58
        dialog.setModal(false);
61
        dialog.setModal(false);
59
        dialog.setVisible(true);
62
        dialog.setVisible(true);
60
    }
63
    }
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java (-3 / +5 lines)
Lines 57-62 Link Here
57
import org.apache.batik.swing.svg.SVGUserAgent;
57
import org.apache.batik.swing.svg.SVGUserAgent;
58
import org.apache.batik.util.SVGConstants;
58
import org.apache.batik.util.SVGConstants;
59
import org.apache.batik.util.XMLConstants;
59
import org.apache.batik.util.XMLConstants;
60
import org.apache.batik.util.gui.ErrorConsole;
60
import org.apache.batik.util.gui.JErrorPane;
61
import org.apache.batik.util.gui.JErrorPane;
61
62
62
import org.w3c.dom.Element;
63
import org.w3c.dom.Element;
Lines 1070-1078 Link Here
1070
            if (svgUserAgent != null) {
1071
            if (svgUserAgent != null) {
1071
                super.displayError(ex);
1072
                super.displayError(ex);
1072
            } else {
1073
            } else {
1073
                JErrorPane pane =
1074
//                JErrorPane pane =
1074
                    new JErrorPane(ex, JOptionPane.ERROR_MESSAGE);
1075
//                    new JErrorPane(ex, JOptionPane.ERROR_MESSAGE);
1075
                JDialog dialog = pane.createDialog(JSVGCanvas.this, "ERROR");
1076
            	ErrorConsole console = new ErrorConsole(ex, JOptionPane.ERROR_MESSAGE);
1077
                JDialog dialog = console.createDialog(JSVGCanvas.this, "ERROR");
1076
                dialog.setModal(false);
1078
                dialog.setModal(false);
1077
                dialog.setVisible(true); // Safe to be called from any thread
1079
                dialog.setVisible(true); // Safe to be called from any thread
1078
            }
1080
            }
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/bridge/DocumentLoader.java (-1 / +11 lines)
Lines 20-31 Link Here
20
20
21
import java.io.InputStream;
21
import java.io.InputStream;
22
import java.io.IOException;
22
import java.io.IOException;
23
import java.lang.reflect.Proxy;
23
import java.util.HashMap;
24
import java.util.HashMap;
24
25
25
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
26
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
26
import org.apache.batik.dom.svg.SVGDocumentFactory;
27
import org.apache.batik.dom.svg.SVGDocumentFactory;
27
import org.apache.batik.dom.util.DocumentDescriptor;
28
import org.apache.batik.dom.util.DocumentDescriptor;
29
import org.apache.batik.swing.svg.SVGDocumentLoader;
28
import org.apache.batik.util.CleanerThread;
30
import org.apache.batik.util.CleanerThread;
31
import org.apache.batik.util.gui.ErrorHandlerProxy;
29
32
30
import org.w3c.dom.Document;
33
import org.w3c.dom.Document;
31
import org.w3c.dom.Element;
34
import org.w3c.dom.Element;
Lines 103-109 Link Here
103
        if (ret != null)
106
        if (ret != null)
104
            return ret;
107
            return ret;
105
108
106
        SVGDocument document = documentFactory.createSVGDocument(uri);
109
//        SVGDocument document = documentFactory.createSVGDocument(uri);
110
		System.out.println("Installing proxy");
111
		SVGDocumentFactory documentFactoryProxy = (SVGDocumentFactory) Proxy
112
				.newProxyInstance(SVGDocumentFactory.class
113
						.getClassLoader(),
114
						new Class[] { SVGDocumentFactory.class },
115
						new ErrorHandlerProxy(documentFactory, uri));
116
        SVGDocument document = documentFactoryProxy.createSVGDocument(uri);
107
117
108
        DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
118
        DocumentDescriptor desc = documentFactory.getDocumentDescriptor();
109
        DocumentState state = new DocumentState(uri, document, desc);
119
        DocumentState state = new DocumentState(uri, document, desc);
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java (-3 / +5 lines)
Lines 133-138 Link Here
133
import org.apache.batik.util.SVGConstants;
133
import org.apache.batik.util.SVGConstants;
134
import org.apache.batik.util.XMLConstants;
134
import org.apache.batik.util.XMLConstants;
135
import org.apache.batik.util.gui.DOMViewer;
135
import org.apache.batik.util.gui.DOMViewer;
136
import org.apache.batik.util.gui.ErrorConsole;
136
import org.apache.batik.util.gui.JErrorPane;
137
import org.apache.batik.util.gui.JErrorPane;
137
import org.apache.batik.util.gui.LocationBar;
138
import org.apache.batik.util.gui.LocationBar;
138
import org.apache.batik.util.gui.MemoryMonitor;
139
import org.apache.batik.util.gui.MemoryMonitor;
Lines 2734-2742 Link Here
2734
            if (debug) {
2735
            if (debug) {
2735
                ex.printStackTrace();
2736
                ex.printStackTrace();
2736
            }
2737
            }
2737
            JErrorPane pane =
2738
//            JErrorPane pane =
2738
                new JErrorPane(ex, JOptionPane.ERROR_MESSAGE);
2739
//                new JErrorPane(ex, JOptionPane.ERROR_MESSAGE);
2739
            JDialog dialog = pane.createDialog(JSVGViewerFrame.this, "ERROR");
2740
            ErrorConsole console = new ErrorConsole(ex, JOptionPane.ERROR_MESSAGE);
2741
            JDialog dialog = console.createDialog(JSVGViewerFrame.this, "ERROR");
2740
            dialog.setModal(false);
2742
            dialog.setModal(false);
2741
            dialog.setVisible(true);
2743
            dialog.setVisible(true);
2742
        }
2744
        }
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/util/gui/resource/JFramesView.java (+380 lines)
Line 0 Link Here
1
/*
2
3
 Licensed to the Apache Software Foundation (ASF) under one or more
4
 contributor license agreements.  See the NOTICE file distributed with
5
 this work for additional information regarding copyright ownership.
6
 The ASF licenses this file to You under the Apache License, Version 2.0
7
 (the "License"); you may not use this file except in compliance with
8
 the License.  You may obtain a copy of the License at
9
10
 http://www.apache.org/licenses/LICENSE-2.0
11
12
 Unless required by applicable law or agreed to in writing, software
13
 distributed under the License is distributed on an "AS IS" BASIS,
14
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 See the License for the specific language governing permissions and
16
 limitations under the License.
17
18
 */
19
package org.apache.batik.util.gui.resource;
20
21
import java.awt.BasicStroke;
22
import java.awt.BorderLayout;
23
import java.awt.Color;
24
import java.awt.Component;
25
import java.awt.Dimension;
26
import java.awt.FontMetrics;
27
import java.awt.Graphics;
28
import java.awt.Graphics2D;
29
import java.awt.Polygon;
30
import java.awt.Rectangle;
31
import java.awt.Stroke;
32
import java.awt.event.ActionEvent;
33
import java.awt.event.AdjustmentEvent;
34
import java.awt.event.AdjustmentListener;
35
import java.awt.event.MouseAdapter;
36
import java.awt.event.MouseEvent;
37
import java.awt.event.MouseListener;
38
import java.awt.event.MouseMotionAdapter;
39
import java.awt.event.MouseMotionListener;
40
import java.util.HashMap;
41
import java.util.Locale;
42
import java.util.Map;
43
import java.util.ResourceBundle;
44
45
import javax.swing.AbstractAction;
46
import javax.swing.Action;
47
import javax.swing.BorderFactory;
48
import javax.swing.Box;
49
import javax.swing.BoxLayout;
50
import javax.swing.JButton;
51
import javax.swing.JComponent;
52
import javax.swing.JLabel;
53
import javax.swing.JPanel;
54
import javax.swing.JPopupMenu;
55
import javax.swing.JScrollBar;
56
import javax.swing.JScrollPane;
57
import javax.swing.border.BevelBorder;
58
59
public class JFramesView extends JPanel implements ActionMap {
60
61
	/**
62
	 * The resource file name
63
	 */
64
	protected static final String RESOURCES = "org.apache.batik.util.gui.resource.resources.JTimeline";
65
66
	/**
67
	 * The resource bundle
68
	 */
69
	protected static ResourceBundle bundle;
70
71
	/**
72
	 * The resource manager
73
	 */
74
	protected static ResourceManager resources;
75
76
	static {
77
		bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault());
78
		resources = new ResourceManager(bundle);
79
	}
80
81
	/**
82
	 * The button factory.
83
	 */
84
	protected ButtonFactory bf = new ButtonFactory(bundle, this);
85
86
	/**
87
	 * The menu factory.
88
	 */
89
	protected MenuFactory mf = new MenuFactory(bundle, this);
90
91
	private JTimelineSlider sliderPanel;
92
93
	private JPopupMenu cornerPopup;
94
95
	private JLabel timerLabel;
96
97
	private int precisionMillis = 100;
98
99
	private int pixelsPerUnit = 50;
100
101
	private float value = 1;
102
103
	private int knobPosition;
104
105
	private JScrollPane framesScrollPane;
106
	
107
	private JScrollBar verticalScrollBar;
108
	
109
	public JFramesView() {
110
		super(new BorderLayout());
111
112
		actions.put("CornerButtonAction", new CornerButtonAction());
113
		actions.put("IncreaseUnitSizeMenuItemAction",
114
				new IncreaseUnitSizeMenuItemAction());
115
		actions.put("DecreaseUnitSizeMenuItemAction",
116
				new DecreaseUnitSizeMenuItemAction());
117
118
		sliderPanel = new JTimelineSlider();
119
120
		framesScrollPane = new JScrollPane(
121
				new JTimelineFramesPanel());
122
		framesScrollPane.setBorder(null);
123
		framesScrollPane
124
				.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
125
		framesScrollPane
126
				.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
127
		framesScrollPane.setColumnHeaderView(sliderPanel);
128
129
		JButton cornerButton = bf.createJButton("CornerButton");
130
		cornerButton.setFocusable(false);
131
		cornerPopup = new JPopupMenu();
132
		cornerPopup.add(mf.createJMenuItem("IncreaseUnitSizeMenuItem"));
133
		cornerPopup.add(mf.createJMenuItem("DecreaseUnitSizeMenuItem"));
134
		framesScrollPane
135
				.setCorner(JScrollPane.UPPER_RIGHT_CORNER, cornerButton);
136
		add(framesScrollPane);
137
138
		Box footerPanel = new Box(BoxLayout.X_AXIS);
139
		add(footerPanel, BorderLayout.SOUTH);
140
		timerLabel = new JLabel("-- : -- : --");
141
		timerLabel.setBorder(BorderFactory
142
				.createBevelBorder(BevelBorder.LOWERED));
143
		footerPanel.add(timerLabel);
144
		JScrollBar horizScrollBar = new JScrollBar(JScrollBar.HORIZONTAL);
145
		int prefHeight = horizScrollBar.getPreferredSize().height;
146
		footerPanel
147
				.setMaximumSize(new Dimension(Integer.MAX_VALUE, prefHeight));
148
		footerPanel.setMinimumSize(new Dimension(0, prefHeight));
149
		footerPanel.setPreferredSize(footerPanel.getMinimumSize());
150
		footerPanel.add(horizScrollBar);
151
		footerPanel.add(Box.createHorizontalStrut(framesScrollPane
152
				.getVerticalScrollBar().getPreferredSize().width));
153
	}
154
155
	public JScrollBar getVerticalScrollBar() {
156
		return verticalScrollBar;
157
	}
158
159
	public void setVerticalScrollBar(JScrollBar verticalScrollBar) {
160
		this.verticalScrollBar = verticalScrollBar;
161
		add(verticalScrollBar, BorderLayout.EAST);
162
		verticalScrollBar.addAdjustmentListener(new AdjustmentListener() {
163
			public void adjustmentValueChanged(AdjustmentEvent e) {
164
				
165
			}
166
		});
167
	}
168
169
	/**
170
	 * The map that contains the actions
171
	 */
172
	protected Map actions = new HashMap();
173
174
	/**
175
	 * Returns the action associated with the given string or null on error
176
	 * 
177
	 * @param key
178
	 *            the key mapped with the action to get
179
	 * @throws MissingListenerException
180
	 *             if the action is not found
181
	 */
182
	public Action getAction(String key) throws MissingListenerException {
183
		return (Action) actions.get(key);
184
	}
185
186
	protected class CornerButtonAction extends AbstractAction {
187
188
		public void actionPerformed(ActionEvent evt) {
189
			Component invoker = (Component) evt.getSource();
190
			cornerPopup.show(invoker, 0, invoker.getHeight());
191
		}
192
	}
193
194
	protected class IncreaseUnitSizeMenuItemAction extends AbstractAction {
195
196
		public void actionPerformed(ActionEvent evt) {
197
			// TODO:
198
			// Increase unit size in timeline slider
199
		}
200
	}
201
202
	protected class DecreaseUnitSizeMenuItemAction extends AbstractAction {
203
204
		public void actionPerformed(ActionEvent evt) {
205
			// TODO:
206
			// Decrease unit size in timeline slider
207
		}
208
	}
209
210
	public void paint(Graphics g) {
211
		knobPosition = (int) (value * pixelsPerUnit) + SLIDER_X_OFFSET;
212
213
		super.paint(g);
214
	}
215
216
	public static final int SLIDER_X_OFFSET = 10;
217
218
	private static final Color SLIDER_KNOB_FILL_COLOR = new Color(0x77FF7777,
219
			true);
220
221
	private static final Color SLIDER_KNOB_STROKE_COLOR = new Color(0x00FF0000);
222
223
	private static final Stroke SLIDER_KNOB_STROKE = new BasicStroke(1,
224
			BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 5.0f,
225
			new float[] { 5.0f }, 0.0f);
226
227
	private class JTimelineSlider extends JComponent {
228
229
		private boolean paintTrack = false;
230
231
		private Polygon knob;
232
233
		private Rectangle knobBounds;
234
235
		private boolean over;
236
237
		private MouseMotionListener mml = new MouseMotionAdapter() {
238
			public void mouseMoved(MouseEvent e) {
239
				int x = e.getX(), y = e.getY();
240
				boolean b = knobBounds.contains(x, y);
241
				if (b != b) {
242
					repaint();
243
				}
244
				over = b;
245
			}
246
247
			public void mouseDragged(MouseEvent e) {
248
				if (over) {
249
					int x = e.getX();
250
					if (x >= SLIDER_X_OFFSET) {
251
						value = (float) (x - SLIDER_X_OFFSET) / pixelsPerUnit;
252
						JFramesView.this.repaint();
253
					}
254
				}
255
			}
256
		};
257
258
		public JTimelineSlider() {
259
			int height = 30;
260
261
			setMaximumSize(new Dimension(Integer.MAX_VALUE, height));
262
			setMinimumSize(new Dimension(0, height));
263
			setPreferredSize(getMinimumSize());
264
			setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
265
			addMouseMotionListener(mml);
266
267
			int pos = height / 2 - 3;
268
			knob = new Polygon();
269
			knob.addPoint(-4, -pos);
270
			knob.addPoint(4, -pos);
271
			knob.addPoint(4, pos);
272
			knob.addPoint(-4, pos);
273
			knob.addPoint(-4, -pos);
274
275
			knobBounds = new Rectangle(6, height);
276
		}
277
278
		protected void paintComponent(Graphics g) {
279
			super.paintComponent(g);
280
281
			Dimension size = getSize();
282
			if (paintTrack) {
283
				int pos = size.height / 2;
284
				g.setColor(Color.gray);
285
				g.fillRect(0, pos - 1, size.width, 2);
286
				g.setColor(Color.white);
287
				g.drawLine(0, pos + 1, size.width, pos + 1);
288
			}
289
290
			int dx = pixelsPerUnit * precisionMillis / 1000;
291
			FontMetrics fm = g.getFontMetrics();
292
			int timeUnit = 0;
293
			for (int i = SLIDER_X_OFFSET; i < size.width; i += pixelsPerUnit) {
294
				String str = timeUnit++ + "";
295
				int strWidth = fm.stringWidth(str), strHeight = fm.getHeight()
296
						- fm.getDescent();
297
				g.setColor(getBackground());
298
				g.fillRect(i - strWidth / 2, (size.height - strHeight) / 2,
299
						strWidth, strHeight);
300
				g.setColor(Color.black);
301
				g.drawString(str, i - strWidth / 2,
302
						(size.height + strHeight) / 2);
303
				g.setColor(Color.gray);
304
				g.drawLine(i, size.height - 2, i, size.height - 7);
305
				g.drawLine(i, 2, i, 7);
306
				g.setColor(Color.lightGray);
307
				for (int j = i + dx; j < i + pixelsPerUnit; j += dx) {
308
					g.drawLine(j, size.height - 2, j, size.height - 5);
309
					g.drawLine(j, 2, j, 5);
310
				}
311
			}
312
313
			// Paint knob
314
			int x = knobPosition;
315
			int y = size.height / 2;
316
			knobBounds.x = x - knobBounds.width / 2;
317
			knobBounds.y = y - knobBounds.height / 2;
318
319
			g.translate(x, y);
320
			g.setColor(SLIDER_KNOB_FILL_COLOR);
321
			g.fillPolygon(knob);
322
			g.setColor(SLIDER_KNOB_STROKE_COLOR);
323
			g.drawPolygon(knob);
324
			g.translate(-x, -y);
325
		}
326
	}
327
328
	private class JTimelineFramesPanel extends JPanel {
329
330
		private boolean inside;
331
332
		private int hoverPosition;
333
		
334
		private MouseListener ml = new MouseAdapter() {
335
			public void mouseEntered(MouseEvent e) {
336
				inside = true;
337
				JFramesView.this.repaint();
338
			}
339
340
			public void mouseExited(MouseEvent e) {
341
				inside = false;
342
				JFramesView.this.repaint();
343
			}
344
		};
345
346
		private MouseMotionListener mml = new MouseMotionAdapter() {
347
			public void mouseMoved(MouseEvent e) {
348
				int x = e.getX() - SLIDER_X_OFFSET;
349
				int dx = pixelsPerUnit * precisionMillis / 1000;
350
				hoverPosition = SLIDER_X_OFFSET + x - x % dx;
351
				JFramesView.this.repaint();
352
			}
353
		};
354
355
		public JTimelineFramesPanel() {
356
			addMouseListener(ml);
357
			addMouseMotionListener(mml);
358
		}
359
360
		protected void paintComponent(Graphics g) {
361
			Dimension size = getSize();
362
			
363
			int dx = pixelsPerUnit * precisionMillis / 1000;
364
			g.setColor(Color.lightGray);
365
			for (int i = SLIDER_X_OFFSET; i < size.width; i += dx) {
366
				g.drawLine(i, 0, i, size.height);
367
			}
368
369
			g.setColor(SLIDER_KNOB_STROKE_COLOR);
370
			g.drawLine(knobPosition, 0, knobPosition, size.height);
371
			
372
			if (inside) {
373
				Graphics2D g2 = (Graphics2D)g;
374
				g2.setStroke(SLIDER_KNOB_STROKE);
375
				
376
				g2.drawLine(hoverPosition, 0, hoverPosition, size.height);
377
			}
378
		}
379
	}
380
}
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/util/gui/resource/ButtonFactory.java (+26 lines)
Lines 28-33 Link Here
28
import javax.swing.JButton;
28
import javax.swing.JButton;
29
import javax.swing.JCheckBox;
29
import javax.swing.JCheckBox;
30
import javax.swing.JRadioButton;
30
import javax.swing.JRadioButton;
31
import javax.swing.JToggleButton;
31
32
32
/**
33
/**
33
 * This class represents a button factory which builds
34
 * This class represents a button factory which builds
Lines 123-128 Link Here
123
    }
124
    }
124
125
125
    /**
126
    /**
127
     * Creates and returns a new swing button initialised
128
     * to be used as a toolbar toggle button
129
     * @param name the name of the button in the resource bundle
130
     * @throws MissingResourceException if key is not the name of a button.
131
     *         It is not thrown if the mnemonic and the action keys are missing
132
     * @throws ResourceFormatException if the mnemonic is not a single
133
     *         character
134
     * @throws MissingListenerException if the button action is not found in
135
     *         the action map
136
     */
137
    public JToggleButton createJToolbarToggleButton(String name)
138
        throws MissingResourceException,
139
               ResourceFormatException,
140
               MissingListenerException {
141
        JToggleButton result;
142
        try {
143
            result = new JToolbarToggleButton(getString(name+TEXT_SUFFIX));
144
        } catch (MissingResourceException e) {
145
            result = new JToolbarToggleButton();
146
        }
147
        initializeButton(result, name);
148
        return result;
149
    }
150
151
    /**
126
     * Creates and returns a new swing radio button
152
     * Creates and returns a new swing radio button
127
     * @param name the name of the button in the resource bundle
153
     * @param name the name of the button in the resource bundle
128
     * @throws MissingResourceException if key is not the name of a button.
154
     * @throws MissingResourceException if key is not the name of a button.
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/util/gui/resource/Hyperlink.java (+72 lines)
Line 0 Link Here
1
package org.apache.batik.util.gui.resource;
2
3
import java.awt.Cursor;
4
import java.awt.event.MouseAdapter;
5
import java.awt.event.MouseEvent;
6
import java.awt.event.MouseListener;
7
8
import javax.swing.JLabel;
9
10
public class Hyperlink extends JLabel {
11
	private MouseListener ml = new MouseAdapter() {
12
		public void mouseClicked(MouseEvent e) {
13
			if (callback != null) {
14
				callback.linkClicked(new HyperlinkEvent(Hyperlink.this.getCommand()));
15
			}
16
		}
17
	};
18
	
19
	private HyperlinkCallback callback;
20
	
21
	private String command;
22
	
23
	private static final String HTML_TEXT = "<html><font color=\"blue\"><u>__HTML_TEXT__</u></font></html>";
24
	
25
	private String text;
26
	
27
	public Hyperlink(String text, HyperlinkCallback callback) {
28
		this.callback = callback;
29
		setLinkText(text);
30
		setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
31
		addMouseListener(ml);
32
	}
33
34
	public String getLinkText() {
35
		return text;
36
	}
37
	
38
	public void setLinkText(String text) {
39
		this.text = text;
40
		super.setText(HTML_TEXT.replace("__HTML_TEXT__", text));
41
	}
42
43
	public String getCommand() {
44
		return command;
45
	}
46
47
	public void setCommand(String command) {
48
		this.command = command;
49
	}
50
51
	public static class HyperlinkEvent {
52
		
53
		private String command;
54
		
55
		public HyperlinkEvent(String command) {
56
			this.command = command;
57
		}
58
59
		public String getCommand() {
60
			return command;
61
		}
62
63
		public void setCommand(String command) {
64
			this.command = command;
65
		}
66
	}
67
	
68
	public static interface HyperlinkCallback {
69
		public void linkClicked(HyperlinkEvent e);
70
	}
71
}
72
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/util/gui/resource/JDocumentTree.java (+279 lines)
Line 0 Link Here
1
package org.apache.batik.util.gui.resource;
2
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Component;
6
import java.awt.Dimension;
7
import java.awt.GradientPaint;
8
import java.awt.Graphics;
9
import java.awt.Graphics2D;
10
import java.awt.Paint;
11
import java.awt.event.MouseAdapter;
12
import java.awt.event.MouseEvent;
13
import java.util.ArrayList;
14
import java.util.Locale;
15
import java.util.ResourceBundle;
16
17
import javax.swing.BorderFactory;
18
import javax.swing.DefaultListModel;
19
import javax.swing.ImageIcon;
20
import javax.swing.JComponent;
21
import javax.swing.JLabel;
22
import javax.swing.JList;
23
import javax.swing.JPanel;
24
import javax.swing.JScrollBar;
25
import javax.swing.JScrollPane;
26
import javax.swing.JTree;
27
import javax.swing.ListCellRenderer;
28
import javax.swing.tree.TreeNode;
29
30
public class JDocumentTree extends JPanel {
31
32
	/**
33
	 * The resource file name
34
	 */
35
	protected static final String RESOURCES = "org.apache.batik.util.gui.resource.resources.JDocumentTree";
36
37
	/**
38
	 * The resource bundle
39
	 */
40
	protected static ResourceBundle bundle;
41
42
	/**
43
	 * The resource manager
44
	 */
45
	protected static ResourceManager resources;
46
47
	static {
48
		bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault());
49
		resources = new ResourceManager(bundle);
50
	}
51
52
	private JList nodeList;
53
54
	private JScrollPane nodeListScrollPane;
55
56
	private Node rootNode;
57
58
	public JDocumentTree() {
59
		this(null);
60
	}
61
62
	public JDocumentTree(JTree tree) {
63
		super(new BorderLayout());
64
65
		nodeList = new JList(new DefaultListModel());
66
		nodeList.setFixedCellHeight(25);
67
		nodeList.setCellRenderer(new DocTreeCellRenderer());
68
		nodeListScrollPane = new JScrollPane(nodeList);
69
		nodeListScrollPane
70
				.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
71
		nodeListScrollPane.setBorder(null);
72
		add(nodeListScrollPane);
73
74
		TreeNode treeNode = (TreeNode) tree.getModel().getRoot();
75
		rootNode = parse(treeNode, null);
76
		rebuildNodeList(nodeList, rootNode);
77
78
		nodeList.addMouseListener(new MouseAdapter() {
79
			public void mouseClicked(MouseEvent e) {
80
				if (e.getClickCount() == 2) {
81
					Node selectedNode = (Node) nodeList.getSelectedValue();
82
					selectedNode.setExpanded(!selectedNode.isExpanded());
83
					rebuildNodeList(nodeList, rootNode);
84
				}
85
			}
86
		});
87
	}
88
89
	public JScrollBar getVerticalScrollBar() {
90
		return nodeListScrollPane.getVerticalScrollBar();
91
	}
92
93
	public void setVerticalScrollBar(JScrollBar verticalScrollBar) {
94
		nodeListScrollPane.setVerticalScrollBar(verticalScrollBar);
95
	}
96
97
	private void rebuildNodeList(JList nodeList, Node node) {
98
		DefaultListModel listModel = (DefaultListModel) nodeList.getModel();
99
		listModel.clear();
100
		addNode(listModel, node);
101
	}
102
103
	private void addNode(DefaultListModel listModel, Node node) {
104
		Node parent = node.getParent();
105
		if (parent == null || parent.isExpanded()) {
106
			listModel.addElement(node);
107
			Node[] children = node.getChildren();
108
			if (children != null) {
109
				for (int i = 0; i < children.length; i++) {
110
					addNode(listModel, children[i]);
111
				}
112
			}
113
		}
114
	}
115
116
	private Node parse(TreeNode treeNode, Node parent) {
117
		if (treeNode == null) {
118
			return null;
119
		}
120
121
		Node docNode = new Node(parent, treeNode.toString());
122
		int childCount = treeNode.getChildCount();
123
		if (childCount > 0) {
124
			ArrayList childDocNodes = new ArrayList();
125
			for (int i = 0; i < childCount; i++) {
126
				Node childDocNode = parse((TreeNode) treeNode.getChildAt(i),
127
						docNode);
128
				if (childDocNode != null) {
129
					childDocNodes.add(childDocNode);
130
				}
131
			}
132
			docNode.setChildren((Node[]) childDocNodes.toArray(new Node[0]));
133
		}
134
135
		return docNode;
136
	}
137
138
	private class Node extends JComponent {
139
140
		private String text;
141
142
		private Node parent;
143
144
		private int depth;
145
146
		private Node[] children;
147
148
		private boolean expanded = true;
149
150
		private boolean locked = false;
151
152
		public Node(Node parent, String text) {
153
			this.parent = parent;
154
			this.depth = parent == null ? 0 : parent.depth + 1;
155
			setText(text);
156
		}
157
158
		public Node getParent() {
159
			return parent;
160
		}
161
162
		public int getDepth() {
163
			return depth;
164
		}
165
166
		public Node[] getChildren() {
167
			return children;
168
		}
169
170
		public int getChildCount() {
171
			return children == null ? 0 : children.length;
172
		}
173
174
		public void setChildren(Node[] children) {
175
			this.children = children;
176
			if (children != null) {
177
				for (int i = 0; i < children.length; i++) {
178
					children[i].parent = this;
179
				}
180
			}
181
		}
182
183
		public boolean isExpanded() {
184
			if (parent == null) {
185
				return true;
186
			}
187
			if (!expanded) {
188
				return false;
189
			}
190
			return parent.isExpanded();
191
		}
192
193
		public void setExpanded(boolean expanded) {
194
			this.expanded = expanded;
195
		}
196
197
		public String getText() {
198
			return text;
199
		}
200
201
		public void setText(String text) {
202
			this.text = text;
203
		}
204
	}
205
206
	private class DocTreeCellRenderer extends JLabel implements
207
			ListCellRenderer {
208
209
		private final ImageIcon SPACER_ICON = getIcon("TreeNodeSpacer.icon");
210
211
		private final ImageIcon CLOSED_ICON = getIcon("TreeNodeClosed.icon");
212
213
		private final ImageIcon OPENED_ICON = getIcon("TreeNodeOpened.icon");
214
215
		private final ImageIcon LEAF_ICON = getIcon("TreeLeaf.icon");
216
217
		private final ImageIcon LOCK_ICON = getIcon("TreeNodeLocked.icon");
218
219
		private Paint normalPaint, selectedPaint;
220
221
		private boolean selected;
222
223
		private boolean locked = true;
224
225
		public DocTreeCellRenderer() {
226
			setIcon(SPACER_ICON);
227
228
			Dimension dim = getPreferredSize();
229
			normalPaint = new Color(234, 234, 234);
230
			selectedPaint = new GradientPaint(0, 0, Color.white, 0,
231
					2 * dim.height, Color.gray);
232
		}
233
234
		private ImageIcon getIcon(String name) {
235
			return new ImageIcon(JDocumentTree.this.getClass().getResource(
236
					resources.getString(name)));
237
		}
238
239
		protected void paintComponent(Graphics g) {
240
			Dimension size = getSize();
241
			Graphics2D g2 = (Graphics2D) g;
242
			g2.setPaint(selected ? selectedPaint : normalPaint);
243
			g2.fillRect(0, 0, size.width, size.height);
244
245
			g2.setColor(Color.lightGray);
246
			g2.drawLine(0, size.height - 2, size.width, size.height - 2);
247
			g2.setColor(Color.white);
248
			g2.drawLine(0, size.height - 1, size.width, size.height - 1);
249
250
			super.paintComponent(g);
251
252
			g.setColor(Color.white);
253
			int x, y;
254
			x = size.width - 18;
255
			y = (size.height - 16) / 2;
256
			g.draw3DRect(x, y, 16, 16, false);
257
			if (locked) {
258
				LOCK_ICON.paintIcon(this, g, x, y);
259
			}
260
		}
261
262
		public Component getListCellRendererComponent(JList list, Object value,
263
				int index, boolean isSelected, boolean cellHasFocus) {
264
			Node node = (Node) value;
265
			selected = isSelected;
266
			setText(node.getText());
267
			setBorder(BorderFactory.createEmptyBorder(0, node.depth * 10, 0, 0));
268
			if (node.getChildren() == null || node.getChildCount() == 0) {// leaf
269
				setIcon(LEAF_ICON);
270
			} else if (node.isExpanded()) {
271
				setIcon(OPENED_ICON);
272
			} else {
273
				setIcon(CLOSED_ICON);
274
			}
275
276
			return this;
277
		}
278
	}
279
}
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/util/gui/resource/JToolbarToggleButton.java (+74 lines)
Line 0 Link Here
1
/*
2
3
   Licensed to the Apache Software Foundation (ASF) under one or more
4
   contributor license agreements.  See the NOTICE file distributed with
5
   this work for additional information regarding copyright ownership.
6
   The ASF licenses this file to You under the Apache License, Version 2.0
7
   (the "License"); you may not use this file except in compliance with
8
   the License.  You may obtain a copy of the License at
9
10
       http://www.apache.org/licenses/LICENSE-2.0
11
12
   Unless required by applicable law or agreed to in writing, software
13
   distributed under the License is distributed on an "AS IS" BASIS,
14
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
   See the License for the specific language governing permissions and
16
   limitations under the License.
17
18
 */
19
package org.apache.batik.util.gui.resource;
20
21
import java.awt.Insets;
22
import java.awt.event.MouseAdapter;
23
import java.awt.event.MouseEvent;
24
25
import javax.swing.JToggleButton;
26
27
/**
28
 * This class represents the buttons used in toolbars.
29
 *
30
 * @author <a href="mailto:stephane@hillion.org">Stephane Hillion</a>
31
 * @version $Id: JToolbarButton.java 498555 2007-01-22 08:09:33Z cam $
32
 */
33
public class JToolbarToggleButton extends JToggleButton {
34
    /**
35
     * Creates a new toolbar button.
36
     */
37
    public JToolbarToggleButton() {
38
        initialize();
39
    }
40
41
    /**
42
     * Creates a new toolbar button.
43
     * @param txt The button text.
44
     */
45
    public JToolbarToggleButton(String txt) {
46
        super(txt);
47
        initialize();
48
    }
49
50
    /**
51
     * Initializes the button.
52
     */
53
    protected void initialize() {
54
        if (!System.getProperty("java.version").startsWith("1.3")) {
55
            setOpaque(false);
56
            setBackground(new java.awt.Color(0, 0, 0, 0));
57
        }
58
        setBorderPainted(false);
59
        setMargin(new Insets(2, 2, 2, 2));
60
        addMouseListener(new MouseListener());
61
    }
62
63
    /**
64
     * To manage the mouse interactions.
65
     */
66
    protected class MouseListener extends MouseAdapter {
67
        public void mouseEntered(MouseEvent ev) {
68
            setBorderPainted(true);
69
        }
70
        public void mouseExited(MouseEvent ev) {
71
            setBorderPainted(false);
72
        }
73
    }
74
}
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/util/gui/TimelineViewer.java (+214 lines)
Line 0 Link Here
1
package org.apache.batik.util.gui;
2
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Component;
6
import java.awt.Dimension;
7
import java.awt.GradientPaint;
8
import java.awt.Graphics;
9
import java.awt.Graphics2D;
10
import java.awt.Paint;
11
import java.awt.event.ActionEvent;
12
import java.util.HashMap;
13
import java.util.Locale;
14
import java.util.Map;
15
import java.util.ResourceBundle;
16
17
import javax.swing.AbstractAction;
18
import javax.swing.Action;
19
import javax.swing.Box;
20
import javax.swing.BoxLayout;
21
import javax.swing.ImageIcon;
22
import javax.swing.JDialog;
23
import javax.swing.JLabel;
24
import javax.swing.JOptionPane;
25
import javax.swing.JPanel;
26
import javax.swing.JScrollBar;
27
import javax.swing.JScrollPane;
28
import javax.swing.JSeparator;
29
import javax.swing.JSplitPane;
30
import javax.swing.JToolBar;
31
import javax.swing.JTree;
32
import javax.swing.tree.TreeCellRenderer;
33
34
import org.apache.batik.util.gui.resource.ActionMap;
35
import org.apache.batik.util.gui.resource.JDocumentTree;
36
import org.apache.batik.util.gui.resource.JFramesView;
37
import org.apache.batik.util.gui.resource.MissingListenerException;
38
import org.apache.batik.util.gui.resource.ResourceManager;
39
import org.apache.batik.util.gui.resource.ToolBarFactory;
40
41
public class TimelineViewer extends JPanel implements ActionMap {
42
43
	/**
44
	 * The resource file name
45
	 */
46
	protected static final String RESOURCES = "org.apache.batik.util.gui.resources.TimelineViewer";
47
48
	/**
49
	 * The resource bundle
50
	 */
51
	protected static ResourceBundle bundle;
52
53
	/**
54
	 * The resource manager
55
	 */
56
	protected static ResourceManager resources;
57
58
	static {
59
		bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault());
60
		resources = new ResourceManager(bundle);
61
	}
62
63
	/**
64
	 * The toolbar factory.
65
	 */
66
	protected ToolBarFactory tf = new ToolBarFactory(bundle, this);
67
68
	private JTree docTree;
69
70
	public TimelineViewer() {
71
		super(new BorderLayout());
72
		setPreferredSize(new Dimension(800, 300));
73
74
		JSplitPane splitPane = new JSplitPane();
75
		splitPane.setResizeWeight(0.0);
76
		JPanel leftPane = new JPanel();
77
		splitPane.setLeftComponent(leftPane);
78
79
		leftPane.setLayout(new BorderLayout());
80
		leftPane.setMinimumSize(new Dimension(300, 0));
81
		leftPane.setPreferredSize(getMinimumSize());
82
		leftPane.add(createToolBar(), BorderLayout.NORTH);
83
84
		JScrollBar scrollBar = new JScrollBar(JScrollBar.VERTICAL, 0, 1, 0, 100);
85
		JDocumentTree docTree = new JDocumentTree(new JTree());
86
		docTree.setVerticalScrollBar(scrollBar);
87
		leftPane.add(docTree);
88
89
		JFramesView framesView = new JFramesView();
90
		framesView.setVerticalScrollBar(scrollBar);
91
		splitPane.setRightComponent(framesView);
92
		add(splitPane);
93
	}
94
95
	private JPanel createToolBar() {
96
		JPanel toolbarPanel = new JPanel(new BorderLayout());
97
		JToolBar toolbar = tf.createJToolBar("ToolBar");
98
		toolbar.setFloatable(false);
99
100
		toolbarPanel.add(toolbar);
101
		toolbarPanel.add(new JSeparator(), BorderLayout.SOUTH);
102
103
		return toolbarPanel;
104
	}
105
106
	public JDialog createDialog(Component owner, String title) {
107
		JDialog dialog = new JDialog(JOptionPane.getFrameForComponent(owner),
108
				title);
109
		dialog.getContentPane().add(this, BorderLayout.CENTER);
110
		dialog.pack();
111
		return dialog;
112
	}
113
114
	/**
115
	 * The map that contains the actions
116
	 */
117
	protected Map actions = new HashMap();
118
119
	/**
120
	 * Returns the action associated with the given string or null on error
121
	 * 
122
	 * @param key
123
	 *            the key mapped with the action to get
124
	 * @throws MissingListenerException
125
	 *             if the action is not found
126
	 */
127
	public Action getAction(String key) throws MissingListenerException {
128
		return (Action) actions.get(key);
129
	}
130
131
	/**
132
	 * The action associated with the 'All' button.
133
	 */
134
	protected class DisplayAllButtonAction extends AbstractAction {
135
136
		public void actionPerformed(ActionEvent evt) {
137
		}
138
	}
139
140
	public static void main(String[] args) {
141
		JDialog d = new TimelineViewer().createDialog(null,
142
				"Timeline Viewer 0.1");
143
		d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
144
		d.setVisible(true);
145
	}
146
147
//	private class DocTreeCellRenderer extends Box implements
148
//			TreeCellRenderer {
149
//
150
//		private final ImageIcon SPACER_ICON = getIcon("TreeNodeSpacer.icon");
151
//
152
//		private final ImageIcon CLOSED_ICON = getIcon("TreeNodeClosed.icon");
153
//
154
//		private final ImageIcon OPENED_ICON = getIcon("TreeNodeOpened.icon");
155
//
156
//		private final ImageIcon LEAF_ICON = getIcon("TreeLeaf.icon");
157
//
158
//		private Paint gradient;
159
//
160
//		private JLabel label;
161
//
162
//		private JLabel icon;
163
//
164
//		public DocTreeCellRenderer() {
165
//			super(BoxLayout.X_AXIS);
166
//			setOpaque(false);
167
//
168
//			icon = new JLabel(SPACER_ICON);
169
//			add(icon);
170
//
171
//			label = new JLabel();
172
//			add(label);
173
//			
174
//			Dimension dim = getPreferredSize();
175
//			gradient = new GradientPaint(0, 0, Color.white, 0,
176
//					2 * dim.height, Color.gray);
177
//		}
178
//
179
//		public void setBounds(int x, int y, int width, int height) {
180
//			super.setBounds(x, y, docTree.getWidth(), height);
181
//			System.out.println(getBounds());
182
//		}
183
//		
184
//		private ImageIcon getIcon(String name) {
185
//			String uri = resources.getString(name);
186
//			System.out.println(uri);
187
//			return new ImageIcon(TimelineViewer.this.getClass().getResource(
188
//					uri));
189
//		}
190
//
191
//		protected void paintComponent(Graphics g) {
192
//			Graphics2D g2 = (Graphics2D) g;
193
//			g2.setPaint(gradient);
194
//			g2.fillRect(0, 0, getWidth(), getHeight());
195
//
196
//			super.paintComponent(g);
197
//		}
198
//
199
//		public Component getTreeCellRendererComponent(JTree tree, Object value,
200
//				boolean selected, boolean expanded, boolean leaf, int row,
201
//				boolean hasFocus) {
202
//			label.setText(value.toString());
203
//
204
//			if (leaf) {
205
//				icon.setIcon(LEAF_ICON);
206
//			} else if (expanded) {
207
//				icon.setIcon(OPENED_ICON);
208
//			} else {
209
//				icon.setIcon(CLOSED_ICON);
210
//			}
211
//			return this;
212
//		}
213
//	}
214
}
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/util/gui/ErrorHandlerProxy.java (+37 lines)
Line 0 Link Here
1
package org.apache.batik.util.gui;
2
3
import java.lang.reflect.InvocationHandler;
4
import java.lang.reflect.InvocationTargetException;
5
import java.lang.reflect.Method;
6
7
import javax.swing.JDialog;
8
import javax.swing.JOptionPane;
9
10
public class ErrorHandlerProxy implements InvocationHandler {
11
	
12
	private Object delegate;
13
	
14
	private String uri;
15
	
16
	public ErrorHandlerProxy(Object delegate, String uri) {
17
		this.delegate = delegate;
18
		this.uri = uri;
19
	}
20
21
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
22
		try {
23
			System.out.println("proxy invoked");
24
			return method.invoke(delegate, args);
25
		} catch (InvocationTargetException ite) {
26
			System.out.println("Exception occurred");
27
			ite.printStackTrace();
28
		} catch (Exception e) {
29
			System.out.println("Exception occurred");
30
			ErrorConsole console = new ErrorConsole(e, uri, JOptionPane.ERROR_MESSAGE);
31
			JDialog dialog = console.createDialog(null, "ERROR");
32
			dialog.setVisible(true);
33
		}
34
		return null;
35
	}
36
37
}
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/sources/org/apache/batik/util/gui/ErrorConsole.java (+540 lines)
Line 0 Link Here
1
package org.apache.batik.util.gui;
2
3
import java.awt.BorderLayout;
4
import java.awt.Color;
5
import java.awt.Component;
6
import java.awt.Container;
7
import java.awt.Dimension;
8
import java.awt.FlowLayout;
9
import java.awt.GradientPaint;
10
import java.awt.Graphics;
11
import java.awt.Graphics2D;
12
import java.awt.SystemColor;
13
import java.awt.event.ActionEvent;
14
import java.awt.event.ActionListener;
15
import java.awt.event.ItemEvent;
16
import java.awt.event.ItemListener;
17
import java.awt.event.MouseAdapter;
18
import java.awt.event.MouseEvent;
19
import java.awt.event.MouseListener;
20
import java.io.PrintWriter;
21
import java.io.StringWriter;
22
import java.util.ArrayList;
23
import java.util.Enumeration;
24
import java.util.HashMap;
25
import java.util.Iterator;
26
import java.util.List;
27
import java.util.Locale;
28
import java.util.Map;
29
import java.util.ResourceBundle;
30
31
import javax.swing.AbstractAction;
32
import javax.swing.AbstractButton;
33
import javax.swing.Action;
34
import javax.swing.BorderFactory;
35
import javax.swing.Box;
36
import javax.swing.BoxLayout;
37
import javax.swing.ButtonGroup;
38
import javax.swing.ButtonModel;
39
import javax.swing.ImageIcon;
40
import javax.swing.JButton;
41
import javax.swing.JDialog;
42
import javax.swing.JLabel;
43
import javax.swing.JOptionPane;
44
import javax.swing.JPanel;
45
import javax.swing.JPopupMenu;
46
import javax.swing.JScrollPane;
47
import javax.swing.JTextArea;
48
import javax.swing.JTextPane;
49
import javax.swing.JToggleButton;
50
import javax.swing.JToolBar;
51
52
import org.apache.batik.util.gui.resource.ActionMap;
53
import org.apache.batik.util.gui.resource.ButtonFactory;
54
import org.apache.batik.util.gui.resource.Hyperlink;
55
import org.apache.batik.util.gui.resource.JToolbarSeparator;
56
import org.apache.batik.util.gui.resource.MenuFactory;
57
import org.apache.batik.util.gui.resource.MissingListenerException;
58
import org.apache.batik.util.gui.resource.ResourceManager;
59
import org.apache.batik.util.gui.resource.Hyperlink.HyperlinkEvent;
60
import org.w3c.dom.Document;
61
62
public class ErrorConsole extends JPanel implements ActionMap {
63
64
	/**
65
	 * The resource file name
66
	 */
67
	protected static final String RESOURCES = "org.apache.batik.util.gui.resources.ErrorConsole";
68
69
	/**
70
	 * The resource bundle
71
	 */
72
	protected static ResourceBundle bundle;
73
74
	/**
75
	 * The resource manager
76
	 */
77
	protected static ResourceManager resources;
78
79
	static {
80
		bundle = ResourceBundle.getBundle(RESOURCES, Locale.getDefault());
81
		resources = new ResourceManager(bundle);
82
	}
83
84
	/**
85
	 * The button factory.
86
	 */
87
	protected ButtonFactory bf = new ButtonFactory(bundle, this);
88
89
	/**
90
	 * The menu factory.
91
	 */
92
	protected MenuFactory mf = new MenuFactory(bundle, this);
93
94
	private Box consoleList;
95
96
	private ButtonGroup errorGroup;
97
98
	private int displayType;
99
100
	private boolean sortOrderAscending = true;
101
102
	private JPopupMenu popupMenu;
103
104
	public ErrorConsole(Throwable th, int type) {
105
		this(th, null, type);
106
	}
107
108
	public ErrorConsole(Throwable th, String uri, int type) {
109
		super(new BorderLayout());
110
111
		actions.put("DisplayAllButtonAction", new DisplayAllButtonAction());
112
		actions.put("DisplayErrorsButtonAction",
113
				new DisplayErrorsButtonAction());
114
		actions.put("DisplayWarningsButtonAction",
115
				new DisplayWarningsButtonAction());
116
		actions.put("DisplayMessagesButtonAction",
117
				new DisplayMessagesButtonAction());
118
		actions.put("ClearButtonAction", new ClearButtonAction());
119
120
		actions.put("FirstLastSortMenuAction", new FirstLastSortMenuAction());
121
		actions.put("LastFirstSortMenuAction", new LastFirstSortMenuAction());
122
		actions.put("CopyMenuAction", new CopyMenuAction());
123
124
		JPanel errorPanel = new JPanel(new BorderLayout());
125
		errorPanel.setBackground(Color.white);
126
127
		JScrollPane errorScrollPane = new JScrollPane(errorPanel);
128
		add(errorScrollPane);
129
130
		errorGroup = new ButtonGroup();
131
132
		consoleList = new Box(BoxLayout.Y_AXIS);
133
		errorPanel.add(consoleList, BorderLayout.NORTH);
134
135
		popupMenu = createPopupMenu();
136
137
		add(createToolBar(), BorderLayout.NORTH);
138
		add(th, uri, type);
139
		setPreferredSize(new Dimension(550, 400));
140
	}
141
142
	private JToolBar createToolBar() {
143
		JToolBar toolbar = new JToolBar();
144
		toolbar.setFloatable(false);
145
146
		BooleanButtonGroup displayGroup = new BooleanButtonGroup();
147
148
		JToggleButton displayAll = bf
149
				.createJToolbarToggleButton("DisplayAllButton");
150
		displayGroup.add(displayAll);
151
		displayAll.setSelected(true);
152
		displayType(-1, true);
153
		toolbar.add(displayAll);
154
155
		JToggleButton displayErrors = bf
156
				.createJToolbarToggleButton("DisplayErrorsButton");
157
		displayGroup.addOr(displayErrors);
158
		toolbar.add(displayErrors);
159
160
		JToggleButton displayWarnings = bf
161
				.createJToolbarToggleButton("DisplayWarningsButton");
162
		displayGroup.addOr(displayWarnings);
163
		toolbar.add(displayWarnings);
164
165
		JToggleButton displayMessages = bf
166
				.createJToolbarToggleButton("DisplayMessagesButton");
167
		displayGroup.addOr(displayMessages);
168
		toolbar.add(displayMessages);
169
170
		toolbar.add(new JToolbarSeparator());
171
172
		JButton clear = bf.createJToolbarButton("ClearButton");
173
		displayGroup.add(clear);
174
		toolbar.add(clear);
175
176
		return toolbar;
177
	}
178
179
	private class BooleanButtonGroup extends ButtonGroup implements ItemListener {
180
		
181
		private List orElements = new ArrayList();
182
		
183
		private AbstractButton orButton = new JToggleButton();
184
		
185
		public BooleanButtonGroup() {
186
			orButton.addItemListener(this);
187
			add(orButton);
188
		}
189
		
190
		public void itemStateChanged(ItemEvent e) {
191
			if (e.getSource() == orButton && e.getStateChange() == ItemEvent.DESELECTED) {
192
				for (Iterator i = orElements.iterator(); i.hasNext();) {
193
					AbstractButton button = (AbstractButton)i.next();
194
					button.setSelected(false);
195
				}
196
			} else if (e.getStateChange() == ItemEvent.SELECTED) {
197
				setSelected(((AbstractButton)e.getSource()).getModel(), true);
198
			}
199
		}
200
201
		public void addOr(AbstractButton button) {
202
			orElements.add(button);
203
			button.addItemListener(this);
204
		}
205
		
206
		public void setSelected(ButtonModel model, boolean selected) {
207
			for (Iterator i = orElements.iterator(); i.hasNext();) {
208
				AbstractButton button = (AbstractButton)i.next();
209
				if (button.getModel() == model) {
210
					orButton.setSelected(selected);
211
					return;
212
				}
213
			}
214
			super.setSelected(model, selected);
215
		}
216
	}
217
	
218
	private JPopupMenu createPopupMenu() {
219
		JPopupMenu popupMenu = mf.createJMenu("PopupMenu").getPopupMenu();
220
		return popupMenu;
221
	}
222
223
	public JDialog createDialog(Component owner, String title) {
224
		JDialog dialog = new JDialog(JOptionPane.getFrameForComponent(owner),
225
				title);
226
		dialog.getContentPane().add(this, BorderLayout.CENTER);
227
		dialog.pack();
228
		return dialog;
229
	}
230
231
	public void add(Throwable th, String uri, int type) {
232
		ErrorButton errorButton = new ErrorButton(th, uri, type);
233
		errorButton.setPopupMenu(popupMenu);
234
		consoleList.add(errorButton);
235
		errorGroup.add(errorButton);
236
	}
237
238
	/**
239
	 * The map that contains the actions
240
	 */
241
	protected Map actions = new HashMap();
242
243
	/**
244
	 * Returns the action associated with the given string or null on error
245
	 * 
246
	 * @param key
247
	 *            the key mapped with the action to get
248
	 * @throws MissingListenerException
249
	 *             if the action is not found
250
	 */
251
	public Action getAction(String key) throws MissingListenerException {
252
		return (Action) actions.get(key);
253
	}
254
255
	/**
256
	 * The action associated with the 'All' button.
257
	 */
258
	protected class DisplayAllButtonAction extends AbstractAction {
259
260
		public void actionPerformed(ActionEvent evt) {
261
			displayType(-1, true);
262
		}
263
	}
264
265
	/**
266
	 * The action associated with the 'Errors' button.
267
	 */
268
	protected class DisplayErrorsButtonAction extends AbstractAction {
269
270
		public void actionPerformed(ActionEvent evt) {
271
			boolean selected = ((AbstractButton)evt.getSource()).isSelected();
272
			displayType(JOptionPane.ERROR_MESSAGE, selected);
273
		}
274
	}
275
276
	/**
277
	 * The action associated with the 'Warnings' button.
278
	 */
279
	protected class DisplayWarningsButtonAction extends AbstractAction {
280
281
		public void actionPerformed(ActionEvent evt) {
282
			boolean selected = ((AbstractButton)evt.getSource()).isSelected();
283
			displayType(JOptionPane.WARNING_MESSAGE, selected);
284
		}
285
	}
286
287
	/**
288
	 * The action associated with the 'Messages' button.
289
	 */
290
	protected class DisplayMessagesButtonAction extends AbstractAction {
291
292
		public void actionPerformed(ActionEvent evt) {
293
			boolean selected = ((AbstractButton)evt.getSource()).isSelected();
294
			displayType(JOptionPane.INFORMATION_MESSAGE, selected);
295
		}
296
	}
297
298
	/**
299
	 * The action associated with the 'Clear' button.
300
	 */
301
	protected class ClearButtonAction extends AbstractAction {
302
303
		public void actionPerformed(ActionEvent evt) {
304
			clearType(displayType);
305
			Enumeration<AbstractButton> buttons = errorGroup.getElements();
306
			while (buttons.hasMoreElements()) {
307
				errorGroup.remove(buttons.nextElement());
308
			}
309
		}
310
	}
311
312
	/**
313
	 * The action associated with the 'First to Last Sort' menu item.
314
	 */
315
	protected class FirstLastSortMenuAction extends AbstractAction {
316
317
		public void actionPerformed(ActionEvent evt) {
318
			if (sortOrderAscending) {
319
				return;
320
			}
321
			reverseComponentOrder(consoleList);
322
			sortOrderAscending = true;
323
		}
324
	}
325
326
	/**
327
	 * The action associated with the 'Last to First Sort' menu item.
328
	 */
329
	protected class LastFirstSortMenuAction extends AbstractAction {
330
331
		public void actionPerformed(ActionEvent evt) {
332
			if (!sortOrderAscending) {
333
				return;
334
			}
335
			reverseComponentOrder(consoleList);
336
			sortOrderAscending = false;
337
		}
338
	}
339
340
	private void reverseComponentOrder(Container container) {
341
		Component[] components = container.getComponents();
342
		consoleList.removeAll();
343
		for (int i = components.length - 1; i >= 0; i--) {
344
			consoleList.add(components[i]);
345
		}
346
	}
347
348
	/**
349
	 * The action associated with the 'Copy' menu item.
350
	 */
351
	protected class CopyMenuAction extends AbstractAction {
352
353
		public void actionPerformed(ActionEvent evt) {
354
355
		}
356
	}
357
358
	private void clearType(int type) {
359
		Component[] components = consoleList.getComponents();
360
		for (int i = 0; i < components.length; i++) {
361
			ErrorButton eb = (ErrorButton) components[i];
362
			if (type < 0 || eb.getType() == type) {
363
				consoleList.remove(eb);
364
			}
365
		}
366
	}
367
368
	private void displayType(int type, boolean visible) {
369
		displayType = type;
370
		Component[] components = consoleList.getComponents();
371
		for (Component c : components) {
372
			ErrorButton eb = (ErrorButton) c;
373
			if (type < 0 || (eb.getType() == type)) {
374
				eb.setVisible(visible);
375
			}
376
		}
377
	}
378
379
	private class ErrorButton extends JToggleButton {
380
381
		private int type;
382
383
		private JTextPane textPane;
384
385
		private Hyperlink link;
386
387
		private ImageIcon icon;
388
389
		private GradientPaint gradient;
390
391
		private JPanel details;
392
393
		private JPopupMenu popupMenu;
394
395
		private ItemListener il = new ItemListener() {
396
			public void itemStateChanged(ItemEvent e) {
397
				if (e.getStateChange() == ItemEvent.SELECTED) {
398
					details.setVisible(true);
399
				} else if (e.getStateChange() == ItemEvent.DESELECTED) {
400
					details.setVisible(false);
401
				} else {
402
					return;
403
				}
404
				repaint();
405
			}
406
		};
407
408
		private MouseListener ml = new MouseAdapter() {
409
			public void mouseClicked(MouseEvent e) {
410
				if (e.getButton() == MouseEvent.BUTTON3) {
411
					popupMenu.show(ErrorButton.this, e.getX(), e.getY());
412
				}
413
			}
414
		};
415
416
		public ErrorButton(Throwable th, String uri, int type) {
417
			this.type = type;
418
419
			setLayout(new BorderLayout(10, 10));
420
			setContentAreaFilled(false);
421
			setBorderPainted(false);
422
			setOpaque(false);
423
			setFocusPainted(false);
424
			setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
425
			addItemListener(il);
426
			addMouseListener(ml);
427
428
			String s;
429
			switch (type) {
430
			case JOptionPane.WARNING_MESSAGE:
431
				s = resources.getString("ErrorButton.warning_icon");
432
				break;
433
			case JOptionPane.INFORMATION_MESSAGE:
434
				s = resources.getString("ErrorButton.message_icon");
435
				break;
436
			case JOptionPane.ERROR_MESSAGE:
437
			default:
438
				s = resources.getString("ErrorButton.error_icon");
439
				break;
440
			}
441
			icon = new ImageIcon(getClass().getResource(s));
442
			add(new JLabel(icon), BorderLayout.WEST);
443
444
			Box centerPane = new Box(BoxLayout.Y_AXIS);
445
			add(centerPane);
446
447
			textPane = new JTextPane();
448
			textPane.setText(th.getMessage());
449
			textPane.setEditable(false);
450
			textPane.setOpaque(false);
451
			textPane.addMouseListener(new MouseAdapter() {
452
				public void mouseClicked(MouseEvent e) {
453
					ErrorButton.this.setSelected(true);
454
				}
455
			});
456
			centerPane.add(textPane, BorderLayout.NORTH);
457
458
			if (uri != null) {
459
				link = new Hyperlink(uri,
460
						new Hyperlink.HyperlinkCallback() {
461
							public void linkClicked(HyperlinkEvent e) {
462
								// new DocumentViewer(doc).setVisible(true);
463
							}
464
						});
465
				centerPane.add(link, BorderLayout.SOUTH);
466
			}
467
468
			details = new JPanel(new BorderLayout());
469
			details.setOpaque(false);
470
			details.setVisible(false);
471
			add(details, BorderLayout.SOUTH);
472
473
			StringWriter sw = new StringWriter();
474
			th.printStackTrace(new PrintWriter(sw));
475
			sw.flush();
476
477
			JTextArea stackTraceText = new JTextArea(sw.toString());
478
			final JScrollPane stackTraceScrollPane = new JScrollPane(
479
					stackTraceText);
480
			stackTraceScrollPane.setVisible(false);
481
			final JButton btnShowDetails = new JButton("Show Details >>");
482
			btnShowDetails.addActionListener(new ActionListener() {
483
				public void actionPerformed(ActionEvent e) {
484
					boolean visible = stackTraceScrollPane.isVisible();
485
					stackTraceScrollPane.setVisible(!visible);
486
					btnShowDetails.setText(visible ? "Show Details >>"
487
							: "<< Hide Details");
488
				}
489
			});
490
			JPanel button = new JPanel(new FlowLayout(FlowLayout.LEADING));
491
			button.setOpaque(false);
492
			button.add(btnShowDetails);
493
			details.add(button, BorderLayout.NORTH);
494
			details.add(stackTraceScrollPane);
495
496
			Dimension dim = getPreferredSize();
497
			gradient = new GradientPaint(0, 0, new Color(217, 226, 234), 0,
498
					2 * dim.height, new Color(193, 207, 221));
499
500
		}
501
502
		public void paintComponent(Graphics g) {
503
			Graphics2D g2 = (Graphics2D) g;
504
			int width = getWidth(), height = getHeight();
505
			g2.setPaint(isSelected() ? gradient : Color.white);
506
			g2.fillRect(0, 0, width, height);
507
			g2.setColor(SystemColor.controlShadow);
508
			g2.drawLine(0, height - 1, width, height - 1);
509
			super.paintComponent(g);
510
		}
511
512
		public int getType() {
513
			return type;
514
		}
515
516
		public void setType(int type) {
517
			this.type = type;
518
			repaint();
519
		}
520
521
		public JPopupMenu getPopupMenu() {
522
			return popupMenu;
523
		}
524
525
		public void setPopupMenu(JPopupMenu popupMenu) {
526
			this.popupMenu = popupMenu;
527
		}
528
	}
529
530
	public static void main(String[] args) {
531
		ErrorConsole ec = new ErrorConsole(new Exception("Test Exception"),
532
				JOptionPane.ERROR_MESSAGE);
533
		ec.add(new Exception("Test Exception"), null, JOptionPane.WARNING_MESSAGE);
534
		ec.add(new Exception("Test Exception"), null, JOptionPane.INFORMATION_MESSAGE);
535
		JDialog d = ec.createDialog(null,
536
				"Error Console 0.1");
537
		d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
538
		d.setVisible(true);
539
	}
540
}
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/resources/org/apache/batik/util/gui/resources/TimelineViewer.properties (+40 lines)
Line 0 Link Here
1
# -----------------------------------------------------------------------------
2
#
3
#   Licensed to the Apache Software Foundation (ASF) under one or more
4
#   contributor license agreements.  See the NOTICE file distributed with
5
#   this work for additional information regarding copyright ownership.
6
#   The ASF licenses this file to You under the Apache License, Version 2.0
7
#   (the "License"); you may not use this file except in compliance with
8
#   the License.  You may obtain a copy of the License at
9
#
10
#       http://www.apache.org/licenses/LICENSE-2.0
11
#
12
#   Unless required by applicable law or agreed to in writing, software
13
#   distributed under the License is distributed on an "AS IS" BASIS,
14
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
#   See the License for the specific language governing permissions and
16
#   limitations under the License.
17
#
18
# The resources for the ErrorConsole
19
#
20
# Author: singh.jasleen@gmail.com
21
# $Id: ErrorConsole.properties 475477 2006-11-15 22:44:28Z cam $
22
# -----------------------------------------------------------------------------
23
24
StartButton.icon     = resources/start.png
25
StartButton.tooltip  = Start
26
27
BackwardButton.icon     = resources/backward.png
28
BackwardButton.tooltip  = Backward
29
30
PlayButton.icon     = resources/play.png
31
PlayButton.tooltip  = Play
32
33
ForwardButton.icon     = resources/forward.png
34
ForwardButton.tooltip  = Forward
35
36
EndButton.icon     = resources/end.png
37
EndButton.tooltip  = End
38
39
ToolBar = StartButton BackwardButton PlayButton ForwardButton \
40
			EndButton
(-)C:/Documents and Settings/fyp24ys/Desktop/batikws/xml-batik/resources/org/apache/batik/util/gui/resources/ErrorConsole.properties (+70 lines)
Line 0 Link Here
1
# -----------------------------------------------------------------------------
2
#
3
#   Licensed to the Apache Software Foundation (ASF) under one or more
4
#   contributor license agreements.  See the NOTICE file distributed with
5
#   this work for additional information regarding copyright ownership.
6
#   The ASF licenses this file to You under the Apache License, Version 2.0
7
#   (the "License"); you may not use this file except in compliance with
8
#   the License.  You may obtain a copy of the License at
9
#
10
#       http://www.apache.org/licenses/LICENSE-2.0
11
#
12
#   Unless required by applicable law or agreed to in writing, software
13
#   distributed under the License is distributed on an "AS IS" BASIS,
14
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
#   See the License for the specific language governing permissions and
16
#   limitations under the License.
17
#
18
# The resources for the ErrorConsole
19
#
20
# Author: singh.jasleen@gmail.com
21
# $Id: ErrorConsole.properties 475477 2006-11-15 22:44:28Z cam $
22
# -----------------------------------------------------------------------------
23
24
Heading.text = SVG Error:
25
26
DisplayAllButton.text     = All
27
DisplayAllButton.icon     = resources/all.png
28
DisplayAllButton.mnemonic = A
29
DisplayAllButton.action   = DisplayAllButtonAction
30
31
DisplayErrorsButton.text     = Errors
32
DisplayErrorsButton.icon     = resources/errors.png
33
DisplayErrorsButton.mnemonic = E
34
DisplayErrorsButton.action   = DisplayErrorsButtonAction
35
36
DisplayWarningsButton.text     = Warnings
37
DisplayWarningsButton.icon     = resources/warnings.png
38
DisplayWarningsButton.mnemonic = W
39
DisplayWarningsButton.action   = DisplayWarningsButtonAction
40
41
DisplayMessagesButton.text     = Messages
42
DisplayMessagesButton.icon     = resources/messages.png
43
DisplayMessagesButton.mnemonic = M
44
DisplayMessagesButton.action   = DisplayMessagesButtonAction
45
46
ClearButton.text     = Clear
47
ClearButton.icon     = resources/clear.png
48
ClearButton.mnemonic = C
49
ClearButton.action   = ClearButtonAction
50
51
ErrorButton.warning_icon = resources/warning-small.png
52
ErrorButton.message_icon = resources/message-small.png
53
ErrorButton.error_icon = resources/error-small.png
54
55
FirstLastSortMenuItem.text     = First > Last Sort Order
56
FirstLastSortMenuItem.type     = ITEM
57
FirstLastSortMenuItem.mnemonic = F
58
59
LastFirstSortMenuItem.text     = Last > First Sort Order
60
LastFirstSortMenuItem.type     = ITEM
61
LastFirstSortMenuItem.mnemonic = L
62
63
CopyMenuItem.text        = Copy (Ctrl+C)
64
CopyMenuItem.type        = ITEM
65
CopyMenuItem.mnemonic    = C
66
CopyMenuItem.accelerator = ctrl C
67
68
PopupMenu = FirstLastSortMenuItem LastFirstSortMenuItem - \
69
            CopyMenuItem
70
PopupMenu.text = ErrorConsolePoupup

Return to bug 42741