use of javax.swing.table.TableColumnModel in project SE2017_4_tuna by SE-admin.
the class UIUpdate method resizeColumnWidth.
public static void resizeColumnWidth(JTable table) {
final TableColumnModel columnModel = table.getColumnModel();
for (int column = 0; column < table.getColumnCount(); column++) {
int width = 50;
for (int row = 0; row < table.getRowCount(); row++) {
TableCellRenderer renderer = table.getCellRenderer(row, column);
Component comp = table.prepareRenderer(renderer, row, column);
width = Math.max(comp.getPreferredSize().width + 1, width);
}
columnModel.getColumn(column).setPreferredWidth(width);
}
}
use of javax.swing.table.TableColumnModel in project intellij-community by JetBrains.
the class CaptureConfigurable method createComponent.
@Nullable
@Override
public JComponent createComponent() {
myTableModel = new MyTableModel();
JBTable table = new JBTable(myTableModel);
table.setColumnSelectionAllowed(false);
TableColumnModel columnModel = table.getColumnModel();
TableUtil.setupCheckboxColumn(columnModel.getColumn(MyTableModel.ENABLED_COLUMN));
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(table);
decorator.setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
myTableModel.addRow();
}
});
decorator.setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.removeSelectedItems(table);
}
});
decorator.setMoveUpAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsUp(table);
}
});
decorator.setMoveDownAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
TableUtil.moveSelectedItemsDown(table);
}
});
decorator.addExtraAction(new DumbAwareActionButton("Duplicate", "Duplicate", PlatformIcons.COPY_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() == 1;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> {
try {
int idx = myTableModel.add(c.clone());
table.getSelectionModel().setSelectionInterval(idx, idx);
} catch (CloneNotSupportedException ex) {
LOG.error(ex);
}
});
}
});
decorator.addExtraAction(new DumbAwareActionButton("Enable Selected", "Enable Selected", PlatformIcons.SELECT_ALL_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = true);
table.repaint();
}
});
decorator.addExtraAction(new DumbAwareActionButton("Disable Selected", "Disable Selected", PlatformIcons.UNSELECT_ALL_ICON) {
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = false);
table.repaint();
}
});
new DumbAwareAction("Toggle") {
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(table.getSelectedRowCount() == 1);
}
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
selectedCapturePoints(table).forEach(c -> c.myEnabled = !c.myEnabled);
table.repaint();
}
}.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0)), table);
decorator.addExtraAction(new DumbAwareActionButton("Import", "Import", AllIcons.Actions.Install) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, true, false, true, true) {
@Override
public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || "xml".equals(file.getExtension()) || file.getFileType() == FileTypes.ARCHIVE);
}
@Override
public boolean isFileSelectable(VirtualFile file) {
return file.getFileType() == StdFileTypes.XML;
}
};
descriptor.setDescription("Please select a file to import.");
descriptor.setTitle("Import Capture Points");
VirtualFile[] files = FileChooser.chooseFiles(descriptor, e.getProject(), null);
if (ArrayUtil.isEmpty(files))
return;
table.getSelectionModel().clearSelection();
for (VirtualFile file : files) {
try {
Document document = JDOMUtil.loadDocument(file.getInputStream());
List<Element> children = document.getRootElement().getChildren();
children.forEach(element -> {
int idx = myTableModel.addIfNeeded(XmlSerializer.deserialize(element, CapturePoint.class));
table.getSelectionModel().addSelectionInterval(idx, idx);
});
} catch (Exception ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
}
});
decorator.addExtraAction(new DumbAwareActionButton("Export", "Export", AllIcons.Actions.Export) {
@Override
public void actionPerformed(@NotNull final AnActionEvent e) {
VirtualFileWrapper wrapper = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor("Export Selected Capture Points to File...", "", "xml"), e.getProject()).save(null, null);
if (wrapper == null)
return;
Element rootElement = new Element("capture-points");
selectedCapturePoints(table).forEach(c -> {
try {
CapturePoint clone = c.clone();
clone.myEnabled = false;
rootElement.addContent(XmlSerializer.serialize(clone));
} catch (CloneNotSupportedException ex) {
LOG.error(ex);
}
});
try {
JDOMUtil.write(rootElement, wrapper.getFile());
} catch (Exception ex) {
final String msg = ex.getLocalizedMessage();
Messages.showErrorDialog(e.getProject(), msg != null && msg.length() > 0 ? msg : ex.toString(), "Export Failed");
}
}
@Override
public boolean isEnabled() {
return table.getSelectedRowCount() > 0;
}
});
BorderLayoutPanel panel = JBUI.Panels.simplePanel();
panel.addToCenter(decorator.createPanel());
myCaptureVariables = new JCheckBox(DebuggerBundle.message("label.capture.configurable.capture.variables"));
panel.addToBottom(myCaptureVariables);
return panel;
}
use of javax.swing.table.TableColumnModel in project Botnak by Gocnak.
the class BaseTableHeaderUI method getHeaderHeight.
private int getHeaderHeight() {
if ((header == null) || (header.getTable() == null)) {
return 0;
}
int height = 0;
boolean accomodatedDefault = false;
TableColumnModel columnModel = header.getColumnModel();
for (int column = 0; column < columnModel.getColumnCount(); column++) {
TableColumn aColumn = columnModel.getColumn(column);
boolean isDefault = (aColumn.getHeaderRenderer() == null);
if (!isDefault || !accomodatedDefault) {
Component comp = getHeaderRenderer(column);
int rendererHeight = comp.getPreferredSize().height;
height = Math.max(height, rendererHeight);
// it returns for a non-null/non-empty value.
if (isDefault && rendererHeight > 0) {
Object headerValue = aColumn.getHeaderValue();
if (headerValue != null) {
headerValue = headerValue.toString();
if (headerValue != null && !headerValue.equals("")) {
accomodatedDefault = true;
}
}
}
}
}
return height + 2;
}
use of javax.swing.table.TableColumnModel in project otapij by FellowTraveler.
the class PaymentInboxTableModel method removeCols.
public static void removeCols(JTable paymentTable) {
TableColumnModel tcm = paymentTable.getColumnModel();
System.out.println("getColumnCount:" + tcm.getColumnCount());
if (tcm.getColumnCount() == 10) {
paymentTable.removeColumn(tcm.getColumn(9));
}
if (tcm.getColumnCount() == 9) {
paymentTable.removeColumn(tcm.getColumn(8));
}
if (tcm.getColumnCount() == 8) {
paymentTable.removeColumn(tcm.getColumn(7));
}
}
use of javax.swing.table.TableColumnModel in project otapij by FellowTraveler.
the class PaymentOutboxTableModel method removeCols.
public static void removeCols(JTable paymentTable) {
TableColumnModel tcm = paymentTable.getColumnModel();
System.out.println("getColumnCount:" + tcm.getColumnCount());
if (tcm.getColumnCount() == 7) {
paymentTable.removeColumn(tcm.getColumn(6));
}
if (tcm.getColumnCount() == 6) {
paymentTable.removeColumn(tcm.getColumn(5));
}
if (tcm.getColumnCount() == 5) {
paymentTable.removeColumn(tcm.getColumn(4));
}
}
Aggregations