use of com.revolsys.swing.menu.MenuFactory in project com.revolsys.open by revolsys.
the class SwingUtil method newComboBox.
static ComboBox<Identifier> newComboBox(final String fieldName, final CodeTable codeTable, final boolean required, final int maxLength, final boolean idSuffix) {
if (codeTable == null) {
return null;
} else {
final ComboBox<Identifier> comboBox = CodeTableComboBoxModel.newComboBox(fieldName, codeTable, !required, idSuffix);
if (comboBox.getModel().getSize() > 0) {
comboBox.setSelectedIndex(0);
}
int longestLength = -1;
for (final Entry<Identifier, List<Object>> codes : codeTable.getCodes().entrySet()) {
int length = 0;
if (idSuffix) {
final Identifier identifier = codes.getKey();
length += identifier.toString().length() + 3;
}
final List<Object> values = codes.getValue();
if (values != null && !values.isEmpty()) {
final String text = Strings.toString(values);
length += text.length();
}
if (length > longestLength) {
longestLength = length;
}
}
if (longestLength == -1) {
longestLength = 10;
}
if (maxLength > 0 && longestLength > maxLength) {
longestLength = maxLength;
}
final StringBuilder value = new StringBuilder();
for (int i = 0; i < longestLength; i++) {
value.append("W");
}
comboBox.setPrototypeDisplayValue(Identifier.newIdentifier(value));
final ComboBoxEditor editor = comboBox.getEditor();
final Component editorComponent = editor.getEditorComponent();
if (editorComponent instanceof JTextComponent) {
final JTextField textComponent = (JTextField) editorComponent;
textComponent.setColumns((int) (longestLength * 0.8));
final MenuFactory menu = MenuFactory.getPopupMenuFactory(textComponent);
MenuFactory.addToComponent(comboBox, menu);
} else {
MenuFactory.getPopupMenuFactory(comboBox);
}
return comboBox;
}
}
use of com.revolsys.swing.menu.MenuFactory in project com.revolsys.open by revolsys.
the class LayerRecordForm method addToolBar.
protected ToolBar addToolBar(final AbstractRecordLayer layer) {
this.toolBar = new ToolBar();
add(this.toolBar, BorderLayout.NORTH);
final RecordDefinition recordDefinition = getRecordDefinition();
final FieldDefinition geometryField = recordDefinition.getGeometryField();
final boolean hasGeometry = geometryField != null;
final EnableCheck editable = new ObjectPropertyEnableCheck(this, "editable");
if (layer != null) {
final MenuFactory menuFactory = MenuFactory.findMenu(layer);
if (menuFactory != null) {
this.toolBar.addButtonTitleIcon("menu", "Layer Menu", "menu", () -> menuFactory.showMenu(layer, this, 10, 10));
}
}
final EnableCheck deletableEnableCheck = editable.and(new ObjectPropertyEnableCheck(this, "deletable"));
this.toolBar.addButton("record", "Delete Record", "table_row_delete", deletableEnableCheck, this::deleteRecord);
// Cut, Copy Paste
this.toolBar.addButton("dnd", "Copy Record", "page_copy", (EnableCheck) null, this::dataTransferCopy);
if (hasGeometry) {
this.toolBar.addButton("dnd", "Copy Geometry", "geometry_copy", (EnableCheck) null, this::copyGeometry);
}
this.toolBar.addButton("dnd", "Paste Record", "paste_plain", editable, this::dataTransferPaste);
if (hasGeometry) {
this.toolBar.addButton("dnd", "Paste Geometry", "geometry_paste", editable, this::pasteGeometry);
}
final EnableCheck canUndo = new ObjectPropertyEnableCheck(this.undoManager, "canUndo");
final EnableCheck canRedo = new ObjectPropertyEnableCheck(this.undoManager, "canRedo");
final EnableCheck modifiedOrDeleted = new ObjectPropertyEnableCheck(this, "modifiedOrDeleted");
this.toolBar.addButton("changes", "Revert Record", "arrow_revert", modifiedOrDeleted, this::revertChanges);
this.toolBar.addButton("changes", "Revert Empty Fields", "field_empty_revert", new ObjectPropertyEnableCheck(this, "hasModifiedEmptyFields"), this::revertEmptyFields);
this.toolBar.addButton("changes", "Undo", "arrow_undo", canUndo, this.undoManager::undo);
this.toolBar.addButton("changes", "Redo", "arrow_redo", canRedo, this.undoManager::redo);
if (hasGeometry) {
this.toolBar.addButtonTitleIcon("zoom", "Zoom to Record", "magnifier_zoom_selected", () -> {
final LayerRecord record = getRecord();
layer.zoomToRecord(record);
});
this.toolBar.addButtonTitleIcon("zoom", "Pan to Record", "pan_selected", () -> {
final LayerRecord record = getRecord();
final MapPanel mapPanel = layer.getMapPanel();
if (mapPanel != null) {
mapPanel.panToRecord(record);
}
});
}
// Geometry manipulation
if (hasGeometry) {
final DataType geometryDataType = geometryField.getDataType();
if (geometryDataType == DataTypes.LINE_STRING || geometryDataType == DataTypes.MULTI_LINE_STRING) {
if (DirectionalFields.getProperty(recordDefinition).hasDirectionalFields()) {
this.toolBar.addButton("geometry", FLIP_RECORD_NAME, FLIP_RECORD_ICON, editable, this::flipRecordOrientation);
this.toolBar.addButton("geometry", FLIP_LINE_ORIENTATION_NAME, FLIP_LINE_ORIENTATION_ICON, editable, this::flipLineOrientation);
this.toolBar.addButton("geometry", FLIP_FIELDS_NAME, FLIP_FIELDS_ICON, editable, this::flipFields);
} else {
this.toolBar.addButton("geometry", "Flip Line Orientation", "flip_line", editable, this::flipLineOrientation);
}
}
}
return this.toolBar;
}
use of com.revolsys.swing.menu.MenuFactory in project com.revolsys.open by revolsys.
the class RecordLayerTablePanel method newToolBar.
protected void newToolBar(final Map<String, Object> pluginConfig) {
final ToolBar toolBar = getToolBar();
final RecordDefinition recordDefinition = getRecordDefinition();
final boolean hasGeometry = recordDefinition.hasGeometryField();
final MenuFactory layerMenuFactory = MenuFactory.findMenu(this.layer);
if (layerMenuFactory != null) {
toolBar.addButtonTitleIcon("menu", "Layer Menu", "menu", () -> layerMenuFactory.showMenu(this.layer, this, 10, 10));
}
if (hasGeometry) {
final EnableCheck hasSelectedRecords = new ObjectPropertyEnableCheck(this.layer, "hasSelectedRecords");
toolBar.addButton("layer", "Zoom to Selected", "magnifier_zoom_selected", hasSelectedRecords, this.layer::zoomToSelected);
toolBar.addButton("layer", "Pan to Selected", "pan_selected", hasSelectedRecords, this.layer::panToSelected);
}
final RecordLayerTable table = getTable();
final TableRowCount tableRowCount = new TableRowCount(table);
toolBar.addComponent("count", tableRowCount);
toolBar.addButtonTitleIcon("table", "Refresh", "table_refresh", this.layer::refresh);
toolBar.addButtonTitleIcon("table", "Export Records", "table_save", new ObjectPropertyEnableCheck(tableRowCount, "rowCount", 0, true), () -> actionExportRecords());
this.fieldSetsButton = toolBar.addButtonTitleIcon("table", "Field Sets", "fields_filter", () -> actionShowFieldSetsMenu());
this.fieldFilterPanel = new FieldFilterPanel(this, this.tableModel, pluginConfig);
if (this.fieldFilterPanel.isVisible()) {
toolBar.addComponent("search", this.fieldFilterPanel);
toolBar.addButtonTitleIcon("search", "Advanced Search", "filter_edits", this.fieldFilterPanel::showAdvancedFilter);
final EnableCheck hasFilter = new ObjectPropertyEnableCheck(this.tableModel, "hasFilter");
toolBar.addButton("search", "Clear Search", "filter_delete", hasFilter, this.fieldFilterPanel::clear);
final EnableCheck hasFilterHistory = new ObjectPropertyEnableCheck(this.tableModel, "hasFilterHistory");
toolBar.addButton("search", ConsumerAction.action("Search History", Icons.getIconWithBadge("book", "filter"), hasFilterHistory, (event) -> {
final Object source = event.getSource();
Component component = null;
if (source instanceof Component) {
component = (Component) source;
}
final BaseJPopupMenu menu = new BaseJPopupMenu();
for (final Condition filter : this.tableModel.getFilterHistory()) {
menu.addMenuItem(filter.toString(), () -> this.fieldFilterPanel.setFilter(filter));
}
menu.showMenu(component, 0, 20);
}));
}
// Filter buttons
boolean first = true;
for (final TableRecordsMode fieldFilterMode : this.tableModel.getFieldFilterModes()) {
final String key = fieldFilterMode.getKey();
final String title = fieldFilterMode.getTitle();
final Icon icon = fieldFilterMode.getIcon();
final EnableCheck enableCheck = fieldFilterMode.getEnableCheck();
final JToggleButton button = toolBar.addToggleButton(FILTER_FIELD, -1, null, title, icon, enableCheck, () -> {
if (this.tableModel != null) {
this.tableModel.setTableRecordsMode(fieldFilterMode);
}
});
this.buttonByMode.put(FILTER_FIELD + "_" + key, button);
if (first) {
button.doClick();
first = false;
}
}
if (hasGeometry) {
final JToggleButton showAllGeometries = addGeometryFilterToggleButton(toolBar, -1, "Show All Records ", "world_filter", "all", null);
showAllGeometries.doClick();
addGeometryFilterToggleButton(toolBar, -1, "Show Records on Map", "map_filter", "boundingBox", new ObjectPropertyEnableCheck(this.tableModel, "filterByBoundingBoxSupported"));
}
}
use of com.revolsys.swing.menu.MenuFactory in project com.revolsys.open by revolsys.
the class ProjectFrame method newMenuBar.
@Override
protected JMenuBar newMenuBar() {
final JMenuBar menuBar = super.newMenuBar();
addMenu(menuBar, newMenuFile());
final MenuFactory tools = newMenuTools();
if (OS.isWindows()) {
tools.addMenuItem("options", "Options...", "Options...", (String) null, () -> {
new PreferencesDialog().showPanel();
});
}
addMenu(menuBar, tools);
return menuBar;
}
use of com.revolsys.swing.menu.MenuFactory in project com.revolsys.open by revolsys.
the class ProjectFrame method newMenuFile.
protected MenuFactory newMenuFile() {
final MenuFactory file = new MenuFactory("File");
file.addMenuItemTitleIcon("projectOpen", "New Project", "layout:add", this::actionNewProject).setAcceleratorControlKey(KeyEvent.VK_N);
file.addMenuItemTitleIcon("projectOpen", "New Project...", "layout:add", () -> {
if (this.project != null) {
this.project.actionImportProject("New Project from Template", true);
}
}).setAcceleratorShiftControlKey(KeyEvent.VK_N);
file.addMenuItemTitleIcon("projectOpen", "Open Project...", "layout:add", this::actionOpenProject).setAcceleratorControlKey(KeyEvent.VK_O);
file.addComponent("projectOpen", this.openRecentMenu);
updateRecentMenu();
file.addMenuItemTitleIcon("projectSave", "Save Project", "layout_save", () -> {
if (this.project.isSaved()) {
this.project.saveAllSettings();
} else {
actionSaveProjectAs();
}
}).setAcceleratorControlKey(KeyEvent.VK_S);
file.addMenuItemTitleIcon("projectSave", "Save Project As...", "layout_save", this::actionSaveProjectAs).setAcceleratorShiftControlKey(KeyEvent.VK_S);
file.addMenuItemTitleIcon("save", "Save as PDF", "save_pdf", SaveAsPdf::save);
file.addMenuItemTitleIcon("print", "Print", "printer", SinglePage::print).setAcceleratorControlKey(KeyEvent.VK_P);
if (OS.isWindows()) {
file.addMenuItemTitleIcon("exit", "Exit", null, this::exit).setAcceleratorKey(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));
} else if (OS.isUnix()) {
file.addMenuItemTitleIcon("exit", "Exit", null, this::exit).setAcceleratorKey(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_MASK));
}
return file;
}
Aggregations