# (DD03) Setting Title

## 1. Data Flow Processing Logic

```mermaid
flowchart TD
    DD03([DD03])
    COND{"plan != null && plan.getDataSetSize() > 0"}
    SET_PLAN["Set desktop window title<br/>SingleViewController.setTitle(plan);"]
    SET_DATASET["Set desktop window title<br/>SingleViewController.setTitle(dataSet.getDataSet(0));"]
    DD04([DD04])

    DD03 --> COND
    COND -- Yes --> SET_PLAN
    COND -- No --> SET_DATASET
    SET_PLAN --> SET_DATASET
    SET_DATASET --> DD04
```

### Inputs

- `(4.2.2) DcmDataSetTree plan`
- `(4.2.1) DcmDataSetTree dataSet`

### Processing Rules

Determine whether the plan is valid by checking that the following conditions are satisfied:

- `plan` is not `null`
- `plan.getDataSetSize() > 0`, indicating that the plan contains at least one dataset

### If the condition is true

Set the window title based on the plan data.

- Call `SingleViewController.setTitle(plan)`

### If the condition is false

Retrieve the first dataset from `dataSet` and use it to set the window title.

- Call `SingleViewController.setTitle(dataSet.getDataSet(0))`

End the current processing and proceed to the next step.

## 2. Sequence Diagram

```mermaid
sequenceDiagram
    participant Panel as Matching3Dx3DPanel_Imple
    participant Tree as DcmDataSetTree
    participant Controller as SingleViewController

    alt plan != null && plan.getDataSetSize() > 0
        Panel->>Controller: setTitle(plan)
    else no
        Panel->>Tree: getDataSet(0)
        Tree-->>Panel: ds0: DcmDataSetTree
        Panel->>Controller: setTitle(ds0)
    end
```

## 3. Class / Method List

| No | Class | Method | Arguments |
| --- | --- | --- | --- |
| 1 | `DcmDataSetTree` | `getDataSetSize` | `-` |
| 2 | `SingleViewController` | `setTitle` | `DcmDataSetTree data` |
| 3 | `DcmDataSetTree` | `getDataSet` | `long key` |

## 4. Detailed Class / Method Description

### 1. `DcmDataSetTree.getDataSetSize`

| Field | Value |
| --- | --- |
| Class Name | `DcmDataSetTree` |
| Method Name | `getDataSetSize` |
| Arguments | `-` |
| Argument Description | `-` |
| Return Type | `int` |
| Overview | Return the numbers of datasets |
| Description | Returns the value of the internal collection `datasets_.size()`.<br><br>This method is used for plan validity checks, such as determining whether `getDataSetSize() > 0`. |

### 2. `SingleViewController.setTitle`

| Field | Value |
| --- | --- |
| Class Name | `SingleViewController` |
| Method Name | `setTitle` |
| Arguments | `dicom.DcmDataSetTree data` |
| Argument Description | `data` - DICOM dataset used for generating the application title. |
| Return Type | `-` |
| Overview | Updates the application window title based on the newly provided DICOM data (if `mainFrame` exists). |
| Description | Updates the application window title based on the newly provided DICOM data (if `mainFrame` exists).<br><br>If `mainFrame` is not `null`, the method performs the following operations:<br><br>Stores the new DICOM dataset in the variable `lastData`.<br>Generates the application title using `AppUtil.getApplicationTitle(...)`, based on the dataset and the last used user name (`lastUserName`).<br>Sets the generated title to the main application window using `mainFrame.setTitle(...)`.<br><br>If `mainFrame` has not been initialized, this method performs no operation. |

### 3. `DcmDataSetTree.getDataSet`

| Field | Value |
| --- | --- |
| Class Name | `DcmDataSetTree` |
| Method Name | `getDataSet` |
| Arguments | `long key` |
| Argument Description | `key` - データセットを特定するためのキー（long 型） |
| Return Type | `DcmDataSetTree` |
| Overview | Retrieves the dataset corresponding to the specified key from the internal collection `datasets_`. |
| Description | Executes `datasets_.get(Long.valueOf(key))` and casts the result to `DcmDataSetTree` before returning it.<br><br>If the specified key does not exist, the return value is `null`, following the standard behavior of `Map#get`. |
