- Timestamp:
- 2005-02-07T10:36:51+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gems/GEMSPreferences.java
r8932 r8971 35 35 import javax.swing.*; 36 36 import javax.swing.event.*; 37 import javax.swing.border.*; 37 38 import org.greenstone.gatherer.Configuration; 38 39 import org.greenstone.gatherer.Dictionary; … … 51 52 static final public String CONNECTION_PREFS = "connection"; 52 53 static final public String GENERAL_PREFS = "general"; 53 54 55 54 static final private Dimension LABEL_SIZE = new Dimension(280, 25); 56 static final private Dimension ROW_SIZE = new Dimension(640, 25);57 55 static final private Dimension SIZE = new Dimension(640, 345); 58 static final private String TRUE = "true"; 59 60 // private CheckList warning_preferences_check_list; 61 private EmailField email_field; 56 57 //private EmailField email_field; 62 58 private JButton apply_button; 63 59 private JButton cancel_button; 64 60 private JButton ok_button; 65 private JCheckBox use_subfields_checkbox; 66 61 67 62 private JCheckBox use_proxy_checkbox; 68 private JCheckBox view_extracted_metadata_checkbox;69 70 63 private JCheckBox workflow_create; 71 64 private JCheckBox workflow_mirror; … … 74 67 private JCheckBox workflow_design; 75 68 private JCheckBox workflow_export; 69 76 70 private JComboBox language_combobox; 77 private JList language_limited_jlist; 78 79 private JComboBox servlet_combobox; // GS380 private JComboBox site_combobox; // GS371 private JList language_limited_jlist; 72 private JList language_code_jlist; 73 private JComboBox servlet_combobox; 74 private JComboBox site_combobox; 81 75 private JLabel interface_language_label; 82 76 private JLabel language_label; 83 private JLabel library_path_label; 84 private JLabel predefined_label; 85 private JLabel program_label; 86 private JLabel proxy_host_label; 87 private JLabel proxy_port_label; 88 private JLabel title_label; 89 private JPanel servlet_pane; 77 90 78 private JRadioButton assistant_mode_radio_button; 91 79 private JRadioButton expert_mode_radio_button; 92 private JRadioButton librarian_mode_radio_button;93 80 private JRadioButton systems_mode_radio_button; 94 81 private JSpinner proxy_port_field; 95 82 private JTabbedPane tab_pane; 96 83 private JTextArea mode_description_textarea; 97 private JTextField library_path_field;98 private JTextField program_field;99 84 private JTextField proxy_host_field; 100 85 private GEMSPreferences self; 101 86 102 87 private String current_site_selection; 88 103 89 public GEMSPreferences() { 104 this(GENERAL_PREFS);105 }106 107 public GEMSPreferences(String initial_view) {108 90 // Initialize 109 91 super(Gatherer.g_man, true); … … 118 100 JPanel general_preferences = createGeneralPreferences(); 119 101 tab_pane.add("Preferences.General", general_preferences); 120 //tab_pane.add("Preferences.Mode", createModePreferences());121 // !! Temporarily disabled for the UNESCO CD-ROM !!122 // tab_pane.add("Preferences.Workflow", createWorkflowPreferences());123 //JPanel connection_preferences = createConnectionPreferences();124 //tab_pane.add("Preferences.Connection", connection_preferences);125 //tab_pane.add("Preferences.Warnings", createWarningPreferences());126 102 127 103 Dictionary.register(tab_pane); … … 155 131 content_pane.add(button_pane, BorderLayout.SOUTH); 156 132 157 Dimension frame_size;// = Gatherer.g_man.getSize();158 Point frame_location;// = Gatherer.g_man.getLocation();159 //setLocation(frame_location.x + ((frame_size.width - SIZE.width) / 2), frame_location.y + ((frame_size.height - SIZE.height)));160 //setLocation(((frame_size.width - SIZE.width) / 2), ((frame_size.height - SIZE.height)));161 133 setLocation(400, 300); 162 163 164 134 tab_pane.setSelectedComponent(general_preferences); 165 166 167 135 168 136 // Clean up 169 137 general_preferences = null; 170 //connection_preferences = null;171 frame_location = null;172 frame_size = null;173 138 cancel_button = null; 174 139 ok_button = null; … … 185 150 // Build the model of available languages 186 151 ArrayList dictionary_model = new ArrayList(); 187 188 // Old method for determining what languages should be available in the combobox189 /*190 dictionary_model.add(new DictionaryEntry(Locale.ENGLISH));191 File classes_folder = new File(Utility.BASE_DIR + StaticStrings.CLASSES_FOLDER);192 File[] possible_dictionaries = classes_folder.listFiles();193 for(int i = 0; i < possible_dictionaries.length; i++) {194 String filename = possible_dictionaries[i].getName();195 if(filename.endsWith(StaticStrings.PROPERTIES_FILE_EXTENSION) && filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) != -1) {196 StringTokenizer tokenizer = new StringTokenizer(filename.substring(filename.indexOf(StaticStrings.UNDERSCORE_CHARACTER) + 1, filename.indexOf(StaticStrings.STOP_CHARACTER)), StaticStrings.UNDERSCORE_CHARACTER);197 Locale locale = null;198 switch(tokenizer.countTokens()) {199 case 1:200 locale = new Locale(tokenizer.nextToken().toLowerCase());201 break;202 case 2:203 locale = new Locale(tokenizer.nextToken().toLowerCase(), tokenizer.nextToken().toUpperCase());204 break;205 }206 tokenizer = null;207 // Open the file and read the first line208 String description = null;209 try {210 BufferedReader br = new BufferedReader(new FileReader(possible_dictionaries[i]));211 String first_line = br.readLine();212 br.close();213 description = first_line.substring(first_line.indexOf(StaticStrings.COLON_CHARACTER) + 1);214 }215 catch(Exception error) {216 }217 DictionaryEntry entry = new DictionaryEntry(description, locale);218 description = null;219 locale = null;220 if(!dictionary_model.contains(entry)) {221 dictionary_model.add(entry);222 }223 entry = null;224 }225 filename = null;226 }227 possible_dictionaries = null;228 classes_folder = null;229 */230 152 231 153 // The new method makes use of the successor to the languages.dat file, classes/xml/languages.xml … … 254 176 interface_language_label.setPreferredSize(LABEL_SIZE); 255 177 256 257 178 Dictionary.registerText(interface_language_label, "GEMS.Preferences.Selected_Languages_Tooltip"); 258 email_field = new EmailField(Configuration.getColor("coloring.error_background", false)); 259 email_field.setText(Configuration.getEmail()); 260 Dictionary.registerTooltip(email_field, "GEMS.Preferences.Selected_Languages_Tooltip"); 261 262 // Extracted metadata 263 264 //Dictionary.registerBoth(view_extracted_metadata_checkbox, "Preferences.General.View_Extracted_Metadata", "Preferences.General.View_Extracted_Metadata_Tooltip"); 265 266 267 // Show file sizes 268 use_subfields_checkbox = new JCheckBox(); 269 JLabel use_subfields_checkbox_label = new JLabel(); 270 use_subfields_checkbox_label.setPreferredSize(new Dimension(225, 30)); 271 use_subfields_checkbox.setSelected(false); 272 use_subfields_checkbox.setVisible(false); 273 use_subfields_checkbox_label.setVisible(false); 274 275 // String blah = Configuration.getString("coloring.workspace_tree_background",true); 276 // System.out.println("before"+ blah); 277 278 if (Configuration.get("GEMS.Preferences.Use_Subelements", true)) { 279 use_subfields_checkbox.setSelected(true); 280 } 281 Dictionary.registerBoth(use_subfields_checkbox_label, "GEMS.Preferences.Use_Subelements", "GEMS.Preferences.Use_Subelements_Tooltip"); 282 179 //email_field = new EmailField(Configuration.getColor("coloring.error_background", false)); 180 //email_field.setText(Configuration.getEmail()); 181 //Dictionary.registerTooltip(email_field, "GEMS.Preferences.Selected_Languages_Tooltip"); 283 182 284 183 // Language … … 286 185 language_label = new JLabel(); 287 186 language_label.setPreferredSize(LABEL_SIZE); 288 289 187 290 188 Dictionary.registerText(language_label, "Preferences.General.Interface_Language"); … … 299 197 } 300 198 } 301 302 //create language_limited_jlist303 //String [] newer = {"blah", "asfd", "dfjdddd", "blee11" ,"asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","asdfsdfsdf", "asdfdsf","safd", "safd", "safd", "safd"};304 305 306 199 307 200 //create language selected box, and high light the apprpropate ones 308 int [] selectedLanguages = new int[300]; 309 int selectedLanguagesLength = 0; 310 311 312 //GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml"); 201 int [] selectedLanguages = new int[300]; 202 int selectedLanguagesLength = 0; 203 204 //GemsLanguageManager gemsLangManager = new GemsLanguageManager("/home/arosmain/gsdl/gli/classes/xml/languages.xml"); 313 205 GEMSLanguageManager gemsLangManager = new GEMSLanguageManager(Configuration.gsdl_path + "/gli/classes/xml/languages.xml"); 314 315 316 language_limited_jlist = new JList(gemsLangManager.getLanguageCodesToArray()); 206 207 //Create the visible JList, and then another one with just the language codes. 208 language_code_jlist = new JList(gemsLangManager.getLanguageCodesToArray()); 209 language_limited_jlist = new JList(gemsLangManager.getLanguageCodesAndNames()); 210 211 //Set the list up to display tabs properly 212 TabListCellRenderer renderer = new TabListCellRenderer(); 213 renderer.setTabs(new int[] {50, 200, 300}); 214 language_limited_jlist.setCellRenderer(renderer); 215 317 216 String enabled_languages = Configuration.getString("GEMS.Preferences.Selected_Languages", true); 318 //we have a string 217 //we have a string: enabled_languages that contains an array of strings delimited by comma's 319 218 String []enabled_languages_split = enabled_languages.split(","); 320 219 Object []language_codes_array = gemsLangManager.getLanguageCodesToArray(); 321 220 322 //System.out.println("before: " +enabled_languages_split[0].toString() + " meh: " + enabled_languages); 323 Vector selected = new Vector(); 324 325 //for each enabled_languages_split 326 //check which languages match, and store the index in selectedLanguages 221 //for each enabled_languages_split, check which languages match, and store the index in selectedLanguages 327 222 for(int k = 0; k < enabled_languages_split.length; k++) { 328 223 … … 331 226 //if the codes match, then include the index p into the vector selectedLanguages 332 227 if (language_codes_array[p].toString().toLowerCase().trim().compareTo(enabled_languages_split[k].toLowerCase().trim()) == 0) 333 { 334 // System.out.println(language_codes_array[p].toString().toLowerCase().trim() + " " + enabled_languages_split[k].toLowerCase().trim()); 335 336 // selected.add(p); 337 selectedLanguages[selectedLanguagesLength] = p; 338 selectedLanguagesLength++; 339 language_limited_jlist.addSelectionInterval(p,p); 340 } 341 342 343 } 344 345 228 { 229 selectedLanguages[selectedLanguagesLength] = p; 230 selectedLanguagesLength++; 231 language_limited_jlist.addSelectionInterval(p,p); 232 } 233 } 346 234 } 347 235 348 //selectedLanguages should contain the indices of the languages that should be selected as349 //stated in enabled_languages350 351 //language_limited_jlist.setSelectedIndices(selectedLanguages);352 // language_limited_jlist.addSelectionInterval(1,1);353 //language_limited_jlist.setSelectedIndex(1);354 355 //because the very first language(index 0) gets chosen no matter what...356 //then I unselected the 0 index, and then check the config file to see if that particular language is357 //indeed selected358 // language_limited_jlist.set359 360 361 362 363 236 // Connect 364 237 language_combobox.addActionListener(new LanguageComboboxListener()); 365 238 366 239 // Layout 367 368 240 JScrollPane langScrollPane = new JScrollPane(language_limited_jlist); 369 370 //langScrollPane.getViewport().setView(language_limited_jlist);371 372 // langScrollPane.setSize(175, 100);373 241 langScrollPane.setPreferredSize(new Dimension(100, 100)); 374 242 lang_limited_pane.setLayout(new GridLayout(1,3)); … … 376 244 lang_limited_pane.add(langScrollPane); 377 245 378 379 246 language_pane.setLayout(new BorderLayout()); 380 247 language_pane.add(language_label, BorderLayout.WEST); … … 382 249 383 250 general_pane.setBorder(org.greenstone.gatherer.gui.BorderFactory.createEmptyBorder(5,5,5,5)); 384 //general_pane.setLayout(new GridLayout(4,1,0,5));385 251 general_pane.setLayout(null); 386 387 general_pane.add(lang_limited_pane); 252 general_pane.add(lang_limited_pane); 388 253 general_pane.add(language_pane); 389 254 //general_pane.add(view_extracted_metadata_checkbox); 390 general_pane.add(use_subfields_checkbox);391 general_pane.add(use_subfields_checkbox_label);392 255 Insets general_pane_insets = general_pane.getInsets(); 393 256 … … 397 260 language_pane.setBounds(20+general_pane_insets.left, 130+general_pane_insets.top, 398 261 language_pane.getPreferredSize().width, language_pane.getPreferredSize().height); 399 400 use_subfields_checkbox_label.setBounds(20+general_pane_insets.left, 200+general_pane_insets.top,401 use_subfields_checkbox_label.getPreferredSize().width, use_subfields_checkbox_label.getPreferredSize().height);402 403 use_subfields_checkbox.setBounds(295+general_pane_insets.left, 200+general_pane_insets.top,404 use_subfields_checkbox.getPreferredSize().width, use_subfields_checkbox.getPreferredSize().height);405 262 406 263 return general_pane; … … 416 273 public void actionPerformed(ActionEvent event) { 417 274 // Submit the various changes 418 // Connection preferences 419 /* String program_str = program_field.getText(); 420 if(program_str.length() > 0 && program_str.indexOf("%1") == -1) { 421 program_str = program_str + " %1"; 422 } 423 Configuration.setPreviewCommand(program_str); 424 425 boolean site_changed = false; 426 if (Gatherer.GS3) { 427 String current_site = Configuration.site_name; 428 String new_site =(String)site_combobox.getSelectedItem() ; 429 if (!new_site.equals(current_site)) { 430 site_changed = true; 431 } 432 Configuration.setSiteAndServlet(new_site, (String)servlet_combobox.getSelectedItem()); 433 } 434 435 Configuration.set("general.use_proxy", true, use_proxy_checkbox.isSelected()); 436 Configuration.setString("general.proxy_host", true, proxy_host_field.getText()); 437 Configuration.setString("general.proxy_port", true, proxy_port_field.getValue() + ""); 438 Gatherer.setProxy(); 439 440 // General preferences 441 Configuration.setEmail(email_field.getText()); 442 443 Configuration.set("general.show_file_size", Configuration.COLLECTION_SPECIFIC, use_subfields_checkbox.isSelected()); 444 // Force both workspace and collection trees to redraw 445 if (Gatherer.g_man != null) { 446 Gatherer.g_man.refreshWorkspaceTree(DragTree.TREE_DISPLAY_CHANGED); 447 Gatherer.g_man.refreshCollectionTree(DragTree.TREE_DISPLAY_CHANGED); 448 } 449 */ 450 //save selected languages list box 451 452 //goes here 453 454 //save subfield checkbox 455 456 Configuration.set("Gems.Preferences.Use_Subelements", true, use_subfields_checkbox.isSelected()); 457 // Gatherer.g_man.enrich_pane.valueChanged((TreeSelectionEvent) null); // Refresh metadata table 458 459 275 460 276 //save interface language 461 277 String current_lang = Configuration.getLanguage(); … … 465 281 } 466 282 467 468 469 //////////////////////save language limited jlist selections 470 471 Vector stringVector = new Vector(); 472 473 Object[] selectedValues = language_limited_jlist.getSelectedValues(); 474 String concatString = new String(); 475 476 for(int k = 0; k < selectedValues.length; k++) { 477 // System.out.println(language_limited_jlist.getComponent(0).toString());//allSelectedLanguages[k] 478 479 //System.out.println(selectedValues[k]); 480 481 if(selectedValues.length-k > 1) 482 concatString = concatString.concat(selectedValues[k].toString() +","); 483 else 484 concatString = concatString.concat(selectedValues[k].toString()); 485 283 //Set language_code_jlist to have the same selections as the language_limited_jlist. 284 //(before, there was only one JList, and it only contained the language codes). 285 int[] selection = language_limited_jlist.getSelectedIndices(); 286 language_code_jlist.setSelectedIndices(selection); 287 Object[] selectedValues = language_code_jlist.getSelectedValues(); 288 String concatString = new String(); 289 290 for(int k = 0; k < selectedValues.length; k++) { 291 if(selectedValues.length-k > 1) 292 concatString = concatString.concat(selectedValues[k].toString() +","); 293 else 294 concatString = concatString.concat(selectedValues[k].toString()); 486 295 } 487 296 488 489 // System.out.println("final cat string: "+ concatString);490 491 492 297 Configuration.setString("GEMS.Preferences.Selected_Languages",true, concatString); 493 298 494 ///////////////////495 /*496 // Mode preferences497 int current_mode = Configuration.getMode();498 int new_mode;499 if(assistant_mode_radio_button.isSelected()) {500 new_mode = Configuration.ASSISTANT_MODE;501 }502 else if(systems_mode_radio_button.isSelected()) {503 new_mode = Configuration.SYSTEMS_MODE;504 }505 else if(expert_mode_radio_button.isSelected()) {506 new_mode = Configuration.EXPERT_MODE;507 }508 else {509 new_mode = Configuration.LIBRARIAN_MODE;510 }511 // If there has been a change in modes, update the config, and also inform the persistant gui views that have a need to know512 if(new_mode != current_mode) {513 Configuration.setMode(new_mode);514 Collection collection = Gatherer.c_man.getCollection();515 if (collection != null) {516 collection.cdm.modeChanged(new_mode);517 }518 Gatherer.g_man.modeChanged(new_mode);519 }520 // Warning preferences521 for(int i = 0; i < warning_preferences_check_list.getEntryCount(); i++) {522 Entry entry = warning_preferences_check_list.get(i);523 Configuration.set(entry.getProperty(), true, entry.isSelected());524 }525 526 if (Gatherer.GS3 && site_changed && Gatherer.c_man.getCollection()!=null) {527 // shut down the collection528 System.err.println("shutting down teh collection");529 Gatherer.g_man.closeCurrentCollection();530 }531 */532 // Workflow preferences533 // Configuration.set("workflow.mirror", false, workflow_mirror.isSelected());534 // Configuration.set("workflow.gather", false, workflow_gather.isSelected());535 // Configuration.set("workflow.enrich", false, workflow_enrich.isSelected());536 // Configuration.set("workflow.design", false, workflow_design.isSelected());537 // Configuration.set("workflow.export", false, workflow_export.isSelected());538 // Configuration.set("workflow.create", false, workflow_create.isSelected());539 // Gatherer.g_man.workflowUpdate("Mirror", workflow_mirror.isSelected());540 // Gatherer.g_man.workflowUpdate("Gather", workflow_gather.isSelected());541 // Gatherer.g_man.workflowUpdate("Enrich", workflow_enrich.isSelected());542 // Gatherer.g_man.workflowUpdate("Design", (workflow_design.isSelected() && Configuration.getMode() > Configuration.ASSISTANT_MODE));543 // Gatherer.g_man.workflowUpdate("Export", workflow_export.isSelected());544 // Gatherer.g_man.workflowUpdate("Create", workflow_create.isSelected());545 546 299 // Always save configuration changes immediately (in case the GLI crashes) 547 300 Configuration.save(); … … 592 345 } 593 346 594 /** This listener updates the mode description depending on what mode is selected. */595 private class ModeRadioButtonListener596 implements ActionListener {597 public void actionPerformed(ActionEvent event) {598 Object source = event.getSource();599 if(source == assistant_mode_radio_button) {600 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Assistant_Description"));601 }602 else if(source == expert_mode_radio_button) {603 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Expert_Description"));604 }605 else if(source == systems_mode_radio_button) {606 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Systems_Description"));607 }608 else {609 mode_description_textarea.setText(Dictionary.get("Preferences.Mode.Librarian_Description"));610 }611 source = null;612 }613 }614 615 private class PredefinedActionListener616 implements ActionListener {617 public void actionPerformed(ActionEvent event) {618 JComboBox cb = (JComboBox) event.getSource();619 WorkflowElementWrapper element = (WorkflowElementWrapper) cb.getSelectedItem();620 CheckboxUpdater task = new CheckboxUpdater(element);621 SwingUtilities.invokeLater(task);622 }623 624 private class CheckboxUpdater625 implements Runnable {626 private WorkflowElementWrapper element;627 public CheckboxUpdater(WorkflowElementWrapper element) {628 this.element = element;629 }630 public void run() {631 workflow_create.setSelected(element.getEnabled("create"));632 workflow_mirror.setSelected(element.getEnabled("mirror"));633 workflow_gather.setSelected(element.getEnabled("gather"));634 workflow_enrich.setSelected(element.getEnabled("enrich"));635 workflow_design.setSelected(element.getEnabled("design"));636 workflow_export.setSelected(element.getEnabled("export"));637 }638 }639 }640 347 641 348 private class LanguageComboboxListener … … 651 358 } 652 359 } 653 654 private class SiteComboboxListener655 implements ActionListener {656 private boolean ignore_event=false;657 public void actionPerformed(ActionEvent event) {658 System.err.println("event occurred "+event.paramString());659 String site = (String) site_combobox.getSelectedItem();660 System.err.println("new site = "+site);661 if (!site.equals(current_site_selection)) {662 current_site_selection = site;663 System.err.println("changed the current selection");664 ArrayList servlet_options = Gatherer.servlet_config.getServletsForSite(current_site_selection);665 if (servlet_options == null) {666 System.err.println("no servlets for this site");667 servlet_combobox.setModel(new DefaultComboBoxModel());668 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip2");669 servlet_combobox.setEnabled(false);670 671 } else {672 System.err.println(ArrayTools.objectArrayToString(servlet_options.toArray()));673 servlet_combobox.setModel(new DefaultComboBoxModel(servlet_options.toArray()));674 Dictionary.registerTooltip(servlet_combobox, "Preferences.Connection.Servlet_Tooltip");675 servlet_combobox.setEnabled(true);676 }677 }678 }679 }680 681 private class UseProxyListener682 implements ActionListener {683 public void actionPerformed(ActionEvent event) {684 boolean enabled = use_proxy_checkbox.isSelected();685 Configuration.set("general.use_proxy", true, enabled);686 // Fortunately this is already driven by the event thread.687 proxy_host_field.setEnabled(enabled);688 proxy_port_field.setEnabled(enabled);689 }690 }691 692 private class WorkflowElementWrapper {693 private Element element;694 private String text;695 public WorkflowElementWrapper(Element element) {696 this.element = element;697 }698 public boolean getEnabled(String name) {699 boolean result = true;700 if(element.getAttribute(name).equalsIgnoreCase("false")) {701 result = false;702 }703 return result;704 }705 public String toString() {706 if(text == null) {707 text = element.getFirstChild().getNodeValue();708 }709 return text;710 }711 }712 360 } 361 362 363 /** 364 A custom list renderer, to display tabs in the JList properly. 365 366 @see http://manning.com/sbe/files/uts2/Chapter10html/Chapter10.htm 367 Added by Matthew Whyte 368 Date last modified: 1/02/05 369 */ 370 class TabListCellRenderer extends JLabel implements ListCellRenderer 371 { 372 protected static Border m_noFocusBorder; 373 protected FontMetrics m_fm = null; 374 protected Insets m_insets = new Insets(0, 0, 0, 0); 375 376 protected int m_defaultTab = 50; 377 protected int[] m_tabs = null; 378 379 public TabListCellRenderer() 380 { 381 super(); 382 m_noFocusBorder = new EmptyBorder(1, 1, 1, 1); 383 setOpaque(true); 384 setBorder(m_noFocusBorder); 385 } 386 387 public Component getListCellRendererComponent(JList list, 388 Object value, int index, boolean isSelected, boolean cellHasFocus) 389 { 390 setText(value.toString()); 391 392 setBackground(isSelected ? list.getSelectionBackground() : list.getBackground()); 393 setForeground(isSelected ? list.getSelectionForeground() : list.getForeground()); 394 395 setFont(list.getFont()); 396 setBorder((cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : m_noFocusBorder); 397 398 return this; 399 } 400 401 public void setDefaultTab(int defaultTab) { m_defaultTab = defaultTab; } 402 403 public int getDefaultTab() { return m_defaultTab; } 404 405 public void setTabs(int[] tabs) { m_tabs = tabs; } 406 407 public int[] getTabs() { return m_tabs; } 408 409 public int getTab(int index) 410 { 411 if (m_tabs == null) 412 return m_defaultTab*index; 413 414 int len = m_tabs.length; 415 if (index >= 0 && index < len) 416 return m_tabs[index]; 417 418 return m_tabs[len-1] + m_defaultTab*(index-len+1); 419 } 420 421 422 public void paint(Graphics g) 423 { 424 m_fm = g.getFontMetrics(); 425 426 g.setColor(getBackground()); 427 g.fillRect(0, 0, getWidth(), getHeight()); 428 getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight()); 429 430 g.setColor(getForeground()); 431 g.setFont(getFont()); 432 m_insets = getInsets(); 433 int x = m_insets.left; 434 int y = m_insets.top + m_fm.getAscent(); 435 436 StringTokenizer st = new StringTokenizer(getText(), "\t"); 437 while (st.hasMoreTokens()) 438 { 439 String sNext = st.nextToken(); 440 g.drawString(sNext, x, y); 441 x += m_fm.stringWidth(sNext); 442 443 if (!st.hasMoreTokens()) 444 break; 445 int index = 0; 446 while (x >= getTab(index)) 447 index++; 448 x = getTab(index); 449 } 450 } 451 }
Note:
See TracChangeset
for help on using the changeset viewer.