r2064 - in isis-fish/trunk/src/main/java/fr/ifremer/isisfish: ui/simulator ui/widget/renderer util
Author: chatellier Date: 2009-04-03 10:21:13 +0000 (Fri, 03 Apr 2009) New Revision: 2064 Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ToolTipListModelFactory.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/SimpleToolTipComboBoxRenderer.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/SimpleToolTipTableColumnRenderer.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/ToolTipListModel.java isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/DocHelper.java Log: Fix already in place tooltip Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ToolTipListModelFactory.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ToolTipListModelFactory.java 2009-04-02 16:43:31 UTC (rev 2063) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/simulator/ToolTipListModelFactory.java 2009-04-03 10:21:13 UTC (rev 2064) @@ -19,6 +19,21 @@ package fr.ifremer.isisfish.ui.simulator; +import static org.codelutin.i18n.I18n._; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import javax.swing.JButton; +import javax.swing.JList; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import fr.ifremer.isisfish.datastore.AnalysePlanStorage; import fr.ifremer.isisfish.datastore.ExportStorage; import fr.ifremer.isisfish.datastore.RuleStorage; @@ -29,23 +44,13 @@ import fr.ifremer.isisfish.util.Doc; import fr.ifremer.isisfish.util.DocHelper; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import static org.codelutin.i18n.I18n.*; - -import javax.swing.JButton; -import javax.swing.JList; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - /** * This is a factory of {@link ToolTipListModel} used in simulator ui * * @author chemit + * @version $Revision$ + * + * Mise a jour: $Date$ */ public class ToolTipListModelFactory { @@ -219,23 +224,24 @@ * the param in the Rule</li> * </ul> * - * @param rules the selected rules (we only use the first one) + * @param ruleName the selected rule name (we only use the first one) * @return the model builded */ - public static ToolTipListModel createRuleParamsModel(String rules) { - System.out.println("createRuleParamsModel for rules : " + rules); + public static ToolTipListModel createRuleParamsModel(String ruleName) { + + if (log.isDebugEnabled()) { + log.debug("createRuleParamsModel for rules : " + ruleName); + } List<String> texts = new ArrayList<String>(); List<String> toolTips = new ArrayList<String>(); - if (rules == null || rules.equals("")) { + if (StringUtils.isEmpty(ruleName)) { return new ToolTipListModel(texts, toolTips); } - String name = RuleStorage.getName(rules); try { - - RuleStorage storage = RuleStorage.getRule(name); + RuleStorage storage = RuleStorage.getRule(ruleName); Map<String, Class> mapParams = storage.getParameterNames(); if (!mapParams.isEmpty()) { @@ -247,7 +253,7 @@ } } catch (Exception eee) { if (log.isWarnEnabled()) { - log.warn(_("isisfish.error.obtain.field", name), eee); + log.warn(_("isisfish.error.obtain.field", ruleName), eee); } } return new ToolTipListModel(texts, toolTips); Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/SimpleToolTipComboBoxRenderer.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/SimpleToolTipComboBoxRenderer.java 2009-04-02 16:43:31 UTC (rev 2063) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/SimpleToolTipComboBoxRenderer.java 2009-04-03 10:21:13 UTC (rev 2064) @@ -1,12 +1,32 @@ +/* *##% + * Copyright (C) 2005 - 2009 + * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + package fr.ifremer.isisfish.ui.widget.renderer; +import java.awt.Color; import java.awt.Component; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.ListCellRenderer; /** - * Simple implementation of {@link ToolTipTableColumnRenderer} renderer + * Simple implementation of {@link ListCellRenderer} renderer * with a cache to store text and tooltip to be displayed. * <p/> * <p/> @@ -14,21 +34,25 @@ * <p/> * Internal cache will be based on two list (one for text, and one for doc) * <p/> - * <b>This is a swixat extends, so just for swixat...</b> * * @author chemit - * @see ToolTipListRenderer * @see ToolTipListModel */ -public class SimpleToolTipComboBoxRenderer extends JLabel implements ListCellRenderer { +public class SimpleToolTipComboBoxRenderer extends JLabel implements + ListCellRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = 6435245208150840312L; + /** the model to use */ protected ToolTipListModel model; - public SimpleToolTipComboBoxRenderer(ToolTipListModel model){ + public SimpleToolTipComboBoxRenderer(ToolTipListModel model) { this.model = model; } + /** - * set the model to use + * Set the model to use. * * @param model the mode to use */ @@ -36,30 +60,21 @@ this.model = model; } - /** - * @param value model contrete value - * @param index index of the row - * @return the text to display (this is a pre-computed value) - */ - public String getText(Object value, int index) { - return model == null ? null : model.getText(index); - } - - /** - * @param value model concret object - * @param index index of the row - * @param text the text to be displayed - * @return the tooltip to display (this is a pre-computed value) - */ - public String getToolTip(Object value, int index, String text) { - return model == null ? null : model.getToolTipText(index); - } - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { String toolTip = model.getToolTipText(index); setToolTipText(toolTip); setText(value.toString()); + if(isSelected) { + setBackground(list.getSelectionBackground()); + setForeground(list.getSelectionForeground()); + super.setOpaque(true); // background won't work + } + else { + setBackground(list.getBackground()); + setForeground(list.getForeground()); + } return this; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/SimpleToolTipTableColumnRenderer.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/SimpleToolTipTableColumnRenderer.java 2009-04-02 16:43:31 UTC (rev 2063) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/SimpleToolTipTableColumnRenderer.java 2009-04-03 10:21:13 UTC (rev 2064) @@ -1,13 +1,33 @@ +/* *##% + * Copyright (C) 2005 - 2009 + * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + package fr.ifremer.isisfish.ui.widget.renderer; -import fr.ifremer.isisfish.ui.widget.editor.GenericCell; +import java.awt.Color; import java.awt.Component; + import javax.swing.JLabel; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; /** - * Simple implementation of {@link ToolTipTableColumnRenderer} renderer + * Simple implementation of {@link TableCellRenderer} renderer * with a cache to store text and tooltip to be displayed. * <p/> * <p/> @@ -15,19 +35,23 @@ * <p/> * Internal cache will be based on two list (one for text, and one for doc) * <p/> - * <b>This is a swixat extends, so just for swixat...</b> * * @author chemit - * @see ToolTipListRenderer * @see ToolTipListModel */ -public class SimpleToolTipTableColumnRenderer extends JLabel implements TableCellRenderer { - /** the model to use */ +public class SimpleToolTipTableColumnRenderer extends JLabel implements + TableCellRenderer { + + /** serialVersionUID. */ + private static final long serialVersionUID = 8016432041908541106L; + + /** The model to use */ protected ToolTipListModel model; - public SimpleToolTipTableColumnRenderer(ToolTipListModel model){ + public SimpleToolTipTableColumnRenderer(ToolTipListModel model) { this.model = model; } + /** * set the model to use * @@ -37,30 +61,22 @@ this.model = model; } - /** - * @param value model contrete value - * @param index index of the row - * @return the text to display (this is a pre-computed value) - */ - public String getText(Object value, int index) { - return model == null ? null : model.getText(index); - } - - /** - * @param value model concret object - * @param index index of the row - * @param text the text to be displayed - * @return the tooltip to display (this is a pre-computed value) - */ - public String getToolTip(Object value, int index, String text) { - return model == null ? null : model.getToolTipText(index); - } - @Override - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - String toolTip = model.getToolTipText(column); + public Component getTableCellRendererComponent(JTable table, Object value, + boolean isSelected, boolean hasFocus, int row, int column) { + String toolTip = model.getToolTipText(row); setToolTipText(toolTip); setText(value.toString()); + if(isSelected) { + setBackground(table.getSelectionBackground()); + setForeground(table.getSelectionForeground()); + super.setOpaque(true); // background won't work + } + else { + setBackground(table.getBackground()); + setForeground(table.getForeground()); + } + return this; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/ToolTipListModel.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/ToolTipListModel.java 2009-04-02 16:43:31 UTC (rev 2063) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/ui/widget/renderer/ToolTipListModel.java 2009-04-03 10:21:13 UTC (rev 2064) @@ -1,3 +1,22 @@ +/* *##% + * Copyright (C) 2005 - 2009 + * Ifremer, Code Lutin, Cedric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + package fr.ifremer.isisfish.ui.widget.renderer; import java.util.List; @@ -2,2 +21,10 @@ +/** + * ToolTipListModel. + * + * @author chemit + * @version $Revision$ + * + * Mise a jour: $Date$ + */ public class ToolTipListModel { @@ -13,29 +40,31 @@ /** cache of tooltip */ protected List<String> tooltips; - public ToolTipListModel(List<String> texts, List<String> tooltips) { - this(texts,tooltips,null); + this(texts, tooltips, null); } - public ToolTipListModel(List<String> texts, List<String> tooltips, List objects) { + public ToolTipListModel(List<String> texts, List<String> tooltips, + List objects) { this.texts = texts; this.tooltips = tooltips; - this.objects=objects; + this.objects = objects; } public String getText(int index) { - return texts == null || index < 0 || texts.size() <= index ? null : texts.get(index); + return texts == null || index < 0 || texts.size() <= index ? null + : texts.get(index); } public String getToolTipText(int index) { - return tooltips == null || index < 0 || tooltips.size() <= index ? null : tooltips.get(index); + return tooltips == null || index < 0 || tooltips.size() <= index ? null + : tooltips.get(index); } public int getIndex(Object value) { int result = -1; if (objects != null) { - result = objects.indexOf(value); + result = objects.indexOf(value); } return result; } Modified: isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/DocHelper.java =================================================================== --- isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/DocHelper.java 2009-04-02 16:43:31 UTC (rev 2063) +++ isis-fish/trunk/src/main/java/fr/ifremer/isisfish/util/DocHelper.java 2009-04-03 10:21:13 UTC (rev 2064) @@ -1,3 +1,22 @@ +/* *##% + * Copyright (C) 2007 - 2009 + * Ifremer, Code Lutin, Cédric Pineau, Benjamin Poussin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + package fr.ifremer.isisfish.util; import static org.codelutin.i18n.I18n._; @@ -57,8 +76,8 @@ f = klazz == null ? null : klazz.getField(fieldName); } catch (NoSuchFieldException e) { // should never appear - log.warn(_("isisfish.error.not.found.field.class", - fieldName, klazz)); + log.warn(_("isisfish.error.not.found.field.class", fieldName, + klazz)); //throw new IsisFishRuntimeException(e); } return f == null ? null : f.getAnnotation(Doc.class); @@ -102,10 +121,10 @@ */ public static String asString(Doc doc) { StringBuilder sb = new StringBuilder(); - if (doc == null) return ""; - if (!"".equals(doc.value())) { - sb.append('\'').append(doc.value()).append('\''); + if (doc == null) { + return ""; } + sb.append(doc.value()); boolean more = false; StringBuilder sb2 = new StringBuilder(); if (!"".equals(doc.author())) { @@ -120,10 +139,10 @@ sb2.append(", version: ").append(doc.version()); more = true; } - if (more) + if (more) { sb.append(" <").append(sb2.toString().substring(2)).append(">"); + } return sb.toString(); } - }
participants (1)
-
chatellier@users.labs.libre-entreprise.org