/**
* 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;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class SourceFrame extends JFrame{
Source source;
SourcePanel sp;
static java.util.Map openSourceFrames = new java.util.HashMap(6);
public static SourceFrame fetchUniqueSourceFrame(Source source) {
Integer sourceid = source.getID();
if (openSourceFrames.containsKey(sourceid)) {
return (SourceFrame)openSourceFrames.get(sourceid);
} else {
SourceFrame sourceframe = new SourceFrame(source);
openSourceFrames.put(sourceid, sourceframe);
sourceframe.setLocation(150,150);
return sourceframe;
}
}
public SourceFrame(Source source) {
this.source=source;
sp = new SourcePanel(source);
if(source.getID() >= 0)
this.setTitle(sp.strings.getString("mainHeader.edit") + ": "+source.getName());
else
this.setTitle(sp.strings.getString("mainHeader.new"));
sp.addExitListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
exitAction_ActionPerformed();
}
});
getContentPane().add(sp);
setResizable(false);
}
public void addActionListener(ActionListener l) {
sp.addActionListener(l);
}
public void exitAction_ActionPerformed() {
dispose();
Integer id = source.getID();
openSourceFrames.remove(id);
}
}