| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.dialog; |
| 16 | |
| 17 | import java.awt.Image; |
| 18 | import java.text.SimpleDateFormat; |
| 19 | |
| 20 | import javax.swing.ImageIcon; |
| 21 | import javax.swing.JFormattedTextField; |
| 22 | import javax.swing.JLabel; |
| 23 | import javax.swing.JScrollPane; |
| 24 | import javax.swing.JTextField; |
| 25 | import javax.swing.text.DateFormatter; |
| 26 | |
| 27 | import net.sourceforge.hiveboard.Board; |
| 28 | import net.sourceforge.hiveboard.Snapshot; |
| 29 | |
| 30 | import zappini.designgridlayout.DesignGridLayout; |
| 31 | import zappini.designgridlayout.Row; |
| 32 | |
| 33 | public class SnapshotDetailPanel extends AbstractBoardPanel |
| 34 | { |
| 35 | static private final String NAME = "snapshot"; |
| 36 | |
| 37 | public SnapshotDetailPanel(Board board, Snapshot snapshot, Image picture) |
| 38 | { |
| 39 | super(NAME); |
| 40 | _board = board; |
| 41 | |
| 42 | _lblBoard.setName(NAME + "-board-label"); |
| 43 | _txfBoard.setName(NAME + "-board"); |
| 44 | _lblDate.setName(NAME + "-date-label"); |
| 45 | _txfDate.setName(NAME + "-date"); |
| 46 | _pictLabel.setName(NAME + "-picture"); |
| 47 | |
| 48 | _txfBoard.setEnabled(false); |
| 49 | _txfDate.setEnabled(false); |
| 50 | |
| 51 | _txfBoard.setText(board.getName()); |
| 52 | _txfDate.setValue(snapshot.getDate()); |
| 53 | _pictLabel.setIcon(new ImageIcon(picture)); |
| 54 | |
| 55 | DesignGridLayout layout = new DesignGridLayout(this); |
| 56 | setLayout(layout); |
| 57 | layout.row().label(_lblBoard).add(_txfBoard); |
| 58 | layout.row().label(_lblDate).add(_txfDate).add(Row.EMPTY); |
| 59 | layout.row().center().add(new JScrollPane(_pictLabel)); |
| 60 | } |
| 61 | |
| 62 | public void setDateFormat(String dateFormat) |
| 63 | { |
| 64 | Object value = _txfDate.getValue(); |
| 65 | _dateFormatter.setFormat(new SimpleDateFormat(dateFormat)); |
| 66 | // We have to reset the value to force the application of the new format |
| 67 | _txfDate.setValue(value); |
| 68 | } |
| 69 | |
| 70 | private final JLabel _lblBoard = new JLabel(); |
| 71 | private final JTextField _txfBoard = new JTextField(); |
| 72 | private final JLabel _lblDate = new JLabel(); |
| 73 | private final DateFormatter _dateFormatter = new DateFormatter(); |
| 74 | private final JFormattedTextField _txfDate = new JFormattedTextField(_dateFormatter); |
| 75 | private final JLabel _pictLabel = new JLabel(); |
| 76 | } |