001: package com.xoetrope.carousel.langed;
002:
003: import java.awt.AWTEvent;
004: import java.awt.BorderLayout;
005: import java.awt.Dimension;
006: import java.awt.Insets;
007: import java.awt.Toolkit;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.awt.event.WindowEvent;
011: import javax.swing.BoxLayout;
012: import javax.swing.ImageIcon;
013: import javax.swing.JButton;
014: import javax.swing.JFrame;
015: import javax.swing.JLabel;
016: import javax.swing.JMenuBar;
017: import javax.swing.JPanel;
018: import javax.swing.JToolBar;
019: import javax.swing.border.BevelBorder;
020:
021: /**
022: * <p>Title: LanguageEditor</p>
023: * <p>Description: Language Resource Translation Utility</p>
024: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
025: * the GNU Public License (GPL), please see license.txt for more details. If
026: * you make commercial use of this software you must purchase a commercial
027: * license from Xoetrope.</p>
028: * <p> $Revision: 1.6 $</p>
029: * @author Luan O'Carroll
030: */
031: public class LangFrame extends JFrame implements ActionListener {
032: private JPanel contentPane;
033: private JMenuBar mainMenu = new JMenuBar();
034: private JToolBar toolbar = new JToolBar();
035: private JButton openFileBtn, closeFileBtn, helpBtn, newBtn, cutBtn,
036: copyBtn, pasteBtn, connectBtn;
037: private JButton a2zBtn, z2aBtn, _0to9Btn, _9to0Btn, prevBtn,
038: nextBtn;
039: private JLabel statusBar = new JLabel(
040: " © Xoetrope, 2004-2007. All rights reserved");
041: private LangEdDesktop langDesktop = null;
042: public final static Insets insets0 = new Insets(0, 0, 0, 0);
043: public static boolean isStandalone;
044:
045: //Construct the frame
046: public LangFrame() {
047: setVisible(false);
048: enableEvents(AWTEvent.WINDOW_EVENT_MASK);
049:
050: try {
051: jbInit();
052: } catch (Exception ex) {
053: ex.printStackTrace();
054: }
055: }
056:
057: //Component initialization
058: private void jbInit() throws Exception {
059: toolbar.putClientProperty("JToolBar.isRollover", Boolean.FALSE);
060: toolbar.setBorder(new BevelBorder(BevelBorder.RAISED));
061: newBtn = configureToolbarButton("new.gif", "new");
062: toolbar.addSeparator(new Dimension(5, 5));
063: openFileBtn = configureToolbarButton("open.gif", "Open File");
064: connectBtn = configureToolbarButton("conn.gif", "Connect");
065: closeFileBtn = configureToolbarButton("save.gif", "Close File");
066: toolbar.addSeparator(new Dimension(5, 5));
067: cutBtn = configureToolbarButton("cut.gif", "cut");
068: copyBtn = configureToolbarButton("copy.gif", "copy");
069: pasteBtn = configureToolbarButton("paste.gif", "paste");
070:
071: toolbar.addSeparator(new Dimension(5, 5));
072: a2zBtn = configureToolbarButton("a2z.gif", "Sort A..Z");
073: z2aBtn = configureToolbarButton("z2a.gif", "Sort Z..A");
074: _0to9Btn = configureToolbarButton("_0to9.gif", "Sort 0..9");
075: _9to0Btn = configureToolbarButton("_9to0.gif", "Sort 9..0");
076:
077: toolbar.addSeparator(new Dimension(5, 5));
078: prevBtn = configureToolbarButton("previous.gif",
079: "Previous string (F7)s");
080: nextBtn = configureToolbarButton("next.gif", "Next string (F8)");
081:
082: toolbar.addSeparator(new Dimension(5, 5));
083: helpBtn = configureToolbarButton("help.gif", "Help");
084:
085: if (isStandalone)
086: langDesktop = new LangEdDesktop(null, false, mainMenu,
087: toolbar);
088:
089: setIconImage(Toolkit.getDefaultToolkit()
090: .createImage(
091: LanguageEditorApplication.class
092: .getResource("logo.gif")));
093: mainMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
094:
095: contentPane = (JPanel) getContentPane();
096: contentPane.setLayout(new BorderLayout());
097:
098: setSize(new Dimension(800, 600));
099: setTitle("XTranslator");
100:
101: JPanel p = new JPanel();
102: p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
103:
104: JPanel p0 = (JPanel) p.add(new JPanel(new BorderLayout()));
105: p0.setAlignmentX(LEFT_ALIGNMENT);
106: p0.setAlignmentY(TOP_ALIGNMENT);
107: p0.add(mainMenu, BorderLayout.NORTH);
108:
109: JPanel p1 = (JPanel) p.add(new JPanel());
110: p1.setAlignmentX(LEFT_ALIGNMENT);
111: p1.setAlignmentY(TOP_ALIGNMENT);
112:
113: p1.setLayout(new BorderLayout());
114: p1.add(toolbar, BorderLayout.NORTH);
115:
116: getContentPane().add(p, BorderLayout.NORTH);
117: getContentPane().add(langDesktop);
118:
119: contentPane.add(statusBar, BorderLayout.SOUTH);
120: }
121:
122: public void actionPerformed(ActionEvent evt) {
123: Object src = evt.getSource();
124: if (src == openFileBtn)
125: langDesktop.openFile();
126: else if (src == newBtn)
127: langDesktop.newFile();
128: else if (src == closeFileBtn)
129: langDesktop.saveFile();
130: else if (src == connectBtn)
131: langDesktop.connectToDatabase();
132: else if (src == cutBtn)
133: langDesktop.cut();
134: else if (src == copyBtn)
135: langDesktop.copy();
136: else if (src == pasteBtn)
137: langDesktop.paste();
138: else if (src == a2zBtn)
139: langDesktop.sortA2Z();
140: else if (src == z2aBtn)
141: langDesktop.sortZ2A();
142: else if (src == _0to9Btn)
143: langDesktop.sort0to9();
144: else if (src == _9to0Btn)
145: langDesktop.sort9to0();
146: else if (src == prevBtn)
147: langDesktop.previousComment();
148: else if (src == nextBtn)
149: langDesktop.nextComment();
150: }
151:
152: //File | Exit action performed
153: public void jMenuFileExit_actionPerformed(ActionEvent e) {
154: System.exit(0);
155: }
156:
157: //Overridden so we can exit when window is closed
158: protected void processWindowEvent(WindowEvent e) {
159: super .processWindowEvent(e);
160: if (e.getID() == WindowEvent.WINDOW_CLOSING)
161: jMenuFileExit_actionPerformed(null);
162: }
163:
164: public JButton configureToolbarButton(String iconName, String name) {
165: JButton b = new JButton();
166:
167: try {
168: b.setIcon(new ImageIcon(LanguageEditorApplication.class
169: .getResource(iconName)));
170: } catch (Exception e) {
171: System.out
172: .println("Could not load language editor toolbar image: "
173: + iconName);
174: }
175: toolbar.add(b);
176: b.setToolTipText(name);
177: b.setMargin(insets0);
178: b.getAccessibleContext().setAccessibleName(name);
179: b.addActionListener(this );
180:
181: return b;
182: }
183:
184: public void setStatusText(String text) {
185: statusBar.setText(text);
186: }
187:
188: JButton getHelpBtn() {
189: return helpBtn;
190: }
191: }
|