| 1 | |
package de.glossmaker.gui.gloss.importGloss; |
| 2 | |
|
| 3 | |
import java.awt.Dimension; |
| 4 | |
import java.awt.Point; |
| 5 | |
import java.awt.Toolkit; |
| 6 | |
import java.beans.PropertyChangeEvent; |
| 7 | |
import java.beans.PropertyChangeListener; |
| 8 | |
|
| 9 | |
import javax.swing.JFrame; |
| 10 | |
|
| 11 | |
import org.apache.log4j.Logger; |
| 12 | |
|
| 13 | |
import de.glossmaker.gloss.datastructure.GlossItems; |
| 14 | |
import de.glossmaker.gloss.language.Translation; |
| 15 | |
import de.glossmaker.gloss.listener.EActionCommands; |
| 16 | |
import de.glossmaker.gloss.observer.GlossItemsChangePublisher; |
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
public class ImportGlossFrame extends JFrame implements PropertyChangeListener { |
| 24 | |
private static final long serialVersionUID = -8272522699243198120L; |
| 25 | 0 | private final static Logger mLogger = Logger.getLogger(ImportGlossFrame.class); |
| 26 | |
|
| 27 | 0 | private GlossItems mGlossItems = null; |
| 28 | 0 | private GlossItems mImportItems = null; |
| 29 | |
|
| 30 | 0 | public ImportGlossFrame(String fileName, GlossItems items) { |
| 31 | 0 | mGlossItems = items; |
| 32 | |
try { |
| 33 | 0 | mImportItems = new GlossItems(); |
| 34 | 0 | mImportItems.readFromFile(fileName); |
| 35 | 0 | initialize(); |
| 36 | 0 | } catch(Exception e) { |
| 37 | 0 | mLogger.error(e); |
| 38 | 0 | } |
| 39 | 0 | GlossItemsChangePublisher.getInstance(mGlossItems).addPropertyChangeListener(this); |
| 40 | 0 | } |
| 41 | |
|
| 42 | |
private void initialize() { |
| 43 | 0 | this.setPreferredSize(new Dimension(800, 520)); |
| 44 | 0 | this.setSize(new Dimension(800, 520)); |
| 45 | 0 | this.setLocation(new Point(0, 0)); |
| 46 | 0 | this.setContentPane(new ImportGlossTablePanel(mGlossItems, mImportItems)); |
| 47 | 0 | this.setTitle(Translation.getInstance().getValue("importgloss.frame.title.text")); |
| 48 | 0 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
| 49 | 0 | int top = (screenSize.height - this.getHeight()) / 2; |
| 50 | 0 | int left = (screenSize.width - this.getWidth()) / 2; |
| 51 | 0 | this.setLocation(left, top); |
| 52 | 0 | } |
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public void propertyChange(PropertyChangeEvent event) { |
| 56 | 0 | if (event.getPropertyName().equals(EActionCommands.FILE_IMPORTED.toString()) || |
| 57 | |
event.getPropertyName().equals(EActionCommands.CLOSE_IMPORT_DIALOG.toString())) { |
| 58 | 0 | this.setVisible(false); |
| 59 | |
} |
| 60 | 0 | } |
| 61 | |
} |