⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileattachpanel.java

📁 发泄网! 发泄网! 发泄网! 发泄网! 发泄网! 发泄网! 发泄网! 发泄网!
💻 JAVA
字号:
	/* CRMS, customer relationship management system	Copyright (C) 2003  Service To Youth Council	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	For further information contact the SYC ICT department on GPL@syc.net.au	98 Kermode Street	North Adelaide	South Australia	SA 5006 	+61 (0)8 8367 0755	*//* * CallViewPanel.java * * Created on 27 March 2003, 00:11 */package crms.applet;import crms.vo.*;import crms.ui.*;import crms.module.*;import crms.util.*;import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.border.*;import javax.swing.event.*;import java.util.*;import java.text.*;import java.beans.*;import java.io.*;import java.text.*;import java.security.AccessControlException;/** * * @author  dmurphy */public class FileAttachPanel extends CRMSPanel {		JPanel titlePanel = new JPanel();	CRMSPanel bodyPanel = CRMSPanel.getEmptyPanel();	JLabel headingLabel = new JLabel();		public static SimpleDateFormat df = new SimpleDateFormat("EEEE, d MMMM, yyyy");	public static SimpleDateFormat tf = new SimpleDateFormat("h:mm a");	JButton buttonSave = new JButton("Attach");	JButton buttonReset = new JButton("Clear");	JButton buttonCancel = new JButton("Close");		JTextArea descText = new JTextArea();	JScrollPane descScrollPane = new JScrollPane(descText);	JTextField textPath = new JTextField();	JButton buttonBrowse = new JButton("Browse");		JPanel buttonPanel = new JPanel();	EntityType attachmentType = null;		int reference = -1;	CallbackDestination destination = null;		/** Creates a new instance of CallViewPanel */	public FileAttachPanel() {	}	public void setReference(EntityType type, int reference) {		this.attachmentType = type;		this.reference = reference;	}	public void setDestination(CallbackDestination new_dest) {		destination = new_dest;	}		public void init() {		final Object thisobj = this;		setLayout(new BorderLayout());		setBackground(Color.WHITE);		headingLabel.setFont(new java.awt.Font("Serif", 1, 18));		headingLabel.setBackground(Color.WHITE);				descText.setWrapStyleWord(true);		descText.setLineWrap(true);				titlePanel.add(headingLabel);		titlePanel.setBackground(Color.WHITE);		add(titlePanel, BorderLayout.NORTH);				buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));		buttonPanel.setBackground(Color.WHITE);		buttonPanel.add(buttonSave);		buttonPanel.add(buttonReset);		buttonPanel.add(buttonCancel);				buttonSave.addActionListener( new ActionListener() {		   public void actionPerformed(ActionEvent ev) {			   attachFile();		   }		});				buttonReset.addActionListener( new ActionListener() {		   public void actionPerformed(ActionEvent ev) {			   refreshData();		   }		});				buttonCancel.addActionListener( new ActionListener() {			public void actionPerformed(ActionEvent ev) {				if (destination != null) destination.callback(thisobj, CRMSComponent.CB_CLOSE_WINDOW, null);		   }		});				buttonBrowse.addActionListener( new ActionListener() {		   public void actionPerformed(ActionEvent ev) {			   showChooser();		   }		});				bodyPanel.setLayout(new GridBagLayout());		bodyPanel.setBackground(Color.WHITE);		bodyPanel.setBorder(new EmptyBorder(0,20,0,20));				descText.setRows(10);				Insets defaultInsets = new Insets(4,0,0,4);						bodyPanel.add(new JLabel("File Location"), 			new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,				GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, defaultInsets, 0, 0));		bodyPanel.add(textPath,			new GridBagConstraints(1, 0, 2, 1, 1.0, 0.0,				GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0));		bodyPanel.add(buttonBrowse,			new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,				GridBagConstraints.CENTER, GridBagConstraints.NONE, defaultInsets, 0, 0));		bodyPanel.add(new JLabel("Description"),			new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0,				GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, defaultInsets, 0, 0));		bodyPanel.add(descScrollPane,			new GridBagConstraints(1, 1, 3, 10, 3.0, 0.0,				GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, defaultInsets, 0, 0));				add(bodyPanel, BorderLayout.CENTER);		add(buttonPanel, BorderLayout.SOUTH);				setCurrentPanel(bodyPanel);				refreshData();	}		public void refreshData() {		descText.setText("");		textPath.setText("");	}	public void showChooser() {		JFileChooser chooser = null;		try {			chooser = new JFileChooser();			int returnVal = chooser.showOpenDialog(this);			if(returnVal == JFileChooser.APPROVE_OPTION) {				try {					textPath.setText(chooser.getSelectedFile().getCanonicalPath());				}				catch (IOException ex) {					ex.printStackTrace();				}			}		} catch (AccessControlException e) {			JOptionPane.showMessageDialog(this, "The local system security policy is not allowing the file browse window to appear; please contact your System Administrator.",					"File Upload", JOptionPane.ERROR_MESSAGE);			return;		}		chooser.setVisible(true);	}		public void attachFile() {				Server server = ServerFactory.getInstance().getServer();		ServerResponse sr = null;				FileAttachment attach = new FileAttachment();				FileSendCommand command = new FileSendCommand();		attach.setAttachmentType(attachmentType);		attach.setReferenceID(String.valueOf(reference));		attach.setAttachedBy(server.getUser());		attach.setDescription(descText.getText());		command.setPhysicalLocation(new File(textPath.getText()));		command.setFileToSend(attach);				sr = server.sendCommand(command);				int result = ((Integer)sr.getPart("result")).intValue();		if (result == 200) {			if (destination != null) destination.callback(this, CRMSComponent.CB_CLOSE_WINDOW, new Object());		} else {			JOptionPane.showMessageDialog(this, "Unknown file upload result: " + result, "File Upload", JOptionPane.ERROR_MESSAGE);		}	}		/**	 * Main class	 *	 * @param args	 */	public static void main(String[] args) {		JFrame frame = new JFrame("Test Bar");		FileAttachPanel ut = new FileAttachPanel();		ut.showChooser();		frame.getContentPane().add(ut);		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		frame.pack();		frame.setVisible(true);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -