Source Code Cross Referenced for RBUntranslatedPanel.java in  » Internationalization-Localization » RBManager » com » ibm » rbm » gui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Internationalization Localization » RBManager » com.ibm.rbm.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *****************************************************************************
003:         * Copyright (C) 2000-2004, International Business Machines Corporation and  *
004:         * others. All Rights Reserved.                                              *
005:         *****************************************************************************
006:         */
007:        package com.ibm.rbm.gui;
008:
009:        import java.awt.*;
010:        import java.awt.event.*;
011:
012:        import javax.swing.*;
013:        import javax.swing.table.*;
014:
015:        import com.ibm.rbm.*;
016:
017:        /**
018:         * The class used to display untranslated items
019:         */
020:        class RBUntranslatedPanel extends JPanel {
021:            RBManager rbm;
022:            Bundle bundle;
023:            RBManagerGUI listener;
024:
025:            // Components - Bundle
026:            JLabel jLabelUntransTitle;
027:            UntranslatedItemsTableModel untransTableModel;
028:            JTable jTableUntrans;
029:            JScrollPane jScrollPaneUntransTable;
030:
031:            // Components - Bundle Manager
032:            Box mainBox;
033:            JPanel mainPanels[];
034:            JLabel numUntransLabels[];
035:            JScrollPane mainScroll;
036:            JScrollPane listScrolls[];
037:            JList untransLists[];
038:
039:            public RBUntranslatedPanel(RBManagerGUI gui) {
040:                super ();
041:                listener = gui;
042:            }
043:
044:            public void setBundle(Bundle b) {
045:                rbm = null;
046:                if (bundle == null) {
047:                    bundle = b;
048:                    initComponents();
049:                } else if (bundle != b) {
050:                    bundle = b;
051:                    updateComponents();
052:                }
053:            }
054:
055:            public void setManager(RBManager m) {
056:                bundle = null;
057:                if (rbm == null) {
058:                    rbm = m;
059:                    initComponents();
060:                } else if (rbm != m) {
061:                    rbm = m;
062:                    updateComponents();
063:                }
064:            }
065:
066:            public void removeElements() {
067:                if (rbm != null || bundle != null) {
068:                    rbm = null;
069:                    bundle = null;
070:                    initComponents();
071:                }
072:            }
073:
074:            // Marks the selected resource as translated and removes from this view
075:            private void markSelectedResourceAsTranslated() {
076:                if (bundle == null)
077:                    return;
078:                if (jTableUntrans.getSelectedRow() < 0)
079:                    return;
080:                if (jTableUntrans.getModel() instanceof  UntranslatedItemsTableModel) {
081:                    int row = jTableUntrans.getSelectedRow();
082:                    UntranslatedItemsTableModel model = (UntranslatedItemsTableModel) jTableUntrans
083:                            .getModel();
084:                    BundleItem item = model.getBundleItem(row);
085:                    item.setTranslated(true);
086:                    model.update();
087:                }
088:            }
089:
090:            // Removes the selected resource from the resource file
091:            private void deleteSelectedResource() {
092:                if (bundle == null)
093:                    return;
094:                if (jTableUntrans.getSelectedRow() < 0)
095:                    return;
096:                if (jTableUntrans.getModel() instanceof  UntranslatedItemsTableModel) {
097:                    int row = jTableUntrans.getSelectedRow();
098:                    UntranslatedItemsTableModel model = (UntranslatedItemsTableModel) jTableUntrans
099:                            .getModel();
100:                    BundleItem item = model.getBundleItem(row);
101:                    if (item.getParentGroup() != null
102:                            && item.getParentGroup().getParentBundle() != null) {
103:                        Bundle bundle = item.getParentGroup().getParentBundle();
104:                        bundle.removeItem(item.getKey());
105:                    }
106:                    model.update();
107:                }
108:            }
109:
110:            private void printTable() {
111:                PrintJob pjob = getToolkit().getPrintJob(new Frame(),
112:                        "Printing Test", null);
113:
114:                if (pjob != null) {
115:                    Graphics pg = pjob.getGraphics();
116:
117:                    if (pg != null) {
118:                        //jTableUntrans.print(pg);
119:                        Dimension page_dim = pjob.getPageDimension();
120:                        pg.setColor(Color.black);
121:                        int y_off = 50;
122:                        int x_off = 30;
123:                        TableModel model = jTableUntrans.getModel();
124:                        pg.setFont(new Font("SansSerif", Font.BOLD, 14));
125:                        pg.drawString("Untranslated Items:       Page 1",
126:                                x_off, y_off);
127:                        pg.setFont(new Font("SansSerif", Font.PLAIN, 10));
128:
129:                        for (int i = 0; i < model.getRowCount(); i++) {
130:                            if (y_off < page_dim.height - 50) {
131:                                y_off += 15;
132:                                String key = model.getValueAt(i, 0).toString();
133:                                String translation = model.getValueAt(i, 1)
134:                                        .toString();
135:                                pg.drawString(key + " -> " + translation,
136:                                        x_off, y_off);
137:                            }
138:                        }
139:                        pg.dispose(); // flush page
140:                    }
141:                    pjob.end();
142:
143:                }
144:            }
145:
146:            public void initComponents() {
147:                // Initialize components
148:                if (bundle != null) {
149:                    jLabelUntransTitle = new JLabel(bundle.name);
150:                    untransTableModel = new UntranslatedItemsTableModel(bundle);
151:                    jTableUntrans = new JTable(untransTableModel);
152:                    jScrollPaneUntransTable = new JScrollPane(jTableUntrans);
153:
154:                    // Lower panel components
155:                    JPanel lowerPanel = new JPanel();
156:                    JButton deleteButton = new JButton(Resources
157:                            .getTranslation("button_delete_resource"));
158:                    JButton translateButton = new JButton(Resources
159:                            .getTranslation("button_mark_translated"));
160:                    JButton printButton = new JButton(Resources
161:                            .getTranslation("button_print_table"));
162:
163:                    deleteButton
164:                            .setMnemonic(RBManagerMenuBar
165:                                    .getKeyEventKey(Resources
166:                                            .getTranslation("button_delete_resource_trigger")));
167:                    translateButton
168:                            .setMnemonic(RBManagerMenuBar
169:                                    .getKeyEventKey(Resources
170:                                            .getTranslation("button_mark_translated_trigger")));
171:                    lowerPanel
172:                            .setBorder(BorderFactory
173:                                    .createTitledBorder(Resources
174:                                            .getTranslation("languageuntrans_selected_resources_options")));
175:                    lowerPanel.setLayout(new GridLayout(1, 2));
176:
177:                    jTableUntrans
178:                            .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
179:                    jTableUntrans.addMouseListener(listener);
180:
181:                    jLabelUntransTitle.setFont(new Font("SansSerif",
182:                            Font.PLAIN, 18));
183:
184:                    // Add action listeners
185:                    deleteButton.addActionListener(new ActionListener() {
186:                        public void actionPerformed(ActionEvent ev) {
187:                            deleteSelectedResource();
188:                        }
189:                    });
190:                    translateButton.addActionListener(new ActionListener() {
191:                        public void actionPerformed(ActionEvent ev) {
192:                            markSelectedResourceAsTranslated();
193:                        }
194:                    });
195:                    printButton.addActionListener(new ActionListener() {
196:                        public void actionPerformed(ActionEvent ev) {
197:                            printTable();
198:                        }
199:                    });
200:
201:                    removeAll();
202:                    setLayout(new BorderLayout());
203:                    lowerPanel.add(deleteButton);
204:                    lowerPanel.add(translateButton);
205:                    //lowerPanel.add(printButton);
206:                    add(jLabelUntransTitle, BorderLayout.NORTH);
207:                    add(jScrollPaneUntransTable, BorderLayout.CENTER);
208:                    add(lowerPanel, BorderLayout.SOUTH);
209:                } else if (rbm != null) {
210:
211:                    int langCount = 0; // The number of languages with untranslated Items
212:                    for (int i = 0; i < rbm.getBundles().size(); i++) {
213:                        Bundle bundle = (Bundle) rbm.getBundles().elementAt(i);
214:                        if (bundle.getUntranslatedItemsSize() > 0)
215:                            langCount++;
216:                    }
217:
218:                    // Initialize the components
219:                    mainPanels = new JPanel[langCount];
220:                    numUntransLabels = new JLabel[langCount];
221:                    listScrolls = new JScrollPane[langCount];
222:                    untransLists = new JList[langCount];
223:
224:                    mainBox = new Box(BoxLayout.Y_AXIS);
225:                    mainScroll = new JScrollPane(mainBox);
226:                    jLabelUntransTitle = new JLabel(rbm.getBaseClass() + " - "
227:                            + Resources.getTranslation("untranslated_items"));
228:
229:                    // Set component properties
230:                    jLabelUntransTitle.setFont(new Font("SansSerif",
231:                            Font.PLAIN, 18));
232:                    mainBox.add(jLabelUntransTitle);
233:
234:                    int count = 0;
235:                    for (int i = 0; i < rbm.getBundles().size(); i++) {
236:                        Bundle bundle = (Bundle) rbm.getBundles().elementAt(i);
237:                        if (bundle.getUntranslatedItemsSize() > 0) {
238:                            mainPanels[count] = new JPanel();
239:                            mainPanels[count].setLayout(new BorderLayout());
240:                            numUntransLabels[count] = new JLabel(
241:                                    Resources
242:                                            .getTranslation("baseuntrans_untrans_count")
243:                                            + bundle.getUntranslatedItemsSize());
244:                            // TODO: Implement a List Model for this list, remove use of vector
245:                            untransLists[count] = new JList(bundle
246:                                    .getUntranslatedItemsAsVector());
247:                            listScrolls[count] = new JScrollPane(
248:                                    untransLists[count]);
249:
250:                            mainPanels[count].setBorder(BorderFactory
251:                                    .createTitledBorder(BorderFactory
252:                                            .createEtchedBorder(), Resources
253:                                            .getTranslation("baseuntrans_file")
254:                                            + " " + bundle.toString()));
255:                            mainPanels[count].removeAll();
256:                            mainPanels[count].add(numUntransLabels[count],
257:                                    BorderLayout.NORTH);
258:                            mainPanels[count].add(listScrolls[count],
259:                                    BorderLayout.CENTER);
260:
261:                            mainBox.add(Box.createVerticalStrut(5));
262:                            mainBox.add(mainPanels[count]);
263:
264:                            count++;
265:                        }
266:                    }
267:                    mainScroll.setPreferredSize(getSize());
268:                    removeAll();
269:                    add(mainScroll);
270:                } else {
271:                    removeAll();
272:                }
273:            }
274:
275:            public void updateComponents() {
276:                // Update components
277:                if (bundle != null) {
278:                    jLabelUntransTitle.setText(bundle.name);
279:                    untransTableModel.setBundle(bundle);
280:                } else if (rbm != null) {
281:                    initComponents();
282:                } else {
283:                    removeAll();
284:                }
285:            }
286:        }
287:
288:        /**
289:         * The table model for untranslated Items
290:         */
291:
292:        class UntranslatedItemsTableModel extends AbstractTableModel {
293:            Bundle bundle;
294:
295:            public UntranslatedItemsTableModel(Bundle bundle) {
296:                this .bundle = bundle;
297:            }
298:
299:            public void setBundle(Bundle bundle) {
300:                this .bundle = bundle;
301:                update();
302:            }
303:
304:            public int getColumnCount() {
305:                return 3;
306:            }
307:
308:            public int getRowCount() {
309:                return bundle.getUntranslatedItemsSize();
310:            }
311:
312:            public Object getValueAt(int row, int col) {
313:                BundleItem item = bundle.getUntranslatedItem(row);
314:                String retStr = null;
315:
316:                switch (col) {
317:                case 0:
318:                    retStr = item.getKey();
319:                    break;
320:                case 1:
321:                    retStr = item.getTranslation();
322:                    break;
323:                case 2:
324:                    retStr = (item.getParentGroup() == null ? "" : item
325:                            .getParentGroup().getName());
326:                    break;
327:                default:
328:                    retStr = Resources.getTranslation("table_cell_error");
329:                }
330:
331:                return retStr;
332:            }
333:
334:            public String getColumnName(int col) {
335:                if (col == 0)
336:                    return Resources
337:                            .getTranslation("languageuntrans_column_key");
338:                else if (col == 1)
339:                    return Resources
340:                            .getTranslation("languageuntrans_column_translation");
341:                else if (col == 2)
342:                    return Resources
343:                            .getTranslation("languageuntrans_column_group");
344:                else
345:                    return Resources.getTranslation("table_column_error");
346:            }
347:
348:            public BundleItem getBundleItem(int row) {
349:                return bundle.getUntranslatedItem(row);
350:            }
351:
352:            public void update() {
353:                fireTableDataChanged();
354:            }
355:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.