/** * Copyright 1999-2009 The Pegadi Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.sources; // Pegadi imports import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ResourceBundle; public class Sources extends JFrame{ JButton newSourceButton; JButton exitSourceButton; SourceSearchPanel sourceSearchPanel ; AbstractAction newAction; ResourceBundle strings; public Sources() { strings = ResourceBundle.getBundle("org.pegadi.sources.SourcesStrings"); createUI(); } public void createUI() { newSourceButton = new JButton(); newSourceButton.setToolTipText(strings.getString("newButton.tooltip")); newSourceButton.setIcon(new ImageIcon(getClass().getResource(strings.getString("newButton.icon")))); newSourceButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { newSourceAction_actionPerformed(e); } }); newSourceButton.setMargin(new Insets(0,0,0,0)); exitSourceButton = new JButton(); exitSourceButton.setToolTipText(strings.getString("exitButton.tooltip")); exitSourceButton.setIcon(new ImageIcon(getClass().getResource(strings.getString("exitButton.icon")))); exitSourceButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { exitSourceAction_actionPerformed(e); } }); exitSourceButton.setMargin(new Insets(0,0,0,0)); sourceSearchPanel = new SourceSearchPanel(); sourceSearchPanel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sourceSearchPanel_actionPerformed(e); } }); getContentPane().setLayout(new BorderLayout()); JPanel controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); controlPanel.add(newSourceButton); controlPanel.add(exitSourceButton); getContentPane().add(controlPanel,BorderLayout.NORTH); getContentPane().add(sourceSearchPanel,BorderLayout.CENTER); setSize(400,400); sourceSearchPanel.setFocusToSearchField(); setTitle(strings.getString("frame.title")); } void newSourceAction_actionPerformed(ActionEvent e) { SourceFrame sourceFrame = new SourceFrame(new Source()); sourceFrame.setLocation(150,150); sourceFrame.pack(); sourceFrame.setVisible(true); } void exitSourceAction_actionPerformed(ActionEvent e) { dispose(); } void sourceSearchPanel_actionPerformed(ActionEvent e) { Source source = (Source)e.getSource(); SourceFrame sf = SourceFrame.fetchUniqueSourceFrame(source); sf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sf_actionPerformed(); } }); sf.pack(); sf.setVisible(true); } public void sf_actionPerformed() { sourceSearchPanel.repeatSearch(); } }