001: /*
002: * HexViewer.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.dialogs;
013:
014: import java.awt.BorderLayout;
015: import java.awt.FlowLayout;
016: import java.awt.event.ActionEvent;
017: import java.awt.event.ActionListener;
018: import java.awt.event.WindowEvent;
019: import java.awt.event.WindowListener;
020: import javax.swing.ActionMap;
021: import javax.swing.InputMap;
022: import javax.swing.JButton;
023: import javax.swing.JComponent;
024: import javax.swing.JDialog;
025: import javax.swing.JPanel;
026: import javax.swing.WindowConstants;
027: import workbench.WbManager;
028: import workbench.gui.WbSwingUtilities;
029: import workbench.gui.actions.EscAction;
030: import workbench.gui.components.BlobHandler;
031: import workbench.gui.components.HexPanel;
032: import workbench.log.LogMgr;
033: import workbench.resource.ResourceMgr;
034: import workbench.resource.Settings;
035:
036: /**
037: * @author support@sql-workbench.net
038: */
039: public class HexViewer extends JDialog implements ActionListener,
040: WindowListener {
041: private HexPanel panel;
042: private JButton closeButton = new JButton(ResourceMgr
043: .getString("LblClose"));
044: private final String settingsId = "workbench.gui.imageviewer";
045: private EscAction escAction;
046:
047: /** Creates a new instance of ImageViewer */
048: public HexViewer(JDialog parent, String title) {
049: super (parent, title, true);
050: this .getContentPane().setLayout(new BorderLayout());
051: this .setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
052: panel = new HexPanel();
053: this .getContentPane().add(panel, BorderLayout.CENTER);
054: JPanel buttonPanel = new JPanel();
055: buttonPanel
056: .setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
057: buttonPanel.add(closeButton);
058: closeButton.addActionListener(this );
059: this .getContentPane().add(buttonPanel, BorderLayout.SOUTH);
060: this .addWindowListener(this );
061: if (!Settings.getInstance().restoreWindowSize(this , settingsId)) {
062: setSize(320, 200);
063: }
064:
065: getRootPane().setDefaultButton(closeButton);
066: InputMap im = this .getRootPane().getInputMap(
067: JComponent.WHEN_IN_FOCUSED_WINDOW);
068: ActionMap am = this .getRootPane().getActionMap();
069: escAction = new EscAction(this );
070: im.put(escAction.getAccelerator(), escAction.getActionName());
071: am.put(escAction.getActionName(), escAction);
072:
073: WbSwingUtilities.center(this , WbManager.getInstance()
074: .getCurrentWindow());
075: }
076:
077: public void setData(byte[] data) {
078: panel.setData(data);
079: }
080:
081: public void actionPerformed(ActionEvent e) {
082: this .setVisible(false);
083: this .dispose();
084: }
085:
086: public void windowOpened(WindowEvent e) {
087: }
088:
089: public void windowClosing(WindowEvent e) {
090: }
091:
092: public void windowClosed(WindowEvent e) {
093: Settings.getInstance().storeWindowSize(this , settingsId);
094: }
095:
096: public void windowIconified(WindowEvent e) {
097: }
098:
099: public void windowDeiconified(WindowEvent e) {
100: }
101:
102: public void windowActivated(WindowEvent e) {
103: }
104:
105: public void windowDeactivated(WindowEvent e) {
106: }
107:
108: }
|