001: /*
002: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
003: *
004: * The program is provided "as is" without any warranty express or
005: * implied, including the warranty of non-infringement and the implied
006: * warranties of merchantibility and fitness for a particular purpose.
007: * IBM will not be liable for any damages suffered by you as a result
008: * of using the Program. In no event will IBM be liable for any
009: * special, indirect or consequential damages or lost profits even if
010: * IBM has been advised of the possibility of their occurrence. IBM
011: * will not be liable for any third party claims against you.
012: */
013: package com.ibm.richtext.swingui;
014:
015: import com.ibm.richtext.textpanel.MTextPanel;
016: import com.ibm.richtext.textpanel.JTextPanel;
017: import com.ibm.richtext.styledtext.MConstText;
018:
019: import java.awt.BorderLayout;
020: import java.awt.Toolkit;
021: import java.awt.datatransfer.Clipboard;
022:
023: import java.awt.event.WindowAdapter;
024: import java.awt.event.WindowEvent;
025:
026: import javax.swing.JFrame;
027: import javax.swing.JMenuBar;
028: import javax.swing.UIManager;
029:
030: import java.awt.Container;
031:
032: /**
033: * JTextFrame is a JFrame containing an editable JTextPanel, a set of standard
034: * menus, and a JTabRuler. This class can be used as-is, but is
035: * primarily intended to be a simple example of how to use the other classes
036: * in this package.
037: * @see com.ibm.richtext.textpanel.JTextPanel
038: * @see SwingMenuBuilder
039: * @see JTabRuler
040: */
041: public final class JTextFrame extends JFrame {
042:
043: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
044: private JTextPanel fTextPanel;
045:
046: /**
047: * Create a new JTextFrame with no text, no title,
048: * and a private clipboard.
049: */
050: public JTextFrame() {
051:
052: super ();
053: init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
054: }
055:
056: /**
057: * Create a new JTextFrame with no text and the given title.
058: * The JTextPanel will use a private clipboard.
059: * @param title the title of this Frame
060: */
061: public JTextFrame(String title) {
062:
063: super (title);
064: init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
065: }
066:
067: /**
068: * Create a new JTextFrame with the given text and title, whose
069: * TextPanel will use the given clipboard.
070: * @param text the initial text in the TextPanel. If null the
071: * TextPanel will initially be empty
072: * @param title the title of this Frame
073: * @param clipboard the Clipboard which the TextPanel will use.
074: * If null the TextPanel will use a private Clipboard
075: */
076: public JTextFrame(MConstText text, String title, Clipboard clipboard) {
077:
078: super (title);
079: init(text, clipboard);
080: }
081:
082: private void init(MConstText text, Clipboard clipboard) {
083:
084: fTextPanel = new JTextPanel(text, clipboard);
085:
086: JTabRuler tabRuler = new JTabRuler(14, 10, fTextPanel);
087:
088: createMenus();
089:
090: Container contentPane = getContentPane();
091: contentPane.setLayout(new BorderLayout());
092: contentPane.add(fTextPanel, "Center");
093: contentPane.add(tabRuler, "North");
094: pack();
095: }
096:
097: private void createMenus() {
098:
099: JMenuBar menuBar = new JMenuBar();
100:
101: SwingMenuBuilder.getInstance().createMenus(menuBar, fTextPanel,
102: this );
103:
104: setJMenuBar(menuBar);
105: }
106:
107: /**
108: * Return the MTextPanel in this frame.
109: */
110: public MTextPanel getTextPanel() {
111:
112: return fTextPanel;
113: }
114:
115: public static void main(String[] args) {
116:
117: String laf = UIManager.getSystemLookAndFeelClassName();
118: if (args.length == 1) {
119: if (args[0].equals("cp")) {
120: laf = UIManager.getCrossPlatformLookAndFeelClassName();
121: }
122: }
123:
124: try {
125: UIManager.setLookAndFeel(laf);
126: } catch (Throwable th) {
127: th.printStackTrace();
128: }
129: JTextFrame frame = new JTextFrame();
130: frame.addWindowListener(new WindowAdapter() {
131: public void windowClosing(WindowEvent e) {
132: System.exit(0);
133: }
134: });
135: frame.setSize(550, 700);
136: frame.show();
137: }
138: }
|