| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| HistoryInputVerifier |
|
| 0.0;0 |
| 1 | /* |
|
| 2 | * $Id$ |
|
| 3 | * |
|
| 4 | * The contents of this file are subject to the Mozilla Public License |
|
| 5 | * Version 1.1 (the "License"); you may not use this file except in |
|
| 6 | * compliance with the License. You may obtain a copy of the License at |
|
| 7 | * http://www.mozilla.org/MPL/ |
|
| 8 | * |
|
| 9 | * Software distributed under the License is distributed on an "AS IS" basis, |
|
| 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
|
| 11 | * for the specific language governing rights and limitations under the License. |
|
| 12 | * |
|
| 13 | * The Original Code is XML Hammer code. (org.xmlhammer.*) |
|
| 14 | * |
|
| 15 | * The Initial Developer of the Original Code is Edwin Dankert. Portions created |
|
| 16 | * by the Initial Developer are Copyright (C) 2005 - 2006 the Initial Developer. |
|
| 17 | * All Rights Reserved. |
|
| 18 | * |
|
| 19 | * Contributor(s): Edwin Dankert <edankert@gmail.com> |
|
| 20 | */ |
|
| 21 | package org.xmlhammer.gui.history; |
|
| 22 | ||
| 23 | import javax.swing.InputVerifier; |
|
| 24 | import javax.swing.JComponent; |
|
| 25 | ||
| 26 | public class HistoryInputVerifier extends InputVerifier { |
|
| 27 | 7876 | private HistoryComboBox combo = null; |
| 28 | ||
| 29 | 7876 | public HistoryInputVerifier(HistoryComboBox combo) { |
| 30 | 7876 | this.combo = combo; |
| 31 | 7876 | } |
| 32 | ||
| 33 | @Override |
|
| 34 | public boolean verify(JComponent component) { |
|
| 35 | 0 | setValue(); |
| 36 | ||
| 37 | 0 | return true; |
| 38 | } |
|
| 39 | ||
| 40 | public HistoryComboBox getCombo() { |
|
| 41 | 0 | return combo; |
| 42 | } |
|
| 43 | ||
| 44 | protected void setValue() { |
|
| 45 | ||
| 46 | 0 | if (!combo.isEmpty()) { |
| 47 | 0 | Object previous = combo.getSelectedItem(); |
| 48 | 0 | if ( previous != null) { |
| 49 | 0 | previous = previous.toString().trim(); |
| 50 | } |
|
| 51 | ||
| 52 | 0 | HistoryComboBoxModel model = (HistoryComboBoxModel)combo.getModel(); |
| 53 | 0 | String value = combo.getEditor().getItem().toString().trim(); |
| 54 | ||
| 55 | 0 | if ( value != previous && !value.equals(previous)) { |
| 56 | // if ( value != null && value.length() > 0) { |
|
| 57 | 0 | ((HistoryComboBoxEditor)combo.getEditor()).setChangable(false); |
| 58 | ||
| 59 | 0 | model.add(value); |
| 60 | 0 | combo.setSelectedItem(value); |
| 61 | ||
| 62 | 0 | ((HistoryComboBoxEditor)combo.getEditor()).setChangable(true); |
| 63 | ||
| 64 | // if ( value != previous && !value.equals(previous)) { |
|
| 65 | 0 | combo.getEditor().setItem( value); |
| 66 | // } |
|
| 67 | } |
|
| 68 | 0 | } else { |
| 69 | 0 | ((HistoryComboBoxEditor)combo.getEditor()).setChangable(false); |
| 70 | 0 | combo.setSelectedItem(null); |
| 71 | 0 | ((HistoryComboBoxEditor)combo.getEditor()).setChangable(true); |
| 72 | } |
|
| 73 | 0 | } |
| 74 | } |