📄 travellerframe.java
字号:
//-----------------------------------------------------------------------------
// Traveller -- A Java Application and Applet
//
// A Genetic Algorithm for Solving the Travelling Salesman Problem
//
// TravellerFrame.java
// version 1.1.0
//
// Copyright 2000-2001 Scott Robert Ladd. All rights reserved.
//
// For more information about this program, contact:
//
// Scott Robert Ladd
// scott@coyotegulch.com
// http://www.coyotegulch.com
//
//-----------------------------------------------------------------------------
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
//
// Free Software Foundation, Inc.
// 59 Temple Place - Suite 330
// Boston, MA 02111-1307, USA.
//-----------------------------------------------------------------------------
/*
** Move this down where other classes can see it, not sitting at the top
** level where it cannot be packaged.
*/
package com.well.www.user.xanthian.java.ui;
import java.awt.*;
import java.awt.event.*;
public class TravellerFrame
extends Frame
implements WindowListener
{
// This size includes its internal padding, but not its external padding.
public final static int PLAYFIELD_SIZE = 400;
// size of pink edge around playfield
public final static int PLAYFIELD_EXTERNAL_PADDING = 8;
/*
** KPD FIXME Stupid border insets aren't available yet, title bar size
** may never be, so pad generously to compensate. For all the world it
** looks like you have to do this twice, once to get the inset sizes,
** and then again to build it. Why didn't the idiotic Frame interface
** design, _knowing_ that every window manager's idea of the appropriate
** decoration sizes differs, just let me specify the net internal,
** rather than gross external, dimensions of the frame? Grrr. Do this
** right when I know how; Scott's EdgedPanel has clues. KPD.
**
** Mix and match rants, I said it again another way, then consolidated
** the source codes:
**
** KPD FIXME -- At best these are guesses, and should be inquired of the
** platform's Java peer interfaces; what a miserable mess for an api and
** the programmer that the frame is specified by its outside dimensions,
** modifiable at whim by the user or the platform windowing system
** provider, and so not entirely under programmer control, instead of by
** its inside dimensions, which is what the programmer wants to control
** anyway. These don't have to be constants, and logical packaging is
** for this very frame object to learn their values. This would also be
** a dandy place to bury the details of asking for an outer dimension,
** by providing a service to clients of this class that sets up a window
** when requested by its net dimensions. The only problem is that we're
** porking up this simple package into a heavy-weight. Is there a
** better approach; perhaps a TravellerConstants package, or is that too
** much the Fortran anonymous BLOCK COMMON approach?
*/
public final static int FRAME_EDGE_THICKNESS = 3;
private final static int FRAME_TITLE_HEIGHT = 19;
private static boolean isApplication = false;
/*
** Use this to keep the four smaller windows a consistent width, which
** looks dressy.
*/
public final static int PLAYFIELD_FRAME_WIDTH =
PLAYFIELD_SIZE +
( 2 * PLAYFIELD_EXTERNAL_PADDING ) +
( 2 * FRAME_EDGE_THICKNESS ) ;
public TravellerFrame(String str)
{
super(str);
addWindowListener(this);
setResizable(false);
}
/*
** Bletch. Internet Explorer, and perhaps other browsers, put a trailer
** status bar the size of the title bar _under_ the window, and still
** chew it out of the interior allowance, so we need to slime things up
** here and in the main program source files' init() methods to cater
** for the needed added height, and put another level of indirection
** everywhere that was using the FRAME_TITLE_HEIGHT public variable,
** which now goes private.
*/
public static boolean getApplicationStatus()
{
return isApplication;
}
public static void setApplicationStatus( boolean isApp )
{
isApplication = isApp;
}
public static int getFrameEdgeThickness()
{
return FRAME_EDGE_THICKNESS;
}
public static int getTitleBarHeightAllowance()
{
if ( isApplication )
{ return FRAME_TITLE_HEIGHT; }
else
{ return 2 * FRAME_TITLE_HEIGHT; }
}
public void windowOpened(WindowEvent e)
{
// not used
}
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
/*
** We are trying here to make sure that when a web window refresh
** occurs, which closes the applet windows, there are no residual static
** references left hanging to prevent windows from reopening when the
** applet is relaunched.
**
** Unfortunately, this also nukes the stand alone application when the
** pop-up seeder windows close. Oh, well.
*/
public void windowClosed(WindowEvent e)
{
// dispose();
// System.exit(0);
}
public void windowIconified(WindowEvent e)
{
// not used
}
public void windowDeiconified(WindowEvent e)
{
// not used
}
public void windowActivated(WindowEvent e)
{
// not used
}
public void windowDeactivated(WindowEvent e)
{
// not used
}
public void windowClose()
{
this.setVisible(false);
try { this.finalize(); }
catch ( Throwable t )
{
System.out.println("TravellerFrame.windowClose() caught a Throwable");
}
this.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -