Example usage for java.awt.event WindowListener WindowListener

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

Introduction

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

Prototype

WindowListener

Source Link

Usage

From source file:test.uk.co.modularaudio.util.swing.colouredtoggle.TestUseColouredLabelToggle.java

public void go() throws Exception {
    final JFrame testFrame = new JFrame("TestFrame");
    testFrame.setSize(new Dimension(300, 300));
    testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final Container contentPane = testFrame.getContentPane();

    final MigLayoutStringHelper msh = new MigLayoutStringHelper();
    msh.addLayoutConstraint("fill");
    msh.addLayoutConstraint("gap 0");
    msh.addLayoutConstraint("insets 0");

    contentPane.setLayout(msh.createMigLayout());

    final Color surroundColor = Color.decode("#FFFFFF");
    final Color backgroundColor = Color.BLACK;
    final Color foregroundColor = Color.white;

    final ToggleReceiver testReceiver = new ToggleReceiver() {

        @Override//from  w  ww  .  j a  v a2s .c om
        public void receiveToggle(final int toggleId, final boolean active) {
            log.trace("Received a toggle of " + toggleId + " to " + active);
        }
    };

    final ColouredLabelToggle clt = new ColouredLabelToggle("Trigger", "Tooltip Text", backgroundColor,
            foregroundColor, surroundColor, false, testReceiver, 0);
    contentPane.add(clt, "grow");

    testFrame.pack();

    testFrame.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(final WindowEvent e) {
        }

        @Override
        public void windowIconified(final WindowEvent e) {
        }

        @Override
        public void windowDeiconified(final WindowEvent e) {
        }

        @Override
        public void windowDeactivated(final WindowEvent e) {
        }

        @Override
        public void windowClosing(final WindowEvent e) {
            log.trace("Window closing. Value of control is \"" + clt.getControlValue() + "\"");
        }

        @Override
        public void windowClosed(final WindowEvent e) {
        }

        @Override
        public void windowActivated(final WindowEvent e) {
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            log.trace("Showing test frame");
            testFrame.setVisible(true);
        }
    });
}

From source file:test.uk.co.modularaudio.util.swing.texttoggle.TestUseTextToggle.java

public void go() throws Exception {
    final JFrame testFrame = new JFrame("TestFrame");
    testFrame.setSize(new Dimension(300, 300));
    testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    final Container contentPane = testFrame.getContentPane();

    final MigLayoutStringHelper msh = new MigLayoutStringHelper();
    msh.addLayoutConstraint("fill");
    msh.addLayoutConstraint("gap 0");
    msh.addLayoutConstraint("insets 0");

    contentPane.setLayout(msh.createMigLayout());

    final Color BACKGROUND_COLOR = Color.BLACK;
    final Color SCOPE_BODY = new Color(75, 131, 155);
    final Color SCOPE_AXIS_DETAIL = SCOPE_BODY.darker().darker();

    final Color selectedTextColor = SCOPE_BODY;
    final Color unselectedTextColor = SCOPE_AXIS_DETAIL;
    final Color borderColor = SCOPE_AXIS_DETAIL;
    final Color backgroundColor = BACKGROUND_COLOR;

    final ToggleReceiver testReceiver = new ToggleReceiver() {

        @Override//  w  w w  .j  a v  a  2 s.  com
        public void receiveToggle(final int toggleId, final boolean active) {
            log.trace("Received a toggle of " + toggleId + " to " + active);
        }
    };

    final TextToggle tt = new TextToggle("Bi Polar", "Uni Polar", selectedTextColor, unselectedTextColor,
            backgroundColor, borderColor, true, true, testReceiver, -1);

    contentPane.add(tt, "grow");

    testFrame.pack();

    testFrame.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(final WindowEvent e) {
        }

        @Override
        public void windowIconified(final WindowEvent e) {
        }

        @Override
        public void windowDeiconified(final WindowEvent e) {
        }

        @Override
        public void windowDeactivated(final WindowEvent e) {
        }

        @Override
        public void windowClosing(final WindowEvent e) {
            log.trace("Window closing. Value of control is \"" + tt.getControlValue() + "\"");
        }

        @Override
        public void windowClosed(final WindowEvent e) {
        }

        @Override
        public void windowActivated(final WindowEvent e) {
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            log.trace("Showing test frame");
            testFrame.setVisible(true);
        }
    });
}

From source file:org.parosproxy.paros.view.AbstractFrame.java

/**
 * This is the default constructor//from  w  w w .java 2 s  . c o  m
 */
public AbstractFrame(String frameName) {
    super();
    this.frameName = frameName;
    setIconImage(Res.IMAGE_LOGO);
    setVisible(false);
    setTitle(Constant.PROGRAM_NAME);
    setFont(Res.FONT_DIALOG_11);
    restoreLocationAdnSize();
    /*       
           addComponentListener(new ComponentListener() {
             public void componentShown(ComponentEvent paramComponentEvent) {
             }
                     
             public void componentResized(ComponentEvent paramComponentEvent) {
    storeLocation();
             }
                     
             public void componentMoved(ComponentEvent paramComponentEvent) {
    storeLocation();
             }
                     
             public void componentHidden(ComponentEvent paramComponentEvent) {
    System.out.println("HIDE " + AbstractFrame.this.frameName);            
             }
          });
    */

    addWindowStateListener(new WindowStateListener() {

        public void windowStateChanged(WindowEvent paramWindowEvent) {
            System.out.println("  windowStateChanged " + AbstractFrame.this.frameName);
        }
    });

    addWindowListener(new WindowListener() {
        public void windowOpened(WindowEvent paramWindowEvent) {
        }

        public void windowIconified(WindowEvent paramWindowEvent) {
        }

        public void windowDeiconified(WindowEvent paramWindowEvent) {
        }

        public void windowDeactivated(WindowEvent paramWindowEvent) {
        }

        public void windowClosed(WindowEvent paramWindowEvent) {
        }

        public void windowActivated(WindowEvent paramWindowEvent) {
        }

        public void windowClosing(WindowEvent paramWindowEvent) {
            storeLocation();
        }

    });
}

From source file:com.jskj.asset.client.panel.slgl.DiZhiYiHaoPinDengJiJDialog.java

/**
 * Creates new form PTGuDingZiChanDengJiJDialog
 *///from   w w  w.j a va  2 s  .c  om
public DiZhiYiHaoPinDengJiJDialog() {
    super();
    init();
    initComponents();
    userId = AssetClientApp.getSessionMap().getUsertb().getUserId();
    userName = AssetClientApp.getSessionMap().getUsertb().getUserName();
    isNew = false;
    barcode = DanHao.getDanHao("YHP");

    this.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosing(WindowEvent e) {
            exit();
        }

        @Override
        public void windowClosed(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }

    });

    ((BaseTextField) jTextFieldName).registerPopup(new IPopupBuilder() {

        public int getType() {
            return IPopupBuilder.TYPE_POPUP_TEXT;
        }

        public String getWebServiceURI() {
            return Constants.HTTP + Constants.APPID + "yhplb";
        }

        public String getConditionSQL() {
            wait = true;
            chooseZichan();
            while (wait) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    Logger.getLogger(PTGuDingZiChanDengJiJDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            String sql = "";
            sql += " cgsq_id like \"%YHCG%\" and is_completed = 1 and status = 0 ";
            if (sqid != null) {
                sql += " and cgsq_id = \"" + sqid + "\" ";
            }
            if (!jTextFieldName.getText().trim().equals("")) {
                sql += (" and cgzc_id in ( select dzyhp_id  from dizhiyihaopin where dzyhp_name like \"%"
                        + jTextFieldName.getText() + "%\"" + " or zujima like \"%"
                        + jTextFieldName.getText().toLowerCase() + "%\")");
            }
            return sql;
        }

        public String[][] displayColumns() {
            return new String[][] { { "shenqingdan.shenqingdanId", "???" },
                    { "shenqingdan.zhidanren", "" }, { "dzyhpId", "?ID" },
                    { "dzyhpName", "???" } };
        }

        public void setBindedMap(HashMap bindedMap) {
            if (bindedMap != null) {
                jTextFieldZcid
                        .setText(bindedMap.get("dzyhpId") == null ? "" : bindedMap.get("dzyhpId").toString());
                jTextFieldZctype.setText(
                        bindedMap.get("dzyhpType") == null ? "" : bindedMap.get("dzyhpType").toString());
                jTextFieldName.setText(
                        bindedMap.get("dzyhpName") == null ? "" : bindedMap.get("dzyhpName").toString());
                jTextFieldPinpai.setText(
                        bindedMap.get("dzyhpPinpai") == null ? "" : bindedMap.get("dzyhpPinpai").toString());
                jTextFieldXinghao.setText(
                        bindedMap.get("dzyhpXinghao") == null ? "" : bindedMap.get("dzyhpXinghao").toString());
                jTextFieldGuige.setText(
                        bindedMap.get("dzyhpGuige") == null ? "" : bindedMap.get("dzyhpGuige").toString());
                jTextFieldPrice.setText(
                        bindedMap.get("saleprice") == null ? "" : bindedMap.get("saleprice").toString());
                jTextFieldUnit
                        .setText(bindedMap.get("unitId") == null ? "" : bindedMap.get("unitId").toString());
                HashMap map = (HashMap) bindedMap.get("suppliertb");
                if (map != null) {
                    jTextFieldSupplier
                            .setText(map.get("supplierName") == null ? "" : map.get("supplierName").toString());
                }
                //                    jTextFieldBaoxiuqi.setText(bindedMap.get("dzyhpGuaranteedate") == null ? "" : bindedMap.get("dzyhpGuaranteedate").toString());
                jTextFieldSequence.setText(bindedMap.get("dzyhpSequence") == null ? ""
                        : bindedMap.get("dzyhpSequence").toString());
                jTextAreaRemark.setText(
                        bindedMap.get("dzyhpRemark") == null ? "" : bindedMap.get("dzyhpRemark").toString());
                imageUri = bindedMap.get("unitPhoto") == null ? "" : bindedMap.get("unitPhoto").toString();
                //                    jTextFieldBaoxiuqi.setEditable(false);
                jTextFieldQuantity
                        .setText(bindedMap.get("count") == null ? "" : bindedMap.get("count").toString());
                jTextFieldQuantity.setEditable(false);
                zhijielingyong = Integer.parseInt("" + bindedMap.get("zhijielingyong"));
                map = (HashMap) bindedMap.get("shenqingdan");
                yuandanID = (String) map.get("shenqingdanId");
                danjujine = Float.parseFloat("" + map.get("danjujine"));
                if (zhijielingyong == 1 || danjujine > 1000) {
                    jButton8.setEnabled(false);
                } else {
                    jButton8.setEnabled(true);
                }
            }
        }
    });
}

From source file:com.jskj.asset.client.panel.slgl.GuDingZiChanYanShouJDialog.java

/**
 * Creates new form GuDingZiChanRuKu//from   www  .  j av a  2  s. c om
 */
public GuDingZiChanYanShouJDialog() {
    super();
    init();
    initComponents();
    userId = AssetClientApp.getSessionMap().getUsertb().getUserId();
    userName = AssetClientApp.getSessionMap().getUsertb().getUserName();
    isNew = false;

    this.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosing(WindowEvent e) {
            exit();
        }

        @Override
        public void windowClosed(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }

    });

    jTextField1.setText(DanHao.getDanHao("ZCYS"));
    jTextField1.setEditable(false);

    jTextField2.setText(dateformate.format(new Date()).toString());
    jTextField2.setEditable(false);

    jTextFieldYanshouren.setText(userName);
    jTextFieldYanshouren.setEditable(false);
    yanshouren_id = userId;

    jTextFieldZhidanren.setText(userName);
    jTextFieldZhidanren.setEditable(false);
    zhidanren_id = userId;

    jTextFieldJianceren.setText(userName);
    jTextFieldJianceren.setEditable(false);

    ((BaseTextField) jTextFieldCaigouren).registerPopup(new IPopupBuilder() {

        public int getType() {
            return IPopupBuilder.TYPE_POPUP_TEXT;
        }

        public String getWebServiceURI() {
            return Constants.HTTP + Constants.APPID + "user";
        }

        public String getConditionSQL() {
            String sql = "";
            if (!jTextFieldCaigouren.getText().trim().equals("")) {
                sql = "(user_name like \"%" + jTextFieldCaigouren.getText() + "%\"" + " or zujima like \"%"
                        + jTextFieldCaigouren.getText().toLowerCase() + "%\")";
            }
            return sql;
        }

        public String[][] displayColumns() {
            return new String[][] { { "userId", "ID" }, { "userName", "??" } };
        }

        public void setBindedMap(HashMap bindedMap) {
            if (bindedMap != null) {
                jTextFieldCaigouren
                        .setText(bindedMap.get("userName") == null ? "" : bindedMap.get("userName").toString());
                caigouren_id = (Integer) bindedMap.get("userId");
            }
        }
    });

    ((BaseTextField) jTextFieldZichan).registerPopup(new IPopupBuilder() {

        public int getType() {
            return IPopupBuilder.TYPE_POPUP_TEXT;
        }

        public String getWebServiceURI() {
            return Constants.HTTP + Constants.APPID + "gdzclb";
        }

        public String getConditionSQL() {
            wait = true;
            chooseZichan();
            while (wait) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    Logger.getLogger(PTGuDingZiChanDengJiJDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            String sql = "";
            sql += " cgsq_id like \"%GDZC%\" and is_completed = 1 and status = 1 "
                    + " and cgsq_id NOT IN( SELECT cgsq_id FROM (SELECT cgsq_id,COUNT(*) AS num FROM zichanliebiao WHERE STATUS=0 GROUP BY cgsq_id) AS a WHERE a.num > 0)";
            if (sqid != null) {
                sql += " and cgsq_id = \"" + sqid + "\" ";
            }
            if (!jTextFieldZichan.getText().trim().equals("")) {
                sql += (" and cgzc_id in ( select gdzc_id  from gudingzichan where gdzc_name like \"%"
                        + jTextFieldZichan.getText() + "%\"" + " or zujima like \"%"
                        + jTextFieldZichan.getText().toLowerCase() + "%\")");
            }
            return sql;
        }

        public String[][] displayColumns() {
            return new String[][] { { "shenqingdan.shenqingdanId", "???" },
                    { "shenqingdan.zhidanren", "" }, { "gdzcId", "ID" },
                    { "gdzcName", "??" } };
        }

        public void setBindedMap(HashMap bindedMap) {
            if (bindedMap != null) {
                jTextFieldZichan
                        .setText(bindedMap.get("gdzcName") == null ? "" : bindedMap.get("gdzcName").toString());
                jTextFieldXinghao.setText(
                        bindedMap.get("gdzcXinghao") == null ? "" : bindedMap.get("gdzcXinghao").toString());
                jTextFieldGuige.setText(
                        bindedMap.get("gdzcGuige") == null ? "" : bindedMap.get("gdzcGuige").toString());
                jTextFieldPrice.setText(
                        bindedMap.get("saleprice") == null ? "" : bindedMap.get("saleprice").toString());
                jTextFieldUnit
                        .setText(bindedMap.get("unitId") == null ? "" : bindedMap.get("unitId").toString());
                jTextFieldQuantity
                        .setText(bindedMap.get("count") == null ? "" : bindedMap.get("count").toString());
                jTextFieldQuantity.setEditable(false);
                zcid = (Integer) bindedMap.get("gdzcId");
                HashMap map = (HashMap) bindedMap.get("shenqingdan");
                yuandanID = (String) map.get("shenqingdanId");
            }
        }
    });
}

