@Override public void createControl(Composite parent) { mComposite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(2, false); layout.marginWidth = layout.marginHeight = 0; mComposite.setLayout(layout); GridDataFactory.fillDefaults().grab(true, true).applyTo(mComposite); Label l = new Label(mComposite, SWT.NONE); l.setText("Size: "); GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(l); mSizeLabel = new Label(mComposite, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(mSizeLabel); l = new Label(mComposite, SWT.NONE); l.setText("Usage: "); GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(l); mUsageLabel = new Label(mComposite, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(mUsageLabel); l = new Label(mComposite, SWT.NONE); l.setText("Type: "); GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(l); mTypeLabel = new Label(mComposite, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).applyTo(mTypeLabel); l = new Label(mComposite, SWT.NONE); l.setText("Format Data As: "); GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(l); DisplayFormat[] values = DisplayFormat.values(); List<String> formats = new ArrayList<String>(values.length); for (DisplayFormat format : values) { formats.add(format.name()); } mDisplayFormatCombo = new Combo(mComposite, SWT.DROP_DOWN | SWT.READ_ONLY); mDisplayFormatCombo.setItems(formats.toArray(new String[formats.size()])); mDisplayFormatCombo.select(0); mDisplayFormatCombo.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { updateContents(); } }); GridDataFactory.fillDefaults().grab(true, false).applyTo(mDisplayFormatCombo); mTextControl = new Text( mComposite, SWT.BORDER | SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.H_SCROLL); GridDataFactory.fillDefaults().span(2, 1).grab(true, true).applyTo(mTextControl); mTextControl.setEditable(false); }
/** * Adds a cell format to the hash map, keyed on its index. If the format record is not * initialized, then its index number is determined and its initialize method called. If the font * is not a built in format, then it is added to the list of formats for writing out * * @param fr the format record */ public final void addFormat(DisplayFormat fr) throws NumFormatRecordsException { if (!fr.isInitialized()) { fr.initialize(nextCustomIndexNumber); nextCustomIndexNumber++; } if (nextCustomIndexNumber > maxFormatRecordsIndex) { nextCustomIndexNumber = maxFormatRecordsIndex; throw new NumFormatRecordsException(); } if (fr.getFormatIndex() >= nextCustomIndexNumber) { nextCustomIndexNumber = fr.getFormatIndex() + 1; } if (!fr.isBuiltIn()) { formatsList.add(fr); formats.put(new Integer(fr.getFormatIndex()), fr); } }
/** * Rationalizes the display formats. Duplicate formats are removed and the format indices of the * cells adjusted accordingly. It is invoked immediately prior to writing writing out the sheet * * @param im the index mapping for the font rationalization */ public IndexMapping rationalizeDisplayFormats() { ArrayList newformats = new ArrayList(); int numremoved = 0; IndexMapping mapping = new IndexMapping(nextCustomIndexNumber); // Iterate through the old list Iterator i = formatsList.iterator(); DisplayFormat df = null; DisplayFormat df2 = null; boolean duplicate = false; while (i.hasNext()) { df = (DisplayFormat) i.next(); Assert.verify(!df.isBuiltIn()); // Compare against formats already on the list Iterator i2 = newformats.iterator(); duplicate = false; while (i2.hasNext() && !duplicate) { df2 = (DisplayFormat) i2.next(); if (df2.equals(df)) { duplicate = true; mapping.setMapping(df.getFormatIndex(), mapping.getNewIndex(df2.getFormatIndex())); numremoved++; } } // If this format is not a duplicate then add it to the new list if (!duplicate) { newformats.add(df); int indexnum = df.getFormatIndex() - numremoved; if (indexnum > maxFormatRecordsIndex) { System.err.println("Warning: too many number formats - using default format"); indexnum = 0; // the default number format index } mapping.setMapping(df.getFormatIndex(), df.getFormatIndex() - numremoved); } } // Set the new list formatsList = newformats; // Update the index codes for the remaining formats i = formatsList.iterator(); while (i.hasNext()) { df = (DisplayFormat) i.next(); df.initialize(mapping.getNewIndex(df.getFormatIndex())); } return mapping; }