import java.awt.event.*; import java.awt.*; import java.beans.*; import java.util.*; import java.net.*; import java.io.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import javax.swing.plaf.*; public class HEI_Desk_14 extends JFrame implements ActionListener, VetoableChangeListener { private JDesktopPane desktop; private JMenuItem openItem, exitItem, nextItem, cascadeItem, tileItem, short_File; private JMenuItem openCal, about, openPP, NCRform, N2TformI, N2TformN, N2H, formB, formO, formC; private JMenuItem JbPrformB1,JbPrformB2,JbPrformB3,JbPrformB4,JbPrformO1,JbPrformO2,JbPrformO3,JbPrformO4; private JMenuItem JbPrformC1,JbPrformC2,JbPrformC3,JbPrformC4,JbPrformBa,JbPrformOa,JbPrformCa; private JCheckBoxMenuItem dragItem; private JButton winButton, javaButton, motifButton; String HEI_DIR = "./htm", HST_DIR = "./hst", if_hei, savestg = "save"; JFileChooser fc = new JFileChooser(HEI_DIR); JFileChooser fcr = new JFileChooser(HST_DIR); HEI_Html_Filter filter = new HEI_Html_Filter(); HEI_Filter hei_filter = new HEI_Filter(); HEI_Rev_Filter rev_filter = new HEI_Rev_Filter(); static final Integer DOCLAYER = new Integer(5); static final Integer TOOLLAYER = new Integer(6); static final Integer HELPLAYER = new Integer(7); int nextFrameX = 0; int nextFrameY = 0; int frameDistance = 0; static final String ABOUTMSG = "HEI - HEICO Engineering Application Tool\n"; public HEI_Desk_14() { super( "HEI - Engineering Application Tool" ); final int inset = 10; Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds ( inset, inset/2, screenSize.width - inset*2, screenSize.height - inset*2 ); desktop = new JDesktopPane(); getContentPane().add( desktop ); buildMenus(); buildLaF(); show(); } protected void buildLaF() { // Add the look and feel controls using regular AWT buttons JPanel lnfPanel = new JPanel(); LnFListener lnfListener = new LnFListener(this); javaButton = new JButton("Metal"); javaButton.addActionListener(lnfListener); lnfPanel.add(javaButton); motifButton = new JButton("Motif"); motifButton.addActionListener(lnfListener); lnfPanel.add(motifButton); winButton = new JButton("Windows"); winButton.addActionListener(lnfListener); lnfPanel.add(winButton); getContentPane().add(lnfPanel, BorderLayout.SOUTH); //UIManager.addPropertyChangeListener(new UISwitchListener((JComponent)getRootPane())); } protected void buildMenus() { JMenuBar menuBar = new JMenuBar(); setJMenuBar( menuBar ); JMenu file = buildfileMenu(); JMenu wind = buildwindMenu(); JMenu formJ = buildFormJMenu(); JMenu formN = buildFormNMenu(); JMenu help = buildHelpMenu(); menuBar.add(file); menuBar.add(wind); menuBar.add(formJ); menuBar.add(formN); menuBar.add(help); } protected JMenu buildfileMenu() { JMenu file = new JMenu("File"); openItem = new JMenuItem( "Open File" ); openCal = new JMenuItem( "Open Calendar" ); openPP = new JMenuItem("Open Part Number Page"); exitItem = new JMenuItem( "Exit" ); openItem.addActionListener(this); openCal.addActionListener(this); openPP.addActionListener(this); exitItem.addActionListener(this); file.add(openItem); file.add(openCal); file.add(openPP); file.add(exitItem); return file; } protected JMenu buildwindMenu() { JMenu wind = new JMenu( "Window" ); nextItem = new JMenuItem( "Next" ); cascadeItem = new JMenuItem( "Cascade" ); tileItem = new JMenuItem( "Tile" ); dragItem = new JCheckBoxMenuItem( "Drag Outline" ); nextItem.addActionListener(this); cascadeItem.addActionListener(this); tileItem.addActionListener(this); dragItem.addActionListener(this); wind.add(nextItem); wind.add(cascadeItem); wind.add(tileItem); wind.add(dragItem); return wind; } protected JMenu buildFormJMenu() { JMenu formJ = new JMenu("JB Print Forms"); formB = new JMenu("Start JB Print Form (Beeper - HEISCO1)"); JbPrformB1 = new JMenuItem("Chameleon-1"); JbPrformB2 = new JMenuItem("Chameleon-2"); JbPrformB3 = new JMenuItem("Chameleon-3"); JbPrformB4 = new JMenuItem("Chameleon-4"); formO = new JMenu("Start JB Print Form (Office - MEATII)"); JbPrformO1 = new JMenuItem("Chameleon-1"); JbPrformO2 = new JMenuItem("Chameleon-2"); JbPrformO3 = new JMenuItem("Chameleon-3"); JbPrformO4 = new JMenuItem("Chameleon-4"); formC = new JMenu("Start JB Print Form (Chameleon - BLACMM1)"); JbPrformC1 = new JMenuItem("Chameleon-1"); JbPrformC2 = new JMenuItem("Chameleon-2"); JbPrformC3 = new JMenuItem("Chameleon-3"); JbPrformC4 = new JMenuItem("Chameleon-4"); JbPrformB1.addActionListener(this);JbPrformB2.addActionListener(this);JbPrformB3.addActionListener(this); JbPrformB4.addActionListener(this);JbPrformO1.addActionListener(this);JbPrformO2.addActionListener(this); JbPrformO3.addActionListener(this);JbPrformO4.addActionListener(this);JbPrformC1.addActionListener(this); JbPrformC2.addActionListener(this);JbPrformC3.addActionListener(this);JbPrformC4.addActionListener(this); formB.add(JbPrformB1);formB.add(JbPrformB2);formB.add(JbPrformB3);formB.add(JbPrformB4); formO.add(JbPrformO1);formO.add(JbPrformO2);formO.add(JbPrformO3);formO.add(JbPrformO4); formC.add(JbPrformC1);formC.add(JbPrformC2);formC.add(JbPrformC3);formC.add(JbPrformC4); formJ.add(formB);formJ.add(formO);formJ.add(formC); return formJ; } protected JMenu buildFormNMenu() { JMenu formN = new JMenu("NCR Forms"); NCRform = new JMenuItem("Start NCR Query Form"); N2TformI = new JMenuItem("Start Index to Java Table Form"); N2TformN = new JMenuItem("Start NCR to Java Table Form"); N2H = new JMenuItem("Run NCR DB To Html"); NCRform.addActionListener(this); N2TformI.addActionListener(this); N2TformN.addActionListener(this); N2H.addActionListener(this); formN.add(NCRform);formN.add(N2TformI);formN.add(N2TformN);formN.add(N2H); return formN; } protected JMenu buildHelpMenu() { JMenu help = new JMenu("Help"); about = new JMenuItem("About HEI..."); about.addActionListener(this); help.add(about); return help; } public void selectNextWindow() { JInternalFrame[] frames = desktop.getAllFrames(); for ( int i = 0; i < frames.length; i++ ) { if ( frames[i].isSelected() ) { try { int next = i + 1; while ( next != i && frames[next].isIcon() ) { next++; } if ( next == i ) { return; } frames[next].setSelected( true ); frames[next].toFront(); return; } catch( PropertyVetoException e ) {} } } } public void tileWindows() { JInternalFrame[] frames = desktop.getAllFrames(); int frameCount = 0; for ( int i = 0; i < frames.length; i++ ) { if ( !frames[i].isIcon() ) { frameCount++; } } int row = (int)Math.sqrt( frameCount ); int col = frameCount / row; int extra = frameCount % row; int width = desktop.getWidth() / col; int height = desktop.getHeight() / row; int r = 0; int c = 0; for ( int i = 0; i < frames.length; i++ ) { if ( !frames[i].isIcon() ) { try { frames[i].setMaximum( false ); frames[i].reshape( c * width, r * height, width, height ); r++; if ( r == row ) { r = 0; c++; if ( c == col - extra ) { row++; height = desktop.getHeight() / row; } } } catch( PropertyVetoException e ) {} } } } public void cascadeWindows() { JInternalFrame[] frames = desktop.getAllFrames(); int x = 0; int y = 0; int width = desktop.getWidth() / 2; int height = desktop.getHeight() / 2; for ( int i = 0; i < frames.length; i++ ) { if ( !frames[i].isIcon() ) { try { frames[i].setMaximum( false ); frames[i].reshape( x, y, width, height ); x += frameDistance; y += frameDistance; if ( x + width > desktop.getWidth() ) x = 0; if ( y + height > desktop.getHeight() ) y = 0; } catch( PropertyVetoException e ) {} } } } public void createInternalFrame( Component c, String s ) { JInternalFrame frame = new JInternalFrame( "File View", true, true, true, true ); frame.getContentPane().add( c ); desktop.add( frame, DOCLAYER ); frame.addVetoableChangeListener(this); int width = desktop.getWidth() / 2; int height = desktop.getHeight() / 2; frame.setBounds( 10, 10, 560, 600); //frame.reshape( nextFrameX, nextFrameY, width, height ); frame.setOpaque( true ); frame.setVisible(true); try { frame.setSelected( true ); } catch( PropertyVetoException pve ) {} if ( frameDistance == 0 ) frameDistance = frame.getHeight() / 5; nextFrameX += frameDistance; nextFrameY += frameDistance; if ( nextFrameX + width > desktop.getWidth() ) nextFrameX = 0; if ( nextFrameY + height > desktop.getHeight() ) nextFrameY = 0; } public Component createEditorPane( URL u ) { JEditorPane panel = new JEditorPane(); panel.setEditable( false ); try { panel.setPage( u ); } catch ( IOException io ) { panel.setText("Error: " + io ); } return new JScrollPane( panel ); } public void vetoableChange( PropertyChangeEvent event ) throws PropertyVetoException { JInternalFrame frame = (JInternalFrame)event.getSource(); String name = event.getPropertyName(); Object value = event.getNewValue(); if ( name.equals ( "closed" ) && value.equals ( Boolean.TRUE ) ) { int result = JOptionPane.showInternalConfirmDialog ( frame, "Do you really want to close?" ); if ( result == JOptionPane.NO_OPTION || result == JOptionPane.CANCEL_OPTION ) { throw new PropertyVetoException ( "Closed canceled", event ); } } } public void actionPerformed( ActionEvent evt ) { Object source = evt.getSource(); if ( source == openItem ) { fc.addChoosableFileFilter( filter ); int returnVal = fc.showOpenDialog( HEI_Desk_14.this ); if ( returnVal == JFileChooser.APPROVE_OPTION ) { File file = fc.getSelectedFile(); try { URL fileName = new URL( "file:///" + file.toString() ); createInternalFrame( createEditorPane( fileName ), fileName.toString() ); } catch (MalformedURLException m) { System.err.println("Malformed URL: " + file); } } } else if ( source == NCRform ) { JInternalFrame doc = new NCR_IF_Man20f (); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformB1 ) { JInternalFrame doc = new JbPr_IF_14c ( "Beeper_HEISCO1@CHAMELEON-1" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformB2 ) { JInternalFrame doc = new JbPr_IF_14c ( "Beeper_HEISCO1@CHAMELEON-2" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformB3 ) { JInternalFrame doc = new JbPr_IF_14c ( "Beeper_HEISCO1@CHAMELEON-3" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformB4 ) { JInternalFrame doc = new JbPr_IF_14c ( "Beeper_HEISCO1@CHAMELEON-4" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformO1 ) { JInternalFrame doc = new JbPr_IF_14c ( "Office_MEATII@CHAMELEON-1" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformO2 ) { JInternalFrame doc = new JbPr_IF_14c ( "Office_MEATII@CHAMELEON-2" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformO3 ) { JInternalFrame doc = new JbPr_IF_14c ( "Office_MEATII@CHAMELEON-3" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformO4 ) { JInternalFrame doc = new JbPr_IF_14c ( "Office_MEATII@CHAMELEON-4" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformC1 ) { JInternalFrame doc = new JbPr_IF_14c ( "Chameleon_BLACMM1@CHAMELEON-1" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformC2 ) { JInternalFrame doc = new JbPr_IF_14c ( "Chameleon_BLACMM1@CHAMELEON-2" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformC3 ) { JInternalFrame doc = new JbPr_IF_14c ( "Chameleon_BLACMM1@CHAMELEON-3" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == JbPrformC4 ) { JInternalFrame doc = new JbPr_IF_14c ( "Chameleon_BLACMM1@CHAMELEON-4" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == N2TformI ) { JInternalFrame doc = new Ncr_DB2Tbl_12c ( "Index" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); //doc.setResizeable(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == N2TformN ) { JInternalFrame doc = new Ncr_DB2Tbl_12c ( "NCR" ); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); //doc.setResizeable(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == N2H ) { new Ncr2Htm_01(); } else if ( source == openCal ) { JInternalFrame doc = new JCalendarFrame(); desktop.add(doc, DOCLAYER); try { doc.setVisible(true); doc.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == openPP ) { JInternalFrame help = new PN_Page(); desktop.add(help, DOCLAYER); try { help.setVisible(true); help.setSelected(true); } catch (java.beans.PropertyVetoException e2) {} } else if ( source == about ) { JOptionPane.showMessageDialog(this, ABOUTMSG); } else if ( source == exitItem ) { System.exit( 0 ); } else if ( source == nextItem ) { selectNextWindow(); } else if ( source == tileItem ) { tileWindows(); } else if ( source == cascadeItem ) { cascadeWindows(); } else if ( source == dragItem ) { desktop.putClientProperty( "JDesktopPane.dragMode", dragItem.isSelected() ? "outline" : null ); } } public static void main( String args[] ) { HEI_Desk_14 app = new HEI_Desk_14(); app.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } }); } }