📄 deploymentoptionsui.java
字号:
/* * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is * described in this document. In particular, and without limitation, these intellectual property rights may * include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents * or pending patent applications in the U.S. and in other countries. * * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. * standard license agreement and applicable provisions of the FAR and its supplements. * * Use is subject to license terms. * * This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo and * Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. * * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits r?serv?s. * * Sun Microsystems, Inc. d?tient les droits de propri?t? intellectuels relatifs ? la technologie incorpor?e dans * le produit qui est d?crit dans ce document. En particulier, et ce sans limitation, ces droits de propri?t? * intellectuelle peuvent inclure un ou plus des brevets am?ricains list?s ? l'adresse http://www.sun.com/patents * et un ou les brevets suppl?mentaires ou les applications de brevet en attente aux Etats - Unis et dans les * autres pays. * * L'utilisation est soumise aux termes du contrat de licence. * * Cette distribution peut comprendre des composants d?velopp?s par des tierces parties. * Sun, Sun Microsystems, le logo Sun et Java sont des marques de fabrique ou des marques d?pos?es de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.spot.spotworld.gui;import com.sun.spot.spotworld.CodingManager;import java.awt.BorderLayout;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.KeyEvent;import java.io.File;import javax.swing.BorderFactory;import javax.swing.Box;import javax.swing.BoxLayout;import javax.swing.JButton;import javax.swing.JCheckBox;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JTextField;/** * * @author randy */public class DeploymentOptionsUI extends JPanel implements ItemListener, ActionListener { private JDialog frame; private JCheckBox cleanCheckBox; private JCheckBox compileCheckBox; private JCheckBox deployCheckBox; private JLabel cleanCBLabel; private JLabel compileCBLabel; private JLabel deployCBLabel; private JTextField projectDirTextField; private JButton chooseDirButton; private boolean suiteOlderThanSource; private boolean userHasDoneSomething; private boolean userHitOkOrCancel; private boolean userOK; // Take action on user changes or not? (User may cancel for "No.") private JButton startButton; private JButton cancelButton; private CodingManager codingManager; public void init(){ suiteOlderThanSource = true; userHasDoneSomething = false; userHitOkOrCancel = false; userOK = false; codingManager = CodingManager.getInstance(); } public static DeploymentOptionsUI openNew(JFrame parentFrame){ DeploymentOptionsUI instance = new DeploymentOptionsUI(); instance.init(); instance.setLayout(new BorderLayout()); instance.createComponents(); instance.setInitialComponentState(); instance.addComponents(); instance.setOpaque(true); //content panes must be opaque instance.createFrame(parentFrame); //Create and set up the window. return instance; } public void createFrame(JFrame parentFrame){ frame = new JDialog(parentFrame, "Deployment Options", true); //Ture indicate modal. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setContentPane(this); //Display the window. frame.pack(); frame.setLocationRelativeTo(parentFrame); frame.setVisible(true); } public void createComponents(){ cleanCheckBox = new JCheckBox(); cleanCheckBox.setToolTipText("Remove the build directories, thereby forcing\nthe next compile to redo everything."); cleanCheckBox.addItemListener(this); compileCheckBox = new JCheckBox(); compileCheckBox.setToolTipText("Use ant to compile src/*.java files to build/*.class files \nand combine them into a suite file."); compileCheckBox.addItemListener(this); deployCheckBox = new JCheckBox(); deployCheckBox.setToolTipText("Deploys the suite file."); deployCheckBox.addItemListener(this); cleanCBLabel = new JLabel("Clean"); compileCBLabel = new JLabel("Compile (current suite is out of date w.r.t src)"); deployCBLabel = new JLabel("Deploy suite"); chooseDirButton = new JButton("Choose ..."); chooseDirButton.addActionListener(this); projectDirTextField = new JTextField(40); //set how many characters wide to start. projectDirTextField.setText(codingManager.getCurrentProjDir().getAbsolutePath()); projectDirTextField.addActionListener(this); cancelButton = new JButton("Cancel"); cancelButton.addActionListener(this); startButton = new JButton("Start"); startButton.addActionListener(this); } public void setInitialComponentState(){ cleanCheckBox.setSelected(false); boolean newSrc = isSourceNewerThanSuite(codingManager.getCurrentProjDir()); compileCheckBox.setSelected(newSrc); compileCheckBox.repaint(); String compileCBText = ""; if(newSrc) compileCBLabel.setText("Compile (current suite is out of date w.r.t src)"); else compileCBLabel.setText("Compile (current suite is more recent than src)"); compileCBLabel.revalidate(); compileCBLabel.doLayout(); deployCheckBox.setSelected(true); deployCheckBox.repaint(); } /* * return true if stuff in the current project directories /src * subdirectory is newer than the stuff in the /suite/image.suite file. * If EITHER does not exist return false. */ public boolean isSourceNewerThanSuite(File dir){ File srcDir = new File(codingManager.getCurrentProjDir().getAbsolutePath()+ "/src"); File suiteFile = new File(dir.getAbsolutePath() + "/suite/image.suite"); if( (! suiteFile.exists()) || (! srcDir.exists())) return false; long tSrc = codingManager.getMostRecentModTime(srcDir); if(! suiteFile.exists()){return true;} return tSrc > suiteFile.lastModified(); } public void addComponents(){ JLabel title = new JLabel("Use this directory (contains a build.xml)"); add(title, BorderLayout.PAGE_START); JPanel gbPanel = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 0.5; c.weighty = 0.5; c.insets = new Insets(0,3,0,3); c.anchor = c.LINE_START; c.gridy = 0; c.gridx = 0; c.gridwidth = 3; gbPanel.add(projectDirTextField, c); gbPanel.add(chooseDirButton); c.gridwidth = 1; c.gridy = 1; c.gridx = 0; c.weightx = 0.2; gbPanel.add(cleanCheckBox, c); c.gridx = 1; c.weightx = 0.8; gbPanel.add(cleanCBLabel, c); c.gridy = 2; c.gridx = 0; c.weightx = 0.2; gbPanel.add(compileCheckBox, c); c.gridx = 1; c.weightx = 0.8; String compileCBText = ""; gbPanel.add(compileCBLabel, c); c.gridy = 3; c.gridx = 0; c.weightx = 0.2; gbPanel.add(deployCheckBox, c); c.gridx = 1; c.weightx = 0.8; gbPanel.add(deployCBLabel, c); add(gbPanel, BorderLayout.CENTER); JPanel okCancelPanel = new JPanel(); okCancelPanel.setLayout(new BoxLayout(okCancelPanel, BoxLayout.X_AXIS)); okCancelPanel.add(Box.createHorizontalGlue()); okCancelPanel.add(cancelButton); okCancelPanel.add(startButton); startButton.setMnemonic(KeyEvent.VK_ENTER); okCancelPanel.setBorder(BorderFactory.createEmptyBorder( 10, 0, 10, 10)); add(okCancelPanel, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(20,20,20,20)); startButton.setSelected(true); startButton.setFocusPainted(true); } public boolean isCleanSelected(){ return cleanCheckBox.isSelected(); } public boolean isCompiledSelected(){ return compileCheckBox.isSelected(); } public boolean isDeploySelected(){ return deployCheckBox.isSelected(); } /** Listens to the check boxes. */ public void itemStateChanged(ItemEvent e) { userHasDoneSomething = true; int index = 0; char c = '-'; Object source = e.getItemSelectable(); } public void actionPerformed(ActionEvent e){ if(e.getSource() == projectDirTextField){ String newDirName = projectDirTextField.getText(); newProjectDirInput(newDirName); return; } if(e.getSource() == chooseDirButton){ File f = CodingManager.getInstance().getBuildFileFromUser(this); String newDirName = f.getAbsolutePath(); projectDirTextField.setText(newDirName); projectDirTextField.repaint(); newProjectDirInput(newDirName); return; } if(e.getSource() == startButton) { userHitOkOrCancel = true; boolean ok = doProjDirCheck(projectDirTextField.getText()); if (ok) { userOK = true; frame.dispose(); } else { userOK = false; } } if(e.getSource() == cancelButton){ userHitOkOrCancel = true; userOK = false; frame.dispose(); } } public boolean doProjDirCheck(String newDirName){ String status = codingManager.checkIfProperProjDirectory(newDirName); if( status.equals("OK")){ return true; } else { informUser(status, "Problem with directory name"); projectDirTextField.setText(codingManager.getCurrentProjDir().getAbsolutePath()); projectDirTextField.repaint(); return false; } } /* * User has provided a new name. It may not be a proper directory, check that. * If it is okay, set it as the current project in the CodingManager, and reset the * initial check box state as appropriate. */ public void newProjectDirInput(String newDirName){ boolean legit = doProjDirCheck(newDirName); if(!legit) return; File newDir = new File(newDirName); codingManager.setCurrentProjDir(newDir); setInitialComponentState(); } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("Deploymnet options"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Create and set up the content pane. JComponent newContentPane = new DeploymentOptionsUI(); newContentPane.setOpaque(true); //content panes must be opaque frame.setContentPane(newContentPane); //Display the window. frame.pack(); frame.setVisible(true); } public void informUser(String message, String frameTitle ){ JOptionPane.showMessageDialog(this, message, frameTitle, JOptionPane.WARNING_MESSAGE); } public boolean askUserApplyChanges(){ Object[] options = { "No", "Yes"}; int n = JOptionPane.showOptionDialog(null, "Apply these changes?", "", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); switch(n){ case(0): return false; case(1): return true; } return false; } public boolean isUserOK() { return userOK; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -