public void init(SshToolsApplication application,
SshToolsApplicationPanel panel) throws SshToolsApplicationException {
this.panel = panel;
this.application = application;
if (application != null) {
setTitle(ConfigurationLoader.getVersionString(
application.getApplicationName(),
application.getApplicationVersion())); // + " " + application.getApplicationVersion());
}
// Register the File menu
panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu(
"File", "File", 'f", 0));
// Register the Exit action
if (showExitAction && (application != null)) {
panel.registerAction(exitAction = new ExitAction(application, this));
// Register the New Window Action
}
if (showNewWindowAction && (application != null)) {
panel.registerAction(newWindowAction = new NewWindowAction(
application));
// Register the Help menu
}
panel.registerActionMenu(new SshToolsApplicationPanel.ActionMenu(
"Help", "Help", 'h", 99));
// Register the About box action
if (showAboutBox && (application != null)) {
panel.registerAction(aboutAction = new AboutAction(this, application));
}
getApplicationPanel().rebuildActionComponents();
JPanel p = new JPanel(new BorderLayout());
if (panel.getJMenuBar() != null) {
setJMenuBar(panel.getJMenuBar());
}
if (panel.getToolBar() != null) {
JPanel t = new JPanel(new BorderLayout());
t.add(panel.getToolBar(), BorderLayout.NORTH);
t.add(toolSeparator = new JSeparator(JSeparator.HORIZONTAL),
BorderLayout.SOUTH);
toolSeparator.setVisible(panel.getToolBar().isVisible());
final SshToolsApplicationPanel pnl = panel;
panel.getToolBar().addComponentListener(new ComponentAdapter() {
public void componentHidden(ComponentEvent evt) {
log.debug("Tool separator is now " +
pnl.getToolBar().isVisible());
toolSeparator.setVisible(pnl.getToolBar().isVisible());
}
});
p.add(t, BorderLayout.NORTH);
}
p.add(panel, BorderLayout.CENTER);
if (panel.getStatusBar() != null) {
p.add(panel.getStatusBar(), BorderLayout.SOUTH);
}
getContentPane().setLayout(new GridLayout(1, 1));
getContentPane().add(p);
// Watch for the frame closing
//setDefaultCloseOperation(JInternalFrame.DO_NOTHING_ON_CLOSE);
addVetoableChangeListener(new VetoableChangeListener() {
public void vetoableChange(PropertyChangeEvent evt)
throws PropertyVetoException {
if (application != null) {
application.closeContainer(SshToolsApplicationInternalFrame.this);
} else {
if (evt.getPropertyName().equals(IS_CLOSED_PROPERTY)) {
boolean changed = ((Boolean) evt.getNewValue()).booleanValue();
if (changed) {
int confirm = JOptionPane.showOptionDialog(SshToolsApplicationInternalFrame.this,
"Close " + getTitle() + "?",
"Close Operation",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null,
null, null);
if (confirm == 0) {
SshToolsApplicationInternalFrame.this.getDesktopPane()
.remove(SshToolsApplicationInternalFrame.this);
}
}
}
}
}
});
/*this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
if(application!=null)
application.closeContainer(SshToolsApplicationFrame.this);
else
hide();
}
});
// If this is the first frame, center the window on the screen
/*Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
boolean found = false;
if (application!=null && application.getContainerCount() != 0) {
for (int i = 0; (i < application.getContainerCount()) && !found;
i++) {
SshToolsApplicationContainer c = application.getContainerAt(i);
if (c instanceof SshToolsApplicationFrame) {
SshToolsApplicationFrame f = (SshToolsApplicationFrame) c;
setSize(f.getSize());
Point newLocation = new Point(f.getX(), f.getY());
newLocation.x += 48;
newLocation.y += 48;
if (newLocation.x > (screenSize.getWidth() - 64)) {
newLocation.x = 0;
}
if (newLocation.y > (screenSize.getHeight() - 64)) {
newLocation.y = 0;
}
setLocation(newLocation);
found = true;
}
}
}
if (!found) {
// Is there a previous stored geometry we can use?
if (PreferencesStore.preferenceExists(PREF_LAST_FRAME_GEOMETRY)) {
setBounds(PreferencesStore.getRectangle(
PREF_LAST_FRAME_GEOMETRY, getBounds()));
}
else {
pack();
UIUtil.positionComponent(SwingConstants.CENTER, this);
}
}*/
pack();
}
|