From source file:com.jskj.asset.client.panel.slgl.PTGuDingZiChanDengJiJDialog.java

/**
 * Creates new form PTGuDingZiChanDengJiJDialog
 *///  www .j  av  a2s . c  om
public PTGuDingZiChanDengJiJDialog() {
    super();
    init();
    initComponents();
    userId = AssetClientApp.getSessionMap().getUsertb().getUserId();
    userName = AssetClientApp.getSessionMap().getUsertb().getUserName();
    mainFrame = AssetClientApp.getApplication().getMainFrame();
    isNew = false;
    barcode = DanHao.getDanHao("PTZC");

    gdzcPhoto.setModel(new BaseListModel<String>(new ArrayList(), ""));

    this.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosing(WindowEvent e) {
            exit();
        }

        @Override
        public void windowClosed(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }

    });

    ((BaseTextField) jTextFieldName).registerPopup(new IPopupBuilder() {

        public int getType() {
            return IPopupBuilder.TYPE_POPUP_TEXT;
        }

        public String getWebServiceURI() {
            return Constants.HTTP + Constants.APPID + "gdzclb";
        }

        public String getConditionSQL() {
            //waitTask?
            wait = true; //Task
            chooseZichan(); //ChooseTask????????ID?sqid
            while (wait) { //ChooseTask
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    Logger.getLogger(PTGuDingZiChanDengJiJDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            String sql = "";
            sql += " cgsq_id like \"%GDZC%\" and is_completed = 1 and status = 0 ";
            if (sqid != null) { //ChooseTask?sqid??????id?
                //???????????
                sql += " and cgsq_id = \"" + sqid + "\" ";
            }
            if (!jTextFieldName.getText().trim().equals("")) {
                sql += (" and cgzc_id in ( select gdzc_id  from gudingzichan where gdzc_type like \"%%\" and (gdzc_name like \"%"
                        + jTextFieldName.getText() + "%\"" + " or zujima like \"%"
                        + jTextFieldName.getText().toLowerCase() + "%\"))");
            } else {
                sql += (" and cgzc_id in ( select gdzc_id  from gudingzichan where gdzc_type like \"%%\" )");
            }

            return sql;
        }

        public String[][] displayColumns() {
            return new String[][] { { "shenqingdan.shenqingdanId", "???" },
                    { "shenqingdan.zhidanren", "" }, { "gdzcId", "ID" },
                    { "gdzcName", "??" } };
        }

        public void setBindedMap(HashMap bindedMap) {
            if (bindedMap != null) {
                jTextFieldZcid
                        .setText(bindedMap.get("gdzcId") == null ? "" : bindedMap.get("gdzcId").toString());
                jTextFieldZctype
                        .setText(bindedMap.get("gdzcType") == null ? "" : bindedMap.get("gdzcType").toString());
                jTextFieldName
                        .setText(bindedMap.get("gdzcName") == null ? "" : bindedMap.get("gdzcName").toString());
                jTextFieldPinpai.setText(
                        bindedMap.get("gdzcPinpai") == null ? "" : bindedMap.get("gdzcPinpai").toString());
                jTextFieldXinghao.setText(
                        bindedMap.get("gdzcXinghao") == null ? "" : bindedMap.get("gdzcXinghao").toString());
                jTextFieldGuige.setText(
                        bindedMap.get("gdzcGuige") == null ? "" : bindedMap.get("gdzcGuige").toString());
                jTextFieldPrice.setText(
                        bindedMap.get("saleprice") == null ? "" : bindedMap.get("saleprice").toString());
                jTextFieldUnit
                        .setText(bindedMap.get("unitId") == null ? "" : bindedMap.get("unitId").toString());
                //                    jTextFieldBaoxiuqi.setText(bindedMap.get("gdzcGuaranteedate") == null ? "" : bindedMap.get("gdzcGuaranteedate").toString());
                jTextFieldXuliehao.setText(
                        bindedMap.get("gdzcSequence") == null ? "" : bindedMap.get("gdzcSequence").toString());
                jTextAreaRemark.setText(bindedMap.get("gdzcRemark").toString().equals("null") ? ""
                        : bindedMap.get("gdzcRemark").toString());
                imageUri = bindedMap.get("gdzcPhoto") == null ? "" : bindedMap.get("gdzcPhoto").toString();
                //                    jTextFieldBaoxiuqi.setEditable(false);
                jTextFieldQuantity
                        .setText(bindedMap.get("count") == null ? "" : bindedMap.get("count").toString());
                jTextFieldQuantity.setEditable(false);
                HashMap map = (HashMap) bindedMap.get("shenqingdan");
                yuandanID = (String) map.get("shenqingdanId");
                map = (HashMap) bindedMap.get("suppliertb");
                supplier = (String) map.get("supplierName");
                jTextFieldSupplier.setText(supplier);
            }
        }
    });

}

From source file:io.github.jeremgamer.editor.panels.MusicFrame.java

public MusicFrame(JFrame frame, final GeneralSave gs) {

    ArrayList<BufferedImage> icons = new ArrayList<BufferedImage>();
    try {/* ww w.  j a v  a  2s. c  o m*/
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon16.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon32.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon64.png")));
        icons.add(ImageIO.read(ImageGetter.class.getResource("icon128.png")));
    } catch (IOException e1) {
        e1.printStackTrace();
    }

    this.setIconImages((List<? extends Image>) icons);

    this.setTitle("Musique");
    this.setSize(new Dimension(300, 225));

    this.addWindowListener(new WindowListener() {
        @Override
        public void windowActivated(WindowEvent event) {
        }

        @Override
        public void windowClosed(WindowEvent event) {
        }

        @Override
        public void windowClosing(WindowEvent event) {
            try {
                gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (clip != null) {
                clip.stop();
                clip.close();
                try {
                    audioStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void windowDeactivated(WindowEvent event) {
        }

        @Override
        public void windowDeiconified(WindowEvent event) {
        }

        @Override
        public void windowIconified(WindowEvent event) {
        }

        @Override
        public void windowOpened(WindowEvent event) {
        }
    });

    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));

    this.setModal(true);
    this.setLocationRelativeTo(frame);

    JPanel properties = new JPanel();
    properties.setBorder(BorderFactory.createTitledBorder("Lecture"));
    ButtonGroup bg = new ButtonGroup();
    bg.add(one);
    bg.add(loop);
    one.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JRadioButton rb = (JRadioButton) event.getSource();
            if (rb.isSelected()) {
                gs.set("music.reading", 0);
                try {
                    gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (clip != null) {
                    if (clip.isRunning())
                        clip.loop(0);
                }
            }
        }
    });
    loop.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent event) {
            JRadioButton rb = (JRadioButton) event.getSource();
            if (rb.isSelected()) {
                gs.set("music.reading", 1);
                try {
                    gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (clip != null) {
                    if (clip.isRunning())
                        clip.loop(Clip.LOOP_CONTINUOUSLY);
                }
            }
        }
    });
    properties.add(one);
    properties.add(loop);
    if (gs.getInt("music.reading") == 0) {
        one.setSelected(true);
    } else {
        loop.setSelected(true);
    }

    volume.setMaximum(100);
    volume.setMinimum(0);
    volume.setValue(30);
    volume.setPaintTicks(true);
    volume.setPaintLabels(true);
    volume.setMinorTickSpacing(10);
    volume.setMajorTickSpacing(20);
    volume.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
            JSlider slider = (JSlider) event.getSource();
            double value = slider.getValue();
            gain = value / 100;
            dB = (float) (Math.log(gain) / Math.log(10.0) * 20.0);
            if (clip != null)
                gainControl.setValue(dB);
            gs.set("music.volume", (int) value);
        }
    });
    volume.setValue(gs.getInt("music.volume"));
    properties.add(volume);
    properties.setPreferredSize(new Dimension(300, 125));

    content.add(properties);

    JPanel browsePanel = new JPanel();
    browsePanel.setBorder(BorderFactory.createTitledBorder(""));
    JButton browse = new JButton("Parcourir...");
    if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) {
        preview.setEnabled(false);
        browse.setText("");
        try {
            browse.setIcon(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    browse.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JButton button = (JButton) event.getSource();
            if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) {
                if (clip != null) {
                    clip.stop();
                    clip.close();
                    try {
                        audioStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                name.setText("");
                preview.setEnabled(false);
                button.setText("Parcourir...");
                button.setIcon(null);
                new File("projects/" + Editor.getProjectName() + "/music.wav").delete();
                gs.set("music.name", "");
            } else {
                String path = null;
                JFileChooser chooser = new JFileChooser(Editor.lastPath);
                FileNameExtensionFilter filter = new FileNameExtensionFilter("Audio (WAV)", "wav");
                chooser.setFileFilter(filter);
                chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                int option = chooser.showOpenDialog(null);
                if (option == JFileChooser.APPROVE_OPTION) {
                    path = chooser.getSelectedFile().getAbsolutePath();
                    Editor.lastPath = chooser.getSelectedFile().getParent();
                    copyMusic(new File(path));
                    button.setText("");
                    try {
                        button.setIcon(
                                new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png"))));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    gs.set("music.name", new File(path).getName());
                    try {
                        gs.save(new File("projects/" + Editor.getProjectName() + "/general.rbd"));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    name.setText(new File(path).getName());
                    preview.setEnabled(true);
                }
            }
        }

    });
    if (new File("projects/" + Editor.getProjectName() + "/music.wav").exists()) {
        preview.setEnabled(true);
    } else {
        preview.setEnabled(false);
    }
    preview.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            JToggleButton tb = (JToggleButton) event.getSource();
            if (tb.isSelected()) {
                try {
                    audioStream = AudioSystem.getAudioInputStream(
                            new File("projects/" + Editor.getProjectName() + "/music.wav"));
                    format = audioStream.getFormat();
                    info = new DataLine.Info(Clip.class, format);
                    clip = (Clip) AudioSystem.getLine(info);
                    clip.open(audioStream);
                    clip.start();
                    gainControl = (FloatControl) clip.getControl(FloatControl.Type.MASTER_GAIN);
                    gainControl.setValue(dB);
                    if (loop.isSelected()) {
                        clip.loop(Clip.LOOP_CONTINUOUSLY);
                    } else {
                        clip.loop(0);
                    }
                    clip.addLineListener(new LineListener() {
                        @Override
                        public void update(LineEvent event) {
                            Clip clip = (Clip) event.getSource();
                            if (!clip.isRunning()) {
                                preview.setSelected(false);
                                clip.stop();
                                clip.close();
                                try {
                                    audioStream.close();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                    });
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            } else {
                clip.stop();
                clip.close();
                try {
                    audioStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    });
    JPanel buttons = new JPanel();
    buttons.setLayout(new BorderLayout());
    buttons.add(browse, BorderLayout.WEST);
    buttons.add(preview, BorderLayout.EAST);
    browsePanel.setLayout(new BorderLayout());
    browsePanel.add(buttons, BorderLayout.NORTH);
    browsePanel.add(name, BorderLayout.SOUTH);

    name.setPreferredSize(new Dimension(280, 25));
    name.setText(gs.getString("music.name"));
    content.add(browsePanel);

    this.setContentPane(content);
    this.setVisible(true);
}

From source file:com.jskj.asset.client.panel.slgl.ITGuDingZiChanDengJiJDialog.java

/**
 * Creates new form PTGuDingZiChanDengJiJDialog
 *//*from w w  w  . j av a  2s . c  o m*/
public ITGuDingZiChanDengJiJDialog() {
    super();
    init();
    initComponents();
    userId = AssetClientApp.getSessionMap().getUsertb().getUserId();
    userName = AssetClientApp.getSessionMap().getUsertb().getUserName();
    mainFrame = AssetClientApp.getApplication().getMainFrame();
    isNew = false;
    barcode = DanHao.getDanHao("ITZC");

    gdzcPhoto.setModel(new BaseListModel<String>(new ArrayList(), ""));

    this.addWindowListener(new WindowListener() {

        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosing(WindowEvent e) {
            exit();
        }

        @Override
        public void windowClosed(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }

    });

    ((BaseTextField) jTextFieldName).registerPopup(new IPopupBuilder() {

        public int getType() {
            return IPopupBuilder.TYPE_POPUP_TEXT;
        }

        public String getWebServiceURI() {
            return Constants.HTTP + Constants.APPID + "gdzclb";
        }

        public String getConditionSQL() {
            wait = true;
            chooseZichan();
            while (wait) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ex) {
                    Logger.getLogger(PTGuDingZiChanDengJiJDialog.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            String sql = "";
            sql += " cgsq_id like \"%GDZC%\" and is_completed = 1 and status = 0 ";
            if (sqid != null) {
                sql += " and cgsq_id = \"" + sqid + "\" ";
            }
            if (!jTextFieldName.getText().trim().equals("")) {
                sql += (" and cgzc_id in ( select gdzc_id  from gudingzichan where gdzc_type like \"%IT%\" and (gdzc_name like \"%"
                        + jTextFieldName.getText() + "%\"" + " or zujima like \"%"
                        + jTextFieldName.getText().toLowerCase() + "%\"))");
            } else {
                sql += (" and cgzc_id in ( select gdzc_id  from gudingzichan where gdzc_type like \"%IT%\" )");
            }
            return sql;
        }

        public String[][] displayColumns() {
            return new String[][] { { "shenqingdan.shenqingdanId", "???" },
                    { "shenqingdan.zhidanren", "" }, { "gdzcId", "ID" },
                    { "gdzcName", "??" } };
        }

        public void setBindedMap(HashMap bindedMap) {
            if (bindedMap != null) {
                jTextFieldZcid
                        .setText(bindedMap.get("gdzcId") == null ? "" : bindedMap.get("gdzcId").toString());
                jTextFieldZctype
                        .setText(bindedMap.get("gdzcType") == null ? "" : bindedMap.get("gdzcType").toString());
                jTextFieldName
                        .setText(bindedMap.get("gdzcName") == null ? "" : bindedMap.get("gdzcName").toString());
                jTextFieldPinpai.setText(
                        bindedMap.get("gdzcPinpai") == null ? "" : bindedMap.get("gdzcPinpai").toString());
                jTextFieldXinghao.setText(
                        bindedMap.get("gdzcXinghao") == null ? "" : bindedMap.get("gdzcXinghao").toString());
                jTextFieldGuige.setText(
                        bindedMap.get("gdzcGuige") == null ? "" : bindedMap.get("gdzcGuige").toString());
                jTextFieldPrice.setText(
                        bindedMap.get("saleprice") == null ? "" : bindedMap.get("saleprice").toString());
                jTextFieldUnit
                        .setText(bindedMap.get("unitId") == null ? "" : bindedMap.get("unitId").toString());
                //                    jTextFieldBaoxiuqi.setText(bindedMap.get("gdzcGuaranteedate") == null ? "" : bindedMap.get("gdzcGuaranteedate").toString());
                jTextFieldXuliehao.setText(
                        bindedMap.get("gdzcSequence") == null ? "" : bindedMap.get("gdzcSequence").toString());
                jTextAreaRemark.setText(
                        bindedMap.get("gdzcRemark") == null ? "" : bindedMap.get("gdzcRemark").toString());
                imageUri = bindedMap.get("gdzcPhoto") == null ? "" : bindedMap.get("gdzcPhoto").toString();
                //                    jTextFieldBaoxiuqi.setEditable(false);
                jTextFieldQuantity
                        .setText(bindedMap.get("count") == null ? "" : bindedMap.get("count").toString());
                jTextFieldQuantity.setEditable(false);
                HashMap map = (HashMap) bindedMap.get("shenqingdan");
                yuandanID = (String) map.get("shenqingdanId");
                map = (HashMap) bindedMap.get("suppliertb");
                supplier = (String) map.get("supplierName");
                jTextFieldSupplier.setText(supplier);
            }
        }
    });
}

From source file:org.openadaptor.auxil.connector.ui.TableUIConnector.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.//from  w  w  w .  j  a v a  2  s.c o  m
 */
private void initialiseGUI() {
    guiIsActive = true;
    log.debug("Initialising UI");
    //Create and set up the window.
    frame = new JFrame(name);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowListener() {
        public void windowClosing(WindowEvent arg0) {
            log.debug("WindowClosing");
            guiIsActive = false;
            disconnect();
        }

        public void windowActivated(WindowEvent arg0) {
        }

        public void windowClosed(WindowEvent arg0) {
        }

        public void windowDeactivated(WindowEvent arg0) {
        }

        public void windowDeiconified(WindowEvent arg0) {
        }

        public void windowIconified(WindowEvent arg0) {
        }

        public void windowOpened(WindowEvent arg0) {
        }
    });

    //Create and set up the content pane.
    tablePanel = new JPanel(new BorderLayout());
    tablePanel.setOpaque(true); //content panes must be opaque
    frame.setContentPane(tablePanel);

    //Create the data model for the table.
    tableModel = new SimpleTableModel(columnNames);
    tableModel.addRow();
    table = new JTable(tableModel);
    table.setShowGrid(true);
    table.setBorder(BorderFactory.createLineBorder(Color.lightGray, 1));
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    tablePanel.add(scrollPane, BorderLayout.CENTER);

    JPanel buttonPanel = createButtonPanel(BUTTON_NAMES);
    tablePanel.add(buttonPanel, BorderLayout.SOUTH);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
    log.debug("UI initialised");
}

From source file:org.opendatakit.appengine.updater.UpdaterWindow.java

/**
 * Create the application./*from   w w  w.java 2  s  .c  om*/
 */
public UpdaterWindow(CommandLine cmd) {
    super();
    AnnotationProcessor.process(this);// if not using AOP
    this.cmd = cmd;
    frame = new JFrame();
    frame.setBounds(100, 100, isLinux() ? 720 : 680, 595);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.addWindowListener(new WindowListener() {
        @Override
        public void windowOpened(WindowEvent e) {
        }

        @Override
        public void windowClosing(WindowEvent e) {
        }

        @Override
        public void windowClosed(WindowEvent e) {
        }

        @Override
        public void windowIconified(WindowEvent e) {
        }

        @Override
        public void windowDeiconified(WindowEvent e) {
        }

        @Override
        public void windowActivated(WindowEvent e) {
        }

        @Override
        public void windowDeactivated(WindowEvent e) {
        }
    });

    JLabel lblEmail = new JLabel(t(TranslatedStrings.EMAIL_LABEL));

    txtEmail = new JTextField();
    txtEmail.setFocusable(true);
    txtEmail.setEditable(true);
    txtEmail.setColumns(60);
    txtEmail.setMaximumSize(txtEmail.getPreferredSize());
    if (cmd.hasOption(ArgumentNameConstants.EMAIL)) {
        txtEmail.setText(cmd.getOptionValue(ArgumentNameConstants.EMAIL));
    }
    lblEmail.setLabelFor(txtEmail);

    JLabel lblToken = new JLabel(t(TranslatedStrings.TOKEN_GRANTING_LABEL));

    txtToken = new JTextField();
    txtToken.setColumns(60);
    txtToken.setMaximumSize(txtToken.getPreferredSize());
    txtToken.setFocusable(false);
    txtToken.setEditable(false);
    if (cmd.hasOption(ArgumentNameConstants.TOKEN_GRANTING_CODE)) {
        txtToken.setText(cmd.getOptionValue(ArgumentNameConstants.TOKEN_GRANTING_CODE));
    }
    lblToken.setLabelFor(txtToken);

    // set up listener for updating warning message
    txtEmail.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateUI();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateUI();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateUI();
        }

    });

    // set up listener for updating warning message
    txtToken.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateUI();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateUI();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateUI();
        }

    });

    if ((txtEmail.getText().length() > 0) && ((txtToken.getText().length() > 0) || perhapsHasToken())) {
        lblWarning = new JLabel(t(TranslatedStrings.WARNING_ERRANT_LABEL));
    } else {
        lblWarning = new JLabel(t(TranslatedStrings.WARNING_REDIRECT_LABEL));
    }

    JLabel outputArea = new JLabel(t(TranslatedStrings.OUTPUT_LBL));
    editorArea = new JTextPane(new DefaultStyledDocument());
    editorArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
    //Put the editor pane in a scroll pane.
    editorScrollPane = new JScrollPane(editorArea);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setPreferredSize(new Dimension(400, 300));
    editorScrollPane.setMinimumSize(new Dimension(10, 10));

    outputArea.setLabelFor(editorScrollPane);
    // Create a container so that we can add a title around
    // the scroll pane. Can't add a title directly to the
    // scroll pane because its background would be white.
    // Lay out the label and scroll pane from top to bottom.
    JPanel listPane = new JPanel();
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
    listPane.add(outputArea);
    listPane.add(Box.createRigidArea(new Dimension(0, 5)));
    listPane.add(editorScrollPane);
    listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    btnDeleteToken = new JButton(t(TranslatedStrings.DELETE_TOKEN_LABEL));
    btnDeleteToken.addActionListener(new DeleteTokenActionListener());
    btnDeleteToken.setEnabled(perhapsHasToken());

    btnChoose = new JButton(t(TranslatedStrings.GET_TOKEN_LABEL));
    if ((txtEmail.getText().length() > 0) && (txtToken.getText().length() > 0) || perhapsHasToken()) {
        if (perhapsHasToken()) {
            btnChoose.setText(t(TranslatedStrings.VERIFY_TOKEN_LABEL));
        } else {
            btnChoose.setText(t(TranslatedStrings.SET_TOKEN_LABEL));
        }
    } else {
        btnChoose.setText(t(TranslatedStrings.GET_TOKEN_LABEL));
    }
    btnChoose.addActionListener(new GetTokenActionListener());
    btnChoose.setEnabled(txtEmail.getText().length() > 0);

    btnUpload = new JButton(t(TranslatedStrings.UPLOAD_LABEL));
    btnUpload.addActionListener(new UploadActionListener());
    btnUpload.setEnabled((txtEmail.getText().length() > 0) && perhapsHasToken());

    btnRollback = new JButton(t(TranslatedStrings.ROLLBACK_LABEL));
    btnRollback.addActionListener(new RollbackActionListener());
    btnRollback.setEnabled((txtEmail.getText().length() > 0) && perhapsHasToken());

    GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
    groupLayout
            .setHorizontalGroup(
                    groupLayout.createSequentialGroup().addContainerGap()
                            .addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblEmail)
                                    .addComponent(txtEmail).addComponent(lblToken).addComponent(txtToken)
                                    .addComponent(lblWarning).addComponent(listPane)
                                    .addGroup(groupLayout.createSequentialGroup().addComponent(btnDeleteToken)
                                            .addGap(3 * HorizontalSpacing).addComponent(btnChoose)
                                            .addGap(HorizontalSpacing).addComponent(btnUpload)
                                            .addGap(3 * HorizontalSpacing, 4 * HorizontalSpacing,
                                                    Short.MAX_VALUE)
                                            .addComponent(btnRollback)))
                            .addContainerGap());

    groupLayout.setVerticalGroup(groupLayout.createSequentialGroup().addContainerGap().addComponent(lblEmail)
            .addPreferredGap(ComponentPlacement.RELATED).addComponent(txtEmail)
            .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(lblToken)
            .addPreferredGap(ComponentPlacement.RELATED).addComponent(txtToken)
            .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(lblWarning)
            .addPreferredGap(ComponentPlacement.UNRELATED).addComponent(listPane)
            .addPreferredGap(ComponentPlacement.UNRELATED)
            .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(btnDeleteToken)
                    .addComponent(btnChoose).addComponent(btnUpload).addComponent(btnRollback))
            .addContainerGap());

    frame.getContentPane().setLayout(groupLayout);

    frame.addWindowListener(this);
}