?? install.java
字號(hào):
{ System.exit(0); } protected JPanel createButtonPanel() { JPanel buttonPanel = new JPanel(); buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0)); // Create and set layout. GridBagLayout grid = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); buttonPanel.setLayout(grid); // Create labels and fields. c.insets = new Insets(2, 2, 2, 2); // Okay button. c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.anchor = GridBagConstraints.EAST; grid.setConstraints(m_okayButton = new JButton("OK"), c); buttonPanel.add(m_okayButton); m_okayButton.setDefaultCapable(true); getRootPane().setDefaultButton(m_okayButton); // Cancel button. c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.anchor = GridBagConstraints.WEST; grid.setConstraints(m_cancelButton = new JButton("Cancel"), c); buttonPanel.add(m_cancelButton); // Add action listeners. m_okayButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { doOkay(); } }); m_cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { doCancel(); } }); // Status label. m_statusLabel = new JLabel("Oscar installation"); m_statusLabel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); // Complete panel. JPanel panel = new JPanel(new BorderLayout()); panel.add(buttonPanel, BorderLayout.CENTER); panel.add(m_statusLabel, BorderLayout.SOUTH); return panel; } public static void centerWindow(Component window) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Dimension dim = toolkit.getScreenSize(); int screenWidth = dim.width; int screenHeight = dim.height; int x = (screenWidth - window.getSize().width) / 2; int y = (screenHeight - window.getSize().height) / 2; window.setLocation(x, y); } public static void main(String[] argv) throws Exception { String msg = "<html>" + "<center><h1>Oscar " + OscarConstants.OSCAR_VERSION_VALUE + "</h1></center>" + "You can download example bundles at the Oscar shell prompt by<br>" + "using the <b><tt>obr</tt></b> command to access the Oscar Bundle Repository;<br>" + "type <b><tt>obr help</tt></b> at the Oscar shell prompt for details." + "</html>"; JLabel label = new JLabel(msg); label.setFont(new Font("SansSerif", Font.PLAIN, 11)); final JDialog dlg = new JDialog((Frame) null, "Oscar Install", true); dlg.getContentPane().setLayout(new BorderLayout(10, 10)); dlg.getContentPane().add(label, BorderLayout.CENTER); JPanel panel = new JPanel(); JButton button = new JButton("OK"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dlg.hide(); } }); panel.add(button); dlg.getContentPane().add(panel, BorderLayout.SOUTH); // For spacing purposes... dlg.getContentPane().add(new JPanel(), BorderLayout.NORTH); dlg.getContentPane().add(new JPanel(), BorderLayout.EAST); dlg.getContentPane().add(new JPanel(), BorderLayout.WEST); dlg.pack(); centerWindow(dlg); dlg.show(); Install obj = new Install(); obj.setVisible(true); } class InstallRunnable implements Runnable { public void run() { Map propMap = new HashMap(); for (int i = 0; i < m_propList.size(); i++) { Property prop = (Property) m_propList.get(i); propMap.put(prop.getName(), prop); } String installDir = ((StringProperty) propMap.get(INSTALL_DIR)).getStringValue(); // Make sure the install directory ends with separator char. if (!installDir.endsWith(File.separator)) { installDir = installDir + File.separator; } // Make sure the install directory exists and // that is actually a directory. File file = new File(installDir); if (!file.exists()) { if (!file.mkdirs()) { JOptionPane.showMessageDialog(Install.this, "Unable to create install directory.", "Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } } else if (!file.isDirectory()) { JOptionPane.showMessageDialog(Install.this, "The selected install location is not a directory.", "Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } // Status updater runnable. StatusRunnable sr = new StatusRunnable(); // Loop through and process resources. for (int i = 0; i < m_artifactList.size(); i++) { ArtifactHolder ah = (ArtifactHolder) m_artifactList.get(i); if (ah.isIncluded()) { if (!ah.getArtifact().process(sr, propMap)) { JOptionPane.showMessageDialog(Install.this, "An error occurred while processing the resources.", "Error", JOptionPane.ERROR_MESSAGE); System.exit(-1); } } } System.exit(0); } } class StatusRunnable implements Status, Runnable { private String text = null; public void setText(String s) { text = s; try { SwingUtilities.invokeAndWait(this); } catch (Exception ex) { // Ignore. } } public void run() { m_statusLabel.setText(text); } } // Re-usable static member for ResourceHolder inner class. private static BooleanProperty m_trueProp = new BooleanPropertyImpl("mandatory", true); class ArtifactHolder { private BooleanProperty m_isIncluded = null; private Artifact m_artifact = null; public ArtifactHolder(Artifact artifact) { this(m_trueProp, artifact); } public ArtifactHolder(BooleanProperty isIncluded, Artifact artifact) { m_isIncluded = isIncluded; m_artifact = artifact; } public boolean isIncluded() { return m_isIncluded.getBooleanValue(); } public Artifact getArtifact() { return m_artifact; } }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -