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);
}
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);
}
}
}
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();
}
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());
}
}
});
}
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());
}
}
});
}
Aggregations