Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,3 +1,18 @@
{{omit from|ACL2}}
{{omit from|awk|No access to GUI functions.}}
{{omit from|Batch File|No access to GUI functions.}}
{{omit from|Blast}}
{{omit from|Logtalk}}
{{omit from|Lotus 123 Macro Scripting}}
{{omit from|M4}}
{{omit from|Maxima}}
{{omit from|PARI/GP}}
{{omit from|PHP|PHP cannot create windows by itself}}
{{omit from|PostScript}}
{{omit from|Retro}}
{{omit from|TI-83 BASIC|Does not have windows.}}
{{omit from|TI-89 BASIC|Does not have windows.}}
Treat windows or at least window identities as [[wp:First-class_object|first class objects]].
*Store window identities in variables, compare them for equality.

View file

@ -0,0 +1,144 @@
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.lang.reflect.InvocationTargetException;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class WindowController extends JFrame {
// Create UI on correct thread
public static void main( final String[] args ) {
EventQueue.invokeLater (
new Runnable() {
public void run() {
new WindowController();
}
}
);
}
private JComboBox list;
// Button class to call the right method
private class ControlButton extends JButton {
private ControlButton( final String name ) {
super(
new AbstractAction( name ) {
public void actionPerformed( final ActionEvent e ) {
try {
WindowController.class.getMethod( "do" + name )
.invoke ( WindowController.this );
} catch ( final Exception x ) { // poor practice
x.printStackTrace(); // also poor practice
}
}
}
);
}
}
// UI for controlling windows
public WindowController() {
super( "Controller" );
final JPanel main = new JPanel();
final JPanel controls = new JPanel();
setLocationByPlatform( true );
setResizable( false );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setLayout( new BorderLayout( 3, 3 ) );
getRootPane().setBorder( new EmptyBorder( 3, 3, 3, 3 ) );
add( new JLabel( "Add windows and control them." ), BorderLayout.NORTH );
main.add( list = new JComboBox() );
add( main, BorderLayout.CENTER );
controls.setLayout( new GridLayout( 0, 1, 3, 3 ) );
controls.add( new ControlButton( "Add" ) );
controls.add( new ControlButton( "Hide" ) );
controls.add( new ControlButton( "Show" ) );
controls.add( new ControlButton( "Close" ) );
controls.add( new ControlButton( "Maximise" ) );
controls.add( new ControlButton( "Minimise" ) );
controls.add( new ControlButton( "Move" ) );
controls.add( new ControlButton( "Resize" ) );
add( controls, BorderLayout.EAST );
pack();
setVisible( true );
}
// These are the windows we're controlling, but any JFrame would do
private static class ControlledWindow extends JFrame {
private int num;
public ControlledWindow( final int num ) {
super( Integer.toString( num ) );
this.num = num;
setLocationByPlatform( true );
getRootPane().setBorder( new EmptyBorder( 3, 3, 3, 3 ) );
setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
add( new JLabel( "I am window " + num + ". Use the controller to control me." ) );
pack();
setVisible( true );
}
public String toString() {
return "Window " + num;
}
}
// Here comes the useful bit - window control code
// Everything else was just to allow us to do this!
public void doAdd() {
list.addItem( new ControlledWindow( list.getItemCount () + 1 ) );
pack();
}
public void doHide() {
( ( JFrame ) list.getSelectedItem() ).setVisible( false );
}
public void doShow() {
( ( JFrame ) list.getSelectedItem() ).setVisible( true );
}
public void doClose() {
( ( JFrame ) list.getSelectedItem() ).dispose();
}
public void doMinimise() {
( ( JFrame ) list.getSelectedItem() ).setState( Frame.ICONIFIED );
}
public void doMaximise() {
( ( JFrame ) list.getSelectedItem() ).setExtendedState( Frame.MAXIMIZED_BOTH );
}
public void doMove() {
( ( JFrame ) list.getSelectedItem() ).setLocation
(
Integer.parseInt( JOptionPane.showInputDialog( "Horizontal position?" ) ),
Integer.parseInt( JOptionPane.showInputDialog( "Vertical position?" ) )
);
}
public void doResize() {
final JFrame window = ( JFrame ) list.getSelectedItem();
window.setBounds
(
window.getX(),
window.getY(),
Integer.parseInt( JOptionPane.showInputDialog( "Width?" ) ),
Integer.parseInt( JOptionPane.showInputDialog( "Height?" ) )
);
}
}

View file

@ -0,0 +1,7 @@
nb=NotebookCreate[]; (*Create a window and store in a variable*)
nb===nb2 (*test for equality with another window object*)
SetOptions[nb,Visible->False](*Hide*)
SetOptions[nb,Visible->True](*Show*)
NotebookClose[nb] (*Close*)
SetOptions[nb,WindowMargins->{{x,Automatic},{y,Automatic}}](*Move to x,y screen position*)
SetOptions[nb,WindowSize->{100,100}](*Resize*)

View file

@ -53,10 +53,10 @@ proc resizeWin {} {
}
}
grid [label .l -text "Window handle:"] [label .l2 -textvariable win]
grid [label .l -text "Window handle:"] [label .l2 -textvariable win]
grid [button .b1 -text "Open/Reset" -command openWin] -
grid [button .b2 -text "Close" -command closeWin] -
grid [button .b3 -text "Minimize" -command minimizeWin] -
grid [button .b4 -text "Maximize" -command maximizeWin] -
grid [button .b5 -text "Move" -command moveWin] -
grid [button .b6 -text "Resize" -command resizeWin] -
grid [button .b2 -text "Close" -command closeWin] -
grid [button .b3 -text "Minimize" -command minimizeWin] -
grid [button .b4 -text "Maximize" -command maximizeWin] -
grid [button .b5 -text "Move" -command moveWin] -
grid [button .b6 -text "Resize" -command resizeWin] -