Пример #1
0
  @Override
  public UIDefaults getDefaults() {
    try {
      final Method superMethod = BasicLookAndFeel.class.getDeclaredMethod("getDefaults");
      superMethod.setAccessible(true);
      final UIDefaults metalDefaults = (UIDefaults) superMethod.invoke(new MetalLookAndFeel());

      final UIDefaults defaults = (UIDefaults) superMethod.invoke(base);
      if (SystemInfo.isLinux) {
        if (!Registry.is("darcula.use.native.fonts.on.linux")) {
          Font font = findFont("DejaVu Sans");
          if (font != null) {
            for (Object key : defaults.keySet()) {
              if (key instanceof String && ((String) key).endsWith(".font")) {
                defaults.put(key, new FontUIResource(font.deriveFont(13f)));
              }
            }
          }
        } else if (Arrays.asList("CN", "JP", "KR", "TW")
            .contains(Locale.getDefault().getCountry())) {
          for (Object key : defaults.keySet()) {
            if (key instanceof String && ((String) key).endsWith(".font")) {
              final Font font = defaults.getFont(key);
              if (font != null) {
                defaults.put(key, new FontUIResource("Dialog", font.getStyle(), font.getSize()));
              }
            }
          }
        }
      }

      LafManagerImpl.initInputMapDefaults(defaults);
      initIdeaDefaults(defaults);
      patchStyledEditorKit(defaults);
      patchComboBox(metalDefaults, defaults);
      defaults.remove("Spinner.arrowButtonBorder");
      defaults.put("Spinner.arrowButtonSize", JBUI.size(16, 5).asUIResource());
      MetalLookAndFeel.setCurrentTheme(createMetalTheme());
      if (SystemInfo.isWindows && Registry.is("ide.win.frame.decoration")) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JDialog.setDefaultLookAndFeelDecorated(true);
      }
      if (SystemInfo.isLinux && JBUI.isHiDPI()) {
        applySystemFonts(defaults);
      }
      defaults.put("EditorPane.font", defaults.getFont("TextField.font"));
      return defaults;
    } catch (Exception e) {
      log(e);
    }
    return super.getDefaults();
  }
Пример #2
0
  /**
   * Add this theme's custom entries to the defaults table.
   *
   * @param table the defaults table, non-null
   * @throws NullPointerException if {@code table} is {@code null}
   */
  public void addCustomEntriesToTable(UIDefaults table) {
    UIDefaults.LazyValue focusBorder =
        t -> new BorderUIResource.LineBorderUIResource(getPrimary1());
    // .30 0 DDE8F3 white secondary2
    java.util.List<?> buttonGradient =
        Arrays.asList(
            new Object[] {
              Float.valueOf(.3f),
              Float.valueOf(0f),
              new ColorUIResource(0xDDE8F3),
              getWhite(),
              getSecondary2()
            });

    // Other possible properties that aren't defined:
    //
    // Used when generating the disabled Icons, provides the region to
    // constrain grays to.
    // Button.disabledGrayRange -> Object[] of Integers giving min/max
    // InternalFrame.inactiveTitleGradient -> Gradient when the
    //   internal frame is inactive.
    Color cccccc = new ColorUIResource(0xCCCCCC);
    Color dadada = new ColorUIResource(0xDADADA);
    Color c8ddf2 = new ColorUIResource(0xC8DDF2);
    Object directoryIcon = getIconResource("icons/ocean/directory.gif");
    Object fileIcon = getIconResource("icons/ocean/file.gif");
    java.util.List<?> sliderGradient =
        Arrays.asList(
            new Object[] {
              Float.valueOf(.3f),
              Float.valueOf(.2f),
              c8ddf2,
              getWhite(),
              new ColorUIResource(SECONDARY2)
            });

    Object[] defaults =
        new Object[] {
          "Button.gradient",
          buttonGradient,
          "Button.rollover",
          Boolean.TRUE,
          "Button.toolBarBorderBackground",
          INACTIVE_CONTROL_TEXT_COLOR,
          "Button.disabledToolBarBorderBackground",
          cccccc,
          "Button.rolloverIconType",
          "ocean",
          "CheckBox.rollover",
          Boolean.TRUE,
          "CheckBox.gradient",
          buttonGradient,
          "CheckBoxMenuItem.gradient",
          buttonGradient,

          // home2
          "FileChooser.homeFolderIcon",
          getIconResource("icons/ocean/homeFolder.gif"),
          // directory2
          "FileChooser.newFolderIcon",
          getIconResource("icons/ocean/newFolder.gif"),
          // updir2
          "FileChooser.upFolderIcon",
          getIconResource("icons/ocean/upFolder.gif"),

          // computer2
          "FileView.computerIcon",
          getIconResource("icons/ocean/computer.gif"),
          "FileView.directoryIcon",
          directoryIcon,
          // disk2
          "FileView.hardDriveIcon",
          getIconResource("icons/ocean/hardDrive.gif"),
          "FileView.fileIcon",
          fileIcon,
          // floppy2
          "FileView.floppyDriveIcon",
          getIconResource("icons/ocean/floppy.gif"),
          "Label.disabledForeground",
          getInactiveControlTextColor(),
          "Menu.opaque",
          Boolean.FALSE,
          "MenuBar.gradient",
          Arrays.asList(
              new Object[] {
                Float.valueOf(1f),
                Float.valueOf(0f),
                getWhite(),
                dadada,
                new ColorUIResource(dadada)
              }),
          "MenuBar.borderColor",
          cccccc,
          "InternalFrame.activeTitleGradient",
          buttonGradient,
          // close2
          "InternalFrame.closeIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/close.gif", table),
                  getHastenedIcon("icons/ocean/close-pressed.gif", table));
            }
          },
          // minimize
          "InternalFrame.iconifyIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/iconify.gif", table),
                  getHastenedIcon("icons/ocean/iconify-pressed.gif", table));
            }
          },
          // restore
          "InternalFrame.minimizeIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/minimize.gif", table),
                  getHastenedIcon("icons/ocean/minimize-pressed.gif", table));
            }
          },
          // menubutton3
          "InternalFrame.icon",
          getIconResource("icons/ocean/menu.gif"),
          // maximize2
          "InternalFrame.maximizeIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/maximize.gif", table),
                  getHastenedIcon("icons/ocean/maximize-pressed.gif", table));
            }
          },
          // paletteclose
          "InternalFrame.paletteCloseIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new IFIcon(
                  getHastenedIcon("icons/ocean/paletteClose.gif", table),
                  getHastenedIcon("icons/ocean/paletteClose-pressed.gif", table));
            }
          },
          "List.focusCellHighlightBorder",
          focusBorder,
          "MenuBarUI",
          "javax.swing.plaf.metal.MetalMenuBarUI",
          "OptionPane.errorIcon",
          getIconResource("icons/ocean/error.png"),
          "OptionPane.informationIcon",
          getIconResource("icons/ocean/info.png"),
          "OptionPane.questionIcon",
          getIconResource("icons/ocean/question.png"),
          "OptionPane.warningIcon",
          getIconResource("icons/ocean/warning.png"),
          "RadioButton.gradient",
          buttonGradient,
          "RadioButton.rollover",
          Boolean.TRUE,
          "RadioButtonMenuItem.gradient",
          buttonGradient,
          "ScrollBar.gradient",
          buttonGradient,
          "Slider.altTrackColor",
          new ColorUIResource(0xD2E2EF),
          "Slider.gradient",
          sliderGradient,
          "Slider.focusGradient",
          sliderGradient,
          "SplitPane.oneTouchButtonsOpaque",
          Boolean.FALSE,
          "SplitPane.dividerFocusColor",
          c8ddf2,
          "TabbedPane.borderHightlightColor",
          getPrimary1(),
          "TabbedPane.contentAreaColor",
          c8ddf2,
          "TabbedPane.contentBorderInsets",
          new Insets(4, 2, 3, 3),
          "TabbedPane.selected",
          c8ddf2,
          "TabbedPane.tabAreaBackground",
          dadada,
          "TabbedPane.tabAreaInsets",
          new Insets(2, 2, 0, 6),
          "TabbedPane.unselectedBackground",
          SECONDARY3,
          "Table.focusCellHighlightBorder",
          focusBorder,
          "Table.gridColor",
          SECONDARY1,
          "TableHeader.focusCellBackground",
          c8ddf2,
          "ToggleButton.gradient",
          buttonGradient,
          "ToolBar.borderColor",
          cccccc,
          "ToolBar.isRollover",
          Boolean.TRUE,
          "Tree.closedIcon",
          directoryIcon,
          "Tree.collapsedIcon",
          new UIDefaults.LazyValue() {
            public Object createValue(UIDefaults table) {
              return new COIcon(
                  getHastenedIcon("icons/ocean/collapsed.gif", table),
                  getHastenedIcon("icons/ocean/collapsed-rtl.gif", table));
            }
          },
          "Tree.expandedIcon",
          getIconResource("icons/ocean/expanded.gif"),
          "Tree.leafIcon",
          fileIcon,
          "Tree.openIcon",
          directoryIcon,
          "Tree.selectionBorderColor",
          getPrimary1(),
          "Tree.dropLineColor",
          getPrimary1(),
          "Table.dropLineColor",
          getPrimary1(),
          "Table.dropLineShortColor",
          OCEAN_BLACK,
          "Table.dropCellBackground",
          OCEAN_DROP,
          "Tree.dropCellBackground",
          OCEAN_DROP,
          "List.dropCellBackground",
          OCEAN_DROP,
          "List.dropLineColor",
          getPrimary1()
        };
    table.putDefaults(defaults);
  }
Пример #3
0
    public void actionPerformed(ActionEvent e) {
      if (isDirectorySelected()) {
        File dir = getDirectory();
        if (dir != null) {
          try {
            // Strip trailing ".."
            dir = ShellFolder.getNormalizedFile(dir);
          } catch (IOException ex) {
            // Ok, use f as is
          }
          changeDirectory(dir);
          return;
        }
      }

      JFileChooser chooser = getFileChooser();

      String filename = getFileName();
      FileSystemView fs = chooser.getFileSystemView();
      File dir = chooser.getCurrentDirectory();

      if (filename != null) {
        // Remove whitespaces from end of filename
        int i = filename.length() - 1;

        while (i >= 0 && filename.charAt(i) <= ' ') {
          i--;
        }

        filename = filename.substring(0, i + 1);
      }

      if (filename == null || filename.length() == 0) {
        // no file selected, multiple selection off, therefore cancel the approve action
        resetGlobFilter();
        return;
      }

      File selectedFile = null;
      File[] selectedFiles = null;

      // Unix: Resolve '~' to user's home directory
      if (File.separatorChar == '/') {
        if (filename.startsWith("~/")) {
          filename = System.getProperty("user.home") + filename.substring(1);
        } else if (filename.equals("~")) {
          filename = System.getProperty("user.home");
        }
      }

      if (chooser.isMultiSelectionEnabled()
          && filename.length() > 1
          && filename.charAt(0) == '"'
          && filename.charAt(filename.length() - 1) == '"') {
        List<File> fList = new ArrayList<File>();

        String[] files = filename.substring(1, filename.length() - 1).split("\" \"");
        // Optimize searching files by names in "children" array
        Arrays.sort(files);

        File[] children = null;
        int childIndex = 0;

        for (String str : files) {
          File file = fs.createFileObject(str);
          if (!file.isAbsolute()) {
            if (children == null) {
              children = fs.getFiles(dir, false);
              Arrays.sort(children);
            }
            for (int k = 0; k < children.length; k++) {
              int l = (childIndex + k) % children.length;
              if (children[l].getName().equals(str)) {
                file = children[l];
                childIndex = l + 1;
                break;
              }
            }
          }
          fList.add(file);
        }

        if (!fList.isEmpty()) {
          selectedFiles = fList.toArray(new File[fList.size()]);
        }
        resetGlobFilter();
      } else {
        selectedFile = fs.createFileObject(filename);
        if (!selectedFile.isAbsolute()) {
          selectedFile = fs.getChild(dir, filename);
        }
        // check for wildcard pattern
        FileFilter currentFilter = chooser.getFileFilter();
        if (!selectedFile.exists() && isGlobPattern(filename)) {
          changeDirectory(selectedFile.getParentFile());
          if (globFilter == null) {
            globFilter = new GlobFilter();
          }
          try {
            globFilter.setPattern(selectedFile.getName());
            if (!(currentFilter instanceof GlobFilter)) {
              actualFileFilter = currentFilter;
            }
            chooser.setFileFilter(null);
            chooser.setFileFilter(globFilter);
            return;
          } catch (PatternSyntaxException pse) {
            // Not a valid glob pattern. Abandon filter.
          }
        }

        resetGlobFilter();

        // Check for directory change action
        boolean isDir = (selectedFile != null && selectedFile.isDirectory());
        boolean isTrav = (selectedFile != null && chooser.isTraversable(selectedFile));
        boolean isDirSelEnabled = chooser.isDirectorySelectionEnabled();
        boolean isFileSelEnabled = chooser.isFileSelectionEnabled();
        boolean isCtrl =
            (e != null
                && (e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0);

        if (isDir && isTrav && (isCtrl || !isDirSelEnabled)) {
          changeDirectory(selectedFile);
          return;
        } else if ((isDir || !isFileSelEnabled)
            && (!isDir || !isDirSelEnabled)
            && (!isDirSelEnabled || selectedFile.exists())) {
          selectedFile = null;
        }
      }

      if (selectedFiles != null || selectedFile != null) {
        if (selectedFiles != null || chooser.isMultiSelectionEnabled()) {
          if (selectedFiles == null) {
            selectedFiles = new File[] {selectedFile};
          }
          chooser.setSelectedFiles(selectedFiles);
          // Do it again. This is a fix for bug 4949273 to force the
          // selected value in case the ListSelectionModel clears it
          // for non-existing file names.
          chooser.setSelectedFiles(selectedFiles);
        } else {
          chooser.setSelectedFile(selectedFile);
        }
        chooser.approveSelection();
      } else {
        if (chooser.isMultiSelectionEnabled()) {
          chooser.setSelectedFiles(null);
        } else {
          chooser.setSelectedFile(null);
        }
        chooser.cancelSelection();
      }
    }