Skip to content

Commit

Permalink
Merge pull request #116 from SeeSharpSoft/fb_cell_renderer_fixes
Browse files Browse the repository at this point in the history
Fonts & Fixes
  • Loading branch information
SeeSharpSoft committed Mar 31, 2019
2 parents edff7c0 + 3aab0ed commit 82647f4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .bettercodehub.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
component_depth: 10
component_depth: 8
languages:
- java
- java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorFontType;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
Expand All @@ -27,6 +29,7 @@
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Collections;
Expand Down Expand Up @@ -295,6 +298,10 @@ public int getRowCount() {
return getDataHandler().getCurrentState().length;
}

public Font getFont() {
return EditorColorsManager.getInstance().getGlobalScheme().getFont(EditorFontType.PLAIN);
}

public int getColumnCount() {
Object[][] currentData = getDataHandler().getCurrentState();
return currentData.length > 0 ? currentData[0].length : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.util.Vector;

public class CsvTableEditorActions extends CsvTableEditorUtilBase {

Expand Down Expand Up @@ -145,18 +144,6 @@ public void actionPerformed(ActionEvent e) {
}
}

private void removeColumn(DefaultTableModel tableModel, int column) {
int prevColumnCount = tableModel.getColumnCount();

Vector rows = tableModel.getDataVector();
for (Object row : rows) {
((Vector) row).remove(column);
}

tableModel.setColumnCount(prevColumnCount - 1);
tableModel.fireTableStructureChanged();
}

private final class DeleteColumnAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,17 @@ private void initializedUIComponents() {

tblEditor.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
tblEditor.setShowColumns(true);
tblEditor.setFont(getFont());
setTableRowHeight(0);

tblEditor.getColumnModel().addColumnModelListener(tableEditorListener);

tblEditor.setDefaultRenderer(String.class, new MultiLineCellRenderer(this.tableEditorKeyListener, this));
tblEditor.setDefaultRenderer(Object.class, new MultiLineCellRenderer(this.tableEditorKeyListener, this));
tblEditor.setDefaultEditor(String.class, new MultiLineCellRenderer(this.tableEditorKeyListener, this));
tblEditor.setDefaultEditor(Object.class, new MultiLineCellRenderer(this.tableEditorKeyListener, this));
MultiLineCellRenderer cellRenderer = new MultiLineCellRenderer(this.tableEditorKeyListener, this);
MultiLineCellRenderer cellEditor = new MultiLineCellRenderer(this.tableEditorKeyListener, this);
tblEditor.setDefaultRenderer(String.class, cellRenderer);
tblEditor.setDefaultRenderer(Object.class, cellRenderer);
tblEditor.setDefaultEditor(String.class, cellEditor);
tblEditor.setDefaultEditor(Object.class, cellEditor);
tblEditor.registerKeyboardAction(this.tableEditorActions.undo,
KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK), JComponent.WHEN_FOCUSED);
tblEditor.registerKeyboardAction(this.tableEditorActions.redo,
Expand Down Expand Up @@ -201,7 +204,7 @@ public void updateEditorLayout() {
getFileEditorState().setColumnWidths(columnWidths);
}

float zoomFactor = calcuateZoomFactor();
float zoomFactor = calculateZoomFactor();
for (int i = 0; i < currentColumnCount; ++i) {
TableColumn column = this.tblEditor.getColumnModel().getColumn(i);
column.setPreferredWidth(Math.round(columnWidths[i] * zoomFactor));
Expand All @@ -212,7 +215,7 @@ public void updateEditorLayout() {
panelInfo.setVisible(getFileEditorState().showInfoPanel());
}

private float calcuateZoomFactor() {
private float calculateZoomFactor() {
float fontHeight = getFontHeight();
return fontHeight / baseFontHeight;
}
Expand Down Expand Up @@ -386,7 +389,7 @@ public JComponent getPreferredFocusedComponent() {

public void storeCurrentTableLayout() {
int[] widths = getCurrentColumnsWidths();
float zoomFactor = calcuateZoomFactor();
float zoomFactor = calculateZoomFactor();
for (int i = 0; i < widths.length; i++) {
widths[i] /= zoomFactor;
}
Expand Down Expand Up @@ -459,7 +462,7 @@ protected String generateCsv(Object[][] data) {
}

private int getGlobalFontSize() {
return EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize();
return EditorColorsManager.getInstance().getGlobalScheme().getEditorFontSize();
}

private int getFontHeight() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class MultiLineCellRenderer extends JTextArea implements TableCellRenderer, TableCellEditor {

private Set<CellEditorListener> cellEditorListenerSet = Collections.synchronizedSet(new HashSet<>());
private Set<CellEditorListener> cellEditorListenerSet = new HashSet<>();
private final UserDataHolder userDataHolder;

public MultiLineCellRenderer(CsvTableEditorKeyListener keyListener, UserDataHolder userDataHolderParam) {
Expand Down Expand Up @@ -142,11 +142,15 @@ protected void fireCancelCellEditing() {

@Override
public void addCellEditorListener(CellEditorListener cellEditorListener) {
cellEditorListenerSet.add(cellEditorListener);
synchronized (cellEditorListenerSet) {
cellEditorListenerSet.add(cellEditorListener);
}
}

@Override
public void removeCellEditorListener(CellEditorListener cellEditorListener) {
cellEditorListenerSet.remove(cellEditorListener);
synchronized (cellEditorListenerSet) {
cellEditorListenerSet.remove(cellEditorListener);
}
}
}

0 comments on commit 82647f4

Please sign in to comment.