/* File Name: PropertyWindow.java */ package explorer.client.gui; import explorer.FileSystemDAO; import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.border.*; /** * GUI to display the properties of a File Object such as * File Name, * File Location, * File Size, * last Modified Date, * Access Check such as Read Only, Hidden */ public class PropertyWindow extends JWindow implements ActionListener { private FileSystemDAO fileSystem; private JPanel fileNamePanel; private JTextField txtFileName; private JPanel fileInfoPanel; private JLabel lblLocation; private JLabel lblSize; private JLabel lblLastModified; private JPanel accessPanel; private JCheckBox chkReadOnly; private JCheckBox chkHidden; private JPanel buttonPanel; private JButton cmdRename; private JButton cmdOK; private JButton cmdCancel; public PropertyWindow(Frame parent, FileSystemDAO fileInfo) { super(parent); fileSystem = fileInfo; this.setSize(400, 300); this.setLocationRelativeTo(parent); JPanel contentPanel = (JPanel)this.getContentPane(); contentPanel.setBorder(BorderFactory.createRaisedBevelBorder()); contentPanel.setLayout(new BorderLayout(10, 10)); JPanel northPanel = new JPanel(); northPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); northPanel.setBackground(new Color(22, 88, 176)); JLabel titleLabel = new JLabel(fileSystem.getFileName()+" Properties", JLabel.LEFT); titleLabel.setBackground(new Color(22, 88, 176)); titleLabel.setForeground(new Color(255, 255, 255)); titleLabel.setFont(new Font("TimesNewRoman", Font.BOLD, 12)); titleLabel.setVisible(true); northPanel.add(titleLabel); contentPanel.add(northPanel, BorderLayout.NORTH); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); JPanel pnl; JLabel lblHeadingDesc; fileNamePanel = new JPanel(); fileNamePanel.setLayout(new FlowLayout(FlowLayout.LEFT)); txtFileName = new JTextField(fileSystem.getFileName()); txtFileName.setColumns(30); txtFileName.setFont(new Font("TimesNewRoman", Font.PLAIN, 12)); fileNamePanel.add(txtFileName); fileNamePanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); centerPanel.add(fileNamePanel); fileInfoPanel = new JPanel(); fileInfoPanel.setLayout(new BorderLayout(15, 10)); JPanel headingPanel = new JPanel(); headingPanel.setLayout(new GridLayout(3, 1)); lblHeadingDesc = new JLabel("Location:"); lblHeadingDesc.setSize(100, 20); headingPanel.add(lblHeadingDesc); lblHeadingDesc = new JLabel("Size:"); lblHeadingDesc.setSize(100, 20); headingPanel.add(lblHeadingDesc); lblHeadingDesc = new JLabel("Modified On:"); lblHeadingDesc.setSize(100, 20); headingPanel.add(lblHeadingDesc); fileInfoPanel.add(headingPanel, BorderLayout.WEST); JPanel valuePanel = new JPanel(); valuePanel.setLayout(new GridLayout(3, 1)); lblLocation = new JLabel(fileSystem.getFilePath()); valuePanel.add(lblLocation); lblSize = new JLabel(fileSystem.getLength()+" bytes"); valuePanel.add(lblSize); lblLastModified = new JLabel(new java.text.SimpleDateFormat("E, MMM dd, yyyy, hh:mm:ss").format(new java.util.Date(fileSystem.getLastModifiedDate()))); valuePanel.add(lblLastModified); fileInfoPanel.add(valuePanel, BorderLayout.CENTER); fileInfoPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); centerPanel.add(fileInfoPanel); accessPanel = new JPanel(); accessPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 15, 10)); lblHeadingDesc = new JLabel("Attributes:"); lblHeadingDesc.setSize(100, 20); accessPanel.add(lblHeadingDesc); chkReadOnly = new JCheckBox("Read-Only"); chkReadOnly.setSelected(fileInfo.isReadOnly()); accessPanel.add(chkReadOnly); chkHidden = new JCheckBox("Hidden"); chkReadOnly.setSelected(fileInfo.isHiddenFile()); accessPanel.add(chkHidden); centerPanel.add(accessPanel); buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); cmdOK = new JButton("OK"); cmdOK.addActionListener(this); buttonPanel.add(cmdOK); cmdCancel = new JButton("Cancel"); cmdCancel.addActionListener(this); buttonPanel.add(cmdCancel); centerPanel.add(buttonPanel); contentPanel.add(centerPanel, BorderLayout.CENTER); contentPanel.updateUI(); this.setVisible(true); } public void actionPerformed(ActionEvent ae) { if(ae.getSource()==cmdOK) { ClientOpenFrame parent = (ClientOpenFrame)super.getParent(); fileSystem.setReadOnly(chkReadOnly.isSelected()); parent.getClient().setProperties(parent.getPresentClient(), fileSystem, txtFileName.getText()); } this.dispose(); } }