📄 utilitytoolbar.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 *//* * UtilityToolbar.java * * Created on 9 May 2003, 14:47 */package crms.applet;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.net.URL;import java.io.*;import crms.vo.*;import crms.util.*;/** * * @author dmurphy */public class UtilityToolbar extends javax.swing.JToolBar { public static final Color TOOLBAR_BACKGROUND = Color.WHITE; public static final Color BUTTON_BACKGROUND = Color.WHITE; public JPanel buttonPanel = new JPanel(new FlowLayout()); private JButton buttonAttachments = null; private JButton buttonNotes = null; private JButton buttonSecurity = null; private JButton buttonMeetings = null; private JButton buttonContacts = null; private JButton buttonCompanies = null; private JLabel label = new JLabel(); private EntityType entityType = null; private int entityID = -1; private String entityName = null; private Permission entityPermission = null; /** Creates a new instance of UtilityToolbar */ public UtilityToolbar(EntityType type, int entityID) { this.entityType = type; this.entityID = entityID; init(); } public void setEntityPermission(Permission p) { this.entityPermission = p; buttonSecurity.setVisible(p.canSecurity()); } public void setName(String name) { entityName = name; } public void init() { // initialise the toolbar setBackground(TOOLBAR_BACKGROUND); setLayout(new BorderLayout()); setFloatable(false); buttonPanel.setBackground(TOOLBAR_BACKGROUND); // add the contacts button /* no longer used if (entityType == EntityType.COMPANY) { buttonContacts = UtilityToolbar.createButton(getClass().getResource("/toolbarButtonGraphics/general/SaveAll24.gif"), "Contacts"); buttonContacts.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { if ( entityType == EntityType.COMPANY) { ContactViewPanel cPanel = new ContactViewPanel(entityID); PanelManager.getInstance().activatePanel(cPanel); } } }); buttonPanel.add(buttonContacts); } */ // attachments buttonAttachments = UtilityToolbar.createButton(getClass().getResource("/toolbarButtonGraphics/general/SaveAll24.gif"), "Attachments"); buttonAttachments.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { FileAttachViewWindow window = new FileAttachViewWindow(); window.setReference(entityType, entityID, !entityPermission.canWrite()); window.display(); } }); buttonPanel.add(buttonAttachments); // add the calls button for companies if (entityType == EntityType.COMPANY ) { buttonCompanies = UtilityToolbar.createButton(getClass().getResource("/toolbarButtonGraphics/general/SaveAll24.gif"), "Calls"); // add action listner buttonCompanies.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ev) { CallViewPanel cPanel = new CallViewPanel(entityID); PanelManager.getInstance().activatePanel(cPanel); } }); buttonPanel.add(buttonCompanies); } if (entityType == EntityType.CONTACT || entityType == EntityType.COMPANY) { // notes buttonNotes = createButton(getClass().getResource("/images/notes_icon.jpg"), "Notes"); buttonNotes.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { NotesViewWindow window = new NotesViewWindow(); window.setNotes(entityType, entityID, !entityPermission.canWrite()); window.display(); //PanelManager.getInstance().activatePanel( new NotesViewPanel(entityType, entityID, entityPermission)); } }); // meetings buttonPanel.add(buttonNotes); buttonMeetings = createButton(getClass().getResource("/images/meeting_icon.gif"), "Meetings"); buttonMeetings.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { MeetingViewWindow window = new MeetingViewWindow(); ContactType type; if (entityType == EntityType.COMPANY) { type = ContactType.ORGANISATION; } else { type = ContactType.CONTACT; } window.setReference(type, entityID, !entityPermission.canWrite()); window.display(); } }); buttonPanel.add(buttonMeetings); // add security button (always at end) buttonSecurity = createButton(getClass().getResource("/toolbarButtonGraphics/general/SaveAll24.gif"), "Security"); buttonSecurity.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { PermissionWindow window = new PermissionWindow(); window.setEntity(entityType, entityID, entityPermission); window.setTitle(entityName!= null ? entityName : "Unknown"); window.display(); //PanelManager.getInstance().activatePanel( new EntityPermissionPanel(entityType, entityID, entityPermission)); } }); buttonPanel.add(buttonSecurity); } label.setBackground(Color.WHITE); // add buttons to the panel add(label, BorderLayout.WEST); add(buttonPanel, BorderLayout.EAST); } public void setLabel(String label) { this.label.setText(label); } public void addButton(JButton newButton) { newButton.setBackground(BUTTON_BACKGROUND); buttonPanel.add(newButton); } public static JButton createButton(URL resourceFile, String toolTipText) { JButton button = new JButton(); if (resourceFile != null) { File iconFile = new File(resourceFile.toExternalForm()); if (iconFile.exists()) { ImageIcon icon = new ImageIcon(resourceFile); icon.setImage(icon.getImage().getScaledInstance(24,24, Image.SCALE_SMOOTH)); if (icon == null) { throw new RuntimeException("Couldn't find icon at " + resourceFile); } button.setToolTipText(toolTipText); button.setIcon(icon); // Place text to the left of icon, vertically centered button.setVerticalTextPosition(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.LEFT); } else { button.setText(toolTipText); } } else { button.setText(toolTipText); } button.setBackground(Color.WHITE); return button; } /** * Main class * * @param args */ public static void main(String[] args) { JFrame frame = new JFrame("Utillity Bar"); UtilityToolbar ut = new UtilityToolbar(EntityType.CONTACT,1); 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 + -