r71 - trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor
Author: tchemit Date: 2012-12-15 00:16:31 +0100 (Sat, 15 Dec 2012) New Revision: 71 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/71 Log: reformat some codes Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java 2012-12-14 23:13:54 UTC (rev 70) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java 2012-12-14 23:16:31 UTC (rev 71) @@ -24,15 +24,27 @@ * #L% */ -import fr.ifremer.tutti.ui.swing.util.ComponentResizer; import com.google.common.base.Preconditions; import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.ComponentMover; +import fr.ifremer.tutti.ui.swing.util.ComponentResizer; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; -import java.awt.event.WindowAdapter; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.AbstractCellEditor; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JTable; +import javax.swing.border.LineBorder; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; import java.awt.Color; import java.awt.Component; import java.awt.Frame; @@ -40,33 +52,24 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import javax.swing.AbstractCellEditor; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JTable; -import javax.swing.border.LineBorder; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import jaxx.runtime.JAXXUtil; -import jaxx.runtime.SwingUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import static org.nuiton.i18n.I18n._; /** * Component to edit a cell containing attachments - * + * * @author kmorin * @since 0.2 */ public class AttachmentCellComponent extends JButton { - + /** Logger. */ private static final Log log = LogFactory.getLog(AttachmentCellComponent.class); + private static final long serialVersionUID = 1L; + public AttachmentCellComponent() { setContentAreaFilled(false); setOpaque(false); @@ -80,16 +83,18 @@ public static TableCellEditor newEditor(AttachmentEditorUI ui) { return new AttachmentCellEditor(ui); } - - + + public static class AttachmentCellEditor extends AbstractCellEditor implements TableCellEditor { + private static final long serialVersionUID = 1L; + protected final AttachmentCellComponent component; protected final AttachmentEditorUI ui; protected Frame frame; - + protected JTable table; protected AbstractTuttiTableModel<AbstractTuttiBeanUIModel> tableModel; @@ -101,10 +106,10 @@ protected Integer rowIndex; protected Integer columnIndex; - + public AttachmentCellEditor(AttachmentEditorUI ui) { this.ui = ui; - + component = new AttachmentCellComponent(); component.setBorder(new LineBorder(Color.BLACK)); component.addKeyListener(new KeyAdapter() { @@ -131,23 +136,23 @@ if (frame == null) { frame = SwingUtil.getParentContainer(ui, Frame.class); } - + ui.setBorder(BorderFactory.createTitledBorder(_(columnIdentifier.getHeaderI18nKey()))); ui.setBean(editRow); ui.setProperty(columnIdentifier.getPropertyName()); - + JDialog editor = new JDialog(frame, true); editor.setUndecorated(true); editor.add(ui); editor.setResizable(true); editor.pack(); - + ComponentResizer cr = new ComponentResizer(); cr.registerComponent(editor); ComponentMover cm = new ComponentMover(); cm.setDragInsets(cr.getDragInsets()); cm.registerComponent(editor); - + editor.addWindowListener(new WindowAdapter() { @Override @@ -159,7 +164,7 @@ JAXXUtil.destroy(ui); } }); - + // Computes the location of bottom left corner of the cell Component comp = component; int x = 0; @@ -176,7 +181,7 @@ } editor.setLocation(x, y); editor.setVisible(true); - + int r = rowIndex; int c = columnIndex; @@ -186,7 +191,7 @@ // reselect this cell AbstractSelectTableAction.doSelectCell(table, r, c); } - + @Override public Component getTableCellEditorComponent(JTable table, Object value, @@ -194,7 +199,7 @@ int row, int column) { if (tableModel == null) { - tableModel = (AbstractTuttiTableModel<AbstractTuttiBeanUIModel>) table.getModel(); + tableModel = (AbstractTuttiTableModel<AbstractTuttiBeanUIModel>) table.getModel(); this.table = table; columnIdentifier = tableModel.getPropertyName(column); } @@ -240,11 +245,11 @@ editRow = null; } } - + public static class AttachmentCellRenderer implements TableCellRenderer { protected final AttachmentCellComponent component; - + protected String propertyName; public AttachmentCellRenderer() { @@ -262,19 +267,19 @@ String text; if (value == null) { if (propertyName == null) { - AbstractTuttiTableModel tableModel = + AbstractTuttiTableModel tableModel = (AbstractTuttiTableModel) table.getModel(); ColumnIdentifier columnIdentifier = tableModel.getPropertyName(column); propertyName = columnIdentifier.getPropertyName(); } // use HTML to show the tooltip in italic text = "<html><body><i>" + _("tutti.tooltip." + propertyName + ".none") + "</i></body></html>"; - + } else { // use html to display the tooltip on several lines text = "<html><body>" + String.valueOf(value).replace("\n", "<br/>") + "</body></html>"; } - + boolean editable = table.isCellEditable(row, column); component.setEnabled(editable); component.setToolTipText(text); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java 2012-12-14 23:13:54 UTC (rev 70) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentEditorUIHandler.java 2012-12-14 23:16:31 UTC (rev 71) @@ -28,8 +28,18 @@ import fr.ifremer.tutti.persistence.entities.data.Attachment; import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; +import jaxx.runtime.SwingUtil; +import jaxx.runtime.swing.HBox; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.SwingConstants; import java.awt.Cursor; -import java.awt.Desktop; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -38,45 +48,34 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; import java.util.List; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JFileChooser; -import javax.swing.JLabel; -import javax.swing.SwingConstants; -import jaxx.runtime.SwingUtil; -import jaxx.runtime.swing.HBox; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Handler of the LongTextEditorUI + * * @author kmorin * @since 0.2 */ public class AttachmentEditorUIHandler { - + private static final Log log = LogFactory.getLog(AttachmentEditorUIHandler.class); - + private final AttachmentEditorUI ui; - + private JFileChooser fileChooser = new JFileChooser(); public AttachmentEditorUIHandler(AttachmentEditorUI attachmentEditorUI) { ui = attachmentEditorUI; - + ui.addPropertyChangeListener(new PropertyChangeListener() { + @Override public void propertyChange(PropertyChangeEvent evt) { init(); } }); } - + public void init() { resetFields(); ui.getAttachments().removeAll(); @@ -91,14 +90,15 @@ } } } - + protected void addAttachment(final Attachment attachment) { final HBox hbox = new HBox(); hbox.setVerticalAlignment(SwingConstants.CENTER); - + JButton deleteButton = new JButton(SwingUtil.createActionIcon("delete")); deleteButton.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { AbstractTuttiBeanUIModel bean = ui.getBean(); String property = ui.getProperty(); @@ -107,17 +107,17 @@ list.remove(attachment); TuttiUIUtil.setProperty(bean, property, list); } - + ui.getAttachments().remove(hbox); - + JDialog parent = SwingUtil.getParentContainer(ui, JDialog.class); parent.pack(); } }); hbox.add(deleteButton); - + final JLabel label = new JLabel("<html><body><a href=''>" - + attachment.getName() + "</a></body></html>"); + + attachment.getName() + "</a></body></html>"); label.setToolTipText(attachment.getComment()); label.addMouseListener(new MouseAdapter() { @@ -135,23 +135,21 @@ public void mouseExited(MouseEvent e) { label.setCursor(Cursor.getDefaultCursor()); } - + }); hbox.add(label); - + ui.getAttachments().add(hbox); } - - /** - * closes the editor - */ + + /** closes the editor */ public void close() { if (log.isInfoEnabled()) { log.info("Will close UI " + ui); } SwingUtil.getParentContainer(ui, Window.class).dispose(); } - + public void chooseFile() { if (fileChooser.showOpenDialog(ui) == JFileChooser.APPROVE_OPTION) { File file = fileChooser.getSelectedFile(); @@ -159,7 +157,7 @@ ui.getFile().setText(file.getAbsolutePath()); } } - + public void addAttachment() { AbstractTuttiBeanUIModel bean = ui.getBean(); String property = ui.getProperty(); @@ -186,7 +184,7 @@ parent.pack(); } } - + protected void resetFields() { ui.setModel(new Attachment()); fileChooser.setSelectedFile(null); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2012-12-14 23:13:54 UTC (rev 70) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2012-12-14 23:16:31 UTC (rev 71) @@ -24,50 +24,52 @@ * #L% */ -import fr.ifremer.tutti.ui.swing.util.ComponentResizer; import com.google.common.base.Preconditions; import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.ComponentMover; +import fr.ifremer.tutti.ui.swing.util.ComponentResizer; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; -import java.awt.event.WindowAdapter; +import jaxx.runtime.JAXXUtil; +import jaxx.runtime.SwingUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.swing.AbstractCellEditor; +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JTable; +import javax.swing.border.LineBorder; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; import java.awt.Color; import java.awt.Component; import java.awt.Frame; -import java.awt.Insets; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import javax.swing.AbstractCellEditor; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JTable; -import javax.swing.border.LineBorder; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import jaxx.runtime.JAXXUtil; -import jaxx.runtime.SwingUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import static org.nuiton.i18n.I18n._; /** * Component to edit a cell in a popup with a text area - * + * * @author kmorin * @since 0.2 */ -public class LongTextCellComponent extends JButton{ - +public class LongTextCellComponent extends JButton { + /** Logger. */ private static final Log log = LogFactory.getLog(LongTextCellComponent.class); + private static final long serialVersionUID = 1L; + public LongTextCellComponent() { setContentAreaFilled(false); setOpaque(false); @@ -81,19 +83,22 @@ public static TableCellEditor newEditor(LongTextEditorUI ui) { return new LongTextCellEditor(ui); } - - + + public static class LongTextCellEditor extends AbstractCellEditor implements TableCellEditor { public static final int DEFAULT_EDITOR_WIDTH = 400; + public static final int DEFAULT_EDITOR_HEIGHT = 200; - + + private static final long serialVersionUID = 1L; + protected final LongTextCellComponent component; protected final LongTextEditorUI ui; protected Frame frame; - + protected JTable table; protected AbstractTuttiTableModel<AbstractTuttiBeanUIModel> tableModel; @@ -105,10 +110,10 @@ protected Integer rowIndex; protected Integer columnIndex; - + public LongTextCellEditor(LongTextEditorUI ui) { this.ui = ui; - + component = new LongTextCellComponent(); component.setBorder(new LineBorder(Color.BLACK)); component.addKeyListener(new KeyAdapter() { @@ -135,23 +140,23 @@ if (frame == null) { frame = SwingUtil.getParentContainer(ui, Frame.class); } - + ui.setBorder(BorderFactory.createTitledBorder(_(columnIdentifier.getHeaderI18nKey()))); ui.setBean(editRow); ui.setProperty(columnIdentifier.getPropertyName()); - + JDialog editor = new JDialog(frame, true); editor.setUndecorated(true); editor.add(ui); editor.setSize(DEFAULT_EDITOR_WIDTH, DEFAULT_EDITOR_HEIGHT); editor.setResizable(true); - + ComponentResizer cr = new ComponentResizer(); cr.registerComponent(editor); ComponentMover cm = new ComponentMover(); cm.setDragInsets(cr.getDragInsets()); cm.registerComponent(editor); - + editor.addWindowListener(new WindowAdapter() { @Override @@ -163,7 +168,7 @@ JAXXUtil.destroy(ui); } }); - + // Computes the location of bottom left corner of the cell Component comp = component; int x = 0; @@ -180,7 +185,7 @@ } editor.setLocation(x, y); editor.setVisible(true); - + int r = rowIndex; int c = columnIndex; @@ -190,7 +195,7 @@ // reselect this cell AbstractSelectTableAction.doSelectCell(table, r, c); } - + @Override public Component getTableCellEditorComponent(JTable table, Object value, @@ -198,7 +203,7 @@ int row, int column) { if (tableModel == null) { - tableModel = (AbstractTuttiTableModel<AbstractTuttiBeanUIModel>) table.getModel(); + tableModel = (AbstractTuttiTableModel<AbstractTuttiBeanUIModel>) table.getModel(); this.table = table; columnIdentifier = tableModel.getPropertyName(column); } @@ -244,11 +249,11 @@ editRow = null; } } - + public static class LongTextCellRenderer implements TableCellRenderer { protected final LongTextCellComponent component; - + protected String propertyName; public LongTextCellRenderer() { @@ -266,19 +271,19 @@ String text; if (value == null) { if (propertyName == null) { - AbstractTuttiTableModel tableModel = + AbstractTuttiTableModel tableModel = (AbstractTuttiTableModel) table.getModel(); ColumnIdentifier columnIdentifier = tableModel.getPropertyName(column); propertyName = columnIdentifier.getPropertyName(); } // use HTML to show the tooltip in italic text = "<html><body><i>" + _("tutti.tooltip." + propertyName + ".none") + "</i></body></html>"; - + } else { // use html to display the tooltip on several lines text = "<html><body>" + String.valueOf(value).replace("\n", "<br/>") + "</body></html>"; } - + boolean editable = table.isCellEditable(row, column); component.setEnabled(editable); component.setToolTipText(text); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java 2012-12-14 23:13:54 UTC (rev 70) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextEditorUIHandler.java 2012-12-14 23:16:31 UTC (rev 71) @@ -26,28 +26,30 @@ import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; -import java.awt.Window; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; import jaxx.runtime.SwingUtil; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.awt.Window; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + /** * Handler of the LongTextEditorUI + * * @author kmorin * @since 0.2 */ public class LongTextEditorUIHandler { - + private static final Log log = LogFactory.getLog(LongTextEditorUIHandler.class); - + private final LongTextEditorUI ui; public LongTextEditorUIHandler(LongTextEditorUI longTextEditorUI) { ui = longTextEditorUI; - + ui.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { @@ -63,28 +65,24 @@ } }); } - - /** - * pushes the typed text in the property of the bean - */ + + /** pushes the typed text in the property of the bean */ public void setText() { String value = ui.getTextContent().getText(); AbstractTuttiBeanUIModel bean = ui.getBean(); String property = ui.getProperty(); TuttiUIUtil.setProperty(bean, property, value); } - + public void resetText() { AbstractTuttiBeanUIModel bean = ui.getBean(); String property = ui.getProperty(); TuttiUIUtil.setProperty(bean, property, null); - + ui.getTextContent().setText(""); } - - /** - * closes the editor - */ + + /** closes the editor */ public void close() { if (log.isInfoEnabled()) { log.info("Will close UI " + ui);
participants (1)
-
tchemit@users.forge.codelutin.com