001: package com.xoetrope.carousel.wizard;
002:
003: import java.util.Vector;
004:
005: import java.awt.Color;
006: import java.awt.Font;
007: import java.awt.Rectangle;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.awt.event.KeyEvent;
011: import java.awt.event.MouseEvent;
012: import javax.swing.BorderFactory;
013: import javax.swing.JLabel;
014: import javax.swing.JList;
015: import javax.swing.JPanel;
016: import javax.swing.JScrollPane;
017: import javax.swing.JTextArea;
018: import javax.swing.JTextField;
019: import javax.swing.ListSelectionModel;
020: import javax.swing.event.ChangeEvent;
021: import javax.swing.event.ChangeListener;
022:
023: import net.xoetrope.swing.XImage;
024: import net.xoetrope.editor.project.XEditorProject;
025:
026: /**
027: *
028: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
029: * the GNU Public License (GPL), please see license.txt for more details. If
030: * you make commercial use of this software you must purchase a commercial
031: * license from Xoetrope.</p>
032: * <p> $Revision: 1.5 $</p>
033: */
034: public class XFontPanel extends XWizardPanel implements ActionListener,
035: ChangeListener {
036: private boolean isStandalone = false;
037: private XImage imageControl1 = new XImage();
038: private JTextArea jTextArea1 = new JTextArea();
039: private JPanel jPanel1 = new JPanel();
040: private JLabel jLabel1 = new JLabel();
041: private JLabel headlineLabel = new JLabel();
042: private JLabel subHeadingLabel = new JLabel();
043: private JLabel bodyTextLabel = new JLabel();
044: private JLabel captionsLabel = new JLabel();
045: private JLabel codesLabel = new JLabel();
046: private JLabel selectedLabel = null;
047: private Font selectedFont = null;
048: private JScrollPane jScrollPane1 = new JScrollPane();
049:
050: private String fonts[] = { "SanSerif", "Serif", "Monospaced",
051: "Dialog", "DialogInput" };
052: private JList fontList = new JList(fonts);
053: private Font headlineFont = new java.awt.Font("SansSerif", 1, 16);
054: private Font subHeadingFont = new java.awt.Font("SansSerif", 1, 10);
055: private Font bodyTextFont = new java.awt.Font("SansSerif", 0, 10);
056: private Font captionsFont = new java.awt.Font("SansSerif", 1, 9);
057: private Font codesFont = new java.awt.Font("Monospaced", 0, 10);
058: private javax.swing.JCheckBox boldCB = new javax.swing.JCheckBox();
059: private javax.swing.JCheckBox italicCB = new javax.swing.JCheckBox();
060: private JTextField sizeField = new JTextField();
061: private JLabel jLabel2 = new JLabel();
062: private JLabel jLabel3 = new JLabel();
063: private JLabel jLabel4 = new JLabel();
064: private String schemes[] = { "Professional", "Casual",
065: "High Contrast", "System" };
066: private javax.swing.JComboBox schemeList = new javax.swing.JComboBox(
067: schemes);
068:
069: private XEditorProject currentProject;
070:
071: public static final int FONT_HEADING = 0;
072: public static final int FONT_SUBHEADING = 1;
073: public static final int FONT_BODYTEXT = 2;
074: public static final int FONT_CAPTION = 3;
075: public static final int FONT_CODE = 4;
076: public static final int NUM_FONTS_PER_SCHEME = 5;
077:
078: public static final int PROFESSION_SCHEME = 0;
079: public static final int CASUAL_SCHEME = 1;
080: public static final int HIGHCONTRAST_SCHEME = 2;
081: public static final int SYSTEM_SCHEME = 3;
082:
083: Font[] profScheme = { new java.awt.Font("SansSerif", 1, 16), // Heading
084: new java.awt.Font("SansSerif", 1, 10), // Sub heading
085: new java.awt.Font("SansSerif", 0, 10), // Body
086: new java.awt.Font("SansSerif", 2, 10), // Caption
087: new java.awt.Font("Monospaced", 0, 10) // Code
088: };
089:
090: Font[] casualScheme = { new java.awt.Font("Serif", 1, 20), // Heading
091: new java.awt.Font("Serif", 1, 16), // Sub heading
092: new java.awt.Font("Serif", 0, 12), // Body
093: new java.awt.Font("Serif", 2, 10), // Caption
094: new java.awt.Font("Monospaced", 0, 12) // Code
095: };
096:
097: Font[] highContrastScheme = {
098: new java.awt.Font("SansSerif", 1, 20), // Heading
099: new java.awt.Font("SansSerif", 1, 16), // Sub heading
100: new java.awt.Font("SansSerif", 0, 14), // Body
101: new java.awt.Font("SansSerif", 2, 12), // Caption
102: new java.awt.Font("Monospaced", 0, 12) // Code
103: };
104:
105: Font[] systemScheme = { new java.awt.Font("SansSerif", 1, 16), // Heading
106: new java.awt.Font("Dialog", 1, 10), // Sub heading
107: new java.awt.Font("Dialog", 0, 10), // Body
108: new java.awt.Font("Monospaced", 2, 10), // Caption
109: new java.awt.Font("Monospaced", 0, 10) // Code
110: };
111:
112: private Vector wizardFonts;
113: private Vector wizardColours;
114:
115: public XFontPanel(XEditorProject proj, Vector colours,
116: Vector fonts, String name, String panelNumber) {
117: super (name);
118: currentProject = proj;
119:
120: wizardColours = colours;
121: wizardFonts = fonts;
122:
123: try {
124: jbInit(panelNumber);
125: } catch (Exception ex) {
126: ex.printStackTrace();
127: }
128: }
129:
130: void jbInit(String panelNumber) throws Exception {
131: useFontScheme(0);
132: Font font = new java.awt.Font("SansSerif", 0, 11);
133:
134: setLayout(null);
135: imageControl1.setBackground(getBackground());
136: imageControl1.setBounds(new Rectangle(5, 9, 179, 366));
137: imageControl1.setImage(currentProject
138: .getImage("com/xoetrope/carousel/wizard/fonts.jpg"));
139: imageControl1.setBorder(BorderFactory.createEtchedBorder());
140:
141: jTextArea1.setBackground(getBackground());
142: jTextArea1
143: .setText("Step "
144: + panelNumber
145: + ": Choose the fonts for the various types of text used in your catalogue.");
146: jTextArea1.setLineWrap(true);
147: jTextArea1.setWrapStyleWord(true);
148: jTextArea1.setBounds(new Rectangle(190, 10, 400, 39));
149:
150: jPanel1.setBorder(BorderFactory.createEtchedBorder());
151: jPanel1.setBounds(new Rectangle(191, 73, 397, 303));
152: jPanel1.setLayout(null);
153:
154: jLabel1.setText("Schemes");
155: jLabel1.setBounds(new Rectangle(191, 55, 88, 17));
156:
157: headlineLabel
158: .setToolTipText("Click on this text to choose the headline font");
159: headlineLabel.setText("Headline Text");
160: headlineLabel.setBounds(new Rectangle(9, 48, 379, 34));
161: headlineLabel
162: .addMouseListener(new java.awt.event.MouseAdapter() {
163: public void mouseClicked(MouseEvent e) {
164: headlineLabel_mouseClicked(e);
165: }
166: });
167: headlineLabel.setOpaque(true);
168: headlineLabel.setBackground(Color.white);
169: selectedLabel = headlineLabel;
170: selectedFont = headlineFont;
171:
172: subHeadingLabel
173: .setToolTipText("Click on this text to choose the sub heading font");
174: subHeadingLabel.setText("Sub headings");
175: subHeadingLabel.setBounds(new Rectangle(9, 85, 302, 20));
176: subHeadingLabel
177: .addMouseListener(new java.awt.event.MouseAdapter() {
178: public void mouseClicked(MouseEvent e) {
179: subHeadingLabel_mouseClicked(e);
180: }
181: });
182:
183: bodyTextLabel
184: .setToolTipText("Click on this text to choose the body text font");
185: bodyTextLabel.setText("Body Text");
186: bodyTextLabel.setBounds(new Rectangle(9, 108, 355, 20));
187: bodyTextLabel
188: .addMouseListener(new java.awt.event.MouseAdapter() {
189: public void mouseClicked(MouseEvent e) {
190: bodyTextLabel_mouseClicked(e);
191: }
192: });
193:
194: captionsLabel
195: .setToolTipText("Click on this text to choose the captions font");
196: captionsLabel.setText("Captions");
197: captionsLabel.setBounds(new Rectangle(9, 132, 312, 17));
198: captionsLabel
199: .addMouseListener(new java.awt.event.MouseAdapter() {
200: public void mouseClicked(MouseEvent e) {
201: captionsLabel_mouseClicked(e);
202: }
203: });
204:
205: codesLabel
206: .setToolTipText("Click on this text to choose the codes font");
207: codesLabel.setText("Codes");
208: codesLabel.setBounds(new Rectangle(9, 152, 287, 17));
209: codesLabel.addMouseListener(new java.awt.event.MouseAdapter() {
210: public void mouseClicked(MouseEvent e) {
211: codesLabel_mouseClicked(e);
212: }
213: });
214:
215: jScrollPane1.setBounds(new Rectangle(7, 195, 200, 102));
216: fontList.setToolTipText("Click here to choose the font family");
217: fontList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
218: fontList.addKeyListener(new java.awt.event.KeyAdapter() {
219: public void keyReleased(KeyEvent e) {
220: fontList_keyReleased(e);
221: }
222: });
223: fontList.addMouseListener(new java.awt.event.MouseAdapter() {
224: public void mouseClicked(MouseEvent e) {
225: fontList_mouseClicked(e);
226: }
227: });
228:
229: boldCB.setToolTipText("Click to choose an bold font");
230: boldCB.setText("Bold");
231: boldCB.setBounds(new Rectangle(242, 190, 90, 25));
232: boldCB.addActionListener(new java.awt.event.ActionListener() {
233: public void actionPerformed(ActionEvent e) {
234: boldCB_actionPerformed(e);
235: }
236: });
237:
238: italicCB.setToolTipText("Click to choose an italic font");
239: italicCB.setText("Italic");
240: italicCB.setBounds(new Rectangle(242, 211, 90, 25));
241: italicCB.addActionListener(new java.awt.event.ActionListener() {
242: public void actionPerformed(ActionEvent e) {
243: italicCB_actionPerformed(e);
244: }
245: });
246:
247: sizeField.setToolTipText("Enter the font size in points here");
248: sizeField.setText("10");
249: sizeField.setBounds(new Rectangle(287, 237, 48, 21));
250: sizeField
251: .addActionListener(new java.awt.event.ActionListener() {
252: public void actionPerformed(ActionEvent e) {
253: sizeField_actionPerformed(e);
254: }
255: });
256:
257: jLabel2.setText("Size");
258: jLabel2.setBounds(new Rectangle(242, 238, 41, 17));
259: jLabel3.setText("Font");
260: jLabel3.setBounds(new Rectangle(8, 177, 41, 17));
261: jLabel4.setText("Predefined scheme");
262: jLabel4.setBounds(new Rectangle(8, 10, 121, 17));
263: schemeList
264: .setToolTipText("Click here to use a predefined font scheme");
265: schemeList.setBounds(new Rectangle(137, 7, 252, 24));
266: schemeList
267: .addActionListener(new java.awt.event.ActionListener() {
268:
269: public void actionPerformed(ActionEvent e) {
270: schemeList_actionPerformed(e);
271: }
272: });
273: jScrollPane1.getViewport().add(fontList, null);
274:
275: add(imageControl1, null);
276: add(jTextArea1, null);
277: add(jPanel1, null);
278: jPanel1.add(jScrollPane1, null);
279: jPanel1.add(jLabel3, null);
280: jPanel1.add(boldCB, null);
281: jPanel1.add(italicCB, null);
282: jPanel1.add(jLabel2, null);
283: jPanel1.add(sizeField, null);
284: jPanel1.add(subHeadingLabel, null);
285: jPanel1.add(bodyTextLabel, null);
286: jPanel1.add(captionsLabel, null);
287: jPanel1.add(codesLabel, null);
288: jPanel1.add(headlineLabel, null);
289: jPanel1.add(schemeList, null);
290: jPanel1.add(jLabel4, null);
291: add(jLabel1, null);
292:
293: wizardFonts.clear();
294: wizardFonts.add(headlineFont);
295: wizardFonts.add(subHeadingFont);
296: wizardFonts.add(bodyTextFont);
297: wizardFonts.add(captionsFont);
298: wizardFonts.add(codesFont);
299:
300: updatePanel();
301: OutputFontDetails();
302: }
303:
304: public void actionPerformed(ActionEvent evt) {
305: }
306:
307: public void stateChanged(ChangeEvent evt) {
308: }
309:
310: void headlineLabel_mouseClicked(MouseEvent e) {
311: clearLabels();
312: headlineLabel.setOpaque(true);
313: headlineLabel.setBackground(Color.white);
314: selectedLabel = headlineLabel;
315: selectedFont = headlineFont;
316: OutputFontDetails();
317: }
318:
319: void subHeadingLabel_mouseClicked(MouseEvent e) {
320: clearLabels();
321: subHeadingLabel.setOpaque(true);
322: subHeadingLabel.setBackground(Color.white);
323: selectedLabel = subHeadingLabel;
324: selectedFont = subHeadingFont;
325: OutputFontDetails();
326: }
327:
328: void bodyTextLabel_mouseClicked(MouseEvent e) {
329: clearLabels();
330: bodyTextLabel.setOpaque(true);
331: bodyTextLabel.setBackground(Color.white);
332: selectedLabel = bodyTextLabel;
333: selectedFont = bodyTextFont;
334: OutputFontDetails();
335: }
336:
337: void captionsLabel_mouseClicked(MouseEvent e) {
338: clearLabels();
339: captionsLabel.setOpaque(true);
340: captionsLabel.setBackground(Color.white);
341: selectedLabel = captionsLabel;
342: selectedFont = captionsFont;
343: OutputFontDetails();
344: }
345:
346: void codesLabel_mouseClicked(MouseEvent e) {
347: clearLabels();
348: codesLabel.setOpaque(true);
349: codesLabel.setBackground(Color.white);
350: selectedLabel = codesLabel;
351: selectedFont = codesFont;
352: OutputFontDetails();
353: }
354:
355: void clearLabels() {
356: Color clr = getBackground();
357: headlineLabel.setBackground(clr);
358: subHeadingLabel.setBackground(clr);
359: bodyTextLabel.setBackground(clr);
360: captionsLabel.setBackground(clr);
361: codesLabel.setBackground(clr);
362: }
363:
364: void sizeField_actionPerformed(ActionEvent e) {
365: UpdateSelectedFont();
366: }
367:
368: void italicCB_actionPerformed(ActionEvent e) {
369: UpdateSelectedFont();
370: }
371:
372: void boldCB_actionPerformed(ActionEvent e) {
373: UpdateSelectedFont();
374: }
375:
376: void fontList_mouseClicked(MouseEvent e) {
377: UpdateSelectedFont();
378: }
379:
380: void fontList_keyReleased(KeyEvent e) {
381: UpdateSelectedFont();
382: }
383:
384: void UpdateSelectedFont() {
385: String fontName = fontList.getSelectedValue().toString();
386: int fontStyle = 0;
387:
388: if (boldCB.isSelected())
389: fontStyle |= Font.BOLD;
390: if (italicCB.isSelected())
391: fontStyle |= Font.ITALIC;
392: int fontSize = new Integer(sizeField.getText()).intValue();
393:
394: Font newFont = new Font(fontName, fontStyle, fontSize);
395: if (selectedFont == headlineFont) {
396: headlineFont = newFont;
397: selectedFont = headlineFont;
398: } else if (selectedFont == subHeadingFont) {
399: subHeadingFont = newFont;
400: selectedFont = subHeadingFont;
401: } else if (selectedFont == bodyTextFont) {
402: bodyTextFont = newFont;
403: selectedFont = bodyTextFont;
404: } else if (selectedFont == captionsFont) {
405: captionsFont = newFont;
406: selectedFont = captionsFont;
407: } else if (selectedFont == codesFont) {
408: codesFont = newFont;
409: codesFont = headlineFont;
410: }
411:
412: selectedLabel.setFont(selectedFont);
413: selectedLabel.repaint();
414: selectedLabel.setVisible(false);
415: selectedLabel.setVisible(true);
416:
417: wizardFonts.clear();
418: wizardFonts.add(headlineFont);
419: wizardFonts.add(subHeadingFont);
420: wizardFonts.add(bodyTextFont);
421: wizardFonts.add(captionsFont);
422: wizardFonts.add(codesFont);
423: }
424:
425: void OutputFontDetails() {
426: sizeField.setText(Integer.toString(selectedFont.getSize()));
427: int fStyle = selectedFont.getStyle();
428: if ((fStyle & Font.ITALIC) > 0)
429: italicCB.setSelected(true);
430: else
431: italicCB.setSelected(false);
432:
433: if ((fStyle & Font.BOLD) > 0)
434: boldCB.setSelected(true);
435: else
436: boldCB.setSelected(false);
437:
438: String fontname = selectedFont.getFontName();
439: int pos = fontname.indexOf('.');
440: if (pos > 0)
441: fontname = fontname.substring(0, pos);
442: if (fontname.compareTo("sanserif") == 0)
443: fontList.setSelectedIndex(0);
444: else if (fontname.compareTo("serif") == 0)
445: fontList.setSelectedIndex(1);
446: else if (fontname.compareTo("monospaced") == 0)
447: fontList.setSelectedIndex(2);
448: else if (fontname.compareTo("dialog") == 0)
449: fontList.setSelectedIndex(3);
450: else if (fontname.compareTo("dialogInput") == 0)
451: fontList.setSelectedIndex(4);
452: else
453: fontList.setSelectedIndex(0);
454:
455: selectedLabel.setVisible(false);
456: selectedLabel.setVisible(true);
457: }
458:
459: void schemeList_actionPerformed(ActionEvent e) {
460: int selIdx = schemeList.getSelectedIndex();
461: useFontScheme(selIdx);
462: updatePanel();
463: }
464:
465: public void updatePanel() {
466: headlineLabel.setFont((Font) wizardFonts.elementAt(0));
467: subHeadingLabel.setFont((Font) wizardFonts.elementAt(1));
468: bodyTextLabel.setFont((Font) wizardFonts.elementAt(2));
469: captionsLabel.setFont((Font) wizardFonts.elementAt(3));
470: codesLabel.setFont((Font) wizardFonts.elementAt(4));
471:
472: headlineLabel.setVisible(false);
473: headlineLabel.setVisible(true);
474: subHeadingLabel.setVisible(false);
475: subHeadingLabel.setVisible(true);
476: bodyTextLabel.setVisible(false);
477: bodyTextLabel.setVisible(true);
478: captionsLabel.setVisible(false);
479: captionsLabel.setVisible(true);
480: codesLabel.setVisible(false);
481: codesLabel.setVisible(true);
482:
483: refreshComponentColors();
484: }
485:
486: void refreshComponentColors() {
487: headlineLabel.setForeground((Color) wizardColours
488: .elementAt(XColourPanel.COLOR_HEADING));
489: subHeadingLabel.setForeground((Color) wizardColours
490: .elementAt(XColourPanel.COLOR_SUBHEADING));
491: bodyTextLabel.setForeground((Color) wizardColours
492: .elementAt(XColourPanel.COLOR_BODYTEXT));
493: captionsLabel.setForeground((Color) wizardColours
494: .elementAt(XColourPanel.COLOR_CAPTION));
495: codesLabel.setForeground((Color) wizardColours
496: .elementAt(XColourPanel.COLOR_CODE));
497:
498: italicCB.setForeground((Color) wizardColours
499: .elementAt(XColourPanel.COLOR_CAPTION));
500: boldCB.setForeground((Color) wizardColours
501: .elementAt(XColourPanel.COLOR_CAPTION));
502: jLabel2.setForeground((Color) wizardColours
503: .elementAt(XColourPanel.COLOR_CAPTION));
504: jLabel3.setForeground((Color) wizardColours
505: .elementAt(XColourPanel.COLOR_CAPTION));
506: jLabel4.setForeground((Color) wizardColours
507: .elementAt(XColourPanel.COLOR_CAPTION));
508:
509: Color bgColor = (Color) wizardColours
510: .elementAt(XColourPanel.COLOR_BKGROUND);
511: headlineLabel.setBackground(bgColor);
512: subHeadingLabel.setBackground(bgColor);
513: bodyTextLabel.setBackground(bgColor);
514: captionsLabel.setBackground(bgColor);
515: codesLabel.setBackground(bgColor);
516: italicCB.setBackground(bgColor);
517: boldCB.setBackground(bgColor);
518: jPanel1.setBackground(bgColor);
519:
520: jPanel1.setVisible(false);
521: jPanel1.setVisible(true);
522: }
523:
524: void useFontScheme(int idx) {
525: Font[] fontScheme = profScheme;
526: switch (idx) {
527: case PROFESSION_SCHEME:
528: fontScheme = profScheme;
529: break;
530:
531: case CASUAL_SCHEME:
532: fontScheme = casualScheme;
533: break;
534:
535: case HIGHCONTRAST_SCHEME:
536: fontScheme = highContrastScheme;
537: break;
538:
539: case SYSTEM_SCHEME:
540: default:
541: fontScheme = systemScheme;
542: break;
543: }
544:
545: wizardFonts.clear();
546: for (int i = 0; i < NUM_FONTS_PER_SCHEME; i++) {
547: wizardFonts.add(fontScheme[i]);
548: }
549: }
550:
551: public Font getFont(int fntIdx) {
552: return (Font) wizardFonts.elementAt(fntIdx);
553: }
554: }
|