Search in sources :

Example 56 with JFileChooser

use of javax.swing.JFileChooser in project SEPA by arces-wot.

the class Dashboard method initialize.

/**
 * Initialize the contents of the frame.
 */
private void initialize() {
    namespacesDM = new DefaultTableModel(0, 0) {

        /**
         */
        private static final long serialVersionUID = 6788045463932990156L;

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    namespacesDM.setColumnIdentifiers(namespacesHeader);
    propertiesDM = new DefaultTableModel(0, 0) {

        /**
         */
        private static final long serialVersionUID = -5161490469556412655L;

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    propertiesDM.setColumnIdentifiers(propertiesHeader);
    frmSepaDashboard = new JFrame();
    frmSepaDashboard.setTitle(versionLabel);
    frmSepaDashboard.setBounds(100, 100, 925, 768);
    frmSepaDashboard.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 925, 0 };
    gridBagLayout.rowHeights = new int[] { 78, 651, 39, 0 };
    gridBagLayout.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };
    frmSepaDashboard.getContentPane().setLayout(gridBagLayout);
    JPanel configuration = new JPanel();
    GridBagConstraints gbc_configuration = new GridBagConstraints();
    gbc_configuration.insets = new Insets(0, 0, 5, 0);
    gbc_configuration.fill = GridBagConstraints.BOTH;
    gbc_configuration.gridx = 0;
    gbc_configuration.gridy = 0;
    frmSepaDashboard.getContentPane().add(configuration, gbc_configuration);
    configuration.setBorder(new TitledBorder(null, "Configuration", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    GridBagLayout gbl_configuration = new GridBagLayout();
    gbl_configuration.columnWidths = new int[] { 46, 45, 31, 20, 0, 24, 0, 0, 0, 0, 0, 0, 37, 0 };
    gbl_configuration.rowHeights = new int[] { 9, -25, 0 };
    gbl_configuration.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, Double.MIN_VALUE };
    gbl_configuration.rowWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
    configuration.setLayout(gbl_configuration);
    JLabel label1 = new JLabel("URL:");
    label1.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    GridBagConstraints gbc_label1 = new GridBagConstraints();
    gbc_label1.anchor = GridBagConstraints.EAST;
    gbc_label1.insets = new Insets(0, 0, 5, 5);
    gbc_label1.gridx = 0;
    gbc_label1.gridy = 0;
    configuration.add(label1, gbc_label1);
    JButton btnLoadXmlProfile = new JButton("Load SAP profile");
    btnLoadXmlProfile.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            // String path = appProperties.getProperty("path");
            final JFileChooser fc = new JFileChooser(appProperties.getProperty("appProfile"));
            // final JFileChooser fc = new
            // JFileChooser("/Users/luca/Documents/SEPAProject/WOTDemo/tools/");
            DashboardFileFilter filter = new DashboardFileFilter("JSON SAP Profile (.jsap)", ".jsap");
            fc.setFileFilter(filter);
            int returnVal = fc.showOpenDialog(frmSepaDashboard);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                String fileName = fc.getSelectedFile().getPath();
                if (loadSAP(fileName)) {
                    FileOutputStream out = null;
                    try {
                        out = new FileOutputStream("dashboard.properties");
                    } catch (FileNotFoundException e3) {
                        logger.error(e3.getMessage());
                        return;
                    }
                    appProperties = new Properties();
                    appProperties.put("appProfile", fileName);
                    try {
                        appProperties.store(out, "Dashboard properties");
                    } catch (IOException e1) {
                        logger.error(e1.getMessage());
                    }
                    try {
                        out.close();
                    } catch (IOException e2) {
                        logger.error(e2.getMessage());
                    }
                }
            }
        }
    });
    labelUrl = new JLabel("---");
    GridBagConstraints gbc_labelUrl = new GridBagConstraints();
    gbc_labelUrl.anchor = GridBagConstraints.WEST;
    gbc_labelUrl.insets = new Insets(0, 0, 5, 5);
    gbc_labelUrl.gridx = 1;
    gbc_labelUrl.gridy = 0;
    configuration.add(labelUrl, gbc_labelUrl);
    JLabel label2 = new JLabel("http:");
    label2.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    GridBagConstraints gbc_label2 = new GridBagConstraints();
    gbc_label2.insets = new Insets(0, 0, 5, 5);
    gbc_label2.gridx = 2;
    gbc_label2.gridy = 0;
    configuration.add(label2, gbc_label2);
    labelHttpPort = new JLabel("---");
    GridBagConstraints gbc_labelHttpPort = new GridBagConstraints();
    gbc_labelHttpPort.anchor = GridBagConstraints.WEST;
    gbc_labelHttpPort.insets = new Insets(0, 0, 5, 5);
    gbc_labelHttpPort.gridx = 3;
    gbc_labelHttpPort.gridy = 0;
    configuration.add(labelHttpPort, gbc_labelHttpPort);
    JLabel lblWs = new JLabel("ws:");
    lblWs.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    GridBagConstraints gbc_lblWs = new GridBagConstraints();
    gbc_lblWs.insets = new Insets(0, 0, 5, 5);
    gbc_lblWs.gridx = 4;
    gbc_lblWs.gridy = 0;
    configuration.add(lblWs, gbc_lblWs);
    labelWsPort = new JLabel("---");
    GridBagConstraints gbc_labelWsPort = new GridBagConstraints();
    gbc_labelWsPort.anchor = GridBagConstraints.WEST;
    gbc_labelWsPort.insets = new Insets(0, 0, 5, 5);
    gbc_labelWsPort.gridx = 5;
    gbc_labelWsPort.gridy = 0;
    configuration.add(labelWsPort, gbc_labelWsPort);
    JLabel lblUpdate = new JLabel("update:");
    lblUpdate.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    GridBagConstraints gbc_lblUpdate = new GridBagConstraints();
    gbc_lblUpdate.insets = new Insets(0, 0, 5, 5);
    gbc_lblUpdate.gridx = 6;
    gbc_lblUpdate.gridy = 0;
    configuration.add(lblUpdate, gbc_lblUpdate);
    labelUpdatePath = new JLabel("---");
    GridBagConstraints gbc_labelUpdatepath = new GridBagConstraints();
    gbc_labelUpdatepath.anchor = GridBagConstraints.WEST;
    gbc_labelUpdatepath.insets = new Insets(0, 0, 5, 5);
    gbc_labelUpdatepath.gridx = 7;
    gbc_labelUpdatepath.gridy = 0;
    configuration.add(labelUpdatePath, gbc_labelUpdatepath);
    JLabel lblQuery = new JLabel("query:");
    lblQuery.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    GridBagConstraints gbc_lblQuery = new GridBagConstraints();
    gbc_lblQuery.insets = new Insets(0, 0, 5, 5);
    gbc_lblQuery.gridx = 8;
    gbc_lblQuery.gridy = 0;
    configuration.add(lblQuery, gbc_lblQuery);
    labelQueryPath = new JLabel("---");
    GridBagConstraints gbc_labelQueryPath = new GridBagConstraints();
    gbc_labelQueryPath.anchor = GridBagConstraints.WEST;
    gbc_labelQueryPath.insets = new Insets(0, 0, 5, 5);
    gbc_labelQueryPath.gridx = 9;
    gbc_labelQueryPath.gridy = 0;
    configuration.add(labelQueryPath, gbc_labelQueryPath);
    JLabel lblSubscribe = new JLabel("subscribe:");
    lblSubscribe.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    GridBagConstraints gbc_lblSubscribe = new GridBagConstraints();
    gbc_lblSubscribe.insets = new Insets(0, 0, 5, 5);
    gbc_lblSubscribe.gridx = 10;
    gbc_lblSubscribe.gridy = 0;
    configuration.add(lblSubscribe, gbc_lblSubscribe);
    labelSubscribePath = new JLabel("---");
    GridBagConstraints gbc_labelSubscribePath = new GridBagConstraints();
    gbc_labelSubscribePath.anchor = GridBagConstraints.WEST;
    gbc_labelSubscribePath.insets = new Insets(0, 0, 5, 5);
    gbc_labelSubscribePath.gridx = 11;
    gbc_labelSubscribePath.gridy = 0;
    configuration.add(labelSubscribePath, gbc_labelSubscribePath);
    GridBagConstraints gbc_btnLoadXmlProfile = new GridBagConstraints();
    gbc_btnLoadXmlProfile.insets = new Insets(0, 0, 5, 0);
    gbc_btnLoadXmlProfile.anchor = GridBagConstraints.NORTHEAST;
    gbc_btnLoadXmlProfile.gridx = 12;
    gbc_btnLoadXmlProfile.gridy = 0;
    configuration.add(btnLoadXmlProfile, gbc_btnLoadXmlProfile);
    JLabel label3 = new JLabel("https:");
    label3.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    GridBagConstraints gbc_label3 = new GridBagConstraints();
    gbc_label3.insets = new Insets(0, 0, 0, 5);
    gbc_label3.gridx = 2;
    gbc_label3.gridy = 1;
    configuration.add(label3, gbc_label3);
    labelHttpsPort = new JLabel("---");
    GridBagConstraints gbc_labelHttpsPort = new GridBagConstraints();
    gbc_labelHttpsPort.anchor = GridBagConstraints.WEST;
    gbc_labelHttpsPort.insets = new Insets(0, 0, 0, 5);
    gbc_labelHttpsPort.gridx = 3;
    gbc_labelHttpsPort.gridy = 1;
    configuration.add(labelHttpsPort, gbc_labelHttpsPort);
    JLabel lblWss = new JLabel("wss:");
    lblWss.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    GridBagConstraints gbc_lblWss = new GridBagConstraints();
    gbc_lblWss.insets = new Insets(0, 0, 0, 5);
    gbc_lblWss.gridx = 4;
    gbc_lblWss.gridy = 1;
    configuration.add(lblWss, gbc_lblWss);
    labelWssPort = new JLabel("---");
    GridBagConstraints gbc_labelWssPort = new GridBagConstraints();
    gbc_labelWssPort.anchor = GridBagConstraints.WEST;
    gbc_labelWssPort.insets = new Insets(0, 0, 0, 5);
    gbc_labelWssPort.gridx = 5;
    gbc_labelWssPort.gridy = 1;
    configuration.add(labelWssPort, gbc_labelWssPort);
    JLabel lblNewLabel = new JLabel("secure:");
    lblNewLabel.setFont(new Font("Lucida Grande", Font.BOLD, 13));
    GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
    gbc_lblNewLabel.insets = new Insets(0, 0, 0, 5);
    gbc_lblNewLabel.gridx = 6;
    gbc_lblNewLabel.gridy = 1;
    configuration.add(lblNewLabel, gbc_lblNewLabel);
    labelSecurePath = new JLabel("---");
    GridBagConstraints gbc_labelSecurePath = new GridBagConstraints();
    gbc_labelSecurePath.anchor = GridBagConstraints.WEST;
    gbc_labelSecurePath.insets = new Insets(0, 0, 0, 5);
    gbc_labelSecurePath.gridx = 7;
    gbc_labelSecurePath.gridy = 1;
    configuration.add(labelSecurePath, gbc_labelSecurePath);
    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    GridBagConstraints gbc_tabbedPane = new GridBagConstraints();
    gbc_tabbedPane.insets = new Insets(0, 0, 5, 0);
    gbc_tabbedPane.fill = GridBagConstraints.BOTH;
    gbc_tabbedPane.gridx = 0;
    gbc_tabbedPane.gridy = 1;
    frmSepaDashboard.getContentPane().add(tabbedPane, gbc_tabbedPane);
    JPanel primitives = new JPanel();
    tabbedPane.addTab("Primitives", null, primitives, null);
    primitives.setBorder(new TitledBorder(null, "Primitives", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    GridBagLayout gbl_primitives = new GridBagLayout();
    gbl_primitives.columnWidths = new int[] { 684, 0, 0 };
    gbl_primitives.rowHeights = new int[] { 114, 115, 0, 0, 0 };
    gbl_primitives.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE };
    gbl_primitives.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE };
    primitives.setLayout(gbl_primitives);
    JSplitPane splitPanel_Update = new JSplitPane();
    splitPanel_Update.setResizeWeight(0.5);
    GridBagConstraints gbc_splitPanel_Update = new GridBagConstraints();
    gbc_splitPanel_Update.insets = new Insets(0, 0, 5, 5);
    gbc_splitPanel_Update.fill = GridBagConstraints.BOTH;
    gbc_splitPanel_Update.gridx = 0;
    gbc_splitPanel_Update.gridy = 0;
    primitives.add(splitPanel_Update, gbc_splitPanel_Update);
    JPanel panel_4 = new JPanel();
    splitPanel_Update.setLeftComponent(panel_4);
    GridBagLayout gbl_panel_4 = new GridBagLayout();
    gbl_panel_4.columnWidths = new int[] { 66, 0 };
    gbl_panel_4.rowHeights = new int[] { 17, 75, 0 };
    gbl_panel_4.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl_panel_4.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    panel_4.setLayout(gbl_panel_4);
    JLabel lblUpdates = new JLabel("UPDATEs");
    GridBagConstraints gbc_lblUpdates = new GridBagConstraints();
    gbc_lblUpdates.anchor = GridBagConstraints.NORTH;
    gbc_lblUpdates.insets = new Insets(0, 0, 5, 0);
    gbc_lblUpdates.gridx = 0;
    gbc_lblUpdates.gridy = 0;
    panel_4.add(lblUpdates, gbc_lblUpdates);
    lblUpdates.setFont(new Font("Lucida Grande", Font.BOLD, 14));
    JScrollPane scrollPane = new JScrollPane();
    GridBagConstraints gbc_scrollPane = new GridBagConstraints();
    gbc_scrollPane.fill = GridBagConstraints.BOTH;
    gbc_scrollPane.gridx = 0;
    gbc_scrollPane.gridy = 1;
    panel_4.add(scrollPane, gbc_scrollPane);
    updatesList = new JList<String>(updateListDM);
    scrollPane.setViewportView(updatesList);
    updatesList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                if (updatesList.getSelectedIndex() != -1) {
                    String sparql = appProfile.update(updatesList.getSelectedValue());
                    sparql = sparql.replaceFirst("\n", "");
                    sparql = sparql.replaceAll("\t", "");
                    sparql = sparql.trim();
                    SPARQLUpdate.setText(sparql);
                    Bindings bindings = appProfile.updateBindings(updatesList.getSelectedValue());
                    updateForcedBindingsDM.clearBindings();
                    if (bindings == null)
                        return;
                    for (String var : bindings.getVariables()) {
                        updateForcedBindingsDM.addBindings(var, bindings.isLiteral(var));
                    }
                }
            }
        }
    });
    updatesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JPanel panel_5 = new JPanel();
    splitPanel_Update.setRightComponent(panel_5);
    GridBagLayout gbl_panel_5 = new GridBagLayout();
    gbl_panel_5.columnWidths = new int[] { 101, 0 };
    gbl_panel_5.rowHeights = new int[] { 16, 0, 0 };
    gbl_panel_5.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl_panel_5.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    panel_5.setLayout(gbl_panel_5);
    JLabel lblForcedBindings = new JLabel("Forced bindings");
    GridBagConstraints gbc_lblForcedBindings = new GridBagConstraints();
    gbc_lblForcedBindings.anchor = GridBagConstraints.NORTH;
    gbc_lblForcedBindings.insets = new Insets(0, 0, 5, 0);
    gbc_lblForcedBindings.gridx = 0;
    gbc_lblForcedBindings.gridy = 0;
    panel_5.add(lblForcedBindings, gbc_lblForcedBindings);
    JScrollPane scrollPane_2 = new JScrollPane();
    GridBagConstraints gbc_scrollPane_2 = new GridBagConstraints();
    gbc_scrollPane_2.fill = GridBagConstraints.BOTH;
    gbc_scrollPane_2.gridx = 0;
    gbc_scrollPane_2.gridy = 1;
    panel_5.add(scrollPane_2, gbc_scrollPane_2);
    updateForcedBindings = new JTable(updateForcedBindingsDM);
    scrollPane_2.setViewportView(updateForcedBindings);
    JSplitPane splitPanel_Subscribe = new JSplitPane();
    GridBagConstraints gbc_splitPanel_Subscribe = new GridBagConstraints();
    gbc_splitPanel_Subscribe.insets = new Insets(0, 0, 5, 0);
    gbc_splitPanel_Subscribe.fill = GridBagConstraints.BOTH;
    gbc_splitPanel_Subscribe.gridx = 1;
    gbc_splitPanel_Subscribe.gridy = 0;
    primitives.add(splitPanel_Subscribe, gbc_splitPanel_Subscribe);
    JPanel panel_6 = new JPanel();
    splitPanel_Subscribe.setLeftComponent(panel_6);
    GridBagLayout gbl_panel_6 = new GridBagLayout();
    gbl_panel_6.columnWidths = new int[] { 193, 0 };
    gbl_panel_6.rowHeights = new int[] { 17, 72, 0 };
    gbl_panel_6.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl_panel_6.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    panel_6.setLayout(gbl_panel_6);
    JLabel lblSubscribes = new JLabel("SUBSCRIBEs");
    GridBagConstraints gbc_lblSubscribes = new GridBagConstraints();
    gbc_lblSubscribes.anchor = GridBagConstraints.NORTH;
    gbc_lblSubscribes.insets = new Insets(0, 0, 5, 0);
    gbc_lblSubscribes.gridx = 0;
    gbc_lblSubscribes.gridy = 0;
    panel_6.add(lblSubscribes, gbc_lblSubscribes);
    lblSubscribes.setFont(new Font("Lucida Grande", Font.BOLD, 14));
    JScrollPane scrollPane_3 = new JScrollPane();
    GridBagConstraints gbc_scrollPane_3 = new GridBagConstraints();
    gbc_scrollPane_3.fill = GridBagConstraints.BOTH;
    gbc_scrollPane_3.gridx = 0;
    gbc_scrollPane_3.gridy = 1;
    panel_6.add(scrollPane_3, gbc_scrollPane_3);
    subscribesList = new JList<String>(subscribeListDM);
    subscribesList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting() == false) {
                if (subscribesList.getSelectedIndex() != -1) {
                    String sparql = appProfile.subscribe(subscribesList.getSelectedValue());
                    sparql = sparql.replaceFirst("\n", "");
                    sparql = sparql.replaceAll("\t", "");
                    sparql = sparql.trim();
                    SPARQLSubscribe.setText(sparql);
                }
                Bindings bindings = appProfile.subscribeBindings(subscribesList.getSelectedValue());
                subscribeForcedBindingsDM.clearBindings();
                if (bindings == null)
                    return;
                for (String var : bindings.getVariables()) {
                    subscribeForcedBindingsDM.addBindings(var, bindings.isLiteral(var));
                }
            }
        }
    });
    scrollPane_3.setViewportView(subscribesList);
    subscribesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JPanel panel_7 = new JPanel();
    splitPanel_Subscribe.setRightComponent(panel_7);
    GridBagLayout gbl_panel_7 = new GridBagLayout();
    gbl_panel_7.columnWidths = new int[] { 454, 0 };
    gbl_panel_7.rowHeights = new int[] { 16, 126, 0 };
    gbl_panel_7.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl_panel_7.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
    panel_7.setLayout(gbl_panel_7);
    JLabel lblForcedBindings_1 = new JLabel("Forced bindings");
    GridBagConstraints gbc_lblForcedBindings_1 = new GridBagConstraints();
    gbc_lblForcedBindings_1.anchor = GridBagConstraints.NORTH;
    gbc_lblForcedBindings_1.insets = new Insets(0, 0, 5, 0);
    gbc_lblForcedBindings_1.gridx = 0;
    gbc_lblForcedBindings_1.gridy = 0;
    panel_7.add(lblForcedBindings_1, gbc_lblForcedBindings_1);
    JScrollPane scrollPane_1 = new JScrollPane();
    GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints();
    gbc_scrollPane_1.fill = GridBagConstraints.BOTH;
    gbc_scrollPane_1.gridx = 0;
    gbc_scrollPane_1.gridy = 1;
    panel_7.add(scrollPane_1, gbc_scrollPane_1);
    subscribeForcedBindings = new JTable(subscribeForcedBindingsDM);
    scrollPane_1.setViewportView(subscribeForcedBindings);
    JScrollPane scrollPane_Update = new JScrollPane();
    GridBagConstraints gbc_scrollPane_Update = new GridBagConstraints();
    gbc_scrollPane_Update.fill = GridBagConstraints.BOTH;
    gbc_scrollPane_Update.insets = new Insets(0, 0, 5, 5);
    gbc_scrollPane_Update.gridx = 0;
    gbc_scrollPane_Update.gridy = 1;
    primitives.add(scrollPane_Update, gbc_scrollPane_Update);
    SPARQLUpdate = new JTextArea();
    scrollPane_Update.setViewportView(SPARQLUpdate);
    SPARQLUpdate.setLineWrap(true);
    btnUpdate = new JButton("UPDATE");
    btnUpdate.setEnabled(false);
    btnUpdate.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Bindings forced = new Bindings();
            for (int index = 0; index < updateForcedBindingsDM.getRowCount(); index++) {
                String value = (String) updateForcedBindingsDM.getValueAt(index, 1);
                String var = (String) updateForcedBindingsDM.getValueAt(index, 0);
                boolean literal = (boolean) updateForcedBindingsDM.getValueAt(index, 2);
                if (value.equals("")) {
                    lblInfo.setText("Please specify binding value: " + var);
                    lblInfo.setToolTipText("Please specify binding value: " + var);
                    return;
                }
                if (literal)
                    forced.addBinding(var, new RDFTermLiteral(value));
                else
                    forced.addBinding(var, new RDFTermURI(value));
            }
            String update = SPARQLUpdate.getText().replaceAll("[\n\t]", "");
            long start = System.currentTimeMillis();
            Response result = sepaClient.update(update, forced);
            long stop = System.currentTimeMillis();
            String status = "DONE";
            if (result.isError()) {
                status = "FAILED " + ((ErrorResponse) result).getErrorMessage();
            }
            lblInfo.setText("UPDATE (" + (stop - start) + " ms): " + status);
            lblInfo.setToolTipText("UPDATE (" + (stop - start) + " ms): " + status);
        }
    });
    JScrollPane scrollPane_Subscribe = new JScrollPane();
    GridBagConstraints gbc_scrollPane_Subscribe = new GridBagConstraints();
    gbc_scrollPane_Subscribe.fill = GridBagConstraints.BOTH;
    gbc_scrollPane_Subscribe.insets = new Insets(0, 0, 5, 0);
    gbc_scrollPane_Subscribe.gridx = 1;
    gbc_scrollPane_Subscribe.gridy = 1;
    primitives.add(scrollPane_Subscribe, gbc_scrollPane_Subscribe);
    SPARQLSubscribe = new JTextArea();
    scrollPane_Subscribe.setViewportView(SPARQLSubscribe);
    SPARQLSubscribe.setLineWrap(true);
    GridBagConstraints gbc_btnUpdate = new GridBagConstraints();
    gbc_btnUpdate.insets = new Insets(0, 0, 5, 5);
    gbc_btnUpdate.gridx = 0;
    gbc_btnUpdate.gridy = 2;
    primitives.add(btnUpdate, gbc_btnUpdate);
    JPanel panel = new JPanel();
    GridBagConstraints gbc_panel = new GridBagConstraints();
    gbc_panel.insets = new Insets(0, 0, 5, 0);
    gbc_panel.fill = GridBagConstraints.BOTH;
    gbc_panel.gridx = 1;
    gbc_panel.gridy = 2;
    primitives.add(panel, gbc_panel);
    GridBagLayout gbl_panel = new GridBagLayout();
    gbl_panel.columnWidths = new int[] { 0, 0, 0 };
    gbl_panel.rowHeights = new int[] { 0, 0 };
    gbl_panel.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE };
    gbl_panel.rowWeights = new double[] { 1.0, Double.MIN_VALUE };
    panel.setLayout(gbl_panel);
    btnQuery = new JButton("QUERY");
    btnQuery.setEnabled(false);
    btnQuery.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            Bindings forced = new Bindings();
            for (int index = 0; index < subscribeForcedBindings.getRowCount(); index++) {
                String value = (String) subscribeForcedBindings.getValueAt(index, 1);
                boolean literal = (boolean) subscribeForcedBindings.getValueAt(index, 2);
                String var = (String) subscribeForcedBindings.getValueAt(index, 0);
                if (value.equals("")) {
                    lblInfo.setText("Please specify binding value: " + var);
                    lblInfo.setToolTipText("Please specify binding value: " + var);
                    return;
                }
                if (literal)
                    forced.addBinding(var, new RDFTermLiteral(value));
                else
                    forced.addBinding(var, new RDFTermURI(value));
            }
            String query = SPARQLSubscribe.getText().replaceAll("[\n\t]", "");
            lblInfo.setText("Running query...");
            long start = System.currentTimeMillis();
            response = sepaClient.query(query, forced);
            long stop = System.currentTimeMillis();
            String status = "DONE";
            if (response.isError()) {
                status = "FAILED " + ((ErrorResponse) response).getErrorMessage();
            } else {
                bindingsDM.clear();
                BindingsResults ret = ((QueryResponse) response).getBindingsResults();
                bindingsDM.setAddedResults(ret, null);
                status = " " + ret.size() + " bindings results";
            }
            lblInfo.setText("QUERY (" + (stop - start) + " ms) :" + status);
            lblInfo.setToolTipText("QUERY (" + (stop - start) + " ms) :" + status);
        }
    });
    GridBagConstraints gbc_btnQuery = new GridBagConstraints();
    gbc_btnQuery.insets = new Insets(0, 0, 0, 5);
    gbc_btnQuery.gridx = 0;
    gbc_btnQuery.gridy = 0;
    panel.add(btnQuery, gbc_btnQuery);
    btnSubscribe = new JButton("SUBSCRIBE");
    btnSubscribe.setEnabled(false);
    btnSubscribe.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (btnSubscribe.getText().equals("SUBSCRIBE")) {
                Bindings forced = new Bindings();
                for (int index = 0; index < subscribeForcedBindings.getRowCount(); index++) {
                    String value = (String) subscribeForcedBindings.getValueAt(index, 1);
                    boolean literal = (boolean) subscribeForcedBindings.getValueAt(index, 2);
                    String var = (String) subscribeForcedBindings.getValueAt(index, 0);
                    if (value.equals("")) {
                        lblInfo.setText("Please specify binding value: " + var);
                        lblInfo.setToolTipText("Please specify binding value: " + var);
                        return;
                    }
                    ;
                    if (literal)
                        forced.addBinding(var, new RDFTermLiteral(value));
                    else
                        forced.addBinding(var, new RDFTermURI(value));
                }
                String query = SPARQLSubscribe.getText().replaceAll("[\n\t]", "");
                response = sepaClient.subscribe(query, forced);
                if (response.getClass().equals(ErrorResponse.class)) {
                    lblInfo.setText(response.toString());
                    lblInfo.setToolTipText(response.toString());
                    return;
                }
                // SPUID and results
                String spuid = ((SubscribeResponse) response).getSpuid();
                BindingsResults ret = ((SubscribeResponse) response).getBindingsResults();
                // Subscription panel
                JPanel sub = new JPanel();
                // Results label
                JLabel infoLabel = new JLabel();
                infoLabel.setText("Subscribed. First results: " + ret.size());
                subscriptionResultsLabels.put(spuid, infoLabel);
                // Results table
                subscriptionResultsDM.put(spuid, new BindingsTableModel());
                JTable bindingsResultsTable = new JTable(subscriptionResultsDM.get(spuid));
                bindingsResultsTable.setDefaultRenderer(Object.class, bindingsRender);
                bindingsResultsTable.setAutoCreateRowSorter(true);
                bindingsResultsTable.registerKeyboardAction(new CopyAction(), KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), JComponent.WHEN_FOCUSED);
                bindingsResultsTable.setCellSelectionEnabled(true);
                subscriptionResultsTables.put(spuid, bindingsResultsTable);
                subscriptionResultsDM.get(spuid).setAddedResults(ret, spuid);
                JScrollPane bindingsResults = new JScrollPane();
                bindingsResults.setViewportView(bindingsResultsTable);
                // Unsubscribe button
                JButton unsubscribeButton = new JButton(spuid);
                unsubscribeButton.setEnabled(true);
                unsubscribeButton.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent e) {
                        response = sepaClient.unsubscribe(spuid);
                        // if (response.isUnsubscribeResponse()) {
                        subscriptions.remove(sub);
                        subscriptionResultsDM.remove(spuid);
                        subscriptionResultsLabels.remove(spuid);
                        subscriptionResultsTables.remove(spuid);
                    // }
                    }
                });
                // Query label
                JLabel queryLabel = new JLabel("<html>" + query + " forced bindings: " + forced.toString() + "</html>");
                queryLabel.setFont(new Font("Arial", Font.BOLD, 14));
                // Layout
                GridBagConstraints layoutFill = new GridBagConstraints();
                layoutFill.fill = GridBagConstraints.BOTH;
                sub.setLayout(new BoxLayout(sub, BoxLayout.Y_AXIS));
                sub.setName(subscribesList.getSelectedValue());
                // Add components
                sub.add(queryLabel);
                sub.add(unsubscribeButton);
                sub.add(bindingsResults);
                sub.add(infoLabel);
                subscriptions.add(sub, layoutFill);
            }
        }
    });
    GridBagConstraints gbc_btnSubscribe = new GridBagConstraints();
    gbc_btnSubscribe.gridx = 1;
    gbc_btnSubscribe.gridy = 0;
    panel.add(btnSubscribe, gbc_btnSubscribe);
    JScrollPane bindingsResults = new JScrollPane();
    GridBagConstraints gbc_bindingsResults = new GridBagConstraints();
    gbc_bindingsResults.fill = GridBagConstraints.BOTH;
    gbc_bindingsResults.gridwidth = 2;
    gbc_bindingsResults.gridx = 0;
    gbc_bindingsResults.gridy = 3;
    primitives.add(bindingsResults, gbc_bindingsResults);
    bindingsResultsTable = new JTable(bindingsDM);
    bindingsResults.setViewportView(bindingsResultsTable);
    bindingsResultsTable.setDefaultRenderer(Object.class, bindingsRender);
    bindingsResultsTable.setAutoCreateRowSorter(true);
    bindingsResultsTable.registerKeyboardAction(new CopyAction(), KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), JComponent.WHEN_FOCUSED);
    bindingsResultsTable.setCellSelectionEnabled(true);
    subscriptions = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.addTab("Subscriptions", null, subscriptions, null);
    JPanel namespaces = new JPanel();
    tabbedPane.addTab("Namespaces", null, namespaces, null);
    namespaces.setBorder(new TitledBorder(null, "Namespaces", TitledBorder.LEADING, TitledBorder.TOP, null, null));
    GridBagLayout gbl_namespaces = new GridBagLayout();
    gbl_namespaces.columnWidths = new int[] { 0, 0, 0 };
    gbl_namespaces.rowHeights = new int[] { 43, 0 };
    gbl_namespaces.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE };
    gbl_namespaces.rowWeights = new double[] { 1.0, Double.MIN_VALUE };
    namespaces.setLayout(gbl_namespaces);
    JScrollPane scrollPane_4 = new JScrollPane();
    GridBagConstraints gbc_scrollPane_4 = new GridBagConstraints();
    gbc_scrollPane_4.gridwidth = 2;
    gbc_scrollPane_4.insets = new Insets(0, 0, 0, 5);
    gbc_scrollPane_4.fill = GridBagConstraints.BOTH;
    gbc_scrollPane_4.gridx = 0;
    gbc_scrollPane_4.gridy = 0;
    namespaces.add(scrollPane_4, gbc_scrollPane_4);
    namespacesTable = new JTable(namespacesDM);
    scrollPane_4.setViewportView(namespacesTable);
    JPanel infoPanel = new JPanel();
    GridBagConstraints gbc_infoPanel = new GridBagConstraints();
    gbc_infoPanel.anchor = GridBagConstraints.SOUTH;
    gbc_infoPanel.fill = GridBagConstraints.HORIZONTAL;
    gbc_infoPanel.gridx = 0;
    gbc_infoPanel.gridy = 2;
    frmSepaDashboard.getContentPane().add(infoPanel, gbc_infoPanel);
    GridBagLayout gbl_infoPanel = new GridBagLayout();
    gbl_infoPanel.columnWidths = new int[] { 73, 0, 0, 97, 76, 0 };
    gbl_infoPanel.rowHeights = new int[] { 29, 0 };
    gbl_infoPanel.columnWeights = new double[] { 1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
    gbl_infoPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
    infoPanel.setLayout(gbl_infoPanel);
    lblInfo = new JLabel("Info");
    GridBagConstraints gbc_lblInfo = new GridBagConstraints();
    gbc_lblInfo.anchor = GridBagConstraints.WEST;
    gbc_lblInfo.insets = new Insets(0, 10, 0, 5);
    gbc_lblInfo.gridx = 0;
    gbc_lblInfo.gridy = 0;
    infoPanel.add(lblInfo, gbc_lblInfo);
    ToolTipManager.sharedInstance().setDismissDelay(Integer.MAX_VALUE);
    chckbxClearonnotify = new JCheckBox("ClearOnNotify");
    chckbxClearonnotify.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
        }
    });
    GridBagConstraints gbc_chckbxClearonnotify = new GridBagConstraints();
    gbc_chckbxClearonnotify.insets = new Insets(0, 0, 0, 5);
    gbc_chckbxClearonnotify.gridx = 1;
    gbc_chckbxClearonnotify.gridy = 0;
    infoPanel.add(chckbxClearonnotify, gbc_chckbxClearonnotify);
    JCheckBox chckbxQname = new JCheckBox("Qname");
    chckbxQname.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            bindingsRender.showAsQName(chckbxQname.isSelected());
            bindingsDM.fireTableDataChanged();
            for (BindingsTableModel table : subscriptionResultsDM.values()) {
                table.fireTableDataChanged();
            }
        }
    });
    chckbxQname.setSelected(true);
    GridBagConstraints gbc_chckbxQname = new GridBagConstraints();
    gbc_chckbxQname.insets = new Insets(0, 0, 0, 5);
    gbc_chckbxQname.gridx = 2;
    gbc_chckbxQname.gridy = 0;
    infoPanel.add(chckbxQname, gbc_chckbxQname);
    chckbxAutoscroll = new JCheckBox("Autoscroll");
    GridBagConstraints gbc_chckbxAutoscroll = new GridBagConstraints();
    gbc_chckbxAutoscroll.anchor = GridBagConstraints.WEST;
    gbc_chckbxAutoscroll.insets = new Insets(0, 0, 0, 5);
    gbc_chckbxAutoscroll.gridx = 3;
    gbc_chckbxAutoscroll.gridy = 0;
    infoPanel.add(chckbxAutoscroll, gbc_chckbxAutoscroll);
    chckbxAutoscroll.setSelected(true);
    JButton btnClean = new JButton("Clear");
    GridBagConstraints gbc_btnClean = new GridBagConstraints();
    gbc_btnClean.anchor = GridBagConstraints.NORTHWEST;
    gbc_btnClean.gridx = 4;
    gbc_btnClean.gridy = 0;
    infoPanel.add(btnClean, gbc_btnClean);
    btnClean.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (primitives.isShowing()) {
                bindingsDM.clear();
                lblInfo.setText("Results cleaned");
                lblInfo.setToolTipText("Results cleaned");
            } else {
                for (String spuid : subscriptionResultsTables.keySet()) {
                    if (subscriptionResultsTables.get(spuid).isShowing()) {
                        subscriptionResultsDM.get(spuid).clear();
                        subscriptionResultsLabels.get(spuid).setText("Results cleaned");
                    }
                }
            }
        }
    });
    bindingsRender.setNamespaces(namespacesDM);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) BindingsResults(it.unibo.arces.wot.sepa.commons.sparql.BindingsResults) ARBindingsResults(it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults) Insets(java.awt.Insets) JTextArea(javax.swing.JTextArea) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) JTabbedPane(javax.swing.JTabbedPane) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) FileNotFoundException(java.io.FileNotFoundException) ListSelectionEvent(javax.swing.event.ListSelectionEvent) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) TitledBorder(javax.swing.border.TitledBorder) Properties(java.util.Properties) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral) Font(java.awt.Font) JFrame(javax.swing.JFrame) ChangeListener(javax.swing.event.ChangeListener) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) IOException(java.io.IOException) ListSelectionListener(javax.swing.event.ListSelectionListener) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) Response(it.unibo.arces.wot.sepa.commons.response.Response) SubscribeResponse(it.unibo.arces.wot.sepa.commons.response.SubscribeResponse) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ChangeEvent(javax.swing.event.ChangeEvent) FileOutputStream(java.io.FileOutputStream) JTable(javax.swing.JTable) JSplitPane(javax.swing.JSplitPane)

Example 57 with JFileChooser

use of javax.swing.JFileChooser in project felix by apache.

the class RemoteLogger_jtable method actionPerformed.

public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();
    if (o == jb_save) {
        PrintStream ps = System.out;
        JFileChooser jfc = new JFileChooser();
        if (jfc.showSaveDialog(null) == JFileChooser.APPROVE_OPTION & jfc.getSelectedFile() != null) {
            try {
                ps = new PrintStream(new java.io.FileOutputStream(jfc.getSelectedFile()));
                System.out.println("Save remote log into \"" + jfc.getSelectedFile().getName() + "\"");
            } catch (FileNotFoundException fnfe) {
                System.out.println("err : " + fnfe);
            }
        }
        int col = this.logList.getColumnCount();
        // last line always empty
        int line = this.logList.getRowCount() - 1;
        // ps.print(col+" "+line);
        Vector tableData = new Vector();
        tableData = this.getDataVector();
        for (int i = 0; i < line; i++) {
            ps.print(i + " : ");
            for (int j = 0; j < col; j++) {
                ps.print((String) (((Vector) (tableData.elementAt(i))).elementAt(j)) + " | ");
            }
            ps.print("\n");
        }
    }
}
Also used : PrintStream(java.io.PrintStream) JFileChooser(javax.swing.JFileChooser) FileNotFoundException(java.io.FileNotFoundException) Vector(java.util.Vector)

Example 58 with JFileChooser

use of javax.swing.JFileChooser in project hale by halestudio.

the class FileTiler method loadCommandPaths.

/**
 * Load the command paths from the preferences or ask the user for them
 */
private void loadCommandPaths() {
    String convert = pref.get(PREF_CONVERT, null);
    String identify = pref.get(PREF_IDENTIFY, null);
    JFileChooser commandChooser = new JFileChooser();
    if (convert != null && identify != null) {
        if (JOptionPane.showConfirmDialog(null, "<html>Found paths to executables:<br/><b>" + convert + "<br/>" + identify + "</b><br/>Do you want to use this settings?</html>", "Paths to executables", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
            convert = null;
            identify = null;
        }
    }
    if (convert == null) {
        // ask for convert path
        convert = askForPath(commandChooser, new ContainsFileFilter("convert"), "Please select your convert executable");
    }
    if (convert != null && identify == null) {
        // ask for identify path
        identify = askForPath(commandChooser, new ContainsFileFilter("identify"), "Please select your identify executable");
    }
    if (convert == null)
        pref.remove(PREF_CONVERT);
    else
        pref.put(PREF_CONVERT, convert);
    if (identify == null)
        pref.remove(PREF_IDENTIFY);
    else
        pref.put(PREF_IDENTIFY, identify);
    convertPath = convert;
    identifyPath = identify;
}
Also used : JFileChooser(javax.swing.JFileChooser)

Example 59 with JFileChooser

use of javax.swing.JFileChooser in project hale by halestudio.

the class FileTiler method run.

/**
 * Ask the user for an image file for that a tiled map shall be created
 */
public void run() {
    JFileChooser fileChooser = new JFileChooser();
    // load current dir
    fileChooser.setCurrentDirectory(new File(pref.get(PREF_DIR, fileChooser.getCurrentDirectory().getAbsolutePath())));
    // open
    int returnVal = fileChooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        // save current dir
        pref.put(PREF_DIR, fileChooser.getCurrentDirectory().getAbsolutePath());
        // get file
        File imageFile = fileChooser.getSelectedFile();
        // get image dimension
        Dimension size = getSize(imageFile);
        log.info("Image size: " + size);
        // ask for min tile size
        int minTileSize = 0;
        while (minTileSize <= 0) {
            try {
                minTileSize = Integer.parseInt(JOptionPane.showInputDialog("Minimal tile size", String.valueOf(DEF_MIN_TILE_SIZE)));
            } catch (Exception e) {
                minTileSize = 0;
            }
        }
        // determine min map width
        int width = size.width;
        while (width / 2 > minTileSize && width % 2 == 0) {
            width = width / 2;
        }
        // min map width
        int minMapWidth = width;
        log.info("Minimal map width: " + minMapWidth);
        // determine min map height
        int height = size.height;
        while (height / 2 > minTileSize && height % 2 == 0) {
            // min map height
            height = height / 2;
        }
        int minMapHeight = height;
        log.info("Minimal map height: " + minMapHeight);
        // ask for min map size
        int minMapSize = 0;
        while (minMapSize <= 0) {
            try {
                minMapSize = Integer.parseInt(JOptionPane.showInputDialog("Minimal map size", String.valueOf(DEF_MIN_MAP_SIZE)));
            } catch (Exception e) {
                minMapSize = 0;
            }
        }
        // determine zoom levels
        int zoomLevels = 1;
        width = size.width;
        height = size.height;
        while (width % 2 == 0 && height % 2 == 0 && width / 2 >= Math.max(minMapWidth, minMapSize) && height / 2 >= Math.max(minMapHeight, minMapSize)) {
            zoomLevels++;
            width = width / 2;
            height = height / 2;
        }
        log.info("Number of zoom levels: " + zoomLevels);
        // determine tile width
        width = minMapWidth;
        int tileWidth = minMapWidth;
        for (int i = 3; i < Math.sqrt(minMapWidth) && width > minTileSize; ) {
            tileWidth = width;
            if (width % i == 0) {
                width = width / i;
            } else
                i++;
        }
        // determine tile height
        height = minMapHeight;
        int tileHeight = minMapHeight;
        for (int i = 3; i < Math.sqrt(minMapHeight) && height > minTileSize; ) {
            tileHeight = height;
            if (height % i == 0) {
                height = height / i;
            } else
                i++;
        }
        // create tiles for each zoom level
        if (JOptionPane.showConfirmDialog(null, "Create tiles (" + tileWidth + "x" + tileHeight + ") for " + zoomLevels + " zoom levels?", "Create tiles", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
            int currentWidth = size.width;
            int currentHeight = size.height;
            File currentImage = imageFile;
            Properties properties = new Properties();
            properties.setProperty(PROP_TILE_WIDTH, String.valueOf(tileWidth));
            properties.setProperty(PROP_TILE_HEIGHT, String.valueOf(tileHeight));
            properties.setProperty(PROP_ZOOM_LEVELS, String.valueOf(zoomLevels));
            List<File> files = new ArrayList<File>();
            for (int i = 0; i < zoomLevels; i++) {
                int mapWidth = currentWidth / tileWidth;
                int mapHeight = currentHeight / tileHeight;
                log.info("Creating tiles for zoom level " + i);
                log.info("Map width: " + currentWidth + " pixels, " + mapWidth + " tiles");
                log.info("Map height: " + currentHeight + " pixels, " + mapHeight + " tiles");
                // create tiles
                tile(currentImage, TILE_FILE_PREFIX + i + TILE_FILE_SEPARATOR + "%d", TILE_FILE_EXTENSION, tileWidth, tileHeight);
                // add files to list
                for (int num = 0; num < mapWidth * mapHeight; num++) {
                    files.add(new File(imageFile.getParentFile().getAbsolutePath() + File.separator + TILE_FILE_PREFIX + i + TILE_FILE_SEPARATOR + num + TILE_FILE_EXTENSION));
                }
                // store map width and height at current zoom
                properties.setProperty(PROP_MAP_WIDTH + i, String.valueOf(mapWidth));
                properties.setProperty(PROP_MAP_HEIGHT + i, String.valueOf(mapHeight));
                // create image for next zoom level
                currentWidth /= 2;
                currentHeight /= 2;
                // create temp image file name
                File nextImage = suffixFile(imageFile, i + 1);
                // resize image
                convert(currentImage, nextImage, currentWidth, currentHeight, 100);
                // delete previous temp file
                if (!currentImage.equals(imageFile)) {
                    if (!currentImage.delete()) {
                        log.warn("Error deleting " + imageFile.getAbsolutePath());
                    }
                }
                currentImage = nextImage;
            }
            // delete previous temp file
            if (!currentImage.equals(imageFile)) {
                if (!currentImage.delete()) {
                    log.warn("Error deleting " + imageFile.getAbsolutePath());
                }
            }
            // write properties file
            File propertiesFile = new File(imageFile.getParentFile().getAbsolutePath() + File.separator + MAP_PROPERTIES_FILE);
            try {
                FileWriter propertiesWriter = new FileWriter(propertiesFile);
                try {
                    properties.store(propertiesWriter, "Map generated from " + imageFile.getName());
                    // add properties file to list
                    files.add(propertiesFile);
                } finally {
                    propertiesWriter.close();
                }
            } catch (IOException e) {
                log.error("Error writing map properties file", e);
            }
            // add a converter properties file
            String convProperties = askForPath(fileChooser, new ExactFileFilter(CONVERTER_PROPERTIES_FILE), "Select a converter properties file");
            File convFile = null;
            if (convProperties != null) {
                convFile = new File(convProperties);
                files.add(convFile);
            }
            // create jar file
            log.info("Creating jar archive...");
            if (createJarArchive(replaceExtension(imageFile, MAP_ARCHIVE_EXTENSION), files)) {
                log.info("Archive successfully created, deleting tiles...");
                // don't delete converter properties
                if (convFile != null)
                    files.remove(files.size() - 1);
                // delete files
                for (File file : files) {
                    if (!file.delete()) {
                        log.warn("Error deleting " + file.getAbsolutePath());
                    }
                }
            }
            log.info("Fin.");
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) Dimension(java.awt.Dimension) IOException(java.io.IOException) Properties(java.util.Properties) File(java.io.File) IOException(java.io.IOException)

Example 60 with JFileChooser

use of javax.swing.JFileChooser in project omegat by omegat-org.

the class SpellcheckerConfigurationController method chooseDirectory.

private void chooseDirectory() {
    // open a dialog box to choose the directory
    JFileChooser fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    fileChooser.setDialogTitle(OStrings.getString("GUI_SPELLCHECKER_FILE_CHOOSER_TITLE"));
    if (fileChooser.showOpenDialog(panel) == JFileChooser.APPROVE_OPTION) {
        // we should write the result into the directory text field
        File file = fileChooser.getSelectedFile();
        panel.directoryTextField.setText(file.getAbsolutePath());
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File)

Aggregations

JFileChooser (javax.swing.JFileChooser)797 File (java.io.File)571 IOException (java.io.IOException)185 FileFilter (javax.swing.filechooser.FileFilter)109 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)96 ActionEvent (java.awt.event.ActionEvent)59 ActionListener (java.awt.event.ActionListener)48 JButton (javax.swing.JButton)44 JPanel (javax.swing.JPanel)40 Component (java.awt.Component)39 FileOutputStream (java.io.FileOutputStream)39 FileNotFoundException (java.io.FileNotFoundException)30 JMenuItem (javax.swing.JMenuItem)29 Point (java.awt.Point)28 ArrayList (java.util.ArrayList)28 FileWriter (java.io.FileWriter)25 Dimension (java.awt.Dimension)24 PrintWriter (java.io.PrintWriter)24 JLabel (javax.swing.JLabel)22 JFrame (javax.swing.JFrame)21