Ejemplo n.º 1
0
  /**
   * Prompts the user to select a file.
   *
   * @param acceptableSuffixes
   * @return
   */
  private File getFileUsingDialog(final String... acceptableSuffixes) {
    // For some strange reason,
    // the only way to get a Mac OS X native-style file dialog
    // is to use an AWT FileDialog instead of a Swing JDialog
    if (GameRunner.isMac()) {
      final FileDialog fileDialog = new FileDialog(MainFrame.getInstance());
      fileDialog.setMode(FileDialog.LOAD);
      fileDialog.setFilenameFilter(
          new FilenameFilter() {
            public boolean accept(final File dir, final String name) {
              if (acceptableSuffixes == null || acceptableSuffixes.length == 0) return true;
              for (final String suffix : acceptableSuffixes) {
                if (name.toLowerCase().endsWith(suffix)) return true;
              }
              return false;
            }
          });
      fileDialog.setVisible(true);
      final String fileName = fileDialog.getFile();
      final String dirName = fileDialog.getDirectory();
      if (fileName == null) return null;
      return new File(dirName, fileName);
    }
    final JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileFilter(
        new FileFilter() {
          @Override
          public boolean accept(final File file) {
            if (file == null) return false;
            else if (file.isDirectory()) return true;
            else {
              final String name = file.getAbsolutePath().toLowerCase();
              for (final String suffix : acceptableSuffixes) {
                if (name.endsWith(suffix)) return true;
              }
              return false;
            }
          }

          @Override
          public String getDescription() {
            return Arrays.toString(acceptableSuffixes);
          }
        });
    final int rVal = fileChooser.showOpenDialog(MainFrame.getInstance());
    if (rVal == JFileChooser.APPROVE_OPTION) {
      return fileChooser.getSelectedFile();
    }
    return null;
  }
Ejemplo n.º 2
0
 /** Creates new ScrollableTextField */
 public ScrollableTextField(final int minVal, final int maxVal) {
   super();
   loadImages(this);
   m_text = new IntTextField(minVal, maxVal);
   setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
   add(m_text);
   Insets inset = new Insets(0, 0, 0, 0);
   if (GameRunner.isMac()) {
     inset = new Insets(2, 0, 2, 0);
   }
   m_up = new JButton(s_up);
   m_up.addActionListener(m_incrementAction);
   m_up.setMargin(inset);
   m_down = new JButton(s_down);
   m_down.setMargin(inset);
   m_down.addActionListener(m_decrementAction);
   m_max = new JButton(s_max);
   m_max.setMargin(inset);
   m_max.addActionListener(m_maxAction);
   m_min = new JButton(s_min);
   m_min.setMargin(inset);
   m_min.addActionListener(m_minAction);
   final JPanel upDown = new JPanel();
   upDown.setLayout(new BoxLayout(upDown, BoxLayout.Y_AXIS));
   upDown.add(m_up);
   upDown.add(m_down);
   final JPanel maxMin = new JPanel();
   maxMin.setLayout(new BoxLayout(maxMin, BoxLayout.Y_AXIS));
   maxMin.add(m_max);
   maxMin.add(m_min);
   add(upDown);
   add(maxMin);
   // add(new JSpinner());
   m_text.addChangeListener(m_textListener);
   setWidgetActivation();
 }