All files / src/generator swingMappings.ts

100% Statements 12/12
100% Branches 10/10
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32    14x                                   132x       108x 108x 103x 98x 93x 88x    
import type { ComponentModel, ComponentType } from "../components/ComponentModel";
 
const SWING_CLASS_MAP: Partial<Record<ComponentType, string>> = {
  Panel: "JPanel",
  Button: "JButton",
  Label: "JLabel",
  TextField: "JTextField",
  PasswordField: "JPasswordField",
  TextArea: "JTextArea",
  CheckBox: "JCheckBox",
  RadioButton: "JRadioButton",
  ComboBox: "JComboBox<String>",
  List: "JList<String>",
  ProgressBar: "JProgressBar",
  Slider: "JSlider",
  Spinner: "JSpinner",
  Separator: "JSeparator",
};
 
export function getSwingClass(componentType: ComponentType): string {
  return SWING_CLASS_MAP[componentType] ?? "JButton";
}
 
export function getComponentSwingType(comp: ComponentModel): string {
  const componentType = comp.type as string;
  if (componentType === "MenuBar") return "JMenuBar";
  if (componentType === "Menu") return "JMenu";
  if (componentType === "MenuItem") return "JMenuItem";
  if (componentType === "ToolBar") return "JToolBar";
  return getSwingClass(comp.type);
}