View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/LocalizedStringPanel.java,v 1.1 2003/08/10 09:33:18 doballve Exp $ 3 * 4 * ==================================================================== 5 * 6 * This code is subject to the freebxml License, Version 1.1 7 * 8 * Copyright (c) 2003 freebxml.org. All rights reserved. 9 * 10 * ==================================================================== 11 */ 12 package com.sun.xml.registry.client.browser; 13 14 import java.awt.*; 15 import java.awt.event.*; 16 import java.util.*; 17 import javax.swing.*; 18 import javax.swing.DefaultComboBoxModel; 19 import javax.xml.registry.*; 20 import javax.xml.registry.infomodel.*; 21 22 /*** 23 * Panel to edit/inspect a LocalizedString. 24 * 25 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 26 * <a href="mailto:diego.ballve@republica.fi">Diego Ballve</a> 27 */ 28 public class LocalizedStringPanel extends JBPanel { 29 JComboBox localeCombo = null; 30 JTextField charsetText = null; 31 JTextArea valueText = null; 32 33 protected GridBagConstraints c = null; 34 protected GridBagLayout gbl = null; 35 36 37 /*** 38 * Creates new LocalizedStringsPanel 39 */ 40 public LocalizedStringPanel() { 41 setBorder(BorderFactory.createTitledBorder("LocalizedString Details")); 42 43 gbl = new GridBagLayout(); 44 c = new GridBagConstraints(); 45 setLayout(gbl); 46 47 //The name Text 48 JLabel localeLabel = new JLabel("Locale: ", SwingConstants.LEFT); 49 c.gridx = 0; 50 c.gridy = 0; 51 c.gridwidth = 1; 52 c.gridheight = 1; 53 c.weightx = 0.0; 54 c.weighty = 0.0; 55 c.fill = GridBagConstraints.NONE; 56 c.anchor = GridBagConstraints.WEST; 57 c.insets = new Insets(4, 4, 0, 4); 58 gbl.setConstraints(localeLabel, c); 59 add(localeLabel); 60 61 localeCombo = new JComboBox(); 62 localeCombo.setModel(new DefaultComboBoxModel(Locale.getAvailableLocales())); 63 c.gridx = 1; 64 c.gridy = 0; 65 c.gridwidth = 1; 66 c.gridheight = 1; 67 c.weightx = 1; 68 c.weighty = 0.0; 69 c.fill = GridBagConstraints.HORIZONTAL; 70 c.anchor = GridBagConstraints.EAST; 71 c.insets = new Insets(4, 4, 4, 4); 72 gbl.setConstraints(localeCombo, c); 73 add(localeCombo); 74 75 JLabel charsetLabel = new JLabel("Charset: ", SwingConstants.LEFT); 76 c.gridx = 0; 77 c.gridy = 1; 78 c.gridwidth = 1; 79 c.gridheight = 1; 80 c.weightx = 0.0; 81 c.weighty = 0.0; 82 c.fill = GridBagConstraints.NONE; 83 c.anchor = GridBagConstraints.WEST; 84 c.insets = new Insets(4, 4, 0, 4); 85 gbl.setConstraints(charsetLabel, c); 86 add(charsetLabel); 87 88 charsetText = new JTextField(); 89 c.gridx = 1; 90 c.gridy = 1; 91 c.gridwidth = 1; 92 c.gridheight = 1; 93 c.weightx = 1; 94 c.weighty = 0.0; 95 c.fill = GridBagConstraints.HORIZONTAL; 96 c.anchor = GridBagConstraints.WEST; 97 c.insets = new Insets(4, 4, 0, 4); 98 gbl.setConstraints(charsetText, c); 99 add(charsetText); 100 101 JLabel valueLabel = new JLabel("Value:", SwingConstants.LEFT); 102 c.gridx = 0; 103 c.gridy = 2; 104 c.gridwidth = 1; 105 c.gridheight = 1; 106 c.weightx = 0.0; 107 c.weighty = 0.0; 108 c.fill = GridBagConstraints.NONE; 109 c.anchor = GridBagConstraints.WEST; 110 c.insets = new Insets(4, 4, 0, 4); 111 gbl.setConstraints(valueLabel, c); 112 add(valueLabel); 113 114 valueText = new JTextArea(); 115 valueText.setLineWrap(true); 116 valueText.setRows(2); 117 c.gridx = 1; 118 c.gridy = 2; 119 c.gridwidth = 1; 120 c.gridheight = 2; 121 c.weightx = 1; 122 c.weighty = 1; 123 c.fill = GridBagConstraints.BOTH; 124 c.anchor = GridBagConstraints.WEST; 125 c.insets = new Insets(4, 4, 0, 4); 126 gbl.setConstraints(valueText, c); 127 add(valueText); 128 } 129 130 public void setModel(Object obj) throws JAXRException { 131 if (!(obj instanceof LocalizedString)) { 132 throw new InvalidRequestException("Expecting a LocalizedString. Got a " + obj.getClass().getName()); 133 } 134 super.setModel(obj); 135 136 LocalizedString lString = (LocalizedString)obj; 137 138 try { 139 if (lString != null) { 140 Locale lStringLocale = lString.getLocale(); 141 localeCombo.setSelectedItem(lStringLocale); 142 143 String lStringCharset = lString.getCharsetName(); 144 if (lStringCharset != null) { 145 charsetText.setText(lStringCharset); 146 } 147 148 String lStringValue = lString.getValue(); 149 if (lStringValue != null) { 150 valueText.setText(lStringValue); 151 } 152 } 153 } 154 catch (JAXRException e) { 155 RegistryBrowser.displayError(e); 156 } 157 } 158 159 public Object getModel() throws JAXRException { 160 super.getModel(); 161 if (model != null) { 162 LocalizedString lString = (LocalizedString)model; 163 164 lString.setLocale((Locale)localeCombo.getSelectedItem()); 165 166 lString.setCharsetName(charsetText.getText()); 167 168 lString.setValue(valueText.getText()); 169 170 RegistryBrowser.getInstance().getRootPane().updateUI(); 171 } 172 173 return model; 174 } 175 176 protected void validateInput() throws JAXRException { 177 super.validateInput(); 178 179 if (localeCombo.getSelectedItem() == null) { 180 throw new JAXRException("Error. LocalizedString.locale must not be null"); 181 } 182 183 if (charsetText.getText() == null) { 184 throw new JAXRException("Error. LocalizedString.charset must not be null"); 185 } 186 187 if (valueText.getText().length() > 256) { 188 throw new JAXRException("Error. LocalizedString.value length must be <= 256"); 189 } 190 } 191 192 public void clear() throws JAXRException { 193 super.clear(); 194 localeCombo.setSelectedItem(Locale.getDefault()); 195 charsetText.setText(""); 196 valueText.setText(""); 197 } 198 199 200 } 201

This page was automatically generated by Maven