From: <rh...@us...> - 2014-08-31 19:44:05
|
Revision: 27123 http://sourceforge.net/p/jmri/code/27123 Author: rhwood Date: 2014-08-31 19:44:02 +0000 (Sun, 31 Aug 2014) Log Message: ----------- Whitespace, formatting, JavaDocs, and IDE warnings. Modified Paths: -------------- trunk/jmri/java/src/jmri/jmrit/roster/FunctionLabelPane.java trunk/jmri/java/src/jmri/jmrit/roster/RosterMediaPane.java Modified: trunk/jmri/java/src/jmri/jmrit/roster/FunctionLabelPane.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/roster/FunctionLabelPane.java 2014-08-31 19:30:44 UTC (rev 27122) +++ trunk/jmri/java/src/jmri/jmrit/roster/FunctionLabelPane.java 2014-08-31 19:44:02 UTC (rev 27123) @@ -1,5 +1,4 @@ // FunctionEntryPane.java - package jmri.jmrit.roster; import java.awt.Color; @@ -19,16 +18,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - /** * Display and edit the function labels in a RosterEntry * - * @author Bob Jacobsen Copyright (C) 2008 - * @version $Revision$ + * @author Bob Jacobsen Copyright (C) 2008 + * @author Randall Wood Copyright (C) 2014 */ public class FunctionLabelPane extends javax.swing.JPanel { + RosterEntry re; - + JTextField[] labels; JCheckBox[] lockable; JRadioButton[] shunterMode; @@ -39,31 +38,31 @@ // we're doing a manual allocation of position for // now, based on 28 labels private final int maxfunction = 28; - + public FunctionLabelPane(RosterEntry r) { re = r; - + GridBagLayout gbLayout = new GridBagLayout(); GridBagConstraints cL = new GridBagConstraints(); setLayout(gbLayout); - labels = new JTextField[maxfunction+1]; - lockable = new JCheckBox[maxfunction+1]; - shunterMode = new JRadioButton[maxfunction+1]; + labels = new JTextField[maxfunction + 1]; + lockable = new JCheckBox[maxfunction + 1]; + shunterMode = new JRadioButton[maxfunction + 1]; shunterModeGroup = new ButtonGroup(); - _imageFilePath = new EditableResizableImagePanel[maxfunction+1]; - _imagePressedFilePath = new EditableResizableImagePanel[maxfunction+1]; - + _imageFilePath = new EditableResizableImagePanel[maxfunction + 1]; + _imagePressedFilePath = new EditableResizableImagePanel[maxfunction + 1]; + cL.gridx = 0; cL.gridy = 0; cL.ipadx = 3; cL.anchor = GridBagConstraints.NORTHWEST; - cL.insets = new Insets (0,0,0,15); + cL.insets = new Insets(0, 0, 0, 15); cL.fill = GridBagConstraints.HORIZONTAL; cL.weighty = 1.0; int nextx = 0; - + // first column add(new JLabel(Bundle.getMessage("FunctionButtonN")), cL); cL.gridx++; @@ -90,150 +89,178 @@ cL.gridx++; add(new JLabel(Bundle.getMessage("FunctionButtonShunterFn")), cL); cL.gridx++; - + cL.gridx = 0; cL.gridy = 1; - for (int i = 0; i<=maxfunction; i++) { + for (int i = 0; i <= maxfunction; i++) { // label the row - add(new JLabel(""+i), cL); + add(new JLabel("" + i), cL); cL.gridx++; - + // add the label labels[i] = new JTextField(20); - if (r.getFunctionLabel(i)!=null) labels[i].setText(r.getFunctionLabel(i)); + if (r.getFunctionLabel(i) != null) { + labels[i].setText(r.getFunctionLabel(i)); + } add(labels[i], cL); cL.gridx++; - + // add the checkbox lockable[i] = new JCheckBox(); lockable[i].setSelected(r.getFunctionLockable(i)); add(lockable[i], cL); cL.gridx++; - + // add the function buttons - _imageFilePath[i] = new EditableResizableImagePanel((r.getFunctionImage(i) != null) ? r.getFunctionImage(i) : "", 20, 20); - _imageFilePath[i].setDropFolder(LocoFile.getFileLocation()); - _imageFilePath[i].setBackground(new Color(0,0,0,0)); - _imageFilePath[i].setToolTipText(Bundle.getMessage("FunctionButtonRosterImageToolTip")); - _imageFilePath[i].setBorder(BorderFactory.createLineBorder(java.awt.Color.blue)); + _imageFilePath[i] = new EditableResizableImagePanel((r.getFunctionImage(i) != null) ? r.getFunctionImage(i) : "", 20, 20); + _imageFilePath[i].setDropFolder(LocoFile.getFileLocation()); + _imageFilePath[i].setBackground(new Color(0, 0, 0, 0)); + _imageFilePath[i].setToolTipText(Bundle.getMessage("FunctionButtonRosterImageToolTip")); + _imageFilePath[i].setBorder(BorderFactory.createLineBorder(java.awt.Color.blue)); add(_imageFilePath[i], cL); cL.gridx++; - - _imagePressedFilePath[i] = new EditableResizableImagePanel((r.getFunctionSelectedImage(i) != null) ? r.getFunctionSelectedImage(i) : "", 20, 20); - _imagePressedFilePath[i].setDropFolder(LocoFile.getFileLocation()); - _imagePressedFilePath[i].setBackground(new Color(0,0,0,0)); - _imagePressedFilePath[i].setToolTipText(Bundle.getMessage("FunctionButtonPressedRosterImageToolTip")); - _imagePressedFilePath[i].setBorder(BorderFactory.createLineBorder(java.awt.Color.blue)); - add(_imagePressedFilePath[i], cL); + + _imagePressedFilePath[i] = new EditableResizableImagePanel((r.getFunctionSelectedImage(i) != null) ? r.getFunctionSelectedImage(i) : "", 20, 20); + _imagePressedFilePath[i].setDropFolder(LocoFile.getFileLocation()); + _imagePressedFilePath[i].setBackground(new Color(0, 0, 0, 0)); + _imagePressedFilePath[i].setToolTipText(Bundle.getMessage("FunctionButtonPressedRosterImageToolTip")); + _imagePressedFilePath[i].setBorder(BorderFactory.createLineBorder(java.awt.Color.blue)); + add(_imagePressedFilePath[i], cL); cL.gridx++; - + shunterMode[i] = new JRadioButton(); shunterModeGroup.add(shunterMode[i]); - if ( ("F"+i).compareTo(r.getShuntingFunction()) == 0) - shunterMode[i].setSelected(true); + if (("F" + i).compareTo(r.getShuntingFunction()) == 0) { + shunterMode[i].setSelected(true); + } add(shunterMode[i], cL); cL.gridx++; - + // advance position cL.gridy++; - if (cL.gridy-1 == ((maxfunction+1)/2)+1) { + if (cL.gridy - 1 == ((maxfunction + 1) / 2) + 1) { cL.gridy = 1; // skip titles - nextx = nextx+6; + nextx = nextx + 6; } cL.gridx = nextx; } } - + /** * Do the GUI contents agree with a RosterEntry? + * * @param r * @return true if GUI differs from RosterEntry */ public boolean guiChanged(RosterEntry r) { - if (labels!=null) { - for (int i = 0; i<labels.length; i++) - if (labels[i]!=null) { - if (r.getFunctionLabel(i)==null && !labels[i].getText().equals("")) + if (labels != null) { + for (int i = 0; i < labels.length; i++) { + if (labels[i] != null) { + if (r.getFunctionLabel(i) == null && !labels[i].getText().equals("")) { return true; - if (r.getFunctionLabel(i)!=null && !r.getFunctionLabel(i).equals(labels[i].getText())) + } + if (r.getFunctionLabel(i) != null && !r.getFunctionLabel(i).equals(labels[i].getText())) { return true; + } } + } } - if (lockable!=null) { - for (int i = 0; i<lockable.length; i++) - if (lockable[i]!=null) { - if (r.getFunctionLockable(i) && !lockable[i].isSelected()) + if (lockable != null) { + for (int i = 0; i < lockable.length; i++) { + if (lockable[i] != null) { + if (r.getFunctionLockable(i) && !lockable[i].isSelected()) { return true; - if (!r.getFunctionLockable(i) && lockable[i].isSelected()) + } + if (!r.getFunctionLockable(i) && lockable[i].isSelected()) { return true; + } } + } } - if (_imageFilePath!=null) { - for (int i = 0; i<_imageFilePath.length; i++) - if (_imageFilePath[i]!=null) { - if (r.getFunctionImage(i)==null && !_imageFilePath[i].getImagePath().equals("")) + if (_imageFilePath != null) { + for (int i = 0; i < _imageFilePath.length; i++) { + if (_imageFilePath[i] != null) { + if (r.getFunctionImage(i) == null && !_imageFilePath[i].getImagePath().equals("")) { return true; - if (r.getFunctionImage(i)!=null && !r.getFunctionImage(i).equals(_imageFilePath[i].getImagePath())) + } + if (r.getFunctionImage(i) != null && !r.getFunctionImage(i).equals(_imageFilePath[i].getImagePath())) { return true; + } } + } } - if (_imagePressedFilePath!=null) { - for (int i = 0; i<_imagePressedFilePath.length; i++) - if (_imagePressedFilePath[i]!=null) { - if (r.getFunctionSelectedImage(i)==null && !_imagePressedFilePath[i].getImagePath().equals("")) + if (_imagePressedFilePath != null) { + for (int i = 0; i < _imagePressedFilePath.length; i++) { + if (_imagePressedFilePath[i] != null) { + if (r.getFunctionSelectedImage(i) == null && !_imagePressedFilePath[i].getImagePath().equals("")) { return true; - if (r.getFunctionSelectedImage(i)!=null && !r.getFunctionSelectedImage(i).equals(_imagePressedFilePath[i].getImagePath())) + } + if (r.getFunctionSelectedImage(i) != null && !r.getFunctionSelectedImage(i).equals(_imagePressedFilePath[i].getImagePath())) { return true; + } } + } } - if (shunterMode!=null) { - String shunFn = ""; - for (int i = 0; i<shunterMode.length; i++) { - if ((shunterMode[i]!=null) && (shunterMode[i].isSelected())) - shunFn = "F"+i; - } - if (shunFn.compareTo(r.getShuntingFunction())!=0) - return true; + if (shunterMode != null) { + String shunFn = ""; + for (int i = 0; i < shunterMode.length; i++) { + if ((shunterMode[i] != null) && (shunterMode[i].isSelected())) { + shunFn = "F" + i; + } + } + if (shunFn.compareTo(r.getShuntingFunction()) != 0) { + return true; + } } - return false; + return false; } - - /** + + /** * Fill a RosterEntry object from GUI contents + * * @param r - **/ + * + */ public void update(RosterEntry r) { - if (labels!=null) { - String shunFn = ""; - for (int i = 0; i<labels.length; i++) { - if (labels[i]!=null && !labels[i].getText().equals("")) { - r.setFunctionLabel(i, labels[i].getText()); - r.setFunctionLockable(i, lockable[i].isSelected()); - r.setFunctionImage(i, _imageFilePath[i].getImagePath()); - r.setFunctionSelectedImage(i, _imagePressedFilePath[i].getImagePath()); - } else if (labels[i]!=null && labels[i].getText().equals("")) { - if (r.getFunctionLabel(i) != null) { - r.setFunctionLabel(i, null); - r.setFunctionImage(i, null); - r.setFunctionSelectedImage(i, null); - } - } - if ((shunterMode[i]!=null) && (shunterMode[i].isSelected())) - shunFn = "F"+i; - } - r.setShuntingFunction(shunFn); + if (labels != null) { + String shunFn = ""; + for (int i = 0; i < labels.length; i++) { + if (labels[i] != null && !labels[i].getText().equals("")) { + r.setFunctionLabel(i, labels[i].getText()); + r.setFunctionLockable(i, lockable[i].isSelected()); + r.setFunctionImage(i, _imageFilePath[i].getImagePath()); + r.setFunctionSelectedImage(i, _imagePressedFilePath[i].getImagePath()); + } else if (labels[i] != null && labels[i].getText().equals("")) { + if (r.getFunctionLabel(i) != null) { + r.setFunctionLabel(i, null); + r.setFunctionImage(i, null); + r.setFunctionSelectedImage(i, null); + } + } + if ((shunterMode[i] != null) && (shunterMode[i].isSelected())) { + shunFn = "F" + i; + } + } + r.setShuntingFunction(shunFn); } } public void dispose() { - if (log.isDebugEnabled()) log.debug("dispose"); + if (log.isDebugEnabled()) { + log.debug("dispose"); + } } - - public boolean includeInPrint() { return print; } - public void includeInPrint(boolean inc) { print = inc; } + + public boolean includeInPrint() { + return print; + } + + public void includeInPrint(boolean inc) { + print = inc; + } boolean print = false; - - @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SBSC_USE_STRINGBUFFER_CONCATENATION") + + @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "SBSC_USE_STRINGBUFFER_CONCATENATION") // Only used occasionally, so inefficient String processing not really a problem // though it would be good to fix it if you're working in this area public void printPane(HardcopyWriter w) { @@ -244,20 +271,20 @@ // Define column widths for name and value output. // Make col 2 slightly larger than col 1 and reduce both to allow for // extra spaces that will be added during concatenation - int col1Width = w.getCharactersPerLine()/2 -3 - 5; - int col2Width = w.getCharactersPerLine()/2 -3 + 5; + int col1Width = w.getCharactersPerLine() / 2 - 3 - 5; + int col2Width = w.getCharactersPerLine() / 2 - 3 + 5; try { //Create a string of spaces the width of the first column String spaces = ""; - for (int i=0; i < col1Width; i++) { - spaces = spaces + " "; + for (int i = 0; i < col1Width; i++) { + spaces = spaces + " "; } // start with pane name in bold String heading1 = "Function"; String heading2 = "Description"; String s; - int interval = spaces.length()- heading1.length(); + int interval = spaces.length() - heading1.length(); w.setFontStyle(Font.BOLD); // write the section name and dividing line s = "FUNCTION LABELS"; @@ -265,26 +292,27 @@ w.writeBorders(); //Draw horizontal dividing line for each Pane section w.write(w.getCurrentLineNumber(), 0, w.getCurrentLineNumber(), - w.getCharactersPerLine()+1); + w.getCharactersPerLine() + 1); s = "\n"; - w.write(s,0,s.length()); + w.write(s, 0, s.length()); w.setFontStyle(Font.BOLD + Font.ITALIC); - s = " " + heading1 + spaces.substring(0,interval) + " " + heading2; + s = " " + heading1 + spaces.substring(0, interval) + " " + heading2; w.write(s, 0, s.length()); w.writeBorders(); s = "\n"; - w.write(s,0,s.length()); + w.write(s, 0, s.length()); w.setFontStyle(Font.PLAIN); // index over variables - for (int i=0; i<maxfunction; i++) { - String name = ""+i; - if(re.getFunctionLockable(i)) + for (int i = 0; i < maxfunction; i++) { + String name = "" + i; + if (re.getFunctionLockable(i)) { name = name + " (locked)"; + } String value = re.getFunctionLabel(i); //Skip Blank functions - if (value!=null){ + if (value != null) { //define index values for name and value substrings int nameLeftIndex = 0; @@ -298,54 +326,52 @@ // If so, split it and do the same checks for the Value // Then concatenate the name and value (or the split versions thereof) // before writing - if split, repeat until all pieces have been output - while ((valueLeftIndex < value.length()) || (nameLeftIndex < name.length())){ - // name split code - if (name.substring(nameLeftIndex).length() > col1Width){ - for (int j = 0; j < col1Width; j++) { - String delimiter = name.substring(nameLeftIndex + col1Width - j - 1, - nameLeftIndex + col1Width - j); - if (delimiter.equals(" ") || delimiter.equals(";") || delimiter.equals(",")) { - nameRightIndex = nameLeftIndex + col1Width - j; - break; - } + while ((valueLeftIndex < value.length()) || (nameLeftIndex < name.length())) { + // name split code + if (name.substring(nameLeftIndex).length() > col1Width) { + for (int j = 0; j < col1Width; j++) { + String delimiter = name.substring(nameLeftIndex + col1Width - j - 1, + nameLeftIndex + col1Width - j); + if (delimiter.equals(" ") || delimiter.equals(";") || delimiter.equals(",")) { + nameRightIndex = nameLeftIndex + col1Width - j; + break; + } + } + trimmedName = name.substring(nameLeftIndex, nameRightIndex); + nameLeftIndex = nameRightIndex; + int space = spaces.length() - trimmedName.length(); + s = " " + trimmedName + spaces.substring(0, space); + } else { + trimmedName = name.substring(nameLeftIndex); + int space = spaces.length() - trimmedName.length(); + s = " " + trimmedName + spaces.substring(0, space); + name = ""; + nameLeftIndex = 0; } - trimmedName = name.substring(nameLeftIndex,nameRightIndex); - nameLeftIndex = nameRightIndex; - int space = spaces.length()- trimmedName.length(); - s = " " + trimmedName + spaces.substring(0,space); - } - else { - trimmedName = name.substring(nameLeftIndex); - int space = spaces.length() - trimmedName.length(); - s = " " + trimmedName + spaces.substring(0,space); - name = ""; - nameLeftIndex = 0; - } - // value split code - if (value.substring(valueLeftIndex).length() > col2Width){ - for (int j = 0; j < col2Width; j++){ - String delimiter = value.substring(valueLeftIndex + col2Width - j - 1, valueLeftIndex + col2Width - j); - if (delimiter.equals(" ") || delimiter.equals(";") || delimiter.equals(",")) { - valueRightIndex = valueLeftIndex + col2Width - j; - break; - } + // value split code + if (value.substring(valueLeftIndex).length() > col2Width) { + for (int j = 0; j < col2Width; j++) { + String delimiter = value.substring(valueLeftIndex + col2Width - j - 1, valueLeftIndex + col2Width - j); + if (delimiter.equals(" ") || delimiter.equals(";") || delimiter.equals(",")) { + valueRightIndex = valueLeftIndex + col2Width - j; + break; + } + } + trimmedValue = value.substring(valueLeftIndex, valueRightIndex); + valueLeftIndex = valueRightIndex; + s = s + " " + trimmedValue; + } else { + trimmedValue = value.substring(valueLeftIndex); + s = s + " " + trimmedValue; + valueLeftIndex = 0; + value = ""; } - trimmedValue = value.substring(valueLeftIndex,valueRightIndex); - valueLeftIndex = valueRightIndex; - s= s + " " + trimmedValue; - } - else { - trimmedValue = value.substring(valueLeftIndex); - s = s + " " + trimmedValue; - valueLeftIndex = 0; - value = ""; - } - w.write(s,0,s.length()); - w.writeBorders(); - s = "\n"; - w.write(s,0,s.length()); + w.write(s, 0, s.length()); + w.writeBorders(); + s = "\n"; + w.write(s, 0, s.length()); } - // handle special cases + // handle special cases } } s = "\n"; @@ -353,7 +379,8 @@ w.write(s, 0, s.length()); w.writeBorders(); w.write(s, 0, s.length()); - } catch (IOException e) { log.warn("error during printing: "+e); + } catch (IOException e) { + log.warn("error during printing: " + e); } } Modified: trunk/jmri/java/src/jmri/jmrit/roster/RosterMediaPane.java =================================================================== --- trunk/jmri/java/src/jmri/jmrit/roster/RosterMediaPane.java 2014-08-31 19:30:44 UTC (rev 27122) +++ trunk/jmri/java/src/jmri/jmrit/roster/RosterMediaPane.java 2014-08-31 19:44:02 UTC (rev 27123) @@ -20,268 +20,295 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/* -* <hr> -* This file is part of JMRI. -* <P> -* JMRI is free software; you can redistribute it and/or modify it under -* the terms of version 2 of the GNU General Public License as published -* by the Free Software Foundation. See the "COPYING" file for a copy -* of this license. -* <P> -* JMRI 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. -* <P> -* @author Lionel Jeanson Copyright (C) 2009 -* @version $$ -*/ - /** - * A media pane for roster configuration tool, contains: - * + a selector for roster image (a large image for throttle background...) - * + a selector for roster icon (a small image for list displays...) - * + a selector for roster URL (link to wikipedia page about prototype...) - * + a table displaying user attributes for that locomotive - * - * @author Lionel Jeanson - Copyright 2009 + * A media pane for roster configuration tool. It contains:<ul> + * <li>a selector for roster image (a large image for throttle + * background...)</li> + * <li>a selector for roster icon (a small image for list displays...)</li> + * <li>a selector for roster URL (link to wikipedia page about + * prototype...)</li> + * <li>a table displaying user attributes for that locomotive</li> + * </ul> + * <hr> + * This file is part of JMRI. + * <P> + * JMRI is free software; you can redistribute it and/or modify it under the + * terms of version 2 of the GNU General Public License as published by the Free + * Software Foundation. See the "COPYING" file for a copy of this license. + * <P> + * JMRI 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. + * <P> + * @author Lionel Jeanson Copyright (C) 2009 + * @author Randall Wood Copyright (C) 2014 */ public class RosterMediaPane extends JPanel { - private static final long serialVersionUID = 2420617780437463773L; - JLabel _imageFPlabel = new JLabel(); - EditableResizableImagePanel _imageFilePath; - JLabel _iconFPlabel = new JLabel(); - EditableResizableImagePanel _iconFilePath; - JLabel _URLlabel = new JLabel(); - JTextField _URL = new JTextField(30); - RosterAttributesTableModel rosterAttributesModel; + private static final long serialVersionUID = 2420617780437463773L; + JLabel _imageFPlabel = new JLabel(); + EditableResizableImagePanel _imageFilePath; + JLabel _iconFPlabel = new JLabel(); + EditableResizableImagePanel _iconFilePath; + JLabel _URLlabel = new JLabel(); + JTextField _URL = new JTextField(30); + RosterAttributesTableModel rosterAttributesModel; - final ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrit.roster.JmritRosterBundle"); + final ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrit.roster.JmritRosterBundle"); - public RosterMediaPane(RosterEntry r) { - _imageFilePath = new EditableResizableImagePanel(r.getImagePath(), 320, 240); - _imageFilePath.setDropFolder(LocoFile.getFileLocation()); - _imageFilePath.setToolTipText(rb.getString("MediaRosterImageToolTip")); - _imageFilePath.setBorder(BorderFactory.createLineBorder(Color.blue)); - _imageFPlabel.setText(rb.getString("MediaRosterImageLabel")); + public RosterMediaPane(RosterEntry r) { + _imageFilePath = new EditableResizableImagePanel(r.getImagePath(), 320, 240); + _imageFilePath.setDropFolder(LocoFile.getFileLocation()); + _imageFilePath.setToolTipText(rb.getString("MediaRosterImageToolTip")); + _imageFilePath.setBorder(BorderFactory.createLineBorder(Color.blue)); + _imageFPlabel.setText(rb.getString("MediaRosterImageLabel")); - _iconFilePath = new EditableResizableImagePanel(r.getIconPath(), 160, 120); - _iconFilePath.setDropFolder(LocoFile.getFileLocation()); - _iconFilePath.setToolTipText(rb.getString("MediaRosterIconToolTip")); - _iconFilePath.setBorder(BorderFactory.createLineBorder(Color.blue)); - _iconFPlabel.setText(rb.getString("MediaRosterIconLabel")); + _iconFilePath = new EditableResizableImagePanel(r.getIconPath(), 160, 120); + _iconFilePath.setDropFolder(LocoFile.getFileLocation()); + _iconFilePath.setToolTipText(rb.getString("MediaRosterIconToolTip")); + _iconFilePath.setBorder(BorderFactory.createLineBorder(Color.blue)); + _iconFPlabel.setText(rb.getString("MediaRosterIconLabel")); - _URL.setText(r.getURL()); - _URL.setToolTipText(rb.getString("MediaRosterURLToolTip")); - _URLlabel.setText(rb.getString("MediaRosterURLLabel")); + _URL.setText(r.getURL()); + _URL.setToolTipText(rb.getString("MediaRosterURLToolTip")); + _URLlabel.setText(rb.getString("MediaRosterURLLabel")); - rosterAttributesModel = new RosterAttributesTableModel(r); //t, columnNames); - JTable jtAttributes = new JTable(); - jtAttributes.setModel(rosterAttributesModel); - JScrollPane jsp = new JScrollPane(jtAttributes); + rosterAttributesModel = new RosterAttributesTableModel(r); //t, columnNames); + JTable jtAttributes = new JTable(); + jtAttributes.setModel(rosterAttributesModel); + JScrollPane jsp = new JScrollPane(jtAttributes); // jtAttributes.setFillsViewportHeight(true); // Java 1.6 only + JPanel mediap = new JPanel(); + GridBagLayout gbLayout = new GridBagLayout(); + GridBagConstraints gbc = new GridBagConstraints(); + Dimension textFieldDim = new Dimension(320, 20); + Dimension imageFieldDim = new Dimension(320, 200); + Dimension iconFieldDim = new Dimension(160, 100); + Dimension tableDim = new Dimension(400, 200); + mediap.setLayout(gbLayout); - JPanel mediap = new JPanel(); - GridBagLayout gbLayout = new GridBagLayout(); - GridBagConstraints gbc = new GridBagConstraints(); - Dimension textFieldDim = new Dimension(320,20); - Dimension imageFieldDim = new Dimension(320,200); - Dimension iconFieldDim = new Dimension(160,100); - Dimension tableDim = new Dimension(400,200); - mediap.setLayout(gbLayout); + gbc.insets = new Insets(0, 8, 0, 8); + gbc.gridx = 0; + gbc.gridy = 0; + gbLayout.setConstraints(_imageFPlabel, gbc); + mediap.add(_imageFPlabel); - gbc.insets = new Insets(0, 8, 0, 8); - gbc.gridx = 0; - gbc.gridy = 0; - gbLayout.setConstraints( _imageFPlabel,gbc); - mediap.add( _imageFPlabel); + gbc.gridx = 1; + gbc.gridy = 0; + _imageFilePath.setMinimumSize(imageFieldDim); + _imageFilePath.setMaximumSize(imageFieldDim); + _imageFilePath.setPreferredSize(imageFieldDim); + gbLayout.setConstraints(_imageFilePath, gbc); + mediap.add(_imageFilePath); - gbc.gridx = 1; - gbc.gridy = 0; - _imageFilePath.setMinimumSize(imageFieldDim); - _imageFilePath.setMaximumSize(imageFieldDim); - _imageFilePath.setPreferredSize(imageFieldDim); - gbLayout.setConstraints( _imageFilePath,gbc); - mediap.add( _imageFilePath); + gbc.gridx = 0; + gbc.gridy = 2; + gbLayout.setConstraints(_iconFPlabel, gbc); + mediap.add(_iconFPlabel); - gbc.gridx = 0; - gbc.gridy = 2; - gbLayout.setConstraints( _iconFPlabel,gbc); - mediap.add( _iconFPlabel); + gbc.gridx = 1; + gbc.gridy = 2; + _iconFilePath.setMinimumSize(iconFieldDim); + _iconFilePath.setMaximumSize(iconFieldDim); + _iconFilePath.setPreferredSize(iconFieldDim); + gbLayout.setConstraints(_iconFilePath, gbc); + mediap.add(_iconFilePath); - gbc.gridx = 1; - gbc.gridy = 2; - _iconFilePath.setMinimumSize(iconFieldDim); - _iconFilePath.setMaximumSize(iconFieldDim); - _iconFilePath.setPreferredSize(iconFieldDim); - gbLayout.setConstraints( _iconFilePath,gbc); - mediap.add( _iconFilePath); + gbc.gridx = 0; + gbc.gridy = 4; + gbLayout.setConstraints(_URLlabel, gbc); + mediap.add(_URLlabel); - gbc.gridx = 0; - gbc.gridy = 4; - gbLayout.setConstraints(_URLlabel,gbc); - mediap.add(_URLlabel); + gbc.gridx = 1; + gbc.gridy = 4; + _URL.setMinimumSize(textFieldDim); + _URL.setPreferredSize(textFieldDim); + gbLayout.setConstraints(_URL, gbc); + mediap.add(_URL); - gbc.gridx = 1; - gbc.gridy = 4; - _URL.setMinimumSize(textFieldDim); - _URL.setPreferredSize(textFieldDim); - gbLayout.setConstraints(_URL,gbc); - mediap.add(_URL); + this.setLayout(new BorderLayout()); + add(mediap, BorderLayout.NORTH); + add(new JLabel(rb.getString("MediaRosterAttributeTableDescription")), BorderLayout.CENTER); // some nothing in the middle + jsp.setMinimumSize(tableDim); + jsp.setMaximumSize(tableDim); + jsp.setPreferredSize(tableDim); + add(jsp, BorderLayout.SOUTH); + } - this.setLayout(new BorderLayout()); - add(mediap, BorderLayout.NORTH); - add(new JLabel(rb.getString("MediaRosterAttributeTableDescription")), BorderLayout.CENTER); // some nothing in the middle - jsp.setMinimumSize(tableDim); - jsp.setMaximumSize(tableDim); - jsp.setPreferredSize(tableDim); - add(jsp, BorderLayout.SOUTH); - } + public boolean guiChanged(RosterEntry r) { + if (!r.getURL().equals(_URL.getText())) { + return true; + } + if (!r.getImagePath().equals(_imageFilePath.getImagePath())) { + return true; + } + if (!r.getIconPath().equals(_iconFilePath.getImagePath())) { + return true; + } + return rosterAttributesModel.wasModified(); + } - public boolean guiChanged(RosterEntry r) { - if (!r.getURL().equals(_URL.getText())) return true; - if (!r.getImagePath().equals(_imageFilePath.getImagePath())) return true; - if (!r.getIconPath().equals(_iconFilePath.getImagePath())) return true; - if (rosterAttributesModel.wasModified()) return true; - return false; - } + public void update(RosterEntry r) { + r.setURL(_URL.getText()); + r.setImagePath(_imageFilePath.getImagePath()); + r.setIconPath(_iconFilePath.getImagePath()); + rosterAttributesModel.updateModel(r); + } - public void update(RosterEntry r) { - r.setURL(_URL.getText()) ; - r.setImagePath(_imageFilePath.getImagePath()) ; - r.setIconPath(_iconFilePath.getImagePath()) ; - rosterAttributesModel.updateModel(r); - } + public void dispose() { + if (log.isDebugEnabled()) { + log.debug("dispose"); + } + } - public void dispose() { - if (log.isDebugEnabled()) { - log.debug("dispose"); - } - } + private class RosterAttributesTableModel extends AbstractTableModel { - private class RosterAttributesTableModel extends AbstractTableModel { - Vector<KeyValueModel> attributes; - String titles[]; - boolean wasModified; + Vector<KeyValueModel> attributes; + String titles[]; + boolean wasModified; - private class KeyValueModel { - public KeyValueModel(String k, String v) { key=k; value=v; } - public String key, value; - } + private class KeyValueModel { - public RosterAttributesTableModel(RosterEntry r) { - setModel(r); + public KeyValueModel(String k, String v) { + key = k; + value = v; + } + public String key, value; + } - titles = new String[2]; - titles[0] = rb.getString("MediaRosterAttributeName"); - titles[1] = rb.getString("MediaRosterAttributeValue"); - } + public RosterAttributesTableModel(RosterEntry r) { + setModel(r); - public void setModel(RosterEntry r) { - if (r.getAttributes() != null) { - attributes = new Vector<KeyValueModel>(r.getAttributes().size()); - Iterator<String> ite = r.getAttributes().iterator(); - while (ite.hasNext()) { - String key = ite.next(); - KeyValueModel kv = new KeyValueModel(key, r.getAttribute(key)); - attributes.add(kv); - } - } - else - attributes = new Vector<KeyValueModel>(0); - wasModified = false; - } + titles = new String[2]; + titles[0] = rb.getString("MediaRosterAttributeName"); + titles[1] = rb.getString("MediaRosterAttributeValue"); + } - public void updateModel(RosterEntry r) { - // add and update keys - for (int i=0; i<attributes.size(); i++) { - KeyValueModel kv = attributes.get(i); - if ( (kv.key.length()>0) && // only update if key value defined, will do the remove to - ((r.getAttributes() == null) || (r.getAttribute(kv.key)==null) || (kv.value.compareTo(r.getAttribute(kv.key))!=0)) ) - r.putAttribute(kv.key, kv.value); - } - //remove undefined keys - if (r.getAttributes() != null) { - Iterator<String> ite = r.getAttributes().iterator(); - while (ite.hasNext()) - if (! keyExist(ite.next())) // not very efficient algorithm! - ite.remove(); - } - wasModified = false; - } + public void setModel(RosterEntry r) { + if (r.getAttributes() != null) { + attributes = new Vector<KeyValueModel>(r.getAttributes().size()); + Iterator<String> ite = r.getAttributes().iterator(); + while (ite.hasNext()) { + String key = ite.next(); + KeyValueModel kv = new KeyValueModel(key, r.getAttribute(key)); + attributes.add(kv); + } + } else { + attributes = new Vector<KeyValueModel>(0); + } + wasModified = false; + } - private boolean keyExist(String k) { - if (k==null) return false; - for (int i=0; i<attributes.size(); i++) - if ( k.compareTo(attributes.get(i).key) == 0) - return true; - return false; - } + public void updateModel(RosterEntry r) { + for (KeyValueModel kv : attributes) { + if ((kv.key.length() > 0) && // only update if key value defined, will do the remove to + ((r.getAttributes() == null) || (r.getAttribute(kv.key) == null) || (kv.value.compareTo(r.getAttribute(kv.key)) != 0))) { + r.putAttribute(kv.key, kv.value); + } + } + //remove undefined keys + if (r.getAttributes() != null) { + Iterator<String> ite = r.getAttributes().iterator(); + while (ite.hasNext()) { + if (!keyExist(ite.next())) // not very efficient algorithm! + { + ite.remove(); + } + } + } + wasModified = false; + } - public int getColumnCount() { - return 2; - } + private boolean keyExist(String k) { + if (k == null) { + return false; + } + for (KeyValueModel attribute : attributes) { + if (k.compareTo(attribute.key) == 0) { + return true; + } + } + return false; + } - public int getRowCount() { - return attributes.size()+1; - } + @Override + public int getColumnCount() { + return 2; + } - public String getColumnName(int col){ - return titles[col]; - } + @Override + public int getRowCount() { + return attributes.size() + 1; + } - public Object getValueAt(int row, int col) { - if (row<attributes.size()) { - if (col == 0) - return attributes.get(row).key; - if (col == 1) - return attributes.get(row).value; - } - return "..."; - } + @Override + public String getColumnName(int col) { + return titles[col]; + } - public void setValueAt(Object value, int row, int col) { - KeyValueModel kv; - - if (row<attributes.size()) // already exist? - kv = attributes.get(row); - else - kv = new KeyValueModel("",""); - - if (col == 0) // update key - //Force keys to be save as a single string with no spaces - if (! keyExist(((String) value).replaceAll("\\s", ""))) // if not exist - kv.key = ((String) value).replaceAll("\\s", ""); - else { - setValueAt(value+"-1", row, col); // else change key name - return; - } + @Override + public Object getValueAt(int row, int col) { + if (row < attributes.size()) { + if (col == 0) { + return attributes.get(row).key; + } + if (col == 1) { + return attributes.get(row).value; + } + } + return "..."; + } - if (col == 1) // update value - kv.value = (String) value; - if (row<attributes.size()) // existing one - attributes.set(row, kv); - else - attributes.add(row, kv); // new one + @Override + public void setValueAt(Object value, int row, int col) { + KeyValueModel kv; - if ((col==0) && (kv.key.compareTo("")==0)) - attributes.remove(row); // actually maybe remove - - wasModified = true; - fireTableCellUpdated(row, col); - } + if (row < attributes.size()) // already exist? + { + kv = attributes.get(row); + } else { + kv = new KeyValueModel("", ""); + } - public boolean isCellEditable(int row, int col) { - return true; - } + if (col == 0) // update key + //Force keys to be save as a single string with no spaces + { + if (!keyExist(((String) value).replaceAll("\\s", ""))) // if not exist + { + kv.key = ((String) value).replaceAll("\\s", ""); + } else { + setValueAt(value + "-1", row, col); // else change key name + return; + } + } - public boolean wasModified() { - return wasModified; - } - } + if (col == 1) // update value + { + kv.value = (String) value; + } + if (row < attributes.size()) // existing one + { + attributes.set(row, kv); + } else { + attributes.add(row, kv); // new one + } + if ((col == 0) && (kv.key.compareTo("") == 0)) { + attributes.remove(row); // actually maybe remove + } + wasModified = true; + fireTableCellUpdated(row, col); + } - static Logger log = LoggerFactory.getLogger(RosterMediaPane.class.getName()); + @Override + public boolean isCellEditable(int row, int col) { + return true; + } + + public boolean wasModified() { + return wasModified; + } + } + + static Logger log = LoggerFactory.getLogger(RosterMediaPane.class.getName()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |