Example usage for java.awt.event KeyAdapter KeyAdapter

List of usage examples for java.awt.event KeyAdapter KeyAdapter

Introduction

In this page you can find the example usage for java.awt.event KeyAdapter KeyAdapter.

Prototype

KeyAdapter

Source Link

Usage

From source file:com.frostwire.gui.library.LibraryFilesTableMediator.java

@Override
protected void addListeners() {
    super.addListeners();

    TABLE.addKeyListener(new KeyAdapter() {
        @Override//  w ww  .jav a 2s  .c o  m
        public void keyReleased(KeyEvent e) {
            if (LibraryUtils.isRefreshKeyEvent(e)) {
                LibraryMediator.instance().getLibraryExplorer().refreshSelection(true);
            }
        }
    });

}

From source file:gtu._work.etc._3DSMovieRenamer.java

private void initGUI() {
    try {//from  w w w  .  j  a  v  a 2  s .com
        final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);

        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("3DS Rename");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("vid list", null, jPanel1, null);
                {
                    openDir = new JButton();
                    jPanel1.add(openDir, BorderLayout.NORTH);
                    openDir.setText("open dir");
                    openDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            swingUtil.invokeAction("openDir.actionPerformed", evt);
                        }
                    });
                }
                {
                    ListModel vidListModel = new DefaultListModel();
                    vidList = new JList();
                    jPanel1.add(vidList, BorderLayout.CENTER);
                    vidList.setModel(vidListModel);
                    vidList.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            swingUtil.invokeAction("vidList.mouseClicked", evt);
                        }
                    });
                    vidList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            swingUtil.invokeAction("vidList.keyPressed", evt);
                        }
                    });
                }
                {
                    jPanel3 = new JPanel();
                    jPanel1.add(jPanel3, BorderLayout.SOUTH);
                    jPanel3.setPreferredSize(new java.awt.Dimension(445, 34));
                    {
                        renameText = new JTextField();
                        jPanel3.add(renameText);
                        renameText.setPreferredSize(new java.awt.Dimension(187, 24));
                    }
                    {
                        renameBtn = new JButton();
                        jPanel3.add(renameBtn);
                        renameBtn.setText("rename");
                        renameBtn.setPreferredSize(new java.awt.Dimension(106, 24));
                        renameBtn.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("renameBtn.mouseClicked", evt);
                            }
                        });
                    }
                    {
                        forceChange = new JCheckBox();
                        jPanel3.add(forceChange);
                        forceChange.setText("force");
                        forceChange.setPreferredSize(new java.awt.Dimension(64, 21));
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("copy", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        ListModel copyToListModel = new DefaultListModel();
                        copyToList = new JList();
                        jScrollPane1.setViewportView(copyToList);
                        copyToList.setModel(copyToListModel);
                        copyToList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("copyToList.mouseClicked", evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("BT Movie", null, jPanel4, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel4.add(jScrollPane2, BorderLayout.WEST);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(254, 355));
                    {
                        btDirTree = new JTree();
                        jScrollPane2.setViewportView(btDirTree);
                        btDirTree.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction(evt);
                            }
                        });
                        btDirTree.addPropertyChangeListener(new PropertyChangeListener() {
                            public void propertyChange(PropertyChangeEvent evt) {
                                swingUtil.invokeAction(evt);
                            }
                        });
                        JTreeUtil.newInstance(btDirTree).fileSystem(DEFAULT_BT_DIR);
                    }
                }
                {
                    jPanel5 = new JPanel();
                    BorderLayout jPanel5Layout = new BorderLayout();
                    jPanel5.setLayout(jPanel5Layout);
                    jPanel4.add(jPanel5, BorderLayout.CENTER);
                    {
                        jScrollPane3 = new JScrollPane();
                        jPanel5.add(jScrollPane3, BorderLayout.CENTER);
                        jScrollPane3.setPreferredSize(new java.awt.Dimension(427, 355));
                        {
                            DefaultListModel btMovListModel = new DefaultListModel();
                            btMovList = new JList();
                            jScrollPane3.setViewportView(btMovList);
                            btMovList.setModel(btMovListModel);
                            btMovList.addMouseListener(new MouseAdapter() {
                                public void mouseClicked(MouseEvent evt) {
                                    swingUtil.invokeAction(evt);
                                }
                            });
                            btMovList.addKeyListener(new KeyAdapter() {
                                public void keyPressed(KeyEvent evt) {
                                    JListUtil.newInstance(btMovList).defaultJListKeyPressed(evt);
                                }
                            });
                        }
                    }
                }
            }
            {
                jPanel6 = new JPanel();
                FlowLayout jPanel6Layout = new FlowLayout();
                jTabbedPane1.addTab("common", null, jPanel6, null);
                jPanel6.setLayout(jPanel6Layout);
                {
                    execute3dsVidTransfer = new JButton();
                    jPanel6.add(execute3dsVidTransfer);
                    execute3dsVidTransfer.setText("execute 3ds video transfer");
                    execute3dsVidTransfer.setPreferredSize(new java.awt.Dimension(207, 42));
                    execute3dsVidTransfer.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            String bat = "C:/apps/_movie/3DSVideov1.00/3DS Video.exe";
                            try {
                                Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", bat));
                            } catch (IOException e) {
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
                {
                    openMovieAppDir = new JButton();
                    jPanel6.add(openMovieAppDir);
                    openMovieAppDir.setText("open movie app dir");
                    openMovieAppDir.setPreferredSize(new java.awt.Dimension(207, 42));
                    openMovieAppDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                Desktop.getDesktop().open(new File("C:/apps/_movie"));
                            } catch (IOException e) {
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
            }
            {
                jPanel7 = new JPanel();
                BorderLayout jPanel7Layout = new BorderLayout();
                jTabbedPane1.addTab("fake rename", null, jPanel7, null);
                jPanel7.setLayout(jPanel7Layout);
                {
                    openFakeRenameDir = new JButton();
                    jPanel7.add(openFakeRenameDir, BorderLayout.NORTH);
                    openFakeRenameDir.setText("open dir");
                    openFakeRenameDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            if (file != null) {
                                DefaultListModel model = new DefaultListModel();
                                for (File f : file.listFiles()) {
                                    model.addElement(f);
                                }
                                openFakeRenameDirList.setModel(model);
                            }
                        }
                    });
                }
                {
                    DefaultListModel openFakeRenameDirListModel = new DefaultListModel();
                    openFakeRenameDirList = new JList();
                    jPanel7.add(openFakeRenameDirList, BorderLayout.CENTER);
                    openFakeRenameDirList.setModel(openFakeRenameDirListModel);
                    openFakeRenameDirList.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            File file = (File) JListUtil.getLeadSelectionObject(openFakeRenameDirList);
                            try {
                                Process process = Runtime.getRuntime()
                                        .exec(String.format("cmd /c call \"%s\"", file));
                                InputStream ins = process.getInputStream();
                                while (ins.read() != -1) {
                                    //TODO
                                }
                                ins.close();
                                System.out.println("done...");
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    openFakeRenameDirList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            JListUtil.newInstance(openFakeRenameDirList).defaultJListKeyPressed(evt);
                        }
                    });
                }
                {
                    jPanel8 = new JPanel();
                    jPanel7.add(jPanel8, BorderLayout.SOUTH);
                    jPanel8.setPreferredSize(new java.awt.Dimension(681, 43));
                    {
                        openFakeRenameDir_newName = new JTextField();
                        jPanel8.add(openFakeRenameDir_newName);
                        openFakeRenameDir_newName.setPreferredSize(new java.awt.Dimension(287, 27));
                    }
                    {
                        fakeRenameExecute = new JButton();
                        jPanel8.add(fakeRenameExecute);
                        fakeRenameExecute.setText("execute");
                        fakeRenameExecute.setPreferredSize(new java.awt.Dimension(95, 27));
                        fakeRenameExecute.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                DefaultListModel model = (DefaultListModel) openFakeRenameDirList.getModel();
                                //TODO
                            }
                        });
                    }
                }
            }

            swingUtil.addAction("copyToList.mouseClicked", new Action() {
                public void action(EventObject evt) throws Exception {
                    try {
                        if (((MouseEvent) evt).getButton() == 3) {
                            JMenuItem reloadMenu = new JMenuItem();
                            reloadMenu.setText("reload SD card directory");
                            reloadMenu.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                    DefaultListModel copyToListModel = new DefaultListModel();
                                    for (final File f : load3DSDir.listFiles(new FilenameFilter() {
                                        public boolean accept(File paramFile, String paramString) {
                                            if (paramFile.isDirectory()
                                                    && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) {
                                                return true;
                                            }
                                            return false;
                                        }
                                    })) {
                                        copyToListModel.addElement(f);
                                    }
                                    copyToList.setModel(copyToListModel);
                                }
                            });
                            JMenuItem copyAllToMenu = new JMenuItem();
                            {
                                copyAllToMenu.setText(
                                        String.format("move %d vids to...", vidList.getModel().getSize()));
                                final File toDir = (File) JListUtil.getLeadSelectionObject(copyToList);
                                if (toDir == null || !toDir.exists() || !toDir.isDirectory()) {
                                    copyAllToMenu.setEnabled(false);
                                }
                                if (vidList.getModel().getSize() == 0) {
                                    copyAllToMenu.setText("copy no file...");
                                    copyAllToMenu.setEnabled(false);
                                }
                                copyAllToMenu.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent e) {
                                        DefaultListModel model = JListUtil.newInstance(vidList).getModel();
                                        if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil
                                                .newInstance().iconWaringMessage().confirmButtonYesNo()
                                                .showConfirmDialog("are you sure copy files : "
                                                        + model.getSize() + "\n to dir : " + toDir,
                                                        "COPY VIDS")) {
                                            return;
                                        }
                                        for (int ii = 0; ii < model.getSize(); ii++) {
                                            File src = (File) model.getElementAt(ii);
                                            src.renameTo(new File(toDir, src.getName()));
                                        }
                                        JOptionPaneUtil.newInstance().iconInformationMessage()
                                                .showMessageDialog("copy completed!", "SUCCESS");
                                        loadDirVids();
                                    }
                                });
                            }

                            JPopupMenuUtil.newInstance(copyToList).applyEvent((MouseEvent) evt)
                                    .addJMenuItem(reloadMenu, copyAllToMenu).show();
                        }
                    } catch (Exception ex) {
                        JCommonUtil.handleException(ex);
                    }
                }
            });
            swingUtil.addAction("openDir.actionPerformed", new Action() {
                public void action(EventObject evt) throws Exception {
                    File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                            .getApproveSelectedFile();
                    if (file == null) {
                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                .showMessageDialog("dir not corrent!, set desktop", getTitle());
                        loadDir = FileUtil.DESKTOP_DIR;
                    } else {
                        loadDir = file;
                    }
                    loadDirVids();
                }
            });
            swingUtil.addAction("vidList.mouseClicked", new Action() {
                //                    final String player = "C:/Program Files (x86)/GRETECH/GomPlayer/GOM.EXE";

                public void action(EventObject evt) throws Exception {
                    int pos = -1;
                    if ((pos = vidList.getLeadSelectionIndex()) == -1) {
                        return;
                    }
                    MouseEvent mevt = (MouseEvent) evt;

                    final File selectItem = (File) vidList.getModel().getElementAt(pos);

                    List<JMenuItem> menuList = new ArrayList<JMenuItem>();
                    JMenuItem simpleRenamer = new JMenuItem();
                    final String simpleRenamePrefix = RandomUtil.upperCase(3);
                    simpleRenamer.setText("Rename : " + simpleRenamePrefix);
                    simpleRenamer.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent paramActionEvent) {
                            String value = StringUtils.defaultString(JOptionPaneUtil.newInstance()
                                    .showInputDialog("3 char prefix?", "AVI PREFIX"), simpleRenamePrefix);
                            if (value != null && value.matches("[a-zA-Z]{3}")) {
                                selectItem.renameTo(getNewFile(selectItem.getParentFile(), value));
                                loadDirVids();
                            } else {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("prefix is not correct!", "ERROR");
                            }
                        }
                    });
                    menuList.add(simpleRenamer);
                    if (load3DSDir == null) {
                        reload3DSDir();
                        if (load3DSDir == null) {
                            JMenuItem disable = new JMenuItem();
                            disable.setText("MOVE : SD card is not set!");
                            disable.setEnabled(false);
                            menuList.add(disable);
                        }
                    } else {
                        for (final File f : load3DSDir.listFiles(new FilenameFilter() {
                            public boolean accept(File paramFile, String paramString) {
                                if (paramFile.isDirectory() && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) {
                                    return true;
                                }
                                return false;
                            }
                        })) {
                            JMenuItem copyTo = new JMenuItem();
                            copyTo.setText("MOVE : " + f.getName());
                            copyTo.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent paramActionEvent) {
                                    if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION == JOptionPaneUtil
                                            .newInstance().iconQuestionMessage().confirmButtonYesNo()
                                            .showConfirmDialog(//
                                                    "are you sure move file\n" + //
                                    selectItem + "\n" + //
                                    "to\n" + //
                                    "dir : " + f + "  ??"//
                                    , "COPY FILE")) {

                                        File copyToNewDirFile = new File(f, selectItem.getName());
                                        if (copyToNewDirFile.exists()) {
                                            JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(
                                                    "target dir file already exist!, need rename!",
                                                    "FILE ALREADY EXIST");
                                            return;
                                        }
                                        selectItem.renameTo(copyToNewDirFile);
                                        loadDirVids();

                                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                                .showMessageDialog("move completed!", "MOVE FILE");
                                    }
                                }
                            });
                            menuList.add(copyTo);
                        }
                    }
                    JPopupMenuUtil.newInstance(vidList).applyEvent(mevt)
                            .addJMenuItem(menuList.toArray(new JMenuItem[menuList.size()])).show();

                    if (mevt.getClickCount() != 2) {
                        return;
                    }
                    String clkItemPath = selectItem.getAbsolutePath();
                    String command = "cmd /c call \"" + clkItemPath + "\"";
                    System.out.println(command);
                    Runtime.getRuntime().exec(command);
                }
            });
            swingUtil.addAction("vidList.keyPressed", new Action() {
                public void action(EventObject evt) throws Exception {
                    JListUtil.newInstance(vidList).defaultJListKeyPressed(evt);
                }
            });
            swingUtil.addAction("renameBtn.mouseClicked", new Action() {

                Pattern aviNamePattern = Pattern.compile("^([a-zA-Z]{3})_\\d{4}\\.[aA][vV][iI]$");

                public void action(EventObject evt) throws Exception {
                    String name = StringUtils.defaultIfEmpty(renameText.getText(), RandomUtil.upperCase(3));
                    System.out.println("name = " + name + ", force : " + forceChange.isSelected());
                    if (!name.matches("[a-zA-Z]{3}")) {
                        renameText.setText("");
                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                .showMessageDialog("rename must eng 3 char!", "ERROR");
                        return;
                    }
                    DefaultListModel model = (DefaultListModel) vidList.getModel();
                    boolean matchOk = false;
                    if (model.size() != 0) {
                        File oldFile = null;
                        Matcher matcher = null;
                        for (int ii = 0; ii < model.getSize(); ii++) {
                            oldFile = (File) model.getElementAt(ii);

                            if (!oldFile.exists()) {
                                JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(
                                        "file not exeist : \n" + oldFile.getAbsolutePath(), getTitle());
                                return;
                            }
                            matcher = aviNamePattern.matcher(oldFile.getName());
                            matchOk = matcher.find();
                            System.out.println("matchOk = " + matchOk);
                            if (matchOk && !forceChange.isSelected()) {
                                oldFile.renameTo(getNewFile(oldFile.getParentFile(), matcher.group(1)));
                            } else {
                                oldFile.renameTo(getNewFile(oldFile.getParentFile(), name));
                            }
                        }
                        JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog("success!",
                                getTitle());
                    }
                    loadDirVids();
                }
            });

            ToolTipManager.sharedInstance().setInitialDelay(0);
            swingUtil.addAction(btMovList, MouseEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    final File file = (File) JListUtil.getLeadSelectionObject(btMovList);
                    if (JMouseEventUtil.buttonLeftClick(1, evt)) {
                        btMovList.setToolTipText(
                                DateFormatUtils.format(file.lastModified(), "yyyy/MM/dd HH:mm:ss") + " length:"
                                        + (file.length() / 1024) + "k");
                    }

                    final Object[] objects = btMovList.getSelectedValues();
                    JPopupMenuUtil.newInstance(btMovList).applyEvent(evt)//
                            .addJMenuItem("move out", (objects != null && objects.length > 0),
                                    new ActionListener() {
                                        public void actionPerformed(ActionEvent paramActionEvent) {
                                            List<File> list = new ArrayList<File>();
                                            for (Object val : objects) {
                                                list.add((File) val);
                                            }
                                            if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure move file from\n" + list.toString().replace(',', '\n')
                                                            + "\nto\n" + DEFAULT_BT_DIR,
                                                    "MOVE")) {
                                                return;
                                            }
                                            StringBuilder sb = new StringBuilder();
                                            File moveTo = null;
                                            for (File file : list) {
                                                sb.append((file.renameTo(
                                                        moveTo = new File(DEFAULT_BT_DIR, file.getName()))
                                                        && moveTo.exists()) ? "" : file + "\n");
                                            }
                                            JCommonUtil._jOptionPane_showMessageDialog_info(
                                                    sb.length() == 0 ? "move success!" : "move failed!\n" + sb);
                                        }
                                    })
                            .addJMenuItem("delete this", file.exists(), new ActionListener() {
                                public void actionPerformed(ActionEvent paramActionEvent) {
                                    if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                            "sure delete file \n" + file, "DELETE")) {
                                        return;
                                    }
                                    boolean result = file.delete();
                                    System.out.println("!!!!!" + result + "..." + file.exists());
                                    JCommonUtil._jOptionPane_showMessageDialog_info(
                                            result ? "delete success!" : "delete failed!");
                                }
                            }).show();

                    if (JMouseEventUtil.buttonLeftClick(2, evt)) {
                        Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", file));
                    }
                }
            });
            swingUtil.addAction(btDirTree, MouseEvent.class, new Action() {

                File getSingleFile() {
                    return ((JFile) JTreeUtil.newInstance(btDirTree).getSelectItem().getUserObject()).getFile();
                }

                public void action(EventObject evt) throws Exception {
                    int selectCount = btDirTree.getSelectionModel().getSelectionCount();
                    if (selectCount == 1) {
                        final File file = getSingleFile();
                        JPopupMenuUtil.newInstance(btDirTree).applyEvent(evt).addJMenuItem("delete this",
                                selectCount == 1 && file.exists(), new ActionListener() {
                                    public void actionPerformed(ActionEvent paramActionEvent) {
                                        if (file.isFile()) {
                                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure delete FILE : \n" + file, "WARNING")) {
                                                file.delete();
                                                JCommonUtil._jOptionPane_showMessageDialog_info(
                                                        (file.exists() ? "delete failed!" : "delete success!"));
                                            }
                                        }
                                        if (file.isDirectory()) {
                                            StringBuilder sb = new StringBuilder();
                                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure delete DIR : \n" + file, "WARNING")) {
                                                List<Boolean> delL = new ArrayList<Boolean>();
                                                for (File f : file.listFiles()) {
                                                    if (fileExtensionPattern.matcher(f.getName()).find()
                                                            || f.length() > 1000000L) {
                                                        if (!JCommonUtil
                                                                ._JOptionPane_showConfirmDialog_yesNoOption(
                                                                        "delete this : \n" + f,
                                                                        "CHECK AGAIN")) {
                                                            continue;
                                                        }
                                                        delL.add(f.delete());
                                                    }
                                                    delL.add(f.delete());
                                                }
                                                for (File f : file.listFiles()) {
                                                    if (f.exists()) {
                                                        sb.append(f + "\n");
                                                    }
                                                }
                                                System.out.println("delL.contains(false)==================>"
                                                        + delL.contains(false));
                                            }
                                            if (!file.delete()) {
                                                sb.append(file + "\n");
                                            }
                                            JCommonUtil._jOptionPane_showMessageDialog_info(
                                                    sb.length() > 0 ? "delete failed!\nlist:\n" + sb
                                                            : "delete success!");
                                            if (sb.length() == 0) {
                                                DefaultMutableTreeNode node = JTreeUtil.newInstance(btDirTree)
                                                        .getSelectItem();
                                                System.out.println(
                                                        JTreeUtil.newInstance(btDirTree).removeNode(node));
                                            }
                                        }
                                    }
                                }).addJMenuItem("open dir", new ActionListener() {
                                    public void actionPerformed(ActionEvent paramActionEvent) {
                                        File openTarget = file;
                                        if (file.isFile()) {
                                            openTarget = file.getParentFile();
                                        }
                                        try {
                                            Desktop.getDesktop().open(openTarget);
                                        } catch (IOException e) {
                                            JCommonUtil.handleException(e);
                                        }
                                    }
                                }).show();
                    }
                }
            });
            swingUtil.addAction(btDirTree, PropertyChangeEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    List<File> list = new ArrayList<File>();
                    for (DefaultMutableTreeNode node : JTreeUtil.newInstance(btDirTree).getSelectItems()) {
                        JFile jfile = (JFile) node.getUserObject();
                        if (jfile.getFile().isDirectory()) {
                            for (File f : jfile.getFile().listFiles(new FilenameFilter() {
                                public boolean accept(File paramFile, String paramString) {
                                    return fileExtensionPattern.matcher(paramString).find();
                                }
                            })) {
                                System.out.println(f.getName() + "...." + f.length());
                                list.add(f);
                            }
                        }
                    }
                    Collections.sort(list, new Comparator<File>() {
                        public int compare(File paramT1, File paramT2) {
                            return paramT1.lastModified() > paramT2.lastModified() ? -1 : 1;
                        }
                    });
                    btMovList.setModel(JListUtil.createModel(list.iterator()));
                }
            });
        }
        this.setSize(702, 422);

        loadDirVids();
        reload3DSDir();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:edu.ku.brc.specify.config.AgentSearchDialogES.java

/**
 * Creates the Default UI for Lable task
 *
 *///from ww w.j  a v a2s  .c  o m
protected void createUI() {
    searchText = createTextField(30);
    searchBtn = createButton(getResourceString("SEARCH"));
    ActionListener doQuery = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            form.getDataFromUI();

            StringBuilder strBuf = new StringBuilder(128);
            for (String key : formFieldToColumnMap.keySet()) {
                String value = dataMap.get(key);
                if (isNotEmpty(value)) {
                    if (strBuf.length() > 0) {
                        strBuf.append(" OR ");
                    }
                    strBuf.append(formFieldToColumnMap.get(key) + ":" + value);
                }

            }
            searchText.setText(strBuf.toString());
            doQuery();
        }
    };

    searchBtn.addActionListener(doQuery);
    searchText.addActionListener(doQuery);
    searchText.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (searchText.getBackground() != textBGColor) {
                searchText.setBackground(textBGColor);
            }
        }
    });

    String viewName = "test";
    String name = null; // use the default

    formView = AppContextMgr.getInstance().getView(name, viewName);
    if (formView != null) {
        form = ViewFactory.createFormView(null, formView, null, dataMap, MultiView.NO_OPTIONS, null);
        if (form != null) {
            add(form.getUIComponent(), BorderLayout.CENTER);
        } else {
            return;
        }
    } else {
        log.info("Couldn't load form with name [" + name + "] Id [" + viewName + "]");
    }
    //form.setDataObj(prefNode);
    //form.getValidator().validateForm();

    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 10));

    PanelBuilder builder = new PanelBuilder(new FormLayout("p,1dlu,p", "p,2dlu,p,2dlu,p"));
    CellConstraints cc = new CellConstraints();

    //builder.addSeparator(getResourceString("AgentSearchTitle"), cc.xywh(1,1,3,1));
    builder.add(form.getUIComponent(), cc.xy(1, 1));
    builder.add(searchBtn, cc.xy(3, 1));

    panel.add(builder.getPanel(), BorderLayout.NORTH);
    contentPanel = new JPanel(new NavBoxLayoutManager(0, 2));
    //contentPanel.setMaximumSize(new Dimension(300,300));
    //contentPanel.setPreferredSize(new Dimension(300,300));

    scrollPane = new JScrollPane(contentPanel);
    panel.add(scrollPane, BorderLayout.CENTER);
    //scrollPane.setMaximumSize(new Dimension(300,300));
    scrollPane.setPreferredSize(new Dimension(300, 200));

    // Bottom Button UI
    cancelBtn = createButton(getResourceString("CANCEL"));
    okBtn = createButton(getResourceString("OK"));

    okBtn.addActionListener(this);
    getRootPane().setDefaultButton(okBtn);

    ButtonBarBuilder btnBuilder = new ButtonBarBuilder();
    btnBuilder.addGlue();
    btnBuilder.addGriddedButtons(new JButton[] { cancelBtn, okBtn });

    cancelBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setVisible(false);
        }
    });

    panel.add(btnBuilder.getPanel(), BorderLayout.SOUTH);

    setContentPane(panel);
    pack();
    updateUI();
}

From source file:com.sec.ose.osi.ui.frm.main.identification.codematch.table.JPanCMTableArea.java

protected JTableInfoForCMMultipleFile getJTableInfoForCMMultipleFile() {
    if (jTableInfoForCMMultipleFile == null) {
        jTableInfoForCMMultipleFile = new JTableInfoForCMMultipleFile();
        jTableInfoForCMMultipleFile.addKeyListener(new KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent e) {
                keyReleasedAction(jTableInfoForCMMultipleFile);
            }//from  w w  w.  ja v a 2s .  c om
        });

        jTableInfoForCMMultipleFile.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                mouseClickedAction(jTableInfoForCMMultipleFile, e);
            }
        });
    }
    return jTableInfoForCMMultipleFile;
}

From source file:gtu._work.ui.CheckJavaClassPathUI.java

private void initGUI() {
    try {//from   w ww.j  av  a2 s  . co m
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        setTitle("??importjava");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("", null, jPanel1, null);
                {
                    classPathText = new JTextField();
                    jPanel1.add(classPathText, BorderLayout.NORTH);
                    classPathText.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            if (StringUtils.isNotBlank(classPathText.getText())) {
                                String text = classPathText.getText();
                                DefaultListModel model = (DefaultListModel) classPathList.getModel();
                                boolean findOk = false;
                                for (int ii = 0; ii < model.size(); ii++) {
                                    String val = (String) model.getElementAt(ii);
                                    if (StringUtils.equals(val, text)) {
                                        findOk = true;
                                    }
                                }
                                if (!findOk) {
                                    model.addElement(text);
                                }
                            }
                        }
                    });
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(492, 302));
                    {
                        DefaultListModel classPathListModel = new DefaultListModel();
                        classPathList = new JList();

                        Set<String> clzSet = new HashSet<String>();
                        for (Enumeration<?> enu = configBean.getConfigProp().keys(); enu.hasMoreElements();) {
                            String key = (String) enu.nextElement();
                            if (key.contains(CLASSNAME_KEY)) {
                                clzSet.add(configBean.getConfigProp().getProperty(key));
                            }
                        }
                        for (String clzName : clzSet) {
                            classPathListModel.addElement(clzName);
                        }

                        jScrollPane1.setViewportView(classPathList);
                        classPathList.setModel(classPathListModel);
                        classPathList.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(classPathList).defaultJListKeyPressed(evt);
                            }
                        });
                    }
                }
                {
                    executeBtn = new JButton();
                    jPanel1.add(executeBtn, BorderLayout.WEST);
                    executeBtn.setText("\u57f7\u884c");
                    executeBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            executeBtnActionPerformed(evt);
                        }
                    });
                }
                {
                    srcPathText = new JTextField();
                    if (configBean.getConfigProp().containsKey(SRCPATHTEXT_KEY)) {
                        srcPathText.setText(configBean.getConfigProp().getProperty(SRCPATHTEXT_KEY));
                    }

                    jPanel1.add(srcPathText, BorderLayout.SOUTH);
                    JCommonUtil.jTextFieldSetFilePathMouseEvent(srcPathText, true);
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("log", null, jPanel2, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel2.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(530, 350));
                    {
                        logArea = new JTextArea();
                        jScrollPane2.setViewportView(logArea);
                    }
                }
            }
        }
        pack();
        this.setSize(551, 417);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:com.declarativa.interprolog.gui.Ini2BCKP.java

/*********************/

public Ini2BCKP(AbstractPrologEngine e, boolean autoDisplay) {
    /// super("PrologEngine listener (Swing)");
    System.out.println("ENTRA");
    if (e != null) {
        engine = e;/*  w  ww .  j  a  va 2  s.  co m*/
    } else {
        throw new IPException("missing Prolog engine");
    }

    String VF = e.getImplementationPeer().visualizationFilename();
    if (engine.getLoadFromJar()) {
        engine.consultFromPackage(VF, Ini2BCKP.class);
    } else {
        engine.consultRelative(VF, Ini2BCKP.class);
    }
    engine.teachMoreObjects(guiExamples());

    if (engine == null) {
        dispose(); // no interface object permitted!
    } else {
        topLevelCount++;
    }
    debug = engine.isDebug();

    loadedFiles = new Vector();

    initComponents();

    //constructWindowContents();
    ///        constructMenu();
    addWindowListener(this);

    prologInput.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                //                    sendToProlog();
                e.consume();
            }
        }
    });
    //prologOutput.append("Welcome to an InterProlog top level\n" + e.getPrologVersion() + "\n\n");
    prologOutput.append("\n ARG ENGINE v18 ALPHA ");
    prologOutput.append("\t Argument Engine based on WFS \n\n");
    prologOutput.append("\t UIKM Group - Umea University \n\n");
    prologOutput.append("\t {esteban, jcnieves, helena}@cs.umu.se \n\n");
    if (autoDisplay) {
        setVisible(true);
        //            focusInput();
    }
}

From source file:gtu.zcognos.DimensionUI.java

private void initGUI() {
    try {/*ww  w .ja  v a  2 s  . com*/

        final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);
        {
            GroupLayout thisLayout = new GroupLayout((JComponent) getContentPane());
            getContentPane().setLayout(thisLayout);
            this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            {
                projectId = new JTextField();
            }
            {
                jLabel1 = new JLabel();
                jLabel1.setText("PROJECT_ID");
            }
            {
                create = new JButton();
                create.setText("create");
                create.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("create.actionPerformed", evt);
                    }
                });
            }
            {
                reportId = new JTextField();
            }
            {
                jLabel8 = new JLabel();
                jLabel8.setText("report id");
            }
            {
                addDimensionFromDb = new JButton();
                addDimensionFromDb.setText("add from db");
                addDimensionFromDb.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("addFromDb.actionPerformed", evt);
                    }
                });
            }
            {
                dataSourceTable = new JTextField();
                dataSourceTable.setText("rscdpg0901");
            }
            {
                jLabel7 = new JLabel();
                jLabel7.setText("data source table");
            }
            {
                addDimension = new JButton();
                addDimension.setText("add");
                addDimension.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("add.actionPerformed", evt);
                    }
                });
            }
            {
                dimensionName = new JTextField();
            }
            {
                jLabel6 = new JLabel();
                jLabel6.setText("dimension chinese name");
            }
            {
                jLabel5 = new JLabel();
                jLabel5.setText("rscdzzzz id index");
            }
            {
                String[] idx = new String[20];
                for (int ii = 0; ii < idx.length; ii++) {
                    idx[ii] = "id" + (ii + 1);
                }
                ComboBoxModel rscdzzzzIdIndexModel = new DefaultComboBoxModel(idx);
                rscdzzzzIdIndex = new JComboBox();
                rscdzzzzIdIndex.setModel(rscdzzzzIdIndexModel);
            }
            {
                jLabel3 = new JLabel();
                jLabel3.setText("Dimension");
            }
            {
                jScrollPane1 = new JScrollPane();
                {
                    DefaultListModel dimensionListModel = new DefaultListModel();
                    dimensionList = new JList();
                    jScrollPane1.setViewportView(dimensionList);
                    dimensionList.setModel(dimensionListModel);
                    dimensionList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            JListUtil.newInstance(dimensionList).defaultJListKeyPressed(evt);
                        }
                    });
                }
            }
            {
                exportDir = new JButton();
                exportDir.setText("export dir");
                exportDir.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        swingUtil.invokeAction("exportDir.actionPerformed", evt);
                    }
                });
            }
            {
                category = new JTextField();
            }
            {
                jLabel4 = new JLabel();
                jLabel4.setText("category");
            }
            {
                tableName = new JTextField();
            }
            {
                jLabel2 = new JLabel();
                jLabel2.setText("merge table name");
            }
            thisLayout
                    .setHorizontalGroup(thisLayout.createSequentialGroup().addContainerGap(12, 12)
                            .addGroup(thisLayout.createParallelGroup()
                                    .addComponent(jLabel3, GroupLayout.Alignment.LEADING,
                                            GroupLayout.PREFERRED_SIZE, 196, GroupLayout.PREFERRED_SIZE)
                                    .addGroup(thisLayout.createSequentialGroup().addGap(19).addGroup(thisLayout
                                            .createParallelGroup().addGroup(thisLayout.createSequentialGroup()
                                                    .addComponent(exportDir, GroupLayout.PREFERRED_SIZE, 119,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(
                                                            addDimension, GroupLayout.PREFERRED_SIZE, 119,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                                    .addGroup(thisLayout.createParallelGroup().addComponent(
                                                            addDimensionFromDb, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 191,
                                                            GroupLayout.PREFERRED_SIZE)
                                                            .addGroup(thisLayout.createSequentialGroup().addGap(
                                                                    88)
                                                                    .addComponent(create,
                                                                            GroupLayout.PREFERRED_SIZE, 119,
                                                                            GroupLayout.PREFERRED_SIZE))))
                                            .addGroup(thisLayout.createSequentialGroup().addGroup(thisLayout
                                                    .createParallelGroup()
                                                    .addComponent(jLabel6, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel5, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel4, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel8, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel2, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel7, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel1, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 196,
                                                            GroupLayout.PREFERRED_SIZE))
                                                    .addGap(39)
                                                    .addGroup(thisLayout.createParallelGroup()
                                                            .addComponent(dimensionName,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(rscdzzzzIdIndex,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(category,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(reportId,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(tableName,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(dataSourceTable,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                            .addComponent(projectId,
                                                                    GroupLayout.Alignment.LEADING,
                                                                    GroupLayout.PREFERRED_SIZE, 204,
                                                                    GroupLayout.PREFERRED_SIZE)))
                                            .addComponent(jScrollPane1, GroupLayout.Alignment.LEADING,
                                                    GroupLayout.PREFERRED_SIZE, 436,
                                                    GroupLayout.PREFERRED_SIZE))))
                            .addContainerGap(11, 11));
            thisLayout.setVerticalGroup(thisLayout.createSequentialGroup().addContainerGap(12, 12)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(projectId, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(dataSourceTable, GroupLayout.Alignment.BASELINE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(tableName, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(reportId, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(category, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup()
                            .addComponent(jLabel5, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(rscdzzzzIdIndex, GroupLayout.Alignment.LEADING,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(dimensionName, GroupLayout.Alignment.BASELINE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(addDimension, GroupLayout.Alignment.BASELINE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(exportDir, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addComponent(addDimensionFromDb, GroupLayout.Alignment.BASELINE,
                                    GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                    .addGap(11)
                    .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 269, GroupLayout.PREFERRED_SIZE)
                    .addGap(12).addComponent(create, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(9, 9));
        }
        this.setSize(513, 632);

        swingUtil.addAction("exportDir.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                        .getApproveSelectedFile();
                if (file != null) {
                    baseDir = file;
                }
            }
        });

        swingUtil.addAction("addFromDb.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                String project = projectId.getText();
                Validate.notEmpty(project, "projectId is null");
                Validate.notEmpty(dataSourceTable.getText(), "dataSourceTable is null");

                DefaultListModel model = (DefaultListModel) dimensionList.getModel();
                for (Dimension_ ddd : InformixDbConn.queryGetDaminsion(dataSourceTable.getText(), project)) {
                    model.addElement(ddd);
                }
            }
        });

        swingUtil.addAction("add.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                // Validate.notEmpty(tableName.getText(),
                // "tableName is null");
                Validate.notEmpty(category.getText(), "category is null");
                Validate.notEmpty(dimensionName.getText(), "dimensionName is null");
                Validate.notEmpty(dataSourceTable.getText(), "dataSourceTable is null");
                // Validate.notEmpty(reportId.getText(),
                // "reportId is null");

                String report_id = StringUtils.defaultString(reportId.getText(), projectId.getText());

                String tName = tableName.getText();
                if (StringUtils.isEmpty(tName)) {
                    tName = randomTableName();
                }

                DefaultListModel model = (DefaultListModel) dimensionList.getModel();
                model.addElement(new Dimension_(dataSourceTable.getText(), tName, category.getText(),
                        (String) rscdzzzzIdIndex.getSelectedItem(), dimensionName.getText(), report_id));
            }
        });

        swingUtil.addAction("create.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {

                String project = projectId.getText();
                Validate.notEmpty(project, "projectId is null");
                Validate.notNull(baseDir, "exportDir is null");

                File destDir = new File(baseDir, project);

                Map<String, Object> map = new HashMap<String, Object>();

                List<Map<String, String>> llist = new ArrayList<Map<String, String>>();

                int idx = 2;
                int categoryId = 1;
                DefaultListModel model = (DefaultListModel) dimensionList.getModel();
                for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                    Dimension_ di = (Dimension_) enu.nextElement();

                    Map mmm = new HashMap();
                    mmm.put("rscdpg0901", di.dataSourceTable);//
                    mmm.put("rscdpg0901a", di.tableName);//
                    mmm.put("rscdpg0901a_category", di.category);//
                    mmm.put("rscdpg0901a_report_id", di.reportId);//
                    mmm.put("rscdzzzz_id", di.idIndex);//
                    mmm.put("rscdpg0901a_dname", di.dimensionName);//
                    llist.add(mmm);
                }

                map.put("PROJECT_ID", project);
                map.put("RSCDPG0901", llist);
                map.put("rscdpg0901", dataSourceTable.getText());

                ConfigCopy.getInstance().applyBaseDir(baseDir).applyProjectId(project).execute();

                Dimension.getInstance()//
                        .applyDestDir(destDir.getAbsolutePath())//
                        .applyParameter(map)//
                        .execute();

                JOptionPaneUtil.newInstance().iconInformationMessage()
                        .showMessageDialog(project + " create completed!!\r\n dir : " //
                                + destDir.getAbsolutePath(), project);

                Desktop.getDesktop().open(destDir);
            }
        });

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.codesourcery.jasm16.ide.ui.views.WorkspaceExplorer.java

private JPanel createPanel() {
    treeModel = createTreeModel();//from  w ww .j a v  a2 s .co  m
    tree.setModel(treeModel);
    setColors(tree);
    tree.setRootVisible(false);

    //      for (int i = 0; i < tree.getRowCount(); i++) {
    //         tree.expandRow(i);
    //      }

    tree.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {
                final WorkspaceTreeNode selection = getSelectedNode();
                if (selection != null) {
                    deleteResource(selection);
                }
            } else if (e.getKeyCode() == KeyEvent.VK_F5) {
                refreshWorkspace(null);
            }
        }
    });

    tree.addMouseListener(new MouseAdapter() {

        public void mouseClicked(java.awt.event.MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                final TreePath path = tree.getPathForLocation(e.getX(), e.getY());
                if (path != null) {
                    final WorkspaceTreeNode selected = (WorkspaceTreeNode) path.getLastPathComponent();
                    final IAssemblyProject project = getProject(selected);
                    try {
                        if (project != null) {
                            onTreeNodeLeftClick(project, selected);
                        } else {
                            System.err.println("Unable to locate project for " + selected);
                        }
                    } catch (IOException e1) {
                        LOG.error("mouseClicked(): Internal error", e1);
                    }
                }
            }
        }
    });

    final TreeSelectionListener selectionListener = new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {

        }
    };

    tree.getSelectionModel().addTreeSelectionListener(selectionListener);

    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        public Color getTextSelectionColor() {
            return Color.GREEN;
        };

        public java.awt.Color getTextNonSelectionColor() {
            return Color.GREEN;
        };

        public Color getBackgroundSelectionColor() {
            return Color.BLACK;
        };

        public Color getBackgroundNonSelectionColor() {
            return Color.BLACK;
        };

        public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {

            java.awt.Component result = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
                    row, hasFocus);

            String label = value.toString();
            Color color = getTextColor();
            if (value instanceof WorkspaceTreeNode) {
                if (value instanceof ProjectNode) {
                    final ProjectNode projectNode = (ProjectNode) value;
                    final IAssemblyProject project = projectNode.getValue();
                    label = project.getName();

                    if (project.isClosed()) {
                        color = Color.LIGHT_GRAY;
                    } else {
                        if (projectNode.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                    }
                } else if (value instanceof FileNode) {
                    FileNode fn = (FileNode) value;
                    label = fn.getValue().getName();
                    switch (fn.type) {
                    case DIRECTORY:
                        if (fn.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                        break;
                    case OBJECT_FILE:
                        label = "[O] " + label;
                        break;
                    case EXECUTABLE:
                        label = "[E] " + label;
                        break;
                    case SOURCE_CODE:
                        label = "[S] " + label;
                        if (fn.hasCompilationErrors()) {
                            color = Color.RED;
                        }
                        break;
                    default:
                        // ok
                    }
                }
            }
            setForeground(color);
            setText(label);
            return result;
        };

    });

    setupPopupMenu();

    final JScrollPane pane = new JScrollPane(tree);
    setColors(pane);

    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());
    GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH);
    setColors(result);
    result.add(pane, cnstrs);
    return result;
}

From source file:org.openmicroscopy.shoola.util.ui.NumericalTextField.java

/**
 * Creates a new instance.//from  ww w .j  ava2  s  .c o m
 *
 * @param min The minimum value of the text field.
 * @param max The maximum value of the text field.
 * @param type The number type.
 */
public NumericalTextField(double min, double max, Class<?> type) {
    document = new NumericalPlainDocument(min, max);
    setHorizontalAlignment(JTextField.RIGHT);
    setDocument(document);
    originalText = null;
    editedColor = null;
    document.addDocumentListener(this);
    addFocusListener(this);
    addKeyListener(new KeyAdapter() {

        /**
         * Checks if the text is valid.
         * @see KeyListener#keyPressed(KeyEvent)
         */
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                String s = getText();
                String v = checkValue();
                if (v != null && !v.equals(s)) {
                    setText(v);
                }
            }
        }
    });
    numberType = type;
    accepted = NUMERIC;
    setNegativeAccepted(min < 0);
}

From source file:gtu._work.ui.JarFinderUI.java

private void initGUI() {
    try {//ww w. ja va2s. c o  m

        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setTitle("Jar finder");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("src dir", null, jPanel1, null);
                {
                    openDir = new JButton();
                    jPanel1.add(openDir, BorderLayout.NORTH);
                    openDir.setText("open dir");
                    openDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                        }
                    });
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(406, 255));
                    {
                        DefaultListModel jList1Model = new DefaultListModel();
                        try {
                            prop.load(new FileInputStream(CONFIG_FILE));
                            for (Enumeration<?> enu = prop.keys(); enu.hasMoreElements();) {
                                File val = new File((String) enu.nextElement());
                                jList1Model.addElement(val);
                            }
                        } catch (Exception ex) {
                            JCommonUtil.handleException("??:" + CONFIG_FILE, ex);
                        }
                        jarFileDirs = new JList();
                        jScrollPane1.setViewportView(jarFileDirs);
                        jarFileDirs.setModel(jList1Model);
                        jarFileDirs.setPreferredSize(new java.awt.Dimension(406, 221));
                        jarFileDirs.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                if (!JListUtil.newInstance(jarFileDirs).isCorrectMouseClick(evt)) {
                                    return;
                                }
                                File file = (File) JListUtil.getLeadSelectionObject(jarFileDirs);
                                try {
                                    Desktop.getDesktop().open(file);
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                        jarFileDirs.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(jarFileDirs).defaultJListKeyPressed(evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("result", null, jPanel2, null);
                {
                    jPanel3 = new JPanel();
                    BorderLayout jPanel3Layout = new BorderLayout();
                    jPanel3.setLayout(jPanel3Layout);
                    jPanel2.add(jPanel3, BorderLayout.NORTH);
                    jPanel3.setPreferredSize(new java.awt.Dimension(406, 26));
                    {
                        searchText = new JTextField();
                        jPanel3.add(searchText, BorderLayout.WEST);
                        searchText.setPreferredSize(new java.awt.Dimension(326, 26));
                    }
                    {
                        search = new JButton();
                        jPanel3.add(search, BorderLayout.CENTER);
                        search.setText("search");
                        search.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jButton2ActionPerformed(evt);
                            }
                        });
                    }
                }
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel2.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(406, 231));
                    {
                        ListModel searchResultModel = new DefaultListModel();
                        searchResult = new JList();
                        jScrollPane2.setViewportView(searchResult);
                        searchResult.setModel(searchResultModel);
                        searchResult.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                jList1MouseClicked(evt);
                            }
                        });
                        searchResult.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(searchResult).defaultJListKeyPressed(evt);
                            }
                        });
                    }
                }
                {
                    resetFinder = new JButton();
                    jPanel2.add(resetFinder, BorderLayout.SOUTH);
                    resetFinder.setText("reset finder");
                    resetFinder.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jarfinder.clear();
                        }
                    });
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("copy to", null, jPanel4, null);
                {
                    copyToBtn = new JButton();
                    jPanel4.add(copyToBtn, BorderLayout.NORTH);
                    copyToBtn.setText("copy to");
                    copyToBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                                    .getApproveSelectedFile();
                            if (file == null) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("copy to dir undefined!", getTitle());
                                return;
                            } else {
                                copyToFile = file;
                            }
                        }
                    });
                }
                {
                    jScrollPane3 = new JScrollPane();
                    jPanel4.add(jScrollPane3, BorderLayout.CENTER);
                    {
                        DefaultListModel copyToListModel = new DefaultListModel();
                        copyToList = new JList();
                        jScrollPane3.setViewportView(copyToList);
                        copyToList.setModel(copyToListModel);
                        {
                            panel = new JPanel();
                            jTabbedPane1.addTab("config", null, panel, null);
                            panel.setLayout(new FormLayout(
                                    new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC,
                                            FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
                                            ColumnSpec.decode("default:grow"), },
                                    new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, }));
                            {
                                lblNewLabel = new JLabel("JD Gui");
                                panel.add(lblNewLabel, "2, 2, right, default");
                            }
                            {
                                jdGuiText = new JTextField();
                                JCommonUtil.jTextFieldSetFilePathMouseEvent(jdGuiText, false);
                                panel.add(jdGuiText, "4, 2, fill, default");
                                jdGuiText.setColumns(10);
                            }
                            {
                                saveConfigBtn = new JButton("");
                                saveConfigBtn.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            configBean.reflectSetConfig(JarFinderUI.this);
                                            configBean.store();
                                            JCommonUtil._jOptionPane_showMessageDialog_info("?!");
                                        } catch (Exception ex) {
                                            JCommonUtil.handleException(ex);
                                        }
                                    }
                                });
                                panel.add(saveConfigBtn, "2, 24");
                            }
                        }
                        copyToList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                // copyToFile
                                if (evt.getClickCount() != 2) {
                                    return;
                                }
                                if (copyToList.getLeadSelectionIndex() == -1) {
                                    return;
                                }
                                if (copyToFile == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("copy to dir undefined!", getTitle());
                                    return;
                                }
                                DefaultListModel model = (DefaultListModel) copyToList.getModel();
                                Object val = model.getElementAt(copyToList.getLeadSelectionIndex());
                                StringBuilder sb = new StringBuilder();
                                sb.append("?\n");
                                sb.append("file : " + val + "\n");
                                sb.append("copy to dir : " + copyToFile + "\n");
                                ComfirmDialogResult result = JOptionPaneUtil.newInstance().confirmButtonYesNo()
                                        .showConfirmDialog(sb, getTitle());
                                File srcFile = new File((String) val);
                                if (!srcFile.exists()) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog(srcFile + "  not found!", getTitle());
                                    return;
                                }
                                File copyDestFile = new File(copyToFile, srcFile.getName());
                                switch (result) {
                                case YES_OK_OPTION:
                                    System.out.println("yes..");
                                    try {
                                        FileUtil.copyFile(srcFile, copyDestFile);
                                    } catch (IOException e) {
                                        JCommonUtil.handleException(e.toString(), e);
                                    }
                                    if (srcFile != null && //
                                    copyDestFile != null && //
                                    srcFile.length() == copyDestFile.length()) {
                                        JOptionPaneUtil.newInstance().iconInformationMessage()
                                                .showMessageDialog("success!\n" + copyDestFile, getTitle());
                                    } else {
                                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                                .showMessageDialog("failed!\n" + copyDestFile, getTitle());
                                    }
                                    break;
                                case NO_OPTION:
                                    System.out.println("no..");
                                    break;
                                }
                            }
                        });
                    }
                }
            }

            jTabbedPane1.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent evt) {
                    copyToList.setModel(searchResult.getModel());
                }
            });
        }
        this.setSize(562, 407);

        JCommonUtil.frameCloseDo(this, new WindowAdapter() {
            public void windowClosing(WindowEvent paramWindowEvent) {
                if (CONFIG_FILE.exists()) {
                    DefaultListModel model = (DefaultListModel) jarFileDirs.getModel();
                    for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                        Object obj = enu.nextElement();
                        prop.setProperty(((File) obj).getAbsolutePath(), "");
                    }
                    try {
                        prop.store(new FileOutputStream(CONFIG_FILE), "testtesttesttest");
                    } catch (Exception e) {
                        JCommonUtil.handleException("", e);
                    }
                }
                setVisible(false);
                dispose();
            }
        });

        {
            configBean.reflectInit(this);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}