Search in sources :

Example 31 with BevelBorder

use of javax.swing.border.BevelBorder in project tetrad by cmu-phil.

the class TetradDesktop method setupDesktop.

/**
 * Sets up the desktop components.
 */
private void setupDesktop() {
    removeAll();
    if (this.logArea != null) {
        Border border = new CompoundBorder(new EmptyBorder(0, 2, 0, 2), new BevelBorder(BevelBorder.LOWERED));
        logArea.setBorder(border);
        JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, desktopPane, logArea);
        splitPane.setDividerSize(5);
        splitPane.setDividerLocation(getDivider());
        add(splitPane, BorderLayout.CENTER);
    } else {
        add(desktopPane, BorderLayout.CENTER);
    }
    JMenuBar menuBar = new TetradMenuBar(this);
    add(menuBar, BorderLayout.NORTH);
}
Also used : BevelBorder(javax.swing.border.BevelBorder) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) JSplitPane(javax.swing.JSplitPane) Border(javax.swing.border.Border) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) BevelBorder(javax.swing.border.BevelBorder) JMenuBar(javax.swing.JMenuBar)

Example 32 with BevelBorder

use of javax.swing.border.BevelBorder in project artisynth_core by artisynth.

the class MovieMakerDialog method actionPerformed.

public void actionPerformed(ActionEvent event) {
    String cmd = event.getActionCommand();
    Object source = event.getSource();
    if (cmd.equals(FULL_WINDOW_CMD)) {
        setCaptureMode(CaptureMode.WINDOW);
        showCaptureFrame.setEnabled(false);
        showAreaSelectionFrame(false);
        updateCaptureArea();
        viewWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        fullWindowButton.setBorder(new BevelBorder(BevelBorder.LOWERED));
        customWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        originalSize.setEnabled(false);
        constrainSize.setEnabled(false);
        resizeWidth.getTextField().setEnabled(false);
        resizeHeight.getTextField().setEnabled(false);
        resizeSamples.getTextField().setEnabled(false);
    } else if (cmd.equals(VIEW_WINDOW_CMD)) {
        setCaptureMode(CaptureMode.VIEWER);
        showCaptureFrame.setEnabled(false);
        showAreaSelectionFrame(false);
        updateCaptureArea();
        viewWindowButton.setBorder(new BevelBorder(BevelBorder.LOWERED));
        fullWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        customWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        originalSize.setEnabled(true);
        if (!originalSize.isSelected()) {
            originalSize.doClick();
        }
        constrainSize.setEnabled(false);
        resizeWidth.getTextField().setEnabled(false);
        resizeHeight.getTextField().setEnabled(false);
        resizeSamples.getTextField().setEnabled(false);
    } else if (cmd.equals(CUSTOM_WINDOW_CMD)) {
        setCaptureMode(CaptureMode.CUSTOM);
        if (!showCaptureFrame.isSelected() || !showCaptureFrame.isEnabled()) {
            showCaptureFrame.setEnabled(true);
            showCaptureFrame.setSelected(true);
        }
        showAreaSelectionFrame(true);
        viewWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        fullWindowButton.setBorder(new BevelBorder(BevelBorder.RAISED));
        customWindowButton.setBorder(new BevelBorder(BevelBorder.LOWERED));
        originalSize.setEnabled(false);
        constrainSize.setEnabled(false);
        resizeWidth.getTextField().setEnabled(false);
        resizeHeight.getTextField().setEnabled(false);
        resizeSamples.getTextField().setEnabled(false);
    } else if (cmd.equals(REC_AUDIO_CMD)) {
        if (recordAudio.isSelected()) {
            println("rec. audio selected");
            recordAudioTxt.setSelected(false);
        }
        normalizeAudio.setEnabled(recordAudio.isSelected() || recordAudioTxt.isSelected());
    } else if (cmd.equals(REC_AUDIO_TO_TXT_CMD)) {
        if (recordAudioTxt.isSelected()) {
            println("rec. audio txt selected");
            recordAudio.setSelected(false);
        }
        normalizeAudio.setEnabled(recordAudio.isSelected() || recordAudioTxt.isSelected());
    } else if (cmd.equals(START_CMD)) {
        startMovie();
    } else if (cmd.equals(STOP_CMD)) {
        stopMovie();
    } else if (cmd.equals(CLOSE_CMD)) {
        setVisible(false);
    } else if (cmd.equals(WAYPOINT_CMD)) {
        waypointCapture();
    } else if (cmd.equals(FRAME_CMD)) {
        try {
            myMovieMaker.forceGrab();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else if (cmd.equals(CUSTOMIZE_CMD)) {
        Method method = (Method) methodSelector.getValue();
        MovieMaker.MethodInfo methodInfo = myMovieMaker.getMethodInfo(method);
        MethodDialog dialog = new MethodDialog(this, methodInfo);
        dialog.setLocationRelativeTo(this);
        dialog.setVisible(true);
    } else if (source == showCaptureFrame) {
        showAreaSelectionFrame(showCaptureFrame.isSelected());
    } else if (source == originalSize) {
        if (originalSize.isSelected()) {
            constrainSize.setEnabled(false);
            resizeWidth.setValue(windowWidth.getIntValue());
            resizeHeight.setValue(windowHeight.getIntValue());
            resizeWidth.getTextField().setEnabled(false);
            resizeHeight.getTextField().setEnabled(false);
            resizeSamples.getTextField().setEnabled(false);
        } else {
            constrainSize.setEnabled(true);
            resizeWidth.getTextField().setEnabled(true);
            resizeHeight.getTextField().setEnabled(true);
            resizeSamples.getTextField().setEnabled(true);
        }
    } else if (cmd.equals("Screenshot")) {
        takeScreenshot();
    } else if (source == constrainSize && constrainSize.isSelected()) {
        double scale = resizeWidth.getDoubleValue() / windowWidth.getDoubleValue();
        resizeHeight.setValue(scale * windowHeight.getIntValue());
        setMovieMakerCaptureAreaFromResize();
    } else if (source == alwaysOnTop) {
        boolean onTop = alwaysOnTop.isSelected();
        myMovieMaker.setAlwaysOnTop(onTop);
        if (isRecordingStarted) {
            myFrame.setAlwaysOnTop(onTop);
        }
    }
}
Also used : BevelBorder(javax.swing.border.BevelBorder) MethodInfo(artisynth.core.moviemaker.MovieMaker.MethodInfo) FrameBufferObject(maspack.render.GL.FrameBufferObject) Method(artisynth.core.moviemaker.MovieMaker.Method) InternalErrorException(maspack.util.InternalErrorException)

Example 33 with BevelBorder

use of javax.swing.border.BevelBorder in project hortonmachine by TheHortonMachine.

the class DatabaseController method addJtreeContextMenu.

private void addJtreeContextMenu() {
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
    popupMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            if (currentSelectedTable != null) {
                List<Action> tableActions = makeTableAction(currentSelectedTable);
                for (Action action : tableActions) {
                    if (action != null) {
                        JMenuItem item = new JMenuItem(action);
                        popupMenu.add(item);
                        item.setHorizontalTextPosition(JMenuItem.RIGHT);
                    } else {
                        popupMenu.add(new JSeparator());
                    }
                }
            } else if (currentSelectedDb != null) {
                List<Action> tableActions = makeDatabaseAction(currentSelectedDb);
                for (Action action : tableActions) {
                    if (action != null) {
                        JMenuItem item = new JMenuItem(action);
                        popupMenu.add(item);
                        item.setHorizontalTextPosition(JMenuItem.RIGHT);
                    } else {
                        popupMenu.add(new JSeparator());
                    }
                }
            } else if (currentSelectedColumn != null) {
                List<Action> columnActions = makeColumnActions(currentSelectedColumn);
                for (Action action : columnActions) {
                    if (action != null) {
                        JMenuItem item = new JMenuItem(action);
                        popupMenu.add(item);
                        item.setHorizontalTextPosition(JMenuItem.RIGHT);
                    } else {
                        popupMenu.add(new JSeparator());
                    }
                }
            } else if (currentSelectedLeaf != null) {
                List<Action> columnActions = makeLeafActions(currentSelectedLeaf);
                for (Action action : columnActions) {
                    if (action != null) {
                        JMenuItem item = new JMenuItem(action);
                        popupMenu.add(item);
                        item.setHorizontalTextPosition(JMenuItem.RIGHT);
                    } else {
                        popupMenu.add(new JSeparator());
                    }
                }
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            popupMenu.removeAll();
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            popupMenu.removeAll();
        }
    });
    databaseTreeView._databaseTree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                int row = databaseTreeView._databaseTree.getClosestRowForLocation(e.getX(), e.getY());
                databaseTreeView._databaseTree.setSelectionRow(row);
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });
    addConnectButtonContextMenu();
}
Also used : AbstractAction(javax.swing.AbstractAction) Action(javax.swing.Action) MouseEvent(java.awt.event.MouseEvent) BevelBorder(javax.swing.border.BevelBorder) PopupMenuListener(javax.swing.event.PopupMenuListener) MouseAdapter(java.awt.event.MouseAdapter) ArrayList(java.util.ArrayList) List(java.util.List) JMenuItem(javax.swing.JMenuItem) PopupMenuEvent(javax.swing.event.PopupMenuEvent) JPopupMenu(javax.swing.JPopupMenu) JSeparator(javax.swing.JSeparator)

Example 34 with BevelBorder

use of javax.swing.border.BevelBorder in project hortonmachine by TheHortonMachine.

the class DatabaseController method addSqlAreaContextMenu.

@SuppressWarnings({ "serial", "unchecked" })
private void addSqlAreaContextMenu(JTextPane sqlEditorArea) {
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
    popupMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            AbstractAction loadAction = new AbstractAction("Load saved query") {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        byte[] savedQueries = PreferencesHandler.getPreference(HM_SAVED_QUERIES, new byte[0]);
                        List<SqlData> sqlDataList;
                        if (savedQueries.length == 0) {
                            sqlDataList = new ArrayList<>();
                        } else {
                            sqlDataList = (List<SqlData>) SqlTemplatesAndActions.convertFromBytes(savedQueries);
                        }
                        Set<String> checkSet = new TreeSet<>();
                        sqlDataList.removeIf(sd -> sd.name == null || !checkSet.add(sd.name));
                        if (sqlDataList.size() == 0) {
                            GuiUtilities.showWarningMessage(DatabaseController.this, null, "No saved queries available.");
                        } else {
                            sqlDataList.sort((sd1, sd2) -> sd1.name.compareTo(sd2.name));
                            Map<String, SqlData> collect = sqlDataList.stream().collect(Collectors.toMap(c -> c.name, Function.identity()));
                            List<String> names = sqlDataList.stream().map(sd -> sd.name).collect(Collectors.toList());
                            String selected = GuiUtilities.showComboDialog(DatabaseController.this, "Select Query", "Select the query to load", names.toArray(new String[0]), null);
                            if (selected != null && selected.length() > 0) {
                                SqlData sqlData = collect.get(selected);
                                if (sqlData != null) {
                                    addTextToQueryEditor(sqlData.sql);
                                }
                            }
                        }
                    } catch (Exception e1) {
                        GuiUtilities.showErrorMessage(DatabaseController.this, e1.getMessage());
                    }
                }
            };
            AbstractAction saveAction = new AbstractAction("Save current query") {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        byte[] savedQueries = PreferencesHandler.getPreference(HM_SAVED_QUERIES, new byte[0]);
                        List<SqlData> sqlDataList = new ArrayList<>();
                        if (savedQueries.length != 0) {
                            sqlDataList = (List<SqlData>) SqlTemplatesAndActions.convertFromBytes(savedQueries);
                        }
                        String sql = currentSqlEditorArea.getText();
                        String newName = GuiUtilities.showInputDialog(DatabaseController.this, "Enter a name for the saved query", "query " + new DateTime().toString(HMConstants.dateTimeFormatterYYYYMMDDHHMMSS));
                        if (newName == null || newName.trim().length() == 0) {
                            return;
                        }
                        sqlDataList.removeIf(sd -> sd.name == newName);
                        SqlData sd = new SqlData();
                        sd.name = newName;
                        sd.sql = sql;
                        sqlDataList.add(sd);
                        byte[] bytesToSave = SqlTemplatesAndActions.convertObjectToBytes(sqlDataList);
                        PreferencesHandler.setPreference(HM_SAVED_QUERIES, bytesToSave);
                    } catch (Exception e1) {
                        Logger.INSTANCE.insertError("", "ERROR", e1);
                    }
                }
            };
            AbstractAction removeAction = new AbstractAction("Remove a query from saved") {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        byte[] savedQueries = PreferencesHandler.getPreference(HM_SAVED_QUERIES, new byte[0]);
                        List<SqlData> sqlDataList = (List<SqlData>) SqlTemplatesAndActions.convertFromBytes(savedQueries);
                        Set<String> checkSet = new TreeSet<>();
                        sqlDataList.removeIf(sd -> sd.name == null || !checkSet.add(sd.name));
                        if (sqlDataList.size() == 0) {
                            GuiUtilities.showWarningMessage(DatabaseController.this, null, "No saved queries available.");
                        } else {
                            sqlDataList.sort((sd1, sd2) -> sd1.name.compareTo(sd2.name));
                            List<String> names = sqlDataList.stream().map(sd -> sd.name).collect(Collectors.toList());
                            String selected = GuiUtilities.showComboDialog(DatabaseController.this, "Select Query", "Select the query to remove", names.toArray(new String[0]), null);
                            if (selected != null && selected.length() > 0) {
                                sqlDataList.removeIf(sd -> {
                                    if (sd.name == null)
                                        return true;
                                    return sd.name.equals(selected);
                                });
                                byte[] bytesToSave = SqlTemplatesAndActions.convertObjectToBytes(sqlDataList);
                                PreferencesHandler.setPreference(HM_SAVED_QUERIES, bytesToSave);
                            }
                        }
                    } catch (Exception e1) {
                        GuiUtilities.showErrorMessage(DatabaseController.this, e1.getMessage());
                    }
                }
            };
            AbstractAction exportAction = new AbstractAction("Export saved queries") {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        byte[] savedQueries = PreferencesHandler.getPreference(HM_SAVED_QUERIES, new byte[0]);
                        List<SqlData> sqlDataList = (List<SqlData>) SqlTemplatesAndActions.convertFromBytes(savedQueries);
                        JSONArray queriesArray = new JSONArray();
                        for (SqlData sqlData : sqlDataList) {
                            JSONObject item = new JSONObject();
                            item.put(sqlData.name, sqlData.sql);
                            queriesArray.put(item);
                        }
                        String jsonString = queriesArray.toString(2);
                        File[] files = guiBridge.showSaveFileDialog("Select queries json to create", PreferencesHandler.getLastFile(), new HMFileFilter("JSON Files", new String[] { "json" }));
                        if (files != null && files.length > 0) {
                            String absolutePath = files[0].getAbsolutePath();
                            PreferencesHandler.setLastPath(absolutePath);
                            FileUtilities.writeFile(jsonString, files[0]);
                        }
                    } catch (Exception e1) {
                        GuiUtilities.showErrorMessage(DatabaseController.this, e1.getMessage());
                    }
                }
            };
            AbstractAction importAction = new AbstractAction("Import saved queries") {

                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        File[] files = guiBridge.showOpenFileDialog("Select queries json to import", PreferencesHandler.getLastFile(), new HMFileFilter("JSON Files", new String[] { "json" }));
                        if (files != null && files.length > 0) {
                            String absolutePath = files[0].getAbsolutePath();
                            PreferencesHandler.setLastPath(absolutePath);
                            byte[] savedQueries = PreferencesHandler.getPreference(HM_SAVED_QUERIES, new byte[0]);
                            List<SqlData> sqlDataList = new ArrayList<>();
                            if (savedQueries.length != 0) {
                                sqlDataList = (List<SqlData>) SqlTemplatesAndActions.convertFromBytes(savedQueries);
                            }
                            String json = FileUtilities.readFile(files[0]);
                            JSONArray queriesArray = new JSONArray(json);
                            for (int i = 0; i < queriesArray.length(); i++) {
                                JSONObject jsonObject = queriesArray.getJSONObject(i);
                                String[] names = JSONObject.getNames(jsonObject);
                                for (String name : names) {
                                    boolean hasAlready = sqlDataList.stream().anyMatch(sd -> sd.name.equals(name));
                                    if (!hasAlready) {
                                        SqlData newSqlData = new SqlData();
                                        newSqlData.name = name;
                                        newSqlData.sql = jsonObject.getString(name);
                                        sqlDataList.add(newSqlData);
                                    }
                                }
                            }
                            byte[] bytesToSave = SqlTemplatesAndActions.convertObjectToBytes(sqlDataList);
                            PreferencesHandler.setPreference(HM_SAVED_QUERIES, bytesToSave);
                        }
                    } catch (Exception e1) {
                        GuiUtilities.showErrorMessage(DatabaseController.this, e1.getMessage());
                    }
                }
            };
            JMenuItem item = new JMenuItem(saveAction);
            item.setHorizontalTextPosition(JMenuItem.RIGHT);
            popupMenu.add(item);
            item = new JMenuItem(loadAction);
            item.setHorizontalTextPosition(JMenuItem.RIGHT);
            popupMenu.add(item);
            item = new JMenuItem(removeAction);
            item.setHorizontalTextPosition(JMenuItem.RIGHT);
            popupMenu.add(item);
            popupMenu.addSeparator();
            item = new JMenuItem(exportAction);
            item.setHorizontalTextPosition(JMenuItem.RIGHT);
            popupMenu.add(item);
            item = new JMenuItem(importAction);
            item.setHorizontalTextPosition(JMenuItem.RIGHT);
            popupMenu.add(item);
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            popupMenu.removeAll();
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            popupMenu.removeAll();
        }
    });
    sqlEditorArea.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                int row = databaseTreeView._databaseTree.getClosestRowForLocation(e.getX(), e.getY());
                databaseTreeView._databaseTree.setSelectionRow(row);
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });
}
Also used : Logger(org.hortonmachine.dbs.log.Logger) WKTReader(org.locationtech.jts.io.WKTReader) TableCellRenderer(javax.swing.table.TableCellRenderer) Border(javax.swing.border.Border) Map(java.util.Map) HMFileFilter(org.hortonmachine.gears.libs.modules.HMFileFilter) TitledBorder(javax.swing.border.TitledBorder) QueryResult(org.hortonmachine.dbs.compat.objects.QueryResult) JFrame(javax.swing.JFrame) TableLevel(org.hortonmachine.dbs.compat.objects.TableLevel) TreePath(javax.swing.tree.TreePath) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) SpatialiteCommonMethods(org.hortonmachine.dbs.spatialite.SpatialiteCommonMethods) Set(java.util.Set) Component(java.awt.Component) Tool(org.geotools.swing.JMapFrame.Tool) LogProgressMonitor(org.hortonmachine.gears.libs.monitor.LogProgressMonitor) AbstractAction(javax.swing.AbstractAction) OmsVectorWriter(org.hortonmachine.gears.io.vectorwriter.OmsVectorWriter) ParseException(org.locationtech.jts.io.ParseException) JPanel(javax.swing.JPanel) IHMProgressMonitor(org.hortonmachine.gears.libs.monitor.IHMProgressMonitor) JSplitPane(javax.swing.JSplitPane) Action(javax.swing.Action) DbsHelper(org.hortonmachine.gears.io.dbs.DbsHelper) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SqlName(org.hortonmachine.dbs.utils.SqlName) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) JTabbedPane(javax.swing.JTabbedPane) StringSelection(java.awt.datatransfer.StringSelection) INosqlDocument(org.hortonmachine.dbs.nosql.INosqlDocument) ImageIcon(javax.swing.ImageIcon) JTextPane(javax.swing.JTextPane) GeometryUtilities(org.hortonmachine.gears.utils.geometry.GeometryUtilities) DbLevel(org.hortonmachine.dbs.compat.objects.DbLevel) GuiBridgeHandler(org.hortonmachine.gui.utils.GuiBridgeHandler) JButton(javax.swing.JButton) JdbcBlob(org.h2.jdbc.JdbcBlob) TableColumn(javax.swing.table.TableColumn) BevelBorder(javax.swing.border.BevelBorder) INosqlDb(org.hortonmachine.dbs.nosql.INosqlDb) IOException(java.io.IOException) PopupMenuListener(javax.swing.event.PopupMenuListener) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) LogConsoleController(org.hortonmachine.gui.console.LogConsoleController) JScrollPane(javax.swing.JScrollPane) ColumnLevel(org.hortonmachine.dbs.compat.objects.ColumnLevel) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) GTSpatialiteThreadsafeDb(org.hortonmachine.gears.spatialite.GTSpatialiteThreadsafeDb) EDb(org.hortonmachine.dbs.compat.EDb) ADb(org.hortonmachine.dbs.compat.ADb) JTextArea(javax.swing.JTextArea) Style(org.geotools.styling.Style) ImageCache(org.hortonmachine.gui.utils.ImageCache) JDialog(javax.swing.JDialog) JSONObject(org.json.JSONObject) ComponentListener(java.awt.event.ComponentListener) ByteArrayInputStream(java.io.ByteArrayInputStream) ESpatialiteGeometryType(org.hortonmachine.dbs.datatypes.ESpatialiteGeometryType) PreferencesHandler(org.hortonmachine.gears.utils.PreferencesHandler) MouseAdapter(java.awt.event.MouseAdapter) ImageIO(javax.imageio.ImageIO) HMConstants(org.hortonmachine.gears.libs.modules.HMConstants) ConnectionData(org.hortonmachine.dbs.compat.ConnectionData) BorderLayout(java.awt.BorderLayout) Clipboard(java.awt.datatransfer.Clipboard) BufferedImage(java.awt.image.BufferedImage) DefaultTableModel(javax.swing.table.DefaultTableModel) ComponentEvent(java.awt.event.ComponentEvent) Collectors(java.util.stream.Collectors) HM(org.hortonmachine.HM) Dimension(java.awt.Dimension) List(java.util.List) PopupMenuEvent(javax.swing.event.PopupMenuEvent) DbsUtilities(org.hortonmachine.dbs.utils.DbsUtilities) CategoryHistogram(org.hortonmachine.gears.utils.chart.CategoryHistogram) JSeparator(javax.swing.JSeparator) Polygon(org.locationtech.jts.geom.Polygon) JTable(javax.swing.JTable) ChartPanel(org.jfree.chart.ChartPanel) Geometry(org.locationtech.jts.geom.Geometry) SpatialiteTableNames(org.hortonmachine.dbs.spatialite.SpatialiteTableNames) Toolkit(java.awt.Toolkit) GuiUtilities(org.hortonmachine.gui.utils.GuiUtilities) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ASpatialDb(org.hortonmachine.dbs.compat.ASpatialDb) Transferable(java.awt.datatransfer.Transferable) DefaultFeatureCollection(org.geotools.feature.DefaultFeatureCollection) HMMapframe(org.hortonmachine.gui.utils.HMMapframe) Function(java.util.function.Function) SwingConstants(javax.swing.SwingConstants) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Scatter(org.hortonmachine.gears.utils.chart.Scatter) SwingUtilities(javax.swing.SwingUtilities) TreeSelectionListener(javax.swing.event.TreeSelectionListener) IOnCloseListener(org.hortonmachine.gui.utils.GuiUtilities.IOnCloseListener) JMenuItem(javax.swing.JMenuItem) TransferHandler(javax.swing.TransferHandler) JFreeChart(org.jfree.chart.JFreeChart) JComponent(javax.swing.JComponent) DatabaseTreeCellRenderer(org.hortonmachine.database.tree.DatabaseTreeCellRenderer) MultiLineTableCellRenderer(org.hortonmachine.database.tree.MultiLineTableCellRenderer) INosqlCollection(org.hortonmachine.dbs.nosql.INosqlCollection) FileUtilities(org.hortonmachine.gears.utils.files.FileUtilities) JPopupMenu(javax.swing.JPopupMenu) DateTime(org.joda.time.DateTime) JOptionPane(javax.swing.JOptionPane) JTree(javax.swing.JTree) FeatureUtilities(org.hortonmachine.gears.utils.features.FeatureUtilities) ActionEvent(java.awt.event.ActionEvent) Date(java.sql.Date) JdbcSQLException(org.h2.jdbc.JdbcSQLException) CommonQueries(org.hortonmachine.dbs.utils.CommonQueries) LeafLevel(org.hortonmachine.dbs.compat.objects.LeafLevel) DatabaseTreeModel(org.hortonmachine.database.tree.DatabaseTreeModel) JSONArray(org.json.JSONArray) Set(java.util.Set) TreeSet(java.util.TreeSet) MouseEvent(java.awt.event.MouseEvent) BevelBorder(javax.swing.border.BevelBorder) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) MouseAdapter(java.awt.event.MouseAdapter) PopupMenuEvent(javax.swing.event.PopupMenuEvent) JPopupMenu(javax.swing.JPopupMenu) ParseException(org.locationtech.jts.io.ParseException) SQLException(java.sql.SQLException) IOException(java.io.IOException) JdbcSQLException(org.h2.jdbc.JdbcSQLException) DateTime(org.joda.time.DateTime) HMFileFilter(org.hortonmachine.gears.libs.modules.HMFileFilter) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) JMenuItem(javax.swing.JMenuItem) AbstractAction(javax.swing.AbstractAction) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 35 with BevelBorder

use of javax.swing.border.BevelBorder in project hortonmachine by TheHortonMachine.

the class DatabaseController method addDataTableContextMenu.

private void addDataTableContextMenu(JTable table) {
    JPopupMenu popupMenu = new JPopupMenu();
    popupMenu.setBorder(new BevelBorder(BevelBorder.RAISED));
    popupMenu.addPopupMenuListener(new PopupMenuListener() {

        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
            int[] selectedRows = table.getSelectedRows();
            int[] selectedCols = table.getSelectedColumns();
            boolean isGeom = false;
            boolean isBinary = false;
            boolean proposeChart = false;
            ESpatialiteGeometryType geomType = null;
            if (selectedCols.length == 1 && selectedRows.length > 0) {
                // check content
                Object valueObj = table.getValueAt(selectedRows[0], selectedCols[0]);
                if (valueObj instanceof byte[] || valueObj instanceof JdbcBlob) {
                    isBinary = true;
                }
                String valueAt = valueObj.toString();
                String checkString = valueAt.split("\\(")[0].trim();
                checkString = removeSrid(checkString);
                if (ESpatialiteGeometryType.isGeometryName(checkString)) {
                    isGeom = true;
                    geomType = ESpatialiteGeometryType.forName(checkString);
                }
            }
            if (selectedCols.length > 1 && selectedRows.length > 1) {
                proposeChart = true;
            }
            JMenuItem item = new JMenuItem(new AbstractAction("Copy cells content") {

                private static final long serialVersionUID = 1L;

                @Override
                public void actionPerformed(ActionEvent e) {
                    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                    table.getTransferHandler().exportToClipboard(table, clipboard, TransferHandler.COPY);
                }
            });
            item.setHorizontalTextPosition(JMenuItem.RIGHT);
            popupMenu.add(item);
            if (isBinary) {
                JMenuItem item1 = new JMenuItem(new AbstractAction("View as image") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        for (int r : selectedRows) {
                            Object valueObj = table.getValueAt(r, selectedCols[0]);
                            byte[] bytes = null;
                            if (valueObj instanceof JdbcBlob) {
                                JdbcBlob blob = (JdbcBlob) valueObj;
                                try {
                                    bytes = blob.getBytes(0, (int) blob.length());
                                } catch (SQLException e1) {
                                    Logger.INSTANCE.e("error reading image bytes", e1);
                                    continue;
                                }
                            } else if (valueObj instanceof byte[]) {
                                bytes = (byte[]) valueObj;
                            }
                            if (bytes != null) {
                                try {
                                    BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes));
                                    GuiUtilities.showImage(popupMenu, valueObj.toString(), image);
                                } catch (IOException e1) {
                                    GuiUtilities.showWarningMessage(popupMenu, "Not an image.");
                                    break;
                                }
                            }
                        }
                    }
                });
                item1.setHorizontalTextPosition(JMenuItem.RIGHT);
                popupMenu.add(item1);
                JMenuItem itemToString = new JMenuItem(new AbstractAction("View as string") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        for (int r : selectedRows) {
                            Object valueObj = table.getValueAt(r, selectedCols[0]);
                            byte[] bytes = null;
                            if (valueObj instanceof JdbcBlob) {
                                JdbcBlob blob = (JdbcBlob) valueObj;
                                try {
                                    bytes = blob.getBytes(0, (int) blob.length());
                                } catch (SQLException e1) {
                                    Logger.INSTANCE.e("error reading image bytes", e1);
                                    continue;
                                }
                            } else if (valueObj instanceof byte[]) {
                                bytes = (byte[]) valueObj;
                            }
                            if (bytes != null) {
                                String string = new String(bytes);
                                JTextArea tArea = new JTextArea(string, 10, 20);
                                JPanel p = new JPanel(new BorderLayout());
                                final JScrollPane scroll = new JScrollPane(tArea);
                                p.add(scroll, BorderLayout.CENTER);
                                tArea.setLineWrap(true);
                                GuiUtilities.openDialogWithPanel(p, "Cell as string", new Dimension(600, 500), false);
                            }
                        }
                    }
                });
                itemToString.setHorizontalTextPosition(JMenuItem.RIGHT);
                popupMenu.add(itemToString);
            }
            if (proposeChart) {
                JMenuItem item1 = new JMenuItem(new AbstractAction("Chart values") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        try {
                            int chartsCount = selectedCols.length - 1;
                            String xLabel = table.getColumnName(selectedCols[0]);
                            Scatter scatterChart = null;
                            CategoryHistogram categoryHistogram = null;
                            for (int i = 0; i < chartsCount; i++) {
                                Object tmpX = table.getValueAt(0, selectedCols[0]);
                                boolean doCat = true;
                                if (tmpX instanceof Number) {
                                    doCat = false;
                                }
                                Object tmpY = table.getValueAt(0, selectedCols[i + 1]);
                                if (!(tmpY instanceof Number)) {
                                    break;
                                }
                                if (doCat) {
                                    if (categoryHistogram == null) {
                                        String[] xStr = new String[selectedRows.length];
                                        double[] y = new double[selectedRows.length];
                                        for (int r : selectedRows) {
                                            Object xObj = table.getValueAt(r, selectedCols[0]);
                                            Object yObj = table.getValueAt(r, selectedCols[i + 1]);
                                            xStr[r] = xObj.toString();
                                            y[r] = ((Number) yObj).doubleValue();
                                        }
                                        categoryHistogram = new CategoryHistogram(xStr, y);
                                    }
                                } else {
                                    if (scatterChart == null) {
                                        scatterChart = new Scatter("");
                                        List<Boolean> showLines = new ArrayList<Boolean>();
                                        for (int j = 0; j < chartsCount; j++) {
                                            showLines.add(true);
                                        }
                                        scatterChart.setShowLines(showLines);
                                        scatterChart.setXLabel(xLabel);
                                        scatterChart.setYLabel("");
                                    }
                                    double[] x = new double[selectedRows.length];
                                    double[] y = new double[selectedRows.length];
                                    String seriesName = table.getColumnName(selectedCols[i + 1]);
                                    for (int r : selectedRows) {
                                        Object xObj = table.getValueAt(r, selectedCols[0]);
                                        Object yObj = table.getValueAt(r, selectedCols[i + 1]);
                                        x[r] = ((Number) xObj).doubleValue();
                                        y[r] = ((Number) yObj).doubleValue();
                                    }
                                    scatterChart.addSeries(seriesName, x, y);
                                }
                            }
                            Dimension dimension = new Dimension(800, 600);
                            if (scatterChart != null) {
                                JFreeChart chart = scatterChart.getChart();
                                ChartPanel chartPanel = new ChartPanel(chart, true);
                                chartPanel.setPreferredSize(dimension);
                                JPanel p = new JPanel(new BorderLayout());
                                p.add(chartPanel, BorderLayout.CENTER);
                                GuiUtilities.openDialogWithPanel(p, "Chart from cells", dimension, false);
                            } else if (categoryHistogram != null) {
                                JFreeChart chart = categoryHistogram.getChart();
                                ChartPanel chartPanel = new ChartPanel(chart, true);
                                chartPanel.setPreferredSize(dimension);
                                JPanel p = new JPanel(new BorderLayout());
                                p.add(chartPanel, BorderLayout.CENTER);
                                GuiUtilities.openDialogWithPanel(p, "Chart from cells", dimension, false);
                            } else {
                                GuiUtilities.showWarningMessage(popupMenu, "Charting of selected data not possible.");
                            }
                        } catch (Exception ex) {
                            Logger.INSTANCE.insertError("", "ERROR", ex);
                        }
                    }
                });
                item1.setHorizontalTextPosition(JMenuItem.RIGHT);
                popupMenu.add(item1);
            }
            if (isGeom) {
                JMenuItem item1 = new JMenuItem(new AbstractAction("View geometry") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        WKTReader wktReader = new WKTReader();
                        List<Geometry> geomsList = new ArrayList<>();
                        for (int r : selectedRows) {
                            try {
                                String valueAt = table.getValueAt(r, selectedCols[0]).toString();
                                valueAt = removeSrid(valueAt);
                                Geometry geometry = wktReader.read(valueAt);
                                if (geometry instanceof GeometryCollection) {
                                    int numGeometries = geometry.getNumGeometries();
                                    for (int j = 0; j < numGeometries; j++) {
                                        Geometry geometryN = geometry.getGeometryN(j);
                                        geomsList.add(geometryN);
                                    }
                                } else {
                                    geomsList.add(geometry);
                                }
                            } catch (ParseException e1) {
                                Logger.INSTANCE.insertError("", "ERROR", e1);
                            }
                        }
                        if (geomsList.size() > 0) {
                            List<SimpleFeatureCollection> fcs = FeatureUtilities.featureCollectionsFromGeometry(null, geomsList.toArray(new Geometry[0]));
                            showInMapFrame(false, fcs.toArray(new SimpleFeatureCollection[0]), null);
                        }
                    }
                });
                item1.setHorizontalTextPosition(JMenuItem.RIGHT);
                popupMenu.add(item1);
                JMenuItem item2 = new JMenuItem(new AbstractAction("Plot geometry") {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        WKTReader wktReader = new WKTReader();
                        List<Geometry> geomsList = new ArrayList<>();
                        for (int r : selectedRows) {
                            try {
                                String valueAt = table.getValueAt(r, selectedCols[0]).toString();
                                valueAt = removeSrid(valueAt);
                                Geometry geometry = wktReader.read(valueAt);
                                if (geometry instanceof GeometryCollection) {
                                    int numGeometries = geometry.getNumGeometries();
                                    for (int j = 0; j < numGeometries; j++) {
                                        Geometry geometryN = geometry.getGeometryN(j);
                                        geomsList.add(geometryN);
                                    }
                                } else {
                                    geomsList.add(geometry);
                                }
                            } catch (ParseException e1) {
                                Logger.INSTANCE.insertError("", "ERROR", e1);
                            }
                        }
                        if (geomsList.size() > 0) {
                            HM.plotJtsGeometries(null, geomsList);
                        }
                    }
                });
                item2.setHorizontalTextPosition(JMenuItem.RIGHT);
                popupMenu.add(item2);
                if (geomType != null && !geomType.isPoint()) {
                    JMenuItem item3 = new JMenuItem(new AbstractAction("View geometry with directions hint") {

                        private static final long serialVersionUID = 1L;

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            WKTReader wktReader = new WKTReader();
                            List<Geometry> geomsList = new ArrayList<>();
                            for (int r : selectedRows) {
                                try {
                                    String valueAt = table.getValueAt(r, selectedCols[0]).toString();
                                    valueAt = removeSrid(valueAt);
                                    Geometry geometry = wktReader.read(valueAt);
                                    if (geometry instanceof GeometryCollection) {
                                        int numGeometries = geometry.getNumGeometries();
                                        for (int j = 0; j < numGeometries; j++) {
                                            Geometry geometryN = geometry.getGeometryN(j);
                                            List<Polygon> simpleDirectionArrows = GeometryUtilities.createSimpleDirectionArrow(geometryN);
                                            geomsList.add(geometryN);
                                            geomsList.addAll(simpleDirectionArrows);
                                        }
                                    } else {
                                        List<Polygon> simpleDirectionArrows = GeometryUtilities.createSimpleDirectionArrow(geometry);
                                        geomsList.add(geometry);
                                        geomsList.addAll(simpleDirectionArrows);
                                    }
                                } catch (ParseException e1) {
                                    Logger.INSTANCE.insertError("", "ERROR", e1);
                                }
                            }
                            if (geomsList.size() > 0) {
                                List<SimpleFeatureCollection> fcs = FeatureUtilities.featureCollectionsFromGeometry(null, geomsList.toArray(new Geometry[0]));
                                showInMapFrame(false, fcs.toArray(new SimpleFeatureCollection[0]), null);
                            }
                        }
                    });
                    item3.setHorizontalTextPosition(JMenuItem.RIGHT);
                    popupMenu.add(item3);
                }
            }
        }

        private String removeSrid(String valueAt) {
            if (valueAt.startsWith("SRID=")) {
                valueAt = valueAt.split(";")[1];
            }
            return valueAt;
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
            popupMenu.removeAll();
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent e) {
            popupMenu.removeAll();
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                popupMenu.show(e.getComponent(), e.getX(), e.getY());
            }
        }
    });
}
Also used : JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ChartPanel(org.jfree.chart.ChartPanel) BevelBorder(javax.swing.border.BevelBorder) SQLException(java.sql.SQLException) JdbcSQLException(org.h2.jdbc.JdbcSQLException) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) ArrayList(java.util.ArrayList) JdbcBlob(org.h2.jdbc.JdbcBlob) WKTReader(org.locationtech.jts.io.WKTReader) PopupMenuEvent(javax.swing.event.PopupMenuEvent) BufferedImage(java.awt.image.BufferedImage) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) BorderLayout(java.awt.BorderLayout) JMenuItem(javax.swing.JMenuItem) Polygon(org.locationtech.jts.geom.Polygon) AbstractAction(javax.swing.AbstractAction) CategoryHistogram(org.hortonmachine.gears.utils.chart.CategoryHistogram) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) IOException(java.io.IOException) Dimension(java.awt.Dimension) JPopupMenu(javax.swing.JPopupMenu) JFreeChart(org.jfree.chart.JFreeChart) ParseException(org.locationtech.jts.io.ParseException) SQLException(java.sql.SQLException) IOException(java.io.IOException) JdbcSQLException(org.h2.jdbc.JdbcSQLException) SimpleFeatureCollection(org.geotools.data.simple.SimpleFeatureCollection) Geometry(org.locationtech.jts.geom.Geometry) ESpatialiteGeometryType(org.hortonmachine.dbs.datatypes.ESpatialiteGeometryType) ByteArrayInputStream(java.io.ByteArrayInputStream) JSONObject(org.json.JSONObject) Clipboard(java.awt.datatransfer.Clipboard) ParseException(org.locationtech.jts.io.ParseException) Scatter(org.hortonmachine.gears.utils.chart.Scatter)

Aggregations

BevelBorder (javax.swing.border.BevelBorder)51 JPanel (javax.swing.JPanel)18 JScrollPane (javax.swing.JScrollPane)14 Dimension (java.awt.Dimension)13 ActionEvent (java.awt.event.ActionEvent)13 JLabel (javax.swing.JLabel)13 BorderLayout (java.awt.BorderLayout)12 JButton (javax.swing.JButton)11 MouseAdapter (java.awt.event.MouseAdapter)10 MouseEvent (java.awt.event.MouseEvent)10 FlowLayout (java.awt.FlowLayout)9 Insets (java.awt.Insets)9 JPopupMenu (javax.swing.JPopupMenu)9 TitledBorder (javax.swing.border.TitledBorder)9 Font (java.awt.Font)8 IOException (java.io.IOException)8 JMenuItem (javax.swing.JMenuItem)8 Color (java.awt.Color)7 EtchedBorder (javax.swing.border.EtchedBorder)7 ActionListener (java.awt.event.ActionListener)6